home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / daytime.zip / getdate.c < prev    next >
C/C++ Source or Header  |  1998-10-18  |  52KB  |  1,952 lines

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