[BusyBox] SH Command-line completion
Gennady Feldman
gena01 at cachier.com
Mon Jan 29 17:47:37 UTC 2001
I have fixed up the code for command-line completion. First of all I want
to thank Vladimir for cleaning-up and fixing up the code. I just fixed a
few things to make sure that following cases work when doing command-line
completion:
1. cd home/ge<TAB>
matches my username (and then other subdirectories many levels deep)
2. cd /home/ge<TAB>
matches absolute subdirectories properly now.
P.S. I am still unsure about the following code, since I wasn't able to
produce a valid test case:
/* before word for match */
command_ps[pos-strlen(matchBuf)]=0;
strcpy(matchBuf, command_ps+pos);
<lines skipped>
/* add tail */
strcat(command_ps, matchBuf);
since in most cases I got matchBuf which was empty. Also command-line
editing doesn't seem to work for me when pressing arrow-keys, even though
I have #define BB_FEATURE_SH_COMMAND_EDITING enabled.
G.F.
-------------- next part --------------
Index: cmdedit.c
===================================================================
RCS file: /var/cvs/busybox/cmdedit.c,v
retrieving revision 1.31
diff -u -r1.31 cmdedit.c
--- cmdedit.c 2001/01/27 06:01:42 1.31
+++ cmdedit.c 2001/01/29 17:31:26
@@ -487,14 +487,14 @@
/* name is directory */
strcpy(found, next->d_name);
strcat(found, "/");
- if(type==FIND_DIR_ONLY)
- strcat(found, " ");
+ /* if(type==FIND_DIR_ONLY)
+ strcat(found, " ");*/
} else {
/* not put found file if search only dirs for cd */
if(type==FIND_DIR_ONLY)
continue;
strcpy(found, next->d_name);
- strcat(found, " ");
+ /*strcat(found, " ");*/
}
/* Add it to the list */
matches = xrealloc(matches, (nm+1)*sizeof(char *));
@@ -587,18 +587,25 @@
if ( (len_found-strlen(matchBuf)+len) < BUFSIZ ) {
int recalc_pos = len;
-
+ int z_pos=pos; /* we need this to look for last '/' in the line! */
+
/* before word for match */
- command_ps[pos-strlen(matchBuf)]=0;
-
+ /* command_ps[pos-strlen(matchBuf)]=0; */
+ while (( z_pos > (pos-strlen(matchBuf) ) ) && ( command_ps[z_pos] != '/' ) ) z_pos--;
+
+ if (command_ps[z_pos] == '/' ) z_pos++;
+
+ command_ps[z_pos]=0;
+
/* tail line */
- strcpy(matchBuf, command_ps+pos);
+ strcpy(matchBuf, command_ps+z_pos);
/* add match */
strcat(command_ps, matches[0]);
+
/* add tail */
strcat(command_ps, matchBuf);
-
+
/* write out the matched command */
len=strlen(command_ps);
recalc_pos = len-recalc_pos+pos;
More information about the busybox
mailing list