1 /* Parse dates for touch.
2 Copyright (C) 1989, 1990, 1991 Free Software Foundation Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Written by Jim Kingdon and David MacKenzie. */
22 #if defined (CONFIG_BROKETS)
23 /* We use <config.h> instead of "config.h" so that a compilation
24 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
25 (which it would do because it found this file in $srcdir). */
32 /* The following block of alloca-related preprocessor directives is here
33 solely to allow compilation by non GNU-C compilers of the C parser
34 produced from this file by old versions of bison. Newer versions of
35 bison include a block similar to this one in bison.simple. */
38 #define alloca __builtin_alloca
52 #include <sys/types.h>
60 /* Some old versions of bison generate parsers that use bcopy.
61 That loses on systems that don't provide the function, so we have
62 to redefine it here. */
63 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
64 #define bcopy(from, to, len) memcpy ((to), (from), (len))
69 /* Lexical analyzer's current scan position in the input string. */
72 /* The return value. */
77 #define yyparse posixtime_yyparse
79 static int yyerror ();
89 digitpair /* minutes */
92 if ($1 >= 1 && $1 <= 12)
97 if ($2 >= 1 && $2 <= 31)
102 if ($3 >= 0 && $3 <= 23)
107 if ($4 >= 0 && $4 <= 59)
116 /* Deduce the century based on the year.
117 See POSIX.2 section 4.63.3. */
121 | digitpair digitpair {
122 t.tm_year = $1 * 100 + $2;
123 if (t.tm_year < 1900) {
132 /* Use current year. */
134 tmp = localtime (&now);
135 t.tm_year = tmp->tm_year;
139 seconds : /* empty */ {
143 if ($2 >= 0 && $2 <= 61)
151 digitpair : DIGIT DIGIT {
161 if (ch >= '0' && ch <= '9')
166 else if (ch == '.' || ch == 0)
169 return '?'; /* Cause an error. */
178 /* Parse a POSIX-style date and return it, or (time_t)-1 for an error. */
185 /* Let mktime decide whether it is daylight savings time. */
193 /* Parse a POSIX-style date and return it, or NULL for an error. */
199 if (posixtime (s) == -1)