[asterisk-commits] trunk - r7660 /trunk/pbx.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Dec 27 13:59:10 CST 2005
Author: russell
Date: Tue Dec 27 13:59:09 2005
New Revision: 7660
URL: http://svn.digium.com/view/asterisk?rev=7660&view=rev
Log:
avoid duplicate strlen calls for the command completion functions for
'show application' and 'show applications'
Modified:
trunk/pbx.c
Modified: trunk/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx.c?rev=7660&r1=7659&r2=7660&view=diff
==============================================================================
--- trunk/pbx.c (original)
+++ trunk/pbx.c Tue Dec 27 13:59:09 2005
@@ -2957,11 +2957,12 @@
* application at one time. You can type 'show application Dial Echo' and
* you will see informations about these two applications ...
*/
-static char *complete_show_application(char *line, char *word,
- int pos, int state)
+static char *complete_show_application(char *line, char *word, int pos, int state)
{
struct ast_app *a;
+ char *ret = NULL;
int which = 0;
+ int wordlen = strlen(word);
/* try to lock applications list ... */
if (ast_mutex_lock(&applock)) {
@@ -2972,19 +2973,18 @@
/* ... walk all applications ... */
for (a = apps; a; a = a->next) {
/* ... check if word matches this application ... */
- if (!strncasecmp(word, a->name, strlen(word))) {
+ if (!strncasecmp(word, a->name, wordlen)) {
/* ... if this is right app serve it ... */
if (++which > state) {
- char *ret = strdup(a->name);
- ast_mutex_unlock(&applock);
- return ret;
+ ret = strdup(a->name);
+ break;
}
}
}
- /* no application match */
ast_mutex_unlock(&applock);
- return NULL;
+
+ return ret;
}
static int handle_show_application(int fd, int argc, char *argv[])
@@ -3198,6 +3198,8 @@
static char *complete_show_applications(char *line, char *word, int pos, int state)
{
+ int wordlen = strlen(word);
+
if (pos == 2) {
if (ast_strlen_zero(word)) {
switch (state) {
@@ -3208,13 +3210,13 @@
default:
return NULL;
}
- } else if (! strncasecmp(word, "like", strlen(word))) {
+ } else if (! strncasecmp(word, "like", wordlen)) {
if (state == 0) {
return strdup("like");
} else {
return NULL;
}
- } else if (! strncasecmp(word, "describing", strlen(word))) {
+ } else if (! strncasecmp(word, "describing", wordlen)) {
if (state == 0) {
return strdup("describing");
} else {
More information about the asterisk-commits
mailing list