Whitespace / formatting / bracket cleanup.
[oweals/busybox.git] / cmdedit.c
index 6a53c12f648ce20b9049a41983ebdc42cde2a18d..272d22fc037595e41bb637e2f09b155d2e3151f1 100644 (file)
--- a/cmdedit.c
+++ b/cmdedit.c
  */
 
 
-#define TEST
+//#define TEST
 
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <ctype.h>
+#include <signal.h>
+#include <limits.h>
 
 #ifndef TEST
 
 
 #define BB_FEATURE_SH_COMMAND_EDITING
 #define BB_FEATURE_SH_TAB_COMPLETION
-#define BB_FEATURE_USERNAME_COMPLETION
+#define BB_FEATURE_SH_USERNAME_COMPLETION
 #define BB_FEATURE_NONPRINTABLE_INVERSE_PUT
 #define BB_FEATURE_BASH_STYLE_PROMT
 #define BB_FEATURE_CLEAN_UP
 
-#define TRUE  1
-#define FALSE 0
 #define D(x)  x
 
 #endif                                                 /* TEST */
 
+#ifdef BB_FEATURE_SH_TAB_COMPLETION
+#include <dirent.h>
+#include <sys/stat.h>
+#endif
+
 #ifdef BB_FEATURE_SH_COMMAND_EDITING
 
 #ifndef BB_FEATURE_SH_TAB_COMPLETION
-#undef  BB_FEATURE_USERNAME_COMPLETION
+#undef  BB_FEATURE_SH_USERNAME_COMPLETION
 #endif
 
-#if defined(BB_FEATURE_USERNAME_COMPLETION) || defined(BB_FEATURE_BASH_STYLE_PROMT)
+#if defined(BB_FEATURE_SH_USERNAME_COMPLETION) || defined(BB_FEATURE_BASH_STYLE_PROMT)
 #define BB_FEATURE_GETUSERNAME_AND_HOMEDIR
 #endif
 
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <ctype.h>
-#include <signal.h>
-#include <limits.h>
-
-#ifdef BB_FEATURE_SH_TAB_COMPLETION
-#include <dirent.h>
-#include <sys/stat.h>
-#endif
-
 #ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR
 #ifndef TEST
 #include "pwd_grp/pwd.h"
@@ -555,6 +552,9 @@ static void clean_up_and_die(int sig)
 static void cmdedit_setwidth(int w, int redraw_flg)
 {
        cmdedit_termw = cmdedit_prmt_len + 2;
+       if (w <= cmdedit_termw) {
+               cmdedit_termw = cmdedit_termw % w;
+       }
        if (w > cmdedit_termw) {
 
                cmdedit_termw = w;
@@ -567,10 +567,7 @@ static void cmdedit_setwidth(int w, int redraw_flg)
                        redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), len - cursor);
                        fflush(stdout);
                }
-       } else {
-               error_msg("\n*** Error: minimum screen width is %d",
-                                 cmdedit_termw);
-       }
+       } 
 }
 
 extern void cmdedit_init(void)
@@ -626,7 +623,7 @@ static int is_execute(const struct stat *st)
        return FALSE;
 }
 
-#ifdef BB_FEATURE_USERNAME_COMPLETION
+#ifdef BB_FEATURE_SH_USERNAME_COMPLETION
 
 static char **username_tab_completion(char *ud, int *num_matches)
 {
@@ -688,7 +685,7 @@ static char **username_tab_completion(char *ud, int *num_matches)
                return (matches);
        }
 }
-#endif                                                 /* BB_FEATURE_USERNAME_COMPLETION */
+#endif                                                 /* BB_FEATURE_SH_USERNAME_COMPLETION */
 
 enum {
        FIND_EXE_ONLY = 0,
@@ -785,7 +782,7 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches,
                strcpy(dirbuf, command);
                /* set dir only */
                dirbuf[(pfind - command) + 1] = 0;
-#ifdef BB_FEATURE_USERNAME_COMPLETION
+#ifdef BB_FEATURE_SH_USERNAME_COMPLETION
                if (dirbuf[0] == '~')   /* ~/... or ~user/... */
                        username_tab_completion(dirbuf, 0);
 #endif
@@ -1010,12 +1007,14 @@ static int find_match(char *matchBuf, int *len_with_quotes)
        /* skip first not quoted '\'' or '"' */
        for (i = 0; int_buf[i] == '\'' || int_buf[i] == '"'; i++);
        /* collapse quote or unquote // or /~ */
-       while ((int_buf[i] & ~QUOT) == '/' && (
-                                                                                  (int_buf[i + 1] & ~QUOT) == '/'
-                                                                                  || (int_buf[i + 1] & ~QUOT) ==
-                                                                                  '~')) i++;
-       if (i)
+       while ((int_buf[i] & ~QUOT) == '/' && 
+                       ((int_buf[i + 1] & ~QUOT) == '/'
+                        || (int_buf[i + 1] & ~QUOT) == '~')) {
+               i++;
+       }
+       if (i) {
                collapse_pos(0, i);
+       }
 
        /* set only match and destroy quotes */
        j = 0;
@@ -1066,7 +1065,7 @@ static void input_tab(int *lastWasTab)
                /* Free up any memory already allocated */
                input_tab(0);
 
-#ifdef BB_FEATURE_USERNAME_COMPLETION
+#ifdef BB_FEATURE_SH_USERNAME_COMPLETION
                /* If the word starts with `~' and there is no slash in the word,
                 * then try completing this word as a username. */
 
@@ -1234,9 +1233,10 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
        setTermSettings(inputFd, (void *) &new_settings);
        handlers_sets |= SET_RESET_TERM;
 
-       cmdedit_init();
        /* Print out the command prompt */
        parse_prompt(prompt);
+       /* Now initialize things */
+       cmdedit_init();
 
        while (1) {