#include <stdio.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#if defined(__FreeBSD__)
-#include <stdlib.h>
-#elif defined(_WIN32)
+#ifdef _WIN32
#include <malloc.h>
-#else
+#endif
+#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
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);
}
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;
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)();
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 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];
/* Process ini file in user's home. */
f = fopen(path, "rt");
if (f) {
- fprintf(stderr, "Warning: Automatically reading options from '%s'\n", path);
lc_opt_from_file(path, f, lc_opts_default_error_handler);
fclose(f);
}
/* Process ini file in current directory. */
f = fopen(local_ini_file, "rt");
if (f) {
- fprintf(stderr, "Warning: Automatically reading options from '%s'\n", local_ini_file);
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);
}