Browse code

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).

Andrei Pelinescu-Onciul authored on 08/08/2010 16:09:17
Showing 1 changed files
... ...
@@ -1802,36 +1802,31 @@ char** sercmd_completion(const char* text, int start, int end)
1802 1802
 				}
1803 1803
 			}
1804 1804
 #endif /* USE_MI */
1805
-#ifdef USE_CFG_VARS
1806 1805
 		}else if (crt_param_no==2){
1807
-			if (attempted_completion_state!=COMPLETE_CFG_GRP){
1808
-				for(i=0; complete_params_cfg_var[i]; i++){
1809
-					if ((cmd_len==strlen(complete_params_cfg_var[i])) &&
1810
-						(strncmp(&rl_line_buffer[cmd_start],
1806
+#ifdef USE_CFG_VARS
1807
+			/* see if we complete cfg. var names for this command */
1808
+			for(i=0; complete_params_cfg_var[i]; i++){
1809
+				if ((cmd_len==strlen(complete_params_cfg_var[i])) &&
1810
+					(strncmp(&rl_line_buffer[cmd_start],
1811 1811
 								 complete_params_cfg_var[i],
1812 1812
 								 cmd_len)==0)){
1813
-						attempted_completion_state=COMPLETE_CFG_GRP;
1814
-						/* find grp_start */
1815
-						for(j=cmd_end; (j<start) && ((rl_line_buffer[j]==' ') 
1816
-									|| (rl_line_buffer[j]=='\t')); j++);
1817
-						grp_start=j;
1818
-						break;
1819
-					}
1820
-				}
1821
-			}
1822
-			if (attempted_completion_state==COMPLETE_CFG_GRP){
1823
-				/* get the group name from the grp_param */
1824
-				/* find first whitespace for the group name*/
1825
-				for(j=grp_start; (j<start) && (rl_line_buffer[j]!=' ') &&
1826
-						(rl_line_buffer[j]!='\t'); j++);
1827
-				grp_len=j-grp_start;
1828
-				for(grp=cfg_grp_lst; grp; grp=grp->next){
1829
-					if (grp_len==grp->grp_name.len &&
1830
-							memcmp(&rl_line_buffer[grp_start], grp->grp_name.s,
1831
-										grp_len)==0) {
1832
-						attempted_completion_state=COMPLETE_CFG_VAR;
1833
-						crt_cfg_grp=grp;
1834
-						goto end;
1813
+					/* get the group name: */
1814
+					/* find grp_start */
1815
+					for(j=cmd_end; (j<start) && ((rl_line_buffer[j]==' ') ||
1816
+							(rl_line_buffer[j]=='\t')); j++);
1817
+					grp_start=j;
1818
+					/* find group end / grp_len*/
1819
+					for(j=grp_start; (j<start) && (rl_line_buffer[j]!=' ') &&
1820
+								(rl_line_buffer[j]!='\t'); j++);
1821
+					grp_len=j-grp_start;
1822
+					for(grp=cfg_grp_lst; grp; grp=grp->next){
1823
+						if (grp_len==grp->grp_name.len &&
1824
+								memcmp(&rl_line_buffer[grp_start],
1825
+										grp->grp_name.s, grp_len)==0) {
1826
+							attempted_completion_state=COMPLETE_CFG_VAR;
1827
+							crt_cfg_grp=grp;
1828
+							goto end;
1829
+						}
1835 1830
 					}
1836 1831
 				}
1837 1832
 			}