aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/diff.c27
-rw-r--r--editors/vi.c20
2 files changed, 35 insertions, 12 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 07594e8d8..a3ca2b660 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -121,6 +121,7 @@ typedef struct FILE_and_pos_t {
121struct globals { 121struct globals {
122 smallint exit_status; 122 smallint exit_status;
123 int opt_U_context; 123 int opt_U_context;
124 const char *other_dir;
124 char *label[2]; 125 char *label[2];
125 struct stat stb[2]; 126 struct stat stb[2];
126}; 127};
@@ -760,9 +761,11 @@ static int FAST_FUNC add_to_dirlist(const char *filename,
760 void *userdata, int depth UNUSED_PARAM) 761 void *userdata, int depth UNUSED_PARAM)
761{ 762{
762 struct dlist *const l = userdata; 763 struct dlist *const l = userdata;
764 const char *file = filename + l->len;
765 while (*file == '/')
766 file++;
763 l->dl = xrealloc_vector(l->dl, 6, l->e); 767 l->dl = xrealloc_vector(l->dl, 6, l->e);
764 /* + 1 skips "/" after dirname */ 768 l->dl[l->e] = xstrdup(file);
765 l->dl[l->e] = xstrdup(filename + l->len + 1);
766 l->e++; 769 l->e++;
767 return TRUE; 770 return TRUE;
768} 771}
@@ -778,6 +781,25 @@ static int FAST_FUNC skip_dir(const char *filename,
778 add_to_dirlist(filename, sb, userdata, depth); 781 add_to_dirlist(filename, sb, userdata, depth);
779 return SKIP; 782 return SKIP;
780 } 783 }
784 if (!(option_mask32 & FLAG(N))) {
785 /* -r without -N: no need to recurse into dirs
786 * which do not exist on the "other side".
787 * Testcase: diff -r /tmp /
788 * (it would recurse deep into /proc without this code) */
789 struct dlist *const l = userdata;
790 filename += l->len;
791 if (filename[0]) {
792 struct stat osb;
793 char *othername = concat_path_file(G.other_dir, filename);
794 int r = stat(othername, &osb);
795 free(othername);
796 if (r != 0 || !S_ISDIR(osb.st_mode)) {
797 /* other dir doesn't have similarly named
798 * directory, don't recurse */
799 return SKIP;
800 }
801 }
802 }
781 return TRUE; 803 return TRUE;
782} 804}
783 805
@@ -791,6 +813,7 @@ static void diffdir(char *p[2], const char *s_start)
791 /*list[i].s = list[i].e = 0; - memset did it */ 813 /*list[i].s = list[i].e = 0; - memset did it */
792 /*list[i].dl = NULL; */ 814 /*list[i].dl = NULL; */
793 815
816 G.other_dir = p[1 - i];
794 /* We need to trim root directory prefix. 817 /* We need to trim root directory prefix.
795 * Using list.len to specify its length, 818 * Using list.len to specify its length,
796 * add_to_dirlist will remove it. */ 819 * add_to_dirlist will remove it. */
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
507static void query_screen_dimensions(void) 507static 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
523static void edit_file(char *fn) 520static 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);