[asterisk-commits] rizzo: trunk r47813 - /trunk/main/cli.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 17 14:50:55 MST 2006


Author: rizzo
Date: Fri Nov 17 15:50:55 2006
New Revision: 47813

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47813
Log:
describe a bit the patterns that you can have in the commands,
and add support for wildcard (spelled as '%').

On passing fix a bug in the expansion code which was hidden and
appeared when implementing the wildcard
The fix is just the line 'src != argindex', in case someone wants
to test this on 1.4 - but i would just keep this in trunk.


Modified:
    trunk/main/cli.c

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=47813&r1=47812&r2=47813
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Fri Nov 17 15:50:55 2006
@@ -1036,7 +1036,7 @@
 /*!
  * Some regexp characters in cli arguments are reserved and used as separators.
  */
-static const char cli_rsvd[] = "[]{}|*";
+static const char cli_rsvd[] = "[]{}|*%";
 
 /*!
  * initialize the _full_cmd string and related parameters,
@@ -1111,6 +1111,12 @@
  * match a word in the CLI entry.
  * returns -1 on mismatch, 0 on match of an optional word,
  * 1 on match of a full word.
+ *
+ * The pattern can be
+ *   any_word		match for equal
+ *   [foo|bar|baz]	optionally, one of these words
+ *   {foo|bar|baz}	exactly, one of these words
+ *   %			any word
  */
 static int word_match(const char *cmd, const char *cli_word)
 {
@@ -1123,6 +1129,10 @@
 		return (strcasecmp(cmd, cli_word) == 0) ? 1 : -1;
 	/* regexp match, takes [foo|bar] or {foo|bar} */
 	l = strlen(cmd);
+	/* wildcard match - will extend in the future */
+	if (l > 0 && cli_word[0] == '%') {
+		return 1;	/* wildcard */
+	}
 	pos = strcasestr(cli_word, cmd);
 	if (pos == NULL) /* not found, say ok if optional */
 		return cli_word[0] == '[' ? 0 : -1;
@@ -1158,8 +1168,13 @@
 		return (pos != 0) ? NULL : strdup(token);
 	}
 	/* now handle regexp match */
+
+	/* Wildcard always matches, so we never do is_prefix on them */
+
 	t1 = ast_strdupa(token + 1);	/* copy, skipping first char */
 	while (pos >= 0 && (s = strsep(&t1, cli_rsvd)) && *s) {
+		if (*s == '%')	/* wildcard */
+			continue;
 		if (strncasecmp(s, word, lw))	/* no match */
 			continue;
 		(*actual)++;
@@ -1608,7 +1623,7 @@
 				break;
 		}
 
-		if (src < argindex)	/* not a match */
+		if (src != argindex)	/* not a match */
 			continue;
 		ret = is_prefix(argv[src], e->cmda[dst], state - matchnum, &n);
 		matchnum += n;	/* this many matches here */



More information about the asterisk-commits mailing list