*
* Version $Id$
*/
-
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Copyright (C) 2002-2005 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
/*
- * Given a string "str", separate the integer part into
+ * Given a string "str", separate the numeric part into
* str, and the modifier into mod.
*/
static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_len)
{
int i, len, num_begin, num_end, mod_begin, mod_end;
- /*
- * Look for modifier by walking back looking for the first
- * space or digit.
- */
strip_trailing_junk(str);
len = strlen(str);
/* Walk through integer part */
for ( ; i<len; i++) {
- if (!B_ISDIGIT(str[i])) {
+ if (!B_ISDIGIT(str[i]) && str[i] != '.') {
break;
}
}
if (num_len == 0) {
return false;
}
+ /* Eat any spaces in front of modifier */
for ( ; i<len; i++) {
if (!B_ISSPACE(str[i])) {
break;
return false;
}
bstrncpy(str, &str[mod_end], len);
+ Dmsg2(900, "num=%s mod=%s\n", num, mod);
return true;
}
/*
* Convert a string duration to utime_t (64 bit seconds)
- * Returns 0: if error
- 1: if OK, and value stored in value
+ * Returns false: if error
+ true: if OK, and value stored in value
*/
-int duration_to_utime(char *str, utime_t *value)
+bool duration_to_utime(char *str, utime_t *value)
{
int i, mod_len;
double val, total = 0.0;
while (*str) {
if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) {
- return 0;
+ return false;
}
/* Now find the multiplier corresponding to the modifier */
mod_len = strlen(mod_str);
if (mod_len == 0) {
- i = 1; /* assume seconds */
+ i = 1; /* default to seconds */
} else {
for (i=0; mod[i]; i++) {
if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
}
}
if (mod[i] == NULL) {
- i = 1; /* no modifier, assume secs */
+ 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 0;
+ return false;
}
total += val * mult[i];
}
*value = (utime_t)total;
- return 1;
+ return true;
}
/*
/*
* Convert a size in bytes to uint64_t
- * Returns 0: if error
- 1: if OK, and value stored in value
+ * Returns false: if error
+ true: if OK, and value stored in value
*/
-int size_to_uint64(char *str, int str_len, uint64_t *value)
+bool size_to_uint64(char *str, int str_len, uint64_t *value)
{
int i, mod_len;
double val;
}
/* Now find the multiplier corresponding to the modifier */
mod_len = strlen(mod_str);
- for (i=0; mod[i]; i++) {
- if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
- break;
+ if (mod_len == 0) {
+ i = 0; /* default with no modifier = 1 */
+ } else {
+ for (i=0; mod[i]; i++) {
+ if (strncasecmp(mod_str, mod[i], mod_len) == 0) {
+ break;
+ }
+ }
+ if (mod[i] == NULL) {
+ return false;
}
- }
- if (mod[i] == NULL) {
- i = 0; /* no modifier found, assume 1 */
}
Dmsg2(900, "str=%s: mult=%d\n", str, mult[i]);
errno = 0;
val = strtod(num_str, NULL);
if (errno != 0 || val < 0) {
- return 0;
+ return false;
}
- *value = (utime_t)(val * mult[i]);
- return 1;
+ *value = (utime_t)(val * mult[i]);
+ return true;
}
/*