*: introduce and use FAST_FUNC: regparm on i386, otherwise no-on
[oweals/busybox.git] / libbb / lineedit.c
index 62dcc55cd2ba5785875582892133e058133c0d37..42f372fb944611170cad6038251141fd8abfe4f7 100644 (file)
@@ -80,10 +80,9 @@ struct lineedit_statics {
        volatile unsigned cmdedit_termw; /* = 80; */ /* actual terminal width */
        sighandler_t previous_SIGWINCH_handler;
 
-
-       int cmdedit_x;           /* real x terminal position */
-       int cmdedit_y;           /* pseudoreal y terminal position */
-       int cmdedit_prmt_len;    /* length of prompt (without colors etc) */
+       unsigned cmdedit_x;        /* real x terminal position */
+       unsigned cmdedit_y;        /* pseudoreal y terminal position */
+       unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */
 
        unsigned cursor;
        unsigned command_len;
@@ -262,12 +261,12 @@ static void input_backward(unsigned num)
                return;
        cursor -= num;
 
-       if ((unsigned)cmdedit_x >= num) {
+       if (cmdedit_x >= num) {
                cmdedit_x -= num;
                if (num <= 4) {
                        /* This is longer by 5 bytes on x86.
-                        * Also gets mysteriously
-                        * miscompiled for some ARM users.
+                        * Also gets miscompiled for ARM users
+                        * (busybox.net/bugs/view.php?id=2274).
                         * printf(("\b\b\b\b" + 4) - num);
                         * return;
                         */
@@ -282,9 +281,12 @@ static void input_backward(unsigned num)
 
        /* Need to go one or more lines up */
        num -= cmdedit_x;
-       count_y = 1 + (num / cmdedit_termw);
-       cmdedit_y -= count_y;
-       cmdedit_x = cmdedit_termw * count_y - num;
+       {
+               unsigned w = cmdedit_termw; /* volatile var */
+               count_y = 1 + (num / w);
+               cmdedit_y -= count_y;
+               cmdedit_x = w * count_y - num;
+       }
        /* go to 1st column; go up; go to correct column */
        printf("\r" "\033[%dA" "\033[%dC", count_y, cmdedit_x);
 }
@@ -292,10 +294,12 @@ static void input_backward(unsigned num)
 static void put_prompt(void)
 {
        out1str(cmdedit_prompt);
-       cmdedit_x = cmdedit_prmt_len;
        cursor = 0;
-// Huh? what if cmdedit_prmt_len >= width?
-       cmdedit_y = 0;                  /* new quasireal y */
+       {
+               unsigned w = cmdedit_termw; /* volatile var */
+               cmdedit_y = cmdedit_prmt_len / w; /* new quasireal y */
+               cmdedit_x = cmdedit_prmt_len % w;
+       }
 }
 
 /* draw prompt, editor line, and clear tail */
@@ -861,7 +865,8 @@ static void input_tab(smallint *lastWasTab)
                        exe_n_cwd_tab_completion(matchBuf, find_type);
                /* Sort, then remove any duplicates found */
                if (matches) {
-                       int i, n = 0;
+                       unsigned i;
+                       int n = 0;
                        qsort_string_vector(matches, num_matches);
                        for (i = 0; i < num_matches - 1; ++i) {
                                if (matches[i] && matches[i+1]) { /* paranoia */
@@ -1317,7 +1322,7 @@ static void cmdedit_setwidth(unsigned w, int redraw_flg)
 
 static void win_changed(int nsig)
 {
-       int width;
+       unsigned width;
        get_terminal_width_height(0, &width, NULL);
        cmdedit_setwidth(width, nsig /* - just a yes/no flag */);
        if (nsig == SIGWINCH)
@@ -1347,12 +1352,12 @@ static void win_changed(int nsig)
  * 0  on ctrl-C (the line entered is still returned in 'command'),
  * >0 length of input string, including terminating '\n'
  */
-int read_line_input(const char *prompt, char *command, int maxsize, line_input_t *st)
+int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, line_input_t *st)
 {
 #if ENABLE_FEATURE_TAB_COMPLETION
        smallint lastWasTab = FALSE;
 #endif
-       unsigned int ic;
+       unsigned ic;
        unsigned char c;
        smallint break_out = 0;
 #if ENABLE_FEATURE_EDITING_VI
@@ -1840,7 +1845,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
        return command_len;
 }
 
-line_input_t *new_line_input_t(int flags)
+line_input_t* FAST_FUNC new_line_input_t(int flags)
 {
        line_input_t *n = xzalloc(sizeof(*n));
        n->flags = flags;
@@ -1850,7 +1855,7 @@ line_input_t *new_line_input_t(int flags)
 #else
 
 #undef read_line_input
-int read_line_input(const char* prompt, char* command, int maxsize)
+int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize)
 {
        fputs(prompt, stdout);
        fflush(stdout);