home *** CD-ROM | disk | FTP | other *** search
- Update to parseargs by Peter da Silva (peter@ficc.uu.net).
- (second update: more improvements to arg parsing, argChar type)
- (third update, return to original calling sequence, argList type)
- (fourth update: removed routines not relevant to parseargs, removed
- tracing/interactive stuff. )
-
- Parseargs is a really nifty set of routines, but it doesn't fit too
- well with standard UNIX semantics. In particular, you can get into a
- lot of trouble using it in a script if it drops into interactive mode
- on you. Also, it's not as useful as it could be for non-UNIX systems.
- To make it work better, I've made a couple of changes.
-
- It compiled straight out of the box on System III once I'd provided
- bcopy, bcmp, and strtol. The strtol I've provided is almost totally
- untested, but hopefully you won't need to use it. It's only for folks with
- old UNIX systems.
-
- First change was to disable the interactive prompting for arguments.
- I think that's inconsistent with usual UNIX semantics.
-
- The second change was to allow for a trailing list of arguments. I
- originally implemented this by changing the calling sequence to parseargs.
- On reflection this would just produce incompatibilities, so I added a
- new flag, ARGLIST, and a new type, listStr. Later, other kinds of lists
- can presumably be added. A list handles a pointer to a list of objects:
-
- struct arglist *fred;
-
- Operations are defined on arglists, L_NEXT(fred) produces the next element
- in fred. L_STRING(fred) produces the value of fred cast to "char *".
-
- During evaluation the list is kept in LIFO order, and it's reversed just
- before returning to parseargs. This simplifies the coding of the list
- routines, but still lets you step through the list in a reasonable order.
-
- The final change is the addition of a 'argChar' type. This parses character
- arguments (such as the '-T' option to 'awk'), accepting single characters,
- '\nnn' octal escapes, and '^X' for control characters.
-
- Parseargs itself no longer uses ckalloc, traceset, funclist, and so on.
- these routines are pretty cool, but when you're grafting parseargs onto
- an existing program they just get in the way. Also, it's possible to make
- parseargs fail in a cleaner fashion by handling out-of-memory cases myself.
- Certainly there's not going to be any loose memory lying around to be
- collected when parseargs starts up!
-
- Also, the error messages have been made a bit more descriptive. Instead
- of saying "stest: value required for -c flag", it prints "stest: RepCount
- required for -c flag". The ad_prompt element should relly be a descriptive
- word that can be used in a sentence... or for non_UNIX systems a multi-
- character or keyword based flag. I have an Amiga version included, for
- example, that uses keyword syntax. In that version, the usage message reads:
-
- Usage: amiga_test <name> [GROUP <newsgroup>]... [REP <repcount>] +
- [DIR <dirname>] [X] [Y] [Z] [TAB <tabchar>] [<file>]...
-
- Instead of:
-
- Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] \
- [-d <DIRname>] [-x] [-y] [-z] [-t <TABchar>] [<File>]...
-
- This would solve the old problem of UNIX programs sticking out like a
- sore thumb in other operating systems.
-
- The Amiga version still needs to prompt for options if called with a
- single '?' as an argument. Perhaps it will be possible to read options
- out of tooltypes and finally integrate CLI and Workbench environments.
-