comparison src/fileio.c @ 6328:e97a1cc44be8

(Finsert_file_contents): Don't let same_at_end be less than same_at_start.
author Richard M. Stallman <rms@gnu.org>
date Mon, 14 Mar 1994 01:29:37 +0000
parents 2a8a76b9a2fe
children c7e1f551e97a
comparison
equal deleted inserted replaced
6327:d93a087868cb 6328:e97a1cc44be8
2605 if (!NILP (replace)) 2605 if (!NILP (replace))
2606 { 2606 {
2607 char buffer[1 << 14]; 2607 char buffer[1 << 14];
2608 int same_at_start = BEGV; 2608 int same_at_start = BEGV;
2609 int same_at_end = ZV; 2609 int same_at_end = ZV;
2610 int overlap;
2611
2610 immediate_quit = 1; 2612 immediate_quit = 1;
2611 QUIT; 2613 QUIT;
2612 /* Count how many chars at the start of the file 2614 /* Count how many chars at the start of the file
2613 match the text at the beginning of the buffer. */ 2615 match the text at the beginning of the buffer. */
2614 while (1) 2616 while (1)
2676 Otherwise loop around and scan the preceding bufferfull. */ 2678 Otherwise loop around and scan the preceding bufferfull. */
2677 if (bufpos != 0) 2679 if (bufpos != 0)
2678 break; 2680 break;
2679 } 2681 }
2680 immediate_quit = 0; 2682 immediate_quit = 0;
2683
2684 /* Don't try to reuse the same piece of text twice. */
2685 overlap = same_at_start - BEGV - (same_at_end + st.st_size - ZV);
2686 if (overlap > 0)
2687 same_at_end += overlap;
2688
2681 /* Arrange to read only the nonmatching middle part of the file. */ 2689 /* Arrange to read only the nonmatching middle part of the file. */
2682 XFASTINT (beg) = same_at_start - BEGV; 2690 XFASTINT (beg) = same_at_start - BEGV;
2683 XFASTINT (end) = st.st_size - (ZV - same_at_end); 2691 XFASTINT (end) = st.st_size - (ZV - same_at_end);
2692
2684 del_range_1 (same_at_start, same_at_end, 0); 2693 del_range_1 (same_at_start, same_at_end, 0);
2685 /* Insert from the file at the proper position. */ 2694 /* Insert from the file at the proper position. */
2686 SET_PT (same_at_start); 2695 SET_PT (same_at_start);
2687 } 2696 }
2688 2697