# line 2 "getdate.y" /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" /* $OrigRevision: 2.1 $ ** ** Originally written by Steven M. Bellovin while ** at the University of North Carolina at Chapel Hill. Later tweaked by ** a couple of people on Usenet. Completely overhauled by Rich $alz ** and Jim Berets in August, 1990; ** send any email to Rich. ** ** This grammar has eight shift/reduce conflicts. ** ** This code is in the public domain and has no copyright. */ /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */ /* SUPPRESS 288 on yyerrlab *//* Label unused */ #include #include #include #define NEED_TZSET struct timeb { time_t time; /* Seconds since the epoch */ unsigned short millitm; /* Field not used */ short timezone; short dstflag; /* Field not used */ }; #include #include #include #include #include #include #if !defined(lint) && !defined(SABER) static char RCS[] = "$Header: /home/laramie/berliner/ws/backup/usr/src/cmd/backup/lib/getdate.y,v 1.5 1992/06/09 21:46:21 sam Exp $"; #endif /* !defined(lint) && !defined(SABER) */ #define EPOCH 1970 #define HOURN(x) (x * 60) #define SECSPERDAY (24L * 60L * 60L) #define CHECK_TM(y) (((y) % 100) < 70 ? (y) + 2000 : (y) + 1900) /* ** An entry in the lexical lookup table. */ typedef struct _TABLE { char *name; int type; time_t value; } TABLE; /* ** Daylight-savings mode: on, off, or not yet known. */ typedef enum _DSTMODE { DSTon, DSToff, DSTmaybe } DSTMODE; /* ** Meridian: am, pm, or 24-hour style. */ typedef enum _MERIDIAN { MERam, MERpm, MER24 } MERIDIAN; /* ** Global variables. We could get rid of most of these by using a good ** union as the yacc stack. (This routine was originally written before ** yacc had the %union construct.) Maybe someday; right now we only use ** the %union very rarely. */ static char *yyInput; static DSTMODE yyDSTmode; static time_t yyDayOrdinal; static time_t yyDayNumber; static int yyHaveDate; static int yyHaveDay; static int yyHaveRel; static int yyHaveTime; static int yyHaveZone; static time_t yyTimezone; static time_t yyDay; static time_t yyHour; static time_t yyMinutes; static time_t yyMonth; static time_t yySeconds; static time_t yyYear; static MERIDIAN yyMeridian; static time_t yyRelMonth; static time_t yyRelSeconds; static char *domainname = "hsm_libdump"; /* for dgettext() */ #define yylex 1 /* suppress yacc's definition */ # line 109 "getdate.y" typedef union #ifdef __cplusplus YYSTYPE #endif { time_t Number; enum _MERIDIAN Meridian; } YYSTYPE; # define tAGO 257 # define tDAY 258 # define tDAYZONE 259 # define tID 260 # define tMERIDIAN 261 # define tMINUTE_UNIT 262 # define tMONTH 263 # define tMONTH_UNIT 264 # define tSEC_UNIT 265 # define tSNUMBER 266 # define tUNUMBER 267 # define tZONE 268 #include #ifdef __STDC__ #include #include #define YYCONST const #else #include #include #define YYCONST #endif #include #if defined(__cplusplus) || defined(__STDC__) #if defined(__cplusplus) && defined(__EXTERN_C__) extern "C" { #endif #ifndef yyerror #if defined(__cplusplus) void yyerror(YYCONST char *); #endif #endif #ifndef yylex int yylex(void); #endif int yyparse(void); #if defined(__cplusplus) && defined(__EXTERN_C__) } #endif #endif #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; extern int yyerrflag; YYSTYPE yylval; YYSTYPE yyval; typedef int yytabelem; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif #if YYMAXDEPTH > 0 int yy_yys[YYMAXDEPTH], *yys = yy_yys; YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv; #else /* user does initial allocation */ int *yys; YYSTYPE *yyv; #endif static int yymaxdepth = YYMAXDEPTH; # define YYERRCODE 256 # line 296 "getdate.y" /* Month and day table. */ static TABLE MonthDayTable[] = { { "january", tMONTH, 1 }, { "february", tMONTH, 2 }, { "march", tMONTH, 3 }, { "april", tMONTH, 4 }, { "may", tMONTH, 5 }, { "june", tMONTH, 6 }, { "july", tMONTH, 7 }, { "august", tMONTH, 8 }, { "september", tMONTH, 9 }, { "sept", tMONTH, 9 }, { "october", tMONTH, 10 }, { "november", tMONTH, 11 }, { "december", tMONTH, 12 }, { "sunday", tDAY, 0 }, { "monday", tDAY, 1 }, { "tuesday", tDAY, 2 }, { "tues", tDAY, 2 }, { "wednesday", tDAY, 3 }, { "wednes", tDAY, 3 }, { "thursday", tDAY, 4 }, { "thur", tDAY, 4 }, { "thurs", tDAY, 4 }, { "friday", tDAY, 5 }, { "saturday", tDAY, 6 }, { NULL } }; /* Time units table. */ static TABLE UnitsTable[] = { { "year", tMONTH_UNIT, 12 }, { "month", tMONTH_UNIT, 1 }, { "fortnight", tMINUTE_UNIT, 14 * 24 * 60 }, { "week", tMINUTE_UNIT, 7 * 24 * 60 }, { "day", tMINUTE_UNIT, 1 * 24 * 60 }, { "hour", tMINUTE_UNIT, 60 }, { "minute", tMINUTE_UNIT, 1 }, { "min", tMINUTE_UNIT, 1 }, { "second", tSEC_UNIT, 1 }, { "sec", tSEC_UNIT, 1 }, { NULL } }; /* Assorted relative-time words. */ static TABLE OtherTable[] = { { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 }, { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 }, { "today", tMINUTE_UNIT, 0 }, { "now", tMINUTE_UNIT, 0 }, { "last", tUNUMBER, -1 }, { "this", tMINUTE_UNIT, 0 }, { "next", tUNUMBER, 2 }, { "first", tUNUMBER, 1 }, /* { "second", tUNUMBER, 2 }, */ { "third", tUNUMBER, 3 }, { "fourth", tUNUMBER, 4 }, { "fifth", tUNUMBER, 5 }, { "sixth", tUNUMBER, 6 }, { "seventh", tUNUMBER, 7 }, { "eighth", tUNUMBER, 8 }, { "ninth", tUNUMBER, 9 }, { "tenth", tUNUMBER, 10 }, { "eleventh", tUNUMBER, 11 }, { "twelfth", tUNUMBER, 12 }, { "ago", tAGO, 1 }, { NULL } }; /* The timezone table. */ static TABLE TimezoneTable[] = { { "gmt", tZONE, HOURN( 0) }, /* Greenwich Mean */ { "ut", tZONE, HOURN( 0) }, /* Universal (Coordinated) */ { "utc", tZONE, HOURN( 0) }, { "wet", tZONE, HOURN( 0) }, /* Western European */ { "bst", tDAYZONE, HOURN( 0) }, /* British Summer */ { "wat", tZONE, HOURN( 1) }, /* West Africa */ { "at", tZONE, HOURN( 2) }, /* Azores */ #if 0 /* For completeness. BST is also British Summer, and GST is * also Guam Standard. */ { "bst", tZONE, HOURN( 3) }, /* Brazil Standard */ { "gst", tZONE, HOURN( 3) }, /* Greenland Standard */ #endif { "nft", tZONE, HOURN(3.5) }, /* Newfoundland */ { "nst", tZONE, HOURN(3.5) }, /* Newfoundland Standard */ { "ndt", tDAYZONE, HOURN(3.5) }, /* Newfoundland Daylight */ { "ast", tZONE, HOURN( 4) }, /* Atlantic Standard */ { "adt", tDAYZONE, HOURN( 4) }, /* Atlantic Daylight */ { "est", tZONE, HOURN( 5) }, /* Eastern Standard */ { "edt", tDAYZONE, HOURN( 5) }, /* Eastern Daylight */ { "cst", tZONE, HOURN( 6) }, /* Central Standard */ { "cdt", tDAYZONE, HOURN( 6) }, /* Central Daylight */ { "mst", tZONE, HOURN( 7) }, /* Mountain Standard */ { "mdt", tDAYZONE, HOURN( 7) }, /* Mountain Daylight */ { "pst", tZONE, HOURN( 8) }, /* Pacific Standard */ { "pdt", tDAYZONE, HOURN( 8) }, /* Pacific Daylight */ { "yst", tZONE, HOURN( 9) }, /* Yukon Standard */ { "ydt", tDAYZONE, HOURN( 9) }, /* Yukon Daylight */ { "hst", tZONE, HOURN(10) }, /* Hawaii Standard */ { "hdt", tDAYZONE, HOURN(10) }, /* Hawaii Daylight */ { "cat", tZONE, HOURN(10) }, /* Central Alaska */ { "ahst", tZONE, HOURN(10) }, /* Alaska-Hawaii Standard */ { "nt", tZONE, HOURN(11) }, /* Nome */ { "idlw", tZONE, HOURN(12) }, /* International Date Line West */ { "cet", tZONE, -HOURN(1) }, /* Central European */ { "met", tZONE, -HOURN(1) }, /* Middle European */ { "mewt", tZONE, -HOURN(1) }, /* Middle European Winter */ { "mest", tDAYZONE, -HOURN(1) }, /* Middle European Summer */ { "swt", tZONE, -HOURN(1) }, /* Swedish Winter */ { "sst", tDAYZONE, -HOURN(1) }, /* Swedish Summer */ { "fwt", tZONE, -HOURN(1) }, /* French Winter */ { "fst", tDAYZONE, -HOURN(1) }, /* French Summer */ { "eet", tZONE, -HOURN(2) }, /* Eastern Europe, USSR Zone 1 */ { "bt", tZONE, -HOURN(3) }, /* Baghdad, USSR Zone 2 */ { "it", tZONE, -HOURN(3.5) },/* Iran */ { "zp4", tZONE, -HOURN(4) }, /* USSR Zone 3 */ { "zp5", tZONE, -HOURN(5) }, /* USSR Zone 4 */ { "ist", tZONE, -HOURN(5.5) },/* Indian Standard */ { "zp6", tZONE, -HOURN(6) }, /* USSR Zone 5 */ #if 0 /* For completeness. NST is also Newfoundland Stanard, nad SST is * also Swedish Summer. */ { "nst", tZONE, -HOURN(6.5) },/* North Sumatra */ { "sst", tZONE, -HOURN(7) }, /* South Sumatra, USSR Zone 6 */ #endif /* 0 */ { "wast", tZONE, -HOURN(7) }, /* West Australian Standard */ { "wadt", tDAYZONE, -HOURN(7) }, /* West Australian Daylight */ { "jt", tZONE, -HOURN(7.5) },/* Java (3pm in Cronusland!) */ { "cct", tZONE, -HOURN(8) }, /* China Coast, USSR Zone 7 */ { "jst", tZONE, -HOURN(9) }, /* Japan Standard, USSR Zone 8 */ { "cast", tZONE, -HOURN(9.5) },/* Central Australian Standard */ { "cadt", tDAYZONE, -HOURN(9.5) },/* Central Australian Daylight */ { "east", tZONE, -HOURN(10) }, /* Eastern Australian Standard */ { "eadt", tDAYZONE, -HOURN(10) }, /* Eastern Australian Daylight */ { "gst", tZONE, -HOURN(10) }, /* Guam Standard, USSR Zone 9 */ { "nzt", tZONE, -HOURN(12) }, /* New Zealand */ { "nzst", tZONE, -HOURN(12) }, /* New Zealand Standard */ { "nzdt", tDAYZONE, -HOURN(12) }, /* New Zealand Daylight */ { "idle", tZONE, -HOURN(12) }, /* International Date Line East */ { NULL } }; /* Military timezone table. */ static TABLE MilitaryTable[] = { { "a", tZONE, HOURN( 1) }, { "b", tZONE, HOURN( 2) }, { "c", tZONE, HOURN( 3) }, { "d", tZONE, HOURN( 4) }, { "e", tZONE, HOURN( 5) }, { "f", tZONE, HOURN( 6) }, { "g", tZONE, HOURN( 7) }, { "h", tZONE, HOURN( 8) }, { "i", tZONE, HOURN( 9) }, { "k", tZONE, HOURN( 10) }, { "l", tZONE, HOURN( 11) }, { "m", tZONE, HOURN( 12) }, { "n", tZONE, HOURN(- 1) }, { "o", tZONE, HOURN(- 2) }, { "p", tZONE, HOURN(- 3) }, { "q", tZONE, HOURN(- 4) }, { "r", tZONE, HOURN(- 5) }, { "s", tZONE, HOURN(- 6) }, { "t", tZONE, HOURN(- 7) }, { "u", tZONE, HOURN(- 8) }, { "v", tZONE, HOURN(- 9) }, { "w", tZONE, HOURN(-10) }, { "x", tZONE, HOURN(-11) }, { "y", tZONE, HOURN(-12) }, { "z", tZONE, HOURN( 0) }, { NULL } }; /* ARGSUSED */ static void yyerror(s) char *s; { } static time_t ToSeconds(Hours, Minutes, Seconds, Meridian) time_t Hours; time_t Minutes; time_t Seconds; MERIDIAN Meridian; { if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) return -1; switch (Meridian) { case MER24: if (Hours < 0 || Hours > 23) return -1; return (Hours * 60L + Minutes) * 60L + Seconds; case MERam: if (Hours < 1 || Hours > 12) return -1; if (Hours != 12) return (Hours * 60L + Minutes) * 60L + Seconds; else return Minutes * 60L + Seconds; case MERpm: if (Hours < 1 || Hours > 12) return -1; if (Hours != 12) return ((Hours + 12) * 60L + Minutes) * 60L + Seconds; else return (720L + Minutes) * 60L + Seconds; } /* NOTREACHED */ return (-1); } static time_t Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) time_t Month; time_t Day; time_t Year; time_t Hours; time_t Minutes; time_t Seconds; MERIDIAN Meridian; DSTMODE DSTmode; { static int DaysInMonth[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; time_t tod; time_t Julian; time_t i; if (Year < 0) Year = -Year; if (Year < 138) Year += 1900; DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 29 : 28; if (Year < EPOCH || Year > 2037 || Month < 1 || Month > 12 /* LINTED Month is a time_t so intermediate results aren't truncated */ || Day < 1 || Day > DaysInMonth[(int)--Month]) return -1; for (Julian = Day - 1, i = 0; i < Month; i++) Julian += DaysInMonth[i]; for (i = EPOCH; i < Year; i++) Julian += 365 + (i % 4 == 0); Julian *= SECSPERDAY; Julian += yyTimezone * 60L; if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) return -1; Julian += tod; if (DSTmode == DSTon || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) Julian -= 60 * 60; return Julian; } static time_t DSTcorrect(Start, Future) time_t Start; time_t Future; { time_t StartDay; time_t FutureDay; StartDay = (localtime(&Start)->tm_hour + 1) % 24; FutureDay = (localtime(&Future)->tm_hour + 1) % 24; return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; } static time_t RelativeDate(Start, DayOrdinal, DayNumber) time_t Start; time_t DayOrdinal; time_t DayNumber; { struct tm *tm; time_t now; now = Start; tm = localtime(&now); now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); return DSTcorrect(Start, now); } static time_t RelativeMonth(Start, RelMonth) time_t Start; time_t RelMonth; { struct tm *tm; time_t Month; time_t Year; if (RelMonth == 0) return 0; tm = localtime(&Start); Month = 12 * tm->tm_year + tm->tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; return DSTcorrect(Start, Convert(Month, (time_t)tm->tm_mday, Year, (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, MER24, DSTmaybe)); } static int LookupWord(buff) char *buff; { char *p; char *q; TABLE *tp; uint_t i; int abbrev; /* Make it lowercase. */ for (p = buff; *p; p++) if (isupper((u_char)*p)) *p = tolower(*p); if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) { yylval.Meridian = MERam; return tMERIDIAN; } if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { yylval.Meridian = MERpm; return tMERIDIAN; } /* See if we have an abbreviation for a month. */ if (strlen(buff) == 3) abbrev = 1; else if (strlen(buff) == 4 && buff[3] == '.') { abbrev = 1; buff[3] = '\0'; } else abbrev = 0; for (tp = MonthDayTable; tp->name; tp++) { if (abbrev) { if (strncmp(buff, tp->name, 3) == 0) { yylval.Number = tp->value; return tp->type; } } else if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } } for (tp = TimezoneTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } for (tp = UnitsTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } /* Strip off any plural and try the units table again. */ i = strlen(buff) - 1; if (buff[i] == 's') { buff[i] = '\0'; for (tp = UnitsTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } } for (tp = OtherTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } /* Military timezones. */ if (buff[1] == '\0' && isalpha((u_char)*buff)) { for (tp = MilitaryTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } } /* Drop out any periods and try the timezone table again. */ for (i = 0, p = q = buff; *q; q++) if (*q != '.') *p++ = *q; else i++; *p = '\0'; if (i) for (tp = TimezoneTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return tp->type; } return tID; } void pdateerr(p) char *p; { char *name = "DATEMSK"; /* env variable for date format */ char *value; char fmt[256], line[256]; FILE *fp; time_t now; struct tm *tm; value = getenv(name); if (value == (char *)0) { fprintf(stderr, dgettext(domainname, "%s: Environment variable %s not set\n"), p, name); return; } switch (getdate_err) { case 0: default: fprintf(stderr, dgettext(domainname, "%s: Unkown getdate() error\n"), p); break; case 1: fprintf(stderr, dgettext(domainname, "%s: %s null or undefined\n"), p, name); break; case 2: fprintf(stderr, dgettext(domainname, "%s: Cannot read template file %s\n"), p, value); break; case 3: fprintf(stderr, dgettext(domainname, "%s: Failed to get file status information\n"), p); break; case 4: fprintf(stderr, dgettext(domainname, "%s: Template file %s not a regular file\n"), p, value); break; case 5: fprintf(stderr, dgettext(domainname, "%s: Error reading template file %s\n"), p, value); break; case 6: fprintf(stderr, dgettext(domainname, "%s: %s failed\n"), p, "malloc()"); break; case 7: fprintf(stderr, dgettext(domainname, "%s: Bad date/time format\n"), p); fp = fopen(value, "r"); if (fp == (FILE *)0) break; now = time((time_t *)0); tm = localtime(&now); fprintf(stderr, dgettext(domainname, "The following are examples of valid formats:\n")); while (fgets(fmt, sizeof (fmt), fp)) { if (strchr(fmt, '%') == (char *)0) continue; fprintf(stderr, " "); (void) strftime(line, sizeof (line), fmt, tm); fprintf(stderr, "%s", line); } (void) fclose(fp); break; case 8: (void) fprintf(stderr, dgettext(domainname, "%s: Invalid date specification\n"), p); break; } } #undef yylex static int yylex() { char c; char *p; char buff[20]; int Count; int sign; for ( ; ; ) { while (isspace((u_char)*yyInput)) yyInput++; if (isdigit((u_char)(c = *yyInput)) || c == '-' || c == '+') { if (c == '-' || c == '+') { sign = c == '-' ? -1 : 1; if (!isdigit((u_char)*++yyInput)) /* skip the '-' sign */ continue; } else sign = 0; yylval.Number = 0; while (isdigit((u_char)(c = *yyInput++))) { int n; char digit = c; (void) sscanf(&digit, "%1d", &n); yylval.Number = 10 * yylval.Number + n; } yyInput--; if (sign < 0) yylval.Number = -yylval.Number; return sign ? tSNUMBER : tUNUMBER; } if (isalpha((u_char)c)) { for (p = buff; isalpha((u_char)(c = *yyInput++)) || c == '.'; ) if (p < &buff[sizeof (buff) - 1]) *p++ = c; *p = '\0'; yyInput--; return LookupWord(buff); } if (c != '(') return *yyInput++; Count = 0; do { c = *yyInput++; if (c == '\0') return c; if (c == '(') Count++; else if (c == ')') Count--; } while (Count > 0); } } time_t getreldate(p, now) char *p; struct timeb *now; { struct tm *tm; struct timeb ftz; time_t Start; time_t tod; if (strcmp(setlocale(LC_TIME, NULL), "C")) { static char localedate[24]; struct tm ltm; tm = getdate(p); if (getdate_err == 1 /* NODATEMASK */) { char buffy[BUFSIZ]; time_t current; printf(gettext("environment variable %s not set\n"), "DATEMSK"); do { time(¤t); tm = localtime(¤t); memcpy(<m, tm, sizeof(ltm)); tm = <m; (void) fputs(gettext("Enter date as mmddhhmm[yy]: "), stdout); (void) fflush(stdout); if (fgets(buffy, sizeof (buffy), stdin) == NULL) { (void) printf(gettext("Encountered EOF on stdin\n")); return(-1); } } while (sscanf(buffy, "%2d%2d%2d%2d%2d", &(tm->tm_mon), &(tm->tm_mday), &(tm->tm_hour), &(tm->tm_min), &(tm->tm_year)) < 4); (tm->tm_mon)--; } else if (tm == NULL) return(-1); (void)sprintf(localedate, "%d:%2.2d %d/%d %d", tm->tm_hour, tm->tm_min, tm->tm_mon + 1, tm->tm_mday, CHECK_TM(tm->tm_year)); p = localedate; } yyInput = p; if (now == NULL) { now = &ftz; (void) time(&ftz.time); /* Set the timezone global. */ tzset(); /* LINTED timezone is time_t so intermediate results aren't truncated */ ftz.timezone = (int) timezone / 60; } tm = localtime(&now->time); yyYear = tm->tm_year; yyMonth = tm->tm_mon + 1; yyDay = tm->tm_mday; yyTimezone = now->timezone; yyDSTmode = DSTmaybe; yyHour = tm->tm_hour; yyMinutes = tm->tm_min; yySeconds = tm->tm_sec; yyMeridian = MER24; yyRelSeconds = 0; yyRelMonth = 0; yyHaveDate = 0; yyHaveDay = 0; yyHaveRel = 0; yyHaveTime = 0; yyHaveZone = 0; if (yyparse() || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1) return -1; if (yyHaveDate || yyHaveTime || yyHaveDay) { Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, yyMeridian, yyDSTmode); if (Start < 0) return -1; } else { Start = now->time; if (!yyHaveRel) Start -= ((tm->tm_hour * 60L) + tm->tm_min * 60L) + tm->tm_sec; } Start += yyRelSeconds; Start += RelativeMonth(Start, yyRelMonth); if (yyHaveDay && !yyHaveDate) { tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber); Start += tod; } /* Have to do *something* with a legitimate -1 so it's distinguishable * from the error return value. (Alternately could set errno on error.) */ return Start == -1 ? 0 : Start; } #if defined(TEST) /* ARGSUSED */ main(ac, av) int ac; char *av[]; { char buff[128]; time_t d; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); (void) printf(gettext("Enter date, or blank line to exit.\n\t> ")); (void) fflush(stdout); while (gets(buff) && buff[0]) { d = getreldate(buff, (struct timeb *)NULL); if (d == -1) (void) printf(gettext("Bad format - couldn't convert.\n")); else { (void) cftime(buff, "%c\n", &d); (void) printf("%s", buff); } (void) printf("\t> "); (void) fflush(stdout); } exit(0); /* NOTREACHED */ } #endif /* defined(TEST) */ static YYCONST yytabelem yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 39 # define YYLAST 221 static YYCONST yytabelem yyact[]={ 13, 11, 22, 39, 16, 12, 18, 17, 15, 9, 10, 40, 44, 20, 43, 42, 46, 29, 35, 34, 33, 30, 27, 32, 31, 41, 36, 28, 37, 14, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0, 38, 0, 21, 0, 0, 19, 24, 23, 26, 25 }; static YYCONST yytabelem yypact[]={ -10000000, -258,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000, -45, -10000000,-10000000, -245, -17, -240, -241,-10000000,-10000000,-10000000,-10000000, -247,-10000000, -248, -249,-10000000,-10000000,-10000000, -18,-10000000,-10000000, -10000000,-10000000,-10000000, -55, -22,-10000000, -252,-10000000,-10000000, -253, -10000000, -255,-10000000, -250,-10000000,-10000000,-10000000 }; static YYCONST yytabelem yypgo[]={ 0, 28, 37, 36, 35, 34, 33, 32, 31, 30, 29 }; static YYCONST yytabelem yyr1[]={ 0, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 7, 7, 7, 6, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 1, 1 }; static YYCONST yytabelem yyr2[]={ 0, 0, 4, 3, 3, 3, 3, 3, 2, 5, 9, 9, 13, 13, 3, 3, 3, 5, 5, 7, 11, 5, 9, 5, 7, 5, 2, 5, 5, 3, 5, 5, 3, 5, 5, 3, 3, 1, 3 }; static YYCONST yytabelem yychk[]={ -10000000, -2, -3, -4, -5, -6, -7, -8, -9, 267, 268, 259, 263, 258, -10, 266, 262, 265, 264, 261, 58, 258, 47, 263, 262, 265, 264, 267, 44, 257, 262, 265, 264, 267, 267, 267, 44, -1, 266, 58, 261, 47, 267, 267, 267, -1, 266 }; static YYCONST yytabelem yydef[]={ 1, -2, 2, 3, 4, 5, 6, 7, 8, 36, 14, 15, 0, 16, 26, 0, 29, 32, 35, 9, 0, 18, 0, 23, 27, 31, 34, 21, 17, 25, 28, 30, 33, 37, 19, 24, 0, 10, 11, 0, 38, 0, 22, 37, 20, 12, 13 }; typedef struct #ifdef __cplusplus yytoktype #endif { #ifdef __cplusplus const #endif char *t_name; int t_val; } yytoktype; #ifndef YYDEBUG # define YYDEBUG 0 /* don't allow debugging */ #endif #if YYDEBUG yytoktype yytoks[] = { "tAGO", 257, "tDAY", 258, "tDAYZONE", 259, "tID", 260, "tMERIDIAN", 261, "tMINUTE_UNIT", 262, "tMONTH", 263, "tMONTH_UNIT", 264, "tSEC_UNIT", 265, "tSNUMBER", 266, "tUNUMBER", 267, "tZONE", 268, "-unknown-", -1 /* ends search */ }; #ifdef __cplusplus const #endif char * yyreds[] = { "-no such reduction-", "spec : /* empty */", "spec : spec item", "item : time", "item : zone", "item : date", "item : day", "item : rel", "item : number", "time : tUNUMBER tMERIDIAN", "time : tUNUMBER ':' tUNUMBER o_merid", "time : tUNUMBER ':' tUNUMBER tSNUMBER", "time : tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid", "time : tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER", "zone : tZONE", "zone : tDAYZONE", "day : tDAY", "day : tDAY ','", "day : tUNUMBER tDAY", "date : tUNUMBER '/' tUNUMBER", "date : tUNUMBER '/' tUNUMBER '/' tUNUMBER", "date : tMONTH tUNUMBER", "date : tMONTH tUNUMBER ',' tUNUMBER", "date : tUNUMBER tMONTH", "date : tUNUMBER tMONTH tUNUMBER", "rel : relunit tAGO", "rel : relunit", "relunit : tUNUMBER tMINUTE_UNIT", "relunit : tSNUMBER tMINUTE_UNIT", "relunit : tMINUTE_UNIT", "relunit : tSNUMBER tSEC_UNIT", "relunit : tUNUMBER tSEC_UNIT", "relunit : tSEC_UNIT", "relunit : tSNUMBER tMONTH_UNIT", "relunit : tUNUMBER tMONTH_UNIT", "relunit : tMONTH_UNIT", "number : tUNUMBER", "o_merid : /* empty */", "o_merid : tMERIDIAN", }; #endif /* YYDEBUG */ # line 1 "/usr/share/lib/ccs/yaccpar" /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 1993 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ #pragma ident "%Z%%M% %I% %E% SMI" /* ** Skeleton parser driver for yacc output */ /* ** yacc user known macros and defines */ #define YYERROR goto yyerrlab #define YYACCEPT return(0) #define YYABORT return(1) #define YYBACKUP( newtoken, newvalue )\ {\ if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\ {\ yyerror( "syntax error - cannot backup" );\ goto yyerrlab;\ }\ yychar = newtoken;\ yystate = *yyps;\ yylval = newvalue;\ goto yynewstate;\ } #define YYRECOVERING() (!!yyerrflag) #define YYNEW(type) malloc(sizeof(type) * yynewmax) #define YYCOPY(to, from, type) \ (type *) memcpy(to, (char *) from, yymaxdepth * sizeof (type)) #define YYENLARGE( from, type) \ (type *) realloc((char *) from, yynewmax * sizeof(type)) #ifndef YYDEBUG # define YYDEBUG 1 /* make debugging available */ #endif /* ** user known globals */ int yydebug; /* set to 1 to get debugging */ /* ** driver internal defines */ #define YYFLAG (-10000000) /* ** global variables used by the parser */ YYSTYPE *yypv; /* top of value stack */ int *yyps; /* top of state stack */ int yystate; /* current state */ int yytmp; /* extra var (lasts between blocks) */ int yynerrs; /* number of errors */ int yyerrflag; /* error recovery flag */ int yychar; /* current input token number */ #ifdef YYNMBCHARS #define YYLEX() yycvtok(yylex()) /* ** yycvtok - return a token if i is a wchar_t value that exceeds 255. ** If i<255, i itself is the token. If i>255 but the neither ** of the 30th or 31st bit is on, i is already a token. */ #if defined(__STDC__) || defined(__cplusplus) int yycvtok(int i) #else int yycvtok(i) int i; #endif { int first = 0; int last = YYNMBCHARS - 1; int mid; wchar_t j; if(i&0x60000000){/*Must convert to a token. */ if( yymbchars[last].character < i ){ return i;/*Giving up*/ } while ((last>=first)&&(first>=0)) {/*Binary search loop*/ mid = (first+last)/2; j = yymbchars[mid].character; if( j==i ){/*Found*/ return yymbchars[mid].tvalue; }else if( j= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( ++yy_ps >= &yys[ yymaxdepth ] ) /* room on stack? */ { /* ** reallocate and recover. Note that pointers ** have to be reset, or bad things will happen */ long yyps_index = (yy_ps - yys); long yypv_index = (yy_pv - yyv); long yypvt_index = (yypvt - yyv); int yynewmax; #ifdef YYEXPAND yynewmax = YYEXPAND(yymaxdepth); #else yynewmax = 2 * yymaxdepth; /* double table size */ if (yymaxdepth == YYMAXDEPTH) /* first time growth */ { char *newyys = (char *)YYNEW(int); char *newyyv = (char *)YYNEW(YYSTYPE); if (newyys != 0 && newyyv != 0) { yys = YYCOPY(newyys, yys, int); yyv = YYCOPY(newyyv, yyv, YYSTYPE); } else yynewmax = 0; /* failed */ } else /* not first time */ { yys = YYENLARGE(yys, int); yyv = YYENLARGE(yyv, YYSTYPE); if (yys == 0 || yyv == 0) yynewmax = 0; /* failed */ } #endif if (yynewmax <= yymaxdepth) /* tables not expanded */ { yyerror( "yacc stack overflow" ); YYABORT; } yymaxdepth = yynewmax; yy_ps = yys + yyps_index; yy_pv = yyv + yypv_index; yypvt = yyv + yypvt_index; } *yy_ps = yy_state; *++yy_pv = yyval; /* ** we have a new state - find out what to do */ yy_newstate: if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG ) goto yydefault; /* simple state */ #if YYDEBUG /* ** if debugging, need to mark whether new token grabbed */ yytmp = yychar < 0; #endif if ( ( yychar < 0 ) && ( ( yychar = YYLEX() ) < 0 ) ) yychar = 0; /* reached EOF */ #if YYDEBUG if ( yydebug && yytmp ) { register int yy_i; printf( "Received token " ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) ) goto yydefault; if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar ) /*valid shift*/ { yychar = -1; yyval = yylval; yy_state = yy_n; if ( yyerrflag > 0 ) yyerrflag--; goto yy_stack; } yydefault: if ( ( yy_n = yydef[ yy_state ] ) == -2 ) { #if YYDEBUG yytmp = yychar < 0; #endif if ( ( yychar < 0 ) && ( ( yychar = YYLEX() ) < 0 ) ) yychar = 0; /* reached EOF */ #if YYDEBUG if ( yydebug && yytmp ) { register int yy_i; printf( "Received token " ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) { break; } } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ /* ** look through exception table */ { register YYCONST int *yyxi = yyexca; while ( ( *yyxi != -1 ) || ( yyxi[1] != yy_state ) ) { yyxi += 2; } while ( ( *(yyxi += 2) >= 0 ) && ( *yyxi != yychar ) ) ; if ( ( yy_n = yyxi[1] ) < 0 ) YYACCEPT; } } /* ** check for syntax error */ if ( yy_n == 0 ) /* have an error */ { /* no worry about speed here! */ switch ( yyerrflag ) { case 0: /* new error */ yyerror( "syntax error" ); goto skip_init; yyerrlab: /* ** get globals into registers. ** we have a user generated syntax type error */ yy_pv = yypv; yy_ps = yyps; yy_state = yystate; skip_init: yynerrs++; /* FALLTHRU */ case 1: case 2: /* incompletely recovered error */ /* try again... */ yyerrflag = 3; /* ** find state where "error" is a legal ** shift action */ while ( yy_ps >= yys ) { yy_n = yypact[ *yy_ps ] + YYERRCODE; if ( yy_n >= 0 && yy_n < YYLAST && yychk[yyact[yy_n]] == YYERRCODE) { /* ** simulate shift of "error" */ yy_state = yyact[ yy_n ]; goto yy_stack; } /* ** current state has no shift on ** "error", pop stack */ #if YYDEBUG # define _POP_ "Error recovery pops state %d, uncovers state %d\n" if ( yydebug ) printf( _POP_, *yy_ps, yy_ps[-1] ); # undef _POP_ #endif yy_ps--; yy_pv--; } /* ** there is no state on stack with "error" as ** a valid shift. give up. */ YYABORT; case 3: /* no shift yet; eat a token */ #if YYDEBUG /* ** if debugging, look up token in list of ** pairs. 0 and negative shouldn't occur, ** but since timing doesn't matter when ** debugging, it doesn't hurt to leave the ** tests here. */ if ( yydebug ) { register int yy_i; printf( "Error recovery discards " ); if ( yychar == 0 ) printf( "token end-of-file\n" ); else if ( yychar < 0 ) printf( "token -none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) { break; } } printf( "token %s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( yychar == 0 ) /* reached EOF. quit */ YYABORT; yychar = -1; goto yy_newstate; } }/* end if ( yy_n == 0 ) */ /* ** reduction by production yy_n ** put stack tops, etc. so things right after switch */ #if YYDEBUG /* ** if debugging, print the string that is the user's ** specification of the reduction which is just about ** to be done. */ if ( yydebug ) printf( "Reduce by (%d) \"%s\"\n", yy_n, yyreds[ yy_n ] ); #endif yytmp = yy_n; /* value to switch over */ yypvt = yy_pv; /* $vars top of value stack */ /* ** Look in goto table for next state ** Sorry about using yy_state here as temporary ** register variable, but why not, if it works... ** If yyr2[ yy_n ] doesn't have the low order bit ** set, then there is no action to be done for ** this reduction. So, no saving & unsaving of ** registers done. The only difference between the ** code just after the if and the body of the if is ** the goto yy_stack in the body. This way the test ** can be made before the choice of what to do is needed. */ { /* length of production doubled with extra bit */ register int yy_len = yyr2[ yy_n ]; if ( !( yy_len & 01 ) ) { yy_len >>= 1; yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + *( yy_ps -= yy_len ) + 1; if ( yy_state >= YYLAST || yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) { yy_state = yyact[ yypgo[ yy_n ] ]; } goto yy_stack; } yy_len >>= 1; yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + *( yy_ps -= yy_len ) + 1; if ( yy_state >= YYLAST || yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) { yy_state = yyact[ yypgo[ yy_n ] ]; } } /* save until reenter driver code */ yystate = yy_state; yyps = yy_ps; yypv = yy_pv; } /* ** code supplied by user is placed in this switch */ switch( yytmp ) { case 3: # line 127 "getdate.y" { yyHaveTime++; } break; case 4: # line 130 "getdate.y" { yyHaveZone++; } break; case 5: # line 133 "getdate.y" { yyHaveDate++; } break; case 6: # line 136 "getdate.y" { yyHaveDay++; } break; case 7: # line 139 "getdate.y" { yyHaveRel++; } break; case 9: # line 145 "getdate.y" { yyHour = yypvt[-1].Number; yyMinutes = 0; yySeconds = 0; yyMeridian = yypvt[-0].Meridian; } break; case 10: # line 151 "getdate.y" { yyHour = yypvt[-3].Number; yyMinutes = yypvt[-1].Number; yySeconds = 0; yyMeridian = yypvt[-0].Meridian; } break; case 11: # line 157 "getdate.y" { yyHour = yypvt[-3].Number; yyMinutes = yypvt[-1].Number; yyMeridian = MER24; yyDSTmode = DSToff; yyTimezone = - (yypvt[-0].Number % 100 + (yypvt[-0].Number / 100) * 60); } break; case 12: # line 164 "getdate.y" { yyHour = yypvt[-5].Number; yyMinutes = yypvt[-3].Number; yySeconds = yypvt[-1].Number; yyMeridian = yypvt[-0].Meridian; } break; case 13: # line 170 "getdate.y" { yyHour = yypvt[-5].Number; yyMinutes = yypvt[-3].Number; yySeconds = yypvt[-1].Number; yyMeridian = MER24; yyDSTmode = DSToff; yyTimezone = - (yypvt[-0].Number % 100 + (yypvt[-0].Number / 100) * 60); } break; case 14: # line 180 "getdate.y" { yyTimezone = yypvt[-0].Number; yyDSTmode = DSToff; } break; case 15: # line 184 "getdate.y" { yyTimezone = yypvt[-0].Number; yyDSTmode = DSTon; } break; case 16: # line 190 "getdate.y" { yyDayOrdinal = 1; yyDayNumber = yypvt[-0].Number; } break; case 17: # line 194 "getdate.y" { yyDayOrdinal = 1; yyDayNumber = yypvt[-1].Number; } break; case 18: # line 198 "getdate.y" { yyDayOrdinal = yypvt[-1].Number; yyDayNumber = yypvt[-0].Number; } break; case 19: # line 204 "getdate.y" { yyMonth = yypvt[-2].Number; yyDay = yypvt[-0].Number; } break; case 20: # line 208 "getdate.y" { yyMonth = yypvt[-4].Number; yyDay = yypvt[-2].Number; yyYear = yypvt[-0].Number; } break; case 21: # line 213 "getdate.y" { yyMonth = yypvt[-1].Number; yyDay = yypvt[-0].Number; } break; case 22: # line 217 "getdate.y" { yyMonth = yypvt[-3].Number; yyDay = yypvt[-2].Number; yyYear = yypvt[-0].Number; } break; case 23: # line 222 "getdate.y" { yyMonth = yypvt[-0].Number; yyDay = yypvt[-1].Number; } break; case 24: # line 226 "getdate.y" { yyMonth = yypvt[-1].Number; yyDay = yypvt[-2].Number; yyYear = yypvt[-0].Number; } break; case 25: # line 233 "getdate.y" { yyRelSeconds = -yyRelSeconds; yyRelMonth = -yyRelMonth; } break; case 27: # line 240 "getdate.y" { yyRelSeconds += yypvt[-1].Number * yypvt[-0].Number * 60L; } break; case 28: # line 243 "getdate.y" { yyRelSeconds += yypvt[-1].Number * yypvt[-0].Number * 60L; } break; case 29: # line 246 "getdate.y" { yyRelSeconds += yypvt[-0].Number * 60L; } break; case 30: # line 249 "getdate.y" { yyRelSeconds += yypvt[-1].Number; } break; case 31: # line 252 "getdate.y" { yyRelSeconds += yypvt[-1].Number; } break; case 32: # line 255 "getdate.y" { yyRelSeconds++; } break; case 33: # line 258 "getdate.y" { yyRelMonth += yypvt[-1].Number * yypvt[-0].Number; } break; case 34: # line 261 "getdate.y" { yyRelMonth += yypvt[-1].Number * yypvt[-0].Number; } break; case 35: # line 264 "getdate.y" { yyRelMonth += yypvt[-0].Number; } break; case 36: # line 269 "getdate.y" { if (yyHaveTime && yyHaveDate && !yyHaveRel) yyYear = yypvt[-0].Number; else { yyHaveTime++; if (yypvt[-0].Number < 100) { yyHour = yypvt[-0].Number; yyMinutes = 0; } else { yyHour = yypvt[-0].Number / 100; yyMinutes = yypvt[-0].Number % 100; } yySeconds = 0; yyMeridian = MER24; } } break; case 37: # line 288 "getdate.y" { yyval.Meridian = MER24; } break; case 38: # line 291 "getdate.y" { yyval.Meridian = yypvt[-0].Meridian; } break; # line 556 "/usr/share/lib/ccs/yaccpar" } goto yystack; /* reset registers in driver code */ }