Add wget -P support, finishing off bug #1176
[oweals/busybox.git] / cmdedit.c
index cc39e562ae611583184c9f3ccf80e3880ffa9e85..a2b23860322e117b9fd24b56a12578b6203aafa3 100644 (file)
--- a/cmdedit.c
+++ b/cmdedit.c
@@ -76,7 +76,7 @@
 #undef  BB_FEATURE_COMMAND_USERNAME_COMPLETION
 #endif
 
-#if defined(BB_FEATURE_COMMAND_USERNAME_COMPLETION) || !defined(BB_FEATURE_SH_SIMPLE_PROMPT)
+#if defined(BB_FEATURE_COMMAND_USERNAME_COMPLETION) || defined(BB_FEATURE_SH_FANCY_PROMPT)
 #define BB_FEATURE_GETUSERNAME_AND_HOMEDIR
 #endif
 
@@ -151,7 +151,7 @@ static int cursor;          /* required global for signal handler */
 static int len;                        /* --- "" - - "" - -"- --""-- --""--- */
 static char *command_ps;       /* --- "" - - "" - -"- --""-- --""--- */
 static
-#ifdef BB_FEATURE_SH_SIMPLE_PROMPT
+#ifndef BB_FEATURE_SH_FANCY_PROMPT
        const
 #endif
 char *cmdedit_prompt;          /* --- "" - - "" - -"- --""-- --""--- */
@@ -166,7 +166,7 @@ static char *home_pwd_buf = "";
 static int my_euid;
 #endif
 
-#ifndef BB_FEATURE_SH_SIMPLE_PROMPT
+#ifdef BB_FEATURE_SH_FANCY_PROMPT
 static char *hostname_buf = "";
 static int num_ok_lines = 1;
 #endif
@@ -335,7 +335,7 @@ static void put_prompt(void)
        cursor = 0;
 }
 
-#ifdef BB_FEATURE_SH_SIMPLE_PROMPT
+#ifndef BB_FEATURE_SH_FANCY_PROMPT
 static void parse_prompt(const char *prmt_ptr)
 {
        cmdedit_prompt = prmt_ptr;
@@ -571,7 +571,6 @@ extern void cmdedit_init(void)
                atexit(cmdedit_reset_term);     /* be sure to do this only once */
        }
 
-#if 0
        if ((handlers_sets & SET_TERM_HANDLERS) == 0) {
                signal(SIGKILL, clean_up_and_die);
                signal(SIGINT, clean_up_and_die);
@@ -579,8 +578,6 @@ extern void cmdedit_init(void)
                signal(SIGTERM, clean_up_and_die);
                handlers_sets |= SET_TERM_HANDLERS;
        }
-#endif 
-
 }
 
 #ifdef BB_FEATURE_COMMAND_TAB_COMPLETION
@@ -983,17 +980,14 @@ static int find_match(char *matchBuf, int *len_with_quotes)
                         || (int_buf[i + 1] & ~QUOT) == '~')) {
                i++;
        }
-       if (i) {
-               collapse_pos(0, i);
-       }
 
        /* set only match and destroy quotes */
        j = 0;
-       for (i = 0; pos_buf[i] >= 0; i++) {
-               matchBuf[i] = matchBuf[pos_buf[i]];
+       for (c = 0; pos_buf[i] >= 0; i++) {
+               matchBuf[c++] = matchBuf[pos_buf[i]];
                j = pos_buf[i] + 1;
        }
-       matchBuf[i] = 0;
+       matchBuf[c] = 0;
        /* old lenght matchBuf with quotes symbols */
        *len_with_quotes = j ? j - pos_buf[0] : 0;
 
@@ -1097,8 +1091,7 @@ static void input_tab(int *lastWasTab)
                        /* new len                         */
                        len = strlen(command_ps);
                        /* write out the matched command   */
-                       input_end();
-                       input_backward(cursor - recalc_pos);
+                       redraw(cmdedit_y, len - recalc_pos);
                }
                if (tmp != matches[0])
                        free(tmp);
@@ -1469,7 +1462,7 @@ prepare_to_die:
                                history_counter++;
                        }
                }
-#if !defined(BB_FEATURE_SH_SIMPLE_PROMPT)
+#if defined(BB_FEATURE_SH_FANCY_PROMPT)
                num_ok_lines++;
 #endif
        }
@@ -1478,7 +1471,7 @@ prepare_to_die:
 #if defined(BB_FEATURE_CLEAN_UP) && defined(BB_FEATURE_COMMAND_TAB_COMPLETION)
        input_tab(0);                           /* strong free */
 #endif
-#if !defined(BB_FEATURE_SH_SIMPLE_PROMPT)
+#if defined(BB_FEATURE_SH_FANCY_PROMPT)
        free(cmdedit_prompt);
 #endif
        return;
@@ -1489,7 +1482,6 @@ prepare_to_die:
 extern void cmdedit_terminate(void)
 {
        cmdedit_reset_term();
-#if 0
        if ((handlers_sets & SET_TERM_HANDLERS) != 0) {
                signal(SIGKILL, SIG_DFL);
                signal(SIGINT, SIG_DFL);
@@ -1498,7 +1490,6 @@ extern void cmdedit_terminate(void)
                signal(SIGWINCH, SIG_DFL);
                handlers_sets &= ~SET_TERM_HANDLERS;
        }
-#endif 
 }
 
 #endif /* BB_FEATURE_COMMAND_EDITING */
@@ -1519,7 +1510,7 @@ int main(int argc, char **argv)
 {
        char buff[BUFSIZ];
        char *prompt =
-#if !defined(BB_FEATURE_SH_SIMPLE_PROMPT)
+#if defined(BB_FEATURE_SH_FANCY_PROMPT)
                "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:\
 \\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] \
 \\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]";