[MPlayer-dev-eng] Re: [TEST PATCH] How to get rid of all sscanf() or new face of config :)

Andriy N. Gritsenko andrej at lucky.net
Wed Mar 26 13:42:44 CET 2003


    Hi!

Sometime (on Tuesday, March 25 at 23:35) I wrote...
>    7. And most big feature for me - you can obtain full menu structure
>for GUI via mconfig->opts! You don't need anymore have your own menu
>config, it has all you want! See:
>CONF_TYPE_FLAG                                      checkbox
>CONF_TYPE_INT,CONF_TYPE_FLOAT,CONF_TYPE_POSITION    slider (may be)
>CONF_TYPE_STRING,CONF_TYPE_SPAN                     input box
>CONF_TYPE_SUBCONFIG                                 dialog box
>CONF_TYPE_CHOOSE                                    select box
>CONF_TYPE_LIST                  selection/reorder box, two-panel for example
>    Unfortunately, I didn't find what to do with CONF_TYPE_FUNC* so they
>may be just input fields (as string)? CONF_TYPE_PRINT just ignored.
>    So from now what you have to do is to arrange all fields and you have
>all your menu ready! Isn't it funny? :)

    In addition to yesterday's patch I send now new. It will help you to
make nested menus (from main menu bar to drop-down submenu, for example),
just split full config to fake subconfigs by putting them in items with
type CONF_TYPE_DUMMY ("^file","^audio","^video",etc). :)

    With best wishes.
    Andriy.
-------------- next part --------------
--- m_config.c.old	Tue Mar 25 22:25:36 2003
+++ m_config.c	Wed Mar 26 13:59:13 2003
@@ -149,17 +149,24 @@ m_config_get_co(m_config_option_t *co, c
     l = strlen(co->opt->name);
     if (l == 0)
       continue;
+    // check for full matching first
+    if(strcasecmp(co->opt->name,arg) == 0)
+      break;
+    // check if it's dummy - descent into it without ':'
+    else if(co->opt->type == CONF_TYPE_DUMMY) {
+      m_config_option_t *sc = m_config_get_co(co->s.ubconfig,arg);
+      if(sc)
+	return sc;
     // check for opt:subopt syntax
-    if((co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) &&
-       !strncasecmp(co->opt->name,arg,l) && arg[l] == ':') {
+    } else if((co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) &&
+	      !strncasecmp(co->opt->name,arg,l) && arg[l] == ':') {
       return m_config_get_co(co->s.ubconfig,&arg[l+1]);
     // check for wildcards
     } else if((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) && 
 	      (co->opt->name[l-1] == '*')) {
       if(strncasecmp(co->opt->name,arg,l-1) == 0)
 	break;
-    } else if(strcasecmp(co->opt->name,arg) == 0)
-      break;
+    }
   }
   return co;
 }
--- m_option.c.old	Tue Mar 25 20:29:07 2003
+++ m_option.c	Wed Mar 26 14:02:31 2003
@@ -15,6 +15,31 @@
 //#include "m_config.h"
 #include "mp_msg.h"
 
