busybox: Move libresolv detection to LEDE Makefile
[openwrt/openwrt.git] / package / utils / busybox / patches / 401-vi-don-t-touch-file-with-x-when-modified_count-0.patch
1 From e88608eae24ae5934034e1ecb6c494fefbf1b9ae Mon Sep 17 00:00:00 2001
2 From: Denys Vlasenko <vda.linux@googlemail.com>
3 Date: Mon, 13 Mar 2017 20:50:42 +0100
4 Subject: [PATCH 1/2] vi: don't touch file with :x when modified_count == 0
5
6 Along with it, there are other changes
7
8 - Check for uppercase X is removed as the expression will be always false and
9 :X itself is another totally different command in standard vim
10 - The status line will show number of written lines instead of lines requested
11 by the colon command. This is also how the standard vim is doing, though
12 the difference is that '!' has to be explicitly specified in vim to allow
13 partial writes
14
15 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
17 ---
18 editors/vi.c | 43 ++++++++++++++++++++++++++-----------------
19 1 file changed, 26 insertions(+), 17 deletions(-)
20
21 --- a/editors/vi.c
22 +++ b/editors/vi.c
23 @@ -1038,7 +1038,9 @@ static void colon(char *buf)
24 || strncmp(p, "wn", cnt) == 0
25 || (p[0] == 'x' && !p[1])
26 ) {
27 - cnt = file_write(current_filename, text, end - 1);
28 + if (modified_count != 0 || p[0] != 'x') {
29 + cnt = file_write(current_filename, text, end - 1);
30 + }
31 if (cnt < 0) {
32 if (cnt == -1)
33 status_line_bold("Write error: %s", strerror(errno));
34 @@ -1049,8 +1051,9 @@ static void colon(char *buf)
35 current_filename,
36 count_lines(text, end - 1), cnt
37 );
38 - if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n'
39 - || p[0] == 'X' || p[1] == 'Q' || p[1] == 'N'
40 + if (p[0] == 'x'
41 + || p[1] == 'q' || p[1] == 'n'
42 + || p[1] == 'Q' || p[1] == 'N'
43 ) {
44 editing = 0;
45 }
46 @@ -1480,16 +1483,19 @@ static void colon(char *buf)
47 goto ret;
48 }
49 #endif
50 - // how many lines in text[]?
51 - li = count_lines(q, r);
52 - size = r - q + 1;
53 //if (useforce) {
54 // if "fn" is not write-able, chmod u+w
55 // sprintf(syscmd, "chmod u+w %s", fn);
56 // system(syscmd);
57 // forced = TRUE;
58 //}
59 - l = file_write(fn, q, r);
60 + if (modified_count != 0 || cmd[0] != 'x') {
61 + size = r - q + 1;
62 + l = file_write(fn, q, r);
63 + } else {
64 + size = 0;
65 + l = 0;
66 + }
67 //if (useforce && forced) {
68 // chmod u-w
69 // sprintf(syscmd, "chmod u-w %s", fn);
70 @@ -1500,17 +1506,20 @@ static void colon(char *buf)
71 if (l == -1)
72 status_line_bold_errno(fn);
73 } else {
74 + // how many lines written
75 + li = count_lines(q, q + l - 1);
76 status_line("'%s' %dL, %dC", fn, li, l);
77 - if (q == text && r == end - 1 && l == size) {
78 - modified_count = 0;
79 - last_modified_count = -1;
80 - }
81 - if ((cmd[0] == 'x' || cmd[1] == 'q' || cmd[1] == 'n'
82 - || cmd[0] == 'X' || cmd[1] == 'Q' || cmd[1] == 'N'
83 - )
84 - && l == size
85 - ) {
86 - editing = 0;
87 + if (l == size) {
88 + if (q == text && q + l == end) {
89 + modified_count = 0;
90 + last_modified_count = -1;
91 + }
92 + if (cmd[0] == 'x'
93 + || cmd[1] == 'q' || cmd[1] == 'n'
94 + || cmd[1] == 'Q' || cmd[1] == 'N'
95 + ) {
96 + editing = 0;
97 + }
98 }
99 }
100 #if ENABLE_FEATURE_VI_YANKMARK