[asterisk-commits] trunk - r7693 /trunk/pbx.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sun Jan 1 11:50:39 CST 2006
Author: russell
Date: Sun Jan 1 11:50:37 2006
New Revision: 7693
URL: http://svn.digium.com/view/asterisk?rev=7693&view=rev
Log:
clean up some loops and replace some duplicate code with a for loop (issue #6100)
Modified:
trunk/pbx.c
Modified: trunk/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx.c?rev=7693&r1=7692&r2=7693&view=diff
==============================================================================
--- trunk/pbx.c (original)
+++ trunk/pbx.c Sun Jan 1 11:50:37 2006
@@ -1207,13 +1207,10 @@
return NULL;
}
- for (acf = acf_root; acf; acf = acf->next) {
- if (!strncasecmp(word, acf->name, wordlen)) {
- if (++which > state) {
- ret = strdup(acf->name);
- break;
- }
- }
+ /* case-insensitive for convenience in this 'complete' function */
+ for (acf = acf_root; acf && !ret; acf = acf->next) {
+ if (!strncasecmp(word, acf->name, wordlen) && ++which > state)
+ ret = strdup(acf->name);
}
ast_mutex_unlock(&acflock);
@@ -1232,9 +1229,8 @@
}
for (acfptr = acf_root; acfptr; acfptr = acfptr->next) {
- if (!strcmp(name, acfptr->name)) {
+ if (!strcmp(name, acfptr->name))
break;
- }
}
ast_mutex_unlock(&acflock);
@@ -2970,16 +2966,10 @@
return NULL;
}
- /* ... walk all applications ... */
- for (a = apps; a; a = a->next) {
- /* ... check if word matches this application ... */
- if (!strncasecmp(word, a->name, wordlen)) {
- /* ... if this is right app serve it ... */
- if (++which > state) {
- ret = strdup(a->name);
- break;
- }
- }
+ /* return the n-th [partial] matching entry */
+ for (a = apps; a && !ret; a = a->next) {
+ if (!strncasecmp(word, a->name, wordlen) && ++which > state)
+ ret = strdup(a->name);
}
ast_mutex_unlock(&applock);
@@ -5701,22 +5691,17 @@
const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
{
struct ast_var_t *variables;
- struct varshead *headp;
-
+ int i;
+ struct varshead *places[2] = { NULL, &globals };
+
+ if (!name)
+ return NULL;
if (chan)
- headp=&chan->varshead;
- else
- headp=&globals;
-
- if (name) {
- AST_LIST_TRAVERSE(headp,variables,entries) {
- if (!strcmp(name, ast_var_name(variables)))
- return ast_var_value(variables);
- }
- if (headp != &globals) {
- /* Check global variables if we haven't already */
- headp = &globals;
- AST_LIST_TRAVERSE(headp,variables,entries) {
+ places[0] = &chan->varshead;
+
+ for (i = 0; i < 2; i++) {
+ if (places[i]) {
+ AST_LIST_TRAVERSE(places[i], variables, entries) {
if (!strcmp(name, ast_var_name(variables)))
return ast_var_value(variables);
}
More information about the asterisk-commits
mailing list