[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[help-gengetopt] RE: a small improvement(?) in the config file parser
From: |
Gyozo, PAPP (VBuster) |
Subject: |
[help-gengetopt] RE: a small improvement(?) in the config file parser |
Date: |
Mon, 18 Oct 2004 11:13:12 +0200 |
" as I understand the right (and consistent with getopt_long)
" behavior is to use an empty argument if there's only an equal
" sign without anything after.
Yes, basically this is my intention.
" so the configuration
"
" > " [0] = PACKAGE_VAR_NAME
" > " [1] = "--option-with-arg="
" > " [2] = "arbitrary"
"
" is the right one and it results in the same output as if we
" would have passed that command line, am I right?
Yes.
" If so, could you please send me the patch that corrects this
" problem? :-)
I'll send a patch against the original 2.13 and not the recent 2.13rc1.
It also includes the the compilation warnings elimination and the fix of the
uninitialized `result' variable in _required() function.
What is more important is this patch contains another bug fix in the config
parser I've overlooked for a long time.
<code to be replaced somewhere around the line 360 in src/skels/c_source.h_skel>
/* truncate fopt at the end of the first non-valid character */
next_token = strcspn (fopt, " \t\r\n=");
if (fopt[next_token] == '\0') /* the line is over */
{
farg = NULL;
goto noarg;
}
fopt[next_token++] = '\0';
/* advance pointers to the next token after the end of fopt */
next_token += strspn (fopt + next_token, " \t\r\n#");
str_index += next_token;
</code to be replaced>
Erroneously, '#' was part of the token delimiter character rather than treating
it as the first character of a new token (comment).
Now the code above has been replaced with the following one:
/* truncate fopt at the end of the first non-valid character */
next_token = strcspn (fopt, " \t\r\n=");
if (fopt[next_token] == '\0') /* the line is over */
{
farg = NULL;
equal = 0;
goto noarg;
}
/* remember if equal sign is present */
equal = (fopt[next_token] == '=');
fopt[next_token++] = '\0';
/* advance pointers to the next token after the end of fopt */
next_token += strspn (fopt + next_token, " \t\r\n");
/* check for the presence of equal sign, and if so, skip it */
if ( !equal )
if ((equal = (fopt[next_token] == '=')))
{
next_token++;
next_token += strspn (fopt + next_token, " \t\r\n");
}
str_index += next_token;
It may also be good to know that the current implementation does always be
aware of the presence or absence of the '=', because, in my understanding, the
'=' has become a new token rather than a simple delimiter or a "syntactic
sugar". This complicates the original source a little, but I hope this will
result a more user friendly config parser.
Gyozo
config2.patch
Description: config2.patch