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)
-
- 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. You can undo
- this change by #defining INTERACTIVE when compiling parseargs.c.
-
- 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 "type", argList. This handles a pointer to a list of names:
-
- struct namelist {
- struct namelist *nl_next;
- char *nl_name;
- };
-
- This is implemented with some "magic" in parseargs, and perhaps it would
- do better as an additional flag, ARGLIST, and a set of listType routines
- to handle them. Also, it currently keeps the list in LIFO order. It would
- be more convenient in FIFO order, though this would take a little more
- work to implement (basically just stepping through the list in argList to
- find the tail, instead of inserting at the head), and can be fixed in a
- single pass after parseargs returns with (say) !argv = reverselist(argv)!:
-
- struct namelist *reverselist(from)
- struct namelist *from;
- {
- struct namelist *to, *tmp;
-
- to = NULL;
- while(from) {
- tmp = from->nl_next; /* remove top from old list */
- from = from->nl_next;
- tmp->nl_next = to; /* insert top in new list */
- to = tmp;
- }
- return to;
- }
-
- 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! To turn on TRACE and the funclist code
- just add -DTRACESTUFF and -DFUNCLISTSTUFF to the Makefile.
-
- 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. This may require some redesign: it's almost
- certainly not going to be possible to stuff *extra* file names into
- argv. Perhaps something like:
-
- parseargs(&argc, &argv, "File");
-
- ????????
-