annotate src/scroll.c @ 9513:76ce1230257f

Use purify-flag not noninteractive.
author Simon Marshall <simon@gnu.org>
date Thu, 13 Oct 1994 07:55:30 +0000
parents cd81dba38a49
children 14cd96eda0e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Calculate what line insertion or deletion to do, and do it,
7307
cd81dba38a49 Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6888
diff changeset
2 Copyright (C) 1985, 1986, 1990, 1993, 1994 Free Software Foundation, Inc.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
732
a8d94735277e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 529
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3356
diff changeset
21 #include <config.h>
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include "termchar.h"
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include "lisp.h"
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "dispextern.h"
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
25 #include "frame.h"
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 extern struct display_line **ophys_lines;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #define max(a, b) ((a) > (b) ? (a) : (b))
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #define min(a, b) ((a) < (b) ? (a) : (b))
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 /* All costs measured in characters.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
33 So no cost can exceed the area of a frame, measured in characters.
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
34 Let's hope this is never more than 1000000 characters. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
36 #define INFINITY 1000000
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 struct matrix_elt
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 /* Cost of outputting through this line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 if no insert/delete is done just above it. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
42 int writecost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 /* Cost of outputting through this line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 if an insert is done just above it. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
45 int insertcost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 /* Cost of outputting through this line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 if a delete is done just above it. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
48 int deletecost;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 /* Number of inserts so far in this run of inserts,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 for the cost in insertcost. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
51 unsigned char insertcount;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 /* Number of deletes so far in this run of deletes,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 for the cost in deletecost. */
6773
ed16e189b9a5 (struct matrix_elt): Use int, not short.
Richard M. Stallman <rms@gnu.org>
parents: 6647
diff changeset
54 unsigned char deletecount;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 };
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 /* Determine, in matrix[i,j], the cost of updating the first j old lines
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 into the first i new lines.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 This involves using insert or delete somewhere if i != j.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 For each matrix elements, three kinds of costs are recorded:
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 the smallest cost that ends with an insert, the smallest
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 cost that ends with a delete, and the smallest cost that
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 ends with neither one. These are kept separate because
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 on some terminals the cost of doing an insert varies
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 depending on whether one was just done, etc. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 /* draw_cost[VPOS] is the cost of outputting new line at VPOS.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 old_hash[VPOS] is the hash code of the old line at VPOS.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 new_hash[VPOS] is the hash code of the new line at VPOS.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
71 Note that these are not true frame vpos's, but relative
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 to the place at which the first mismatch between old and
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 new contents appears. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
76 calculate_scrolling (frame, matrix, window_size, lines_below,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 draw_cost, old_hash, new_hash,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 free_at_end)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
79 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 /* matrix is of size window_size + 1 on each side. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 struct matrix_elt *matrix;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 int window_size;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 int *draw_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 int *old_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 int *new_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 int free_at_end;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 register int i, j;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
89 int frame_height = FRAME_HEIGHT (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 register struct matrix_elt *p, *p1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 register int cost, cost1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 /* first_insert_cost[I] is the cost of doing the first insert-line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 at the I'th line of the lines we are considering,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 where I is origin 1 (as it is below). */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 int *first_insert_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
98 = &FRAME_INSERT_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 int *first_delete_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
100 = &FRAME_DELETE_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 int *next_insert_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
102 = &FRAME_INSERTN_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 int *next_delete_cost
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
104 = &FRAME_DELETEN_COST (frame)[frame_height - 1 - lines_moved];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 /* Discourage long scrolls on fast lines.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
107 Don't scroll nearly a full frame height unless it saves
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 at least 1/4 second. */
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
109 int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110
3356
09759a9653c5 (calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
111 if (baud_rate <= 0)
09759a9653c5 (calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
112 extra_cost = 1;
09759a9653c5 (calculate_scrolling): Defend against negative baud_rate.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
113
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 /* initialize the top left corner of the matrix */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 matrix->writecost = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 matrix->insertcost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 matrix->deletecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 matrix->insertcount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 matrix->deletecount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 /* initialize the left edge of the matrix */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 cost = first_insert_cost[1] - next_insert_cost[1];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 for (i = 1; i <= window_size; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 p = matrix + i * (window_size + 1);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 cost += draw_cost[i] + next_insert_cost[i] + extra_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 p->insertcost = cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 p->writecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 p->deletecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 p->insertcount = i;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 p->deletecount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 /* initialize the top edge of the matrix */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 cost = first_delete_cost[1] - next_delete_cost[1];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 for (j = 1; j <= window_size; j++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 cost += next_delete_cost[j];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 matrix[j].deletecost = cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 matrix[j].writecost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 matrix[j].insertcost = INFINITY;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 matrix[j].deletecount = j;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 matrix[j].insertcount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
146 /* `i' represents the vpos among new frame contents.
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
147 `j' represents the vpos among the old frame contents. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 p = matrix + window_size + 2; /* matrix [1, 1] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 for (i = 1; i <= window_size; i++, p++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 for (j = 1; j <= window_size; j++, p++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 /* p contains the address of matrix [i, j] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 /* First calculate the cost assuming we do
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 not insert or delete above this line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 That is, if we update through line i-1
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 based on old lines through j-1,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 and then just change old line j to new line i. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 p1 = p - window_size - 2; /* matrix [i-1, j-1] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 cost = p1->writecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 if (cost > p1->insertcost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 cost = p1->insertcost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 if (cost > p1->deletecost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 cost = p1->deletecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 if (old_hash[j] != new_hash[i])
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 cost += draw_cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 p->writecost = cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 /* Calculate the cost if we do an insert-line
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 before outputting this line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 That is, we update through line i-1
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 based on old lines through j,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 do an insert-line on line i,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 and then output line i from scratch,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 leaving old lines starting from j for reuse below. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 p1 = p - window_size - 1; /* matrix [i-1, j] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 /* No need to think about doing a delete followed
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 immediately by an insert. It cannot be as good
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 as not doing either of them. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 if (free_at_end == i)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 cost = p1->writecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 cost1 = p1->insertcost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 cost = p1->writecost + first_insert_cost[i];
6888
a39caeb88721 (calculate_scrolling): Add explicit casts, to avoid compiler warnings.
Karl Heuer <kwzh@gnu.org>
parents: 6773
diff changeset
188 if ((int) p1->insertcount > i)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 abort ();
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1;
6888
a39caeb88721 (calculate_scrolling): Add explicit casts, to avoid compiler warnings.
Karl Heuer <kwzh@gnu.org>
parents: 6773
diff changeset
194 if ((int) p->insertcount > i)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 abort ();
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 /* Calculate the cost if we do a delete line after
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 outputting this line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 That is, we update through line i
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 based on old lines through j-1,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 and throw away old line j. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 p1 = p - 1; /* matrix [i, j-1] */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 /* No need to think about doing an insert followed
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 immediately by a delete. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 if (free_at_end == i)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 cost = p1->writecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 cost1 = p1->deletecost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 cost = p1->writecost + first_delete_cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 cost1 = p1->deletecost + next_delete_cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 p->deletecost = min (cost, cost1);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 p->deletecount = (cost < cost1) ? 1 : p1->deletecount + 1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
220 /* Perform insert-lines and delete-lines operations on FRAME
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
221 according to the costs in MATRIX.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
222 Update the frame's current_glyphs info to record what was done.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
223
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
224 WINDOW_SIZE is the number of lines being considered for scrolling
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
225 and UNCHANGED_AT_TOP is the vpos of the first line being considered.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
226 These two arguments can specify any contiguous range of lines.
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
227
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
228 We also shuffle the charstarts vectors for the lines
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
229 along with the glyphs; but the results are not quite right,
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
230 since we cannot offset them for changes in amount of text
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
231 in this line or that line. Luckily it doesn't matter,
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
232 since update_frame and update_line will copy in the proper
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
233 new charstarts vectors from the frame's desired_glyphs. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
236 do_scrolling (frame, matrix, window_size, unchanged_at_top)
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
237 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 struct matrix_elt *matrix;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 int window_size;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 int unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 register struct matrix_elt *p;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 register int i, j;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
244 register struct frame_glyphs *current_frame;
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
245 /* temp_frame->enable[i] means line i has been moved to current_frame. */
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
246 register struct frame_glyphs *temp_frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 struct queue { int count, pos; } *queue;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 int offset = unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 int qi = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 int window = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 register int tem;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 int next;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
254 queue = (struct queue *) alloca (FRAME_HEIGHT (frame)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 * sizeof (struct queue));
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
257 current_frame = FRAME_CURRENT_GLYPHS (frame);
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
258 temp_frame = FRAME_TEMP_GLYPHS (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
260 bcopy (current_frame->glyphs, temp_frame->glyphs,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
261 current_frame->height * sizeof (GLYPH *));
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
262 bcopy (current_frame->charstarts, temp_frame->charstarts,
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
263 current_frame->height * sizeof (GLYPH *));
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
264 bcopy (current_frame->used, temp_frame->used,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
265 current_frame->height * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
266 bcopy (current_frame->highlight, temp_frame->highlight,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
267 current_frame->height * sizeof (char));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
268 bzero (temp_frame->enable, temp_frame->height * sizeof (char));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
269 bcopy (current_frame->bufp, temp_frame->bufp,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
270 current_frame->height * sizeof (int));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 #ifdef HAVE_X_WINDOWS
968
861714452cb3 * scroll.c (FRAME_IS_TERMCAP, FRAME_IS_X, FRAME_HAS_MINIBUF):
Jim Blandy <jimb@redhat.com>
parents: 766
diff changeset
273 if (FRAME_X_P (frame))
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
275 bcopy (current_frame->top_left_x, temp_frame->top_left_x,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
276 current_frame->height * sizeof (short));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
277 bcopy (current_frame->top_left_y, temp_frame->top_left_y,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
278 current_frame->height * sizeof (short));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
279 bcopy (current_frame->pix_width, temp_frame->pix_width,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
280 current_frame->height * sizeof (short));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
281 bcopy (current_frame->pix_height, temp_frame->pix_height,
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
282 current_frame->height * sizeof (short));
1410
9b29df8c7cb3 * scroll.c (do_scrolling): Don't bcopy non-existant `nruns' or
Joseph Arceneaux <jla@gnu.org>
parents: 968
diff changeset
283 bcopy (current_frame->max_ascent, temp_frame->max_ascent,
1714
2a1dbc7de507 * scroll.c (do_scrolling): When bcopying the max_ascent field from
Jim Blandy <jimb@redhat.com>
parents: 1410
diff changeset
284 current_frame->height * sizeof (short));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 #endif
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 i = j = window_size;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 while (i > 0 || j > 0)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 p = matrix + i * (window_size + 1) + j;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 tem = p->insertcost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 if (tem < p->writecost && tem < p->deletecost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 /* Insert should be done at vpos i-1, plus maybe some before */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 queue[qi].count = p->insertcount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 i -= p->insertcount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 queue[qi++].pos = i + unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 else if (p->deletecost < p->writecost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 /* Old line at vpos j-1, and maybe some before it,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 should be deleted */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 j -= p->deletecount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 if (!window)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 set_terminal_window (window_size + unchanged_at_top);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 window = 1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 ins_del_lines (j + unchanged_at_top, - p->deletecount);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 /* Best thing done here is no insert or delete */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 /* Old line at vpos j-1 ends up at vpos i-1 */
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
317 current_frame->glyphs[i + offset - 1]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
318 = temp_frame->glyphs[j + offset - 1];
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
319 current_frame->charstarts[i + offset - 1]
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
320 = temp_frame->charstarts[j + offset - 1];
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
321 current_frame->used[i + offset - 1]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
322 = temp_frame->used[j + offset - 1];
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
323 current_frame->highlight[i + offset - 1]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
324 = temp_frame->highlight[j + offset - 1];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
326 temp_frame->enable[j + offset - 1] = 1;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 i--;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 j--;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 if (!window && qi)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 set_terminal_window (window_size + unchanged_at_top);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 window = 1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 /* Now do all insertions */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 next = unchanged_at_top;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 for (i = qi - 1; i >= 0; i--)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 ins_del_lines (queue[i].pos, queue[i].count);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 /* Mark the inserted lines as clear,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 and put into them the line-contents strings
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 that were discarded during the deletions.
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
348 Those are the ones for which temp_frame->enable was not set. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 tem = queue[i].pos;
320
81130da351be *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 154
diff changeset
350 for (j = tem + queue[i].count - 1; j >= tem; j--)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
352 current_frame->enable[j] = 0;
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
353 while (temp_frame->enable[next])
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 next++;
6647
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
355 current_frame->glyphs[j] = temp_frame->glyphs[next];
e6611521fb67 (do_scrolling): Handle charstarts like glyphs.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
356 current_frame->charstarts[j] = temp_frame->charstarts[next++];
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 if (window)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 set_terminal_window (0);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
365 scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 draw_cost, old_hash, new_hash, free_at_end)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
367 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 int window_size, unchanged_at_top, unchanged_at_bottom;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 int *draw_cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 int *old_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 int *new_hash;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 int free_at_end;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 struct matrix_elt *matrix;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 matrix = ((struct matrix_elt *)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
378 calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 draw_cost, old_hash, new_hash,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 free_at_end);
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
381 do_scrolling (frame, matrix, window_size, unchanged_at_top);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
384 /* Return number of lines in common between current and desired frame contents
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 described to us only as vectors of hash codes OLDHASH and NEWHASH.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 Consider only vpos range START to END (not including END).
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 Ignore short lines on the assumption that
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 avoiding redrawing such a line will have little weight. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 int
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 scrolling_max_lines_saved (start, end, oldhash, newhash, cost)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 int start, end;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 int *oldhash, *newhash, *cost;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 struct { int hash; int count; } lines[01000];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 register int i, h;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 register int matchcount = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 int avg_length = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 int threshold;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 /* Compute a threshold which is 1/4 of average length of these lines. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 for (i = start; i < end; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 avg_length += cost[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 avg_length /= end - start;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 threshold = avg_length / 4;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 bzero (lines, sizeof lines);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 /* Put new lines' hash codes in hash table.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 Ignore lines shorter than the threshold.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 Thus, if the lines that are in common
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 are mainly the ones that are short,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 they won't count. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 for (i = start; i < end; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 if (cost[i] > threshold)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 h = newhash[i] & 0777;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 lines[h].hash = newhash[i];
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 lines[h].count++;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 /* Look up old line hash codes in the hash table.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 Count number of matches between old lines and new. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 for (i = start; i < end; i++)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 h = oldhash[i] & 0777;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 if (oldhash[i] == lines[h].hash)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 matchcount++;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 if (--lines[h].count == 0)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 lines[h].hash = 0;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 return matchcount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 /* Return a measure of the cost of moving the lines
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 starting with vpos FROM, up to but not including vpos TO,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 down by AMOUNT lines (AMOUNT may be negative).
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 These are the same arguments that might be given to
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
447 scroll_frame_lines to perform this scrolling. */
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
449 scroll_cost (frame, from, to, amount)
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
450 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 int from, to, amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
453 /* Compute how many lines, at bottom of frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 will not be involved in actual motion. */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 int limit = to;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 int offset;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
457 int height = FRAME_HEIGHT (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
421
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
459 if (amount == 0)
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
460 return 0;
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
461
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 if (! scroll_region_ok)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 limit = height;
421
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
464 else if (amount > 0)
1cc29824b3f1 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 320
diff changeset
465 limit += amount;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 if (amount < 0)
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 int temp = to;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 to = from + amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 from = temp + amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 amount = - amount;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 offset = height - limit;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 return
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
478 (FRAME_INSERT_COST (frame)[offset + from]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
479 + (amount - 1) * FRAME_INSERTN_COST (frame)[offset + from]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
480 + FRAME_DELETEN_COST (frame)[offset + to]
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
481 + (amount - 1) * FRAME_DELETE_COST (frame)[offset + to]);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 /* Calculate the line insertion/deletion
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 overhead and multiply factor values */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
488 line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf)
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
489 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 int ov1, ovn;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 int pf1, pfn;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 register int *ov, *mf;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 register int i;
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
495 register int frame_height = FRAME_HEIGHT (frame);
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 register int insert_overhead = ov1 * 10;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 register int next_insert_cost = ovn * 10;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
499 for (i = frame_height-1; i >= 0; i--)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 {
529
413127b220ef *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 421
diff changeset
501 mf[i] = next_insert_cost / 10;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 next_insert_cost += pfn;
529
413127b220ef *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 421
diff changeset
503 ov[i] = (insert_overhead + next_insert_cost) / 10;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 insert_overhead += pf1;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 static void
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
509 ins_del_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 one_line_string, multi_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 setup_string, cleanup_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 costvec, ncostvec, coefficient)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
513 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 char *one_line_string, *multi_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 char *setup_string, *cleanup_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 int *costvec, *ncostvec;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 int coefficient;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 {
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 if (multi_string)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
520 line_ins_del (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 string_cost (multi_string) * coefficient,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 per_line_cost (multi_string) * coefficient,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 0, 0, costvec, ncostvec);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 else if (one_line_string)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
525 line_ins_del (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 string_cost (setup_string) + string_cost (cleanup_string), 0,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 string_cost (one_line_string),
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 per_line_cost (one_line_string),
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 costvec, ncostvec);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 else
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
531 line_ins_del (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 9999, 0, 9999, 0,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 costvec, ncostvec);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 /* Calculate the insert and delete line costs.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 Note that this is done even when running with a window system
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 because we want to know how long scrolling takes (and avoid it).
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
539 This must be redone whenever the frame height changes.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 We keep the ID costs in a precomputed array based on the position
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 at which the I or D is performed. Also, there are two kinds of ID
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 costs: the "once-only" and the "repeated". This is to handle both
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 those terminals that are able to insert N lines at a time (once-
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 only) and those that must repeatedly insert one line.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 The cost to insert N lines at line L is
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
548 [tt.t_ILov + (frame_height + 1 - L) * tt.t_ILpf] +
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
549 N * [tt.t_ILnov + (frame_height + 1 - L) * tt.t_ILnpf]
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 ILov represents the basic insert line overhead. ILpf is the padding
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 required to allow the terminal time to move a line: insertion at line
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
553 L changes (frame_height + 1 - L) lines.
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 The first bracketed expression above is the overhead; the second is
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 the multiply factor. Both are dependent only on the position at
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 which the insert is performed. We store the overhead in
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
558 FRAME_INSERT_COST (frame) and the multiply factor in
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
559 FRAME_INSERTN_COST (frame). Note however that any insertion
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 must include at least one multiply factor. Rather than compute this
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
561 as FRAME_INSERT_COST (frame)[line]+FRAME_INSERTN_COST (frame)[line],
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
562 we add FRAME_INSERTN_COST (frame) into FRAME_INSERT_COST (frame).
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 This is reasonable because of the particular algorithm used in calcM.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 Deletion is essentially the same as insertion.
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 */
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
568 do_line_insertion_deletion_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 ins_line_string, multi_ins_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 del_line_string, multi_del_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 setup_string, cleanup_string, coefficient)
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
572 FRAME_PTR frame;
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 char *ins_line_string, *multi_ins_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 char *del_line_string, *multi_del_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 char *setup_string, *cleanup_string;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 int coefficient;
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
578 if (FRAME_INSERT_COST (frame) != 0)
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
580 FRAME_INSERT_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
581 (int *) xrealloc (FRAME_INSERT_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
582 FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
583 FRAME_DELETEN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
584 (int *) xrealloc (FRAME_DELETEN_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
585 FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
586 FRAME_INSERTN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
587 (int *) xrealloc (FRAME_INSERTN_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
588 FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
589 FRAME_DELETE_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
590 (int *) xrealloc (FRAME_DELETE_COST (frame),
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
591 FRAME_HEIGHT (frame) * sizeof (int));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 else
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 {
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
595 FRAME_INSERT_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
596 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
597 FRAME_DELETEN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
598 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
599 FRAME_INSERTN_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
600 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
601 FRAME_DELETE_COST (frame) =
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
602 (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 }
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
605 ins_del_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 ins_line_string, multi_ins_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 setup_string, cleanup_string,
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
608 FRAME_INSERT_COST (frame), FRAME_INSERTN_COST (frame),
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 coefficient);
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
610 ins_del_costs (frame,
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 del_line_string, multi_del_string,
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 setup_string, cleanup_string,
766
b9e81bfc7ad9 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 732
diff changeset
613 FRAME_DELETEN_COST (frame), FRAME_DELETE_COST (frame),
154
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 coefficient);
48df093640da Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 }