Mercurial > mplayer.hg
annotate m_struct.c @ 8257:635df9d22d38
100l patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
author | michael |
---|---|
date | Sat, 23 Nov 2002 12:37:06 +0000 |
parents | 7c9253521f9c |
children | 864cdb2debb0 |
rev | line source |
---|---|
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
1 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
2 #include "config.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
3 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
4 #ifdef NEW_CONFIG |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
5 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
6 #include <stdlib.h> |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
7 #include <string.h> |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
8 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
9 #include "m_option.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
10 #include "m_struct.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
11 #include "mp_msg.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
12 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
13 m_option_t* |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
14 m_struct_get_field(m_struct_t* st,char* f) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
15 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
16 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
17 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
|
18 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
|
19 return &st->fields[i]; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
20 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
21 return NULL; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
22 } |
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 void* |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
25 m_struct_alloc(m_struct_t* st) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
26 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
27 void* r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
28 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
29 if(!st->defaults) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
30 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s need defaults\n"); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
31 return NULL; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
32 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
33 // Check the struct fields |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
34 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
|
35 if(st->fields[i].type->flags & M_OPT_TYPE_INDIRECT) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
36 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s->%s: option type with the indirect flag are forbiden\n",st->name,st->fields[i].name); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
37 return NULL; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
38 } |
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 r = calloc(1,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
42 memcpy(r,st->defaults,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
43 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 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
|
48 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
49 return r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
50 } |
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 int |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
53 m_struct_set(m_struct_t* st, void* obj, char* field, char* param) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
54 m_option_t* f = m_struct_get_field(st,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
55 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
56 if(!f) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
57 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
|
58 st->name,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
59 return 0; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
60 } |
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 if(f->type->parse(f,field,param,M_ST_MB_P(obj,f->p),M_CONFIG_FILE) < 0) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
63 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Strut %s, field %s parsing error: %s\n", |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
64 st->name,field,param); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
65 return 0; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
66 } |
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 return 1; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
69 } |
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 void |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
72 m_struct_reset(m_struct_t* st, void* obj, char* field) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
73 m_option_t* f; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
74 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
75 if(!field) { // Reset all options |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
76 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
77 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
|
78 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
|
79 return; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
80 } |
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 // Only one |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
83 f = m_struct_get_field(st,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
84 if(!f) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
85 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
|
86 st->name,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
87 return; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
88 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
89 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
|
90 } |
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 /// Free an allocated struct |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
93 void |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
94 m_struct_free(m_struct_t* st, void* obj) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
95 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
96 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
97 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
|
98 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
|
99 free(obj); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
100 } |
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 void* |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
103 m_struct_copy(m_struct_t* st, void* obj) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
104 void* r = malloc(st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
105 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
106 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
107 memcpy(r,obj,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 } |
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 return r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
115 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
116 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
117 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
118 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
119 #endif // NEW_CONFIG |