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