| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts 35.0 is bundled with AutoGen. It is a tool that virtually eliminates the hassle of processing options and keeping man pages, info docs and usage text up to date. This package allows you to specify several program attributes, up to a hundred option types and many option attributes. From this, it then produces all the code necessary to parse and handle the command line and configuration file options, and the documentation that should go with your program as well.
All the features notwithstanding, some applications simply have well-established command line interfaces. Even still, those programs may use the configuration file parsing portion of the library. See the “AutoOpts Features” and “Configuration File Format” sections.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts supports option processing; option state saving; and program documentation with innumerable features. Here, we list a few obvious ones and some important ones, but the full list is really defined by all the attributes defined in the Option Definitions section.
[PROGRAM_NAME]” or “<?program-name>”, See section configuration file presets.
<?auto-options [[option-text]]>” may be used to set AutoOpts
option processing options. Viz., GNU usage layout versus AutoOpts
conventional layout, and misuse-usage versus no-misuse-usage,
See section Usage and Version Info Display.
dis-abled with a disablement prefix.
Such options may default to either an enabled or a disabled state. You
may also provide an enablement prefix, too, e.g., --allow-mumble
and --prevent-mumble (see section Common Option Attributes).
xxx-value;” in
the option definition file. “xxx” is the name of the option below:
These are always available. “more-help” will pass the full usage
text through a pager.
This is added to the option list if “usage-opt” is specified.
It yields the abbreviated usage to ‘stdout’.
This is added to the option list if “version = xxx;” is specified.
These are added to the option list if “homerc” is specified.
gnu-usage attribute (see section Program Information Attributes).
This can be overridden by the user himself with the
AUTOOPTS_USAGE environment variable. If it exists and is set
to the string gnu, it will force GNU-ish style format; if it is
set to the string autoopts, it will force AutoOpts standard
format; otherwise, it will have no effect.
ENABLE_NLS defined and _() defined to
a localization function such as gettext(3GNU), then the option
processing code will be localizable (see section Internationalizing AutoOpts).
allow-errors
(see section Program Description Attributes) attribute. When processing reaches a point
where optionProcess (see section optionProcess) needs to be called
again, the current option can be set with RESTART_OPT(n)
(see section RESTART_OPT( n ) - Resume Option Processing) before calling optionProcess.
See: See section Options for Library Code.
#include-d into the client option definitions
and they specify an "anchor" option that has a callback and must be invoked.
That will give the library access to the option state for their options.
#include into their own option definitions.
See “AutoOpt-ed Library for AutoOpt-ed Program” (see section AutoOpt-ed Library for AutoOpt-ed Program)
for more details.
main() routines can take advantage of all of AutoOpts’ functionality.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When AutoGen is installed, the AutoOpts project is installed with it. AutoOpts includes various AutoGen templates and a pair of shared libraries. These libraries may be used under the terms of version 3 of the GNU Lesser General Public License (LGPL).
One of these libraries (libopts) is needed by programs that are built
using AutoOpts generated code. This library is available as a separate
“tear-off” source tarball. It is redistributable for use under either of
two licenses: The above mentioned GNU Lesser General Public License, and
the advertising-clause-free BSD license. Both of these license terms are
incorporated into appropriate COPYING files included with the libopts
source tarball. This source may be incorporated into your package with
the following simple commands:
rm -rf libopts libopts-* gunzip -c `autoopts-config libsrc` | \ tar -xvf - mv libopts-*.*.* libopts |
View the ‘libopts/README’ file for further integration information.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts has its conventional way of displaying option information that includes somewhat more information that the standard GNU method. AutoOpts will also print out a line of usage text for each option type when options are misspecified. GNU programs typically do not do this. These defaults can be changed on a per-program basis by adding either or both of the following in the option definition file:
gnu-usage; no-misuse-usage; |
Users may also override these settings with the AUTOOPTS_USAGE
environment variable. It may be set to a comma or white space separated
list of the following strings:
The format of the extended usage text will be displayed in GNU-normal form.
The default display for --version will be to include a note
on licensing terms.
The format of the extended usage will be in AutoOpts’ native layout.
When an option error is made on the command line, the abbreviated usage text will be suppressed.
When an option error is made on the command line, the abbreviated usage text will be shown.
The setting used is the last one seen. The autoopts and
misuse-usage serve no purpose, unless the definition file
entries were specified as above.
Note for developers:
The templates used to implement AutoOpts depend heavily upon
token pasting. That mens that if you name an option, “debug”, for
example, the generated header will expect to be able to emit
#define macros such as this:
#define DESC(n) (autogenOptions.pOptDesc[INDEX_OPT_## n]) |
and expect DESC(DEBUG) to expand correctly into
(autogenOptions.pOptDesc[INDEX_OPT_DEBUG]).
If DEBUG is #defined to something else, then
that something else will be in the above expansion.
If you discover you are having strange problems like this,
you may wish to use some variation of the guard-option-names
See section Program Description Attributes.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Since it is generally easier to start with a simple example than it is
to look at the options that AutoGen uses itself, here is a very simple
AutoOpts example. You can copy this example out of the Info file and
into a source file to try it. You can then embellish it into what you
really need. For more extensive examples, you can also examine the help
output and option definitions for the commands columns,
getdefs and autogen itself.
For our simple example, assume you have a program named check
that takes two options:
check does.
You want this option available as a POSIX-style flag option
and a GNU long option. You want to allow as many of these
as the user wishes.
First, specify your program attributes and its options to AutoOpts, as with the following example.
AutoGen Definitions options;
prog-name = check;
prog-title = "Checkout Automated Options";
long-opts;
main = { main-type = shell-process; };
flag = {
name = check-dirs;
value = L; /* flag style option character */
arg-type = string; /* option argument indication */
max = NOLIMIT; /* occurrence limit (none) */
stack-arg; /* save opt args in a stack */
descrip = "Checkout directory list";
};
flag = {
name = show_defs;
descrip = "Show the definition tree";
disable = dont; /* mark as enable/disable type */
/* option. Disable as `dont-' */
};
|
Then perform the following steps:
cflags="-DTEST_CHECK_OPTS `autoopts-config cflags`"
ldflags="`autoopts-config ldflags`"
autogen checkopt.def
cc -o check -g ${cflags} checkopt.c ${ldflags}
./check --help
Running those commands yields:
check - Checkout Automated Options
USAGE: check [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
Flg Arg Option-Name Description
-L Str check-dirs Checkout directory list
- may appear multiple times
no show-defs Show the definition tree
- disabled as --dont-show-defs
-? no help Display extended usage information and exit
-! no more-help Extended usage information passed thru pager
Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.
|
Normally, however, you would compile ‘checkopt.c’ as in:
cc -o checkopt.o $cflags -c checkopt.c |
and link ‘checkopt.o’ with the rest of your program.
The main program causes the options to be processed
by calling optionProcess (see section optionProcess):
main( int argc, char** argv )
{
{
int optct = optionProcess( &checkOptions, argc, argv );
argc -= optct;
argv += optct;
}
|
The options are tested and used as in the following fragment.
“ENABLED_OPT” is used instead of “HAVE_OPT” for the
show-defs option because it is an enabled/disabled option type:
if ( ENABLED_OPT( SHOW_DEFS )
&& HAVE_OPT( CHECK_DIRS )) {
int dirct = STACKCT_OPT( CHECK_DIRS );
char** dirs = STACKLST_OPT( CHECK_DIRS );
while (dirct-- > 0) {
char* dir = *dirs++;
...
|
A lot of magic happens to make this happen. The rest of this chapter will describe the myriad of option attributes supported by AutoOpts. However, keep in mind that, in general, you won’t need much more than what was described in this "quick start" section.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts uses an AutoGen definitions file for the definitions of the program options and overall configuration attributes. The complete list of program and option attributes is quite extensive, so if you are reading to understand how to use AutoOpts, I recommend reading the "Quick Start" section (see section Quick Start) and paying attention to the following:
prog-name, prog-title, and argument, program
attributes, See section Program Description Attributes.
name and descrip option attributes, See section Required Attributes.
value (flag character) and min (occurrence counts)
option attributes, See section Common Option Attributes.
arg-type from the option argument specification section,
See section Option Argument Specification.
Keep in mind that the majority are rarely used and can be safely ignored. However, when you have special option processing requirements, the flexibility is there.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following global definitions are used to define attributes of the entire program. These generally alter the configuration or global behavior of the AutoOpts option parser. The first two are required of every program. The third is required if there are to be any left over arguments (operands) after option processing. The rest have been grouped below. Except as noted, there may be only one copy of each of these definitions:
This attribute is required. Variable names derived from this name
are derived using string->c_name! (see section ‘string->c-name!’ - map non-name chars to underscore).
This attribute is required and may be any descriptive text.
This attribute is required if your program uses operand arguments.
It specifies the syntax of the arguments that follow the options.
It may not be empty, but if it is not supplied, then option processing
must consume all the arguments. If it is supplied and starts with an
open bracket ([), then there is no requirement on the presence or
absence of command line arguments following the options. Lastly, if it
is supplied and does not start with an open bracket, then option
processing must not consume all of the command line arguments.
| 7.5.1.1 Usage and Version Info Display | ||
| 7.5.1.2 Program Configuration | ||
| 7.5.1.3 Programming Details | ||
| 7.5.1.4 User Presentation Attributes |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These will affect the way usage is seen and whether or not version information gets displayed.
If this attribute is provided, it may specify the full length usage text, or a variable name assignable to a “char const *” pointer, or it may be empty. The meanings are determined by the length.
This string should be readily translatable and provision will be made to translate it if this is provided and the source code is compiled with “ENABLE_NLS” defined.
If this attribute is provided, it is used to specify an abbreviated version of the usage text. This text is constructed in the same way as the “full-usage”, described above.
AutoOpts normaly displays usage text in a format that provides more
information than the standard GNU layout, but that also means it is
not the standard GNU layout. This attribute changes the default to
GNU layout, with the AUTOOPTS_USAGE environment variable used
to request autoopts layout.
See See section Developer and User Notes.
When there is a command line syntax error, by default AutoOpts will
display the abbreviated usage text, rather than just a one line
“you goofed it, ask for usage” message. You can change the default
behavior for your program by supplying this attribute. The user may
override this choice, again, with the AUTOOPTS_USAGE environment
variable. See See section Developer and User Notes.
The version text in the ‘getopt.tpl’ template will include this text in parentheses after the program name, when this attribute is specified. For example:
mumble (stumble) 1.0 |
says that the “mumble” program is version 1.0 and is part of the
“stumble” group of programs.
Specifies the program version and activates the VERSION option, See section Automatically Supported Options.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Programs may be “pre-configured” before normal command line options are processed (See see section Immediate Action Attributes). How configuration files and environment variables are handled get specified with these attributes.
Indicates that the command line usage of --load-opts and/or
--save-opts are disallowed.
Indicates looking in the environment for values of variables named,
PROGRAM_OPTNAME or PROGRAM, where PROGRAM is the
upper cased C-name of the program and OPTNAME is the
upper cased C-name of a specific option. The contents of
the PROGRAM variable, if found, are tokenized and processed.
The contents of PROGRAM_OPTNAME environment variables are taken
as the option argument to the option nameed optname.
Specifies either a directory or a file using a specific path, a path based
on an environment variable or a path relative to installation directories.
The method used depends on the first two characters of the name. If the
first character is not the dollar character ($), then it is
presumed to be a path name based on the current directory.
Otherwise, the method depends on the second character:
The path is relative to the directory where the executable was found.
The path is relative to the package data directory, e.g.
/usr/local/share/autogen.
The path is derived from the named environment variable.
Use as many as you like. The presence of this attribute
activates the --save-opts and --load-opts options.
See the optionMakePath(3AGEN) man page for excruciating details.
See section configuration file presets.
Specifies the configuration file name. This is only useful if you
have provided at least one homerc attribute.
default: .<prog-name>rc
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These attributes affect some of the ways that the option data are used and made available to the program.
The contents of this attribute should be just the name of the configuration file. A "#include" naming this file will be inserted at the top of the generated header.
These values should be defined as indexed values, thus:
exit-name[0] = success; exit-desc[0] = 'Successful program execution.'; exit-name[1] = failure; exit-desc[1] = 'The operation failed or command syntax was not valid.'; |
By default, all programs have these effectively defined for them.
They may be overridden by explicitly defining any or all of these values.
Additional names and descriptions may be defined.
They will cause an enumeration to be emitted, like this one
for getdefs:
typedef enum {
GETDEFS_EXIT_SUCCESS = 0,
GETDEFS_EXIT_FAILURE = 1
} getdefs_exit_code_t;
|
which will be augmented by any exit-name definitions beyond “1”.
This attribute will cause two procedures to be added to the code file:
usage_message and vusage_message, with any applicable prefix
(see prefix, below). They are declared in the
generated header, thus:
extern void vusage_message(char const * fmt, va_list ap); extern void usage_message(char const * fmt, ...); |
These functions print the message to ‘stderr’ and invoke the usage
function with the exit code set to 1 (EXIT_FAILURE).
This string is inserted into the .h interface file. Generally used for
global variables or #include directives required by
flag-code text and shared with other program text.
Do not specify your configuration header (‘config.h’) in this
attribute or the include attribute, however. Instead, use
config-header, above.
AutoOpts generates macros that presume that there are no cpp macros
with the same name as the option name. For example, if you have an option
named, debug, then you must not use #ifdef DEBUG in your code.
If you specify this attribute, every option name will be guarded. If the name
is #define-d, then a warning will be issued and the name undefined.
If you do not specify this and there is a conflict, you will get strange
error messages.
This attribute may be set to any of four recognized states:
#undef) any conflicting preprocessor macros. The code
will include compiler warnings (via #warning). Some compilers are
not ANSI-C-99 compliant yet and will error out on those warnings. You may
compile with -DNO_OPTION_NAME_WARNINGS to silence or mostly silence
them.
no-warning”. All of the needed
#undefs will be emitted, without any conflict checking #warning
directives emitted.
full-enum”. The option manipulation
preprocessor macros will not token paste the option names to the index
enumeration prefix. e.g. you will need to use HAVE_OPT(INDEX_OPT_DEBUG)
instead of HAVE_OPT(DEBUG).
This string is inserted into the .c file. Generally used for global
variables required only by flag-code program text.
If you are going to handle your option processing with the getopt.tpl
template instead of using libopts, then specify this attribute. It will
suppress mention of --more-help in the generated documentation.
(getopt_long does not support --more-help.)
This value is inserted into all global names. This will disambiguate them if more than one set of options are to be compiled into a single program.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Attributes that affect the user’s experience.
The presence of this attribute indicates ignoring any command line
option errors. This may also be turned on and off by invoking the
macros ERRSKIP_OPTERR and ERRSTOP_OPTERR from the
generated interface file.
Presence indicates GNU-standard long option processing. Partial name matches are accepted, if they are at least two characters long and the partial match is unique. The matching is not case sensitive, and the underscore, hyphen and carat characters are all equivalent (they match).
If any options do not have an option value (flag character) specified,
and least one does specify such a value, then you must specify
long-opts. If none of your options specify an option value
(flag character) and you do not specify long-opts, then command
line arguments are processed in "named option mode". This means that:
- and -- are completely optional.
argument program attribute is disallowed.
Modifies when or whether option names get translated. If provided, it must be assigned one of two values:
to suppress option name translation for configuration file and and environment variable processing.
to suppress option name translation completely. The usage text will
always be translated if ENABLE_NLS is defined and you have
translations for that text.
See also the various “XLAT” interface entries in the
AutoOpts Programmatic Interface section (see section Programmatic Interface).
Normally, POSIX compliant commands do not allow for options to be interleaved with operands. If this is necessary for historical reasons, there are two approaches available:
optionProcess to return the index of the operand like it normally
does and process the operand(s). When an operand is encountered that starts
with a hyphen, then set the AutoOpts current index with the RESTART_OPT
macro (see see section RESTART_OPT( n ) - Resume Option Processing), and re-invoke optionProcess. This will
also allow you to process the operands in context.
Specifies that the --reset-option command line option is to be supported.
This makes it possible to suppress any setting that might be found in
a configuration file or environment variable.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some libraries provide their own code for processing command line options, and this may be used by programs that utilize AutoOpts. You may also wish to write a library that gets configured with AutoOpts options and config files. Such a library may either supply its own configury routine and process its own options, or it may export its option descriptions to programs that also use AutoOpts. This section will describe how to do all of these different things.
| 7.5.2.1 AutoOpt-ed Library for AutoOpt-ed Program | ||
| 7.5.2.2 AutoOpt-ed Library for Regular Program | ||
| 7.5.2.3 AutoOpt-ed Program Calls Regular Library |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The library source code must provide an option definition file that consists
of only the attribute library
and flag entries. The “library” attribute does not need any
associated value, so it will generally appeary by itself on a line folowed
by a semi-colon. The first flag entry must contain the following
attributes:
This name is used in the construction of a global pointer of type
tOptDesc const*. It is always required.
It tells AutoOpts that this option serves no normal purpose.
It will be used to add usage clarity and to locate option descriptors
in the library code.
This is a string that is inserted in the extended usage display before the options specific to the current library. It is always required.
This should match the name of the library. This string is also used in the construction of the option descriptor pointer name. In the end, it looks like this:
extern tOptDesc const* <<lib-name>>_<<name>>_optDesc_p; |
and is used in the macros generated for the library’s .h file.
In order to compile this AutoOpts using library, you must create a
special header that is not used by the client program. This is accomplished
by creating an option definition file that contains essentially exactly the
following:
AutoGen definitions options; prog-name = does-not-matter; // but is always required prog-title = 'also does not matter'; // also required config-header = 'config.h'; // optional, but common library; #include library-options-only.def |
and nothing else. AutoGen will produce only the .h file.
You may now compile your library, referencing just this .h file.
The macros it creates will utilize a global variable that will be defined
by the AutoOpts-using client program. That program will need to
have the following #include in its option definition file:
#include library-options-only.def |
All the right things will magically happen so that the global variables
named <<lib-name>>_<<name>>_optDesc_p are initialized correctly.
For an example, please see the AutoOpts test script:
‘autoopts/test/library.test’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In this case, your library must provide an option processing function
to a calling program. This is accomplished by setting the allow-errors
global option attribute. Each time your option handling function is called,
you must determine where your scan is to resume and tell the AutoOpts library
by invoking:
RESTART_OPT(next_arg_index); |
and then invoke not_opt_index = optionProcess(...).
The not_opt_index value can be used to set optind,
if that is the global being used to scan the program argument array.
In this method, do NOT utilize the global library attribute.
Your library must specify its options as if it were a complete program.
You may choose to specify an alternate usage() function so that
usage for other parts of the option interface may be displayed as well.
See “Program Information Attributes” (see section Program Information Attributes).
At the moment, there is no method for calling optionUsage() telling
it to produce just the information about the options and not the program
as a whole. Some later revision after somebody asks.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As with providing an AutoOpt-ed library to a non-AutoOpt-ed
program, you must write the option description file as if you were writing
all the options for the program, but you should specify the
allow-errors global option attribute and you will likely want an
alternate usage() function (see “Program Information Attributes”
see section Program Information Attributes). In this case, though, when
optionProcess() returns, you need to test to see if there might be
library options. If there might be, then call the library’s exported
routine for handling command line options, set the next-option-to-process
with the RESTART_OPT() macro, and recall optionProcess().
Repeat until done.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These attributes are used to define how and what information is displayed to the user of the program.
The copyright is a structured value containing three to five
values. If copyright is used, then the first three are required.
An example of this might be:
copyright = {
date = "1992-2008";
owner = "Bruce Korb";
eaddr = 'bkorb@gnu.org';
type = GPL;
};
|
This string is added to the usage output when the HELP option is selected.
Gives additional information whenever the usage routine is invoked.
The name of the package the program belongs to. This will appear
parenthetically after the program name in the version and usage output,
e.g.: autogen (GNU autogen) - The Automated Program Generator.
This attribute will not change anything except appearance. Normally, the option names are all documented in lower case. However, if you specify this attribute, then they will display in the case used in their specification. Command line options will still be matched without case sensitivity.
These define global pointer variables that point to the program
descriptor and the first option descriptor for a library option. This
is intended for use by certain libraries that need command line and/or
initialization file option processing. These definitions have no effect
on the option template output, but are used for creating a library
interface file. Normally, the first "option" for a library will be a
documentation option that cannot be specified on the command line, but
is marked as settable. The library client program will invoke the
SET_OPTION macro which will invoke a handler function that will
finally set these global variables.
Optionally names the usage procedure, if the library routine
optionUsage() does not work for you. If you specify
my_usage as the value of this attribute, for example, you will
use a procedure by that name for displaying usage. Of course, you will
need to provide that procedure and it must conform to this profile:
void my_usage( tOptions* pOptions, int exitCode ) |
Normally, the default format produced by the optionUsage procedure
is AutoOpts Standard. By specifying this attribute, the default format
will be GNU-ish style. Either default may be overridden by the user with
the AUTOOPTS_USAGE environment variable. If it is set to gnu
or autoopts, it will alter the style appropriately. This attribute
will conflict with the usage attribute.
Some applications traditionally require that the command operands be
intermixed with the command options. In order to handle that, the arguments
must be reordered. If you are writing such an application, specify this
global option. All of the options (and any associated option arguments)
will be brought to the beginning of the argument list. New applications
should not use this feature, if at all possible. This feature is
disabled if POSIXLY_CORRECT is defined in the environment.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When AutoOpts generates the code to parse the command line options, it has
the ability to produce any of several types of main() procedures.
This is done by specifying a global structured value for
main. The values that it contains are dependent on the value set for
the one value it must have: main-type.
The recognized values for main-type are:
Here is an example of an include variation:
main = {
main-type = include;
tpl = "main-template.tpl";
};
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When the main-type is specified to be guile,
a main() procedure is generated that calls gh_enter(), providing
it with a generated inner_main() to invoke. If you must perform
certain tasks before calling gh_enter(), you may specify such code
in the value for the
before-guile-boot attribute.
The inner_main() procedure itself will process the command line
arguments (by calling optionProcess(),
see section optionProcess), and then either invoke the code
specified with the
guile-main attribute, or else export the parsed options to Guile
symbols and invoke the scm_shell() function from the Guile library.
This latter will render the program nearly identical to the stock
guile(1) program.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This will produce a main() procedure that parses the command line
options and emits to ‘stdout’ Bourne shell commands that puts the
option state into environment variables. This can be used within a
shell script as follows:
unset OPTION_CT
eval "`opt_parser \"$@\"`"
test -z "${OPTION_CT}" && exit 1
test ${OPTION_CT} -gt 0 && shift ${OPTION_CT}
|
If the option parsing code detects an error or a request for usage, it will not emit an assignment to OPTION_CT and the script should just exit. If the options are set consistently, then something along the lines of the following will be written to ‘stdout’ and evaled:
OPTION_CT=4
export OPTION_CT
MYPROG_SECOND='first'
export MYPROG_SECOND
MYPROG_ANOTHER=1 # 0x1
export MYPROG_ANOTHER
|
If the arguments are to be reordered, however, then the resulting set
of operands will be emitted and OPTION_CT gets set to zero.
For example, the following would be appended to the above:
set -- 'operand1' 'operand2' 'operand3'
OPTION_CT=0
|
OPTION_CT is set to zero since it is not necessary to shift
off any options.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This will produce a main() procedure that emits a shell script
that will parse the command line options. That script can be emitted
to ‘stdout’ or inserted or substituted into a pre-existing shell
script file. Improbable markers are used to identify previously inserted
parsing text:
# # # # # # # # # # -- do not modify this marker -- |
The program is also pretty insistent upon starting its parsing script on the second line.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You must supply a value for the main-text attribute.
You may also supply a value for
option-code. If you do, then the optionProcess invocation
will not be emitted into the code. AutoOpts will wrap the main-text
inside of:
int
main( int argc, char** argv )
{
{ // replaced by option-code, if that exists
int ct = optionProcess( &<<prog-name>>Options, argc, argv );
argc -= ct;
argv += ct;
}
<<your main-text goes here>>
}
|
so you can most conveniently set the value with a “here string”
(see section A Here String):
code = <<- _EndOfMainProc_ <<your text goes here>> _EndOfMainProc_; |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You must write a template to produce your main procedure.
You specify the name of the template with the tpl attribute
and it will be incorporated at the point where AutoOpts is ready
to emit the main() procedure.
This can be very useful if, in your working environment, you have
many programs with highly similar main() procedures. All you need
to do is parameterize the variations and specify which variant is needed
within the main AutoOpts specification. Since you are coding
the template for this, the attributes needed for this variation would
be dictated by your template.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You must write a template to produce your main procedure. That template
must contain a definition for the function specified with the func
attribute to this main() procedure specification. Typically, this
template will be incorporated by using the --lib-template option
(see section lib-template option (-l)) in the AutoGen invocation. Otherwise, this
variation operates in much the same way as “include”
(see section include: code emitted from included template) method.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This produces a main procedure that invokes a procedure once for each operand
on the command line (non-option arguments), OR once for each
non-blank, non-comment stdin input line. Leading and trailing white
space is trimmed from the input line and comment lines are lines that are
empty or begin with a comment character, defaulting to a hash (’#’) character.
NB:
The argument program attribute (see section Program Description Attributes)
must begin with the [ character, to indicate that there are
command operands, but that they are optional.
There are a number of attributes to main that may be used:
handler-procThis attribute is required. It is used to name the procedure to call. That procedure is presumed to be external, but if you provide the code for it, then the procedure is emitted as a static procedure in the generated code.
This procedure should return 0 on success, a cumulative error code on warning and exit without returning on an unrecoverable error. As the cumulative warning codes are or-ed together, the codes should be some sort of bit mask in order to be ultimately decipherable (if you need to do that).
If the called procedure needs to cause a fail-exit, it is expected to call
exit(3) directly. If you want to cause a warning exit code, then this
handler function should return a non-zero status. That value will be
OR-ed into a result integer for computing the final exit code. E.g.,
here is part of the emitted code:
int res = 0;
if (argc > 0) {
do {
res |= my_handler( *(argv++) );
} while (--argc > 0);
} else { ...
|
handler-typeIf you do not supply this attribute, your handler procedure must be the default type. The profile of the procedure must be:
int my_handler( char const *pz_entry ); |
However, if you do supply this attribute, you may set the value to any of four alternate flavors:
This is essentially the same as the default handler type, except that before your procedure is invoked, the generated code has verified that the string names an existing file. The profile is unchanged.
Before calling your procedure, the file is f-opened according to the “X”,
where “X” may be any of the legal modes for fopen(3C). In this case,
the profile for your procedure must be:
int my_handler( char const* pz_fname, FILE* entry_fp ); |
Before calling your procedure, the contents of the file are read or mapped into memory. (Excessively large files may cause problems.) The ‘some-text-of-file’ disallows empty files. Both require regular files. In this case, the profile for your procedure must be:
program_exit_code_t
my_handler(char const* pz_fname, char* file_text,
size_t text_size);
|
Note that though the file_text is not const, any changes made to
it are not written back to the original file. It is merely a memory image of
the file contents. Also, the memory allocated to hold the text is
text_size + 1 bytes long and the final byte is always NUL.
The file contents need not be text, as the data are read with the read(2)
system call.
If you select one of these file type handlers, then on access or usage errors
the PROGRAM_EXIT_FAILURE exit code will, by default, be or-ed
into the final exit code. This can be changed by specifying the
global file-fail-code attribute and naming a different value.
That is, something other than failure. You may choose success,
in which case file access issues will not affect the exit code and the error
message will not be printed.
my_handler-codeWith this attribute, you provide the code for your handler procedure
in the option definition file. In this case, your main()
procedure specification might look something like this:
main = {
main-type = for-each;
handler-proc = my_handler;
my_handler-code = <<- EndOfMyCode
/* whatever you want to do */
EndOfMyCode;
};
|
and instead of an emitted external reference, a procedure will be emitted that looks like this:
static int
my_handler( char const* pz_entry )
{
int res = 0;
<<my_handler-code goes here>>
return res;
}
|
main-initThis is code that gets inserted after the options have been processed, but before the handler procs get invoked.
main-finiThis is code that gets inserted after all the entries have been processed,
just before returning from main().
comment-charIf you wish comment lines to start with a character other than a hash
(#) character, then specify one character with this attribute.
If that character is the NUL byte, then only blank lines will be
considered comments.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For each option you wish to specify, you must have a block macro named
flag defined. There are two required attributes: name and
descrip. If any options do not have a value (traditional flag
character) attribute, then the long-opts program attribute must also
be defined. As a special exception, if no options have a value
and long-opts is not defined and argument is
not defined, then all arguments to the program are named options. In this
case, the - and -- command line option markers are optional.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Every option must have exactly one copy of both of these attributes.
Long name for the option. Even if you are not accepting long options
and are only accepting flags, it must be provided. AutoOpts generates
private, named storage that requires this name. This name also causes
a #define-d name to be emitted. It must not conflict with any
other names you may be using in your program.
For example, if your option name is, debug or munged-up,
you must not use the #define names DEBUG (or
MUNGED_UP) in your program for non-AutoOpts related purposes.
They are now used by AutoOpts.
Sometimes (most especially under Windows), you may get a surprise.
For example, INTERFACE is apparently a user space name that
one should be free to use. Windows usurps this name. To solve this,
you must do one of the following:
export = '#undef INTERFACE'; |
guard-option-names; |
Except for documentation options, a very brief description of
the option. About 40 characters on one line, maximum. It appears on
the usage() output next to the option name. If, however, the
option is a documentation option, it will appear on one or more lines by
itself. It is thus used to visually separate and comment upon groups of
options in the usage text.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These option attributes are optional. Any that do appear in the definition of a flag, may appear only once.
The flag character to specify for traditional option flags, e.g., -L.
Maximum occurrence count (invalid if disable present).
The default maximum is 1. NOLIMIT can be used for the value,
otherwise it must be a number or a #define that evaluates to a number.
Minimum occurrence count. If present, then the option must appear on the command line. Do not define it with the value zero (0).
If an option must be specified, but it need not be specified on the command line, then specify this attribute for the option.
There are two effects to this attribute: the usage text will not show the option, and the generated documentation will mark it with: “NOTE: THIS OPTION IS DEPRECATED”.
Prefix for disabling (inverting sense of) the option. Only useful if long option names are being processed.
Long-name prefix for enabling the option (invalid if disable not present). Only useful if long option names are being processed.
If default is for option being enabled. (Otherwise, the OPTST_DISABLED bit is set at compile time.) Only useful if the option can be disabled.
If an option is relevant on certain platforms or when certain features
are enabled or disabled, you can specify the compile time flag used
to indicate when the option should be compiled in or out. For example,
if you have a configurable feature, mumble that is indicated
with the compile time define, WITH_MUMBLING, then add:
ifdef = WITH_MUMBLING; |
Take care when using these. There are several caveats:
ifdef and ifndef may apply to any one option.
VALUE_OPT_ values are #define-d. If WITH_MUMBLING
is not defined, then the associated VALUE_OPT_ value will not be
#define-d either. So, if you have an option named, MUMBLING
that is active only if WITH_MUMBLING is #define-d, then
VALUE_OPT_MUMBLING will be #define-d iff WITH_MUMBLING
is #define-d. Watch those switch statements.
omitted-usage, then the option will be recognized
as disabled when it is configured out of the build, but will yield the
message, “This option has been disabled.” You may specify an alternate
message by giving omitted-usage a string value. e.g.:
omitted-usage = 'you cannot do this'; |
This option specifies that the option is not allowed on the command line.
Such an option may not take a value (flag character) attribute.
The program must have the homerc (see section Program Description Attributes) option set.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Certain options may need to be processed early. For example, in order to
suppress the processing of configuration files, it is necessary to process the
command line option --no-load-opts before the config files are
processed. To accommodate this, certain options may have their enabled or
disabled forms marked for immediate processing. The consequence of this is
that they are processed ahead of all other options in the reverse of normal
order.
Normally, the first options processed are the options specified in the first
homerc file, followed by then next homerc file through to the
end of config file processing. Next, environment variables are processed and
finally, the command line options. The later options override settings
processed earlier. That actually gives them higher priority. Command line
immediate action options actually have the lowest priority of all. They would
be used only if they are to have an effect on the processing of subsequent
options.
Use this option attribute to specify that the enabled form of the option
is to be processed immediately. The help and more-help
options are so specified. They will also call exit() upon
completion, so they do have an effect on the processing
of the remaining options :-).
Use this option attribute to specify that the disabled form of the
option is to be processed immediately. The load-opts option is
so specified. The --no-load-opts command line option will
suppress the processing of config files and environment variables.
Contrariwise, the --load-opts command line option is
processed normally. That means that the options specified in that file
will be processed after all the homerc files and, in fact, after
options that precede it on the command line.
If either the immediate or the immed-disable attributes
are set to the string, “also”, then the option will actually be
processed twice: first at the immediate processing phase and again
at the “normal” time.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These attributes may be used as many times as you need. They are used at the end of the option processing to verify that the context within which each option is found does not conflict with the presence or absence of other options.
This is not a complete cover of all possible conflicts and requirements, but it simple to implement and covers the more common situations.
one entry for every option that must be present when this option is present
one entry for every option that cannot be present when this option is present
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the option can be set outside of option processing, specify
“settable”. If this attribute is defined, special macros for setting
this particular option will be inserted into the interface file. For example,
TEMPL_DIRS is a settable option for AutoGen, so a macro named
SET_OPT_TEMPL_DIRS(a) appears in the interface file. This attribute
interacts with the documentation attribute.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If presetting this option is not allowed, specify “no-preset”.
(Thus, environment variables and values set in configuration files will be
ignored.)
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Generally, when several options are mutually exclusive and basically serve the
purpose of selecting one of several processing modes, specify the
“equivalence” attribute. These options will be considered an
equivalence class. Sometimes, it is just easier to deal with them as such.
All members of the equivalence class must contain the same equivalenced-to
option, including the equivalenced-to option itself. Thus, it must be a class
member.
For an option equivalence class, there is a single occurrence counter for
the class. It can be referenced with the interface macro,
COUNT_OPT(BASE_OPTION), where “BASE_OPTION” is the equivalenced-to
option name.
Also, please take careful note: since the options are mapped to the equivalenced-to option descriptor, any option argument values are mapped to that descriptor also. Be sure you know which “equivalent option” was selected before getting an option argument value!
During the presetting phase of option processing (see section Configuring your program), equivalenced options may be specified. However, if different equivalenced members are specified, only the last instance will be recognized and the others will be discarded. A conflict error is indicated only when multiple different members appear on the command line itself.
As an example of where equivalenced options might be useful, cpio(1)
has three options -o, -i, and -p that define the
operational mode of the program (create, extract and
pass-through, respectively). They form an equivalence class from
which one and only one member must appear on the command line. If
cpio were an AutoOpt-ed program, then each of these option
definitions would contain:
equivalence = create; |
and the program would be able to determine the operating mode with code that worked something like this:
switch (WHICH_IDX_CREATE) {
case INDEX_OPT_CREATE: ...
case INDEX_OPT_EXTRACT: ...
case INDEX_OPT_PASS_THROUGH: ...
default: /* cannot happen */
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sometimes, for backwards compatibility or tradition or just plain convenience, it works better to define one option as a pure alias for another option. For such situations, provide the following pieces of information:
flag = {
name = aliasing-option-name;
value = aliasing-flag-char; // optional !
aliases = aliased-to-option;
};
|
Do not provide anything else. The usage text for such an option will be:
alais for aliased-to-option option |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If your program processes its arguments in named option mode (See
“long-opts” in Program Description Attributes), then you may select one
of your options to be the default option. Do so by using attribute
“default” with one of the options. The option so specified must have
an arg-type (see section Option Argument Specification) specified, but not the
arg-optional (see section Option Argument Optional) attribute. That is to say, the
option argument must be required.
If you have done this, then any arguments that do not match an option
name and do not contain an equal sign (=) will be interpreted as
an option argument to the default option.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This attribute means the option exists for the purpose of separating option description text in the usage output. Libraries may choose to make it settable so that the library can determine which command line option is the first one that pertains to the library.
If the “documentation” attribute is present, then all other
attributes are disabled except settable, call-proc and
flag-code. settable must be and is only specified if
call-proc, extract-code or flag-code has been specified.
When present, the descrip attribute will be displayed only when the
--help option has been specified. It will be displayed flush to the
left hand margin and may consist of one or more lines of text. The name of
the option will not be printed.
Documentation options are for clarifying the usage text and will not appear in generated man pages or in the generated invoking texinfo doc.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you need to give the translators a special note about a particular option,
please use the “translators” attribute. The attribute text will be
emitted into the generated .c text where the option related strings get
defined. To make a general comment about all of the option code, add comments
to an include attribute (see section Program Description Attributes). Do not
use this attribute globally, or it will get emitted into every option
definition block.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Command line options come in three flavors: options that do not take arguments, those that do and those that may. Without an "arg-type" attribute, AutoOpts will not process an argument to an option. If "arg-type" is specified and "arg-optional" is also specified, then the next command line token will be taken to be an argument, unless it looks like the name of another option.
If the argument type is specified to be anything other than "str[ing]", then
AutoOpts will specify a callback procedure to handle the argument. Some of
these procedures will be created and inserted into the generated .c
file, and others are already built into the ‘libopts’ library.
Therefore, if you write your own callback procedure
(see section Option Argument Handling), then you must either not specify an
"arg-type" attribute, or else specify it to be of type "str[ing]". Your
callback function will be able to place its own restrictions on what that
string may contain or represent.
Option argument handling attributes depend upon the value set for the
arg-type attribute. It specifies the type of argument the option
will take. If not present, the option cannot take an argument. If present,
it must be an entry in the following table. The first three letters is
sufficient.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = string;
The argument may be any arbitrary string, though your program or option callback procedure may place additional constraints upon it.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = number;
The argument must be a correctly formed integer, without any trailing U’s or
L’s. AutoOpts contains a library procedure to convert the string to a number.
If you specify range checking with arg-range (see below), then AutoOpts
produces a special purpose procedure for this option.
scaled marks the option so that suffixes of ‘k’, ‘K’,
‘m’, ‘M’, ‘g’, ‘G’, ‘t’, and ‘T’ will multiply
the given number by a power of 1000 or 1024. Lower case letters scale by a
power of 1000 and upper case scale by a power of 1024.
arg-range is used to create a callback procedure for validating the
range of the option argument. It must match one of the range entries. Each
arg-range should consist of either an integer by itself or an integer
range. The integer range is specified by one or two integers separated by the
two character sequence, ->. Be sure to quote the entire range string.
The definitions parser will not accept the range syntax as a single string
token.
The generated procedure imposes the range constraints as follows:
INT_MIN, both for obvious
reasons and because that value is used to indicate a single-valued match.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = boolean;
The argument will be interpreted and always yield either AG_TRUE or
AG_FALSE. False values are the empty string, the number zero, or a
string that starts with f, F, n or N
(representing False or No). Anything else will be interpreted as True.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = keyword;
The argument must match a specified list of strings (see section Keyword list).
Assuming you have named the option, optn-name, the strings will be
converted into an enumeration of type te_Optn_Name with the values
OPTN_NAME_KEYWORD.* If you have not specified a default value,
the value OPTN_NAME_UNDEFINED will be inserted with the value zero.
The option will be initialized to that value. You may now use this in your
code as follows:
te_Optn_Name opt = OPT_VALUE_OPTN_NAME;
switch (opt) {
case OPTN_NAME_UNDEFINED: /* undefined things */ break;
case OPTN_NAME_KEYWORD: /* `keyword' things */ break;
default: /* utterly impossible */ ;
}
|
AutoOpts produces a special purpose procedure for this option.
If you have need for the string name of the selected keyword, you
may obtain this with the macro, OPT_OPTN_NAME_VAL2STR(val).
The value you pass would normally be OPT_VALUE_OPTN_NAME,
but anything with numeric value that is legal for te_Optn_Name
may be passed. Anything out of range will result in the string,
"*INVALID*" being returned. The strings are read only.
It may be used as in:
te_Optn_Name opt = OPT_VALUE_OPTN_NAME;
printf( "you selected the %s keyword\n",
OPT_OPTN_NAME_VAL2STR(opt) );
|
* Note: you may replace the OPTN_NAME enumeration prefix with
another prefix by specifying a
prefix-enum attribute.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = set;
The argument must be a list of names each of which must match the strings
"all", "none" or one of the keywords (see section Keyword list)
specified for this option. all will turn on all membership bits and
none will turn them all off. Specifying one of the keywords will turn
on the corresponding set membership bit. Literal numbers may also be used and
may, thereby, set or clear more than one bit. Preceding a keyword or literal
number with a bang (! - exclamation point) will turn the bit(s) off.
The number of keywords allowed is constrained by the number of bits in a
pointer, as the bit set is kept in a void*.
If, for example, you specified first in your list of keywords,
then you can use the following code to test to see if either first
or all was specified:
uintptr_t opt = OPT_VALUE_OPTN_NAME;
if (opt & OPTN_NAME_FIRST)
/* OPTN_NAME_FIRST bit was set */ ;
|
AutoOpts produces a special purpose procedure for this option.
To set multiple bits as the default (initial) value, you must
specify an initial numeric value (which might become inaccurate over
time), or else specify arg-default multiple times. Do not
specify a series of names conjoined with + symbols as the
value for any of the arg-default attributes. That works for
option parsing, but not for the option code generation.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = hierarchy;
arg-type = nested;
This denotes an option with a structure-valued argument, a.k.a.
“subopts” in getopts terminology. The argument is parsed
and the values made available to the program via the find and
find next calls (See section optionFindValue,
See section optionGetValue, and
see section optionFindNextValue).
tOptionValue * val = optionGetValue(VALUE_OPT_OPTN_NAME, "name");
while (val != NULL) {
process(val);
val = optionNextValue(VALUE_OPT_OPTN_NAME, val);
if (wrong_name(val, "name"))
break;
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = file;
This argument type will have some validations on the argument and, optionally, actually open the file. You must specify several additonal attributes for the option:
If not specified or empty, then the directory portion of the name is checked. The directory must exist or the argument is rejected and the usage procedure is invoked.
Otherwise, both the directory as above and the full name is tested for existence. If the value begins with the two letters “no”, then the file must not pre-exist. Otherwise, the file is expected to exist.
If not specified or empty, the file is left alone.
If the value begins with the four letters “desc”[riptor], then
open(2) is used and optArg.argFd is set. Otherwise, the
file is opened with fopen and optArg.argFp is set.
If “open-file” is set and not empty, then you must specify the open mode. Set the value to the flag bits or mode string as appropriate for the open type.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = time-duration;
The argument will be converted into a number of seconds. It may be a multi-part number with different parts being multiplied into a seconds value and added into the final result. Valid forms are in the table below. Upper cased letters represent numbers that must be used in the expressions.
where the hyphens (-) are really colons(:), but the
texi doc system won’t allow colons there.
HH is multiplied by 3600 and MM multiplied by 60
before they are added to SS. This time specification may not be
followed by any other time specs. HH and MM are both optional,
though HH cannot be specified without MM.
DAYS is multiplied by the number of seconds in a day. This value may
be followed by (and added to) values specified by HH:MM:SS or the
suffixed values below. If present, it must always be first.
HRS is multiplied by the number of seconds in an hour. This value may
be followed by (and added to) values specified by MM:SS or the
suffixed values below.
MINS is multiplied by the number of seconds in a minute. This value may
be followed by (and added to) a count of seconds.
This value can only be the last value in a time specification. The s
suffix is optional.
5 d 1:10:05 ==> 5 days + 1 hour 10 minutes and 5 seconds 5 d 1 h 10 m 5 ==> yields: 436205 seconds 5d1h10m5s ==> same result -- spaces are optional. |
When saved into a config file, the value will be stored as a simple count of seconds. There are actually more (many) accepted time duration strings. The full documentation can be found with ISO-8601 documentation and the more extedded documentation when “parse_duration()” becomes more widely available.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
arg-type = time-date;
The argument will be converted into the number of seconds since the epoch. The conversion rules are very complicated, please see the ‘getdate_r(3GNU)’ man page. There are some additional restrictions:
PKGDATADIR defined and naming a
valid directory.
DATEMSK environment variable will be set to the ‘datemsk’ file
within that directory.
If that file is not accessible for any reason, the string will be parsed as a time duration (see section Arg Type Time Duration) instead of a specific date and time.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the arg-type is keyword (see section Arg Type Keyword) or
set-membership (see section Arg Type Set Membership), then you must specify
the list of keywords by a series of keyword entries. The interface
file will contain values for <OPTN_NAME>_<KEYWORD> for each
keyword entry. keyword option types will have an enumeration and
set-membership option types will have a set of unsigned bits
#define-d.
If the arg-type is specifically keyword, you may also add
special handling code with a
extra-code attribute. After optionEnumerationVal has
converted the input string into an enumeration, you may insert code to
process this enumeration value (pOptDesc->optArg.argEnum).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This attribute indicates that the user does not have to supply an argument for
the option. This is only valid if the arg-type is string
(see section Arg Type String) or keyword (see section Arg Type Keyword). If it
is keyword, then this attribute may also specify the default keyword to
assume when the argument is not supplied. If left empty, arg-default
(see section Default Option Argument Value) or the zero-valued keyword will be used.
This is overridden and the options are required if the libopts library
gets configured with --disable-optional-args.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This specifies the default option argument value to be used when the option is
not specified or preset. You may specify multiple arg-default values if
the argument type is set membership.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts will either specify or automatically generate callback procedures
for options that take specialized arguments. The only option argument types
that are not specialized are plain string arguments and no argument at all.
For options that fall into one of those two categories, you may specify your
own callback function, as specified below. If you do this and if you
specify that options are resettable (see section Automatically Supported Options), then your
option handling code must look for the OPTST_RESET bit in
the fOptState field of the option descriptor.
If the option takes a string argument, then you may specify that the option
is to be handled by the libopts library procedures
stackOptArg() or unstackOptArg() (see below). In this case,
you may not provide option handling code.
Finally, documentation options (see section Option Sectioning Comment) may
also be marked as settable (see section Program may set option) and have special
callback functions (either flag-code, extract-code, or
call-proc).
statements to execute when the option is encountered. The generated procedure will look like this:
static void
doOpt<name>( tOptions* pOptions, tOptDesc* pOptDesc )
{
<flag-code>
}
|
Only certain fields within the tOptions and tOptDesc
structures may be accessed. See section Data for Option Processing.
This is effectively identical to flag-code, except that the
source is kept in the output file instead of the definitions file.
A long comment is used to demarcate the code. You must not modify
that marker. Before regenerating the option code file,
the old file is renamed from MUMBLE.c to MUMBLE.c.save. The template
will be looking there for the text to copy into the new output file.
external procedure to call when option is encountered. The calling
sequence must conform to the sequence defined above for the generated
procedure, doOpt<name>. It has the same restrictions
regarding the fields within the structures passed in as arguments.
See section Data for Option Processing.
Name of another option whose flag-code can be executed
when this option is encountered.
Call a special library routine to stack the option’s arguments. Special
macros in the interface file are provided for determining how many of the
options were found (STACKCT_OPT(NAME)) and to obtain a pointer to a
list of pointers to the argument values (STACKLST_OPT(NAME)).
Obviously, for a stackable argument, the max attribute
(see section Common Option Attributes) needs to be set higher than 1.
If this stacked argument option has a disablement prefix, then the entire stack of arguments will be cleared by specifying the option with that disablement prefix.
Call a special library routine to remove (“unstack”) strings
from a stack-arg option stack. This attribute must name
the option that is to be “unstacked”. Neither this option nor
the stacked argument option it references may be equivalenced to
another option.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Normally, AutoOpts produces usage text that is difficult to translate. It is pieced together on the fly using words and phrases scattered around here and there, piecing together toe document. This does not translate well.
Incorporated into this package are some ways around the problem. First, you
should specify the full-usage and short-usage program attributes
(see section Program Description Attributes). This will enable your translators to translate
the usage text as a whole.
Your translators will also be able to translate long option names. The option name translations will then become the names searched for both on the command line and in configuration files. However, it will not affect the names of environment variable names used to configure your program.
If it is considered desireable to keep configuration files in the “C”
locale, then several macros are available to suppress or delay the
translations of option names at run time. These are all disabled if
ENABLE_NLS is not defined at compile time. These macros must
be invoked before the first invocation of optionProcess.
Disable (or enable) the translations of option names for configuration files. If you enable translation for config files, then they will be translated for command line options.
Disable (or enable) the translations of option names for command line processing. If you disable the translation for command line processing, you will also disable it for configuration file processing. Once translated, the option names will remain translated.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts includes AutoGen templates for producing abbreviated man pages and for producing the invoking section of an info document. To take advantage of these templates, you must add several attributes to your option definitions.
If an option has an argument, the argument should have a name for
documentation purposes. It will default to arg-type, but
it will likely be clearer with something else like, file-name
instead of string (the type).
First, every flag definition other than “documentation”
definitions, must have a doc attribute defined. If the option takes
an argument, then it will need an arg-name attribute as well. The
doc text should be in plain sentences with minimal formatting. The
Texinfo commands @code, and @var will have its enclosed text
made into \fB entries in the man page, and the @file text
will be made into \fI entries. The arg-name attribute is
used to display the option’s argument in the man page.
Options marked with the “documentation” attribute are for documenting the usage text. All other options should have the “doc” attribute in order to document the usage of the option in the generated man pages.
This text will be inserted as a lead-in paragraph in the OPTIONS
section of the generated man page.
This is a compound attribute that requires three subattributes:
This describes the section type. Basically, the title of the section
that will be added to all output documentation. There may be only one
doc-section for any given ds-type. If there are duplicates,
the results are undefined (it might work, it might not).
There are five categories of ds-type sections.
They are those that the documentation templates would otherwise:
ds-types by this name.
These are marked, below, as ao-only.
alternate.
doc-section was provided.
These are marked, augments.
known
Some of these are emitted by the documentation templates only if certain conditions are met. If there are conditions, they are explained below. If there are no conditions, then you will always see the named section in the output.
The output sections will appear in this order:
ao-only.
alternate.
augments.
ao-only.
ao-only, if environment presets or configuration file processing
has been specified.
At this point, the unknown, alphabetized sections are inserted.
known
augments, if environment presets have been specified.
augments, if configuration file processing has been specified.
known
augments.
known
known
known
known
known
alternate, if the copyright stanza has either
an author or an owner attribute.
alternate, if there is a copyright stanza.
augments, if the copyright stanza has an
eaddr attribute.
augments.
This describes the format of the associated ds-text section.
man, mdoc and texi formats are supported.
Regardless of the chosen format, the formatting tags in the output
text will be converted to man macros for man pages,
mdoc macros for mdoc pages, and texi macros for
texinfo pages.
This is the descriptive text, written according to the rules for
ds-format documents.
Here is an example of a “doc-section” for a “SEE ALSO” type.
doc-section = {
ds-type = 'SEE ALSO'; // or anything else
ds-format = 'man'; // or texi or mdoc format
ds-text = <<-_EOText_
text relevant to this section type,
in the chosen format
_EOText_;
};
|
These attributes are now deprecated.
Please use a doc-section stanza with a ds-type
attribute set to DESCRIPTION instead.
This attribute is used to add a very short explanation about what a program is used for when the “title” attribute is insufficient. If there is no “doc-section” stanza of type “DESCRIPTION”, then this text is used for the man page DESCRIPTION section, too.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts provides automated support for several options. help and
more-help are always provided. The others are conditional upon
various global program attributes being defined See section Program Description Attributes.
Below are the option names and default flag values. The flags are activated
if and only if at least one user-defined option also uses a flag value. The
long names are supported as option names if long-opts has been
specified. These option flags may be deleted or changed to characters of your
choosing by specifying
xxx-value = "y";, where xxx is one of the
option names below and y is either empty or the character of your choice.
For example, to change the help flag from ? to h, specify
help-value = "h";; and to require that save-opts be specified
only with its long option name, specify
save-opts-value = "";.
With the exception of the load-opts option, none of these automatically
supported options will be recognized in configuration files or environment
variables.
This option will immediately invoke the USAGE() procedure
and display the usage line, a description of each option with
its description and option usage information. This is followed
by the contents of the definition of the detail text macro.
This option is identical to the help option, except that the
output is passed through a pager program. (more by default, or
the program identified by the PAGER environment variable.)
This option must be requested by specifying, usage-opt in the option
definition file. It will produce abbreviated help text to ‘stdout’ and
exit with zero status (EXIT_SUCCESS).
This will print the program name, title and version. If it is followed by
the letter c and a value for copyright and owner have
been provided, then the copyright will be printed, too. If it is followed
by the letter n, then the full copyright notice (if available) will
be printed. The version attribute must be specified in the option
definition file.
This option will load options from the named file. They will be treated exactly as if they were loaded from the normally found configuration files, but will not be loaded until the option is actually processed. This can also be used within another configuration file, causing them to nest. This is the only automatically supported option that can be activated inside of config files or with environment variables.
Specifying the negated form of the option (--no-load-opts) will
suppress the processing of configuration files and environment variables.
This option is activated by specifying one or more homerc attributes.
This option will cause the option state to be printed in the configuration file format when option processing is done but not yet verified for consistency. The program will terminate successfully without running when this has completed. Note that for most shells you will have to quote or escape the flag character to restrict special meanings to the shell.
The output file will be the configuration file name (default or provided by
rcfile) in the last directory named in a homerc definition.
This option may be set from within your program by invoking the
"SET_OPT_SAVE_OPTS(filename)" macro (see section SET_OPT_name - Force an option to be set).
Invoking this macro will set the file name for saving the option processing
state, but the state will not actually be saved. You must call
optionSaveFile to do that (see section optionSaveFile).
CAVEAT: if, after invoking this macro, you call
optionProcess, the option processing state will be saved to this file
and optionProcess will not return. You may wish to invoke
CLEAR_OPT( SAVE_OPTS ) (see section CLEAR_OPT( <NAME> ) - Clear Option Markings) beforehand if you do need
to reinvoke optionProcess.
This option is activated by specifying one or more homerc attributes.
This option takes the name of an option for the current program and resets its
state such that it is set back to its original, compile-time initialized
value. If the option state is subsequently stored (via --save-opts),
the named option will not appear in that file.
This option is activated by specifying the resettable attribute.
BEWARE: If the resettable attribute is specified, all
option callbacks must look for the OPTST_RESET bit in the
fOptState field of the option descriptor. If set, the optCookie
and optArg fields will be unchanged from their last setting. When the
callback returns, these fields will be set to their original values. If you
use this feature and you have allocated data hanging off of the cookie, you
need to deallocate it.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
AutoOpts has developed a set of standardized options.
You may incorporate these options in your program simply by first
adding a #define for the options you want, and then the line,
#include stdoptions.def |
in your option definitions. The supported options are specified thus:
#define DEBUG #define DIRECTORY #define DRY_RUN #define INPUT #define INTERACTIVE #define OUTPUT #define WARN #define SILENT #define QUIET #define BRIEF #define VERBOSE |
By default, only the long form of the option will be available.
To specify the short (flag) form, suffix these names with _FLAG.
e.g.,
#define DEBUG_FLAG |
--silent, --quiet, --brief and --verbose are
related in that they all indicate some level of diagnostic output.
These options are all designed to conflict with each other.
Instead of four different options, however, several levels can be
incorporated by #define-ing VERBOSE_ENUM. In conjunction
with VERBOSE, it incorporates the notion of 5 levels in an
enumeration: silent, quiet, brief,
informative and verbose; with the default being
brief.
Here is an example program that uses the following set of definitions:
AutoGen Definitions options;
prog-name = default-test;
prog-title = 'Default Option Example';
homerc = '$$/../share/default-test', '$HOME', '.';
environrc;
long-opts;
gnu-usage;
usage-opt;
version = '1.0';
main = {
main-type = shell-process;
};
#define DEBUG_FLAG
#define WARN_FLAG
#define WARN_LEVEL
#define VERBOSE_FLAG
#define VERBOSE_ENUM
#define DRY_RUN_FLAG
#define OUTPUT_FLAG
#define INPUT_FLAG
#define DIRECTORY_FLAG
#define INTERACTIVE_FLAG
#include stdoptions.def
|
Running a few simple commands on that definition file:
autogen default-test.def
copts="-DTEST_DEFAULT_TEST_OPTS `autoopts-config cflags`"
lopts="`autoopts-config ldflags`"
cc -o default-test ${copts} default-test.c ${lopts}
|
Yields a program which, when run with ‘--help’, prints out:
default-test - Default Option Example - Ver. 1.0
USAGE: default-test [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
The following options are commonly used and are provided and supported
by AutoOpts:
-D, --debug run program with debugging info
-V, --verbose=KWd run program with progress info
-w, --warn=num specify a warning-level threshhold
- disabled as --no-warn
-R, --dry-run program will make no changes
-I, --interactive=str prompt for confirmation
-i, --input=str redirect input from file
-o, --output=str redirect output to file
-d, --directory=str use specified dir for I/O
version and help options:
-v, --version[=arg] Output version information and exit
-?, --help Display extended usage information and exit
-!, --more-help Extended usage information passed thru pager
-u, --usage Abbreviated usage to stdout
->, --save-opts[=arg] Save the option state to a config file
-<, --load-opts=str Load options from a config file
- disabled as --no-load-opts
- may appear multiple times
Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.
The following option preset mechanisms are supported:
- reading file $$/../share/default-test
- reading file $HOME/.default_testrc
- reading file ./.default_testrc
- examining environment variables named DEFAULT_TEST_*
The valid "verbose" option keywords are:
silent quiet brief informative verbose
or an integer from 0 through 4
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The user interface for access to the argument information is completely defined in the generated header file and in the portions of the distributed file "options.h" that are marked "public".
In the following macros, text marked <NAME> or name
is the name of the option in upper case and segmented
with underscores _. The macros and enumerations defined in the
options header (interface) file are used as follows:
To see how these #define macros are used in a program,
the reader is referred to the several ‘opts.h’ files
included with the AutoGen sources.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes the data that may be accessed from within the
option processing callback routines. The following fields may be used
in the following ways and may be used for read only. The first set is
addressed from the tOptDesc* pointer:
These may be used by option procedures to determine which option they are working on (in case they handle several options).
These may be used by option procedures to determine which option was used to set the current option. This may be different from the above if the options are members of an equivalence class.
If AutoOpts is processing command line arguments, then this value will contain the current occurrence count. During the option preset phase (reading configuration files and examining environment variables), the value is zero.
The field may be tested for the following bit values
(prefix each name with OPTST_, e.g. OPTST_INIT):
Initial compiled value. As a bit test, it will always yield FALSE.
The option was set via the SET_OPT() macro.
The option was set via a configuration file.
The option was set via a command line option.
This is a mask of flags that show the set state, one of the above four values.
This bit is set when the option was selected by an equivalenced option.
This bit is set if the option is to be disabled.
(Meaning it was a long option prefixed by the disablement prefix, or
the option has not been specified yet and initializes as disabled.)
As an example of how this might be used, in AutoGen I want to allow
template writers to specify that the template output can be left
in a writable or read-only state. To support this, there is a Guile
function named set-writable (see section ‘set-writable’ - Make the output file be writable).
Also, I provide for command options --writable and
--not-writable. I give precedence to command line and RC
file options, thus:
switch (STATE_OPT( WRITABLE )) {
case OPTST_DEFINED:
case OPTST_PRESET:
fprintf(stderr, zOverrideWarn, pCurTemplate->pzFileName,
pCurMacro->lineNo);
break;
default:
if (gh_boolean_p( set ) && (set == SCM_BOOL_F))
CLEAR_OPT( WRITABLE );
else
SET_OPT_WRITABLE;
}
|
Pointer to the latest argument string. BEWARE If the argument type is numeric, an enumeration or a bit mask, then this will be the argument value and not a pointer to a string.
The following two fields are addressed from the tOptions* pointer:
Points to a NUL-terminated string containing the current program name, as retrieved from the argument vector.
Points to a NUL-terminated string containing the full path of the current program, as retrieved from the argument vector. (If available on your system.)
Note these fields get filled in during the first call to
optionProcess(). All other fields are private, for the exclusive
use of AutoOpts code and are subject to change.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Make as if the option had never been specified.
HAVE_OPT(<NAME>) will yield FALSE
after invoking this macro.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro will tell you how many times the option was specified on the command line. It does not include counts of preset options.
if (COUNT_OPT( NAME ) != desired-count) {
make-an-undesirable-message.
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro is used internally by other AutoOpt macros. It is not for general use. It is used to obtain the option description corresponding to its UPPER CASED option name argument. This is primarily used in other macro definitions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro is emitted if it is both settable and it can be disabled. If it cannot be disabled, it may always be CLEAR-ed (see above).
The form of the macro will actually depend on whether the
option is equivalenced to another, and/or has an assigned
handler procedure. Unlike the SET_OPT macro,
this macro does not allow an option argument.
DISABLE_OPT_NAME; |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Yields true if the option defaults to disabled and
ISUNUSED_OPT() would yield true. It also yields true if
the option has been specified with a disablement prefix,
disablement value or the DISABLE_OPT_NAME macro was invoked.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When it is necessary to continue (return to caller) on option errors, invoke this option. It is reversible. See section ERRSTOP_OPTERR - Stop on Errors.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
After invoking this macro, if optionProcess()
encounters an error, it will call exit(1) rather than return.
This is the default processing mode. It can be overridden by
specifying allow-errors in the definitions file,
or invoking the macro See section ERRSKIP_OPTERR - Ignore Option Errors.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro yields true if the option has been specified in any fashion at all. It is used thus:
if (HAVE_OPT( NAME )) {
<do-things-associated-with-opt-name>;
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro yields true if the option has been specified either on the command line or via a SET/DISABLE macro.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro yields true if the option has
never been specified, or has been cleared via the
CLEAR_OPT() macro.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The full count of all options, both those defined and those generated automatically by AutoOpts. This is primarily used to initialize the program option descriptor structure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The option argument value as a pointer to string. Note that argument
values that have been specified as numbers are stored as numbers or
keywords. For such options, use instead the OPT_VALUE_name
define. It is used thus:
if (HAVE_OPT( NAME )) {
char* p = OPT_ARG( NAME );
<do-things-with-opt-name-argument-string>;
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Invoking this macro will disable the translation of option names only while
processing configuration files and environment variables. This must be
invoked before the first call to optionProcess.. You need not invoke
this if your option definition file contains the attribute assignment,
“no-xlate = opt-cfg;”.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Invoking this macro will completely disable the translation of option names.
This must be invoked before the first call to optionProcess. You need
not invoke this if your option definition file contains the attribute
assignment, “no-xlate = opt;”.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro gets emitted only for options that take numeric, keyword or set membership arguments. The macro yields a word-sized integer containing the enumeration, bit set or numeric value for the option argument.
int opt_val = OPT_VALUE_name; |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If ENABLE_NLS is defined, this macro will cause the translation of
option names to happen before starting the processing of configuration files
and environment variables. This will change the recognition of options within
the $PROGRAMNAME environment variable, but will not alter the names
used for setting options via $PROGRAMNAME_name environment variables.
This must be invoked before the first call to optionProcess. You might
need to use this macro if your option definition file contains the attribute
assignment, “no-xlate = opt;” or “no-xlate = opt-cfg;”, and
you have determined in some way that you wish to override that.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If ENABLE_NLS is defined, translate the option names before processing
the command line options. Long option names may thus be localized.
(If the names were translated before configuration processing, they will
not be re-translated.)
This must be invoked before the first call to optionProcess. You might
need to use this macro if your option definition file contains the attribute
assignment, “no-xlate = opt;” and you have determined in some way that
you wish to override that.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If option processing has stopped (either because of an error
or something was encountered that looked like a program argument),
it can be resumed by providing this macro with the index n
of the next option to process and calling optionProcess() again.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro gets emitted only when the given
option has the settable attribute specified.
The form of the macro will actually depend on whether the option is equivalenced to another, has an option argument and/or has an assigned handler procedure. If the option has an argument, then this macro will too. Beware that the argument is not reallocated, so the value must not be on the stack or deallocated in any other way for as long as the value might get referenced.
If you have supplied at least one ‘homerc’ file
(see section Program Description Attributes), this macro will be emitted for the
--save-opts option.
SET_OPT_SAVE_OPTS( "filename" ); |
See section Automatically Supported Options, for a discussion of the implications of using this particular example.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When the option handling attribute is specified
as stack_arg, this macro may be used to determine how
many of them actually got stacked.
Do not use this on options that have not been stacked or has not been
specified (the stack_arg attribute must have been specified,
and HAVE_OPT(<NAME>) must yield TRUE).
Otherwise, you will likely seg fault.
if (HAVE_OPT( NAME )) {
int ct = STACKCT_OPT( NAME );
char** pp = STACKLST_OPT( NAME );
do {
char* p = *pp++;
do-things-with-p;
} while (--ct > 0);
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The address of the list of pointers to the option arguments. The pointers are ordered by the order in which they were encountered in the option presets and command line processing.
Do not use this on options that have not been stacked or has not been
specified (the stack_arg attribute must have been specified,
and HAVE_OPT(<OPTION>) must yield TRUE).
Otherwise, you will likely seg fault.
if (HAVE_OPT( NAME )) {
int ct = STACKCT_OPT( NAME );
char** pp = STACKLST_OPT( NAME );
do {
char* p = *pp++;
do-things-with-p;
} while (--ct > 0);
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is just a shortcut for RESTART_OPT(1) (See section RESTART_OPT( n ) - Resume Option Processing.)
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you need to know if an option was set because of presetting actions
(configuration file processing or environment variables), versus a command
line entry versus one of the SET/DISABLE macros, then use this macro. It
will yield one of four values: OPTST_INIT, OPTST_SET,
OPTST_PRESET or OPTST_DEFINED. It is used thus:
switch (STATE_OPT( NAME )) {
case OPTST_INIT:
not-preset, set or on the command line. (unless CLEAR-ed)
case OPTST_SET:
option set via the SET_OPT_NAME() macro.
case OPTST_PRESET:
option set via an configuration file or environment variable
case OPTST_DEFINED:
option set via a command line option.
default:
cannot happen :)
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro invokes the procedure registered to display
the usage text. Normally, this will be optionUsage from the
AutoOpts library, but you may select another procedure by specifying
usage = "proc_name" program attribute. This procedure must
take two arguments first, a pointer to the option descriptor, and
second the exit code. The macro supplies the option descriptor
automatically. This routine is expected to call exit(3) with
the provided exit code.
The optionUsage routine also behaves differently depending
on the exit code:
EXIT_SUCCESS (the value zero)It is assumed that full usage help has been requested. Consequently, more information is provided than when displaying usage and exiting with a non-zero exit code. Output will be sent to ‘stdout’ and the program will exit with a zero status code.
EX_USAGE (64)The abbreviated usage will be printed to ‘stdout’ and the program will exit with a zero status code. “EX_USAGE” may or may not be 64. If your system provides “/usr/include/sysexits.h” that has a different value, then that value will be used.
any other valueThe abbreviated usage will be printed to stderr and the program will exit with the provided status code.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is a #define for the flag character used to
specify an option on the command line. If value was not
specified for the option, then it is a unique number associated
with the option. option value refers to this value,
option argument refers to the (optional) argument to the
option.
switch (WHICH_OPT_OTHER_OPT) {
case VALUE_OPT_NAME:
this-option-was-really-opt-name;
case VALUE_OPT_OTHER_OPT:
this-option-was-really-other-opt;
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the version attribute is defined for the program,
then a stringified version will be #defined as PROGRAM_VERSION and
PROGRAM_FULL_VERSION. PROGRAM_FULL_VERSION is used for printing
the program version in response to the version option. The version
option is automatically supplied in response to this attribute, too.
You may access PROGRAM_VERSION via programOptions.pzFullVersion.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro gets emitted only for equivalenced-to options. It is used to obtain the index for the one of the several equivalence class members set the equivalenced-to option.
switch (WHICH_IDX_OTHER_OPT) {
case INDEX_OPT_NAME:
this-option-was-really-opt-name;
case INDEX_OPT_OTHER_OPT:
this-option-was-really-other-opt;
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro gets emitted only for equivalenced-to options. It is used to obtain the value code for the one of the several equivalence class members set the equivalenced-to option.
switch (WHICH_OPT_OTHER_OPT) {
case VALUE_OPT_NAME:
this-option-was-really-opt-name;
case VALUE_OPT_OTHER_OPT:
this-option-was-really-other-opt;
}
|
| [ < ] | [ > ] | [ << ] |
7.6.22 STACKLST_OPT( <NAME> ) - Argument StackThe address of the list of pointers to the option arguments. The pointers are ordered by the order in which they were encountered in the option presets and command line processing. Do not use this on options that have not been stacked or has not been
specified (the
7.6.23 START_OPT - Restart Option ProcessingThis is just a shortcut for RESTART_OPT(1) (See section RESTART_OPT( n ) - Resume Option Processing.)
7.6.24 STATE_OPT( <NAME> ) - Option StateIf you need to know if an option was set because of presetting actions
(configuration file processing or environment variables), versus a command
line entry versus one of the SET/DISABLE macros, then use this macro. It
will yield one of four values:
7.6.25 USAGE( exit-code ) - Usage invocation macroThis macro invokes the procedure registered to display
the usage text. Normally, this will be The
7.6.26 VALUE_OPT_name - Option Flag ValueThis is a #define for the flag character used to
specify an option on the command line. If
7.6.27 VERSION - Version and Full VersionIf the You may access PROGRAM_VERSION via
7.6.28 WHICH_IDX_name - Which Equivalenced IndexThis macro gets emitted only for equivalenced-to options. It is used to obtain the index for the one of the several equivalence class members set the equivalenced-to option.
7.6.29 WHICH_OPT_name - Which Equivalenced OptionThis macro gets emitted only for equivalenced-to options. It is used to obtain the value code for the one of the several equivalence class members set the equivalenced-to option.
|