changeset 32301:a65635702512

cosmetics: Move some functions around to avoid ugly forward declarations.
author diego
date Mon, 27 Sep 2010 12:10:59 +0000
parents 1ca3d798b518
children 6d3212dd47b2
files m_config.c
diffstat 1 files changed, 106 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/m_config.c	Mon Sep 27 11:54:17 2010 +0000
+++ b/m_config.c	Mon Sep 27 12:10:59 2010 +0000
@@ -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 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);
-
-static int
-show_profile(m_option_t *opt, char* name, char *param);
+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 void
-m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefix);
+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]);
 
-static int
-list_options(m_option_t *opt, char* name, char *param);
+        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_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;
-}