[Xorp-hackers] [PATCH] xorp: rtrmgr: Fix command completion with %allow-range option on multi-value nodes

igorm at etf.rs igorm at etf.rs
Thu Mar 15 05:42:10 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      |   34 +++++++++++++++++++++++++++++++++-
 xorp/rtrmgr/template_tree_node.cc |    6 +++---
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/xorp/rtrmgr/template_tree.cc b/xorp/rtrmgr/template_tree.cc
index fa04132..6134a30 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
@@ -425,12 +436,33 @@ TemplateTree::find_node(const list<string>& path_segments) const
 	    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) {
 		matches.push_back(t);
 		continue;
 	    }
+
+	    /**
+	     * 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);
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