Module: sip-router Branch: sr_3.0 Commit: b6f3ab32d17866b1234c6966f294bd95f9f80b4b URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b6f3ab32...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Sun Aug 8 18:09:17 2010 +0200
sercmd: fix cfg. var name completion
In some rare cases cfg. variable name completion did not work properly (e.g. reusing a command from history, editing it, changing the group and attempting command completion again). This was due to an assumption that the state would be re-initialized on new commands (which is mostly not true). (cherry picked from commit 261d8282e6dabf73a65904e7a8413ccec9faf2fd)
---
utils/sercmd/sercmd.c | 49 ++++++++++++++++++++++--------------------------- 1 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/utils/sercmd/sercmd.c b/utils/sercmd/sercmd.c index 1f1a721..3b4432a 100644 --- a/utils/sercmd/sercmd.c +++ b/utils/sercmd/sercmd.c @@ -1802,36 +1802,31 @@ char** sercmd_completion(const char* text, int start, int end) } } #endif /* USE_MI */ -#ifdef USE_CFG_VARS }else if (crt_param_no==2){ - if (attempted_completion_state!=COMPLETE_CFG_GRP){ - for(i=0; complete_params_cfg_var[i]; i++){ - if ((cmd_len==strlen(complete_params_cfg_var[i])) && - (strncmp(&rl_line_buffer[cmd_start], +#ifdef USE_CFG_VARS + /* see if we complete cfg. var names for this command */ + for(i=0; complete_params_cfg_var[i]; i++){ + if ((cmd_len==strlen(complete_params_cfg_var[i])) && + (strncmp(&rl_line_buffer[cmd_start], complete_params_cfg_var[i], cmd_len)==0)){ - attempted_completion_state=COMPLETE_CFG_GRP; - /* find grp_start */ - for(j=cmd_end; (j<start) && ((rl_line_buffer[j]==' ') - || (rl_line_buffer[j]=='\t')); j++); - grp_start=j; - break; - } - } - } - if (attempted_completion_state==COMPLETE_CFG_GRP){ - /* get the group name from the grp_param */ - /* find first whitespace for the group name*/ - for(j=grp_start; (j<start) && (rl_line_buffer[j]!=' ') && - (rl_line_buffer[j]!='\t'); j++); - grp_len=j-grp_start; - for(grp=cfg_grp_lst; grp; grp=grp->next){ - if (grp_len==grp->grp_name.len && - memcmp(&rl_line_buffer[grp_start], grp->grp_name.s, - grp_len)==0) { - attempted_completion_state=COMPLETE_CFG_VAR; - crt_cfg_grp=grp; - goto end; + /* get the group name: */ + /* find grp_start */ + for(j=cmd_end; (j<start) && ((rl_line_buffer[j]==' ') || + (rl_line_buffer[j]=='\t')); j++); + grp_start=j; + /* find group end / grp_len*/ + for(j=grp_start; (j<start) && (rl_line_buffer[j]!=' ') && + (rl_line_buffer[j]!='\t'); j++); + grp_len=j-grp_start; + for(grp=cfg_grp_lst; grp; grp=grp->next){ + if (grp_len==grp->grp_name.len && + memcmp(&rl_line_buffer[grp_start], + grp->grp_name.s, grp_len)==0) { + attempted_completion_state=COMPLETE_CFG_VAR; + crt_cfg_grp=grp; + goto end; + } } } }