hyc@umix.cc.umich.edu (Howard Chu) (04/14/88)
XX XX result = ( jd - JD1970 ) * 24 * 60 * 60 + sdc; XX XX return ( tw -> tw_clock = result ); XX } XX XX/* */ XX XX/*** twsubtract - subtract tw2 from tw1, returning result in seconds XX XXThe point of this routine is that using twclock( tw1 ) - twclock( tw2 ) XXwould limit you to dates after the Unix* Epoch ( 01 January 1970 ). This XXroutine avoids that limit. However, because the result is represented XXby 32 bits, it is still limited to a span of two billion seconds, which is XXabout 66 years. XX XX*/ XX XXlong XXtwsubtract( tw1, tw2 ) XXstruct tws *tw1, *tw2; XX { XX register long jd1, jd2, sdc1, sdc2, result; XX XX if ( ( jd1 = twjuliandate( tw1 ) ) == -1L ) XX return ( 0L ); XX if ( ( sdc1 = twsubdayclock( tw1 ) ) == -1L ) XX return ( 0L ); XX XX if ( ( jd2 = twjuliandate( tw2 ) ) == -1L ) XX return ( 0L ); XX if ( ( sdc2 = twsubdayclock( tw2 ) ) == -1L ) XX return ( 0L ); XX XX result = ( jd1 - jd2 ) * 24 * 60 * 60 + ( sdc1 - sdc2 ); XX XX return ( result ); XX } XX XX/* */ XX XX/* XX * Simple calculation of day of the week. Algorithm used is Zeller's XX * congruence. Currently, we assume if tw -> tw_year < 100 XX * then the century is CENTURY. XX */ XX XXset_dotw( tw ) XXstruct tws *tw; XX { XX register int month, day, year, century; XX XX month = tw -> tw_mon - 1; XX day = tw -> tw_mday; XX year = tw -> tw_year % 100; XX century = tw -> tw_year >= 100 ? tw -> tw_year / 100 : CENTURY; XX XX if ( month <= 0 ) XX { XX month += 12; XX if ( --year < 0 ) XX { XX year += 100; XX century--; XX } XX } XX XX tw -> tw_wday = XX ((26 * month - 2) / 10 + day + year + year / 4 XX - 3 * century / 4 + 1) % 7; XX XX tw -> tw_flags &= ~TW_SDAY; XX tw -> tw_flags |= TW_SIMP; XX } XX XX XX/* * Unix is a virus from outer space. */ SHAR_EOF if test 9035 -ne "`wc -c dtime.c`" then echo shar: error transmitting dtime.c '(should have been 9035 characters)' fi echo shar: extracting dtimep.lex '(7327 characters)' sed 's/^XX//' << \SHAR_EOF > dtimep.lex XX%e 2000 XX%p 5000 XX%n 1000 XX%a 4000 XX%START Z XXsun (sun(day)?) XXmon (mon(day)?) XXtue (tue(sday)?) XXwed (wed(nesday)?) XXthu (thu(rsday)?) XXfri (fri(day)?) XXsat (sat(urday)?) XX XXDAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat}) XX XXjan (jan(uary)?) XXfeb (feb(ruary)?) XXmar (mar(ch)?) XXapr (apr(il)?) XXmay (may) XXjun (jun(e)?) XXjul (jul(y)?) XXaug (aug(ust)?) XXsep (sep(tember)?) XXoct (oct(ober)?) XXnov (nov(ember)?) XXdec (dec(ember)?) XX XXMONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec}) XX XXw ([ \t]*) XXW ([ \t]+) XXD ([0-9]?[0-9]) XXd [0-9] XX%{ XX/* dtimep.lex - routines to do ``ARPA-style'' time parsing XX XXver date who remarks XX--- ------- --- ------------------------------------------------------------- XX01B 15nov86 JP Thouroughly hacked by Jef Poskanzer. XX01A ??????? MTR Original version from the MH 6.5 distribution, courtesy XX of Marshall Rose. XX XX*/ XX XX#include "tws.h" XX#include <ctype.h> XX#include <sys/types.h> XX#include <time.h> XX#ifdef SYS5 XX#include <string.h> XX#else SYS5 XX#include <strings.h> XX#include <sys/timeb.h> XX#endif SYS5 XX XX#ifdef SYS5 XXextern int daylight; XXextern long timezone; XXextern char *tzname[]; XX#endif SYS5 XX XX/* XX * Table to convert month names to numeric month. We use the XX * fact that the low order 5 bits of the sum of the 2nd & 3rd XX * characters of the name is a hash with no collisions for the 12 XX * valid month names. (The mask to 5 bits maps any combination of XX * upper and lower case into the same hash value). XX */ XXstatic int month_map[] = { XX 0, XX 6, /* 1 - Jul */ XX 3, /* 2 - Apr */ XX 5, /* 3 - Jun */ XX 0, XX 10, /* 5 - Nov */ XX 0, XX 1, /* 7 - Feb */ XX 11, /* 8 - Dec */ XX 0, XX 0, XX 0, XX 0, XX 0, XX 0, XX 0, /*15 - Jan */ XX 0, XX 0, XX 0, XX 2, /*19 - Mar */ XX 0, XX 8, /*21 - Sep */ XX 0, XX 9, /*23 - Oct */ XX 0, XX 0, XX 4, /*26 - May */ XX 0, XX 7 }; /*28 - Aug */ XX/* XX * Same trick for day-of-week using the hash function XX * (c1 & 7) + (c2 & 4) XX */ XXstatic int day_map[] = { XX 0, XX 0, XX 0, XX 6, /* 3 - Sat */ XX 4, /* 4 - Thu */ XX 0, XX 5, /* 6 - Fri */ XX 0, /* 7 - Sun */ XX 2, /* 8 - Tue */ XX 1 /* 9 - Mon */, XX 0, XX 3 }; /*11 - Wed */ XX#define SETDAY tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\ XX tw.tw_flags |= TW_SEXP;\ XX cp += 2; XX#define SETMONTH tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\ XX cp += 2;\ XX SKIPD; XX#define CVT1OR2 (i=(*cp++ - '0'), isdigit(*cp)? i*10 + (*cp++ - '0') : i) XX#define CVT2 ( (*cp++ - '0')*10 + (*cp++ - '0') ) XX#define CVT3 ( ( (*cp++ - '0')*10 + (*cp++ - '0') )*10 + (*cp++ - '0') ) XX#define CVT4 ( ( ( (*cp++ - '0')*10 + (*cp++ - '0') )*10 + (*cp++ - '0') )*10 + (*cp++ - '0') ) XX#define SKIPD while ( ! isdigit( *cp++ ) ) ; --cp; XX#define ZONE(x) tw.tw_zone=(x); XX#define ZONED(x) tw.tw_zone=(x); tw.tw_flags |= TW_DST; XX#define LC(c) (isupper( c ) ? tolower( c ) : ( c )) XX%} XX%% XX%{ XXstruct tws * XXdparsetime( str ) XXchar *str; XX { XX register int i; XX static struct tws tw; XX register char *cp; XX register int gotdate = 0; XX#ifndef SYS5 XX struct timeb tb; XX#endif not SYS5 XX long clock; XX XX start_cond = 0; XX XX /* Zero out the struct. */ XX bzero( (char *) &tw, sizeof tw ); XX XX /* Set default time zone. */ XX#ifndef SYS5 XX ftime( &tb ); XX tw.tw_zone = -tb.timezone; XX#else SYS5 XX tzset( ); XX tw.tw_zone = -(timezone / 60); XX#endif SYS5 XX XX for ( ; ; ) XX switch ( cp = str, lex_string( &str, start_cond ) ) XX { XX case -1: XX if ( ! gotdate ) XX return ( NULL ); XX tw.tw_flags |= TW_JUNK; XX /* fall through */ XX case 0: XX if ( tw.tw_year == 0 ) XX { XX /* Set default year. */ XX time( &clock ); XX tw.tw_year = localtime( &clock ) -> tm_year; XX } XX return ( &tw ); XX XX%} XX{DAY}","?{w} SETDAY; XX"("{DAY}")"(","?) cp++, SETDAY; XX XX{D}(("-"{D}"-")|("/"{D}"/")){D}?{d}{d}{w} { XX#ifdef EUROPE XX tw.tw_mday = CVT1OR2; cp++; XX tw.tw_mon = CVT1OR2 - 1; cp++; XX#else EUROPE XX tw.tw_mon = CVT1OR2 - 1; cp++; XX tw.tw_mday = CVT1OR2; cp++; XX#endif EUROPE XX for ( i = 0; isdigit( *cp ); ) XX i = i * 10 + (*cp++ - '0'); XX tw.tw_year = i; XX gotdate++; XX } XX{D}("/"|"-"){D}{w} { XX#ifdef EUROPE XX tw.tw_mday = CVT1OR2; cp++; XX tw.tw_mon = CVT1OR2 - 1; XX#else EUROPE XX tw.tw_mon = CVT1OR2 - 1; cp++; XX tw.tw_mday = CVT1OR2; XX#endif EUROPE XX gotdate++; XX } XX{D}(("-"{MONTH}"-")|(" "{MONTH}" ")|({MONTH})){D}?{d}{d}({W}at)?{w} { XX tw.tw_mday = CVT1OR2; XX while ( ! isalpha( *cp++ ) ) XX ; XX SETMONTH; XX for ( i = 0; isdigit( *cp ); ) XX i = i * 10 + (*cp++ - '0'); XX tw.tw_year = i; XX gotdate++; XX } XX{D}"-"?{MONTH}({W}at)?{w} { XX tw.tw_mday = CVT1OR2; XX while ( ! isalpha( *cp++ ) ) XX ; XX SETMONTH; XX gotdate++; XX } XX{MONTH}{W}{D}","{W}{D}?{d}{d}{w} { XX cp++; XX SETMONTH; XX tw.tw_mday = CVT1OR2; XX SKIPD; XX for ( i = 0; isdigit( *cp ); ) XX i = i * 10 + (*cp++ - '0'); XX tw.tw_year = i; XX gotdate++; XX } XX{MONTH}{W}{D}{w} { XX cp++; XX SETMONTH; XX tw.tw_mday = CVT1OR2; XX gotdate++; XX } XX XX{D}:{D}:{D}({w}am)?{w} { XX tw.tw_hour = CVT1OR2; cp++; XX tw.tw_min = CVT1OR2; cp++; XX tw.tw_sec = CVT1OR2; XX BEGIN Z; XX } XX{D}:{D}:{D}{w}pm{w} { XX tw.tw_hour = CVT1OR2 + 12; cp++; XX tw.tw_min = CVT1OR2; cp++; XX tw.tw_sec = CVT1OR2; XX BEGIN Z; XX } XX{D}:{D}({w}am)?{w} { XX tw.tw_hour = CVT1OR2; cp++; XX tw.tw_min = CVT1OR2; XX BEGIN Z; XX } XX{D}:{D}{w}pm{w} { XX tw.tw_hour = CVT1OR2 + 12; cp++; XX tw.tw_min = CVT1OR2; XX BEGIN Z; XX } XX[0-2]{d}{d}{d}{d}{d}{w} { XX tw.tw_hour = CVT1OR2; XX tw.tw_min = CVT1OR2; XX tw.tw_sec = CVT1OR2; XX BEGIN Z; XX } XX[0-2]{d}{d}{d}{w} { XX tw.tw_hour = CVT1OR2; XX tw.tw_min = CVT1OR2; XX BEGIN Z; XX } XX<Z>"-"?ut ZONE(0 * 60); XX<Z>"-"?gmt ZONE(0 * 60); XX<Z>"-"?jst ZONE(2 * 60); XX<Z>"-"?jdt ZONED(2 * 60); XX<Z>"-"?est ZONE(-5 * 60); XX<Z>"-"?edt ZONED(-5 * 60); XX<Z>"-"?cst ZONE(-6 * 60); XX<Z>"-"?cdt ZONED(-6 * 60); XX<Z>"-"?mst ZONE(-7 * 60); XX<Z>"-"?mdt ZONED(-7 * 60); XX<Z>"-"?pst ZONE(-8 * 60); XX<Z>"-"?pdt ZONED(-8 * 60); XX<Z>"-"?nst ZONE(-(3 * 60 + 30)); XX<Z>"-"?ast ZONE(-4 * 60); XX<Z>"-"?adt ZONED(-4 * 60); XX<Z>"-"?yst ZONE(-9 * 60); XX<Z>"-"?ydt ZONED(-9 * 60); XX<Z>"-"?hst ZONE(-10 * 60); XX<Z>"-"?hdt ZONED(-10 * 60); XX<Z>"-"?bst ZONED(-1 * 60); XX<Z>[a-i] tw.tw_zone = 60 * (('a'-1) - LC (*cp)); XX<Z>[k-m] tw.tw_zone = 60 * ('a' - LC (*cp)); XX<Z>[n-y] tw.tw_zone = 60 * (LC (*cp) - 'm'); XX<Z>"+"[0-1]{d}{d}{d} { XX cp++; XX tw.tw_zone = ((cp[0] * 10 + cp[1]) XX -('0' * 10 + '0'))*60 XX +((cp[2] * 10 + cp[3]) XX -('0' * 10 + '0')); XX#ifdef DSTXXX XX zonehack (&tw); XX#endif DSTXXX XX cp += 4; XX } XX<Z>"-"[0-1]{d}{d}{d} { XX cp++; XX tw.tw_zone = (('0' * 10 + '0') XX -(cp[0] * 10 + cp[1]))*60 XX +(('0' * 10 + '0') XX -(cp[2] * 10 + cp[3])); XX#ifdef DSTXXX XX zonehack (&tw); XX#endif DSTXXX XX cp += 4; XX } XX XX<Z>{W}{d}{d}{d}{d} { XX SKIPD; XX tw.tw_year = CVT4; XX } XX\n | XX{W} ; XX%% XX XX#ifdef DSTXXX XXstatic XXzonehack( tw ) XXregister struct tws *tw; XX { XX register struct tm *tm; XX XX if ( twclock( tw ) == -1L ) XX return; XX XX tm = localtime( &tw -> tw_clock ); XX if ( tm -> tm_isdst ) XX { XX tw -> tw_flags |= TW_DST; XX tw -> tw_zone -= 60; XX } XX } XX#endif DSTXXX XX XX XX#ifdef SYS5 XX/* Not all SYS5's have bzero( ). */ XX XXbzero( b, length ) XXchar *b; XXint length; XX { XX while ( length-- > 0 ) XX *b++ = 0; XX } XX#endif SHAR_EOF if test 7327 -ne "`wc -c dtimep.lex`" then echo shar: error transmitting dtimep.lex '(should have been 7327 characters)' fi echo shar: extracting lexedit.sed '(356 characters)' sed 's/^XX//' << \SHAR_EOF > lexedit.sed XX2,/^extern int yylineno;$/c\ XXstatic int start_cond = 0;\ XX#define BEGIN start_cond = XX/^struct yysvf \*yyestate;$/,/^extern struct yysvf yysvec/d XX/^# define YYNEWLINE /,/^int nstr;/d XX/^while((nstr = yylook()/,/^if(yywrap()) /d XX/^case -1:$/,/^fprintf(yyout,"bad switch yylook /c\ XX default: return(0); XX/^struct yysvf *yybgin = yysvec+1;$/d XX/^int yylineno /,$d SHAR_EOF if test 356 -ne "`wc -c lexedit.sed`" then echo shar: error transmitting lexedit.sed '(should have been 356 characters)' fi echo shar: extracting lexstring.c '(3765 characters)' sed 's/^XX//' << \SHAR_EOF > lexstring.c XX#include <stdio.h> XX#include <ctype.h> XX XX#define YYLERR yysvec XX#define YYTYPE int XX#define YYLMAX 256 XX XXstruct yysvf { XX struct yywork *yystoff; XX struct yysvf *yyother; XX int *yystops; XX}; XX XXstruct yywork { XX YYTYPE verify; XX YYTYPE advance; XX}; XX XXextern int yyvstop[]; XXextern struct yywork yycrank[]; XXextern struct yysvf yysvec[]; XXextern struct yywork *yytop; XXextern char yymatch[]; XXextern char yyextra[]; XX XX#ifdef LEXDEBUG XXstatic int debug = 0; XX#endif LEXDEBUG XX XXlex_string( strptr, start_cond) XX char **strptr; XX int start_cond; XX{ XX register struct yysvf *state, **lsp; XX register struct yywork *tran; XX register int ch; XX register char *cp = *strptr; XX register int *found; XX struct yysvf *yylstate[YYLMAX]; XX XX /* start off machines */ XX lsp = yylstate; XX state = yysvec+1+start_cond; XX for (;;){ XX# ifdef LEXDEBUG XX if(debug) XX fprintf(stderr,"state %d\n",state-yysvec-1); XX# endif XX tran = state->yystoff; XX if(tran == yycrank) XX /* may not be any transitions */ XX if (state->yyother == 0 || XX state->yyother->yystoff == yycrank) XX break; XX XX ch = *cp++; XX#ifdef ONECASE XX if (isupper(ch) ) XX ch = tolower(ch); XX#endif ONECASE XXtryagain: XX# ifdef LEXDEBUG XX if(debug){ XX fprintf(stderr,"char "); XX allprint(ch); XX putchar('\n'); XX } XX# endif XX if ( tran > yycrank){ XX tran += ch; XX if (tran <= yytop && tran->verify+yysvec == state){ XX if ((state = tran->advance+yysvec) == YYLERR){ XX /* error transitions */ XX --cp; XX break; XX } XX *lsp++ = state; XX goto contin; XX } XX XX } else if(tran < yycrank) { XX /* r < yycrank */ XX tran = yycrank+(yycrank-tran) + ch; XX# ifdef LEXDEBUG XX if (debug) XX fprintf(stderr,"compressed state\n"); XX# endif XX if(tran <= yytop && tran->verify+yysvec == state){ XX if ((state = tran->advance+yysvec) == YYLERR) XX /* error transitions */ XX break; XX XX *lsp++ = state; XX goto contin; XX } XX tran += (yymatch[ch] - ch); XX# ifdef LEXDEBUG XX if(debug){ XX fprintf(stderr,"try fall back character "); XX allprint(yymatch[ch]); XX putchar('\n'); XX } XX# endif XX if(tran <= yytop && tran->verify+yysvec == state){ XX if(tran->advance+yysvec == YYLERR) XX /* error transition */ XX break; XX XX *lsp++ = state = tran->advance+yysvec; XX goto contin; XX } XX } XX if ((state = state->yyother) && XX (tran = state->yystoff) != yycrank){ XX# ifdef LEXDEBUG XX if(debug) XX fprintf(stderr,"fall back to state %d\n", XX state-yysvec-1); XX# endif XX goto tryagain; XX } else XX break; XX XXcontin: XX# ifdef LEXDEBUG XX if(debug){ XX fprintf(stderr,"state %d char ",state-yysvec-1); XX allprint(ch); XX putchar('\n'); XX } XX# endif XX ; XX } XX# ifdef LEXDEBUG XX if(debug){ XX fprintf(stderr,"stopped at %d with ",*(lsp-1)-yysvec-1); XX allprint(ch); XX putchar('\n'); XX } XX# endif XX while (lsp-- > yylstate){ XX if (*lsp != 0 && (found= (*lsp)->yystops) && *found > 0){ XX if(yyextra[*found]){ XX /* must backup */ XX ch = -*found; XX do { XX while (*found && *found++ != ch) XX ; XX } while (lsp > yylstate && XX (found = (*--lsp)->yystops)); XX } XX# ifdef LEXDEBUG XX if(debug){ XX fprintf(stderr,"\nmatch "); XX for ( cp = *strptr; XX cp <= ((*strptr)+(lsp-yylstate)); XX cp++) XX allprint( *cp ); XX fprintf(stderr," action %d\n",*found); XX } XX# endif XX *strptr += (lsp - yylstate + 1); XX return(*found); XX } XX } XX /* the string didn't match anything - if we're looking at XX * eos, just return 0. Otherwise, bump the string pointer XX * and return -1. XX */ XX# ifdef LEXDEBUG XX if(debug) XX fprintf(stderr,"\nno match\n"); XX#endif LEXDEBUG XX if ( **strptr ) { XX (*strptr)++; XX return (-1); XX } XX return (0); XX} XX XX#ifdef LEXDEBUG XXallprint(c) XX char c; XX{ XX if ( c < 32 ) { XX putc( '^', stderr ); XX c += 32; XX } else if ( c == 127 ) { XX putc( '^', stderr ); XX c = '?'; XX } XX putc( c, stderr ); XX} XX#endif LEXDEBUG SHAR_EOF if test 3765 -ne "`wc -c lexstring.c`" then echo shar: error transmitting lexstring.c '(should have been 3765 characters)' fi echo shar: extracting libtws.3 '(2241 characters)' sed 's/^XX//' << \SHAR_EOF > libtws.3 XX.TH libtws 3 "08 November 1986" XX.SH NAME XXlibtws \- alternate date and time routines including parsing XX.SH SYNOPSIS XX.nf XX.fc ^ ~ XX.ta \w'char *dtimezone( offset, flags ); 'u XXinclude "tws.h" XX.PP XX^struct tws *dlocaltime( clock );~^/* local clock into tws */ XXlong *clock; XX.PP XX^struct tws *gmtime( clock );~^/* GMT clock into tws */ XXlong *clock; XX.PP XX^char *dtime( clock );~^/* clock into string */ XXlong *clock; XX.PP XX^long twclock( t );~^/* tws into clock */ XXstruct tws *t; XX.PP XX^long twjuliandate( t );~^/* tws into Julian day number */ XXstruct tws *t; XX.PP XX^struct tws *dparsetime( str );~^/* string into tws */ XXchar *str; XX.PP XX^char *dctime( t );~^/* tws into string */ XXstruct tws *t; XX.PP XX^char *dasctime( t, flags );~^/* tws into string */ XXstruct tws *t; XXint flags; XX.PP XX^char *dtimezone( offset, flags );~^/* timezone into string */ XXint offset, flags; XX.PP XX^char *dtwszone( t );~^/* tws's timezone into string */ XXstruct tws *t; XX.PP XX^char *dtimemow( );~^/* current time into string */ XX.PP XX^struct tws *dtwstime( );~^/* current time into tws */ XX.PP XX^void twscopy( tot, fromt );~^/* copy a tws */ XXstruct tws *tot, *fromt; XX.PP XX^int twsort( t1, t2 );~^/* compare two tws's */ XXstruct tws *t1, *t2; XX.PP XX^long twsubtract( t1, t2 );~^/* seconds between t2 and t1 */ XXstruct tws *t1, *t2; XX.fi XX.SH DESCRIPTION XX.I Libtws XXis a fairly complete date/time library. XXUnlike the standard Unix* date/time routines, XX.I libtws XXwill parse date/time strings into internal form. XXThe format for specifying date/time strings is pretty loose - basically XXthe same as the format for date/times in network mail. XX.PP XXMost of the routines do not use the Unix* "clock" time XXformat, and therefore are not limited to dates after 01 January 1970. XXIn particular, twsubtract() lets you subtract two dates without XXconverting them to "clock" form. XX.SH "SEE\ ALSO" XX.IR ctime(3), XX.IR time(3) XX.SH AUTHOR XXMost of XX.I libtws XXcame from version 6.5 of the MH message XXhandling system, courtesy of Marshall Rose. XXSome improvements (?) were added by Jef Poskanzer. XX.SH BUGS XXThe return values point to static data whose contents are overwritten XXby the next call. XX.PP XXThe basic Unix* time format (clock) only goes back to 1970, limiting XXapplications somewhat. XX.SH NOTE XX* Unix is a virus from outer space. SHAR_EOF if test 2241 -ne "`wc -c libtws.3`" then echo shar: error transmitting libtws.3 '(should have been 2241 characters)' fi echo shar: extracting tws.h '(2999 characters)' sed 's/^XX//' << \SHAR_EOF > tws.h XX/* tws.h - header file for libtws date/time library XX (from mod.sources, Volume 8, Issue 81.) XX XX{Second distribution of phoon, deltime, and libtws - 24feb87. XX Jef Poskanzer, UniSoft Systems, Berkeley XX unisoft!jef@ucbvax.Berkeley.Edu XX ...ucbvax!unisoft!jef XX (415)644-1230 } XX XXThis library is used to allow date stamping of files in Unix. The XXstandard time routines in Unix do not provide routines to convert a XXparsed time into a time(3) clock value, so.... If you don't have this XXcode, and can't get it, take out the references to it in arcdos.c, XXand remove the reference to tws.h and libtws.a in the Makefile. XX XX -- Howard Chu, March 3, 1987 XX University of Michigan Computing Center XX hyc@umix.cc.umich.edu XX ...ihnp4!umich!umix!hyc */ XX XX XX/* Definition of the tws data structure. */ XX XXstruct tws { XX int tw_sec; XX int tw_min; XX int tw_hour; XX XX int tw_mday; XX int tw_mon; XX int tw_year; XX XX int tw_wday; XX int tw_yday; XX XX int tw_zone; XX XX long tw_clock; XX XX int tw_flags; XX#define TW_NULL 0x0000 XX#define TW_SDAY 0x0007 /* how day-of-week was determined */ XX#define TW_SNIL 0x0000 /* not given */ XX#define TW_SEXP 0x0001 /* explicitly given */ XX#define TW_SIMP 0x0002 /* implicitly given */ XX#define TW_DST 0x0010 /* daylight savings time */ XX#define TW_ZONE 0x0020 /* use numeric timezones only */ XX#define TW_JUNK 0x0040 /* date string contained junk */ XX}; XX XX XX/* Declarations of routines. */ XX XXvoid twscopy( ); XX /* twscopy( &totws, &fromtws ) copies a tws */ XXint twsort( ); XX /* twsort( &tws1, &tws2 ) compares two tws's: 1 means tws1 is XX later; -1 means tws1 is earlier; 0 means they are equal */ XXlong twclock( ); XX /* twclock( &tws ) turns a tws into a time(3)-style clock value */ XXlong twjuliandate( ); XX /* twjuliandate( &tws ) returns the Julian day number of a tws */ XXlong twsubtract( ); XX /* twsubtract( &tws1, &tws2 ) returns seconds of difference */ XX XX/* These routines are functionally similar to the ctime(3) routines XX in the standard Unix library. */ XXchar *dctime( ); XX /* dctime( &tws ) returns a string for the date/time passed in */ XXstruct tws *dlocaltime( ); XX /* dlocaltime( &clock ) turns a time(3) clock value into a tws */ XXstruct tws *dgmtime( ); XX /* dgmtime( &clock ) turns a time(3) clock value into a tws */ XXchar *dasctime( ); XX /* dasctime( &tws, flags ) turns a tws into a string */ XXchar *dtimezone( ); XX /* dtimezone( offset, flags ) returns the name of the time zone */ XX XXchar *dtimenow( ); XX /* dtimenow( ) returns a string for the current date/time */ XX XXstruct tws *dparsetime( ); XX /* dparsetime( &str ) turns a string into a tws */ XX XXstruct tws *dtwstime( ); XX /* dtwstime( ) returns a tws for the current date/time */ XX XX#ifdef ATZ XX#define dtime(cl) dasctime( dlocaltime( cl ), TW_NULL ) XX#else ATZ XX#define dtime(cl) dasctime( dlocaltime( cl ), TW_ZONE ) XX#endif ATZ XX XX#define dtwszone(tw) dtimezone( tw -> tw_zone, tw -> tw_flags ) XX XX XXextern char *tw_dotw[], *tw_ldotw[], *tw_moty[]; SHAR_EOF if test 2999 -ne "`wc -c tws.h`" then echo shar: error transmitting tws.h '(should have been 2999 characters)' fi # End of shell archive exit 0