[Xorp-hackers] [PATCH] xorp: rtrmgr: Fix command completion with %allow-range option on multi-value nodes
igorm at etf.rs
igorm at etf.rs
Tue Mar 13 03:55:50 PDT 2012
From: Igor Maravic <igorm at etf.rs>
Fixed problem of command completion for multi-value nodes with allow-range option.
Without this fix, if we would enter number within the allowed range, and then we would enter
" " + "\t" we wouldn't get any command propositions.
Signed-off-by: Igor Maravic <igorm at etf.rs>
---
xorp/rtrmgr/template_tree.cc | 45 +++++++++++++++++++++++++++++++-----
xorp/rtrmgr/template_tree_node.cc | 6 ++--
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/xorp/rtrmgr/template_tree.cc b/xorp/rtrmgr/template_tree.cc
index fa04132..08c9280 100644
--- a/xorp/rtrmgr/template_tree.cc
+++ b/xorp/rtrmgr/template_tree.cc
@@ -38,6 +38,17 @@
#include "template_tree.hh"
#include "template_tree_node.hh"
+#ifdef HAVE_REGEX_H
+# include <regex.h>
+#else // ! HAVE_REGEX_H
+# ifdef HAVE_PCRE_H
+# include <pcre.h>
+# endif
+# ifdef HAVE_PCREPOSIX_H
+# include <pcreposix.h>
+# endif
+#endif // ! HAVE_REGEX_H
+
#ifdef HOST_OS_WINDOWS
#define stat _stat
@@ -422,18 +433,38 @@ TemplateTree::find_node(const list<string>& path_segments) const
// There's no exact name match, so we're probably looking for a
// match of an encoded typestr or a value against a typed variable.
for (ti = ttn->children().begin(); ti != ttn->children().end(); ++ti) {
- TemplateTreeNode* t = *ti;
- if (t->type() == NODE_VOID)
+ TemplateTreeNode* t = *ti;
+ if (t->type() == NODE_VOID)
continue;
- if ((t->parent() == NULL) || (! t->parent()->is_tag()))
+ if ((t->parent() == NULL) || (! t->parent()->is_tag()))
continue;
- if (t->encoded_typestr() == segname) {
+ if (t->encoded_typestr() == segname) {
matches.push_back(t);
continue;
- }
- string s;
- if (t->type_match(segname, s))
+ }
+
+ /**
+ * Check if this segname represents some kind of range.
+ * If it does, it will match regexp below, and we
+ * are expecting t->encoded_typestr to be "<uint>" or "<uint64>" or "<int>"
+ */
+ regex_t range_reg;
+ if (regcomp(&range_reg, "[\[][-]{0,1}[0-9]+[.][.][-]{0,1}[0-9]+]", REG_EXTENDED))
+ XLOG_UNREACHABLE();
+
+ bool is_range = !regexec(&range_reg, segname.c_str(), 0, 0, 0);
+ regfree(&range_reg);
+ if (is_range &&
+ (t->encoded_typestr() == "<uint>"
+ || t->encoded_typestr() == "<int>"
+ || t->encoded_typestr() == "<uint64>")) {
matches.push_back(t);
+ continue;
+ }
+
+ string s;
+ if (t->type_match(segname, s))
+ matches.push_back(t);
}
if (matches.size() == 0)
return NULL;
diff --git a/xorp/rtrmgr/template_tree_node.cc b/xorp/rtrmgr/template_tree_node.cc
index 7ae9698..4c858e8 100644
--- a/xorp/rtrmgr/template_tree_node.cc
+++ b/xorp/rtrmgr/template_tree_node.cc
@@ -1471,7 +1471,7 @@ UIntTemplate::type_match(const string& orig, string& error_msg) const
return false;
}
}
- return true;
+ return check_allowed_value(orig, error_msg);
}
string
@@ -1585,7 +1585,7 @@ ULongTemplate::type_match(const string& orig, string& error_msg) const
return false;
}
}
- return true;
+ return check_allowed_value(orig, error_msg);
}
string
@@ -1703,7 +1703,7 @@ IntTemplate::type_match(const string& orig, string& error_msg) const
}
return false;
}
- return true;
+ return check_allowed_value(orig, error_msg);
}
string
--
1.7.5.4
More information about the Xorp-hackers
mailing list