[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [help-gengetopt] config parser patch for more graceful parsing
From: |
Papp Gyozo (VBuster) |
Subject: |
Re: [help-gengetopt] config parser patch for more graceful parsing |
Date: |
Fri, 28 Sep 2007 18:57:42 +0200 |
From: Lorenzo Bettini
> > I hope this patch could be in the next package.
> >
> > --- gengetopt-2.18.orig/src/skels/c_source.h_skel Fri Jul 14 20:07:31 2006
> > +++ gengetopt-2.18/src/skels/c_source.h_skel Tue Nov 21 19:36:40 2006
> > @@ -653,8 +653,11 @@
> > }
> > }
> > else
> > - { /* read up the remaining part up to a delimiter */
> > - next_token = strcspn (farg, " \t\r\n#\'\"");
> > + { /* read up the remaining part up to end of line or comment sign
> */
> > + char *ch = (str_index + (next_token = strcspn (farg,
> "\r\n#")));
> > + /* remove trailing whitespaces */
> > + for ( --ch; (*ch >= '\t' && *ch <= '\r') || *ch == ' '; --ch )
> > + --next_token;
> > str_index += next_token;
> > }
>
> I'm really sorry about that, it must have escaped me.
Oh never mind that. You can realize now that I could wait for it for a long
time ;)
> I noticed that the strcspn does not include ' nor " is that correct?
Yes, but be careful! First it goes to the end of the line and then steps back
on (thus removes) trailing whitespaces. If you simply use strcspn() w/o ' and "
parser can't cope with the strings mentioned above:
> key = MC JMS
This way key_arg will be "MC JMS"
The another benefit of this patch is values containing more than one "word"
does not have to be quoted at all.