mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 16:20:37 +00:00
clean up some loops and replace some duplicate code with a for loop (issue #6100)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7693 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
45
pbx.c
45
pbx.c
@@ -1207,13 +1207,10 @@ static char *complete_show_function(char *line, char *word, int pos, int state)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (acf = acf_root; acf; acf = acf->next) {
|
/* case-insensitive for convenience in this 'complete' function */
|
||||||
if (!strncasecmp(word, acf->name, wordlen)) {
|
for (acf = acf_root; acf && !ret; acf = acf->next) {
|
||||||
if (++which > state) {
|
if (!strncasecmp(word, acf->name, wordlen) && ++which > state)
|
||||||
ret = strdup(acf->name);
|
ret = strdup(acf->name);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_mutex_unlock(&acflock);
|
ast_mutex_unlock(&acflock);
|
||||||
@@ -1232,10 +1229,9 @@ struct ast_custom_function* ast_custom_function_find(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (acfptr = acf_root; acfptr; acfptr = acfptr->next) {
|
for (acfptr = acf_root; acfptr; acfptr = acfptr->next) {
|
||||||
if (!strcmp(name, acfptr->name)) {
|
if (!strcmp(name, acfptr->name))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ast_mutex_unlock(&acflock);
|
ast_mutex_unlock(&acflock);
|
||||||
|
|
||||||
@@ -2970,16 +2966,10 @@ static char *complete_show_application(char *line, char *word, int pos, int stat
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... walk all applications ... */
|
/* return the n-th [partial] matching entry */
|
||||||
for (a = apps; a; a = a->next) {
|
for (a = apps; a && !ret; a = a->next) {
|
||||||
/* ... check if word matches this application ... */
|
if (!strncasecmp(word, a->name, wordlen) && ++which > state)
|
||||||
if (!strncasecmp(word, a->name, wordlen)) {
|
|
||||||
/* ... if this is right app serve it ... */
|
|
||||||
if (++which > state) {
|
|
||||||
ret = strdup(a->name);
|
ret = strdup(a->name);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_mutex_unlock(&applock);
|
ast_mutex_unlock(&applock);
|
||||||
@@ -5701,22 +5691,17 @@ int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t
|
|||||||
const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
|
const char *pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
|
||||||
{
|
{
|
||||||
struct ast_var_t *variables;
|
struct ast_var_t *variables;
|
||||||
struct varshead *headp;
|
int i;
|
||||||
|
struct varshead *places[2] = { NULL, &globals };
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
return NULL;
|
||||||
if (chan)
|
if (chan)
|
||||||
headp=&chan->varshead;
|
places[0] = &chan->varshead;
|
||||||
else
|
|
||||||
headp=&globals;
|
|
||||||
|
|
||||||
if (name) {
|
for (i = 0; i < 2; i++) {
|
||||||
AST_LIST_TRAVERSE(headp,variables,entries) {
|
if (places[i]) {
|
||||||
if (!strcmp(name, ast_var_name(variables)))
|
AST_LIST_TRAVERSE(places[i], variables, entries) {
|
||||||
return ast_var_value(variables);
|
|
||||||
}
|
|
||||||
if (headp != &globals) {
|
|
||||||
/* Check global variables if we haven't already */
|
|
||||||
headp = &globals;
|
|
||||||
AST_LIST_TRAVERSE(headp,variables,entries) {
|
|
||||||
if (!strcmp(name, ast_var_name(variables)))
|
if (!strcmp(name, ast_var_name(variables)))
|
||||||
return ast_var_value(variables);
|
return ast_var_value(variables);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user