summaryrefslogtreecommitdiffhomepage
path: root/ir/libcore
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2013-04-23 09:55:38 +0200
committerMatthias Braun <matze@braunis.de>2013-04-23 14:58:47 +0200
commit415192712bb6d3f5352cc1fb16025b5133b8e1de (patch)
tree1bb324890717d28bc1d2cf515b4a06c4e8d0caaf /ir/libcore
parentc1106f5b3ed1d52cb03f3d03aa1b58d2475028a0 (diff)
libcore: remove unused parts, cleanup, use C99
This especially removes unused complicated error reporting mechanisms
Diffstat (limited to 'ir/libcore')
-rw-r--r--ir/libcore/lc_opts.c530
-rw-r--r--ir/libcore/lc_opts.h77
-rw-r--r--ir/libcore/lc_opts_enum.c6
-rw-r--r--ir/libcore/lc_opts_enum.h4
-rw-r--r--ir/libcore/lc_opts_t.h27
-rw-r--r--ir/libcore/lc_printf.c214
-rw-r--r--ir/libcore/lc_printf.h11
7 files changed, 297 insertions, 572 deletions
diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c
index fc9c162..260ac80 100644
--- a/ir/libcore/lc_opts.c
+++ b/ir/libcore/lc_opts.c
@@ -38,47 +38,13 @@ static void set_name(lc_opt_entry_t *ent, const char *name)
#define entries_equal(e1,e2) entry_matches(e1, (e2)->hash, (e2)->name)
-static lc_opt_err_info_t *set_error(lc_opt_err_info_t *err, int error, const char *arg)
-{
- if (err) {
- err->error = error;
- err->msg = "";
- err->arg = arg;
- }
-
- return err;
-}
-
-int lc_opt_raise_error(const lc_opt_err_info_t *err, lc_opt_error_handler_t *handler,
- const char *fmt, ...)
-{
- va_list args;
- int res = 0;
-
- va_start(args, fmt);
- if (err && lc_opt_is_error(err)) {
- res = 1;
- if (handler) {
- char buf[256];
- vsnprintf(buf, sizeof(buf), fmt, args);
- handler(buf, err);
- }
- }
- va_end(args);
-
- return res;
-}
-
static lc_opt_entry_t *init_entry(lc_opt_entry_t *ent, lc_opt_entry_t *parent,
- const char *name, const char *desc)
+ const char *name, const char *desc)
{
- const char *copied_name;
- const char *copied_desc;
-
obstack_grow0(&obst, name, strlen(name));
- copied_name = (char*)obstack_finish(&obst);
+ const char *copied_name = (char*)obstack_finish(&obst);
obstack_grow0(&obst, desc, strlen(desc));
- copied_desc = (char*)obstack_finish(&obst);
+ const char *copied_desc = (char*)obstack_finish(&obst);
memset(ent, 0, sizeof(*ent));
set_name(ent, copied_name);
@@ -87,19 +53,14 @@ static lc_opt_entry_t *init_entry(lc_opt_entry_t *ent, lc_opt_entry_t *parent,
return ent;
}
-static lc_opt_entry_t *init_grp(lc_opt_entry_t *ent, lc_opt_err_info_t *err)
+static lc_opt_entry_t *init_grp(lc_opt_entry_t *ent)
{
ent->is_grp = 1;
INIT_LIST_HEAD(&ent->v.grp.grps);
INIT_LIST_HEAD(&ent->v.grp.opts);
- set_error(err, lc_opt_err_none, "");
- if (ent->parent) {
- if (ent->parent->is_grp)
- list_add_tail(&ent->list, &lc_get_grp_special(ent->parent)->grps);
- else
- set_error(err, lc_opt_err_grp_expected, ent->parent->name);
- }
+ if (ent->parent && ent->parent->is_grp)
+ list_add_tail(&ent->list, &lc_get_grp_special(ent->parent)->grps);
return ent;
}
@@ -109,13 +70,11 @@ static lc_opt_entry_t *init_opt(lc_opt_entry_t *ent,
void *val, size_t length,
lc_opt_callback_t *cb,
lc_opt_dump_t *dump,
- lc_opt_dump_vals_t *dump_vals,
- lc_opt_err_info_t *err)
+ lc_opt_dump_vals_t *dump_vals)
{
lc_opt_special_t *s = lc_get_opt_special(ent);
ent->is_grp = 0;
- set_error(err, lc_opt_err_none, "");
list_add_tail(&ent->list, &lc_get_grp_special(ent->parent)->opts);
s->type = type;
@@ -139,7 +98,7 @@ lc_opt_entry_t *lc_opt_root_grp(void)
inited = 1;
init_entry(&root_group, NULL, "root", "The root node");
- init_grp(&root_group, NULL);
+ init_grp(&root_group);
}
return &root_group;
@@ -152,22 +111,16 @@ int lc_opt_grp_is_root(const lc_opt_entry_t *ent)
static const char *get_type_name(lc_opt_type_t type)
{
- const char *res;
-
-#define XXX(t) case lc_opt_type_ ## t: res = #t; break
switch (type) {
- XXX(enum);
- XXX(bit);
- XXX(int);
- XXX(double);
- XXX(boolean);
- XXX(string);
- default:
- res = "<none>";
+ case lc_opt_type_enum: return "enum";
+ case lc_opt_type_bit: return "bit";
+ case lc_opt_type_int: return "int";
+ case lc_opt_type_double: return "double";
+ case lc_opt_type_boolean: return "boolean";
+ case lc_opt_type_string: return "string";
+ case lc_opt_type_invalid: break;
}
-#undef XXX
-
- return res;
+ return "<none>";
}
const char *lc_opt_get_type_name(const lc_opt_entry_t *ent)
@@ -177,12 +130,12 @@ const char *lc_opt_get_type_name(const lc_opt_entry_t *ent)
lc_opt_entry_t *lc_opt_get_grp(lc_opt_entry_t *parent, const char *name)
{
- lc_opt_entry_t *ent = lc_opt_find_grp(parent, name, NULL);
+ lc_opt_entry_t *ent = lc_opt_find_grp(parent, name);
if (!ent) {
ent = OALLOC(&obst, lc_opt_entry_t);
init_entry(ent, parent, name, "");
- init_grp(ent, NULL);
+ init_grp(ent);
}
return ent;
@@ -192,77 +145,58 @@ lc_opt_entry_t *lc_opt_add_opt(lc_opt_entry_t *parent,
const char *name, const char *desc,
lc_opt_type_t type, void *value, size_t length,
lc_opt_callback_t *cb, lc_opt_dump_t *dump,
- lc_opt_dump_vals_t *dump_vals,
- lc_opt_err_info_t *err)
+ lc_opt_dump_vals_t *dump_vals)
{
- lc_opt_entry_t *res = NULL;
-
- if (parent->is_grp) {
- lc_opt_entry_t *ent = lc_opt_find_opt(parent, name, NULL);
-
- if (!ent) {
- res = OALLOC(&obst, lc_opt_entry_t);
- init_entry(res, parent, name, desc);
- init_opt(res, type, value, length, cb, dump, dump_vals, err);
- } else
- set_error(err, lc_opt_err_opt_already_there, name);
- } else
- set_error(err, lc_opt_err_grp_expected, name);
+ if (!parent->is_grp)
+ return NULL;
+ lc_opt_entry_t *ent = lc_opt_find_opt(parent, name);
+ if (ent != NULL)
+ return NULL;
+ lc_opt_entry_t *res = OALLOC(&obst, lc_opt_entry_t);
+ init_entry(res, parent, name, desc);
+ init_opt(res, type, value, length, cb, dump, dump_vals);
return res;
}
-static lc_opt_entry_t *lc_opt_find_ent(const struct list_head *head, const char *name,
- int error_to_use, lc_opt_err_info_t *err)
+static lc_opt_entry_t *lc_opt_find_ent(const struct list_head *head,
+ const char *name)
{
- lc_opt_entry_t *found = NULL;
- int error = error_to_use;
unsigned hash = hash_str(name);
-
- if (!list_empty(head)) {
- list_for_each_entry(lc_opt_entry_t, ent, head, list) {
- if (entry_matches(ent, hash, name)) {
- error = lc_opt_err_none;
- found = ent;
- break;
- }
- }
+ list_for_each_entry(lc_opt_entry_t, ent, head, list) {
+ if (entry_matches(ent, hash, name))
+ return ent;
}
-
- set_error(err, error, name);
- return found;
+ return NULL;
}
-lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err)
+lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name)
{
- return grp ? lc_opt_find_ent(&lc_get_grp_special(grp)->grps,
- name, lc_opt_err_grp_not_found, err) : NULL;
+ return grp ? lc_opt_find_ent(&lc_get_grp_special(grp)->grps, name) : NULL;
}
-lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err)
+lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name)
{
- return grp ? lc_opt_find_ent(&lc_get_grp_special(grp)->opts,
- name, lc_opt_err_opt_not_found, err) : NULL;
+ return grp ? lc_opt_find_ent(&lc_get_grp_special(grp)->opts, name) : NULL;
}
static const lc_opt_entry_t *resolve_up_to_last(const lc_opt_entry_t *root,
- const char * const *names, int pos, int n, lc_opt_err_info_t *err)
+ const char *const *names,
+ int pos, int n)
{
- lc_opt_entry_t *ent;
-
if (pos == n)
return root;
- ent = lc_opt_find_grp(root, names[pos], err);
- return ent ? resolve_up_to_last(ent, names, pos + 1, n, err) : NULL;
+ lc_opt_entry_t *ent = lc_opt_find_grp(root, names[pos]);
+ return ent != NULL ? resolve_up_to_last(ent, names, pos + 1, n) : NULL;
}
static const char *path_delim = "/.";
static lc_opt_entry_t *resolve_up_to_last_str_rec(lc_opt_entry_t *from,
- const char *path,
- const char **last_name)
+ const char *path,
+ const char **last_name)
{
lc_opt_entry_t *res = from;
@@ -303,38 +237,38 @@ static lc_opt_entry_t *resolve_up_to_last_str(lc_opt_entry_t *root, const char *
}
lc_opt_entry_t *lc_opt_resolve_grp(const lc_opt_entry_t *root,
- const char * const *names, int n, lc_opt_err_info_t *err)
+ const char * const *names, int n)
{
- const lc_opt_entry_t *grp = resolve_up_to_last(root, names, 0, n - 1, err);
- return lc_opt_find_grp(grp, names[n - 1], err);
+ const lc_opt_entry_t *grp = resolve_up_to_last(root, names, 0, n - 1);
+ return lc_opt_find_grp(grp, names[n - 1]);
}
lc_opt_entry_t *lc_opt_resolve_opt(const lc_opt_entry_t *root,
- const char * const *names, int n, lc_opt_err_info_t *err)
+ const char * const *names, int n)
{
- const lc_opt_entry_t *grp = resolve_up_to_last(root, names, 0, n - 1, err);
- return lc_opt_find_opt(grp, names[n - 1], err);
+ const lc_opt_entry_t *grp = resolve_up_to_last(root, names, 0, n - 1);
+ return lc_opt_find_opt(grp, names[n - 1]);
}
static char *strtolower(char *buf, size_t n, const char *str)
{
- unsigned i;
- for (i = 0; i < n; ++i)
+ for (unsigned i = 0; i < n; ++i)
buf[i] = tolower((unsigned char)str[i]);
return buf;
}
-int lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data, size_t length, ...)
+bool lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data,
+ size_t length, ...)
{
va_list args;
- int res = 0;
- int integer;
+ bool res = false;
+ int integer;
(void) name;
va_start(args, length);
if (data) {
- res = 1;
+ res = true;
switch (type) {
case lc_opt_type_bit:
integer = va_arg(args, int);
@@ -360,7 +294,7 @@ int lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data, size_t lengt
*((double *) data) = va_arg(args, double);
break;
default:
- res = 0;
+ res = false;
}
}
@@ -396,9 +330,7 @@ int lc_opt_std_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, v
strncpy(buf, "", n);
res = 0;
}
- }
-
- else {
+ } else {
strncpy(buf, "", n);
res = 0;
}
@@ -416,91 +348,80 @@ int lc_opt_bool_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t t
return n;
}
-int lc_opt_occurs(lc_opt_entry_t *opt, const char *value, lc_opt_err_info_t *err)
+bool lc_opt_occurs(lc_opt_entry_t *opt, const char *value)
{
static const struct {
const char *str;
int val;
} bool_strings[] = {
- { "yes", 1 },
- { "true", 1 },
- { "on", 1 },
- { "1", 1 },
- { "no", 0 },
+ { "true", 1 },
+ { "yes", 1 },
+ { "on", 1 },
+ { "1", 1 },
{ "false", 0 },
- { "off", 0 },
- { "0", 0 },
+ { "no", 0 },
+ { "off", 0 },
+ { "0", 0 },
};
- unsigned i;
- int error = lc_opt_err_illegal_format;
- lc_opt_special_t *s = lc_get_opt_special(opt);
- char buf[16];
- union {
- int integer;
- double dbl;
- } val_storage, *val = &val_storage;
-
- if (!opt) {
- set_error(err, lc_opt_err_opt_not_found, "");
+ if (opt == NULL) {
return 0;
}
+ lc_opt_special_t *s = lc_get_opt_special(opt);
if (!s->cb) {
- set_error(err, lc_opt_err_no_callback, "");
return 0;
}
- s->is_set = 1;
+ s->is_set = true;
+ bool fine = true;
switch (s->type) {
- case lc_opt_type_int:
- if (sscanf(value, "%i", (int *) val)) {
- error = lc_opt_err_unknown_value;
- if (s->cb(opt->name, s->type, s->value, s->length, val->integer))
- error = lc_opt_err_none;
- }
- break;
+ case lc_opt_type_int: {
+ int val;
+ if (sscanf(value, "%i", &val)) {
+ fine = s->cb(opt->name, s->type, s->value, s->length, val);
+ }
+ break;
+ }
- case lc_opt_type_double:
- if (sscanf(value, "%lf", (double *) val)) {
- error = lc_opt_err_unknown_value;
- if (s->cb(opt->name, s->type, s->value, s->length, val->dbl))
- error = lc_opt_err_none;
+ case lc_opt_type_double: {
+ double val;
+ if (sscanf(value, "%lf", &val)) {
+ fine = s->cb(opt->name, s->type, s->value, s->length, val);
+ }
+ break;
+ }
+
+ case lc_opt_type_boolean:
+ case lc_opt_type_bit: {
+ char buf[16];
+ int val = 0;
+ strtolower(buf, sizeof(buf), value);
+ for (unsigned i = 0; i < ARRAY_SIZE(bool_strings); ++i) {
+ if (strcmp(buf, bool_strings[i].str) == 0) {
+ val = bool_strings[i].val;
+ fine = true;
+ break;
}
- break;
+ }
- case lc_opt_type_boolean:
- case lc_opt_type_bit:
- strtolower(buf, sizeof(buf), value);
- for (i = 0; i < ARRAY_SIZE(bool_strings); ++i) {
- if (strcmp(buf, bool_strings[i].str) == 0) {
- val->integer = bool_strings[i].val;
- error = lc_opt_err_none;
- break;
- }
- }
-
- if (error == lc_opt_err_none) {
- error = lc_opt_err_unknown_value;
- if (s->cb(opt->name, s->type, s->value, s->length, val->integer))
- error = lc_opt_err_none;
- }
+ if (fine) {
+ fine = s->cb(opt->name, s->type, s->value, s->length, val);
+ }
- break;
+ break;
+ }
- case lc_opt_type_string:
- case lc_opt_type_enum:
- error = lc_opt_err_unknown_value;
- if (s->cb(opt->name, s->type, s->value, s->length, value))
- error = lc_opt_err_none;
- break;
- case lc_opt_type_invalid:
- abort();
+ case lc_opt_type_string:
+ case lc_opt_type_enum:
+ fine = s->cb(opt->name, s->type, s->value, s->length, value);
+ break;
+ case lc_opt_type_invalid:
+ abort();
}
- set_error(err, error, value);
- return error == lc_opt_err_none;
+ return fine;
}
char *lc_opt_value_to_string(char *buf, size_t len, const lc_opt_entry_t *ent)
@@ -514,7 +435,8 @@ char *lc_opt_value_to_string(char *buf, size_t len, const lc_opt_entry_t *ent)
return buf;
}
-static char *lc_opt_values_to_string(char *buf, size_t len, const lc_opt_entry_t *ent)
+static char *lc_opt_values_to_string(char *buf, size_t len,
+ const lc_opt_entry_t *ent)
{
const lc_opt_special_t *s = lc_get_opt_special(ent);
if (s->dump_vals)
@@ -523,19 +445,17 @@ static char *lc_opt_values_to_string(char *buf, size_t len, const lc_opt_entry_t
return buf;
}
-int lc_opt_add_table(lc_opt_entry_t *root, const lc_opt_table_entry_t *table)
+bool lc_opt_add_table(lc_opt_entry_t *root, const lc_opt_table_entry_t *table)
{
- int i, res = 0;
- lc_opt_err_info_t err;
+ bool res = false;
- for (i = 0; table[i].name != NULL; ++i) {
+ for (int i = 0; table[i].name != NULL; ++i) {
const char *name;
const lc_opt_table_entry_t *tab = &table[i];
- lc_opt_entry_t *grp = resolve_up_to_last_str(root, tab->name, &name);
-
- lc_opt_add_opt(grp, name, tab->desc, tab->type, tab->value, tab->len, tab->cb, tab->dump, tab->dump_vals, &err);
- if (err.error != lc_opt_err_none)
- res = 1;
+ lc_opt_entry_t *grp = resolve_up_to_last_str(root, tab->name, &name);
+ lc_opt_entry_t *entry = lc_opt_add_opt(grp, name, tab->desc, tab->type, tab->value, tab->len, tab->cb, tab->dump, tab->dump_vals);
+ if (entry == NULL)
+ res = true;
}
return res;
@@ -546,9 +466,8 @@ static void lc_opt_print_grp_path_rec(char *buf, size_t len, const lc_opt_entry_
if (ent == stop_ent)
return;
if (!lc_opt_grp_is_root(ent)) {
- size_t l;
lc_opt_print_grp_path_rec(buf, len, ent->parent, separator, stop_ent);
- l = strlen(buf);
+ size_t l = strlen(buf);
if (l > 0 && l < len-1) {
buf[l] = separator;
buf[l + 1] = '\0';
@@ -616,8 +535,7 @@ void lc_opt_print_help_for_entry(lc_opt_entry_t *ent, char separator, FILE *f)
static void indent(FILE *f, int n)
{
- int i;
- for (i = 0; i < n; ++i)
+ for (int i = 0; i < n; ++i)
fputc(' ', f);
}
@@ -628,25 +546,25 @@ static void lc_opt_print_tree_lc_opt_indent(lc_opt_entry_t *ent, FILE *f, int le
indent(f, level);
fprintf(f, "%c%s(\"%s\"):%s = %s\n", s->is_set ? '+' : '-', ent->name,
- ent->desc, lc_opt_get_type_name(ent), lc_opt_value_to_string(buf, sizeof(buf), ent));
+ ent->desc, lc_opt_get_type_name(ent),
+ lc_opt_value_to_string(buf, sizeof(buf), ent));
}
static void lc_opt_print_tree_grp_indent(lc_opt_entry_t *ent, FILE *f, int level)
{
- lc_grp_special_t *s;
+ if (!ent->is_grp)
+ return;
- if (ent->is_grp) {
- s = lc_get_grp_special(ent);
- indent(f, level);
- fprintf(f, "/%s\n", ent->name);
+ lc_grp_special_t *s = lc_get_grp_special(ent);
+ indent(f, level);
+ fprintf(f, "/%s\n", ent->name);
- list_for_each_entry(lc_opt_entry_t, e, &s->grps, list) {
- lc_opt_print_tree_grp_indent(e, f, level + 2);
- }
+ list_for_each_entry(lc_opt_entry_t, e, &s->grps, list) {
+ lc_opt_print_tree_grp_indent(e, f, level + 2);
+ }
- list_for_each_entry(lc_opt_entry_t, e, &s->opts, list) {
- lc_opt_print_tree_lc_opt_indent(e, f, level + 2);
- }
+ list_for_each_entry(lc_opt_entry_t, e, &s->opts, list) {
+ lc_opt_print_tree_lc_opt_indent(e, f, level + 2);
}
}
@@ -655,164 +573,54 @@ void lc_opt_print_tree(lc_opt_entry_t *ent, FILE *f)
lc_opt_print_tree_grp_indent(ent, f, 0);
}
-static int lc_opts_default_error_handler(const char *prefix, const lc_opt_err_info_t *err)
-{
- fprintf(stderr, "%s: %s; %s\n", prefix, err->msg, err->arg);
- return 0;
-}
-
-int lc_opt_from_single_arg(const lc_opt_entry_t *root,
- const char *opt_prefix,
- const char *arg, lc_opt_error_handler_t *handler)
+int lc_opt_from_single_arg(const lc_opt_entry_t *root, const char *arg)
{
const lc_opt_entry_t *grp = root;
- size_t n = strlen(arg);
- size_t n_prefix = opt_prefix != NULL ? strlen(opt_prefix) : 0;
- int error = 0;
- int ret = 0;
- lc_opt_err_info_t err;
- const char *end, *eqsign;
-
- if (n >= n_prefix && (n_prefix == 0 || strncmp(opt_prefix, arg, n_prefix) == 0)) {
- arg = arg + n_prefix;
-
- /* find the next delimiter (the -) and extract the string up to
- * there. */
+ /* find the next delimiter (the -) and extract the string up to
+ * there. */
+ const char *end = strchr(arg, OPT_DELIM);
+ const char *eqsign = strchr(arg, '=');
+ if (eqsign && eqsign < end)
+ end = NULL;
+ while (end != NULL) {
+ /* Copy the part of the option into the buffer and add the
+ * finalizing zero. */
+ char *buf = (char*)obstack_copy0(&obst, arg, end - arg);
+
+ /* Resolve the group inside the group */
+ grp = lc_opt_find_grp(grp, buf);
+ if (grp == NULL)
+ return 0;
+
+ /* Find the next option part delimiter. */
+ arg = end + 1;
end = strchr(arg, OPT_DELIM);
eqsign = strchr(arg, '=');
if (eqsign && eqsign < end)
end = NULL;
- while (end != NULL) {
- /*
- * Copy the part of the option into the buffer and add the
- * finalizing zero.
- */
- char *buf = (char*)obstack_copy0(&obst, arg, end - arg);
-
- /* Resolve the group inside the group */
- grp = lc_opt_find_grp(grp, buf, &err);
- error = lc_opt_raise_error(&err, handler, ERR_STRING, arg);
- if (error)
- break;
-
- /* Find the next option part delimiter. */
- arg = end + 1;
- end = strchr(arg, OPT_DELIM);
- eqsign = strchr(arg, '=');
- if (eqsign && eqsign < end)
- end = NULL;
- obstack_free(&obst, buf);
- }
-
- if (!error) {
- lc_opt_entry_t *opt;
- char *buf;
-
- /*
- * Now, we are at the last option part:
- * --grp1-grp2-...-grpn-opt=value
- * Check, for the = and evaluate the option string. If the = is
- * missing, we should have a boolean option, but that is checked
- * later.
- */
- end = strchr(arg, '=');
- buf = (char*)obstack_copy0(&obst, arg, end ? end - arg : (int) strlen(arg));
- opt = lc_opt_find_opt(grp, buf, &err);
- error = lc_opt_raise_error(&err, handler, ERR_STRING, arg);
-
- if (!error) {
- /*
- * Now evaluate the parameter of the option (the part after
- * the =) if it was given.
- */
- arg = end ? end + 1 : "true";
-
- /* Set the value of the option. */
- lc_opt_occurs(opt, arg, &err);
- ret = !lc_opt_raise_error(&err, handler, ERR_STRING, arg);
- }
- }
+ obstack_free(&obst, buf);
}
- return ret;
-}
-
-int lc_opt_from_argv(const lc_opt_entry_t *root,
- const char *opt_prefix,
- int argc, const char *argv[],
- lc_opt_error_handler_t *handler)
-{
- int i;
- int options_set = 0;
-
- if (handler == NULL)
- handler = lc_opts_default_error_handler;
-
- for (i = 0; i < argc; ++i) {
- options_set |= lc_opt_from_single_arg(root, opt_prefix, argv[i], handler);
- }
-
- return options_set;
-}
-
-static int opt_arg_type(const lc_arg_occ_t *occ)
-{
- (void) occ;
- return lc_arg_type_ptr;
-}
-
-static int opt_arg_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
-{
- char buf[256];
-
- lc_opt_entry_t *opt = (lc_opt_entry_t*)arg->v_ptr;
- const char *s = buf;
- size_t res = 0;
-
- switch (occ->conversion) {
- case 'V':
- lc_opt_value_to_string(buf, sizeof(buf), opt);
- break;
- case 'T':
- s = lc_opt_get_type_name(opt);
- break;
- case 'D':
- s = opt->desc;
- break;
- case 'O':
- s = opt->name;
- break;
- default:
- s = NULL;
- }
-
- if (s)
- res = lc_appendable_snadd(app, s, strlen(s));
-
- return res;
-}
-
-static const lc_arg_handler_t lc_opt_arg_handler = {
- opt_arg_type,
- opt_arg_emit
-};
-
-
-/* lc_printf facility for options */
-
-const lc_arg_env_t *lc_opt_get_arg_env(void)
-{
- static lc_arg_env_t *env = NULL;
-
- if (!env) {
- env = lc_arg_new_env();
+ /*
+ * Now, we are at the last option part:
+ * --grp1-grp2-...-grpn-opt=value
+ * Check, for the = and evaluate the option string. If the = is
+ * missing, we should have a boolean option, but that is checked
+ * later.
+ */
+ end = strchr(arg, '=');
+ char *buf = (char*)obstack_copy0(&obst, arg, end ? end - arg : (int) strlen(arg));
+ lc_opt_entry_t *opt = lc_opt_find_opt(grp, buf);
+ if (opt == NULL)
+ return 0;
- lc_arg_register(env, "opt:value", 'V', &lc_opt_arg_handler);
- lc_arg_register(env, "opt:type", 'T', &lc_opt_arg_handler);
- lc_arg_register(env, "opt:desc", 'D', &lc_opt_arg_handler);
- lc_arg_register(env, "opt:name", 'O', &lc_opt_arg_handler);
- }
+ /*
+ * Now evaluate the parameter of the option (the part after
+ * the =) if it was given.
+ */
+ arg = end ? end + 1 : "true";
- return env;
+ /* Set the value of the option. */
+ return lc_opt_occurs(opt, arg);
}
diff --git a/ir/libcore/lc_opts.h b/ir/libcore/lc_opts.h
index fd90962..799d404 100644
--- a/ir/libcore/lc_opts.h
+++ b/ir/libcore/lc_opts.h
@@ -13,6 +13,7 @@
#define _LC_OPTS_H
#include <stdio.h>
+#include <stdbool.h>
#include "lc_printf.h"
@@ -29,40 +30,14 @@ typedef enum {
lc_opt_type_double
} lc_opt_type_t;
-/**
- * Error codes.
- */
-typedef enum {
- lc_opt_err_none = 0,
- lc_opt_err_no_callback,
- lc_opt_err_illegal_option_type,
- lc_opt_err_illegal_format,
- lc_opt_err_grp_not_found,
- lc_opt_err_opt_not_found,
- lc_opt_err_grp_expected,
- lc_opt_err_opt_already_there,
- lc_opt_err_file_not_found,
- lc_opt_err_unknown_value
-} lc_opt_err_t;
-
-typedef struct {
- int error;
- const char *msg;
- const char *arg;
-} lc_opt_err_info_t;
-
-#define lc_opt_is_error(err) ((err)->error != lc_opt_err_none)
-
typedef struct lc_opt_entry_t lc_opt_entry_t;
-typedef int (lc_opt_callback_t)(const char *name, lc_opt_type_t type, void *data, size_t length, ...);
+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, const char *name, lc_opt_type_t type, void *data, size_t length);
typedef int (lc_opt_dump_vals_t)(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t length);
-typedef int (lc_opt_error_handler_t)(const char *prefix, const lc_opt_err_info_t *err);
-
typedef struct {
const char *name; /**< The name of the option. */
const char *desc; /**< A description for the option. */
@@ -152,10 +127,9 @@ lc_opt_entry_t *lc_opt_add_opt(lc_opt_entry_t *grp,
void *value, size_t length,
lc_opt_callback_t *cb,
lc_opt_dump_t *dump,
- lc_opt_dump_vals_t *dump_vals,
- lc_opt_err_info_t *err);
+ lc_opt_dump_vals_t *dump_vals);
-int lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data, size_t length, ...);
+bool lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data, size_t length, ...);
int lc_opt_std_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t length);
@@ -178,50 +152,45 @@ int lc_opt_bool_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t t
* Find a group inside another group.
* @param grp The group to search inside.
* @param name The name of the group you are looking for.
- * @param err Error info (may be NULL).
* @return The group or NULL, if no such group can be found.
*/
-lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err);
+lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name);
/**
* Find an option inside another group.
* @param grp The group to search inside.
* @param name The name of the option you are looking for.
- * @param err Error info (may be NULL).
* @return The group or NULL, if no such option can be found.
*/
-lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err);
+lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name);
/**
* Resolve a group.
* @param root The group to start resolving from.
* @param names A string array containing the path to the group.
* @param n Number of entries in @p names to consider.
- * @param err Error information (may be NULL).
* @return The group or NULL, if none is found.
*/
lc_opt_entry_t *lc_opt_resolve_grp(const lc_opt_entry_t *root,
- const char * const *names, int n, lc_opt_err_info_t *err);
+ const char * const *names, int n);
/**
* Resolve an option.
* @param root The group to start resolving from.
* @param names A string array containing the path to the option.
* @param n Number of entries in @p names to consider.
- * @param err Error information (may be NULL).
* @return The option or NULL, if none is found.
*/
lc_opt_entry_t *lc_opt_resolve_opt(const lc_opt_entry_t *root,
- const char * const *names, int n, lc_opt_err_info_t *err);
+ const char * const *names, int n);
/**
* Set the value of an option.
* @param opt The option to set.
* @param value The value of the option in a string representation.
- * @param err Error information (may be NULL).
* @return 0, if an error occurred, 1 else.
*/
-int lc_opt_occurs(lc_opt_entry_t *opt, const char *value, lc_opt_err_info_t *err);
+bool lc_opt_occurs(lc_opt_entry_t *opt, const char *value);
/**
* Convert the option to a string representation.
@@ -254,38 +223,14 @@ void lc_opt_print_help_for_entry(lc_opt_entry_t *ent, char separator, FILE *f);
void lc_opt_print_tree(lc_opt_entry_t *ent, FILE *f);
-int lc_opt_add_table(lc_opt_entry_t *grp, const lc_opt_table_entry_t *table);
-
-/**
- * The same as lc_opt_from_single_arg() only for an array of arguments.
- */
-int lc_opt_from_argv(const lc_opt_entry_t *root,
- const char *opt_prefix,
- int argc, const char *argv[],
- lc_opt_error_handler_t *handler);
+bool lc_opt_add_table(lc_opt_entry_t *grp, const lc_opt_table_entry_t *table);
/**
* Set options from a single (command line) argument.
* @param root The root group we start resolving from.
- * @param opt_prefix The option prefix which shall be stripped of (mostly --).
* @param arg The command line argument itself.
- * @param handler An error handler.
* @return 1, if the argument was set, 0 if not.
*/
-int lc_opt_from_single_arg(const lc_opt_entry_t *grp,
- const char *opt_prefix,
- const char *arg,
- lc_opt_error_handler_t *handler);
-
-/**
- * Get printf environment for the option module.
- * Currently implemented options are:
- * %{opt:value} (%V) Value of an option.
- * %{opt:type} (%T) Type of an option.
- * %{opt:name} (%O) Name of an option.
- * %{opt:desc} (%D) Description of an option.
- * @return The option printf environment.
- */
-const lc_arg_env_t *lc_opt_get_arg_env(void);
+int lc_opt_from_single_arg(const lc_opt_entry_t *grp, const char *arg);
#endif
diff --git a/ir/libcore/lc_opts_enum.c b/ir/libcore/lc_opts_enum.c
index c1b8d5f..6c5221b 100644
--- a/ir/libcore/lc_opts_enum.c
+++ b/ir/libcore/lc_opts_enum.c
@@ -16,7 +16,7 @@
static const char *delim = " \t|,";
#define DECL_CB(N, op) \
-int lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...) \
+bool lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, 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; \
@@ -25,7 +25,7 @@ int lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, s
char *s, *tmp; \
size_t begin, end; \
const char *arg; \
- int res = 0; \
+ bool res = false; \
\
(void) name; \
(void) type; \
@@ -50,7 +50,7 @@ int lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, s
for (i = 0; items[i].name != NULL; ++i) { \
if (strcmp(s, items[i].name) == 0) { \
*var->value op items[i].value; \
- res = 1; \
+ res = true; \
} \
} \
} \
diff --git a/ir/libcore/lc_opts_enum.h b/ir/libcore/lc_opts_enum.h
index 9368b0d..abc741e 100644
--- a/ir/libcore/lc_opts_enum.h
+++ b/ir/libcore/lc_opts_enum.h
@@ -19,7 +19,7 @@ typedef struct { \
const lc_opt_enum_ ## N ## _items_t *items; \
} lc_opt_enum_ ## N ## _var_t; \
\
-int lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...); \
+bool lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...); \
int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
int lc_opt_enum_ ## N ## _dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
@@ -48,7 +48,7 @@ typedef struct {
#define LC_OPT_ENT_ENUM_FUNC_PTR(name, desc, var) _LC_OPT_ENT_ENUM(func_ptr, name, desc, var)
-int lc_opt_enum_func_ptr_cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...);
+bool lc_opt_enum_func_ptr_cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...);
int lc_opt_enum_func_ptr_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
int lc_opt_enum_func_ptr_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
diff --git a/ir/libcore/lc_opts_t.h b/ir/libcore/lc_opts_t.h
index 7e4f4d6..5733fc6 100644
--- a/ir/libcore/lc_opts_t.h
+++ b/ir/libcore/lc_opts_t.h
@@ -19,25 +19,22 @@ typedef struct {
} lc_grp_special_t;
typedef struct {
- lc_opt_type_t type;
- lc_opt_callback_t *cb;
- lc_opt_dump_t *dump;
+ lc_opt_type_t type;
+ lc_opt_callback_t *cb;
+ lc_opt_dump_t *dump;
lc_opt_dump_vals_t *dump_vals;
- void *value;
- size_t length;
- unsigned is_set : 1;
+ void *value;
+ size_t length;
+ bool is_set : 1;
} lc_opt_special_t;
struct lc_opt_entry_t {
- unsigned hash;
- const char *name;
- const char *desc;
+ unsigned hash;
+ const char *name;
+ const char *desc;
struct lc_opt_entry_t *parent;
-
- unsigned is_grp : 1;
-
+ bool is_grp : 1;
struct list_head list;
-
union {
lc_grp_special_t grp;
lc_opt_special_t opt;
@@ -47,8 +44,4 @@ struct lc_opt_entry_t {
#define lc_get_opt_special(ent) (&(ent)->v.opt)
#define lc_get_grp_special(ent) (&(ent)->v.grp)
-int lc_opt_raise_error(const lc_opt_err_info_t *err,
- lc_opt_error_handler_t *handler,
- const char *fmt, ...);
-
#endif
diff --git a/ir/libcore/lc_printf.c b/ir/libcore/lc_printf.c
index 6336fdb..93f32e5 100644
--- a/ir/libcore/lc_printf.c
+++ b/ir/libcore/lc_printf.c
@@ -28,15 +28,15 @@
/* printf implementation */
typedef struct lc_arg_t {
- struct lc_arg_t *next;
- const char *name;
- char letter;
- int lc_arg_type;
+ struct lc_arg_t *next;
+ const char *name;
+ char letter;
+ int lc_arg_type;
const lc_arg_handler_t *handler;
} lc_arg_t;
struct lc_arg_env_t {
- set *args; /**< Map for named arguments. */
+ set *args; /**< Map for named arguments. */
lc_arg_t *lower[26]; /**< Map for lower conversion specifiers. */
lc_arg_t *upper[26]; /**< Map for upper conversion specifiers. */
};
@@ -79,27 +79,25 @@ void lc_arg_free_env(lc_arg_env_t *env)
free(env);
}
-int lc_arg_register(lc_arg_env_t *env, const char *name, char letter, const lc_arg_handler_t *handler)
+int lc_arg_register(lc_arg_env_t *env, const char *name, char letter,
+ const lc_arg_handler_t *handler)
{
lc_arg_t arg;
- lc_arg_t *ent;
- int base = 0;
- lc_arg_t **map = NULL;
-
arg.name = name;
arg.letter = letter;
arg.handler = handler;
+ lc_arg_t **map = NULL;
+ int base = 0;
if (isupper((unsigned char)letter)) {
map = env->upper;
base = 'A';
- }
- else if (islower((unsigned char)letter)) {
+ } else if (islower((unsigned char)letter)) {
map = env->lower;
base = 'a';
}
- ent = set_insert(lc_arg_t, env->args, &arg, sizeof(arg), hash_str(name));
+ lc_arg_t *ent = set_insert(lc_arg_t, env->args, &arg, sizeof(arg), hash_str(name));
if (ent && base != 0)
map[letter - base] = ent;
@@ -262,33 +260,29 @@ static int std_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_
make_fmt(fmt, sizeof(fmt), occ);
switch (occ->conversion) {
-
/* Store the number of written characters in the given
* int pointer location */
- case 'n':
- {
- int *num = (int*)val->v_ptr;
- *num = (int)app->written;
- }
+ case 'n': {
+ int *num = (int*)val->v_ptr;
+ *num = (int)app->written;
break;
+ }
/* strings are dumped directly, since they can get really big. A
* buffer of 128 letters for all other types should be enough. */
- case 's':
- {
- const char *str = (const char*)val->v_ptr;
- res = lc_arg_append(app, occ, str, strlen(str));
- }
+ case 's': {
+ const char *str = (const char*)val->v_ptr;
+ res = lc_arg_append(app, occ, str, strlen(str));
break;
+ }
- default:
- {
- int len = MAX(128, occ->width + 1);
- char *buf = XMALLOCN(char, len);
- res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
- res = lc_appendable_snadd(app, buf, res);
- free(buf);
- }
+ default: {
+ int len = MAX(128, occ->width + 1);
+ char *buf = XMALLOCN(char, len);
+ res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
+ res = lc_appendable_snadd(app, buf, res);
+ free(buf);
+ }
}
return res;
@@ -333,29 +327,26 @@ static char *read_int(const char *s, int *value)
/* Generic printf() function. */
-int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, va_list args)
+int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
+ va_list args)
{
- int res = 0;
- const char *s;
+ int res = 0;
const char *last = fmt + strlen(fmt);
/* Find the first % */
- s = strchr(fmt, '%');
+ const char *s = strchr(fmt, '%');
/* Emit the text before the first % was found */
lc_appendable_snadd(app, fmt, (s ? s : last) - fmt);
while (s != NULL) {
- lc_arg_occ_t occ;
lc_arg_value_t val;
- const lc_arg_t *arg = NULL;
- const char *old;
- char ch;
/* We must be at a '%' */
assert(*s == '%');
/* Reset the occurrence structure */
+ lc_arg_occ_t occ;
memset(&occ, 0, sizeof(occ));
/* Eat all flags and set the corresponding flags in the occ struct */
@@ -400,74 +391,74 @@ int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
* - some modifiers followed by a conversion specifier
* - or some other character, which ends this format invalidly
*/
- ch = *s;
+ char ch = *s;
+ const lc_arg_t *arg = NULL;
switch (ch) {
case '%':
s++;
res += lc_appendable_chadd(app, '%');
break;
- case '{':
- {
- const char *named = ++s;
+ case '{': {
+ const char *named = ++s;
- /* Read until the closing brace or end of the string. */
- for (ch = *s; ch != '}' && ch != '\0'; ch = *++s) {
- }
+ /* Read until the closing brace or end of the string. */
+ for (ch = *s; ch != '}' && ch != '\0'; ch = *++s) {
+ }
- if (s - named) {
- size_t n = s - named;
- char *name;
- lc_arg_t tmp;
+ if (s - named) {
+ size_t n = s - named;
+ char *name;
+ lc_arg_t tmp;
- name = (char*) malloc(sizeof(char) * (n + 1));
- memcpy(name, named, sizeof(char) * n);
- name[n] = '\0';
- tmp.name = name;
+ name = (char*) malloc(sizeof(char) * (n + 1));
+ memcpy(name, named, sizeof(char) * n);
+ name[n] = '\0';
+ tmp.name = name;
- arg = set_find(lc_arg_t, env->args, &tmp, sizeof(tmp), hash_str(named));
- occ.modifier = "";
- occ.modifier_length = 0;
+ arg = set_find(lc_arg_t, env->args, &tmp, sizeof(tmp), hash_str(named));
+ occ.modifier = "";
+ occ.modifier_length = 0;
- /* Set the conversion specifier of the occurrence to the
- * letter specified in the argument description. */
- if (arg)
- occ.conversion = arg->letter;
+ /* Set the conversion specifier of the occurrence to the
+ * letter specified in the argument description. */
+ if (arg)
+ occ.conversion = arg->letter;
- free(name);
+ free(name);
- /* If we ended with a closing brace, move the current
- * pointer after it, since it is not to be dumped. */
- if (ch == '}')
- s++;
- }
+ /* If we ended with a closing brace, move the current
+ * pointer after it, since it is not to be dumped. */
+ if (ch == '}')
+ s++;
}
break;
+ }
- default:
- {
- const char *mod = s;
-
- /* Read, as long there are letters */
- while (isalpha((unsigned char)ch) && !arg) {
- int base = 'a';
- lc_arg_t * const *map = env->lower;
-
- /* If uppercase, select the uppercase map from the environment */
- if (isupper((unsigned char)ch)) {
- base = 'A';
- map = env->upper;
- }
-
- if (map[ch - base] != NULL) {
- occ.modifier = mod;
- occ.modifier_length = s - mod;
- occ.conversion = ch;
- arg = map[ch - base];
- }
-
- ch = *++s;
+ default: {
+ const char *mod = s;
+
+ /* Read, as long there are letters */
+ while (isalpha((unsigned char)ch) && !arg) {
+ int base = 'a';
+ lc_arg_t *const *map = env->lower;
+
+ /* If uppercase, select the uppercase map from the
+ * environment */
+ if (isupper((unsigned char)ch)) {
+ base = 'A';
+ map = env->upper;
+ }
+
+ if (map[ch - base] != NULL) {
+ occ.modifier = mod;
+ occ.modifier_length = s - mod;
+ occ.conversion = ch;
+ arg = map[ch - base];
}
+
+ ch = *++s;
}
+ }
}
/* Call the handler if an argument was determined */
@@ -490,7 +481,7 @@ int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
res += handler->emit(app, &occ, &val);
}
- old = s;
+ const char *old = s;
s = strchr(s, '%');
res += lc_appendable_snadd(app, old, (s ? s : last) - old);
}
@@ -502,20 +493,18 @@ int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
int lc_epprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_evpprintf(env, app, fmt, args);
+ int res = lc_evpprintf(env, app, fmt, args);
va_end(args);
return res;
}
int lc_pprintf(lc_appendable_t *app, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_vpprintf(app, fmt, args);
+ int res = lc_vpprintf(app, fmt, args);
va_end(args);
return res;
}
@@ -527,40 +516,36 @@ int lc_vpprintf(lc_appendable_t *app, const char *fmt, va_list args)
int lc_eprintf(const lc_arg_env_t *env, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_efprintf(env, stdout, fmt, args);
+ int res = lc_efprintf(env, stdout, fmt, args);
va_end(args);
return res;
}
int lc_esnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_evsnprintf(env, buf, len, fmt, args);
+ int res = lc_evsnprintf(env, buf, len, fmt, args);
va_end(args);
return res;
}
int lc_efprintf(const lc_arg_env_t *env, FILE *file, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_evfprintf(env, file, fmt, args);
+ int res = lc_evfprintf(env, file, fmt, args);
va_end(args);
return res;
}
int lc_eoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_evoprintf(env, obst, fmt, args);
+ int res = lc_evoprintf(env, obst, fmt, args);
va_end(args);
return res;
}
@@ -572,33 +557,30 @@ int lc_evprintf(const lc_arg_env_t *env, const char *fmt, va_list args)
int lc_evsnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, va_list args)
{
- int res;
lc_appendable_t app;
lc_appendable_init(&app, lc_appendable_string, buf, len);
- res = lc_evpprintf(env, &app, fmt, args);
+ int res = lc_evpprintf(env, &app, fmt, args);
lc_appendable_finish(&app);
return res;
}
int lc_evfprintf(const lc_arg_env_t *env, FILE *f, const char *fmt, va_list args)
{
- int res;
lc_appendable_t app;
lc_appendable_init(&app, lc_appendable_file, f, 0);
- res = lc_evpprintf(env, &app, fmt, args);
+ int res = lc_evpprintf(env, &app, fmt, args);
lc_appendable_finish(&app);
return res;
}
int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, va_list args)
{
- int res;
lc_appendable_t app;
lc_appendable_init(&app, lc_appendable_obstack, obst, 0);
- res = lc_evpprintf(env, &app, fmt, args);
+ int res = lc_evpprintf(env, &app, fmt, args);
lc_appendable_finish(&app);
return res;
}
@@ -606,40 +588,36 @@ int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt,
int lc_printf(const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_vprintf(fmt, args);
+ int res = lc_vprintf(fmt, args);
va_end(args);
return res;
}
int lc_snprintf(char *buf, size_t len, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_vsnprintf(buf, len, fmt, args);
+ int res = lc_vsnprintf(buf, len, fmt, args);
va_end(args);
return res;
}
int lc_fprintf(FILE *f, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_vfprintf(f, fmt, args);
+ int res = lc_vfprintf(f, fmt, args);
va_end(args);
return res;
}
int lc_oprintf(struct obstack *obst, const char *fmt, ...)
{
- int res;
va_list args;
va_start(args, fmt);
- res = lc_voprintf(obst, fmt, args);
+ int res = lc_voprintf(obst, fmt, args);
va_end(args);
return res;
}
diff --git a/ir/libcore/lc_printf.h b/ir/libcore/lc_printf.h
index c6e7909..fa01042 100644
--- a/ir/libcore/lc_printf.h
+++ b/ir/libcore/lc_printf.h
@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <obstack.h>
@@ -35,11 +36,11 @@ typedef struct lc_arg_occ_t {
the @c get_lc_arg_type member function of
the handler. */
- unsigned flag_hash : 1; /**< @c # flag was seen. */
- unsigned flag_zero : 1; /**< @c 0 flag was seen. */
- unsigned flag_minus : 1; /**< @c - flag was seen. */
- unsigned flag_plus : 1; /**< @c + flag was seen. */
- unsigned flag_space : 1; /**< A space flag was seen. */
+ bool flag_hash : 1; /**< @c # flag was seen. */
+ bool flag_zero : 1; /**< @c 0 flag was seen. */
+ bool flag_minus : 1; /**< @c - flag was seen. */
+ bool flag_plus : 1; /**< @c + flag was seen. */
+ bool flag_space : 1; /**< A space flag was seen. */
} lc_arg_occ_t;
/**