annotate cfgparser.h @ 4272:68a40de07167

cleaned some parts, tested and working with g400/450, g200 is buggy :(
author alex
date Sat, 19 Jan 2002 22:46:28 +0000
parents 83aedfde69f8
children 1cee88ee8db5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
1 /*
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
2 * command line and config file parser
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
3 */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
4
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
5 #ifndef __CONFIG_H
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
6 #define __CONFIG_H
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
7
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
8 #define CONF_TYPE_FLAG 0
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
9 #define CONF_TYPE_INT 1
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
10 #define CONF_TYPE_FLOAT 2
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
11 #define CONF_TYPE_STRING 3
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
12 #define CONF_TYPE_FUNC 4
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
13 #define CONF_TYPE_FUNC_PARAM 5
152
372a9a836e86 cfgparser fix
szabii
parents: 151
diff changeset
14 #define CONF_TYPE_PRINT 6
1536
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
15 #define CONF_TYPE_FUNC_FULL 7
2617
b97a9e3fdb63 added subconfig type
alex
parents: 1629
diff changeset
16 #define CONF_TYPE_SUBCONFIG 8
b97a9e3fdb63 added subconfig type
alex
parents: 1629
diff changeset
17
1536
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
18
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
19 #define ERR_NOT_AN_OPTION -1
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
20 #define ERR_MISSING_PARAM -2
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
21 #define ERR_OUT_OF_RANGE -3
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
22 #define ERR_FUNC_ERR -4
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
23
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 153
diff changeset
24
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
25
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
26 #define CONF_MIN (1<<0)
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
27 #define CONF_MAX (1<<1)
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 152
diff changeset
28 #define CONF_RANGE (CONF_MIN|CONF_MAX)
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
29 #define CONF_NOCFG (1<<2)
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
30 #define CONF_NOCMD (1<<3)
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
31 #define CONF_GLOBAL (1<<4)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
32 #define CONF_NOSAVE (1<<5)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
33
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
34
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
35 typedef struct config config_t;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
36 typedef struct m_config m_config_t;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
37 typedef struct config_save config_save_t;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
38
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
39 #include "playtree.h"
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
40
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
41 typedef void (*cfg_default_func_t)(config_t *, char*);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
42
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
43 struct config {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
44 char *name;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
45 void *p;
3559
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2617
diff changeset
46 unsigned int type;
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2617
diff changeset
47 unsigned int flags;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
48 float min,max;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
49 cfg_default_func_t default_func;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
50 };
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
51
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
52
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
53
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
54 struct m_config {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
55 config_t** opt_list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
56 config_save_t** config_stack;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
57 int cs_level;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
58 int parser_mode; /* COMMAND_LINE or CONFIG_FILE */
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
59 int flags;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
60 play_tree_t* pt; // play tree we use for playlist option, etc
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
61 play_tree_t* last_entry; // last added entry
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
62 play_tree_t* last_parent; // if last_entry is NULL we must create child of this
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
63 int recursion_depth;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
64 };
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
65
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
66 struct config_save {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
67 config_t* opt;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
68 union {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
69 int as_int;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
70 float as_float;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
71 void* as_pointer;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
72 } param;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
73 char* opt_name;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
74 };
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
75
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
76
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
77 typedef int (*cfg_func_arg_param_t)(config_t *, char *, char *);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
78 typedef int (*cfg_func_param_t)(config_t *, char *);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
79 typedef int (*cfg_func_t)(config_t *);
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
80
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
81 /* parse_config_file returns:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
82 * -1 on error (can't malloc, invalid option...)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
83 * 0 if can't open configfile
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
84 * 1 on success
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
85 */
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
86 int m_config_parse_config_file(m_config_t *config, char *conffile);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
87
1629
13aeaa05ac5e multifile support in config parser
arpi
parents: 1536
diff changeset
88 /* parse_command_line returns:
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
89 * -1 on error (invalid option...)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
90 * 0 if there was no filename on command line
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
91 * 1 if there were filenames
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
92 */
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
93 int m_config_parse_command_line(m_config_t* config, int argc, char **argv, char **envp);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
94
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
95
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
96 void m_config_register_options(m_config_t *config,config_t *args);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
97
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
98 int m_config_set_option(m_config_t *config,char *opt, char *param);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
99
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
100 config_t* m_config_get_option(m_config_t *config, char* arg);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
101
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4156
diff changeset
102 int m_config_switch_flag(m_config_t *config, char* opt);
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4156
diff changeset
103
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4156
diff changeset
104 void m_config_set_flag(m_config_t *config, char* opt, int max);
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4156
diff changeset
105
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4156
diff changeset
106 void* m_config_get_option_ptr(m_config_t *config, char* arg);
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4156
diff changeset
107
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
108 m_config_t* m_config_new(play_tree_t* pt);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
109
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
110 void m_config_free(m_config_t* config);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
111
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
112 void m_config_push(m_config_t* config);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
113
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3559
diff changeset
114 int m_config_pop(m_config_t* config);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
115 #endif /* __CONFIG_H */