(gperf.info.gz) Declarations
Info Catalog
(gperf.info.gz) Input Format
(gperf.info.gz) Input Format
(gperf.info.gz) Keywords
`struct' Declarations and C Code Inclusion
------------------------------------------
The keyword input file optionally contains a section for including
arbitrary C declarations and definitions, as well as provisions for
providing a user-supplied `struct'. If the `-t' option _is_ enabled,
you _must_ provide a C `struct' as the last component in the
declaration section from the keyfile file. The first field in this
struct must be a `char *' or `const char *' identifier called `name',
although it is possible to modify this field's name with the `-K'
option described below.
Here is a simple example, using months of the year and their
attributes as input:
struct months { char *name; int number; int days; int leap_days; };
%%
january, 1, 31, 31
february, 2, 28, 29
march, 3, 31, 31
april, 4, 30, 30
may, 5, 31, 31
june, 6, 30, 30
july, 7, 31, 31
august, 8, 31, 31
september, 9, 30, 30
october, 10, 31, 31
november, 11, 30, 30
december, 12, 31, 31
Separating the `struct' declaration from the list of keywords and
other fields are a pair of consecutive percent signs, `%%', appearing
left justified in the first column, as in the UNIX utility `lex'.
Using a syntax similar to GNU utilities `flex' and `bison', it is
possible to directly include C source text and comments verbatim into
the generated output file. This is accomplished by enclosing the region
inside left-justified surrounding `%{', `%}' pairs. Here is an input
fragment based on the previous example that illustrates this feature:
%{
#include <assert.h>
/* This section of code is inserted directly into the output. */
int return_month_days (struct months *months, int is_leap_year);
%}
struct months { char *name; int number; int days; int leap_days; };
%%
january, 1, 31, 31
february, 2, 28, 29
march, 3, 31, 31
...
It is possible to omit the declaration section entirely. In this
case the keyfile begins directly with the first keyword line, e.g.:
january, 1, 31, 31
february, 2, 28, 29
march, 3, 31, 31
april, 4, 30, 30
...
Info Catalog
(gperf.info.gz) Input Format
(gperf.info.gz) Input Format
(gperf.info.gz) Keywords
automatically generated byinfo2html