diff options
author | Ron Yorston <rmy@pobox.com> | 2023-02-06 10:46:54 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-02-06 10:46:54 +0000 |
commit | c5fe5ad712e11e4d06d5becab5f888531f55a863 (patch) | |
tree | 6a5d5e7902fb4760ae70418e43fe09241759151f | |
parent | 0708c8a68dfaf39ec9c48e477ff44a5c6c7d497c (diff) | |
download | busybox-w32-c5fe5ad712e11e4d06d5becab5f888531f55a863.tar.gz busybox-w32-c5fe5ad712e11e4d06d5becab5f888531f55a863.tar.bz2 busybox-w32-c5fe5ad712e11e4d06d5becab5f888531f55a863.zip |
vi: allow change of 'fileformat' option
For some reason the 'fileformat' option was made read-only when
it was introduced in commit 420afde92e (vi: add fileformats option).
I think I'd read some vim documentation that made it seem more
complicated than it really is.
Costs 48 bytes.
-rw-r--r-- | editors/vi.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/editors/vi.c b/editors/vi.c index 574feb465..d6cfeae0e 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -119,7 +119,7 @@ | |||
119 | //config: help | 119 | //config: help |
120 | //config: Enable the editor to detect the format of files it reads | 120 | //config: Enable the editor to detect the format of files it reads |
121 | //config: so they can be written out with the appropriate line | 121 | //config: so they can be written out with the appropriate line |
122 | //config: endings. Enable the 'fileformats' option. | 122 | //config: endings. Enable the 'fileformat' and 'fileformats' options. |
123 | //config: | 123 | //config: |
124 | //config:config FEATURE_VI_SET | 124 | //config:config FEATURE_VI_SET |
125 | //config: bool "Support :set" | 125 | //config: bool "Support :set" |
@@ -346,9 +346,14 @@ struct globals { | |||
346 | "sm\0""showmatch\0" \ | 346 | "sm\0""showmatch\0" \ |
347 | "ts\0""tabstop\0" | 347 | "ts\0""tabstop\0" |
348 | 348 | ||
349 | #define FF_DOS_UNIX 0 | 349 | #define FF_DOS 0 |
350 | #define FF_UNIX_DOS 1 | 350 | #define FF_UNIX 1 |
351 | #define FORMATS_STR \ | 351 | |
352 | #define FF_STR \ | ||
353 | "dos\0" \ | ||
354 | "unix\0" | ||
355 | |||
356 | #define FFS_STR \ | ||
352 | "dos,unix\0" \ | 357 | "dos,unix\0" \ |
353 | "unix,dos\0" | 358 | "unix,dos\0" |
354 | #else | 359 | #else |
@@ -2111,7 +2116,7 @@ static int file_insert(const char *fn, char *p, int initial) | |||
2111 | # endif | 2116 | # endif |
2112 | #if ENABLE_FEATURE_VI_FILE_FORMAT | 2117 | #if ENABLE_FEATURE_VI_FILE_FORMAT |
2113 | if (initial && cnt > 0) | 2118 | if (initial && cnt > 0) |
2114 | fileformat = cnt == size ? FF_UNIX_DOS : FF_DOS_UNIX; | 2119 | fileformat = cnt == size ? FF_UNIX : FF_DOS; |
2115 | #endif | 2120 | #endif |
2116 | fi: | 2121 | fi: |
2117 | close(fd); | 2122 | close(fd); |
@@ -2453,7 +2458,7 @@ static int file_write(char *fn, char *first, char *last) | |||
2453 | int fd, cnt, charcnt; | 2458 | int fd, cnt, charcnt; |
2454 | #if ENABLE_PLATFORM_MINGW32 | 2459 | #if ENABLE_PLATFORM_MINGW32 |
2455 | # if ENABLE_FEATURE_VI_FILE_FORMAT | 2460 | # if ENABLE_FEATURE_VI_FILE_FORMAT |
2456 | # define dos (fileformat == FF_DOS_UNIX) | 2461 | # define dos (fileformat == FF_DOS) |
2457 | # else | 2462 | # else |
2458 | # define dos (1) | 2463 | # define dos (1) |
2459 | # endif | 2464 | # endif |
@@ -2782,9 +2787,7 @@ static void setops(char *args, int flg_no) | |||
2782 | return; | 2787 | return; |
2783 | } | 2788 | } |
2784 | #else | 2789 | #else |
2785 | if (index & VI_FILEFORMAT) | 2790 | if (index & (VI_TABSTOP | VI_FILEFORMAT | VI_FILEFORMATS)) { |
2786 | goto bad; | ||
2787 | if (index & (VI_TABSTOP | VI_FILEFORMATS)) { | ||
2788 | if (!eq || flg_no) // no "=NNN" or it is "notabstop"? | 2791 | if (!eq || flg_no) // no "=NNN" or it is "notabstop"? |
2789 | goto bad; | 2792 | goto bad; |
2790 | if (index & VI_TABSTOP) { | 2793 | if (index & VI_TABSTOP) { |
@@ -2793,8 +2796,16 @@ static void setops(char *args, int flg_no) | |||
2793 | goto bad; | 2796 | goto bad; |
2794 | tabstop = t; | 2797 | tabstop = t; |
2795 | return; | 2798 | return; |
2799 | } else if (index & VI_FILEFORMAT) { | ||
2800 | int t = index_in_strings(FF_STR, eq + 1); | ||
2801 | if (t < 0) | ||
2802 | goto bad; | ||
2803 | if (fileformat != t) | ||
2804 | modified_count++; | ||
2805 | fileformat = t; | ||
2806 | return; | ||
2796 | } else { // VI_FILEFORMATS | 2807 | } else { // VI_FILEFORMATS |
2797 | int t = index_in_strings(FORMATS_STR, eq + 1); | 2808 | int t = index_in_strings(FFS_STR, eq + 1); |
2798 | if (t < 0) | 2809 | if (t < 0) |
2799 | goto bad; | 2810 | goto bad; |
2800 | fileformats = t; | 2811 | fileformats = t; |
@@ -3321,9 +3332,9 @@ static void colon(char *buf) | |||
3321 | if (!name[0]) | 3332 | if (!name[0]) |
3322 | break; | 3333 | break; |
3323 | if (mask == VI_FILEFORMAT) | 3334 | if (mask == VI_FILEFORMAT) |
3324 | printf("%s=%s ", name, nth_string("dos\0unix\0", fileformat)); | 3335 | printf("%s=%s ", name, nth_string(FF_STR, fileformat)); |
3325 | else if (mask == VI_FILEFORMATS) | 3336 | else if (mask == VI_FILEFORMATS) |
3326 | printf("%s=%s ", name, nth_string(FORMATS_STR, fileformats)); | 3337 | printf("%s=%s ", name, nth_string(FFS_STR, fileformats)); |
3327 | else if (mask == VI_TABSTOP) | 3338 | else if (mask == VI_TABSTOP) |
3328 | printf("%s=%u ", name, tabstop); | 3339 | printf("%s=%u ", name, tabstop); |
3329 | else | 3340 | else |