home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / scroll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-30  |  19.8 KB  |  640 lines

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