+// Dummy type, just as menu separator, never called!
+
+static int parse_dummy(m_option_t* opt,char *name, const char *param, void* dst, int src) {
+  (void) opt;
+  (void) name;
+  (void) dst;
+  (void) param;
+  (void) src;
+  return M_OPT_UNKNOW;
+}
+
+m_option_type_t m_option_type_dummy = {
+  "Separator",
+  "",
+  0,
+  0,
+  parse_dummy,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL
+};
+
 // Default function that just do a memcpy
 
 static void copy_opt(m_option_t* opt,void* dst,void* src) {
@@ -118,7 +143,7 @@ m_option_type_t m_option_type_flag = {
 static int parse_int(m_option_t* opt,char *name, const char *param, void* dst, int src) {
   long tmp_int;
   char *endptr;
-  src = 0;
+  (void) src;
 
   if (param == NULL)
     return M_OPT_MISSING_PARAM;
@@ -145,7 +170,7 @@ static int parse_int(m_option_t* opt,cha
 }
 
 static char* print_int(m_option_t* opt,  void* val) {
-  opt = NULL;
+  (void) opt;
   return dup_printf("%d",VAL(val));
 }
 
@@ -183,7 +208,7 @@ m_option_type_t m_option_type_int = {
 static int parse_float(m_option_t* opt,char *name, const char *param, void* dst, int src) {
   float tmp_float;
   char* endptr;
-  src = 0;
+  (void) src;
 
   if (param == NULL)
     return M_OPT_MISSING_PARAM;
@@ -230,7 +255,7 @@ static int parse_float(m_option_t* opt,c
 }
 
 static char* print_float(m_option_t* opt,  void* val) {
-  opt = NULL;
+  (void) opt;
   return dup_printf("%f",VAL(val));
 }
 
@@ -268,6 +293,8 @@ m_option_type_t m_option_type_float = {
 static int parse_position(m_option_t* opt,char *name, const char *param, void* dst, int src) {
   off_t tmp_off;
   char dummy;
+  (void) name;
+  (void) src;
 
   if (param == NULL)
     return M_OPT_MISSING_PARAM;
@@ -303,6 +330,7 @@ static int parse_position(m_option_t* op
 }
 
 static char* print_position(m_option_t* opt,  void* val) {
+  (void) opt;
   return dup_printf(sizeof(off_t) == sizeof(int) ?  "%d" : "%lld",VAL(val));
 }
 
@@ -331,6 +359,8 @@ m_option_type_t m_option_type_position =
 #define VAL(x) (*(char**)(x))
 
 static int parse_str(m_option_t* opt,char *name, const char *param, void* dst, int src) {
+  (void) name;
+  (void) src;
   
 #ifndef DISABLE_OLD_FILTER_CONFIG
   if (opt->flags & M_OPT_EMPTY && !param)
@@ -363,10 +393,12 @@ static int parse_str(m_option_t* opt,cha
 }
 
 static char* print_str(m_option_t* opt,  void* val) {
+  (void) opt;
   return (val && VAL(val) && strlen(VAL(val)) > 0) ? strdup(VAL(val)) : NULL;
 }
 
 static void copy_str(m_option_t* opt,void* dst, void* src) {
+  (void) opt;
   if(dst && src) {
 //    if(VAL(dst)) free(VAL(dst)); //FIXME!!!
     VAL(dst) = VAL(src) ? strdup(VAL(src)) : NULL;
@@ -411,7 +443,9 @@ m_option_type_t m_option_type_string = {
 
 static int parse_choose(m_option_t* opt,char *name,const char *param,void* dst,int src) {
   char *subopt;
-  char** lst = NULL;
+  char** lst;
+  (void) opt;
+  (void) name;
 
   if (param == NULL || strlen(param) == 0)
     return M_OPT_MISSING_PARAM;
@@ -436,6 +470,7 @@ static int parse_choose(m_option_t* opt,
 }
 
 static char* print_choose(m_option_t *opt, void *val) {
+  (void) val;
   return (opt->priv) ? strdup((char *)opt->priv) : NULL;
 }
 
@@ -583,6 +618,7 @@ static char* print_list(m_option_t* opt,
   char **lst;
   char *ret = NULL, *last = NULL;
   int i = 0;
+  (void) src;
 
   if(opt && opt->priv) {
     for(lst = opt->priv; lst[i]; i++) {
@@ -653,6 +689,8 @@ static void free_func_pf(void* src) {
 // Parser for func_param and func_full
 static int parse_func_pf(m_option_t* opt,char *name, const char *param, void* dst, int src) {
   m_func_save_t *s,*p;
+  (void) opt;
+  (void) src;
 
   if(!dst)
     return 1;
@@ -674,6 +712,7 @@ static int parse_func_pf(m_option_t* opt
 
 static void copy_func_pf(m_option_t* opt,void* dst, void* src) {
   m_func_save_t *d = NULL, *s,* last = NULL;
+  (void) opt;
 
   if(!(dst && src)) return;
   s = VAL(src);
@@ -700,6 +739,7 @@ static void copy_func_pf(m_option_t* opt
 
 static void set_func_param(m_option_t* opt, void* dst, void* src) {
   m_func_save_t* s;
+  (void) dst;
 
   if(!src) return;
   s = VAL(src);
@@ -730,6 +770,7 @@ m_option_type_t m_option_type_func_param
 
 static void set_func_full(m_option_t* opt, void* dst, void* src) {
   m_func_save_t* s;
+  (void) dst;
 
   if(!src) return;
 
@@ -760,6 +801,10 @@ m_option_type_t m_option_type_func_full 
 #define VAL(x) (*(int*)(x))
 
 static int parse_func(m_option_t* opt,char *name, const char *param, void* dst, int src) {
+  (void) opt;
+  (void) name;
+  (void) param;
+  (void) src;
   if(dst)
     VAL(dst) += 1;
   return 0;
@@ -767,6 +812,7 @@ static int parse_func(m_option_t* opt,ch
 
 static void set_func(m_option_t* opt,void* dst, void* src) {
   int i;
+  (void) dst;
   if(opt->priv) ((m_opt_default_func_t)opt->priv)(opt,opt->name);
   for(i = 0 ; i < VAL(src) ; i++)
     ((m_opt_func_t) opt->p)(opt);
@@ -789,6 +835,10 @@ m_option_type_t m_option_type_func = {
 /////////////////// Print, opt->t is (char[])
 
 static int parse_print(m_option_t* opt,char *name, const char *param, void* dst, int src) {
+  (void) name;
+  (void) dst;
+  (void) param;
+  (void) src;
   if(opt->type->flags&M_OPT_TYPE_INDIRECT)
     mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", *(char **) opt->p);
   else
@@ -838,6 +888,7 @@ static int parse_subconf(m_option_t* opt
   char *subparam, *subopt_p;
   char *p;
   char** lst = NULL;
+  (void) name;
 
   if (param == NULL || strlen(param) == 0)
     return 0; // empty parameter list is valid anyway ;)
@@ -982,6 +1033,8 @@ static int parse_span(m_option_t* opt,ch
   m_span_t* span = dst;
   char *s,*e = NULL;
   int r = M_OPT_INVALID;
+  (void) opt;
+  (void) src;
 
   if(param == NULL)
     return M_OPT_MISSING_PARAM;
--- m_option.h.old	Tue Mar 25 20:26:16 2003
+++ m_option.h	Wed Mar 26 13:11:54 2003
@@ -15,7 +15,7 @@ extern m_option_type_t m_option_type_fla
 extern m_option_type_t m_option_type_int;
 extern m_option_type_t m_option_type_float;
 extern m_option_type_t m_option_type_string;
-extern m_option_type_t m_option_type_string_list;
+//extern m_option_type_t m_option_type_string_list;
 extern m_option_type_t m_option_type_position;
 
 extern m_option_type_t m_option_type_print;
@@ -24,6 +24,7 @@ extern m_option_type_t m_option_type_sub
 // extern m_option_type_t m_option_type_imgfmt;
 extern m_option_type_t m_option_type_choose;
 extern m_option_type_t m_option_type_list;
+extern m_option_type_t m_option_type_dummy;
 
 // Func based types 
 extern m_option_type_t m_option_type_func_full;
@@ -90,6 +91,8 @@ extern m_option_type_t m_option_type_spa
 // but selection may contain comma separated list of options that will be
 // saved as list of names (char ***)opt->priv
 #define CONF_TYPE_LIST		(&m_option_type_list)
+// menu separator ;)
+#define CONF_TYPE_DUMMY		(&m_option_type_dummy)
 
 /////////////////////////////////////////////////////////////////////////////////////////////
 


More information about the MPlayer-dev-eng mailing list