Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
926d86d
)
Improved parse_size_arg() a little more.
author
Wayne Davison
<wayned@samba.org>
Fri, 14 Oct 2005 19:48:34 +0000
(19:48 +0000)
committer
Wayne Davison
<wayned@samba.org>
Fri, 14 Oct 2005 19:48:34 +0000
(19:48 +0000)
options.c
patch
|
blob
|
blame
|
history
diff --git
a/options.c
b/options.c
index
c34d531
..
a5c4b8b
100644
(file)
--- a/
options.c
+++ b/
options.c
@@
-648,11
+648,11
@@
static int count_args(const char **argv)
}
}
-static OFF_T parse_size_arg(char **size_arg)
+static OFF_T parse_size_arg(char **size_arg
, char def_suf
)
{
{
- const char *arg;
- OFF_T size;
int mult, make_compatible = 0;
int mult, make_compatible = 0;
+ const char *arg, *p;
+ OFF_T size = 0;
for (arg = *size_arg; isdigit(*(uchar*)arg); arg++) {}
if (*arg == '.')
for (arg = *size_arg; isdigit(*(uchar*)arg); arg++) {}
if (*arg == '.')
@@
-661,27
+661,31
@@
static OFF_T parse_size_arg(char **size_arg)
mult = 1000, make_compatible = 1;
else
mult = 1024;
mult = 1000, make_compatible = 1;
else
mult = 1024;
- switch (*arg) {
+ if ((p = strstr(arg, "+1")) != NULL
+ || (p = strstr(arg, "-1")) != NULL) {
+ if (p[2] == '\0') {
+ size = atoi(p + (*p == '+'));
+ make_compatible = 1;
+ } else
+ p = NULL;
+ }
+ switch (*arg && arg != p ? *arg : def_suf) {
+ case 'b': case 'B':
+ size += atof(*size_arg);
+ break;
case 'k': case 'K':
case 'k': case 'K':
- size = atof(*size_arg) * mult;
+ size
+
= atof(*size_arg) * mult;
break;
case 'm': case 'M':
break;
case 'm': case 'M':
- size = atof(*size_arg) * mult*mult;
+ size
+
= atof(*size_arg) * mult*mult;
break;
case 'g': case 'G':
break;
case 'g': case 'G':
- size = atof(*size_arg) * mult*mult*mult;
- break;
- case '\0': case '+': case '-':
- size = atof(*size_arg);
+ size += atof(*size_arg) * mult*mult*mult;
break;
default:
size = -1;
break;
}
break;
default:
size = -1;
break;
}
- if (strchr(arg, '+'))
- size++, make_compatible = 1;
- else if (strchr(arg, '-'))
- size--, make_compatible = 1;
if (size > 0 && make_compatible) {
/* We convert this manually because we many need %lld
* precision, and that's not portable. */
if (size > 0 && make_compatible) {
/* We convert this manually because we many need %lld
* precision, and that's not portable. */
@@
-911,7
+915,7
@@
int parse_arguments(int *argc, const char ***argv, int frommain)
break;
case OPT_MAX_SIZE:
break;
case OPT_MAX_SIZE:
- if ((max_size = parse_size_arg(&max_size_arg)) <= 0) {
+ if ((max_size = parse_size_arg(&max_size_arg
, 'b'
)) <= 0) {
snprintf(err_buf, sizeof err_buf,
"--max-size value is invalid: %s\n",
max_size_arg);
snprintf(err_buf, sizeof err_buf,
"--max-size value is invalid: %s\n",
max_size_arg);