2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// \file
|
|
|
|
/// \ingroup OptionsStruct
|
|
|
|
|
2002-11-12 14:16:30 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/m_option.h"
|
|
|
|
#include "core/m_struct.h"
|
|
|
|
#include "core/mp_msg.h"
|
2002-11-12 14:16:30 +00:00
|
|
|
|
2007-11-09 06:50:53 +00:00
|
|
|
const m_option_t*
|
|
|
|
m_struct_get_field(const m_struct_t* st,const char* f) {
|
2002-11-12 14:16:30 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0 ; st->fields[i].name ; i++) {
|
|
|
|
if(strcasecmp(st->fields[i].name,f) == 0)
|
|
|
|
return &st->fields[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2007-11-09 06:50:53 +00:00
|
|
|
m_struct_alloc(const m_struct_t* st) {
|
2002-11-12 14:16:30 +00:00
|
|
|
int i;
|
|
|
|
void* r;
|
|
|
|
|
|
|
|
if(!st->defaults) {
|
2003-08-29 21:42:51 +00:00
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s needs defaults\n",st->name);
|
2002-11-12 14:16:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = calloc(1,st->size);
|
|
|
|
memcpy(r,st->defaults,st->size);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-11-12 14:16:30 +00:00
|
|
|
for(i = 0 ; st->fields[i].name ; i++) {
|
|
|
|
if(st->fields[i].type->flags & M_OPT_TYPE_DYNAMIC)
|
|
|
|
memset(M_ST_MB_P(r,st->fields[i].p),0,st->fields[i].type->size);
|
|
|
|
m_option_copy(&st->fields[i],M_ST_MB_P(r,st->fields[i].p),M_ST_MB_P(st->defaults,st->fields[i].p));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-07-28 08:07:47 +00:00
|
|
|
int m_struct_set(const m_struct_t *st, void *obj, const char *field,
|
|
|
|
struct bstr param)
|
|
|
|
{
|
2007-11-09 06:50:53 +00:00
|
|
|
const m_option_t* f = m_struct_get_field(st,field);
|
2002-11-12 14:16:30 +00:00
|
|
|
|
|
|
|
if(!f) {
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s doesn't have any %s field\n",
|
|
|
|
st->name,field);
|
|
|
|
return 0;
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
2002-11-12 14:16:30 +00:00
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
if(f->type->parse(f, bstr0(field), param, M_ST_MB_P(obj,f->p)) < 0) {
|
2011-07-28 08:07:47 +00:00
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s, field %s parsing error: %.*s\n",
|
|
|
|
st->name, field, BSTR_P(param));
|
2002-11-12 14:16:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-11-12 14:16:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Free an allocated struct
|
|
|
|
void
|
2007-11-09 06:50:53 +00:00
|
|
|
m_struct_free(const m_struct_t* st, void* obj) {
|
2002-11-12 14:16:30 +00:00
|
|
|
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);
|
|
|
|
}
|