/* called on alias() functions in the config file */ int conf_alias(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv) { if(argc < 2) { cfg_error(cfg, "function '%s' requires 2 arguments", cfg_opt_name(opt)); return -1; } printf("got alias '%s' = '%s'\n", argv[0], argv[1]); return 0; }
/** * Check if the given opt value is non-negative */ static gint cf_validate_num(cfg_t *cfg, cfg_opt_t *opt) { gint value = cfg_opt_getnint(opt, 0); if (value < 0) { cfg_error(cfg, "'%s' in section '%s' must be a non-negative value", cfg_opt_name(opt), cfg_name(cfg)); return -1; } return 0; }
static gint cf_validate_num_zero(cfg_t *cfg, cfg_opt_t *opt) { gint value = cfg_opt_getnint(opt, 0); if (value < 0) { cfg_error(cfg, "'%s' in section '%s' cannot be a negative " "value.", cfg_opt_name(opt), cfg_name(cfg)); return -1; } return 0; }
/* parse values for the auto-create-bookmark option */ int conf_parse_acb(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result) { if(strcmp(value, "yes") == 0) *(int *)result = ACB_YES; else if(strcmp(value, "no") == 0) *(int *)result = ACB_NO; else if(strcmp(value, "ask") == 0) *(int *)result = ACB_ASK; else { cfg_error(cfg, "invalid value for option '%s': %s", cfg_opt_name(opt), value); return -1; } return 0; }
/** * Parse log level values from the config file and set result to a * GLogLevelFlags value */ static gint cf_log_level(cfg_t *cfg, cfg_opt_t *opt, const gchar *value, void *result) { if (!strncmp(value, "none", 4)) *(GLogLevelFlags *)result = G_LOG_LEVEL_ERROR; else if (!strncmp(value, "error", 5)) *(GLogLevelFlags *)result = G_LOG_LEVEL_ERROR; else if (!strncmp(value, "warning", 7)) *(GLogLevelFlags *)result = G_LOG_LEVEL_WARNING; else if (!strncmp(value, "info", 4)) *(GLogLevelFlags *)result = G_LOG_LEVEL_MESSAGE; else if (!strncmp(value, "debug", 5)) *(GLogLevelFlags *)result = G_LOG_LEVEL_DEBUG; else { cfg_error(cfg, "Invalid value for option '%s': '%s'", cfg_opt_name(opt), value); return -1; } return 0; }