Skip to content

Commit

Permalink
xorp: rtrmgr: Fix command completion with %allow-range option on mult…
Browse files Browse the repository at this point in the history
…i-value nodes

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@etf.rs>
  • Loading branch information
Igor Maravic authored and greearb committed Mar 15, 2012
1 parent 535e294 commit ad8f554
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
34 changes: 33 additions & 1 deletion xorp/rtrmgr/template_tree.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions xorp/rtrmgr/template_tree_node.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1705,7 +1705,7 @@ IntTemplate::type_match(const string& orig, string& error_msg) const
}
return false;
}
return true;
return check_allowed_value(orig, error_msg);
}

string
Expand Down

0 comments on commit ad8f554

Please sign in to comment.