home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / getdate.c < prev    next >
C/C++ Source or Header  |  1993-12-04  |  34KB  |  1,316 lines

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