[Mplayer-cvslog] CVS: main playtree.c,1.4,1.5 cfgparser.c,1.40,1.41 cfgparser.h,1.10,1.11

Alban Bedel CVS albeu at mplayer.dev.hu
Sat Jan 19 17:58:06 CET 2002


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv16144

Modified Files:
	playtree.c cfgparser.c cfgparser.h 
Log Message:
Few bug fix and improvment in config/playtree system


Index: playtree.c
===================================================================
RCS file: /cvsroot/mplayer/main/playtree.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- playtree.c	17 Jan 2002 20:24:28 -0000	1.4
+++ playtree.c	19 Jan 2002 16:58:04 -0000	1.5
@@ -335,11 +335,13 @@
 
   if(ni > 0) {
     if(pt->params[n].value != NULL) free(pt->params[n].value);
-    pt->params[n].value = val;
+    pt->params[n].value = val != NULL ? strdup(val) : NULL;
     return;
   }
 
   pt->params = (play_tree_param_t*)realloc(pt->params,(n+2)*sizeof(play_tree_param_t));
+  if(pt->params == NULL)
+    printf("Can't realloc params\n");
   pt->params[n].name = strdup(name);
   pt->params[n].value = val != NULL ? strdup(val) : NULL;
   memset(&pt->params[n+1],0,sizeof(play_tree_param_t));

Index: cfgparser.c
===================================================================
RCS file: /cvsroot/mplayer/main/cfgparser.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- cfgparser.c	17 Jan 2002 20:24:28 -0000	1.40
+++ cfgparser.c	19 Jan 2002 16:58:04 -0000	1.41
@@ -89,7 +89,8 @@
   case CONF_TYPE_FUNC_FULL :
     if(strcasecmp(conf->name,opt) != 0) save->opt_name = strdup(opt);
   case CONF_TYPE_FUNC_PARAM :
-    save->param.as_pointer = strdup(param);
+    if(param)
+      save->param.as_pointer = strdup(param);
   case CONF_TYPE_FUNC :    
     break;
   default :
@@ -137,7 +138,7 @@
 	if(config->config_stack[i] == NULL) continue;
 	for(iter = config->config_stack[i]; iter != NULL && iter->opt != NULL ; iter++) {
 	  if(iter->opt == save->opt && 
-	     strcasecmp(save->param.as_pointer,iter->param.as_pointer) == 0 && 
+	     ((save->param.as_pointer == NULL || iter->param.as_pointer == NULL) || strcasecmp(save->param.as_pointer,iter->param.as_pointer) == 0) && 
 	     (save->opt_name == NULL || 
 	      (iter->opt_name && strcasecmp(save->opt_name,iter->opt_name)))) break;
 	}
@@ -308,17 +309,16 @@
 			namelength=strlen(conf[i].name);
 			if ( (conf[i].name[namelength-1]=='*') && 
 				    !memcmp(opt, conf[i].name, namelength-1))
-			        break;
+			  goto option_found;
 			if (!strcasecmp(opt, conf[i].name))
-			break;
+			  goto option_found;
 		}
 	}
-	if (conf[i].name == NULL) {
-		if (config->parser_mode == CONFIG_FILE)
-			mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid option:\n");
-		ret = ERR_NOT_AN_OPTION;
-		goto out;
-	}
+	if (config->parser_mode == CONFIG_FILE)
+		mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid option:\n");
+	ret = ERR_NOT_AN_OPTION;
+	goto out;	
+	option_found :
 	mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: name='%s' p=%p type=%d\n",
 	    conf[i].name, conf[i].p, conf[i].type);
 
@@ -927,7 +927,7 @@
 
 config_t*
 m_config_get_option(m_config_t *config, char* arg) {
-  int i;
+  int i,j;
   config_t *conf;
   config_t **conf_list;
 
@@ -938,7 +938,8 @@
 
   conf_list = config->opt_list;
   if(conf_list) {
-    for(conf = conf_list[0]; conf != NULL ; conf ++) {
+    for(j = 0 ; conf_list[j] != NULL ; j++) {
+      conf = conf_list[j];
       for(i=0; conf[i].name != NULL; i++) {
 	if(strcasecmp(conf[i].name,arg) == 0)
 	  return &conf[i];
@@ -948,4 +949,35 @@
   return NULL;
 }
 
+void*
+m_config_get_option_ptr(m_config_t *config, char* arg) {
+  config_t* conf = m_config_get_option(config,arg);
+  if(!conf) return NULL;
+  return conf->p;
+}
+
+#define AS_INT(c) (*((int*)c->p))
 
+int
+m_config_switch_flag(m_config_t *config, char* opt) {
+  config_t *conf;
+  
+  conf = m_config_get_option(config,opt);
+  if(!conf) return 0;
+  if(conf->type != CONF_TYPE_FLAG) return 0;
+  if( AS_INT(conf) == conf->min) AS_INT(conf) = conf->max;
+  else if(AS_INT(conf) == conf->max) AS_INT(conf) = conf->min;
+  else return 0;
+
+  return 1;
+}
+    
+void
+m_config_set_flag(m_config_t *config, char* opt, int max) {
+  config_t *conf;
+  conf = m_config_get_option(config,opt);
+  if(!conf) return;
+  if(conf->type != CONF_TYPE_FLAG) return 0;
+  if(max) AS_INT(conf) = conf->max;
+  else AS_INT(conf) = conf->min;
+}

Index: cfgparser.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfgparser.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- cfgparser.h	14 Jan 2002 23:38:49 -0000	1.10
+++ cfgparser.h	19 Jan 2002 16:58:04 -0000	1.11
@@ -99,6 +99,12 @@
 
 config_t* m_config_get_option(m_config_t *config, char* arg);
 
+int m_config_switch_flag(m_config_t *config, char* opt);
+
+void m_config_set_flag(m_config_t *config, char* opt, int max);
+
+void* m_config_get_option_ptr(m_config_t *config, char* arg);
+
 m_config_t* m_config_new(play_tree_t* pt);
 
 void m_config_free(m_config_t* config);




More information about the MPlayer-cvslog mailing list