annotate cfgparser.c @ 4255:5a4a4b272d10

vidix_grkey_support checking for colorkeying
author alex
date Sat, 19 Jan 2002 16:58:33 +0000
parents f04c49aa2408
children 83aedfde69f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
1 /*
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
2 * command line and config file parser
336
e24fe1b5b918 less output
szabii
parents: 195
diff changeset
3 * by Szabolcs Berecz <szabi@inf.elte.hu>
e24fe1b5b918 less output
szabii
parents: 195
diff changeset
4 * (C) 2001
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
5 *
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
6 * subconfig support by alex
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
7 */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
8
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
9 //#define DEBUG
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
10
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
11 #include <stdlib.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
12 #include <stdio.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
13 #include <ctype.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
14 #include <unistd.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
15 #include <fcntl.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
16 #include <string.h>
336
e24fe1b5b918 less output
szabii
parents: 195
diff changeset
17 #include <errno.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
18 #include "config.h"
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
19
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
20 #include "mp_msg.h"
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
21
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
22 #define COMMAND_LINE 0
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
23 #define CONFIG_FILE 1
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
24
177
szabii
parents: 167
diff changeset
25 #define MAX_RECURSION_DEPTH 8
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
26
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
27 #ifdef MP_DEBUG
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
28 #include <assert.h>
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
29 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
30
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
31 #include "cfgparser.h"
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
32
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
33
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
34
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
35 static void
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
36 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
37 config_save_t* save;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
38 int sl=0;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
39
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
40 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
41 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
42 assert(config->cs_level >= 0);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
43 assert(conf != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
44 assert(opt != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
45 assert( ! (conf->flags & CONF_NOSAVE));
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
46 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
47
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
48 switch(conf->type) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
49 case CONF_TYPE_PRINT :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
50 case CONF_TYPE_SUBCONFIG :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
51 return;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
52 default :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
53 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
54
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
55 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
56
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
57 save = config->config_stack[config->cs_level];
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
58
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
59 if(save) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
60 for(sl = 0; save[sl].opt != NULL; sl++){
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
61 // Check to not allocate the same arg two times
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
62 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
63 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
64 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
65
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
66 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
67 if(save == NULL || save[sl].opt == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
68 save = (config_save_t*)realloc(save,(sl+2)*sizeof(config_save_t));
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
69 if(save == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
70 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",(sl+2)*sizeof(config_save_t),strerror(errno));
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
71 return;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
72 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
73 memset(&save[sl],0,2*sizeof(config_save_t));
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
74 save[sl].opt = conf;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
75 }
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 switch(conf->type) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
79 case CONF_TYPE_FLAG :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
80 case CONF_TYPE_INT :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
81 save[sl].param.as_int = *((int*)conf->p);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
82 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
83 case CONF_TYPE_FLOAT :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
84 save[sl].param.as_float = *((float*)conf->p);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
85 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
86 case CONF_TYPE_STRING :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
87 save[sl].param.as_pointer = *((char**)conf->p);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
88 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
89 case CONF_TYPE_FUNC_FULL :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
90 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
91 case CONF_TYPE_FUNC_PARAM :
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
92 if(param)
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
93 save->param.as_pointer = strdup(param);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
94 case CONF_TYPE_FUNC :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
95 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
96 default :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
97 printf("Should never append in m_config_save_option : conf->type=%d\n",conf->type);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
98 }
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 config->config_stack[config->cs_level] = save;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
101 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
102
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
103 static int
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
104 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
105 char* arg = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
106 config_save_t* iter=NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
107 int i=-1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
108
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
109 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
110 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
111 assert(config->cs_level >= 0);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
112 assert(save != NULL);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
113 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
114
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
115
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
116 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
117 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
118
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
119 if(save->opt->default_func)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
120 save->opt->default_func(save->opt,arg);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
121
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
122 switch(save->opt->type) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
123 case CONF_TYPE_FLAG :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
124 case CONF_TYPE_INT :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
125 *((int*)save->opt->p) = save->param.as_int;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
126 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
127 case CONF_TYPE_FLOAT :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
128 *((float*)save->opt->p) = save->param.as_float;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
129 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
130 case CONF_TYPE_STRING :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
131 *((char**)save->opt->p) = save->param.as_pointer;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
132 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
133 case CONF_TYPE_FUNC_PARAM :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
134 case CONF_TYPE_FUNC_FULL :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
135 case CONF_TYPE_FUNC :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
136 if(config->cs_level > 0) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
137 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
138 if(config->config_stack[i] == NULL) continue;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
139 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
140 if(iter->opt == save->opt &&
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
141 ((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
142 (save->opt_name == NULL ||
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
143 (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
144 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
145 }
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 free(save->param.as_pointer);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
148 if(save->opt_name) free(save->opt_name);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
149 save->opt_name = save->param.as_pointer = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
150 if(i < 0) break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
151 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
152 switch(iter->opt->type) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
153 case CONF_TYPE_FUNC :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
154 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
155 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
156 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
157 case CONF_TYPE_FUNC_PARAM :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
158 if (iter->param.as_pointer == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
159 printf("We lost param for option %s?\n",iter->opt->name);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
160 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
161 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
162 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
163 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
164 break;
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 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
167 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
168 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
169 }else {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
170 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
171 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
172
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
173 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
174 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 break;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
177 default :
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
178 printf("Why do we reverse this : name=%s type=%d ?\n",save->opt->name,save->opt->type);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
179 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
180
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
181 return 1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
182 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
183
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
184 void
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
185 m_config_push(m_config_t* config) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
186
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
187 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
188 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
189 assert(config->cs_level >= 0);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
190 #endif
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
191
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
192 config->cs_level++;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
193 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
194 if(config->config_stack == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
195 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
196 config->cs_level = -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
197 return;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
198 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
199 config->config_stack[config->cs_level] = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
200 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
201 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
202
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
203 int
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
204 m_config_pop(m_config_t* config) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
205 int i,ret= 1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
206 config_save_t* cs;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
207
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
208 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
209 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
210 assert(config->cs_level > 0);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
211 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
212
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
213 if(config->config_stack[config->cs_level] != NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
214 cs = config->config_stack[config->cs_level];
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
215 for(i=0; cs[i].opt != NULL ; i++ ) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
216 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
217 ret = -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
218 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
219 free(config->config_stack[config->cs_level]);
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 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
222 config->cs_level--;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
223 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
224 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
225 config->cs_level = -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
226 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
227 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
228 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
229 return ret;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
230 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
231
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
232 m_config_t*
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
233 m_config_new(play_tree_t* pt) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
234 m_config_t* config;
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 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
237 assert(pt != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
238 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
239
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
240 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
241 if(config == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
242 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
243 return NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
244 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
245 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
246 if(config->config_stack == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
247 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
248 free(config);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
249 return NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
250 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
251 config->global = 1; // We always start with global options
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
252 config->pt = pt;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
253 return config;
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
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
256 void
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
257 m_config_free(m_config_t* config) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
258
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
259 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
260 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
261 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
262
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
263 free(config->opt_list);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
264 free(config->config_stack);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
265 free(config);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
266 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
267
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
268
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
269 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
270 {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
271 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
272 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
273 assert(config->pt != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
274 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
275
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
276 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
277 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "init_conf: wrong mode!\n");
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
278 return -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
279 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
280 #endif
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
281 config->parser_mode = mode;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
282 config->global = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
283 return 1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
284 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
285
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
286
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
287 static int config_read_option(m_config_t *config,config_t** conf_list, char *opt, char *param)
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
288 {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
289 int i=0,nconf = 0;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
290 long tmp_int;
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
291 double tmp_float;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
292 int ret = -1;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
293 char *endptr;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
294 config_t* conf=NULL;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
295
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
296 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
297 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
298 assert(conf_list != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
299 assert(opt != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
300 #endif
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 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
303 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
304 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
305 conf = conf_list[nconf];
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
306 for (i = 0; conf[i].name != NULL; i++) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
307 int namelength;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
308 /* allow 'aa*' in config.name */
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
309 namelength=strlen(conf[i].name);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
310 if ( (conf[i].name[namelength-1]=='*') &&
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
311 !memcmp(opt, conf[i].name, namelength-1))
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
312 goto option_found;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
313 if (!strcasecmp(opt, conf[i].name))
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
314 goto option_found;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
315 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
316 }
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
317 if (config->parser_mode == CONFIG_FILE)
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
318 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid option:\n");
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
319 ret = ERR_NOT_AN_OPTION;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
320 goto out;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
321 option_found :
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
322 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: name='%s' p=%p type=%d\n",
2621
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
323 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
324
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
325 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
326 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
327 ret = ERR_NOT_AN_OPTION;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
328 goto out;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
329 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
330 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
331 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "this option can only be used in config file:\n", opt);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
332 ret = ERR_NOT_AN_OPTION;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
333 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
334 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
335 if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
336 play_tree_t* list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
337 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
338 assert(config->pt != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
339 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
340 if(!param) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
341 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "playlist option need a filename\n");
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
342 ret = ERR_MISSING_PARAM;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
343 goto out;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
344 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
345 list = parse_playlist_file(param);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
346 if(list) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
347 if(config->last_entry) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
348 play_tree_append_entry(config->last_entry,list);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
349 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
350 else
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
351 play_tree_set_child(config->pt,list);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
352 config->last_entry = list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
353 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
354 if(config->parser_mode == COMMAND_LINE)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
355 config->global = 0;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
356 return 1;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
357 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
358 if(config->global == 0 && ! (conf[i].flags & CONF_GLOBAL) )
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
359 m_config_push(config);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
360 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
361 m_config_save_option(config,&conf[i],opt,param);
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
362 switch (conf[i].type) {
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
363 case CONF_TYPE_FLAG:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
364 /* flags need a parameter in config file */
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
365 if (config->parser_mode == CONFIG_FILE) {
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
366 if (!strcasecmp(param, "yes") || /* any other language? */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
367 !strcasecmp(param, "ja") ||
161
9008302e2dc0 Added support for spanish (Yes, I'm a C programer also ;o)
telenieko
parents: 160
diff changeset
368 !strcasecmp(param, "si") ||
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
369 !strcasecmp(param, "igen") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
370 !strcasecmp(param, "y") ||
1536
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 1304
diff changeset
371 !strcasecmp(param, "j") ||
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
372 !strcasecmp(param, "i") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
373 !strcmp(param, "1"))
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
374 *((int *) conf[i].p) = conf[i].max;
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
375 else if (!strcasecmp(param, "no") ||
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
376 !strcasecmp(param, "nein") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
377 !strcasecmp(param, "nicht") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
378 !strcasecmp(param, "nem") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
379 !strcasecmp(param, "n") ||
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
380 !strcmp(param, "0"))
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
381 *((int *) conf[i].p) = conf[i].min;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
382 else {
3559
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2650
diff changeset
383 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid parameter for flag: %s\n", param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
384 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
385 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
386 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
387 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
388 } else { /* parser_mode == COMMAND_LINE */
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
389 *((int *) conf[i].p) = conf[i].max;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
390 ret = 0;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
391 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
392 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
393 case CONF_TYPE_INT:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
394 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
395 goto err_missing_param;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
396
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
397 tmp_int = strtol(param, &endptr, 0);
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
398 if (*endptr) {
3559
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2650
diff changeset
399 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be an integer: %s\n", param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
400 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
401 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
402 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
403
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
404 if (conf[i].flags & CONF_MIN)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
405 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
406 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %d: %s\n", (int) conf[i].min, param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
407 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
408 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
409 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
410
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
411 if (conf[i].flags & CONF_MAX)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
412 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
413 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %d: %s\n", (int) conf[i].max, param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
414 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
415 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
416 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
417
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
418 *((int *) conf[i].p) = tmp_int;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
419 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
420 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
421 case CONF_TYPE_FLOAT:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
422 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
423 goto err_missing_param;
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
424
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
425 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
426
624df8ea0e0e New aspect prescale code, parses aspect value from mpeg sequence header or commandline.
atmos4
parents: 1629
diff changeset
427 if ((*endptr == ':') || (*endptr == '/'))
624df8ea0e0e New aspect prescale code, parses aspect value from mpeg sequence header or commandline.
atmos4
parents: 1629
diff changeset
428 tmp_float /= strtod(endptr+1, &endptr);
624df8ea0e0e New aspect prescale code, parses aspect value from mpeg sequence header or commandline.
atmos4
parents: 1629
diff changeset
429
195
452453f82bfa strto* int/float reader
szabii
parents: 191
diff changeset
430 if (*endptr) {
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
431 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
432 " or a ratio (numerator[:/]denominator): %s\n", param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
433 ret = ERR_MISSING_PARAM;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
434 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
435 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
436
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
437 if (conf[i].flags & CONF_MIN)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
438 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
439 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %f: %s\n", conf[i].min, param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
440 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
441 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
442 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
443
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
444 if (conf[i].flags & CONF_MAX)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
445 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
446 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %f: %s\n", conf[i].max, param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
447 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
448 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
449 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
450
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
451 *((float *) conf[i].p) = tmp_float;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
452 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
453 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
454 case CONF_TYPE_STRING:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
455 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
456 goto err_missing_param;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
457
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
458 if (conf[i].flags & CONF_MIN)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
459 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
460 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
461 (int) conf[i].min, param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
462 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
463 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
464 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
465
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
466 if (conf[i].flags & CONF_MAX)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
467 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
468 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
469 (int) conf[i].max, param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
470 ret = ERR_OUT_OF_RANGE;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
471 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
472 }
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
473 *((char **) conf[i].p) = strdup(param);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
474 ret = 1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
475 break;
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
476 case CONF_TYPE_FUNC_PARAM:
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
477 if (param == NULL)
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
478 goto err_missing_param;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
479 if ((((cfg_func_param_t) conf[i].p)(conf + i, param)) < 0) {
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
480 ret = ERR_FUNC_ERR;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
481 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
482 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
483 ret = 1;
151
9708d4b2765b cfgparser fix
szabii
parents: 150
diff changeset
484 break;
1536
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 1304
diff changeset
485 case CONF_TYPE_FUNC_FULL:
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 1304
diff changeset
486 if (param!=NULL && param[0]=='-'){
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
487 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
488 if (ret>=0) ret=0;
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 1304
diff changeset
489 /* 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
490 }else{
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
491 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
492 /* 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
493 /* if we return 1: accepted param */
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 1304
diff changeset
494 }
e89233dab4da New feature for option processing: CONF_TYPE_FUNC_FULL
folke
parents: 1304
diff changeset
495 break;
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
496 case CONF_TYPE_FUNC:
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
497 if ((((cfg_func_t) conf[i].p)(conf + i)) < 0) {
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
498 ret = ERR_FUNC_ERR;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
499 goto out;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
500 }
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
501 ret = 0;
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
502 break;
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
503 case CONF_TYPE_SUBCONFIG:
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
504 {
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
505 char *subparam;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
506 char *subopt;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
507 int subconf_optnr;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
508 config_t *subconf;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
509 config_t *sublist[] = { NULL , NULL };
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
510 char *token;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
511
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
512 if (param == NULL)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
513 goto err_missing_param;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
514
3613
8a82dca566bc missing 1 byte in array size
pl
parents: 3559
diff changeset
515 subparam = malloc(strlen(param)+1);
8a82dca566bc missing 1 byte in array size
pl
parents: 3559
diff changeset
516 subopt = malloc(strlen(param)+1);
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
517
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
518 subconf = conf[i].p;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
519 sublist[0] = subconf;
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
520 for (subconf_optnr = 0; subconf[subconf_optnr].name != NULL; subconf_optnr++)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
521 /* NOTHING */;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
522
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
523 token = strtok(param, (char *)&(":"));
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
524 while(token)
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
525 {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
526 int sscanf_ret;
3761
b66a62f332d6 fixed subconfig parser
alex
parents: 3684
diff changeset
527 /* clear out */
b66a62f332d6 fixed subconfig parser
alex
parents: 3684
diff changeset
528 subopt[0] = subparam[0] = 0;
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
529
3559
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2650
diff changeset
530 sscanf_ret = sscanf(token, "%[^=]=%s", subopt, subparam);
3761
b66a62f332d6 fixed subconfig parser
alex
parents: 3684
diff changeset
531
b66a62f332d6 fixed subconfig parser
alex
parents: 3684
diff changeset
532 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
533 switch(sscanf_ret)
2621
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
534 {
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
535 case 1:
3761
b66a62f332d6 fixed subconfig parser
alex
parents: 3684
diff changeset
536 subparam[0] = 0;
2621
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
537 case 2:
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
538 if ((ret = config_read_option(config,sublist, subopt, subparam)) < 0)
2621
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
539 {
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
540 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
541 ret, token);
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2650
diff changeset
542 goto out;
2621
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
543 }
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
544 break;
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
545 default:
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
546 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
547 ret = ERR_NOT_AN_OPTION;
f61dcc63be5f exchanged return with goto out in subconfig parsing and fixed error messages
alex
parents: 2650
diff changeset
548 goto out;
2621
169d97f8aeaf fixed subconfig, exiting on error, supporting flags
alex
parents: 2619
diff changeset
549 }
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
550 token = strtok(NULL, (char *)&(":"));
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
551 }
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
552
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
553 free(subparam);
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
554 free(subopt);
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
555 ret = 1;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
556 break;
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
557 }
152
372a9a836e86 cfgparser fix
szabii
parents: 151
diff changeset
558 case CONF_TYPE_PRINT:
2619
b66f42e9ec2d subconfig support
alex
parents: 2615
diff changeset
559 printf("%s", (char *) conf[i].p);
152
372a9a836e86 cfgparser fix
szabii
parents: 151
diff changeset
560 exit(1);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
561 default:
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
562 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown config type specified in conf-mplayer.h!\n");
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
563 break;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
564 }
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
565 out:
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
566 if(ret >= 0 && config->global == 0 && ! (conf[i].flags & CONF_GLOBAL)) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
567 play_tree_t* dest = config->last_entry ? config->last_entry : config->last_parent;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
568 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
569 assert(dest != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
570 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
571 if(ret == 0)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
572 play_tree_set_param(dest,opt,NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
573 else if(ret > 0)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
574 play_tree_set_param(dest,opt,param);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
575 m_config_pop(config);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
576 }
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
577 return ret;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
578 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
579 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "missing parameter for option: %s\n", opt);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
580 ret = ERR_MISSING_PARAM;
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
581 goto out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
582 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
583
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
584 int m_config_set_option(m_config_t *config,char *opt, char *param) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
585
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
586 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
587 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
588 assert(opt != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
589 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
590 mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Setting option %s=%s\n",opt,param);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
591 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
592 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
593
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
594 int m_config_parse_config_file(m_config_t *config, char *conffile)
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
595 {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
596 #define PRINT_LINENUM printf("%s(%d): ", conffile, line_num)
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
597 #define MAX_LINE_LEN 1000
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
598 #define MAX_OPT_LEN 100
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
599 #define MAX_PARAM_LEN 100
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
600 FILE *fp;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
601 char *line;
179
szabii
parents: 177
diff changeset
602 char opt[MAX_OPT_LEN + 1];
szabii
parents: 177
diff changeset
603 char param[MAX_PARAM_LEN + 1];
167
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
604 char c; /* for the "" and '' check */
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
605 int tmp;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
606 int line_num = 0;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
607 int line_pos; /* line pos */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
608 int opt_pos; /* opt pos */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
609 int param_pos; /* param pos */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
610 int ret = 1;
1090
szabii
parents: 1089
diff changeset
611 int errors = 0;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
612
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
613 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
614 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
615 // assert(conf_list != NULL);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
616 #endif
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
617 if (++config->recursion_depth > 1)
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
618 printf("Reading config file: %s", conffile);
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
619
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
620 if (config->recursion_depth > MAX_RECURSION_DEPTH) {
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
621 printf(": too deep 'include'. check your configfiles\n");
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
622 ret = -1;
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
623 goto out;
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
624 }
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
625
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
626 if (init_conf(config, CONFIG_FILE) == -1) {
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
627 ret = -1;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
628 goto out;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
629 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
630
179
szabii
parents: 177
diff changeset
631 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
632 printf("\ncan't get memory for 'line': %s", strerror(errno));
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
633 ret = -1;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
634 goto out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
635 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
636
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
637 if ((fp = fopen(conffile, "r")) == NULL) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
638 if (config->recursion_depth > 1)
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
639 printf(": %s\n", strerror(errno));
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
640 free(line);
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
641 ret = 0;
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
642 goto out;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
643 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
644 if (config->recursion_depth > 1)
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
645 printf("\n");
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
646
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
647 while (fgets(line, MAX_LINE_LEN, fp)) {
1090
szabii
parents: 1089
diff changeset
648 if (errors >= 16) {
szabii
parents: 1089
diff changeset
649 printf("too many errors\n");
szabii
parents: 1089
diff changeset
650 goto out;
szabii
parents: 1089
diff changeset
651 }
szabii
parents: 1089
diff changeset
652
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
653 line_num++;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
654 line_pos = 0;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
655
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
656 /* skip whitespaces */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
657 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
658 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
659
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
660 /* EOL / comment */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
661 if (line[line_pos] == '\0' || line[line_pos] == '#')
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
662 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
663
480
787f2792beeb now it accepts monitor_hfreq...
szabii
parents: 336
diff changeset
664 /* read option. */
787f2792beeb now it accepts monitor_hfreq...
szabii
parents: 336
diff changeset
665 for (opt_pos = 0; isprint(line[line_pos]) &&
787f2792beeb now it accepts monitor_hfreq...
szabii
parents: 336
diff changeset
666 line[line_pos] != ' ' &&
787f2792beeb now it accepts monitor_hfreq...
szabii
parents: 336
diff changeset
667 line[line_pos] != '#' &&
787f2792beeb now it accepts monitor_hfreq...
szabii
parents: 336
diff changeset
668 line[line_pos] != '='; /* NOTHING */) {
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
669 opt[opt_pos++] = line[line_pos++];
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
670 if (opt_pos >= MAX_OPT_LEN) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
671 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
672 printf("too long option\n");
1090
szabii
parents: 1089
diff changeset
673 errors++;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
674 ret = -1;
1090
szabii
parents: 1089
diff changeset
675 goto nextline;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
676 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
677 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
678 if (opt_pos == 0) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
679 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
680 printf("parse error\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
681 ret = -1;
1090
szabii
parents: 1089
diff changeset
682 errors++;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
683 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
684 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
685 opt[opt_pos] = '\0';
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
686
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
687 #ifdef MP_DEBUG
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
688 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
689 printf("option: %s\n", opt);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
690 #endif
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
691
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
692 /* skip whitespaces */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
693 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
694 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
695
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
696 /* check '=' */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
697 if (line[line_pos++] != '=') {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
698 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
699 printf("option without parameter\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
700 ret = -1;
1090
szabii
parents: 1089
diff changeset
701 errors++;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
702 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
703 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
704
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
705 /* whitespaces... */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
706 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
707 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
708
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
709 /* read the parameter */
167
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
710 if (line[line_pos] == '"' || line[line_pos] == '\'') {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
711 c = line[line_pos];
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
712 ++line_pos;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
713 for (param_pos = 0; line[line_pos] != c; /* NOTHING */) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
714 param[param_pos++] = line[line_pos++];
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
715 if (param_pos >= MAX_PARAM_LEN) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
716 PRINT_LINENUM;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
717 printf("too long parameter\n");
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
718 ret = -1;
1090
szabii
parents: 1089
diff changeset
719 errors++;
szabii
parents: 1089
diff changeset
720 goto nextline;
167
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
721 }
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
722 }
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
723 line_pos++; /* skip the closing " or ' */
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
724 } else {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
725 for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos])
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
726 && line[line_pos] != '#'; /* NOTHING */) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
727 param[param_pos++] = line[line_pos++];
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
728 if (param_pos >= MAX_PARAM_LEN) {
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
729 PRINT_LINENUM;
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
730 printf("too long parameter\n");
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
731 ret = -1;
1090
szabii
parents: 1089
diff changeset
732 errors++;
szabii
parents: 1089
diff changeset
733 goto nextline;
167
53f289e99102 parameter can be in quotes in config file
szabii
parents: 166
diff changeset
734 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
735 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
736 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
737 param[param_pos] = '\0';
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
738
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
739 /* did we read a parameter? */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
740 if (param_pos == 0) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
741 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
742 printf("option without parameter\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
743 ret = -1;
1090
szabii
parents: 1089
diff changeset
744 errors++;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
745 continue;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
746 }
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
747
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
748 #ifdef MP_DEBUG
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
749 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
750 printf("parameter: %s\n", param);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
751 #endif
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
752
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
753 /* now, check if we have some more chars on the line */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
754 /* whitespace... */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
755 while (isspace(line[line_pos]))
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
756 ++line_pos;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
757
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
758 /* EOL / comment */
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
759 if (line[line_pos] != '\0' && line[line_pos] != '#') {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
760 PRINT_LINENUM;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
761 printf("extra characters on line: %s\n", line+line_pos);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
762 ret = -1;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
763 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
764
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
765 tmp = m_config_set_option(config, opt, param);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
766 switch (tmp) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
767 case ERR_NOT_AN_OPTION:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
768 case ERR_MISSING_PARAM:
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
769 case ERR_OUT_OF_RANGE:
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
770 case ERR_FUNC_ERR:
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
771 PRINT_LINENUM;
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
772 printf("%s\n", opt);
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
773 ret = -1;
1090
szabii
parents: 1089
diff changeset
774 errors++;
150
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
775 continue;
2f3e01a1fd87 cfgparse fixes
szabii
parents: 147
diff changeset
776 /* break */
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
777 }
1093
szabii
parents: 1090
diff changeset
778 nextline:
1304
ecb834719dc9 fix gcc-3.0 warning
jkeil
parents: 1093
diff changeset
779 ;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
780 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
781
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
782 free(line);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
783 fclose(fp);
166
6b79d801e183 include recursion check
szabii
parents: 161
diff changeset
784 out:
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
785 --config->recursion_depth;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
786 return ret;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
787 }
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
788
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
789 int m_config_parse_command_line(m_config_t *config, int argc, char **argv, char **envp)
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
790 {
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
791 int i;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
792 int tmp;
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
793 char *opt;
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
794 int no_more_opts = 0;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
795
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
796 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
797 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
798 assert(config->pt != NULL);
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
799 assert(argv != NULL);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
800 assert(envp != NULL);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
801 assert(argc >= 1);
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
802 #endif
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
803
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
804 if (init_conf(config, COMMAND_LINE) == -1)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
805 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
806 if(config->last_parent == NULL)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
807 config->last_parent = config->pt;
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
808 /* 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
809 ++config->recursion_depth;
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
810
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
811 for (i = 1; i < argc; i++) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
812 //next:
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
813 opt = argv[i];
2650
bf7248edcc20 fixed commandline bug: handling '-' as option when '--' unused
alex
parents: 2624
diff changeset
814 /* check for -- (no more options id.) except --help! */
2623
0d8f8d313f9c fixed fault with --help
alex
parents: 2621
diff changeset
815 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h'))
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
816 {
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
817 no_more_opts = 1;
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
818 if (i+1 >= argc)
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
819 {
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
820 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
821 goto err_out;
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
822 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
823 continue;
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
824 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
825 if((opt[0] == '{') && (opt[1] == '\0'))
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
826 {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
827 play_tree_t* entry = play_tree_new();
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
828 config->global = 0;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
829 if(config->last_entry == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
830 play_tree_set_child(config->last_parent,entry);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
831 } else {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
832 play_tree_append_entry(config->last_entry,entry);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
833 config->last_entry = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
834 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
835 config->last_parent = entry;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
836 continue;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
837 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
838
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
839 if((opt[0] == '}') && (opt[1] == '\0'))
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
840 {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
841 if( ! config->last_parent || ! config->last_parent->parent) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
842 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
843 goto err_out;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
844 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
845 config->last_entry = config->last_parent;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
846 config->last_parent = config->last_entry->parent;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
847 continue;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
848 }
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
849
2650
bf7248edcc20 fixed commandline bug: handling '-' as option when '--' unused
alex
parents: 2624
diff changeset
850 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
851 {
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
852 /* remove trailing '-' */
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
853 opt++;
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
854
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
855 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
856 tmp = m_config_set_option(config, opt, argv[i + 1]);
1629
13aeaa05ac5e multifile support in config parser
arpi
parents: 1536
diff changeset
857
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
858 switch (tmp) {
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
859 case ERR_NOT_AN_OPTION:
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
860 case ERR_MISSING_PARAM:
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
861 case ERR_OUT_OF_RANGE:
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
862 case ERR_FUNC_ERR:
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
863 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error %d while parsing option: '%s'!\n",
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
864 tmp, opt);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
865 goto err_out;
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
866 default:
1075
a981413af7cd : No such... fix
szabii
parents: 1062
diff changeset
867 i += tmp;
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
868 break;
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
869 }
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
870 }
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
871 else /* filename */
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
872 {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
873 play_tree_t* entry = play_tree_new();
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
874 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
875 play_tree_add_file(entry,argv[i]);
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
876 /* opt is not an option -> treat it as a filename */
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
877 config->global = 0; // We start entry specific options
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
878 if(config->last_entry == NULL)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
879 play_tree_set_child(config->last_parent,entry);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
880 else
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
881 play_tree_append_entry(config->last_entry,entry);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
882 config->last_entry = entry;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
883 }
1089
b2a29e1224e4 some fix
szabii
parents: 1077
diff changeset
884 }
2615
fc7985beff39 fixed arpi's cfgparser bug
alex
parents: 2380
diff changeset
885
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
886 --config->recursion_depth;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
887 if(config->last_parent != config->pt)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
888 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n");
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
889 config->global = 1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
890 return 1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
891 #if 0
1629
13aeaa05ac5e multifile support in config parser
arpi
parents: 1536
diff changeset
892 err_out_mem:
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
893 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
894 #endif
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
895 err_out:
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
896 --config->recursion_depth;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
897 config->global = 1;
2624
64844fccf623 partly upgraded to mp_msg and fixed minor bug in parse_command_line
alex
parents: 2623
diff changeset
898 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "command line: %s\n", argv[i]);
160
5f0c50a9e347 cfgparse fix...
szabii
parents: 158
diff changeset
899 return -1;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents:
diff changeset
900 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
901
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
902 void
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
903 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
904 int list_len = 0;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
905 config_t** conf_list = config->opt_list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
906
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
907 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
908 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
909 assert(args != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
910 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
911
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
912 if(conf_list) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
913 for ( ; conf_list[list_len] != NULL; list_len++)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
914 /* NOTHING */;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
915 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
916
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
917 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
918 if(conf_list == NULL) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
919 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(struct conf*)*(list_len+2),strerror(errno));
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
920 return;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
921 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
922 conf_list[list_len] = args;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
923 conf_list[list_len+1] = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
924
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
925 config->opt_list = conf_list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
926 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
927
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
928 config_t*
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
929 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
930 int i,j;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
931 config_t *conf;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
932 config_t **conf_list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
933
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
934 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
935 assert(config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
936 assert(arg != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
937 #endif
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
938
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
939 conf_list = config->opt_list;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
940 if(conf_list) {
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
941 for(j = 0 ; conf_list[j] != NULL ; j++) {
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
942 conf = conf_list[j];
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
943 for(i=0; conf[i].name != NULL; i++) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
944 if(strcasecmp(conf[i].name,arg) == 0)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
945 return &conf[i];
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
946 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
947 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
948 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
949 return NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
950 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
951
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
952 void*
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
953 m_config_get_option_ptr(m_config_t *config, char* arg) {
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
954 config_t* conf = m_config_get_option(config,arg);
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
955 if(!conf) return NULL;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
956 return conf->p;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
957 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 3761
diff changeset
958
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
959 #define AS_INT(c) (*((int*)c->p))
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
960
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
961 int
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
962 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
963 config_t *conf;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
964
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
965 conf = m_config_get_option(config,opt);
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
966 if(!conf) return 0;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
967 if(conf->type != CONF_TYPE_FLAG) return 0;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
968 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
969 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
970 else return 0;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
971
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
972 return 1;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
973 }
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
974
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
975 void
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
976 m_config_set_flag(m_config_t *config, char* opt, int max) {
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
977 config_t *conf;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
978 conf = m_config_get_option(config,opt);
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
979 if(!conf) return;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
980 if(conf->type != CONF_TYPE_FLAG) return 0;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
981 if(max) AS_INT(conf) = conf->max;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
982 else AS_INT(conf) = conf->min;
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
983 }