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