help-gengetopt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-gengetopt] RE: a small improvement(?) in the config file parse


From: Lorenzo Bettini
Subject: Re: [help-gengetopt] RE: a small improvement(?) in the config file parser
Date: Thu, 28 Oct 2004 18:33:42 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040929

I included this patch in

http://rap.dsi.unifi.it/~bettini/gengetopt-2.13rc3.tar.gz

(I haven't changed to rc4 though :-)

thanks
        Lorenzo

Gyozo, PAPP (VBuster) wrote:
" 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



------------------------------------------------------------------------

_______________________________________________
Help-gengetopt mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gengetopt


--
+-----------------------------------------------------+
|  Lorenzo Bettini          ICQ# lbetto, 16080134     |
|  PhD in Computer Science                            |
|  Dip. Sistemi e Informatica, Univ. di Firenze       |
|  Tel +39 055 4796741, Fax +39 055 4796730           |
|  Florence - Italy        (GNU/Linux User # 158233)  |
|  Home Page        : http://www.lorenzobettini.it    |
|  http://music.dsi.unifi.it         XKlaim language  |
|  http://www.lorenzobettini.it/purple    Cover Band  |
|  http://www.gnu.org/software/src-highlite           |
|  http://www.gnu.org/software/gengetopt              |
|  http://www.lorenzobettini.it/software/gengen       |
|  http://www.lorenzobettini.it/software/doublecpp    |
+-----------------------------------------------------+





reply via email to

[Prev in Thread] Current Thread [Next in Thread]