projects
/
project
/
uci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lua: include /opt/local/lib and /opt/local/include in the search path on mac os x
[project/uci.git]
/
cli.c
diff --git
a/cli.c
b/cli.c
index
61afa80
..
144cdde
100644
(file)
--- a/
cli.c
+++ b/
cli.c
@@
-26,6
+26,8
@@
static enum {
CLI_FLAG_QUIET = (1 << 1),
CLI_FLAG_NOCOMMIT = (1 << 2),
CLI_FLAG_BATCH = (1 << 3),
CLI_FLAG_QUIET = (1 << 1),
CLI_FLAG_NOCOMMIT = (1 << 2),
CLI_FLAG_BATCH = (1 << 3),
+ CLI_FLAG_SHOW_EXT = (1 << 4),
+ CLI_FLAG_NOPLUGINS= (1 << 5),
} flags;
static FILE *input;
} flags;
static FILE *input;
@@
-39,6
+41,7
@@
enum {
CMD_DEL,
CMD_RENAME,
CMD_REVERT,
CMD_DEL,
CMD_RENAME,
CMD_REVERT,
+ CMD_REORDER,
/* package cmds */
CMD_SHOW,
CMD_CHANGES,
/* package cmds */
CMD_SHOW,
CMD_CHANGES,
@@
-84,7
+87,7
@@
uci_lookup_section_ref(struct uci_section *s)
struct uci_type_list *ti = type_list;
int maxlen;
struct uci_type_list *ti = type_list;
int maxlen;
- if (!s->anonymous)
+ if (!s->anonymous
|| !(flags & CLI_FLAG_SHOW_EXT)
)
return s->e.name;
/* look up in section type list */
return s->e.name;
/* look up in section type list */
@@
-95,6
+98,8
@@
uci_lookup_section_ref(struct uci_section *s)
}
if (!ti) {
ti = malloc(sizeof(struct uci_type_list));
}
if (!ti) {
ti = malloc(sizeof(struct uci_type_list));
+ if (!ti)
+ return NULL;
memset(ti, 0, sizeof(struct uci_type_list));
ti->next = type_list;
type_list = ti;
memset(ti, 0, sizeof(struct uci_type_list));
ti->next = type_list;
type_list = ti;
@@
-107,8
+112,12
@@
uci_lookup_section_ref(struct uci_section *s)
} else {
typestr = realloc(typestr, maxlen);
}
} else {
typestr = realloc(typestr, maxlen);
}
- sprintf(typestr, "@%s[%d]", ti->name, ti->idx);
+
+ if (typestr)
+ sprintf(typestr, "@%s[%d]", ti->name, ti->idx);
+
ti->idx++;
ti->idx++;
+
return typestr;
}
return typestr;
}
@@
-130,11
+139,13
@@
static void uci_usage(void)
"\tdelete <config>[.<section[.<option>]]\n"
"\trename <config>.<section>[.<option>]=<name>\n"
"\trevert <config>[.<section>[.<option>]]\n"
"\tdelete <config>[.<section[.<option>]]\n"
"\trename <config>.<section>[.<option>]=<name>\n"
"\trevert <config>[.<section>[.<option>]]\n"
+ "\treorder <config>.<section>=<position>\n"
"\n"
"Options:\n"
"\t-c <path> set the search path for config files (default: /etc/config)\n"
"\t-d <str> set the delimiter for list values in uci show\n"
"\t-f <file> use <file> as input instead of stdin\n"
"\n"
"Options:\n"
"\t-c <path> set the search path for config files (default: /etc/config)\n"
"\t-d <str> set the delimiter for list values in uci show\n"
"\t-f <file> use <file> as input instead of stdin\n"
+ "\t-L do not load any plugins\n"
"\t-m when importing, merge data into an existing package\n"
"\t-n name unnamed sections on export (default)\n"
"\t-N don't name unnamed sections\n"
"\t-m when importing, merge data into an existing package\n"
"\t-n name unnamed sections on export (default)\n"
"\t-N don't name unnamed sections\n"
@@
-143,6
+154,7
@@
static void uci_usage(void)
"\t-q quiet mode (don't print error messages)\n"
"\t-s force strict mode (stop on parser errors, default)\n"
"\t-S disable strict mode\n"
"\t-q quiet mode (don't print error messages)\n"
"\t-s force strict mode (stop on parser errors, default)\n"
"\t-S disable strict mode\n"
+ "\t-X do not use extended syntax on 'show'\n"
"\n",
appname
);
"\n",
appname
);
@@
-218,8
+230,8
@@
static void uci_show_changes(struct uci_package *p)
{
struct uci_element *e;
{
struct uci_element *e;
- uci_foreach_element(&p->saved_
history
, e) {
- struct uci_
history *h = uci_to_history
(e);
+ uci_foreach_element(&p->saved_
delta
, e) {
+ struct uci_
delta *h = uci_to_delta
(e);
char *prefix = "";
char *op = "=";
char *prefix = "";
char *op = "=";
@@
-246,6
+258,7
@@
static int package_cmd(int cmd, char *tuple)
{
struct uci_element *e = NULL;
struct uci_ptr ptr;
{
struct uci_element *e = NULL;
struct uci_ptr ptr;
+ int ret = 0;
if (uci_lookup_ptr(ctx, &ptr, tuple, true) != UCI_OK) {
cli_perror();
if (uci_lookup_ptr(ctx, &ptr, tuple, true) != UCI_OK) {
cli_perror();
@@
-260,8
+273,10
@@
static int package_cmd(int cmd, char *tuple)
case CMD_COMMIT:
if (flags & CLI_FLAG_NOCOMMIT)
return 0;
case CMD_COMMIT:
if (flags & CLI_FLAG_NOCOMMIT)
return 0;
- if (uci_commit(ctx, &ptr.p, false) != UCI_OK)
+ if (uci_commit(ctx, &ptr.p, false) != UCI_OK)
{
cli_perror();
cli_perror();
+ ret = 1;
+ }
break;
case CMD_EXPORT:
uci_export(ctx, stdout, ptr.p, true);
break;
case CMD_EXPORT:
uci_export(ctx, stdout, ptr.p, true);
@@
-270,7
+285,7
@@
static int package_cmd(int cmd, char *tuple)
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
- ret
urn
1;
+ ret
=
1;
}
switch(e->type) {
case UCI_TYPE_PACKAGE:
}
switch(e->type) {
case UCI_TYPE_PACKAGE:
@@
-289,8
+304,9
@@
static int package_cmd(int cmd, char *tuple)
break;
}
break;
}
- uci_unload(ctx, ptr.p);
- return 0;
+ if (ptr.p)
+ uci_unload(ctx, ptr.p);
+ return ret;
}
static int uci_do_import(int argc, char **argv)
}
static int uci_do_import(int argc, char **argv)
@@
-402,7
+418,7
@@
static int uci_do_section_cmd(int cmd, int argc, char **argv)
return 1;
}
return 1;
}
- if (ptr.value && (cmd != CMD_SET) && (cmd != CMD_ADD_LIST) && (cmd != CMD_RENAME))
+ if (ptr.value && (cmd != CMD_SET) && (cmd != CMD_ADD_LIST) && (cmd != CMD_RENAME)
&& (cmd != CMD_REORDER)
)
return 1;
e = ptr.last;
return 1;
e = ptr.last;
@@
-437,6
+453,14
@@
static int uci_do_section_cmd(int cmd, int argc, char **argv)
case CMD_ADD_LIST:
ret = uci_add_list(ctx, &ptr);
break;
case CMD_ADD_LIST:
ret = uci_add_list(ctx, &ptr);
break;
+ case CMD_REORDER:
+ if (!ptr.s || !ptr.value) {
+ ctx->err = UCI_ERR_NOTFOUND;
+ cli_perror();
+ return 1;
+ }
+ ret = uci_reorder_section(ctx, ptr.s, strtoul(ptr.value, NULL, 10));
+ break;
case CMD_DEL:
ret = uci_delete(ctx, &ptr);
break;
case CMD_DEL:
ret = uci_delete(ctx, &ptr);
break;
@@
-460,7
+484,7
@@
static int uci_do_section_cmd(int cmd, int argc, char **argv)
static int uci_batch_cmd(void)
{
static int uci_batch_cmd(void)
{
- char *argv[MAX_ARGS];
+ char *argv[MAX_ARGS
+ 2
];
char *str = NULL;
int ret = 0;
int i, j;
char *str = NULL;
int ret = 0;
int i, j;
@@
-548,6
+572,8
@@
static int uci_cmd(int argc, char **argv)
cmd = CMD_RENAME;
else if (!strcasecmp(argv[0], "revert"))
cmd = CMD_REVERT;
cmd = CMD_RENAME;
else if (!strcasecmp(argv[0], "revert"))
cmd = CMD_REVERT;
+ else if (!strcasecmp(argv[0], "reorder"))
+ cmd = CMD_REORDER;
else if (!strcasecmp(argv[0], "del") ||
!strcasecmp(argv[0], "delete"))
cmd = CMD_DEL;
else if (!strcasecmp(argv[0], "del") ||
!strcasecmp(argv[0], "delete"))
cmd = CMD_DEL;
@@
-569,6
+595,7
@@
static int uci_cmd(int argc, char **argv)
case CMD_DEL:
case CMD_RENAME:
case CMD_REVERT:
case CMD_DEL:
case CMD_RENAME:
case CMD_REVERT:
+ case CMD_REORDER:
return uci_do_section_cmd(cmd, argc, argv);
case CMD_SHOW:
case CMD_EXPORT:
return uci_do_section_cmd(cmd, argc, argv);
case CMD_SHOW:
case CMD_EXPORT:
@@
-592,6
+619,7
@@
int main(int argc, char **argv)
int ret;
int c;
int ret;
int c;
+ flags = CLI_FLAG_SHOW_EXT;
appname = argv[0];
input = stdin;
ctx = uci_alloc_context();
appname = argv[0];
input = stdin;
ctx = uci_alloc_context();
@@
-600,7
+628,7
@@
int main(int argc, char **argv)
return 1;
}
return 1;
}
- while((c = getopt(argc, argv, "c:d:f:
mnNp:P:sSq
")) != -1) {
+ while((c = getopt(argc, argv, "c:d:f:
LmnNp:P:sSqX
")) != -1) {
switch(c) {
case 'c':
uci_set_confdir(ctx, optarg);
switch(c) {
case 'c':
uci_set_confdir(ctx, optarg);
@@
-609,12
+637,20
@@
int main(int argc, char **argv)
delimiter = optarg;
break;
case 'f':
delimiter = optarg;
break;
case 'f':
+ if (input != stdin) {
+ perror("uci");
+ return 1;
+ }
+
input = fopen(optarg, "r");
if (!input) {
perror("uci");
return 1;
}
break;
input = fopen(optarg, "r");
if (!input) {
perror("uci");
return 1;
}
break;
+ case 'L':
+ flags |= CLI_FLAG_NOPLUGINS;
+ break;
case 'm':
flags |= CLI_FLAG_MERGE;
break;
case 'm':
flags |= CLI_FLAG_MERGE;
break;
@@
-632,16
+668,19
@@
int main(int argc, char **argv)
ctx->flags &= ~UCI_FLAG_EXPORT_NAME;
break;
case 'p':
ctx->flags &= ~UCI_FLAG_EXPORT_NAME;
break;
case 'p':
- uci_add_
history
_path(ctx, optarg);
+ uci_add_
delta
_path(ctx, optarg);
break;
case 'P':
break;
case 'P':
- uci_add_
history
_path(ctx, ctx->savedir);
+ uci_add_
delta
_path(ctx, ctx->savedir);
uci_set_savedir(ctx, optarg);
flags |= CLI_FLAG_NOCOMMIT;
break;
case 'q':
flags |= CLI_FLAG_QUIET;
break;
uci_set_savedir(ctx, optarg);
flags |= CLI_FLAG_NOCOMMIT;
break;
case 'q':
flags |= CLI_FLAG_QUIET;
break;
+ case 'X':
+ flags &= ~CLI_FLAG_SHOW_EXT;
+ break;
default:
uci_usage();
return 0;
default:
uci_usage();
return 0;
@@
-656,13
+695,16
@@
int main(int argc, char **argv)
uci_usage();
return 0;
}
uci_usage();
return 0;
}
+
+ if (!(flags & CLI_FLAG_NOPLUGINS))
+ uci_load_plugins(ctx, NULL);
+
ret = uci_cmd(argc - 1, argv + 1);
if (input != stdin)
fclose(input);
ret = uci_cmd(argc - 1, argv + 1);
if (input != stdin)
fclose(input);
- if (ret == 255) {
+
+ if (ret == 255)
uci_usage();
uci_usage();
- return 0;
- }
uci_free_context(ctx);
uci_free_context(ctx);