If a setter is available for an option, we would only call the setter
and not make any changes to the structure field itself. It turns out
that the first thing each of the setters does is to set the structure
field to the given value, so we might as well do that directly.
We set the value before calling the setter such that the setter can
still override the value.
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
if (!has_argument && (!arg[1] || arg[1][0] == '-')) {
unsigned u = decl->u.choice.default_selected;
if (!has_argument && (!arg[1] || arg[1][0] == '-')) {
unsigned u = decl->u.choice.default_selected;
+ *(unsigned *)(((char *)opt) + decl->offset) = u;
if (decl->u.choice.set)
decl->u.choice.set(opt, u);
if (decl->u.choice.set)
decl->u.choice.set(opt, u);
- else
- *(unsigned *)(((char *)opt) + decl->offset) = u;
continue;
u = decl->u.choice.choice[i].value;
continue;
u = decl->u.choice.choice[i].value;
+ *(unsigned *)(((char *)opt) + decl->offset) = u;
if (decl->u.choice.set)
decl->u.choice.set(opt, u);
if (decl->u.choice.set)
decl->u.choice.set(opt, u);
- else
- *(unsigned *)(((char *)opt) + decl->offset) = u;
return has_argument ? 1 : 2;
}
return has_argument ? 1 : 2;
}
char *endptr;
int val = strtol(arg[1], &endptr, 0);
if (*endptr == '\0' && (val == 0 || val == 1)) {
char *endptr;
int val = strtol(arg[1], &endptr, 0);
if (*endptr == '\0' && (val == 0 || val == 1)) {
+ if (decl->offset != (size_t) -1)
+ *p = val;
if (decl->u.b.set)
decl->u.b.set(opt, val);
if (decl->u.b.set)
decl->u.b.set(opt, val);
- else if (decl->offset != (size_t) -1)
- *p = val;
+ if (decl->offset != (size_t) -1)
+ *p = 1;
if (decl->u.b.set)
decl->u.b.set(opt, 1);
if (decl->u.b.set)
decl->u.b.set(opt, 1);
- else if (decl->offset != (size_t) -1)
- *p = 1;
}
if (match_long_name(decl, name, name + strlen(name))) {
}
if (match_long_name(decl, name, name + strlen(name))) {
+ if (decl->offset != (size_t) -1)
+ *p = 0;
if (decl->u.b.set)
decl->u.b.set(opt, 0);
if (decl->u.b.set)
decl->u.b.set(opt, 0);
- else if (decl->offset != (size_t) -1)
- *p = 0;
if (has_argument) {
long l = strtol(val, NULL, 0);
if (has_argument) {
long l = strtol(val, NULL, 0);
if (decl->u.l.set)
decl->u.l.set(opt, l);
if (decl->u.l.set)
decl->u.l.set(opt, l);
return 1;
}
if (arg[1]) {
long l = strtol(arg[1], &endptr, 0);
if (*endptr == '\0') {
return 1;
}
if (arg[1]) {
long l = strtol(arg[1], &endptr, 0);
if (*endptr == '\0') {
if (decl->u.l.set)
decl->u.l.set(opt, l);
if (decl->u.l.set)
decl->u.l.set(opt, l);
return 2;
}
}
if (decl->u.l.default_value != decl->u.l.default_selected) {
return 2;
}
}
if (decl->u.l.default_value != decl->u.l.default_selected) {
+ *p = decl->u.l.default_selected;
if (decl->u.l.set)
decl->u.l.set(opt, decl->u.l.default_selected);
if (decl->u.l.set)
decl->u.l.set(opt, decl->u.l.default_selected);
- else
- *p = decl->u.l.default_selected;