diff options
Diffstat (limited to 'src/scroll.c')
| -rw-r--r-- | src/scroll.c | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/src/scroll.c b/src/scroll.c index abc5c17400a..b9ed8c04ba8 100644 --- a/src/scroll.c +++ b/src/scroll.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* Calculate what line insertion or deletion to do, and do it | 1 | /* Calculate what line insertion or deletion to do, and do it |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1986, 1990, 1993-1994, 2001-2012 | 3 | Copyright (C) 1985-1986, 1990, 1993-1994, 2001-2013 Free Software |
| 4 | Free Software Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 7 | 7 | ||
| @@ -21,7 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | #include <stdio.h> | 23 | #include <stdio.h> |
| 24 | #include <setjmp.h> | 24 | |
| 25 | #include "lisp.h" | 25 | #include "lisp.h" |
| 26 | #include "termchar.h" | 26 | #include "termchar.h" |
| 27 | #include "dispextern.h" | 27 | #include "dispextern.h" |
| @@ -86,7 +86,7 @@ static void do_scrolling (struct frame *, | |||
| 86 | new contents appears. */ | 86 | new contents appears. */ |
| 87 | 87 | ||
| 88 | static void | 88 | static void |
| 89 | calculate_scrolling (FRAME_PTR frame, | 89 | calculate_scrolling (struct frame *frame, |
| 90 | /* matrix is of size window_size + 1 on each side. */ | 90 | /* matrix is of size window_size + 1 on each side. */ |
| 91 | struct matrix_elt *matrix, | 91 | struct matrix_elt *matrix, |
| 92 | int window_size, int lines_below, | 92 | int window_size, int lines_below, |
| @@ -195,13 +195,13 @@ calculate_scrolling (FRAME_PTR frame, | |||
| 195 | { | 195 | { |
| 196 | cost = p1->writecost + first_insert_cost[i]; | 196 | cost = p1->writecost + first_insert_cost[i]; |
| 197 | if ((int) p1->insertcount > i) | 197 | if ((int) p1->insertcount > i) |
| 198 | abort (); | 198 | emacs_abort (); |
| 199 | cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount]; | 199 | cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount]; |
| 200 | } | 200 | } |
| 201 | p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost; | 201 | p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost; |
| 202 | p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1; | 202 | p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1; |
| 203 | if ((int) p->insertcount > i) | 203 | if ((int) p->insertcount > i) |
| 204 | abort (); | 204 | emacs_abort (); |
| 205 | 205 | ||
| 206 | /* Calculate the cost if we do a delete line after | 206 | /* Calculate the cost if we do a delete line after |
| 207 | outputting this line. | 207 | outputting this line. |
| @@ -246,31 +246,30 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 246 | struct matrix_elt *p; | 246 | struct matrix_elt *p; |
| 247 | int i, j, k; | 247 | int i, j, k; |
| 248 | 248 | ||
| 249 | /* Set to 1 if we have set a terminal window with | 249 | /* True if we have set a terminal window with set_terminal_window. */ |
| 250 | set_terminal_window. It's unsigned to work around GCC bug 48228. */ | 250 | bool terminal_window_p = 0; |
| 251 | unsigned int terminal_window_p = 0; | ||
| 252 | 251 | ||
| 253 | /* A queue for line insertions to be done. */ | 252 | /* A queue for line insertions to be done. */ |
| 254 | struct queue { int count, pos; }; | 253 | struct queue { int count, pos; }; |
| 255 | struct queue *queue_start | 254 | struct queue *queue_start |
| 256 | = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue)); | 255 | = alloca (current_matrix->nrows * sizeof *queue_start); |
| 257 | struct queue *queue = queue_start; | 256 | struct queue *queue = queue_start; |
| 258 | 257 | ||
| 259 | char *retained_p = (char *) alloca (window_size * sizeof (char)); | 258 | char *retained_p = alloca (window_size * sizeof *retained_p); |
| 260 | int *copy_from = (int *) alloca (window_size * sizeof (int)); | 259 | int *copy_from = alloca (window_size * sizeof *copy_from); |
| 261 | 260 | ||
| 262 | /* Zero means line is empty. */ | 261 | /* Zero means line is empty. */ |
| 263 | memset (retained_p, 0, window_size * sizeof (char)); | 262 | memset (retained_p, 0, window_size * sizeof (char)); |
| 264 | for (k = 0; k < window_size; ++k) | 263 | for (k = 0; k < window_size; ++k) |
| 265 | copy_from[k] = -1; | 264 | copy_from[k] = -1; |
| 266 | 265 | ||
| 267 | #if GLYPH_DEBUG | 266 | #ifdef GLYPH_DEBUG |
| 268 | # define CHECK_BOUNDS \ | 267 | # define CHECK_BOUNDS \ |
| 269 | do \ | 268 | do \ |
| 270 | { \ | 269 | { \ |
| 271 | int ck; \ | 270 | int ck; \ |
| 272 | for (ck = 0; ck < window_size; ++ck) \ | 271 | for (ck = 0; ck < window_size; ++ck) \ |
| 273 | xassert (copy_from[ck] == -1 \ | 272 | eassert (copy_from[ck] == -1 \ |
| 274 | || (copy_from[ck] >= 0 && copy_from[ck] < window_size)); \ | 273 | || (copy_from[ck] >= 0 && copy_from[ck] < window_size)); \ |
| 275 | } \ | 274 | } \ |
| 276 | while (0); | 275 | while (0); |
| @@ -317,12 +316,12 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 317 | { | 316 | { |
| 318 | /* Best thing done here is no insert or delete, i.e. a write. */ | 317 | /* Best thing done here is no insert or delete, i.e. a write. */ |
| 319 | --i, --j; | 318 | --i, --j; |
| 320 | xassert (i >= 0 && i < window_size); | 319 | eassert (i >= 0 && i < window_size); |
| 321 | xassert (j >= 0 && j < window_size); | 320 | eassert (j >= 0 && j < window_size); |
| 322 | copy_from[i] = j; | 321 | copy_from[i] = j; |
| 323 | retained_p[j] = 1; | 322 | retained_p[j] = 1; |
| 324 | 323 | ||
| 325 | #if GLYPH_DEBUG | 324 | #ifdef GLYPH_DEBUG |
| 326 | CHECK_BOUNDS; | 325 | CHECK_BOUNDS; |
| 327 | #endif | 326 | #endif |
| 328 | } | 327 | } |
| @@ -368,13 +367,13 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 368 | } | 367 | } |
| 369 | 368 | ||
| 370 | for (k = 0; k < window_size; ++k) | 369 | for (k = 0; k < window_size; ++k) |
| 371 | xassert (copy_from[k] >= 0 && copy_from[k] < window_size); | 370 | eassert (copy_from[k] >= 0 && copy_from[k] < window_size); |
| 372 | 371 | ||
| 373 | /* Perform the row swizzling. */ | 372 | /* Perform the row swizzling. */ |
| 374 | mirrored_line_dance (current_matrix, unchanged_at_top, window_size, | 373 | mirrored_line_dance (current_matrix, unchanged_at_top, window_size, |
| 375 | copy_from, retained_p); | 374 | copy_from, retained_p); |
| 376 | 375 | ||
| 377 | /* Some sanity checks if GLYPH_DEBUG != 0. */ | 376 | /* Some sanity checks if GLYPH_DEBUG is defined. */ |
| 378 | CHECK_MATRIX (current_matrix); | 377 | CHECK_MATRIX (current_matrix); |
| 379 | 378 | ||
| 380 | if (terminal_window_p) | 379 | if (terminal_window_p) |
| @@ -423,7 +422,7 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 423 | is the equivalent of draw_cost for the old line contents */ | 422 | is the equivalent of draw_cost for the old line contents */ |
| 424 | 423 | ||
| 425 | static void | 424 | static void |
| 426 | calculate_direct_scrolling (FRAME_PTR frame, | 425 | calculate_direct_scrolling (struct frame *frame, |
| 427 | /* matrix is of size window_size + 1 on each side. */ | 426 | /* matrix is of size window_size + 1 on each side. */ |
| 428 | struct matrix_elt *matrix, | 427 | struct matrix_elt *matrix, |
| 429 | int window_size, int lines_below, | 428 | int window_size, int lines_below, |
| @@ -653,29 +652,26 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 653 | 652 | ||
| 654 | /* A queue of deletions and insertions to be performed. */ | 653 | /* A queue of deletions and insertions to be performed. */ |
| 655 | struct alt_queue { int count, pos, window; }; | 654 | struct alt_queue { int count, pos, window; }; |
| 656 | struct alt_queue *queue_start = (struct alt_queue *) | 655 | struct alt_queue *queue_start = alloca (window_size * sizeof *queue_start); |
| 657 | alloca (window_size * sizeof *queue_start); | ||
| 658 | struct alt_queue *queue = queue_start; | 656 | struct alt_queue *queue = queue_start; |
| 659 | 657 | ||
| 660 | /* Set to 1 if a terminal window has been set with | 658 | /* True if a terminal window has been set with set_terminal_window. */ |
| 661 | set_terminal_window: */ | 659 | bool terminal_window_p = 0; |
| 662 | int terminal_window_p = 0; | ||
| 663 | 660 | ||
| 664 | /* A nonzero value of write_follows indicates that a write has been | 661 | /* If true, a write has been selected, allowing either an insert or a |
| 665 | selected, allowing either an insert or a delete to be selected | 662 | delete to be selected next. If false, a delete cannot be selected |
| 666 | next. When write_follows is zero, a delete cannot be selected | ||
| 667 | unless j < i, and an insert cannot be selected unless i < j. | 663 | unless j < i, and an insert cannot be selected unless i < j. |
| 668 | This corresponds to a similar restriction (with the ordering | 664 | This corresponds to a similar restriction (with the ordering |
| 669 | reversed) in calculate_direct_scrolling, which is intended to | 665 | reversed) in calculate_direct_scrolling, which is intended to |
| 670 | ensure that lines marked as inserted will be blank. */ | 666 | ensure that lines marked as inserted will be blank. */ |
| 671 | int write_follows_p = 1; | 667 | bool write_follows_p = 1; |
| 672 | 668 | ||
| 673 | /* For each row in the new matrix what row of the old matrix it is. */ | 669 | /* For each row in the new matrix what row of the old matrix it is. */ |
| 674 | int *copy_from = (int *) alloca (window_size * sizeof (int)); | 670 | int *copy_from = alloca (window_size * sizeof *copy_from); |
| 675 | 671 | ||
| 676 | /* Non-zero for each row in the new matrix that is retained from the | 672 | /* Non-zero for each row in the new matrix that is retained from the |
| 677 | old matrix. Lines not retained are empty. */ | 673 | old matrix. Lines not retained are empty. */ |
| 678 | char *retained_p = (char *) alloca (window_size * sizeof (char)); | 674 | char *retained_p = alloca (window_size * sizeof *retained_p); |
| 679 | 675 | ||
| 680 | memset (retained_p, 0, window_size * sizeof (char)); | 676 | memset (retained_p, 0, window_size * sizeof (char)); |
| 681 | 677 | ||
| @@ -728,7 +724,7 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 728 | place they belong. */ | 724 | place they belong. */ |
| 729 | int n_to_write = p->writecount; | 725 | int n_to_write = p->writecount; |
| 730 | write_follows_p = 1; | 726 | write_follows_p = 1; |
| 731 | xassert (n_to_write > 0); | 727 | eassert (n_to_write > 0); |
| 732 | 728 | ||
| 733 | if (i > j) | 729 | if (i > j) |
| 734 | { | 730 | { |
| @@ -796,13 +792,12 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, | |||
| 796 | 792 | ||
| 797 | 793 | ||
| 798 | void | 794 | void |
| 799 | scrolling_1 (FRAME_PTR frame, int window_size, int unchanged_at_top, | 795 | scrolling_1 (struct frame *frame, int window_size, int unchanged_at_top, |
| 800 | int unchanged_at_bottom, int *draw_cost, int *old_draw_cost, | 796 | int unchanged_at_bottom, int *draw_cost, int *old_draw_cost, |
| 801 | int *old_hash, int *new_hash, int free_at_end) | 797 | int *old_hash, int *new_hash, int free_at_end) |
| 802 | { | 798 | { |
| 803 | struct matrix_elt *matrix; | 799 | struct matrix_elt *matrix |
| 804 | matrix = ((struct matrix_elt *) | 800 | = alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix); |
| 805 | alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix)); | ||
| 806 | 801 | ||
| 807 | if (FRAME_SCROLL_REGION_OK (frame)) | 802 | if (FRAME_SCROLL_REGION_OK (frame)) |
| 808 | { | 803 | { |
| @@ -886,7 +881,7 @@ scrolling_max_lines_saved (int start, int end, | |||
| 886 | overhead and multiply factor values */ | 881 | overhead and multiply factor values */ |
| 887 | 882 | ||
| 888 | static void | 883 | static void |
| 889 | line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn, | 884 | line_ins_del (struct frame *frame, int ov1, int pf1, int ovn, int pfn, |
| 890 | register int *ov, register int *mf) | 885 | register int *ov, register int *mf) |
| 891 | { | 886 | { |
| 892 | register int i; | 887 | register int i; |
| @@ -904,7 +899,7 @@ line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn, | |||
| 904 | } | 899 | } |
| 905 | 900 | ||
| 906 | static void | 901 | static void |
| 907 | ins_del_costs (FRAME_PTR frame, | 902 | ins_del_costs (struct frame *frame, |
| 908 | const char *one_line_string, const char *multi_string, | 903 | const char *one_line_string, const char *multi_string, |
| 909 | const char *setup_string, const char *cleanup_string, | 904 | const char *setup_string, const char *cleanup_string, |
| 910 | int *costvec, int *ncostvec, | 905 | int *costvec, int *ncostvec, |
| @@ -960,7 +955,7 @@ ins_del_costs (FRAME_PTR frame, | |||
| 960 | */ | 955 | */ |
| 961 | 956 | ||
| 962 | void | 957 | void |
| 963 | do_line_insertion_deletion_costs (FRAME_PTR frame, | 958 | do_line_insertion_deletion_costs (struct frame *frame, |
| 964 | const char *ins_line_string, | 959 | const char *ins_line_string, |
| 965 | const char *multi_ins_string, | 960 | const char *multi_ins_string, |
| 966 | const char *del_line_string, | 961 | const char *del_line_string, |