bug-wget
[Top][All Lists]
Advanced

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

Re: [Bug-wget] Having some problems with getopt_long


From: vivi
Subject: Re: [Bug-wget] Having some problems with getopt_long
Date: Wed, 04 Aug 2010 16:52:01 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100620 Icedove/3.0.5

On 04/08/10 15:26, Giuseppe Scrivano wrote:
> Hello!
> 
> thanks for working on this.
> 
> vivi <address@hidden> writes:
> 
>> Hi all
>>
>> I've got the config option working to some extent, however, after the
>> first run of getopt_long, it ignores the second getopt_long that takes
>> the rest of the users options. So any options other than --config are
>> ignored. I'm not sure why, if anyone could shed any light on the topic,
>> it would be greatly appreciated.
>>
>> I've attached main.c, 899 - 928 is where the problem seems to be.
> 
> Can you please send a diff the next time? :-)  If you are working on the
> Bazaar repository, you can get it with "bzr diff [FILE...]".

Ah OK, will do next time :)

> 
>>   while ((retconf = getopt_long(argc, argv, 
>>                                 short_options, long_options, &longindex)) != 
>> -1)
> 
> Please leave an empty space between the function name and the opening
> '('.  Also remove the trailing white space on the same line.
> 
> As:
> 
>   while ((retconf = getopt_long (argc, argv,
>                                 short_options, long_options, &longindex)) != 
> -1)
> 
> 
>>
>>   /*If the user did not use the config flag, read the system wgetrc and 
>> ~/.wgetrc. */
>>   if (use_userconfig == false)
>>     initialize();
> 
> Same here.
> 
> 
> 
>>   longindex = -1;
>>   while ((ret = getopt_long (argc, argv,
>>                              short_options, long_options, &longindex)) != -1)
>>     {
> 
> In order to use a getopt_long loop again I think there is need to reset
> `optind' too.  So you'll have:
> 
>   optind = 0;
>   longindex = -1;
>   while ((ret = getopt_long (argc, argv,
>                              short_options, long_options, &longindex)) != -1)
> 
> 
> I am not sure this will not cause problems too, I have never seen
> getopt_long called in this way.  I will investigate better.

Great, it works now! However, one problem I found is that if a
unrecognized option is given, an error is posted twice, most likely due
to getopt_long running twice.

e.g

address@hidden ~/wget/trunk]$ ./src/wget --bingbong
./src/wget: unrecognized option '--bingbong'
./src/wget: unrecognized option '--bingbong'
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.

Reza




reply via email to

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