Lines 1-16
Link Here
|
1 |
--- file.c.orig 2017-12-13 17:48:59 UTC |
1 |
--- file.c.orig 2019-05-11 16:23:57 UTC |
2 |
+++ file.c |
2 |
+++ file.c |
3 |
@@ -202,7 +202,12 @@ int savefile() { |
3 |
@@ -189,21 +189,23 @@ int modcheck() { |
4 |
del_range_chars(name, 0, 1 + force_rewrite); |
4 |
|
|
|
5 |
int savefile() { |
6 |
int force_rewrite = 0; |
7 |
+ int shall_quit = 0; |
8 |
char name[BUFFERSIZE]; |
9 |
#ifndef NO_WORDEXP |
10 |
size_t len; |
11 |
wordexp_t p; |
12 |
#endif |
13 |
|
14 |
- if (! curfile[0] && wcslen(inputline) < 3) { // casos ":w" ":w!" ":x" ":x!" |
15 |
+ if (! curfile[0] && wcslen(inputline) < 3) { // casos ":w" ":w!" ":wq" ":x" ":x!" |
16 |
sc_error("There is no filename"); |
17 |
return -1; |
18 |
} |
19 |
|
20 |
if (inputline[1] == L'!') force_rewrite = 1; |
21 |
+ if (inputline[1] == L'q') shall_quit = 1; |
22 |
|
23 |
wcstombs(name, inputline, BUFFERSIZE); |
24 |
- del_range_chars(name, 0, 1 + force_rewrite); |
25 |
+ del_range_chars(name, 0, 1 + force_rewrite + shall_quit); |
26 |
|
27 |
#ifndef NO_WORDEXP |
5 |
wordexp(name, &p, 0); |
28 |
wordexp(name, &p, 0); |
|
|
29 |
@@ -221,7 +223,7 @@ int savefile() { |
30 |
#endif |
6 |
|
31 |
|
7 |
- if (! force_rewrite && p.we_wordv[0] && file_exists(p.we_wordv[0])) { |
32 |
if (! force_rewrite && file_exists(name)) { |
8 |
+ if (wcslen(inputline) > 2 && (!p.we_wordv || !p.we_wordv[0])) { |
33 |
- sc_error("File already exists. Use \"!\" to force rewrite."); |
9 |
+ sc_error("Trailing space(s)"); |
34 |
+ sc_error("File already exists. Use \"w!\" to force rewrite."); |
10 |
+ return -1; |
|
|
11 |
+ } |
12 |
+ |
13 |
+ if (! force_rewrite && p.we_wordv && p.we_wordv[0] && file_exists(p.we_wordv[0])) { |
14 |
sc_error("File already exists. Use \"!\" to force rewrite."); |
15 |
wordfree(&p); |
16 |
return -1; |
35 |
return -1; |
|
|
36 |
} |
37 |
|
38 |
@@ -235,7 +237,7 @@ int savefile() { |
39 |
// if it exists and no '!' is set, return. |
40 |
if (!strlen(curfile) && backup_exists(name)) { |
41 |
if (!force_rewrite) { |
42 |
- sc_error("Backup file of %s exists. Use \"!\" to force the write process.", name); |
43 |
+ sc_error("Backup file of %s exists. Use \"w!\" to force the write process.", name); |
44 |
return -1; |
45 |
} else remove_backup(name); |
46 |
} |