home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / LIBS / CMDLINE / README.TXT < prev    next >
Encoding:
Text File  |  1996-04-27  |  2.4 KB  |  61 lines

  1. Hi,
  2.     Here is my argument parser.  You need to have a struct of type 
  3. ARGLIST called ArgList in your main program which defines the switches
  4. possible and associates callbacks.  Then at the beginning you call
  5.  
  6. parse_char(&argc,argv,flag);
  7.  
  8. where flag is TRUE if you want case sensitivity or false otherwise.
  9.  
  10.  
  11.  
  12. Switches may be concatentated, for example: /axe will call the callbacks
  13. for switches a, x, and e.  This routine steps through the argv list looking
  14. for switches; it will NOT find switches that are concatenated on the
  15. end of filenames for example.  But it should find any switches that
  16. are concatenated to the executable name because of the way MSDOS handles
  17. command lines.
  18.  
  19. The switch handler will delete all switches from the ARGV array so that
  20. if you want to do furtheer parsing (e.g. of file names) you don't have 
  21. to worry with them.  if an undefined switch is encountered the handler
  22. will abort the program with an error message.
  23.  
  24.  
  25. Switches may be preceded by the '/' , '-', or '+' chars
  26. There are four types of switches:
  27.  
  28. ARG_SWITCH:
  29.  
  30. unconditional switch, calls callback with the value TRUE
  31.  
  32. ARG_BOOL:
  33.     returns a true or false value to the callback routine, depending
  34. on whether the switch prefix was '+' or '-'
  35.  
  36. ARG_CONCATSTRING
  37.     returns the entire string which follows the switch to the
  38. callback routine.  Since the entire string is passed to the callback routine,
  39. any switches after a CONCATSTRING switch will be considered as part of
  40. the string rather than as part of the switch.  However BOOL and SWITCH
  41. type switches may be concatenated before such a switch with no problems.
  42. I should say that only the string in the current ARGV element will be
  43. passed; other argv elements will be processed independently and thus will
  44. not be affected.  Currently, the switch handler does not handle switches
  45. with spaces in them.
  46.  
  47. ARG_NOCONCATSTRING:
  48.     Same as arg_concatstring but it passes the entire switch contents
  49. including the switch character that caused the callback.
  50.  
  51.  
  52. I generally write short callback routines which just set a variable
  53. true or false or load a string into a variable.  I might do some local
  54. verification that a string value is correct; but if I need to error
  55. check (for example sometimes two switches are mutually exclusive) I
  56. do it in the main routine after the switch parsing rather than incorporate
  57. it into the callbacks.
  58.  
  59. Have fun,
  60.  
  61. David