Shell command line parser library

Discussion in 'C++' started by Max, Nov 11, 2011.

  1. Max

    Max Guest

    Hi all

    I excuse me in advance if this group is not the right place to post my
    question but I don't have a clear idea regarding the right place could
    be. I'm developing a console application accepting custom command like,
    for example, a common shell can do. I developed my our command parser
    but I'm not very satisfied with it and I would to know if there is some
    ready made and more powered lirbary (in C++ or C) for parse command
    line commands. After some search I found there are some libraries
    making this job (like tclap, argtable and so on) but the problem is
    that all these libraries accept command in POSIX standard (mean
    -[command] [param]). Instead of this approac I need a parser working
    with standard command that can have more than one option like:

    >[command] [opt1] [opt2] [opt2] ....


    A pratical example could be:

    >read 0x12345 100 b 12


    Someone know if such library exist?

    Thank you to all

    --
    Max, Nov 11, 2011
    #1
    1. Advertising

  2. "Max" <> writes:

    > I excuse me in advance if this group is not the right place to post my
    > question but I don't have a clear idea regarding the right place could
    > be.


    You might have more luck is a system-specific group, though argument
    parsing can be done almost entirely in portable C.

    > I'm developing a console application accepting custom command like,
    > for example, a common shell can do. I developed my our command parser
    > but I'm not very satisfied with it and I would to know if there is some
    > ready made and more powered lirbary (in C++ or C) for parse command
    > line commands. After some search I found there are some libraries
    > making this job (like tclap, argtable and so on) but the problem is
    > that all these libraries accept command in POSIX standard (mean
    > -[command] [param]). Instead of this approac I need a parser working
    > with standard command that can have more than one option like:
    >
    >>[command] [opt1] [opt2] [opt2] ....

    >
    > A pratical example could be:
    >
    >>read 0x12345 100 b 12

    >
    > Someone know if such library exist?


    I think you've found at least one. I can't see why argtable (for
    example) can't be used to do what you want. You may need to say a bit
    more about what forms you are considering, since, as it stands, there is
    no parsing to do! I may have misunderstood what it is you want.

    --
    Ben.
    Ben Bacarisse, Nov 11, 2011
    #2
    1. Advertising

  3. On 11/11/2011 04:21 PM, Max wrote:
    > Hi all
    >
    > I excuse me in advance if this group is not the right place to post my
    > question but I don't have a clear idea regarding the right place could
    > be. I'm developing a console application accepting custom command like,
    > for example, a common shell can do. I developed my our command parser
    > but I'm not very satisfied with it and I would to know if there is some
    > ready made and more powered lirbary (in C++ or C) for parse command
    > line commands. After some search I found there are some libraries
    > making this job (like tclap, argtable and so on) but the problem is
    > that all these libraries accept command in POSIX standard (mean
    > -[command] [param]). Instead of this approac I need a parser working
    > with standard command that can have more than one option like:
    >
    >> [command] [opt1] [opt2] [opt2] ....

    >
    > A pratical example could be:
    >
    >> read 0x12345 100 b 12

    >
    > Someone know if such library exist?
    >
    > Thank you to all
    >


    Check out boost::program_options here ...

    http://www.boost.org/doc/libs/1_47_0/doc/html/program_options.html

    I haven't used it yet, so I don't know if it does what you want.
    Robert Hairgrove, Nov 11, 2011
    #3
  4. Max

    Joe Pfeiffer Guest

    "Max" <> writes:

    > Hi all
    >
    > I excuse me in advance if this group is not the right place to post my
    > question but I don't have a clear idea regarding the right place could
    > be. I'm developing a console application accepting custom command like,
    > for example, a common shell can do. I developed my our command parser
    > but I'm not very satisfied with it and I would to know if there is some
    > ready made and more powered lirbary (in C++ or C) for parse command
    > line commands. After some search I found there are some libraries
    > making this job (like tclap, argtable and so on) but the problem is
    > that all these libraries accept command in POSIX standard (mean
    > -[command] [param]). Instead of this approac I need a parser working
    > with standard command that can have more than one option like:
    >
    >>[command] [opt1] [opt2] [opt2] ....

    >
    > A pratical example could be:
    >
    >>read 0x12345 100 b 12

    >
    > Someone know if such library exist?
    >
    > Thank you to all


    If that's really what your commands look like, you'll be hard pressed to
    find a library that will be easier to use than just pulling the
    arguments out of argv.
    Joe Pfeiffer, Nov 11, 2011
    #4
  5. Max

    Jorgen Grahn Guest

    ["Followup-To:" header set to comp.lang.c++.]
    On Fri, 2011-11-11, Max wrote:
    > Hi all
    >
    > I excuse me in advance if this group is not the right place to post my
    > question but I don't have a clear idea regarding the right place could
    > be. I'm developing a console application accepting custom command like,
    > for example, a common shell can do. I developed my our command parser
    > but I'm not very satisfied with it and I would to know if there is some
    > ready made and more powered lirbary (in C++ or C)


    I guess that means you're going to use it from C++, right? Then why
    the crosspost to comp.lang.c? It's not as if C++ users are ignorant
    of important C libraries; we use them all the time.

    > for parse command
    > line commands. After some search I found there are some libraries
    > making this job (like tclap, argtable and so on) but the problem is
    > that all these libraries accept command in POSIX standard (mean
    > -[command] [param]).


    That's not the normal way of naming things. What you call "command" is
    called an "option character" or a "flag", and it's only one letter,
    e.g. "-o foo". And you also have the non-option arguments, which is
    basically what's left of argv after processing the options.

    > Instead of this approac I need a parser working
    > with standard command that can have more than one option like:
    >
    >>[command] [opt1] [opt2] [opt2] ....

    >
    > A pratical example could be:
    >
    >>read 0x12345 100 b 12

    >
    > Someone know if such library exist?


    Although it's a bit unclear, I will assume that you're not talking
    about the arguments passed to your main(), but that you get lines of
    text from the user (perhaps standard input) which are commands.

    Last time I did something like this I did it myself; it's not that hard.
    But in retrospect I think I should have:

    - taken the line of text
    - tokenized it on whitespace (possibly allowing "foo bar" to be one
    token) to argv-style
    - chopped off the first one for use as the "command name"
    - in the handling of each command, parsed the arguments using POSIX
    getopt() or the GNU extension

    That way I'd get a proven and well-known meta-language, not an ad-hoc
    one invented by me.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Nov 11, 2011
    #5
    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. Replies:
    2
    Views:
    5,665
    Jonathan Bromley
    Feb 18, 2005
  2. Replies:
    4
    Views:
    1,697
    Terry Hancock
    Apr 23, 2005
  3. Donald Duck

    Best command for running shell command

    Donald Duck, Jul 11, 2006, in forum: Python
    Replies:
    3
    Views:
    393
    iapain
    Jul 11, 2006
  4. Max

    Shell command line parser library

    Max, Nov 11, 2011, in forum: C Programming
    Replies:
    4
    Views:
    702
    Jorgen Grahn
    Nov 11, 2011
  5. Dib Urim
    Replies:
    4
    Views:
    185
    Michele Dondi
    Dec 3, 2003
Loading...

Share This Page