Content-type: text/html
void deletetable(table *tbl)
table *readtable(char *fname, generic *keyexcl, int numexcl, char *fmt)
int writetable(table *tbl, char *fname, char *header, int wfmt, char delim)
int getfieldvalue(table *tbl, char *fldname, generic key, generic *value)
int setfieldvalue(table *tbl, char *fldname, generic key, generic value)
gentype getfieldtype(table *tbl, char *fldname)
char *getfieldname(table *tbl, int fldindex, char *str)
int getkeyvalue(table *tbl, int recindex, generic *value)
gentype getkeytype(table *tbl)
int countrecords(table *tbl)
int countfields(table *tbl)
int addrecord(table *tbl, generic key)
int delrecord(table *tbl, generic key)
The first element of the string specifies the key value type for the table. Key value types can be from the following set: I = integer, F = floating point, C = character, S = string. Following elements of the format string are pairs of type specifiers and field names. Each element is separated by white space. Field names may contain white space by quoting the value or escaping the white space characters. Quote characers are single quote ('), double quote ("), parentheses(()), or curly braces ({}).
The readtable and writetable routines read and write tables to disk files. The format of the table files is as follows:
The first non-blank, non-comment line of the file is a format string as specified for the createtable routine. Succeeding non-blank, non-comment lines are white space delimited table records. Lines starting with a pound sign (#) are considered comments. Lines consisting entirely of white space characters, or consisting only of an end-of-line character, are considered to be blank. Field names and values may contain white space or other special purpose characters by quoteing the name or value or by escaping the special characters.
The format of a table file can either be contained in the file iself, or it can be specified in the call to readtable. If the format is in the file, then the fmt parameter to readtable should be a NULL pointer. If fmt is non-NULL then the routine will not try to read a format line from the file and will rely on the provided format string instead.
The writetable routine will optionally write the table format string to the file, if the wfmt parameter is non-zero. An optional header can also be specified that will be written as comments before anything else is written to the file. Even the delimiter character can be specified by the user, though this should be a white space character or else the file will not be readable by readtable.
The getfieldvalue and setfieldvalue allow values in individual fields to be obtained or changed. Both the field name and record key must be specified.
The getfieldtype and getfieldname return information about fields based on either the field name (for getfieldtype) or the field index (for getfieldname).
The countfields and countrecords return geometric information about a table.
The addrecord and delrecord adds or deletes records from a table. In either case the record key must be specified. When adding a record the key must not already exist in the table.
All field values are returned and specified as generic data types. The generic data type is specified in the utils.h header file and routines for manipulating generic data elements are provided in the libutils library. The data type is basically a union of the following data types: long integer, double precision float, character, and pointer to characters. It may be important to note that the character element is actually a long integer and can hold values significantly outside the range of the standard char type.
NOTE: While the table routines provide some of the functionality of a simple database, they are not meant to be used as a general database engine and are not optimized for such use. The intended use for these routines is to provide access to a configuration file during program initialization and to manipulate the values in that configuration file during runtime.