getdate.c 56 KB

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