Mercurial > mplayer.hg
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 |
rev | line source |
---|---|
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 |
1536
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
153
diff
changeset
|
15 #define CONF_TYPE_FUNC_FULL 7 |
2617 | 16 #define CONF_TYPE_SUBCONFIG 8 |
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 | 25 |
153 | 26 #define CONF_MIN (1<<0) |
27 #define CONF_MAX (1<<1) | |
28 #define CONF_RANGE (CONF_MIN|CONF_MAX) | |
151 | 29 #define CONF_NOCFG (1<<2) |
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 | 42 |
43 struct config { | |
44 char *name; | |
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 | 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 | 50 }; |
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 | 80 |
147 | 81 /* parse_config_file returns: |
82 * -1 on error (can't malloc, invalid option...) | |
83 * 0 if can't open configfile | |
84 * 1 on success | |
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 | 87 |
1629 | 88 /* parse_command_line returns: |
147 | 89 * -1 on error (invalid option...) |
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 | 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 | 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 | 115 #endif /* __CONFIG_H */ |