annotate m_property.c @ 17914:f9cb6fc1608a

Add an option to list the properties: -list-properties
author albeu
date Wed, 22 Mar 2006 16:35:17 +0000
parents 52f95509cd05
children 3787f29f0b20
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"
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,
f9cb6fc1608a Add an option to list the properties: -list-properties
albeu
parents: 17911
diff changeset
165 max,
f9cb6fc1608a Add an option to list the properties: -list-properties
albeu
parents: 17911
diff changeset
166 opt->flags & CONF_GLOBAL ? "Yes" : "No",
f9cb6fc1608a Add an option to list the properties: -list-properties
albeu
parents: 17911
diff changeset
167 opt->flags & CONF_NOCMD ? "No" : "Yes",
f9cb6fc1608a Add an option to list the properties: -list-properties
albeu
parents: 17911
diff changeset
168 opt->flags & CONF_NOCFG ? "No" : "Yes");
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 }