xref: /titanic_41/usr/src/cmd/cron/att1.y (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate %{
2*7c478bd9Sstevel@tonic-gate /*
3*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate  * with the License.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
14*7c478bd9Sstevel@tonic-gate  *
15*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate  */
23*7c478bd9Sstevel@tonic-gate %}
24*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
25*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate %{
29*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.4	*/
30*7c478bd9Sstevel@tonic-gate %}
31*7c478bd9Sstevel@tonic-gate %{
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include "stdio.h"
34*7c478bd9Sstevel@tonic-gate #include "ctype.h"
35*7c478bd9Sstevel@tonic-gate #include "time.h"
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate extern int yylex(void);
38*7c478bd9Sstevel@tonic-gate extern void yyerror();
39*7c478bd9Sstevel@tonic-gate extern void atabort(char *);
40*7c478bd9Sstevel@tonic-gate int yyparse(void);
41*7c478bd9Sstevel@tonic-gate extern	int	gmtflag;
42*7c478bd9Sstevel@tonic-gate extern	int	mday[];
43*7c478bd9Sstevel@tonic-gate extern	struct	tm *tp, at, rt;
44*7c478bd9Sstevel@tonic-gate %}
45*7c478bd9Sstevel@tonic-gate %token	TIME
46*7c478bd9Sstevel@tonic-gate %token	NOW
47*7c478bd9Sstevel@tonic-gate %token	NOON
48*7c478bd9Sstevel@tonic-gate %token	MIDNIGHT
49*7c478bd9Sstevel@tonic-gate %token	MINUTE
50*7c478bd9Sstevel@tonic-gate %token	HOUR
51*7c478bd9Sstevel@tonic-gate %token	DAY
52*7c478bd9Sstevel@tonic-gate %token	WEEK
53*7c478bd9Sstevel@tonic-gate %token	MONTH
54*7c478bd9Sstevel@tonic-gate %token	YEAR
55*7c478bd9Sstevel@tonic-gate %token	UNIT
56*7c478bd9Sstevel@tonic-gate %token	SUFF
57*7c478bd9Sstevel@tonic-gate %token	ZONE
58*7c478bd9Sstevel@tonic-gate %token	AM
59*7c478bd9Sstevel@tonic-gate %token	PM
60*7c478bd9Sstevel@tonic-gate %token	ZULU
61*7c478bd9Sstevel@tonic-gate %token	NEXT
62*7c478bd9Sstevel@tonic-gate %token	NUMB
63*7c478bd9Sstevel@tonic-gate %token	COLON
64*7c478bd9Sstevel@tonic-gate %token	COMMA
65*7c478bd9Sstevel@tonic-gate %token	PLUS
66*7c478bd9Sstevel@tonic-gate %token	UNKNOWN
67*7c478bd9Sstevel@tonic-gate %right	NUMB
68*7c478bd9Sstevel@tonic-gate %%
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate args
71*7c478bd9Sstevel@tonic-gate 	: time ampm timezone date incr {
72*7c478bd9Sstevel@tonic-gate 		if (at.tm_min >= 60 || at.tm_hour >= 24)
73*7c478bd9Sstevel@tonic-gate 			atabort("bad time");
74*7c478bd9Sstevel@tonic-gate 		if (at.tm_mon >= 12 || at.tm_mday > mday[at.tm_mon])
75*7c478bd9Sstevel@tonic-gate 			atabort("bad date");
76*7c478bd9Sstevel@tonic-gate 		if (at.tm_year >= 1900)
77*7c478bd9Sstevel@tonic-gate 			at.tm_year -= 1900;
78*7c478bd9Sstevel@tonic-gate 		if (at.tm_year < 70 || at.tm_year >= 139)
79*7c478bd9Sstevel@tonic-gate 			atabort("bad year");
80*7c478bd9Sstevel@tonic-gate 	}
81*7c478bd9Sstevel@tonic-gate 	| time ampm timezone date incr UNKNOWN {
82*7c478bd9Sstevel@tonic-gate 		yyerror();
83*7c478bd9Sstevel@tonic-gate 	}
84*7c478bd9Sstevel@tonic-gate 	;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate time
87*7c478bd9Sstevel@tonic-gate 	: hour {
88*7c478bd9Sstevel@tonic-gate 		at.tm_hour = $1;
89*7c478bd9Sstevel@tonic-gate 	}
90*7c478bd9Sstevel@tonic-gate 	| hour COLON number {
91*7c478bd9Sstevel@tonic-gate 		at.tm_hour = $1;
92*7c478bd9Sstevel@tonic-gate 		at.tm_min = $3;
93*7c478bd9Sstevel@tonic-gate 		$3 = $1;
94*7c478bd9Sstevel@tonic-gate 	}
95*7c478bd9Sstevel@tonic-gate 	| hour minute {
96*7c478bd9Sstevel@tonic-gate 		at.tm_hour = $1;
97*7c478bd9Sstevel@tonic-gate 		at.tm_min = $2;
98*7c478bd9Sstevel@tonic-gate 		$2 = $1;
99*7c478bd9Sstevel@tonic-gate 	}
100*7c478bd9Sstevel@tonic-gate 	| TIME {
101*7c478bd9Sstevel@tonic-gate 		switch ($1) {
102*7c478bd9Sstevel@tonic-gate 		case NOON:
103*7c478bd9Sstevel@tonic-gate 			at.tm_hour = 12;
104*7c478bd9Sstevel@tonic-gate 			break;
105*7c478bd9Sstevel@tonic-gate 		case MIDNIGHT:
106*7c478bd9Sstevel@tonic-gate 			at.tm_hour = 0;
107*7c478bd9Sstevel@tonic-gate 			break;
108*7c478bd9Sstevel@tonic-gate 		case NOW:
109*7c478bd9Sstevel@tonic-gate 			at.tm_hour = tp->tm_hour;
110*7c478bd9Sstevel@tonic-gate 			at.tm_min = tp->tm_min;
111*7c478bd9Sstevel@tonic-gate 			at.tm_sec = tp->tm_sec;
112*7c478bd9Sstevel@tonic-gate 			break;
113*7c478bd9Sstevel@tonic-gate 		}
114*7c478bd9Sstevel@tonic-gate 	}
115*7c478bd9Sstevel@tonic-gate 	;
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate ampm
118*7c478bd9Sstevel@tonic-gate 	: /*empty*/
119*7c478bd9Sstevel@tonic-gate 	{
120*7c478bd9Sstevel@tonic-gate 	}
121*7c478bd9Sstevel@tonic-gate 	| SUFF {
122*7c478bd9Sstevel@tonic-gate 		switch ($1) {
123*7c478bd9Sstevel@tonic-gate 		case PM:
124*7c478bd9Sstevel@tonic-gate 			if (at.tm_hour < 1 || at.tm_hour > 12)
125*7c478bd9Sstevel@tonic-gate 				atabort("bad hour");
126*7c478bd9Sstevel@tonic-gate 				at.tm_hour %= 12;
127*7c478bd9Sstevel@tonic-gate 				at.tm_hour += 12;
128*7c478bd9Sstevel@tonic-gate 				break;
129*7c478bd9Sstevel@tonic-gate 		case AM:
130*7c478bd9Sstevel@tonic-gate 			if (at.tm_hour < 1 || at.tm_hour > 12)
131*7c478bd9Sstevel@tonic-gate 				atabort("bad hour");
132*7c478bd9Sstevel@tonic-gate 			at.tm_hour %= 12;
133*7c478bd9Sstevel@tonic-gate 			break;
134*7c478bd9Sstevel@tonic-gate 		}
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 	;
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate timezone
139*7c478bd9Sstevel@tonic-gate 	: /*empty*/
140*7c478bd9Sstevel@tonic-gate 	{
141*7c478bd9Sstevel@tonic-gate 	}
142*7c478bd9Sstevel@tonic-gate 	| ZONE {
143*7c478bd9Sstevel@tonic-gate 		if (at.tm_hour == 24 && at.tm_min != 0)
144*7c478bd9Sstevel@tonic-gate 			atabort("bad time");
145*7c478bd9Sstevel@tonic-gate 		at.tm_hour %= 24;
146*7c478bd9Sstevel@tonic-gate 		gmtflag = 1;
147*7c478bd9Sstevel@tonic-gate 	}
148*7c478bd9Sstevel@tonic-gate 	;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate date
151*7c478bd9Sstevel@tonic-gate 	: /*empty*/ {
152*7c478bd9Sstevel@tonic-gate 		at.tm_mday = tp->tm_mday;
153*7c478bd9Sstevel@tonic-gate 		at.tm_mon = tp->tm_mon;
154*7c478bd9Sstevel@tonic-gate 		at.tm_year = tp->tm_year;
155*7c478bd9Sstevel@tonic-gate 		if ((at.tm_hour < tp->tm_hour)
156*7c478bd9Sstevel@tonic-gate 			|| ((at.tm_hour==tp->tm_hour)&&(at.tm_min<tp->tm_min)))
157*7c478bd9Sstevel@tonic-gate 			rt.tm_mday++;
158*7c478bd9Sstevel@tonic-gate 	}
159*7c478bd9Sstevel@tonic-gate 	| MONTH number {
160*7c478bd9Sstevel@tonic-gate 		at.tm_mon = $1;
161*7c478bd9Sstevel@tonic-gate 		at.tm_mday = $2;
162*7c478bd9Sstevel@tonic-gate 		at.tm_year = tp->tm_year;
163*7c478bd9Sstevel@tonic-gate 		if (at.tm_mon < tp->tm_mon)
164*7c478bd9Sstevel@tonic-gate 			at.tm_year++;
165*7c478bd9Sstevel@tonic-gate 	}
166*7c478bd9Sstevel@tonic-gate 	| MONTH number COMMA number {
167*7c478bd9Sstevel@tonic-gate 		at.tm_mon = $1;
168*7c478bd9Sstevel@tonic-gate 		at.tm_mday = $2;
169*7c478bd9Sstevel@tonic-gate 		at.tm_year = $4;
170*7c478bd9Sstevel@tonic-gate 	}
171*7c478bd9Sstevel@tonic-gate 	| DAY {
172*7c478bd9Sstevel@tonic-gate 		at.tm_mon = tp->tm_mon;
173*7c478bd9Sstevel@tonic-gate 		at.tm_mday = tp->tm_mday;
174*7c478bd9Sstevel@tonic-gate 		at.tm_year = tp->tm_year;
175*7c478bd9Sstevel@tonic-gate 		if ($1 < 7) {
176*7c478bd9Sstevel@tonic-gate 			rt.tm_mday = $1 - tp->tm_wday;
177*7c478bd9Sstevel@tonic-gate 			if (rt.tm_mday < 0)
178*7c478bd9Sstevel@tonic-gate 				rt.tm_mday += 7;
179*7c478bd9Sstevel@tonic-gate 		} else if ($1 == 8)
180*7c478bd9Sstevel@tonic-gate 			rt.tm_mday += 1;
181*7c478bd9Sstevel@tonic-gate 	}
182*7c478bd9Sstevel@tonic-gate 	;
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate incr
185*7c478bd9Sstevel@tonic-gate 	: /*empty*/
186*7c478bd9Sstevel@tonic-gate 	| NEXT UNIT	{ addincr:
187*7c478bd9Sstevel@tonic-gate 		switch ($2) {
188*7c478bd9Sstevel@tonic-gate 		case MINUTE:
189*7c478bd9Sstevel@tonic-gate 			rt.tm_min += $1;
190*7c478bd9Sstevel@tonic-gate 			break;
191*7c478bd9Sstevel@tonic-gate 		case HOUR:
192*7c478bd9Sstevel@tonic-gate 			rt.tm_hour += $1;
193*7c478bd9Sstevel@tonic-gate 			break;
194*7c478bd9Sstevel@tonic-gate 		case DAY:
195*7c478bd9Sstevel@tonic-gate 			rt.tm_mday += $1;
196*7c478bd9Sstevel@tonic-gate 			break;
197*7c478bd9Sstevel@tonic-gate 		case WEEK:
198*7c478bd9Sstevel@tonic-gate 			rt.tm_mday += $1 * 7;
199*7c478bd9Sstevel@tonic-gate 			break;
200*7c478bd9Sstevel@tonic-gate 		case MONTH:
201*7c478bd9Sstevel@tonic-gate 			rt.tm_mon += $1;
202*7c478bd9Sstevel@tonic-gate 			break;
203*7c478bd9Sstevel@tonic-gate 		case YEAR:
204*7c478bd9Sstevel@tonic-gate 			rt.tm_year += $1;
205*7c478bd9Sstevel@tonic-gate 			break;
206*7c478bd9Sstevel@tonic-gate 		}
207*7c478bd9Sstevel@tonic-gate 	}
208*7c478bd9Sstevel@tonic-gate 	| PLUS opt_number UNIT { goto addincr; }
209*7c478bd9Sstevel@tonic-gate 	;
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate hour
212*7c478bd9Sstevel@tonic-gate 	: NUMB		{ $$ = $1; }
213*7c478bd9Sstevel@tonic-gate 	| NUMB NUMB	{ $$ = 10 * $1 + $2; }
214*7c478bd9Sstevel@tonic-gate 	;
215*7c478bd9Sstevel@tonic-gate minute
216*7c478bd9Sstevel@tonic-gate 	: NUMB NUMB	{ $$ = 10 * $1 + $2; }
217*7c478bd9Sstevel@tonic-gate 	;
218*7c478bd9Sstevel@tonic-gate number
219*7c478bd9Sstevel@tonic-gate 	: NUMB		{ $$ = $1; }
220*7c478bd9Sstevel@tonic-gate 	| number NUMB	{ $$ = 10 * $1 + $2; }
221*7c478bd9Sstevel@tonic-gate 	;
222*7c478bd9Sstevel@tonic-gate opt_number
223*7c478bd9Sstevel@tonic-gate 	: /* empty */	{ $$ = 1; }
224*7c478bd9Sstevel@tonic-gate 	| number	{ $$ = $1; }
225*7c478bd9Sstevel@tonic-gate 	;
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate %%
228