3 * Configuration parser for Director Run Configuration
4 * directives, which are part of the Schedule Resource
11 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34 extern struct s_jl joblevels[];
36 /* Forward referenced subroutines */
50 s_wpos, /* 1st, 2nd, ...*/
54 char *name; /* keyword */
55 enum e_state state; /* parser state */
56 int code; /* state value */
59 /* Keywords understood by parser */
60 static struct s_keyw keyw[] = {
61 {N_("on"), s_none, 0},
64 {N_("sun"), s_wday, 0},
65 {N_("mon"), s_wday, 1},
66 {N_("tue"), s_wday, 2},
67 {N_("wed"), s_wday, 3},
68 {N_("thu"), s_wday, 4},
69 {N_("fri"), s_wday, 5},
70 {N_("sat"), s_wday, 6},
71 {N_("jan"), s_month, 0},
72 {N_("feb"), s_month, 1},
73 {N_("mar"), s_month, 2},
74 {N_("apr"), s_month, 3},
75 {N_("may"), s_month, 4},
76 {N_("jun"), s_month, 5},
77 {N_("jul"), s_month, 6},
78 {N_("aug"), s_month, 7},
79 {N_("sep"), s_month, 8},
80 {N_("oct"), s_month, 9},
81 {N_("nov"), s_month, 10},
82 {N_("dec"), s_month, 11},
84 {N_("sunday"), s_wday, 0},
85 {N_("monday"), s_wday, 1},
86 {N_("tuesday"), s_wday, 2},
87 {N_("wednesday"), s_wday, 3},
88 {N_("thursday"), s_wday, 4},
89 {N_("friday"), s_wday, 5},
90 {N_("saturday"), s_wday, 6},
91 {N_("january"), s_month, 0},
92 {N_("february"), s_month, 1},
93 {N_("march"), s_month, 2},
94 {N_("april"), s_month, 3},
95 {N_("june"), s_month, 5},
96 {N_("july"), s_month, 6},
97 {N_("august"), s_month, 7},
98 {N_("september"), s_month, 8},
99 {N_("october"), s_month, 9},
100 {N_("november"), s_month, 10},
101 {N_("december"), s_month, 11},
103 {N_("daily"), s_daily, 0},
104 {N_("weekly"), s_weekly, 0},
105 {N_("monthly"), s_monthly, 0},
106 {N_("hourly"), s_hourly, 0},
108 {N_("1st"), s_wpos, 0},
109 {N_("2nd"), s_wpos, 1},
110 {N_("3rd"), s_wpos, 2},
111 {N_("4th"), s_wpos, 3},
112 {N_("5th"), s_wpos, 4},
114 {N_("first"), s_wpos, 0},
115 {N_("second"), s_wpos, 1},
116 {N_("third"), s_wpos, 2},
117 {N_("fourth"), s_wpos, 3},
118 {N_("fifth"), s_wpos, 4},
122 static int have_hour, have_mday, have_wday, have_month, have_wpos;
126 static void clear_defaults()
128 have_hour = have_mday = have_wday = have_month = have_wpos = TRUE;
129 clear_bit(0,lrun.hour);
130 clear_bits(0, 30, lrun.mday);
131 clear_bits(0, 6, lrun.wday);
132 clear_bits(0, 11, lrun.month);
133 clear_bits(0, 4, lrun.wpos);
136 static void set_defaults()
138 have_hour = have_mday = have_wday = have_month = have_wpos = FALSE;
140 set_bit(0,lrun.hour);
141 set_bits(0, 30, lrun.mday);
142 set_bits(0, 6, lrun.wday);
143 set_bits(0, 11, lrun.month);
144 set_bits(0, 4, lrun.wpos);
148 /* Check if string is a number */
149 static int is_num(char *num)
153 while ((ch = *p++)) {
154 if (ch < '0' || ch > '9') {
161 /* Keywords (RHS) permitted in Run records */
162 static struct s_kw RunFields[] = {
171 * Store Schedule Run information
173 * Parse Run statement:
175 * Run <keyword=value ...> [on] 2 january at 23:45
177 * Default Run time is daily at 0:0
179 * There can be multiple run statements, they are simply chained
183 void store_run(LEX *lc, struct res_items *item, int index, int pass)
186 int token, state, state2 = 0, code = 0, code2 = 0;
187 int options = lc->options;
188 RUN **run = (RUN **)(item->value);
194 lc->options |= LOPT_NO_IDENT; /* want only "strings" */
196 /* clear local copy of run record */
197 memset(&lrun, 0, sizeof(RUN));
199 /* scan for Job level "full", "incremental", ... */
200 for (found=TRUE; found; ) {
202 token = lex_get_token(lc, T_NAME);
203 for (i=0; RunFields[i].name; i++) {
204 if (strcasecmp(lc->str, RunFields[i].name) == 0) {
206 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
207 scan_err1(lc, "Expected an equals, got: %s", lc->str);
210 token = lex_get_token(lc, T_NAME);
211 switch (RunFields[i].token) {
212 case 'L': /* level */
213 for (j=0; joblevels[j].level_name; j++) {
214 if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
215 lrun.level = joblevels[j].level;
216 lrun.job_type = joblevels[j].job_type;
222 scan_err1(lc, _("Job level field: %s not found in run record"), lc->str);
228 res = GetResWithName(R_POOL, lc->str);
230 scan_err1(lc, "Could not find specified Pool Resource: %s",
234 lrun.pool = (POOL *)res;
237 case 'S': /* storage */
239 res = GetResWithName(R_STORAGE, lc->str);
241 scan_err1(lc, "Could not find specified Storage Resource: %s",
245 lrun.storage = (STORE *)res;
248 case 'M': /* messages */
250 res = GetResWithName(R_MSGS, lc->str);
252 scan_err1(lc, "Could not find specified Messages Resource: %s",
256 lrun.msgs = (MSGS *)res;
260 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
264 } /* end if strcasecmp */
265 } /* end for RunFields */
267 /* At this point, it is not a keyword. Check for old syle
268 * Job Levels without keyword. This form is depreciated!!!
270 for (j=0; joblevels[j].level_name; j++) {
271 if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
272 lrun.level = joblevels[j].level;
273 lrun.job_type = joblevels[j].job_type;
278 } /* end for found */
282 * Scan schedule times.
283 * Default is: daily at 0:0
288 for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
293 code = atoi(lc->str) - 1;
294 if (code < 0 || code > 30) {
295 scan_err0(lc, _("Day number out of range (1-31)"));
298 case T_NAME: /* this handles drop through from keyword */
299 case T_UNQUOTED_STRING:
300 if (strchr(lc->str, (int)'-')) {
304 if (strchr(lc->str, (int)':')) {
308 /* everything else must be a keyword */
309 for (i=0; keyw[i].name; i++) {
310 if (strcasecmp(lc->str, keyw[i].name) == 0) {
311 state = keyw[i].state;
318 scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
325 scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
332 case s_mday: /* day of month */
334 clear_bits(0, 30, lrun.mday);
335 clear_bits(0, 6, lrun.wday);
338 set_bit(code, lrun.mday);
340 case s_month: /* month of year */
342 clear_bits(0, 11, lrun.month);
345 set_bit(code, lrun.month);
347 case s_wday: /* week day */
349 clear_bits(0, 6, lrun.wday);
350 clear_bits(0, 30, lrun.mday);
353 set_bit(code, lrun.wday);
355 case s_wpos: /* Week position 1st, ... */
357 clear_bits(0, 4, lrun.wpos);
360 set_bit(code, lrun.wpos);
362 case s_time: /* time */
364 scan_err0(lc, _("Time must be preceded by keyword AT."));
368 clear_bit(0, lrun.hour);
370 p = strchr(lc->str, ':');
372 scan_err0(lc, _("Time logic error.\n"));
375 *p++ = 0; /* separate two halves */
376 code = atoi(lc->str);
378 if (len > 2 && p[len-1] == 'm') {
379 if (p[len-2] == 'a') {
381 } else if (p[len-2] == 'p') {
384 scan_err0(lc, _("Bad time specification."));
394 if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
395 scan_err0(lc, _("Bad time specification."));
398 set_bit(code, lrun.hour);
406 p = strchr(lc->str, '-');
408 scan_err0(lc, _("Range logic error.\n"));
410 *p++ = 0; /* separate two halves */
412 /* Check for day range */
413 if (is_num(lc->str) && is_num(p)) {
414 code = atoi(lc->str) - 1;
416 if (code < 0 || code > 30 || code2 < 0 || code2 > 30) {
417 scan_err0(lc, _("Bad day range specification."));
420 clear_bits(0, 30, lrun.mday);
421 clear_bits(0, 6, lrun.wday);
425 set_bits(code, code2, lrun.mday);
427 set_bits(code, 30, lrun.mday);
428 set_bits(0, code2, lrun.mday);
433 /* lookup first half of keyword range (week days or months) */
435 for (i=0; keyw[i].name; i++) {
436 if (strcmp(lc->str, keyw[i].name) == 0) {
437 state = keyw[i].state;
443 if (i != 0 || (state != s_month && state != s_wday && state != s_wpos)) {
444 scan_err0(lc, _("Invalid month, week or position day range"));
448 /* Lookup end of range */
450 for (i=0; keyw[i].name; i++) {
451 if (strcmp(p, keyw[i].name) == 0) {
452 state2 = keyw[i].state;
453 code2 = keyw[i].code;
458 if (i != 0 || state != state2 || code == code2) {
459 scan_err0(lc, _("Invalid month, weekday or position range"));
462 if (state == s_wday) {
464 clear_bits(0, 6, lrun.wday);
465 clear_bits(0, 30, lrun.mday);
469 set_bits(code, code2, lrun.wday);
471 set_bits(code, 6, lrun.wday);
472 set_bits(0, code2, lrun.wday);
474 } else if (state == s_month) {
476 clear_bits(0, 30, lrun.month);
480 set_bits(code, code2, lrun.month);
482 /* this is a bit odd, but we accept it anyway */
483 set_bits(code, 30, lrun.month);
484 set_bits(0, code2, lrun.month);
487 /* Must be position */
489 clear_bits(0, 4, lrun.wpos);
493 set_bits(code, code2, lrun.wpos);
495 set_bits(code, 4, lrun.wpos);
496 set_bits(0, code2, lrun.wpos);
502 set_bits(0, 23, lrun.hour);
503 set_bits(0, 30, lrun.mday);
504 set_bits(0, 11, lrun.month);
505 set_bits(0, 4, lrun.wpos);
509 set_bit(0, lrun.wday);
510 set_bits(0, 11, lrun.month);
511 set_bits(0, 4, lrun.wpos);
515 set_bits(0, 30, lrun.mday);
516 set_bits(0, 11, lrun.month);
517 set_bits(0, 4, lrun.wpos);
521 set_bits(0, 11, lrun.month);
522 set_bits(0, 4, lrun.wpos);
525 scan_err0(lc, _("Unexpected run state\n"));
531 /* Allocate run record, copy new stuff into it,
532 * and link it into the list of run records
533 * in the schedule resource.
536 trun = (RUN *)malloc(sizeof(RUN));
537 memcpy(trun, &lrun, sizeof(RUN));
544 lc->options = options; /* restore scanner options */
545 set_bit(index, res_all.res_sch.hdr.item_present);