3 /// \ingroup OptionsStruct
15 m_struct_get_field(const m_struct_t
* st
,const char* f
) {
18 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
19 if(strcasecmp(st
->fields
[i
].name
,f
) == 0)
20 return &st
->fields
[i
];
26 m_struct_alloc(const m_struct_t
* st
) {
31 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s needs defaults\n",st
->name
);
34 // Check the struct fields
35 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
36 if(st
->fields
[i
].type
->flags
& M_OPT_TYPE_INDIRECT
) {
37 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s->%s: Option types with the indirect flag are forbidden.\n",st
->name
,st
->fields
[i
].name
);
42 r
= calloc(1,st
->size
);
43 memcpy(r
,st
->defaults
,st
->size
);
45 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
46 if(st
->fields
[i
].type
->flags
& M_OPT_TYPE_DYNAMIC
)
47 memset(M_ST_MB_P(r
,st
->fields
[i
].p
),0,st
->fields
[i
].type
->size
);
48 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
));
54 m_struct_set(const m_struct_t
* st
, void* obj
, char* field
, char* param
) {
55 const m_option_t
* f
= m_struct_get_field(st
,field
);
58 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s doesn't have any %s field\n",
63 if(f
->type
->parse(f
,field
,param
,M_ST_MB_P(obj
,f
->p
),M_CONFIG_FILE
) < 0) {
64 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s, field %s parsing error: %s\n",
65 st
->name
,field
,param
);
73 m_struct_reset(const m_struct_t
* st
, void* obj
, const char* field
) {
76 if(!field
) { // Reset all options
78 for(i
= 0 ; st
->fields
[i
].name
; i
++)
79 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
));
84 f
= m_struct_get_field(st
,field
);
86 mp_msg(MSGT_CFGPARSER
, MSGL_ERR
,"Struct %s doesn't have any %s field\n",
90 m_option_copy(f
,M_ST_MB_P(obj
,f
->p
),M_ST_MB_P(st
->defaults
,f
->p
));
93 /// Free an allocated struct
95 m_struct_free(const m_struct_t
* st
, void* obj
) {
98 for(i
= 0 ; st
->fields
[i
].name
; i
++)
99 m_option_free(&st
->fields
[i
],M_ST_MB_P(obj
,st
->fields
[i
].p
));
104 m_struct_copy(const m_struct_t
* st
, void* obj
) {
105 void* r
= malloc(st
->size
);
108 memcpy(r
,obj
,st
->size
);
109 for(i
= 0 ; st
->fields
[i
].name
; i
++) {
110 if(st
->fields
[i
].type
->flags
& M_OPT_TYPE_DYNAMIC
)
111 memset(M_ST_MB_P(r
,st
->fields
[i
].p
),0,st
->fields
[i
].type
->size
);
112 m_option_copy(&st
->fields
[i
],M_ST_MB_P(r
,st
->fields
[i
].p
),M_ST_MB_P(obj
,st
->fields
[i
].p
));