Mercurial > mplayer.hg
annotate cfgparser.c @ 10492:fbf6c613e671
sync by Juan Martin <nauj27@teleline.es>
author | diego |
---|---|
date | Mon, 28 Jul 2003 02:22:18 +0000 |
parents | d83e4e54985c |
children |
rev | line source |
---|---|
147 | 1 /* |
2 * command line and config file parser | |
336 | 3 * by Szabolcs Berecz <szabi@inf.elte.hu> |
4 * (C) 2001 | |
2619 | 5 * |
6 * subconfig support by alex | |
147 | 7 */ |
8 | |
9 //#define DEBUG | |
10 | |
11 #include <stdlib.h> | |
12 #include <stdio.h> | |
13 #include <ctype.h> | |
14 #include <unistd.h> | |
15 #include <fcntl.h> | |
16 #include <string.h> | |
336 | 17 #include <errno.h> |
7611
411886c03c54
strtod is locale-dependant, so it may only accept either '.' or ',' as decimal point,
atmos4
parents:
7503
diff
changeset
|
18 #include <math.h> |
7870
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
19 |
7879 | 20 #include "config.h" |
21 | |
8164
487cfc28525d
New config system + cleanup of header inter dependency
albeu
parents:
8123
diff
changeset
|
22 #ifndef NEW_CONFIG |
487cfc28525d
New config system + cleanup of header inter dependency
albeu
parents:
8123
diff
changeset
|
23 |
7870
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
24 #ifdef USE_SETLOCALE |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
25 #include <locale.h> |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
26 #endif |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
27 |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
28 #include "mp_msg.h" |
147 | 29 |
30 #define COMMAND_LINE 0 | |
31 #define CONFIG_FILE 1 | |
32 | |
5215 | 33 #define LIST_SEPARATOR ',' |
34 | |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
35 #define CONFIG_GLOBAL (1<<0) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
36 #define CONFIG_RUNNING (1<<1) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
37 |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
38 #define SET_GLOBAL(c) (c->flags |= CONFIG_GLOBAL) |
5655
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
39 #ifdef GLOBAL_OPTIONS_ONLY |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
40 #define UNSET_GLOBAL(c) |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
41 #else |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
42 #define UNSET_GLOBAL(c) (c->flags &= (!CONFIG_GLOBAL)) |
5655
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
43 #endif |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
44 #define IS_GLOBAL(c) (c->flags & CONFIG_GLOBAL) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
45 #define SET_RUNNING(c) (c->flags |= CONFIG_RUNNING) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
46 #define IS_RUNNING(c) (c->flags & CONFIG_RUNNING) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
47 |
177 | 48 #define MAX_RECURSION_DEPTH 8 |
166 | 49 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
50 #ifdef MP_DEBUG |
147 | 51 #include <assert.h> |
52 #endif | |
53 | |
54 #include "cfgparser.h" | |
8164
487cfc28525d
New config system + cleanup of header inter dependency
albeu
parents:
8123
diff
changeset
|
55 #include "playtree.h" |
147 | 56 |
5215 | 57 static void m_config_list_options(m_config_t *config); |
58 static void m_config_error(int err,char* opt,char* val); | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
59 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
60 static void |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
61 m_config_save_option(m_config_t* config, config_t* conf,char* opt, char *param) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
62 config_save_t* save; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
63 int sl=0; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
64 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
65 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
66 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
67 assert(config->cs_level >= 0); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
68 assert(conf != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
69 assert(opt != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
70 assert( ! (conf->flags & CONF_NOSAVE)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
71 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
72 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
73 switch(conf->type) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
74 case CONF_TYPE_PRINT : |
10320
d83e4e54985c
backport PRINT_INDIRECT to old-config parser (new config fails on some 64bit systems - should be fixed) and some minor corrections
alex
parents:
9813
diff
changeset
|
75 case CONF_TYPE_PRINT_INDIRECT : |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
76 case CONF_TYPE_SUBCONFIG : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
77 return; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
78 default : |
4384 | 79 ; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
80 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
81 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
82 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Saving option %s\n",opt); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
83 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
84 save = config->config_stack[config->cs_level]; |
147 | 85 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
86 if(save) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
87 for(sl = 0; save[sl].opt != NULL; sl++){ |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
88 // Check to not save the same arg two times |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
89 if(save[sl].opt == conf && (save[sl].opt_name == NULL || strcasecmp(save[sl].opt_name,opt) == 0)) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
90 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
91 } |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
92 if(save[sl].opt) |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
93 return; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
94 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
95 |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
96 save = (config_save_t*)realloc(save,(sl+2)*sizeof(config_save_t)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
97 if(save == NULL) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
98 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",(sl+2)*sizeof(config_save_t),strerror(errno)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
99 return; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
100 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
101 memset(&save[sl],0,2*sizeof(config_save_t)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
102 save[sl].opt = conf; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
103 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
104 switch(conf->type) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
105 case CONF_TYPE_FLAG : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
106 case CONF_TYPE_INT : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
107 save[sl].param.as_int = *((int*)conf->p); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
108 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
109 case CONF_TYPE_FLOAT : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
110 save[sl].param.as_float = *((float*)conf->p); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
111 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
112 case CONF_TYPE_STRING : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
113 save[sl].param.as_pointer = *((char**)conf->p); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
114 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
115 case CONF_TYPE_FUNC_FULL : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
116 if(strcasecmp(conf->name,opt) != 0) save->opt_name = strdup(opt); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
117 case CONF_TYPE_FUNC_PARAM : |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
118 if(param) |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
119 save->param.as_pointer = strdup(param); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
120 case CONF_TYPE_FUNC : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
121 break; |
5215 | 122 case CONF_TYPE_STRING_LIST : |
123 save[sl].param.as_pointer = *((char***)conf->p); | |
124 break; | |
7114
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
125 case CONF_TYPE_POSITION : |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
126 save[sl].param.as_off_t = *((off_t*)conf->p); |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
127 break; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
128 default : |
5115 | 129 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Should never append in m_config_save_option : conf->type=%d\n",conf->type); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
130 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
131 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
132 config->config_stack[config->cs_level] = save; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
133 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
134 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
135 static int |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
136 m_config_revert_option(m_config_t* config, config_save_t* save) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
137 char* arg = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
138 config_save_t* iter=NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
139 int i=-1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
140 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
141 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
142 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
143 assert(config->cs_level >= 0); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
144 assert(save != NULL); |
147 | 145 #endif |
146 | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
147 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
148 arg = save->opt_name ? save->opt_name : save->opt->name; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
149 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Reverting option %s\n",arg); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
150 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
151 if(save->opt->default_func) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
152 save->opt->default_func(save->opt,arg); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
153 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
154 switch(save->opt->type) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
155 case CONF_TYPE_FLAG : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
156 case CONF_TYPE_INT : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
157 *((int*)save->opt->p) = save->param.as_int; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
158 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
159 case CONF_TYPE_FLOAT : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
160 *((float*)save->opt->p) = save->param.as_float; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
161 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
162 case CONF_TYPE_STRING : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
163 *((char**)save->opt->p) = save->param.as_pointer; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
164 break; |
5215 | 165 case CONF_TYPE_STRING_LIST : |
166 *((char***)save->opt->p) = save->param.as_pointer; | |
167 break; | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
168 case CONF_TYPE_FUNC_PARAM : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
169 case CONF_TYPE_FUNC_FULL : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
170 case CONF_TYPE_FUNC : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
171 if(config->cs_level > 0) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
172 for(i = config->cs_level - 1 ; i >= 0 ; i--){ |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
173 if(config->config_stack[i] == NULL) continue; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
174 for(iter = config->config_stack[i]; iter != NULL && iter->opt != NULL ; iter++) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
175 if(iter->opt == save->opt && |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
176 ((save->param.as_pointer == NULL || iter->param.as_pointer == NULL) || strcasecmp(save->param.as_pointer,iter->param.as_pointer) == 0) && |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
177 (save->opt_name == NULL || |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
178 (iter->opt_name && strcasecmp(save->opt_name,iter->opt_name)))) break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
179 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
180 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
181 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
182 free(save->param.as_pointer); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
183 if(save->opt_name) free(save->opt_name); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
184 save->opt_name = save->param.as_pointer = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
185 if(i < 0) break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
186 arg = iter->opt_name ? iter->opt_name : iter->opt->name; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
187 switch(iter->opt->type) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
188 case CONF_TYPE_FUNC : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
189 if ((((cfg_func_t) iter->opt->p)(iter->opt)) < 0) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
190 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
191 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
192 case CONF_TYPE_FUNC_PARAM : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
193 if (iter->param.as_pointer == NULL) { |
5115 | 194 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"We lost param for option %s?\n",iter->opt->name); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
195 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
196 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
197 if ((((cfg_func_param_t) iter->opt->p)(iter->opt, (char*)iter->param.as_pointer)) < 0) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
198 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
199 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
200 case CONF_TYPE_FUNC_FULL : |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
201 if (iter->param.as_pointer != NULL && ((char*)iter->param.as_pointer)[0]=='-'){ |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
202 if( ((cfg_func_arg_param_t) iter->opt->p)(iter->opt, arg, NULL) < 0) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
203 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
204 }else { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
205 if (((cfg_func_arg_param_t) save->opt->p)(iter->opt, arg, (char*)iter->param.as_pointer) < 0) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
206 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
207 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
208 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
209 break; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
210 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
211 break; |
7114
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
212 case CONF_TYPE_POSITION : |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
213 *((off_t*)save->opt->p) = save->param.as_off_t; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
214 break; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
215 default : |
5115 | 216 mp_msg(MSGT_CFGPARSER,MSGL_WARN,"Why do we reverse this : name=%s type=%d ?\n",save->opt->name,save->opt->type); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
217 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
218 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
219 return 1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
220 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
221 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
222 void |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
223 m_config_push(m_config_t* config) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
224 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
225 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
226 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
227 assert(config->cs_level >= 0); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
228 #endif |
147 | 229 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
230 config->cs_level++; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
231 config->config_stack = (config_save_t**)realloc(config->config_stack ,sizeof(config_save_t*)*(config->cs_level+1)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
232 if(config->config_stack == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
233 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*)*(config->cs_level+1),strerror(errno)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
234 config->cs_level = -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
235 return; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
236 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
237 config->config_stack[config->cs_level] = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
238 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level=%d\n",config->cs_level); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
239 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
240 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
241 int |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
242 m_config_pop(m_config_t* config) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
243 int i,ret= 1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
244 config_save_t* cs; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
245 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
246 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
247 assert(config != NULL); |
4771 | 248 //assert(config->cs_level > 0); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
249 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
250 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
251 if(config->config_stack[config->cs_level] != NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
252 cs = config->config_stack[config->cs_level]; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
253 for(i=0; cs[i].opt != NULL ; i++ ) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
254 if (m_config_revert_option(config,&cs[i]) < 0) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
255 ret = -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
256 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
257 free(config->config_stack[config->cs_level]); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
258 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
259 config->config_stack = (config_save_t**)realloc(config->config_stack ,sizeof(config_save_t*)*config->cs_level); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
260 config->cs_level--; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
261 if(config->cs_level > 0 && config->config_stack == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
262 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*)*config->cs_level,strerror(errno)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
263 config->cs_level = -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
264 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
265 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
266 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config poped level=%d\n",config->cs_level); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
267 return ret; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
268 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
269 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
270 m_config_t* |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
271 m_config_new(play_tree_t* pt) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
272 m_config_t* config; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
273 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
274 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
275 assert(pt != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
276 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
277 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
278 config = (m_config_t*)calloc(1,sizeof(m_config_t)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
279 if(config == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
280 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(m_config_t),strerror(errno)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
281 return NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
282 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
283 config->config_stack = (config_save_t**)calloc(1,sizeof(config_save_t*)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
284 if(config->config_stack == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
285 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*),strerror(errno)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
286 free(config); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
287 return NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
288 } |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
289 SET_GLOBAL(config); // We always start with global options |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
290 config->pt = pt; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
291 return config; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
292 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
293 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
294 void |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
295 m_config_free(m_config_t* config) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
296 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
297 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
298 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
299 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
300 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
301 free(config->opt_list); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
302 free(config->config_stack); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
303 free(config); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
304 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
305 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
306 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
307 static int init_conf(m_config_t *config, int mode) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
308 { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
309 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
310 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
311 assert(config->pt != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
312 assert(config->last_entry == NULL || config->last_entry->parent == config->pt); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
313 |
147 | 314 if (mode != COMMAND_LINE && mode != CONFIG_FILE) { |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
315 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "init_conf: wrong mode!\n"); |
147 | 316 return -1; |
317 } | |
318 #endif | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
319 config->parser_mode = mode; |
147 | 320 return 1; |
321 } | |
322 | |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
323 static int config_is_entry_option(m_config_t *config, char *opt, char *param) { |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
324 play_tree_t* entry = NULL; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
325 |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
326 #ifdef MP_DEBUG |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
327 assert(config->pt != NULL); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
328 #endif |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
329 |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
330 if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
331 if(!param) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
332 return ERR_MISSING_PARAM; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
333 entry = parse_playlist_file(param); |
4890
0c1526391dd3
New option use-stdin to use when stdin will be used as a file
albeu
parents:
4771
diff
changeset
|
334 if(!entry) { |
0c1526391dd3
New option use-stdin to use when stdin will be used as a file
albeu
parents:
4771
diff
changeset
|
335 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Playlist parsing failed: %s\n",param); |
0c1526391dd3
New option use-stdin to use when stdin will be used as a file
albeu
parents:
4771
diff
changeset
|
336 return 1; |
0c1526391dd3
New option use-stdin to use when stdin will be used as a file
albeu
parents:
4771
diff
changeset
|
337 } |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
338 } |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
339 |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
340 if(! IS_RUNNING(config)) { |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
341 if(strcasecmp(opt,"vcd") == 0) { |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
342 char* s; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
343 if(!param) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
344 return ERR_MISSING_PARAM; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
345 s = (char*)malloc((strlen(param) + 6 + 1)*sizeof(char)); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
346 sprintf(s,"vcd://%s",param); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
347 entry = play_tree_new(); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
348 play_tree_add_file(entry,s); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
349 free(s); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
350 } else if(strcasecmp(opt,"dvd") == 0) { |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
351 char* s; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
352 if(!param) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
353 return ERR_MISSING_PARAM; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
354 s = (char*)malloc((strlen(param) + 6 + 1)*sizeof(char)); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
355 sprintf(s,"dvd://%s",param); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
356 entry = play_tree_new(); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
357 play_tree_add_file(entry,s); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
358 free(s); |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
359 } else if(strcasecmp(opt,"tv") == 0) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
360 char *s,*pr,*prs; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
361 char *ps,*pe,*channel=NULL; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
362 char *as; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
363 int on=0; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
364 if(!param) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
365 return ERR_MISSING_PARAM; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
366 ps = param; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
367 pe = strchr(param,':'); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
368 pr = prs = (char*)malloc((strlen(param)+1)*sizeof(char)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
369 pr[0] = '\0'; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
370 while(ps) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
371 if(!pe) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
372 pe = ps + strlen(ps); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
373 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
374 as = strchr(ps,'='); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
375 if(as && as[1] != '\0' && pe-as > 0) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
376 as++; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
377 else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
378 as = NULL; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
379 if( !as && pe-ps == 2 && strncasecmp("on",ps,2) == 0 ) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
380 on = 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
381 else if(as && as-ps == 8 && strncasecmp("channel",ps,6) == 0 && pe-as > 0) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
382 channel = (char*)realloc(channel,(pe-as+1)*sizeof(char)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
383 strncpy(channel,as,pe-as); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
384 channel[pe-as] = '\0'; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
385 } else if(pe-ps > 0) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
386 if(prs != pr) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
387 prs[0] = ':'; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
388 prs++; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
389 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
390 strncpy(prs,ps,pe-ps); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
391 prs += pe-ps; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
392 prs[0] = '\0'; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
393 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
394 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
395 if(pe[0] != '\0') { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
396 ps = pe+1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
397 pe = strchr(ps,':'); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
398 } else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
399 ps = NULL; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
400 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
401 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
402 if(on) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
403 int l=5; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
404 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
405 if(channel) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
406 l += strlen(channel); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
407 s = (char*) malloc((l+1)*sizeof(char)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
408 if(channel) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
409 sprintf(s,"tv://%s",channel); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
410 else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
411 sprintf(s,"tv://"); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
412 entry = play_tree_new(); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
413 play_tree_add_file(entry,s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
414 if(strlen(pr) > 0) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
415 play_tree_set_param(entry,"tv",pr); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
416 free(s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
417 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
418 free(pr); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
419 if(channel) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
420 free(channel); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
421 |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
422 } |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
423 } |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
424 |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
425 if(entry) { |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
426 if(config->last_entry) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
427 play_tree_append_entry(config->last_entry,entry); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
428 else |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
429 play_tree_set_child(config->pt,entry); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
430 config->last_entry = entry; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
431 if(config->parser_mode == COMMAND_LINE) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
432 UNSET_GLOBAL(config); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
433 return 1; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
434 } else |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
435 return 0; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
436 } |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
437 |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
438 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
439 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
440 static int config_read_option(m_config_t *config,config_t** conf_list, char *opt, char *param) |
147 | 441 { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
442 int i=0,nconf = 0; |
195 | 443 long tmp_int; |
7114
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
444 off_t tmp_off; |
195 | 445 double tmp_float; |
7114
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
446 int dummy; |
160 | 447 int ret = -1; |
195 | 448 char *endptr; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
449 config_t* conf=NULL; |
147 | 450 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
451 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
452 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
453 assert(conf_list != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
454 assert(opt != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
455 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
456 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
457 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: conf=%p opt='%s' param='%s'\n", |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
458 conf, opt, param); |
4220
fe2c20d52a25
Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents:
4156
diff
changeset
|
459 for(nconf = 0 ; conf_list[nconf] != NULL; nconf++) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
460 conf = conf_list[nconf]; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
461 for (i = 0; conf[i].name != NULL; i++) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
462 int namelength; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
463 /* allow 'aa*' in config.name */ |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
464 namelength=strlen(conf[i].name); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
465 if ( (conf[i].name[namelength-1]=='*') && |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
466 !memcmp(opt, conf[i].name, namelength-1)) |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
467 goto option_found; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
468 if (!strcasecmp(opt, conf[i].name)) |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
469 goto option_found; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
470 } |
147 | 471 } |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
472 if (config->parser_mode == CONFIG_FILE) |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
473 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid option: %s\n",opt); |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
474 ret = ERR_NOT_AN_OPTION; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
475 goto out; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
476 option_found : |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
477 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: name='%s' p=%p type=%d\n", |
2621 | 478 conf[i].name, conf[i].p, conf[i].type); |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
479 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
480 if (conf[i].flags & CONF_NOCFG && config->parser_mode == CONFIG_FILE) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
481 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "this option can only be used on command line:\n", opt); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
482 ret = ERR_NOT_AN_OPTION; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
483 goto out; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
484 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
485 if (conf[i].flags & CONF_NOCMD && config->parser_mode == COMMAND_LINE) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
486 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "this option can only be used in config file:\n", opt); |
160 | 487 ret = ERR_NOT_AN_OPTION; |
488 goto out; | |
489 } | |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
490 ret = config_is_entry_option(config,opt,param); |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
491 if(ret != 0) |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
492 return ret; |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
493 else |
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
494 ret = -1; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
495 if(! IS_RUNNING(config) && ! IS_GLOBAL(config) && |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
496 ! (conf[i].flags & CONF_GLOBAL) && conf[i].type != CONF_TYPE_SUBCONFIG ) |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
497 m_config_push(config); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
498 if( !(conf[i].flags & CONF_NOSAVE) && ! (conf[i].flags & CONF_GLOBAL) ) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
499 m_config_save_option(config,&conf[i],opt,param); |
2619 | 500 switch (conf[i].type) { |
147 | 501 case CONF_TYPE_FLAG: |
502 /* flags need a parameter in config file */ | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
503 if (config->parser_mode == CONFIG_FILE) { |
147 | 504 if (!strcasecmp(param, "yes") || /* any other language? */ |
505 !strcasecmp(param, "ja") || | |
161
9008302e2dc0
Added support for spanish (Yes, I'm a C programer also ;o)
telenieko
parents:
160
diff
changeset
|
506 !strcasecmp(param, "si") || |
147 | 507 !strcasecmp(param, "igen") || |
508 !strcasecmp(param, "y") || | |
1536
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
509 !strcasecmp(param, "j") || |
147 | 510 !strcasecmp(param, "i") || |
511 !strcmp(param, "1")) | |
2619 | 512 *((int *) conf[i].p) = conf[i].max; |
151 | 513 else if (!strcasecmp(param, "no") || |
147 | 514 !strcasecmp(param, "nein") || |
515 !strcasecmp(param, "nicht") || | |
516 !strcasecmp(param, "nem") || | |
517 !strcasecmp(param, "n") || | |
518 !strcmp(param, "0")) | |
2619 | 519 *((int *) conf[i].p) = conf[i].min; |
160 | 520 else { |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
521 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid parameter for flag: %s\n", param); |
160 | 522 ret = ERR_OUT_OF_RANGE; |
523 goto out; | |
524 } | |
525 ret = 1; | |
147 | 526 } else { /* parser_mode == COMMAND_LINE */ |
2619 | 527 *((int *) conf[i].p) = conf[i].max; |
160 | 528 ret = 0; |
147 | 529 } |
530 break; | |
531 case CONF_TYPE_INT: | |
532 if (param == NULL) | |
160 | 533 goto err_missing_param; |
195 | 534 |
535 tmp_int = strtol(param, &endptr, 0); | |
536 if (*endptr) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
537 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be an integer: %s\n", param); |
160 | 538 ret = ERR_OUT_OF_RANGE; |
539 goto out; | |
540 } | |
147 | 541 |
2619 | 542 if (conf[i].flags & CONF_MIN) |
543 if (tmp_int < conf[i].min) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
544 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %d: %s\n", (int) conf[i].min, param); |
160 | 545 ret = ERR_OUT_OF_RANGE; |
546 goto out; | |
547 } | |
147 | 548 |
2619 | 549 if (conf[i].flags & CONF_MAX) |
550 if (tmp_int > conf[i].max) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
551 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %d: %s\n", (int) conf[i].max, param); |
160 | 552 ret = ERR_OUT_OF_RANGE; |
553 goto out; | |
554 } | |
147 | 555 |
2619 | 556 *((int *) conf[i].p) = tmp_int; |
160 | 557 ret = 1; |
147 | 558 break; |
559 case CONF_TYPE_FLOAT: | |
560 if (param == NULL) | |
160 | 561 goto err_missing_param; |
7870
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
562 /* <olo@altkom.com.pl> Use portable C locale for parsing floats: */ |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
563 #ifdef USE_SETLOCALE |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
564 setlocale(LC_NUMERIC, "C"); |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
565 #endif |
195 | 566 tmp_float = strtod(param, &endptr); |
2031
624df8ea0e0e
New aspect prescale code, parses aspect value from mpeg sequence header or commandline.
atmos4
parents:
1629
diff
changeset
|
567 |
7611
411886c03c54
strtod is locale-dependant, so it may only accept either '.' or ',' as decimal point,
atmos4
parents:
7503
diff
changeset
|
568 switch(*endptr) { |
411886c03c54
strtod is locale-dependant, so it may only accept either '.' or ',' as decimal point,
atmos4
parents:
7503
diff
changeset
|
569 case ':': |
411886c03c54
strtod is locale-dependant, so it may only accept either '.' or ',' as decimal point,
atmos4
parents:
7503
diff
changeset
|
570 case '/': |
2031
624df8ea0e0e
New aspect prescale code, parses aspect value from mpeg sequence header or commandline.
atmos4
parents:
1629
diff
changeset
|
571 tmp_float /= strtod(endptr+1, &endptr); |
7870
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
572 default: |
7611
411886c03c54
strtod is locale-dependant, so it may only accept either '.' or ',' as decimal point,
atmos4
parents:
7503
diff
changeset
|
573 break; |
411886c03c54
strtod is locale-dependant, so it may only accept either '.' or ',' as decimal point,
atmos4
parents:
7503
diff
changeset
|
574 } |
7870
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
575 #ifdef USE_SETLOCALE |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
576 setlocale(LC_NUMERIC, ""); |
b571ae470520
Fixed a bug in MPlayer which would prevent proper parsing of
arpi
parents:
7611
diff
changeset
|
577 #endif |
2031
624df8ea0e0e
New aspect prescale code, parses aspect value from mpeg sequence header or commandline.
atmos4
parents:
1629
diff
changeset
|
578 |
195 | 579 if (*endptr) { |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
580 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be a floating point number" |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
581 " or a ratio (numerator[:/]denominator): %s\n", param); |
160 | 582 ret = ERR_MISSING_PARAM; |
583 goto out; | |
584 } | |
147 | 585 |
2619 | 586 if (conf[i].flags & CONF_MIN) |
587 if (tmp_float < conf[i].min) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
588 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %f: %s\n", conf[i].min, param); |
160 | 589 ret = ERR_OUT_OF_RANGE; |
590 goto out; | |
591 } | |
147 | 592 |
2619 | 593 if (conf[i].flags & CONF_MAX) |
594 if (tmp_float > conf[i].max) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
595 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %f: %s\n", conf[i].max, param); |
160 | 596 ret = ERR_OUT_OF_RANGE; |
597 goto out; | |
598 } | |
147 | 599 |
2619 | 600 *((float *) conf[i].p) = tmp_float; |
160 | 601 ret = 1; |
147 | 602 break; |
603 case CONF_TYPE_STRING: | |
604 if (param == NULL) | |
160 | 605 goto err_missing_param; |
147 | 606 |
2619 | 607 if (conf[i].flags & CONF_MIN) |
608 if (strlen(param) < conf[i].min) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
609 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %d chars: %s\n", |
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
610 (int) conf[i].min, param); |
160 | 611 ret = ERR_OUT_OF_RANGE; |
612 goto out; | |
613 } | |
147 | 614 |
2619 | 615 if (conf[i].flags & CONF_MAX) |
616 if (strlen(param) > conf[i].max) { | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
617 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %d chars: %s\n", |
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
618 (int) conf[i].max, param); |
160 | 619 ret = ERR_OUT_OF_RANGE; |
620 goto out; | |
621 } | |
2619 | 622 *((char **) conf[i].p) = strdup(param); |
160 | 623 ret = 1; |
147 | 624 break; |
5215 | 625 case CONF_TYPE_STRING_LIST: |
626 if (param == NULL) | |
627 goto err_missing_param; | |
628 else { | |
629 int n = 0,len; | |
630 char *ptr = param, *last_ptr, **res; | |
631 | |
632 while(ptr[0] != '\0') { | |
633 last_ptr = ptr; | |
634 ptr = strchr(ptr,LIST_SEPARATOR); | |
635 if(!ptr) { | |
7503
f0888351bd46
accept empty strings too for STRING_LIST (example: "-xyz 1,2.5,,4," )
arpi
parents:
7472
diff
changeset
|
636 // if(strlen(last_ptr) > 0) |
5215 | 637 n++; |
638 break; | |
639 } | |
640 ptr++; | |
641 n++; | |
642 } | |
643 if(n == 0) | |
644 goto err_missing_param; | |
645 else if( (conf[i].flags & CONF_MIN && n < conf[i].min) || | |
646 (conf[i].flags & CONF_MAX && n > conf[i].max) ) { | |
647 ret = ERR_OUT_OF_RANGE; | |
648 goto out; | |
649 } | |
650 ret = 1; | |
8384
7a7980b874f5
fixed 'mplayer -nosound xxx' sig11 if configfile have string list options
arpi
parents:
8164
diff
changeset
|
651 res = malloc((n+2)*sizeof(char*)); |
5215 | 652 ptr = param; |
653 n = 0; | |
7503
f0888351bd46
accept empty strings too for STRING_LIST (example: "-xyz 1,2.5,,4," )
arpi
parents:
7472
diff
changeset
|
654 // while(ptr[0] != '\0') { |
f0888351bd46
accept empty strings too for STRING_LIST (example: "-xyz 1,2.5,,4," )
arpi
parents:
7472
diff
changeset
|
655 while(1) { |
5215 | 656 last_ptr = ptr; |
657 ptr = strchr(ptr,LIST_SEPARATOR); | |
658 if(!ptr) { | |
7503
f0888351bd46
accept empty strings too for STRING_LIST (example: "-xyz 1,2.5,,4," )
arpi
parents:
7472
diff
changeset
|
659 //if(strlen(last_ptr) > 0) |
f0888351bd46
accept empty strings too for STRING_LIST (example: "-xyz 1,2.5,,4," )
arpi
parents:
7472
diff
changeset
|
660 { |
5215 | 661 res[n] = strdup(last_ptr); |
662 n++; | |
663 } | |
664 break; | |
665 } | |
666 len = ptr - last_ptr; | |
667 res[n] = (char*)malloc(len + 1); | |
7503
f0888351bd46
accept empty strings too for STRING_LIST (example: "-xyz 1,2.5,,4," )
arpi
parents:
7472
diff
changeset
|
668 if(len) strncpy(res[n],last_ptr,len); |
5215 | 669 res[n][len] = '\0'; |
670 ptr++; | |
671 n++; | |
672 } | |
673 res[n] = NULL; | |
674 *((char ***) conf[i].p) = res; | |
675 } | |
676 break; | |
151 | 677 case CONF_TYPE_FUNC_PARAM: |
678 if (param == NULL) | |
160 | 679 goto err_missing_param; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
680 if ((((cfg_func_param_t) conf[i].p)(conf + i, param)) < 0) { |
160 | 681 ret = ERR_FUNC_ERR; |
682 goto out; | |
683 } | |
684 ret = 1; | |
151 | 685 break; |
1536
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
686 case CONF_TYPE_FUNC_FULL: |
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
687 if (param!=NULL && param[0]=='-'){ |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
688 ret=((cfg_func_arg_param_t) conf[i].p)(conf + i, opt, NULL); |
1536
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
689 if (ret>=0) ret=0; |
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
690 /* if we return >=0: param is processed again (if there is any) */ |
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
691 }else{ |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
692 ret=((cfg_func_arg_param_t) conf[i].p)(conf + i, opt, param); |
1536
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
693 /* if we return 0: need no param, precess it again */ |
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
694 /* if we return 1: accepted param */ |
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
695 } |
e89233dab4da
New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents:
1304
diff
changeset
|
696 break; |
150 | 697 case CONF_TYPE_FUNC: |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
698 if ((((cfg_func_t) conf[i].p)(conf + i)) < 0) { |
160 | 699 ret = ERR_FUNC_ERR; |
700 goto out; | |
701 } | |
702 ret = 0; | |
150 | 703 break; |
2619 | 704 case CONF_TYPE_SUBCONFIG: |
705 { | |
706 char *subparam; | |
707 char *subopt; | |
708 int subconf_optnr; | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
709 config_t *subconf; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
710 config_t *sublist[] = { NULL , NULL }; |
2619 | 711 char *token; |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
712 char *p; |
2619 | 713 |
714 if (param == NULL) | |
715 goto err_missing_param; | |
716 | |
3613 | 717 subparam = malloc(strlen(param)+1); |
718 subopt = malloc(strlen(param)+1); | |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
719 p = strdup(param); // In case that param is a static string (cf man strtok) |
2619 | 720 |
721 subconf = conf[i].p; | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
722 sublist[0] = subconf; |
2619 | 723 for (subconf_optnr = 0; subconf[subconf_optnr].name != NULL; subconf_optnr++) |
724 /* NOTHING */; | |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
725 config->sub_conf = opt; |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
726 token = strtok(p, (char *)&(":")); |
2619 | 727 while(token) |
728 { | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
729 int sscanf_ret; |
3761 | 730 /* clear out */ |
731 subopt[0] = subparam[0] = 0; | |
2619 | 732 |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7114
diff
changeset
|
733 sscanf_ret = sscanf(token, "%[^=]=%[^:]", subopt, subparam); |
3761 | 734 |
735 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "token: '%s', i=%d, subopt='%s', subparam='%s' (ret: %d)\n", token, i, subopt, subparam, sscanf_ret); | |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
736 switch(sscanf_ret) |
2621 | 737 { |
738 case 1: | |
3761 | 739 subparam[0] = 0; |
2621 | 740 case 2: |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
741 if ((ret = config_read_option(config,sublist, subopt, subparam)) < 0) |
2621 | 742 { |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
743 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Subconfig parsing returned error: %d in token: %s\n", |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
744 ret, token); |
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
745 goto out; |
2621 | 746 } |
747 break; | |
748 default: | |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
749 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid subconfig argument! ('%s')\n", token); |
3559
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
750 ret = ERR_NOT_AN_OPTION; |
f61dcc63be5f
exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents:
2650
diff
changeset
|
751 goto out; |
2621 | 752 } |
2619 | 753 token = strtok(NULL, (char *)&(":")); |
754 } | |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
755 config->sub_conf = NULL; |
2619 | 756 free(subparam); |
757 free(subopt); | |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
758 free(p); |
2619 | 759 ret = 1; |
760 break; | |
761 } | |
152 | 762 case CONF_TYPE_PRINT: |
5115 | 763 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", (char *) conf[i].p); |
152 | 764 exit(1); |
10320
d83e4e54985c
backport PRINT_INDIRECT to old-config parser (new config fails on some 64bit systems - should be fixed) and some minor corrections
alex
parents:
9813
diff
changeset
|
765 case CONF_TYPE_PRINT_INDIRECT: |
d83e4e54985c
backport PRINT_INDIRECT to old-config parser (new config fails on some 64bit systems - should be fixed) and some minor corrections
alex
parents:
9813
diff
changeset
|
766 mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", *(char **) conf[i].p); |
d83e4e54985c
backport PRINT_INDIRECT to old-config parser (new config fails on some 64bit systems - should be fixed) and some minor corrections
alex
parents:
9813
diff
changeset
|
767 exit(1); |
7114
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
768 case CONF_TYPE_POSITION: |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
769 if (param == NULL) |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
770 goto err_missing_param; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
771 |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
772 if (sscanf(param, sizeof(off_t) == sizeof(int) ? |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7879
diff
changeset
|
773 "%d%c" : "%lld%c", &tmp_off, (char *)&dummy) != 1) { |
7114
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
774 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be an integer: %s\n", param); |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
775 ret = ERR_OUT_OF_RANGE; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
776 goto out; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
777 } |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
778 |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
779 if (conf[i].flags & CONF_MIN) |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
780 if (tmp_off < conf[i].min) { |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
781 mp_msg(MSGT_CFGPARSER, MSGL_ERR, |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
782 (sizeof(off_t) == sizeof(int) ? |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
783 "parameter must be >= %d: %s\n" : |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
784 "parameter must be >= %lld: %s\n"), |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
785 (off_t) conf[i].min, param); |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
786 ret = ERR_OUT_OF_RANGE; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
787 goto out; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
788 } |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
789 |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
790 if (conf[i].flags & CONF_MAX) |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
791 if (tmp_off > conf[i].max) { |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
792 mp_msg(MSGT_CFGPARSER, MSGL_ERR, |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
793 (sizeof(off_t) == sizeof(int) ? |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
794 "parameter must be <= %d: %s\n" : |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
795 "parameter must be <= %lld: %s\n"), |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
796 (off_t) conf[i].max, param); |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
797 ret = ERR_OUT_OF_RANGE; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
798 goto out; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
799 } |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
800 |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
801 *((off_t *) conf[i].p) = tmp_off; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
802 ret = 1; |
79187bd813a6
64-bit -sb offsets patch by Andy Goth <unununium@openverse.com>
alex
parents:
5934
diff
changeset
|
803 break; |
147 | 804 default: |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
805 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown config type specified in conf-mplayer.h!\n"); |
147 | 806 break; |
807 } | |
160 | 808 out: |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
809 if(ret >= 0 && ! IS_RUNNING(config) && ! IS_GLOBAL(config) && ! (conf[i].flags & CONF_GLOBAL) && conf[i].type != CONF_TYPE_SUBCONFIG ) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
810 play_tree_t* dest = config->last_entry ? config->last_entry : config->last_parent; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
811 char* o; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
812 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
813 assert(dest != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
814 #endif |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
815 if(config->sub_conf) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
816 o = (char*)malloc((strlen(config->sub_conf) + 1 + strlen(opt) + 1)*sizeof(char)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
817 sprintf(o,"%s:%s",config->sub_conf,opt); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
818 } else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
819 o =strdup(opt); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
820 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
821 if(ret == 0) |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
822 play_tree_set_param(dest,o,NULL); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
823 else if(ret > 0) |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
824 play_tree_set_param(dest,o,param); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
825 free(o); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
826 m_config_pop(config); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
827 } |
160 | 828 return ret; |
829 err_missing_param: | |
3684
00bd914b6fb1
subconfig fix (if sscanf()==1, then null out second (non-present) parameter) and some errormessage fixes
alex
parents:
3613
diff
changeset
|
830 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "missing parameter for option: %s\n", opt); |
160 | 831 ret = ERR_MISSING_PARAM; |
832 goto out; | |
147 | 833 } |
834 | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
835 int m_config_set_option(m_config_t *config,char *opt, char *param) { |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
836 char *e; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
837 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
838 assert(config != NULL); |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
839 assert(config->opt_list != NULL); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
840 assert(opt != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
841 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
842 mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Setting option %s=%s\n",opt,param); |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
843 e = strchr(opt,':'); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
844 if(e && e[1] != '\0') { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
845 int ret; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
846 config_t* opt_list[] = { NULL, NULL }; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
847 char* s = (char*)malloc((e-opt+1)*sizeof(char)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
848 strncpy(s,opt,e-opt); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
849 s[e-opt] = '\0'; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
850 opt_list[0] = m_config_get_option_ptr(config,s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
851 if(!opt_list[0]) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
852 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"m_config_set_option %s=%s : no %s subconfig\n",opt,param,s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
853 free(s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
854 return ERR_NOT_AN_OPTION; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
855 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
856 e++; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
857 s = (char*)realloc(s,strlen(e) + 1); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
858 strcpy(s,e); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
859 ret = config_read_option(config,opt_list,s,param); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
860 free(s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
861 return ret; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
862 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
863 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
864 return config_read_option(config,config->opt_list,opt,param); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
865 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
866 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
867 int m_config_parse_config_file(m_config_t *config, char *conffile) |
147 | 868 { |
5115 | 869 #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_INFO,"%s(%d): ", conffile, line_num) |
9813 | 870 #define MAX_LINE_LEN 10000 |
871 #define MAX_OPT_LEN 1000 | |
872 #define MAX_PARAM_LEN 1000 | |
147 | 873 FILE *fp; |
874 char *line; | |
179 | 875 char opt[MAX_OPT_LEN + 1]; |
876 char param[MAX_PARAM_LEN + 1]; | |
167 | 877 char c; /* for the "" and '' check */ |
147 | 878 int tmp; |
879 int line_num = 0; | |
880 int line_pos; /* line pos */ | |
881 int opt_pos; /* opt pos */ | |
882 int param_pos; /* param pos */ | |
883 int ret = 1; | |
1090 | 884 int errors = 0; |
147 | 885 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
886 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
887 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
888 // assert(conf_list != NULL); |
147 | 889 #endif |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
890 if (++config->recursion_depth > 1) |
5115 | 891 mp_msg(MSGT_CFGPARSER,MSGL_INFO,"Reading config file: %s", conffile); |
1089 | 892 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
893 if (config->recursion_depth > MAX_RECURSION_DEPTH) { |
5934 | 894 mp_msg(MSGT_CFGPARSER,MSGL_ERR,": too deep 'include'. check your configfiles\n"); |
1089 | 895 ret = -1; |
896 goto out; | |
897 } | |
166 | 898 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
899 if (init_conf(config, CONFIG_FILE) == -1) { |
166 | 900 ret = -1; |
901 goto out; | |
902 } | |
147 | 903 |
179 | 904 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { |
5934 | 905 mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"\ncan't get memory for 'line': %s", strerror(errno)); |
166 | 906 ret = -1; |
907 goto out; | |
147 | 908 } |
909 | |
910 if ((fp = fopen(conffile, "r")) == NULL) { | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
911 if (config->recursion_depth > 1) |
5934 | 912 mp_msg(MSGT_CFGPARSER,MSGL_ERR,": %s\n", strerror(errno)); |
147 | 913 free(line); |
166 | 914 ret = 0; |
915 goto out; | |
147 | 916 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
917 if (config->recursion_depth > 1) |
5115 | 918 mp_msg(MSGT_CFGPARSER,MSGL_INFO,"\n"); |
147 | 919 |
920 while (fgets(line, MAX_LINE_LEN, fp)) { | |
1090 | 921 if (errors >= 16) { |
5934 | 922 mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"too many errors\n"); |
1090 | 923 goto out; |
924 } | |
925 | |
147 | 926 line_num++; |
927 line_pos = 0; | |
928 | |
929 /* skip whitespaces */ | |
930 while (isspace(line[line_pos])) | |
931 ++line_pos; | |
932 | |
933 /* EOL / comment */ | |
934 if (line[line_pos] == '\0' || line[line_pos] == '#') | |
935 continue; | |
936 | |
480 | 937 /* read option. */ |
938 for (opt_pos = 0; isprint(line[line_pos]) && | |
939 line[line_pos] != ' ' && | |
940 line[line_pos] != '#' && | |
941 line[line_pos] != '='; /* NOTHING */) { | |
147 | 942 opt[opt_pos++] = line[line_pos++]; |
943 if (opt_pos >= MAX_OPT_LEN) { | |
944 PRINT_LINENUM; | |
5934 | 945 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long option\n"); |
1090 | 946 errors++; |
147 | 947 ret = -1; |
1090 | 948 goto nextline; |
147 | 949 } |
950 } | |
951 if (opt_pos == 0) { | |
952 PRINT_LINENUM; | |
5934 | 953 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"parse error\n"); |
147 | 954 ret = -1; |
1090 | 955 errors++; |
147 | 956 continue; |
957 } | |
958 opt[opt_pos] = '\0'; | |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
959 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
960 #ifdef MP_DEBUG |
147 | 961 PRINT_LINENUM; |
5115 | 962 mp_msg(MSGT_CFGPARSER,MSGL_INFO,"option: %s\n", opt); |
147 | 963 #endif |
964 | |
965 /* skip whitespaces */ | |
966 while (isspace(line[line_pos])) | |
967 ++line_pos; | |
968 | |
969 /* check '=' */ | |
970 if (line[line_pos++] != '=') { | |
971 PRINT_LINENUM; | |
5934 | 972 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"option without parameter\n"); |
147 | 973 ret = -1; |
1090 | 974 errors++; |
147 | 975 continue; |
976 } | |
977 | |
978 /* whitespaces... */ | |
979 while (isspace(line[line_pos])) | |
980 ++line_pos; | |
981 | |
982 /* read the parameter */ | |
167 | 983 if (line[line_pos] == '"' || line[line_pos] == '\'') { |
984 c = line[line_pos]; | |
985 ++line_pos; | |
986 for (param_pos = 0; line[line_pos] != c; /* NOTHING */) { | |
987 param[param_pos++] = line[line_pos++]; | |
988 if (param_pos >= MAX_PARAM_LEN) { | |
989 PRINT_LINENUM; | |
5934 | 990 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long parameter\n"); |
167 | 991 ret = -1; |
1090 | 992 errors++; |
993 goto nextline; | |
167 | 994 } |
995 } | |
996 line_pos++; /* skip the closing " or ' */ | |
997 } else { | |
998 for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos]) | |
999 && line[line_pos] != '#'; /* NOTHING */) { | |
1000 param[param_pos++] = line[line_pos++]; | |
1001 if (param_pos >= MAX_PARAM_LEN) { | |
1002 PRINT_LINENUM; | |
5934 | 1003 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long parameter\n"); |
167 | 1004 ret = -1; |
1090 | 1005 errors++; |
1006 goto nextline; | |
167 | 1007 } |
147 | 1008 } |
1009 } | |
1010 param[param_pos] = '\0'; | |
1011 | |
1012 /* did we read a parameter? */ | |
1013 if (param_pos == 0) { | |
1014 PRINT_LINENUM; | |
5934 | 1015 mp_msg(MSGT_CFGPARSER,MSGL_ERR,"option without parameter\n"); |
147 | 1016 ret = -1; |
1090 | 1017 errors++; |
147 | 1018 continue; |
1019 } | |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1020 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1021 #ifdef MP_DEBUG |
147 | 1022 PRINT_LINENUM; |
5115 | 1023 mp_msg(MSGT_CFGPARSER,MSGL_INFO,"parameter: %s\n", param); |
147 | 1024 #endif |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1025 |
147 | 1026 /* now, check if we have some more chars on the line */ |
1027 /* whitespace... */ | |
1028 while (isspace(line[line_pos])) | |
1029 ++line_pos; | |
1030 | |
1031 /* EOL / comment */ | |
1032 if (line[line_pos] != '\0' && line[line_pos] != '#') { | |
1033 PRINT_LINENUM; | |
5934 | 1034 mp_msg(MSGT_CFGPARSER,MSGL_WARN,"extra characters on line: %s\n", line+line_pos); |
147 | 1035 ret = -1; |
1036 } | |
1037 | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1038 tmp = m_config_set_option(config, opt, param); |
147 | 1039 switch (tmp) { |
1040 case ERR_NOT_AN_OPTION: | |
1041 case ERR_MISSING_PARAM: | |
1042 case ERR_OUT_OF_RANGE: | |
150 | 1043 case ERR_FUNC_ERR: |
1044 PRINT_LINENUM; | |
5115 | 1045 mp_msg(MSGT_CFGPARSER,MSGL_INFO,"%s\n", opt); |
150 | 1046 ret = -1; |
1090 | 1047 errors++; |
150 | 1048 continue; |
1049 /* break */ | |
147 | 1050 } |
1093 | 1051 nextline: |
1304 | 1052 ; |
147 | 1053 } |
1054 | |
1055 free(line); | |
1056 fclose(fp); | |
166 | 1057 out: |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1058 --config->recursion_depth; |
147 | 1059 return ret; |
1060 } | |
1061 | |
7201
22beff6edf75
Improved MacOS X SDL support, enable SDL main() wrapper for Darwin, remove unused envp.
atmos4
parents:
7145
diff
changeset
|
1062 int m_config_parse_command_line(m_config_t *config, int argc, char **argv) |
147 | 1063 { |
1064 int i; | |
1065 int tmp; | |
1066 char *opt; | |
2615 | 1067 int no_more_opts = 0; |
147 | 1068 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1069 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1070 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1071 assert(config->pt != NULL); |
147 | 1072 assert(argv != NULL); |
1073 assert(argc >= 1); | |
1074 #endif | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1075 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1076 if (init_conf(config, COMMAND_LINE) == -1) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1077 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1078 if(config->last_parent == NULL) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1079 config->last_parent = config->pt; |
1089 | 1080 /* in order to work recursion detection properly in parse_config_file */ |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1081 ++config->recursion_depth; |
1089 | 1082 |
147 | 1083 for (i = 1; i < argc; i++) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1084 //next: |
147 | 1085 opt = argv[i]; |
2650
bf7248edcc20
fixed commandline bug: handling '-' as option when '--' unused
alex
parents:
2624
diff
changeset
|
1086 /* check for -- (no more options id.) except --help! */ |
2623 | 1087 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h')) |
2615 | 1088 { |
1089 no_more_opts = 1; | |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1090 if (i+1 >= argc) |
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1091 { |
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1092 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "You added '--' but no filenames presented!\n"); |
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1093 goto err_out; |
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1094 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1095 continue; |
2615 | 1096 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1097 if((opt[0] == '{') && (opt[1] == '\0')) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1098 { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1099 play_tree_t* entry = play_tree_new(); |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
1100 UNSET_GLOBAL(config); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1101 if(config->last_entry == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1102 play_tree_set_child(config->last_parent,entry); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1103 } else { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1104 play_tree_append_entry(config->last_entry,entry); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1105 config->last_entry = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1106 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1107 config->last_parent = entry; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1108 continue; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1109 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1110 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1111 if((opt[0] == '}') && (opt[1] == '\0')) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1112 { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1113 if( ! config->last_parent || ! config->last_parent->parent) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1114 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n"); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1115 goto err_out; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1116 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1117 config->last_entry = config->last_parent; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1118 config->last_parent = config->last_entry->parent; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1119 continue; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1120 } |
2615 | 1121 |
2650
bf7248edcc20
fixed commandline bug: handling '-' as option when '--' unused
alex
parents:
2624
diff
changeset
|
1122 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ |
2615 | 1123 { |
1124 /* remove trailing '-' */ | |
1125 opt++; | |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1126 |
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1127 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); |
5655
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1128 // We handle here some specific option |
5215 | 1129 if(strcasecmp(opt,"list-options") == 0) { |
1130 m_config_list_options(config); | |
1131 exit(1); | |
5655
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1132 // Loop option when it apply to a group |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1133 } else if(strcasecmp(opt,"loop") == 0 && |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1134 (! config->last_entry || config->last_entry->child) ) { |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1135 int l; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1136 char* end; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1137 l = strtol(argv[i+1],&end,0); |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1138 if(!end) |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1139 tmp = ERR_OUT_OF_RANGE; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1140 else { |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1141 play_tree_t* pt = config->last_entry ? config->last_entry : config->last_parent; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1142 l = l <= 0 ? -1 : l; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1143 pt->loop = l; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1144 tmp = 1; |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1145 } |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1146 } else // All normal options |
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1147 tmp = m_config_set_option(config, opt, argv[i + 1]); |
1629 | 1148 |
2615 | 1149 switch (tmp) { |
1150 case ERR_NOT_AN_OPTION: | |
1151 case ERR_MISSING_PARAM: | |
1152 case ERR_OUT_OF_RANGE: | |
1153 case ERR_FUNC_ERR: | |
5215 | 1154 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error: "); |
1155 m_config_error(tmp,opt,argv[i+1]); | |
160 | 1156 goto err_out; |
2615 | 1157 default: |
1075 | 1158 i += tmp; |
2615 | 1159 break; |
1160 } | |
1161 } | |
1162 else /* filename */ | |
1163 { | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1164 play_tree_t* entry = play_tree_new(); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1165 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1166 play_tree_add_file(entry,argv[i]); |
4890
0c1526391dd3
New option use-stdin to use when stdin will be used as a file
albeu
parents:
4771
diff
changeset
|
1167 if(strcasecmp(argv[i],"-") == 0) |
0c1526391dd3
New option use-stdin to use when stdin will be used as a file
albeu
parents:
4771
diff
changeset
|
1168 m_config_set_option(config,"use-stdin",NULL); |
2615 | 1169 /* opt is not an option -> treat it as a filename */ |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
1170 UNSET_GLOBAL(config); // We start entry specific options |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1171 if(config->last_entry == NULL) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1172 play_tree_set_child(config->last_parent,entry); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1173 else |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1174 play_tree_append_entry(config->last_entry,entry); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1175 config->last_entry = entry; |
147 | 1176 } |
1089 | 1177 } |
2615 | 1178 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1179 --config->recursion_depth; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1180 if(config->last_parent != config->pt) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1181 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); |
5655
117f34bb7097
Add correct loop option parsing in command line parser.
albeu
parents:
5215
diff
changeset
|
1182 config->flags &= (!CONFIG_GLOBAL); |
4268
83aedfde69f8
Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents:
4254
diff
changeset
|
1183 SET_RUNNING(config); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1184 return 1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1185 #if 0 |
1629 | 1186 err_out_mem: |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1187 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "can't allocate memory for filenames (%s)\n", strerror(errno)); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1188 #endif |
160 | 1189 err_out: |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1190 --config->recursion_depth; |
2624
64844fccf623
partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents:
2623
diff
changeset
|
1191 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "command line: %s\n", argv[i]); |
160 | 1192 return -1; |
147 | 1193 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1194 |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1195 int |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1196 m_config_register_options(m_config_t *config,config_t *args) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1197 int list_len = 0; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1198 config_t** conf_list = config->opt_list; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1199 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1200 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1201 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1202 assert(args != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1203 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1204 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1205 if(conf_list) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1206 for ( ; conf_list[list_len] != NULL; list_len++) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1207 /* NOTHING */; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1208 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1209 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1210 conf_list = (config_t**)realloc(conf_list,sizeof(struct conf*)*(list_len+2)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1211 if(conf_list == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1212 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(struct conf*)*(list_len+2),strerror(errno)); |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1213 return 0; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1214 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1215 conf_list[list_len] = args; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1216 conf_list[list_len+1] = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1217 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1218 config->opt_list = conf_list; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1219 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1220 return 1; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1221 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1222 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1223 config_t* |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1224 m_config_get_option(m_config_t *config, char* arg) { |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1225 int i,j; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1226 char *e; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1227 config_t *conf; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1228 config_t **conf_list; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1229 config_t* cl[] = { NULL, NULL }; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1230 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1231 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1232 assert(config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1233 assert(arg != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1234 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1235 |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1236 e = strchr(arg,':'); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1237 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1238 if(e) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1239 char *s; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1240 s = (char*)malloc((e-arg+1)*sizeof(char)); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1241 strncpy(s,arg,e-arg); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1242 s[e-arg] = '\0'; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1243 cl[0] = m_config_get_option(config,s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1244 conf_list = cl; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1245 free(s); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1246 } else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1247 conf_list = config->opt_list; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1248 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1249 if(conf_list) { |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1250 for(j = 0 ; conf_list[j] != NULL ; j++) { |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1251 conf = conf_list[j]; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1252 for(i=0; conf[i].name != NULL; i++) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1253 if(strcasecmp(conf[i].name,arg) == 0) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1254 return &conf[i]; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1255 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1256 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1257 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1258 return NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1259 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1260 |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1261 void* |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1262 m_config_get_option_ptr(m_config_t *config, char* arg) { |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1263 config_t* conf; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1264 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1265 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1266 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1267 assert(arg != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1268 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1269 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1270 conf = m_config_get_option(config,arg); |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1271 if(!conf) return NULL; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1272 return conf->p; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1273 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3761
diff
changeset
|
1274 |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1275 int |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1276 m_config_get_int (m_config_t *config, char* arg,int* err_ret) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1277 int *ret; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1278 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1279 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1280 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1281 assert(arg != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1282 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1283 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1284 ret = m_config_get_option_ptr(config,arg); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1285 if(err_ret) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1286 *err_ret = 0; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1287 if(!ret) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1288 if(err_ret) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1289 *err_ret = 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1290 return -1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1291 } else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1292 return (*ret); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1293 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1294 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1295 float |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1296 m_config_get_float (m_config_t *config, char* arg,int* err_ret) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1297 float *ret; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1298 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1299 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1300 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1301 assert(arg != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1302 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1303 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1304 ret = m_config_get_option_ptr(config,arg); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1305 if(err_ret) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1306 *err_ret = 0; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1307 if(!ret) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1308 if(err_ret) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1309 *err_ret = 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1310 return -1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1311 } else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1312 return (*ret); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1313 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1314 |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1315 #define AS_INT(c) (*((int*)c->p)) |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1316 |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1317 int |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1318 m_config_set_int(m_config_t *config, char* arg,int val) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1319 config_t* opt; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1320 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1321 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1322 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1323 assert(arg != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1324 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1325 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1326 opt = m_config_get_option(config,arg); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1327 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1328 if(!opt || opt->type != CONF_TYPE_INT) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1329 return ERR_NOT_AN_OPTION; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1330 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1331 if(opt->flags & CONF_MIN && val < opt->min) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1332 return ERR_OUT_OF_RANGE; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1333 if(opt->flags & CONF_MAX && val > opt->max) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1334 return ERR_OUT_OF_RANGE; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1335 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1336 m_config_save_option(config,opt,arg,NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1337 AS_INT(opt) = val; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1338 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1339 return 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1340 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1341 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1342 int |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1343 m_config_set_float(m_config_t *config, char* arg,float val) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1344 config_t* opt; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1345 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1346 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1347 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1348 assert(arg != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1349 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1350 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1351 opt = m_config_get_option(config,arg); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1352 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1353 if(!opt || opt->type != CONF_TYPE_FLOAT) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1354 return ERR_NOT_AN_OPTION; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1355 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1356 if(opt->flags & CONF_MIN && val < opt->min) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1357 return ERR_OUT_OF_RANGE; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1358 if(opt->flags & CONF_MAX && val > opt->max) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1359 return ERR_OUT_OF_RANGE; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1360 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1361 m_config_save_option(config,opt,arg,NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1362 *((float*)opt->p) = val; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1363 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1364 return 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1365 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1366 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1367 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1368 int |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1369 m_config_switch_flag(m_config_t *config, char* opt) { |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1370 config_t *conf; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1371 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1372 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1373 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1374 assert(opt != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1375 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1376 |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1377 conf = m_config_get_option(config,opt); |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1378 if(!conf || conf->type != CONF_TYPE_FLAG) return 0; |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1379 if( AS_INT(conf) == conf->min) AS_INT(conf) = conf->max; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1380 else if(AS_INT(conf) == conf->max) AS_INT(conf) = conf->min; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1381 else return 0; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1382 |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1383 return 1; |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1384 } |
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1385 |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1386 int |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1387 m_config_set_flag(m_config_t *config, char* opt, int state) { |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1388 config_t *conf; |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1389 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1390 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1391 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1392 assert(opt != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1393 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1394 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1395 conf = m_config_get_option(config,opt); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1396 if(!conf || conf->type != CONF_TYPE_FLAG) return 0; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1397 if(state) AS_INT(conf) = conf->max; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1398 else AS_INT(conf) = conf->min; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1399 return 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1400 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1401 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1402 int |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1403 m_config_get_flag(m_config_t *config, char* opt) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1404 config_t *conf; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1405 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1406 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1407 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1408 assert(opt != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1409 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1410 |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1411 conf = m_config_get_option(config,opt); |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1412 if(!conf || conf->type != CONF_TYPE_FLAG) return -1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1413 if(AS_INT(conf) == conf->max) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1414 return 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1415 else if(AS_INT(conf) == conf->min) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1416 return 0; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1417 else |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1418 return -1; |
4254
f04c49aa2408
Few bug fix and improvment in config/playtree system
albeu
parents:
4220
diff
changeset
|
1419 } |
4292
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1420 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1421 int m_config_is_option_set(m_config_t *config, char* arg) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1422 config_t* opt; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1423 config_save_t* save; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1424 int l,i; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1425 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1426 #ifdef MP_DEBUG |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1427 assert(config != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1428 assert(arg != NULL); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1429 #endif |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1430 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1431 opt = m_config_get_option(config,arg); |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1432 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1433 if(!opt) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1434 return -1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1435 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1436 for(l = config->cs_level ; l >= 0 ; l--) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1437 save = config->config_stack[l]; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1438 if(!save) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1439 continue; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1440 for(i = 0 ; save[i].opt != NULL ; i++) { |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1441 if(save[i].opt == opt) |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1442 return 1; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1443 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1444 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1445 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1446 return 0; |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1447 } |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1448 |
1cee88ee8db5
Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents:
4268
diff
changeset
|
1449 #undef AS_INT |
5215 | 1450 |
1451 static void m_config_print_option_list(char* prefix, config_t* opt_list) { | |
1452 char* pf = NULL; | |
1453 config_t* opt; | |
1454 char min[50],max[50],*type; | |
1455 | |
1456 | |
1457 for(opt = opt_list ; opt->name != NULL ; opt++) { | |
1458 if(opt->type == CONF_TYPE_SUBCONFIG) { | |
1459 if(prefix) { | |
1460 pf = (char*)malloc(strlen(prefix) + strlen(opt->name) + 1); | |
1461 sprintf(pf,"%s:%s",prefix,opt->name); | |
1462 } else | |
1463 pf = strdup(opt->name); | |
1464 m_config_print_option_list(pf,(config_t*)opt->p); | |
1465 free(pf); | |
1466 continue; | |
1467 } | |
1468 if(prefix) | |
1469 printf("%1.15s:",prefix); | |
1470 if(opt->flags & CONF_MIN) | |
1471 sprintf(min,"%-8.0f",opt->min); | |
1472 else | |
1473 strcpy(min,"No"); | |
1474 if(opt->flags & CONF_MAX) | |
1475 sprintf(max,"%-8.0f",opt->max); | |
1476 else | |
1477 strcpy(max,"No"); | |
1478 switch(opt->type) { | |
1479 case CONF_TYPE_FLAG: | |
1480 type = "Flag"; | |
1481 break; | |
1482 case CONF_TYPE_INT: | |
1483 type = "Integer"; | |
1484 break; | |
1485 case CONF_TYPE_FLOAT: | |
1486 type = "Float"; | |
1487 break; | |
1488 case CONF_TYPE_STRING: | |
1489 type = "String"; | |
1490 break; | |
1491 case CONF_TYPE_FUNC: | |
1492 case CONF_TYPE_FUNC_PARAM: | |
1493 case CONF_TYPE_FUNC_FULL: | |
1494 type = "Function"; | |
1495 break; | |
1496 case CONF_TYPE_PRINT: | |
10320
d83e4e54985c
backport PRINT_INDIRECT to old-config parser (new config fails on some 64bit systems - should be fixed) and some minor corrections
alex
parents:
9813
diff
changeset
|
1497 case CONF_TYPE_PRINT_INDIRECT: |
5215 | 1498 type = "Print"; |
1499 break; | |
1500 case CONF_TYPE_STRING_LIST: | |
1501 type = "String list"; | |
1502 break; | |
1503 default: | |
1504 type = ""; | |
1505 break; | |
1506 } | |
1507 printf("%-*.15s %-13.13s %-10.10s %-10.10s %-3.3s %-3.3s %-3.3s\n", | |
1508 30 - (prefix ? strlen(prefix) + 1 : 0), | |
1509 opt->name, | |
1510 type, | |
1511 min, | |
1512 max, | |
1513 opt->flags & CONF_GLOBAL ? "Yes" : "No", | |
1514 opt->flags & CONF_NOCMD ? "No" : "Yes", | |
1515 opt->flags & CONF_NOCFG ? "No" : "Yes"); | |
1516 } | |
1517 | |
1518 } | |
1519 | |
1520 | |
1521 static void m_config_list_options(m_config_t *config) { | |
1522 int i; | |
1523 | |
1524 printf("\nName Type Min Max Glob CL Cfg\n\n"); | |
1525 for(i = 0; config->opt_list[i] ; i++) | |
1526 m_config_print_option_list(NULL,config->opt_list[i]); | |
1527 } | |
1528 | |
1529 | |
1530 | |
1531 static void m_config_error(int err,char* opt,char* val) { | |
1532 switch(err) { | |
1533 case ERR_NOT_AN_OPTION: | |
5785 | 1534 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"'%s' is not a mplayer/mencoder option\n",opt); |
5215 | 1535 break; |
1536 case ERR_MISSING_PARAM: | |
1537 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"option '%s' need a parameter\n",opt); | |
1538 break; | |
1539 case ERR_OUT_OF_RANGE: | |
1540 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"value '%s' of option '%s' is out of range\n",val,opt); | |
1541 break; | |
1542 case ERR_FUNC_ERR: | |
1543 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"while parsing option '%s'\n",opt); | |
1544 break; | |
1545 } | |
1546 } | |
8164
487cfc28525d
New config system + cleanup of header inter dependency
albeu
parents:
8123
diff
changeset
|
1547 |
487cfc28525d
New config system + cleanup of header inter dependency
albeu
parents:
8123
diff
changeset
|
1548 #endif |