handle_config_setting
source
parseconf.c
line
212 - 311
function
212 static void
213 handle_config_setting(struct mystr* p_setting_str, struct mystr* p_value_str,
214 int errs_fatal)
215 {
216 /* Is it a string setting? */
217 {
218 const struct parseconf_str_setting* p_str_setting = parseconf_str_array;
219 while (p_str_setting->p_setting_name != 0)
220 {
221 if (str_equal_text(p_setting_str, p_str_setting->p_setting_name))
222 {
223 /* Got it */
224 const char** p_curr_setting = p_str_setting->p_variable;
225 if (*p_curr_setting)
226 {
227 vsf_sysutil_free((char*)*p_curr_setting);
228 }
229 if (str_isempty(p_value_str))
230 {
231 *p_curr_setting = 0;
232 }
233 else
234 {
235 *p_curr_setting = str_strdup(p_value_str);
236 }
237 return;
238 }
239 p_str_setting++;
240 }
241 }
242 if (str_isempty(p_value_str))
243 {
244 if (errs_fatal)
245 {
246 die2("missing value in config file for: ", str_getbuf(p_setting_str));
247 }
248 else
249 {
250 return;
251 }
252 }
253 /* Is it a boolean value? */
254 {
255 const struct parseconf_bool_setting* p_bool_setting = parseconf_bool_array;
256 while (p_bool_setting->p_setting_name != 0)
257 {
258 if (str_equal_text(p_setting_str, p_bool_setting->p_setting_name))
259 {
260 /* Got it */
261 str_upper(p_value_str);
262 if (str_equal_text(p_value_str, "YES") ||
263 str_equal_text(p_value_str, "TRUE") ||
264 str_equal_text(p_value_str, "1"))
265 {
266 *(p_bool_setting->p_variable) = 1;
267 }
268 else if (str_equal_text(p_value_str, "NO") ||
269 str_equal_text(p_value_str, "FALSE") ||
270 str_equal_text(p_value_str, "0"))
271 {
272 *(p_bool_setting->p_variable) = 0;
273 }
274 else if (errs_fatal)
275 {
276 die2("bad bool value in config file for: ",
277 str_getbuf(p_setting_str));
278 }
279 return;
280 }
281 p_bool_setting++;
282 }
283 }
284 /* Is it an unsigned integer setting? */
285 {
286 const struct parseconf_uint_setting* p_uint_setting = parseconf_uint_array;
287 while (p_uint_setting->p_setting_name != 0)
288 {
289 if (str_equal_text(p_setting_str, p_uint_setting->p_setting_name))
290 {
291 /* Got it */
292 /* If the value starts with 0, assume it's an octal value */
293 if (!str_isempty(p_value_str) &&
294 str_get_char_at(p_value_str, 0) == '0')
295 {
296 *(p_uint_setting->p_variable) = str_octal_to_uint(p_value_str);
297 }
298 else
299 {
300 *(p_uint_setting->p_variable) = str_atoi(p_value_str);
301 }
302 return;
303 }
304 p_uint_setting++;
305 }
306 }
307 if (errs_fatal)
308 {
309 die2("unrecognised variable in config file: ", str_getbuf(p_setting_str));
310 }
311 }
最終更新:2009年01月31日 22:32