|
|
1.1 ! root 1: # define ID 257 ! 2: # define MONTH 258 ! 3: # define DAY 259 ! 4: # define MERIDIAN 260 ! 5: # define NUMBER 261 ! 6: # define UNIT 262 ! 7: # define MUNIT 263 ! 8: # define SUNIT 264 ! 9: # define ZONE 265 ! 10: # define DAYZONE 266 ! 11: # define AGO 267 ! 12: ! 13: # line 3 "getdate.y" ! 14: /* Steven M. Bellovin (unc!smb) */ ! 15: /* Dept. of Computer Science */ ! 16: /* University of North Carolina at Chapel Hill */ ! 17: /* @(#)getdate.y 2.5 3/3/83 */ ! 18: ! 19: #include <sys/types.h> ! 20: #ifdef USG ! 21: struct timeb ! 22: { ! 23: time_t time; ! 24: unsigned short millitm; ! 25: short timezone; ! 26: short dstflag; ! 27: }; ! 28: #else ! 29: #include <sys/timeb.h> ! 30: #endif ! 31: #include <ctype.h> ! 32: #include <time.h> ! 33: ! 34: #define NULL 0 ! 35: #define daysec (24L*60L*60L) ! 36: static int timeflag, zoneflag, dateflag, dayflag, relflag; ! 37: static time_t relsec, relmonth; ! 38: static int hh, mm, ss, merid, daylight; ! 39: static int dayord, dayreq; ! 40: static int month, day, year; ! 41: static int ourzone; ! 42: #define AM 1 ! 43: #define PM 2 ! 44: #define DAYLIGHT 1 ! 45: #define STANDARD 2 ! 46: #define MAYBE 3 ! 47: #define yyclearin yychar = -1 ! 48: #define yyerrok yyerrflag = 0 ! 49: extern int yychar; ! 50: extern short yyerrflag; ! 51: #ifndef YYMAXDEPTH ! 52: #define YYMAXDEPTH 150 ! 53: #endif ! 54: #ifndef YYSTYPE ! 55: #define YYSTYPE int ! 56: #endif ! 57: YYSTYPE yylval, yyval; ! 58: # define YYERRCODE 256 ! 59: ! 60: # line 109 "getdate.y" ! 61: ! 62: ! 63: static int mdays[12] = ! 64: {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; ! 65: #define epoch 1970 ! 66: ! 67: extern struct tm *localtime(); ! 68: time_t dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag) ! 69: int mm, dd, yy, h, m, s, mer, zone, dayflag; ! 70: { ! 71: time_t tod, jdate; ! 72: register int i; ! 73: time_t timeconv(); ! 74: ! 75: if (yy < 0) yy = -yy; ! 76: if (yy < 100) yy += 1900; ! 77: mdays[1] = 28 + (yy%4 == 0); ! 78: if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 || ! 79: dd < 1 || dd > mdays[--mm]) return (-1); ! 80: jdate = dd-1; ! 81: for (i=0; i<mm; i++) jdate += mdays[i]; ! 82: for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0); ! 83: jdate *= daysec; ! 84: jdate += zone * 60L; ! 85: if ((tod = timeconv(h, m, s, mer)) < 0) return (-1); ! 86: jdate += tod; ! 87: if (dayflag==DAYLIGHT || (dayflag==MAYBE&&localtime(&jdate)->tm_isdst)) ! 88: jdate += -1*60*60; ! 89: return (jdate); ! 90: } ! 91: ! 92: time_t dayconv(ord, day, now) int ord, day; time_t now; ! 93: { ! 94: register struct tm *loctime; ! 95: time_t tod; ! 96: time_t daylcorr(); ! 97: ! 98: tod = now; ! 99: loctime = localtime(&tod); ! 100: tod += daysec * ((day - loctime->tm_wday + 7) % 7); ! 101: tod += 7*daysec*(ord<=0?ord:ord-1); ! 102: return daylcorr(tod, now); ! 103: } ! 104: ! 105: time_t timeconv(hh, mm, ss, mer) register int hh, mm, ss, mer; ! 106: { ! 107: if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1); ! 108: switch (mer) { ! 109: case AM: if (hh < 1 || hh > 12) return(-1); ! 110: return (60L * ((hh%12)*60L + mm)+ss); ! 111: case PM: if (hh < 1 || hh > 12) return(-1); ! 112: return (60L * ((hh%12 +12)*60L + mm)+ss); ! 113: case 24: if (hh < 0 || hh > 23) return (-1); ! 114: return (60L * (hh*60L + mm)+ss); ! 115: default: return (-1); ! 116: } ! 117: } ! 118: time_t monthadd(sdate, relmonth) time_t sdate, relmonth; ! 119: { ! 120: struct tm *ltime; ! 121: time_t dateconv(); ! 122: time_t daylcorr(); ! 123: int mm, yy; ! 124: ! 125: if (relmonth == 0) return 0; ! 126: ltime = localtime(&sdate); ! 127: mm = 12*ltime->tm_year + ltime->tm_mon + relmonth; ! 128: yy = mm/12; ! 129: mm = mm%12 + 1; ! 130: return daylcorr(dateconv(mm, ltime->tm_mday, yy, ltime->tm_hour, ! 131: ltime->tm_min, ltime->tm_sec, 24, ourzone, MAYBE), sdate); ! 132: } ! 133: ! 134: time_t daylcorr(future, now) time_t future, now; ! 135: { ! 136: int fdayl, nowdayl; ! 137: ! 138: nowdayl = (localtime(&now)->tm_hour+1) % 24; ! 139: fdayl = (localtime(&future)->tm_hour+1) % 24; ! 140: return (future-now) + 60L*60L*(nowdayl-fdayl); ! 141: } ! 142: ! 143: static char *lptr; ! 144: ! 145: yylex() ! 146: { ! 147: extern int yylval; ! 148: int sign; ! 149: register char c; ! 150: register char *p; ! 151: char idbuf[20]; ! 152: int pcnt; ! 153: ! 154: for (;;) { ! 155: while (isspace(*lptr)) lptr++; ! 156: ! 157: if (isdigit(c = *lptr) || c == '-' || c == '+') { ! 158: if (c== '-' || c == '+') { ! 159: if (c=='-') sign = -1; ! 160: else sign = 1; ! 161: if (!isdigit(*++lptr)) { ! 162: /* yylval = sign; return (NUMBER); */ ! 163: return yylex(); /* skip the '-' sign */ ! 164: } ! 165: } else sign = 1; ! 166: yylval = 0; ! 167: while (isdigit(c = *lptr++)) yylval = 10*yylval + c - '0'; ! 168: yylval *= sign; ! 169: lptr--; ! 170: return (NUMBER); ! 171: ! 172: } else if (isalpha(c)) { ! 173: p = idbuf; ! 174: while (isalpha(c = *lptr++) || c=='.') ! 175: *p++ = c; ! 176: *p = '\0'; ! 177: lptr--; ! 178: return (lookup(idbuf)); ! 179: } ! 180: ! 181: else if (c == '(') { ! 182: pcnt = 0; ! 183: do { ! 184: c = *lptr++; ! 185: if (c == '\0') return(c); ! 186: else if (c == '(') pcnt++; ! 187: else if (c == ')') pcnt--; ! 188: } while (pcnt > 0); ! 189: } ! 190: ! 191: else return (*lptr++); ! 192: } ! 193: } ! 194: ! 195: struct table { ! 196: char *name; ! 197: int type, value; ! 198: }; ! 199: ! 200: struct table mdtab[] = { ! 201: {"January", MONTH, 1}, ! 202: {"February", MONTH, 2}, ! 203: {"March", MONTH, 3}, ! 204: {"April", MONTH, 4}, ! 205: {"May", MONTH, 5}, ! 206: {"June", MONTH, 6}, ! 207: {"July", MONTH, 7}, ! 208: {"August", MONTH, 8}, ! 209: {"September", MONTH, 9}, ! 210: {"Sept", MONTH, 9}, ! 211: {"October", MONTH, 10}, ! 212: {"November", MONTH, 11}, ! 213: {"December", MONTH, 12}, ! 214: ! 215: {"Sunday", DAY, 0}, ! 216: {"Monday", DAY, 1}, ! 217: {"Tuesday", DAY, 2}, ! 218: {"Tues", DAY, 2}, ! 219: {"Wednesday", DAY, 3}, ! 220: {"Wednes", DAY, 3}, ! 221: {"Thursday", DAY, 4}, ! 222: {"Thur", DAY, 4}, ! 223: {"Thurs", DAY, 4}, ! 224: {"Friday", DAY, 5}, ! 225: {"Saturday", DAY, 6}, ! 226: {0, 0, 0}}; ! 227: ! 228: #define HRS *60 ! 229: #define HALFHR 30 ! 230: struct table mztab[] = { ! 231: {"a.m.", MERIDIAN, AM}, ! 232: {"am", MERIDIAN, AM}, ! 233: {"p.m.", MERIDIAN, PM}, ! 234: {"pm", MERIDIAN, PM}, ! 235: {"nst", ZONE, 3 HRS + HALFHR}, /* Newfoundland */ ! 236: {"n.s.t.", ZONE, 3 HRS + HALFHR}, ! 237: {"ast", ZONE, 4 HRS}, /* Atlantic */ ! 238: {"a.s.t.", ZONE, 4 HRS}, ! 239: {"adt", DAYZONE, 4 HRS}, ! 240: {"a.d.t.", DAYZONE, 4 HRS}, ! 241: {"est", ZONE, 5 HRS}, /* Eastern */ ! 242: {"e.s.t.", ZONE, 5 HRS}, ! 243: {"edt", DAYZONE, 5 HRS}, ! 244: {"e.d.t.", DAYZONE, 5 HRS}, ! 245: {"cst", ZONE, 6 HRS}, /* Central */ ! 246: {"c.s.t.", ZONE, 6 HRS}, ! 247: {"cdt", DAYZONE, 6 HRS}, ! 248: {"c.d.t.", DAYZONE, 6 HRS}, ! 249: {"mst", ZONE, 7 HRS}, /* Mountain */ ! 250: {"m.s.t.", ZONE, 7 HRS}, ! 251: {"mdt", DAYZONE, 7 HRS}, ! 252: {"m.d.t.", DAYZONE, 7 HRS}, ! 253: {"pst", ZONE, 8 HRS}, /* Pacific */ ! 254: {"p.s.t.", ZONE, 8 HRS}, ! 255: {"pdt", DAYZONE, 8 HRS}, ! 256: {"p.d.t.", DAYZONE, 8 HRS}, ! 257: {"yst", ZONE, 9 HRS}, /* Yukon */ ! 258: {"y.s.t.", ZONE, 9 HRS}, ! 259: {"ydt", DAYZONE, 9 HRS}, ! 260: {"y.d.t.", DAYZONE, 9 HRS}, ! 261: {"hst", ZONE, 10 HRS}, /* Hawaii */ ! 262: {"h.s.t.", ZONE, 10 HRS}, ! 263: {"hdt", DAYZONE, 10 HRS}, ! 264: {"h.d.t.", DAYZONE, 10 HRS}, ! 265: {"bst", ZONE, 11 HRS}, /* Bering */ ! 266: {"b.s.t.", ZONE, 11 HRS}, ! 267: {"bdt", DAYZONE, 11 HRS}, ! 268: {"b.d.t.", DAYZONE, 11 HRS}, ! 269: ! 270: {"gmt", ZONE, 0 HRS}, ! 271: {"g.m.t.", ZONE, 0 HRS}, ! 272: ! 273: {"aest", ZONE, -10 HRS}, /* Australian Eastern Time */ ! 274: {"a.e.s.t.", ZONE, -10 HRS}, ! 275: {"aesst", DAYZONE, -10 HRS}, /* Australian Eastern Summer Time */ ! 276: {"a.e.s.s.t.", DAYZONE, -10 HRS}, ! 277: {"acst", ZONE, -(9 HRS + HALFHR)}, /* Australian Central Time */ ! 278: {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)}, ! 279: {"acsst", DAYZONE, -(9 HRS + HALFHR)}, /* Australian Central Summer */ ! 280: {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)}, ! 281: {"awst", ZONE, -8 HRS}, /* Australian Western Time */ ! 282: {"a.w.s.t.", ZONE, -8 HRS}, /* (no daylight time there, I'm told */ ! 283: {0, 0, 0}}; ! 284: ! 285: struct table unittb[] = { ! 286: {"year", MUNIT, 12}, ! 287: {"month", MUNIT, 1}, ! 288: {"fortnight", UNIT, 14*24*60}, ! 289: {"week", UNIT, 7*24*60}, ! 290: {"day", UNIT, 1*24*60}, ! 291: {"hour", UNIT, 60}, ! 292: {"minute", UNIT, 1}, ! 293: {"min", UNIT, 1}, ! 294: {"second", SUNIT, 1}, ! 295: {"sec", SUNIT, 1}, ! 296: {0, 0, 0}}; ! 297: ! 298: struct table othertb[] = { ! 299: {"tomorrow", UNIT, 1*24*60}, ! 300: {"yesterday", UNIT, -1*24*60}, ! 301: {"today", UNIT, 0}, ! 302: {"now", UNIT, 0}, ! 303: {"last", NUMBER, -1}, ! 304: {"this", UNIT, 0}, ! 305: {"next", NUMBER, 2}, ! 306: {"first", NUMBER, 1}, ! 307: /* {"second", NUMBER, 2}, */ ! 308: {"third", NUMBER, 3}, ! 309: {"fourth", NUMBER, 4}, ! 310: {"fifth", NUMBER, 5}, ! 311: {"sixth", NUMBER, 6}, ! 312: {"seventh", NUMBER, 7}, ! 313: {"eigth", NUMBER, 8}, ! 314: {"ninth", NUMBER, 9}, ! 315: {"tenth", NUMBER, 10}, ! 316: {"eleventh", NUMBER, 11}, ! 317: {"twelfth", NUMBER, 12}, ! 318: {"ago", AGO, 1}, ! 319: {0, 0, 0}}; ! 320: ! 321: struct table milzone[] = { ! 322: {"a", ZONE, 1 HRS}, ! 323: {"b", ZONE, 2 HRS}, ! 324: {"c", ZONE, 3 HRS}, ! 325: {"d", ZONE, 4 HRS}, ! 326: {"e", ZONE, 5 HRS}, ! 327: {"f", ZONE, 6 HRS}, ! 328: {"g", ZONE, 7 HRS}, ! 329: {"h", ZONE, 8 HRS}, ! 330: {"i", ZONE, 9 HRS}, ! 331: {"k", ZONE, 10 HRS}, ! 332: {"l", ZONE, 11 HRS}, ! 333: {"m", ZONE, 12 HRS}, ! 334: {"n", ZONE, -1 HRS}, ! 335: {"o", ZONE, -2 HRS}, ! 336: {"p", ZONE, -3 HRS}, ! 337: {"q", ZONE, -4 HRS}, ! 338: {"r", ZONE, -5 HRS}, ! 339: {"s", ZONE, -6 HRS}, ! 340: {"t", ZONE, -7 HRS}, ! 341: {"u", ZONE, -8 HRS}, ! 342: {"v", ZONE, -9 HRS}, ! 343: {"w", ZONE, -10 HRS}, ! 344: {"x", ZONE, -11 HRS}, ! 345: {"y", ZONE, -12 HRS}, ! 346: {"z", ZONE, 0 HRS}, ! 347: {0, 0, 0}}; ! 348: ! 349: lookup(id) char *id; ! 350: { ! 351: #define gotit (yylval=i->value, i->type) ! 352: #define getid for(j=idvar, k=id; *j++ = *k++; ) ! 353: ! 354: char idvar[20]; ! 355: register char *j, *k; ! 356: register struct table *i; ! 357: int abbrev; ! 358: ! 359: getid; ! 360: if (strlen(idvar) == 3) abbrev = 1; ! 361: else if (strlen(idvar) == 4 && idvar[3] == '.') { ! 362: abbrev = 1; ! 363: idvar[3] = '\0'; ! 364: } ! 365: else abbrev = 0; ! 366: ! 367: if (islower(*idvar)) *idvar = toupper(*idvar); ! 368: ! 369: for (i = mdtab; i->name; i++) { ! 370: k = idvar; ! 371: for (j = i->name; *j++ == *k++;) { ! 372: if (abbrev && j==i->name+3) return gotit; ! 373: if (j[-1] == 0) return gotit; ! 374: } ! 375: } ! 376: ! 377: getid; ! 378: for (i = mztab; i->name; i++) ! 379: if (strcmp(i->name, idvar) == 0) return gotit; ! 380: ! 381: for (j = idvar; *j; j++) if (isupper(*j)) *j = tolower(*j); ! 382: for (i=mztab; i->name; i++) ! 383: if (strcmp(i->name, idvar) == 0) return gotit; ! 384: ! 385: getid; ! 386: for (i=unittb; i->name; i++) ! 387: if (strcmp(i->name, idvar) == 0) return gotit; ! 388: ! 389: if (idvar[strlen(idvar)-1] == 's') idvar[strlen(idvar)-1] = '\0'; ! 390: for (i=unittb; i->name; i++) ! 391: if (strcmp(i->name, idvar) == 0) return gotit; ! 392: ! 393: getid; ! 394: for (i = othertb; i->name; i++) ! 395: if (strcmp(i->name, idvar) == 0) return gotit; ! 396: ! 397: getid; ! 398: if (strlen(idvar) == 1 && isalpha(*idvar)) { ! 399: if (isupper(*idvar)) *idvar = tolower(*idvar); ! 400: for (i = milzone; i->name; i++) ! 401: if (strcmp(i->name, idvar) == 0) return gotit; ! 402: } ! 403: ! 404: return(ID); ! 405: } ! 406: ! 407: time_t getdate(p, now) char *p; struct timeb *now; ! 408: { ! 409: #define mcheck(f) if (f>1) err++ ! 410: time_t monthadd(); ! 411: int err; ! 412: struct tm *lt; ! 413: struct timeb ftz; ! 414: ! 415: time_t sdate, tod; ! 416: ! 417: lptr = p; ! 418: if (now == ((struct timeb *) NULL)) { ! 419: now = &ftz; ! 420: ftime(&ftz); ! 421: } ! 422: lt = localtime(&now->time); ! 423: year = lt->tm_year; ! 424: month = lt->tm_mon+1; ! 425: day = lt->tm_mday; ! 426: relsec = 0; relmonth = 0; ! 427: timeflag=zoneflag=dateflag=dayflag=relflag=0; ! 428: ourzone = now->timezone; ! 429: daylight = MAYBE; ! 430: hh = mm = ss = 0; ! 431: merid = 24; ! 432: ! 433: if (err = yyparse()) return (-1); ! 434: ! 435: mcheck(timeflag); ! 436: mcheck(zoneflag); ! 437: mcheck(dateflag); ! 438: mcheck(dayflag); ! 439: ! 440: if (err) return (-1); ! 441: ! 442: if (dateflag || timeflag || dayflag) { ! 443: sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylight); ! 444: if (sdate < 0) return -1; ! 445: } ! 446: else { ! 447: sdate = now->time; ! 448: if (relflag == 0) ! 449: sdate -= (lt->tm_sec + lt->tm_min*60 + ! 450: lt->tm_hour*(60L*60L)); ! 451: } ! 452: ! 453: sdate += relsec; ! 454: sdate += monthadd(sdate, relmonth); ! 455: ! 456: if (dayflag) { ! 457: tod = dayconv(dayord, dayreq, sdate); ! 458: sdate += tod; ! 459: } ! 460: ! 461: return sdate; ! 462: } ! 463: ! 464: yyerror(s) char *s; ! 465: {} ! 466: short yyexca[] ={ ! 467: -1, 1, ! 468: 0, -1, ! 469: -2, 0, ! 470: }; ! 471: # define YYNPROD 33 ! 472: # define YYLAST 220 ! 473: short yyact[]={ ! 474: ! 475: 12, 13, 21, 9, 14, 15, 16, 10, 11, 37, ! 476: 17, 36, 35, 19, 33, 30, 29, 28, 26, 38, ! 477: 34, 31, 27, 8, 7, 6, 5, 4, 3, 2, ! 478: 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 479: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 480: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 481: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 482: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 483: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 484: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 485: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 486: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 487: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 488: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 489: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 490: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 491: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 492: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 493: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 494: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 495: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 496: 0, 0, 0, 22, 20, 18, 32, 23, 24, 25 }; ! 497: short yypact[]={ ! 498: ! 499: -1000,-258,-1000,-1000,-1000,-1000,-1000,-257,-1000, -45, ! 500: -1000,-1000,-243, -22,-1000,-1000,-1000,-1000,-1000,-244, ! 501: -1000,-245,-246,-1000,-1000,-1000, -23,-1000, -44, -27, ! 502: -1000,-249,-1000,-250,-252,-1000,-241,-1000,-1000 }; ! 503: short yypgo[]={ ! 504: ! 505: 0, 30, 29, 28, 27, 26, 25, 24, 23 }; ! 506: short yyr1[]={ ! 507: ! 508: 0, 1, 1, 2, 2, 2, 2, 2, 2, 8, ! 509: 3, 3, 3, 3, 3, 4, 4, 6, 6, 6, ! 510: 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, ! 511: 7, 7, 7 }; ! 512: short yyr2[]={ ! 513: ! 514: 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, ! 515: 2, 3, 4, 5, 6, 1, 1, 1, 2, 2, ! 516: 3, 5, 2, 4, 2, 3, 2, 2, 2, 1, ! 517: 1, 1, 2 }; ! 518: short yychk[]={ ! 519: ! 520: -1000, -1, -2, -3, -4, -5, -6, -7, -8, 261, ! 521: 265, 266, 258, 259, 262, 263, 264, 267, 260, 58, ! 522: 259, 47, 258, 262, 263, 264, 261, 44, 261, 261, ! 523: 261, 44, 260, 58, 47, 261, 261, 261, 260 }; ! 524: short yydef[]={ ! 525: ! 526: 1, -2, 2, 3, 4, 5, 6, 7, 8, 9, ! 527: 15, 16, 0, 17, 29, 30, 31, 32, 10, 0, ! 528: 19, 0, 24, 26, 27, 28, 22, 18, 11, 20, ! 529: 25, 0, 12, 0, 0, 23, 13, 21, 14 }; ! 530: # ifdef YYDEBUG ! 531: # include "y.debug" ! 532: # endif ! 533: ! 534: # define YYFLAG -1000 ! 535: # define YYERROR goto yyerrlab ! 536: # define YYACCEPT return(0) ! 537: # define YYABORT return(1) ! 538: ! 539: /* parser for yacc output */ ! 540: ! 541: #ifdef YYDEBUG ! 542: int yydebug = 0; /* 1 for debugging */ ! 543: #endif ! 544: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */ ! 545: int yychar = -1; /* current input token number */ ! 546: int yynerrs = 0; /* number of errors */ ! 547: short yyerrflag = 0; /* error recovery flag */ ! 548: ! 549: yyparse() ! 550: { short yys[YYMAXDEPTH]; ! 551: int yyj, yym; ! 552: register YYSTYPE *yypvt; ! 553: register int yystate, yyn; ! 554: register short *yyps; ! 555: register YYSTYPE *yypv; ! 556: register short *yyxi; ! 557: ! 558: yystate = 0; ! 559: yychar = -1; ! 560: yynerrs = 0; ! 561: yyerrflag = 0; ! 562: yyps= &yys[-1]; ! 563: yypv= &yyv[-1]; ! 564: ! 565: yystack: /* put a state and value onto the stack */ ! 566: #ifdef YYDEBUG ! 567: if(yydebug >= 3) ! 568: if(yychar < 0 || yytoknames[yychar] == 0) ! 569: printf("char %d in %s", yychar, yystates[yystate]); ! 570: else ! 571: printf("%s in %s", yytoknames[yychar], yystates[yystate]); ! 572: #endif ! 573: if( ++yyps >= &yys[YYMAXDEPTH] ) { ! 574: yyerror( "yacc stack overflow" ); ! 575: return(1); ! 576: } ! 577: *yyps = yystate; ! 578: ++yypv; ! 579: *yypv = yyval; ! 580: yynewstate: ! 581: yyn = yypact[yystate]; ! 582: if(yyn <= YYFLAG) goto yydefault; /* simple state */ ! 583: if(yychar<0) { ! 584: yychar = yylex(); ! 585: #ifdef YYDEBUG ! 586: if(yydebug >= 2) { ! 587: if(yychar <= 0) ! 588: printf("lex EOF\n"); ! 589: else if(yytoknames[yychar]) ! 590: printf("lex %s\n", yytoknames[yychar]); ! 591: else ! 592: printf("lex (%c)\n", yychar); ! 593: } ! 594: #endif ! 595: if(yychar < 0) ! 596: yychar = 0; ! 597: } ! 598: if((yyn += yychar) < 0 || yyn >= YYLAST) ! 599: goto yydefault; ! 600: if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ ! 601: yychar = -1; ! 602: yyval = yylval; ! 603: yystate = yyn; ! 604: if( yyerrflag > 0 ) --yyerrflag; ! 605: goto yystack; ! 606: } ! 607: yydefault: ! 608: /* default state action */ ! 609: if( (yyn=yydef[yystate]) == -2 ) { ! 610: if(yychar < 0) { ! 611: yychar = yylex(); ! 612: #ifdef YYDEBUG ! 613: if(yydebug >= 2) ! 614: if(yychar < 0) ! 615: printf("lex EOF\n"); ! 616: else ! 617: printf("lex %s\n", yytoknames[yychar]); ! 618: #endif ! 619: if(yychar < 0) ! 620: yychar = 0; ! 621: } ! 622: /* look through exception table */ ! 623: for(yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate); ! 624: yyxi += 2 ) ; /* VOID */ ! 625: while( *(yyxi+=2) >= 0 ){ ! 626: if( *yyxi == yychar ) break; ! 627: } ! 628: if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ ! 629: } ! 630: if( yyn == 0 ){ /* error */ ! 631: /* error ... attempt to resume parsing */ ! 632: switch( yyerrflag ){ ! 633: case 0: /* brand new error */ ! 634: #ifdef YYDEBUG ! 635: yyerror("syntax error\n%s", yystates[yystate]); ! 636: if(yytoknames[yychar]) ! 637: yyerror("saw %s\n", yytoknames[yychar]); ! 638: else if(yychar >= ' ' && yychar < '\177') ! 639: yyerror("saw `%c'\n", yychar); ! 640: else if(yychar == 0) ! 641: yyerror("saw EOF\n"); ! 642: else ! 643: yyerror("saw char 0%o\n", yychar); ! 644: #else ! 645: yyerror( "syntax error" ); ! 646: #endif ! 647: yyerrlab: ! 648: ++yynerrs; ! 649: case 1: ! 650: case 2: /* incompletely recovered error ... try again */ ! 651: yyerrflag = 3; ! 652: /* find a state where "error" is a legal shift action */ ! 653: while ( yyps >= yys ) { ! 654: yyn = yypact[*yyps] + YYERRCODE; ! 655: if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ ! 656: yystate = yyact[yyn]; /* simulate a shift of "error" */ ! 657: goto yystack; ! 658: } ! 659: yyn = yypact[*yyps]; ! 660: /* the current yyps has no shift onn "error", pop stack */ ! 661: #ifdef YYDEBUG ! 662: if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); ! 663: #endif ! 664: --yyps; ! 665: --yypv; ! 666: } ! 667: /* there is no state on the stack with an error shift ... abort */ ! 668: yyabort: ! 669: return(1); ! 670: case 3: /* no shift yet; clobber input char */ ! 671: #ifdef YYDEBUG ! 672: if( yydebug ) printf( "error recovery discards char %d\n", yychar ); ! 673: #endif ! 674: if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */ ! 675: yychar = -1; ! 676: goto yynewstate; /* try again in the same state */ ! 677: } ! 678: } ! 679: /* reduction by production yyn */ ! 680: #ifdef YYDEBUG ! 681: if(yydebug) { char *s; ! 682: printf("reduce %d in:\n\t", yyn); ! 683: for(s = yystates[yystate]; *s; s++) { ! 684: putchar(*s); ! 685: if(*s == '\n' && *(s+1)) ! 686: putchar('\t'); ! 687: } ! 688: } ! 689: #endif ! 690: yyps -= yyr2[yyn]; ! 691: yypvt = yypv; ! 692: yypv -= yyr2[yyn]; ! 693: yyval = yypv[1]; ! 694: yym=yyn; ! 695: /* consult goto table to find next state */ ! 696: yyn = yyr1[yyn]; ! 697: yyj = yypgo[yyn] + *yyps + 1; ! 698: if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; ! 699: switch(yym){ ! 700: ! 701: case 3: ! 702: # line 42 "getdate.y" ! 703: ! 704: {timeflag++;} break; ! 705: case 4: ! 706: # line 44 "getdate.y" ! 707: ! 708: {zoneflag++;} break; ! 709: case 5: ! 710: # line 46 "getdate.y" ! 711: ! 712: {dateflag++;} break; ! 713: case 6: ! 714: # line 48 "getdate.y" ! 715: ! 716: {dayflag++;} break; ! 717: case 7: ! 718: # line 50 "getdate.y" ! 719: ! 720: {relflag++;} break; ! 721: case 9: ! 722: # line 54 "getdate.y" ! 723: ! 724: {if (timeflag && dateflag && !relflag) year = yypvt[-0]; ! 725: else {timeflag++;hh = yypvt[-0]/100;mm = yypvt[-0]%100;ss = 0;merid = 24;}} break; ! 726: case 10: ! 727: # line 58 "getdate.y" ! 728: ! 729: {hh = yypvt[-1]; mm = 0; ss = 0; merid = yypvt[-0];} break; ! 730: case 11: ! 731: # line 60 "getdate.y" ! 732: ! 733: {hh = yypvt[-2]; mm = yypvt[-0]; merid = 24;} break; ! 734: case 12: ! 735: # line 62 "getdate.y" ! 736: ! 737: {hh = yypvt[-3]; mm = yypvt[-1]; merid = yypvt[-0];} break; ! 738: case 13: ! 739: # line 64 "getdate.y" ! 740: ! 741: {hh = yypvt[-4]; mm = yypvt[-2]; ss = yypvt[-0]; merid = 24;} break; ! 742: case 14: ! 743: # line 66 "getdate.y" ! 744: ! 745: {hh = yypvt[-5]; mm = yypvt[-3]; ss = yypvt[-1]; merid = yypvt[-0];} break; ! 746: case 15: ! 747: # line 69 "getdate.y" ! 748: ! 749: {ourzone = yypvt[-0]; daylight = STANDARD;} break; ! 750: case 16: ! 751: # line 71 "getdate.y" ! 752: ! 753: {ourzone = yypvt[-0]; daylight = DAYLIGHT;} break; ! 754: case 17: ! 755: # line 74 "getdate.y" ! 756: ! 757: {dayord = 1; dayreq = yypvt[-0];} break; ! 758: case 18: ! 759: # line 76 "getdate.y" ! 760: ! 761: {dayord = 1; dayreq = yypvt[-1];} break; ! 762: case 19: ! 763: # line 78 "getdate.y" ! 764: ! 765: {dayord = yypvt[-1]; dayreq = yypvt[-0];} break; ! 766: case 20: ! 767: # line 81 "getdate.y" ! 768: ! 769: {month = yypvt[-2]; day = yypvt[-0];} break; ! 770: case 21: ! 771: # line 83 "getdate.y" ! 772: ! 773: {month = yypvt[-4]; day = yypvt[-2]; year = yypvt[-0];} break; ! 774: case 22: ! 775: # line 85 "getdate.y" ! 776: ! 777: {month = yypvt[-1]; day = yypvt[-0];} break; ! 778: case 23: ! 779: # line 87 "getdate.y" ! 780: ! 781: {month = yypvt[-3]; day = yypvt[-2]; year = yypvt[-0];} break; ! 782: case 24: ! 783: # line 89 "getdate.y" ! 784: ! 785: {month = yypvt[-0]; day = yypvt[-1];} break; ! 786: case 25: ! 787: # line 91 "getdate.y" ! 788: ! 789: {month = yypvt[-1]; day = yypvt[-2]; year = yypvt[-0];} break; ! 790: case 26: ! 791: # line 95 "getdate.y" ! 792: ! 793: {relsec += 60L * yypvt[-1] * yypvt[-0];} break; ! 794: case 27: ! 795: # line 97 "getdate.y" ! 796: ! 797: {relmonth += yypvt[-1] * yypvt[-0];} break; ! 798: case 28: ! 799: # line 99 "getdate.y" ! 800: ! 801: {relsec += yypvt[-1];} break; ! 802: case 29: ! 803: # line 101 "getdate.y" ! 804: ! 805: {relsec += 60L * yypvt[-0];} break; ! 806: case 30: ! 807: # line 103 "getdate.y" ! 808: ! 809: {relmonth += yypvt[-0];} break; ! 810: case 31: ! 811: # line 105 "getdate.y" ! 812: ! 813: {relsec++;} break; ! 814: case 32: ! 815: # line 107 "getdate.y" ! 816: ! 817: {relsec = -relsec; relmonth = -relmonth;} break; ! 818: } ! 819: goto yystack; /* stack new state and value */ ! 820: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.