This small package (a .c file and associated .h header) written in standard c aims at handling command line arguments and configuration files in a unified manner. Please note that many of the features presented here may be enabled or disabled at will, making the package quite robust. To download the package feel free to scroll to the bottom of this page.
At this time the package only works with ASCII strings.
The application is required to provide storage for a OPTHD header structure that holds pointer towards an array of OPTENTRY options. Each option is expected to feature:
The function OptPrs_ParseString is intended to process the command line that an application receives. First element in the string is expected to be the name of the application.
The package finds strings in one of two ways, depending on the first character. If a quote or double quote starts the string, then next quote character of same type is searched; all in between is the string. On the other hand, if no such characters are fist the string extends until first white space is encountered.
As a side note, the executable is considered a string in this respect.
These are all characters with an ASCII code lower than or equal to space character. 0, new line and line feed retain historical meaning. Entities on the command line are delimited by white spaces.
At the command line a word is interpreted as an option name if it is preceded by one of following strings: -, --, / and \
Options specified at the command prompt (or elsewhere) are case insensitive. They must consist of a single word (no characters <= space).
The option name may optionally be followed by an equal sign and an optional argument. The argument may became a required feature by turning appropriate flag on.
A string placed right after executable's name or one that follows an option that does not take arguments or one that follows the argument of an option is named an "orphan" string. Usually, these will represent paths to input files. The package stores these strings separately in an array in the order that they appear.
The function OptPrs_ParseFile is able to process a file, extracting the information stored in proper format.
Comments may only appear on a dedicated line. To be identified as an comment line, first character that is not a white space must be one of #, //, ;
Multi-line comment is also accepted, taking the form /* */. As an exception, after the */ an option may be placed.
A meaningful line must start with an option name followed by an equal sign. The name is case insensitive.
After the equal sign all white spaces are skipped. The value is either the inner part of a quoted text or all the text on that line without eventual white-spaces at the end of the line.
Beside succinct information about how options may be presented at command line, OptPrs_PrintUsage function also prints each option and it's description.
Using OptPrs_Save function one may save the options as they are present inside the array at any given time. The format of the file that is generated is compatible with the format expected by OptPrs_ParseFile function, so the file may be reloaded.
The file starts with a two-line comment stating the name of the application and the time when the save operation was issued. Following this short intro a group of two lines is written for each option: first one is a comment telling the description of that option and second is the NAME = VALUE pair.
This is not intended to be a complete description of the package. It is considered just enough to make you a top user. Compile time options were, for example, entirely omitted. Please feel free to send comments, questions, whatever at nicu [here goes a dot] tofan [ here goes @ ] gmail [ dot again ] com.