On Fri, 24 Oct 2003, Boogie El Aceitoso wrote:
I need a command line parser that understands filename swith spaces.
Since I'm absolutelly sure I'm not the first developer to need a command
line parser, I was wondering is there's a decent open source one available.
What do you need, exactly? You see, all operating systems I know
of do all the difficult parsing for you ahead-of-time, especially
the kind dealing with "filenames with spaces." E.g., if you call
a program like this:
prompt> myprog eenie meenie "My Documents" > foobar
what your C++ program will actually see internally is something
like this:
argv[0]: something like "myprog"
argv[1]: "eenie"
argv[2]: "meenie"
argv[3]: "My Documents"
argv[4]: NULL
You see, the space in "My Documents" has been preserved because
the user typed in quotes at the command line. No special
parsing necessary.
On the other hand, if you want a parser that can handle simple
Unix-style command-line tags like
prompt> myprog -abcd -o output.txt --foo --whozit
then you might be interested in some of the source code here:
http://www.contrib.andrew.cmu.edu/~ajo/free-software/
for instance, 'detab.c', 'rot13.c', or 'quine.c'. These
programs' main() functions contain some simple code for this
kind of parsing that I've found to be very useful and extensible;
I'd be glad to explain it in more detail if you think it's what
you're looking for.
Many systems have functions called 'getopt' or similar that
can do fancy argument parsing, but those packages aren't
standard C or C++, and if you want help with them you would
do better to ask in a group related to the particular package.
HTH,
-Arthur