mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 21:50:39 +00:00
lib: Macroize CLI matcher tracing
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
d6c9cdd0dd
commit
54c5dce6a5
@ -27,6 +27,15 @@
|
|||||||
#include "command_match.h"
|
#include "command_match.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#ifdef TRACE_MATCHER
|
||||||
|
#define TM 1
|
||||||
|
#else
|
||||||
|
#define TM 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define trace_matcher(...) \
|
||||||
|
do { if (TM) fprintf (stderr, __VA_ARGS__); } while (0);
|
||||||
|
|
||||||
DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command Tokens")
|
DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command Tokens")
|
||||||
|
|
||||||
/* matcher helper prototypes */
|
/* matcher helper prototypes */
|
||||||
@ -115,12 +124,12 @@ command_match (struct graph *cmdgraph,
|
|||||||
assert (*el);
|
assert (*el);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACE_MATCHER
|
if (!*el) {
|
||||||
if (!*el)
|
trace_matcher ("No match");
|
||||||
fprintf (stdout, "No match\n");
|
}
|
||||||
else
|
else {
|
||||||
fprintf (stdout, "Matched command\n->string %s\n->desc %s\n", (*el)->string, (*el)->doc);
|
trace_matcher ("Matched command\n->string %s\n->desc %s\n", (*el)->string, (*el)->doc);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
// free the leader token we alloc'd
|
// free the leader token we alloc'd
|
||||||
XFREE (MTYPE_TMP, vector_slot (vvline, 0));
|
XFREE (MTYPE_TMP, vector_slot (vvline, 0));
|
||||||
@ -193,28 +202,26 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
|
|||||||
// get the current operating input token
|
// get the current operating input token
|
||||||
char *input_token = vector_slot (vline, n);
|
char *input_token = vector_slot (vline, n);
|
||||||
|
|
||||||
#ifdef TRACE_MATCHER
|
trace_matcher ("\"%-20s\" matches \"%-30s\" ? ", input_token, token->text);
|
||||||
fprintf (stdout, "\"%-20s\" matches \"%-30s\" ? ", input_token, token->text);
|
|
||||||
enum match_type mt = match_token (token, input_token);
|
enum match_type mt = match_token (token, input_token);
|
||||||
fprintf (stdout, "min: %d - ", minmatch);
|
trace_matcher ("min: %d - ", minmatch);
|
||||||
switch (mt)
|
switch (mt)
|
||||||
{
|
{
|
||||||
case trivial_match:
|
case trivial_match:
|
||||||
fprintf (stdout, "trivial_match ");
|
trace_matcher ("trivial_match ");
|
||||||
break;
|
break;
|
||||||
case no_match:
|
case no_match:
|
||||||
fprintf (stdout, "no_match ");
|
trace_matcher ("no_match ");
|
||||||
break;
|
break;
|
||||||
case partly_match:
|
case partly_match:
|
||||||
fprintf (stdout, "partly_match ");
|
trace_matcher ("partly_match ");
|
||||||
break;
|
break;
|
||||||
case exact_match:
|
case exact_match:
|
||||||
fprintf (stdout, "exact_match ");
|
trace_matcher ("exact_match ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mt >= minmatch) fprintf (stdout, " MATCH");
|
if (mt >= minmatch) { trace_matcher (" MATCH") };
|
||||||
fprintf (stdout, "\n");
|
trace_matcher ("\n");
|
||||||
#endif
|
|
||||||
|
|
||||||
// if we don't match this node, die
|
// if we don't match this node, die
|
||||||
if (match_token (token, input_token) < minmatch)
|
if (match_token (token, input_token) < minmatch)
|
||||||
@ -344,37 +351,35 @@ command_complete (struct graph *graph,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
enum match_type minmatch = min_match_level (token->type);
|
enum match_type minmatch = min_match_level (token->type);
|
||||||
#ifdef TRACE_MATCHER
|
trace_matcher ("\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
|
||||||
fprintf (stdout, "\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (match_token (token, input_token))
|
switch (match_token (token, input_token))
|
||||||
{
|
{
|
||||||
case trivial_match:
|
case trivial_match:
|
||||||
#ifdef TRACE_MATCHER
|
trace_matcher ("trivial_match\n");
|
||||||
fprintf (stdout, "trivial_match\n");
|
assert(idx == vector_active (vline) - 1);
|
||||||
#endif
|
listnode_add (next, gn);
|
||||||
|
break;
|
||||||
case partly_match:
|
case partly_match:
|
||||||
#ifdef TRACE_MATCHER
|
trace_matcher ("partly_match\n");
|
||||||
fprintf (stdout, "partly_match\n");
|
// last token on line is partial and
|
||||||
#endif
|
// not a space
|
||||||
if (idx == vector_active (vline) - 1)
|
if (idx == vector_active (vline) - 1)
|
||||||
{
|
{
|
||||||
listnode_add (next, gn);
|
listnode_add (next, gn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (minmatch > partly_match)
|
if (minmatch <= partly_match)
|
||||||
break;
|
add_nexthops (next, gn);
|
||||||
|
|
||||||
|
break;
|
||||||
case exact_match:
|
case exact_match:
|
||||||
#ifdef TRACE_MATCHER
|
trace_matcher ("exact_match\n");
|
||||||
fprintf (stdout, "exact_match\n");
|
|
||||||
#endif
|
|
||||||
add_nexthops (next, gn);
|
add_nexthops (next, gn);
|
||||||
|
listnode_add (next, gn);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#ifdef TRACE_MATCHER
|
trace_matcher ("no_match\n");
|
||||||
fprintf (stdout, "no_match\n");
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user