11 m_struct_get_field(m_struct_t
* st
,char* f
) {
14 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
15 if(strcasecmp(st
->fields
[i
].name
,f
) == 0)
16 return &st
->fields
[i
];
22 m_struct_alloc(m_struct_t
* st
) {
27 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s needs defaults\n",st
->name
);
30 // Check the struct fields
31 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
32 if(st
->fields
[i
].type
->flags
& M_OPT_TYPE_INDIRECT
) {
33 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s->%s: option type with the indirect flag are forbiden\n",st
->name
,st
->fields
[i
].name
);
38 r
= calloc(1,st
->size
);
39 memcpy(r
,st
->defaults
,st
->size
);
41 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
42 if(st
->fields
[i
].type
->flags
& M_OPT_TYPE_DYNAMIC
)
43 memset(M_ST_MB_P(r
,st
->fields
[i
].p
),0,st
->fields
[i
].type
->size
);
44 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
));
50 m_struct_set(m_struct_t
* st
, void* obj
, char* field
, char* param
) {
51 m_option_t
* f
= m_struct_get_field(st
,field
);
54 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s doesn't have any %s field\n",
59 if(f
->type
->parse(f
,field
,param
,M_ST_MB_P(obj
,f
->p
),M_CONFIG_FILE
) < 0) {
60 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s, field %s parsing error: %s\n",
61 st
->name
,field
,param
);
69 m_struct_reset(m_struct_t
* st
, void* obj
, char* field
) {
72 if(!field
) { // Reset all options
74 for(i
= 0 ; st
->fields
[i
].name
; i
++)
75 m_option_copy(&st
->fields
[i
],M_ST_MB_P(obj
,st
->fields
[i
].p
),M_ST_MB_P(st
->defaults
,st
->fields
[i
].p
));
80 f
= m_struct_get_field(st
,field
);
82 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s doesn't have any %s field\n",
86 m_option_copy(f
,M_ST_MB_P(obj
,f
->p
),M_ST_MB_P(st
->defaults
,f
->p
));
89 /// Free an allocated struct
91 m_struct_free(m_struct_t
* st
, void* obj
) {
94 for(i
= 0 ; st
->fields
[i
].name
; i
++)
95 m_option_free(&st
->fields
[i
],M_ST_MB_P(obj
,st
->fields
[i
].p
));
100 m_struct_copy(m_struct_t
* st
, void* obj
) {
101 void* r
= malloc(st
->size
);
104 memcpy(r
,obj
,st
->size
);
105 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
106 if(st
->fields
[i
].type
->flags
& M_OPT_TYPE_DYNAMIC
)
107 memset(M_ST_MB_P(r
,st
->fields
[i
].p
),0,st
->fields
[i
].type
->size
);
108 m_option_copy(&st
->fields
[i
],M_ST_MB_P(r
,st
->fields
[i
].p
),M_ST_MB_P(obj
,st
->fields
[i
].p
));