Standard for parsing

3

31337one

Hello everyone,

I am writing an application that uses a command line interface. It will
be configurable by passing arguments on the command line. The program
is going to run in windows and linux.

I was wondering what most linux/windows tools use to parse arguments.

Example: ls -a or ls --help

I need to support both short ( -a ) and long ( --help ) versions of the
commands. If I had to choose though, I would prefer long versions as
they are easier to remember.

I have looked at Getopt but to be honest, im not impressed. It appears
to only do short options and isnt even included in Visual Studio.

Thanks for your help.
 
S

spibou

Hello everyone,

I am writing an application that uses a command line interface. It will
be configurable by passing arguments on the command line. The program
is going to run in windows and linux.

I was wondering what most linux/windows tools use to parse arguments.

Example: ls -a or ls --help

I need to support both short ( -a ) and long ( --help ) versions of the
commands. If I had to choose though, I would prefer long versions as
they are easier to remember.

I have looked at Getopt but to be honest, im not impressed. It appears
to only do short options and isnt even included in Visual Studio.

Questions about specific operating systems are not topical here.
For Linux I would suggest comp.unix.programmer or
comp.os.linux.development.apps However this kind of thing can
probably be done using standard C. I don't know how Windows
passes command line arguments but if your problem is basically
how to parse the strings pointed to by argv[] then you definitely
only need standard C. It's not hard , depending on how complicated
your application's command line options may be , but be prepared for
some tedious work examining many special cases.

If you describe your problem in more detail we should be able to offer
more help.

out_of_topic {
For Linux have a look at getopt_long()

And for what is worth I prefer one letter options
because they are faster to type.
}

Spiros Bousbouras
 
F

Flash Gordon

Hello everyone,

I am writing an application that uses a command line interface. It will
be configurable by passing arguments on the command line. The program
is going to run in windows and linux.

I was wondering what most linux/windows tools use to parse arguments.

Example: ls -a or ls --help

I need to support both short ( -a ) and long ( --help ) versions of the
commands. If I had to choose though, I would prefer long versions as
they are easier to remember.
ant.
I have looked at Getopt but to be honest, im not impressed. It appears
to only do short options and isnt even included in Visual Studio.

This isn't a sources wanted group but I'll help anyway. glibc has a
getopt_long function which probably does what you what you want. Being
GNU, it is obviously open source. Since it is possible to write such a
function in standard C you may well be able to simply re-compile it for
any other system you want (subject to licensing terms, obviously).
Failing that you could look for the BSD implementation or any other
implementation, there are plenty about.
 
3

31337one

How is this out of topic?

I am not asking how to parse command line arguments. I know how to do
that. I was wondering if there is a standard that programmers of the C
language use. I am no professional but I was wondering if there was
something that is widely used for parsing. Something that has already
been solidified to catch bad input and errors.

The question is not platform specific. The question is about C code
that is widely used to parse commands.

I dont see how its not related to this group. This is the C group and
im asking about C code.
 
S

spibou

How is this out of topic?

I am not asking how to parse command line arguments. I know how to do
that. I was wondering if there is a standard that programmers of the C
language use. I am no professional but I was wondering if there was
something that is widely used for parsing. Something that has already
been solidified to catch bad input and errors.

The question is not platform specific. The question is about C code
that is widely used to parse commands.

I dont see how its not related to this group. This is the C group and
im asking about C code.

Your original question was
"I was wondering what most linux/windows tools use to parse arguments."
It refers to specific operating systems. With the way you phrase things
this time it is on topic. The answer is no , the standard library does
not
provide functions for parsing command line options.

Spiros Bousbouras
 
3

31337one

Then, as I asked in the OP, what do they use?

The only reason I am asking here, is because I wanted some straight C
that does the parsing. I dont want to ask a specific windows or linux
group because they will give me an answer that is platform dependent.
 
S

spibou

Then, as I asked in the OP, what do they use?

The only reason I am asking here, is because I wanted some straight C
that does the parsing. I dont want to ask a specific windows or linux
group because they will give me an answer that is platform dependent.

I would imagine that different people use different things. Both Flash
Gordon and I have mentioned getopt_long which should compile for
both systems. I'm also sure that a Google search would reveal many
libraries. But as far as I know there isn't one that "everyone" uses.

Spiros Bousbouras
 
F

Flash Gordon

(e-mail address removed) wrote:

