Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > PBM: getopt_long doesn't process more than one long option table

Reply
Thread Tools

PBM: getopt_long doesn't process more than one long option table

 
 
Vince C.
Guest
Posts: n/a
 
      07-16-2007
Hi.

I've isntalled Bloodshed Dev-C++ 4.9.9 for Windows. It comes with MinGW
3.4.2. I'm trying to use getopt_long() in my console application to parse
multiple command line arguments syntaxes. I do that by looping through many
arrays of struct options. It looks like getopt_long() only processes the
first array of options; it returns -1 immediately on the second array
onwards. Here's the code I used:

#include <cstdlib>
#include <iostream>
#include <getopt.h>

using namespace std;

int main(int argc, char *argv[])
{
static option instArray[] = {
{ "install", required_argument, NULL, 'f' },
{ "name", required_argument, NULL, 'l' },
{ "description", required_argument, NULL, 'n' },
{ "title", required_argument, NULL, 'd' },
{ }
};
static option helpArray[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' },
{ }
};
static struct optItem {
char* name;
char* shortOpts;
option* opts;
} optArray[] = {
{ "Help", "-f:l:n:d:", helpArray },
{ "Install", "hv", instArray }
};
const unsigned nArrayLength = sizeof(optArray) / sizeof(optArray[0]);

// Loop twice with long option arrays
for ( int i = 0, option,; i < nArrayLength; i++ )
{
int optIndex = 0;
cout << "Arg table: " << optArray[i].name << endl;
while ( (option = getopt_long(argc, argv,
optArray[i].shortOpts, optArray[i].opts,
&optIndex)) != -1
)
if ( option == 1 )
cout << " Argument " << optarg << " found." << endl;
}
}


Here's the output:

Arg table: Help
Argument install found.
D:\Projects\Examples\Getopt\getopt.exe: unknown option -- v
D:\Projects\Examples\Getopt\getopt.exe: unknown option -- b
Arg table: Install


I expected

Arg table: Help
Argument install found.
D:\Projects\Examples\Getopt\getopt.exe: unknown option -- v
D:\Projects\Examples\Getopt\getopt.exe: unknown option -- b
Arg table: Install
Argument install found.
D:\Projects\Examples\Getopt\getopt.exe: unknown option -- v
D:\Projects\Examples\Getopt\getopt.exe: unknown option -- b

Did I do something wrong or is it a bug?

Thanks in advance,
Vince C.


 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      07-17-2007
Vince C. wrote:
> Hi.
>
> I've isntalled Bloodshed Dev-C++ 4.9.9 for Windows. It comes with MinGW
> 3.4.2. I'm trying to use getopt_long() in my console application to parse
> multiple command line arguments syntaxes. I do that by looping through many
> arrays of struct options. It looks like getopt_long() only processes the
> first array of options; it returns -1 immediately on the second array
> onwards. Here's the code I used:
>


Unfortunately, Vince, getopt_long() is not part of the C++ standard
(ISO/IEC 14882:1998 or 14882:2003), and as such, is off-topic here.
However, I would recommend you ask in gnu.g++.help, where it would be
on-topic.

> [code redacted]

 
Reply With Quote
 
 
 
 
Vince C.
Guest
Posts: n/a
 
      07-17-2007
red floyd wrote:

> Unfortunately, Vince, getopt_long() is not part of the C++ standard
> (ISO/IEC 14882:1998 or 14882:2003), and as such, is off-topic here.
> However, I would recommend you ask in gnu.g++.help, where it would be
> on-topic.
>
>> [code redacted]


Sorry, I thought comp.std.c++ was about C++ standards and comp.lang.c++
about everything else. I have no descriptions about the forums in my NNTP
client. I also thought gnu.g++ was about compiler g++ only...

It's a bit tricky to find the appropriate group, I'm sorry :s ...

Thanks for the info. I'll post over gnu.g++.

--

Vince C.
 
Reply With Quote
 
Vince C.
Guest
Posts: n/a
 
      07-17-2007
red floyd wrote:

> Unfortunately, Vince, getopt_long() is not part of the C++ standard
> (ISO/IEC 14882:1998 or 14882:2003), and as such, is off-topic here.
> However, I would recommend you ask in gnu.g++.help, where it would be
> on-topic.
>
>> [code redacted]


Too bad... I see only *one* post ("Spammed by FAX") in gnu.g++ . I think
that forum is dead... I just hope there is a chance I get a response
somewhere...

--

Vince C.
 
Reply With Quote
 
Lionel B
Guest
Posts: n/a
 
      07-17-2007
On Tue, 17 Jul 2007 11:48:45 +0200, Vince C. wrote:

> red floyd wrote:
>
>> Unfortunately, Vince, getopt_long() is not part of the C++ standard
>> (ISO/IEC 14882:1998 or 14882:2003), and as such, is off-topic here.
>> However, I would recommend you ask in gnu.g++.help, where it would be
>> on-topic.
>>
>>> [code redacted]

>
> Too bad... I see only *one* post ("Spammed by FAX") in gnu.g++


Is there actually such a ng? Try gnu.g++.help.

--
Lionel B
 
Reply With Quote
 
Vince C.
Guest
Posts: n/a
 
      07-17-2007
Lionel B wrote:

>> Too bad... I see only *one* post ("Spammed by FAX") in gnu.g++

>
> Is there actually such a ng? Try gnu.g++.help.


Yes, there is one. But gnu.g++.help looks a little bit busier so I'll post
there.

Thanks.

--

Vince C.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      07-18-2007
On Jul 17, 11:45 am, "Vince C." <(E-Mail Removed)> wrote:
> red floyd wrote:
> > Unfortunately, Vince, getopt_long() is not part of the C++ standard
> > (ISO/IEC 14882:1998 or 14882:2003), and as such, is off-topic here.
> > However, I would recommend you ask in gnu.g++.help, where it would be
> > on-topic.


> >> [code redacted]


> Sorry, I thought comp.std.c++ was about C++ standards and comp.lang.c++
> about everything else.


comp.std.c++ is about the C++ standard itself. comp.lang.c++ is
about everything that concerns C++ in general, but excludes
platform and implementation specific issues. The distinction
isn't always very clear. Discussion about threading in C++ is
certainly relevant, but basic threading algorithms aren't, nor
are details of a platform-specific threading API. The classic
"test" is that if the answer would be more or less the same for
most platforms, but different for a different language, the post
belongs here, but if the answer would be more or less the same
for different languages, but different for different platforms,
it's off topic. But of course, that test supposes that you know
the answer before posing the question.

In this case, getopts_long is very much 1) a GNUism, and 2)
available in C and (probably) in other languages as well.
Questions about how best to encapsulate it in a C++ class (or
whether there exist C++ alternatives) would probably be on
topic, but that's about it.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to ‘(const __gnu_cxx::hash<long long int>) (const long long int&)’ veryhotsausage C++ 1 07-04-2008 05:41 PM
Will one ASP .Net worker process use more than one CPU? =?Utf-8?B?Sm9obiBCYWlsZXk=?= ASP .Net 3 09-14-2007 05:32 PM
getopt and getopt_long for Windows? Angel Tsankov C++ 1 03-03-2006 02:02 PM
getopt_long problem jenea C Programming 2 02-26-2005 12:11 AM
getopt_long() problems Karthik C Programming 2 01-22-2004 04:42 PM



Advertisments