Francesco, Andrew:
I've made one additional small change. There was a problem when
using optstr_get() on the last argument of a filter line. Normally,
optstr_get() returns -1 if the option was NOT present, 0 if present
without any (valid) argument given, or > 0 as the number of values
provided. My option parsing depends upon this behavior, but
unfortunately for the last argument, a zero length string is passed off
to scanf() resulting in -1 returned, even though the argument was
supplied. I have added one small check to just return zero, instead of
passing scanf() an empty string. I've tested it and it seems to work fine.
Allan
Allan N. Snider wrote:
Attached is a patch (against v1.1.0), that makes a minor change to
the argument parsing code. When the parameter(s) of a filter argument
are retrieved the code skips past the argument name plus one
character, which it assumes is the '=' sign. I modified it to only
skip the '=' if it is in fact an equal sign. When this is done, it
allows a more convenient form for optional string values ("%s"), for
example:
-J filter=arg[=string]
I can do a lookup on arg and provide a default if no value is present,
or use the provided string. Without the patch, a statement like '-J
filter=arg1:arg2', would yeild arg2 as the string value for arg1.
I don't think this change has any other side affect. It's
aesthetically more pleasing then having to write:
-J filter=arg1=:arg2
Allan
diff -ruN old/libtc/optstr.c new/libtc/optstr.c
--- old/libtc/optstr.c 2007-03-10 03:25:26.000000000 -0500
+++ new/libtc/optstr.c 2007-03-10 03:27:20.000000000 -0500
@@ -112,8 +112,13 @@
return 0;
}
- /* skip the `=' */
- ch += (strlen(name) + 1);
+ /* skip the `=' (if it is one) */
+ ch += strlen( name );
+ if( *ch == '=' )
+ ch++;
+
+ if( !*ch )
+ return 0;
va_start(ap, fmt);