home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Press 1997 July
/
Sezamfile97_1.iso
/
msdos
/
c
/
cbase11.a03
/
CBASE11.ZIP
/
MAN
/
CBDDLP.MAN
< prev
next >
Wrap
Text File
|
1993-01-01
|
7KB
|
151 lines
NAME
cbddlp - cbase data definition language processor
SYNOPSIS
cbddlp ddlfile
DESCRIPTION
The cbddlp command processes cbase data definition language (DDL)
files. A cbase database can be specified in a DDL file, which is
then processed using cbddlp to generate the C files required by
cbase to manipulate that database. cbddlp requires that DDL
files have the suffix ".ddl". The C files generated are given
the same name as the DDL file except for the suffix; a .h and a
.i file are generated. The .h file must be included by every
module accessing the database, while the .i file must be included
by exactly one module of every program that accesses the database.
There are three types of DDL statements: data file, index file,
and record. The syntax for the record statement is
record recname {
[[unique ]key] dbtype fldname[\[elemc\]];
...
};
recname is the name of the record. dbtype is the database data
type of the field. fldname is the name of the field, and must be
unique for a given database. elemc specifies the number of
elements for array data types; this may be any C expression valid
for defining the size of a static array. The key keyword
specifies that an index is to be maintained on this field. The
unique keyword specifies that the keys in this index must be
unique. Multiple records can be defined in the same DDL file.
User-defined data types may also be specified in a DDL file, but
require an additional piece of information. For the predefined
data types, cbddlp knows what the corresponding C data type is
(t_string : char, t_int : int, etc.). But for user-defined data
types, this must be explicitly specified. The syntax for this is
as follows.
[[unique ]key] dbtype:ctype fldname[[elemc]];
where dbtype is a user-defined database data type and ctype is
the corresponding C data type. ctype must consist of only one
identifier; if the C data type consists of multiple identifiers
(e.g., long double), either #define or typedef must be used to
reduce it to one identifier (e.g., typedef long double ldouble).
The syntax for the data file statement is
data file "filename" contains recname;
filename is the name of the file in which recname records are to
be stored. The data file statement must precede its associated
record statement.
The syntax for the index file statement is
index file "filename" contains keyname;
filename is the name of the file in which keyname keys are to be
indexed. The index file statement must precede the record
statement containing the associated key.
C comments may appear in DDL files wherever white space is
allowed, with the exception of within the keyword pairs "data
file" and "index file". C preprocessor statements may also be
placed in DDL files, but cannot currently span multiple lines,
nor can comments on the same line as a preprocessor statement;
any line beginning with the # character (excluding any leading
white space) will be passed directly through to the generated .h
file.
In the headers generated by cbddlp, a macro for the record name
is constructed by converting all lower case letters in the record
name to capitals. A macro is also defined for each field in the
same fashion. The initial characters (up to four) of the first
field name of a record preceding the first underscore are used as
a prefix for the field count macro and field definition list.
This prefix must be unique for all records in a database. The
field count macro identifier is constructed by converting this
prefix to capitals and appending FLDC. The field definition list
identifier is constructed by appending fldv to the prefix.
EXAMPLE
Below is given an example DDL file for a rolodeck database
consisting of a single record.
/* constants */
#define NAME_MAX (40) /* max name length */
#define ADDR_MAX (40) /* max address length */
#define NOTELIN_MAX (4) /* note lines */
#define NOTECOL_MAX (40) /* note columns */
/* file assignments */
data file "rolodeck.dat" contains rolodeck;
index file "rdcont.ndx" contains rd_contact;
index file "rdcomp.ndx" contains rd_company;
record rolodeck { /* rolodeck record */
unique key t_string
rd_contact[NAME_MAX]; /* contact name */
t_string rd_title[41]; /* contact title */
key t_string rd_company[NAME_MAX]; /* company name */
t_string rd_addr[81]; /* address */
t_string rd_city[26]; /* city */
t_string rd_state[3]; /* state */
t_string rd_zip[11]; /* zip code */
t_string rd_phone[13]; /* phone number */
t_string rd_ext[5]; /* phone extension */
t_string rd_fax[13]; /* fax number */
t_string rd_notes[NOTELIN_MAX * NOTECOL_MAX];
/* notes */
};
If the name of this DDL file was rolodeck.ddl, the generated C
files would be rolodeck.h and rolodeck.i. The cbase name macro
would be ROLODECK (the record identifier capitalized). The field
count macro would be RDFLDC, and the field definition list would
be rdfldv. The rolodeck would be therefore be opened (for
writing) with the C statement
cbopen(ROLODECK, "r+", RDFLDC, rdfldv);
The phone number from the current record would be read from the
database with
cbgetrf(cbp, RD_PHONE, buf);
NOTES
For a make utility to automatically process DDL files without an
explicit rule for each one, suffix rules defining the creation of
the data definition header files from a DDL file can be added to
the makefile. For the standard UNIX make, the following
instructions would be inserted near the beginning of the
makefile.
# suffix rules
.SUFFIXES: .ddl .h .i
.ddl.h:
cbddlp $<
.ddl.i:
cbddlp $<
The exact procedure for other make utilities varies.