home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume10 / parseargs / README.PDS < prev    next >
Encoding:
Text File  |  1990-02-16  |  3.8 KB  |  91 lines

  1. Update to parseargs by Peter da Silva (peter@ficc.uu.net).
  2. (second update: more improvements to arg parsing, argChar type)
  3. (third update, return to original calling sequence, argList type)
  4.  
  5. Parseargs is a really nifty set of routines, but it doesn't fit too
  6. well with standard UNIX semantics. In particular, you can get into a
  7. lot of trouble using it in a script if it drops into interactive mode
  8. on you. Also, it's not as useful as it could be for non-UNIX systems.
  9. To make it work better, I've made a couple of changes.
  10.  
  11. It compiled straight out of the box on System III once I'd provided
  12. bcopy, bcmp, and strtol. The strtol I've provided is almost totally
  13. untested, but hopefully you won't need to use it. It's only for folks with
  14. old UNIX systems.
  15.  
  16. First change was to disable the interactive prompting for arguments.
  17. I think that's inconsistent with usual UNIX semantics. You can undo
  18. this change by #defining INTERACTIVE when compiling parseargs.c.
  19.  
  20. The second change was to allow for a trailing list of arguments. I
  21. originally implemented this by changing the calling sequence to parseargs.
  22. On reflection this would just produce incompatibilities, so I added a
  23. new "type", argList. This handles a pointer to a list of names:
  24.  
  25. struct namelist {
  26.     struct namelist *nl_next;
  27.     char *nl_name;
  28. };
  29.  
  30. This is implemented with some "magic" in parseargs, and perhaps it would
  31. do better as an additional flag, ARGLIST, and a set of listType routines
  32. to handle them. Also, it currently keeps the list in LIFO order. It would
  33. be more convenient in FIFO order, though this would take a little more
  34. work to implement (basically just stepping through the list in argList to
  35. find the tail, instead of inserting at the head), and can be fixed in a
  36. single pass after parseargs returns with (say) !argv = reverselist(argv)!:
  37.  
  38. struct namelist *reverselist(from)
  39. struct namelist *from;
  40. {
  41.     struct namelist *to, *tmp;
  42.  
  43.     to = NULL;
  44.     while(from) {
  45.         tmp = from->nl_next; /* remove top from old list */
  46.         from = from->nl_next;
  47.         tmp->nl_next = to; /* insert top in new list */
  48.         to = tmp;
  49.     }
  50.     return to;
  51. }
  52.  
  53. The final change is the addition of a 'argChar' type. This parses character
  54. arguments (such as the '-T' option to 'awk'), accepting single characters,
  55. '\nnn' octal escapes, and '^X' for control characters.
  56.  
  57. Parseargs itself no longer uses ckalloc, traceset, funclist, and so on.
  58. these routines are pretty cool, but when you're grafting parseargs onto
  59. an existing program they just get in the way. Also, it's possible to make
  60. parseargs fail in a cleaner fashion by handling out-of-memory cases myself.
  61. Certainly there's not going to be any loose memory lying around to be
  62. collected when parseargs starts up! To turn on TRACE and the funclist code
  63. just add -DTRACESTUFF and -DFUNCLISTSTUFF to the Makefile.
  64.  
  65. Also, the error messages have been made a bit more descriptive. Instead
  66. of saying "stest: value required for -c flag", it prints "stest: RepCount
  67. required for -c flag". The ad_prompt element should relly be a descriptive
  68. word that can be used in a sentence... or for non_UNIX systems a multi-
  69. character or keyword based flag. I have an Amiga version included, for
  70. example, that uses keyword syntax. In that version, the usage message reads:
  71.  
  72. Usage: amiga_test <name> [GROUP <newsgroup>]... [REP <repcount>] +
  73.     [DIR <dirname>] [X] [Y] [Z] [TAB <tabchar>] [<file>]...
  74.  
  75. Instead of:
  76.  
  77. Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] \
  78.     [-d <DIRname>] [-x] [-y] [-z] [-t <TABchar>] [<File>]...
  79.  
  80. This would solve the old problem of UNIX programs sticking out like a
  81. sore thumb in other operating systems.
  82.  
  83. The Amiga version still needs to prompt for options if called with a
  84. single '?' as an argument. This may require some redesign: it's almost
  85. certainly not going to be possible to stuff *extra* file names into
  86. argv. Perhaps something like:
  87.  
  88.     parseargs(&argc, &argv, "File");
  89.  
  90. ????????
  91.