Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!bfmny0!tneff From: tneff@bfmny0.BFM.COM (Tom Neff) Newsgroups: comp.mail.uucp Subject: Re: UUCP status files and wierd dates - revisted. Message-ID: <16065@bfmny0.BFM.COM> Date: 27 Nov 90 00:18:24 GMT References: <803@sci34hub.UUCP> <754@dynasys.UUCP> <967@iiasa.UUCP> Reply-To: tneff@bfmny0.BFM.COM (Tom Neff) Lines: 250 This might be a good time to repost my 'ago' program for Sys V. I made a new SHAR just for you. #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # README # ago.1 # ago.c # This archive created: Mon Nov 26 19:16:19 1990 export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'README' then echo shar: "will not over-write existing file 'README'" else sed 's/^X//' << \SHAR_EOF > 'README' X XAGO is a System V command to display formatted date/time strings for Xtimes in the past or future. I needed to do this and couldn't find Xanything out there, so voila! X XVersion 1.2 adds the -T switch to let you translate an absolute numeric XUNIX time value into a formatted date string. X XYou will need getopt(3C) to parse the command line. If this isn't Xin your standard C library, get one of the PD versions and link it in. X X X X@(#) README $Revision: 1.2 $ $Date: 90/11/26 19:05:05 $ SHAR_EOF fi if test -f 'ago.1' then echo shar: "will not over-write existing file 'ago.1'" else sed 's/^X//' << \SHAR_EOF > 'ago.1' X'\" @(#) $Id: ago.1,v 1.2 90/11/26 19:15:20 tneff Exp $ X.TH AGO 1 X.SH NAME X\fBago\fR \- display date for times in the past or future X.SH USAGE X.B ago X.B [-s secs] X.B [-m mins] X.B [-h hrs] X.B [-d days] X.B [-w wks] X.B [-T timeval] X.B [+fmt] X.SH DESCRIPTION XThe X.I ago Xcommand is an extension to date(1) that displays a formatted date/time Xstring for a moment in the past or future, specified in seconds, minutes, Xhours, days and/or weeks relative to now. X.I ago Xaccepts the same format string as date(1). X.sp XWith no parameters specified, Xor with only X.I +fmt Xspecified, X.I ago Xbehaves exactly like date(1). XIf any of X.I \-s \-m \-h \-d \-w Xare specified, X.I ago X.B subtracts Xthe argument values from the current time before display. X(Specifying negative arguments will X.B add Xthe values to the current time, i.e., point into the future.) X.sp XIf the X.I -T Xoption is given, the X.b timeval Xoption value will be used as an absolute time argument Xinstead of adding or subtracting from the current time. XThis is useful for decoding binary timestamps found in Xcertain databases. X.sp XFor further details on the format string, see date(1). X.SH EXAMPLES X.sp X$ ago X.br XFri Jan 12 17:22:05 EST 1990 X.sp X$ ago -d20 -h3 X.br XSat Dec 23 14:23:00 EST 1989 X.sp X$ ago -w-3 X.br XFri Feb 2 17:23:41 EST 1990 X.sp X$ ago -T 651891946 X.br XTue Aug 28 21:05:46 EDT 1990 X.sp X$ ago -d-1 +'Tomorrow the time zone will be "%Z"' X.br XTomorrow the time zone will be "EST" X.SH SEE ALSO X.BR date(1), cftime(3C). SHAR_EOF fi if test -f 'ago.c' then echo shar: "will not over-write existing file 'ago.c'" else sed 's/^X//' << \SHAR_EOF > 'ago.c' X/* X * ago - display date for times in the past or future X * X * usage: X * ago [-s secs] [-m mins] [-h hrs] [-d days] [-w wks] [+fmt] X * X * where: X * -s secs Specifies how far into the past to look. X * -m mins A negative argument looks into the future. X * -h hrs X * -d days X * -w wks X * -T timeval An absolute timeval replaces 'now' as a base. X * X * +fmt is a cftime(3C) format string with a leading '+' X * for compatibility with date(1). If omitted, the X * date(1) default of "%a %b %e %T %Z %Y" is used. X * X * NOTE: X * Uses getopt(3C) to parse the command line. X * X * $Log: ago.c,v $ X * Revision 1.2 90/09/18 15:45:07 tneff X * add -T timeval switch -- specifies an absolute base instead of 'now' X * X * Revision 1.1 90/01/12 20:20:13 tneff X * Initial revision X * X */ X X#ident "@(#) $Id: ago.c,v 1.2 90/09/18 15:45:07 tneff Exp $" X X#include X#include X#include X X/* The command mainline. */ X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X int c; X int errflg = 0; X extern char *optarg; X extern int optind; X X time_t when = 0; X char *fmt; X X char buf[1024]; X X int secs, mins, hrs, days, wks = 0; X X /* Collect option switches */ X X while ((c = getopt(argc, argv, "s:m:h:d:w:T:?")) != -1) X switch (c) X { X case 's': X if ((secs = atol(optarg)) == 0) X errflg++; X break; X case 'm': X if ((mins = atol(optarg)) == 0) X errflg++; X break; X case 'h': X if ((hrs = atol(optarg)) == 0) X errflg++; X break; X case 'd': X if ((days = atol(optarg)) == 0) X errflg++; X break; X case 'w': X if ((wks = atol(optarg)) == 0) X errflg++; X break; X case 'T': X if ((when = atol(optarg)) == 0) X errflg++; X break; X X default: X errflg++; X } X X /* Validate args and print usage message if bad */ X X switch(argc-optind) X { X case 0: X fmt = "%a %b %e %T %Z %Y"; X break; X case 1: X if (argv[optind][0] == '+') X fmt = argv[optind]+1; X else X errflg++; X break; X default: X errflg++; X } X X if (errflg) X { X fprintf(stderr, "usage: %s [-s secs] [-m mins] [-h hrs] [-d days] [-w wks] [+fmt]\n", argv[0]); X exit(1); X } X X /* Start with 'now' or our preset value */ X X if (when == 0) X when = time(NULL); X X /* Adjust */ X X when -= secs*1; X when -= mins*60; X when -= hrs*60*60; X when -= days*60*60*24; X when -= wks*60*60*24*7; X X /* Format and output */ X X cftime(buf, fmt, &when); X printf("%s\n",buf); X} SHAR_EOF fi exit 0 # End of shell archive