home *** CD-ROM | disk | FTP | other *** search
- Hi,
- Here is my argument parser. You need to have a struct of type
- ARGLIST called ArgList in your main program which defines the switches
- possible and associates callbacks. Then at the beginning you call
-
- parse_char(&argc,argv,flag);
-
- where flag is TRUE if you want case sensitivity or false otherwise.
-
-
-
- Switches may be concatentated, for example: /axe will call the callbacks
- for switches a, x, and e. This routine steps through the argv list looking
- for switches; it will NOT find switches that are concatenated on the
- end of filenames for example. But it should find any switches that
- are concatenated to the executable name because of the way MSDOS handles
- command lines.
-
- The switch handler will delete all switches from the ARGV array so that
- if you want to do furtheer parsing (e.g. of file names) you don't have
- to worry with them. if an undefined switch is encountered the handler
- will abort the program with an error message.
-
-
- Switches may be preceded by the '/' , '-', or '+' chars
- There are four types of switches:
-
- ARG_SWITCH:
-
- unconditional switch, calls callback with the value TRUE
-
- ARG_BOOL:
- returns a true or false value to the callback routine, depending
- on whether the switch prefix was '+' or '-'
-
- ARG_CONCATSTRING
- returns the entire string which follows the switch to the
- callback routine. Since the entire string is passed to the callback routine,
- any switches after a CONCATSTRING switch will be considered as part of
- the string rather than as part of the switch. However BOOL and SWITCH
- type switches may be concatenated before such a switch with no problems.
- I should say that only the string in the current ARGV element will be
- passed; other argv elements will be processed independently and thus will
- not be affected. Currently, the switch handler does not handle switches
- with spaces in them.
-
- ARG_NOCONCATSTRING:
- Same as arg_concatstring but it passes the entire switch contents
- including the switch character that caused the callback.
-
-
- I generally write short callback routines which just set a variable
- true or false or load a string into a variable. I might do some local
- verification that a string value is correct; but if I need to error
- check (for example sometimes two switches are mutually exclusive) I
- do it in the main routine after the switch parsing rather than incorporate
- it into the callbacks.
-
- Have fun,
-
- David