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. */
21 #define alloca __builtin_alloca
35 #include <sys/types.h>
40 /* Lexical analyzer's current scan position in the input string. */
43 /* The return value. */
48 #define yyparse posixtime_yyparse
50 static int yyerror ();
60 digitpair
/* minutes */
63 if
($1 >= 1 && $1 <= 12)
68 if
($2 >= 1 && $2 <= 31)
73 if
($3 >= 0 && $3 <= 23)
78 if
($4 >= 0 && $4 <= 59)
87 /* Deduce the century based on the year.
88 See POSIX.2 section 4.63.3. */
92 | digitpair digitpair
{
93 t.tm_year
= $1 * 100 + $2;
94 if
(t.tm_year
< 1900) {
103 /* Use current year. */
105 tmp
= localtime
(&now
);
106 t.tm_year
= tmp
->tm_year
;
110 seconds
: /* empty */ {
114 if
($2 >= 0 && $2 <= 61)
122 digitpair
: DIGIT DIGIT
{
132 if
(ch
>= '0' && ch
<= '9')
137 else if
(ch
== '.' || ch
== 0)
140 return
'?'; /* Cause an error. */
149 /* Parse a POSIX-style date and return it, or (time_t)-1 for an error. */
156 /* Let mktime decide whether it is daylight savings time. */
164 /* Parse a POSIX-style date and return it, or NULL for an error. */
170 if
(posixtime
(s
) == -1)