help-gengetopt
[Top][All Lists]
Advanced

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

Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?


From: Lorenzo Bettini
Subject: Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?
Date: Thu, 13 Apr 2006 11:09:10 +0200
User-agent: Mail/News 1.5 (X11/20060228)

Andre Noll wrote:
On 21:40, Lorenzo Bettini wrote:
actually I haven't found your explanation (Andre) in the info file of glibc,

to which explanation are you referring here?

This one:

The problem is that gengetopt generates code that always sets the
extern variable "optind" to one before entering the loop which calls
getopt_long(). According to POSIX, this instructs getopt_long() to
continue to parse those command line options that were passed to it
during the previous call.

actually optind is the index of the next argument to scan (1 because the 0 is the program name)


indeed the files you sent me work even with optind = 1.

Yes, they were meant to illustrate how to link more than one parser
to a single binary, not to demonstrate the optind = 0 vs. optind =
1 issue :)

OK :-)


I guess the problems you used to have were due to the fact that getopt expects the first argument in the argv array to be the name of the program (and so it discards it). So you always have to put a first element in the vector.

split_args() puts the name of the first arg to argv[0]. Of course,
that's not the name of a program, but that shouldn't matter, should
it? Anyway, I now use a variant of your improved version.

that name will be printed in case of errors thus it's up to the programmer to put a correct name (in your case you put the name of the option that fires the second scanning and this makes sense)


I think the right behavior is to go back to optind = 1

I tested the problematic "grab" command of para_audiod again with
optind = 1, and it doesn't work. Maybe there's something wrong with
my code, I'll doublecheck it and try to come up with a simpler program
that demonstrates the issue.

In case anybody sees anything suspicious, here are the relevant lines:


<SNIP>

OK, I'll check it!

Notice that, if you use the configuration parser generated by gengetopt, this will construct a correct array (by inserting, as the first element, the name of the program).

I'm not sure I understand this as I don't see where the config parser
constructs an array.

probably because you did not enable the config parser feature in gengetopt?

cheers
        Lorenzo

--
+-----------------------------------------------------+
|  Lorenzo Bettini          ICQ# lbetto, 16080134     |
|  PhD in Computer Science                            |
|  Dip. Sistemi e Informatica, Univ. di Firenze       |
|  Tel +39 055 4237460, Fax +39 055 4237437           |
|  Florence - Italy        (GNU/Linux User # 158233)  |
|  Home Page        : http://www.lorenzobettini.it    |
|  http://music.dsi.unifi.it         XKlaim language  |
|  http://www.purplesucker.com Deep 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]