getdate.c 61 KB

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