aboutsummaryrefslogtreecommitdiff
path: root/lib/optcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/optcache.c')
-rw-r--r--lib/optcache.c76
1 files changed, 36 insertions, 40 deletions
diff --git a/lib/optcache.c b/lib/optcache.c
index a059b29a..15b011b5 100644
--- a/lib/optcache.c
+++ b/lib/optcache.c
@@ -42,6 +42,7 @@ optcache_dup(struct mf_option_cache *tab, size_t size)
for (i = 0; i < size; i++) {
newtab[i] = tab[i];
newtab[i].name = mu_strdup(newtab[i].name);
+ newtab[i].isset = 0;
}
return newtab;
}
@@ -72,7 +73,7 @@ mf_optcache_add(struct mf_option_cache *tab, size_t size, int flags)
}
static struct mf_option_cache *
-find_option(char *name)
+find_option(char const *name)
{
struct cache_list_elt *elt;
@@ -89,14 +90,18 @@ find_option(char *name)
}
int
-mf_optcache_set_option(char *name, char *value)
+mf_optcache_set_option(char const *name, char const *value)
{
+ int rc;
struct mf_option_cache *p = find_option(name);
if (!p) {
errno = ENOENT;
return 1;
}
- return p->handler(name, &p->value, value);
+ rc = p->handler(name, &p->value, value);
+ if (rc == 0)
+ p->isset = 1;
+ return rc;
}
void
@@ -109,79 +114,70 @@ mf_optcache_flush()
struct mf_option_cache *opt;
for (i = 0, opt = elt->opt; i < elt->size; i++, opt++)
- if (opt->value && opt->set)
- opt->set(opt->value);
+ if (opt->isset && opt->set)
+ opt->set(&opt->value);
}
}
int
-mf_option_string(char *opt, void **pval, char *newval)
+mf_option_string(char const *opt, union mf_option_value *val, char const *arg)
{
- if (*pval)
- free(*pval);
- *pval = strdup(newval);
+ free(val->ov_string);
+ val->ov_string = strdup(arg);
return 0;
}
int
-mf_option_boolean(char *opt, void **pval, char *newval)
+mf_option_boolean(char const *opt, union mf_option_value *val, char const *arg)
{
- int val;
-
- if (strcmp (newval, "yes") == 0
- || strcmp (newval, "true") == 0
- || strcmp (newval, "t") == 0)
- val = 1;
- else if (strcmp (newval, "no") == 0
- || strcmp (newval, "false") == 0
- || strcmp (newval, "nil") == 0)
- val = 0;
+ int b;
+
+ if (strcmp (arg, "yes") == 0
+ || strcmp (arg, "true") == 0
+ || strcmp (arg, "t") == 0)
+ b = 1;
+ else if (strcmp (arg, "no") == 0
+ || strcmp (arg, "false") == 0
+ || strcmp (arg, "nil") == 0)
+ b = 0;
else {
char *p;
- val = strtoul(newval, &p, 10);
+ b = strtoul(arg, &p, 10);
if (*p) {
errno = EINVAL;
return 1;
}
}
- *pval = (void*) val;
+ val->ov_bool = b;
return 0;
}
int
-mf_option_time(char *opt, void **pval, char *newval)
+mf_option_timeout(char const *opt, union mf_option_value *val, char const *arg)
{
time_t interval;
const char *endp;
- if (parse_time_interval(newval, &interval, &endp)) {
+
+ if (parse_time_interval(arg, &interval, &endp)) {
mu_error(_("%s: unrecognized time format (near `%s')"),
opt, endp);
return 1;
}
- if (!*pval)
- *pval = mu_alloc(sizeof(time_t));
- *(time_t*) *pval = interval;
+ val->ov_time = interval;
return 0;
}
int
-mf_option_time_t(char *opt, void **pval, char *newval)
+mf_option_size(char const *opt, union mf_option_value *val, char const *arg)
{
- if (!*pval)
- *pval = mu_alloc(sizeof(time_t));
- memcpy(*pval, newval, sizeof(time_t));
- return 0;
-}
-
-int
-mf_option_size_t(char *opt, void **pval, char *newval)
-{
- if (!*pval)
- *pval = mu_alloc(sizeof(size_t));
- memcpy(*pval, newval, sizeof(size_t));
+ char *p;
+ unsigned long n = strtoul(arg, &p, 10);
+ if (*p)
+ return 1;
+ val->ov_size = n;
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.