home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / cvs-1.8 / cvs-1 / cvs-1.8.1 / lib / getdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  48.5 KB  |  1,945 lines

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