What is the "boost way" of parsing command line arguments? When I searched the archives, some user recommended spirit for this task, but this seems to heavy-weighted for me. I tried tokenizer, but a seperator for the command line is not provided. - you have to remove quotations marks (only escaped_list_separator can do this) - your have to ignore multiple tokens (only char_seperator can do this) If I write this seperator its still wouldn't provide the api I would like to see for a command line parser. I saw in the past there have been an attemp by Bill Kempf to provide a command line parser for boost but it didn't find its way into the library from reasons I don't know. So is there a recommended way to parse options I did overlook? Is a command line parser planned? Thanks for your answers, CL
cl_corba_at wrote:
What is the "boost way" of parsing command line arguments?
When I searched the archives, some user recommended spirit for this task, but this seems to heavy-weighted for me.
I tried tokenizer, but a seperator for the command line is not provided. - you have to remove quotations marks (only escaped_list_separator can do this) - your have to ignore multiple tokens (only char_seperator can do this) If I write this seperator its still wouldn't provide the api I would like to see for a command line parser.
I saw in the past there have been an attemp by Bill Kempf to provide a command line parser for boost but it didn't find its way into the library from reasons I don't know.
So is there a recommended way to parse options I did overlook? Is a command line parser planned?
As far as I remember Vladimir Prus has requested Boost review for his program_options library. You can find it here: http://zigzag.cs.msu.su:7813/program_options I've used it for several applications and must say, that it is very simple, powerful and flexible to use. Regards Hartmut
The URL appears to be invalid. joe -----Original Message----- From: HartmutKaiser@t-online.de [mailto:HartmutKaiser@t-online.de] Sent: Monday, April 14, 2003 3:04 AM To: Boost-Users@yahoogroups.com Subject: RE: [Boost-Users] command line parsing As far as I remember Vladimir Prus has requested Boost review for his program_options library. You can find it here: http://zigzag.cs.msu.su:7813/program_options I've used it for several applications and must say, that it is very simple, powerful and flexible to use. Regards Hartmut
cl_corba_at wrote:
What is the "boost way" of parsing command line arguments?
When I searched the archives, some user recommended spirit for
task, but this seems to heavy-weighted for me.
I tried tokenizer, but a seperator for the command line is not provided. - you have to remove quotations marks (only escaped_list_separator can do this) - your have to ignore multiple tokens (only char_seperator can do this) If I write this seperator its still wouldn't provide the api I would like to see for a command line parser.
I saw in the past there have been an attemp by Bill Kempf to
a command line parser for boost but it didn't find its way into
Thanks a lot for this link. I am glad to see that there is a library into review process. When I checked the documentation, I saw that windows command line (WinMain - whole arguments without programm name in a C-string) are not supported. So someone has to use tokenizer to split the string into a vector and a seperator is still missing. CL --- In Boost-Users@yahoogroups.com, HartmutKaiser@t... wrote: this provide the
library from reasons I don't know.
So is there a recommended way to parse options I did overlook? Is a command line parser planned?
As far as I remember Vladimir Prus has requested Boost review for his program_options library. You can find it here:
http://zigzag.cs.msu.su:7813/program_options
I've used it for several applications and must say, that it is very simple, powerful and flexible to use.
Regards Hartmut
Many compilers suport a workaround for this in the form of __argc, __argv global variables. I known Borland do it and I think VC++ also does it. The runtime library help of your compiler should take any doubts. I made a simple function to parse the windows command line, for a Windows CE application (using my own tokenizer class). It's very basic and it's not general enough, but if you are interested just drop me a line (it handles "" delimeters in a basic way). ~Nuno Lucas On 14 Apr 2003 at 11:40, cl_corba_at wrote:
Thanks a lot for this link. I am glad to see that there is a library into review process.
When I checked the documentation, I saw that windows command line (WinMain - whole arguments without programm name in a C-string) are not supported.
So someone has to use tokenizer to split the string into a vector and a seperator is still missing.
CL
-------------------- SDI - Sistemas e Desenvolvimento Informático Rua Nova da Estação, 315 -- 4710-234 Braga Tel: 253 268 690/1 Fax: 253 268 692
cl_corba_at wrote:
Thanks a lot for this link. I am glad to see that there is a library into review process.
When I checked the documentation, I saw that windows command line (WinMain - whole arguments without programm name in a C-string) are not supported.
Right, the library assumes argc/argv or vector of strings.
So someone has to use tokenizer to split the string into a vector and a seperator is still missing.
I guess that's the right job for boost::tokenizer... Frankly, I've missed the WinMain case, and not sure what to do. The problem is that single string might erase important information --- what happens if you have command line argument with embedded space. Maybe, using __argv/__argc, as suggested by Nuno Lucas is just better. - Volodya
I guess that's the right job for boost::tokenizer...
The problem is, that a command line seperator for the tokenizer is not provided by boost, so you rely on external code. If I use the tokenizer, I have to parse the arguments, copy them in a vector and then pass it to your module.
Frankly, I've missed the WinMain case, and not sure what to do. The problem is that single string might erase important information --- what happens if you have command line argument with embedded space.
Embedded spaces should be placed in quotation marks which should be removed by the tokenizer. Arguments could be seperated by one ore more space.
Maybe, using __argv/__argc, as suggested by Nuno Lucas is just better.
This is what I will use now, but what I don't like on this solution is that it is compiler dependand. CL
cl_corba_at wrote:
I guess that's the right job for boost::tokenizer...
The problem is, that a command line seperator for the tokenizer is not provided by boost, so you rely on external code.
I assumed you only have to separate on whitespace, so existing tokenizers will do.
If I use the tokenizer, I have to parse the arguments, copy them in a vector and then pass it to your module.
Yep, but is this a problem. Something like: boost::tokenizer<...> tok(...); options_and_arguments oa = parse_command_line(vector<string>(tok.begin(), tok.end())); (Of course, provided there's something you can put in "...")
Frankly, I've missed the WinMain case, and not sure what to do. The problem is that single string might erase important information --- what happens if you have command line argument with embedded space.
Embedded spaces should be placed in quotation marks which should be removed by the tokenizer. Arguments could be seperated by one ore more space.
Do you mean that if I type
program "a b c" "C:/Program files"
then the program will receive this string, with quotes there? (The linux
shell will strip quotes completely). If this is so, then it's possibe to
implement. For example, the following program:
#include<iostream>
#include
Maybe, using __argv/__argc, as suggested by Nuno Lucas is just better.
This is what I will use now, but what I don't like on this solution is that it is compiler dependand.
I understand your concerns. Is the solution above is sufficient, I can move it into the library. OTOH, I'd rather not to reimplement all the windowns shell quoting rules inside program_options (especially and I don't seem to understand them). - Volodya
participants (5)
-
cl_corba_at
-
HartmutKaiser@t-online.de
-
Joe Mariadassou
-
Nuno Lucas
-
Vladimir Prus