* parsetime.c - parse time for at(1)
* Copyright (C) 1993, 1994 Thomas Koenig
*
* parsetime.c - parse time for at(1)
* Copyright (C) 1993, 1994 Thomas Koenig
*
JAN, FEB, MAR, APR, MAY, JUN,
JUL, AUG, SEP, OCT, NOV, DEC,
SUN, MON, TUE, WED, THU, FRI, SAT,
JAN, FEB, MAR, APR, MAY, JUN,
JUL, AUG, SEP, OCT, NOV, DEC,
SUN, MON, TUE, WED, THU, FRI, SAT,
- case AM:
- case PM:
- if (hour > 12)
- panic("garbled time");
-
- if (sc_tokid == PM) {
- if (hour != 12) /* 12:xx PM is 12:xx, not 24:xx */
- hour += 12;
- } else {
- if (hour == 12) /* 12:xx AM is 00:xx, not 12:xx */
- hour = 0;
- }
- if (UTC != token())
- break; /* else fallthrough */
-
- case UTC:
- hour += tm->tm_gmtoff/(60*60);
- while (hour < 0)
- hour += 24;
- minute += (tm->tm_gmtoff/60);
- while (minute < 0)
- minute += 60;
- tm->tm_gmtoff = 0;
- token();
- break;
- default:
- if (hour > 23)
- panic("garbled time");
- break;
+ case AM:
+ case PM:
+ if (hour > 12)
+ panic("garbled time");
+
+ if (sc_tokid == PM) {
+ if (hour != 12) /* 12:xx PM is 12:xx, not 24:xx */
+ hour += 12;
+ } else {
+ if (hour == 12) /* 12:xx AM is 00:xx, not 12:xx */
+ hour = 0;
+ }
+ if (UTC != token())
+ break; /* else fallthrough */
+
+ case UTC:
+ hour += tm->tm_gmtoff/(60*60);
+ while (hour < 0)
+ hour += 24;
+ minute += (tm->tm_gmtoff/60);
+ while (minute < 0)
+ minute += 60;
+ tm->tm_gmtoff = 0;
+ token();
+ break;
+ default:
+ if (hour > 23)
+ panic("garbled time");
+ break;
* a relative offset, it's okay to bump things
* If minutes are the same assume tomorrow was meant
*/
* a relative offset, it's okay to bump things
* If minutes are the same assume tomorrow was meant
*/
- if ((sc_tokid == EOF || sc_tokid == PLUS) &&
- ((tm->tm_hour > hour) || ((tm->tm_hour == hour) && (tm->tm_min >= minute)))) {
- tm->tm_mday++;
- tm->tm_wday++;
+ if ((sc_tokid == EOF || sc_tokid == PLUS) &&
+ ((tm->tm_hour > hour) || ((tm->tm_hour == hour) && (tm->tm_min >= minute)))) {
+ tm->tm_mday++;
+ tm->tm_wday++;
-assign_date(struct tm *tm, long mday, long mon, long year)
+assign_date(struct tm *tm, int mday, int mon, int year)
* month() picks apart a month specification
*
* /[<month> NUMBER [NUMBER]] \
* |[TOMORROW] |
* |[DAY OF WEEK] |
* |NUMBER [SLASH NUMBER [SLASH NUMBER]]|
* month() picks apart a month specification
*
* /[<month> NUMBER [NUMBER]] \
* |[TOMORROW] |
* |[DAY OF WEEK] |
* |NUMBER [SLASH NUMBER [SLASH NUMBER]]|
assign_date(tm, mday, mon, year);
break;
assign_date(tm, mday, mon, year);
break;
time_t nowtimer, runtimer;
struct tm nowtime, runtime;
int hr = 0;
time_t nowtimer, runtimer;
struct tm nowtime, runtime;
int hr = 0;
- case NOW:
- if (scc < 1) {
- return nowtimer;
- }
- /* now is optional prefix for PLUS tree */
- expect(PLUS);
- case PLUS:
- plus(&runtime);
- break;
-
- case NUMBER:
- tod(&runtime);
- month(&runtime);
- break;
-
- /* evil coding for TEATIME|NOON|MIDNIGHT - we've initialised
- * hr to zero up above, then fall into this case in such a
- * way so we add +12 +4 hours to it for teatime, +12 hours
- * to it for noon, and nothing at all for midnight, then
- * set our runtime to that hour before leaping into the
- * month scanner
- */
- case TEATIME:
- hr += 4;
- case NOON:
- hr += 12;
- case MIDNIGHT:
- if (runtime.tm_hour >= hr) {
- runtime.tm_mday++;
- runtime.tm_wday++;
- }
- runtime.tm_hour = hr;
- runtime.tm_min = 0;
- token();
- /* FALLTHROUGH to month setting */
- default:
- month(&runtime);
- break;
+ case NOW:
+ if (scc < 1) {
+ return nowtimer;
+ }
+ /* now is optional prefix for PLUS/NEXT tree */
+ switch (token()) {
+ case PLUS:
+ plus(&runtime);
+ break;
+
+ case NEXT:
+ next(&runtime);
+ break;
+
+ default:
+ plonk(sc_token);
+ break;
+ }
+ break;
+
+ case PLUS:
+ plus(&runtime);
+ break;
+
+ case NEXT:
+ next(&runtime);
+ break;
+
+ case NUMBER:
+ tod(&runtime);
+ month(&runtime);
+ break;
+
+ /* evil coding for TEATIME|NOON|MIDNIGHT - we've initialised
+ * hr to zero up above, then fall into this case in such a
+ * way so we add +12 +4 hours to it for teatime, +12 hours
+ * to it for noon, and nothing at all for midnight, then
+ * set our runtime to that hour before leaping into the
+ * month scanner
+ */
+ case TEATIME:
+ hr += 4;
+ case NOON:
+ hr += 12;
+ case MIDNIGHT:
+ if (runtime.tm_hour >= hr) {
+ runtime.tm_mday++;
+ runtime.tm_wday++;
+ }
+ runtime.tm_hour = hr;
+ runtime.tm_min = 0;
+ token();
+ /* FALLTHROUGH to month setting */
+ default:
+ month(&runtime);
+ break;