Exemple #1
0
static int config_destroy(void *p)
{
    struct m_config *config = p;
    for (struct m_config_option *copt = config->opts; copt; copt = copt->next) {
        if (copt->alias_owner)
            continue;
        if (copt->opt->type->flags & M_OPT_TYPE_DYNAMIC) {
            m_option_free(copt->opt, copt->data);
        }
        if (copt->global_backup)
            m_option_free(copt->opt, copt->global_backup);
    }
    return 0;
}
Exemple #2
0
void
m_config_pop(m_config_t* config) {
  m_config_option_t *co;
  m_config_save_slot_t *slot;

#ifdef MP_DEBUG
  assert(config != NULL);
  assert(config->lvl > 1);
#endif

  for(co = config->opts ; co ; co = co->next ) {
    int pop = 0;
    if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
      continue;
    if(co->opt->flags & (M_OPT_GLOBAL|M_OPT_NOSAVE))
      continue;
    if(co->flags & M_CFG_OPT_ALIAS)
      continue;
    if(co->slots->lvl > config->lvl)
      mp_msg(MSGT_CFGPARSER, MSGL_WARN,MSGTR_SaveSlotTooOld,config->lvl,co->slots->lvl);

    while(co->slots->lvl >= config->lvl) {
      m_option_free(co->opt,co->slots->data);
      slot = co->slots;
      co->slots = slot->prev;
      free(slot);
      pop++;
    }
    if(pop) // We removed some ctx -> set the previous value
      m_option_set(co->opt,co->opt->p,co->slots->data);
  }

  config->lvl--;
  mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config poped level=%d\n",config->lvl);
}
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;
}
/// Free an allocated struct
void
m_struct_free(const m_struct_t* st, void* obj) {
  int i;

  for(i = 0 ; st->fields[i].name ; i++)
    m_option_free(&st->fields[i],M_ST_MB_P(obj,st->fields[i].p));
  free(obj);
}
Exemple #5
0
void
m_config_free(m_config_t* config) {
  m_config_option_t *i = config->opts, *ct;
  m_config_save_slot_t *sl,*st;
  m_profile_t *p,*pn;
  int j;

#ifdef MP_DEBUG
  assert(config != NULL);
#endif

  while(i) {
    if (i->flags & M_CFG_OPT_ALIAS)
      sl = NULL;
    else
      sl = i->slots;
    while(sl) {
      m_option_free(i->opt,sl->data);
      st = sl->prev;
      free(sl);
      sl = st;
    }
    if(i->name != i->opt->name)
      free(i->name);
    if(i->opt->p && (i->opt->type->flags & M_OPT_TYPE_DYNAMIC))
      m_option_free(i->opt, i->opt->p);
    ct = i->next;
    free(i);
    i = ct;
  }
  for(p = config->profiles ; p ; p = pn) {
    pn = p->next;
    free(p->name);
    free(p->desc);
    for(j = 0 ; j < p->num_opts ; j++) {
      free(p->opts[2*j]);
      free(p->opts[2*j + 1]);
    }
    free(p->opts);
    free(p);
  }
  free(config->self_opts);
  free(config);
}
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);
}
Exemple #7
0
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;
}