Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Library for console commands syntax check

Reply
Thread Tools

Library for console commands syntax check

 
 
Max
Guest
Posts: n/a
 
      10-26-2010

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.
--

 
Reply With Quote
 
 
 
 
Vladimir Jovic
Guest
Posts: n/a
 
      10-26-2010
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...m_options.html

I have found several other similar libraries. Just google for "c++
library program options parser"
 
Reply With Quote
 
 
 
 
Rui Maciel
Guest
Posts: n/a
 
      10-26-2010
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
 
Reply With Quote
 
Max
Guest
Posts: n/a
 
      10-27-2010
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...m_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...

--

 
Reply With Quote
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      10-27-2010
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
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      10-27-2010
On Oct 26, 9:24*am, "Max" <non...@noreply.com> 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.


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-27-2010
Malcolm McLean <> writes:
> On Oct 26, 9:24Â*am, "Max" <non...@noreply.com> 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) kst- <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"
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      10-28-2010
On Oct 27, 4:45*pm, Keith Thompson <ks...@mib.org> wrote:
> Malcolm McLean <malcolm.mcle...@btinternet.com> 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.



 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-05-2010
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...m_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 .
 
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
Library for console commands syntax check Max C++ 7 10-28-2010 09:29 AM
Cisco console commands quick reference? alexviseu Cisco 1 07-10-2006 09:27 AM
Need Help Differentiating Bad Commands From Incomplete Commands Tim Stanka Python 1 08-02-2004 02:08 AM
Re: console mp3->wav decoder for $indows or GUI one which supports console Ben Finney Python 2 06-30-2003 05:43 AM
Re: man pages for C commands (GCC commands) Ben Pfaff C Programming 4 06-28-2003 06:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57