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