diff options
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/editors/vi.c b/editors/vi.c index 27f2a3abd..02bdbb37b 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -147,10 +147,10 @@ struct globals { | |||
147 | #endif | 147 | #endif |
148 | 148 | ||
149 | smallint editing; // >0 while we are editing a file | 149 | smallint editing; // >0 while we are editing a file |
150 | // [code audit says "can be 0 or 1 only"] | 150 | // [code audit says "can be 0, 1 or 2 only"] |
151 | smallint cmd_mode; // 0=command 1=insert 2=replace | 151 | smallint cmd_mode; // 0=command 1=insert 2=replace |
152 | int file_modified; // buffer contents changed (counter, not flag!) | 152 | int file_modified; // buffer contents changed (counter, not flag!) |
153 | int last_file_modified; // = -1; | 153 | int last_file_modified; // = -1; |
154 | int fn_start; // index of first cmd line file name | 154 | int fn_start; // index of first cmd line file name |
155 | int save_argc; // how many file names on cmd line | 155 | int save_argc; // how many file names on cmd line |
156 | int cmdcnt; // repetition count | 156 | int cmdcnt; // repetition count |
@@ -623,7 +623,7 @@ static void edit_file(char *fn) | |||
623 | // These are commands that change text[]. | 623 | // These are commands that change text[]. |
624 | // Remember the input for the "." command | 624 | // Remember the input for the "." command |
625 | if (!adding2q && ioq_start == NULL | 625 | if (!adding2q && ioq_start == NULL |
626 | && strchr(modifying_cmds, c) | 626 | && c != '\0' && strchr(modifying_cmds, c) |
627 | ) { | 627 | ) { |
628 | start_new_cmd_q(c); | 628 | start_new_cmd_q(c); |
629 | } | 629 | } |
@@ -645,8 +645,8 @@ static void edit_file(char *fn) | |||
645 | } | 645 | } |
646 | //------------------------------------------------------------------- | 646 | //------------------------------------------------------------------- |
647 | 647 | ||
648 | place_cursor(rows, 0, FALSE); // go to bottom of screen | 648 | place_cursor(rows - 1, 0, FALSE); // go to bottom of screen |
649 | clear_to_eol(); // Erase to end of line | 649 | clear_to_eol(); // erase to end of line |
650 | cookmode(); | 650 | cookmode(); |
651 | #undef cur_line | 651 | #undef cur_line |
652 | } | 652 | } |
@@ -2009,9 +2009,9 @@ static void start_new_cmd_q(char c) | |||
2009 | { | 2009 | { |
2010 | // get buffer for new cmd | 2010 | // get buffer for new cmd |
2011 | // if there is a current cmd count put it in the buffer first | 2011 | // if there is a current cmd count put it in the buffer first |
2012 | if (cmdcnt > 0) | 2012 | if (cmdcnt > 0) { |
2013 | lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); | 2013 | lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); |
2014 | else { // just save char c onto queue | 2014 | } else { // just save char c onto queue |
2015 | last_modifying_cmd[0] = c; | 2015 | last_modifying_cmd[0] = c; |
2016 | lmc_len = 1; | 2016 | lmc_len = 1; |
2017 | } | 2017 | } |
@@ -2157,21 +2157,21 @@ static void winch_sig(int sig UNUSED_PARAM) | |||
2157 | //----- Come here when we get a continue signal ------------------- | 2157 | //----- Come here when we get a continue signal ------------------- |
2158 | static void cont_sig(int sig UNUSED_PARAM) | 2158 | static void cont_sig(int sig UNUSED_PARAM) |
2159 | { | 2159 | { |
2160 | rawmode(); // terminal to "raw" | 2160 | rawmode(); // terminal to "raw" |
2161 | last_status_cksum = 0; // force status update | 2161 | last_status_cksum = 0; // force status update |
2162 | redraw(TRUE); // re-draw the screen | 2162 | redraw(TRUE); // re-draw the screen |
2163 | 2163 | ||
2164 | signal(SIGTSTP, suspend_sig); | 2164 | signal(SIGTSTP, suspend_sig); |
2165 | signal(SIGCONT, SIG_DFL); | 2165 | signal(SIGCONT, SIG_DFL); |
2166 | kill(my_pid, SIGCONT); | 2166 | kill(my_pid, SIGCONT); // huh? why? we are already "continued"... |
2167 | } | 2167 | } |
2168 | 2168 | ||
2169 | //----- Come here when we get a Suspend signal ------------------- | 2169 | //----- Come here when we get a Suspend signal ------------------- |
2170 | static void suspend_sig(int sig UNUSED_PARAM) | 2170 | static void suspend_sig(int sig UNUSED_PARAM) |
2171 | { | 2171 | { |
2172 | place_cursor(rows - 1, 0, FALSE); // go to bottom of screen | 2172 | place_cursor(rows - 1, 0, FALSE); // go to bottom of screen |
2173 | clear_to_eol(); // Erase to end of line | 2173 | clear_to_eol(); // erase to end of line |
2174 | cookmode(); // terminal to "cooked" | 2174 | cookmode(); // terminal to "cooked" |
2175 | 2175 | ||
2176 | signal(SIGCONT, cont_sig); | 2176 | signal(SIGCONT, cont_sig); |
2177 | signal(SIGTSTP, SIG_DFL); | 2177 | signal(SIGTSTP, SIG_DFL); |
@@ -2247,18 +2247,20 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2247 | 2247 | ||
2248 | fflush(stdout); | 2248 | fflush(stdout); |
2249 | n = chars_to_parse; | 2249 | n = chars_to_parse; |
2250 | // get input from User- are there already input chars in Q? | 2250 | // get input from User - are there already input chars in Q? |
2251 | if (n <= 0) { | 2251 | if (n <= 0) { |
2252 | // the Q is empty, wait for a typed char | 2252 | // the Q is empty, wait for a typed char |
2253 | again: | ||
2253 | n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer)); | 2254 | n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer)); |
2254 | if (n < 0) { | 2255 | if (n <= 0) { |
2255 | if (errno == EBADF || errno == EFAULT || errno == EINVAL | 2256 | place_cursor(rows - 1, 0, FALSE); // go to bottom of screen |
2256 | || errno == EIO) | 2257 | clear_to_eol(); // erase to end of line |
2257 | editing = 0; // want to exit | 2258 | cookmode(); // terminal to "cooked" |
2258 | errno = 0; | 2259 | bb_error_msg_and_die("can't read user input"); |
2259 | } | 2260 | } |
2260 | if (n <= 0) | 2261 | /* elsewhere we can get very confused by NULs */ |
2261 | return 0; // error | 2262 | if (readbuffer[0] == '\0') |
2263 | goto again; | ||
2262 | if (readbuffer[0] == 27) { | 2264 | if (readbuffer[0] == 27) { |
2263 | // This is an ESC char. Is this Esc sequence? | 2265 | // This is an ESC char. Is this Esc sequence? |
2264 | // Could be bare Esc key. See if there are any | 2266 | // Could be bare Esc key. See if there are any |