Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Shell command line parser library

Reply
Thread Tools

Shell command line parser library

 
 
Max
Guest
Posts: n/a
 
      11-11-2011
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

--

 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-11-2011
"Max" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Robert Hairgrove
Guest
Posts: n/a
 
      11-11-2011
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:rogram_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.
 
Reply With Quote
 
Joe Pfeiffer
Guest
Posts: n/a
 
      11-11-2011
"Max" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-11-2011
["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 .
 
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
Shell command line parser library Max C Programming 4 11-11-2011 11:30 PM
Best command for running shell command Donald Duck Python 3 07-11-2006 03:05 PM
Run Unix shell command $ parse command line arguments in python rkoida@yahoo.com Python 4 04-23-2005 04:42 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM
Capture external command output line by line on Windows 98, shell problem. Dib Urim Perl Misc 4 12-03-2003 07:57 PM



Advertisments