[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, 1 May 2006 17:04:43 +0200 |
User-agent: |
Mutt/1.5.9i |
On 21:04, Lorenzo Bettini wrote:
> Andre Noll wrote:
> >Unfortunately, "optind = 0 means initialize" seems to be a glibc
> >feature that is not backed up by POSIX. So I agree that gengetopt
> >should not rely on it. Which leaves the question how to tell getopt
> >to discard any internal pointers in a portable way.
> >
>
> I guess the right thing to do is to never free arguments passed to
> getopt_long if another call has to be made: this seems to never be safe
> (even because getopt_long can rearrange the elements, as documented).
That's bad news to me as my application reads one line at a time from
a client, calls a suitable parser (depending on the first word in
the line), does some work and starts over. So the same parser can be
called arbitrary often, and the command line options of the previous
call are completely irrelevant for the next call. What should I do
in this situation?
> I uploaded a newer version here
>
> http://rap.dsi.unifi.it/~bettini/gengetopt-2.17rc.tar.gz
>
> I still haven't documented the use of multiple parsers but there's the
> test test_multiple_parsers that can be taken as an example of usage of
> three parsers.
>
> there's the new parser function that can be generated with the gengetopt
> command line
>
> -S, --string-parser generate a string parser (the string
> contains the command line)
>
> see the test test_multiple_parsers.c
Nice. That saves some work as the application no longer has to split
the command line. However, I fail to see how this solves the above
problem. What I need is something like the following pseudo code:
while (read line from client(line)) {
if (first word of line is "first_cmd")
if (test_first_cmdline_cmd_parser_string(line +
strlen("first_cmd"),
&first_args_info, "first_cmd") == 0) {
do_work(&first_args_info);
continue;
}
}
This does not work for me because glibc's getopt internally keeps
a pointer to the command line during the first call and uses this
pointer during the second call. At that time the pointer is either
no longer valid (in case "line" gets dynamically allocated and freed
after do_work()), or points to some random place in "line" (if "line"
is a static buffer which has new contents).
> Of course I switched back to optind = 1
Of course, that made paraslash's grab command stop working ;)
Regards
Andre
--
The only person who always got his work done by Friday was Robinson Crusoe
signature.asc
Description: Digital signature
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?,
Andre Noll <=
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Lorenzo Bettini, 2006/05/02
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Andre Noll, 2006/05/04
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Lorenzo Bettini, 2006/05/05
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Andre Noll, 2006/05/06
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Lorenzo Bettini, 2006/05/07
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Andre Noll, 2006/05/08
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Lorenzo Bettini, 2006/05/11
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Andre Noll, 2006/05/13
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Lorenzo Bettini, 2006/05/14
- Re: [help-gengetopt] make cmd_line_list and cmd_line_list_tmp static?, Andre Noll, 2006/05/16