static int parse_profile(m_option_t* opt,char *name, 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; }
m_profile_t* m_config_add_profile(m_config_t* config, char* name) { m_profile_t* p = m_config_get_profile(config,name); if(p) return p; p = calloc(1,sizeof(m_profile_t)); p->name = strdup(name); p->next = config->profiles; config->profiles = p; return p; }
static void set_profile(m_option_t *opt, void* dst, 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 parse_profile(struct m_config *config, const struct m_option *opt, struct bstr name, struct bstr param, bool set) { if (!bstrcmp0(param, "help")) { struct m_profile *p; if (!config->profiles) { mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "No profiles have been defined.\n"); return M_OPT_EXIT - 1; } mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "Available profiles:\n"); 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; } char **list = NULL; int r = m_option_type_string_list.parse(opt, name, param, &list); if (r < 0) return r; if (!list || !list[0]) return M_OPT_INVALID; for (int i = 0; list[i]; i++) { struct m_profile *p = m_config_get_profile(config, list[i]); if (!p) { mp_tmsg(MSGT_CFGPARSER, MSGL_WARN, "Unknown profile '%s'.\n", list[i]); r = M_OPT_INVALID; } else if (set) m_config_set_profile(config, p); } m_option_free(opt, &list); return r; }