Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
[bpt/emacs.git] / src / scroll.c
index 3afc927..3b033f3 100644 (file)
@@ -1,13 +1,13 @@
 /* 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  Free Software Foundation, Inc.
+                 2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,20 +15,20 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
 #include <stdio.h>
 #include <string.h>
-#include "termchar.h"
+#include <setjmp.h>
 #include "lisp.h"
+#include "termchar.h"
 #include "dispextern.h"
 #include "keyboard.h"
 #include "frame.h"
 #include "window.h"
+#include "termhooks.h"
 
 /* All costs measured in characters.
    So no cost can exceed the area of a frame, measured in characters.
@@ -58,12 +58,14 @@ struct matrix_elt
     unsigned char writecount;
   };
 
-static void do_direct_scrolling P_ ((struct glyph_matrix *,
-                                    struct matrix_elt *,
-                                    int, int));
-static void do_scrolling P_ ((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
@@ -84,24 +86,20 @@ static void do_scrolling P_ ((struct glyph_matrix *,
    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);
   register struct matrix_elt *p, *p1;
   register int cost, cost1;
 
-  int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below);
+  int lines_moved = window_size
+    + (FRAME_SCROLL_REGION_OK (frame) ? 0 : lines_below);
   /* first_insert_cost[I] is the cost of doing the first insert-line
      at the i'th line of the lines we are considering,
      where I is origin 1 (as it is below).  */
@@ -241,11 +239,7 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
    of lines.  */
 
 static void
-do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
-     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;
@@ -264,7 +258,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
   int *copy_from = (int *) alloca (window_size * sizeof (int));
 
   /* 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;
 
@@ -308,12 +302,12 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
          /* Set the terminal window, if not done already.  */
          if (! terminal_window_p)
            {
-             set_terminal_window (window_size + unchanged_at_top);
+             set_terminal_window (frame, window_size + unchanged_at_top);
              terminal_window_p = 1;
            }
 
          /* Delete lines on the terminal.  */
-         ins_del_lines (j + unchanged_at_top, - p->deletecount);
+         ins_del_lines (frame, j + unchanged_at_top, - p->deletecount);
        }
       else
        {
@@ -338,7 +332,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
       /* Set the terminal window if not yet done.  */
       if (!terminal_window_p)
        {
-         set_terminal_window (window_size + unchanged_at_top);
+         set_terminal_window (frame, window_size + unchanged_at_top);
          terminal_window_p = 1;
        }
 
@@ -347,7 +341,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
          --queue;
 
          /* Do the deletion on the terminal.  */
-         ins_del_lines (queue->pos, queue->count);
+         ins_del_lines (frame, queue->pos, queue->count);
 
          /* All lines in the range deleted become empty in the glyph
             matrix.  Assign to them glyph rows that are not retained.
@@ -380,7 +374,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
   CHECK_MATRIX (current_matrix);
 
   if (terminal_window_p)
-    set_terminal_window (0);
+    set_terminal_window (frame, 0);
 }
 
 \f
@@ -425,18 +419,13 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
    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);
@@ -467,7 +456,8 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
   /* Overhead of setting the scroll window, plus the extra cost
      cost of scrolling by a distance of one.  The extra cost is
      added once for consistency with the cost vectors */
-  scroll_overhead = scroll_region_cost + extra_cost;
+  scroll_overhead
+    = FRAME_SCROLL_REGION_COST (frame) + extra_cost;
 
   /* initialize the top left corner of the matrix */
   matrix->writecost = 0;
@@ -650,8 +640,9 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
    the cost matrix for this approach is constructed. */
 
 static void
-do_direct_scrolling (current_matrix, cost_matrix, window_size,
-                    unchanged_at_top)
+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;
@@ -686,7 +677,7 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
      old matrix.  Lines not retained are empty.  */
   char *retained_p = (char *) alloca (window_size * sizeof (char));
 
-  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);
@@ -742,9 +733,9 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
          if (i > j)
            {
              /* Immediately insert lines */
-             set_terminal_window (i + unchanged_at_top);
+             set_terminal_window (frame, i + unchanged_at_top);
              terminal_window_p = 1;
-             ins_del_lines (j - n_to_write + unchanged_at_top, i - j);
+             ins_del_lines (frame, j - n_to_write + unchanged_at_top, i - j);
            }
          else if (i < j)
            {
@@ -774,9 +765,9 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
          --queue;
          if (queue->count)
            {
-             set_terminal_window (queue->window);
+             set_terminal_window (frame, queue->window);
              terminal_window_p = 1;
-             ins_del_lines (queue->pos, queue->count);
+             ins_del_lines (frame, queue->pos, queue->count);
            }
          else
            {
@@ -799,7 +790,7 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
                       copy_from, retained_p);
 
   if (terminal_window_p)
-    set_terminal_window (0);
+    set_terminal_window (frame, 0);
 }
 
 
@@ -819,13 +810,13 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
   matrix = ((struct matrix_elt *)
            alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
 
-  if (scroll_region_ok)
+  if (FRAME_SCROLL_REGION_OK (frame))
     {
       calculate_direct_scrolling (frame, matrix, window_size,
                                  unchanged_at_bottom,
                                  draw_cost, old_draw_cost,
                                  old_hash, new_hash, free_at_end);
-      do_direct_scrolling (frame->current_matrix,
+      do_direct_scrolling (frame, frame->current_matrix,
                           matrix, window_size, unchanged_at_top);
     }
   else
@@ -833,7 +824,8 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
       calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom,
                           draw_cost, old_hash, new_hash,
                           free_at_end);
-      do_scrolling (frame->current_matrix, matrix, window_size,
+      do_scrolling (frame,
+                    frame->current_matrix, matrix, window_size,
                    unchanged_at_top);
     }
 }
@@ -847,9 +839,7 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
    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;
@@ -865,7 +855,7 @@ scrolling_max_lines_saved (start, end, oldhash, newhash, cost)
   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
@@ -902,9 +892,7 @@ scrolling_max_lines_saved (start, end, oldhash, newhash, cost)
    to scroll_frame_lines to perform this scrolling.  */
 
 int
-scroll_cost (frame, from, to, amount)
-     FRAME_PTR frame;
-     int from, to, amount;
+scroll_cost (FRAME_PTR frame, int from, int to, int amount)
 {
   /* Compute how many lines, at bottom of frame,
      will not be involved in actual motion.  */
@@ -915,7 +903,7 @@ scroll_cost (frame, from, to, amount)
   if (amount == 0)
     return 0;
 
-  if (! scroll_region_ok)
+  if (! FRAME_SCROLL_REGION_OK (frame))
     limit = height;
   else if (amount > 0)
     limit += amount;
@@ -941,11 +929,7 @@ scroll_cost (frame, from, to, amount)
    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);
@@ -962,15 +946,11 @@ line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf)
 }
 
 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,
+              char *one_line_string, char *multi_string,
+              char *setup_string, char *cleanup_string,
+              int *costvec, int *ncostvec,
+              int coefficient)
 {
   if (multi_string)
     line_ins_del (frame,