[MPlayer-cvslog] r32387 - trunk/m_config.c

diego subversion at mplayerhq.hu
Mon Sep 27 14:10:59 CEST 2010


Author: diego
Date: Mon Sep 27 14:10:59 2010
New Revision: 32387

Log:
cosmetics: Move some functions around to avoid ugly forward declarations.

Modified:
   trunk/m_config.c

Modified: trunk/m_config.c
==============================================================================
--- trunk/m_config.c	Mon Sep 27 13:54:17 2010	(r32386)
+++ trunk/m_config.c	Mon Sep 27 14:10:59 2010	(r32387)
@@ -36,20 +36,116 @@
 
 #define MAX_PROFILE_DEPTH 20
 
-static int
-parse_profile(const m_option_t *opt, const char *name, const char *param, void *dst, int src);
 
-static void
-set_profile(const m_option_t *opt, void* dst, const void* src);
+static int parse_profile(const m_option_t *opt, const char *name,
+                         const char *param, void *dst, int src)
+{
+    m_config_t *config = opt->priv;
+    char **list = NULL;
+    int i, r;
+    if (param && !strcmp(param, "help")) {
+        m_profile_t *p;
+        if (!config->profiles) {
+            mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_NoProfileDefined);
+            return M_OPT_EXIT-1;
+        }
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_AvailableProfiles);
+        for (p = config->profiles; p; p = p->next)
+            mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n", p->name,
+                   p->desc ? p->desc : "");
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+        return M_OPT_EXIT-1;
+    }
 
-static int
-show_profile(m_option_t *opt, char* name, char *param);
+    r = m_option_type_string_list.parse(opt, name, param, &list,src);
+    if (r < 0)
+        return r;
+    if (!list || !list[0])
+        return M_OPT_INVALID;
+    for (i = 0; list[i]; i++)
+        if (!m_config_get_profile(config,list[i])) {
+            mp_msg(MSGT_CFGPARSER, MSGL_WARN, MSGTR_UnknownProfile, list[i]);
+            r = M_OPT_INVALID;
+        }
+    if (dst)
+        m_option_copy(opt, dst, &list);
+    else
+        m_option_free(opt, &list);
+    return r;
+}
 
 static void
-m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefix);
+set_profile(const m_option_t *opt, void *dst, const void *src)
+{
+    m_config_t *config = opt->priv;
+    m_profile_t *p;
+    char **list = NULL;
+    int i;
+    if (!src || !*(char***)src)
+        return;
+    m_option_copy(opt,&list,src);
+    for (i = 0; list[i]; i++) {
+        p = m_config_get_profile(config, list[i]);
+        if (!p)
+            continue;
+        m_config_set_profile(config, p);
+    }
+    m_option_free(opt, &list);
+}
 
