Autogen Guide
Autogen Guide
Autogen Guide
Generator
For version 5.18, August 2015
Bruce Korb
[email protected]
AutoGen copyright
c 1992-2015 Bruce Korb
1 Introduction
AutoGen is a tool designed for generating program files that contain repetitive text with
varied substitutions. Its goal is to simplify the maintenance of programs that contain large
amounts of repetitious text. This is especially valuable if there are several blocks of such
text that must be kept synchronized in parallel tables.
An obvious example is the problem of maintaining the code required for processing
program options and configuration settings. Processing options requires a minimum of four
different constructs be kept in proper order in different places in your program. You need
at least:
1. The flag character in the flag string,
2. code to process the flag when it is encountered,
3. a global state variable or two, and
4. a line in the usage text.
You will need more things besides this if you choose to implement long option names,
configuration (rc/ini) file processing, environment variable settings and keep all the docu-
mentation for these up to date. This can be done mechanically; with the proper templates
and this program. In fact, it has already been done and AutoGen itself uses it See Chapter 7
[AutoOpts], page 83. For a simple example of Automated Option processing, See Section 7.4
[Quick Start], page 88. For a full list of the Automated Option features, See Section 7.1
[Features], page 83. Be forewarned, though, the feature list is ridiculously extensive.
We did this because it is burdensome and difficult to avoid conflicts using either M4
tokenization or C preprocessor substitution rules. It also makes it easier to specify
expressions that transform the value. Of course, our expressions are less cryptic than
the shell methods.
6. These same markers are used, in conjunction with enclosed keywords, to indicate sec-
tions of text that are to be skipped and for sections of text that are to be repeated.
This is a major improvement over using C preprocessing macros. With the C prepro-
cessor, you have no way of selecting output text because it is an unvarying, mechanical
substitution process.
7. Finally, we supply methods for carefully controlling the output. Sometimes, it is just
simply easier and clearer to compute some text or a value in one context when its
application needs to be later. So, functions are available for saving text or values for
later use.
== c +]
#include "list.h"
char const* az_name_list[] = {[+
FOR list "," +]
"[+list_info+]"[+
ENDFOR list +] };[+
ESAC +]
The [+ AutoGen5 template h c +] text tells AutoGen that this is an AutoGen version
5 template file; that it is to be processed twice; that the start macro marker is [+; and the
end marker is +]. The template will be processed first with a suffix value of h and then
with c. Normally, the suffix values are appended to the base-name to create the output file
name.
The [+ == h +] and [+ == c +] CASE selection clauses select different text for the two
different passes. In this example, the output is nearly disjoint and could have been put in
two separate templates. However, sometimes there are common sections and this is just an
example.
The [+FOR list "," +] and [+ ENDFOR list +] clauses delimit a block of text that will
be repeated for every definition of list. Inside of that block, the definition name-value
pairs that are members of each list are available for substitutions.
The remainder of the macros are expressions. Some of these contain special expres-
sion functions that are dependent on AutoGen named values; others are simply Scheme
Chapter 1: Introduction 5
expressions, the result of which will be inserted into the output text. Other expressions are
names of AutoGen values. These values will be inserted into the output text. For example,
[+list_info+] will result in the value associated with the name list_info being inserted
between the double quotes and (string-upcase! (get "list_element")) will first "get"
the value associated with the name list_element, then change the case of all the letters
to upper case. The result will be inserted into the output document.
If you have compiled AutoGen, you can copy out the template and definitions as de-
scribed above and run autogen list.def. This will produce exactly the hypothesized
desired output.
One more point, too. Lets say you decided it was too much trouble to figure out how
to use AutoGen, so you created this enumeration and string list with thousands of entries.
Now, requirements have changed and it has become necessary to map a string containing
the enumeration name into the enumeration number. With AutoGen, you just alter the
template to emit the table of names. It will be guaranteed to be in the correct order, missing
none of the entries. If you want to do that by hand, well, good luck.
pays by moving all of the option details (usage, flags names etc.) into a well structured
table (a definition file if you will), so that adding a new command line option becomes a
simple matter of adding a set of details to the table.
So far so good! Of course, now that there is a template, writing all of that tedious optargs
processing and usage functions is no longer an issue. Creating a table of the options needed
for the new project and running AutoGen generates all of the option processing code in
C automatically from just the tabular data. AutoGen in fact already ships with such a
template... AutoOpts.
One final consequence of the good separation in the design of AutoGen is that it is
retargetable to a greater extent. The egcs/gcc/fixinc/inclhack.def can equally be used (with
different templates) to create a shell script (inclhack.sh) or a c program (fixincl.c).
This is just the tip of the iceberg. AutoGen is far more powerful than these examples
might indicate, and has many other varied uses. I am certain Bruce or I could supply you
with many and varied examples, and I would heartily recommend that you try it for your
project and see for yourself how it compares to m4.
As an aside, I would be interested to see whether someone might be persuaded to ratio-
nalise autoconf with AutoGen in place of m4... Ben, are you listening? autoconf-3.0! ‘kay?
=)O|
Sincerely,
Gary V. Vaughan
Chapter 2: Definitions File 7
2 Definitions File
This chapter describes the syntax and semantics of the AutoGen definition file. In order
to instantiate a template, you normally must provide a definitions file that identifies itself
and contains some value definitions. Consequently, we keep it very simple. For "advanced"
users, there are preprocessing directives, sparse arrays, named indexes and comments that
may be used as well.
The definitions file is used to associate values with names. Every value is implicitly
an array of values, even if there is only one value. Values may be either simple strings
or compound collections of name-value pairs. An array may not contain both simple and
compound members. Fundamentally, it is as simple as:
prog-name = "autogen";
flag = {
name = templ_dirs;
value = L;
descrip = "Template search directory list";
};
For purposes of commenting and controlling the processing of the definitions, C-style
comments and most C preprocessing directives are honored. The major exception is that
the #if directive is ignored, along with all following text through the matching #endif
directive. The C preprocessor is not actually invoked, so C macro substitution is not
performed.
If AutoGen fails to find the template file in one of these places, it prints an error message
and exits.
Chapter 2: Definitions File 8
no^text^name ’;’
simple-name has the third index (index number 2) defined here. No^text^name is a simple
definition with a shorthand empty string value. The string values for definitions may be
specified in any of several formation rules.
Like ANSI "C", a series of these strings, possibly intermixed with single quote strings,
will be concatenated together.
As with the double quote string, a series of these, even intermixed with double quote strings,
will be concatenated together.
The resulting string will start with the first character on the next line and continue up
to but not including the newline that precedes the line that begins with the marker token.
The characters are copied directly into the result string. Mostly.
If a hyphen follows the less than characters, then leading tabs will be stripped and the
terminating marker will be recognized even if preceded by tabs. Also, if the first character
on the line (after removing tabs) is a backslash and the next character is a tab or space,
then the backslash will be removed as well. No other kind of processing is done on this
string.
Here are three examples:
str1 = <<- STR_END
$quotes = " ’ ‘
STR_END;
" stumble\n"
#endif
’;
Will work. It will enclose the ‘#ifdef LATER’ and ‘#endif’ in the string. But it may
also wreak havoc with the definition processing directives. The hash characters in the
first column should be disambiguated with an escape \ or join them with previous lines:
"fumble\n#ifdef LATER....
#endif This must follow an #if, #ifdef or #ifndef. In all cases, this will resume
normal processing of text.
#endmac Marks the end of the #macdef directive. Error when out of context.
#endshell
Marks the end of the #shell directive. Error when out of context.
#error This directive will cause AutoGen to stop processing and exit with a status of
EXIT FAILURE.
#ident Ignored directive.
#if #if expressions are not analyzed. Everything from here to the matching #endif
is skipped.
#ifdef The definitions that follow, up to the matching #endif will be processed only
if there is a corresponding -Dname command line option or if a #define of that
name has been previously encountered.
#ifndef The definitions that follow, up to the matching #endif will be processed only
if the named value has not been defined.
#include This directive will insert definitions from another file into the current collection.
If the file name is adorned with double quotes or angle brackets (as in a C
program), then the include is ignored.
#let Ignored directive.
#line Alters the current line number and/or file name. You may wish to use this
directive if you extract definition source from other files. getdefs uses this
mechanism so AutoGen will report the correct file and approximate line number
of any errors found in extracted definitions.
#macdef This is a new AT&T research preprocessing directive. Basically, it is a multi-
line #define that may include other preprocessing directives. Text between this
line and a #endmac directive are ignored.
#option This directive will pass the option name and associated text to the AutoOpts op-
tionLoadLine routine (see Section 7.6.32.8 [libopts-optionLoadLine], page 137).
The option text may span multiple lines by continuing them with a backslash.
The backslash/newline pair will be replaced with two space characters. This di-
rective may be used to set a search path for locating template files For example,
this:
#option templ-dirs $ENVVAR/dirname
will direct autogen to use the ENVVAR environment variable to find a direc-
tory named dirname that (may) contain templates. Since these directories are
searched in most recently supplied first order, search directories supplied in this
way will be searched before any supplied on the command line.
#pragma Ignored directive.
#shell Invokes $SHELL or /bin/sh on a script that should generate AutoGen defini-
tions. It does this using the same server process that handles the back-quoted
Chapter 2: Definitions File 14
‘ text. The block of text handed to the shell is terminated with the #endshell
directive.
CAUTION let not your $SHELL be csh.
#undef Will remove any entries from the define list that match the undef name pattern.
/*
* Include a standard set of definitions
*/
#include standards.def
a_block = {
a_field;
a_subblock = {
sub_name = first;
sub_field = "sub value.";
};
#ifdef FEATURE
a_subblock = {
sub_name = second;
};
#endif
};
/* STATE 0: DP_ST_INIT */
{ { DP_ST_NEED_DEF, NULL }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: VAR_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: OTHER_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
Chapter 2: Definitions File 16
/* STATE 1: DP_ST_NEED_DEF */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_NEED_TPL, NULL }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: VAR_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: OTHER_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DELETE_ENT */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: NUMBER */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: ; */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: = */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: , */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: { */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: } */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: [ */
{ DP_ST_INVALID, dp_do_invalid } /* EVT: ] */
/* STATE 2: DP_ST_NEED_TPL */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_NEED_SEMI, dp_do_tpl_name }, /* EVT: VAR_NAME */
{ DP_ST_NEED_SEMI, dp_do_tpl_name }, /* EVT: OTHER_NAME */
{ DP_ST_NEED_SEMI, dp_do_tpl_name }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DELETE_ENT */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: NUMBER */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: ; */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: = */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: , */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: { */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: } */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: [ */
{ DP_ST_INVALID, dp_do_invalid } /* EVT: ] */
/* STATE 3: DP_ST_NEED_SEMI */
Chapter 2: Definitions File 17
/* STATE 4: DP_ST_NEED_NAME */
{ { DP_ST_NEED_DEF, NULL }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_DONE, dp_do_need_name_end }, /* EVT: End-Of-File */
{ DP_ST_HAVE_NAME, dp_do_need_name_var_name }, /* EVT: VAR_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: OTHER_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DELETE_ENT */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: NUMBER */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: ; */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: = */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: , */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: { */
{ DP_ST_HAVE_VALUE, dp_do_end_block }, /* EVT: } */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: [ */
{ DP_ST_INVALID, dp_do_invalid } /* EVT: ] */
/* STATE 5: DP_ST_HAVE_NAME */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: VAR_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: OTHER_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DELETE_ENT */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: NUMBER */
{ DP_ST_NEED_NAME, dp_do_empty_val }, /* EVT: ; */
{ DP_ST_NEED_VALUE, dp_do_have_name_lit_eq }, /* EVT: = */
Chapter 2: Definitions File 18
/* STATE 6: DP_ST_NEED_VALUE */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_HAVE_VALUE, dp_do_str_value }, /* EVT: VAR_NAME */
{ DP_ST_HAVE_VALUE, dp_do_str_value }, /* EVT: OTHER_NAME */
{ DP_ST_HAVE_VALUE, dp_do_str_value }, /* EVT: STRING */
{ DP_ST_HAVE_VALUE, dp_do_str_value }, /* EVT: HERE_STRING */
{ DP_ST_NEED_NAME, dp_do_need_value_delete_ent }, /* EVT: DELETE_ENT */
{ DP_ST_HAVE_VALUE, dp_do_str_value }, /* EVT: NUMBER */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: ; */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: = */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: , */
{ DP_ST_NEED_NAME, dp_do_start_block }, /* EVT: { */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: } */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: [ */
{ DP_ST_INVALID, dp_do_invalid } /* EVT: ] */
/* STATE 7: DP_ST_NEED_IDX */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_NEED_CBKT, dp_do_indexed_name }, /* EVT: VAR_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: OTHER_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DELETE_ENT */
{ DP_ST_NEED_CBKT, dp_do_indexed_name }, /* EVT: NUMBER */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: ; */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: = */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: , */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: { */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: } */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: [ */
{ DP_ST_INVALID, dp_do_invalid } /* EVT: ] */
/* STATE 8: DP_ST_NEED_CBKT */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: VAR_NAME */
Chapter 2: Definitions File 19
/* STATE 9: DP_ST_INDX_NAME */
{ { DP_ST_INVALID, dp_do_invalid }, /* EVT: AUTOGEN */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DEFINITIONS */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: End-Of-File */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: VAR_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: OTHER_NAME */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: HERE_STRING */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: DELETE_ENT */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: NUMBER */
{ DP_ST_NEED_NAME, dp_do_empty_val }, /* EVT: ; */
{ DP_ST_NEED_VALUE, NULL }, /* EVT: = */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: , */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: { */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: } */
{ DP_ST_INVALID, dp_do_invalid }, /* EVT: [ */
{ DP_ST_INVALID, dp_do_invalid } /* EVT: ] */
3 Template File
The AutoGen template file defines the content of the output text. It is composed of two
parts. The first part consists of a pseudo macro invocation and commentary. It is followed
by the template proper.
This pseudo macro is special. It is used to identify the file as a AutoGen template
file, fixing the starting and ending marks for the macro invocations in the rest of the file,
specifying the list of suffixes to be generated by the template and, optionally, the shell to
use for processing shell commands embedded in the template.
AutoGen-ing a file consists of copying text from the template to the output file until a
start macro marker is found. The text from the start marker to the end marker constitutes
the macro text. AutoGen macros may cause sections of the template to be skipped or
processed several times. The process continues until the end of the template is reached.
The process is repeated once for each suffix specified in the pseudo macro.
This chapter describes the format of the AutoGen template macros and the usage of
the AutoGen native macros. Users may augment these by defining their own macros, See
Section 3.6.7 [DEFINE], page 58.
If the suffix begins with one of these three latter characters and a formatting string is
not specified, then that character is presumed to be the suffix separator. Otherwise,
without a specified format string, a single period will separate the suffix from the base
name in constructing the output file name.
4. Shell specification: to specify that the template was written expecting a particular shell
to run the shell commands. By default, the shell used is the autoconf-ed CONFIG_SHELL.
This will usually be /bin/sh. The shell is specified by a hash mark (#) followed by
an exclamation mark (!) followed by a full-path file name (e.g. /usr/xpg4/bin/sh on
Solaris):
[= Autogen5 Template c
#!/usr/xpg4/bin/sh
=]
5. Comments: blank lines, lines starting with a hash mark (#) and not specifying a shell,
and edit mode markers (text between pairs of -*- strings) are all treated as comments.
6. Some scheme expressions may be inserted in order to make configuration changes be-
fore template processing begins. before template processing begins means that there is
no current output file, no current suffix and, basically, none of the AutoGen specific
functions (see Section 3.4 [AutoGen Functions], page 26) may be invoked.
The scheme expression can also be used, for example, to save a pre-existing output file
for later text extraction (see Section 3.5.5 [SCM extract], page 39).
(shellf "mv -f %1$s.c %1$s.sav" (base-name))
After these must come the end macro marker:
6. The punctuation characters used to demarcate the end of a macro. Like the start
marker, it must consist of seven or fewer punctuation characters.
The ending macro marker has a few constraints on its content. Some of them are just
advisory, though. There is no special check for advisory restrictions.
• It must not begin with a POSIX file name character (hyphen -, underscore _ or period
.), the backslash (\) or open parenthesis ((). These are used to identify a suffix
specification, indicate Scheme code and trim white space.
• If it begins with an equal sign, then it must be separated from any suffix specification
by white space.
• The closing marker may not begin with an open parenthesis, as that is used to enclose
a scheme expression.
• It cannot begin with a backslash, as that is used to indicate white space trimming after
the end macro mark. If, in the body of the template, you put the backslash character
(\) before the end macro mark, then any white space characters after the mark and
through the newline character are trimmed.
• It is also helpful to avoid using the comment marker (#). It might be seen as a comment
within the pseudo macro.
• You should avoid using any of the quote characters double, single or back-quote. It
won’t confuse AutoGen, but it might well confuse you and/or your editor.
As an example, assume we want to use [+ and +] as the start and end macro markers,
and we wish to produce a .c and a .h file, then the pseudo macro might look something
like this:
Chapter 3: Template File 23
STRING are output as-is when the single quoted string is evaluated. Back-
slashes are processed before the hash character for consistency with the defini-
tion syntax. It is needed there to avoid preprocessing conflicts.
‘"STRING"’
A double quoted string. This is a cooked text string as in C, except that they
are not concatenated with adjacent strings. Evaluating "‘STRING’" will output
STRING with all backslash sequences interpreted.
‘‘STRING‘’
A back quoted string. When this expression is evaluated, STRING is first
interpreted as a cooked string (as in ‘"STRING"’) and evaluated as a shell
expression by the AutoGen server shell. This expression is replaced by the
stdout output of the shell.
‘(STRING)’
A parenthesized expression. It will be passed to the Guile interpreter for eval-
uation and replaced by the resulting value. If there is a Scheme error in this
expression, Guile 1.4 and Guile 1.6 will report the template line number where
the error occurs. Guile 1.7 has lost this capability.
Guile has the capability of creating and manipulating variables that can be
referenced later on in the template processing. If you define such a variable, it
is invisible to AutoGen. To reference its value, you must use a Guile expression.
For example,
[+ (define my-var "some-string-value") +]
can have that string inserted later, but only as in:
[+ (. my-var) +]
Additionally, other than in the % and ?% expressions, the Guile expressions may
be introduced with the Guile comment character (;) and you may put a series
of Guile expressions within a single macro. They will be implicitly evaluated as
if they were arguments to the (begin ...) expression. The result will be the
result of the last Guile expression evaluated.
Chapter 3: Template File 26
The prefix argument is a per-line string prefix. The optional second argument is a
prefix for the first line only and, in read-only mode, activates editor hints.
-*- buffer-read-only: t -*- vi: set ro:
The warning string also includes information about the template used to construct the file
and the definitions used in its instantiation.
Arguments:
prefix - string for starting each output line
first prefix - Optional - for the first output line
optpfx - Optional - shifted prefix
(exist? "foo[3].bar.baz")
will yield true if all of the following is true:
There is a member value of either group or string type named baz for some group value
bar that is a member of the foo group with index 3. There may be multiple entries of bar
within foo, only one needs to contain a value for baz.
Arguments:
ag-name - name of AutoGen value
Arguments:
ag-name - name of AutoGen value
Arguments:
line off - Optional - offset to line number
alt fmt - Optional - alternate format string
Arguments:
full path - Optional - include full path to file
desired behavior, the --not-writable command line option will override this.
Also, you may use the guile function (chmod "file" mode-value) to override
whatever AutoGen is using for the result mode.
Arguments:
file-name - name of file with text
marker-fmt - format for marker text
caveat - Optional - warn about changing marker
default - Optional - default initial text
/*=fumble bumble
* fmt: ’stumble %s: %d\n’
=*/
You may wish to generate a macro:
Arguments:
name - name of hash list
str - string to hash
Arguments:
str - string to make substitutions in
inside of a makefile shell script. Not every shell construct can be supported; the intent is
to have most ordinary scripts work without much, if any, alteration.
The following transformations are performed on the source text:
1. Trailing whitespace on each line is stripped.
2. Except for the last line, the string, " ; \\" is appended to the end of every line that
does not end with certain special characters or keywords. Note that this will mutilate
multi-line quoted strings, but make renders it impossible to use multi-line constructs
anyway.
3. If the line ends with a backslash, it is left alone.
4. If the line ends with a semi-colon, conjunction operator, pipe (vertical bar) or one of
the keywords "then", "else" or "in", then a space and a backslash is added, but no
semi-colon.
5. The dollar sign character is doubled, unless it immediately precedes an opening paren-
thesis or the single character make macros ’*’, ’<’, ’@’, ’ ?’ or ’%’. Other single character
make macros that do not have enclosing parentheses will fail. For shell usage of the
"$@", "$?" and "$*" macros, you must enclose them with curly braces, e.g., "${?}".
The ksh construct $(<command>) will not work. Though some makes accept ${var}
constructs, this function will assume it is for shell interpretation and double the dollar
character. You must use $(var) for all make substitutions.
6. Double dollar signs are replaced by four before the next character is examined.
7. Every line is prefixed with a tab, unless the first line already starts with a tab.
8. The newline character on the last line, if present, is suppressed.
9. Blank lines are stripped.
10. Lines starting with "@ifdef", "@ifndef", "@else" and "@endif" are presumed to be
autoconf "sed" expression tags. These lines will be emitted as-is, with no tab prefix
and no line splicing backslash. These lines can then be processed at configure time
with AC_CONFIG_FILES sed expressions, similar to:
sed "/^@ifdef foo/d;/^@endif foo/d;/^@ifndef foo/,/^@endif foo/d"
the strings match, but without regard to character case and certain characters are considered
‘equivalent’. Viz., ’-’, ’ ’ and ’^’ are equivalent.
Arguments:
text - text to test for pattern
match - pattern/substring to search for
Arguments:
text - text to test for pattern
match - pattern/substring to search for
have the same structure and number of elements. For example, to replace all amphersands,
less than and greater than characters, do something like this:
(string-substitute source
(list "&" "<" ">")
(list "&" "<" ">"))
Arguments:
source - string to transform
match - substring or substring list to be replaced
repl - replacement strings or substrings
Arguments:
str - input/output string
within the scope of an encompassing block macro must have its matching end macro appear
before the encompassing block macro is either ended or subdivided.
The block macros are these:
CASE This macro has scope through the ESAC macro. The scope is subdivided by
SELECT macros. You must have at least one SELECT macro.
DEFINE This macro has scope through the ENDDEF macro. The defined user macro can
never be a block macro. This macro is extracted from the template before the
template is processed. Consequently, you cannot select a definition based on
context. You can, however, place them all at the end of the file.
FOR This macro has scope through the ENDFOR macro.
IF This macro has scope through the ENDIF macro. The scope may be subdivided
by ELIF and ELSE macros. Obviously, there may be only one ELSE macro and
it must be the last of these subdivisions.
INCLUDE This macro has the scope of the included file. It is a block macro in the sense
that the included file must not contain any incomplete block macros.
WHILE This macro has scope through the ENDWHILE macro.
page 62) in the macro invocation. If you do that, the macro name can be computed with
an expression that gets evaluated every time the INVOKE macro is encountered.
Any remaining text in the macro invocation will be used to create new name/value
pairs that only persist for the duration of the processing of the macro. The expressions are
evaluated the same way basic expressions are evaluated. See Section 3.3 [expression syntax],
page 23.
The resulting definitions are handled much like regular definitions, except:
1. The values may not be compound. That is, they may not contain nested name/value
pairs.
2. The bindings go away when the macro is complete.
3. The name/value pairs are separated by whitespace instead of semi-colons.
4. Sequences of strings are not concatenated.
NB: The macro is extracted from the template as the template is scanned.
You cannot conditionally define a macro by enclosing it in an IF/ENDIF (see
Section 3.6.17 [IF], page 61) macro pair. If you need to dynamically select the
format of a DEFINEd macro, then put the flavors into separate template files
that simply define macros. INCLUDE (see Section 3.6.18 [INCLUDE], page 61)
the appropriate template when you have computed which you need.
Due to this, it is acceptable and even a good idea to place all the DEFINE macros at the
end of the template. That puts the main body of the template at the beginning of the file.
NB: the for-from, for-to, for-by and for-sep functions are disabled outside of the
context of the FOR macro. Likewise, the first-for?, last-for? for-index, and found-
for? functions are disabled outside of the range of a FOR block.
Also: the <value-name> must be a single level name, not a compound name (see
Section 3.2 [naming values], page 23).
[+FOR var (for-from 0) (for-to <number>) (for-sep ",") +]
... text with various substitutions ...[+
ENDFOR var+]
this will repeat the ... text with various substitutions ... <number>+1 times. Each
repetition, except for the last, will have a comma , after it.
[+FOR var ",\n" +]
... text with various substitutions ...[+
ENDFOR var +]
This will do the same thing, but only for the index values of var that have actually been
defined.
ELIF <full-expression-2> +]
emit things that are true maybe[+
ENDWHILE +]
<full-expression> may be any expression described in the EXPR expression function, in-
cluding the use of apply-codes and value-names. If the expression yields an empty string,
it is interpreted as false.
Chapter 3: Template File 63
There are also several functions for determining the output status. See Section 3.4
[AutoGen Functions], page 26.
Chapter 4: Augmenting AutoGen Features 65
5 Invoking autogen
AutoGen creates text files from templates using external definitions.
AutoGen is designed for generating program files that contain repetitive text with varied
substitutions. The goal is to simplify the maintenance of programs that contain large
amounts of repetitious text. This is especially valuable if there are several blocks of such
text that must be kept synchronized.
One common example is the problem of maintaining the code required for processing
program options. Processing options requires a minimum of four different constructs be kept
in proper order in different places in your program. You need at least: The flag character
in the flag string, code to process the flag when it is encountered, a global state variable or
two, and a line in the usage text. You will need more things besides this if you choose to
implement long option names, configuration file processing, environment variables and so
on.
All of this can be done mechanically; with the proper templates and this program.
This chapter was generated by AutoGen, using the agtexi-cmd template and the option
descriptions for the autogen program. This software is released under the GNU General
Public License, version 3 or later.
The following options are often useful while debugging new templates:
Add a directory to the list of directories autogen searches when opening a template,
either as the primary template or an included one. The last entry has the highest priority
in the search list. That is to say, they are searched in reverse order.
definitions option.
This is the “read definitions from file” option. This option takes a string argument FILE.
This option has some usage constraints. It:
• can be disabled with –no-definitions.
• It is enabled by default.
• may not be preset with environment variables or configuration (rc/ini) files.
Use this argument to specify the input definitions file with a command line option. If
you do not specify this option, then there must be a command line argument that specifies
the file, even if only to specify stdin with a hyphen (-). Specify, --no-definitions when
you wish to process a template without any active AutoGen definitions.
shell option.
This is the “name or path name of shell to use” option. This option takes a string argument
shell.
This option has some usage constraints. It:
• must be compiled in by defining SHELL_ENABLED during the compilation.
By default, when AutoGen is built, the configuration is probed for a reasonable Bourne-
like shell to use for shell script processing. If a particular template needs an alternate shell,
it must be specified with this option on the command line, with an environment variable
(SHELL) or in the configuration/initialization file.
Chapter 5: Invoking autogen 71
equate option.
This is the “characters considered equivalent” option. This option takes a string argument
char-list. This option will alter the list of characters considered equivalent. The default
are the three characters, " -^". (The last is conventional on a Tandem/HP-NonStop, and
I used to do a lot of work on Tandems.)
source-time option.
This is the “set mod times to latest source” option.
This option has some usage constraints. It:
• can be disabled with –no-source-time.
If you stamp your output files with the DNE macro output, then your output files will
always be different, even if the content has not really changed. If you use this option, then
Chapter 5: Invoking autogen 72
the modification time of the output files will change only if the input files change. This will
help reduce unneeded builds.
writable option.
This is the “allow output files to be writable” option.
This option has some usage constraints. It:
• can be disabled with –not-writable.
This option will leave output files writable. Normally, output files are read-only.
loop-limit option.
This is the “limit on increment loops” option. This option takes a number argument lim.
This option prevents runaway loops. For example, if you accidentally specify, "FOR x (for-
from 1) (for-to -1) (for-by 1)", it will take a long time to finish. If you do have more than
256 entries in tables, you will need to specify a new limit with this option.
trace option.
This is the “tracing level of detail” option. This option takes a keyword argument level.
This option has some usage constraints. It:
• This option takes a keyword as its argument. The argument sets an enumeration value
that can be tested by comparing the option value macro (OPT VALUE TRACE). The
available keywords are:
nothing debug-message server-shell
templates block-macros expressions
everything
or their numeric equivalent.
This option will cause AutoGen to display a trace of its template processing. There are
six levels, each level including messages from the previous levels:
‘nothing’ Does no tracing at all (default)
Chapter 5: Invoking autogen 73
‘debug-message’
Print messages from the "DEBUG" AutoGen macro (see Section 3.6.6 [DE-
BUG], page 58).
‘server-shell’
Traces all input and output to the server shell. This includes a shell "indepen-
dent" initialization script about 30 lines long. Its output is discarded and not
inserted into any template.
‘templates’
Traces the invocation of DEFINEd macros and INCLUDEs
‘block-macros’
Traces all block macros. The above, plus IF, FOR, CASE and WHILE.
‘expressions’
Displays the results of expression evaluations.
‘everything’
Displays the invocation of every AutoGen macro, even TEXT macros (i.e. the
text outside of macro quotes). Additionally, if you rebuild the “expr.ini” file
with debugging enabled, then all calls to AutoGen defined scheme functions
will also get logged:
cd ${top_builddir}/agen5
DEBUG_ENABLED=true bash bootstrap.dir expr.ini
make CFLAGS=’-g -DDEBUG_ENABLED=1’
Be aware that you cannot rebuild this source in this way without first having
installed the autogen executable in your search path. Because of this, "expr.ini"
is in the distributed source list, and not in the dependencies.
trace-out option.
This is the “tracing output file or filter” option. This option takes a string argument
file. The output specified may be a file name, a file that is appended to, or, if the option
argument begins with the pipe operator (|), a command that will receive the tracing output
as standard in. For example, --traceout=’| less’ will run the trace output through the
less program. Appending to a file is specified by preceding the file name with two greater-
than characters (>>).
show-defs option.
This is the “show the definition tree” option.
This option has some usage constraints. It:
• must be compiled in by defining DEBUG_ENABLED during the compilation.
• may not be preset with environment variables or configuration (rc/ini) files.
This will print out the complete definition tree before processing the template.
Chapter 5: Invoking autogen 74
used-defines option.
This is the “show the definitions used” option.
This option has some usage constraints. It:
• may not be preset with environment variables or configuration (rc/ini) files.
This will print out the names of definition values searched for during the processing of
the template, whether actually found or not. There may be other referenced definitions in
a template in portions of the template not evaluated. Some of the names listed may be
computed names and others AutoGen macro arguments. This is not a means for producing
a definitive, all-encompassing list of all and only the values used from a definition file. This
is intended as an aid to template documentation only.
Many systems default to a zero sized core limit. If the system has the sys/resource.h
header and if this option is supplied, then in the failure exit path, autogen will attempt to
set the soft core limit to whatever the hard core limit is. If that does not work, then an
administrator must raise the hard core size limit.
If you wish to override the suffix specifications in the template, you can use one or more
copies of this option. See the suffix specification in the Section 3.1 [pseudo macro], page 21
section of the info doc.
The AutoGen define names are used for the following purposes:
1. Sections of the AutoGen definitions may be enabled or disabled by using C-style #ifdef
and #ifndef directives.
2. When defining a value for a name, you may specify the index for a particular value.
That index may be a literal value, a define option or a value #define-d in the definitions
themselves.
3. The name of a file may be prefixed with $NAME/. The $NAME part of the name string
will be replaced with the define-d value for NAME.
4. When AutoGen is finished loading the definitions, the defined values are exported to
the environment with, putenv(3). These values can then be used in shell scripts with
${NAME} references and in templates with (getenv "NAME").
5. While processing a template, you may specify an index to retrieve a specific value.
That index may also be a define-d value.
It is entirely equivalent to place this name in the exported environment. Internally, that
is what AutoGen actually does with this option.
Similar to ’C’, AutoGen uses #ifdef/#ifndef preprocessing directives. This option will
cause the matching names to be removed from the list of defined values.
your-sentinel-file:
autogen -MT$@ -MF$*.d .....
local-clean :
rm -f $(clean_targets)
The modification time on the dependency file is adjusted to be one second before the
earliest time stamp of any other output file. Consequently, it is suitable for use as the
sentinel file testifying to the fact the program was successfully run. (-include is the GNU
make way of specifying "include it if it exists". Your make must support that feature or
your bootstrap process must create the file.)
All of this may also be specified using the DEPENDENCIES_OUTPUT or AUTOGEN_MAKE_DEP
environment variables. If defined, dependency information will be output. If defined with
Chapter 5: Invoking autogen 77
white space free text that is something other than true, false, yes, no, 0 or 1, then the
string is taken to be an output file name. If it contains a string of white space characters,
the first token is as above and the second token is taken to be the target (sentinel) file as
-MT in the paragraphs above. DEPENDENCIES_OUTPUT will be ignored if there are multiple
sequences of white space characters or if its contents are, specifically, false, no or 0.
version (-v)
Print the program version to standard out, optionally with licensing information, then exit
0. The optional argument specifies how much licensing detail to provide. The default is to
print just the version. The licensing infomation may be selected with an option argument.
Only the first letter of the argument is examined:
‘version’ Only print the version. This is the default.
‘copyright’
Name the copyright usage licensing terms.
‘verbose’ Print the full copyright usage licensing terms.
usage (-u)
Print abbreviated usage to standard out, then exit 0.
reset-option (-R)
Resets the specified option to the compiled-in initial state. This will undo anything that
may have been set by configuration files. The option argument may be either the option
flag character or its long name.
‘66 (EX_NOINPUT)’
A specified configuration file could not be loaded.
‘70 (EX_SOFTWARE)’
libopts had an internal operational error. Please report it to autogen-
[email protected]. Thank you.
ELSE ?><?
form-error ?><?
ENDIF ?>
This forces the template to be found in the "cgi-tpl/" directory. Note also that there is
no suffix specified in the pseudo macro (see Section 3.1 [pseudo macro], page 21). That tells
AutoGen to emit the output to stdout.
The output is actually spooled until it is complete so that, in the case of an error, the
output can be discarded and a proper error message can be written in its stead.
Please also note that it is advisable, especially for network accessible machines, to con-
figure AutoGen (see Section 6.1 [configuring], page 80) with shell processing disabled (--
disable-shell). That will make it impossible for any referenced template to hand data to
a subshell for interpretation.
is unlikely to match what your system uses. This can be fixed. Once you have installed
autogen, the mapping can be rebuilt on the host operating system. To do so, you must
perform the following steps:
1. Build and install AutoGen in a place where it will be found in your search path.
2. cd ${top_srcdir}/compat
3. ‘autogen strsignal.def’
4. Verify the results by examining the strsignal.h file produced.
5. Re-build and re-install AutoGen.
If you have any problems or peculiarities that cause this process to fail on your platform,
please send me copies of the header files containing the signal names and numbers, along
with the full path names of these files. I will endeavor to fix it. There is a shell script inside
of strsignal.def that tries to hunt down the information.
failures, you will need to invoke the test scripts individually. You may do so by specifying
the test (or list of test) in the TESTS make variable, thus:
gmake TESTS=test-name.test check
I specify gmake because most makes will not let you override internal definitions with
command line arguments. gmake does.
All of the AutoGen tests are written to honor the contents of the VERBOSE environment
variable. Normally, any commentary generated during a test run is discarded unless the
VERBOSE environment variable is set. So, to see what is happening during the test, you
might invoke the following with bash or ksh:
VERBOSE=1 gmake TESTS="for.test forcomma.test" check
Or equivalently with csh:
env VERBOSE=1 gmake TESTS="for.test forcomma.test" check
7. Options may be marked as 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 7.5.5.2 [Common
Attributes], page 106).
8. Verify that required options are present between the minimum and maximum number
of times on the command line. Verify that conflicting options do not appear together.
Verify that options requiring the presence of other options are, in fact, used in the
presence of other options. See See Section 7.5.5.2 [Common Attributes], page 106, and
See Section 7.5.5.4 [Option Conflict Attributes], page 108.
9. There are several Section 7.5.10 [automatic options], page 121. They will have short
flags if any options have option flags and the flags are not suppressed. The associated
flag may be altered or suppressed by specifying no value or an alternate character for
xxx-value; in the option definition file. xxx is the name of the option below:
‘--help’
‘--more-help’
These are always available. ‘--more-help’ will pass the full usage text
through a pager.
‘--usage’ This is added to the option list if usage-opt is specified. It yields the
abbreviated usage to stdout.
‘--version’
This is added to the option list if version = xxx; is specified.
‘--load-opts’
‘--save-opts’
These are added to the option list if homerc is specified. Mostly. If,
disable-save is specified, then --save-opts is disabled.
10. Various forms of main procedures can be added to the output, See Section 7.5.4 [Gen-
erated main], page 100. There are four basic forms:
a. A program that processes the arguments and writes to standard out portable shell
commands containing the digested options.
b. A program that will generate portable shell commands to parse the defined options.
The expectation is that this result will be copied into a shell script and used there.
c. A for-each main that will invoke a named function once for either each non-option
argument on the command line or, if there are none, then once for each non-blank,
non-comment input line read from stdin.
d. A main procedure of your own design. Its code can be supplied in the option
description template or by incorporating another template.
11. There are several methods for handling option arguments.
• nothing (see Section 7.6.13 [OPT ARG], page 128) option argument strings are
globally available.
• user supplied (see Section 7.5.7 [Option Argument Handling], page 115)
• stack option arguments (see Section 7.5.7 [Option Argument Handling], page 115)
• integer numbers (see Section 7.5.6.2 [arg-type number], page 111)
Chapter 7: Automated Option Processing 85
• true or false valued (see Section 7.5.6.3 [arg-type boolean], page 111)
• enumerated list of names (see Section 7.5.6.4 [arg-type keyword], page 112)
• an enumeration (membership) set (see Section 7.5.6.5 [arg-type set membership],
page 112)
• a list of name/value pairs (option subopts) (see Section 7.5.6.6 [arg-type hierar-
chy], page 113)
• a time duration or a specific time and date
• validated file name (see Section 7.5.6.7 [arg-type file name], page 113)
• optional option argument (see Section 7.5.6.11 [arg-optional], page 115)
12. The generated usage text can be emitted in either AutoOpts standard format (max-
imizing the information about each option), or GNU-ish normal form. The default
form is selected by either specifying or not specifying the gnu-usage attribute (see
Section 7.5.3 [information attributes], page 98). 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.
13. The usage text and many other strings are stored in a single character array (see
Section 3.5.56 [SCM string-table-new], page 52). This reduces fixup costs when loading
the program or library. The downside is that if GCC detects that any of these strings
are used in a printf format, you may get the warning, embedded ’\0’ in format. To
eliminate the warning, you must provide GCC with the -Wno-format-contains-nul
option.
14. If you compile with ENABLE_NLS defined and _() defined to a localization function (e.g.
gettext(3GNU)), then the option processing code will be localizable (see Section 7.16
[i18n], page 180). Provided also that you do not define the no-xlate attribute to
anything (see Section 7.5.1.4 [presentation attributes], page 96).
You should also ensure that the ATTRIBUTE_FORMAT_ARG() gets #define-ed to some-
thing useful. There is an autoconf macro named AG_COMPILE_FORMAT_ARG in ag_
macros.m4 that will set it appropriately for you. If you do not do this, then translated
formatting strings may trigger GCC compiler warnings.
15. Provides a callable routine to parse a text string as if it were from one of the
rc/ini/config files, hereafter referred to as a configuration file.
16. By adding a ‘doc’ and ‘arg-name’ attributes to each option, AutoGen will also be able
to produce a man page and the ‘invoking’ section of a texinfo document.
17. Intermingled option processing. AutoOpts options may be intermingled with
command line operands and options processed with other parsing techniques. This
is accomplished by setting the allow-errors (see Section 7.5.1 [program attributes],
page 90) attribute. When processing reaches a point where optionProcess (see
Section 7.6.32.14 [libopts-optionProcess], page 139) needs to be called again, the
current option can be set with RESTART_OPT(n) (see Section 7.6.19 [RESTART OPT],
page 129) before calling optionProcess.
See: See Section 7.5.2 [library attributes], page 97.
18. Library suppliers can specify command line options that their client programs will
accept. They specify option definitions that get #include-d into the client option
Chapter 7: Automated Option Processing 86
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.
19. library options. An AutoOpt-ed library may export its options for use in an AutoOpt-
ed program. This is done by providing an option definition file that client programs
#include into their own option definitions. See “AutoOpt-ed Library for AutoOpt-ed
Program” (see Section 7.5.2.1 [lib and program], page 97) for more details.
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";
doc = ’name of each directory that is to be "checked out".’;
};
flag = {
name = show_defs;
descrip = "Show the definition tree";
disable = dont; /* mark as enable/disable type */
/* option. Disable as ‘dont-’ */
doc = ’disable, if you do not want to see the tree.’;
Chapter 7: Automated Option Processing 89
};
exit 0
two documentation files check.1 and invoke-check.texi. The latter file will be generated
as a chapter, rather than a section or subsection.
autogen -Tagman-cmd check.def
autogen -DLEVEL=chapter -Tagtexi-cmd -binvoke-check.texi check.def
The result of which is left as an exercise for the reader.
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.
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.
‘config-header’
If your build has a configuration header, it must be included before anything
else. Specifying the configuration header file name with this attribute will cause
that to happen.
‘usage-opt’
I apologize for too many confusing usages of usage. This attribute specifies
that --usage and/or -u be supported. The help (usage) text displayed will be
abbreviated when compared to the default help text.
‘no-misuse-usage’
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 7.3 [Caveats], page 87.
‘prog-group’
The version text in the getopt.tpl template will include this text in parenthe-
ses 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.
‘usage’ If your program has some cleanup work that must be done before exiting on
usage mode issues, or if you have to customize the usage message in some way,
specify this procedure and it will be called instead of the default optionUsage()
function. For example, if a program is using the curses library and needs to in-
voke the usage display, then you must arrange to call endwin() before invoking
the library function optionUsage(). This can be handled by specifying your
own usage function, thus:
void
my_usage(tOptions * opts, int ex)
{
if (curses_window_active)
endwin();
optionUsage(opts, ex);
}
‘version’ Specifies the program version and activates the VERSION option, See
Section 7.5.10 [automatic options], page 121.
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.
‘homerc’ Specifies that option settings may be loaded from and stored into configuration
files. Each instance of this attribute is 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 name. If the one entry is empty,
it enables the loading and storing of settings, but no specific files are searched
for. Otherwise, a series of configuration files are hunted down and, if found,
loaded.
If the first character of the ‘homerc’ value 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.
[a-zA-Z] 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. However, saving into a file may be disabled
with the ‘disable-save’. See Section 7.10.1 [loading rcfile], page 147. See the
optionMakePath(3AGEN) man page for excruciating details.
‘rcfile’ Specifies the configuration file name. This is only useful if you have provided
at least one homerc attribute.
default: .<prog-name>rc
‘vendor-opt’
This option implements the -W vendor option command line option.
For POSIX specified utilities, the options are constrained to the options that
are specified by POSIX. Extensions should be handled with -W command line
options, the short flag form. Long option name processing must be disabled.
In fact, the long-opts attribute must not be provided, and some options must
be specified without flag values.
The -W long-name is processed by looking up the long option name that follows
it. It cannot be a short flag because that would conflict with the POSIX flag
name space. It will be processed as if long options were accepted and --long-
name were found on the command line.
‘config-header’
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.
‘exit-name’
‘exit-desc’
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’.
Some of the generated code will exit non-zero if there is an allocation error.
This exit will always be code ‘1’, unless there is an exit named ‘no_mem’ or
‘nomem’. In that case, that value will be used. Additionally, if there is such
a value, and if die-code is specified, then a function nomem_err(size_t len,
char const * what) will be emitted as an inline function for reporting out-of-
memory conditions.
‘usage-message’
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).
‘die-code’
This tells AutoOpts templates to emit code for vdie(), die(), fserr(), and,
possibly the nomem_err() functions. The latter is emitted if an exit name of
‘no-mem’ or ‘nomem’ is specified. If the die-code is assigned a text value, then
that code will be inserted in the vdie function immediately before it prints the
death rattle message.
The profiles for these functions are:
extern void vdie( int exit_code, char const * fmt, va_list);
extern void die( int exit_code, char const * fmt, ...);
extern void fserr(int exit_code, char const * op, char const * fname);
Chapter 7: Automated Option Processing 95
and re-invoke optionProcess. This will also allow you to process the
operands in context.
• Specify this attribute. AutoOpts will re-order the command arguments so
that the operands appear (in the original order) at the end of the argument
list. Differing configuration state is not possible to detect after all options
have been processed.
‘resettable’
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 config-
uration file or environment variable.
macro which will invoke a handler function that will finally set these global
variables.
‘usage’ 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 )
‘gnu-usage’
Normally, the default format produced by the optionUsage procedure is Au-
toOpts 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.
‘reorder-args’
Some applications traditionally require that the command operands be inter-
mixed 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.
The recognized values for main-type are guile, shell-process, shell-parser, main,
include, invoke, and for-each.
The inner_main() procedure itself will process the command line arguments (by calling
optionProcess(), see Section 7.6.32.14 [libopts-optionProcess], page 139), 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.
Chapter 7: Automated Option Processing 101
argc -= ct;
argv += ct;
}
<<main-text>>
return res;
}
so you can most conveniently set the value with a here string (see Section 2.2.7 [here-
string], page 9):
code = <<- _EndOfMainProc_
<<your text goes here>>
_EndOfMainProc_;
appear on the command line. If there are operands after the command line
options, then standard input is typically ignored. It can always be processed
as an input data file, however, if a single bare hyphen is put on the command
line.
‘text-of-file’
‘some-text-of-file’
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 * 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.
file_text is automatically freed, unless you specify a handler-frees at-
tribute. Then your code must free(3) the text.
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.
int res = 0;
<<MYHANDLER-code goes here>>
return res;
}
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:
1. Change the name of your option
2. add the program attribute (see Section 7.5.1 [program attributes], page 90):
export = ’#undef INTERFACE’;
3. add the program attribute:
guard-option-names;
‘descrip’ Except for documentation options, a very brief description of the option. About
40 characters on one line, maximum, not counting any texinfo markups. Texinfo
markups are stripped before printing in the usage text. 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.
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, envi-
ronment 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.
‘immediate’
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 :-).
‘immed-disable’
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.
‘also’ 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.
libopts library. Therefore, if you write your own callback procedure (see Section 7.5.7
[Option Argument Handling], page 115), 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 at-
tribute. 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.
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.
or not), start the string with a carat character (‘^’). If you wish to invert the result and start
without a carried over value, use one of the following: =^ or ^none+. These are equivalent.
The list of names or numbers must be separated by one of the following characters:
‘+-|!,’ or whitespace. The comma is equivalent to whitespace, except that only one may
appear between two entries and it may not appear in conjunction with the or bar (‘|’). The
‘+|’ leading characters or unadorned name signify adding the next named bit to the mask,
and the ‘-!’ leading characters indicate removing it.
The number of keywords allowed is constrained by the number of bits in a pointer, as
the bit set is kept in a void * pointer.
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.
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.
‘open-file’
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.
‘file-mode’
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.
1. Your project must be compiled with PKGDATADIR defined and naming a valid directory.
2. The 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 7.5.6.8 [arg-type time-duration], page 114) instead of a specific date and time.
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 7.5.10 [automatic options], page 121),
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 the stack-arg attribute can be used to specify
that the option is to be handled by the libopts stackOptArg() and unstackOptArg()
library procedures (see below). In this case, you may not provide option handling code.
Finally, ‘documentation’ options (see Section 7.5.5.10 [opt-attr documentation],
page 110) may also be marked as settable (see Section 7.5.5.5 [opt-attr settable],
page 108) and have special callback functions (either ‘flag-code’, ‘extract-code’, or
‘call-proc’).
‘flag-code’
statements to execute when the option is encountered. This may be used in
conjunction with option argument types that cause AutoOpts to emit handler
code. If you do this, the ‘flag-code’ with index zero (0) is emitted into the
handler code before the argument is handled, and the entry with index one (1)
is handled afterward.
The generated procedure will be laid out something like this:
static void
doOpt<name>(tOptions* pOptions, tOptDesc* pOptDesc)
{
<flag-code[0]>
<AutoOpts defined handler code>
<flag-code[1]>
}
Only certain fields within the tOptions and tOptDesc structures may be ac-
cessed. See Section 7.6.1 [Option Processing Data], page 125. When writing this
code, you must be very careful with the pOptions pointer. The handler code
is called with this pointer set to special values for handling special situations.
Your code must handle them. As an example, look at optionEnumerationVal
in enum.c.
‘extract-code’
This is effectively identical to flag-code, except that the source is kept in the
output file instead of the definitions file and you cannot use this in conjunction
with options with arguments, other than string arguments.
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.
‘call-proc’
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
Chapter 7: Automated Option Processing 117
‘flag-proc’
Name of another option whose flag-code can be executed when this option is
encountered.
‘stack-arg’
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 7.5.5.2 [Common Attributes], page 106) 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.
‘unstack-arg’
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 equiv-
alenced to another option.
‘OPT_NO_XLAT_CFG_NAMES;’
‘OPT_XLAT_CFG_NAMES;’
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.
Chapter 7: Automated Option Processing 118
‘OPT_NO_XLAT_OPT_NAMES;’
‘OPT_XLAT_OPT_NAMES;’
Disable (or enable) the translations of option names for command line process-
ing. 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.
‘NOTES’ augments.
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_;
};
‘doc-sub’ This attribute will cause the resulting documentation to be post-processed.
This is normally with sed, see doc-sub-cmd below. This attribute has several
sub-attributes:
‘sub-name’
This is the name of an autogen text definition value, like prog-
name or version. In the sub-text field, occurrences of this name
preceded by two less than characters and followed by two greater
than characters will be replaced by the text value of the definition,
e.g. ‘<<prog-name>>’.
‘sub-text’
The text that gets added to the command file for the post processing
program.
‘sub-type’
If this command only applies to certain types of output, specify this
with a regular expression that will match one of the valid output
format types, e.g. ‘man|mdoc’ will match those two kinds, but not
texi output. If omitted, it will always apply.
For example, if you want to reference the program name in the doc text for an
option common to two programs, put ‘#PROG#’ into the text. The following will
replace all occrrences of ‘#PROG#’ with the current value for prog:
doc-sub = {
sub-name = prog-name;
sub-text = ’s/#PROG#/<<prog-name>>/g’;
};
‘doc-sub-cmd’
A formatting string for constructing the post-processing command. The first
parameter is the name of the file with editing commands in it, and the second
is the file containing the unprocessed document. The default value is:
sed -f %s %s
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 =
"";.
Additionally, the procedure that prints out the program version may be replaced by
specifying version-proc. This procedure must be defined to be of external scope (non-
static). By default, the AutoOpts library provides optionPrintVersion and it will be the
specified callback function in the option definition structure.
With the exception of the load-opts option, none of these automatically supported
options will be recognized in configuration files or environment variables.
‘help -?’ 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.
‘more-help -!’
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.)
‘usage -u’ 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).
‘version -v’
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.
‘load-opts -<’
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.
‘save-opts ->’
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
Chapter 7: Automated Option Processing 123
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 7.6.20 [SET OPT name],
page 129). 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 7.6.32.16 [libopts-optionSaveFile],
page 140). 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 7.6.2 [CLEAR OPT], page 126) beforehand if you do need to reinvoke
optionProcess.
This option is activated by specifying one or more homerc attributes.
‘reset-option -R’
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.
#define SILENT
#define QUIET
Chapter 7: Automated Option Processing 124
#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:
exit 0
Chapter 7: Automated Option Processing 125
‘DISABLED’
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 3.4.50 [SCM set-writable], page 36). 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;
}
‘pzLastArg’
Pointer to the latest argument string. BEWARE If the argument type is nu-
meric, 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:
‘pzProgName’
Points to a NUL-terminated string containing the current program name, as
retrieved from the argument vector.
‘pzProgPath’
Points to a NUL-terminated string containing the full path of the current pro-
gram, 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.
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.
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);
}
do {
char* p = *pp++;
do-things-with-p;
} while (--ct > 0);
}
case OPTST_SET:
option set via the SET_OPT_NAME() macro.
case OPTST_PRESET:
Chapter 7: Automated Option Processing 131
case OPTST_DEFINED:
option set via a command line option.
default:
cannot happen :)
}
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.
with a more recent option library than the one you compiled with. However, if the library
is changed incompatibly, then the library will detect the out of date magic marker, explain
the difficulty and exit. You will then need to rebuild and recompile your option definitions.
This has rarely been necessary.
7.6.32.2 configFileLoad
parse a configuration file
Usage:
const tOptionValue * res = configFileLoad( fname );
Where the arguments are:
Name Type Description
—– —– ————-
fname char const * the file to load
returns const tOption- An allocated, compound value structure
Value *
This routine will load a named configuration file and parse the text as a hierarchically val-
ued option. The option descriptor created from an option definition file is not used via this
interface. The returned value is "named" with the input file name and is of type "OPARG_
TYPE_HIERARCHY". It may be used in calls to optionGetValue(), optionNextValue() and
optionUnloadNested().
If the file cannot be loaded or processed, NULL is returned and errno is set. It may be
set by a call to either open(2) mmap(2) or other file system calls, or it may be:
• ENOENT - the file was not found.
• ENOMSG - the file was empty.
• EINVAL - the file contents are invalid – not properly formed.
• ENOMEM - not enough memory to allocate the needed structures.
7.6.32.3 optionFileLoad
Load the locatable config files, in order
Usage:
int res = optionFileLoad( opts, prog );
Where the arguments are:
Name Type Description
—– —– ————-
opts tOptions * program options descriptor
Once the immediate action configurables have been handled, then the directories are
handled in normal, forward order. In that way, later config files can override the settings of
earlier config files.
See the AutoOpts documentation for a thorough discussion of the config file format.
Configuration files not found or not decipherable are simply ignored.
Returns the value, "-1" if the program options descriptor is out of date or indecipherable.
Otherwise, the value "0" will always be returned.
7.6.32.4 optionFindNextValue
find a hierarcicaly valued option instance
Usage:
const tOptionValue * res = optionFindNextValue( odesc, pPrevVal, name, value );
Where the arguments are:
Name Type Description
—– —– ————-
odesc const an option with a nested arg type
tOptDesc *
pPrevVal const the last entry
tOptionValue
*
name char const * name of value to find
7.6.32.5 optionFindValue
find a hierarcicaly valued option instance
Usage:
const tOptionValue * res = optionFindValue( odesc, name, val );
Where the arguments are:
Name Type Description
—– —– ————-
odesc const an option with a nested arg type
tOptDesc *
name char const * name of value to find
7.6.32.6 optionFree
free allocated option processing memory
Usage:
optionFree( pOpts );
Where the arguments are:
Name Type Description
—– —– ————-
pOpts tOptions * program options descriptor
AutoOpts sometimes allocates memory and puts pointers to it in the option state struc-
tures. This routine deallocates all such memory.
As long as memory has not been corrupted, this routine is always successful.
7.6.32.7 optionGetValue
get a specific value from a hierarcical list
Usage:
const tOptionValue * res = optionGetValue( pOptValue, valueName );
Where the arguments are:
Name Type Description
—– —– ————-
pOptValue const a hierarchcal value
tOptionValue
*
valueName char const * name of value to get
returns const tOption- a compound value structure
Value *
This routine will find an entry in a nested value option or configurable. If "valueName"
is NULL, then the first entry is returned. Otherwise, the first entry with a name that
exactly matches the argument will be returned. If there is no matching value, NULL is
returned and errno is set to ENOENT. If the provided option value is not a hierarchical
value, NULL is also returned and errno is set to EINVAL.
The returned result is NULL and errno is set:
• EINVAL - the pOptValue does not point to a valid hierarchical option value.
• ENOENT - no entry matched the given name.
Chapter 7: Automated Option Processing 137
7.6.32.8 optionLoadLine
process a string for an option name and value
Usage:
optionLoadLine( opts, line );
Where the arguments are:
Name Type Description
—– —– ————-
opts tOptions * program options descriptor
7.6.32.9 optionMemberList
Get the list of members of a bit mask set
Usage:
char * res = optionMemberList( od );
Where the arguments are:
Name Type Description
—– —– ————-
od tOptDesc * the set membership option description
returns char * the names of the set bits
This converts the OPT VALUE name mask value to a allocated string. It is the caller’s
responsibility to free the string.
7.6.32.10 optionNextValue
get the next value from a hierarchical list
Usage:
const tOptionValue * res = optionNextValue( pOptValue, pOldValue );
Where the arguments are:
Name Type Description
—– —– ————-
Chapter 7: Automated Option Processing 138
7.6.32.11 optionOnlyUsage
Print usage text for just the options
Usage:
optionOnlyUsage( pOpts, ex_code );
Where the arguments are:
Name Type Description
—– —– ————-
pOpts tOptions * program options descriptor
7.6.32.12 optionPrintVersion
Print the program version
Usage:
optionPrintVersion( opts, od );
Where the arguments are:
Name Type Description
—– —– ————-
opts tOptions * program options descriptor
7.6.32.13 optionPrintVersionAndReturn
Print the program version
Usage:
optionPrintVersionAndReturn( opts, od );
Where the arguments are:
Name Type Description
—– —– ————-
opts tOptions * program options descriptor
7.6.32.14 optionProcess
this is the main option processing routine
Usage:
int res = optionProcess( opts, a_ct, a_v );
Where the arguments are:
Name Type Description
—– —– ————-
opts tOptions * program options descriptor
7.6.32.15 optionRestore
restore option state from memory copy
Usage:
optionRestore( pOpts );
Where the arguments are:
Name Type Description
—– —– ————-
pOpts tOptions * program options descriptor
Copy back the option state from saved memory. The allocated memory is left intact, so
this routine can be called repeatedly without having to call optionSaveState again. If you
are restoring a state that was saved before the first call to optionProcess(3AO), then you
may change the contents of the argc/argv parameters to optionProcess.
If you have not called optionSaveState before, a diagnostic is printed to stderr and
exit is called.
7.6.32.16 optionSaveFile
saves the option state to a file
Usage:
optionSaveFile( opts );
Where the arguments are:
Name Type Description
—– —– ————-
opts tOptions * program options descriptor
This routine will save the state of option processing to a file. The name of that file can
be specified with the argument to the --save-opts option, or by appending the rcfile
attribute to the last homerc attribute. If no rcfile attribute was specified, it will default
to .programnamerc. If you wish to specify another file, you should invoke the SET_OPT_
SAVE_OPTS(filename) macro.
The recommend usage is as follows:
optionProcess(&progOptions, argc, argv);
if (i_want_a_non_standard_place_for_this)
SET_OPT_SAVE_OPTS("myfilename");
optionSaveFile(&progOptions);
If no homerc file was specified, this routine will silently return and do nothing. If the
output file cannot be created or updated, a message will be printed to stderr and the
routine will return.
7.6.32.17 optionSaveState
saves the option state to memory
Usage:
optionSaveState( pOpts );
Where the arguments are:
Chapter 7: Automated Option Processing 141
7.6.32.18 optionUnloadNested
Deallocate the memory for a nested value
Usage:
optionUnloadNested( pOptVal );
Where the arguments are:
Name Type Description
—– —– ————-
pOptVal tOptionValue the hierarchical value
const *
A nested value needs to be deallocated. The pointer passed in should have been got-
ten from a call to configFileLoad() (See see Section 7.6.32.2 [libopts-configFileLoad],
page 134).
7.6.32.19 optionVersion
return the compiled AutoOpts version number
Usage:
char const * res = optionVersion();
Where the arguments are:
Name Type Description
—– —– ————-
returns char const * the version string in constant memory
Returns the full version string compiled into the library. The returned string cannot be
modified.
7.6.32.20 strequate
map a list of characters to the same value
Usage:
strequate( ch_list );
Where the arguments are:
Chapter 7: Automated Option Processing 142
7.6.32.21 streqvcmp
compare two strings with an equivalence mapping
Usage:
int res = streqvcmp( str1, str2 );
Where the arguments are:
Name Type Description
—– —– ————-
str1 char const * first string
7.6.32.22 streqvmap
Set the character mappings for the streqv functions
Usage:
streqvmap( from, to, ct );
Where the arguments are:
Name Type Description
—– —– ————-
from char Input character
This function name is mapped to option streqvmap so as to not conflict with the POSIX
name space.
none.
7.6.32.23 strneqvcmp
compare two strings with an equivalence mapping
Usage:
int res = strneqvcmp( str1, str2, ct );
Where the arguments are:
Name Type Description
—– —– ————-
str1 char const * first string
7.6.32.24 strtransform
convert a string into its mapped-to value
Usage:
strtransform( dest, src );
Where the arguments are:
Name Type Description
—– —– ————-
dest char * output string
7.7 Multi-Threading
AutoOpts was designed to configure a program for running. This generally happens before
much real work has been started. Consequently, it is expected to be run before multi-
threaded applications have started multiple threads. However, this is not always the case.
Some applications may need to reset and reload their running configuration, and some
may use SET_OPT_xxx() macros during processing. If you need to dynamically change
your option configuration in your multi-threaded application, it is your responsibility to
prevent all threads from accessing the option configuration state, except the one altering
the configuration.
The various accessor macros (HAVE_OPT(), etc.) do not modify state and are safe to
use in a multi-threaded application. It is safe as long as no other thread is concurrently
modifying state, of course.
USAGE( EXIT_FAILURE );
}
argv += arg_ct;
}
if (HAVE_OPT(OPTN_NAME))
respond_to_optn_name();
...
}
• Compile ‘myopts.c’ and link your program with the following additional arguments:
‘autoopts-config cflags ldflags‘ myopts.c
This function will release all the associated memory. AutoOpts generated code
uses this function for its own needs. Client code should only call this function
with pointers gotten from configFileLoad.
# @end table
# The "this, char *" string is separated at the commas, with the
# white space removed. You may use characters other than commas by
# starting the value string with a punctuation character other than
# a single or double quote character. You may also omit intermediate
# values by placing the commas next to each other with no intervening
# white space. For example, "+mumble++yes+" will expand to:
# @*
# @code{arg = @{ argname = mumble; null = "yes"; @};}.
# Example:
#
#subblock sub-def
# Example:
#
#ordering file-name
#
# The argument to each copy of this option will be inserted into
# each output definition, with only a semicolon attached.
# Example:
#
#common_assign ag-def
#
#
#
# Specifies the template name to be used for generating the final output.
# Example:
#
#template file
The PROGRAM environment string is tokenized and parsed much like a command line.
Doubly quoted strings have backslash escapes processed the same way they are processed
in C program constant strings. Singly quoted strings are pretty raw in that backslashes are
honored before other backslashes, apostrophes, newlines and cr/newline pairs. The options
must be introduced with hyphens in the same way as the command line.
Note that not all options may be preset. Options that are specified with the no-preset
attribute and the --help, --more-help, and --save-opts auto-supported options may not
be preset.
if (pOV != NULL) {
const tOptionValue* pGetV = optionGetValue(pOV, "greeting");
if ( (pGetV != NULL)
&& (pGetV->valType == OPARG_TYPE_STRING))
greeting = strdup(pGetV->v.strVal);
return 0;
}
With that text in a file named “hello.c”, this short script:
cc -o hello hello.c ‘autoopts-config cflags ldflags‘
./hello
echo ’greeting Buzz off’ > hello.conf
./hello
echo personalize > hello.conf
./hello
will produce the following output:
Hello, World!
Buzz off, World!
Hello, Bruce Korb!
‘uncooked’
This mode strips leading and trailing white space, but not do any quote pro-
cessing. This is the default and need not be specified.
‘cooked’ The text is trimmed of leading and trailing white space and XML encodings are
processed. These encodings are slightly expanded over the XML specification.
They are specified with an ampersand followed by a value name or numeric
value and then a semicolon:
‘amp’
‘lt’
‘gt’
‘quot’
‘apos’
‘#dd’
‘#xHH’
These are all per fairly standad HTML and/or XML encodings.
Additionally:
‘bs’ The ASCII back space character.
‘ff’ The ASCII form feed character.
‘ht’ The ASCII horizontal (normal) tab character.
‘cr’ The ASCII carriage return character.
‘vt’ The ASCII vertical tab character.
‘bel’ The ASCII alarm bell character.
‘nl’ The ASCII new line character.
‘space’ The ASCII space character. Normally not necessary, but if you
want to preserve leading or trailing space characters, then use this.
And here is an example of an XML-styled value:
<name cooked>
This is&nl;&ht;another multi-line
&ht;string example.
</name>
The string value associated with name will be exactly the text enclosed in quotes with
the encoded characters cooked as you would expect (three text lines with the last line not
ending with a newline, but ending with a period).
a comment -->
<?this is
a bad comment ;->
- enabled by default
-v opt version output version information and exit
-? no help display extended usage information and exit
-! no more-help extended usage information passed thru pager
= = = = = = = =
Specify which definitions are of interest and what to say about them:
GETDEFS_DEFS_TO_GET=${GETDEFS_DEFS_TO_GET}
GETDEFS_DEFS_TO_GET_set=false
export GETDEFS_DEFS_TO_GET
if test -z "${GETDEFS_SUBBLOCK}"
then
GETDEFS_SUBBLOCK_CT=0
export GETDEFS_SUBBLOCK_CT
else
GETDEFS_SUBBLOCK_CT=1
GETDEFS_SUBBLOCK_1=${GETDEFS_SUBBLOCK}
export GETDEFS_SUBBLOCK_CT GETDEFS_SUBBLOCK_1
fi
Chapter 7: Automated Option Processing 164
if test -z "${GETDEFS_LISTATTR}"
then
GETDEFS_LISTATTR_CT=0
export GETDEFS_LISTATTR_CT
else
GETDEFS_LISTATTR_CT=1
GETDEFS_LISTATTR_1=${GETDEFS_LISTATTR}
export GETDEFS_LISTATTR_CT GETDEFS_LISTATTR_1
fi
GETDEFS_ORDERING=${GETDEFS_ORDERING}
GETDEFS_ORDERING_set=false
export GETDEFS_ORDERING
GETDEFS_FIRST_INDEX=${GETDEFS_FIRST_INDEX-’0’}
GETDEFS_FIRST_INDEX_set=false
export GETDEFS_FIRST_INDEX
GETDEFS_FILELIST=${GETDEFS_FILELIST}
GETDEFS_FILELIST_set=false
export GETDEFS_FILELIST
if test -z "${GETDEFS_ASSIGN}"
then
GETDEFS_ASSIGN_CT=0
export GETDEFS_ASSIGN_CT
else
GETDEFS_ASSIGN_CT=1
GETDEFS_ASSIGN_1=${GETDEFS_ASSIGN}
export GETDEFS_ASSIGN_CT GETDEFS_ASSIGN_1
fi
if test -z "${GETDEFS_COMMON_ASSIGN}"
then
GETDEFS_COMMON_ASSIGN_CT=0
export GETDEFS_COMMON_ASSIGN_CT
else
GETDEFS_COMMON_ASSIGN_CT=1
GETDEFS_COMMON_ASSIGN_1=${GETDEFS_COMMON_ASSIGN}
export GETDEFS_COMMON_ASSIGN_CT GETDEFS_COMMON_ASSIGN_1
fi
if test -z "${GETDEFS_COPY}"
then
GETDEFS_COPY_CT=0
export GETDEFS_COPY_CT
else
Chapter 7: Automated Option Processing 165
GETDEFS_COPY_CT=1
GETDEFS_COPY_1=${GETDEFS_COPY}
export GETDEFS_COPY_CT GETDEFS_COPY_1
fi
GETDEFS_SRCFILE=${GETDEFS_SRCFILE}
GETDEFS_SRCFILE_set=false
export GETDEFS_SRCFILE
GETDEFS_LINENUM=${GETDEFS_LINENUM}
GETDEFS_LINENUM_set=false
export GETDEFS_LINENUM
if test -z "${GETDEFS_INPUT}"
then
GETDEFS_INPUT_CT=0
export GETDEFS_INPUT_CT
else
GETDEFS_INPUT_CT=1
GETDEFS_INPUT_1=${GETDEFS_INPUT}
export GETDEFS_INPUT_CT GETDEFS_INPUT_1
fi
GETDEFS_OUTPUT=${GETDEFS_OUTPUT}
GETDEFS_OUTPUT_set=false
export GETDEFS_OUTPUT
GETDEFS_AUTOGEN=${GETDEFS_AUTOGEN}
GETDEFS_AUTOGEN_set=false
export GETDEFS_AUTOGEN
GETDEFS_TEMPLATE=${GETDEFS_TEMPLATE}
GETDEFS_TEMPLATE_set=false
export GETDEFS_TEMPLATE
if test -z "${GETDEFS_AGARG}"
then
GETDEFS_AGARG_CT=0
export GETDEFS_AGARG_CT
else
GETDEFS_AGARG_CT=1
GETDEFS_AGARG_1=${GETDEFS_AGARG}
export GETDEFS_AGARG_CT GETDEFS_AGARG_1
fi
GETDEFS_BASE_NAME=${GETDEFS_BASE_NAME}
GETDEFS_BASE_NAME_set=false
Chapter 7: Automated Option Processing 166
export GETDEFS_BASE_NAME
ARG_COUNT=$#
OPT_ARG=$1
while [ $# -gt 0 ]
do
OPT_ELEMENT=’’
OPT_ARG_VAL=’’
OPT_ARG=${1}
OPT_CODE=‘echo "X${OPT_ARG}"|sed ’s/^X-*//’‘
shift
OPT_ARG=$1
case "${OPT_CODE}" in *=* )
OPT_ARG_VAL=‘echo "${OPT_CODE}"|sed ’s/^[^=]*=//’‘
OPT_CODE=‘echo "${OPT_CODE}"|sed ’s/=.*$//’‘ ;; esac
case "${OPT_CODE}" in
’de’ | \
’def’ | \
’defs’ | \
’defs-’ | \
’defs-t’ | \
’defs-to’ | \
’defs-to-’ | \
’defs-to-g’ | \
’defs-to-ge’ | \
’defs-to-get’ )
if [ -n "${GETDEFS_DEFS_TO_GET}" ] && ${GETDEFS_DEFS_TO_GET_set} ; then
echo ’Error: duplicate DEFS_TO_GET option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_DEFS_TO_GET_set=true
OPT_NAME=’DEFS_TO_GET’
OPT_ARG_NEEDED=YES
;;
’su’ | \
’sub’ | \
’subb’ | \
’subbl’ | \
’subblo’ | \
’subbloc’ | \
’subblock’ )
GETDEFS_SUBBLOCK_CT=‘expr ${GETDEFS_SUBBLOCK_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_SUBBLOCK_CT}"
OPT_NAME=’SUBBLOCK’
OPT_ARG_NEEDED=YES
Chapter 7: Automated Option Processing 167
;;
’li’ | \
’lis’ | \
’list’ | \
’lista’ | \
’listat’ | \
’listatt’ | \
’listattr’ )
GETDEFS_LISTATTR_CT=‘expr ${GETDEFS_LISTATTR_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_LISTATTR_CT}"
OPT_NAME=’LISTATTR’
OPT_ARG_NEEDED=YES
;;
’or’ | \
’ord’ | \
’orde’ | \
’order’ | \
’orderi’ | \
’orderin’ | \
’ordering’ )
if [ -n "${GETDEFS_ORDERING}" ] && ${GETDEFS_ORDERING_set} ; then
echo ’Error: duplicate ORDERING option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_ORDERING_set=true
OPT_NAME=’ORDERING’
eval GETDEFS_ORDERING${OPT_ELEMENT}=true
export GETDEFS_ORDERING${OPT_ELEMENT}
OPT_ARG_NEEDED=OK
;;
’no-’ | \
’no-o’ | \
’no-or’ | \
’no-ord’ | \
’no-orde’ | \
’no-order’ | \
’no-orderi’ | \
’no-orderin’ | \
’no-ordering’ )
if [ -n "${GETDEFS_ORDERING}" ] && ${GETDEFS_ORDERING_set} ; then
echo ’Error: duplicate ORDERING option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
Chapter 7: Automated Option Processing 168
fi >&2
GETDEFS_ORDERING_set=true
GETDEFS_ORDERING=’no’
export GETDEFS_ORDERING
OPT_NAME=’ORDERING’
OPT_ARG_NEEDED=NO
;;
’fi’ | \
’fir’ | \
’firs’ | \
’first’ | \
’first-’ | \
’first-i’ | \
’first-in’ | \
’first-ind’ | \
’first-inde’ | \
’first-index’ )
if [ -n "${GETDEFS_FIRST_INDEX}" ] && ${GETDEFS_FIRST_INDEX_set} ; then
echo ’Error: duplicate FIRST_INDEX option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_FIRST_INDEX_set=true
OPT_NAME=’FIRST_INDEX’
OPT_ARG_NEEDED=YES
;;
’fi’ | \
’fil’ | \
’file’ | \
’filel’ | \
’fileli’ | \
’filelis’ | \
’filelist’ )
if [ -n "${GETDEFS_FILELIST}" ] && ${GETDEFS_FILELIST_set} ; then
echo ’Error: duplicate FILELIST option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_FILELIST_set=true
OPT_NAME=’FILELIST’
eval GETDEFS_FILELIST${OPT_ELEMENT}=true
export GETDEFS_FILELIST${OPT_ELEMENT}
OPT_ARG_NEEDED=OK
;;
Chapter 7: Automated Option Processing 169
’as’ | \
’ass’ | \
’assi’ | \
’assig’ | \
’assign’ )
GETDEFS_ASSIGN_CT=‘expr ${GETDEFS_ASSIGN_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_ASSIGN_CT}"
OPT_NAME=’ASSIGN’
OPT_ARG_NEEDED=YES
;;
’co’ | \
’com’ | \
’comm’ | \
’commo’ | \
’common’ | \
’common-’ | \
’common-a’ | \
’common-as’ | \
’common-ass’ | \
’common-assi’ | \
’common-assig’ | \
’common-assign’ )
GETDEFS_COMMON_ASSIGN_CT=‘expr ${GETDEFS_COMMON_ASSIGN_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_COMMON_ASSIGN_CT}"
OPT_NAME=’COMMON_ASSIGN’
OPT_ARG_NEEDED=YES
;;
’co’ | \
’cop’ | \
’copy’ )
GETDEFS_COPY_CT=‘expr ${GETDEFS_COPY_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_COPY_CT}"
OPT_NAME=’COPY’
OPT_ARG_NEEDED=YES
;;
’sr’ | \
’src’ | \
’srcf’ | \
’srcfi’ | \
’srcfil’ | \
’srcfile’ )
if [ -n "${GETDEFS_SRCFILE}" ] && ${GETDEFS_SRCFILE_set} ; then
echo ’Error: duplicate SRCFILE option’
echo "$GETDEFS_USAGE_TEXT"
Chapter 7: Automated Option Processing 170
exit 1
fi >&2
GETDEFS_SRCFILE_set=true
OPT_NAME=’SRCFILE’
eval GETDEFS_SRCFILE${OPT_ELEMENT}=true
export GETDEFS_SRCFILE${OPT_ELEMENT}
OPT_ARG_NEEDED=OK
;;
’li’ | \
’lin’ | \
’line’ | \
’linen’ | \
’linenu’ | \
’linenum’ )
if [ -n "${GETDEFS_LINENUM}" ] && ${GETDEFS_LINENUM_set} ; then
echo ’Error: duplicate LINENUM option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_LINENUM_set=true
OPT_NAME=’LINENUM’
eval GETDEFS_LINENUM${OPT_ELEMENT}=true
export GETDEFS_LINENUM${OPT_ELEMENT}
OPT_ARG_NEEDED=OK
;;
’in’ | \
’inp’ | \
’inpu’ | \
’input’ )
GETDEFS_INPUT_CT=‘expr ${GETDEFS_INPUT_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_INPUT_CT}"
OPT_NAME=’INPUT’
OPT_ARG_NEEDED=YES
;;
’ou’ | \
’out’ | \
’outp’ | \
’outpu’ | \
’output’ )
if [ -n "${GETDEFS_OUTPUT}" ] && ${GETDEFS_OUTPUT_set} ; then
echo ’Error: duplicate OUTPUT option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
Chapter 7: Automated Option Processing 171
GETDEFS_OUTPUT_set=true
OPT_NAME=’OUTPUT’
OPT_ARG_NEEDED=YES
;;
’au’ | \
’aut’ | \
’auto’ | \
’autog’ | \
’autoge’ | \
’autogen’ )
if [ -n "${GETDEFS_AUTOGEN}" ] && ${GETDEFS_AUTOGEN_set} ; then
echo ’Error: duplicate AUTOGEN option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_AUTOGEN_set=true
OPT_NAME=’AUTOGEN’
eval GETDEFS_AUTOGEN${OPT_ELEMENT}=true
export GETDEFS_AUTOGEN${OPT_ELEMENT}
OPT_ARG_NEEDED=OK
;;
’no-’ | \
’no-a’ | \
’no-au’ | \
’no-aut’ | \
’no-auto’ | \
’no-autog’ | \
’no-autoge’ | \
’no-autogen’ )
if [ -n "${GETDEFS_AUTOGEN}" ] && ${GETDEFS_AUTOGEN_set} ; then
echo ’Error: duplicate AUTOGEN option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_AUTOGEN_set=true
GETDEFS_AUTOGEN=’no’
export GETDEFS_AUTOGEN
OPT_NAME=’AUTOGEN’
OPT_ARG_NEEDED=NO
;;
’te’ | \
’tem’ | \
’temp’ | \
’templ’ | \
Chapter 7: Automated Option Processing 172
’templa’ | \
’templat’ | \
’template’ )
if [ -n "${GETDEFS_TEMPLATE}" ] && ${GETDEFS_TEMPLATE_set} ; then
echo ’Error: duplicate TEMPLATE option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_TEMPLATE_set=true
OPT_NAME=’TEMPLATE’
OPT_ARG_NEEDED=YES
;;
’ag’ | \
’aga’ | \
’agar’ | \
’agarg’ )
GETDEFS_AGARG_CT=‘expr ${GETDEFS_AGARG_CT} + 1‘
OPT_ELEMENT="_${GETDEFS_AGARG_CT}"
OPT_NAME=’AGARG’
OPT_ARG_NEEDED=YES
;;
’ba’ | \
’bas’ | \
’base’ | \
’base-’ | \
’base-n’ | \
’base-na’ | \
’base-nam’ | \
’base-name’ )
if [ -n "${GETDEFS_BASE_NAME}" ] && ${GETDEFS_BASE_NAME_set} ; then
echo ’Error: duplicate BASE_NAME option’
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
GETDEFS_BASE_NAME_set=true
OPT_NAME=’BASE_NAME’
OPT_ARG_NEEDED=YES
;;
’ve’ | \
’ver’ | \
’vers’ | \
’versi’ | \
’versio’ | \
’version’ )
Chapter 7: Automated Option Processing 173
echo "$GETDEFS_LONGUSAGE_TEXT"
exit 0
;;
’he’ | \
’hel’ | \
’help’ )
echo "$GETDEFS_LONGUSAGE_TEXT"
exit 0
;;
’mo’ | \
’mor’ | \
’more’ | \
’more-’ | \
’more-h’ | \
’more-he’ | \
’more-hel’ | \
’more-help’ )
echo "$GETDEFS_LONGUSAGE_TEXT" | ${PAGER-more}
exit 0
;;
’sa’ | \
’sav’ | \
’save’ | \
’save-’ | \
’save-o’ | \
’save-op’ | \
’save-opt’ | \
’save-opts’ )
echo ’Warning: Cannot save options files’ >&2
OPT_ARG_NEEDED=OK
;;
’lo’ | \
’loa’ | \
’load’ | \
’load-’ | \
’load-o’ | \
’load-op’ | \
’load-opt’ | \
’load-opts’ )
echo ’Warning: Cannot load options files’ >&2
OPT_ARG_NEEDED=YES
;;
Chapter 7: Automated Option Processing 174
’no-’ | \
’no-l’ | \
’no-lo’ | \
’no-loa’ | \
’no-load’ | \
’no-load-’ | \
’no-load-o’ | \
’no-load-op’ | \
’no-load-opt’ | \
’no-load-opts’ )
echo ’Warning: Cannot suppress the loading of options files’ >&2
OPT_ARG_NEEDED=NO
;;
* )
echo Unknown option: "${OPT_CODE}" >&2
echo "$GETDEFS_USAGE_TEXT" >&2
exit 1
;;
esac
case "${OPT_ARG_NEEDED}" in
NO )
OPT_ARG_VAL=’’
;;
YES )
if [ -z "${OPT_ARG_VAL}" ]
then
if [ $# -eq 0 ]
then
echo No argument provided for ${OPT_NAME} option
echo "$GETDEFS_USAGE_TEXT"
exit 1
fi >&2
OPT_ARG_VAL=${OPT_ARG}
shift
OPT_ARG=$1
fi
;;
OK )
if [ -z "${OPT_ARG_VAL}" ] && [ $# -gt 0 ]
then
case "${OPT_ARG}" in -* ) ;; * )
OPT_ARG_VAL=${OPT_ARG}
shift
OPT_ARG=$1 ;; esac
fi
;;
Chapter 7: Automated Option Processing 175
esac
if [ -n "${OPT_ARG_VAL}" ]
then
eval GETDEFS_${OPT_NAME}${OPT_ELEMENT}="’${OPT_ARG_VAL}’"
export GETDEFS_${OPT_NAME}${OPT_ELEMENT}
fi
done
OPTION_COUNT=‘expr $ARG_COUNT - $#‘
OPERAND_COUNT=$#
unset OPT_PROCESS || :
unset OPT_ELEMENT || :
unset OPT_ARG || :
unset OPT_ARG_NEEDED || :
unset OPT_NAME || :
unset OPT_CODE || :
unset OPT_ARG_VAL || :
# # # # # # # # # #
#
# END OF AUTOMATED OPTION PROCESSING
#
# # # # # # # # # # -- do not modify this marker --
Man pages may be formatted as either traditional man pages or using mdoc formatting.
The format is selected by selecting the appropriate template.
name The name of the procedure the library user may call.
what A brief sentence describing what the procedure does.
doc A detailed description of what the procedure does. It may ramble
on for as long as necessary to properly describe it.
err A short description of how errors are handled.
ret type The data type returned by the procedure. Omit this for void
procedures.
ret desc Describe what the returned value is, if needed.
private If specified, the function will not be documented. This is used, for
example, to produce external declarations for functions that are not
available for public use, but are used in the generated text.
arg This is a compound attribute that contains:
/*=--subblock=arg=arg_type,arg_name,arg_desc =*/
/*=*
* library: opts
* header: your-opts.h
=*/
/*=export_func optionProcess
*
* what: this is the main option processing routine
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + int + argc + program arg count +
* arg: + char** + argv + program arg vector +
* ret_type: int
* ret_desc: the count of the arguments processed
*
* doc: This is what it does.
* err: When it can’t, it does this.
=*/
Note the subblock and library comments. subblock is an embedded getdefs option (see
[getdefs subblock], page 201) that tells it how to parse the arg attribute. The library and
header entries are global definitions that apply to all the documented functions.
Chapter 7: Automated Option Processing 179
files from various directories to compile that program, you will need to specify
those directories with -Idirpath text in the CFLAGS. Some experimentation
may be necessary in that case.
NOTE: the -Idirpath text is only needed if your option callback functions
include code that require additional #include directives.
‘LDFLAGS’ Any special flags required to link. The flags from autoopts-config ldflags
will be included automatically. This is required only if additional link flags for
the help text emission program might be needed.
‘CC’ This is needed only if cc cannot be found in $PATH (or it is not the one you
want).
To use this, set the exported environment variables and specify getopt as the default
template in your option definitions file (see Section 2.1 [Identification], page 7). You will
have four new files. Assuming your definitions were in a file named myprog-opts.def and
your program name was specified as progname, the resulting files would be created: myprog-
opts.h, myprog-opts.c, getopt-progname.h and getopt-progname.c. You must compile
and link both .c files into your program. If there are link failures, then you are using
AutoOpts features that require the libopts library. You must remove these features, See
Section 7.15.1 [getopt limitations], page 179.
These generated files depend upon configure defines to work correctly. Therefore, you
must specify a config-header attribute (see Section 7.5.1.3 [programming attributes],
page 93) and ensure it has #defines for either HAVE_STDINT_H or HAVE_INTTYPES_H; either
HAVE_SYS_LIMITS_H or HAVE_LIMITS_H; and HAVE_SYSEXITS_H, if the sysexits.h header
is available. The required header files for these defines are, respectively, the /usr/include
files named:
• stdint.h
• inttypes.h
• sys/limits.h
• limits.h
• sysexits.h
The following header files must also exist on the build platform:
• sys/types.h
• stdio.h
• string.h
• unistd.h – or, for getopt long:
• getopt.h
library will always check for this compiled with NLS flag, so libopts does not need to be
specially compiled. The strings returned by the translation function will be strdup(3)-ed
and kept. They will not be re-translated, even if the locale changes, but they will also not
be dependent upon reused or unmappable memory.
You should also ensure that the ATTRIBUTE_FORMAT_ARG() gets #define-ed to something
useful. There is an autoconf macro named AG_COMPILE_FORMAT_ARG in ag_macros.m4 that
will set it appropriately for you. If you do not do this, then translated formatting strings
may trigger GCC compiler warnings.
To internationalize option processing, you should first internationalize your program.
Then, the option processing strings can be added to your translation text by process-
ing the AutoOpts-generated my-opts.c file and adding the distributed po/usage-txt.pot
file. (Also by extracting the strings yourself from the usage-txt.h file.) When you call
optionProcess, all of the user visible AutoOpts strings will be passed through the local-
ization procedure established with the _() preprocessing macro.
All of this is dis-abled if you specify the global attribute no-xlate to anything.
A B
addtogroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 before-guile-boot . . . . . . . . . . . . . . . . . . . . . . . . . . 100
allow-errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
arg-default . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
arg-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 C
arg-optional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 call-proc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
arg-range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 cmd-section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
arg-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 comment-char . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
argument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 config-header . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91, 94
author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 copyright . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Chapter 7: Automated Option Processing 183
D immediate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
default . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 interleaved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
deprecated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
descrip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 K
detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99, 118
die-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
disable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
disable-load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
disable-save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 L
doc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 lib-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
doc-section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
doc-sub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 load-opts-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
doc-sub-cmd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 long-opts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 97, 110
M
E main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
eaddr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 main-fini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 main-init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 main-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
environrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
exit-desc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 more-help-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
exit-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 must-set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
explain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 MYHANDLER-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
extra-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
extract-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 N
name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
no-command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
F no-libopts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
file-exists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 no-misuse-usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
file-mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 no-preset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
flag-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 no-return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
flag-proc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 no-xlate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
full-usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
O
G omitted-usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
gnu-usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91, 100 open-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
guard-option-names . . . . . . . . . . . . . . . . . . . . . . . . . . 95 option-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
guile-main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 option-format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
option-info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
opts-ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
H owner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
handler-frees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
handler-proc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 P
handler-type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
help-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
homerc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
prefix-enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
preserve-case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
I prog-desc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
prog-group. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
ifdef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
prog-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ifndef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
prog-title. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
immed-disable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Chapter 7: Automated Option Processing 184
R translators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
rcfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
reorder-args. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96, 100
reset-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 U
resettable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
unstack-arg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92, 100
S usage-message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
usage-opt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84, 92
save-opts-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 usage-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
scaled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
settable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
short-usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 V
stack-arg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
vendor-opt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
T version-proc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 version-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Chapter 8: Add-on packages for AutoGen 185
8.4.1 Enumerations
str2enum.tpl
Produce an enumeration for a list of input “cmd”s (names). Optionally, produce func-
tions to:
• convert a string to an enumeration
• convert an enumeration value into a string
• invoke a function based on the first token name found in a string
The header file produced will contain the enumeration and declarations for the optional
procedures. The code (.c) file will contain these optional procedures, but can be omitted
if the no-code attribute is specified.
The following attributes are recognized with the str2enum template:
‘cmd’ You must provide a series of these attributes: they specify the list of names
used in the enumeration. Specific values for the names may be specified by
specifying a numeric index for these attributes. e.g. cmd[5] = mumble; will
cause
FOO_CMD_MUMBLE = 5
to be inserted into the enumeration. Do not specify a value of “invalid”,
unless you specify the invalid-name attribute. (In that case, do not specify a
cmd value that matches the invalid-name value.)
‘prefix’ This specifies the first segment of each enumeration name. If not specified,
the first segment of the enumeration definition file name will be used. e.g.
foo-bar.def will default to a FOO prefix.
‘type’ Normally, there is a second constant segment following the prefix. If not spec-
ified, it will be CMD, so if both prefix and type were to default from foo-
bar.def, you will have enumeration values prefixed with FOO_CMD_. If specified
as the empty string, there will be no “type” component to the name and the
default constant prefix will thus be FOO_.
‘base-name’
This specifies the base name of the output files, enumeration type and the
translation functions. The default is to use the basename(3) of the definition
file. e.g. foo-bar.def results in a base-name of foo-bar.
Chapter 8: Add-on packages for AutoGen 187
‘invalid-val’
The default invalid value is zero. Sometimes, it is useful for zero to be valid. If
so, you can specify ~0 or the empty string to be invalid. The empty string will
cause the enumeration count (maximum value plus 1) to be the invalid value.
‘invalid-name’
By default, the invalid value is emitted into the enumeration as FOO_INVALID_
CMD. Specifying this attribute will replace INVALID with whatever you place in
this attribute.
‘add-on-text’
Additional text to insert into the code or header file.
‘ao-file’ Which file to insert the text into. There are four choices, only two
of which are relevant for the str2enum template: “enum-header”,
“enum-code”, “mask-header” or “mask-code”.
‘ao-text’ The text to insert.
‘partial’ Normally, a name must fully match to be found successfully. This attribute
causes the generated code to look for partial matches if the full match gperf
function fails. Partial matches must be at least two characters long.
‘undef-str’
by default, the display string for an undefined value is “* UNDEFINED *”. Use
this to change that.
‘equate’ A series of punctuation characters considered equivalent. Typically, “-_” but
sometimes (Tandem) “-_^”. Do not use ’#’ in the list of characters.
‘dispatch’
A lookup procedure will call a dispatch function for the procedure named after
the keyword identified at the start of a string. Other than as specially noted
below, for every named “cmd”, must have a handling function, plus another
function to handle errors, with “invalid” (or the invalid-name value) as the
cmd name. Multiple dispatch definitions will produce multiple dispatching
functions, each with (potentially) unique argument lists and return types.
You may also use add-on-text to “#define” one function to another, thus
allowing one function to handle multiple keywords or commands. The d-nam
and d-ret attributes are required. The d-arg, d-omit and d-only attributes
are optional:
‘d-nam’ This must be a printf format string with one formatting element:
%s. The %s will be replaced by each cmd name. The %s will be
stripped and the result will be combined with the base name to
construct the dispatch procedure name.
‘d-ret’ The return type of the dispatched function, even if “void”.
‘d-arg’ If there are additional arguments that are to be passed through to
the dispatched function, specify this as though it were part of the
procedure header. (It will be glued into the dispatching function
as is and sedded into what is needed for the dispatched function.)
‘d-omit’ Instead of providing handling functions for all of the cmd names,
the invalid function will be called for omitted command codes.
‘d-only’ You need only provide functions for the names listed by d-only,
plus the “invalid” name. All other command values will trigger
calls to the invalid handling function. Note that the invalid call can
distinguish from a command that could not be found by examining
the value of its first (id) argument.
The handler functions will have the command enumeration as its first first
argument, a pointer to a constant string that will be the character after the
parsed command (keyword) name, plus any d-arg arguments that follow that.
As an example, a file samp-chk.def containing this:
AutoGen Definitions str2enum;
cmd = one, two; invalid-name = oops;
dispatch = { d-nam = ’hdl_%s_cmd’; d-ret = void; };
will produce a header containing:
Chapter 8: Add-on packages for AutoGen 189
typedef enum {
SAMP_OOPS_CMD = 0,
SAMP_CMD_ONE = 1,
SAMP_CMD_TWO = 2,
SAMP_COUNT_CMD
} samp_chk_enum_t;
extern samp_chk_enum_t
find_samp_chk_cmd(char const * str, size_t len);
typedef void(samp_chk_handler_t)(
samp_chk_enum_t id, char const * str);
samp_chk_handler_t
hdl_oops_cmd, hdl_one_cmd, hdl_two_cmd;
extern void
disp_samp_chk(char * str, size_t len);
no-code and no-name are honored. dispatch is not. The lookup function will examine
each token in an input string, determine which bit is specified and add it into a result.
The names may be prefixed with a hyphen (-) or tilde (~) to remove the bit(s) from the
cumulative result. If the string begins with a plus (+), hyphen or tilde, a “base value”
parameter is used for the starting mask, otherwise the conversion starts with zero.
Beyond the enumeration attributes that are used (or ignored), the str2mask template
accepts a mask attribute. It takes a few “subattributes”:
‘m-name’ a special name for a sub-collection of the mask bits
‘m-bit’ The name of each previously defined bit(s). If the desired previously defined
value is a mask, that m-name must be suffixed with “-mask”.
‘m-invert’
When all done collecting the bits, x-or the value with the mask of all the bits
in the collection.
A mask of all bits in the collection is always generated.
Chapter 8: Add-on packages for AutoGen 191
tab-width option.
This is the “tab width” option. This option takes a number argument num. If an indentation
string contains tabs, then this value is used to compute the ending column of the prefix
string.
spread option.
This is the “maximum spread added to column width” option. This option takes a number
argument num. Use this option to specify exactly how many characters may be added to
each column. It allows you to prevent columns from becoming too far apart. Without this
option, columns will attempt to widen columns to fill the full width.
fill option.
This is the “fill lines with input” option.
This option has some usage constraints. It:
• must not appear in combination with any of the following options: spread, col width,
by columns.
Chapter 8: Add-on packages for AutoGen 194
Instead of columnizing the input text, fill the output lines with the input lines. Blank
lines on input will cause a blank line in the output, unless the output is sorted. With sorted
output, blank lines are ignored.
first-indent option.
This is the “first line prefix” option. This option takes a string argument l-pfx.
This option has some usage constraints. It:
• must appear in combination with the following options: indent.
If a number, then this many spaces will be inserted at the start of the first line. Other-
wise, it is a line prefix that will be inserted at the start of that line. If its length exceeds
"indent", then it will be emitted on a line by itself, suffixed by any line separation string.
For example:
$ columns --first=’#define TABLE’ -c 2 -I4 --line=’ \’ <<_EOF_
one
two
three
four
_EOF_
#define TABLE \
one two \
three four
line-separation option.
This is the “string at end of all lines but last” option. This option takes a string argument
sep-str. Use this option if, for example, you wish a backslash to appear at the end of
every line, except the last.
Chapter 8: Add-on packages for AutoGen 195
ending option.
This is the “string at end of last line” option. This option takes a string argument end-str.
This option puts the specified string at the end of the output.
by-columns option.
This is the “print entries in column order” option. Normally, the entries are printed out in
order by rows and then columns. This option will cause the entries to be ordered within
columns. The final column, instead of the final row, may be shorter than the others.
Multiple programs may also share the same initialization file. Common options are
collected at the top, followed by program specific segments. The segments are separated by
lines like:
[COLUMNS]
or by
<?program columns>
Do not mix these styles within one configuration file.
Compound values and carefully constructed string values may also be specified using
XML syntax:
<option-name>
<sub-opt>...<...>...</sub-opt>
</option-name>
yielding an option-name.sub-opt string value of
"...<...>..."
AutoOpts does not track suboptions. You simply note that it is a hierarchicly valued
option. AutoOpts does provide a means for searching the associated name/value pair list
(see: optionFindValue).
The command line options relating to configuration and/or usage help are:
version (-v)
Print the program version to standard out, optionally with licensing information, then exit
0. The optional argument specifies how much licensing detail to provide. The default is to
print just the version. The licensing infomation may be selected with an option argument.
Only the first letter of the argument is examined:
‘version’ Only print the version. This is the default.
‘copyright’
Name the copyright usage licensing terms.
‘verbose’ Print the full copyright usage licensing terms.
Specify which definitions are of interest and what to say about them:
defs-to-get option.
This is the “regexp to look for after the "/*="” option. This option takes a string argu-
ment reg-ex. If you want definitions only from a particular category, or even with names
matching particular patterns, then specify this regular expression for the text that must
follow the /*=.
Chapter 8: Add-on packages for AutoGen 201
subblock option.
This is the “subblock definition names” option. This option takes a string argument sub-
def.
This option has some usage constraints. It:
• may appear an unlimited number of times.
This option is used to create shorthand entries for nested definitions. For example, with:
using subblock thus
--subblock=arg=argname,type,null
and defining an arg thus
arg: this, char *
will then expand to:
arg = { argname = this; type = "char *"; };
The "this, char *" string is separated at the commas, with the white space removed.
You may use characters other than commas by starting the value string with a punctuation
character other than a single or double quote character. You may also omit intermediate
values by placing the commas next to each other with no intervening white space. For
example, "+mumble++yes+" will expand to:
arg = { argname = mumble; null = "yes"; };.
listattr option.
This is the “attribute with list of values” option. This option takes a string argument def.
This option has some usage constraints. It:
• may appear an unlimited number of times.
This option is used to create shorthand entries for definitions that generally appear
several times. That is, they tend to be a list of values. For example, with:
listattr=foo defined, the text:
foo: this, is, a, multi-list will then expand to:
foo = ’this’, ’is’, ’a’, ’multi-list’;
The texts are separated by the commas, with the white space removed. You may use
characters other than commas by starting the value string with a punctuation character
other than a single or double quote character.
ordering option.
This is the “alphabetize or use named file” option. This option takes an optional string
argument file-name.
This option has some usage constraints. It:
• can be disabled with –no-ordering.
Chapter 8: Add-on packages for AutoGen 202
• It is enabled by default.
By default, ordering is alphabetical by the entry name. Use, no-ordering if order
is unimportant. Use ordering with no argument to order without case sensitivity. Use
ordering=<file-name> if chronological order is important. getdefs will maintain the text
content of file-name. file-name need not exist.
first-index option.
This is the “the first index to apply to groups” option. This option takes a number argument
first-index. By default, the first occurrence of a named definition will have an index of
zero. Sometimes, that needs to be a reserved value. Provide this option to specify a different
starting point.
filelist option.
This is the “insert source file names into defs” option. This option takes an optional string
argument file. Inserts the name of each input file into the output definitions. If no
argument is supplied, the format will be:
infile = ’%s’;
If an argument is supplied, that string will be used for the entry name instead of infile.
assign option.
This is the “global assignments” option. This option takes a string argument ag-def.
This option has some usage constraints. It:
• may appear an unlimited number of times.
The argument to each copy of this option will be inserted into the output definitions,
with only a semicolon attached.
common-assign option.
This is the “assignments common to all blocks” option. This option takes a string argument
ag-def.
This option has some usage constraints. It:
• may appear an unlimited number of times.
The argument to each copy of this option will be inserted into each output definition,
with only a semicolon attached.
copy option.
This is the “file(s) to copy into definitions” option. This option takes a string argument
file.
This option has some usage constraints. It:
Chapter 8: Add-on packages for AutoGen 203
srcfile option.
This is the “insert source file name into each def” option. This option takes an optional
string argument file. Inserts the name of the input file where a definition was found into
the output definition. If no argument is supplied, the format will be:
srcfile = ’%s’;
If an argument is supplied, that string will be used for the entry name instead of srcfile.
linenum option.
This is the “insert source line number into each def” option. This option takes an optional
string argument def-name. Inserts the line number in the input file where a definition was
found into the output definition. If no argument is supplied, the format will be:
linenum = ’%s’;
If an argument is supplied, that string will be used for the entry name instead of linenum.
input option.
This is the “input file to search for defs” option. This option takes a string argument
src-file.
This option has some usage constraints. It:
• may appear an unlimited number of times.
All files that are to be searched for definitions must be named on the command line or
read from stdin. If there is only one input option and it is the string, "-", then the input
file list is read from stdin. If a command line argument is not an option name and does
not contain an assignment operator (=), then it defaults to being an input file name. At
least one input file must be specified.
output option.
This is the “output file to open” option. This option takes a string argument file.
This option has some usage constraints. It:
• is a member of the autogen class of options.
If you are not sending the output to an AutoGen process, you may name an output file
instead.
Chapter 8: Add-on packages for AutoGen 204
autogen option.
This is the “invoke autogen with defs” option. This option takes an optional string argument
ag-cmd.
This option has some usage constraints. It:
• can be disabled with –no-autogen.
• It is enabled by default.
• is a member of the autogen class of options.
This is the default output mode. Specifying no-autogen is equivalent to output=-. If
you supply an argument to this option, that program will be started as if it were AutoGen
and its standard in will be set to the output definitions of this program.
template option.
This is the “template name” option. This option takes a string argument file. Specifies
the template name to be used for generating the final output.
agarg option.
This is the “autogen argument” option. This option takes a string argument ag-opt.
This option has some usage constraints. It:
• may appear an unlimited number of times.
• must not appear in combination with any of the following options: output.
This is a pass-through argument. It allows you to specify any arbitrary argument to be
passed to AutoGen.
base-name option.
This is the “base name for output file(s)” option. This option takes a string argument name.
This option has some usage constraints. It:
• must not appear in combination with any of the following options: output.
When output is going to AutoGen, a base name must either be supplied or derived.
If this option is not supplied, then it is taken from the template option. If that is not
provided either, then it is set to the base name of the current directory.
Multiple programs may also share the same initialization file. Common options are
collected at the top, followed by program specific segments. The segments are separated by
lines like:
[GETDEFS]
or by
<?program getdefs>
Do not mix these styles within one configuration file.
Compound values and carefully constructed string values may also be specified using
XML syntax:
<option-name>
<sub-opt>...<...>...</sub-opt>
</option-name>
yielding an option-name.sub-opt string value of
"...<...>..."
AutoOpts does not track suboptions. You simply note that it is a hierarchicly valued
option. AutoOpts does provide a means for searching the associated name/value pair list
(see: optionFindValue).
The command line options relating to configuration and/or usage help are:
version
Print the program version to standard out, optionally with licensing information, then exit
0. The optional argument specifies how much licensing detail to provide. The default is to
print just the version. The licensing infomation may be selected with an option argument.
Only the first letter of the argument is examined:
‘version’ Only print the version. This is the default.
‘copyright’
Name the copyright usage licensing terms.
‘verbose’ Print the full copyright usage licensing terms.
definitions option.
This is the “read definitions from file” option. This option takes a string argument FILE.
Pass-through AutoGen argument
shell option.
This is the “name or path name of shell to use” option. This option takes a string argument
shell. Pass-through AutoGen argument
equate option.
This is the “characters considered equivalent” option. This option takes a string argument
char-list. Pass-through AutoGen argument
source-time option.
This is the “set mod times to latest source” option. Pass-through AutoGen argument
writable option.
This is the “allow output files to be writable” option.
This option has some usage constraints. It:
• can be disabled with –not-writable.
Pass-through AutoGen argument
loop-limit option.
This is the “limit on increment loops” option. This option takes a number argument lim.
Pass-through AutoGen argument
Chapter 8: Add-on packages for AutoGen 211
trace option.
This is the “tracing level of detail” option. This option takes a keyword argument level.
This option has some usage constraints. It:
• This option takes a keyword as its argument. The argument sets an enumeration value
that can be tested by comparing the option value macro (OPT VALUE TRACE). The
available keywords are:
nothing debug-message server-shell
templates block-macros expressions
everything
or their numeric equivalent.
Pass-through AutoGen argument
trace-out option.
This is the “tracing output file or filter” option. This option takes a string argument file.
Pass-through AutoGen argument
show-defs option.
This is the “show the definition tree” option. Pass-through AutoGen argument
used-defines option.
This is the “show the definitions used” option. Pass-through AutoGen argument
Concept Index
F
features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
L
finite state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 let. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
flags-cant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 let directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
flags-must . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 library attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
fOptState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
for loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
futures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 line directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
looping, for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
G
getdefs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 M
getdefs help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 m4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
getdefs-agarg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 macdef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
getdefs-assign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 macdef directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
getdefs-autogen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 macro syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
getdefs-base-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 macro, pseudo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
getdefs-common-assign . . . . . . . . . . . . . . . . . . . . . . . 202 main procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
getdefs-copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 misuse-usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
getdefs-defs-to-get . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
getdefs-filelist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
getdefs-first-index . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 N
getdefs-input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 named option mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
getdefs-linenum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Naming Conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
getdefs-listattr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 naming values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
getdefs-ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 native macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
getdefs-output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 no-misuse-usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
getdefs-srcfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
getdefs-subblock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
getdefs-template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 O
getopt long. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 optActualIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
gnu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 optActualValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
optIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
H Option Argument Handling . . . . . . . . . . . . . . . . . . . 115
here-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Option Arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
option attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Option Conflict Attributes . . . . . . . . . . . . . . . . . . . . 108
I Option Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ident . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 option descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
ident directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 option directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Option Processing Data . . . . . . . . . . . . . . . . . . . . . . 125
if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 optOccCt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
if directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 optValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
if test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
ifdef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ifdef directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 P
ifndef. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ifndef directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 pragma directive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
immediate action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 predefines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 program attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
include directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 pseudo macro. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Concept Index 217
W
R while test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
rcfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147, 154
Redirecting Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
remote procedure call . . . . . . . . . . . . . . . . . . . . . . . . . 185 X
Required Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 105 XDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
RPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 XML to AutoGen Definiton Converter . . . . . . . . 207
rpcgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 xml2ag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
xml2ag help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
xml2ag-base-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
S xml2ag-core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
sample rcfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 xml2ag-define . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 xml2ag-definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
shell directive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 xml2ag-equate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
shell options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146, 158 xml2ag-lib-template . . . . . . . . . . . . . . . . . . . . . . . . . . 210
shell-generated string . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 xml2ag-loop-limit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Signal Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 xml2ag-make-dep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
xml2ag-no-fmemopen . . . . . . . . . . . . . . . . . . . . . . . . . 210
simple definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
xml2ag-output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
standard options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
xml2ag-override-tpl . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
string, double quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
xml2ag-select-suffix . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
string, shell output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
xml2ag-shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
string, single quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
xml2ag-show-defs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
xml2ag-skip-suffix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
T xml2ag-source-time . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
xml2ag-templ-dirs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
template file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7, 21 xml2ag-timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
The Automated Program Generator . . . . . . . . . . . 67 xml2ag-trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
xml2ag-trace-out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
xml2ag-undefine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
U xml2ag-used-defines . . . . . . . . . . . . . . . . . . . . . . . . . . 211
undef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 xml2ag-writable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Function Index 218
Function Index
* def-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
*= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 def-file-line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
*=* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 DEFINE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
*== . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 DESC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
*==* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 DISABLE_OPT_name. . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
*~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 dne . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
*~* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
*~~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 E
*~~* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
ELIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
= emit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
=.............................................. 50 emit-string-table. . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
=* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 ENABLED_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
== . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 ENDDEF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
==* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 ENDFOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
ENDIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
ENDWHILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
~ error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
~.............................................. 50 error-source-line. . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
~* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 ERRSKIP_OPTERR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
~~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 ERRSTOP_OPTERR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
~~* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 ESAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
exist? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
EXPR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
A extract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
ag-fprintf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
ag-function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
agpl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
F
ao_string_tokenize . . . . . . . . . . . . . . . . . . . . . . . . . 133 find-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
autogen-version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 first-for?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
FOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
for-by . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
B for-from . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
for-index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
base-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
BREAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 for-sep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
bsd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 for-to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
format-arg-count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
found-for?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
C fprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
c-file-line-fmt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
c-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
CASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
G
chdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
CLEAR_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 get-c-name. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
COMMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 get-down-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
configFileLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 get-up-name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
CONTINUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 gperf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 gperf-code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
COUNT_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 gpl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
D H
DEBUG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 HAVE_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Function Index 219
M R
raw-shell-str . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
make-gperf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 RESTART_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
make-header-guard. . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 RETURN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
make-tmp-dir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
makefile-script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
match-value? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 S
max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
max-file-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 set-option. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 set-writable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
mk-gettextable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 SET_OPT_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
shell-str . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
O shellf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
OPT_ARG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 sprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
OPT_NO_XLAT_CFG_NAMES . . . . . . . . . . . . . . . . . . . . . . 128 stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
OPT_NO_XLAT_OPT_NAMES . . . . . . . . . . . . . . . . . . . . . . 128 stack-join. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
OPT_VALUE_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 STACKCT_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
OPT_XLAT_CFG_NAMES . . . . . . . . . . . . . . . . . . . . . . . . . 128 STACKLST_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
OPT_XLAT_OPT_NAMES . . . . . . . . . . . . . . . . . . . . . . . . . 128 START_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
OPTION_CT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 STATE_OPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
optionFileLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 strequate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Function Index 220
Table of Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 The Purpose of AutoGen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 csh/zsh caveat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 A User’s Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Definitions File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 The Identification Definition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Named Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Definition List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2 Double Quote String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.3 Single Quote String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.4 An Unquoted String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.5 Shell Output String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.6 Scheme Result String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.7 A Here String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.8 Concatenated Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 Assigning an Index to a Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Dynamic Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Controlling What Gets Processed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.6 Pre-defined Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.7 Commenting Your Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.8 What it all looks like. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.9 Finite State Machine Grammar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.10 Alternate Definition Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3 Template File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1 Format of the Pseudo Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.2 Naming a value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3 Macro Expression Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3.1 Apply Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3.2 Basic Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4 AutoGen Scheme Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.1 ag-fprintf - format to autogen stream . . . . . . . . . . . . . . . . . . 26
3.4.2 ag-function? - test for function . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.3 base-name - base output name . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.4 chdir - Change current directory . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.5 count - definition count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.4.6 def-file - definitions file name . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.4.7 def-file-line - get a definition file+line number . . . . . . . . 27
ii
5 Invoking autogen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.1 autogen help/usage (--help) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.2 input-select options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.3 out-handling options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
5.4 debug-tpl options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.5 processing options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.6 dep-track options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.7 presetting/configuring autogen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
5.8 autogen exit status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.9 autogen Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79