From 9a06bd552126d69db40d30779cfc49404e42d761 Mon Sep 17 00:00:00 2001 From: John Southworth Date: Sat, 28 Jan 2012 12:25:52 -0800 Subject: Add ability to differentiate between node types in help text --- src/cli_shell_api.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'src') diff --git a/src/cli_shell_api.cpp b/src/cli_shell_api.cpp index 18d3db7..aa8eafd 100644 --- a/src/cli_shell_api.cpp +++ b/src/cli_shell_api.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -228,6 +229,84 @@ existsEffective(Cstore& cstore, const Cpath& args) exit(cstore.cfgPathEffective(args) ? 0 : 1); } +/* isMulti */ +static void +isMulti(Cstore& cstore, const Cpath& args) +{ + MapT tmap; + cstore.getParsedTmpl(args, tmap, 0); + string multi = tmap["multi"]; + exit((multi == "1") ? 0 : 1); +} + +/* isTag */ +static void +isTag(Cstore& cstore, const Cpath& args) +{ + MapT tmap; + cstore.getParsedTmpl(args, tmap, 0); + string tag = tmap["tag"]; + exit((tag == "1") ? 0 : 1); +} + +/* isValue */ +static void +isValue(Cstore& cstore, const Cpath& args) +{ + MapT tmap; + cstore.getParsedTmpl(args, tmap, 0); + string is_value = tmap["is_value"]; + exit((is_value == "1") ? 0 : 1); +} + +/* isLeaf */ +static void +isLeaf(Cstore& cstore, const Cpath& args) +{ + MapT tmap; + bool is_leaf_typeless = false; + tmap["type"] = ""; + cstore.getParsedTmpl(args, tmap, 0); + string is_value = tmap["is_value"]; + string tag = tmap["tag"]; + string type = tmap["type"]; + vector tcnodes; + cstore.tmplGetChildNodes(args, tcnodes); + if (tcnodes.size() == 0) { + // typeless leaf node + is_leaf_typeless = true; + } + exit(((is_value != "1") && (tag != "1") && (type != "" || is_leaf_typeless)) ? 0 : 1); +} + +static void getNodeType(Cstore& cstore, const Cpath& args) { + MapT tmap; + bool is_leaf_typeless = false; + tmap["type"] = ""; + cstore.getParsedTmpl(args, tmap, 0); + string is_value = tmap["is_value"]; + string tag = tmap["tag"]; + string type = tmap["type"]; + string multi = tmap["multi"]; + vector tcnodes; + cstore.tmplGetChildNodes(args, tcnodes); + if (tcnodes.size() == 0) { + // typeless leaf node + is_leaf_typeless = true; + } + if (tag == "1") { + printf("tag"); + } else if (!((is_value != "1") && (tag != "1") && (type != "" || is_leaf_typeless))) { + printf("non-leaf"); + } else if (multi == "1") { + printf("multi"); + } else { + printf("leaf"); + } + exit(0); + +} + /* same as listNodes() in Perl API. * * outputs a string representing multiple nodes. this string MUST be @@ -579,6 +658,12 @@ static OpT ops[] = { OP(listActiveNodes, -1, NULL, -1, NULL, false), OP(listEffectiveNodes, -1, NULL, 1, "Must specify config path", false), + OP(isMulti, -1, NULL, 1, "Must specify config path", false), + OP(isTag, -1, NULL, 1, "Must specify config path", false), + OP(isLeaf, -1, NULL, 1, "Must specify config path", false), + OP(isValue, -1, NULL, 1, "Must specify config path", false), + OP(getNodeType, -1, NULL, 1, "Must specify config path", false), + OP(returnValue, -1, NULL, 1, "Must specify config path", false), OP(returnActiveValue, -1, NULL, 1, "Must specify config path", false), OP(returnEffectiveValue, -1, NULL, 1, "Must specify config path", false), -- cgit v1.2.3