\input texinfo
@c %**start of header
@setfilename autogen.info
@settitle AutoGen
@setchapternewpage off
@c %**end of header

@ignore
DO NOT EDIT THIS FILE   (autogen.texi)

It has been autogen-ed  Wednesday May 17, 2000 at 11:16:00 AM BST
From the definitions    stdin
and the template file   auto_gen.tpl

Plus bits and pieces gathered from all over the source/build
directories:

        ../src/agFunCase.c
        ../src/agFunEval.c
        ../src/agFunFor.c
        ../src/agFunIf.c
        ../src/agFunOut.c
        ../src/agFunc.c
        ../src/agDirect.c
        ../src/agExpr.c
        ../autoopts/opthead.tpl
        ../src/opts.def
        ../autoopts/autoopts.texi
     ../columns/columns.menu
     ../columns/columns.texi
     ../getdefs/getdefs.menu
     ../getdefs/getdefs.texi
     ../src/autogen.menu
     ../src/autogen.texi

@end ignore

@set EDITION 4.5
@set VERSION 4.5
@set UPDATED May 2000

@dircategory GNU programming tools
@direntry
* AutoGen: (autogen).         The Automated Program Generator
@end direntry

@ifinfo
This file documents  Version @value{VERSION}

AutoGen copyright @copyright{} 1992-1999 Bruce Korb
snprintfv copyright @copyright{} 1999 Gary V. Vaughan

AutoGen is free software.

You may redistribute it and/or modify it under the terms of the
GNU General Public License, as published by the Free Software
Foundation; either version 2, or (at your option) any later version.

AutoGen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with AutoGen.  See the file "COPYING".  If not,
write to:  The Free Software Foundation, Inc.,
           59 Temple Place - Suite 330,
           Boston,  MA  02111-1307, USA.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
@end ignore
@end ifinfo


@titlepage
@title AutoGen - The Automated Program Generator
@subtitle For version @value{VERSION}, @value{UPDATED}
@author Bruce Korb (AutoGen, AutoOpts)
@author @email{autogen@@linuxbox.com}

@author Gary V. Vaughan (snprintfv)
@author @email{gvv@@techie.com}

@page
@vskip 0pt plus 1filll
AutoGen copyright 1992-1999 Bruce Korb
@sp 2
This is the second edition of the GNU AutoGen documentation,
@sp 2
Published by Bruce Korb, 910 Redwood Dr., Santa Cruz, CA  95060

AutoGen is free software.

You may redistribute it and/or modify it under the terms of the
GNU General Public License, as published by the Free Software
Foundation; either version 2, or (at your option) any later version.

AutoGen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with AutoGen.  See the file "COPYING".  If not,
write to:  The Free Software Foundation, Inc.,
           59 Temple Place - Suite 330,
           Boston,  MA  02111-1307, USA.
@end titlepage

@ifinfo
@node Top, Introduction, , (dir)
@top The Automated Program Generator
@comment  node-name,  next,  previous,  up

This file documents AutoGen, a tool designed for generating program
files that contain repetitive text with varied substitutions.
This document is very long because it is intended as a reference
document.  For a quick start example, @xref{Example Usage}.
For a simple example of Automated Option processing, @xref{Quick Start}.

This edition documents version @value{VERSION}, @value{UPDATED}.

@menu
* Introduction::         AutoGen's Purpose
* Definitions File::     AutoGen Definitions File
* Template File::        AutoGen Template
* AutoGen Invocation::   Invoking AutoGen
* Installation::         What Gets Installed Where
* AutoOpts::             Automated Option Processing
* Add-Ons::              Add-on packages for AutoGen
* Future::               Some ideas for the future.
* Concept Index::        General index
* Function Index::       Function index
@end menu

@end ifinfo

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@end ignore
@page
@node Introduction
@chapter Introduction
@cindex 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.

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:

@enumerate
@item
The flag character in the flag string,
@item
code to process the flag when it is encountered,
@item
a global state variable or two, and
@item
a line in the usage text.
@end enumerate

@noindent
You will need more things besides this if you choose to implement long
option names, rc/ini file processing, environment variables and so on.
For a simple example of Automated Option processing, @xref{Quick Start}.

All of this can be done mechanically; with the proper templates and this
program.  In fact, it has already been done and AutoGen itself uses it:
@xref{AutoOpts}.

@menu
* Generalities::         General Ideas
* Example Usage::        A Simple Example
* Testimonial::          A User's Perspective
@end menu

@node Generalities
@section General Ideas
@cindex m4

The idea of this program is to have a text file, a template if
you will, that contains the general text of the desired output file.
That file includes substitution expressions and sections of text that are
replicated under the control of separate definition files.

@cindex design goals

AutoGen was designed with the following features:

@enumerate
@item
The definitions are completely separate from the template.  By
completely isolating the definitions from the template it greatly
increases the flexibility of the template implementation.  A secondary
goal is that a template user only needs to specify those data
that are necessary to describe his application of a template.

@item
Each datum in the definitions is named.  Thus, the definitions can be
rearranged, augmented and become obsolete without it being necessary to
go back and clean up older definition files.  Reduce incompatibilities!

@item
Multiple values for a given name create an array of values.
This array of values is used to control the repetition of
sections of the template.

@item
There are named collections of definitions.  They form a nested hierarchy.
Associated values are collected and associated with a group name.
These associated data are used collectively in sets of substitutions.

@item
The template has special markers to indicate where substitutions are
required, much like the @code{$@{VAR@}} construct in a shell @code{here
doc}.  These markers are not fixed strings.  They are specified at the
start of each template.  Template designers know best what fits into their
syntax and can avoid marker conflicts.

We did this because it is burdensome and difficult to avoid conflicts
using the pure 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.

@item
These same markers are used, in conjunction with enclosed keywords, to
indicate sections of text that are to be skipped and for sections of
text that were to be repeated.  This is a major improvement over using C
preprocessing macros.  With the C preprocessor, you have no way of
selecting output text because it is an @i{un}varying, mechanical
substitution process.

@item
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.
@end enumerate

@node Example Usage
@section A Simple Example
@cindex example, simple
@cindex simple example

Assume you have an enumeration of names and you wish to associate some
string with each name.  Assume also, for the sake of this example,
that it is either too complex or too large to maintain easily by hand.
We will start by writing an abbreviated version of what the result
is supposed to be.  We will use that to construct our output templates.

@noindent
In a header file, @file{list.h}, you define the enumeration
and the global array containing the associated strings:

@example
typedef enum @{
        IDX_ALPHA,
        IDX_BETA,
        IDX_OMEGA @}  list_enum;

extern const char* az_name_list[ 3 ];
@end example

@noindent
Then you also have @file{list.c} that defines the actual
strings:

@example
#include "list.h"
const char* az_name_list[] = @{
        "some alpha stuff",
        "more beta stuff",
        "final omega stuff" @};
@end example

@noindent
First, we will define the information that is unique for
each enumeration name/string pair.

@example
autogen definitions list;
list = @{ list_element = alpha;
         list_info    = "some alpha stuff"; @};
list = @{ list_info    = "more beta stuff";
         list_element = beta; @};
list = @{ list_element = omega;
         list_info    = "final omega stuff"; @};
@end example

The @code{autogen definitions list;} entry defines the file as an
AutoGen definition file that uses a template named @code{list}.  That is
followed by three @code{list} entries that define the associations
between the enumeration names and the strings.  The order of the
differently named elements inside of list is unimportant.  They are
reversed inside of the @code{beta} entry and the output is unaffected.

Now, to actually create the output, we need a template or two that can
be expanded into the files you want.  In this program, we use a single
template that is capable of multiple output files.

It looks something like this.
(For a full description, @xref{Template File}.)

