home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / useful / dist / gnu / fileutils / build / lib / getdate.c next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  47.6 KB  |  1,934 lines

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