-/* $OpenBSD: parser.c,v 1.124 2023/04/13 11:52:43 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.125 2023/04/15 10:36:59 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
#include "parser.h"
enum token_type {
- NOTOKEN,
ENDTOKEN,
+ NOTOKEN,
+ ANYTOKEN,
KEYWORD,
ADDRESS,
PEERADDRESS,
const struct token *next;
};
+static const struct token *prevtable;
+
static const struct token t_main[];
static const struct token t_show[];
static const struct token t_show_summary[];
};
static const struct token t_show_prefix[] = {
- { NOTOKEN, "", NONE, NULL},
- { FLAG, "all", F_LONGER, NULL},
- { FLAG, "longer-prefixes", F_LONGER, NULL},
- { FLAG, "or-longer", F_LONGER, NULL},
- { FLAG, "or-shorter", F_SHORTER, NULL},
+ { FLAG, "all", F_LONGER, t_show_rib},
+ { FLAG, "longer-prefixes", F_LONGER, t_show_rib},
+ { FLAG, "or-longer", F_LONGER, t_show_rib},
+ { FLAG, "or-shorter", F_SHORTER, t_show_rib},
+ { ANYTOKEN, "", NONE, t_show_rib},
{ ENDTOKEN, "", NONE, NULL}
};
show_valid_args(table);
return (NULL);
}
+ if (match->type == ANYTOKEN) {
+ if (prevtable == NULL)
+ prevtable = table;
+ table = match->next;
+ continue;
+ }
argc--;
argv++;
t = &table[i];
}
break;
+ case ANYTOKEN:
+ /* match anything if nothing else matched before */
+ if (match == 0) {
+ match++;
+ t = &table[i];
+ }
+ break;
case KEYWORD:
if (word != NULL && strncmp(word, table[i].keyword,
wordlen) == 0) {
{
int i;
+ if (prevtable != NULL) {
+ const struct token *t = prevtable;
+ prevtable = NULL;
+ show_valid_args(t);
+ fprintf(stderr, "or any of\n");
+ }
+
for (i = 0; table[i].type != ENDTOKEN; i++) {
switch (table[i].type) {
case NOTOKEN:
fprintf(stderr, " <cr>\n");
break;
+ case ANYTOKEN:
+ break;
case KEYWORD:
case FLAG:
case ASTYPE: