xref: /minix3/minix/include/configfile.h (revision c2808d8b071b2aef9b390713b505f4c9dc567fbd)
1*c2808d8bSBen Gras /*	configfile.h - Generic configuration file format.
2*c2808d8bSBen Gras  *							Author: Kees J. Bot
3*c2808d8bSBen Gras  *								5 Jun 1999
4*c2808d8bSBen Gras  */
5*c2808d8bSBen Gras #ifndef _CONFIGFILE_H
6*c2808d8bSBen Gras #define _CONFIGFILE_H
7*c2808d8bSBen Gras 
8*c2808d8bSBen Gras /* Data can only be modified inside the library. */
9*c2808d8bSBen Gras #ifndef _c
10*c2808d8bSBen Gras #define _c	const
11*c2808d8bSBen Gras #endif
12*c2808d8bSBen Gras 
13*c2808d8bSBen Gras typedef _c struct config {	/* Contents of a generic configuration file. */
14*c2808d8bSBen Gras _c	struct config	*next;		/* Next configuration file thing. */
15*c2808d8bSBen Gras _c	struct config	*list;		/* For a { sublist }. */
16*c2808d8bSBen Gras 	const char	*file;		/* File and line where this is found. */
17*c2808d8bSBen Gras 	unsigned	line;
18*c2808d8bSBen Gras 	int		flags;		/* Special flags. */
19*c2808d8bSBen Gras 	char		word[1];	/* Payload. */
20*c2808d8bSBen Gras } config_t;
21*c2808d8bSBen Gras 
22*c2808d8bSBen Gras #define CFG_CLONG	0x0001		/* strtol(word, &end, 0) is valid. */
23*c2808d8bSBen Gras #define CFG_OLONG	0x0002		/* strtol(word, &end, 010). */
24*c2808d8bSBen Gras #define CFG_DLONG	0x0004		/* strtol(word, &end, 10). */
25*c2808d8bSBen Gras #define CFG_XLONG	0x0008		/* strtol(word, &end, 0x10). */
26*c2808d8bSBen Gras #define CFG_CULONG	0x0010		/* strtoul(word, &end, 0). */
27*c2808d8bSBen Gras #define CFG_OULONG	0x0020		/* strtoul(word, &end, 010). */
28*c2808d8bSBen Gras #define CFG_DULONG	0x0040		/* strtoul(word, &end, 10). */
29*c2808d8bSBen Gras #define CFG_XULONG	0x0080		/* strtoul(word, &end, 0x10). */
30*c2808d8bSBen Gras #define CFG_STRING	0x0100		/* The word is enclosed in quotes. */
31*c2808d8bSBen Gras #define CFG_SUBLIST	0x0200		/* This is a sublist, so no word. */
32*c2808d8bSBen Gras #define CFG_ESCAPED	0x0400		/* Escapes are still marked with \. */
33*c2808d8bSBen Gras 
34*c2808d8bSBen Gras config_t *config_read(const char *_file, int flags, config_t *_cfg);
35*c2808d8bSBen Gras void config_delete(config_t *_cfg);
36*c2808d8bSBen Gras int config_renewed(config_t *_cfg);
37*c2808d8bSBen Gras size_t config_length(config_t *_cfg);
38*c2808d8bSBen Gras #define config_issub(cfg)	(!!((cfg)->flags & CFG_SUBLIST))
39*c2808d8bSBen Gras #define config_isatom(cfg)	(!config_issub(cfg))
40*c2808d8bSBen Gras #define config_isstring(cfg)	(!!((cfg)->flags & CFG_STRING))
41*c2808d8bSBen Gras 
42*c2808d8bSBen Gras #undef _c
43*c2808d8bSBen Gras 
44*c2808d8bSBen Gras #endif /* _CONFIGFILE_H */
45