"Options:\n"
"\t-f <file> use <file> as input instead of stdin\n"
"\t-m when importing, merge data into an existing package\n"
- "\t-s force strict mode (stop on parser errors)\n"
+ "\t-s force strict mode (stop on parser errors, default)\n"
"\t-S disable strict mode\n"
+ "\t-n name unnamed sections on export (default)\n"
+ "\t-N don't name unnamed sections\n"
"\n",
argv[0]
);
return 1;
}
- while((c = getopt(argc, argv, "mf:sS")) != -1) {
+ while((c = getopt(argc, argv, "mf:sSnN")) != -1) {
switch(c) {
case 'f':
input = fopen(optarg, "r");
ctx->flags &= ~UCI_FLAG_STRICT;
ctx->flags |= UCI_FLAG_PERROR;
break;
+ case 'n':
+ ctx->flags |= UCI_FLAG_EXPORT_NAME;
+ break;
+ case 'N':
+ ctx->flags &= ~UCI_FLAG_EXPORT_NAME;
+ break;
default:
uci_usage(argc, argv);
break;
uci_foreach_element(&p->sections, s) {
struct uci_section *sec = uci_to_section(s);
fprintf(stream, "\nconfig '%s'", uci_escape(ctx, sec->type));
- if (!sec->anonymous)
+ if (!sec->anonymous || (ctx->flags & UCI_FLAG_EXPORT_NAME))
fprintf(stream, " '%s'", uci_escape(ctx, sec->e.name));
fprintf(stream, "\n");
uci_foreach_element(&sec->options, o) {
};
enum uci_flags {
- UCI_FLAG_STRICT = (1 << 0), /* strict mode for the parser */
- UCI_FLAG_PERROR = (1 << 1), /* print error messages to stderr */
+ UCI_FLAG_STRICT = (1 << 0), /* strict mode for the parser */
+ UCI_FLAG_PERROR = (1 << 1), /* print parser error messages */
+ UCI_FLAG_EXPORT_NAME = (1 << 2), /* when exporting, name unnamed sections */
};
struct uci_element