diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-06 23:22:49 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-06 23:22:49 +0100 |
| commit | 5de72223957a8bdbda4e7f6cde2273d9331b8b74 (patch) | |
| tree | 61badf15fa6de33a035bc0b53d03bf7ef088ee8e | |
| parent | 3620c4ee677224aed6d6fa02aa8d034b4495370e (diff) | |
| download | busybox-w32-5de72223957a8bdbda4e7f6cde2273d9331b8b74.tar.gz busybox-w32-5de72223957a8bdbda4e7f6cde2273d9331b8b74.tar.bz2 busybox-w32-5de72223957a8bdbda4e7f6cde2273d9331b8b74.zip | |
vi: code shrink
function old new delta
colon 4005 3989 -16
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | editors/vi.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/editors/vi.c b/editors/vi.c index 814a63a7b..13f79ed10 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
| @@ -2849,16 +2849,16 @@ static void colon(char *buf) | |||
| 2849 | } | 2849 | } |
| 2850 | not_implemented(p); | 2850 | not_implemented(p); |
| 2851 | #else | 2851 | #else |
| 2852 | char c, *q, *r; | 2852 | char cmd[MAX_INPUT_LEN], *args; |
| 2853 | char *fn, cmd[MAX_INPUT_LEN], *args; | ||
| 2854 | char *exp = NULL; | ||
| 2855 | char *useforce; | ||
| 2856 | int cmdlen; | 2853 | int cmdlen; |
| 2854 | char *useforce; | ||
| 2855 | char *q, *r; | ||
| 2857 | int b, e; | 2856 | int b, e; |
| 2858 | // check how many addresses we got | 2857 | // check how many addresses we got |
| 2859 | # define GOT_ADDRESS (got & 1) | 2858 | # define GOT_ADDRESS (got & 1) |
| 2860 | # define GOT_RANGE ((got & 3) == 3) | 2859 | # define GOT_RANGE ((got & 3) == 3) |
| 2861 | unsigned got; | 2860 | unsigned got; |
| 2861 | char *exp = NULL; // may hold expand_args() result: if VI_COLON_EXPAND, needs freeing! | ||
| 2862 | 2862 | ||
| 2863 | // :3154 // if (-e line 3154) goto it else stay put | 2863 | // :3154 // if (-e line 3154) goto it else stay put |
| 2864 | // :4,33w! foo // write a portion of buffer to file "foo" | 2864 | // :4,33w! foo // write a portion of buffer to file "foo" |
| @@ -2880,8 +2880,6 @@ static void colon(char *buf) | |||
| 2880 | if (!*buf || *buf == '"') | 2880 | if (!*buf || *buf == '"') |
| 2881 | goto ret; // ignore empty lines or those starting with '"' | 2881 | goto ret; // ignore empty lines or those starting with '"' |
| 2882 | 2882 | ||
| 2883 | fn = current_filename; | ||
| 2884 | |||
| 2885 | // look for optional address(es) ":." ":1" ":1,9" ":'q,'a" ":%" | 2883 | // look for optional address(es) ":." ":1" ":1,9" ":'q,'a" ":%" |
| 2886 | b = e = -1; | 2884 | b = e = -1; |
| 2887 | got = 0; | 2885 | got = 0; |
| @@ -2901,11 +2899,9 @@ static void colon(char *buf) | |||
| 2901 | 2899 | ||
| 2902 | // assume the command will want a range, certain commands | 2900 | // assume the command will want a range, certain commands |
| 2903 | // (read, substitute) need to adjust these assumptions | 2901 | // (read, substitute) need to adjust these assumptions |
| 2904 | if (!GOT_ADDRESS) { | 2902 | q = text; // if no addr, use 1,$ for the range |
| 2905 | q = text; // no addr, use 1,$ for the range | 2903 | r = end - 1; |
| 2906 | r = end - 1; | 2904 | if (GOT_ADDRESS) { // at least one addr was given, get its details |
| 2907 | } else { | ||
| 2908 | // at least one addr was given, get its details | ||
| 2909 | int lines; | 2905 | int lines; |
| 2910 | if (e < 0 | 2906 | if (e < 0 |
| 2911 | || e > (lines = count_lines(text, end - 1)) | 2907 | || e > (lines = count_lines(text, end - 1)) |
| @@ -2971,16 +2967,18 @@ static void colon(char *buf) | |||
| 2971 | dot_skip_over_ws(); | 2967 | dot_skip_over_ws(); |
| 2972 | } else if (strncmp(cmd, "edit", cmdlen) == 0) { // Edit a file | 2968 | } else if (strncmp(cmd, "edit", cmdlen) == 0) { // Edit a file |
| 2973 | int size; | 2969 | int size; |
| 2970 | char *fn; | ||
| 2974 | 2971 | ||
| 2975 | // don't edit, if the current file has been modified | 2972 | // don't edit, if the current file has been modified |
| 2976 | if (modified_count && !useforce) { | 2973 | if (modified_count && !useforce) { |
| 2977 | status_line_bold("No write since last change (:%s! overrides)", cmd); | 2974 | status_line_bold("No write since last change (:%s! overrides)", cmd); |
| 2978 | goto ret; | 2975 | goto ret; |
| 2979 | } | 2976 | } |
| 2977 | fn = current_filename; | ||
| 2980 | if (args[0]) { | 2978 | if (args[0]) { |
| 2981 | // the user supplied a file name | 2979 | // the user supplied a file name |
| 2982 | fn = exp = expand_args(args); | 2980 | fn = expand_args(args); |
| 2983 | if (exp == NULL) | 2981 | if (fn == NULL) |
| 2984 | goto ret; | 2982 | goto ret; |
| 2985 | } else if (current_filename == NULL) { | 2983 | } else if (current_filename == NULL) { |
| 2986 | // no user file name, no current name- punt | 2984 | // no user file name, no current name- punt |
| @@ -3041,6 +3039,7 @@ static void colon(char *buf) | |||
| 3041 | go_bottom_and_clear_to_eol(); | 3039 | go_bottom_and_clear_to_eol(); |
| 3042 | puts("\r"); | 3040 | puts("\r"); |
| 3043 | for (; q <= r; q++) { | 3041 | for (; q <= r; q++) { |
| 3042 | char c; | ||
| 3044 | int c_is_no_print; | 3043 | int c_is_no_print; |
| 3045 | 3044 | ||
| 3046 | c = *q; | 3045 | c = *q; |
| @@ -3102,11 +3101,12 @@ static void colon(char *buf) | |||
| 3102 | editing = 0; | 3101 | editing = 0; |
| 3103 | } else if (strncmp(cmd, "read", cmdlen) == 0) { // read file into text[] | 3102 | } else if (strncmp(cmd, "read", cmdlen) == 0) { // read file into text[] |
| 3104 | int size, num; | 3103 | int size, num; |
| 3104 | char *fn = current_filename; | ||
| 3105 | 3105 | ||
| 3106 | if (args[0]) { | 3106 | if (args[0]) { |
| 3107 | // the user supplied a file name | 3107 | // the user supplied a file name |
| 3108 | fn = exp = expand_args(args); | 3108 | fn = expand_args(args); |
| 3109 | if (exp == NULL) | 3109 | if (fn == NULL) |
| 3110 | goto ret; | 3110 | goto ret; |
| 3111 | init_filename(fn); | 3111 | init_filename(fn); |
| 3112 | } else if (current_filename == NULL) { | 3112 | } else if (current_filename == NULL) { |
| @@ -3195,6 +3195,7 @@ static void colon(char *buf) | |||
| 3195 | 3195 | ||
| 3196 | # if ENABLE_FEATURE_VI_SEARCH | 3196 | # if ENABLE_FEATURE_VI_SEARCH |
| 3197 | } else if (cmd[0] == 's') { // substitute a pattern with a replacement pattern | 3197 | } else if (cmd[0] == 's') { // substitute a pattern with a replacement pattern |
| 3198 | char c; | ||
| 3198 | char *F, *R, *flags; | 3199 | char *F, *R, *flags; |
| 3199 | size_t len_F, len_R; | 3200 | size_t len_F, len_R; |
| 3200 | int i; | 3201 | int i; |
| @@ -3341,6 +3342,7 @@ static void colon(char *buf) | |||
| 3341 | ) { | 3342 | ) { |
| 3342 | int size, l; | 3343 | int size, l; |
| 3343 | //int forced = FALSE; | 3344 | //int forced = FALSE; |
| 3345 | char *fn = current_filename; | ||
| 3344 | 3346 | ||
| 3345 | // is there a file name to write to? | 3347 | // is there a file name to write to? |
| 3346 | if (args[0]) { | 3348 | if (args[0]) { |
