Program options: terminating parsing.
As context I would like to say that read "The C++ Programming Language" first edition and thought, "That sounds interesting." and then didn't think of it again 'til about a a couple of months ago, when I read Accelerated C++ on the recommendation of a friend and then updated my original copy to the third edition. So I have NO useful C++ experience, please point out even the most obvious things, I really could be that dumb. I have started a non trivial project that I hope will cement some of the things I've read. And that's where boost comes in. I had some success with using boost_filesystem, so I think I am able to extract basic usage out of the documentation but I've failed to find what I'm looking for in program_options. I would really like to parse a line that has the the form: word [options]... nother option-like-non-option-word... so for instance -F after "word" indicates a legitimate value but -F after "nother" shouldn't set or change the value and indeed might not even have a "value" I've been considering producing a class defining operator() to be used as an additional parser that would recognize the second bare word and make all options thereafter into some list for a dummy option, like the file names in the example. However there is mention of allowing multi word options being "not enabled by default" and I thought that the style argument might be the key, but what I've managed to work out from reading a tarball I downloaded of 1_32_0 seems to use style for changing how single words are interpreted. So before I go crazy trying to implement something that sounds easy to say but beyond my ken, is there a method I'm overlooking for terminating the parsing of the command line before the words are all consumed? Thanks for your time, I'll try to be more brief in future. :) -- Blue Skies
The Grumpiest Man You Know wrote:
As context I would like to say that read "The C++ Programming Language" first edition and thought, "That sounds interesting." and then didn't think of it again 'til about a a couple of months ago, when I read Accelerated C++ on the recommendation of a friend and then updated my original copy to the third edition. So I have NO useful C++ experience, please point out even the most obvious things, I really could be that dumb. I have started a non trivial project that I hope will cement some of the things I've read. And that's where boost comes in.
I had some success with using boost_filesystem, so I think I am able to extract basic usage out of the documentation but I've failed to find what I'm looking for in program_options.
I would really like to parse a line that has the the form: word [options]... nother option-like-non-option-word...
so for instance -F after "word" indicates a legitimate value but -F after "nother" shouldn't set or change the value and indeed might not even have a "value"
Can you provide a real example of the syntax you want to support? Why do you want "-F" to mean different things depending on the position on the command line? - Volodya
On Thu, 24 Feb 2005 12:21:06 +0300, Vladimir Prus
The Grumpiest Man You Know wrote:
As context I would like to say that read "The C++ Programming Language" first edition and thought, "That sounds interesting." and then didn't think of it again 'til about a a couple of months ago, when I read Accelerated C++ on the recommendation of a friend and then updated my original copy to the third edition. So I have NO useful C++ experience, please point out even the most obvious things, I really could be that dumb. I have started a non trivial project that I hope will cement some of the things I've read. And that's where boost comes in.
I had some success with using boost_filesystem, so I think I am able to extract basic usage out of the documentation but I've failed to find what I'm looking for in program_options.
I would really like to parse a line that has the the form: word [options]... nother option-like-non-option-word...
so for instance -F after "word" indicates a legitimate value but -F after "nother" shouldn't set or change the value and indeed might not even have a "value"
Can you provide a real example of the syntax you want to support? Why do you want "-F" to mean different things depending on the position on the command line?
Sorry for the slow response, rl sucks. :) Well it's because there are two separate lists of options. One to the program that I'm parsing for and one for code that we just perform a pass through to. I have no control over the options recognized by the other guy I just want to stop parsing when I get to them. My solution was to create a class that defined operator() and use it as the additional parser. Then once I spot the change from "my" to "his" part. I stick all the words n a dummy option. Thanks for taking the time to read and reply.
The Grumpiest Man You Know wrote:
Can you provide a real example of the syntax you want to support? Why do you want "-F" to mean different things depending on the position on the command line?
Sorry for the slow response, rl sucks. :)
Well it's because there are two separate lists of options. One to the program that I'm parsing for and one for code that we just perform a pass through to. I have no control over the options recognized by the other guy I just want to stop parsing when I get to them. My solution was to create a class that defined operator() and use it as the additional parser. Then once I spot the change from "my" to "his" part. I stick all the words n a dummy option.
The standard approach is the "--" token. Say: prog --option1 --option2 -- options_for_the_other_program When program_options sees '--' it stops looking for the regular options and everything after is considered 'positional options'. If you tell me the logic you use to detect the change from "your" to "his" option, I might suggest another approach. - Volodya
Well it's because there are two separate lists of options. One to the program that I'm parsing for and one for code that we just perform a pass through to. I have no control over the options recognized by the other guy I just want to stop parsing when I get to them. My solution was to create a class that defined operator() and use it as the additional parser. Then once I spot the change from "my" to "his" part. I stick all the words n a dummy option.
The standard approach is the "--" token. Say:
Yes, but I can't change the syntax so can't use that.
If you tell me the logic you use to detect the change from "your" to "his" option, I might suggest another approach.
I'd forget my head if it wasn't attached. :) I really should have added this shouldn't I? :) Ok the image I am in is called "foo", it accepts a set of flags and options. Ideally I would be able to use "-option_word" or any unambiguous substring there of, although I'm hoping to squeeze past having to use "--option_word". At some point on the command line there will be the name of command, pretty much the only thing I can say about this is that it won't start with a "-" following this will be zero or more arguments to the command, none of which I can parse. So the command line looks like: foo -foo_opt1 value -foo_flag ... command_name -cmd_option cmd_val -cmd_flag word ... One of the options to foo is to name a file which consists of lines that look like command lines each of which I am parsing with the same code, now I have no zero length regexs :), by having my extra parser class doohicky, ignoring the first word on the line if it's instantiated with a bool initialiser. I really appreciate your help and I'd love to hear the thoughts of someone, unlike me, who knows what they're doing. Thank you for your time. -- Blue Skies
In article
Ok the image I am in is called "foo", it accepts a set of flags and options. Ideally I would be able to use "-option_word" or any unambiguous substring there of, although I'm hoping to squeeze past having to use "--option_word". At some point on the command line there will be the name of command, pretty much the only thing I can say about this is that it won't start with a "-" following this will be zero or more arguments to the command, none of which I can parse. So the command line looks like:
foo -foo_opt1 value -foo_flag ... command_name -cmd_option cmd_val -cmd_flag word ...
I think we can summarize this part as "I am trying to write xargs". Even if you are not, what you are doing with your command line arguments is essentially the same as what xargs does, and I think that's a legitimate need. meeroh
On Fri, 04 Mar 2005 01:48:29 -0500, Miro Jurisic
In article
, The Grumpiest Man You Know wrote: foo -foo_opt1 value -foo_flag ... command_name -cmd_option cmd_val -cmd_flag word ...
I think we can summarize this part as "I am trying to write xargs". Even if you are not, what you are doing with your command line arguments is essentially the same as what xargs does, and I think that's a legitimate need.
Very incisive, it's very much like xargs command line. And putting it that way, I believe there was another chap here last week looking at the same thing. Thank you, I'll go see if he was given the answer I should have read before now. :) -- Blue Skies
participants (3)
-
Miro Jurisic
-
The Grumpiest Man You Know
-
Vladimir Prus