annotate m_struct.c @ 27345:b597fd2924b4

Rename preprocessor directive HAVE_MENU --> CONFIG_MENU.
author diego
date Wed, 30 Jul 2008 18:07:19 +0000
parents cc170348a763
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18258
96568be4bfdc Doxygen attack!
albeu
parents: 10718
diff changeset
1
96568be4bfdc Doxygen attack!
albeu
parents: 10718
diff changeset
2 /// \file
96568be4bfdc Doxygen attack!
albeu
parents: 10718
diff changeset
3 /// \ingroup OptionsStruct
96568be4bfdc Doxygen attack!
albeu
parents: 10718
diff changeset
4
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
5 #include "config.h"
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
6
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
7 #include <stdlib.h>
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
8 #include <string.h>
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
9
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
10 #include "m_option.h"
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
11 #include "m_struct.h"
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
12 #include "mp_msg.h"
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
13
24966
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
14 const m_option_t*
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
15 m_struct_get_field(const m_struct_t* st,const char* f) {
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
16 int i;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
17
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
18 for(i = 0 ; st->fields[i].name ; i++) {
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
19 if(strcasecmp(st->fields[i].name,f) == 0)
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
20 return &st->fields[i];
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
21 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
22 return NULL;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
23 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
24
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
25 void*
24966
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
26 m_struct_alloc(const m_struct_t* st) {
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
27 int i;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
28 void* r;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
29
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
30 if(!st->defaults) {
10718
alex
parents: 10594
diff changeset
31 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s needs defaults\n",st->name);
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
32 return NULL;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
33 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
34 // Check the struct fields
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
35 for(i = 0 ; st->fields[i].name ; i++) {
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
36 if(st->fields[i].type->flags & M_OPT_TYPE_INDIRECT) {
23873
49a433e2e78f cosmetics: misc typo fixes
diego
parents: 19104
diff changeset
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);
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
38 return NULL;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
39 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
40 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
41
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
42 r = calloc(1,st->size);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
43 memcpy(r,st->defaults,st->size);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
44
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
45 for(i = 0 ; st->fields[i].name ; i++) {
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
46 if(st->fields[i].type->flags & M_OPT_TYPE_DYNAMIC)
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
47 memset(M_ST_MB_P(r,st->fields[i].p),0,st->fields[i].type->size);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
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));
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
49 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
50 return r;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
51 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
52
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
53 int
24966
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
54 m_struct_set(const m_struct_t* st, void* obj, char* field, char* param) {
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
55 const m_option_t* f = m_struct_get_field(st,field);
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
56
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
57 if(!f) {
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
58 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s doesn't have any %s field\n",
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
59 st->name,field);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
60 return 0;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
61 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
62
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
63 if(f->type->parse(f,field,param,M_ST_MB_P(obj,f->p),M_CONFIG_FILE) < 0) {
9790
864cdb2debb0 Typo fix
albeu
parents: 8169
diff changeset
64 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s, field %s parsing error: %s\n",
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
65 st->name,field,param);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
66 return 0;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
67 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
68
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
69 return 1;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
70 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
71
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
72 void
24966
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
73 m_struct_reset(const m_struct_t* st, void* obj, const char* field) {
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
74 const m_option_t* f;
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
75
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
76 if(!field) { // Reset all options
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
77 int i;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
78 for(i = 0 ; st->fields[i].name ; i++)
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
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));
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
80 return;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
81 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
82
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
83 // Only one
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
84 f = m_struct_get_field(st,field);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
85 if(!f) {
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
86 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s doesn't have any %s field\n",
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
87 st->name,field);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
88 return;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
89 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
90 m_option_copy(f,M_ST_MB_P(obj,f->p),M_ST_MB_P(st->defaults,f->p));
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
91 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
92
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
93 /// Free an allocated struct
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
94 void
24966
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
95 m_struct_free(const m_struct_t* st, void* obj) {
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
96 int i;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
97
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
98 for(i = 0 ; st->fields[i].name ; i++)
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
99 m_option_free(&st->fields[i],M_ST_MB_P(obj,st->fields[i].p));
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
100 free(obj);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
101 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
102
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
103 void*
24966
cc170348a763 correct const usage in the option handling code so that tables can be
rfelker
parents: 23873
diff changeset
104 m_struct_copy(const m_struct_t* st, void* obj) {
8169
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
105 void* r = malloc(st->size);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
106 int i;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
107
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
108 memcpy(r,obj,st->size);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
109 for(i = 0 ; st->fields[i].name ; i++) {
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
110 if(st->fields[i].type->flags & M_OPT_TYPE_DYNAMIC)
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
111 memset(M_ST_MB_P(r,st->fields[i].p),0,st->fields[i].type->size);
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
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));
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
113 }
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
114
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
115 return r;
7c9253521f9c A struct setter. It allow you to setup struct from some user
albeu
parents:
diff changeset
116 }