Mercurial > mplayer.hg
annotate m_struct.c @ 12528:debda3544d32
history translated
author | alex |
---|---|
date | Wed, 02 Jun 2004 23:14:13 +0000 |
parents | e3727e92e9d8 |
children | 96568be4bfdc |
rev | line source |
---|---|
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
1 #include "config.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
2 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
3 #include <stdlib.h> |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
4 #include <string.h> |
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 "m_option.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
7 #include "m_struct.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
8 #include "mp_msg.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 m_option_t* |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
11 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
|
12 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
13 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
14 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
|
15 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
|
16 return &st->fields[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 return NULL; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
19 } |
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 void* |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
22 m_struct_alloc(m_struct_t* st) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
23 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
24 void* r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
25 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
26 if(!st->defaults) { |
10718 | 27 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
|
28 return NULL; |
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 // Check the struct fields |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
31 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
|
32 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
|
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); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
34 return NULL; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
35 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
36 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
37 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
38 r = calloc(1,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
39 memcpy(r,st->defaults,st->size); |
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 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
|
42 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
|
43 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
|
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)); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
45 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
46 return r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
47 } |
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 int |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
50 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
|
51 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
|
52 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
53 if(!f) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
54 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
|
55 st->name,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
56 return 0; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
57 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
58 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
59 if(f->type->parse(f,field,param,M_ST_MB_P(obj,f->p),M_CONFIG_FILE) < 0) { |
9790 | 60 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
|
61 st->name,field,param); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
62 return 0; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
63 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
64 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
65 return 1; |
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 void |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
69 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
|
70 m_option_t* f; |
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 if(!field) { // Reset all options |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
73 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
74 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
|
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)); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
76 return; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
77 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
78 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
79 // Only one |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
80 f = m_struct_get_field(st,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
81 if(!f) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
82 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
|
83 st->name,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
84 return; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
85 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
86 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
|
87 } |
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 /// Free an allocated struct |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
90 void |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
91 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
|
92 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
93 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
94 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
|
95 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
|
96 free(obj); |
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 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
99 void* |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
100 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
|
101 void* r = malloc(st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
102 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
103 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
104 memcpy(r,obj,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
105 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
|
106 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
|
107 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
|
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)); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
109 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
110 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
111 return r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
112 } |