aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-03-19 10:46:06 +0000
committerErik Andersen <andersen@codepoet.org>2000-03-19 10:46:06 +0000
commit1dbe340ebab31aa85446e83e8bc42f184b59b25b (patch)
tree188b315b963daf910c60ee8a3796d15365e7243f
parentc7c634bd88c57d910c6089de7f0091ca4e3d1843 (diff)
downloadbusybox-1dbe340ebab31aa85446e83e8bc42f184b59b25b.tar.gz
more minor fixes
-Erik
-rw-r--r--Makefile2
-rw-r--r--archival/gunzip.c6
-rw-r--r--cmdedit.c113
-rw-r--r--gunzip.c6
-rw-r--r--shell/cmdedit.c113
5 files changed, 139 insertions, 101 deletions
diff --git a/Makefile b/Makefile
index 1d52e1dcd..e371f35c1 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ DODEBUG = false
# If you want a static binary, turn this on. I can't think
# of many situations where anybody would ever want it static,
# but...
-DOSTATIC = false
+DOSTATIC = true
# This will choke on a non-debian system
ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
diff --git a/archival/gunzip.c b/archival/gunzip.c
index e1c8ac06e..7aa896469 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -1291,12 +1291,6 @@ const char *reject;
/* ========================================================================
* Error handlers.
*/
-void warn(a, b)
-char *a, *b; /* message strings juxtaposed in output */
-{
- WARN((stderr, "warning: %s%s\n", a, b));
-}
-
void read_error()
{
fprintf(stderr, "\n");
diff --git a/cmdedit.c b/cmdedit.c
index 8a7a5fb03..b3e7fd58c 100644
--- a/cmdedit.c
+++ b/cmdedit.c
@@ -184,19 +184,45 @@ char** username_completion_matches(char* command, int *num_matches)
fprintf(stderr, "\nin username_completion_matches\n");
return (matches);
}
+
+#include <dirent.h>
char** find_path_executable_n_cwd_matches(char* command, int *num_matches)
{
+ char *dirName;
char **matches = (char **) NULL;
- matches = malloc(sizeof(char*)*100);
-
- matches[0] = malloc(sizeof(char)*50);
- matches[1] = malloc(sizeof(char)*50);
-
- sprintf(matches[0], "Hello");
- sprintf(matches[1], "Howdy");
- *num_matches=2;
+ DIR *dir;
+ struct dirent *next;
+
+ matches = malloc( sizeof(char*)*50);
+
+ /* Stick a wildcard onto the command, for later use */
+ strcat( command, "*");
+
+ /* Now wall the current directory */
+ dirName = get_current_dir_name();
+ dir = opendir(dirName);
+ if (!dir) {
+ /* Don't print an error, just shut up and return */
+ *num_matches=0;
+ return (matches);
+ }
+ while ((next = readdir(dir)) != NULL) {
+
+ /* Some quick sanity checks */
+ if ((strcmp(next->d_name, "..") == 0)
+ || (strcmp(next->d_name, ".") == 0)) {
+ continue;
+ }
+ /* See if this matches */
+ if (check_wildcard_match(next->d_name, command) == TRUE) {
+ /* Cool, found a match. Add it to the list */
+ matches[*num_matches] = malloc(strlen(next->d_name)+1);
+ strcpy( matches[*num_matches], next->d_name);
+ ++*num_matches;
+ //matches = realloc( matches, sizeof(char*)*(*num_matches));
+ }
+ }
-// fprintf(stderr, "\nin find_path_executable_n_cwd_matches\n");
return (matches);
}
@@ -319,11 +345,11 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
/* For now, we will not bother with trying to distinguish
* whether the cursor is in/at a command extression -- we
* will always try all possable matches. If you don't like
- * that, feel free to fix it.
+ * that then feel free to fix it.
*/
/* Make a local copy of the string -- up
- * to the the position of the cursor */
+ * to the position of the cursor */
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, parsenextc, cursor);
tmp=matchBuf;
@@ -346,59 +372,58 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
matches = (char **) NULL;
}
- /* If the word starts in `~', and there is no slash in the word,
+ /* If the word starts with `~' and there is no slash in the word,
* then try completing this word as a username. */
+
+ /* FIXME -- this check is broken! */
if (*tmp == '~' && !strchr(tmp, '/'))
matches = username_completion_matches(tmp, &num_matches);
- /* Try to match any executable in our patch, and everything
- * in the current working directory that matches.
- */
+ /* Try to match any executable in our path and everything
+ * in the current working directory that matches. */
if (!matches)
matches = find_path_executable_n_cwd_matches(tmp, &num_matches);
+
+ /* Don't leak memory */
+ free( matchBuf);
+
+ /* Did we find exactly one match? */
+ if (matches && num_matches==1) {
+ /* write out the matched command */
+ strncpy(parsenextc+pos, matches[0]+pos, strlen(matches[0])-pos);
+ len=strlen(parsenextc);
+ cursor=len;
+ xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
+ break;
+ }
} else {
+ /* Ok -- the last char was a TAB. Since they
+ * just hit TAB again, print a list of all the
+ * available choices... */
if ( matches && num_matches>0 ) {
int i, col;
- fprintf(stderr, "\nTabbing...\n");
-
- /* Make a list of the matches */
- col += xwrite(outputFd, "\n", 1);
+ /* Go to the next line */
+ xwrite(outputFd, "\n", 1);
+ /* Print the list of matches */
for (i=0,col=0; i<num_matches; i++) {
- col += xwrite(outputFd, prompt, strlen(matches[i]));
+ char foo[17];
+ sprintf(foo, "%-14s ", matches[i]);
+ col += xwrite(outputFd, foo, strlen(foo));
if (col > 60 && matches[i+1] != NULL) {
xwrite(outputFd, "\n", 1);
col = 0;
}
}
+ /* Go to the next line */
xwrite(outputFd, "\n", 1);
-
- len+=strlen(prompt);
- fprintf(stderr, "len=%d\n", len);
-
- /* Move to the beginning of the line */
- input_home(outputFd, &len);
-
- /* erase everything */
- for (j = 0; j < len; j++)
- xwrite(outputFd, " ", 1);
-
- /* return to begining of line */
- input_home(outputFd, &cursor);
-
- /* Rewrite the prompt) */
+ /* Rewrite the prompt */
xwrite(outputFd, prompt, strlen(prompt));
-
/* Rewrite the command */
- len = strlen(parsenextc);
xwrite(outputFd, parsenextc, len);
-
- /* Move back to where the cursor used to be */
- for (cursor=pos; cursor > 0; cursor--)
+ /* Put the cursor back to where it used to be */
+ for (cursor=len; cursor > pos; cursor--)
xwrite(outputFd, "\b", 1);
- cursor = pos;
-
- //fprintf(stderr, "\nprompt='%s'\n", prompt);
}
}
break;
@@ -451,7 +476,6 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
/* return to begining of line */
for (; cursor > 0; cursor--)
xwrite(outputFd, "\b", 1);
- xwrite(outputFd, parsenextc, len);
/* erase old command */
for (j = 0; j < len; j++)
@@ -462,6 +486,7 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
xwrite(outputFd, "\b", 1);
memset(parsenextc, 0, BUFSIZ);
+ len = strlen(parsenextc);
/* write new command */
strcpy(parsenextc, hp->s);
len = strlen(hp->s);
diff --git a/gunzip.c b/gunzip.c
index e1c8ac06e..7aa896469 100644
--- a/gunzip.c
+++ b/gunzip.c
@@ -1291,12 +1291,6 @@ const char *reject;
/* ========================================================================
* Error handlers.
*/
-void warn(a, b)
-char *a, *b; /* message strings juxtaposed in output */
-{
- WARN((stderr, "warning: %s%s\n", a, b));
-}
-
void read_error()
{
fprintf(stderr, "\n");
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 8a7a5fb03..b3e7fd58c 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -184,19 +184,45 @@ char** username_completion_matches(char* command, int *num_matches)
fprintf(stderr, "\nin username_completion_matches\n");
return (matches);
}
+
+#include <dirent.h>
char** find_path_executable_n_cwd_matches(char* command, int *num_matches)
{
+ char *dirName;
char **matches = (char **) NULL;
- matches = malloc(sizeof(char*)*100);
-
- matches[0] = malloc(sizeof(char)*50);
- matches[1] = malloc(sizeof(char)*50);
-
- sprintf(matches[0], "Hello");
- sprintf(matches[1], "Howdy");
- *num_matches=2;
+ DIR *dir;
+ struct dirent *next;
+
+ matches = malloc( sizeof(char*)*50);
+
+ /* Stick a wildcard onto the command, for later use */
+ strcat( command, "*");
+
+ /* Now wall the current directory */
+ dirName = get_current_dir_name();
+ dir = opendir(dirName);
+ if (!dir) {
+ /* Don't print an error, just shut up and return */
+ *num_matches=0;
+ return (matches);
+ }
+ while ((next = readdir(dir)) != NULL) {
+
+ /* Some quick sanity checks */
+ if ((strcmp(next->d_name, "..") == 0)
+ || (strcmp(next->d_name, ".") == 0)) {
+ continue;
+ }
+ /* See if this matches */
+ if (check_wildcard_match(next->d_name, command) == TRUE) {
+ /* Cool, found a match. Add it to the list */
+ matches[*num_matches] = malloc(strlen(next->d_name)+1);
+ strcpy( matches[*num_matches], next->d_name);
+ ++*num_matches;
+ //matches = realloc( matches, sizeof(char*)*(*num_matches));
+ }
+ }
-// fprintf(stderr, "\nin find_path_executable_n_cwd_matches\n");
return (matches);
}
@@ -319,11 +345,11 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
/* For now, we will not bother with trying to distinguish
* whether the cursor is in/at a command extression -- we
* will always try all possable matches. If you don't like
- * that, feel free to fix it.
+ * that then feel free to fix it.
*/
/* Make a local copy of the string -- up
- * to the the position of the cursor */
+ * to the position of the cursor */
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, parsenextc, cursor);
tmp=matchBuf;
@@ -346,59 +372,58 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
matches = (char **) NULL;
}
- /* If the word starts in `~', and there is no slash in the word,
+ /* If the word starts with `~' and there is no slash in the word,
* then try completing this word as a username. */
+
+ /* FIXME -- this check is broken! */
if (*tmp == '~' && !strchr(tmp, '/'))
matches = username_completion_matches(tmp, &num_matches);
- /* Try to match any executable in our patch, and everything
- * in the current working directory that matches.
- */
+ /* Try to match any executable in our path and everything
+ * in the current working directory that matches. */
if (!matches)
matches = find_path_executable_n_cwd_matches(tmp, &num_matches);
+
+ /* Don't leak memory */
+ free( matchBuf);
+
+ /* Did we find exactly one match? */
+ if (matches && num_matches==1) {
+ /* write out the matched command */
+ strncpy(parsenextc+pos, matches[0]+pos, strlen(matches[0])-pos);
+ len=strlen(parsenextc);
+ cursor=len;
+ xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
+ break;
+ }
} else {
+ /* Ok -- the last char was a TAB. Since they
+ * just hit TAB again, print a list of all the
+ * available choices... */
if ( matches && num_matches>0 ) {
int i, col;
- fprintf(stderr, "\nTabbing...\n");
-
- /* Make a list of the matches */
- col += xwrite(outputFd, "\n", 1);
+ /* Go to the next line */
+ xwrite(outputFd, "\n", 1);
+ /* Print the list of matches */
for (i=0,col=0; i<num_matches; i++) {
- col += xwrite(outputFd, prompt, strlen(matches[i]));
+ char foo[17];
+ sprintf(foo, "%-14s ", matches[i]);
+ col += xwrite(outputFd, foo, strlen(foo));
if (col > 60 && matches[i+1] != NULL) {
xwrite(outputFd, "\n", 1);
col = 0;
}
}
+ /* Go to the next line */
xwrite(outputFd, "\n", 1);
-
- len+=strlen(prompt);
- fprintf(stderr, "len=%d\n", len);
-
- /* Move to the beginning of the line */
- input_home(outputFd, &len);
-
- /* erase everything */
- for (j = 0; j < len; j++)
- xwrite(outputFd, " ", 1);
-
- /* return to begining of line */
- input_home(outputFd, &cursor);
-
- /* Rewrite the prompt) */
+ /* Rewrite the prompt */
xwrite(outputFd, prompt, strlen(prompt));
-
/* Rewrite the command */
- len = strlen(parsenextc);
xwrite(outputFd, parsenextc, len);
-
- /* Move back to where the cursor used to be */
- for (cursor=pos; cursor > 0; cursor--)
+ /* Put the cursor back to where it used to be */
+ for (cursor=len; cursor > pos; cursor--)
xwrite(outputFd, "\b", 1);
- cursor = pos;
-
- //fprintf(stderr, "\nprompt='%s'\n", prompt);
}
}
break;
@@ -451,7 +476,6 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
/* return to begining of line */
for (; cursor > 0; cursor--)
xwrite(outputFd, "\b", 1);
- xwrite(outputFd, parsenextc, len);
/* erase old command */
for (j = 0; j < len; j++)
@@ -462,6 +486,7 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd,
xwrite(outputFd, "\b", 1);
memset(parsenextc, 0, BUFSIZ);
+ len = strlen(parsenextc);
/* write new command */
strcpy(parsenextc, hp->s);
len = strlen(hp->s);