Mercurial > mplayer.hg
annotate m_struct.c @ 36394:2f815fdd521c
Remove pointless cast.
author | reimar |
---|---|
date | Sat, 26 Oct 2013 09:36:21 +0000 |
parents | 389d43c448b3 |
children |
rev | line source |
---|---|
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
1 /* |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
3 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
8 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
13 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
17 */ |
18258 | 18 |
19 /// \file | |
20 /// \ingroup OptionsStruct | |
21 | |
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
22 #include "config.h" |
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 #include <stdlib.h> |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
25 #include <string.h> |
35903 | 26 #include <strings.h> |
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
27 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
28 #include "m_option.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
29 #include "m_struct.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
30 #include "mp_msg.h" |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
31 |
24966
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
32 const m_option_t* |
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
33 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
|
34 int i; |
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 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
|
37 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
|
38 return &st->fields[i]; |
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 return NULL; |
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 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
43 void* |
24966
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
44 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
|
45 int i; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
46 void* 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 if(!st->defaults) { |
10718 | 49 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
|
50 return NULL; |
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 // Check the struct fields |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
53 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
|
54 if(st->fields[i].type->flags & M_OPT_TYPE_INDIRECT) { |
23873 | 55 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
|
56 return NULL; |
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 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
60 r = calloc(1,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
61 memcpy(r,st->defaults,st->size); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24966
diff
changeset
|
62 |
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
68 return r; |
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 int |
30695
a26f6577d338
Make more option-parsing related function arguments const.
reimar
parents:
30429
diff
changeset
|
72 m_struct_set(const m_struct_t* st, void* obj, const char* field, const char* param) { |
24966
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
73 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
|
74 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
75 if(!f) { |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
76 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
|
77 st->name,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
78 return 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24966
diff
changeset
|
79 } |
8169
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 if(f->type->parse(f,field,param,M_ST_MB_P(obj,f->p),M_CONFIG_FILE) < 0) { |
9790 | 82 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
|
83 st->name,field,param); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
84 return 0; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
85 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24966
diff
changeset
|
86 |
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
87 return 1; |
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 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
90 void |
24966
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
91 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
|
92 const m_option_t* f; |
8169
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 if(!field) { // Reset all options |
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 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
|
97 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
|
98 return; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
99 } |
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 // Only one |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
102 f = m_struct_get_field(st,field); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24966
diff
changeset
|
103 if(!f) { |
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
104 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
|
105 st->name,field); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
106 return; |
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 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
|
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 /// Free an allocated struct |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
112 void |
24966
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
113 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
|
114 int i; |
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 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
|
117 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
|
118 free(obj); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
119 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
120 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
121 void* |
24966
cc170348a763
correct const usage in the option handling code so that tables can be
rfelker
parents:
23873
diff
changeset
|
122 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
|
123 void* r = malloc(st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
124 int i; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
24966
diff
changeset
|
125 |
8169
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
126 memcpy(r,obj,st->size); |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 } |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
132 |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
133 return r; |
7c9253521f9c
A struct setter. It allow you to setup struct from some user
albeu
parents:
diff
changeset
|
134 } |