Shell command line parser library

M

Max

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

--
 
B

Ben Bacarisse

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

Robert Hairgrove

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

Joe Pfeiffer

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

Jorgen Grahn

["Followup-To:" header set to comp.lang.c++.]
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
 

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

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top