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 */
53 char *name; /* keyword */
54 enum e_state state; /* parser state */
55 int code; /* state value */
58 /* Keywords understood by parser */
59 static struct s_keyw keyw[] = {
60 {N_("on"), s_none, 0},
63 {N_("sun"), s_wday, 0},
64 {N_("mon"), s_wday, 1},
65 {N_("tue"), s_wday, 2},
66 {N_("wed"), s_wday, 3},
67 {N_("thu"), s_wday, 4},
68 {N_("fri"), s_wday, 5},
69 {N_("sat"), s_wday, 6},
70 {N_("jan"), s_month, 0},
71 {N_("feb"), s_month, 1},
72 {N_("mar"), s_month, 2},
73 {N_("apr"), s_month, 3},
74 {N_("may"), s_month, 4},
75 {N_("jun"), s_month, 5},
76 {N_("jul"), s_month, 6},
77 {N_("aug"), s_month, 7},
78 {N_("sep"), s_month, 8},
79 {N_("oct"), s_month, 9},
80 {N_("nov"), s_month, 10},
81 {N_("dec"), s_month, 11},
83 {N_("sunday"), s_wday, 0},
84 {N_("monday"), s_wday, 1},
85 {N_("tuesday"), s_wday, 2},
86 {N_("wednesday"), s_wday, 3},
87 {N_("thursday"), s_wday, 4},
88 {N_("friday"), s_wday, 5},
89 {N_("saturday"), s_wday, 6},
90 {N_("january"), s_month, 0},
91 {N_("february"), s_month, 1},
92 {N_("march"), s_month, 2},
93 {N_("april"), s_month, 3},
94 {N_("june"), s_month, 5},
95 {N_("july"), s_month, 6},
96 {N_("august"), s_month, 7},
97 {N_("september"), s_month, 8},
98 {N_("october"), s_month, 9},
99 {N_("november"), s_month, 10},
100 {N_("december"), s_month, 11},
102 {N_("daily"), s_daily, 0},
103 {N_("weekly"), s_weekly, 0},
104 {N_("monthly"), s_monthly, 0},
105 {N_("hourly"), s_hourly, 0},
109 static int have_hour, have_mday, have_wday, have_month;
113 static void clear_defaults()
115 have_hour = have_mday = have_wday = have_month = TRUE;
116 clear_bit(0,lrun.hour);
117 clear_bits(0, 30, lrun.mday);
118 clear_bits(0, 6, lrun.wday);
119 clear_bits(0, 11, lrun.month);
122 static void set_defaults()
124 have_hour = have_mday = have_wday = have_month = FALSE;
126 set_bit(0,lrun.hour);
127 set_bits(0, 30, lrun.mday);
128 set_bits(0, 6, lrun.wday);
129 set_bits(0, 11, lrun.month);
133 /* Check if string is a number */
134 static int is_num(char *num)
138 while ((ch = *p++)) {
139 if (ch < '0' || ch > '9') {
146 /* Keywords (RHS) permitted in Run records */
147 static struct s_kw RunFields[] = {
156 * Store Schedule Run information
158 * Parse Run statement:
160 * Run <keyword=value ...> [on] 2 january at 23:45
162 * Default Run time is daily at 0:0
164 * There can be multiple run statements, they are simply chained
168 void store_run(LEX *lc, struct res_items *item, int index, int pass)
171 int token, state, state2, code, code2;
172 int options = lc->options;
173 RUN **run = (RUN **)(item->value);
179 lc->options |= LOPT_NO_IDENT; /* want only "strings" */
181 /* clear local copy of run record */
182 memset(&lrun, 0, sizeof(RUN));
184 /* scan for Job level "full", "incremental", ... */
185 for (found=TRUE; found; ) {
187 token = lex_get_token(lc, T_NAME);
188 for (i=0; RunFields[i].name; i++) {
189 if (strcasecmp(lc->str, RunFields[i].name) == 0) {
191 if (lex_get_token(lc, T_ALL) != T_EQUALS) {
192 scan_err1(lc, "Expected an equals, got: %s", lc->str);
194 token = lex_get_token(lc, T_NAME);
195 switch (RunFields[i].token) {
196 case 'L': /* level */
197 for (j=0; joblevels[j].level_name; j++) {
198 if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
199 lrun.level = joblevels[j].level;
200 lrun.job_type = joblevels[j].job_type;
206 scan_err1(lc, _("Job level field: %s not found in run record"), lc->str);
211 res = GetResWithName(R_POOL, lc->str);
213 scan_err1(lc, "Could not find specified Pool Resource: %s",
216 lrun.pool = (POOL *)res;
219 case 'S': /* storage */
221 res = GetResWithName(R_STORAGE, lc->str);
223 scan_err1(lc, "Could not find specified Storage Resource: %s",
226 lrun.storage = (STORE *)res;
229 case 'M': /* messages */
231 res = GetResWithName(R_MSGS, lc->str);
233 scan_err1(lc, "Could not find specified Messages Resource: %s",
236 lrun.msgs = (MSGS *)res;
240 scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
243 } /* end if strcasecmp */
244 } /* end for RunFields */
246 /* At this point, it is not a keyword. Check for old syle
247 * Job Levels without keyword. This form is depreciated!!!
249 for (j=0; joblevels[j].level_name; j++) {
250 if (strcasecmp(lc->str, joblevels[j].level_name) == 0) {
251 lrun.level = joblevels[j].level;
252 lrun.job_type = joblevels[j].job_type;
257 } /* end for found */
261 * Scan schedule times.
262 * Default is: daily at 0:0
267 for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
272 code = atoi(lc->str) - 1;
273 if (code < 0 || code > 30) {
274 scan_err0(lc, _("Day number out of range (1-31)"));
277 case T_NAME: /* this handles drop through from keyword */
278 case T_UNQUOTED_STRING:
279 if (strchr(lc->str, (int)'-')) {
283 if (strchr(lc->str, (int)':')) {
287 /* everything else must be a keyword */
288 for (i=0; keyw[i].name; i++) {
289 if (strcasecmp(lc->str, keyw[i].name) == 0) {
290 state = keyw[i].state;
297 scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
303 scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
309 case s_mday: /* day of month */
311 clear_bits(0, 30, lrun.mday);
312 clear_bits(0, 6, lrun.wday);
315 set_bit(code, lrun.mday);
317 case s_month: /* month of year */
319 clear_bits(0, 11, lrun.month);
322 set_bit(code, lrun.month);
324 case s_wday: /* week day */
326 clear_bits(0, 6, lrun.wday);
327 clear_bits(0, 30, lrun.mday);
330 set_bit(code, lrun.wday);
332 case s_time: /* time */
334 scan_err0(lc, _("Time must be preceded by keyword AT."));
337 clear_bit(0, lrun.hour);
339 p = strchr(lc->str, ':');
341 scan_err0(lc, _("Time logic error.\n"));
343 *p++ = 0; /* separate two halves */
344 code = atoi(lc->str);
346 if (len > 2 && p[len-1] == 'm') {
347 if (p[len-2] == 'a') {
349 } else if (p[len-2] == 'p') {
352 scan_err0(lc, _("Bad time specification."));
361 if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
362 scan_err0(lc, _("Bad time specification."));
364 set_bit(code, lrun.hour);
372 p = strchr(lc->str, '-');
374 scan_err0(lc, _("Range logic error.\n"));
376 *p++ = 0; /* separate two halves */
378 /* Check for day range */
379 if (is_num(lc->str) && is_num(p)) {
380 code = atoi(lc->str) - 1;
382 if (code < 0 || code > 30 || code2 < 0 || code2 > 30) {
383 scan_err0(lc, _("Bad day range specification."));
386 clear_bits(0, 30, lrun.mday);
387 clear_bits(0, 6, lrun.wday);
391 set_bits(code, code2, lrun.mday);
393 set_bits(code, 30, lrun.mday);
394 set_bits(0, code2, lrun.mday);
399 /* lookup first half of keyword range (week days or months) */
401 for (i=0; keyw[i].name; i++) {
402 if (strcmp(lc->str, keyw[i].name) == 0) {
403 state = keyw[i].state;
409 if (i != 0 || (state != s_month && state != s_wday)) {
410 scan_err0(lc, _("Invalid month or week day range"));
413 /* Lookup end of range */
415 for (i=0; keyw[i].name; i++) {
416 if (strcmp(p, keyw[i].name) == 0) {
417 state2 = keyw[i].state;
418 code2 = keyw[i].code;
423 if (i != 0 || state != state2 ||
424 (state2 != s_month && state2 != s_wday) || code == code2) {
425 scan_err0(lc, _("Invalid month or weekday range"));
427 if (state == s_wday) {
429 clear_bits(0, 6, lrun.wday);
430 clear_bits(0, 30, lrun.mday);
434 set_bits(code, code2, lrun.wday);
436 set_bits(code, 6, lrun.wday);
437 set_bits(0, code2, lrun.wday);
440 /* must be s_month */
442 clear_bits(0, 30, lrun.month);
446 set_bits(code, code2, lrun.month);
448 /* this is a bit odd, but we accept it anyway */
449 set_bits(code, 30, lrun.month);
450 set_bits(0, code2, lrun.month);
456 set_bits(0, 23, lrun.hour);
457 set_bits(0, 30, lrun.mday);
458 set_bits(0, 11, lrun.month);
462 set_bit(0, lrun.wday);
463 set_bits(0, 11, lrun.month);
467 set_bits(0, 30, lrun.mday);
468 set_bits(0, 11, lrun.month);
472 set_bits(0, 11, lrun.month);
475 scan_err0(lc, _("Unexpected run state\n"));
480 /* Allocate run record, copy new stuff into it,
481 * and link it into the list of run records
482 * in the schedule resource.
485 trun = (RUN *)malloc(sizeof(RUN));
486 memcpy(trun, &lrun, sizeof(RUN));
493 lc->options = options; /* restore scanner options */
494 set_bit(index, res_all.res_sch.hdr.item_present);