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