Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/doc/autogen/autogen.html/ drwxr-xr-x | |
| Viewing file: Select action/file-type: Next: csh/zsh caveat, Previous: Generalities, Up: Introduction [Contents][Index] 1.2 A Simple ExampleThis is just one simple example that shows a few basic features.
If you are interested, you also may run "make check" with the
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 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 looks something like this. (For a full description, See Template File.) [+ AutoGen5 template h c +]
[+ CASE (suffix) +][+
== h +]
typedef enum {[+
FOR list "," +]
IDX_[+ (string-upcase! (get "list_element")) +][+
ENDFOR list +] } list_enum;
extern char const* az_name_list[ [+ (count "list") +] ];
[+
== c +]
#include "list.h"
char const* az_name_list[] = {[+
FOR list "," +]
"[+list_info+]"[+
ENDFOR list +] };[+
ESAC +]
The The The The remainder of the macros are expressions. Some of these contain
special expression functions that are dependent on AutoGen named values;
others are simply Scheme expressions, the result of which will be
inserted into the output text. Other expressions are names of AutoGen
values. These values will be inserted into the output text. For example,
If you have compiled AutoGen, you can copy out the template and definitions
as described above and run One more point, too. Lets say you decided it was too much trouble to figure out how to use AutoGen, so you created this enumeration and string list with thousands of entries. Now, requirements have changed and it has become necessary to map a string containing the enumeration name into the enumeration number. With AutoGen, you just alter the template to emit the table of names. It will be guaranteed to be in the correct order, missing none of the entries. If you want to do that by hand, well, good luck. Next: csh/zsh caveat, Previous: Generalities, Up: Introduction [Contents][Index] |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0085 ]-- |