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