summaryrefslogtreecommitdiffhomepage
path: root/ir/libcore
diff options
context:
space:
mode:
authorChristoph Mallon <mallon@cs.uni-saarland.de>2015-07-13 21:00:42 +0200
committerChristoph Mallon <mallon@cs.uni-saarland.de>2015-07-14 07:37:45 +0200
commit932ae2dc3964d611ba423a04b96b3a5690e8397e (patch)
tree0ee0be63f5b17b3513572536bc780ed68d8af8b7 /ir/libcore
parentf3272823b8e6e93bf3a7b5b04b1d98e299b79357 (diff)
Remove the unnecessary parameter 'type' from option callbacks.
Diffstat (limited to 'ir/libcore')
-rw-r--r--ir/libcore/lc_opts.c79
-rw-r--r--ir/libcore/lc_opts.h18
-rw-r--r--ir/libcore/lc_opts_enum.c3
3 files changed, 55 insertions, 45 deletions
diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c
index ddc917a..407d475 100644
--- a/ir/libcore/lc_opts.c
+++ b/ir/libcore/lc_opts.c
@@ -254,46 +254,53 @@ static char *strtolower(char *buf, size_t n, const char *str)
return buf;
}
-bool lc_opt_std_cb(lc_opt_type_t type, void *data, size_t length, ...)
+bool lc_opt_bit_cb(void *data, size_t length, ...)
{
va_list args;
va_start(args, length);
+ bool val = va_arg(args, int);
+ if (val)
+ *(unsigned*)data |= length;
+ else
+ *(unsigned*)data &= ~length;
+ va_end(args);
+ return true;
+}
- bool res = false;
- if (data) {
- res = true;
- switch (type) {
- case lc_opt_type_bit: {
- bool val = va_arg(args, int);
- if (val)
- *(unsigned*)data |= length;
- else
- *(unsigned*)data &= ~length;
- break;
- }
-
- case lc_opt_type_boolean:
- *((bool*) data) = va_arg(args, int);
- break;
-
- case lc_opt_type_string:
- strncpy((char*)data, va_arg(args, const char *), length);
- break;
+bool lc_opt_bool_cb(void *data, size_t length, ...)
+{
+ va_list args;
+ va_start(args, length);
+ *(bool*)data = va_arg(args, int);
+ va_end(args);
+ return true;
+}
- case lc_opt_type_int:
- *((int *) data) = va_arg(args, int);
- break;
+bool lc_opt_double_cb(void *data, size_t length, ...)
+{
+ va_list args;
+ va_start(args, length);
+ *(double*)data = va_arg(args, double);
+ va_end(args);
+ return true;
+}
- case lc_opt_type_double:
- *((double *) data) = va_arg(args, double);
- break;
- default:
- res = false;
- }
- }
+bool lc_opt_int_cb(void *data, size_t length, ...)
+{
+ va_list args;
+ va_start(args, length);
+ *(int*)data = va_arg(args, int);
+ va_end(args);
+ return true;
+}
+bool lc_opt_string_cb(void *data, size_t length, ...)
+{
+ va_list args;
+ va_start(args, length);
+ strncpy((char*)data, va_arg(args, const char*), length);
va_end(args);
- return res;
+ return true;
}
int lc_opt_bit_dump(char *const buf, size_t const n, void *const data)
@@ -365,14 +372,14 @@ static bool lc_opt_occurs(lc_opt_entry_t *opt, const char *value)
case lc_opt_type_int: {
int val;
if (sscanf(value, "%i", &val))
- fine = s->cb(s->type, s->value, s->length, val);
+ fine = s->cb(s->value, s->length, val);
break;
}
case lc_opt_type_double: {
double val;
if (sscanf(value, "%lf", &val))
- fine = s->cb(s->type, s->value, s->length, val);
+ fine = s->cb(s->value, s->length, val);
break;
}
@@ -390,14 +397,14 @@ static bool lc_opt_occurs(lc_opt_entry_t *opt, const char *value)
}
if (fine)
- fine = s->cb(s->type, s->value, s->length, val);
+ fine = s->cb(s->value, s->length, val);
break;
}
case lc_opt_type_string:
case lc_opt_type_enum:
- fine = s->cb(s->type, s->value, s->length, value);
+ fine = s->cb(s->value, s->length, value);
break;
case lc_opt_type_invalid:
abort();
diff --git a/ir/libcore/lc_opts.h b/ir/libcore/lc_opts.h
index 69678c6..1c1f659 100644
--- a/ir/libcore/lc_opts.h
+++ b/ir/libcore/lc_opts.h
@@ -32,7 +32,7 @@ typedef enum {
typedef struct lc_opt_entry_t lc_opt_entry_t;
-typedef bool (lc_opt_callback_t)(lc_opt_type_t type, void *data, size_t length, ...);
+typedef bool (lc_opt_callback_t)(void *data, size_t length, ...);
typedef int (lc_opt_dump_t)(char *buf, size_t n, void *data);
@@ -65,20 +65,20 @@ typedef struct {
{ name, desc, type, 1 ? (value) : (val_type*)0 /* Produces a warning, if var has wrong type. */, len, cb, dump, dump_vals }
#define LC_OPT_ENT_INT(name, desc, addr) \
- _LC_OPT_ENT(name, desc, lc_opt_type_int, int, addr, 0, lc_opt_std_cb, lc_opt_int_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_int, int, addr, 0, lc_opt_int_cb, lc_opt_int_dump, NULL)
#define LC_OPT_ENT_DBL(name, desc, addr) \
- _LC_OPT_ENT(name, desc, lc_opt_type_double, double, addr, 0, lc_opt_std_cb, lc_opt_double_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_double, double, addr, 0, lc_opt_double_cb, lc_opt_double_dump, NULL)
#define LC_OPT_ENT_BIT(name, desc, addr, mask) \
- _LC_OPT_ENT(name, desc, lc_opt_type_bit, unsigned, addr, mask, lc_opt_std_cb, lc_opt_bit_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_bit, unsigned, addr, mask, lc_opt_bit_cb, lc_opt_bit_dump, NULL)
#define LC_OPT_ENT_BOOL(name, desc, addr) \
- _LC_OPT_ENT(name, desc, lc_opt_type_boolean, bool, addr, 0, lc_opt_std_cb, lc_opt_bool_dump, lc_opt_bool_dump_vals)
+ _LC_OPT_ENT(name, desc, lc_opt_type_boolean, bool, addr, 0, lc_opt_bool_cb, lc_opt_bool_dump, lc_opt_bool_dump_vals)
typedef char lc_opt_str_t[];
#define LC_OPT_ENT_STR(name, desc, buf) \
- _LC_OPT_ENT(name, desc, lc_opt_type_string, lc_opt_str_t, buf, sizeof(*buf), lc_opt_std_cb, lc_opt_string_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_string, lc_opt_str_t, buf, sizeof(*buf), lc_opt_string_cb, lc_opt_string_dump, NULL)
#define LC_OPT_LAST \
_LC_OPT_ENT(NULL, NULL, lc_opt_type_invalid, void, NULL, 0, NULL, NULL, NULL)
@@ -122,7 +122,11 @@ lc_opt_entry_t *lc_opt_add_opt(lc_opt_entry_t *grp,
lc_opt_dump_t *dump,
lc_opt_dump_vals_t *dump_vals);
-lc_opt_callback_t lc_opt_std_cb;
+lc_opt_callback_t lc_opt_bit_cb;
+lc_opt_callback_t lc_opt_bool_cb;
+lc_opt_callback_t lc_opt_double_cb;
+lc_opt_callback_t lc_opt_int_cb;
+lc_opt_callback_t lc_opt_string_cb;
lc_opt_dump_t lc_opt_bit_dump;
lc_opt_dump_t lc_opt_bool_dump;
diff --git a/ir/libcore/lc_opts_enum.c b/ir/libcore/lc_opts_enum.c
index e1415b0..6e87027 100644
--- a/ir/libcore/lc_opts_enum.c
+++ b/ir/libcore/lc_opts_enum.c
@@ -14,7 +14,7 @@
static const char *delim = " \t|,";
#define DECL_CB(N, op) \
-bool lc_opt_enum_ ## N ## _cb(lc_opt_type_t type, void *data, size_t len, ...) \
+bool lc_opt_enum_ ## N ## _cb(void *data, size_t len, ...) \
{ \
lc_opt_enum_ ## N ## _var_t *var = (lc_opt_enum_ ## N ## _var_t*)data; \
const lc_opt_enum_ ## N ## _items_t *items = var->items; \
@@ -26,7 +26,6 @@ bool lc_opt_enum_ ## N ## _cb(lc_opt_type_t type, void *data, size_t len, ...) \
bool res = false; \
\
(void) len; \
- (void) type; \
va_start(args, len); \
arg = va_arg(args, const char *); \
va_end(args); \