plparseopts: Parse command-line arguments

PLINT plparseopts ( p_argc ,
  argv ,
  mode );
 

Parse command-line arguments.

plparseopts removes all recognized flags (decreasing argc accordingly), so that invalid input may be readily detected. It can also be used to process user command line flags. The user can merge an option table of type PLOptionTable into the internal option table info structure using plMergeOpts. Or, the user can specify that ONLY the external table(s) be parsed by calling plClearOpts before plMergeOpts.

The default action taken by plparseopts is as follows:

Returns with an error if an unrecognized option or badly formed option-value pair are encountered.
Returns immediately (return code 0) when the first non-option command line argument is found.
Returns with the return code of the option handler, if one was called.
Deletes command line arguments from argv list as they are found, and decrements argc accordingly.
Does not show "invisible" options in usage or help messages.
Assumes the program name is contained in argv[0].

These behaviors may be controlled through the mode argument.

p_argc (int *, input/output)

Number of arguments.

argv (PLCHAR_NC_MATRIX, input/output)

A vector of character strings containing *p_argc command-line arguments.

mode (PLINT, input)

Parsing mode with the following possibilities:

  • PL_PARSE_FULL (1) -- Full parsing of command line and all error messages enabled, including program exit when an error occurs. Anything on the command line that isn't recognized as a valid option or option argument is flagged as an error.

  • PL_PARSE_QUIET (2) -- Turns off all output except in the case of errors.

  • PL_PARSE_NODELETE (4) -- Turns off deletion of processed arguments.

  • PL_PARSE_SHOWALL (8) -- Show invisible options

  • PL_PARSE_NOPROGRAM (32) -- Specified if argv[0] is NOT a pointer to the program name.

  • PL_PARSE_NODASH (64) -- Set if leading dash is NOT required.

  • PL_PARSE_SKIP (128) -- Set to quietly skip over any unrecognized arguments.

Redacted form:

This function is used in all of the examples.