summaryrefslogtreecommitdiff
path: root/tools/permutations.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2021-08-26 11:43:08 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2021-08-26 21:03:44 +0200
commit90c8406c209a698ecc28c80ad7ebced13a84e3e8 (patch)
tree74bedac5f4d8c3bc5b1bdfb42e6eefaa001d714c /tools/permutations.c
parent3e324ff41921c719de3aabc4136546828416532f (diff)
lib: add `![...]` syntax for easy "no" forms
This allows defining a CLI command like this: `[no] some setting ![VALUE]` with VALUE being optional for the "no" form, but required for the positive form. It's just a `[...]` where the empty branch can only be taken for commands starting with `no`. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tools/permutations.c')
-rw-r--r--tools/permutations.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/permutations.c b/tools/permutations.c
index f51d4a4ec9..b280cc15b1 100644
--- a/tools/permutations.c
+++ b/tools/permutations.c
@@ -61,9 +61,22 @@ void permute(struct graph_node *start)
struct cmd_token *stok = start->data;
struct graph_node *gnn;
struct listnode *ln;
+ bool is_neg = false;
// recursive dfs
listnode_add(position, start);
+
+ for (ALL_LIST_ELEMENTS_RO(position, ln, gnn)) {
+ struct cmd_token *tok = gnn->data;
+
+ if (tok->type == WORD_TKN && !strcmp(tok->text, "no")) {
+ is_neg = true;
+ break;
+ }
+ if (tok->type < SPECIAL_TKN)
+ break;
+ }
+
for (unsigned int i = 0; i < vector_active(start->to); i++) {
struct graph_node *gn = vector_slot(start->to, i);
struct cmd_token *tok = gn->data;
@@ -82,6 +95,9 @@ void permute(struct graph_node *start)
fprintf(stdout, "\n");
} else {
bool skip = false;
+
+ if (tok->type == NEG_ONLY_TKN && !is_neg)
+ continue;
if (stok->type == FORK_TKN && tok->type != FORK_TKN)
for (ALL_LIST_ELEMENTS_RO(position, ln, gnn))
if (gnn == gn) {