Please provide context when replying so people can see what you are
replying to. There is no guarantee that everyone has, or ever will, see
the message you are replying to. See 99% of the messages in this group,
including those you have been replying to for how posts should look.
Then, as I asked in the OP, what do they use?

People use all sorts of different methods for command line processing. I
have seen very badly written command line processing code used, the *nix
standard getopt, the GNU versions, and variations of all of these ported
to Windows.
The only reason I am asking here, is because I wanted some straight C
that does the parsing. I dont want to ask a specific windows or linux
group because they will give me an answer that is platform dependent.

As I suggested in my previous post, download the code for the GNU
version of getopt_long or the BSD version or any of the other freely
available versions. Alternatively write your own and post it here and we
will comment on it.
 
W

William Ahern

How is this out of topic?

I am not asking how to parse command line arguments. I know how to do
that. I was wondering if there is a standard that programmers of the C
language use. I am no professional but I was wondering if there was
something that is widely used for parsing. Something that has already been
solidified to catch bad input and errors.

<off-topic>
GNU getopt.c is written in standard C, and includes getopt_long(). You can
include it directly with your project, and find it all over the web.

If you don't like the GNU GPL license, then grab the getopt_long()
implementation from OpenBSD. You can even download the individual file
from the OpenBSD website. This, too, is written in standard (read
portable) C, and comes with a very permissive license.

Though, strictly speaking, I've only ever seen dash-prefixed program
option arguments in Unix. In Unix getopt() is standardized, and
getopt_long() is very near a de facto standard for all recent platforms.

And now, I think it's become plainly obvious why we shouldn't discuss
these things here.
The question is not platform specific. The question is about C code that
is widely used to parse commands.

I dont see how its not related to this group. This is the C group and im
asking about C code.

We don't discuss C code per se, only C code in the context of a
broader discussion about the content, meaning, intent, and consequences of
the C language standard. Also, I know of no Usenet group worth its salt
which fancies itself a directory service. If somebody simply asks where to
get something, the discussion will, hopefully, turn into something more
meaningful. But this process is hindered when the rules of topicality are
ignored.
 
3

31337one

GNU getopt.c is written in standard C, and includes getopt_long(). You can
include it directly with your project, and find it all over the web.

If you don't like the GNU GPL license, then grab the getopt_long()
implementation from OpenBSD. You can even download the individual file
from the OpenBSD website. This, too, is written in standard (read
portable) C, and comes with a very permissive license.
...


Soooo, will this OpenBSD version work in windows and linux?
 
S

spibou

Soooo, will this OpenBSD version work in windows and linux?

I have no experience with it but I think that the "standard (read
portable) C" part speaks quite clearly. Beyond that the only sure
method is to try it.

Spiros Bousbouras
 
K

Keith Thompson

How is this out of topic?

How is what out of topic? Please provide context in each followup.
I am not asking how to parse command line arguments. I know how to do
that. I was wondering if there is a standard that programmers of the C
language use. I am no professional but I was wondering if there was
something that is widely used for parsing. Something that has already
been solidified to catch bad input and errors.

There is no standard in C either for the format of command-line
arguments or for code to parse them.

The format of command-line arguments is often standardized (perhaps
informally) for each operating system. Unix tends to use a "-" prefix
with single-character options. Many GNU and GNU-inspired tools also
accept a "--" prefix with longer option names. MS-DOS tends to use a
"/" prefix with single-character options. OpenVMS uses a "/" prefix
with long abbreviatable option names. And so forth.
 
M

Malcolm

Hello everyone,

I am writing an application that uses a command line interface. It will
be configurable by passing arguments on the command line. The program
is going to run in windows and linux.

I was wondering what most linux/windows tools use to parse arguments.

Example: ls -a or ls --help

I need to support both short ( -a ) and long ( --help ) versions of the
commands. If I had to choose though, I would prefer long versions as
they are easier to remember.

I have looked at Getopt but to be honest, im not impressed. It appears
to only do short options and isnt even included in Visual Studio.

Thanks for your help.

typedef struct
{
int helpflag;
double tfactor;
char oogly_oogly[32];
} OPTIONS;

int parseoptions(OPTION *options, int argc, char ** argv,)
{
filldefaults(options);
/* lots of messy code here */
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,188
Messages
2,571,002
Members
47,591
Latest member
WoodrowBut

Latest Threads

Top