annotate m_property.c @ 17911:52f95509cd05

Add the new property API and implement a couple properties. Move the volume and mute command to the command to property bridge.
author albeu
date Wed, 22 Mar 2006 00:19:02 +0000
parents
children f9cb6fc1608a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
12 #include "help_mp.h"
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
13
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
14 #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
15
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
16 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
17 if(!prop) return M_PROPERTY_UNKNOWN;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
18 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
19 }
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 char* m_property_print(m_option_t* prop) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
23 m_property_ctrl_f ctrl;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
24 void* val;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
25 char* ret;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
26
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
27 if(!prop) return NULL;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
28
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
29 ctrl = prop->p;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
30 // 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
31 if(ctrl(prop,M_PROPERTY_PRINT,&ret) >= 0)
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
32 return ret;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
33 // fallback on the default print for this type
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
34 val = calloc(1,prop->type->size);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
35 if(ctrl(prop,M_PROPERTY_GET,val) <= 0) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
36 free(val);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
37 return NULL;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
38 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
39 ret = m_option_print(prop,val);
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 ret == (char*)-1 ? NULL : ret;
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
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
44 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
45 m_property_ctrl_f ctrl;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
46 void* val;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
47 int r;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
48
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
49 if(!prop) return M_PROPERTY_UNKNOWN;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
50
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
51 ctrl = prop->p;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
52 // try the property own parsing func
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
53 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
54 return r;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
55 // fallback on the default
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
56 val = calloc(1,prop->type->size);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
57 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
58 free(val);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
59 return r;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
60 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
61 r = ctrl(prop,M_PROPERTY_SET,val);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
62 m_option_free(prop,val);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
63 free(val);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
64 return r;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
65 }
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 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
68 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
69 char *p = NULL,*e,*ret = malloc(size), num_val;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
70 int skip = 0, lvl = 0, skip_lvl = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
71
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
72 while(str[0]) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
73 if(str[0] == '\\') {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
74 int sl = 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
75 switch(str[1]) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
76 case 'e':
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
77 p = "\x1b", l = 1; break;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
78 case 'n':
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
79 p = "\n", l = 1; break;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
80 case 'r':
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
81 p = "\r", l = 1; break;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
82 case 't':
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
83 p = "\t", l = 1; break;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
84 case 'x':
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
85 if(str[2]) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
86 char num[3] = { str[2], str[3], 0 };
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
87 char* end = num;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
88 num_val = strtol(num,&end,16);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
89 sl = end-num;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
90 l = 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
91 p = &num_val;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
92 } else
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
93 l = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
94 break;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
95 default:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
96 p = str+1, l = 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
97 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
98 str+=1+sl;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
99 } else if(lvl > 0 && str[0] == ')') {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
100 if(skip && lvl <= skip_lvl) skip = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
101 lvl--, str++, l = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
102 } 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
103 int pl = e-str-2;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
104 char pname[pl+1];
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
105 m_option_t* prop;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
106 memcpy(pname,str+2,pl);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
107 pname[pl] = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
108 if((prop = m_option_list_find(prop_list,pname)) &&
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
109 (p = m_property_print(prop)))
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
110 l = strlen(p), fr = 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
111 else
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
112 l = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
113 str = e+1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
114 } 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
115 int pl = e-str-2;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
116 char pname[pl+1];
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
117 m_option_t* prop;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
118 lvl++;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
119 if(!skip) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
120 memcpy(pname,str+2,pl);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
121 pname[pl] = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
122 if(!(prop = m_option_list_find(prop_list,pname)) ||
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
123 m_property_do(prop,M_PROPERTY_GET,NULL) < 0)
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
124 skip = 1, skip_lvl = lvl;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
125 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
126 str = e+1, l = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
127 } else
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
128 p = str, l = 1, str++;
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 if(skip || l <= 0) continue;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
131
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
132 if(pos+l+1 > size) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
133 size = pos+l+512;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
134 ret = realloc(ret,size);
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 memcpy(ret+pos,p,l);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
137 pos += l;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
138 if(fr) free(p), fr = 0;
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
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
141 ret[pos] = 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
142 return ret;
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 // Some generic property implementations
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
146
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
147 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
148 void* arg,int var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
149 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
150 case M_PROPERTY_GET:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
151 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
152 *(int*)arg = var;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
153 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
154 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
155 return M_PROPERTY_NOT_IMPLEMENTED;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
156 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
157
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
158 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
159 void* arg,int* var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
160 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
161 case M_PROPERTY_SET:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
162 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
163 M_PROPERTY_CLAMP(prop,*(int*)arg);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
164 *var = *(int*)arg;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
165 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
166 case M_PROPERTY_STEP_UP:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
167 case M_PROPERTY_STEP_DOWN:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
168 *var += (arg ? *(int*)arg : 1) *
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
169 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
170 M_PROPERTY_CLAMP(prop,*var);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
171 return 1;
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 return m_property_int_ro(prop,action,arg,*var);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
174 }
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_choice(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_STEP_UP:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
180 case M_PROPERTY_STEP_DOWN:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
181 *var += action == M_PROPERTY_STEP_UP ? 1 : prop->max;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
182 *var %= (int)prop->max+1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
183 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
184 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
185 return m_property_int_range(prop,action,arg,var);
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
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
188 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
189 void* arg,int* var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
190 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
191 case M_PROPERTY_STEP_UP:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
192 case M_PROPERTY_STEP_DOWN:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
193 *var = *var == prop->min ? prop->max : prop->min;
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_PRINT:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
196 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
197 *(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
198 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
199 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
200 return m_property_int_range(prop,action,arg,var);
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
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
203 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
204 void* arg,float var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
205 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
206 case M_PROPERTY_GET:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
207 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
208 *(float*)arg = var;
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 case M_PROPERTY_PRINT:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
211 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
212 *(char**)arg = malloc(20);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
213 sprintf(*(char**)arg,"%.2f",var);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
214 return 1;
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 return M_PROPERTY_NOT_IMPLEMENTED;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
217 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
218
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
219 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
220 void* arg,float* var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
221 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
222 case M_PROPERTY_SET:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
223 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
224 M_PROPERTY_CLAMP(prop,*(float*)arg);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
225 *var = *(float*)arg;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
226 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
227 case M_PROPERTY_STEP_UP:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
228 case M_PROPERTY_STEP_DOWN:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
229 *var += (arg ? *(float*)arg : 0.1) *
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
230 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
231 M_PROPERTY_CLAMP(prop,*var);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
232 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
233 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
234 return m_property_float_ro(prop,action,arg,*var);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
235 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
236
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
237 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
238 void* arg,float* var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
239 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
240 case M_PROPERTY_PRINT:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
241 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
242 *(char**)arg = malloc(20);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
243 sprintf(*(char**)arg,"%d ms",ROUND((*var)*1000));
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
244 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
245 default:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
246 return m_property_float_range(prop,action,arg,var);
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 }
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
249
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
250 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
251 void* arg,double var) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
252 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
253 case M_PROPERTY_GET:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
254 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
255 *(double*)arg = var;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
256 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
257 case M_PROPERTY_PRINT:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
258 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
259 *(char**)arg = malloc(20);
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
260 sprintf(*(char**)arg,"%.2f",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_NOT_IMPLEMENTED;
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_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
267 switch(action) {
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
268 case M_PROPERTY_GET:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
269 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
270 *(char**)arg = str;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
271 return 1;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
272 case M_PROPERTY_PRINT:
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
273 if(!arg) return 0;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
274 *(char**)arg = str ? strdup(str) : NULL;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
275 return 1;
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 return M_PROPERTY_NOT_IMPLEMENTED;
52f95509cd05 Add the new property API and implement a couple properties.
albeu
parents:
diff changeset
278 }