]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/run_conf.c
Fix newvol.c
[bacula/bacula] / bacula / src / dird / run_conf.c
index b9e307bad332253d086d3884d6ec38c1db48ce67..032ce1037f326de0da1d171161b91c11093508ab 100644 (file)
@@ -47,6 +47,7 @@ enum e_state {
    s_weekly,
    s_monthly,
    s_hourly,
+   s_wpos,                           /* 1st, 2nd, ...*/
 };  
 
 struct s_keyw {
@@ -103,30 +104,44 @@ static struct s_keyw keyw[] = {
   {N_("weekly"),     s_weekly,  0},
   {N_("monthly"),    s_monthly, 0},
   {N_("hourly"),     s_hourly,  0},
+
+  {N_("1st"),        s_wpos,    0},
+  {N_("2nd"),        s_wpos,    1},
+  {N_("3rd"),        s_wpos,    2},
+  {N_("4th"),        s_wpos,    3},
+  {N_("5th"),        s_wpos,    4},
+
+  {N_("first"),      s_wpos,    0},
+  {N_("second"),     s_wpos,    1},
+  {N_("third"),      s_wpos,    2},
+  {N_("fourth"),     s_wpos,    3},
+  {N_("fifth"),      s_wpos,    4},
   {NULL,        s_none,    0}
 };
 
-static int have_hour, have_mday, have_wday, have_month;
+static int have_hour, have_mday, have_wday, have_month, have_wpos;
 static int have_at;
 static RUN lrun;
 
 static void clear_defaults()
 {
-   have_hour = have_mday = have_wday = have_month = TRUE;
+   have_hour = have_mday = have_wday = have_month = have_wpos = TRUE;
    clear_bit(0,lrun.hour);
    clear_bits(0, 30, lrun.mday);
    clear_bits(0, 6, lrun.wday);
    clear_bits(0, 11, lrun.month);
+   clear_bits(0, 4, lrun.wpos);
 }
 
 static void set_defaults()
 {
-   have_hour = have_mday = have_wday = have_month = FALSE;
+   have_hour = have_mday = have_wday = have_month = have_wpos = FALSE;
    have_at = FALSE;
    set_bit(0,lrun.hour);
    set_bits(0, 30, lrun.mday);
    set_bits(0, 6, lrun.wday);
    set_bits(0, 11, lrun.month);
+   set_bits(0, 4, lrun.wpos);
 }
 
 
@@ -168,7 +183,7 @@ static struct s_kw RunFields[] = {
 void store_run(LEX *lc, struct res_items *item, int index, int pass)
 {
    int i, j, found;
-   int token, state, state2, code, code2;
+   int token, state, state2 = 0, code = 0, code2 = 0;
    int options = lc->options;
    RUN **run = (RUN **)(item->value);  
    RUN *trun;
@@ -190,6 +205,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
            found = TRUE;
            if (lex_get_token(lc, T_ALL) != T_EQUALS) {
                scan_err1(lc, "Expected an equals, got: %s", lc->str);
+              /* NOT REACHED */ 
            }
            token = lex_get_token(lc, T_NAME);
            switch (RunFields[i].token) {
@@ -204,6 +220,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
               }
               if (j != 0) {
                   scan_err1(lc, _("Job level field: %s not found in run record"), lc->str);
+                 /* NOT REACHED */
               }
               break;
             case 'P':                 /* Pool */
@@ -212,6 +229,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  if (res == NULL) {
                      scan_err1(lc, "Could not find specified Pool Resource: %s",
                                lc->str);
+                    /* NOT REACHED */
                  }
                  lrun.pool = (POOL *)res;
               }
@@ -222,6 +240,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  if (res == NULL) {
                      scan_err1(lc, "Could not find specified Storage Resource: %s",
                                lc->str);
+                    /* NOT REACHED */
                  }
                  lrun.storage = (STORE *)res;
               }
@@ -232,12 +251,14 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  if (res == NULL) {
                      scan_err1(lc, "Could not find specified Messages Resource: %s",
                                lc->str);
+                    /* NOT REACHED */
                  }
                  lrun.msgs = (MSGS *)res;
               }
               break;
            default:
                scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
+              /* NOT REACHED */
               break;
            } /* end switch */     
         } /* end if strcasecmp */
