X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flibcore%2Flc_opts.c;h=f9b84b7b066e048360f0042fc055048fd9f2afb8;hb=38249b0311df91904bb3a566a770efe650f40efc;hp=4cb52df539c15289993ba3fe6f39495c0e94aa9c;hpb=d3f254f3d57f0a9cc57621d46e7179c88a443f67;p=libfirm diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c index 4cb52df53..f9b84b7b0 100644 --- a/ir/libcore/lc_opts.c +++ b/ir/libcore/lc_opts.c @@ -16,6 +16,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" #include #include @@ -130,7 +131,7 @@ static lc_opt_entry_t *init_grp(lc_opt_entry_t *ent, lc_opt_err_info_t *err) set_error(err, lc_opt_err_none, ""); if(ent->parent) { if(ent->parent->is_grp) - list_add(&ent->list, &lc_get_grp_special(ent->parent)->grps); + list_add_tail(&ent->list, &lc_get_grp_special(ent->parent)->grps); else set_error(err, lc_opt_err_grp_expected, ent->parent->name); } @@ -150,7 +151,7 @@ static lc_opt_entry_t *init_opt(lc_opt_entry_t *ent, ent->is_grp = 0; set_error(err, lc_opt_err_none, ""); - list_add(&ent->list, &lc_get_grp_special(ent->parent)->opts); + list_add_tail(&ent->list, &lc_get_grp_special(ent->parent)->opts); s->type = type; s->value = val; @@ -627,7 +628,7 @@ static void lc_opt_print_help_rec(lc_opt_entry_t *ent, char separator, lc_opt_en lc_grp_special_t *s = lc_get_grp_special(ent); char grp_name[512]; char value[256]; - char values[256]; + char values[512]; lc_opt_entry_t *e; if(!list_empty(&s->opts)) { @@ -707,9 +708,16 @@ 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; +} void lc_opt_from_file(const char *filename, FILE *f, lc_opt_error_handler_t *handler) { + if (handler == NULL) + handler = lc_opts_default_error_handler; PMANGLE(in) = f; lc_opt_init_parser(filename, handler); PMANGLE(parse)(); @@ -726,7 +734,7 @@ int lc_opt_from_single_arg(const lc_opt_entry_t *root, int ret = 0; lc_opt_err_info_t err; - char *end, *buf; + char *end, *buf, *eqsign; if(n >= n_prefix && strncmp(opt_prefix, arg, n_prefix) == 0) { arg = arg + n_prefix; @@ -756,7 +764,10 @@ int lc_opt_from_single_arg(const lc_opt_entry_t *root, /* find the next delimiter (the -) and extract the string up to * there. */ - end = strchr(arg, OPT_DELIM); + 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 @@ -772,7 +783,10 @@ int lc_opt_from_single_arg(const lc_opt_entry_t *root, /* Find the next option part delimiter. */ arg = end + 1; - end = strchr(arg, OPT_DELIM); + end = strchr(arg, OPT_DELIM); + eqsign = strchr(arg, '='); + if (eqsign && eqsign < end) + end = NULL; obstack_free(&obst, buf); } @@ -816,6 +830,9 @@ int lc_opt_from_argv(const lc_opt_entry_t *root, 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); } @@ -883,13 +900,7 @@ const lc_arg_env_t *lc_opt_get_arg_env(void) return env; } -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; -} - -void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_prefix, int argc, const char **argv) +void lc_opt_default_configs(const char *ini_name) { FILE *f; char path[MAX_PATH]; @@ -920,7 +931,7 @@ void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_pr snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name); home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0'; } else { - /* FIXME: some error occured */ + /* FIXME: some error occurred */ home_dir_ini_file[0] = '\0'; } } @@ -942,7 +953,4 @@ void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_pr lc_opt_from_file(local_ini_file, f, lc_opts_default_error_handler); fclose(f); } - - /* process arguments from the command line */ - lc_opt_from_argv(root, arg_prefix, argc, argv, lc_opts_default_error_handler); }