Library for console commands syntax check

M

Max

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

Vladimir Jovic

Max said:
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"
 
R

Rui Maciel

Max said:
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
 
M

Max

Vladimir said:
Max said:
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... :-(

--
 
J

Jens Thoms Toerring

In comp.lang.c Max said:
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
 
M

Malcolm McLean

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

Keith Thompson

Malcolm McLean said:
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).
 
M

Malcolm McLean

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

Jorgen Grahn

Vladimir said:
Max said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top