#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
#include "lc_parser_t.h"
#include "hashptr.h"
#include "lc_printf.h"
+#include "xmalloc.h"
#define ERR_STRING "In argument \"%s\": "
lc_opt_entry_t *ent = lc_opt_find_grp(parent, name, NULL);
if(!ent) {
- ent = obstack_alloc(&obst, sizeof(*ent));
+ ent = OALLOC(&obst, lc_opt_entry_t);
init_entry(ent, parent, name, "");
init_grp(ent, NULL);
}
lc_opt_entry_t *ent = lc_opt_find_opt(parent, name, NULL);
if(!ent) {
- res = obstack_alloc(&obst, sizeof(*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
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)();
return ret;
}
-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_argv(const lc_opt_entry_t *root,
const char *opt_prefix,
int argc, const char *argv[],