diff options
Diffstat (limited to 'apps/plugins/rockboy/rcvars.c')
-rw-r--r-- | apps/plugins/rockboy/rcvars.c | 211 |
1 files changed, 0 insertions, 211 deletions
diff --git a/apps/plugins/rockboy/rcvars.c b/apps/plugins/rockboy/rcvars.c deleted file mode 100644 index a47794aa6f..0000000000 --- a/apps/plugins/rockboy/rcvars.c +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | #include "rockmacros.h" | ||
2 | |||
3 | #include "defs.h" | ||
4 | #include "rc.h" | ||
5 | |||
6 | static rcvar_t rcvars[150]; | ||
7 | |||
8 | static int nvars; | ||
9 | |||
10 | void rc_export(rcvar_t *v) | ||
11 | { | ||
12 | const rcvar_t end = RCV_END; | ||
13 | |||
14 | if (!v) return; | ||
15 | nvars++; | ||
16 | // rcvars = realloc(rcvars, sizeof (rcvar_t) * (nvars+1)); | ||
17 | // if (!rcvars) | ||
18 | // die("out of memory adding rcvar %s\n", v->name); | ||
19 | rcvars[nvars-1] = *v; | ||
20 | rcvars[nvars] = end; | ||
21 | } | ||
22 | |||
23 | void rc_exportvars(rcvar_t *vars) | ||
24 | { | ||
25 | while(vars->type) | ||
26 | rc_export(vars++); | ||
27 | } | ||
28 | |||
29 | |||
30 | |||
31 | int rc_findvar(char *name) | ||
32 | { | ||
33 | int i; | ||
34 | if (!rcvars) return -1; | ||
35 | for (i = 0; rcvars[i].name; i++) | ||
36 | if (!strcmp(rcvars[i].name, name)) | ||
37 | break; | ||
38 | if (!rcvars[i].name) | ||
39 | return -1; | ||
40 | return i; | ||
41 | } | ||
42 | |||
43 | |||
44 | int my_atoi(const char *s) | ||
45 | { | ||
46 | int a = 0; | ||
47 | if (*s == '0') | ||
48 | { | ||
49 | s++; | ||
50 | if (*s == 'x' || *s == 'X') | ||
51 | { | ||
52 | s++; | ||
53 | while (*s) | ||
54 | { | ||
55 | if (isdigit(*s)) | ||
56 | a = (a<<4) + *s - '0'; | ||
57 | else if (strchr("ABCDEF", *s)) | ||
58 | a = (a<<4) + *s - 'A' + 10; | ||
59 | else if (strchr("abcdef", *s)) | ||
60 | a = (a<<4) + *s - 'a' + 10; | ||
61 | else return a; | ||
62 | s++; | ||
63 | } | ||
64 | return a; | ||
65 | } | ||
66 | while (*s) | ||
67 | { | ||
68 | if (strchr("01234567", *s)) | ||
69 | a = (a<<3) + *s - '0'; | ||
70 | else return a; | ||
71 | s++; | ||
72 | } | ||
73 | return a; | ||
74 | } | ||
75 | if (*s == '-') | ||
76 | { | ||
77 | s++; | ||
78 | for (;;) | ||
79 | { | ||
80 | if (isdigit(*s)) | ||
81 | a = (a*10) + *s - '0'; | ||
82 | else return -a; | ||
83 | s++; | ||
84 | } | ||
85 | } | ||
86 | while (*s) | ||
87 | { | ||
88 | if (isdigit(*s)) | ||
89 | a = (a*10) + *s - '0'; | ||
90 | else return a; | ||
91 | s++; | ||
92 | } | ||
93 | return a; | ||
94 | } | ||
95 | |||
96 | |||
97 | int rc_setvar_n(int i, int c, char **v) | ||
98 | { | ||
99 | int j; | ||
100 | int *n; | ||
101 | char **s; | ||
102 | |||
103 | switch (rcvars[i].type) | ||
104 | { | ||
105 | case rcv_int: | ||
106 | if (c < 1) return -1; | ||
107 | n = (int *)rcvars[i].mem; | ||
108 | *n = my_atoi(v[0]); | ||
109 | return 0; | ||
110 | case rcv_string: | ||
111 | if (c < 1) return -1; | ||
112 | s = (char **)rcvars[i].mem; | ||
113 | // if (*s) free(*s); | ||
114 | strcpy(*s,v[0]); | ||
115 | if (!*s) | ||
116 | die("out of memory setting rcvar %s\n", rcvars[i].name); | ||
117 | return 0; | ||
118 | case rcv_vector: | ||
119 | if (c > rcvars[i].len) | ||
120 | c = rcvars[i].len; | ||
121 | for (j = 0; j < c ; j++) | ||
122 | ((int *)rcvars[i].mem)[j] = my_atoi(v[j]); | ||
123 | return 0; | ||
124 | case rcv_bool: | ||
125 | if (c < 1 || atoi(v[0]) || strchr("yYtT", v[0][0])) | ||
126 | *(int *)rcvars[i].mem = 1; | ||
127 | else if (strchr("0nNfF", v[0][0])) | ||
128 | *(int *)rcvars[i].mem = 0; | ||
129 | else | ||
130 | return -1; | ||
131 | return 0; | ||
132 | } | ||
133 | return -1; | ||
134 | } | ||
135 | |||
136 | |||
137 | int rc_setvar(char *name, int c, char **v) | ||
138 | { | ||
139 | int i; | ||
140 | |||
141 | i = rc_findvar(name); | ||
142 | if (i < 0) return i; | ||
143 | |||
144 | return rc_setvar_n(i, c, v); | ||
145 | } | ||
146 | |||
147 | |||
148 | void *rc_getmem_n(int i) | ||
149 | { | ||
150 | return rcvars[i].mem; | ||
151 | } | ||
152 | |||
153 | |||
154 | void *rc_getmem(char *name) | ||
155 | { | ||
156 | int i; | ||
157 | i = rc_findvar(name); | ||
158 | if (i < 0) return NULL; | ||
159 | return rcvars[i].mem; | ||
160 | } | ||
161 | |||
162 | int rc_getint_n(int i) | ||
163 | { | ||
164 | if (i < 0) return 0; | ||
165 | switch (rcvars[i].type) | ||
166 | { | ||
167 | case rcv_int: | ||
168 | case rcv_bool: | ||
169 | return *(int *)rcvars[i].mem; | ||
170 | } | ||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | int *rc_getvec_n(int i) | ||
175 | { | ||
176 | if (i < 0) return NULL; | ||
177 | switch (rcvars[i].type) | ||
178 | { | ||
179 | case rcv_int: | ||
180 | case rcv_bool: | ||
181 | case rcv_vector: | ||
182 | return (int *)rcvars[i].mem; | ||
183 | } | ||
184 | return NULL; | ||
185 | } | ||
186 | |||
187 | char *rc_getstr_n(int i) | ||
188 | { | ||
189 | if (i < 0) return 0; | ||
190 | switch (rcvars[i].type) | ||
191 | { | ||
192 | case rcv_string: | ||
193 | return *(char **)rcvars[i].mem; | ||
194 | } | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | int rc_getint(char *name) | ||
199 | { | ||
200 | return rc_getint_n(rc_findvar(name)); | ||
201 | } | ||
202 | |||
203 | int *rc_getvec(char *name) | ||
204 | { | ||
205 | return rc_getvec_n(rc_findvar(name)); | ||
206 | } | ||
207 | |||
208 | char *rc_getstr(char *name) | ||
209 | { | ||
210 | return rc_getstr_n(rc_findvar(name)); | ||
211 | } | ||