[comp.std.unix] parseargs vs. getopt

darcy@druid.uucp (D'Arcy J.M. Cain) (06/24/90)

From:  darcy@druid.uucp (D'Arcy J.M. Cain)

In article <729@longway.TIC.COM> From: David J. MacKenzie <djm@eng.umd.edu>
>Parseargs has a lot of problems; I looked at it and discarded it.  It
>might provide a superior interface to the programmer, but it doesn't
>provide the same interface to the user; that is, it doesn't conform to
>the standard Unix option syntax that most programs use (allowing
>ganging of multiple single-letter options into a single argument, for
>example).  Since getopt is an existing-practice de-facto standard, I

You might like my getarg function.  I designed it as a replacement for
getopt but in such a way that the user can use it exactly like getopt.
It does however support extra functionality which can be used if the user
is aware of it.  For one thing, options and arguments (files) can be
mixed instead of requiring all options to precede the files.  You can
also initialise the argument list more than once supporting things such
as environment default command lines, arguments from files etc mixed
with arguments from the command line.  I just posted it recently to
alt.sources and I'm interested in getting some feedback on it.

-- 
D'Arcy J.M. Cain (darcy@druid)     |   Government:
D'Arcy Cain Consulting             |   Organized crime with an attitude
West Hill, Ontario, Canada         |
(416) 281-6094                     |

Volume-Number: Volume 20, Number 45

peter@ficc.uucp (06/25/90)

From:  peter@ficc.uucp

In article <729@longway.TIC.COM> From: David J. MacKenzie <djm@eng.umd.edu>
> Parseargs has a lot of problems; I looked at it and discarded it.

On the other hand, I looked at it and fixed them. Check comp.sources.misc.

> It
> might provide a superior interface to the programmer, but it doesn't
> provide the same interface to the user; that is, it doesn't conform to
> the standard Unix option syntax that most programs use (allowing
> ganging of multiple single-letter options into a single argument, for
> example).

Actually, it does do this. You shoulda looked harder. What it doesn't do
is handle variable nubers of arguments, which is one thing I fixed.

> Since getopt is an existing-practice de-facto standard, I
> see no justification for trying to push something quite different that
> hardly anyone uses as an IEEE standard.

Given the things that have already gone in to POSIX, even the almighty
base (such as fgetpos, or banning silent truncation of long file names)
I think that's a bit of a quibble. Getopt pretty much has to stay, I
agree. But parseargs should be considered as a recommended alternative.
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.
<peter@ficc.ferranti.com>


Volume-Number: Volume 20, Number 49

chip@tct.uucp (Chip Salzenberg) (06/27/90)

From:  chip@tct.uucp (Chip Salzenberg)

According to darcy@druid.uucp (D'Arcy J.M. Cain):
>[Getarg] support[s] extra functionality which can be used if the user
>is aware of it.  For one thing, options and arguments (files) can be
>mixed instead of requiring all options to precede the files.

Consider:

	rm ./-a -b -c -d -e -f

With getopt, all five arguments are filenames.  With getarg, the first
argument is a filename and the rest are options.  This is a feature?
No thanks.

-- 
Chip Salzenberg at ComDev/TCT     <chip@tct.uucp>, <uunet!ateng!tct!chip>

Volume-Number: Volume 20, Number 53

lezz@codex.uucp (Leslie Giles) (06/27/90)

From:  lezz@codex.uucp (Leslie Giles)

darcy@druid.uucp (D'Arcy J.M. Cain) writes:

>You might like my getarg function.  I designed it as a replacement for
>   ... You can
>also initialise the argument list more than once supporting things such
>as environment default command lines, arguments from files etc mixed
>with arguments from the command line.  I just posted it recently to
>alt.sources and I'm interested in getting some feedback on it.

It is also possible to restart getopt() by setting various variables.
I did this in some code to support defaults, as mentioned above.  If anybody
wants to know how to do this then you can mail me (I don't have the code in
front of me at the moment - it'd take time to find it) at...

codex!lezz

Volume-Number: Volume 20, Number 54

darcy@druid.uucp (D'Arcy J.M. Cain) (06/29/90)

From:  darcy@druid.uucp (D'Arcy J.M. Cain)

In article <742@longway.TIC.COM> std-unix@uunet.uu.net writes:
>From:  lezz@codex.uucp (Leslie Giles)
>darcy@druid.uucp (D'Arcy J.M. Cain) writes:
>>   ... You can
>>also initialise the argument list more than once supporting things such
>>as environment default command lines, arguments from files etc mixed
>>with arguments from the command line.  I just posted it recently to
>>alt.sources and I'm interested in getting some feedback on it.
>
>It is also possible to restart getopt() by setting various variables.
>I did this in some code to support defaults, as mentioned above.  If anybody
>wants to know how to do this then you can mail me (I don't have the code in
>front of me at the moment - it'd take time to find it) at...
>
I guess I wasn't clear in that paragraph.  The posting goes into great detail
about this but the main point is not that you can restart your argument
processing but that another set of arguments can be stuffed into the ones
you already have.  It allows for something like the following:  Say you
have a program called foo which takes options a & b with no arguments and
f with an argument "on" or "off".  Perhaps the user normally wants this flag
off but wants to override that default this time.  Also the a flag is always
used.  The .profile has the following line:

foo="-a -f off"

Assume also that there is a file called bar with the following line:

-b

then he calls the program like this:

foo -f on -@ bar file1 -f off file2

Assuming that the program is set up correctly then the effective command
is

foo -a -f off -f on -b file1 -f off file2

Which should process file1 with the flag turned on and file2 with the flag
turned off.  As you can see, The environment variable is stuffed into the
command line between the program name and the first argument and the contents
of the file bar is inserted in the line where the file name appears.  While
it may be possible to do something like that with getopt I imagine it would
not be as simple as with my interface.

-- 
D'Arcy J.M. Cain (darcy@druid)     |   Government:
D'Arcy Cain Consulting             |   Organized crime with an attitude
West Hill, Ontario, Canada         |
(416) 281-6094                     |

Note to moderator:  I think this is the wrong group to discuss but I can't
decide the proper one.  Please feel free to add a followup-to line if you
wish.

[ I don't know a better place for it, either. -mod ]

Volume-Number: Volume 20, Number 73