getdate.c 51 KB

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