-/* Calculate what line insertion or deletion to do, and do it,
- Copyright (C) 1985, 1986, 1990, 1993, 1994, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+/* Calculate what line insertion or deletion to do, and do it
+
+Copyright (C) 1985-1986, 1990, 1993-1994, 2001-2013 Free Software
+Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
#include <stdio.h>
-#include <string.h>
-#include <setjmp.h>
+
#include "lisp.h"
#include "termchar.h"
#include "dispextern.h"
unsigned char writecount;
};
-static void do_direct_scrolling P_ ((struct frame *,
- struct glyph_matrix *,
- struct matrix_elt *,
- int, int));
-static void do_scrolling P_ ((struct frame *,
- struct glyph_matrix *,
- struct matrix_elt *,
- int, int));
+static void do_direct_scrolling (struct frame *,
+ struct glyph_matrix *,
+ struct matrix_elt *,
+ int, int);
+static void do_scrolling (struct frame *,
+ struct glyph_matrix *,
+ struct matrix_elt *,
+ int, int);
\f
/* Determine, in matrix[i,j], the cost of updating the first j old
new contents appears. */
static void
-calculate_scrolling (frame, matrix, window_size, lines_below,
- draw_cost, old_hash, new_hash,
- free_at_end)
- FRAME_PTR frame;
- /* matrix is of size window_size + 1 on each side. */
- struct matrix_elt *matrix;
- int window_size, lines_below;
- int *draw_cost;
- int *old_hash;
- int *new_hash;
- int free_at_end;
+calculate_scrolling (FRAME_PTR frame,
+ /* matrix is of size window_size + 1 on each side. */
+ struct matrix_elt *matrix,
+ int window_size, int lines_below,
+ int *draw_cost, int *old_hash, int *new_hash,
+ int free_at_end)
{
register int i, j;
int frame_lines = FRAME_LINES (frame);
/* Discourage long scrolls on fast lines.
Don't scroll nearly a full frame height unless it saves
at least 1/4 second. */
- int extra_cost = baud_rate / (10 * 4 * FRAME_LINES (frame));
+ int extra_cost = (int) (baud_rate / (10 * 4 * FRAME_LINES (frame)));
if (baud_rate <= 0)
extra_cost = 1;
{
cost = p1->writecost + first_insert_cost[i];
if ((int) p1->insertcount > i)
- abort ();
+ emacs_abort ();
cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount];
}
p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost;
p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1;
if ((int) p->insertcount > i)
- abort ();
+ emacs_abort ();
/* Calculate the cost if we do a delete line after
outputting this line.
of lines. */
static void
-do_scrolling (frame, current_matrix, matrix, window_size, unchanged_at_top)
- struct frame *frame;
- struct glyph_matrix *current_matrix;
- struct matrix_elt *matrix;
- int window_size;
- int unchanged_at_top;
+do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
+ struct matrix_elt *matrix, int window_size,
+ int unchanged_at_top)
{
struct matrix_elt *p;
int i, j, k;
/* Set to 1 if we have set a terminal window with
- set_terminal_window. */
- int terminal_window_p = 0;
+ set_terminal_window. It's unsigned to work around GCC bug 48228. */
+ unsigned int terminal_window_p = 0;
/* A queue for line insertions to be done. */
struct queue { int count, pos; };
struct queue *queue_start
- = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue));
+ = alloca (current_matrix->nrows * sizeof *queue_start);
struct queue *queue = queue_start;
- char *retained_p = (char *) alloca (window_size * sizeof (char));
- int *copy_from = (int *) alloca (window_size * sizeof (int));
+ char *retained_p = alloca (window_size * sizeof *retained_p);
+ int *copy_from = alloca (window_size * sizeof *copy_from);
/* Zero means line is empty. */
- bzero (retained_p, window_size * sizeof (char));
+ memset (retained_p, 0, window_size * sizeof (char));
for (k = 0; k < window_size; ++k)
copy_from[k] = -1;
-#define CHECK_BOUNDS \
+#ifdef GLYPH_DEBUG
+# define CHECK_BOUNDS \
do \
{ \
- int k; \
- for (k = 0; k < window_size; ++k) \
- xassert (copy_from[k] == -1 \
- || (copy_from[k] >= 0 && copy_from[k] < window_size)); \
+ int ck; \
+ for (ck = 0; ck < window_size; ++ck) \
+ eassert (copy_from[ck] == -1 \
+ || (copy_from[ck] >= 0 && copy_from[ck] < window_size)); \
} \
while (0);
+#endif
/* When j is advanced, this corresponds to deleted lines.
When i is advanced, this corresponds to inserted lines. */
{
/* Best thing done here is no insert or delete, i.e. a write. */
--i, --j;
- xassert (i >= 0 && i < window_size);
- xassert (j >= 0 && j < window_size);
+ eassert (i >= 0 && i < window_size);
+ eassert (j >= 0 && j < window_size);
copy_from[i] = j;
retained_p[j] = 1;
-#if GLYPH_DEBUG
+#ifdef GLYPH_DEBUG
CHECK_BOUNDS;
#endif
}
}
for (k = 0; k < window_size; ++k)
- xassert (copy_from[k] >= 0 && copy_from[k] < window_size);
+ eassert (copy_from[k] >= 0 && copy_from[k] < window_size);
/* Perform the row swizzling. */
mirrored_line_dance (current_matrix, unchanged_at_top, window_size,
copy_from, retained_p);
- /* Some sanity checks if GLYPH_DEBUG != 0. */
+ /* Some sanity checks if GLYPH_DEBUG is defined. */
CHECK_MATRIX (current_matrix);
if (terminal_window_p)
is the equivalent of draw_cost for the old line contents */
static void
-calculate_direct_scrolling (frame, matrix, window_size, lines_below,
- draw_cost, old_draw_cost, old_hash, new_hash,
- free_at_end)
- FRAME_PTR frame;
- /* matrix is of size window_size + 1 on each side. */
- struct matrix_elt *matrix;
- int window_size, lines_below;
- int *draw_cost;
- int *old_draw_cost;
- int *old_hash;
- int *new_hash;
- int free_at_end;
+calculate_direct_scrolling (FRAME_PTR frame,
+ /* matrix is of size window_size + 1 on each side. */
+ struct matrix_elt *matrix,
+ int window_size, int lines_below,
+ int *draw_cost, int *old_draw_cost,
+ int *old_hash, int *new_hash,
+ int free_at_end)
{
register int i, j;
int frame_lines = FRAME_LINES (frame);
/* Discourage long scrolls on fast lines.
Don't scroll nearly a full frame height unless it saves
at least 1/4 second. */
- int extra_cost = baud_rate / (10 * 4 * FRAME_LINES (frame));
+ int extra_cost = (int) (baud_rate / (10 * 4 * FRAME_LINES (frame)));
if (baud_rate <= 0)
extra_cost = 1;
the cost matrix for this approach is constructed. */
static void
-do_direct_scrolling (frame, current_matrix, cost_matrix,
- window_size, unchanged_at_top)
- struct frame *frame;
- struct glyph_matrix *current_matrix;
- struct matrix_elt *cost_matrix;
- int window_size;
- int unchanged_at_top;
+do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
+ struct matrix_elt *cost_matrix, int window_size,
+ int unchanged_at_top)
{
struct matrix_elt *p;
int i, j;
int write_follows_p = 1;
/* For each row in the new matrix what row of the old matrix it is. */
- int *copy_from = (int *) alloca (window_size * sizeof (int));
+ int *copy_from = alloca (window_size * sizeof *copy_from);
/* Non-zero for each row in the new matrix that is retained from the
old matrix. Lines not retained are empty. */
- char *retained_p = (char *) alloca (window_size * sizeof (char));
+ char *retained_p = alloca (window_size * sizeof *retained_p);
- bzero (retained_p, window_size * sizeof (char));
+ memset (retained_p, 0, window_size * sizeof (char));
/* Perform some sanity checks when GLYPH_DEBUG is on. */
CHECK_MATRIX (current_matrix);
place they belong. */
int n_to_write = p->writecount;
write_follows_p = 1;
- xassert (n_to_write > 0);
+ eassert (n_to_write > 0);
if (i > j)
{
\f
void
-scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
- draw_cost, old_draw_cost, old_hash, new_hash, free_at_end)
- FRAME_PTR frame;
- int window_size, unchanged_at_top, unchanged_at_bottom;
- int *draw_cost;
- int *old_draw_cost;
- int *old_hash;
- int *new_hash;
- int free_at_end;
+scrolling_1 (FRAME_PTR frame, int window_size, int unchanged_at_top,
+ int unchanged_at_bottom, int *draw_cost, int *old_draw_cost,
+ int *old_hash, int *new_hash, int free_at_end)
{
struct matrix_elt *matrix;
matrix = ((struct matrix_elt *)
such a line will have little weight. */
int
-scrolling_max_lines_saved (start, end, oldhash, newhash, cost)
- int start, end;
- int *oldhash, *newhash, *cost;
+scrolling_max_lines_saved (int start, int end,
+ int *oldhash, int *newhash,
+ int *cost)
{
struct { int hash; int count; } lines[01000];
register int i, h;
avg_length /= end - start;
threshold = avg_length / 4;
- bzero (lines, sizeof lines);
+ memset (lines, 0, sizeof lines);
/* Put new lines' hash codes in hash table. Ignore lines shorter
than the threshold. Thus, if the lines that are in common are
return matchcount;
}
\f
-/* Return a measure of the cost of moving the lines starting with vpos
- FROM, up to but not including vpos TO, down by AMOUNT lines (AMOUNT
- may be negative). These are the same arguments that might be given
- to scroll_frame_lines to perform this scrolling. */
-
-int
-scroll_cost (frame, from, to, amount)
- FRAME_PTR frame;
- int from, to, amount;
-{
- /* Compute how many lines, at bottom of frame,
- will not be involved in actual motion. */
- int limit = to;
- int offset;
- int height = FRAME_LINES (frame);
-
- if (amount == 0)
- return 0;
-
- if (! FRAME_SCROLL_REGION_OK (frame))
- limit = height;
- else if (amount > 0)
- limit += amount;
-
- if (amount < 0)
- {
- int temp = to;
- to = from + amount;
- from = temp + amount;
- amount = - amount;
- }
-
- offset = height - limit;
-
- return
- (FRAME_INSERT_COST (frame)[offset + from]
- + (amount - 1) * FRAME_INSERTN_COST (frame)[offset + from]
- + FRAME_DELETE_COST (frame)[offset + to]
- + (amount - 1) * FRAME_DELETEN_COST (frame)[offset + to]);
-}
-\f
/* Calculate the line insertion/deletion
overhead and multiply factor values */
static void
-line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf)
- FRAME_PTR frame;
- int ov1, ovn;
- int pf1, pfn;
- register int *ov, *mf;
+line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn,
+ register int *ov, register int *mf)
{
register int i;
register int frame_lines = FRAME_LINES (frame);
}
static void
-ins_del_costs (frame,
- one_line_string, multi_string,
- setup_string, cleanup_string,
- costvec, ncostvec, coefficient)
- FRAME_PTR frame;
- char *one_line_string, *multi_string;
- char *setup_string, *cleanup_string;
- int *costvec, *ncostvec;
- int coefficient;
+ins_del_costs (FRAME_PTR frame,
+ const char *one_line_string, const char *multi_string,
+ const char *setup_string, const char *cleanup_string,
+ int *costvec, int *ncostvec,
+ int coefficient)
{
if (multi_string)
line_ins_del (frame,
*/
void
-do_line_insertion_deletion_costs (frame,
- ins_line_string, multi_ins_string,
- del_line_string, multi_del_string,
- setup_string, cleanup_string, coefficient)
- FRAME_PTR frame;
- char *ins_line_string, *multi_ins_string;
- char *del_line_string, *multi_del_string;
- char *setup_string, *cleanup_string;
- int coefficient;
+do_line_insertion_deletion_costs (FRAME_PTR frame,
+ const char *ins_line_string,
+ const char *multi_ins_string,
+ const char *del_line_string,
+ const char *multi_del_string,
+ const char *setup_string,
+ const char *cleanup_string,
+ int coefficient)
{
- if (FRAME_INSERT_COST (frame) != 0)
- {
- FRAME_INSERT_COST (frame) =
- (int *) xrealloc (FRAME_INSERT_COST (frame),
- FRAME_LINES (frame) * sizeof (int));
- FRAME_DELETEN_COST (frame) =
- (int *) xrealloc (FRAME_DELETEN_COST (frame),
- FRAME_LINES (frame) * sizeof (int));
- FRAME_INSERTN_COST (frame) =
- (int *) xrealloc (FRAME_INSERTN_COST (frame),
- FRAME_LINES (frame) * sizeof (int));
- FRAME_DELETE_COST (frame) =
- (int *) xrealloc (FRAME_DELETE_COST (frame),
- FRAME_LINES (frame) * sizeof (int));
- }
- else
- {
- FRAME_INSERT_COST (frame) =
- (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
- FRAME_DELETEN_COST (frame) =
- (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
- FRAME_INSERTN_COST (frame) =
- (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
- FRAME_DELETE_COST (frame) =
- (int *) xmalloc (FRAME_LINES (frame) * sizeof (int));
- }
+ FRAME_INSERT_COST (frame) =
+ xnrealloc (FRAME_INSERT_COST (frame), FRAME_LINES (frame), sizeof (int));
+ FRAME_DELETEN_COST (frame) =
+ xnrealloc (FRAME_DELETEN_COST (frame), FRAME_LINES (frame), sizeof (int));
+ FRAME_INSERTN_COST (frame) =
+ xnrealloc (FRAME_INSERTN_COST (frame), FRAME_LINES (frame), sizeof (int));
+ FRAME_DELETE_COST (frame) =
+ xnrealloc (FRAME_DELETE_COST (frame), FRAME_LINES (frame), sizeof (int));
ins_del_costs (frame,
ins_line_string, multi_ins_string,
FRAME_DELETE_COST (frame), FRAME_DELETEN_COST (frame),
coefficient);
}
-
-/* arch-tag: cdb7149c-48e7-4793-a948-2786c8e45485
- (do not change this comment) */