diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/sed.c | 13 | ||||
-rw-r--r-- | editors/vi.c | 20 |
2 files changed, 19 insertions, 14 deletions
diff --git a/editors/sed.c b/editors/sed.c index 7af8f867a..7d6e7e79f 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -61,6 +61,10 @@ | |||
61 | #include "libbb.h" | 61 | #include "libbb.h" |
62 | #include "xregex.h" | 62 | #include "xregex.h" |
63 | 63 | ||
64 | enum { | ||
65 | OPT_in_place = 1 << 0, | ||
66 | }; | ||
67 | |||
64 | /* Each sed command turns into one of these structures. */ | 68 | /* Each sed command turns into one of these structures. */ |
65 | typedef struct sed_cmd_s { | 69 | typedef struct sed_cmd_s { |
66 | /* Ordered by alignment requirements: currently 36 bytes on x86 */ | 70 | /* Ordered by alignment requirements: currently 36 bytes on x86 */ |
@@ -938,8 +942,11 @@ static void process_files(void) | |||
938 | 942 | ||
939 | if (matched) { | 943 | if (matched) { |
940 | /* once matched, "n,xxx" range is dead, disabling it */ | 944 | /* once matched, "n,xxx" range is dead, disabling it */ |
941 | if (sed_cmd->beg_line > 0) | 945 | if (sed_cmd->beg_line > 0 |
946 | && !(option_mask32 & OPT_in_place) /* but not for -i */ | ||
947 | ) { | ||
942 | sed_cmd->beg_line = -2; | 948 | sed_cmd->beg_line = -2; |
949 | } | ||
943 | sed_cmd->in_match = !( | 950 | sed_cmd->in_match = !( |
944 | /* has the ending line come, or is this a single address command? */ | 951 | /* has the ending line come, or is this a single address command? */ |
945 | (sed_cmd->end_line ? | 952 | (sed_cmd->end_line ? |
@@ -1270,9 +1277,6 @@ static void add_cmd_block(char *cmdstr) | |||
1270 | int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1277 | int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1271 | int sed_main(int argc UNUSED_PARAM, char **argv) | 1278 | int sed_main(int argc UNUSED_PARAM, char **argv) |
1272 | { | 1279 | { |
1273 | enum { | ||
1274 | OPT_in_place = 1 << 0, | ||
1275 | }; | ||
1276 | unsigned opt; | 1280 | unsigned opt; |
1277 | llist_t *opt_e, *opt_f; | 1281 | llist_t *opt_e, *opt_f; |
1278 | int status = EXIT_SUCCESS; | 1282 | int status = EXIT_SUCCESS; |
@@ -1292,6 +1296,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1292 | opt_e = opt_f = NULL; | 1296 | opt_e = opt_f = NULL; |
1293 | opt_complementary = "e::f::" /* can occur multiple times */ | 1297 | opt_complementary = "e::f::" /* can occur multiple times */ |
1294 | "nn"; /* count -n */ | 1298 | "nn"; /* count -n */ |
1299 | /* -i must be first, to match OPT_in_place definition */ | ||
1295 | opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, | 1300 | opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, |
1296 | &G.be_quiet); /* counter for -n */ | 1301 | &G.be_quiet); /* counter for -n */ |
1297 | //argc -= optind; | 1302 | //argc -= optind; |
diff --git a/editors/vi.c b/editors/vi.c index 0f412c362..73e095cf8 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -504,20 +504,17 @@ static int init_text_buffer(char *fn) | |||
504 | } | 504 | } |
505 | 505 | ||
506 | #if ENABLE_FEATURE_VI_WIN_RESIZE | 506 | #if ENABLE_FEATURE_VI_WIN_RESIZE |
507 | static void query_screen_dimensions(void) | 507 | static int query_screen_dimensions(void) |
508 | { | 508 | { |
509 | # if ENABLE_FEATURE_VI_ASK_TERMINAL | 509 | int err = get_terminal_width_height(STDIN_FILENO, &columns, &rows); |
510 | if (!G.get_rowcol_error) | ||
511 | G.get_rowcol_error = | ||
512 | # endif | ||
513 | get_terminal_width_height(STDIN_FILENO, &columns, &rows); | ||
514 | if (rows > MAX_SCR_ROWS) | 510 | if (rows > MAX_SCR_ROWS) |
515 | rows = MAX_SCR_ROWS; | 511 | rows = MAX_SCR_ROWS; |
516 | if (columns > MAX_SCR_COLS) | 512 | if (columns > MAX_SCR_COLS) |
517 | columns = MAX_SCR_COLS; | 513 | columns = MAX_SCR_COLS; |
514 | return err; | ||
518 | } | 515 | } |
519 | #else | 516 | #else |
520 | # define query_screen_dimensions() ((void)0) | 517 | # define query_screen_dimensions() (0) |
521 | #endif | 518 | #endif |
522 | 519 | ||
523 | static void edit_file(char *fn) | 520 | static void edit_file(char *fn) |
@@ -536,7 +533,7 @@ static void edit_file(char *fn) | |||
536 | rows = 24; | 533 | rows = 24; |
537 | columns = 80; | 534 | columns = 80; |
538 | size = 0; | 535 | size = 0; |
539 | query_screen_dimensions(); | 536 | IF_FEATURE_VI_ASK_TERMINAL(G.get_rowcol_error =) query_screen_dimensions(); |
540 | #if ENABLE_FEATURE_VI_ASK_TERMINAL | 537 | #if ENABLE_FEATURE_VI_ASK_TERMINAL |
541 | if (G.get_rowcol_error /* TODO? && no input on stdin */) { | 538 | if (G.get_rowcol_error /* TODO? && no input on stdin */) { |
542 | uint64_t k; | 539 | uint64_t k; |
@@ -546,9 +543,12 @@ static void edit_file(char *fn) | |||
546 | if ((int32_t)k == KEYCODE_CURSOR_POS) { | 543 | if ((int32_t)k == KEYCODE_CURSOR_POS) { |
547 | uint32_t rc = (k >> 32); | 544 | uint32_t rc = (k >> 32); |
548 | columns = (rc & 0x7fff); | 545 | columns = (rc & 0x7fff); |
546 | if (columns > MAX_SCR_COLS) | ||
547 | columns = MAX_SCR_COLS; | ||
549 | rows = ((rc >> 16) & 0x7fff); | 548 | rows = ((rc >> 16) & 0x7fff); |
549 | if (rows > MAX_SCR_ROWS) | ||
550 | rows = MAX_SCR_ROWS; | ||
550 | } | 551 | } |
551 | query_screen_dimensions(); | ||
552 | } | 552 | } |
553 | #endif | 553 | #endif |
554 | new_screen(rows, columns); // get memory for virtual screen | 554 | new_screen(rows, columns); // get memory for virtual screen |
@@ -2797,7 +2797,7 @@ static void refresh(int full_screen) | |||
2797 | int li, changed; | 2797 | int li, changed; |
2798 | char *tp, *sp; // pointer into text[] and screen[] | 2798 | char *tp, *sp; // pointer into text[] and screen[] |
2799 | 2799 | ||
2800 | if (ENABLE_FEATURE_VI_WIN_RESIZE) { | 2800 | if (ENABLE_FEATURE_VI_WIN_RESIZE IF_FEATURE_VI_ASK_TERMINAL(&& !G.get_rowcol_error) ) { |
2801 | unsigned c = columns, r = rows; | 2801 | unsigned c = columns, r = rows; |
2802 | query_screen_dimensions(); | 2802 | query_screen_dimensions(); |
2803 | full_screen |= (c - columns) | (r - rows); | 2803 | full_screen |= (c - columns) | (r - rows); |