home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / amicvs1-0.lha / AmiCVS / lib / getdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  44.5 KB  |  1,797 lines

  1.  
  2. /*  A Bison parser, made from getdate.y with Bison version GNU Bison version 1.21
  3. Amiga Port V1.00 by Uwe 'Hoover' Schuerkamp 6-May-93
  4. Contact hoover@mathematik.uni-bielefeld.de on port-related Problems.
  5.   */
  6.  
  7. #define YYBISON 1  /* Identify Bison output.  */
  8.  
  9. #define    tAGO    258
  10. #define    tDAY    259
  11. #define    tDAYZONE    260
  12. #define    tID    261
  13. #define    tMERIDIAN    262
  14. #define    tMINUTE_UNIT    263
  15. #define    tMONTH    264
  16. #define    tMONTH_UNIT    265
  17. #define    tSEC_UNIT    266
  18. #define    tSNUMBER    267
  19. #define    tUNUMBER    268
  20. #define    tZONE    269
  21. #define    tDST    270
  22.  
  23. #line 1 "getdate.y"
  24.  
  25. /* 1.8
  26. ** @(#)getdate.y 1.8 92/03/03
  27. **
  28. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  29. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  30. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  31. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  32. **  send any email to Rich.
  33. **
  34. **  This grammar has eight shift/reduce conflicts.
  35. **
  36. **  This code is in the public domain and has no copyright.
  37. */
  38. /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
  39. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  40.  
  41. #include "system.h"
  42. #include <ctype.h>
  43.  
  44. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  45. #ifdef __GNUC__
  46. #undef alloca            /* might get redefined below */
  47. #endif
  48. #endif
  49.  
  50. extern struct tm *localtime();
  51.  
  52. #define yyparse getdate_yyparse
  53. #define yylex getdate_yylex
  54. #define yyerror getdate_yyerror
  55.  
  56. #if    !defined(lint) && !defined(SABER)
  57. static char RCS[] = "@(#)getdate.y 1.8 92/03/03";
  58. #endif    /* !defined(lint) && !defined(SABER) */
  59.  
  60.  
  61. #define EPOCH        1970
  62. #define HOUR(x)        ((time_t)(x) * 60)
  63. #define SECSPERDAY    (24L * 60L * 60L)
  64.  
  65.  
  66. /*
  67. **  An entry in the lexical lookup table.
  68. */
  69. typedef struct _TABLE {
  70.     char    *name;
  71.     int        type;
  72.     time_t    value;
  73. } TABLE;
  74.  
  75.  
  76. /*
  77. **  Daylight-savings mode:  on, off, or not yet known.
  78. */
  79. typedef enum _DSTMODE {
  80.     DSTon, DSToff, DSTmaybe
  81. } DSTMODE;
  82.  
  83. /*
  84. **  Meridian:  am, pm, or 24-hour style.
  85. */
  86. typedef enum _MERIDIAN {
  87.     MERam, MERpm, MER24
  88. } MERIDIAN;
  89.  
  90.  
  91. /*
  92. **  Global variables.  We could get rid of most of these by using a good
  93. **  union as the yacc stack.  (This routine was originally written before
  94. **  yacc had the %union construct.)  Maybe someday; right now we only use
  95. **  the %union very rarely.
  96. */
  97. static char    *yyInput;
  98. static DSTMODE    yyDSTmode;
  99. static time_t    yyDayOrdinal;
  100. static time_t    yyDayNumber;
  101. static int    yyHaveDate;
  102. static int    yyHaveDay;
  103. static int    yyHaveRel;
  104. static int    yyHaveTime;
  105. static int    yyHaveZone;
  106. static time_t    yyTimezone;
  107. static time_t    yyDay;
  108. static time_t    yyHour;
  109. static time_t    yyMinutes;
  110. static time_t    yyMonth;
  111. static time_t    yySeconds;
  112. static time_t    yyYear;
  113. static MERIDIAN    yyMeridian;
  114. static time_t    yyRelMonth;
  115. static time_t    yyRelSeconds;
  116.  
  117.  
  118. #line 96 "getdate.y"
  119. typedef union {
  120.     time_t        Number;
  121.     enum _MERIDIAN    Meridian;
  122. } YYSTYPE;
  123.  
  124. #ifndef YYLTYPE
  125. typedef
  126.   struct yyltype
  127.     {
  128.       int timestamp;
  129.       int first_line;
  130.       int first_column;
  131.       int last_line;
  132.       int last_column;
  133.       char *text;
  134.    }
  135.   yyltype;
  136.  
  137. #define YYLTYPE yyltype
  138. #endif
  139.  
  140. #include <stdio.h>
  141.  
  142. #ifndef __cplusplus
  143. #ifndef __STDC__
  144. #define const
  145. #endif
  146. #endif
  147.  
  148.  
  149.  
  150. #define    YYFINAL        49
  151. #define    YYFLAG        -32768
  152. #define    YYNTBASE    19
  153.  
  154. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  155.  
  156. static const char yytranslate[] = {     0,
  157.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  158.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  159.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  160.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  161.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  162.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  163.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  164.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  165.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  166.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  167.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  168.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  169.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  170.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  171.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  172.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  173.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  174.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  175.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  176.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  177.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  178.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  179.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  180.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  181.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  182.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  183.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  184. };
  185.  
  186. #if YYDEBUG != 0
  187. static const short yyprhs[] = {     0,
  188.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  189.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  190.     62,    68,    71,    76,    79,    83,    86,    88,    91,    94,
  191.     96,    99,   102,   104,   107,   110,   112,   114,   115
  192. };
  193.  
  194. static const short yyrhs[] = {    -1,
  195.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  196.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  197.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  198.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  199.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  200.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  201.      0,    13,    18,    13,    18,    13,     0,     9,    13,     0,
  202.      9,    13,    17,    13,     0,    13,     9,     0,    13,     9,
  203.     13,     0,    26,     3,     0,    26,     0,    13,     8,     0,
  204.     12,     8,     0,     8,     0,    12,    11,     0,    13,    11,
  205.      0,    11,     0,    12,    10,     0,    13,    10,     0,    10,
  206.      0,    13,     0,     0,     7,     0
  207. };
  208.  
  209. #endif
  210.  
  211. #if YYDEBUG != 0
  212. static const short yyrline[] = { 0,
  213.    110,   111,   114,   117,   120,   123,   126,   129,   132,   138,
  214.    144,   151,   157,   167,   171,   175,   182,   186,   190,   196,
  215.    200,   205,   209,   214,   218,   225,   229,   232,   235,   238,
  216.    241,   244,   247,   250,   253,   256,   261,   289,   292
  217. };
  218.  
  219. static const char * const yytname[] = {   "$","error","$illegal.","tAGO","tDAY",
  220. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  221. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  222. "zone","day","date","rel","relunit","number","o_merid",""
  223. };
  224. #endif
  225.  
  226. static const short yyr1[] = {     0,
  227.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  228.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  229.     24,    24,    24,    24,    24,    25,    25,    26,    26,    26,
  230.     26,    26,    26,    26,    26,    26,    27,    28,    28
  231. };
  232.  
  233. static const short yyr2[] = {     0,
  234.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  235.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  236.      5,     2,     4,     2,     3,     2,     1,     2,     2,     1,
  237.      2,     2,     1,     2,     2,     1,     1,     0,     1
  238. };
  239.  
  240. static const short yydefact[] = {     1,
  241.      0,    17,    15,    30,     0,    36,    33,     0,    37,    14,
  242.      2,     3,     4,     6,     5,     7,    27,     8,    18,    22,
  243.     29,    34,    31,    19,     9,    28,    24,    35,    32,     0,
  244.      0,    16,    26,     0,    25,    38,    20,    23,    39,    11,
  245.      0,    10,     0,    38,    21,    13,    12,     0,     0
  246. };
  247.  
  248. static const short yydefgoto[] = {     1,
  249.     11,    12,    13,    14,    15,    16,    17,    18,    42
  250. };
  251.  
  252. static const short yypact[] = {-32768,
  253.      0,   -15,-32768,-32768,   -10,-32768,-32768,    23,    11,    -8,
  254. -32768,-32768,-32768,-32768,-32768,-32768,    13,-32768,-32768,     7,
  255. -32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,-32768,    12,
  256.     17,-32768,-32768,    22,-32768,    16,     8,-32768,-32768,-32768,
  257.     24,-32768,    25,    -6,-32768,-32768,-32768,    36,-32768
  258. };
  259.  
  260. static const short yypgoto[] = {-32768,
  261. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  262. };
  263.  
  264.  
  265. #define    YYLAST        39
  266.  
  267.  
  268. static const short yytable[] = {    48,
  269.     39,    19,    20,     2,     3,    46,    32,     4,     5,     6,
  270.      7,     8,     9,    10,    24,    33,    35,    25,    26,    27,
  271.     28,    29,    39,    34,    36,    43,    30,    40,    31,    37,
  272.     21,    41,    22,    23,    38,    49,    44,    45,    47
  273. };
  274.  
  275. static const short yycheck[] = {     0,
  276.      7,    17,    13,     4,     5,    12,    15,     8,     9,    10,
  277.     11,    12,    13,    14,     4,     3,    13,     7,     8,     9,
  278.     10,    11,     7,    17,    13,    18,    16,    12,    18,    13,
  279.      8,    16,    10,    11,    13,     0,    13,    13,    44
  280. };
  281. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  282. #line 3 "S:bison.simple"
  283.  
  284. /* Skeleton output parser for bison,
  285.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  286.  
  287.    This program is free software; you can redistribute it and/or modify
  288.    it under the terms of the GNU General Public License as published by
  289.    the Free Software Foundation; either version 1, or (at your option)
  290.    any later version.
  291.  
  292.    This program is distributed in the hope that it will be useful,
  293.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  294.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  295.    GNU General Public License for more details.
  296.  
  297.    You should have received a copy of the GNU General Public License
  298.    along with this program; if not, write to the Free Software
  299.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  300.  
  301.  
  302. #ifndef alloca
  303. #ifdef __GNUC__
  304. #define alloca __builtin_alloca
  305. #else /* not GNU C.  */
  306. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  307. #include <alloca.h>
  308. #else /* not sparc */
  309. #if defined (MSDOS) && !defined (__TURBOC__)
  310. #include <malloc.h>
  311. #else /* not MSDOS, or __TURBOC__ */
  312. #if defined(_AIX)
  313. #include <malloc.h>
  314.  #pragma alloca
  315. #else /* not MSDOS, __TURBOC__, or _AIX */
  316. #ifdef __hpux
  317. #ifdef __cplusplus
  318. extern "C" {
  319. void *alloca (unsigned int);
  320. };
  321. #else /* not __cplusplus */
  322. void *alloca (unsigned int);
  323. #endif /* not __cplusplus */
  324. #endif /* __hpux */
  325. #endif /* not _AIX */
  326. #endif /* not MSDOS, or __TURBOC__ */
  327. #endif /* not sparc.  */
  328. #endif /* not GNU C.  */
  329. #endif /* alloca not defined.  */
  330.  
  331. /* This is the parser code that is written into each bison parser
  332.   when the %semantic_parser declaration is not specified in the grammar.
  333.   It was written by Richard Stallman by simplifying the hairy parser
  334.   used when %semantic_parser is specified.  */
  335.  
  336. /* Note: there must be only one dollar sign in this file.
  337.    It is replaced by the list of actions, each action
  338.    as one case of the switch.  */
  339.  
  340. #define yyerrok        (yyerrstatus = 0)
  341. #define yyclearin    (yychar = YYEMPTY)
  342. #define YYEMPTY        -2
  343. #define YYEOF        0
  344. #define YYACCEPT    return(0)
  345. #define YYABORT     return(1)
  346. #define YYERROR        goto yyerrlab1
  347. /* Like YYERROR except do call yyerror.
  348.    This remains here temporarily to ease the
  349.    transition to the new meaning of YYERROR, for GCC.
  350.    Once GCC version 2 has supplanted version 1, this can go.  */
  351. #define YYFAIL        goto yyerrlab
  352. #define YYRECOVERING()  (!!yyerrstatus)
  353. #define YYBACKUP(token, value) \
  354. do                                \
  355.   if (yychar == YYEMPTY && yylen == 1)                \
  356.     { yychar = (token), yylval = (value);            \
  357.       yychar1 = YYTRANSLATE (yychar);                \
  358.       YYPOPSTACK;                        \
  359.       goto yybackup;                        \
  360.     }                                \
  361.   else                                \
  362.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  363. while (0)
  364.  
  365. #define YYTERROR    1
  366. #define YYERRCODE    256
  367.  
  368. #ifndef YYPURE
  369. #define YYLEX        yylex()
  370. #endif
  371.  
  372. #ifdef YYPURE
  373. #ifdef YYLSP_NEEDED
  374. #define YYLEX        yylex(&yylval, &yylloc)
  375. #else
  376. #define YYLEX        yylex(&yylval)
  377. #endif
  378. #endif
  379.  
  380. /* If nonreentrant, generate the variables here */
  381.  
  382. #ifndef YYPURE
  383.  
  384. int    yychar;            /*  the lookahead symbol        */
  385. YYSTYPE    yylval;            /*  the semantic value of the        */
  386.                 /*  lookahead symbol            */
  387.  
  388. #ifdef YYLSP_NEEDED
  389. YYLTYPE yylloc;            /*  location data for the lookahead    */
  390.                 /*  symbol                */
  391. #endif
  392.  
  393. int yynerrs;            /*  number of parse errors so far       */
  394. #endif  /* not YYPURE */
  395.  
  396. #if YYDEBUG != 0
  397. int yydebug;            /*  nonzero means print parse trace    */
  398. /* Since this is uninitialized, it does not stop multiple parsers
  399.    from coexisting.  */
  400. #endif
  401.  
  402. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  403.  
  404. #ifndef    YYINITDEPTH
  405. #define YYINITDEPTH 200
  406. #endif
  407.  
  408. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  409.     (effective only if the built-in stack extension method is used).  */
  410.  
  411. #if YYMAXDEPTH == 0
  412. #undef YYMAXDEPTH
  413. #endif
  414.  
  415. #ifndef YYMAXDEPTH
  416. #define YYMAXDEPTH 10000
  417. #endif
  418.  
  419. /* Prevent warning if -Wstrict-prototypes.  */
  420. #ifdef __GNUC__
  421. int yyparse (void);
  422. #endif
  423.  
  424. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  425. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  426. #else                /* not GNU C or C++ */
  427. #ifndef __cplusplus
  428.  
  429. /* This is the most reliable way to avoid incompatibilities
  430.    in available built-in functions on various systems.  */
  431. static void
  432. __yy_bcopy (from, to, count)
  433.      char *from;
  434.      char *to;
  435.      int count;
  436. {
  437.   register char *f = from;
  438.   register char *t = to;
  439.   register int i = count;
  440.  
  441.   while (i-- > 0)
  442.     *t++ = *f++;
  443. }
  444.  
  445. #else /* __cplusplus */
  446.  
  447. /* This is the most reliable way to avoid incompatibilities
  448.    in available built-in functions on various systems.  */
  449. static void
  450. __yy_bcopy (char *from, char *to, int count)
  451. {
  452.   register char *f = from;
  453.   register char *t = to;
  454.   register int i = count;
  455.  
  456.   while (i-- > 0)
  457.     *t++ = *f++;
  458. }
  459.  
  460. #endif
  461. #endif
  462.  
  463. #line 184 "bison.simple"
  464. int
  465. yyparse()
  466. {
  467.   register int yystate;
  468.   register int yyn;
  469.   register short *yyssp;
  470.   register YYSTYPE *yyvsp;
  471.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  472.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  473.  
  474.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  475.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  476.  
  477.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  478.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  479.  
  480. #ifdef YYLSP_NEEDED
  481.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  482.   YYLTYPE *yyls = yylsa;
  483.   YYLTYPE *yylsp;
  484.  
  485. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  486. #else
  487. #define YYPOPSTACK   (yyvsp--, yyssp--)
  488. #endif
  489.  
  490.   int yystacksize = YYINITDEPTH;
  491.  
  492. #ifdef YYPURE
  493.   int yychar;
  494.   YYSTYPE yylval;
  495.   int yynerrs;
  496. #ifdef YYLSP_NEEDED
  497.   YYLTYPE yylloc;
  498. #endif
  499. #endif
  500.  
  501.   YYSTYPE yyval;        /*  the variable used to return        */
  502.                 /*  semantic values from the action    */
  503.                 /*  routines                */
  504.  
  505.   int yylen;
  506.  
  507. #if YYDEBUG != 0
  508.   if (yydebug)
  509.     fprintf(stderr, "Starting parse\n");
  510. #endif
  511.  
  512.   yystate = 0;
  513.   yyerrstatus = 0;
  514.   yynerrs = 0;
  515.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  516.  
  517.   /* Initialize stack pointers.
  518.      Waste one element of value and location stack
  519.      so that they stay on the same level as the state stack.
  520.      The wasted elements are never initialized.  */
  521.  
  522.   yyssp = yyss - 1;
  523.   yyvsp = yyvs;
  524. #ifdef YYLSP_NEEDED
  525.   yylsp = yyls;
  526. #endif
  527.  
  528. /* Push a new state, which is found in  yystate  .  */
  529. /* In all cases, when you get here, the value and location stacks
  530.    have just been pushed. so pushing a state here evens the stacks.  */
  531. yynewstate:
  532.  
  533.   *++yyssp = yystate;
  534.  
  535.   if (yyssp >= yyss + yystacksize - 1)
  536.     {
  537.       /* Give user a chance to reallocate the stack */
  538.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  539.       YYSTYPE *yyvs1 = yyvs;
  540.       short *yyss1 = yyss;
  541. #ifdef YYLSP_NEEDED
  542.       YYLTYPE *yyls1 = yyls;
  543. #endif
  544.  
  545.       /* Get the current used size of the three stacks, in elements.  */
  546.       int size = yyssp - yyss + 1;
  547.  
  548. #ifdef yyoverflow
  549.       /* Each stack pointer address is followed by the size of
  550.      the data in use in that stack, in bytes.  */
  551.       yyoverflow("parser stack overflow",
  552.          &yyss1, size * sizeof (*yyssp),
  553.          &yyvs1, size * sizeof (*yyvsp),
  554. #ifdef YYLSP_NEEDED
  555.          &yyls1, size * sizeof (*yylsp),
  556. #endif
  557.          &yystacksize);
  558.  
  559.       yyss = yyss1; yyvs = yyvs1;
  560. #ifdef YYLSP_NEEDED
  561.       yyls = yyls1;
  562. #endif
  563. #else /* no yyoverflow */
  564.       /* Extend the stack our own way.  */
  565.       if (yystacksize >= YYMAXDEPTH)
  566.     {
  567.       yyerror("parser stack overflow");
  568.       return 2;
  569.     }
  570.       yystacksize *= 2;
  571.       if (yystacksize > YYMAXDEPTH)
  572.     yystacksize = YYMAXDEPTH;
  573.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  574.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  575.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  576.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  577. #ifdef YYLSP_NEEDED
  578.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  579.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  580. #endif
  581. #endif /* no yyoverflow */
  582.  
  583.       yyssp = yyss + size - 1;
  584.       yyvsp = yyvs + size - 1;
  585. #ifdef YYLSP_NEEDED
  586.       yylsp = yyls + size - 1;
  587. #endif
  588.  
  589. #if YYDEBUG != 0
  590.       if (yydebug)
  591.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  592. #endif
  593.  
  594.       if (yyssp >= yyss + yystacksize - 1)
  595.     YYABORT;
  596.     }
  597.  
  598. #if YYDEBUG != 0
  599.   if (yydebug)
  600.     fprintf(stderr, "Entering state %d\n", yystate);
  601. #endif
  602.  
  603.   goto yybackup;
  604.  yybackup:
  605.  
  606. /* Do appropriate processing given the current state.  */
  607. /* Read a lookahead token if we need one and don't already have one.  */
  608. /* yyresume: */
  609.  
  610.   /* First try to decide what to do without reference to lookahead token.  */
  611.  
  612.   yyn = yypact[yystate];
  613.   if (yyn == YYFLAG)
  614.     goto yydefault;
  615.  
  616.   /* Not known => get a lookahead token if don't already have one.  */
  617.  
  618.   /* yychar is either YYEMPTY or YYEOF
  619.      or a valid token in external form.  */
  620.  
  621.   if (yychar == YYEMPTY)
  622.     {
  623. #if YYDEBUG != 0
  624.       if (yydebug)
  625.     fprintf(stderr, "Reading a token: ");
  626. #endif
  627.       yychar = YYLEX;
  628.     }
  629.  
  630.   /* Convert token to internal form (in yychar1) for indexing tables with */
  631.  
  632.   if (yychar <= 0)        /* This means end of input. */
  633.     {
  634.       yychar1 = 0;
  635.       yychar = YYEOF;        /* Don't call YYLEX any more */
  636.  
  637. #if YYDEBUG != 0
  638.       if (yydebug)
  639.     fprintf(stderr, "Now at end of input.\n");
  640. #endif
  641.     }
  642.   else
  643.     {
  644.       yychar1 = YYTRANSLATE(yychar);
  645.  
  646. #if YYDEBUG != 0
  647.       if (yydebug)
  648.     {
  649.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  650.       /* Give the individual parser a way to print the precise meaning
  651.          of a token, for further debugging info.  */
  652. #ifdef YYPRINT
  653.       YYPRINT (stderr, yychar, yylval);
  654. #endif
  655.       fprintf (stderr, ")\n");
  656.     }
  657. #endif
  658.     }
  659.  
  660.   yyn += yychar1;
  661.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  662.     goto yydefault;
  663.  
  664.   yyn = yytable[yyn];
  665.  
  666.   /* yyn is what to do for this token type in this state.
  667.      Negative => reduce, -yyn is rule number.
  668.      Positive => shift, yyn is new state.
  669.        New state is final state => don't bother to shift,
  670.        just return success.
  671.      0, or most negative number => error.  */
  672.  
  673.   if (yyn < 0)
  674.     {
  675.       if (yyn == YYFLAG)
  676.     goto yyerrlab;
  677.       yyn = -yyn;
  678.       goto yyreduce;
  679.     }
  680.   else if (yyn == 0)
  681.     goto yyerrlab;
  682.  
  683.   if (yyn == YYFINAL)
  684.     YYACCEPT;
  685.  
  686.   /* Shift the lookahead token.  */
  687.  
  688. #if YYDEBUG != 0
  689.   if (yydebug)
  690.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  691. #endif
  692.  
  693.   /* Discard the token being shifted unless it is eof.  */
  694.   if (yychar != YYEOF)
  695.     yychar = YYEMPTY;
  696.  
  697.   *++yyvsp = yylval;
  698. #ifdef YYLSP_NEEDED
  699.   *++yylsp = yylloc;
  700. #endif
  701.  
  702.   /* count tokens shifted since error; after three, turn off error status.  */
  703.   if (yyerrstatus) yyerrstatus--;
  704.  
  705.   yystate = yyn;
  706.   goto yynewstate;
  707.  
  708. /* Do the default action for the current state.  */
  709. yydefault:
  710.  
  711.   yyn = yydefact[yystate];
  712.   if (yyn == 0)
  713.     goto yyerrlab;
  714.  
  715. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  716. yyreduce:
  717.   yylen = yyr2[yyn];
  718.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  719.  
  720. #if YYDEBUG != 0
  721.   if (yydebug)
  722.     {
  723.       int i;
  724.  
  725.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  726.            yyn, yyrline[yyn]);
  727.  
  728.       /* Print the symbols being reduced, and their result.  */
  729.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  730.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  731.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  732.     }
  733. #endif
  734.  
  735.  
  736.   switch (yyn) {
  737.  
  738. case 3:
  739. #line 114 "getdate.y"
  740. {
  741.         yyHaveTime++;
  742.     ;
  743.     break;}
  744. case 4:
  745. #line 117 "getdate.y"
  746. {
  747.         yyHaveZone++;
  748.     ;
  749.     break;}
  750. case 5:
  751. #line 120 "getdate.y"
  752. {
  753.         yyHaveDate++;
  754.     ;
  755.     break;}
  756. case 6:
  757. #line 123 "getdate.y"
  758. {
  759.         yyHaveDay++;
  760.     ;
  761.     break;}
  762. case 7:
  763. #line 126 "getdate.y"
  764. {
  765.         yyHaveRel++;
  766.     ;
  767.     break;}
  768. case 9:
  769. #line 132 "getdate.y"
  770. {
  771.         yyHour = yyvsp[-1].Number;
  772.         yyMinutes = 0;
  773.         yySeconds = 0;
  774.         yyMeridian = yyvsp[0].Meridian;
  775.     ;
  776.     break;}
  777. case 10:
  778. #line 138 "getdate.y"
  779. {
  780.         yyHour = yyvsp[-3].Number;
  781.         yyMinutes = yyvsp[-1].Number;
  782.         yySeconds = 0;
  783.         yyMeridian = yyvsp[0].Meridian;
  784.     ;
  785.     break;}
  786. case 11:
  787. #line 144 "getdate.y"
  788. {
  789.         yyHour = yyvsp[-3].Number;
  790.         yyMinutes = yyvsp[-1].Number;
  791.         yyMeridian = MER24;
  792.         yyDSTmode = DSToff;
  793.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  794.     ;
  795.     break;}
  796. case 12:
  797. #line 151 "getdate.y"
  798. {
  799.         yyHour = yyvsp[-5].Number;
  800.         yyMinutes = yyvsp[-3].Number;
  801.         yySeconds = yyvsp[-1].Number;
  802.         yyMeridian = yyvsp[0].Meridian;
  803.     ;
  804.     break;}
  805. case 13:
  806. #line 157 "getdate.y"
  807. {
  808.         yyHour = yyvsp[-5].Number;
  809.         yyMinutes = yyvsp[-3].Number;
  810.         yySeconds = yyvsp[-1].Number;
  811.         yyMeridian = MER24;
  812.         yyDSTmode = DSToff;
  813.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  814.     ;
  815.     break;}
  816. case 14:
  817. #line 167 "getdate.y"
  818. {
  819.         yyTimezone = yyvsp[0].Number;
  820.         yyDSTmode = DSToff;
  821.     ;
  822.     break;}
  823. case 15:
  824. #line 171 "getdate.y"
  825. {
  826.         yyTimezone = yyvsp[0].Number;
  827.         yyDSTmode = DSTon;
  828.     ;
  829.     break;}
  830. case 16:
  831. #line 176 "getdate.y"
  832. {
  833.         yyTimezone = yyvsp[-1].Number;
  834.         yyDSTmode = DSTon;
  835.     ;
  836.     break;}
  837. case 17:
  838. #line 182 "getdate.y"
  839. {
  840.         yyDayOrdinal = 1;
  841.         yyDayNumber = yyvsp[0].Number;
  842.     ;
  843.     break;}
  844. case 18:
  845. #line 186 "getdate.y"
  846. {
  847.         yyDayOrdinal = 1;
  848.         yyDayNumber = yyvsp[-1].Number;
  849.     ;
  850.     break;}
  851. case 19:
  852. #line 190 "getdate.y"
  853. {
  854.         yyDayOrdinal = yyvsp[-1].Number;
  855.         yyDayNumber = yyvsp[0].Number;
  856.     ;
  857.     break;}
  858. case 20:
  859. #line 196 "getdate.y"
  860. {
  861.         yyMonth = yyvsp[-2].Number;
  862.         yyDay = yyvsp[0].Number;
  863.     ;
  864.     break;}
  865. case 21:
  866. #line 200 "getdate.y"
  867. {
  868.         yyMonth = yyvsp[-4].Number;
  869.         yyDay = yyvsp[-2].Number;
  870.         yyYear = yyvsp[0].Number;
  871.     ;
  872.     break;}
  873. case 22:
  874. #line 205 "getdate.y"
  875. {
  876.         yyMonth = yyvsp[-1].Number;
  877.         yyDay = yyvsp[0].Number;
  878.     ;
  879.     break;}
  880. case 23:
  881. #line 209 "getdate.y"
  882. {
  883.         yyMonth = yyvsp[-3].Number;
  884.         yyDay = yyvsp[-2].Number;
  885.         yyYear = yyvsp[0].Number;
  886.     ;
  887.     break;}
  888. case 24:
  889. #line 214 "getdate.y"
  890. {
  891.         yyMonth = yyvsp[0].Number;
  892.         yyDay = yyvsp[-1].Number;
  893.     ;
  894.     break;}
  895. case 25:
  896. #line 218 "getdate.y"
  897. {
  898.         yyMonth = yyvsp[-1].Number;
  899.         yyDay = yyvsp[-2].Number;
  900.         yyYear = yyvsp[0].Number;
  901.     ;
  902.     break;}
  903. case 26:
  904. #line 225 "getdate.y"
  905. {
  906.         yyRelSeconds = -yyRelSeconds;
  907.         yyRelMonth = -yyRelMonth;
  908.     ;
  909.     break;}
  910. case 28:
  911. #line 232 "getdate.y"
  912. {
  913.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  914.     ;
  915.     break;}
  916. case 29:
  917. #line 235 "getdate.y"
  918. {
  919.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  920.     ;
  921.     break;}
  922. case 30:
  923. #line 238 "getdate.y"
  924. {
  925.         yyRelSeconds += yyvsp[0].Number * 60L;
  926.     ;
  927.     break;}
  928. case 31:
  929. #line 241 "getdate.y"
  930. {
  931.         yyRelSeconds += yyvsp[-1].Number;
  932.     ;
  933.     break;}
  934. case 32:
  935. #line 244 "getdate.y"
  936. {
  937.         yyRelSeconds += yyvsp[-1].Number;
  938.     ;
  939.     break;}
  940. case 33:
  941. #line 247 "getdate.y"
  942. {
  943.         yyRelSeconds++;
  944.     ;
  945.     break;}
  946. case 34:
  947. #line 250 "getdate.y"
  948. {
  949.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  950.     ;
  951.     break;}
  952. case 35:
  953. #line 253 "getdate.y"
  954. {
  955.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  956.     ;
  957.     break;}
  958. case 36:
  959. #line 256 "getdate.y"
  960. {
  961.         yyRelMonth += yyvsp[0].Number;
  962.     ;
  963.     break;}
  964. case 37:
  965. #line 261 "getdate.y"
  966. {
  967.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  968.         yyYear = yyvsp[0].Number;
  969.         else {
  970.         if(yyvsp[0].Number>10000) {
  971.             time_t date_part;
  972.  
  973.             date_part= yyvsp[0].Number/10000;
  974.             yyHaveDate++;
  975.             yyDay= (date_part)%100;
  976.             yyMonth= (date_part/100)%100;
  977.             yyYear = date_part/10000;
  978.         } 
  979.             yyHaveTime++;
  980.         if (yyvsp[0].Number < 100) {
  981.             yyHour = yyvsp[0].Number;
  982.             yyMinutes = 0;
  983.         }
  984.         else {
  985.             yyHour = yyvsp[0].Number / 100;
  986.             yyMinutes = yyvsp[0].Number % 100;
  987.         }
  988.         yySeconds = 0;
  989.         yyMeridian = MER24;
  990.         }
  991.     ;
  992.     break;}
  993. case 38:
  994. #line 289 "getdate.y"
  995. {
  996.         yyval.Meridian = MER24;
  997.     ;
  998.     break;}
  999. case 39:
  1000. #line 292 "getdate.y"
  1001. {
  1002.         yyval.Meridian = yyvsp[0].Meridian;
  1003.     ;
  1004.     break;}
  1005. }
  1006.    /* the action file gets copied in in place of this dollarsign */
  1007. #line 457 "bison.simple"
  1008.  
  1009.   yyvsp -= yylen;
  1010.   yyssp -= yylen;
  1011. #ifdef YYLSP_NEEDED
  1012.   yylsp -= yylen;
  1013. #endif
  1014.  
  1015. #if YYDEBUG != 0
  1016.   if (yydebug)
  1017.     {
  1018.       short *ssp1 = yyss - 1;
  1019.       fprintf (stderr, "state stack now");
  1020.       while (ssp1 != yyssp)
  1021.     fprintf (stderr, " %d", *++ssp1);
  1022.       fprintf (stderr, "\n");
  1023.     }
  1024. #endif
  1025.  
  1026.   *++yyvsp = yyval;
  1027.  
  1028. #ifdef YYLSP_NEEDED
  1029.   yylsp++;
  1030.   if (yylen == 0)
  1031.     {
  1032.       yylsp->first_line = yylloc.first_line;
  1033.       yylsp->first_column = yylloc.first_column;
  1034.       yylsp->last_line = (yylsp-1)->last_line;
  1035.       yylsp->last_column = (yylsp-1)->last_column;
  1036.       yylsp->text = 0;
  1037.     }
  1038.   else
  1039.     {
  1040.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1041.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1042.     }
  1043. #endif
  1044.  
  1045.   /* Now "shift" the result of the reduction.
  1046.      Determine what state that goes to,
  1047.      based on the state we popped back to
  1048.      and the rule number reduced by.  */
  1049.  
  1050.   yyn = yyr1[yyn];
  1051.  
  1052.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1053.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1054.     yystate = yytable[yystate];
  1055.   else
  1056.     yystate = yydefgoto[yyn - YYNTBASE];
  1057.  
  1058.   goto yynewstate;
  1059.  
  1060. yyerrlab:   /* here on detecting error */
  1061.  
  1062.   if (! yyerrstatus)
  1063.     /* If not already recovering from an error, report this error.  */
  1064.     {
  1065.       ++yynerrs;
  1066.  
  1067. #ifdef YYERROR_VERBOSE
  1068.       yyn = yypact[yystate];
  1069.  
  1070.       if (yyn > YYFLAG && yyn < YYLAST)
  1071.     {
  1072.       int size = 0;
  1073.       char *msg;
  1074.       int x, count;
  1075.  
  1076.       count = 0;
  1077.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1078.       for (x = (yyn < 0 ? -yyn : 0);
  1079.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1080.         if (yycheck[x + yyn] == x)
  1081.           size += strlen(yytname[x]) + 15, count++;
  1082.       msg = (char *) malloc(size + 15);
  1083.       if (msg != 0)
  1084.         {
  1085.           strcpy(msg, "parse error");
  1086.  
  1087.           if (count < 5)
  1088.         {
  1089.           count = 0;
  1090.           for (x = (yyn < 0 ? -yyn : 0);
  1091.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1092.             if (yycheck[x + yyn] == x)
  1093.               {
  1094.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1095.             strcat(msg, yytname[x]);
  1096.             strcat(msg, "'");
  1097.             count++;
  1098.               }
  1099.         }
  1100.           yyerror(msg);
  1101.           free(msg);
  1102.         }
  1103.       else
  1104.         yyerror ("parse error; also virtual memory exceeded");
  1105.     }
  1106.       else
  1107. #endif /* YYERROR_VERBOSE */
  1108.     yyerror("parse error");
  1109.     }
  1110.  
  1111.   goto yyerrlab1;
  1112. yyerrlab1:   /* here on error raised explicitly by an action */
  1113.  
  1114.   if (yyerrstatus == 3)
  1115.     {
  1116.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1117.  
  1118.       /* return failure if at end of input */
  1119.       if (yychar == YYEOF)
  1120.     YYABORT;
  1121.  
  1122. #if YYDEBUG != 0
  1123.       if (yydebug)
  1124.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1125. #endif
  1126.  
  1127.       yychar = YYEMPTY;
  1128.     }
  1129.  
  1130.   /* Else will try to reuse lookahead token
  1131.      after shifting the error token.  */
  1132.  
  1133.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1134.  
  1135.   goto yyerrhandle;
  1136.  
  1137. yyerrdefault:  /* current state does not do anything special for the error token. */
  1138.  
  1139. #if 0
  1140.   /* This is wrong; only states that explicitly want error tokens
  1141.      should shift them.  */
  1142.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1143.   if (yyn) goto yydefault;
  1144. #endif
  1145.  
  1146. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1147.  
  1148.   if (yyssp == yyss) YYABORT;
  1149.   yyvsp--;
  1150.   yystate = *--yyssp;
  1151. #ifdef YYLSP_NEEDED
  1152.   yylsp--;
  1153. #endif
  1154.  
  1155. #if YYDEBUG != 0
  1156.   if (yydebug)
  1157.     {
  1158.       short *ssp1 = yyss - 1;
  1159.       fprintf (stderr, "Error: state stack now");
  1160.       while (ssp1 != yyssp)
  1161.     fprintf (stderr, " %d", *++ssp1);
  1162.       fprintf (stderr, "\n");
  1163.     }
  1164. #endif
  1165.  
  1166. yyerrhandle:
  1167.  
  1168.   yyn = yypact[yystate];
  1169.   if (yyn == YYFLAG)
  1170.     goto yyerrdefault;
  1171.  
  1172.   yyn += YYTERROR;
  1173.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1174.     goto yyerrdefault;
  1175.  
  1176.   yyn = yytable[yyn];
  1177.   if (yyn < 0)
  1178.     {
  1179.       if (yyn == YYFLAG)
  1180.     goto yyerrpop;
  1181.       yyn = -yyn;
  1182.       goto yyreduce;
  1183.     }
  1184.   else if (yyn == 0)
  1185.     goto yyerrpop;
  1186.  
  1187.   if (yyn == YYFINAL)
  1188.     YYACCEPT;
  1189.  
  1190. #if YYDEBUG != 0
  1191.   if (yydebug)
  1192.     fprintf(stderr, "Shifting error token, ");
  1193. #endif
  1194.  
  1195.   *++yyvsp = yylval;
  1196. #ifdef YYLSP_NEEDED
  1197.   *++yylsp = yylloc;
  1198. #endif
  1199.  
  1200.   yystate = yyn;
  1201.   goto yynewstate;
  1202. }
  1203. #line 297 "getdate.y"
  1204.  
  1205.  
  1206. /* Month and day table. */
  1207. static TABLE    MonthDayTable[] = {
  1208.     { "january",    tMONTH,  1 },
  1209.     { "february",    tMONTH,  2 },
  1210.     { "march",        tMONTH,  3 },
  1211.     { "april",        tMONTH,  4 },
  1212.     { "may",        tMONTH,  5 },
  1213.     { "june",        tMONTH,  6 },
  1214.     { "july",        tMONTH,  7 },
  1215.     { "august",        tMONTH,  8 },
  1216.     { "september",    tMONTH,  9 },
  1217.     { "sept",        tMONTH,  9 },
  1218.     { "october",    tMONTH, 10 },
  1219.     { "november",    tMONTH, 11 },
  1220.     { "december",    tMONTH, 12 },
  1221.     { "sunday",        tDAY, 0 },
  1222.     { "monday",        tDAY, 1 },
  1223.     { "tuesday",    tDAY, 2 },
  1224.     { "tues",        tDAY, 2 },
  1225.     { "wednesday",    tDAY, 3 },
  1226.     { "wednes",        tDAY, 3 },
  1227.     { "thursday",    tDAY, 4 },
  1228.     { "thur",        tDAY, 4 },
  1229.     { "thurs",        tDAY, 4 },
  1230.     { "friday",        tDAY, 5 },
  1231.     { "saturday",    tDAY, 6 },
  1232.     { NULL }
  1233. };
  1234.  
  1235. /* Time units table. */
  1236. static TABLE    UnitsTable[] = {
  1237.     { "year",        tMONTH_UNIT,    12 },
  1238.     { "month",        tMONTH_UNIT,    1 },
  1239.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1240.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1241.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1242.     { "hour",        tMINUTE_UNIT,    60 },
  1243.     { "minute",        tMINUTE_UNIT,    1 },
  1244.     { "min",        tMINUTE_UNIT,    1 },
  1245.     { "second",        tSEC_UNIT,    1 },
  1246.     { "sec",        tSEC_UNIT,    1 },
  1247.     { NULL }
  1248. };
  1249.  
  1250. /* Assorted relative-time words. */
  1251. static TABLE    OtherTable[] = {
  1252.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1253.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1254.     { "today",        tMINUTE_UNIT,    0 },
  1255.     { "now",        tMINUTE_UNIT,    0 },
  1256.     { "last",        tUNUMBER,    -1 },
  1257.     { "this",        tMINUTE_UNIT,    0 },
  1258.     { "next",        tUNUMBER,    2 },
  1259.     { "first",        tUNUMBER,    1 },
  1260. /*  { "second",        tUNUMBER,    2 }, */
  1261.     { "third",        tUNUMBER,    3 },
  1262.     { "fourth",        tUNUMBER,    4 },
  1263.     { "fifth",        tUNUMBER,    5 },
  1264.     { "sixth",        tUNUMBER,    6 },
  1265.     { "seventh",    tUNUMBER,    7 },
  1266.     { "eighth",        tUNUMBER,    8 },
  1267.     { "ninth",        tUNUMBER,    9 },
  1268.     { "tenth",        tUNUMBER,    10 },
  1269.     { "eleventh",    tUNUMBER,    11 },
  1270.     { "twelfth",    tUNUMBER,    12 },
  1271.     { "ago",        tAGO,    1 },
  1272.     { NULL }
  1273. };
  1274.  
  1275. /* The timezone table. */
  1276. /* Some of these are commented out because a time_t can't store a float. */
  1277. static TABLE    TimezoneTable[] = {
  1278.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  1279.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  1280.     { "utc",    tZONE,     HOUR( 0) },
  1281.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  1282.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  1283.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  1284.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  1285. #if    0
  1286.     /* For completeness.  BST is also British Summer, and GST is
  1287.      * also Guam Standard. */
  1288.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  1289.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  1290. #endif
  1291. #if 0
  1292.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  1293.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  1294.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  1295. #endif
  1296.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  1297.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  1298.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  1299.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  1300.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  1301.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  1302.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  1303.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  1304.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  1305.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  1306.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  1307.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  1308.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  1309.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  1310.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  1311.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  1312.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  1313.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  1314.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  1315.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  1316.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  1317.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  1318.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  1319.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  1320.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  1321.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  1322.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  1323.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  1324. #if 0
  1325.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  1326. #endif
  1327.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  1328.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  1329. #if 0
  1330.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  1331. #endif
  1332.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  1333. #if    0
  1334.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  1335.      * also Swedish Summer. */
  1336.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  1337.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  1338. #endif    /* 0 */
  1339.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  1340.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  1341. #if 0
  1342.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  1343. #endif
  1344.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  1345.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  1346. #if 0
  1347.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  1348.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  1349. #endif
  1350.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  1351.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  1352.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  1353.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  1354.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  1355.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  1356.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  1357.     {  NULL  }
  1358. };
  1359.  
  1360. /* Military timezone table. */
  1361. static TABLE    MilitaryTable[] = {
  1362.     { "a",    tZONE,    HOUR(  1) },
  1363.     { "b",    tZONE,    HOUR(  2) },
  1364.     { "c",    tZONE,    HOUR(  3) },
  1365.     { "d",    tZONE,    HOUR(  4) },
  1366.     { "e",    tZONE,    HOUR(  5) },
  1367.     { "f",    tZONE,    HOUR(  6) },
  1368.     { "g",    tZONE,    HOUR(  7) },
  1369.     { "h",    tZONE,    HOUR(  8) },
  1370.     { "i",    tZONE,    HOUR(  9) },
  1371.     { "k",    tZONE,    HOUR( 10) },
  1372.     { "l",    tZONE,    HOUR( 11) },
  1373.     { "m",    tZONE,    HOUR( 12) },
  1374.     { "n",    tZONE,    HOUR(- 1) },
  1375.     { "o",    tZONE,    HOUR(- 2) },
  1376.     { "p",    tZONE,    HOUR(- 3) },
  1377.     { "q",    tZONE,    HOUR(- 4) },
  1378.     { "r",    tZONE,    HOUR(- 5) },
  1379.     { "s",    tZONE,    HOUR(- 6) },
  1380.     { "t",    tZONE,    HOUR(- 7) },
  1381.     { "u",    tZONE,    HOUR(- 8) },
  1382.     { "v",    tZONE,    HOUR(- 9) },
  1383.     { "w",    tZONE,    HOUR(-10) },
  1384.     { "x",    tZONE,    HOUR(-11) },
  1385.     { "y",    tZONE,    HOUR(-12) },
  1386.     { "z",    tZONE,    HOUR(  0) },
  1387.     { NULL }
  1388. };
  1389.  
  1390.  
  1391.  
  1392.  
  1393. /* ARGSUSED */
  1394. int
  1395. yyerror(s)
  1396.     char    *s;
  1397. {
  1398.   return 0;
  1399. }
  1400.  
  1401.  
  1402. static time_t
  1403. ToSeconds(Hours, Minutes, Seconds, Meridian)
  1404.     time_t    Hours;
  1405.     time_t    Minutes;
  1406.     time_t    Seconds;
  1407.     MERIDIAN    Meridian;
  1408. {
  1409.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1410.     return -1;
  1411.     switch (Meridian) {
  1412.     case MER24:
  1413.     if (Hours < 0 || Hours > 23)
  1414.         return -1;
  1415.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1416.     case MERam:
  1417.     if (Hours < 1 || Hours > 12)
  1418.         return -1;
  1419.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1420.     case MERpm:
  1421.     if (Hours < 1 || Hours > 12)
  1422.         return -1;
  1423.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1424.     }
  1425.     /* NOTREACHED */
  1426. }
  1427.  
  1428.  
  1429. static time_t
  1430. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1431.     time_t    Month;
  1432.     time_t    Day;
  1433.     time_t    Year;
  1434.     time_t    Hours;
  1435.     time_t    Minutes;
  1436.     time_t    Seconds;
  1437.     MERIDIAN    Meridian;
  1438.     DSTMODE    DSTmode;
  1439. {
  1440.     static int    DaysInMonth[12] = {
  1441.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1442.     };
  1443.     time_t    tod;
  1444.     time_t    Julian;
  1445.     int        i;
  1446.  
  1447.     if (Year < 0)
  1448.     Year = -Year;
  1449.     if (Year < 100)
  1450.     Year += 1900;
  1451.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1452.             ? 29 : 28;
  1453.     if (Year < EPOCH || Year > 1999
  1454.      || Month < 1 || Month > 12
  1455.      /* Lint fluff:  "conversion from long may lose accuracy" */
  1456.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  1457.     return -1;
  1458.  
  1459.     for (Julian = Day - 1, i = 0; i < Month; i++)
  1460.     Julian += DaysInMonth[i];
  1461.     for (i = EPOCH; i < Year; i++)
  1462.     Julian += 365 + (i % 4 == 0);
  1463.     Julian *= SECSPERDAY;
  1464.     Julian += yyTimezone * 60L;
  1465.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  1466.     return -1;
  1467.     Julian += tod;
  1468.     if (DSTmode == DSTon
  1469.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  1470.     Julian -= 60 * 60;
  1471.     return Julian;
  1472. }
  1473.  
  1474.  
  1475. static time_t
  1476. DSTcorrect(Start, Future)
  1477.     time_t    Start;
  1478.     time_t    Future;
  1479. {
  1480.     time_t    StartDay;
  1481.     time_t    FutureDay;
  1482.  
  1483.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  1484.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  1485.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1486. }
  1487.  
  1488.  
  1489. static time_t
  1490. RelativeDate(Start, DayOrdinal, DayNumber)
  1491.     time_t    Start;
  1492.     time_t    DayOrdinal;
  1493.     time_t    DayNumber;
  1494. {
  1495.     struct tm    *tm;
  1496.     time_t    now;
  1497.  
  1498.     now = Start;
  1499.     tm = localtime(&now);
  1500.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1501.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1502.     return DSTcorrect(Start, now);
  1503. }
  1504.  
  1505.  
  1506. static time_t
  1507. RelativeMonth(Start, RelMonth)
  1508.     time_t    Start;
  1509.     time_t    RelMonth;
  1510. {
  1511.     struct tm    *tm;
  1512.     time_t    Month;
  1513.     time_t    Year;
  1514.  
  1515.     if (RelMonth == 0)
  1516.     return 0;
  1517.     tm = localtime(&Start);
  1518.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1519.     Year = Month / 12;
  1520.     Month = Month % 12 + 1;
  1521.     return DSTcorrect(Start,
  1522.         Convert(Month, (time_t)tm->tm_mday, Year,
  1523.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1524.         MER24, DSTmaybe));
  1525. }
  1526.  
  1527.  
  1528. static int
  1529. LookupWord(buff)
  1530.     char        *buff;
  1531. {
  1532.     register char    *p;
  1533.     register char    *q;
  1534.     register TABLE    *tp;
  1535.     int            i;
  1536.     int            abbrev;
  1537.  
  1538.     /* Make it lowercase. */
  1539.     for (p = buff; *p; p++)
  1540.     if (isupper(*p))
  1541.         *p = tolower(*p);
  1542.  
  1543.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  1544.     yylval.Meridian = MERam;
  1545.     return tMERIDIAN;
  1546.     }
  1547.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  1548.     yylval.Meridian = MERpm;
  1549.     return tMERIDIAN;
  1550.     }
  1551.  
  1552.     /* See if we have an abbreviation for a month. */
  1553.     if (strlen(buff) == 3)
  1554.     abbrev = 1;
  1555.     else if (strlen(buff) == 4 && buff[3] == '.') {
  1556.     abbrev = 1;
  1557.     buff[3] = '\0';
  1558.     }
  1559.     else
  1560.     abbrev = 0;
  1561.  
  1562.     for (tp = MonthDayTable; tp->name; tp++) {
  1563.     if (abbrev) {
  1564.         if (strncmp(buff, tp->name, 3) == 0) {
  1565.         yylval.Number = tp->value;
  1566.         return tp->type;
  1567.         }
  1568.     }
  1569.     else if (strcmp(buff, tp->name) == 0) {
  1570.         yylval.Number = tp->value;
  1571.         return tp->type;
  1572.     }
  1573.     }
  1574.  
  1575.     for (tp = TimezoneTable; tp->name; tp++)
  1576.     if (strcmp(buff, tp->name) == 0) {
  1577.         yylval.Number = tp->value;
  1578.         return tp->type;
  1579.     }
  1580.  
  1581.     if (strcmp(buff, "dst") == 0) 
  1582.     return tDST;
  1583.  
  1584.     for (tp = UnitsTable; tp->name; tp++)
  1585.     if (strcmp(buff, tp->name) == 0) {
  1586.         yylval.Number = tp->value;
  1587.         return tp->type;
  1588.     }
  1589.  
  1590.     /* Strip off any plural and try the units table again. */
  1591.     i = strlen(buff) - 1;
  1592.     if (buff[i] == 's') {
  1593.     buff[i] = '\0';
  1594.     for (tp = UnitsTable; tp->name; tp++)
  1595.         if (strcmp(buff, tp->name) == 0) {
  1596.         yylval.Number = tp->value;
  1597.         return tp->type;
  1598.         }
  1599.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1600.     }
  1601.  
  1602.     for (tp = OtherTable; tp->name; tp++)
  1603.     if (strcmp(buff, tp->name) == 0) {
  1604.         yylval.Number = tp->value;
  1605.         return tp->type;
  1606.     }
  1607.  
  1608.     /* Military timezones. */
  1609.     if (buff[1] == '\0' && isalpha(*buff)) {
  1610.     for (tp = MilitaryTable; tp->name; tp++)
  1611.         if (strcmp(buff, tp->name) == 0) {
  1612.         yylval.Number = tp->value;
  1613.         return tp->type;
  1614.         }
  1615.     }
  1616.  
  1617.     /* Drop out any periods and try the timezone table again. */
  1618.     for (i = 0, p = q = buff; *q; q++)
  1619.     if (*q != '.')
  1620.         *p++ = *q;
  1621.     else
  1622.         i++;
  1623.     *p = '\0';
  1624.     if (i)
  1625.     for (tp = TimezoneTable; tp->name; tp++)
  1626.         if (strcmp(buff, tp->name) == 0) {
  1627.         yylval.Number = tp->value;
  1628.         return tp->type;
  1629.         }
  1630.  
  1631.     return tID;
  1632. }
  1633.  
  1634.  
  1635. int
  1636. yylex()
  1637. {
  1638.     register char    c;
  1639.     register char    *p;
  1640.     char        buff[20];
  1641.     int            Count;
  1642.     int            sign;
  1643.  
  1644.     for ( ; ; ) {
  1645.     while (isspace(*yyInput))
  1646.         yyInput++;
  1647.  
  1648.     if (isdigit(c = *yyInput) || c == '-' || c == '+') {
  1649.         if (c == '-' || c == '+') {
  1650.         sign = c == '-' ? -1 : 1;
  1651.         if (!isdigit(*++yyInput))
  1652.             /* skip the '-' sign */
  1653.             continue;
  1654.         }
  1655.         else
  1656.         sign = 0;
  1657.         for (yylval.Number = 0; isdigit(c = *yyInput++); )
  1658.         yylval.Number = 10 * yylval.Number + c - '0';
  1659.         yyInput--;
  1660.         if (sign < 0)
  1661.         yylval.Number = -yylval.Number;
  1662.         return sign ? tSNUMBER : tUNUMBER;
  1663.     }
  1664.     if (isalpha(c)) {
  1665.         for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
  1666.         if (p < &buff[sizeof buff - 1])
  1667.             *p++ = c;
  1668.         *p = '\0';
  1669.         yyInput--;
  1670.         return LookupWord(buff);
  1671.     }
  1672.     if (c != '(')
  1673.         return *yyInput++;
  1674.     Count = 0;
  1675.     do {
  1676.         c = *yyInput++;
  1677.         if (c == '\0')
  1678.         return c;
  1679.         if (c == '(')
  1680.         Count++;
  1681.         else if (c == ')')
  1682.         Count--;
  1683.     } while (Count > 0);
  1684.     }
  1685. }
  1686.  
  1687.  
  1688. time_t
  1689. get_date(p, now)
  1690.     char        *p;
  1691.     struct timeb    *now;
  1692. {
  1693.     struct tm        *tm;
  1694.     struct timeb    ftz;
  1695.     time_t        Start;
  1696.     time_t        tod;
  1697.  
  1698.     yyInput = p;
  1699.     if (now == NULL) {
  1700.     now = &ftz;
  1701. #if    defined(FTIME_MISSING)
  1702.     (void)time(&ftz.time);
  1703.     /* Set the timezone global. */
  1704.     tzset();
  1705. #if    defined(HAVE_TIMEZONE)
  1706.     tm = localtime(&ftz.time);
  1707.     ftz.timezone = tm->tm_gmtoff / 60;
  1708. #else
  1709. #if    defined(timezone)
  1710.     ftz.tzone = (int) timezone / 60;
  1711. #else
  1712.     ftz.timezone = (int) timezone / 60;
  1713. #endif    /* defined(timezone) */
  1714. #endif    /* defined(HAVE_TIMEZONE) */
  1715. #else
  1716.     (void)ftime(&ftz);
  1717. #endif    /* defined(FTIME_MISSING) */
  1718.     }
  1719.  
  1720.     tm = localtime(&now->time);
  1721.     yyYear = tm->tm_year;
  1722.     yyMonth = tm->tm_mon + 1;
  1723.     yyDay = tm->tm_mday;
  1724. #if    defined(timezone)
  1725.     yyTimezone = now->tzone;
  1726. #else
  1727.     yyTimezone = now->timezone;
  1728. #endif    /* defined(timezone) */
  1729.     yyDSTmode = DSTmaybe;
  1730.     yyHour = 0;
  1731.     yyMinutes = 0;
  1732.     yySeconds = 0;
  1733.     yyMeridian = MER24;
  1734.     yyRelSeconds = 0;
  1735.     yyRelMonth = 0;
  1736.     yyHaveDate = 0;
  1737.     yyHaveDay = 0;
  1738.     yyHaveRel = 0;
  1739.     yyHaveTime = 0;
  1740.     yyHaveZone = 0;
  1741.  
  1742.     if (yyparse()
  1743.      || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1744.     return -1;
  1745.  
  1746.     if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1747.     Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1748.             yyMeridian, yyDSTmode);
  1749.     if (Start < 0)
  1750.         return -1;
  1751.     }
  1752.     else {
  1753.     Start = now->time;
  1754.     if (!yyHaveRel)
  1755.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1756.     }
  1757.  
  1758.     Start += yyRelSeconds;
  1759.     Start += RelativeMonth(Start, yyRelMonth);
  1760.  
  1761.     if (yyHaveDay && !yyHaveDate) {
  1762.     tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
  1763.     Start += tod;
  1764.     }
  1765.  
  1766.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  1767.      * from the error return value.  (Alternately could set errno on error.) */
  1768.     return Start == -1 ? 0 : Start;
  1769. }
  1770.  
  1771.  
  1772. #if    defined(TEST)
  1773.  
  1774. /* ARGSUSED */
  1775. main(ac, av)
  1776.     int        ac;
  1777.     char    *av[];
  1778. {
  1779.     char    buff[128];
  1780.     time_t    d;
  1781.  
  1782.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1783.     (void)fflush(stdout);
  1784.     while (gets(buff) && buff[0]) {
  1785.     d = get_date(buff, (struct timeb *)NULL);
  1786.     if (d == -1)
  1787.         (void)printf("Bad format - couldn't convert.\n");
  1788.     else
  1789.         (void)printf("%s", ctime(&d));
  1790.     (void)printf("\t> ");
  1791.     (void)fflush(stdout);
  1792.     }
  1793.     exit(0);
  1794.     /* NOTREACHED */
  1795. }
  1796. #endif    /* defined(TEST) */
  1797.