command line options (UNIX-specific)

der Mouse mouse at mcgill-vision.UUCP
Sat Apr 9 07:44:10 AEST 1988


In article <2414 at zyx.UUCP>, aj at zyx.UUCP (Arndt Jonasson) writes:
> This is a suggestion for a command line parsing routine for C
> programs in Unix.

> I post this [suggestion] in the hope of getting constructive comments
> on what features are missing in my scheme, and whether it is perhaps
> too restrictive or too general [...].

Well, I can't say how constructive you will find these comments, but
here's a critique of what I dislike in what you've said.  (In the usual
tradition of criticism, I'll ignore the points you've mentioned that I
like. :-)

> 'O_parse_options' uses the same model as 'getopt', i.e. first come
> the options, preceded by hyphens (they may be grouped together after
> one hyphen), then come the non-option arguments.

How does one model an option which behaves like tar's -C or ld's -l,
which can appear (almost) anywhere and whose position is significant?

> If an option -s takes an argument, both '-sfoo' and '-s foo' are
> valid.

So you can group options on one hyphen - unless one of them takes an
argument.  Ugly inconsistency.  Also unpleasant: you can't use both
methods when the argument is to be a null string:

foo -s '' -b        - works
foo -s'' -b         - doesn't work

> It will either successfully parse all the options and store values in
> the appropriate variables, or exit the program with an error message.

I want the option of handling the error myself.  Perhaps I don't want
to print a usage message; perhaps I want a usage message that looks
different from yours; perhaps I want to produce the message on stdout
instead; perhaps I want to ignore the offending option; perhaps I want
to ignore the offending option depending on what it is....

How do you model the tar/dump/ar or dd styles of arglist?

I wrote a program a while back which took an option -F, which required
a following filename, as in

% foo -F xyzzy

except that the result was more verbose if the -F was doubled:

% foo -FF xyzzy

How would I model this?

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list