diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2002-02-23 10:01:35 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2002-02-23 10:01:35 +0000 |
commit | 5c1ea023faf7447159eba6040d865beaefd10a77 (patch) | |
tree | 4d689e48a81ebcf04485f37e865cdabeb2287f20 /lib | |
parent | 222d23ec79a0e0062e219e57ff249a64f83bab30 (diff) | |
download | mailutils-5c1ea023faf7447159eba6040d865beaefd10a77.tar.gz mailutils-5c1ea023faf7447159eba6040d865beaefd10a77.tar.bz2 |
Yesterday's fix makes argcv_get include trailing
whitespace to the argv array. To fix:
(argcv_scan): Return len+1 if called on or after
the terminating null character.
(argcv_get): Initialize *argc to zero and continue scanning
until argcv_scan return is > len. Thanks Sam for noticing.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/argcv.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/argcv.c b/lib/argcv.c index 015f29d96..c60674514 100644 --- a/lib/argcv.c +++ b/lib/argcv.c @@ -19,8 +19,6 @@ #include "argcv.h" -char srtime[] = __TIME__; - /* * takes a string and splits it into several strings, breaking at ' ' * command is the string to split @@ -43,7 +41,7 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, i = *save; if (i >= len) - return i; + return i + 1; /* Skip initial whitespace */ while (i < len && isws (command[i])) @@ -102,10 +100,10 @@ argcv_get (const char *command, const char *delim, const char* cmnt, *argv = NULL; /* Count number of arguments */ - *argc = 1; + *argc = 0; save = 0; - while (argcv_scan (len, command, delim, cmnt, &start, &end, &save) < len) + while (argcv_scan (len, command, delim, cmnt, &start, &end, &save) <= len) (*argc)++; *argv = calloc ((*argc + 1), sizeof (char *)); @@ -198,14 +196,14 @@ argcv_string (int argc, char **argv, char **pstring) } #if 0 -char *command = "set prompt=\"& \""; +char *command = "set prompt=\"& \" "; -main() +main(int xargc, char **xargv) { int i, argc; char **argv; - argcv_get (command, "=", NULL, &argc, &argv); + argcv_get (xargv[1] ? xargv[1]:command, "=", "#", &argc, &argv); printf ("%d args:\n", argc); for (i = 0; i < argc; i++) printf ("%s\n", argv[i]); |