3 configfile, config_read, config_delete, config_renewed, config_length, config_issub, config_isatom, config_isstring \- generic configuration file functions
7 #include <configfile.h>
9 config_t *config_read(const char *\fIfile\fP, int \fIflags\fP, config_t *\fIcfg\fP)
10 void config_delete(config_t *\fIcfg\fP)
11 int config_renewed(config_t *\fIcfg\fP)
12 size_t config_length(config_t *\fIcfg\fP)
13 int config_issub(config_t *\fIcfg\fP)
14 int config_isatom(config_t *\fIcfg\fP)
15 int config_isstring(config_t *\fIcfg\fP)
21 routines operate on a generic configuration file that follows the syntax
25 The interface presented by the functions above uses the following type and
26 definitions from <configfile.h>:
31 .ta +\w'type'u +\w'const charmm'u +\w'word[];mm'u
32 typedef const struct config {
33 config_t *next; /* Next configuration file thing. */
34 config_t *list; /* For a { sublist }. */
35 const char *file; /* File and line where this is found. */
37 int flags; /* Special flags. */
38 char word[]; /* Payload. */
41 .ta +\w'#definem'u +\w'CFG_SUBLISTm'u +\w'0x0000mm'u
42 #define CFG_CLONG 0x0001 /* strtol(word, &end, 0) is valid. */
43 #define CFG_OLONG 0x0002 /* strtol(word, &end, 010). */
44 #define CFG_DLONG 0x0004 /* strtol(word, &end, 10). */
45 #define CFG_XLONG 0x0008 /* strtol(word, &end, 0x10). */
46 #define CFG_CULONG 0x0010 /* strtoul(word, &end, 0). */
47 #define CFG_OULONG 0x0020 /* strtoul(word, &end, 010). */
48 #define CFG_DULONG 0x0040 /* strtoul(word, &end, 10). */
49 #define CFG_XULONG 0x0080 /* strtoul(word, &end, 0x10). */
50 #define CFG_STRING 0x0100 /* The word is enclosed in quotes. */
51 #define CFG_SUBLIST 0x0200 /* This is a sublist, so no word. */
52 #define CFG_ESCAPED 0x0400 /* Escapes are still marked with \e. */
57 In memory a configuration file is represented as a list of
59 cells linked together with the
61 field ending with a null pointer. A sublist between braces is attached to a
65 Words and strings are put in the
67 field, a null terminated string. The
69 field records the type and features of a cell. The
71 flags are set if a word is a number according to one of the
75 calls. Purely a number, no quotes or trailing garbage. The
77 flag is set if the object was enclosed in double quotes. Lastly
79 tells if the cell is only a pointer to a sublist in braces.
81 Characters in a word or string may have been formed with the
83 escape character. They have been parsed and expanded, but the \e is still
88 array may be changed, as long as it doesn't grow longer, so one may remove
94 if (cfg->flags & CFG_ESCAPED) {
98 if ((*q = *p) == '\e\e') *q = *++p;
107 The low level syntax of a config file is checked when it is read. If an
108 error is encountered a message is printed and the program exits with exit
109 code 1. What the data means is not checked, that
110 should be done by the program using the data. Only the atom
112 at the beginning of a list is special. It should be followed by a string.
113 The string is seen as the name of a file, that is opened, read, and inserted
116 Unless the name of the file starts with a
118 it is sought relative to the directory the current file is found in.
119 Nonexistent files are treated as being empty.
125 fields in each cell tell where the cell was read.
127 A configuration file is read with
129 The first argument is the file to read. The second is either
133 to tell whether \e escapes should be fully expanded without leaving a trace,
134 or if they should still be marked with a \e so that the caller knows where
138 should be a null pointer on the first call. If you want to reread a config
139 file that may have changed then
141 should be what you previously read.
145 one can free up the memory that has been acquired with
147 to hold the contents of the configuration file.
149 To determine if the contents of configuration file has changed when reread
154 It returns a "changed" flag that is set when the configuration file changed
155 and then clears that flag. It returns true on the very first call. For the
156 function to work you need to feed the old data back into
158 not delete and reread.
160 The length of a series of config structures is told by
164 fields, so a sublist between braces counts as one extra.
171 functions are just pretty macros to test if a cell references a sublist, is
172 a word/string, or is just a string.
178 .TP \w'*/etc/*.confmmmm'u
180 Several files in several
186 The syntax of a config file puts some constraints on what you find in memory.
187 The top level list consists entirely of sublist cells. These point to lists
188 that start with at least an atom, followed by a mix of atoms and sublist cells.
189 These sublists in turn point to a list of only sublist cells (recurse now.)
191 The struct config shown above is not exactly proper C to aid
192 readability, read <configfile.h> itself to see why.
194 Kees J. Bot (kjb@cs.vu.nl)