Mercurial > mplayer.hg
annotate m_property.c @ 20747:d639a26d9141
added definition of DEMUXER_CTRL_RESYNC
author | nicodvb |
---|---|
date | Tue, 07 Nov 2006 22:51:18 +0000 |
parents | 96568be4bfdc |
children | a5e5b0c45c03 |
rev | line source |
---|---|
18258 | 1 |
2 /// \file | |
3 /// \ingroup Properties | |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
4 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
5 #include "config.h" |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
6 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
7 #include <stdlib.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
8 #include <stdio.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
9 #include <string.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
10 #include <inttypes.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
11 #include <unistd.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
12 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
13 #include "m_option.h" |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
14 #include "m_property.h" |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
15 #include "mp_msg.h" |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
16 #include "help_mp.h" |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
17 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
18 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5)) |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
19 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
20 int m_property_do(m_option_t* prop, int action, void* arg) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
21 if(!prop) return M_PROPERTY_UNKNOWN; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
22 return ((m_property_ctrl_f)prop->p)(prop,action,arg); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
23 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
24 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
25 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
26 char* m_property_print(m_option_t* prop) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
27 m_property_ctrl_f ctrl; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
28 void* val; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
29 char* ret; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
30 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
31 if(!prop) return NULL; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
32 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
33 ctrl = prop->p; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
34 // look if the property have it's own print func |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
35 if(ctrl(prop,M_PROPERTY_PRINT,&ret) >= 0) |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
36 return ret; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
37 // fallback on the default print for this type |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
38 val = calloc(1,prop->type->size); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
39 if(ctrl(prop,M_PROPERTY_GET,val) <= 0) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
40 free(val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
41 return NULL; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
42 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
43 ret = m_option_print(prop,val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
44 free(val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
45 return ret == (char*)-1 ? NULL : ret; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
46 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
47 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
48 int m_property_parse(m_option_t* prop, char* txt) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
49 m_property_ctrl_f ctrl; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
50 void* val; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
51 int r; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
52 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
53 if(!prop) return M_PROPERTY_UNKNOWN; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
54 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
55 ctrl = prop->p; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
56 // try the property own parsing func |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
57 if((r = ctrl(prop,M_PROPERTY_PARSE,txt)) != M_PROPERTY_NOT_IMPLEMENTED) |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
58 return r; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
59 // fallback on the default |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
60 val = calloc(1,prop->type->size); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
61 if((r = m_option_parse(prop,prop->name,txt,val,M_CONFIG_FILE)) <= 0) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
62 free(val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
63 return r; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
64 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
65 r = ctrl(prop,M_PROPERTY_SET,val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
66 m_option_free(prop,val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
67 free(val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
68 return r; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
69 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
70 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
71 char* m_properties_expand_string(m_option_t* prop_list,char* str) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
72 int l,fr=0,pos=0,size=strlen(str)+512; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
73 char *p = NULL,*e,*ret = malloc(size), num_val; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
74 int skip = 0, lvl = 0, skip_lvl = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
75 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
76 while(str[0]) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
77 if(str[0] == '\\') { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
78 int sl = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
79 switch(str[1]) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
80 case 'e': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
81 p = "\x1b", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
82 case 'n': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
83 p = "\n", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
84 case 'r': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
85 p = "\r", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
86 case 't': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
87 p = "\t", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
88 case 'x': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
89 if(str[2]) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
90 char num[3] = { str[2], str[3], 0 }; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
91 char* end = num; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
92 num_val = strtol(num,&end,16); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
93 sl = end-num; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
94 l = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
95 p = &num_val; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
96 } else |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
97 l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
98 break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
99 default: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
100 p = str+1, l = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
101 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
102 str+=1+sl; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
103 } else if(lvl > 0 && str[0] == ')') { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
104 if(skip && lvl <= skip_lvl) skip = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
105 lvl--, str++, l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
106 } else if(str[0] == '$' && str[1] == '{' && (e = strchr(str+2,'}'))) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
107 int pl = e-str-2; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
108 char pname[pl+1]; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
109 m_option_t* prop; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
110 memcpy(pname,str+2,pl); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
111 pname[pl] = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
112 if((prop = m_option_list_find(prop_list,pname)) && |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
113 (p = m_property_print(prop))) |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
114 l = strlen(p), fr = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
115 else |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
116 l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
117 str = e+1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
118 } else if(str[0] == '?' && str[1] == '(' && (e = strchr(str+2,':'))) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
119 int pl = e-str-2; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
120 char pname[pl+1]; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
121 m_option_t* prop; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
122 lvl++; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
123 if(!skip) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
124 memcpy(pname,str+2,pl); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
125 pname[pl] = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
126 if(!(prop = m_option_list_find(prop_list,pname)) || |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
127 m_property_do(prop,M_PROPERTY_GET,NULL) < 0) |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
128 skip = 1, skip_lvl = lvl; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
129 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
130 str = e+1, l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
131 } else |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
132 p = str, l = 1, str++; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
133 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
134 if(skip || l <= 0) continue; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
135 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
136 if(pos+l+1 > size) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
137 size = pos+l+512; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
138 ret = realloc(ret,size); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
139 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
140 memcpy(ret+pos,p,l); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
141 pos += l; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
142 if(fr) free(p), fr = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
143 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
144 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
145 ret[pos] = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
146 return ret; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
147 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
148 |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
149 void m_properties_print_help_list(m_option_t* list) { |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
150 char min[50],max[50]; |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
151 int i,count = 0; |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
152 |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
153 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_PropertyListHeader); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
154 for(i = 0 ; list[i].name ; i++) { |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
155 m_option_t* opt = &list[i]; |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
156 if(opt->flags & M_OPT_MIN) |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
157 sprintf(min,"%-8.0f",opt->min); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
158 else |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
159 strcpy(min,"No"); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
160 if(opt->flags & M_OPT_MAX) |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
161 sprintf(max,"%-8.0f",opt->max); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
162 else |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
163 strcpy(max,"No"); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
164 mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-20.20s %-15.15s %-10.10s %-10.10s\n", |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
165 opt->name, |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
166 opt->type->name, |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
167 min, |
17927 | 168 max); |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
169 count++; |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
170 } |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
171 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_TotalProperties, count); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
172 } |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
173 |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
174 // Some generic property implementations |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
175 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
176 int m_property_int_ro(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
177 void* arg,int var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
178 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
179 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
180 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
181 *(int*)arg = var; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
182 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
183 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
184 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
185 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
186 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
187 int m_property_int_range(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
188 void* arg,int* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
189 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
190 case M_PROPERTY_SET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
191 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
192 M_PROPERTY_CLAMP(prop,*(int*)arg); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
193 *var = *(int*)arg; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
194 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
195 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
196 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
197 *var += (arg ? *(int*)arg : 1) * |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
198 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
199 M_PROPERTY_CLAMP(prop,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
200 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
201 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
202 return m_property_int_ro(prop,action,arg,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
203 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
204 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
205 int m_property_choice(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
206 void* arg,int* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
207 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
208 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
209 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
210 *var += action == M_PROPERTY_STEP_UP ? 1 : prop->max; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
211 *var %= (int)prop->max+1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
212 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
213 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
214 return m_property_int_range(prop,action,arg,var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
215 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
216 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
217 int m_property_flag(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
218 void* arg,int* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
219 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
220 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
221 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
222 *var = *var == prop->min ? prop->max : prop->min; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
223 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
224 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
225 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
226 *(char**)arg = strdup((*var > prop->min) ? MSGTR_Enabled : MSGTR_Disabled); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
227 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
228 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
229 return m_property_int_range(prop,action,arg,var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
230 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
231 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
232 int m_property_float_ro(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
233 void* arg,float var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
234 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
235 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
236 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
237 *(float*)arg = var; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
238 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
239 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
240 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
241 *(char**)arg = malloc(20); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
242 sprintf(*(char**)arg,"%.2f",var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
243 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
244 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
245 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
246 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
247 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
248 int m_property_float_range(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
249 void* arg,float* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
250 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
251 case M_PROPERTY_SET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
252 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
253 M_PROPERTY_CLAMP(prop,*(float*)arg); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
254 *var = *(float*)arg; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
255 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
256 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
257 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
258 *var += (arg ? *(float*)arg : 0.1) * |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
259 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
260 M_PROPERTY_CLAMP(prop,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
261 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
262 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
263 return m_property_float_ro(prop,action,arg,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
264 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
265 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
266 int m_property_delay(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
267 void* arg,float* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
268 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
269 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
270 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
271 *(char**)arg = malloc(20); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
272 sprintf(*(char**)arg,"%d ms",ROUND((*var)*1000)); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
273 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
274 default: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
275 return m_property_float_range(prop,action,arg,var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
276 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
277 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
278 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
279 int m_property_double_ro(m_option_t* prop,int action, |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
280 void* arg,double var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
281 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
282 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
283 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
284 *(double*)arg = var; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
285 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
286 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
287 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
288 *(char**)arg = malloc(20); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
289 sprintf(*(char**)arg,"%.2f",var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
290 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
291 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
292 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
293 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
294 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
295 int m_property_string_ro(m_option_t* prop,int action,void* arg,char* str) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
296 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
297 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
298 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
299 *(char**)arg = str; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
300 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
301 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
302 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
303 *(char**)arg = str ? strdup(str) : NULL; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
304 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
305 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
306 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
307 } |