home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / dosutils / gtar109 / getdate.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  37KB  |  1,425 lines

  1.  
  2. /*  A Bison parser, made from d:\work\todo\gnu\tar109\getdate.y  */
  3.  
  4. #define    ID    258
  5. #define    MONTH    259
  6. #define    DAY    260
  7. #define    MERIDIAN    261
  8. #define    NUMBER    262
  9. #define    UNIT    263
  10. #define    MUNIT    264
  11. #define    SUNIT    265
  12. #define    ZONE    266
  13. #define    DAYZONE    267
  14. #define    AGO    268
  15. #define    DST    269
  16.  
  17. #line 2 "d:\work\todo\gnu\tar109\getdate.y"
  18.  
  19.     /*     Originally from: Steven M. Bellovin (unc!smb)    */
  20.     /*    Dept. of Computer Science            */
  21.     /*    University of North Carolina at Chapel Hill    */
  22.     /*    @(#)getdate.y    2.17    11/30/87            */
  23.  
  24. /* #include "defs.h" JF not used any more */
  25. #include <sys/types.h>
  26. #ifdef USG
  27. struct timeb
  28. {
  29.     time_t    time;
  30.     unsigned short millitm;
  31.     short    timezone;
  32.     short    dstflag;
  33. };
  34. static void ftime ();
  35. #else
  36. #include <sys/timeb.h>
  37. #endif
  38. #include <ctype.h>
  39.  
  40. #if defined(BSD4_2) || defined (BSD4_1C)
  41. #include <sys/time.h>
  42. #else /* sane */
  43. #include <time.h>
  44. #endif /* sane */
  45.  
  46. #if defined (STDC_HEADERS) || defined (USG)
  47. #include <string.h>
  48. #endif
  49.  
  50. #ifdef __GNUC__
  51. #define alloca __builtin_alloca
  52. #else
  53. #ifdef sparc
  54. #include <alloca.h>
  55. #endif
  56. #endif
  57.  
  58. #ifndef NULL
  59. #define    NULL    0
  60. #endif
  61. #define daysec (24L*60L*60L)
  62.     static int timeflag, zoneflag, dateflag, dayflag, relflag;
  63.     static time_t relsec, relmonth;
  64.     static int hh, mm, ss, merid, day_light;
  65.     static int dayord, dayreq;
  66.     static int month, day, year;
  67.     static int ourzone;
  68. #define AM 1
  69. #define PM 2
  70. #define DAYLIGHT 1
  71. #define STANDARD 2
  72. #define MAYBE    3
  73.  
  74. static time_t timeconv();
  75. static time_t daylcorr();
  76. static lookup();
  77. static yylex();
  78. static yyerror();
  79.  
  80. static int yylex ();
  81. #define yyparse getdate_yyparse
  82. static int yyerror ();
  83.  
  84.  
  85. #ifndef YYLTYPE
  86. typedef
  87.   struct yyltype
  88.     {
  89.       int timestamp;
  90.       int first_line;
  91.       int first_column;
  92.       int last_line;
  93.       int last_column;
  94.       char *text;
  95.    }
  96.   yyltype;
  97.  
  98. #define YYLTYPE yyltype
  99. #endif
  100.  
  101. #ifndef YYSTYPE
  102. #define YYSTYPE int
  103. #endif
  104. #include <stdio.h>
  105.  
  106. #ifndef __STDC__
  107. #define const
  108. #endif
  109.  
  110.  
  111.  
  112. #define    YYFINAL        44
  113. #define    YYFLAG        -32768
  114. #define    YYNTBASE    18
  115.  
  116. #define YYTRANSLATE(x) ((unsigned)(x) <= 269 ? yytranslate[x] : 27)
  117.  
  118. static const char yytranslate[] = {     0,
  119.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  120.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  121.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  122.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  123.      2,     2,     2,    16,     2,     2,    17,     2,     2,     2,
  124.      2,     2,     2,     2,     2,     2,     2,    15,     2,     2,
  125.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  126.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  127.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  128.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  129.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  130.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  131.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  132.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  133.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  134.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  135.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  136.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  137.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  138.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  139.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  140.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  141.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  142.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  143.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  144.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  145.      6,     7,     8,     9,    10,    11,    12,    13,    14
  146. };
  147.  
  148. #if YYDEBUG != 0
  149. static const short yyrline[] = { 0,
  150.     71,    72,    75,    77,    79,    81,    83,    85,    87,    96,
  151.     98,   100,   102,   105,   107,   109,   113,   115,   118,   120,
  152.    123,   125,   127,   130,   132,   134,   136,   138,   140,   144,
  153.    146,   148,   150,   152,   154,   156
  154. };
  155.  
  156. static const char * const yytname[] = {     0,
  157. "error","$illegal.","ID","MONTH","DAY","MERIDIAN","NUMBER","UNIT","MUNIT","SUNIT",
  158. "ZONE","DAYZONE","AGO","DST","':'","','","'/'","timedate"
  159. };
  160. #endif
  161.  
  162. static const short yyr1[] = {     0,
  163.     18,    18,    19,    19,    19,    19,    19,    19,    20,    21,
  164.     21,    21,    21,    21,    21,    21,    22,    22,    23,    23,
  165.     24,    24,    24,    25,    25,    25,    25,    25,    25,    26,
  166.     26,    26,    26,    26,    26,    26
  167. };
  168.  
  169. static const short yyr2[] = {     0,
  170.      0,     2,     1,     1,     1,     1,     1,     1,     1,     2,
  171.      3,     4,     4,     5,     6,     6,     2,     1,     0,     1,
  172.      1,     2,     2,     3,     5,     2,     4,     2,     3,     2,
  173.      2,     2,     1,     1,     1,     2
  174. };
  175.  
  176. static const short yydefact[] = {     1,
  177.      0,     0,    21,     9,    33,    34,    35,    19,    18,     2,
  178.      8,     3,     4,     6,     5,     7,    26,    22,    28,    23,
  179.     10,    30,    31,    32,     0,     0,    20,    17,    36,     0,
  180.     29,    11,    24,    27,    12,    13,     0,     0,    14,    25,
  181.     15,    16,     0,     0
  182. };
  183.  
  184. static const short yydefgoto[] = {     1,
  185.     10,    11,    12,    13,    28,    14,    15,    16
  186. };
  187.  
  188. static const short yypact[] = {-32768,
  189.     10,     2,   -13,    -4,-32768,-32768,-32768,    -2,-32768,-32768,
  190. -32768,-32768,-32768,-32768,-32768,    12,    11,-32768,    19,-32768,
  191. -32768,-32768,-32768,-32768,    21,    22,-32768,-32768,-32768,    23,
  192. -32768,     1,    14,-32768,-32768,-32768,    25,    26,    17,-32768,
  193. -32768,-32768,    34,-32768
  194. };
  195.  
  196. static const short yypgoto[] = {-32768,
  197. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768
  198. };
  199.  
  200.  
  201. #define    YYLAST        34
  202.  
  203.  
  204. static const short yytable[] = {    19,
  205.     20,    21,    18,    22,    23,    24,    35,    36,    17,    43,
  206.     25,    27,    26,     2,     3,    37,     4,     5,     6,     7,
  207.      8,     9,    41,    42,    29,    31,    30,    32,    33,    34,
  208.     38,    39,    40,    44
  209. };
  210.  
  211. static const short yycheck[] = {     4,
  212.      5,     6,    16,     8,     9,    10,     6,     7,     7,     0,
  213.     15,    14,    17,     4,     5,    15,     7,     8,     9,    10,
  214.     11,    12,     6,     7,    13,     7,    16,     7,     7,     7,
  215.     17,     7,     7,     0
  216. };
  217. #define YYPURE 1
  218.  
  219. /* BISON template */
  220. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  221. #line 3 "simple.bsn"
  222.  
  223. /* Skeleton output parser for bison,
  224.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  225.  
  226.    This program is free software; you can redistribute it and/or modify
  227.    it under the terms of the GNU General Public License as published by
  228.    the Free Software Foundation; either version 1, or (at your option)
  229.    any later version.
  230.  
  231.    This program is distributed in the hope that it will be useful,
  232.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  233.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  234.    GNU General Public License for more details.
  235.  
  236.    You should have received a copy of the GNU General Public License
  237.    along with this program; if not, write to the Free Software
  238.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  239.  
  240.  
  241. #ifdef __GNUC__
  242. #define alloca __builtin_alloca
  243. #else /* Not GNU C.  */
  244. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  245. #include <alloca.h>
  246. #else
  247. #ifdef MSDOS
  248. #include <malloc.h>
  249. #else
  250. void *alloca(unsigned);
  251. #endif /* MSDOS */
  252. #endif /* Sparc. */
  253. #endif /* Not GNU C. */
  254.  
  255. #ifndef bcopy
  256. #define bcopy(s,d,x) memcpy(d,s,x)
  257. #endif
  258.  
  259. /* This is the parser code that is written into each bison parser
  260.   when the %semantic_parser declaration is not specified in the grammar.
  261.   It was written by Richard Stallman by simplifying the hairy parser
  262.   used when %semantic_parser is specified.  */
  263.  
  264. /* Note: there must be only one dollar sign in this file.
  265.    It is replaced by the list of actions, each action
  266.    as one case of the switch.  */
  267.  
  268. #define yyerrok        (yyerrstatus = 0)
  269. #define yyclearin    (yychar = YYEMPTY)
  270. #define YYEMPTY        -2
  271. #define YYEOF        0
  272. #define YYACCEPT    return(0)
  273. #define YYABORT     return(1)
  274. #define YYERROR        goto yyerrlab1
  275. /* Like YYERROR except do call yyerror.
  276.    This remains here temporarily to ease the
  277.    transition to the new meaning of YYERROR, for GCC.
  278.    Once GCC version 2 has supplanted version 1, this can go.  */
  279. #define YYFAIL        goto yyerrlab
  280. #define YYRECOVERING()  (!!yyerrstatus)
  281. #define YYBACKUP(token, value) \
  282. do                                \
  283.   if (yychar == YYEMPTY && yylen == 1)                \
  284.     { yychar = (token), yylval = (value);            \
  285.       yychar1 = YYTRANSLATE (yychar);                \
  286.       YYPOPSTACK;                        \
  287.       goto yybackup;                        \
  288.     }                                \
  289.   else                                \
  290.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  291. while (0)
  292.  
  293. #define YYTERROR    1
  294. #define YYERRCODE    256
  295.  
  296. #ifndef YYIMPURE
  297. #define YYLEX        yylex()
  298. #endif
  299.  
  300. #ifndef YYPURE
  301. #define YYLEX        yylex(&yylval, &yylloc)
  302. #endif
  303.  
  304. /* If nonreentrant, generate the variables here */
  305.  
  306. #ifndef YYIMPURE
  307.  
  308. int    yychar;            /*  the lookahead symbol        */
  309. YYSTYPE    yylval;            /*  the semantic value of the        */
  310.                 /*  lookahead symbol            */
  311.  
  312. #ifdef YYLSP_NEEDED
  313. YYLTYPE yylloc;            /*  location data for the lookahead    */
  314.                 /*  symbol                */
  315. #endif
  316.  
  317. int yynerrs;            /*  number of parse errors so far       */
  318. #endif  /* YYIMPURE */
  319.  
  320. #if YYDEBUG != 0
  321. int yydebug;            /*  nonzero means print parse trace    */
  322. /* Since this is uninitialized, it does not stop multiple parsers
  323.    from coexisting.  */
  324. #endif
  325.  
  326. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  327.  
  328. #ifndef    YYINITDEPTH
  329. #define YYINITDEPTH 200
  330. #endif
  331.  
  332. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  333.     (effective only if the built-in stack extension method is used).  */
  334.  
  335. #if YYMAXDEPTH == 0
  336. #undef YYMAXDEPTH
  337. #endif
  338.  
  339. #ifndef YYMAXDEPTH
  340. #define YYMAXDEPTH 10000
  341. #endif
  342.  
  343. /* This is the most reliable way to avoid incompatibilities
  344.    in available built-in functions on various systems.  */
  345. static void
  346. __yy_bcopy (from, to, count)
  347.      char *from;
  348.      char *to;
  349.      int count;
  350. {
  351.   register char *f = from;
  352.   register char *t = to;
  353.   register int i = count;
  354.  
  355.   while (i-- > 0)
  356.     *t++ = *f++;
  357. }
  358.  
  359. #line 131 "simple.bsn"
  360. int
  361. yyparse()
  362. {
  363.   register int yystate;
  364.   register int yyn;
  365.   register short *yyssp;
  366.   register YYSTYPE *yyvsp;
  367.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  368.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  369.  
  370.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  371.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  372.  
  373.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  374.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  375.  
  376. #ifdef YYLSP_NEEDED
  377.   YYLTYPE *yyls = yylsa;
  378.   YYLTYPE *yylsp;
  379.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  380.  
  381. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  382. #else
  383. #define YYPOPSTACK   (yyvsp--, yysp--)
  384. #endif
  385.  
  386.   int yystacksize = YYINITDEPTH;
  387.  
  388. #ifndef YYPURE
  389.   int yychar;
  390.   YYSTYPE yylval;
  391.   int yynerrs;
  392. #ifdef YYLSP_NEEDED
  393.   YYLTYPE yylloc;
  394. #endif
  395. #endif
  396.  
  397.   YYSTYPE yyval;        /*  the variable used to return        */
  398.                 /*  semantic values from the action    */
  399.                 /*  routines                */
  400.  
  401.   int yylen;
  402.  
  403. #if YYDEBUG != 0
  404.   if (yydebug)
  405.     fprintf(stderr, "Starting parse\n");
  406. #endif
  407.  
  408.   yystate = 0;
  409.   yyerrstatus = 0;
  410.   yynerrs = 0;
  411.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  412.  
  413.   /* Initialize stack pointers.
  414.      Waste one element of value and location stack
  415.      so that they stay on the same level as the state stack.  */
  416.  
  417.   yyssp = yyss - 1;
  418.   yyvsp = yyvs;
  419. #ifdef YYLSP_NEEDED
  420.   yylsp = yyls;
  421. #endif
  422.  
  423. /* Push a new state, which is found in  yystate  .  */
  424. /* In all cases, when you get here, the value and location stacks
  425.    have just been pushed. so pushing a state here evens the stacks.  */
  426. yynewstate:
  427.  
  428.   *++yyssp = yystate;
  429.  
  430.   if (yyssp >= yyss + yystacksize - 1)
  431.     {
  432.       /* Give user a chance to reallocate the stack */
  433.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  434.       YYSTYPE *yyvs1 = yyvs;
  435.       short *yyss1 = yyss;
  436. #ifdef YYLSP_NEEDED
  437.       YYLTYPE *yyls1 = yyls;
  438. #endif
  439.  
  440.       /* Get the current used size of the three stacks, in elements.  */
  441.       int size = yyssp - yyss + 1;
  442.  
  443. #ifdef yyoverflow
  444.       /* Each stack pointer address is followed by the size of
  445.      the data in use in that stack, in bytes.  */
  446.       yyoverflow("parser stack overflow",
  447.          &yyss1, size * sizeof (*yyssp),
  448.          &yyvs1, size * sizeof (*yyvsp),
  449. #ifdef YYLSP_NEEDED
  450.          &yyls1, size * sizeof (*yylsp),
  451. #endif
  452.          &yystacksize);
  453.  
  454.       yyss = yyss1; yyvs = yyvs1;
  455. #ifdef YYLSP_NEEDED
  456.       yyls = yyls1;
  457. #endif
  458. #else /* no yyoverflow */
  459.       /* Extend the stack our own way.  */
  460.       if (yystacksize >= YYMAXDEPTH)
  461.     {
  462.       yyerror("parser stack overflow");
  463.       return 2;
  464.     }
  465.       yystacksize *= 2;
  466.       if (yystacksize > YYMAXDEPTH)
  467.     yystacksize = YYMAXDEPTH;
  468.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  469.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  470.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  471.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  472. #ifdef YYLSP_NEEDED
  473.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  474.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  475. #endif
  476. #endif /* no yyoverflow */
  477.  
  478.       yyssp = yyss + size - 1;
  479.       yyvsp = yyvs + size - 1;
  480. #ifdef YYLSP_NEEDED
  481.       yylsp = yyls + size - 1;
  482. #endif
  483.  
  484. #if YYDEBUG != 0
  485.       if (yydebug)
  486.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  487. #endif
  488.  
  489.       if (yyssp >= yyss + yystacksize - 1)
  490.     YYABORT;
  491.     }
  492.  
  493. #if YYDEBUG != 0
  494.   if (yydebug)
  495.     fprintf(stderr, "Entering state %d\n", yystate);
  496. #endif
  497.  
  498.  yybackup:
  499.  
  500. /* Do appropriate processing given the current state.  */
  501. /* Read a lookahead token if we need one and don't already have one.  */
  502. /* yyresume: */
  503.  
  504.   /* First try to decide what to do without reference to lookahead token.  */
  505.  
  506.   yyn = yypact[yystate];
  507.   if (yyn == YYFLAG)
  508.     goto yydefault;
  509.  
  510.   /* Not known => get a lookahead token if don't already have one.  */
  511.  
  512.   /* yychar is either YYEMPTY or YYEOF
  513.      or a valid token in external form.  */
  514.  
  515.   if (yychar == YYEMPTY)
  516.     {
  517. #if YYDEBUG != 0
  518.       if (yydebug)
  519.     fprintf(stderr, "Reading a token: ");
  520. #endif
  521.       yychar = YYLEX;
  522.     }
  523.  
  524.   /* Convert token to internal form (in yychar1) for indexing tables with */
  525.  
  526.   if (yychar <= 0)        /* This means end of input. */
  527.     {
  528.       yychar1 = 0;
  529.       yychar = YYEOF;        /* Don't call YYLEX any more */
  530.  
  531. #if YYDEBUG != 0
  532.       if (yydebug)
  533.     fprintf(stderr, "Now at end of input.\n");
  534. #endif
  535.     }
  536.   else
  537.     {
  538.       yychar1 = YYTRANSLATE(yychar);
  539.  
  540. #if YYDEBUG != 0
  541.       if (yydebug)
  542.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  543. #endif
  544.     }
  545.  
  546.   yyn += yychar1;
  547.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  548.     goto yydefault;
  549.  
  550.   yyn = yytable[yyn];
  551.  
  552.   /* yyn is what to do for this token type in this state.
  553.      Negative => reduce, -yyn is rule number.
  554.      Positive => shift, yyn is new state.
  555.        New state is final state => don't bother to shift,
  556.        just return success.
  557.      0, or most negative number => error.  */
  558.  
  559.   if (yyn < 0)
  560.     {
  561.       if (yyn == YYFLAG)
  562.     goto yyerrlab;
  563.       yyn = -yyn;
  564.       goto yyreduce;
  565.     }
  566.   else if (yyn == 0)
  567.     goto yyerrlab;
  568.  
  569.   if (yyn == YYFINAL)
  570.     YYACCEPT;
  571.  
  572.   /* Shift the lookahead token.  */
  573.  
  574. #if YYDEBUG != 0
  575.   if (yydebug)
  576.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  577. #endif
  578.  
  579.   /* Discard the token being shifted unless it is eof.  */
  580.   if (yychar != YYEOF)
  581.     yychar = YYEMPTY;
  582.  
  583.   *++yyvsp = yylval;
  584. #ifdef YYLSP_NEEDED
  585.   *++yylsp = yylloc;
  586. #endif
  587.  
  588.   /* count tokens shifted since error; after three, turn off error status.  */
  589.   if (yyerrstatus) yyerrstatus--;
  590.  
  591.   yystate = yyn;
  592.   goto yynewstate;
  593.  
  594. /* Do the default action for the current state.  */
  595. yydefault:
  596.  
  597.   yyn = yydefact[yystate];
  598.   if (yyn == 0)
  599.     goto yyerrlab;
  600.  
  601. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  602. yyreduce:
  603.   yylen = yyr2[yyn];
  604.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  605.  
  606. #if YYDEBUG != 0
  607.   if (yydebug)
  608.     {
  609.       if (yylen == 1)
  610.     fprintf (stderr, "Reducing 1 value via rule %d (line %d), ",
  611.          yyn, yyrline[yyn]);
  612.       else
  613.     fprintf (stderr, "Reducing %d values via rule %d (line %d), ",
  614.          yylen, yyn, yyrline[yyn]);
  615.     }
  616. #endif
  617.  
  618.  
  619.   switch (yyn) {
  620.  
  621. case 3:
  622. #line 76 "d:\work\todo\gnu\tar109\getdate.y"
  623. {timeflag++;;
  624.     break;}
  625. case 4:
  626. #line 78 "d:\work\todo\gnu\tar109\getdate.y"
  627. {zoneflag++;;
  628.     break;}
  629. case 5:
  630. #line 80 "d:\work\todo\gnu\tar109\getdate.y"
  631. {dateflag++;;
  632.     break;}
  633. case 6:
  634. #line 82 "d:\work\todo\gnu\tar109\getdate.y"
  635. {dayflag++;;
  636.     break;}
  637. case 7:
  638. #line 84 "d:\work\todo\gnu\tar109\getdate.y"
  639. {relflag++;;
  640.     break;}
  641. case 9:
  642. #line 88 "d:\work\todo\gnu\tar109\getdate.y"
  643. {if (timeflag && dateflag && !relflag) year = yyvsp[0];
  644.         else if (yyvsp[0] > 10000) {
  645.             dateflag++;
  646.             day= yyvsp[0]%100;
  647.             month= (yyvsp[0]/100)%100;
  648.             year = month/10000;
  649.         } else {timeflag++;hh = yyvsp[0]/100;mm = yyvsp[0]%100;ss = 0;merid = 24;};
  650.     break;}
  651. case 10:
  652. #line 97 "d:\work\todo\gnu\tar109\getdate.y"
  653. {hh = yyvsp[-1]; mm = 0; ss = 0; merid = yyvsp[0];;
  654.     break;}
  655. case 11:
  656. #line 99 "d:\work\todo\gnu\tar109\getdate.y"
  657. {hh = yyvsp[-2]; mm = yyvsp[0]; merid = 24;;
  658.     break;}
  659. case 12:
  660. #line 101 "d:\work\todo\gnu\tar109\getdate.y"
  661. {hh = yyvsp[-3]; mm = yyvsp[-1]; merid = yyvsp[0];;
  662.     break;}
  663. case 13:
  664. #line 103 "d:\work\todo\gnu\tar109\getdate.y"
  665. {hh = yyvsp[-3]; mm = yyvsp[-1]; merid = 24;
  666.         day_light = STANDARD; ourzone = -(yyvsp[0]%100 + 60*(yyvsp[0]/100));;
  667.     break;}
  668. case 14:
  669. #line 106 "d:\work\todo\gnu\tar109\getdate.y"
  670. {hh = yyvsp[-4]; mm = yyvsp[-2]; ss = yyvsp[0]; merid = 24;;
  671.     break;}
  672. case 15:
  673. #line 108 "d:\work\todo\gnu\tar109\getdate.y"
  674. {hh = yyvsp[-5]; mm = yyvsp[-3]; ss = yyvsp[-1]; merid = yyvsp[0];;
  675.     break;}
  676. case 16:
  677. #line 110 "d:\work\todo\gnu\tar109\getdate.y"
  678. {hh = yyvsp[-5]; mm = yyvsp[-3]; ss = yyvsp[-1]; merid = 24;
  679.         day_light = STANDARD; ourzone = -(yyvsp[0]%100 + 60*(yyvsp[0]/100));;
  680.     break;}
  681. case 17:
  682. #line 114 "d:\work\todo\gnu\tar109\getdate.y"
  683. {ourzone = yyvsp[-1]; day_light = yyvsp[0];;
  684.     break;}
  685. case 18:
  686. #line 116 "d:\work\todo\gnu\tar109\getdate.y"
  687. {ourzone = yyvsp[0]; day_light = DAYLIGHT;;
  688.     break;}
  689. case 19:
  690. #line 119 "d:\work\todo\gnu\tar109\getdate.y"
  691. { yyval = STANDARD; ;
  692.     break;}
  693. case 20:
  694. #line 121 "d:\work\todo\gnu\tar109\getdate.y"
  695. { yyval = DAYLIGHT; ;
  696.     break;}
  697. case 21:
  698. #line 124 "d:\work\todo\gnu\tar109\getdate.y"
  699. {dayord = 1; dayreq = yyvsp[0];;
  700.     break;}
  701. case 22:
  702. #line 126 "d:\work\todo\gnu\tar109\getdate.y"
  703. {dayord = 1; dayreq = yyvsp[-1];;
  704.     break;}
  705. case 23:
  706. #line 128 "d:\work\todo\gnu\tar109\getdate.y"
  707. {dayord = yyvsp[-1]; dayreq = yyvsp[0];;
  708.     break;}
  709. case 24:
  710. #line 131 "d:\work\todo\gnu\tar109\getdate.y"
  711. {month = yyvsp[-2]; day = yyvsp[0];;
  712.     break;}
  713. case 25:
  714. #line 133 "d:\work\todo\gnu\tar109\getdate.y"
  715. {month = yyvsp[-4]; day = yyvsp[-2]; year = yyvsp[0];;
  716.     break;}
  717. case 26:
  718. #line 135 "d:\work\todo\gnu\tar109\getdate.y"
  719. {month = yyvsp[-1]; day = yyvsp[0];;
  720.     break;}
  721. case 27:
  722. #line 137 "d:\work\todo\gnu\tar109\getdate.y"
  723. {month = yyvsp[-3]; day = yyvsp[-2]; year = yyvsp[0];;
  724.     break;}
  725. case 28:
  726. #line 139 "d:\work\todo\gnu\tar109\getdate.y"
  727. {month = yyvsp[0]; day = yyvsp[-1];;
  728.     break;}
  729. case 29:
  730. #line 141 "d:\work\todo\gnu\tar109\getdate.y"
  731. {month = yyvsp[-1]; day = yyvsp[-2]; year = yyvsp[0];;
  732.     break;}
  733. case 30:
  734. #line 145 "d:\work\todo\gnu\tar109\getdate.y"
  735. {relsec +=  60L * yyvsp[-1] * yyvsp[0];;
  736.     break;}
  737. case 31:
  738. #line 147 "d:\work\todo\gnu\tar109\getdate.y"
  739. {relmonth += yyvsp[-1] * yyvsp[0];;
  740.     break;}
  741. case 32:
  742. #line 149 "d:\work\todo\gnu\tar109\getdate.y"
  743. {relsec += yyvsp[-1];;
  744.     break;}
  745. case 33:
  746. #line 151 "d:\work\todo\gnu\tar109\getdate.y"
  747. {relsec +=  60L * yyvsp[0];;
  748.     break;}
  749. case 34:
  750. #line 153 "d:\work\todo\gnu\tar109\getdate.y"
  751. {relmonth += yyvsp[0];;
  752.     break;}
  753. case 35:
  754. #line 155 "d:\work\todo\gnu\tar109\getdate.y"
  755. {relsec++;;
  756.     break;}
  757. case 36:
  758. #line 157 "d:\work\todo\gnu\tar109\getdate.y"
  759. {relsec = -relsec; relmonth = -relmonth;;
  760.     break;}
  761. }
  762.    /* the action file gets copied in in place of this dollarsign */
  763. #line 362 "simple.bsn"
  764.  
  765.   yyvsp -= yylen;
  766.   yyssp -= yylen;
  767. #ifdef YYLSP_NEEDED
  768.   yylsp -= yylen;
  769. #endif
  770.  
  771. #if YYDEBUG != 0
  772.   if (yydebug)
  773.     {
  774.       short *ssp1 = yyss - 1;
  775.       fprintf (stderr, "state stack now");
  776.       while (ssp1 != yyssp)
  777.     fprintf (stderr, " %d", *++ssp1);
  778.       fprintf (stderr, "\n");
  779.     }
  780. #endif
  781.  
  782.   *++yyvsp = yyval;
  783.  
  784. #ifdef YYLSP_NEEDED
  785.   yylsp++;
  786.   if (yylen == 0)
  787.     {
  788.       yylsp->first_line = yylloc.first_line;
  789.       yylsp->first_column = yylloc.first_column;
  790.       yylsp->last_line = (yylsp-1)->last_line;
  791.       yylsp->last_column = (yylsp-1)->last_column;
  792.       yylsp->text = 0;
  793.     }
  794.   else
  795.     {
  796.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  797.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  798.     }
  799. #endif
  800.  
  801.   /* Now "shift" the result of the reduction.
  802.      Determine what state that goes to,
  803.      based on the state we popped back to
  804.      and the rule number reduced by.  */
  805.  
  806.   yyn = yyr1[yyn];
  807.  
  808.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  809.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  810.     yystate = yytable[yystate];
  811.   else
  812.     yystate = yydefgoto[yyn - YYNTBASE];
  813.  
  814.   goto yynewstate;
  815.  
  816. yyerrlab:   /* here on detecting error */
  817.  
  818.   if (! yyerrstatus)
  819.     /* If not already recovering from an error, report this error.  */
  820.     {
  821.       ++yynerrs;
  822.  
  823. #ifdef YYERROR_VERBOSE
  824.       yyn = yypact[yystate];
  825.  
  826.       if (yyn > YYFLAG && yyn < YYLAST)
  827.     {
  828.       int size = 0;
  829.       char *msg;
  830.       int x, count;
  831.  
  832.       count = 0;
  833.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  834.         if (yycheck[x + yyn] == x)
  835.           size += strlen(yytname[x]) + 15, count++;
  836.       msg = (char *) xmalloc(size + 15);
  837.       strcpy(msg, "parse error");
  838.  
  839.       if (count < 5)
  840.         {
  841.           count = 0;
  842.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  843.         if (yycheck[x + yyn] == x)
  844.           {
  845.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  846.             strcat(msg, yytname[x]);
  847.             strcat(msg, "'");
  848.             count++;
  849.           }
  850.         }
  851.       yyerror(msg);
  852.       free(msg);
  853.     }
  854.       else
  855. #endif /* YYERROR_VERBOSE */
  856.     yyerror("parse error");
  857.     }
  858.  
  859. yyerrlab1:   /* here on error raised explicitly by an action */
  860.  
  861.   if (yyerrstatus == 3)
  862.     {
  863.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  864.  
  865.       /* return failure if at end of input */
  866.       if (yychar == YYEOF)
  867.     YYABORT;
  868.  
  869. #if YYDEBUG != 0
  870.       if (yydebug)
  871.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  872. #endif
  873.  
  874.       yychar = YYEMPTY;
  875.     }
  876.  
  877.   /* Else will try to reuse lookahead token
  878.      after shifting the error token.  */
  879.  
  880.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  881.  
  882.   goto yyerrhandle;
  883.  
  884. yyerrdefault:  /* current state does not do anything special for the error token. */
  885.  
  886. #if 0
  887.   /* This is wrong; only states that explicitly want error tokens
  888.      should shift them.  */
  889.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  890.   if (yyn) goto yydefault;
  891. #endif
  892.  
  893. yyerrpop:   /* pop the current state because it cannot handle the error token */
  894.  
  895.   if (yyssp == yyss) YYABORT;
  896.   yyvsp--;
  897.   yystate = *--yyssp;
  898. #ifdef YYLSP_NEEDED
  899.   yylsp--;
  900. #endif
  901.  
  902. #if YYDEBUG != 0
  903.   if (yydebug)
  904.     {
  905.       short *ssp1 = yyss - 1;
  906.       fprintf (stderr, "Error: state stack now");
  907.       while (ssp1 != yyssp)
  908.     fprintf (stderr, " %d", *++ssp1);
  909.       fprintf (stderr, "\n");
  910.     }
  911. #endif
  912.  
  913. yyerrhandle:
  914.  
  915.   yyn = yypact[yystate];
  916.   if (yyn == YYFLAG)
  917.     goto yyerrdefault;
  918.  
  919.   yyn += YYTERROR;
  920.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  921.     goto yyerrdefault;
  922.  
  923.   yyn = yytable[yyn];
  924.   if (yyn < 0)
  925.     {
  926.       if (yyn == YYFLAG)
  927.     goto yyerrpop;
  928.       yyn = -yyn;
  929.       goto yyreduce;
  930.     }
  931.   else if (yyn == 0)
  932.     goto yyerrpop;
  933.  
  934.   if (yyn == YYFINAL)
  935.     YYACCEPT;
  936.  
  937. #if YYDEBUG != 0
  938.   if (yydebug)
  939.     fprintf(stderr, "Shifting error token, ");
  940. #endif
  941.  
  942.   *++yyvsp = yylval;
  943. #ifdef YYLSP_NEEDED
  944.   *++yylsp = yylloc;
  945. #endif
  946.  
  947.   yystate = yyn;
  948.   goto yynewstate;
  949. }
  950. #line 158 "d:\work\todo\gnu\tar109\getdate.y"
  951.  
  952.  
  953. static int mdays[12] =
  954.     {31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
  955. #define epoch 1970
  956.  
  957. extern struct tm *localtime();
  958.  
  959. static time_t
  960. dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
  961. int mm, dd, yy, h, m, s, mer, zone, dayflag;
  962. {
  963.     time_t tod, jdate;
  964.     register int i;
  965.  
  966.     if (yy < 0) yy = -yy;
  967.     if (yy < 100) yy += 1900;
  968.     mdays[1] = 28 + (yy%4 == 0 && (yy%100 != 0 || yy%400 == 0));
  969.     if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 ||
  970.         dd < 1 || dd > mdays[--mm]) return (-1);
  971.     jdate = dd-1;
  972.         for (i=0; i<mm; i++) jdate += mdays[i];
  973.     for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
  974.     jdate *= daysec;
  975.     jdate += zone * 60L;
  976.     if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
  977.     jdate += tod;
  978.     if (dayflag==DAYLIGHT || (dayflag==MAYBE&&localtime(&jdate)->tm_isdst))
  979.         jdate += -1*60*60;
  980.     return (jdate);
  981. }
  982.  
  983. static time_t
  984. dayconv(ord, day, now)
  985. int ord, day; time_t now;
  986. {
  987.     register struct tm *loctime;
  988.     time_t tod;
  989.  
  990.     tod = now;
  991.     loctime = localtime(&tod);
  992.     tod += daysec * ((day - loctime->tm_wday + 7) % 7);
  993.     tod += 7*daysec*(ord<=0?ord:ord-1);
  994.     return daylcorr(tod, now);
  995. }
  996.  
  997. static time_t
  998. timeconv(hh, mm, ss, mer)
  999. register int hh, mm, ss, mer;
  1000. {
  1001.     if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
  1002.     switch (mer) {
  1003.         case AM: if (hh < 1 || hh > 12) return(-1);
  1004.              return (60L * ((hh%12)*60L + mm)+ss);
  1005.         case PM: if (hh < 1 || hh > 12) return(-1);
  1006.              return (60L * ((hh%12 +12)*60L + mm)+ss);
  1007.         case 24: if (hh < 0 || hh > 23) return (-1);
  1008.              return (60L * (hh*60L + mm)+ss);
  1009.         default: return (-1);
  1010.     }
  1011. }
  1012.  
  1013. static time_t
  1014. monthadd(sdate, relmonth)
  1015. time_t sdate, relmonth;
  1016. {
  1017.     struct tm *ltime;
  1018.     time_t dateconv();
  1019.     int mm, yy;
  1020.  
  1021.     if (relmonth == 0) return 0;
  1022.     ltime = localtime(&sdate);
  1023.     mm = 12*ltime->tm_year + ltime->tm_mon + relmonth;
  1024.     yy = mm/12;
  1025.     mm = mm%12 + 1;
  1026.     return daylcorr(dateconv(mm, ltime->tm_mday, yy, ltime->tm_hour,
  1027.         ltime->tm_min, ltime->tm_sec, 24, ourzone, MAYBE), sdate);
  1028. }
  1029.  
  1030. static time_t
  1031. daylcorr(future, now)
  1032. time_t future, now;
  1033. {
  1034.     int fdayl, nowdayl;
  1035.  
  1036.     nowdayl = (localtime(&now)->tm_hour+1) % 24;
  1037.     fdayl = (localtime(&future)->tm_hour+1) % 24;
  1038.     return (future-now) + 60L*60L*(nowdayl-fdayl);
  1039. }
  1040.  
  1041. static char *lptr;
  1042.  
  1043. static int
  1044. yylex()
  1045. {
  1046.     extern int yylval;
  1047.     int sign;
  1048.     register char c;
  1049.     register char *p;
  1050.     char idbuf[20];
  1051.     int pcnt;
  1052.  
  1053.     for (;;) {
  1054.         while (isspace(*lptr))
  1055.             lptr++;
  1056.  
  1057.         if (isdigit(c = *lptr) || c == '-' || c == '+') {
  1058.             if (c== '-' || c == '+') {
  1059.                 if (c=='-') sign = -1;
  1060.                 else sign = 1;
  1061.                 if (!isdigit(*++lptr)) {
  1062.                     /* yylval = sign; return (NUMBER); */
  1063.                     return yylex();    /* skip the '-' sign */
  1064.                 }
  1065.             } else sign = 1;
  1066.             yylval = 0;
  1067.             while (isdigit(c = *lptr++))
  1068.                 yylval = 10*yylval + c - '0';
  1069.             yylval *= sign;
  1070.             lptr--;
  1071.             return (NUMBER);
  1072.  
  1073.         } else if (isalpha(c)) {
  1074.             p = idbuf;
  1075.             while (isalpha(c = *lptr++) || c=='.')
  1076.                 if (p < &idbuf[sizeof(idbuf)-1]) *p++ = c;
  1077.             *p = '\0';
  1078.             lptr--;
  1079.             return (lookup(idbuf));
  1080.         }
  1081.  
  1082.         else if (c == '(') {
  1083.             pcnt = 0;
  1084.             do {
  1085.                 c = *lptr++;
  1086.                 if (c == '\0') return(c);
  1087.                 else if (c == '(') pcnt++;
  1088.                 else if (c == ')') pcnt--;
  1089.             } while (pcnt > 0);
  1090.         }
  1091.  
  1092.         else return (*lptr++);
  1093.     }
  1094. }
  1095.  
  1096. struct table {
  1097.     char *name;
  1098.     int type, value;
  1099. };
  1100.  
  1101. static struct table mdtab[] = {
  1102.     {"january", MONTH, 1},
  1103.     {"february", MONTH, 2},
  1104.     {"march", MONTH, 3},
  1105.     {"april", MONTH, 4},
  1106.     {"may", MONTH, 5},
  1107.     {"june", MONTH, 6},
  1108.     {"july", MONTH, 7},
  1109.     {"august", MONTH, 8},
  1110.     {"september", MONTH, 9},
  1111.     {"sept", MONTH, 9},
  1112.     {"october", MONTH, 10},
  1113.     {"november", MONTH, 11},
  1114.     {"december", MONTH, 12},
  1115.  
  1116.     {"sunday", DAY, 0},
  1117.     {"monday", DAY, 1},
  1118.     {"tuesday", DAY, 2},
  1119.     {"tues", DAY, 2},
  1120.     {"wednesday", DAY, 3},
  1121.     {"wednes", DAY, 3},
  1122.     {"thursday", DAY, 4},
  1123.     {"thur", DAY, 4},
  1124.     {"thurs", DAY, 4},
  1125.     {"friday", DAY, 5},
  1126.     {"saturday", DAY, 6},
  1127.     {0, 0, 0}
  1128. };
  1129.  
  1130. #define HRS *60
  1131. #define HALFHR 30
  1132.  
  1133. static struct table mztab[] = {
  1134.     {"a.m.", MERIDIAN, AM},
  1135.     {"am", MERIDIAN, AM},
  1136.     {"p.m.", MERIDIAN, PM},
  1137.     {"pm", MERIDIAN, PM},
  1138.     {"nst", ZONE, 3 HRS + HALFHR},        /* Newfoundland */
  1139.     {"n.s.t.", ZONE, 3 HRS + HALFHR},
  1140.     {"ast", ZONE, 4 HRS},        /* Atlantic */
  1141.     {"a.s.t.", ZONE, 4 HRS},
  1142.     {"adt", DAYZONE, 4 HRS},
  1143.     {"a.d.t.", DAYZONE, 4 HRS},
  1144.     {"est", ZONE, 5 HRS},        /* Eastern */
  1145.     {"e.s.t.", ZONE, 5 HRS},
  1146.     {"edt", DAYZONE, 5 HRS},
  1147.     {"e.d.t.", DAYZONE, 5 HRS},
  1148.     {"cst", ZONE, 6 HRS},        /* Central */
  1149.     {"c.s.t.", ZONE, 6 HRS},
  1150.     {"cdt", DAYZONE, 6 HRS},
  1151.     {"c.d.t.", DAYZONE, 6 HRS},
  1152.     {"mst", ZONE, 7 HRS},        /* Mountain */
  1153.     {"m.s.t.", ZONE, 7 HRS},
  1154.     {"mdt", DAYZONE, 7 HRS},
  1155.     {"m.d.t.", DAYZONE, 7 HRS},
  1156.     {"pst", ZONE, 8 HRS},        /* Pacific */
  1157.     {"p.s.t.", ZONE, 8 HRS},
  1158.     {"pdt", DAYZONE, 8 HRS},
  1159.     {"p.d.t.", DAYZONE, 8 HRS},
  1160.     {"yst", ZONE, 9 HRS},        /* Yukon */
  1161.     {"y.s.t.", ZONE, 9 HRS},
  1162.     {"ydt", DAYZONE, 9 HRS},
  1163.     {"y.d.t.", DAYZONE, 9 HRS},
  1164.     {"hst", ZONE, 10 HRS},        /* Hawaii */
  1165.     {"h.s.t.", ZONE, 10 HRS},
  1166.     {"hdt", DAYZONE, 10 HRS},
  1167.     {"h.d.t.", DAYZONE, 10 HRS},
  1168.  
  1169.     {"gmt", ZONE, 0 HRS},
  1170.     {"g.m.t.", ZONE, 0 HRS},
  1171.     {"bst", DAYZONE, 0 HRS},        /* British Summer Time */
  1172.     {"b.s.t.", DAYZONE, 0 HRS},
  1173.     {"eet", ZONE, 0 HRS},        /* European Eastern Time */
  1174.     {"e.e.t.", ZONE, 0 HRS},
  1175.     {"eest", DAYZONE, 0 HRS},    /* European Eastern Summer Time */
  1176.     {"e.e.s.t.", DAYZONE, 0 HRS},
  1177.     {"met", ZONE, -1 HRS},        /* Middle European Time */
  1178.     {"m.e.t.", ZONE, -1 HRS},
  1179.     {"mest", DAYZONE, -1 HRS},    /* Middle European Summer Time */
  1180.     {"m.e.s.t.", DAYZONE, -1 HRS},
  1181.     {"wet", ZONE, -2 HRS },        /* Western European Time */
  1182.     {"w.e.t.", ZONE, -2 HRS },
  1183.     {"west", DAYZONE, -2 HRS},    /* Western European Summer Time */
  1184.     {"w.e.s.t.", DAYZONE, -2 HRS},
  1185.  
  1186.     {"jst", ZONE, -9 HRS},        /* Japan Standard Time */
  1187.     {"j.s.t.", ZONE, -9 HRS},    /* Japan Standard Time */
  1188.                     /* No daylight savings time */
  1189.  
  1190.     {"aest", ZONE, -10 HRS},    /* Australian Eastern Time */
  1191.     {"a.e.s.t.", ZONE, -10 HRS},
  1192.     {"aesst", DAYZONE, -10 HRS},    /* Australian Eastern Summer Time */
  1193.     {"a.e.s.s.t.", DAYZONE, -10 HRS},
  1194.     {"acst", ZONE, -(9 HRS + HALFHR)},    /* Australian Central Time */
  1195.     {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
  1196.     {"acsst", DAYZONE, -(9 HRS + HALFHR)},    /* Australian Central Summer */
  1197.     {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
  1198.     {"awst", ZONE, -8 HRS},        /* Australian Western Time */
  1199.     {"a.w.s.t.", ZONE, -8 HRS},    /* (no daylight time there, I'm told */
  1200.     {"dst", DST, 0},        /* Explicit daylight time */
  1201.     {0, 0, 0}};
  1202.  
  1203. static struct table unittb[] = {
  1204.     {"year", MUNIT, 12},
  1205.     {"month", MUNIT, 1},
  1206.     {"fortnight", UNIT, 14*24*60},
  1207.     {"week", UNIT, 7*24*60},
  1208.     {"day", UNIT, 1*24*60},
  1209.     {"hour", UNIT, 60},
  1210.     {"minute", UNIT, 1},
  1211.     {"min", UNIT, 1},
  1212.     {"second", SUNIT, 1},
  1213.     {"sec", SUNIT, 1},
  1214.     {0, 0, 0}};
  1215.  
  1216. static struct table othertb[] = {
  1217.     {"tomorrow", UNIT, 1*24*60},
  1218.     {"yesterday", UNIT, -1*24*60},
  1219.     {"today", UNIT, 0},
  1220.     {"now", UNIT, 0},
  1221.     {"last", NUMBER, -1},
  1222.     {"this", UNIT, 0},
  1223.     {"next", NUMBER, 2},
  1224.     {"first", NUMBER, 1},
  1225.     /* {"second", NUMBER, 2}, */
  1226.     {"third", NUMBER, 3},
  1227.     {"fourth", NUMBER, 4},
  1228.     {"fifth", NUMBER, 5},
  1229.     {"sixth", NUMBER, 6},
  1230.     {"seventh", NUMBER, 7},
  1231.     {"eigth", NUMBER, 8},
  1232.     {"ninth", NUMBER, 9},
  1233.     {"tenth", NUMBER, 10},
  1234.     {"eleventh", NUMBER, 11},
  1235.     {"twelfth", NUMBER, 12},
  1236.     {"ago", AGO, 1},
  1237.     {0, 0, 0}};
  1238.  
  1239. static struct table milzone[] = {
  1240.     {"a", ZONE, 1 HRS},
  1241.     {"b", ZONE, 2 HRS},
  1242.     {"c", ZONE, 3 HRS},
  1243.     {"d", ZONE, 4 HRS},
  1244.     {"e", ZONE, 5 HRS},
  1245.     {"f", ZONE, 6 HRS},
  1246.     {"g", ZONE, 7 HRS},
  1247.     {"h", ZONE, 8 HRS},
  1248.     {"i", ZONE, 9 HRS},
  1249.     {"k", ZONE, 10 HRS},
  1250.     {"l", ZONE, 11 HRS},
  1251.     {"m", ZONE, 12 HRS},
  1252.     {"n", ZONE, -1 HRS},
  1253.     {"o", ZONE, -2 HRS},
  1254.     {"p", ZONE, -3 HRS},
  1255.     {"q", ZONE, -4 HRS},
  1256.     {"r", ZONE, -5 HRS},
  1257.     {"s", ZONE, -6 HRS},
  1258.     {"t", ZONE, -7 HRS},
  1259.     {"u", ZONE, -8 HRS},
  1260.     {"v", ZONE, -9 HRS},
  1261.     {"w", ZONE, -10 HRS},
  1262.     {"x", ZONE, -11 HRS},
  1263.     {"y", ZONE, -12 HRS},
  1264.     {"z", ZONE, 0 HRS},
  1265.     {0, 0, 0}};
  1266.  
  1267. static int
  1268. lookup(id)
  1269. char *id;
  1270. {
  1271. #define gotit (yylval=i->value,  i->type)
  1272.  
  1273.     char idvar[128];
  1274.     register char *j, *k;
  1275.     register struct table *i;
  1276.     int abbrev;
  1277.  
  1278.     (void) strcpy(idvar, id);
  1279.     j = idvar;
  1280.     k = id - 1;
  1281.     while (*++k)
  1282.         *j++ = isupper(*k) ? tolower(*k) : *k;
  1283.     *j = '\0';
  1284.  
  1285.     if (strlen(idvar) == 3)
  1286.         abbrev = 1;
  1287.     else
  1288.         if (strlen(idvar) == 4 && idvar[3] == '.' && idvar[1] != '.') {
  1289.             abbrev = 1;
  1290.             idvar[3] = '\0';
  1291.         }
  1292.     else
  1293.         abbrev = 0;
  1294.  
  1295.     for (i = mdtab; i->name; i++) {
  1296.         k = idvar;
  1297.         for (j = i->name; *j++ == *k++;) {
  1298.             if (abbrev && j == i->name+3)
  1299.                 return gotit;
  1300.             if (j[-1] == 0)
  1301.                 return gotit;
  1302.         }
  1303.     }
  1304.  
  1305.     for (i=mztab; i->name; i++)
  1306.         if (strcmp(i->name, idvar) == 0)
  1307.             return gotit;
  1308.  
  1309.     for (i=unittb; i->name; i++)
  1310.         if (strcmp(i->name, idvar) == 0)
  1311.             return gotit;
  1312.  
  1313.     if (idvar[strlen(idvar)-1] == 's')
  1314.         idvar[strlen(idvar)-1] = '\0';
  1315.  
  1316.     for (i=unittb; i->name; i++)
  1317.         if (strcmp(i->name, idvar) == 0)
  1318.             return gotit;
  1319.  
  1320.     for (i = othertb; i->name; i++)
  1321.         if (strcmp(i->name, idvar) == 0)
  1322.             return gotit;
  1323.  
  1324.     if (strlen(idvar) == 1 && isalpha(*idvar)) {
  1325.         for (i = milzone; i->name; i++)
  1326.             if (strcmp(i->name, idvar) == 0)
  1327.                 return gotit;
  1328.     }
  1329.  
  1330.     return ID;
  1331. }
  1332.  
  1333. time_t
  1334. getdate(p, now)
  1335. char *p;
  1336. struct timeb *now;
  1337. {
  1338. #define mcheck(f)    if (f>1) err++
  1339.     time_t monthadd();
  1340.     int err;
  1341.     struct tm *lt;
  1342.     struct timeb ftz;
  1343.  
  1344.     time_t sdate, tod;
  1345.  
  1346.     lptr = p;
  1347.     if (now == ((struct timeb *) NULL)) {
  1348.         now = &ftz;
  1349.         ftime(&ftz);
  1350.     }
  1351.     lt = localtime(&now->time);
  1352.     year = lt->tm_year;
  1353.     month = lt->tm_mon+1;
  1354.     day = lt->tm_mday;
  1355.     relsec = 0; relmonth = 0;
  1356.     timeflag=zoneflag=dateflag=dayflag=relflag=0;
  1357.     ourzone = now->timezone;
  1358.     day_light = MAYBE;
  1359.     hh = mm = ss = 0;
  1360.     merid = 24;
  1361.  
  1362.     if (err = yyparse()) return (-1);
  1363.  
  1364.     mcheck(timeflag);
  1365.     mcheck(zoneflag);
  1366.     mcheck(dateflag);
  1367.     mcheck(dayflag);
  1368.  
  1369.     if (err) return (-1);
  1370.     if (dateflag || timeflag || dayflag) {
  1371.         sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,day_light);
  1372.         if (sdate < 0) return -1;
  1373.     }
  1374.     else {
  1375.         sdate = now->time;
  1376.         if (relflag == 0)
  1377.             sdate -= (lt->tm_sec + lt->tm_min*60 +
  1378.                 lt->tm_hour*(60L*60L));
  1379.     }
  1380.  
  1381.     sdate += relsec;
  1382.     sdate += monthadd(sdate, relmonth);
  1383.  
  1384.     if (dayflag && !dateflag) {
  1385.         tod = dayconv(dayord, dayreq, sdate);
  1386.         sdate += tod;
  1387.     }
  1388.  
  1389.     /*
  1390.     ** Have to do *something* with a legitimate -1 so it's distinguishable
  1391.     ** from the error return value.  (Alternately could set errno on error.)
  1392.     */
  1393.     return (sdate == -1) ? 0 : sdate;
  1394. }
  1395.  
  1396. static int
  1397. yyerror(s)
  1398. char *s;
  1399. {
  1400.   return 0;
  1401. }
  1402.  
  1403. #ifdef USG
  1404. static void
  1405. ftime(timeb)
  1406. struct timeb *timeb;
  1407. {
  1408.     extern long timezone;
  1409. #ifndef DAYLIGHT_MISSING    /* Not all non-BSD libraries have `daylight'. */
  1410.     extern int daylight;
  1411. #endif
  1412.     long t = 0;
  1413.  
  1414.     localtime(&t);    /* Dummy to init timzeone */
  1415.     time(&(timeb->time));
  1416.     timeb->millitm=0;
  1417.     timeb->timezone=timezone/60;    /* Timezone is in seconds! */
  1418. #ifndef DAYLIGHT_MISSING
  1419.     timeb->dstflag=daylight;
  1420. #else
  1421.     timeb->dstflag=0;
  1422. #endif
  1423. }
  1424. #endif
  1425.