diff options
author | Ron Yorston <rmy@pobox.com> | 2017-05-29 14:20:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-05-29 14:34:28 +0100 |
commit | da4f331955bed8afda670afcd58d524a04a0faa9 (patch) | |
tree | f6a3879aefdd714240f8c022375f687b512d2238 /editors/vi.c | |
parent | 74163a535fd21f5fcca4c052d2e7c192d3e264fa (diff) | |
parent | 6683d1cbb44859f549f87f882545b84b9369585c (diff) | |
download | busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.tar.gz busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.tar.bz2 busybox-w32-da4f331955bed8afda670afcd58d524a04a0faa9.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/editors/vi.c b/editors/vi.c index e5ca3adfa..900b41cb5 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -715,14 +715,6 @@ static int init_text_buffer(char *fn) | |||
715 | { | 715 | { |
716 | int rc; | 716 | int rc; |
717 | 717 | ||
718 | flush_undo_data(); | ||
719 | modified_count = 0; | ||
720 | last_modified_count = -1; | ||
721 | #if ENABLE_FEATURE_VI_YANKMARK | ||
722 | /* init the marks */ | ||
723 | memset(mark, 0, sizeof(mark)); | ||
724 | #endif | ||
725 | |||
726 | /* allocate/reallocate text buffer */ | 718 | /* allocate/reallocate text buffer */ |
727 | free(text); | 719 | free(text); |
728 | text_size = 10240; | 720 | text_size = 10240; |
@@ -737,6 +729,14 @@ static int init_text_buffer(char *fn) | |||
737 | // file doesnt exist. Start empty buf with dummy line | 729 | // file doesnt exist. Start empty buf with dummy line |
738 | char_insert(text, '\n', NO_UNDO); | 730 | char_insert(text, '\n', NO_UNDO); |
739 | } | 731 | } |
732 | |||
733 | flush_undo_data(); | ||
734 | modified_count = 0; | ||
735 | last_modified_count = -1; | ||
736 | #if ENABLE_FEATURE_VI_YANKMARK | ||
737 | /* init the marks */ | ||
738 | memset(mark, 0, sizeof(mark)); | ||
739 | #endif | ||
740 | return rc; | 740 | return rc; |
741 | } | 741 | } |
742 | 742 | ||
@@ -1034,7 +1034,9 @@ static void colon(char *buf) | |||
1034 | || strncmp(p, "wn", cnt) == 0 | 1034 | || strncmp(p, "wn", cnt) == 0 |
1035 | || (p[0] == 'x' && !p[1]) | 1035 | || (p[0] == 'x' && !p[1]) |
1036 | ) { | 1036 | ) { |
1037 | cnt = file_write(current_filename, text, end - 1); | 1037 | if (modified_count != 0 || p[0] != 'x') { |
1038 | cnt = file_write(current_filename, text, end - 1); | ||
1039 | } | ||
1038 | if (cnt < 0) { | 1040 | if (cnt < 0) { |
1039 | if (cnt == -1) | 1041 | if (cnt == -1) |
1040 | status_line_bold("Write error: %s", strerror(errno)); | 1042 | status_line_bold("Write error: %s", strerror(errno)); |
@@ -1045,8 +1047,9 @@ static void colon(char *buf) | |||
1045 | current_filename, | 1047 | current_filename, |
1046 | count_lines(text, end - 1), cnt | 1048 | count_lines(text, end - 1), cnt |
1047 | ); | 1049 | ); |
1048 | if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n' | 1050 | if (p[0] == 'x' |
1049 | || p[0] == 'X' || p[1] == 'Q' || p[1] == 'N' | 1051 | || p[1] == 'q' || p[1] == 'n' |
1052 | || p[1] == 'Q' || p[1] == 'N' | ||
1050 | ) { | 1053 | ) { |
1051 | editing = 0; | 1054 | editing = 0; |
1052 | } | 1055 | } |
@@ -1476,16 +1479,19 @@ static void colon(char *buf) | |||
1476 | goto ret; | 1479 | goto ret; |
1477 | } | 1480 | } |
1478 | #endif | 1481 | #endif |
1479 | // how many lines in text[]? | ||
1480 | li = count_lines(q, r); | ||
1481 | size = r - q + 1; | ||
1482 | //if (useforce) { | 1482 | //if (useforce) { |
1483 | // if "fn" is not write-able, chmod u+w | 1483 | // if "fn" is not write-able, chmod u+w |
1484 | // sprintf(syscmd, "chmod u+w %s", fn); | 1484 | // sprintf(syscmd, "chmod u+w %s", fn); |
1485 | // system(syscmd); | 1485 | // system(syscmd); |
1486 | // forced = TRUE; | 1486 | // forced = TRUE; |
1487 | //} | 1487 | //} |
1488 | l = file_write(fn, q, r); | 1488 | if (modified_count != 0 || cmd[0] != 'x') { |
1489 | size = r - q + 1; | ||
1490 | l = file_write(fn, q, r); | ||
1491 | } else { | ||
1492 | size = 0; | ||
1493 | l = 0; | ||
1494 | } | ||
1489 | //if (useforce && forced) { | 1495 | //if (useforce && forced) { |
1490 | // chmod u-w | 1496 | // chmod u-w |
1491 | // sprintf(syscmd, "chmod u-w %s", fn); | 1497 | // sprintf(syscmd, "chmod u-w %s", fn); |
@@ -1496,17 +1502,20 @@ static void colon(char *buf) | |||
1496 | if (l == -1) | 1502 | if (l == -1) |
1497 | status_line_bold_errno(fn); | 1503 | status_line_bold_errno(fn); |
1498 | } else { | 1504 | } else { |
1505 | // how many lines written | ||
1506 | li = count_lines(q, q + l - 1); | ||
1499 | status_line("'%s' %dL, %dC", fn, li, l); | 1507 | status_line("'%s' %dL, %dC", fn, li, l); |
1500 | if (q == text && r == end - 1 && l == size) { | 1508 | if (l == size) { |
1501 | modified_count = 0; | 1509 | if (q == text && q + l == end) { |
1502 | last_modified_count = -1; | 1510 | modified_count = 0; |
1503 | } | 1511 | last_modified_count = -1; |
1504 | if ((cmd[0] == 'x' || cmd[1] == 'q' || cmd[1] == 'n' | 1512 | } |
1505 | || cmd[0] == 'X' || cmd[1] == 'Q' || cmd[1] == 'N' | 1513 | if (cmd[0] == 'x' |
1506 | ) | 1514 | || cmd[1] == 'q' || cmd[1] == 'n' |
1507 | && l == size | 1515 | || cmd[1] == 'Q' || cmd[1] == 'N' |
1508 | ) { | 1516 | ) { |
1509 | editing = 0; | 1517 | editing = 0; |
1518 | } | ||
1510 | } | 1519 | } |
1511 | } | 1520 | } |
1512 | #if ENABLE_FEATURE_VI_YANKMARK | 1521 | #if ENABLE_FEATURE_VI_YANKMARK |
@@ -2816,8 +2825,15 @@ static int readit(void) // read (maybe cursor) key from stdin | |||
2816 | int c; | 2825 | int c; |
2817 | 2826 | ||
2818 | fflush_all(); | 2827 | fflush_all(); |
2819 | c = read_key(STDIN_FILENO, readbuffer, /*timeout off:*/ -2); | 2828 | |
2829 | // Wait for input. TIMEOUT = -1 makes read_key wait even | ||
2830 | // on nonblocking stdin. | ||
2831 | // Note: read_key sets errno to 0 on success. | ||
2832 | again: | ||
2833 | c = read_key(STDIN_FILENO, readbuffer, /*timeout:*/ -1); | ||
2820 | if (c == -1) { // EOF/error | 2834 | if (c == -1) { // EOF/error |
2835 | if (errno == EAGAIN) // paranoia | ||
2836 | goto again; | ||
2821 | go_bottom_and_clear_to_eol(); | 2837 | go_bottom_and_clear_to_eol(); |
2822 | cookmode(); // terminal to "cooked" | 2838 | cookmode(); // terminal to "cooked" |
2823 | bb_error_msg_and_die("can't read user input"); | 2839 | bb_error_msg_and_die("can't read user input"); |