home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / lib-src / getdate.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  49KB  |  1,929 lines

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