source: trunk/minix/man/man3/configfile.3@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 5.6 KB
Line 
1.TH CONFIGFILE 3
2.SH NAME
3configfile, config_read, config_delete, config_renewed, config_length, config_issub, config_isatom, config_isstring \- generic configuration file functions
4.SH SYNOPSIS
5.ft B
6.nf
7#include <configfile.h>
8
9config_t *config_read(const char *\fIfile\fP, int \fIflags\fP, config_t *\fIcfg\fP)
10void config_delete(config_t *\fIcfg\fP)
11int config_renewed(config_t *\fIcfg\fP)
12size_t config_length(config_t *\fIcfg\fP)
13int config_issub(config_t *\fIcfg\fP)
14int config_isatom(config_t *\fIcfg\fP)
15int config_isstring(config_t *\fIcfg\fP)
16.fi
17.ft P
18.SH DESCRIPTION
19The
20.B configfile
21routines operate on a generic configuration file that follows the syntax
22described in
23.BR configfile (5).
24.PP
25The interface presented by the functions above uses the following type and
26definitions from <configfile.h>:
27.PP
28.if n .in +2
29.if t .RS
30.nf
31.ta +\w'type'u +\w'const charmm'u +\w'word[];mm'u
32typedef 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. */
36 unsigned line;
37 int flags; /* Special flags. */
38 char word[]; /* Payload. */
39} config_t;
40
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. */
53.fi
54.if n .in -2
55.if t .RE
56.PP
57In memory a configuration file is represented as a list of
58.B config_t
59cells linked together with the
60.B next
61field ending with a null pointer. A sublist between braces is attached to a
62cell at the
63.B list
64field.
65Words and strings are put in the
66.B word
67field, a null terminated string. The
68.B flags
69field records the type and features of a cell. The
70.B CFG_*LONG
71flags are set if a word is a number according to one of the
72.B strtol
73or
74.B strtoul
75calls. Purely a number, no quotes or trailing garbage. The
76.B CFG_STRING
77flag is set if the object was enclosed in double quotes. Lastly
78.B CFG_SUBLIST
79tells if the cell is only a pointer to a sublist in braces.
80.PP
81Characters in a word or string may have been formed with the
82.B \e
83escape character. They have been parsed and expanded, but the \e is still
84present if
85.B CFG_ESCAPED
86is set. The
87.B word
88array may be changed, as long as it doesn't grow longer, so one may remove
89the \es like this:
90.PP
91.RS
92.ta +4n +4n
93.nf
94if (cfg->flags & CFG_ESCAPED) {
95 char *p, *q;
96 p= q= cfg->word;
97 for (;;) {
98 if ((*q = *p) == '\e\e') *q = *++p;
99 if (*q == 0) break;
100 p++;
101 q++;
102 }
103}
104.fi
105.RE
106.PP
107The low level syntax of a config file is checked when it is read. If an
108error is encountered a message is printed and the program exits with exit
109code 1. What the data means is not checked, that
110should be done by the program using the data. Only the atom
111.B include
112at the beginning of a list is special. It should be followed by a string.
113The string is seen as the name of a file, that is opened, read, and inserted
114in place of the
115.BR include .
116Unless the name of the file starts with a
117.BR / ,
118it is sought relative to the directory the current file is found in.
119Nonexistent files are treated as being empty.
120.PP
121The
122.B file
123and
124.B line
125fields in each cell tell where the cell was read.
126.SS Functions
127A configuration file is read with
128.BR config_read .
129The first argument is the file to read. The second is either
130.B 0
131or
132.B CFG_ESCAPED
133to tell whether \e escapes should be fully expanded without leaving a trace,
134or if they should still be marked with a \e so that the caller knows where
135the excapes are.
136The third argument,
137.IR cfg ,
138should be a null pointer on the first call. If you want to reread a config
139file that may have changed then
140.I cfg
141should be what you previously read.
142.PP
143With
144.B config_delete
145one can free up the memory that has been acquired with
146.BR malloc (3)
147to hold the contents of the configuration file.
148.PP
149To determine if the contents of configuration file has changed when reread
150one uses
151.BR config_renewed
152after
153.BR config_read .
154It returns a "changed" flag that is set when the configuration file changed
155and then clears that flag. It returns true on the very first call. For the
156function to work you need to feed the old data back into
157.BR config_read ,
158not delete and reread.
159.PP
160The length of a series of config structures is told by
161.BR config_length .
162It follows the
163.B next
164fields, so a sublist between braces counts as one extra.
165.PP
166The
167.BR config_issub ,
168.BR config_isatom
169and
170.BR config_isstring
171functions are just pretty macros to test if a cell references a sublist, is
172a word/string, or is just a string.
173.B CFG_SUBLIST
174and
175.B CFG_STRING
176tell the same story.
177.SH FILES
178.TP \w'*/etc/*.confmmmm'u
179.B */etc/*.conf
180Several files in several
181.B etc
182directories.
183.SH "SEE ALSO"
184.BR configfile (5).
185.SH NOTES
186The syntax of a config file puts some constraints on what you find in memory.
187The top level list consists entirely of sublist cells. These point to lists
188that start with at least an atom, followed by a mix of atoms and sublist cells.
189These sublists in turn point to a list of only sublist cells (recurse now.)
190.PP
191The struct config shown above is not exactly proper C to aid
192readability, read <configfile.h> itself to see why.
193.SH AUTHOR
194Kees J. Bot (kjb@cs.vu.nl)
Note: See TracBrowser for help on using the repository browser.