summaryrefslogtreecommitdiffhomepage
path: root/ir/libcore
diff options
context:
space:
mode:
authorChristoph Mallon <mallon@cs.uni-saarland.de>2015-07-13 20:25:00 +0200
committerChristoph Mallon <mallon@cs.uni-saarland.de>2015-07-14 07:35:49 +0200
commit01a34c279e122ebeb39130323a8d73e91f34b71e (patch)
tree66e90eab76fe4d5ee984216daa2fafd637fceb65 /ir/libcore
parentb9b382bbe02448f39adbf5f60e33f9d0ccc6a148 (diff)
Remove the unnecessary parameter 'type' from option dumpers.
Diffstat (limited to 'ir/libcore')
-rw-r--r--ir/libcore/lc_opts.c53
-rw-r--r--ir/libcore/lc_opts.h18
-rw-r--r--ir/libcore/lc_opts_enum.c3
3 files changed, 35 insertions, 39 deletions
diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c
index 3f34d95..cc8034f 100644
--- a/ir/libcore/lc_opts.c
+++ b/ir/libcore/lc_opts.c
@@ -299,37 +299,30 @@ bool lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data,
return res;
}
-int lc_opt_std_dump(char *buf, size_t n, lc_opt_type_t type, void *data)
+int lc_opt_bit_dump(char *const buf, size_t const n, void *const data)
{
- int res;
- if (data) {
- switch (type) {
- case lc_opt_type_bit:
- res = snprintf(buf, n, "%x", *((bool*) data));
- break;
- case lc_opt_type_boolean:
- res = snprintf(buf, n, "%s", *((bool*) data) ? "true" : "false");
- break;
- case lc_opt_type_string:
- strncpy(buf, (const char*)data, n);
- res = n;
- break;
- case lc_opt_type_int:
- res = snprintf(buf, n, "%d", *((int *) data));
- break;
- case lc_opt_type_double:
- res = snprintf(buf, n, "%g", *((double *) data));
- break;
- default:
- strncpy(buf, "", n);
- res = 0;
- }
- } else {
- strncpy(buf, "", n);
- res = 0;
- }
+ return snprintf(buf, n, "%x", *(bool*)data);
+}
- return res;
+int lc_opt_bool_dump(char *const buf, size_t const n, void *const data)
+{
+ return snprintf(buf, n, "%s", *(bool*)data ? "true" : "false");
+}
+
+int lc_opt_double_dump(char *const buf, size_t const n, void *const data)
+{
+ return snprintf(buf, n, "%g", *(double*)data);
+}
+
+int lc_opt_int_dump(char *const buf, size_t const n, void *const data)
+{
+ return snprintf(buf, n, "%d", *(int*)data);
+}
+
+int lc_opt_string_dump(char *const buf, size_t const n, void *const data)
+{
+ strncpy(buf, (char const*)data, n);
+ return n;
}
int lc_opt_bool_dump_vals(char *buf, size_t n, void *data)
@@ -427,7 +420,7 @@ static char *lc_opt_value_to_string(char *buf, size_t len, const lc_opt_entry_t
{
const lc_opt_special_t *s = lc_get_opt_special(ent);
if (s->dump)
- s->dump(buf, len, s->type, s->value);
+ s->dump(buf, len, s->value);
else
strncpy(buf, "<n/a>", len);
return buf;
diff --git a/ir/libcore/lc_opts.h b/ir/libcore/lc_opts.h
index 1be99d0..1305f90 100644
--- a/ir/libcore/lc_opts.h
+++ b/ir/libcore/lc_opts.h
@@ -34,7 +34,7 @@ typedef struct lc_opt_entry_t lc_opt_entry_t;
typedef bool (lc_opt_callback_t)(const char *name, lc_opt_type_t type, void *data, size_t length, ...);
-typedef int (lc_opt_dump_t)(char *buf, size_t n, lc_opt_type_t type, void *data);
+typedef int (lc_opt_dump_t)(char *buf, size_t n, void *data);
typedef int (lc_opt_dump_vals_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_std_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_int, int, addr, 0, lc_opt_std_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_std_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_double, double, addr, 0, lc_opt_std_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_std_dump, NULL)
+ _LC_OPT_ENT(name, desc, lc_opt_type_bit, unsigned, addr, mask, lc_opt_std_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_std_dump, lc_opt_bool_dump_vals)
+ _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)
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_std_dump, NULL)
+ _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)
#define LC_OPT_LAST \
_LC_OPT_ENT(NULL, NULL, lc_opt_type_invalid, void, NULL, 0, NULL, NULL, NULL)
@@ -124,7 +124,11 @@ lc_opt_entry_t *lc_opt_add_opt(lc_opt_entry_t *grp,
lc_opt_callback_t lc_opt_std_cb;
-lc_opt_dump_t lc_opt_std_dump;
+lc_opt_dump_t lc_opt_bit_dump;
+lc_opt_dump_t lc_opt_bool_dump;
+lc_opt_dump_t lc_opt_double_dump;
+lc_opt_dump_t lc_opt_int_dump;
+lc_opt_dump_t lc_opt_string_dump;
lc_opt_dump_vals_t lc_opt_bool_dump_vals;
diff --git a/ir/libcore/lc_opts_enum.c b/ir/libcore/lc_opts_enum.c
index 69b7c99..b2c3130 100644
--- a/ir/libcore/lc_opts_enum.c
+++ b/ir/libcore/lc_opts_enum.c
@@ -64,7 +64,7 @@ DECL_CB(const_ptr, =)
DECL_CB(func_ptr, =)
#define DECL_DUMP(T, N, cond) \
-int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, lc_opt_type_t type, void *data) \
+int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, void *data) \
{ \
lc_opt_enum_ ## N ## _var_t *var = (lc_opt_enum_ ## N ## _var_t*)data; \
const lc_opt_enum_ ## N ## _items_t *items = var->items; \
@@ -72,7 +72,6 @@ int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, lc_opt_type_t type, void *da
TYPE(value) = *var->value; \
int i; \
size_t l = strlen(buf); \
- (void) type; \
\
if (l >= n) \
return (int)l; \