Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Shell command line parser library (http://www.velocityreviews.com/forums/t805806-shell-command-line-parser-library.html)

Max 11-11-2011 03:21 PM

Shell command line parser library
 
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

--


Ben Bacarisse 11-11-2011 04:29 PM

Re: Shell command line parser library
 
"Max" <noname@noreply.com> writes:

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

--
Ben.

Robert Hairgrove 11-11-2011 05:04 PM

Re: Shell command line parser library
 
On 11/11/2011 04:21 PM, Max wrote:
> 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...m_options.html

I haven't used it yet, so I don't know if it does what you want.

Joe Pfeiffer 11-11-2011 07:04 PM

Re: Shell command line parser library
 
"Max" <noname@noreply.com> writes:

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

Jorgen Grahn 11-11-2011 11:30 PM

Re: Shell command line parser library
 
["Followup-To:" header set to comp.lang.c++.]
On Fri, 2011-11-11, Max wrote:
> 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

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .


All times are GMT. The time now is 09:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.