more minor fixes
authorErik Andersen <andersen@codepoet.org>
Sun, 19 Mar 2000 10:46:06 +0000 (10:46 -0000)
committerErik Andersen <andersen@codepoet.org>
Sun, 19 Mar 2000 10:46:06 +0000 (10:46 -0000)
 -Erik

Makefile
archival/gunzip.c
cmdedit.c
gunzip.c
shell/cmdedit.c

index 1d52e1dcdedba19923102aad2af88751c6119d0e..e371f35c1ea5c1034baf9cd0d8c0d9221488230c 100644 (file)
--- 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/'`
index e1c8ac06ee9a985aa8143c624123437601f16764..7aa896469319879f26d0e0db84460501c5f8bd71 100644 (file)
@@ -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");
index 8a7a5fb034b8a578c79456feee3dbcf77af8d011..b3e7fd58c9f1a227dd7f2b923aafc8711c85e6da 100644 (file)
--- 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);
index e1c8ac06ee9a985aa8143c624123437601f16764..7aa896469319879f26d0e0db84460501c5f8bd71 100644 (file)
--- 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");
index 8a7a5fb034b8a578c79456feee3dbcf77af8d011..b3e7fd58c9f1a227dd7f2b923aafc8711c85e6da 100644 (file)
@@ -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);