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

Discussion in 'C++' started by Vince C., Jul 16, 2007.

  1. Vince C.

    Vince C. Guest

    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.name << endl;
    while ( (option = getopt_long(argc, argv,
    optArray.shortOpts, optArray.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.
     
    Vince C., Jul 16, 2007
    #1
    1. Advertising

  2. Vince C.

    red floyd Guest

    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]
     
    red floyd, Jul 17, 2007
    #2
    1. Advertising

  3. Vince C.

    Vince C. Guest

    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.
     
    Vince C., Jul 17, 2007
    #3
  4. Vince C.

    Vince C. Guest

    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.
     
    Vince C., Jul 17, 2007
    #4
  5. Vince C.

    Lionel B Guest

    Re: PBM: getopt_long doesn't process more than one long optiontable

    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
     
    Lionel B, Jul 17, 2007
    #5
  6. Vince C.

    Vince C. Guest

    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.
     
    Vince C., Jul 17, 2007
    #6
  7. Vince C.

    James Kanze Guest

    On Jul 17, 11:45 am, "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]


    > 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:
    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
     
    James Kanze, Jul 18, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Will one ASP .Net worker process use more than one CPU?

    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Sep 10, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    783
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=
    Sep 14, 2007
  2. Merciadri Luca
    Replies:
    4
    Views:
    841
  3. Hemant Shah
    Replies:
    9
    Views:
    94
    Hemant Shah
    Sep 24, 2006
  4. Steven D'Aprano
    Replies:
    0
    Views:
    133
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    107
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page