-static int
-list_options(m_option_t *opt, char* name, char *param);
+static int show_profile(m_option_t *opt, char* name, char *param)
+{
+    m_config_t *config = opt->priv;
+    m_profile_t *p;
+    int i, j;
+    if (!param)
+        return M_OPT_MISSING_PARAM;
+    if (!(p = m_config_get_profile(config, param))) {
+        mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownProfile, param);
+        return M_OPT_EXIT - 1;
+    }
+    if (!config->profile_depth)
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_Profile, param,
+               p->desc ? p->desc : "");
+    config->profile_depth++;
+    for (i = 0; i < p->num_opts; i++) {
+        char spc[config->profile_depth + 1];
+        for (j = 0; j < config->profile_depth; j++)
+            spc[j] = ' ';
+        spc[config->profile_depth] = '\0';
+
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc,
+               p->opts[2 * i], p->opts[2 * i + 1]);
+
+        if (config->profile_depth < MAX_PROFILE_DEPTH &&
+            !strcmp(p->opts[2*i],"profile")) {
+            char *e, *list = p->opts[2 * i + 1];
+            while ((e = strchr(list, ','))) {
+                int l = e-list;
+                char tmp[l+1];
+                if (!l)
+                    continue;
+                memcpy(tmp, list, l);
+                tmp[l] = '\0';
+                show_profile(opt, name, tmp);
+                list = e+1;
+            }
+            if (list[0] != '\0')
+                show_profile(opt, name, list);
+        }
+    }
+    config->profile_depth--;
+    if (!config->profile_depth)
+        mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+    return M_OPT_EXIT - 1;
+}
+
+static int list_options(m_option_t *opt, char* name, char *param)
+{
+    m_config_t *config = opt->priv;
+    m_config_print_option_list(config);
+    return M_OPT_EXIT;
+}
 
 m_config_t*
 m_config_new(void) {
@@ -500,107 +596,3 @@ m_config_set_profile(m_config_t* config,
     m_config_set_option(config,p->opts[2*i],p->opts[2*i+1]);
   config->profile_depth--;
 }
-
-static int
-parse_profile(const m_option_t *opt, const char *name, const char *param, void *dst, int src)
-{
-  m_config_t* config = opt->priv;
-  char** list = NULL;
-  int i,r;
-  if(param && !strcmp(param,"help")) {
-    m_profile_t* p;
-    if(!config->profiles) {
-      mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_NoProfileDefined);
-      return M_OPT_EXIT-1;
-    }
-    mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_AvailableProfiles);
-    for(p = config->profiles ; p ; p = p->next)
-      mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n",p->name,
-	     p->desc ? p->desc : "");
-    mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
-    return M_OPT_EXIT-1;
-  }
-
-  r = m_option_type_string_list.parse(opt,name,param,&list,src);
-  if(r < 0) return r;
-  if(!list || !list[0]) return M_OPT_INVALID;
-  for(i = 0 ; list[i] ; i++)
-    if(!m_config_get_profile(config,list[i])) {
-      mp_msg(MSGT_CFGPARSER, MSGL_WARN, MSGTR_UnknownProfile,
-             list[i]);
-      r = M_OPT_INVALID;
-    }
-  if(dst)
-    m_option_copy(opt,dst,&list);
-  else
-    m_option_free(opt,&list);
-  return r;
-}
-
-static void
-set_profile(const m_option_t *opt, void *dst, const void *src) {
-  m_config_t* config = opt->priv;
-  m_profile_t* p;
-  char** list = NULL;
-  int i;
-  if(!src || !*(char***)src) return;
-  m_option_copy(opt,&list,src);
-  for(i = 0 ; list[i] ; i++) {
-    p = m_config_get_profile(config,list[i]);
-    if(!p) continue;
-    m_config_set_profile(config,p);
-  }
-  m_option_free(opt,&list);
-}
-
-static int
-show_profile(m_option_t *opt, char* name, char *param) {
-  m_config_t* config = opt->priv;
-  m_profile_t* p;
-  int i,j;
-  if(!param) return M_OPT_MISSING_PARAM;
-  if(!(p = m_config_get_profile(config,param))) {
-    mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownProfile, param);
-    return M_OPT_EXIT-1;
-  }
-  if(!config->profile_depth)
-    mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_Profile, param,
-	   p->desc ? p->desc : "");
-  config->profile_depth++;
-  for(i = 0 ; i < p->num_opts ; i++) {
-    char spc[config->profile_depth+1];
-    for(j = 0 ; j < config->profile_depth ; j++)
-      spc[j] = ' ';
-    spc[config->profile_depth] = '\0';
-
-    mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc,
-	   p->opts[2*i], p->opts[2*i+1]);
-
-
-    if(config->profile_depth < MAX_PROFILE_DEPTH &&
-       !strcmp(p->opts[2*i],"profile")) {
-      char* e,*list = p->opts[2*i+1];
-      while((e = strchr(list,','))) {
-	int l = e-list;
-	char tmp[l+1];
-	if(!l) continue;
-	memcpy(tmp,list,l);
-	tmp[l] = '\0';
-	show_profile(opt,name,tmp);
-	list = e+1;
-      }
-      if(list[0] != '\0')
-	show_profile(opt,name,list);
-    }
-  }
-  config->profile_depth--;
-  if(!config->profile_depth) mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
-  return M_OPT_EXIT-1;
-}
-
-static int
-list_options(m_option_t *opt, char* name, char *param) {
-  m_config_t* config = opt->priv;
-  m_config_print_option_list(config);
-  return M_OPT_EXIT;
-}


More information about the MPlayer-cvslog mailing list