[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Introduction

AutoGen is a tool designed for generating program files that contain repetitive text with varied substitutions. Its goal is to simplify the maintenance of programs that contain large amounts of repetitious text. This is especially valuable if there are several blocks of such text that must be kept synchronized in parallel tables.

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:

  1. The flag character in the flag string,
  2. code to process the flag when it is encountered,
  3. a global state variable or two, and
  4. a line in the usage text.

You will need more things besides this if you choose to implement long option names, rc/ini/config file processing, environment variables and so on. 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 See section Automated Option Processing. For a simple example of Automated Option processing, See section Quick Start. For a full list of the Automated Option features, See section AutoOpts Features.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 The Purpose of AutoGen

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.

AutoGen was designed with the following features:

  1. 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.
  2. 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!
  3. Every definition name defines an array of values, even when there is only one entry. These arrays of values are used to control the replication of sections of the template.
  4. 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.
  5. The template has special markers to indicate where substitutions are required, much like the ${VAR} construct in a shell 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 either M4 tokenization or C preprocessor substitution rules. It also makes it easier to specify expressions that transform the value. Of course, our expressions are less cryptic than the shell methods.

  6. These same markers are used, in conjunction with enclosed keywords, to indicate sections of text that are to be skipped and for sections of text that are to be repeated. This is a major improvement over using C preprocessing macros. With the C preprocessor, you have no way of selecting output text because it is an unvarying, mechanical substitution process.
  7. Finally, we supply methods for carefully controlling the output. Sometimes, it is just simply easier and clearer to compute some text or a value in one context when its application needs to be later. So, functions are available for saving text or values for later use.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 A Simple Example

This is just one simple example that shows a few basic features. If you are interested, you also may run "make check" with the VERBOSE environment variable set and see a number of other examples in the ‘agen5/test/testdir’ directory.

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.

In a header file, ‘list.h’, you define the enumeration and the global array containing the associated strings:

 
typedef enum {
        IDX_ALPHA,
        IDX_BETA,
        IDX_OMEGA }  list_enum;

extern char const* az_name_list[ 3 ];

Then you also have ‘list.c’ that defines the actual strings:

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

First, we will define the information that is unique for each enumeration name/string pair. This would be placed in a file named, ‘list.def’, for 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"; };

The autogen definitions list; entry defines the file as an AutoGen definition file that uses a template named list. That is followed by three 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 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. The definitions above refer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘list.tpl’.

It looksrefer to a ‘list’ template, so it would normally be named, ‘l