[Top][All Lists]

[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: Andre Noll
Subject: Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?
Date: Mon, 10 Apr 2006 18:25:48 +0200
User-agent: Mutt/1.5.9i

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?

> 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 :)

> 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.

> 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:

        struct grab_client *grab_client_new(int fd, int argc, char **argv, int
                int i, ret;
                struct grab_client *gc = para_calloc(sizeof(struct 

                gc->conf = para_calloc(sizeof(struct grab_client_args_info));
                gc->argc = argc;
                gc->argv = para_calloc((argc + 1) * sizeof(char *));

                for (i = 0; i < argc; i++) {
                        gc->argv[i] = para_strdup(argv[i]);
                        PARA_INFO_LOG("argc: %d, argv[%d]: %s\n", argc, i, 
                ret = grab_client_cmdline_parser(gc->argc, gc->argv , gc->conf);

(para_calloc() and para_strdup() are just simple wrappers for calloc() and
strdup() that abort on errors)

During first call of

        para_audioc -- grab -h

(which requests the grab help text from para_audiod) everything works
as expected and the following gets logged by PARA_INFO_LOG():

        Apr 10 17:48:32 meins 2 grab_client_new: argc: 2, argv[0]: grab
        Apr 10 17:48:32 meins 2 grab_client_new: argc: 2, argv[1]: -h

However, the second run gives

        Apr 10 17:49:01 meins 2 grab_client_new: argc: 2, argv[0]: grab
        Apr 10 17:49:01 meins 2 grab_client_new: argc: 2, argv[1]: -h
        grab: invalid option -- ë

Switching back to optind = 0 makes the problem go away.

> 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.

The only person who always got his work done by Friday was Robinson Crusoe

reply via email to

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