@@ -265,7 +286,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
    set_defaults();
 
    for ( ; token != T_EOL; (token = lex_get_token(lc, T_ALL))) {
-      int len, pm;
+      int len, pm = 0;
       switch (token) {
         case T_NUMBER:
            state = s_mday;
@@ -295,12 +316,14 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
            }
            if (i != 0) {
                scan_err1(lc, _("Job type field: %s in run record not found"), lc->str);
+              /* NOT REACHED */
            }
            break;
         case T_COMMA:
            continue;
         default:
             scan_err2(lc, _("Unexpected token: %d:%s"), token, lc->str);
+           /* NOT REACHED */
            break;
       }
       switch (state) {
@@ -329,9 +352,17 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
            }
            set_bit(code, lrun.wday);
            break;
+        case s_wpos:                 /* Week position 1st, ... */
+           if (!have_wpos) {
+              clear_bits(0, 4, lrun.wpos);
+              have_wpos = TRUE;
+           }
+           set_bit(code, lrun.wpos);
+           break;
         case s_time:                 /* time */
            if (!have_at) {
                scan_err0(lc, _("Time must be preceded by keyword AT."));
+              /* NOT REACHED */
            }
            if (!have_hour) {
               clear_bit(0, lrun.hour);
@@ -339,6 +370,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
             p = strchr(lc->str, ':');
            if (!p)  {
                scan_err0(lc, _("Time logic error.\n"));
+              /* NOT REACHED */
            }
            *p++ = 0;                 /* separate two halves */
            code = atoi(lc->str);
@@ -350,6 +382,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  pm = 1;
               } else {
                   scan_err0(lc, _("Bad time specification."));
+                 /* NOT REACHED */
               }
            } else {
               pm = 0;
@@ -360,6 +393,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
            }
            if (code < 0 || code > 23 || code2 < 0 || code2 > 59) {
                scan_err0(lc, _("Bad time specification."));
+              /* NOT REACHED */
            }
            set_bit(code, lrun.hour);
            lrun.minute = code2;
@@ -406,8 +440,9 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  break;
               }
            }
-           if (i != 0 || (state != s_month && state != s_wday)) {
-               scan_err0(lc, _("Invalid month or week day range"));
+           if (i != 0 || (state != s_month && state != s_wday && state != s_wpos)) {
+               scan_err0(lc, _("Invalid month, week or position day range"));
+              /* NOT REACHED */
            }
 
            /* Lookup end of range */
@@ -420,9 +455,9 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  break;
               }
            }
-           if (i != 0 || state != state2 || 
-              (state2 != s_month && state2 != s_wday) || code == code2) {
-               scan_err0(lc, _("Invalid month or weekday range"));
+           if (i != 0 || state != state2 || code == code2) {
+               scan_err0(lc, _("Invalid month, weekday or position range"));
+              /* NOT REACHED */
            }
            if (state == s_wday) {
               if (!have_wday) {
@@ -436,8 +471,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  set_bits(code, 6, lrun.wday);
                  set_bits(0, code2, lrun.wday);
               }
-           } else {
-              /* must be s_month */
+           } else if (state == s_month) {
               if (!have_month) {
                  clear_bits(0, 30, lrun.month);
                  have_month = TRUE;
@@ -449,30 +483,47 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass)
                  set_bits(code, 30, lrun.month);
                  set_bits(0, code2, lrun.month);
               }
-           }
+           } else {
+              /* Must be position */
+              if (!have_wpos) {
+                 clear_bits(0, 4, lrun.wpos);
+                 have_wpos = TRUE;
+              }
+              if (code < code2) {
+                 set_bits(code, code2, lrun.wpos);
+              } else {
+                 set_bits(code, 4, lrun.wpos);
+                 set_bits(0, code2, lrun.wpos);
+              }
+           }                      
            break;
         case s_hourly:
            clear_defaults();
            set_bits(0, 23, lrun.hour);
            set_bits(0, 30, lrun.mday);
            set_bits(0, 11, lrun.month);
+           set_bits(0, 4, lrun.wpos);
            break;
         case s_weekly:
            clear_defaults();
            set_bit(0, lrun.wday);
            set_bits(0, 11, lrun.month);
+           set_bits(0, 4, lrun.wpos);
            break;
         case s_daily:
            clear_defaults();
            set_bits(0, 30, lrun.mday);
            set_bits(0, 11, lrun.month);
+           set_bits(0, 4,  lrun.wpos);
            break;
         case s_monthly:
            clear_defaults();
            set_bits(0, 11, lrun.month);
+           set_bits(0, 4,  lrun.wpos);
            break;
         default:
             scan_err0(lc, _("Unexpected run state\n"));
+           /* NOT REACHED */
            break;
       }
    }