Library for console commands syntax check

Discussion in 'C Programming' started by Max, Oct 26, 2010.

  1. Max

    Max Guest

    Hi all

    I'm developing an open source software working with a console interface
    like dos on linux shell. I'm looking for a library or object freely
    usable that will check the correct syntax of the command entered by the
    user before process them. For example I have a command like:

    > command [hex_num_32bit] [a|b] [string]


    I would to know if exist some library that will check, after programmed
    with the correct syntax, that the first param is an hexadecimal 32bit
    number, that the second param is ''a' or 'b' and the thirth parameter
    is a string. I found some libraries making similar jog but are all
    designed for parse command line params. This mean they get params all
    with '-param' or '--param' format (GNU style) that si not my case.

    Thank you for any suggestion you could give me.
    --
    Max, Oct 26, 2010
    #1
    1. Advertising

  2. Max wrote:
    > Hi all
    >
    > I'm developing an open source software working with a console interface
    > like dos on linux shell. I'm looking for a library or object freely
    > usable that will check the correct syntax of the command entered by the
    > user before process them. For example I have a command like:
    >
    >> command [hex_num_32bit] [a|b] [string]

    >
    > I would to know if exist some library that will check, after programmed
    > with the correct syntax, that the first param is an hexadecimal 32bit
    > number, that the second param is ''a' or 'b' and the thirth parameter
    > is a string. I found some libraries making similar jog but are all
    > designed for parse command line params. This mean they get params all
    > with '-param' or '--param' format (GNU style) that si not my case.
    >
    > Thank you for any suggestion you could give me.


    Check this :
    http://www.boost.org/doc/libs/1_44_0/doc/html/program_options.html

    I have found several other similar libraries. Just google for "c++
    library program options parser"
    Vladimir Jovic, Oct 26, 2010
    #2
    1. Advertising

  3. Max

    Rui Maciel Guest

    Max wrote:

    > Hi all
    >
    > I'm developing an open source software working with a console interface
    > like dos on linux shell. I'm looking for a library or object freely
    > usable that will check the correct syntax of the command entered by the
    > user before process them. For example I have a command like:
    >
    >> command [hex_num_32bit] [a|b] [string]



    Hi,

    I'm affraid you will have to write your own parser for that.


    Rui Maciel
    Rui Maciel, Oct 26, 2010
    #3
  4. Max

    Max Guest

    Vladimir Jovic wrote:

    > Max wrote:
    > > Hi all
    > >
    > > I'm developing an open source software working with a console
    > > interface like dos on linux shell. I'm looking for a library or
    > > object freely usable that will check the correct syntax of the
    > > command entered by the user before process them. For example I have
    > > a command like:
    > >
    > > > command [hex_num_32bit] [a|b] [string]

    > >
    > > I would to know if exist some library that will check, after
    > > programmed with the correct syntax, that the first param is an
    > > hexadecimal 32bit number, that the second param is ''a' or 'b' and
    > > the thirth parameter is a string. I found some libraries making
    > > similar jog but are all designed for parse command line params.
    > > This mean they get params all with '-param' or '--param' format
    > > (GNU style) that si not my case.
    > >
    > > Thank you for any suggestion you could give me.

    >
    > Check this :
    > http://www.boost.org/doc/libs/1_44_0/doc/html/program_options.html
    >
    > I have found several other similar libraries. Just google for "c++
    > library program options parser"


    Hi,

    Thank you for your reply. I found this library too but as all the other
    libraries is possible to find with Google it have GNU style, mean
    '--param' that is not my situation... :-(

    --
    Max, Oct 27, 2010
    #4
  5. In comp.lang.c Max <> wrote:

    > Hi all


    > I'm developing an open source software working with a console interface
    > like dos on linux shell. I'm looking for a library or object freely
    > usable that will check the correct syntax of the command entered by the
    > user before process them. For example I have a command like:


    > > command [hex_num_32bit] [a|b] [string]


    > I would to know if exist some library that will check, after programmed
    > with the correct syntax, that the first param is an hexadecimal 32bit
    > number, that the second param is ''a' or 'b' and the thirth parameter
    > is a string.


    All arguments your program receives are strings (thus the check
    of the third parameter is redundant - or do you mean something
    that's enclosed in an extra pair of parenthesis?). So what you
    are loking for isn't related so much to command line arguments
    but something that does checks of what strings may respresent.
    I.e. for the first string (argv[1]) you got to check if it's a
    representation of a hex number that fits into 32 bits and for
    the second string (argv[2]) if it has a strlen() of 1 and con-
    tains either the character 'a' or 'b'. Both things are relati-
    vely simple to do. E.g. for the first one you could use strtol()
    or something similar and the second check is trivial. For more
    complicated cases you probably should check if some regular ex-
    pression library does what you want.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
    Jens Thoms Toerring, Oct 27, 2010
    #5
  6. On Oct 26, 9:24 am, "Max" <> wrote:
    > > command [hex_num_32bit] [a|b] [string]

    >
    > I would to know if exist some library that will check, after programmed
    > with the correct syntax, that the first param is an hexadecimal 32bit
    > number, that the second param is ''a' or 'b' and the thirth parameter
    > is a string.
    > Thank you for any suggestion you could give me.
    >

    sscanf() basically does what you want. You might want a light wrapper
    round it whereby you pass in the argv array and a format string like
    "%x %c %s" and it chops it up and calls sscanf with the argument and
    the matching format.
    Malcolm McLean, Oct 27, 2010
    #6
  7. Malcolm McLean <> writes:
    > On Oct 26, 9:24 am, "Max" <> wrote:
    >> > command [hex_num_32bit] [a|b] [string]

    >>
    >> I would to know if exist some library that will check, after programmed
    >> with the correct syntax, that the first param is an hexadecimal 32bit
    >> number, that the second param is ''a' or 'b' and the thirth parameter
    >> is a string.
    >> Thank you for any suggestion you could give me.
    >>

    > sscanf() basically does what you want. You might want a light wrapper
    > round it whereby you pass in the argv array and a format string like
    > "%x %c %s" and it chops it up and calls sscanf with the argument and
    > the matching format.


    What people seem to forget is that the behavior of sscanf and friends on
    numeric overflow is undefined. I think most implementations behave
    fairly benignly, but there are no guarantees.

    The strto*() functions are safer (but less convenient).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Oct 27, 2010
    #7
  8. On Oct 27, 4:45 pm, Keith Thompson <> wrote:
    > Malcolm McLean <> writes:
    >
    > What people seem to forget is that the behavior of sscanf and friends on
    > numeric overflow is undefined.  I think most implementations behave
    > fairly benignly, but there are no guarantees.
    >

    In a formal sense the functions are totally unusable, unless you
    control the input. Actually they are quite useful. However I recently
    had to take fscanf() out of a program. One data line in a huge file
    had a slightly corrupt line, and there was no easy way to recover from
    fscanfing it. It was replaced by a custom getline() and strtok.
    Malcolm McLean, Oct 28, 2010
    #8
  9. Max

    Jorgen Grahn Guest

    On Wed, 2010-10-27, Max wrote:
    > Vladimir Jovic wrote:
    >
    >> Max wrote:
    >> > Hi all
    >> >
    >> > I'm developing an open source software working with a console
    >> > interface like dos on linux shell. I'm looking for a library or
    >> > object freely usable that will check the correct syntax of the
    >> > command entered by the user before process them. For example I have
    >> > a command like:
    >> >
    >> > > command [hex_num_32bit] [a|b] [string]
    >> >
    >> > I would to know if exist some library that will check, after
    >> > programmed with the correct syntax, that the first param is an
    >> > hexadecimal 32bit number, that the second param is ''a' or 'b' and
    >> > the thirth parameter is a string. I found some libraries making
    >> > similar jog but are all designed for parse command line params.
    >> > This mean they get params all with '-param' or '--param' format
    >> > (GNU style) that si not my case.
    >> >
    >> > Thank you for any suggestion you could give me.

    >>
    >> Check this :
    >> http://www.boost.org/doc/libs/1_44_0/doc/html/program_options.html
    >>
    >> I have found several other similar libraries. Just google for "c++
    >> library program options parser"

    >
    > Hi,
    >
    > Thank you for your reply. I found this library too but as all the other
    > libraries is possible to find with Google it have GNU style, mean
    > '--param' that is not my situation... :-(


    (I assume you're referring to both GNU long options like --param and
    traditional Unix ones like -p.)

    Then perhaps it should *become* your situation. It's not to annoy the
    user they chose to handle the command-line the way they did, back in
    the 1970s -- it's because it's a good user interface.

    (No


    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Nov 5, 2010
    #9
    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. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,967
    Thomas Stegen
    Jun 28, 2003
  2. Ben Finney
    Replies:
    2
    Views:
    987
    Egor Bolonev
    Jun 30, 2003
  3. Tim Stanka
    Replies:
    1
    Views:
    790
    Jeff Epler
    Aug 2, 2004
  4. Max
    Replies:
    7
    Views:
    330
    Malcolm McLean
    Oct 28, 2010
  5. Jean Dubois
    Replies:
    6
    Views:
    96
    Jean Dubois
    Dec 19, 2013
Loading...

Share This Page