src/lib/edit.c
bool duration_to_utime(char *str, utime_t *value)
{
   int i, mod_len;
   double val, total = 0.0;
   char mod_str[20];
   char num_str[50];
   /*
    * The "n" = mins and months appears before minutes so that m maps
    *   to months. These "kludges" make it compatible with pre 1.31
    *   Baculas.
    */
   static const char *mod[] = {"n", "seconds", "months", "minutes", "mins",
                  "hours", "days", "weeks",   "quarters",   "years", NULL};
   static const int32_t mult[] = {60,   1, 60*60*24*30, 60, 60,
                  3600, 3600*24, 3600*24*7, 3600*24*91, 3600*24*365};

   while (*str) {
      if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) {
         return false;
      }
      /* Now find the multiplier corresponding to the modifier */
      mod_len = strlen(mod_str);
      if (mod_len == 0) {
         i = 1;                          /* default to seconds */
      } else {
         for (i=0; mod[i]; i++) {
            if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
               break;
            }
         }
         if (mod[i] == NULL) {
            return false;
         }
      }
      Dmsg2(900, "str=%s: mult=%d\n", num_str, mult[i]);
      errno = 0;
      val = strtod(num_str, NULL);
      if (errno != 0 || val < 0) {
         return false;
      }
      total += val * mult[i];
   }
   *value = (utime_t)total;
   return true;
}
/*
 * Convert a string duration to utime_t (64 bit seconds)
 * Returns false: if error
           true:  if OK, and value stored in value
 */
Convert a string duration to utime_t (64 bit seconds)
Returns false: if error
true:  if OK, and value stored in value
Convert a string duration to utime_t ( 64 bit seconds ) Returns false : if error true : if OK and value stored in value
bool duration_to_utime(char *str, utime_t *value)
{
   int i, mod_len;
   double val, total = 0.0;
   char mod_str[20];
   char num_str[50];
   static const char *mod[] = {"n", "seconds", "months", "minutes", "mins",
                  "hours", "days", "weeks",   "quarters",   "years", NULL};
   static const int32_t mult[] = {60,   1, 60*60*24*30, 60, 60,
                  3600, 3600*24, 3600*24*7, 3600*24*91, 3600*24*365};
   while (*str) {
      if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) {
         return false;
      }
      mod_len = strlen(mod_str);
      if (mod_len == 0) {
         i = 1;                          
      } else {
         for (i=0; mod[i]; i++) {
            if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
               break;
            }
         }
         if (mod[i] == NULL) {
            return false;
         }
      }
      Dmsg2(900, "str=%s: mult=%d\n", num_str, mult[i]);
      errno = 0;
      val = strtod(num_str, NULL);
      if (errno != 0 || val < 0) {
         return false;
      }
      total += val * mult[i];
   }
   *value = (utime_t)total;
   return true;
}
bool duration_to_utime ( char * str , utime_t * value ) { int i , mod_len ; double val , total = 0.0 ; char mod_str [ 20 ] ; char num_str [ 50 ] ; static const char * mod [ ] = { " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , NULL } ; static const int32_t mult [ ] = { 60 , 1 , 60 * 60 * 24 * 30 , 60 , 60 , 3600 , 3600 * 24 , 3600 * 24 * 7 , 3600 * 24 * 91 , 3600 * 24 * 365 } ; while ( * str ) { if ( ! get_modifier ( str , num_str , sizeof ( num_str ) , mod_str , sizeof ( mod_str ) ) ) { return false ; } mod_len = strlen ( mod_str ) ; if ( mod_len == 0 ) { i = 1 ; } else { for ( i = 0 ; mod [ i ] ; i ++ ) { if ( strncasecmp ( mod_str , mod [ i ] , mod_len ) == 0 ) { break ; } } if ( mod [ i ] == NULL ) { return false ; } } Dmsg2 ( 900 , " \n " , num_str , mult [ i ] ) ; errno = 0 ; val = strtod ( num_str , NULL ) ; if ( errno != 0 || val < 0 ) { return false ; } total += val * mult [ i ] ; } * value = ( utime_t ) total ; return true ; }
Convert a string duration to utime_t (64 bit seconds)
 Returns false: if error
true:  if OK, and value stored in value
Convert a string duration to utime_t ( 64 bit seconds ) Returns false : if error true : if OK and value stored in value
/*
    * The "n" = mins and months appears before minutes so that m maps
    *   to months. These "kludges" make it compatible with pre 1.31
    *   Baculas.
    */ /* Now find the multiplier corresponding to the modifier */ /* default to seconds */