home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / utility-src / fileutils / lib / y.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-31  |  42.2 KB  |  1,720 lines  |  [TEXT/KAHL]

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