147
|
1 /*
|
|
2 * command line and config file parser
|
|
3 */
|
|
4
|
|
5 #ifndef __CONFIG_H
|
|
6 #define __CONFIG_H
|
|
7
|
|
8 #define CONF_TYPE_FLAG 0
|
|
9 #define CONF_TYPE_INT 1
|
|
10 #define CONF_TYPE_FLOAT 2
|
|
11 #define CONF_TYPE_STRING 3
|
150
|
12 #define CONF_TYPE_FUNC 4
|
151
|
13 #define CONF_TYPE_FUNC_PARAM 5
|
152
|
14 #define CONF_TYPE_PRINT 6
|
147
|
15
|
153
|
16 #define CONF_MIN (1<<0)
|
|
17 #define CONF_MAX (1<<1)
|
|
18 #define CONF_RANGE (CONF_MIN|CONF_MAX)
|
151
|
19 #define CONF_NOCFG (1<<2)
|
|
20 #define CONF_NOCMD (1<<3)
|
147
|
21
|
|
22 struct config {
|
|
23 char *name;
|
|
24 void *p;
|
150
|
25 unsigned int type :3;
|
151
|
26 unsigned int flags:4;
|
147
|
27 float min,max;
|
|
28 };
|
|
29
|
150
|
30 typedef int (*cfg_func_param_t)(struct config *, char *);
|
|
31 typedef int (*cfg_func_t)(struct config *);
|
|
32
|
147
|
33 /* parse_config_file returns:
|
|
34 * -1 on error (can't malloc, invalid option...)
|
|
35 * 0 if can't open configfile
|
|
36 * 1 on success
|
|
37 */
|
|
38 int parse_config_file(struct config *conf, char *conffile);
|
|
39
|
|
40 /* parse_command_line reutrns:
|
|
41 * -1 on error (invalid option...)
|
|
42 * 0 if there was no filename on command line
|
|
43 * 1 if it found a filename
|
|
44 */
|
|
45 int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char **filename);
|
|
46
|
|
47 #endif /* __CONFIG_H */
|