*/
#include <strings.h>
#include <stdlib.h>
+#include <unistd.h>
#include "uci.h"
static const char *appname = "uci";
int main(int argc, char **argv)
{
int ret;
+ int c;
ctx = uci_alloc_context();
+ if (!ctx) {
+ fprintf(stderr, "Out of memory\n");
+ return 1;
+ }
+
+ while((c = getopt(argc, argv, "sS")) != -1) {
+ switch(c) {
+ case 's':
+ ctx->flags |= UCI_FLAG_STRICT;
+ break;
+ case 'S':
+ ctx->flags &= ~UCI_FLAG_STRICT;
+ ctx->flags |= UCI_FLAG_PERROR;
+ break;
+ default:
+ uci_usage(argc, argv);
+ break;
+ }
+ }
+ if (optind > 1)
+ argv[optind - 1] = argv[0];
+ argv += optind - 1;
+ argc -= optind - 1;
+
if (argc < 2)
uci_usage(argc, argv);
ret = uci_cmd(argc - 1, argv + 1);
if (ret == 255)
uci_usage(argc, argv);
+
uci_free_context(ctx);
return ret;
while (!feof(pctx->file)) {
uci_getln(ctx, 0);
+
+ UCI_TRAP_SAVE(ctx, error);
if (pctx->buf[0])
uci_parse_line(ctx, single);
+ UCI_TRAP_RESTORE(ctx);
+ continue;
+error:
+ if (ctx->flags & UCI_FLAG_PERROR)
+ uci_perror(ctx, NULL);
+ if ((ctx->errno != UCI_ERR_PARSE) ||
+ (ctx->flags & UCI_FLAG_STRICT))
+ UCI_THROW(ctx, ctx->errno);
}
if (package)
ctx = (struct uci_context *) malloc(sizeof(struct uci_context));
memset(ctx, 0, sizeof(struct uci_context));
uci_list_init(&ctx->root);
+ ctx->flags = UCI_FLAG_STRICT;
return ctx;
}
UCI_TYPE_OPTION = 3
};
+enum uci_flags {
+ UCI_FLAG_STRICT = (1 << 0), /* strict mode for the parser */
+ UCI_FLAG_PERROR = (1 << 1), /* print error messages to stderr */
+};
+
struct uci_element
{
struct uci_list list;
/* parser context, use for error handling only */
struct uci_parse_context *pctx;
+ /* uci runtime flags */
+ enum uci_flags flags;
+
/* private: */
int errno;
const char *func;