[BusyBox] cmdedit.c in CVS

Erik Andersen andersen at lineo.com
Thu Nov 2 17:01:55 UTC 2000


On Thu Nov 02, 2000 at 11:47:14AM -0500, Gennady Feldman wrote:
> Hello Erik.
> 
>     I am going to try to take a stab at it. I already got it to compile and removed
> the warning messages.
> I also found a couple of issues while playing/testing the command line completion:
> 1. If you hit TAB twice in a row right at the prompt (empty command string) it
> hangs. I am trying to figure this out and the patch will need to update >1
> function.
> 
> 2. In certain cases it does a segmentation fault when doing command line
> completion.
> 
> On a different note, while looking through the TinyLogin Makefile I found no
> references to uC-libc. I am just curious if Tiny-Login works w/ the new Libc
> Library?

I have not yet tried it.  I'll try it out on the plane today (I'm flying out to
Toronto in about an hour).

The patch looks fine -- applied.

BTW -- with patches -- using 'diff -u' makes me happier, since such patches can
be easily read...  See the attached (your patch but using 'diff -u').  Notice
how mere mortals can read it...

 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--
-------------- next part --------------
--- cmdedit.c	2000/09/25 21:45:57
+++ cmdedit.c	2000/11/02 16:59:25
@@ -283,12 +283,12 @@ char** exe_n_cwd_tab_completion(char* co
 	return (matches);
 }
 
-void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
+void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len, int lastWasTab)
 {
 	/* Do TAB completion */
 	static int num_matches=0;
 	static char **matches = (char **) NULL;
-	int pos = cursor;
+	int pos = *cursor;
 
 
 	if (lastWasTab == FALSE) {
@@ -303,7 +303,7 @@ void input_tab(char* command, char* prom
 		/* Make a local copy of the string -- up 
 		 * to the position of the cursor */
 		matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
-		strncpy(matchBuf, command, cursor);
+		strncpy(matchBuf, command, *cursor);
 		tmp=matchBuf;
 
 		/* skip past any command seperator tokens */
@@ -343,10 +343,10 @@ void input_tab(char* command, char* prom
 		if (matches && num_matches==1) {
 			/* write out the matched command */
 			strncpy(command+pos, matches[0]+pos, strlen(matches[0])-pos);
-			len=strlen(command);
-			cursor=len;
+			*len=strlen(command);
+			*cursor=*len;
 			xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
-			break;
+			return;
 		}
 	} else {
 		/* Ok -- the last char was a TAB.  Since they
@@ -372,9 +372,9 @@ void input_tab(char* command, char* prom
 			/* Rewrite the prompt */
 			xwrite(outputFd, prompt, strlen(prompt));
 			/* Rewrite the command */
-			xwrite(outputFd, command, len);
+			xwrite(outputFd, command, *len);
 			/* Put the cursor back to where it used to be */
-			for (cursor=len; cursor > pos; cursor--)
+			for (cursor=len; *cursor > pos; cursor--)
 				xwrite(outputFd, "\b", 1);
 		}
 	}
@@ -505,7 +505,8 @@ extern void cmdedit_read_input(char* pro
 			break;
 		case '\t':
 #ifdef BB_FEATURE_SH_TAB_COMPLETION
-			input_tab(command, prompt, outputFd, &cursor, &len);
+			input_tab(command, prompt, outputFd, &cursor,
+&len, lastWasTab);
 #endif
 			break;
 		case 14:


More information about the busybox mailing list