18 static rcvar_t
*rcvars
;
26 void rc_export(rcvar_t
*v
)
28 const rcvar_t end
= RCV_END
;
32 rcvars
= realloc(rcvars
, sizeof (rcvar_t
) * (nvars
+1));
34 die("out of memory adding rcvar %s\n", v
->name
);
39 void rc_exportvars(rcvar_t
*vars
)
47 int rc_findvar(char *name
)
50 if (!rcvars
) return -1;
51 for (i
= 0; rcvars
[i
].name
; i
++)
52 if (!strcmp(rcvars
[i
].name
, name
))
60 int my_atoi(const char *s
)
66 if (*s
== 'x' || *s
== 'X')
72 a
= (a
<<4) + *s
- '0';
73 else if (strchr("ABCDEF", *s
))
74 a
= (a
<<4) + *s
- 'A' + 10;
75 else if (strchr("abcdef", *s
))
76 a
= (a
<<4) + *s
- 'a' + 10;
84 if (strchr("01234567", *s
))
85 a
= (a
<<3) + *s
- '0';
97 a
= (a
*10) + *s
- '0';
105 a
= (a
*10) + *s
- '0';
113 int rc_setvar_n(int i
, int c
, char **v
)
119 switch (rcvars
[i
].type
)
122 if (c
< 1) return -1;
123 n
= (int *)rcvars
[i
].mem
;
127 if (c
< 1) return -1;
128 s
= (char **)rcvars
[i
].mem
;
132 die("out of memory setting rcvar %s\n", rcvars
[i
].name
);
135 if (c
> rcvars
[i
].len
)
137 for (j
= 0; j
< c
; j
++)
138 ((int *)rcvars
[i
].mem
)[j
] = my_atoi(v
[j
]);
141 if (c
< 1 || atoi(v
[0]) || strchr("yYtT", v
[0][0]))
142 *(int *)rcvars
[i
].mem
= 1;
143 else if (strchr("0nNfF", v
[0][0]))
144 *(int *)rcvars
[i
].mem
= 0;
153 int rc_setvar(char *name
, int c
, char **v
)
157 i
= rc_findvar(name
);
160 return rc_setvar_n(i
, c
, v
);
164 void *rc_getmem_n(int i
)
166 return rcvars
[i
].mem
;
170 void *rc_getmem(char *name
)
173 i
= rc_findvar(name
);
174 if (i
< 0) return NULL
;
175 return rcvars
[i
].mem
;
178 int rc_getint_n(int i
)
181 switch (rcvars
[i
].type
)
185 return *(int *)rcvars
[i
].mem
;
190 int *rc_getvec_n(int i
)
192 if (i
< 0) return NULL
;
193 switch (rcvars
[i
].type
)
198 return (int *)rcvars
[i
].mem
;
203 char *rc_getstr_n(int i
)
206 switch (rcvars
[i
].type
)
209 return *(char **)rcvars
[i
].mem
;
214 int rc_getint(char *name
)
216 return rc_getint_n(rc_findvar(name
));
219 int *rc_getvec(char *name
)
221 return rc_getvec_n(rc_findvar(name
));
224 char *rc_getstr(char *name
)
226 return rc_getstr_n(rc_findvar(name
));