Parse command-line options
Prototype:   int ParseOptions(int argc, char *argv[], char * (*callback)(int argc, char *argv[]), char *caller)
Parameters: argc how many  argument strings
  argv array of pointers to argument strings
  callback callback function that checks each option
  caller calling function's name (for error and help messages)
Return Value: new value for argc
The principal routine of this file, ParseOptions(), parses and removes the processing options specified on a command line. It is designed to work in concert with the filter() routine.
ParseOptions loops through all the argv entries (ignoring argv[0]). It stops the loop in three cases.
On each pass of the loop, ParseOptions() calls the callback function, passing it the current argc value and a modified argv array. argv[0] is set to the caller argument passed to ParseOptions. This allows the callback function to display more meaningful messages. argv[1] is always set to the current position in the argv array, whether it is at the beginning of an original argv value or somewhere in the middle of one (this is the case when several single-character options can be collected into one string). ParseOptions always sets the first character of argv[1] to be a hyphen.
It is the responsibility of the callback routine to advance the argv pointer. This allows the callback routine to determine what is the legitimate format for an option, i.e.
ParseOptions() manipulates the argv array. It sets the argv[0] value to the caller argument and also modifies argv as the callback routine processes its values. It keeps the argc count in sync with argv and uses the new argc value as its return value. The array pointed to by argv is modified; all options are removed leaving only filename strings in the array for filter() to handle.
If the callback routine detects an error it should return a NULL pointer to indicate this. ParseOptions() will then print an error message and return 0 (which is not a legitimate value for argc).
Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 27 of 485)
Comments, flames, broken links?
Please send email to