* subcommand: one of a list of subcommands.
* Any unique prefix of a tag is allowed to match.
*/
-enum argtype { flag, opaque, choice, external, internal, subcommand, terminal };
+enum argtype { flag, opaque, choice, external, internal, subcommand};
static struct args {
char *tag;
enum argtype type;
union { struct cmd *subcmd; char **options; };
char *desc;
} lafs_args[];
-#define TERMINAL_ARG {NULL, terminal, 0, {NULL}, NULL}
+#define TERMINAL_ARG {NULL, opaque, 0, {NULL}, NULL}
/* When a positional parameter is identified as 'subcommand' it is associated
* with a list of 'struct cmd' identifying the possible subcommands.
int i;
int best = -1;
- for (i = 0; args[i].type != terminal; i++)
+ for (i = 0; args[i].tag; i++)
if (args[i].tag[0] == '-') {
if (strncmp(tag, args[i].tag+1, len) != 0)
continue;
if (lastp)
*lastp = -1;
- for (i = 0; args[i].type != terminal; i++)
+ for (i = 0; args[i].tag; i++)
;
rv = calloc(i+offset, sizeof(char*));
size = i+offset;
} else {
/* must be next positional */
for (i=0;
- args[i].tag[0] != '-' && args[i].type != terminal;
+ args[i].tag && args[i].tag[0] != '-';
i++)
if (rv[i+offset] == NULL)
break;
- if (args[i].tag[0] == '-' || args[i].type == terminal) {
+ if (args[i].tag == NULL || args[i].tag[0] == '-') {
/* No positions left */
asprintf(error, "Extra positional parameter: %s", w);
break;
offset += i+1;
if (lastp)
*lastp = -1;
- for (i = 0; args[i].type != terminal; i++)
+ for (i = 0; args[i].tag; i++)
;
rv = realloc(rv, (i+offset) * sizeof(void*));
while (size < i + offset) {
prefix++;
len = strlen(prefix);
- for ( ; gen_args[next].type != terminal; next++) {
+ for ( ; gen_args[next].tag; next++) {
char *c;
if (gen_args[next].tag[0] != '-')
continue;
p = last;
else {
last = -1;
- for (p = 0; args[p].tag[0] != '-' && args[p].pos != terminal; p++)
+ for (p = 0; args[p].tag && args[p].tag[0] != '-' ; p++)
if (arglist[p+offset] == NULL)
break;
- if (args[p].tag[0] == '-' || args[p].pos == terminal)
+ if (args[p].tag == NULL || args[p].tag[0] == '-')
p = -1;
}
/* 'p' is the arg we expect here, either first positional arg that
* Here are the commands.
* Each command X must define
* static char help_X = "One line of description for the command";
+
* static struct args args_X[] = { list of arg definitions; TERMINAL_ARG};
* static void c_X(struct state *st, void *args) { implement command ;}
* and must be listed in lafs_cmds below.
if (cmd) {
printf("%s: %s\n", cmd->name, cmd->help);
- if (cmd->args[0].type != terminal) {
+ if (cmd->args[0].tag) {
int i;
printf(" Usage: %s", cmd->name);
- for (i=0; cmd->args[i].type != terminal; i++) {
+ for (i=0; cmd->args[i].tag; i++) {
struct args *a = cmd->args+i;
if (a->tag[0] == '-') {
printf(" [--options...]");
}
printf("\n");
printf(" Arguments:\n");
- for (i=0; cmd->args[i].type != terminal; i++) {
+ for (i=0; cmd->args[i].tag; i++) {
struct args *a = cmd->args+i;
if (a->tag[0] != '-') {
printf(" %-15s: %s\n", a->tag, a->desc);