@example
[#autogen template h c #]
[#_IF _SFX h = #]
typedef enum @{[#
   _FOR list , #]
        IDX_[#list_element _up#][#
   /list #] @}  list_enum;

extern const char* az_name_list[ [#_eval list _count #] ];
[#

_ELIF _SFX c = #]
#include "list.h"
const char* az_name_list[] = @{[#
_FOR list ,#]
        "[#list_info#]"[#
/list #] @};[#

_ENDIF header/program #]
@end example

The @code{[#autogen template h c #]} text tells AutoGen that this is a
template file; that it is to be processed twice; that the start macro
marker is @code{[#}; and the end marker is @code{#]}.  The template will
be processed first with a suffix value of @code{h} and then with
@code{c}.

The @code{[#_IF _SFX h = #]} and @code{[#_ELIF _SFX c = #]} 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 @code{[#_FOR list ,#]} and @code{[# /list #]} clauses delimit
blocks of text that will be repeated for every definition of @code{list}.
Inside of that block, the definition name-value pairs that
are members of each @code{list} are available for substitutions.

The remainder of the macros are expressions.  Some of these contain
special expression functions to obtain certain values or modify the
values before they are inserted into the output.  For example,
@code{_count} yields the number of definitions of a particular name,
and @code{_up} will change a string to all upper case.

If you have compiled AutoGen, you can copy out the template and
definitions, run @file{autogen} and produce exactly the hypothesized
desired output.
@node Testimonial
@section A User's Perspective

@format
        Subject: Re: Sysadmin Package
           Date: Thu, 24 Sep 1998
           From: "Gary V. Vaughan"
             To: Alexandre
             CC: autoconf <autoconf@@gnu.org>

> Bruce Korb writes:
> 
> > I would like to recommend my tool.  It exactly and precisely
> > addresses these very problems in a manner far simpler than M4.

Alexandre wrote:
> 
> I'd appreciate opinions from others about advantages/disadvantages of
> each of these macro packages.
@end format

I am using AutoGen in my pet project, and find one of its best points to
be that it separates the operational data from the implementation.

Indulge me for a few paragraphs, and all will be revealed:
In the manual, Bruce cites the example of maintaining command line flags
inside the source code; traditionally spreading usage information, flag
names, letters and processing across several functions (if not files). 
Investing the time in writing a sort of boiler plate (a template in
AutoGen terminology) 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 rationalise autoconf with AutoGen in place of m4...  Ben,
are you listening?  autoconf-3.0! `kay?  =)O|

@format
Sincerely,
        Gary V. Vaughan
@end format

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@end ignore
@page
@node Definitions File
@chapter AutoGen Definitions File
@cindex definitions file
@cindex .def file

This chapter describes the syntax and semantics of the AutoGen
definition file.  Knowledge of identification, simple and compound
definition syntax is required to instantiate a template.  Consequently,
we keep it very simple.  For "advanced" users, there are preprocessing
directives and comments that may be used as well.

The definitions file is used to associate values with names.  When
multiple values are associated with a single name, an implicit array of
values is formed.  Values may be either simple strings or compound
collections of value-name pairs.  An array may not contain both simple
and compound members.  Fundamentally, it is as simple as:

@example
prog_name = "autogen";
flag = @{
    name      = templ_dirs;
    value     = L;
    descrip   = "Template search directory list";
@};
@end example

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 @code{#if} directive is
ignored, along with all following text through the matching
@code{#endif} directive.  The C preprocessor is not actually invoked, so
C macro substitution is @strong{not} performed.

@menu
* Identification::  The First Definition
* Definitions::     Simple and Compound Definitions
* Directives::      Controlling What Gets Processed
* Comments::        Commenting Your Definitions
* Example::         What it all looks like.
* Full Syntax::     YACC Language Grammar
@end menu

@node Identification
@section The First Definition
@cindex identification

The first definition in this file is used to identify it as a
AutoGen file.  It consists of the two keywords,
@samp{autogen} and @samp{definitions} followed by the default
template name and a terminating semi-colon (@code{;}).  That is:

@example
        AutoGen Definitions @var{template-name};
@end example

@noindent
Note that, other than the name @var{template-name}, the words
@samp{AutoGen} and @samp{Definitions} are searched for without case
sensitivity.  Most lookups in this program are case insensitive.

@cindex template, file name
@cindex .tpl, file name
@cindex tpl, file name

@noindent
AutoGen uses the name of the template to find the corresponding template
file.  It searches for the file in the following way, stopping when
it finds the file:

@enumerate
@item
It tries to open @file{./@var{template-name}}.  If it fails,
@item
it tries @file{./@var{template-name}.tpl}.
@item
It searches for either of these files in the directories listed in the
templ-dirs command line option.
@end enumerate

If AutoGen fails to find the template file in one of these places,
it prints an error message and exits.

@node Definitions
@section Simple and Compound Definitions
@cindex definitions
@cindex simple definitions
@cindex compound definitions

Any name may have multiple values associated with it in the definition
file.  If there is more than one instance, the @strong{only} way to
expand all of the copies of it is by using the _FOR (@xref{FOR}.) text
function on it, as described in the next chapter.

There are two kinds of definitions, @samp{simple} and @samp{compound}.
They are defined thus:

@example
compound_name '=' '@{' definition-list '@}' ';'

text_name '=' string ';'

no_text_name ';'
@end example

@noindent
The names may be a simple name taking the next available index,
or may specify an index by name or number.  For example:

@example
txt_name
txt_name[2]
txt_name[ DEF_NAME ]
@end example
@noindent
@code{DEF_NAME} must be defined to have a numeric value.
If you do specify an index, you must take care not to cause conflicts.

@noindent
@code{No_text_name} is a text definition with a shorthand empty string
value.

@noindent
@code{definition-list} is a list of definitions that may or may not
contain nested compound definitions.  Any such definitions may
@strong{only} be expanded within a @code{FOR} block iterating over the
containing compound definition.  @xref{FOR}.

Here is, again, the example definitions from the previous chapter,
with three additional name value pairs.  Two with an empty value
assigned (@var{first} and @var{last}), and a "global" @var{group_name}.

@example
autogen definitions list;
group_name = example;
list = @{ list_element = alpha;  first;
         list_info    = "some alpha stuff"; @};
list = @{ list_info    = "more beta stuff";
         list_element = beta; @};
list = @{ list_element = omega;  last;
         list_info    = "final omega stuff"; @};
@end example

@cindex simple definitions, format
The string values for definitions may be specified in one of four
formation rules:

@table @samp
@item with a double quote @code{"}
@cindex string, double quote
The string follows the C-style escaping (@code{\}, @code{\n}, @code{\f},
@code{\v}, etc.), plus octal character numbers specified as @code{\ooo}.
The difference from "C" is that the string may span multiple lines.

@item with a single quote @code{'}
@cindex string, single quote
This is similar to the shell single-quote string.  However, escapes
@code{\} are honored before another escape, single quotes @code{'}
and hash characters @code{#}.  This latter is done specifically
to disambiguate lines starting with a hash character inside
of a quoted string.  In other words,

@example
foo = '
#endif
';
@end example

could be misinterpreted by the definitions scanner, whereas
this would not:

@example
foo = '
\#endif
';
@end example

@item with a back quote @code{`}
@cindex string, shell output
This is treated identically with the double quote, except that the
resulting string is written to a shell server process and the definition
takes on the value of the output string.

NB:  The text is interpreted by a server shell.  There may be
left over state from previous @code{`} processing and it may
leave state for subsequent processing.  However, a @code{cd}
to the original directory is always issued before the new
command is issued.

A definition utilizing a backquote may not be joined with any other text.

@item without surrounding quotes
The string must not contain any of the characters special to the
definition text.  E.g. @code{;}, @code{"}, @code{'}, @code{`}, @code{=},
@code{@{}, @code{@}}, @code{[}, @code{]}, @code{#} or any
white space character.  Basically, if the string looks like it is a
normal file name or variable name, and it is not one of two keywords
(@samp{autogen} or @samp{definitions}) then it is OK to not quote it.
@end table

If single or double quote characters are used, then you
also have the option, a la ANSI-C syntax, of implicitly
concatenating a series of them together, with intervening
white space ignored.

NOTE: You @strong{cannot} use directives to alter the string
content.  That is,

@example
str = "foo"
#ifdef LATER
      "bar"
#endif
      ;
@end example

@noindent
will result in a syntax error.  The preprocessing directives are not
carried out by the C preprocessor.  However,

@example
str = '"foo\n"
#ifdef LATER
"     bar\n"
#endif
';
@end example

@noindent
@strong{Will} work.  It will enclose the @samp{#ifdef LATER}
and @samp{#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 @code{\} or join them with previous lines:
@code{"foo\n#ifdef LATER...}.

@node Directives
@section Controlling What Gets Processed
@cindex directives

Definition processing directives can @strong{only} be processed
if the '#' character is the first character on a line.  Also, if you
want a '#' as the first character of a line in one of your string
assignments, you should either escape it by preceding it with a
backslash @samp{\}, or by embedding it in the string as in @code{"\n#"}.

All of the normal C preprocessing directives are recognized, though
several are ignored.  There is also an additional @code{#shell} -
@code{#endshell} pair.  Another minor difference is that AutoGen
directives must have the hash character (@code{#}) in column 1.

The ignored directives are:
@samp{#assert}, @samp{#ident}, @samp{#pragma},  and @samp{#if}.
Note that when ignoring the @code{#if} directive, all intervening
text through its matching @code{#endif} is also ignored,
including the @code{#else} clause.

The AutoGen directives that affect the processing of
definitions are:

@table @code

@item #define name [ <text> ]
@cindex #define
@cindex define directive
Will add the name to the define list as if it were a DEFINE program
argument.  Its value will be the first non-whitespace token following
the name.  Quotes are @strong{not} processed.

After the definitions file has been processed, any remaining entries
in the define list will be added to the environment.

@item #else
@cindex #else
@cindex else directive
This must follow an @code{#ifdef} or @code{#ifndef}.
It will change the processing state to the reverse of what it was.

@item #endif
@cindex #endif
@cindex endif directive
This must follow an @code{#ifdef} or @code{#ifndef}.
This will resume normal processing of text.

@item #endshell
@cindex #endshell
@cindex endshell directive
Ends the text processed by a command shell into autogen definitions.

@item #error [ <descriptive text> ]
@cindex #error
@cindex error directive
This directive will cause AutoGen to stop processing
and exit with a status of EXIT_FAILURE.


@item #if [ <ignored conditional expression> ]
@cindex #if
@cindex if directive
@code{#if} expressions are not analyzed.  @strong{Everything} from here
to the matching @code{#endif} is skipped.

@item #ifdef name-to-test
@cindex #ifdef
@cindex ifdef directive
The definitions that follow, up to the matching @code{#endif} will be
processed only if there is a corresponding @code{-Dname} command line
option.

@item #ifndef name-to-test
@cindex #ifndef
@cindex ifndef directive
The definitions that follow, up to the matching @code{#endif} will be
processed only if there is @strong{not} a corresponding @code{-Dname}
command line option or there was a canceling @code{-Uname} option.

@item #include unadorned-file-name
@cindex #include
@cindex include directive
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.

@item #line
@cindex #line
@cindex line directive
Alters the current line number and/or file name.
You may wish to use this directive if you extract definition
source from other files.


@item #shell
@cindex #shell
@cindex shell directive
Invokes $SHELL or /bin/sh on a script that should generate
AutoGen definitions.  It does this using the same server
process that handles the backquoted @code{`} text.

@item #undef name-to-undefine
@cindex #undef
@cindex undef directive
Will remove any entries from the define list
that match the undef name pattern.
@end table

@node Comments
@section Commenting Your Definitions
@cindex comments

The definitions file may contain C-style comments.

@example
/*
 *  This is a comment.
 *  It continues for several lines and suppresses all processing
 *  until the closing characters '*' and '/' appear together.
#include is ignored.
 */
@end example

@node Example
@section What it all looks like.

@noindent
This is an extended example:

@example
autogen definitions @samp{template-name};
/*
 *  This is a comment that describes what these
 *  definitions are all about.
 */
global = "value for a global text definition.";

/*
 *  Include a standard set of definitions
 */
#include standards.def

a_block = @{
    a_field;
    /*
     *  You might want to document sub-block definitions, too
     */
    a_subblock = @{
        sub_name  = first;
        sub_field = "sub value.";
    @};

#ifdef FEATURE
    /*
     *  This definition is applicable only if FEATURE
     *  has been defined during the processing of the definitions.
     */
    a_subblock = @{
        sub_name  = second;
    @};
#endif

@};

a_block = @{
    a_field = here;
@};
@end example

@node    Full Syntax
@section YACC Language Grammar

The processing directives and comments are not
part of the grammar.  They are handled by the scanner/lexer.
The following was extracted directly from the agParse.y source file:

@ignore
Extracted from $top_srcdir/src/agParse.y
@end ignore
@example
definitions     : identity def_list TK_END
                    @{
                        $$ = makeBlockMacro( (YYSTYPE)&rootEntry, $2 );
                    @}
                ;

/*
 *  The marker_list definition is in bison (list-first) order.
 *  It should be reversed for yacc
 */
def_list        : definition           @{ $$ = $1; @}
                | definition def_list  @{ $$ = addSibMacro( $1, $2 ); @}
                | identity   def_list  @{ $$ = $2; @}
                ;


definition      : place ';'
                    @{ $$ = makeTextMacro( $1, (YYSTYPE)"" ); @}

                | place '=' anystring ';'
                    @{ $$ = makeTextMacro( $1, $3 ); @}

                | place '=' '@{' def_list '@}' ';'
                    @{ $$ = makeBlockMacro( $1, $4 ); @}
                ;

identity        : TK_AUTOGEN TK_DEFINITIONS anyname ';'
                    @{ $$ = identify( $3 ); @}
                ;

anystring       : anyname   @{ $$ = $1; @}
                | TK_STRING @{ $$ = $1; @}
                | TK_NUMBER @{ $$ = $1; @}
                ;

anyname         : TK_OTHER_NAME @{ $$ = $1; @}
                | TK_VAR_NAME   @{ $$ = $1; @} ;


place           : TK_VAR_NAME
                    @{ $$ = findPlace( $1, (YYSTYPE)NULL ); @}

                | TK_VAR_NAME '[' TK_NUMBER ']'
                    @{ $$ = findPlace( $1, $3 ); @}

                | TK_VAR_NAME '[' TK_VAR_NAME ']'
                    @{ $$ = findPlace( $1, $3 ); @}
                ;
@end example

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@end ignore
@page
@node Template File
@chapter AutoGen Template
@cindex template file
@cindex .tpl file

The template is really composed of two parts.
The first part consists of a pseudo macro invocation and commentary.
It is followed by the template proper.

@cindex pseudo macro
@cindex macro, pseudo
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, and specifying the list
of suffixes to be generated by the template.

@menu
* template id::      Format of the Pseudo Macro
@end menu

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.  If it starts
with a hash mark (@code{#}), then the macro is a comment.  If it starts
with an underscore (@code{_}), then it is an explicit function invocation.
These functions are listed below.  If it starts with an alphabetic
character, then @code{eval} will be invoked implicitly.  See the
discussion below.  If it begins with any other character (white space
being ignored), then it is in error and processing will stop.

@menu
* CASE::           CASE - Select one of several template blocks
* Cond_Eval::      COND_EVAL - Eval Expression Conditionally
* ELIF::           ELIF - Alternate Conditional Template Block
* ELSE::           ELSE - Alternate Template Block
* ENDIF::          ENDIF - Terminate the @code{IF} Template Block
* ERROR::          ERROR - Cease processing
* ESAC::           ESAC - Terminate the @code{CASE} Template Block
* EVAL::           EVAL - Evaluate and Emit an Expression
* FOR::            FOR - Emit a template block multiple times
* IF::             IF - Conditionally Emit a Template Block
* INCLUDE::        INCLUDE - Read in and emit a template block
* OUTPUT::         OUTPUT - Alter the output file
* SETENV::         SETENV - Compute and Save an Expression
@end menu

@node template id
@section Format of the Pseudo Macro
@cindex template id

The template file must begin with a pseudo-macro.  The pseudo-macro
is used to identify the file as an AutoGen template file,
define the starting and ending macro markers and specify the
list of output files the template is to create.

Assuming we want to use @code{[+} and @code{+]} as the start and
end macro markers, and we wish to produce a @file{.c} and a @file{.h}
file, then the first macro invocation will look something like this:

@example
[+ autogen template -*- Mode: emacs-mode-of-choice -*-

h=chk-%s.h

c +]
@end example

@noindent
Note:  It is generally a good idea to use some sort of opening
bracket in the starting macro and closing bracket in the ending
macro  (e.g. @code{@{}, @code{(}, @code{[}, or even @code{<}
in the starting macro).  It helps both visually and with editors
capable of finding a balancing parenthesis.

@noindent
Detailed description:

The starting macro marker must be the first non-white space characters
encountered in the file.  The marker consists of all the contiguous
ASCII punctuation characters found there.  With optional intervening
white space, this marker must be immediately followed by the keywords,
"autogen" and "template".  Capitalization of these words is not
important.  This is followed by zero, one or more suffix specifications.

Suffix specifications consist of a sequence of POSIX compliant file name
characters and, optionally, an equal sign and a file name "printf"-style
formatting string.  Two string arguments are allowed for that string:
the base name of the definition file and the current suffix (that being
the text to the left of the equal sign).  (Note: "POSIX compliant file
name characters" consist of alphanumerics plus the period (@code{.}),
hyphen (@code{-}) and underscore (@code{_}) characters.)  If there are
no suffix specifications, then the generated file will be written to the
stdout file descriptor.

The pseudo macro ends with an end macro marker.  Like the starting macro
marker, it consists of a contiguous sequence of arbitrary punctuation
characters.  However, additionally, it may not begin with any of the
POSIX file name characters and it may not contain the start macro
marker.

This pseudo macro may appear on one or several lines of text.
Intermixed may be comment lines (completely blank or starting with the
hash character @code{#} in column 1), and file content markers (text
between @code{-*-} pairs on a single line).  This may be used to
establish editing "modes" for the file.  These are ignored by
AutoGen.

The template proper starts after the pseudo-macro.  The starting
character is either the first non-whitespace character or the first
character after the new-line that follows the end macro marker.



@node CASE
@section CASE - Select one of several template blocks
@findex CASE

The arguments are evaluated and converted to a string, if necessary.
The scope of the macro is up to the matching @code{ESAC}.
Within the scope of a CASE, this string is matched against
case element macros named simply "_".  The entire argument string
to the case element macro is treated as a regular expression
and the "CASE" argument is matched against it.  It is successful
only if there is a complete match.

@noindent
For example:

@example
[#_CASE text_mac _get#]
this is a comment because there is no label
[#_ [aA].*#]this is emitted if "text_mac" starts with an 'a'
[#_ .*[zZ]#]this is emitted if it ends with a 'z'
[#_ .*#]this is emitted if nothing else
[#_ESAC#]
@end example

@node Cond_Eval
@section COND_EVAL - Eval Expression Conditionally
@findex COND_EVAL

If the macro text begins with an alphabetic character, it
is assumed to be a text macro name.  If it is, the name is
replaced with the associated value and the resulting expression
is @code{_eval}-ed and printed to the output.  If the name
is unknown or not a text macro name, then the expression is
ignored and no output is produced.

@code{[#var_name ...#]} is thus equivalent to the following:

@example
[#_IF var_name _exist#][#
_EVAL var_name _get ... #][#
_ENDIF#]
@end example

@node ELIF
@section ELIF - Alternate Conditional Template Block
@findex ELIF

This macro must only appear after an @code{IF} function,
and before any associated @code{ELSE} or @code{ENDIF} functions.
It denotes the start of an alternate template block for
the @code{IF} function.  For a complete description @xref{IF}.

@node ELSE
@section ELSE - Alternate Template Block
@findex ELSE

This macro must only appear after an @code{IF} function,
and before the associated @code{ENDIF} function.
It denotes the start of an alternate template block for
the @code{IF} function.  For a complete description @xref{IF}.

@node ENDIF
@section ENDIF - Terminate the @code{IF} Template Block
@findex ENDIF

This macro ends the @code{IF} function template block.
For a complete description @xref{IF}.

@node ERROR
@section ERROR - Cease processing
@findex ERROR
@cindex error handling

The arguments are evaluated and printed to the stderr,
the current output file is removed and AutoGen exits
with the EXIT_FAILURE error code.  IF, however, the argument
is the number 0 (zero), then the output file is silently
removed and processing continues with the next suffix.

@noindent
For example, the following will print the quoted error
message and AutoGen will exit:

@example
[#_ERROR "You did not have enough values to continue"#]
@end example

@node ESAC
@section ESAC - Terminate the @code{CASE} Template Block
@findex ESAC

This macro ends the @code{CASE} function template block.
For a complete description, @xref{CASE}.

@node EVAL
@section EVAL - Evaluate and Emit an Expression
@findex EVAL

The arguments are evaluated and the result printed to the output file.
The expression must be in reverse polish notation.  Strings and numbers
are pushed on the stack, operators and functions pop values and push a
result.  The 'operators' are:

@example
= != > < >= <= ! % & * + - / | ~ #
@end example

@noindent
@strong{NOTE}:  the @code{and} (@code{&}) and @code{or} (@code{|})
operators are logical operators, not bitwise operations.  The
@code{tilde} (@code{~}) operator is a pattern match that yields 1
(@code{true}) if the first (string) argument is fully matched by
the second (pattern) argument, otherwise 0 (@code{false}).  The
@code{#} operator "stringifies" whatever it is attached to.  This
is the only way to push a string onto the stack that does not
begin with an alphabetic or whitespace character.  The other
operators have their normal meanings.

Expression function names are denoted by strings that start with a
@code{_}.  The defined functions are:
@table @samp
@findex CAP
@item CAP
Replace the top of stack as a Capitalized String.

@findex COUNT
@item COUNT
Replace TOS with the count of objects in the
macro named in the top of stack.

@findex DFILE
@item DFILE
Push the name of the definitions file onto the stack

@findex DNE
@item DNE
Replace TOS with a Do Not Edit warning string.
Each line of that string will be prefixed with the text string
on the top of the stack.

@findex DOWN
@item DOWN
Replace the top of stack as a lower case string.

@findex ENV
@item ENV
Replace the TOS with contents of a DEFINE or an environment variable
named by it.  These values may be set @strong{either} before
execution using your regular shell commands @strong{or} with the
@code{SETENV} macro function.

@findex EXIST
@item EXIST
Replace TOS with 1 if top of stack names a defined macro, 0 otherwise.

@findex FIRST
@item FIRST
If AutoGen is currently inside of a _FOR macro function
and this is the first iteration of that loop,
then push a 1 onto the stack, otherwise push a 0.

@findex GET
@item GET
Replace TOS with the value of the named text macro.

@findex GPL
@item GPL
Replace the top two stacked strings with the GNU Public License.  TOS
contains the string to start each output line.  TOS-1 contains the name
of the program the copyright is about.

@findex HILIM
@item HILIM
Replace TOS with the highest index value for the macro it names.

@findex IN
@item IN
Replace the entire stack with a 1 if the string at the bottom of the
stack occurs again in the rest of the stack, 0 otherwise.  Always leaves
one element on the stack, unless a @code{MARK}-er stops it sooner.
In that case, the @code{MARK}-er will be replaced with the 1 or 0.

@findex INDEX
@item INDEX
Push the current, most deeply nested block number on top of stack.
It is zero outside the scope of a FOR macro loop.

@findex JOIN
@item JOIN
Glue together the value of every item on the stack with a single space
character between them.  In this fashion, you can easily pass a list of
values to a shell script.  It will stop and replace a @code{MARK}-er
entry, if found.

@findex KRSTR
@item KRSTR
Stringify the TOS, using K&R "C" syntax.  Many non-printing
characters are replaced with escape sequences.  After compilation,
the resulting string should be identical to the input value.
Multiple lines are continued with an escaped new line, per K&R
rules.

@findex LAST
@item LAST
If AutoGen is currently inside of a _FOR macro function
and this is the last iteration of that loop,
then push a 1 onto the stack, otherwise push a 0.

@findex LEN
@item LEN
Replace the string at TOS with the length of the macro.
For "text" macros, it is the string length.
For "block" macros, it is the number of occurrences.
For compound macros (where the name is a block name followed
by a period and another macro name), it is the sum of these
values.

@findex LGPL
@item LGPL
Replace the top three stacked strings with the GNU Library Public
License.  TOS contains the string to start each output line.  TOS-1
contains the copyright owner.  TOS-2 contains the name of the program
the copyright is about.

@findex LOLIM
@item LOLIM
Replace the TOS with the lowest index value for the named macro.

@findex MAP
@item MAP
This command is deprecated.  Use @code{_tr}.

@findex MARK
@item MARK
Mark a place in the stack where the IN, JOIN, MIN, MAX and SUM
expression functions are to stop processing.

@findex MAX
@item MAX
Replace entire stack with the highest value in the stack.

@findex MIN
@item MIN
Replace entire stack with the lowest value in the stack.

@findex OUTFILE
@item OUTFILE
Push the name of the current output file onto the stack.

@findex PREFIX
@item PREFIX
Prefix every line in TOS-1 with the string in TOS.
E.g. if TOS-1 contains the string, "two''nlines" and TOS
contains "# ", then TOS gets popped and TOS-1 (new TOS) will
contain "# two''n# lines".

@findex PRINTF
@item PRINTF
Using TOS as a format, use vsprintf to make new TOS.  If more than
1 arg is to be consumed, the format must be prefixed with "n$"
where "n" is the number of arguments needed *after* the format and
'$' is the literal dollar sign character.  The format plus "n"
items will get popped and the resulting string pushed back onto
the stack.

@noindent
For example:

@example
[#_EVAL prog_name _get _outfile
"#2$echo '%s_%s'|tr '[a-z]./' '[A-Z]__'" _printf _shell#]
@end example
@noindent

will do the following:
@enumerate
@item
Push the string "@code{prog_name}" onto the stack.

@item
Replace it with the text the @code{prog_name} definition contains.

@item
Push the name of the current output file.

@item
Push a format string that consumes two additional arguments.
(Note the @code{#2$} prefix.)

@item
Invoke @code{vsprintf} and replace the top three stack entries
with the result.

@item
Lastly, replace this string with the output produced by
running it through the @code{shell} expression function.
@end enumerate

@findex SFX
@item SFX
Push the current active suffix.  See @code{generate} in the
@code{Declarations Input} section above.

@findex SHELL
@item SHELL
Replace the TOS by the output produced by writing the value to
a server shell and reading the output back in.  The template
programmer is responsible for ensuring that it completes
within 10 seconds.  If it does not, the server will be killed,
the output tossed and a new server started.

@findex SHRSTR
@item SHRSTR
Convert the text of the string at TOS into a singly quoted string
that a normal shell will process into the original string.
(It will not do macro expansion later, either.)
Contained single quotes become tripled, with the middle quote
escaped with a backslash.  Normal shells will reconstitute the
original string.

@findex SHSTR
@item SHSTR
Convert the text of the string at TOS into a double quoted string
that a normal shell will process into the original string.
(Before doing macro expansion, that is.)
The escaped characters are @code{''''} and @code{"} and @code{#}.
All others are copied directly into the output.

@findex STACK
@item STACK
Pop a compound macro name and push every occurrence of it onto the
stack.  Compound macro names are: @code{blk.text} and mean for every
defined value of @code{text} within every block @code{blk}, push the
value.  If there are blocks within blocks, each nested block name must
be supplied.

@findex STR
@item STR
Stringify the TOS, using ANSI-C syntax.  Many non-printing characters are
replaced with escape sequences.  After compilation, the resulting
string should be identical to the input value.  Multiple lines
are continued with implicit concatenation, per ANSI specifications.
A K&R compiler will choke.

@findex SUM
@item SUM
Replace entire stack with the sum of the values in the stack.

@findex TFILE
@item TFILE
Push the name of the template file onto the stack

@findex TR
@item TR
This is approximately the same as the @code{tr(1)} program, except the
string to transform is the first argument.  The second and third arguments
are used to construct mapping arrays for the transformation of the first
argument.

It is too bad this little program has so many different
and incompatible implementations!

@findex UP
@item UP
Replace the top of stack as an UPPER CASE string.

@findex VAL
@item VAL
Replace TOS with the numeric value of the top of stack [atoi()].

@end table

@node FOR
@section FOR - Emit a template block multiple times
@findex FOR
@cindex looping, for
@cindex for loop

The first argument must be the name of the block.
The scope of the @code{FOR} function extends to a macro marker
that contains a slash @code{/} and this block name, rather
than any other macro function.

If there are any further arguments, a single argument is interpreted as
an iteration separator (text to be emitted between emitted copies of the
text block).  If there are more arguments, they must be named arguments:
@code{FROM}, @code{TO}, @code{BY} or @code{SEP}.
@code{FROM}, @code{TO} and @code{BY} must be followed by a simple
number or a single pair of parentheses containing an expression
to be evaluated into a number.

Each copy of a text block macro has an associated index number.  If the
definition file specified the index values, the indexes may have gaps in
the sequence.  @code{FROM}, @code{TO} and @code{BY} may be used to
select specific sets of entries.  If @code{TO} is omitted, the default
is to terminate the loop when the index goes outside of the valid range
of indexes.  If @code{BY} is omitted, only extant index values will be
iterated.  If @code{BY} is specified on a sparse block, the block will
be emitted with the block values undefined, but @code{[#_eval _index#]}
still showing the correct value.  If @code{FROM} is omitted, the first
or last defined index value will be used (depending on the sign of
@code{BY}).

@example
[#_FOR var FROM 0 TO (LIMIT _env) SEP "," #]
... text with @code{var}ious substitutions ...[#
/var#]
@end example

@noindent
this will repeat the @code{'n... text with @code{var}ious
substitutions ...} several times, depending on @code{LIMIT},
a value which is gotten from the environment.  Each repetition,
except for the last, will have a comma @code{,} after it.

@example
[#_FOR var "," #]
... text with @code{var}ious substitutions ...[#
/var#]
@end example

@noindent
This will do the same thing, but only for the index
values of @code{var} that have actually been defined.

@node IF
@section IF - Conditionally Emit a Template Block
@findex IF
@cindex conditional emit
@cindex if test

Conditional block.  Its arguments are evaluated (see _EVAL) and
if the result is non-zero or a string with one or more bytes,
then the condition is true and the text from that point
until a matched "_ELIF", "_ELSE" or "_ENDIF" is emitted.
"_ELIF" introduces a conditional alternative if the "_IF"
clause evaluated FALSE and "_ELSE" introduces an unconditional
alternative.

@example
[#_IF [[condition]]#]
emit things that are for the true condition[#

_ELIF [[maybe]] #]
emit things that are true maybe[#

_ELSE "This may be a comment" #]
emit this if all but else fails[#

_ENDIF "This may *also* be a comment" #]
@end example

@node INCLUDE
@section INCLUDE - Read in and emit a template block
@findex INCLUDE

The entire contents of the named file is inserted at this point.
The contents of the file are processed for macro expansion.  The
arguments are eval-ed, so you may compute the name of the file to
be included.  The included file must not contain any incomplete
function blocks.  Function blocks are template text beginning with
any of the macro functions @samp{_IF}, @samp{_FOR} and
@samp{_CASE} and extending through the respective terminating
macro functions.

@node OUTPUT
@section OUTPUT - Alter the output file
@findex OUTPUT
@cindex output file

Change the name of the output file.  First argument describes function
and the second the name of the new file.

@table @samp
@findex Delete
@item Delete
Remove the current output file.  Cease processing the template for
the current suffix.  It is an error if there are @code{push}-ed
output files.  Use the @code{[#_ERROR 0#]} function instead.

@findex Switch
@item Switch
Close current output, open new output file

@findex Move
@item Move
Rename current output file.

@findex Push-new
@item Push-new
Leave the current output file open, but purge and create
a new file that will remain open until a @code{pop} @code{delete}
or @code{switch} closes it.

@findex Push-add
@item Push-add
Identical to @code{push-new}, except the contents are @strong{not}
purged, but appended to.

@findex Pop
@item Pop
If there has been a @code{push} on the output, then close that
file and go back to the previously open file.  It is an error
if there has not been a @code{push}.  The file name argument may be
omitted and is ignored.
@end table

@node SETENV
@section SETENV - Compute and Save an Expression
@findex SETENV

The arguments are "_EVAL"-ed.  When done, there should be two values
left.  The first is the name of the environment variable and the second
its value.  This value can be used later in expression evaluations using
the @code{_env} expression function.  No data are written to the output.

@noindent
For example:

@example
[#_SETENV SAVE_ name _get _up + text _get#]
@end example

@noindent
This will:

@enumerate
@item
Push @code{SAVE_} onto stack

@item
Push @code{name} onto stack

@item
Replace @code{name} with value of variable @code{name}.

@item
Replace that value with an upper case version of that value

@item
Concatenate this value to the end of @code{SAVE_} and pop
it off the stack.

@item
Push @code{text} onto stack

@item
Replace @code{text} with value of variable @code{text}.
@end enumerate

@noindent
At this point, the expression evaluation is done and there are two
strings remaining on the stack.  @code{SETENV} will now create an
environment variable with the first stack element as the variable name
and the second stack element as its value.

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copy of generated file ${top_builddir}/src/autogen.texi
@end ignore
@page

@node AutoGen Invocation
@chapter Invoking AutoGen
@cindex autogen invocation
@ignore

DO NOT EDIT THIS FILE   (autogen.texi)

It has been autogen-ed  Wednesday May 17, 2000 at 11:15:53 AM BST
From the definitions    ./opts.def
and the template file   ../autoopts/aginfo.tpl

@end ignore

This chapter documents the @code{AutoOpts}
generated usage text and option meanings for AutoGen.

@menu
* autogen usage::                  AutoGen Usage
* autogen base-name::              base-name Option
* autogen define::                 define Option
* autogen equate::                 equate Option
* autogen loop-limit::             loop-limit Option
* autogen override-tpl::           override-tpl Option
* autogen show-defs::              show-defs Option
* autogen show-shell::             show-shell Option
* autogen skip-suffix::            skip-suffix Option
* autogen templ-dirs::             templ-dirs Option
* autogen timeout::                timeout Option
* autogen undefine::               undefine Option
@end menu

@node autogen usage
@section AutoGen Usage
@cindex autogen usage

This is the automatically generated usage text for AutoGen:

@example

AutoGen - The Automated Program Generator - Ver. 4.5.14
USAGE:  lt-autogen [-<flag> [<val>]]... [--<name>[@{=| @}<val>]]... [ <def-file> ]
  Flg Arg Option-Name    Description
   -L YES templ-dirs     Template search directory list
                                - may appear without limit
   -T YES override-tpl   Override template file
                                - may not be preset
   -b YES base-name      Base name for output file(s)
                                - may not be preset
   -s YES skip-suffix    Omit the file with this suffix
                                - may not be preset
                                - may appear without limit
      YES equate         characters considered equivalent

The following options are often useful while debugging new templates:

  Flg Arg Option-Name    Description
      Num loop-limit     Limit on increment loops
   -t Num timeout        Time limit for servers

These options can be used to control what gets processed
in the definitions files and template files.

  Flg Arg Option-Name    Description
   -D YES define         name to add to definition list
                                - may appear without limit
   -U YES undefine       definition list removal pattern
                                - an alternate for define

Auto-supported Options:

  Flg Arg Option-Name    Description
   -v opt version        Output version information and exit
   -? no  help           Display usage information and exit
   -! no  more-help      Extended usage information passed thru pager
   -> opt save-opts      Save the option state to an rc file
   -< YES load-opts      Load options from an rc file
                                - disabled as --no-load-opts
                                - may appear without limit

Options may be specified by doubled hyphens and their name
or by a single hyphen and the flag character/option value.

If "<def-file>" is "-" or not specified, standard in is assumed.
The default "base-name" is the "<def-file>" with suffixes removed.
However, the template file may specify the output file names.
"loop-limit" is used in debugging to stop runaway expansions.

The following option preset mechanisms are supported:
 - reading file $HOME/.autogenrc
 - reading file ./.autogenrc
 - examining environment variables named AUTOGEN_*

AutoGen is a tool designed for generating program files
that contain repetitive text with varied substitutions.
See the info documentation for details.
@end example


@node autogen templ-dirs
@section templ-dirs Option
@cindex autogen-templ-dirs

Add a directory to the list of directories to search when opening
a template, either as the primary template or an included one.

@node autogen override-tpl
@section override-tpl Option
@cindex autogen-override-tpl

Definition files specify the standard template that is to be expanded.
This option will override that name and expand a different template.

@node autogen base-name
@section base-name Option
@cindex autogen-base-name

A template may specify the exact name of the output file.
Normally, it does not.  It is, instead, the base name of the
definitions file, with suffixes removed.  If the definitions
are being read from standard in or there is some other reason
for using a different base file name, then use this option.

@node autogen skip-suffix
@section skip-suffix Option
@cindex autogen-skip-suffix

Occasionally, it may not be desirable to produce all of the output
files specified in the template.  (For example, only the @file{.h}
header file, but not the @file{.c} program text.)  To do this
specify @code{--skip-suffix=c} on the command line.

@node autogen equate
@section equate Option
@cindex autogen-equate

This option will alter the list of characters considered equivalent.
The default are the three characters, "_-^".  (The latter is
conventional on a Tandem, and I do a lot of work on the Tandem.)

@node autogen loop-limit
@section loop-limit Option
@cindex autogen-loop-limit

This option prevents runaway loops.  For example, if you accidentally
specify, "_FOR x FROM 1 TO -1 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.

@node autogen timeout
@section timeout Option
@cindex autogen-timeout

AutoGen works with a shell server process.  Most normal commands
will complete in less than 10 seconds.  If, however, your commands
need more time than this, use this option.

@node autogen show-defs
@section show-defs Option
@cindex autogen-show-defs

This option is only available with a DEBUG build of AutoGen.
This will print out the complete definition tree before processing
the template.

@node autogen show-shell
@section show-shell Option
@cindex autogen-show-shell

This option is only available with a DEBUG build of AutoGen.
This will cause @code{set -x} to be executed in the shell, with
the resultant output printed to /dev/tty.

@node autogen define
@section define Option
@cindex autogen-define

Just like 'C', AutoGen uses @code{#ifdef/#ifndef} preprocessing
directives.  This option will cause the name to be added to the
list of defined values.  If you supply a define value as well,
it can be used in the template with the @code{_ENV} expression
function.

@node autogen undefine
@section undefine Option
@cindex autogen-undefine

Just like 'C', AutoGen uses @code{#ifdef/#ifndef} preprocessing
directives.  This option will cause the name to be removed from the
list of defined values.
@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@end ignore
@page
@node Installation
@chapter What Gets Installed Where
@cindex Installation

There are several files that get installed.  The number depend
whether or not both shared and archive libraries are to be
installed.  The following assumes that everything is installed
relative to @code{$prefix}.  You can, of course, use
@code{configure} to place these files where you wish.

@strong{NB}:  AutoGen does not contain any compiled-in path names.
All support directories are located via option processing
and the environment variable @code{HOME}.

The installed files are:

@enumerate
@item
The executables in @file{bin} (autogen, getdefs and columns).

@item
The link library(ies) as @file{lib/libopts.*}.

@item
An include file in @file{include/options.h}, needed for
Automated Option Processing (see next chapter).

@item
Six template files in @file{share/autogen}, needed for
Automated Option Processing (@xref{AutoOpts}.) and for documenting
your program.  (@xref{documentation attributes}.)

@item
Info-style help files as @file{info/autogen.info*}.
These files document AutoGen, the option processing
library AutoOpts, and several add-on components.
@end enumerate

This program, library and supporting files can be installed
with two commands:

@itemize @bullet
@item
<src-dir>/configure [ <configure-options> ]
@item
make install
@end itemize

However, you may wish to insert @code{make}
and @code{make check} before the second command.

If you do perform a @code{make check} and there are any failures, you
will find the results in @code{tests/FAILURES}.  Needless to say, I
would be interested in seeing the contents of those files and any
associated messages.  If you choose to go on and analyze one of these
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:

@example
make TESTS=test-name.test check
@end example

All of the AutoGen tests are written to honor the contents of the
@t{VERBOSE} environment variable.  Normally, any commentary generated
during a test run is discarded unless the @t{VERBOSE} environment
variable is set.  So, to see what is happening during the test, you
might invoke the following with @i{bash} or @i{ksh}:

@example
VERBOSE=1 make TESTS="for.test forcomma.test" check
@end example

Or equivalently with @i{csh}:

@example
env VERBOSE=1 make TESTS="for.test forcomma.test" check
@end example

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
autoopts.texi input
@end ignore
@page
@node AutoOpts
@chapter Automated Option Processing
@cindex autoopts

Included with AutoGen is a tool that virtually eliminates the hassle of
processing options and keeping man pages, info docs and usage text up to
date.  This package allows you to specify several program attributes, up
to a hundred option types and many option attributes.  From this, it
then produces all the code necessary to parse and handle the command
line and initialization file options, and the documentation that should
go with your program as well.

AutoOpts is distributed under The GNU General Public License with the
Library extentions (LGPL).

@menu
* Features::          AutoOpts Features
* Quick Start::       Quick Start
* opts.def::          Option Definitions File
* Macro Usage::       User Interface Usage
* option descriptor:: Option Descriptor File
* Using AutoOpts::    Using AutoOpts
* shell options::     AutoOpts for Shell Scripts
* AutoInfo::          Automated @samp{Invoking Info} Doc
* AutoMan pages::     Automated Man Pages
@end menu

@node Features
@section AutoOpts Features
@cindex features

AutoOpts supports option processing; option state saving; and
program documentation with the following features:

@enumerate
@item
Process initialization/rc files
(if specified in the definition and the file(s) exist).

@item
Process environment variable initializations
(if specified in the definition and the variable(s) exist).

@item
Processes the command line options.  Long options are recognized without
case sensitivity, and they may be abbreviated to the minimum length that
is unique within the set of program options.

@item
Store the option state into an initialization/rc file
(if init files are specified and the save options option
is specified on the command line).

@item
Verify that required options are present the
required minimum number of times on the command line.

@item
Verify that options do not appear more than the maximum number
of times.

@item
Verify that conflicting options do not appear together.

@item
Verify that options that require the presence of other options
are, in fact, used in the presence of other options.

@item
Provides a callable routine to parse a line of text as if
it were a line from one of the RC/INI files.  (Consequently,
you may stash options in a text file you process and pass
the relevant text for option processing.)

@item
Produce usage information for the library routine @samp{optionUsage()}.
It will print out the invocation syntax and a list of every option.

@noindent
Three levels of usage are supported:

@table @samp
@item Brief
as when an option error is encountered.

@item Normal
as when @samp{--help} is specified on the command line.

@item Extended
when @samp{--more-help} is specified on the command line.  This output is
passed through a pager (the @code{more} program, if the PAGER
environment variable is not set).  This output differs from normal help
only if a usage detail is specified.
@end table

@item
By adding a @samp{doc} attribute to each option, AutoGen will also be able
to produce a man page and the @samp{invoking} section of a texinfo document.
These documentation templates will also weave in the @samp{explain} and
@samp{detail} program attributes as well.

@item
Produce a #define for the program version that can be
used by the library routine @samp{doVersion()}.

@item
If @code{TEST_MAIN} is defined when AutoGen is run, the
output @file{.c} file will contain a main routine that will
be compiled when @code{TEST_<prog-name>_OPTS} is defined.
@xref{shell options}.
If you choose to compile this program, it is currently
capable of producing one of three results:

@enumerate a
@item
If @code{TEST_MAIN} is defined to contain 3 or fewer characters
(e.g., "yes"), then it will produce a program that processes the
arguments and writes to standard out portable shell commands
containing the digested options.

@item
If @code{TEST_MAIN} is set to @code{putShellParse}, it will produce 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.

@item
If @code{TEST_MAIN} is set to anything else, it must be
a routine name and that routine will be called with
a pointer to the option descriptions as the single argument.
You must supply this routine and, obviously, you can
cause it to do whatever you wish it to do.
@end enumerate
@end enumerate

Furthermore, the @samp{long-name} versions of the options can have
enabling or disabling prefixes.  The option processing supports POSIX
compliant options.  With the @samp{long_opts} attribute set, it also
supports GNU standard long options.  There is automatic support for
@samp{help}, @samp{more-help}, a GNU-compliant @samp{version},
@samp{save-opts} and @samp{load-opts} options.  Finally, there are
facilities in place to allow libraries to intermingle their command line
and initialization options in with the client program options.

@node Quick Start
@section Quick Start
@cindex Quick Start

Since it is generally easier to start with a simple example than it is
to look at the options that AutoGen uses itself, here is a very simple
AutoOpts example.  You can copy this example out of the Info file and
into a source file to try it.  You can then embellish it into what you
really need.

Assume you have a program named @code{check} that takes
two options:

@enumerate
@item
A list of directories to check over for whatever it is @code{check} does.
You want this option available as a POSIX-style flag option
and a GNU long option.  You want to allow as many of these
as the user wishes.
@item
An option to show or not show the definition tree being used.
Only one occurrence is to be allowed, specifying one or the other.
@end enumerate

@noindent
First, specify your program attributes and its options to AutoOpts,
as with the following example.

@smallexample
AutoGen Definitions options;
prog_name     = check;
prog_title    = "Checkout Automated Options";
long_opts;

flag = @{
    name      = check_dirs;
    value     = L;        /* flag style option character */
    flag_arg  = ":";      /* option argument marker      */
    max       = NOLIMIT;  /* occurrence limit (none)     */
    stack_arg;            /* save opt args in a stack    */
    descrip   = "Checkout directory list";
@};

flag = @{
    name      = show_defs;
    descrip   = "Show the definition tree";
    disable   = dont;     /* mark as enable/disable type */
                          /* option.  Disable as `dont-' */
@};
@end smallexample

@noindent
Then perform the following steps:

@enumerate
@item
@code{autogen -L $prefix/share/autogen -DTEST_MAIN=yes checkopt.def}
@item
@code{cc -o check -DTEST_CHECK_OPTS -g checkopt.c -L $prefix/lib -lopts}
@end enumerate

@noindent
And now, @code{./check --help} yields:

@smallexample
check - Checkout Automated Options
USAGE:  check [-<flag> [<val>]]... [--<name>[@{=| @}<val>]]... 
  Flg Arg Option-Name    Description
   -L YES check-dirs     Checkout directory list
                                - may appear without limit
      no  show-defs      Show the definition tree
                                - disabled as --dont-show-defs
   -? no  help           Display usage information and exit
   -! no  more-help      Extended usage information passed thru pager

Options may be specified by doubled markers and their name
or by a single marker and the flag character/option value.
@end smallexample

Normally, however, you would compile @file{checkopt.c} as in:

@smallexample
cc -o checkopt.o -I$prefix/include -c checkopt.c
@end smallexample

and link @file{checkopt.o} with the rest of your program.
The main program causes the options to be processed
by calling @code{optionProcess}:

@smallexample
main( int argc, char** argv )
@{
  @{
    int optct = optionProcess( &checkOptions, argc, argv );
    argc -= optct;
    argv += optct;
  @}
@end smallexample

The options are tested and used as in the following fragment:

@smallexample
  if (HAVE_OPT( SHOW_DEFS )) @{
    int    dirct = STACKCT_OPT( CHECK_DIRS );
    char** dirs  = STACKLST_OPT( CHECK_DIRS );
    while (dirct-- > 0) @{
      char* dir = *dirs++;
      ...
@end smallexample

A lot of magic happens to make this happen.
The rest of this chapter will help you learn how to specify
the option processing and how to examine the resulting state.

@node opts.def
@section Option Definitions File
@cindex opts.def

This file contains the AutoGen definitions that describe the options for
a particular program.  There are several groups of definitions.  The
first describes the program and over-all option processing attributes.
The second group describes the name, usage and other attributes related
to each option.  The third group are used for documenting your program
and are @strong{not} used for command line processing.  The last section
below will describe the command line options that are automatically
provided by AutoOpts.

The list of program and option attributes is quite extensive.  Keep in
mind that the majority are rarely used and can be safely ignored.
However, when you have special option processing requirements, the
flexibility is there.

@menu
* program attributes::        Program Description Attributes
* option attributes::         Option Attributes
* documentation attributes::  Man and Info doc Attributes
* standard options::          Automatically Supported Options
@end menu

@node program attributes
@subsection Program Description Attributes
@cindex program attributes

The following global option definitions are used to define attributes of
the entire program.  The first two are required of every program.  The
rest have been alphabetized.  Except as noted, there may be only one
copy of each of these definitions:

@table @samp
@cindex prog_name
@item prog_name
This attribute is required and its value must follow legal C syntax for
variables.  Because of this constraint, if the file name of your program
is different from this, then use the @var{prog_file_name}, described
below.

@cindex prog_title
@item prog_title
This attribute is required and may be any descriptive text.

@cindex prog_desc
@item prog_desc @strong{and}
@cindex opts_ptr
@itemx opts_ptr
These define global pointer variables that point to the program
descriptor and the first option descriptor for a library option.  This
is intended for use by certain libraries that need command line and/or
initialization file option processing.  These definitions have no effect
on the option template output, but are used for creating a library
interface file.  Normally, the first "option" for a library will be a
documentation option that cannot be specified on the command line, but
is marked as @code{settable}.  The library client program will invoke the
@code{SET_OPTION} macro which will invoke a handler function that will
finally set these global variables.

@cindex allow_errors
@item allow_errors
The presence of this attribute indicates ignoring any command line
option errors.  This may also be turned on and off by invoking the
macros @code{ERRSKIP_OPTERR} and @code{ERRSTOP_OPTERR} from the
generated interface file.

@cindex argument
@item argument
Specifies the syntax of the arguments that @strong{follow} the options.
It may not be empty, but if it is not supplied, then option processing
must consume all the arguments.  If it is supplied and starts with an
open bracket (@code{[}), then there is no requirement on the presence or
absence of command line argument following the options.  Lastly, if it
is supplied and does not start with an open bracket, then option
processing must @strong{not} consume all of the command line arguments.

@cindex copyright
@item copyright

The @code{copyright} is a structured value containing three to five
values.  If @code{copyright} is used, then the first three are required.

@enumerate
@item
@file{date} - the list of applicable dates for the copyright.
@item
@file{owner} - the name of the copyright holder.
@item
@file{type} - specifies the type of copyright.  AutoOpts/AutoGen will
automatically support the text of the GNU Public License (@file{GPL}),
the GNU Public License with Library extensions (@file{LGPL}), the Free
BSD license (@file{BSD}), and a write-it-yourself copyright notice
(@file{NOTE}).  Only these values are recognized.
@item
@file{text} - the text of the copyright notice.  It is only needed
if @file{type} is set to @file{NOTE}.
@item
@file{author} - in case the author name is to appear in the documentation
and is different from the copyright owner.
@end enumerate
@*
An example of this might be:
@example
copyright = @{
    date  = "1992-<=`date +%Y`=>";
    owner = "Bruce Korb";
    type  = GPL;
@};
@end example

@cindex prog_file_name
@item prog_file_name
If the @var{prog_name} attribute does not match the program
file name, then this attribute must be supplied so that where
a file name is required, it can be correctly supplied.

@cindex detail
@item detail
This string is added to the usage output when the HELP option is
selected.

@cindex detail_file
@item detail_file
The contents of this file is added to the usage output when the
MORE-HELP option is selected.

@cindex environrc
@item environrc
Indicates looking in the environment for values of variables named
@*
PROGRAM_OPTNAME.

@cindex exerc
@item exerc
Its presence indicates searching the executable directory for an rc
file.  The directory path in @code{argv[0]} will be used, if possible.
Otherwise, @code{pathfind(3)} will be used to locate your program.

@cindex explain
@item explain
Gives additional information whenever the usage routine is invoked..

@cindex export
@item export
This string is inserted into the .h interface file.  Generally used for
global variables or @code{#include} directives required by
@code{flag_code} text and shared with other program text.

@cindex homerc
@item homerc
Specifies either a directory or a file using a specific path (like @code{.}
or @file{/usr/local/share/progname}) or an environment variable (like
@file{$HOME/rc/} or @file{$PREFIX/share/progname}) to use to try to find
the rcfile.  Use as many as you like.  The presence of this attribute
activates the @code{SAVE_OPTS} and @code{LOAD_OPTS} options.

@cindex include
@item include
This string is inserted into the .c file.  Generally used for global
variables required only by @code{flag_code} program text.

@cindex long_opts
@item long_opts
Presence indicates GNU-standard long option processing.  If any options
do not have an option value (flag character) specified, and least one
does specify such a value, then you must specify @code{long_opts}.  If
none of your options specify an option value and you do not specify
@code{long_opts}, then:
@itemize @bullet
@item
all program arguments are processed as named options
@item
the flag markers @code{-} and @code{--} are completely optional
@item
the @code{argument} program attribute is disallowed
@end itemize

@cindex prefix
@item prefix
This value is inserted into @strong{all} global names.  This will
disambiguate them if more than one set of options are to be compiled
into a single program.

@cindex rcfile
@item rcfile
Specifies the initialization file name.  This is only useful if you
have provided at least one @code{homerc} attribute.
@noindent
default: .<prog_name>rc

@cindex test_main
@item test_main
Creates a test main procedure for testing option processing.  The
resulting program may also be used to process the arguments of a shell
script.  You would use it thus:

@example
eval `./programopts $@@`
if [ -z "$@{OPTION_CT@}" ] ; then exit 1 ; fi
shift $@{OPTION_CT@}
@end example

@cindex usage
@item usage
Optionally names the usage procedure, if the library routine
@code{optionUsage()} does not work for you.  If you specify
@code{gnu_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.

@cindex version
@item version
Specifies the program version and activates the VERSION option.
@end table

@node option attributes
@subsection Option Attributes
@cindex option attributes

For each option you wish to specify, you must have a block macro named
@code{flag} defined.  It @strong{MUST} contain at least two defined text
macros named @code{name} and @code{descrip}.  If any options do not have a
@code{value} macro, then the @code{long_opts} global text macro must be
defined.  As a special exception, if no options have a @code{value}
@strong{and} @code{long_opts} is not defined @strong{and} @code{argument} is
not defined, then all arguments to the program are named and the @code{-}
and @code{--} command line markers are completely optional.

There are four categories of option attributes.  The fifth section below
describes what data are available for writing option processing code.

@menu
* Required Attributes::         Required Attributes
* Optional Attributes::         Singly Optional Attributes
* Multiply Optional::           Multiply Optional Attributes
* Option Processing::           Special Option Processing
* Option Processing Data::      Data for Option Processing
@end menu

@node Required Attributes
@subsubsection Required Attributes
@cindex Required Attributes

Every option must have exactly one copy of both of these attributes.

@table @samp
@cindex name
@item name
Long name for the option.  Even if you are not accepting long options
and are only accepting flags, it must be provided.  AutoOpts generates
private, named storage that require this name.

@cindex descrip
@item descrip
Except for documentation options, a @strong{very} brief description
of the option.  About 40 characters on one line, maximum.
It appears on the @code{usage()} output next to the option name.
Documentation options appear on one or more lines by themselves,
visually separating the usage options.
@end table

@node Optional Attributes
@subsubsection Singly Optional Attributes
@cindex Optional Attributes

These option attributes are optional.  Any that do appear in the
definition of a flag, may appear only once.

@table @samp
@cindex documentation
@item documentation
If present, disables all other attributes except @code{settable},
@code{call_proc} and @code{flag_code}.  @code{settable} must be and is
only specified if @code{call_proc} or @code{flag_code} has been specified.
When present, the @code{descrip} attribute will be displayed only
when the @code{--help} option has been specified.  It will be displayed
flush to the left hand margin and may consist of one or more lines
of text.  The name of the option will not be printed.

The option may be made settable if, for example, you are supplying
options to a client program.  In that fashion, your handler routine for
the documentation option can save the address of the program descriptor
and your first option (@code{prog_desc} and @code{opts_ptr}) in global
pointers.

@cindex value
@item value
The flag character to specify for traditional option flags.  e.g. @code{-L}.

@cindex flag_arg
@item flag_arg
Define the argument type.  Omit attribute for disallowing an option
argument.  Set to the empty string (@code{flag_arg = "";}) for optional
arguments.  Set to ":" for string arguments with no default
value.  Make the first character a @code{=} for arguments that must be
integers.  Anything else is a default value for a required option
argument.  (i.e.  @code{OPT_VALUE(NAME)} returns the default value if
the option has not been set during processing.)

@cindex min
@item min
Minimum occurrence count.  If present, then the option @strong{must}
appear on the command line.  Preset values do not count towards the
minimum occurrence count.

@cindex max
@item max
Maximum occurrence count (invalid if @code{disable} present).

@cindex enable
@item enable
Long-name prefix for enabling the option (invalid if @code{disable}
@strong{not} present).

@cindex disable
@item disable
Prefix for disabling (inverting sense of) the option.

@cindex enabled
@item enabled
If default is for option being enabled.  (Otherwise, the OPTST_DISABLED
bit is set at compile time.)

@cindex no_preset
@item no_preset
If presetting this option is not allowed.  (Thus, environment variables
and values set in rc/ini files will be ignored.)

@cindex settable
@item settable
If the option can be set outside of option processing.  If this
attribute is defined, special macros for setting this particular option
will be inserted into the interface file.  For example,
@code{TEMPL_DIRS} is a settable option for AutoGen, so a macro named
@code{SET_OPT_TEMPL_DIRS(a)} appears in the interface file.  This
attribute interacts with the @code{documentation} attribute.

@cindex equivalence
@item equivalence
Generally, when several options are mutually exclusive and basically serve
the purpose of selecting one of several processing modes, these options
can be considered an equivalence class.  Sometimes, it is just easier to
deal with them as such.

For an option equivalence class, there is a single occurrence counter
for all the members of the class.  All members of the equivalence class
must contain the same equivalenced-to option, including the
equivalenced-to option itself.  Thus, it must be a member.

As an example, @code{cpio(1)} has three options @code{-o}, @code{-i},
and @code{-p} that define the operational mode of the program
(@code{create}, @code{extract} and @code{pass-through}, respectively).
They form an equivalence class from which one and only one member must
appear on the command line.  If @code{cpio} were an AutoOpt-ed program,
then each of these option definitions would contain:

@example
equivalence = create;
@end example

and the program would be able to determine the operating mode
with code that worked something like this:

@example
switch (WHICH_IDX_CREATE) @{
case INDEX_OPT_CREATE:       ...
case INDEX_OPT_EXTRACT:      ...
case INDEX_OPT_PASS_THROUGH: ...
default:    /* cannot happen */
@}
@end example

@cindex default
@item default
If your program processes its arguments in named-option mode, then you
may select @strong{one} of your options to be the default option.  That
option must have a required option argument.

If you have done this, then any arguments that do not match an option
name and do not contain an equal sign (@code{=}) will be interpreted as
option arguments to the default option.
@end table

@node Multiply Optional
@subsubsection Multiply Optional Attributes
@cindex Multiply Optional

These attributes may be used as many times as you need.
They are used at the end of the option processing to verify
that the context within which each option is found does not
conflict with the presence or absence of other options.

This is not a complete cover of all possible conflicts and
requirements, but it simple to implement and covers the
more common situations.

@table @samp
@cindex flags_must
@item flags_must
one entry for every option that @strong{must} be present
when this option is present

@cindex flags_cant
@item flags_cant
one entry for every option that @strong{cannot} be present
when this option is present
@end table

@node Option Processing
@subsubsection Special Option Processing
@cindex Option Processing

The first two attributes interact with the @code{documentation} and
@code{settable} attributes.  See their documentation above.

Pick zero or one of the next four:

@table @samp
@cindex flag_code
@item flag_code
statements to execute when the option is encountered.
The generated procedure will look like this:

@example
static void
doOpt<name>( tOptions* pOptions, tOptDesc* pOptDesc )
@{
<flag_code>
@}
@end example

Only certain fields within the @code{tOptions} and @code{tOptDesc}
structures may be accessed.  @xref{Option Processing Data}.

@cindex call_proc
@item call_proc
external procedure to call when option is encountered.  The calling
sequence must conform to the sequence defined above for the generated
procedure, @code{doOpt<name>}.  It has the same restrictions
regarding the fields within the structures passed in as arguments.
@xref{Option Processing Data}.

@cindex flag_proc
@item flag_proc
Name of another option whose @code{flag_code} can be executed
when this option is encountered.

@cindex stack_arg
@item 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 (@code{STACKCT_OPT(NAME)}) and to obtain a
pointer to a list of pointers to the argument values
(@code{STACKLST_OPT(NAME)}).
@end table

@node Option Processing Data
@subsubsection Data for Option Processing
@cindex Option Processing Data

The following fields may be used in the following ways and may be used
for read only.  The first set is addressed from the @code{tOptDesc*}
pointer:

@table @samp
@cindex optIndex
@item optIndex
@cindex optValue
@item optValue
These may be used by option procedures to determine which option they
are working on (in case they handle several options).

@cindex optActualIndex
@item optActualIndex
@cindex optActualValue
@item optActualValue
These may be used by option procedures to determine which option was
used to set the current option.  This may be different from the above if
the options are members of an equivalence class.

@cindex optOccCt
@item optOccCt
If AutoOpts is processing command line arguments, then this value will
contain the current occurrence count.  During the option preset phase
(reading rc/ini files and examining environment variables), the value is
zero.

@cindex fOptState
@item fOptState
The field may be tested for the following bit values
(prefix each name with @code{OPTST_}, e.g. @code{OPTST_INIT}):

@table @samp
@item INIT
Initial compiled value.  As a bit test, it will always yield FALSE.

@item SET
The option was set via the @code{SET_OPT()} macro.

@item PRESET
The option was set via an RC/INI file, or a call to the
@code{optionLoadLine()} routine.

@item DEFINED
The option was set via a command line option.

@item SET_MASK
This is a mask of flags that show the set state, one of the
above four values.

@item EQUIVALENCE
This bit is set when the option was selected by an equivalenced option.

@item 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 @code{disabled}.)
@end table

@cindex pzLastArg
@item pzLastArg
Pointer to the latest argument string.  BEWARE:  If the argument type is
numeric, this will be the argument @strong{value} and not a pointer to a
string.
@end table

The following two fields are addressed from the @code{tOptions*} pointer:

@table @samp
@cindex pzProgName
@item pzProgName
Points to a NUL-terminated string containing the current program
name, as retrieved from the argument vector.

@cindex pzProgPath
@item pzProgPath
Points to a NUL-terminated string containing the full path of
the current program, as retrieved from the argument vector.
(If available on your system.)

@end table

Note:  these fields get filled in during the first call to
@code{optionProcess()}.  All other fields are private, for the exclusive
use of AutoOpts code and is subject to change.

@node documentation attributes
@subsection Man and Info doc Attributes
@cindex documentation attributes

AutoOpts includes AutoGen templates for producing abbreviated man pages
and for producing the invoking section of an info document.  To take
advantage of these templates, you must add several attributes to your
option definitions.

@cindex doc
First, every @code{flag} definition must have a @code{doc} attribute
defined and many will need an @code{arg_name} attribute as well.  The
@code{doc} text should be in plain sentences with minimal formatting.  The
Texinfo commands @code{@@code}, and @code{@@var} will have its enclosed
text made into @strong{\fB} entries in the man page, and the @code{@@file}
text will be made into @strong{\fI} entries.  The @code{arg_name} attribute
is used to display the option's argument in the man page.

@cindex detail
@cindex prog_man_descrip
@cindex prog_info_descrip
Then, you need to supply a brief description of what your program does.
If you already have a @code{detail} definition, this may be sufficient.
If not, or if you need special formatting for one of the manual formats,
then you will need either a definition for @code{prog_man_descrip} or
@code{prog_info_descrip} or both.  These will be inserted verbatim
in the man page document and the info document, respectively.

@cindex man_doc
Finally, if you need to add man page sections like @code{SEE ALSO} or
@code{USAGE} or other, put that text in a @code{man_doc} definition.  This
text will be inserted verbatim in the man page after the @code{OPTIONS}
section and before the @code{AUTHOR} section.

@node standard options
@subsection Automatically Supported Options
@cindex standard options

AutoOpts provides automated support for five options.  @code{help} and
@code{more-help} are always provided.  @code{version} is provided if
@code{version} is defined in the option definitions.  @code{save-opts}
and @code{load-opts} are provided if at least one @code{homerc} is
defined.

Below are the option names and flag values.  The flags are activated if
and only if at least one user-defined option also uses a flag value.

@table @samp
@item help -?
This option will immediately invoke the @code{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 @code{detail} text macro.

@item more-help -!
This option is identical to the @code{help} option, except that
it also includes the contents of the @code{detail-file} file
(if provided and found), plus the output is passed through
a pager program.  (@code{more} by default, or the program identified
by the @code{PAGER} environment variable.)

@item version -v
This will print the program name, title and version.
If it is followed by the letter @code{c} and
a value for @code{copyright} and @code{owner} have been provided,
then the copyright will be printed, too.
If it is followed by the letter @code{n}, then the full
copyright notice (if available) will be printed.

@item save-opts ->
This option will cause the option state to be printed in
RC/INI file format when option processing is done but not
yet verified for consistency.  The program will terminate
successfully without running when this has completed.
Note that for most shells you will have to quote or escape the
flag character to restrict special meanings to the shell.

The output file will be the RC/INI file name (default or provided
by @code{rcfile}) in the last directory named in a @code{homerc}
definition

@item 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 RC/INI files, but will not be loaded until
the option is actually processed.  This can also be used
within an RC/INI file causing them to nest.

It is ultimately intended that specifying the option,
@code{no-load-opts} will suppress the processing of rc/ini files and
environment variables.  To do this, AutoOpts must first implement
pre-scanning of the options, environment and rc files.
@end table

@node Macro Usage
@section User Interface Usage
@cindex Macro Usage

The user interface for access to the argument information is completely
defined in the generated header file and in the portions of the
distributed file "options.h" that are marked "public".

In the following macros, text marked @code{<OPT_NAME>} or @code{optname}
is the name of the option @strong{in upper case} and @strong{segmented
with underscores @code{_}}.  The macros and enumerations defined in the
options header (interface) file are used as follows:

To see how these @code{#define} macros are used in a program,
the reader is referred to the several @file{opts.h} files
included with the AutoGen sources.

@menu
* CLEAR_OPT::               CLEAR_OPT( <NAME> ) - Clear Option Markings
* COUNT_OPT::               COUNT_OPT( <NAME> ) - Definition Count
* DESC::                    DESC( <NAME> ) - Option Descriptor
* DISABLE_OPT_name::        DISABLE_OPT_name - Disable an option
* ENABLED::                 ENABLED( <NAME> ) - Is Option Enabled?
* ERRSKIP_OPTERR::          ERRSKIP_OPTERR - Ignore Option Errors
* ERRSTOP_OPTERR::          ERRSTOP_OPTERR - Stop on Errors
* HAVE_OPT::                HAVE_OPT( <NAME> ) - Have this option?
* ISSEL_OPT::               ISSEL_OPT( <NAME> ) - Is Option Selected?
* ISUNUSED_OPT::            ISUNUSED_OPT( <NAME> ) - Never Specified?
* OPTION_CT::               OPTION_CT - Full Count of Options
* OPT_ARG::                 OPT_ARG( <NAME> ) - Option Argument String
* OPT_VALUE_name::          OPT_VALUE_name - Option Argument Value
* RESTART_OPT::             RESTART_OPT( n ) - Resume Option Processing
* SET_OPT_name::            SET_OPT_name - Force an option to be set
* STACKCT_OPT::             STACKCT_OPT( <NAME> ) - Stacked Arg Count
* STACKLST_OPT::            STACKLST_OPT( <NAME> ) - Argument Stack
* START_OPT::               START_OPT - Restart Option Processing
* STATE_OPT::               STATE_OPT( <NAME> ) - Option State
* USAGE::                   USAGE( exit-code ) - Usage invocation macro
* VALUE_OPT_name::          VALUE_OPT_name - Option Flag Value
* VERSION::                 VERSION - Version and Full Version
* WHICH_IDX_name::          WHICH_IDX_name - Which Equivalenced Index
* WHICH_OPT_name::          WHICH_OPT_name - Which Equivalenced Option
* teOptIndex::              teOptIndex - Option Index and Enumeration
* OPTIONS_STRUCT_VERSION::  OPTIONS_STRUCT_VERSION - active version
@end menu

@node CLEAR_OPT
@subsection CLEAR_OPT( <NAME> ) - Clear Option Markings
@findex CLEAR_OPT

Make as if the option had never been specified.
@code{HAVE_OPT(<NAME>)} will yield @code{FALSE}
after invoking this macro.

@node COUNT_OPT
@subsection COUNT_OPT( <NAME> ) - Definition Count
@findex COUNT_OPT

This macro will tell you how many times the option was
specified on the command line.  It does not include counts
of preset options.

@example
if (COUNT_OPT( NAME ) != desired-count) @{
    make-an-undesirable-message.
@}
@end example

@node DESC
@subsection DESC( <NAME> ) - Option Descriptor
@findex DESC

This macro is used internally by other AutoOpt macros.
It is not for general use.  It is used to obtain the option description
corresponding to its @strong{UPPER CASED} option name argument.
This is primarily used in other macro definitions.

@node DISABLE_OPT_name
@subsection DISABLE_OPT_name - Disable an option
@findex DISABLE_OPT_name

This macro is emitted if it is both settable
and it can be disabled.  If it cannot be disabled, it may
always be CLEAR-ed (see above).

The form of the macro will actually depend on whether the
option is equivalenced to another, and/or has an assigned
handler procedure.  Unlike the @code{SET_OPT} macro,
this macro does not allow an option argument.

@example
DISABLE_OPT_NAME;
@end example

@node ENABLED
@subsection ENABLED( <NAME> ) - Is Option Enabled?
@findex ENABLED

Yields true if the option defaults to disabled and
@code{ISUNUSED_OPT()} would yield true.  It also yields true if
the option has been specified with a disablement prefix,
disablement value or the @code{DISABLE_OPT_NAME} macro was invoked.

@node ERRSKIP_OPTERR
@subsection ERRSKIP_OPTERR - Ignore Option Errors
@findex ERRSKIP_OPTERR

When it is necessary to continue (return to caller)
on option errors, invoke this option.  It is reversible.
@xref{ERRSTOP_OPTERR}.

@node ERRSTOP_OPTERR
@subsection ERRSTOP_OPTERR - Stop on Errors
@findex ERRSTOP_OPTERR

After invoking this macro, if @code{optionProcess()}
encounters an error, it will call @code{exit(1)} rather than return.
This is the default processing mode.  It can be overridden by
specifying @code{allow_errors} in the definitions file,
or invoking the macro @xref{ERRSKIP_OPTERR}.

@node HAVE_OPT
@subsection HAVE_OPT( <NAME> ) - Have this option?
@findex HAVE_OPT

This macro yields true if the option has been specified
in any fashion at all.  It is used thus:

@example
if (HAVE_OPT( NAME )) @{
    <do-things-associated-with-opt-name>;
@}
@end example

@node ISSEL_OPT
@subsection ISSEL_OPT( <NAME> ) - Is Option Selected?
@findex ISSEL_OPT

This macro yields true if the option has been
specified either on the command line or via a SET/DISABLE macro.

@node ISUNUSED_OPT
@subsection ISUNUSED_OPT( <NAME> ) - Never Specified?
@findex ISUNUSED_OPT

This macro yields true if the option has
never been specified, or has been cleared via the
@code{CLEAR_OPT()} macro.

@node OPTION_CT
@subsection OPTION_CT - Full Count of Options
@findex OPTION_CT

The full count of all options, both those defined
and those generated automatically by AutoOpts.  This is primarily
used to initialize the program option descriptor structure.

@node OPT_ARG
@subsection OPT_ARG( <NAME> ) - Option Argument String
@findex OPT_ARG

The option argument value as a pointer to string.
Note that argument values that have been specified as numbers
are stored as numbers.  For such options, use instead the
@code{OPT_VALUE_name} define.  It is used thus:

@example
if (HAVE_OPT( NAME )) @{
    char* p = OPT_ARG( NAME );
    <do-things-with-opt-name-argument-string>;
@}
@end example

@node OPT_VALUE_name
@subsection OPT_VALUE_name - Option Argument Value
@findex OPT_VALUE_name

This macro gets emitted only for options that
take numeric arguments.  The macro yields a word-sized integer
containing the numeric value of the option argument.

@example
int opt_val = OPT_VALUE_NAME;
@end example

@node RESTART_OPT
@subsection RESTART_OPT( n ) - Resume Option Processing
@findex RESTART_OPT

If option processing has stopped (either because of an error
or something was encountered that looked like a program argument),
it can be resumed by providing this macro with the index @code{n}
of the next option to process and calling @code{optionProcess()} again.

@node SET_OPT_name
@subsection SET_OPT_name - Force an option to be set
@findex SET_OPT_name

This macro gets emitted only when the given
option has the @code{settable} attribute specified.

The form of the macro will actually depend on whether the
option is equivalenced to another, has an option argument
and/or has an assigned handler procedure.  If the option has
an argument, then this macro will too.

@example
SET_OPT_NAME( "string-value" );
@end example

@node STACKCT_OPT
@subsection STACKCT_OPT( <NAME> ) - Stacked Arg Count
@findex STACKCT_OPT

When the option handling attribute is specified
as @code{stack_arg}, this macro may be used to determine how
many of them actually got stacked.

Do not use this on options that have not been stacked or has not been
specified (the @code{stack_arg} attribute must have been specified,
and @code{HAVE_OPT(<NAME>)} must yield TRUE).
Otherwise, you will likely page fault.

@example
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);
@}
@end example

@node STACKLST_OPT
@subsection STACKLST_OPT( <NAME> ) - Argument Stack
@findex STACKLST_OPT

The address of the list of pointers to the
option arguments.  The pointers are ordered by the order in
which they were encountered in the option presets and
command line processing.

Do not use this on options that have not been stacked or has not been
specified (the @code{stack_arg} attribute must have been specified,
and @code{HAVE_OPT(<OPTION>)} must yield TRUE).
Otherwise, you will likely page fault.

@example
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);
@}
@end example

@node START_OPT
@subsection START_OPT - Restart Option Processing
@findex START_OPT

This is just a shortcut for RESTART_OPT(1) (@xref{RESTART_OPT}.)

@node STATE_OPT
@subsection STATE_OPT( <NAME> ) - Option State
@findex STATE_OPT

If you need to know if an option was set because of
presetting actions (RC/INI processing or environment variables),
versus a command line entry versus one of the SET/DISABLE macros,
then use this macro.  It will yield one of four values:
@code{OPTST_INIT}, @code{OPTST_SET}, @code{OPTST_PRESET}
or @code{OPTST_DEFINED}.  It is used thus:

@example
switch (STATE_OPT( NAME )) @{
    case OPTST_INIT:
        not-preset, set or on the command line.  (unless CLEAR-ed)

    case OPTST_SET:
        option set via the SET_OPT_NAME() macro.

    case OPTST_PRESET:
        option set via an RC/INI file or environment variable

    case OPTST_DEFINED:
        option set via a command line option.

    default:
        cannot happen :)
@}
@end example

@node USAGE
@subsection USAGE( exit-code ) - Usage invocation macro
@findex USAGE

This macro invokes the procedure registered to display
the usage text.  Normally, this will be @code{optionUsage} from the
AutoOpts library, but you may select another procedure by specifying
@code{usage = "proc_name"} program attribute.  This procedure must
take two arguments: first, a pointer to the option descriptor, and
second the exit code.  The macro supplies the option descriptor
automatically.  This routine is expected to call @code{exit(3)} with
the provided exit code.

The @code{optionUsage} routine also behaves differently depending
on the exit code.  If the exit code is zero, it is assumed that
assistance has been requested.  Consequently, a little more
information is provided than when displaying usage and exiting
with a non-zero exit code.

@node VALUE_OPT_name
@subsection VALUE_OPT_name - Option Flag Value
@findex VALUE_OPT_name

This is a #define for the flag character used to
specify an option on the command line.  If @code{value} was not
specified for the option, then it is a unique number associated
with the option.  @code{option value} refers to this value,
@code{option argument} refers to the (optional) argument to the
option.

@example
switch (WHICH_OPT_OTHER_OPT) @{
case VALUE_OPT_NAME:
    this-option-was-really-opt-name;
case VALUE_OPT_OTHER_OPT:
    this-option-was-really-other-opt;
@}
@end example

@node VERSION
@subsection VERSION - Version and Full Version
@findex VERSION

If the @code{version} attribute is defined for the program,
then a stringified version will be #defined as PROGRAM_VERSION and
PROGRAM_FULL_VERSION.  PROGRAM_FULL_VERSION is used for printing
the program version in response to the version option.  The version
option is automatically supplied in response to this attribute, too.

You may access PROGRAM_VERSION via @code{programOptions.pzFullVersion}.

@node WHICH_IDX_name
@subsection WHICH_IDX_name - Which Equivalenced Index
@findex WHICH_IDX_name

This macro gets emitted only for equivalenced-to options.  It is used to
obtain the index for the one of the several equivalence class members
set the equivalenced-to option.

@example
switch (WHICH_IDX_OTHER_OPT) @{
case INDEX_OPT_NAME:
    this-option-was-really-opt-name;
case INDEX_OPT_OTHER_OPT:
    this-option-was-really-other-opt;
@}
@end example

@node WHICH_OPT_name
@subsection WHICH_OPT_name - Which Equivalenced Option
@findex WHICH_OPT_name

This macro gets emitted only for equivalenced-to options.  It is used to
obtain the value code for the one of the several equivalence class members
set the equivalenced-to option.

@example
switch (WHICH_OPT_OTHER_OPT) @{
case VALUE_OPT_NAME:
    this-option-was-really-opt-name;
case VALUE_OPT_OTHER_OPT:
    this-option-was-really-other-opt;
@}
@end example

@node teOptIndex
@subsection teOptIndex - Option Index and Enumeration
@findex teOptIndex

This enum defines the complete set of options, both
user specified and automatically provided.  This can be used,
for example, to distinguish which of the equivalenced options
was actually used.

@example
switch (pOptDesc->optActualIndex) @{
case INDEX_OPT_FIRST:
    stuff;
case INDEX_OPT_DIFFERENT:
    different-stuff;
default:
    unknown-things;
@}
@end example

@node OPTIONS_STRUCT_VERSION
@subsection OPTIONS_STRUCT_VERSION - active version

You will not actually need to reference this value, but you need to be
aware that it is there.  It is the first value in the option descriptor
that you pass to @code{optionProcess}.  It contains a magic number and
version information.  Normally, you should be able to work 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 not been
necessary for several years.

@node option descriptor
@section Option Descriptor File
@cindex option descriptor

This is the module that is to be compiled and linked with your program.
It contains internal data and procedures subject to change.  Basically,
it contains a single global data structure containing all the
information provided in the option definitions, plus a number of static
strings and any callout procedures that are specified or required.  You
should never have need for looking at this, except to examine the code
generated for implementing the @code{flag_code} construct.

@node Using AutoOpts
@section Using AutoOpts
@cindex using AutoOpts

To use AutoOpts in your application:

@itemize @bullet
@item
Create a file @samp{myopts.def},
according to the documentation above.
@item
Run AutoGen to create the option interface file (@code{myopts.h})
and the option descriptor code (@code{myopts.c}):

@example
autogen -L $prefix/share/autogen myopts.def
@end example

@item
In all your source files where you need to refer to option state,
@code{#include "myopts.h"} (generated for you).
@item
In your main routine, code something along the lines of:

@example
main( int argc, char** argv )
@{
    @{
        int arg_ct = optionProcess( &myprogOptions, argc, argv );
        argc -= arg_ct;
        if ((argc < ARGC_MIN) || (argc > ARGC_MAX)) @{
            fprintf( stderr, "%s ERROR:  remaining args (%d) "
                     "out of range\n", myprogOptions.pzProgName,
                     argc );

            USAGE( EXIT_FAILURE );
        @}
        argv += arg_ct;
    @}
    if (HAVE_OPT(OPT_NAME))
        respond_to_opt_name();
    ...
@}
@end example

@item
Compile @samp{myopts.c} and link your program
with the following additional arguments:

@example
myopts.o -L $prefix/lib -lopts
@end example
@end itemize

@node shell options
@section AutoOpts for Shell Scripts
@cindex shell options

AutoOpts may be used with shell scripts by automatically creating a
complete program that will process command line options and pass back
the results to the invoking shell by issuing shell variable assignment
commands.  It may also be used to generate portable shell code that can
be inserted into your script.

The functionality of these features, of course, is somewhat constrained
compared with the normal program facilities.  Specifically, you cannot
invoke callout procedures with either of these methods.  Additionally,
if you generate a shell script:

@enumerate
@item
You cannot obtain options from RC/INI files.
@item
You cannot obtain options from environment variables.
@item
You cannot save the option state to an option file.
@item
Option conflict/requirement verification is disabled.
@end enumerate

Both of these methods are enabled by running AutoGen on
the definitions file with the additional global attribute:

@example
test_main [ = proc-to-call ] ;
@end example

If you do not supply a @code{proc-to-call}, it will default
to @code{putBourneShell}.  That will produce a program that
will process the options and generate shell text for the
invoking shell to interpret.  If you supply the name,
@code{putShellParse}, then you will have a program that
will generate a shell script that can parse the options.
If you supply a different procedure name, you will have to
provide that routine and it may do whatever you like.

In summary, you will need to issue approximately the
following two commands to have a working program:

@example
autogen -DTEST_MAIN -L <opt-template-dir> program.def
cc -o program -L <opt-lib-dir> -I <opt-include-dir> \
        -DTEST_program_OPTS program.c -lopts
@end example

The resulting
program can be used within your shell script as follows:

@example
eval `./programopts $@@`
if [ -z "$@{OPTION_CT@}" ] ; then exit 1 ; fi
shift $@{OPTION_CT@}
@end example

If you had used @code{-DTEST_MAIN=putShellParse} instead, then you can,
at this point, merely run the program and it will write the parsing
script to standard out.  You may also provide this program with command
line options to specify the shell script file to create or edit, and you
may specify the shell program to use on the first shell script line.
That program's usage text would look something like this:

@example
<= `
mkdir .tmp
ln $@{top_srcdir@}/getdefs/opts.def .tmp/genshellopt.def
OPTDIR=\`cd $@{top_srcdir@}/autoopts ; pwd\`
cd .tmp
HOME='' $@{AGEXE@} -t40 -L $@{OPTDIR@} -bgenshellopt -- - <<_EOF_
  autogen definitions options;
  test_main = 'putShellParse';
#include genshellopt.def
_EOF_

( $@{CC@} -o genshellopt -DTEST_GETDEFS_OPTS -g -I $@{OPTDIR@} genshellopt.c \\
        -L $@{top_builddir@}/autoopts/.libs/ -lopts \\
        -L $@{top_builddir@}/snprintfv/snprintfv/.libs/ -lsnprintfv 
) > COUT 2>&1

if [ ! -x ./genshellopt ] ; then
echo "compile failed: $@{CC@} -o genshellopt -DTEST_GETDEFS_OPTS -g \\\\
      -I $@{OPTDIR@} genshellopt.c -L $@{OPTDIR@}/.libs/ -lopts \\\\
      -L $@{top_builddir@}/snprintfv/snprintfv/.libs/ -lsnprintfv"
     cat COUT
else
  ( ./genshellopt --help 2>&1 ) |
  sed -e 's;\t;        ;g' -e 's;@{;@@@{;g' -e 's;@};@@@};g'
  cd ..
  rm -rf .tmp
fi ` =>
@end example

@node AutoInfo
@section Automated @samp{Invoking Info} Doc
@cindex AutoInfo

Using the option definitions for an AutoOpt client program, the
@file{aginfo.tpl} template will produce texinfo text that documents the
invocation of your program.  The text emitted is designed to be included
in the full texinfo document for your product.  It is not a
stand-alone document.

Two files will be produced, a @file{.texi} file and a @file{.menu} file.
You should include the @file{.menu} file in your document where you wish
to reference the @samp{invoking} chapter, section or subsection.  The
documentation level is selected by passing a @samp{-DLEVEL=<level-name>}
argument to AutoGen when you build the document.  (See the example
invocation below.)

The @file{.texi} file will contain an introductory paragraph, a menu
and a subordinate section for the invocation usage and for each
documented option.  The introductory paragraph is normally the boiler
plate text:

@example
This chapter documents the @@file@{AutoOpts@} generated usage text
and option meanings for the @@file@{your-program@} program.
@end example

@noindent
However, if your program's option definitions include a
@samp{prog_info_descrip} section, then that is what will be used instead.

These files are produced by invoking the following command:

@example
AutoGen -L $@{prefix@}/share/autogen -T aginfo.tpl \
        -DLEVEL=section your-opts.def
@end example

@noindent
Where @file{$@{prefix@}} is the AutoGen installation prefix
and @file{your-opts.def} is the name of your product's option
definition file.

@node AutoMan pages
@section Automated Man Pages
@cindex AutoMan pages

Using the option definitions for an AutoOpt client program,
the @samp{agman1.tpl} template will produce an nroff document
suitable for use as a @samp{man(1)} page document for a command
line command.  The description section of the document is either
the @samp{prog_man_descrip} text, if present, or the @samp{detail}
text.

Each option in the option definitions file is fully documented
in its usage.  This includes all the information documented
above for each option (@xref{option attributes}.), plus
the @samp{doc} attribute is appended.  Since the @samp{doc}
text is presumed to be designed for @code{texinfo} documentation,
@code{sed} is used to convert some constructs from @code{texi}
to @code{nroff}-for-@code{man}-pages.  Specifically,

@example
convert @@code, @@var and @@samp into \fB...\fP phrases
convert @@file into \fI...\fP phrases
Remove the '@@' prefix from curly braces
Indent example regions
Delete the example commands
Replace @samp{end example} command with ".br"
Replace the @samp{@@*} command with ".br"
@end example

@noindent
This document is produced by invoking the following command:

@example
AutoGen -L $@{prefix@}/share/autogen -T agman1.tpl options.def
@end example

@noindent
Where @file{$@{prefix@}} is the AutoGen installation prefix
and @file{options.def} is the name of your product's option
definition file.

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Absorbed documents from the add-ons

@end ignore
@page
@node Add-Ons
@chapter Add-on packages for AutoGen

This chapter includes several programs that either work closely
with AutoGen (extracting definitions or providing special formatting
functions), or else it is @code{mkmerge}.  I want to promote the
latter as an alternative to the builddir/srcdir schizophrenia.
I hate it. :(

AutoOpts ought to appear in this list also, but since it is
the primary reason why many people would even look into AutoGen
at all, I decided to leave it in the list of chapters.

@menu
* columns Invocation::             Invoking columns
* getdefs Invocation::             Invoking getdefs
@end menu

@page
@ignore
Copy of $f and associated .texi
@end ignore
@node columns Invocation
@section Invoking columns
@cindex columns invocation
@ignore

DO NOT EDIT THIS FILE   (columns.texi)

It has been autogen-ed  Wednesday May 17, 2000 at 11:15:57 AM BST
From the definitions    ../columns/opts.def
and the template file   ../autoopts/aginfo.tpl

@end ignore

This program was designed for the purpose of generating compact,
columnized tables.  It will read a list of text items from standard
in or a specified input file and produce a columnized listing of
all the non-blank lines.  Leading white space on each line is
preserved, but trailing white space is stripped.  Methods of
applying per-entry and per-line embellishments are provided.
See the formatting and separation arguments below.

This program is used by AutoGen to help clean up and organize
its output.

See @file{autogen/src/agfunc.tpl}.

This function was not implemented as an expression function because
either it would have to be many expression functions, or a provision
would have to be added to provide options to expression functions.
Maybe not a bad idea, but it is not being implemented at the moment.

A side benefit is that you can use it outside of AutoGen to columnize
input, a la the @code{ls} command.

@menu
* columns usage::                  columns Usage
* columns by-columns::             by-columns Option
* columns col-width::              col-width Option
* columns columns::                columns Option
* columns first-indent::           first-indent Option
* columns format::                 format Option
* columns indent::                 indent Option
* columns input::                  input Option
* columns line-separation::        line-separation Option
* columns separation::             separation Option
* columns sort::                   sort Option
* columns spread::                 spread Option
* columns tab-width::              tab-width Option
* columns width::                  width Option
@end menu

@node columns usage
@subsection columns Usage
@cindex columns usage

This is the automatically generated usage text for columns:

@example

columns - Columnize Input Text - Ver. 1.1
USAGE:  lt-columns [-<flag> [<val>]]... [--<name>[@{=| @}<val>]]... 
  Flg Arg Option-Name    Description
   -W Num width          Maximum Line Width
   -c Num columns        Desired number of columns
   -w Num col-width      Set width of each column
      Num spread         maximum spread added to column width
   -I YES indent         Line prefix or indentation
      YES first-indent   First line prefix
                                - requires these options:
                                indent
      Num tab-width      tab width
   -s opt sort           Sort input text
   -f YES format         Formatting string for each input
   -S YES separation     Separation string - follows all but last
      YES line-separation string at end of all lines but last
      no  by-columns     Print entries in column order
   -i YES input          Input file (if not stdin)
   -v opt version        Output version information and exit
   -? no  help           Display usage information and exit
   -! no  more-help      Extended usage information passed thru pager

Options may be specified by doubled hyphens and their name
or by a single hyphen and the flag character/option value.

This program was designed for the purpose of generating compact,
columnized tables.  It will read a list of text items from standard
in or a specified input file and produce a columnized listing of
all the non-blank lines.  Leading white space on each line is
preserved, but trailing white space is stripped.  Methods of
applying per-entry and per-line embellishments are provided.
See the formatting and separation arguments below.

This program is used by AutoGen to help clean up and organize
its output.
@end example


@node columns width
@subsection width Option
@cindex columns-width

This option specifies the full width of the output line,
including any start-of-line indentation.  The output will fill
each line as completely as possible, unless the column width has
been explicitly specified.  If the maximum width is less than
the length of the widest input, you will get a single column
of output.

@node columns columns
@subsection columns Option
@cindex columns-columns

Use this option to specify exactly how many columns to produce.
If that many columns will not fit within @var{line_width}, then
the count will be reduced to the number that fit.

@node columns col-width
@subsection col-width Option
@cindex columns-col-width

Use this option to specify exactly how many characters are to be
allocated for each column.  If it is narrower than the widest entry,
it will be over-ridden with the required width.

@node columns spread
@subsection spread Option
@cindex columns-spread

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.

@node columns indent
@subsection indent Option
@cindex columns-indent

If a number, then this many spaces will be inserted at the start of
every line.  Otherwise, it is a line prefix that will be inserted
at the start of every line.

@node columns first-indent
@subsection first-indent Option
@cindex columns-first-indent

If a number, then this many spaces will be inserted at the start of
the first line.  Otherwise, it is a line prefix that will be inserted
at the start of that line.

@node columns tab-width
@subsection tab-width Option
@cindex columns-tab-width

If an indentation string contains tabs, then this value is used to
compute the ending column of the prefix string.

@node columns sort
@subsection sort Option
@cindex columns-sort

Causes the input text to be sorted.  If an argument is supplied,
it is presumed to be a pattern and the sort is based upon the
matched text.  If the pattern starts with or consists of
an asterisk (@code{*}), then the sort is case insensitive.

@node columns format
@subsection format Option
@cindex columns-format

If you need to reformat each input text, the argument to this
option is interpreted as an @code{sprintf(3)} format that is used
to produce each output entry.

@node columns separation
@subsection separation Option
@cindex columns-separation

Use this option if, for example, you wish a comma to appear after
each entry except the last.

@node columns line-separation
@subsection line-separation Option
@cindex columns-line-separation

Use this option if, for example, you wish a backslash to appear at
the end of every line, except the last.

@node columns by-columns
@subsection by-columns Option
@cindex columns-by-columns

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.

@node columns input
@subsection input Option
@cindex columns-input

This program normally runs as a @code{filter}, reading from standard
input, columnizing and writing to standard out.  This option redirects
input to a file.

@page
@ignore
Copy of $f and associated .texi
@end ignore
@node getdefs Invocation
@section Invoking getdefs
@cindex getdefs invocation
@ignore

DO NOT EDIT THIS FILE   (getdefs.texi)

It has been autogen-ed  Wednesday May 17, 2000 at 11:15:55 AM BST
From the definitions    ../getdefs/opts.def
and the template file   ../autoopts/aginfo.tpl

@end ignore

This program extracts AutoGen definitions from a list of source files.
Definitions are delimited by `/*=<entry-type> <entry-name>\n' and `=*/\n'.
From that, this program creates a definition of the following form:

@format
    #line nnn "source-file-name"
    entry_type = @{
        name = entry_name;
        ...
    @};
@end format

The ellipsis `...' is filled in by text found between the two delimiters,
with everything up through the first sequence of asterisks deleted
on every line.  Additionally, if the `<entry-name>' is followed
by a comma, the word `if' and a name `if_name', then the above entry
will appear as:

@format
    #ifdef if_name
    #line nnn "source-file-name"
    entry_type = @{
        name = entry_name;
        ...
    @};
    #endif
@end format

@menu
* getdefs usage::                  getdefs Usage
* getdefs agarg::                  agarg Option
* getdefs assign::                 assign Option
* getdefs autogen::                autogen Option
* getdefs base-name::              base-name Option
* getdefs common-assign::          common-assign Option
* getdefs copy::                   copy Option
* getdefs defs-to-get::            defs-to-get Option
* getdefs filelist::               filelist Option
* getdefs input::                  input Option
* getdefs linenum::                linenum Option
* getdefs ordering::               ordering Option
* getdefs output::                 output Option
* getdefs srcfile::                srcfile Option
* getdefs subblock::               subblock Option
* getdefs template::               template Option
@end menu

@node getdefs usage
@subsection getdefs Usage
@cindex getdefs usage

This is the automatically generated usage text for getdefs:

@example

getdefs - AutoGen Definition Extraction Tool - Ver. 1
USAGE:  getdefs [<option-name>[ =<value>]] ...
   Arg Option-Name   Req?  Description
   YES defs-to-get    opt  Regexp to look for after the "/*="
   opt ordering       opt  Alphabetize or use named file
                                - disabled as --no-ordering
   YES input          YES  Input file to search for defs
                                - a required option
                                - may appear without limit
                                - default option for unnamed options
   YES subblock       opt  subblock definition names
                                - may appear without limit
   opt filelist       opt  Insert source file names into defs

Definition insertion options

   Arg Option-Name   Req?  Description
   YES assign         opt  Global assignments
                                - may appear without limit
   YES common-assign  opt  Assignments common to all blocks
                                - may appear without limit
   YES copy           opt  File(s) to copy into definitions
                                - may appear without limit
   opt srcfile        opt  Insert source file name into each def
   opt linenum        opt  Insert source line number into each def

Definition output disposition options:

   Arg Option-Name   Req?  Description
   YES output         opt  Output file to open
                                - an alternate for autogen
   opt autogen        opt  Invoke AutoGen with defs
                                - disabled as --no-autogen
   YES template       opt  Template Name
   YES agarg          opt  AutoGen Argument
                                - prohibits these options:
                                output
                                - may appear without limit
   YES base-name      opt  Base name for output file(s)
                                - prohibits these options:
                                output

Auto-supported Options:

   Arg Option-Name   Req?  Description
   opt version        opt  Output version information and exit
   no  help           opt  Display usage information and exit
   no  more-help      opt  Extended usage information passed thru pager

All arguments are named options.

This program extracts AutoGen definitions from a list of source files.
Definitions are delimited by `/*=<entry-type> <entry-name>\n' and `=*/\n'.
From that, this program creates a definition of the following form:

    #line nnn "source-file-name"
    entry_type = @{
        name = entry_name;
        ...
    @};

The ellipsis '...' is filled in by text found between the two delimiters,
with everything up through the first sequence of asterisks deleted
on every line.
@end example


@node getdefs defs-to-get
@subsection defs-to-get Option
@cindex getdefs-defs-to-get

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 @code{/*=}.

@node getdefs ordering
@subsection ordering Option
@cindex getdefs-ordering

By default, ordering is alphabetical by the entry name.
Use, @code{no-ordering} if order is unimportant.
Use @code{ordering} with no argument to order without case sensitivity.
Use @code{ordering=<file-name>} if chronological order is important.
getdefs will maintain the text content of @code{file-name}.
@code{file-name} need not exist.


@node getdefs input
@subsection input Option
@cindex getdefs-input

All files that are to be searched for definitions must be named
on the command line.  If an option name is not mentioned in the
command line argument, it is presumed to be this option.  There must
be at least one.

@node getdefs subblock
@subsection subblock Option
@cindex getdefs-subblock

This option is used to create shorthand entries for subblocks.
For example, with:
@*
@code{subblock=arg=argname,type} defined, the text:
@*
@code{arg: this, char *} will then expand to:
@*
@code{arg = @{ argname = this; type = "char *" @};}.


@node getdefs filelist
@subsection filelist Option
@cindex getdefs-filelist

Inserts the name of each input file into the output definitions.
If no argument is supplied, the format will be:
@example
infile = '%s';
@end example
If an argument is supplied, that string will be used for the entry
name instead of @var{infile}.

@node getdefs assign
@subsection assign Option
@cindex getdefs-assign

The argument to each copy of this option will be inserted into
the output definitions, with only a semicolon attached.

@node getdefs common-assign
@subsection common-assign Option
@cindex getdefs-common-assign

The argument to each copy of this option will be inserted into
each output definition, with only a semicolon attached.

@node getdefs copy
@subsection copy Option
@cindex getdefs-copy

The content of each file named by these options will be inserted into
the output definitions.

@node getdefs srcfile
@subsection srcfile Option
@cindex getdefs-srcfile

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:
@example
srcfile = '%s';
@end example
If an argument is supplied, that string will be used for the entry
name instead of @var{srcfile}.

@node getdefs linenum
@subsection linenum Option
@cindex getdefs-linenum

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:
@example
linenum = '%s';
@end example
If an argument is supplied, that string will be used for the entry
name instead of @var{linenum}.

@node getdefs output
@subsection output Option
@cindex getdefs-output

If you are not sending the output to an Augogen process,
you may name an output file instead.

@node getdefs autogen
@subsection autogen Option
@cindex getdefs-autogen

This is the default output mode.  Specifying @code{no-autogen} is
equivalent to @code{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.

@node getdefs template
@subsection template Option
@cindex getdefs-template

Specifies the template name to be used for generating the final output.

@node getdefs agarg
@subsection agarg Option
@cindex getdefs-agarg

This is a passthrough argument.  It allows you to have AutoGen invoked
with any arbitrary argument.

@node getdefs base-name
@subsection base-name Option
@cindex getdefs-base-name

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 @code{template} option.  If that is not provided either, then
it is set to the base name of the current directory.

@ignore
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Resume text from auto_gen.tpl
@end ignore
@page
@node Future
@chapter Some ideas for the future.
@cindex futures

Here are some things that might happen in the distant future.

@itemize @bullet
@item
Rewrite in Guile.

@item
Write code for "AutoGetopts" (GNU getopt), or
possibly the new glibc argp parser.

@item
Fix up current tools that contain
miserably complex perl, shell, sed, awk and m4 scripts
to instead use this tool.
@end itemize
@page
@node Concept Index
@unnumbered Concept Index

@printindex cp
@page
@node Function Index
@unnumbered Function Index

@printindex fn
@page
@contents
@bye
