help-gengetopt
[Top][All Lists]
Advanced

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

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


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

Gyozo, PAPP (VBuster) wrote:
Hi there,

finally I've freed some time to reply very briefly.

" Well I'm quite skeptical of going back to let the config " parser function to actually parse the arguments, since this " would not be consistent with the getopt_long function.

I was looking the generated source and I found that if the long_options 
structure local to _internal() function would be visible by _configfile() 
function, this would solve this problem, because we could easily figure out if 
an option accepted/required an argument or not. Moreover, if the option 
handling would be implemented via helper functions, there should be no problem 
at all.

" Moreover, I'm quite sure that the behavior of the current code is " actually the same of what would happen if you gave at the " command line the sequence " " --option-with-arg = --arbitrary " " i.e., intepret --arbitrary as the argument to --option-with-arg

No, --option-with-arg= (ending in a '=') means an empty(!) option-argument, so 
"--arbitrary" will be the next option and not an option-argument.
" if this is not the case, I think the best solution is to " issue an error saying that in the conf file the line " "--option-with-arg = " is wrong...

getopt_long() returns OK and empty string (or mabe NULL?) in optarg if no option-argument is found. So the line in question above must remain valid. So, if we find an option at the beginning of the line and a following equal sign, too, it means that user wants to specify an option-argument to this option.
There is an implicit assumpion that each (non-empty and not full-comment) line 
in the config file represents one option, and an option declaration must not 
exceed the current line where its declaration starts. If no equal sign is found 
but option requires/accepts an argument, then this assumption is broken (... 
because cmdline_internal() eats the subsequent argv element as option-argument 
which is not in the same line as the option's name is in.) We must examine this 
assumption first, and if it is correct, we must provide that it will be valid. 
No doubt, I think it is quite reasonable. :-))



" I'm not sure I understood the solution of your patch, I mean, " what does the vector " " [0] = PACKAGE_VAR_NAME
" [1] = "--option-with-arg="
" [2] = "arbitrary"
" " produce?

It will/should produce something like this:

        "option (`--option-with-arg') requires an argument."

and that's exactly what I want.


Hi

again, sorry for the delay :-)

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.

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?

If so, could you please send me the patch that corrects this problem? :-)

thanks in advance
cheers
        Lorenzo

--
+-----------------------------------------------------+
|  Lorenzo Bettini          ICQ# lbetto, 16080134     |
|  PhD in Computer Science                            |
|  Dip. Sistemi e Informatica, Univ. di Firenze       |
|  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]