home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / readline / display.c < prev    next >
C/C++ Source or Header  |  1994-01-26  |  22KB  |  841 lines

  1. /* display.c -- readline redisplay facility. */
  2.  
  3. /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
  4.  
  5.    This file is part of the GNU Readline Library, a library for
  6.    reading lines of text with interactive input and history editing.
  7.  
  8.    The GNU Readline Library is free software; you can redistribute it
  9.    and/or modify it under the terms of the GNU General Public License
  10.    as published by the Free Software Foundation; either version 1, or
  11.    (at your option) any later version.
  12.  
  13.    The GNU Readline Library is distributed in the hope that it will be
  14.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15.    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    The GNU General Public License is often shipped with GNU software, and
  19.    is generally kept in a file called COPYING or LICENSE.  If you do not
  20.    have a copy of the license, write to the Free Software Foundation,
  21.    675 Mass Ave, Cambridge, MA 02139, USA. */
  22.  
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25.  
  26. #if defined (HAVE_UNISTD_H)
  27. #  include <unistd.h>
  28. #endif /* HAVE_UNISTD_H */
  29.  
  30. #if defined (HAVE_STDLIB_H)
  31. #  include <stdlib.h>
  32. #else
  33. #  include "ansi_stdlib.h"
  34. #endif /* HAVE_STDLIB_H */
  35.  
  36. #include "posixstat.h"
  37.  
  38. /* System-specific feature definitions and include files. */
  39. #include "rldefs.h"
  40.  
  41. /* Some standard library routines. */
  42. #include "readline.h"
  43. #include "history.h"
  44.  
  45. #if !defined (strchr) && !defined (__STDC__)
  46. extern char *strchr (), *strrchr ();
  47. #endif /* !strchr && !__STDC__ */
  48.  
  49. /* Global and pseudo-global variables and functions
  50.    imported from readline.c. */
  51. extern char *rl_prompt;
  52. extern int readline_echoing_p;
  53. extern char *term_clreol, *term_im, *term_ic,  *term_ei, *term_DC;
  54. /* Termcap variables. */
  55. extern char *term_up, *term_dc, *term_cr, *term_IC;
  56. extern int screenheight, screenwidth, terminal_can_insert;
  57.  
  58. extern void _rl_output_some_chars ();
  59. extern void _rl_output_character_function ();
  60.  
  61. extern int _rl_convert_meta_chars_to_ascii;
  62. extern int _rl_horizontal_scroll_mode;
  63. extern int _rl_mark_modified_lines;
  64. extern int _rl_prefer_visible_bell;
  65.  
  66. /* Pseudo-global functions (local to the readline library) exported
  67.    by this file. */
  68. void _rl_move_cursor_relative (), _rl_output_some_chars ();
  69. void _rl_move_vert ();
  70.  
  71. int rl_on_new_line ();
  72.  
  73. static void update_line (), clear_to_eol ();
  74. static void delete_chars (), insert_some_chars ();
  75.  
  76. extern char *xmalloc (), *xrealloc ();
  77.  
  78. /* **************************************************************** */
  79. /*                                    */
  80. /*            Display stuff                    */
  81. /*                                    */
  82. /* **************************************************************** */
  83.  
  84. /* This is the stuff that is hard for me.  I never seem to write good
  85.    display routines in C.  Let's see how I do this time. */
  86.  
  87. /* (PWP) Well... Good for a simple line updater, but totally ignores
  88.    the problems of input lines longer than the screen width.
  89.  
  90.    update_line and the code that calls it makes a multiple line,
  91.    automatically wrapping line update.  Carefull attention needs
  92.    to be paid to the vertical position variables.
  93.  
  94.    handling of terminals with autowrap on (incl. DEC braindamage)
  95.    could be improved a bit.  Right now I just cheat and decrement
  96.    screenwidth by one. */
  97.  
  98. /* Keep two buffers; one which reflects the current contents of the
  99.    screen, and the other to draw what we think the new contents should
  100.    be.  Then compare the buffers, and make whatever changes to the
  101.    screen itself that we should.  Finally, make the buffer that we
  102.    just drew into be the one which reflects the current contents of the
  103.    screen, and place the cursor where it belongs.
  104.  
  105.    Commands that want to can fix the display themselves, and then let
  106.    this function know that the display has been fixed by setting the
  107.    RL_DISPLAY_FIXED variable.  This is good for efficiency. */
  108.  
  109. /* Global variables declared here. */
  110. /* What YOU turn on when you have handled all redisplay yourself. */
  111. int rl_display_fixed = 0;
  112.  
  113. /* The stuff that gets printed out before the actual text of the line.
  114.    This is usually pointing to rl_prompt. */
  115. char *rl_display_prompt = (char *)NULL;
  116.  
  117. /* Pseudo-global variables declared here. */
  118. /* The visible cursor position.  If you print some text, adjust this. */
  119. int _rl_last_c_pos = 0;
  120. int _rl_last_v_pos = 0;
  121.  
  122. /* Number of lines currently on screen minus 1. */
  123. int _rl_vis_botlin = 0;
  124.  
  125. /* Variables used only in this file. */
  126. /* The last left edge of text that was displayed.  This is used when
  127.    doing horizontal scrolling.  It shifts in thirds of a screenwidth. */
  128. static int last_lmargin = 0;
  129.  
  130. /* The line display buffers.  One is the line currently displayed on
  131.    the screen.  The other is the line about to be displayed. */
  132. static char *visible_line = (char *)NULL;
  133. static char *invisible_line = (char *)NULL;
  134.  
  135. /* A buffer for `modeline' messages. */
  136. static char msg_buf[128];
  137.  
  138. /* Non-zero forces the redisplay even if we thought it was unnecessary. */
  139. static int forced_display = 0;
  140.  
  141. /* Default and initial buffer size.  Can grow. */
  142. static int line_size = 1024;
  143.  
  144. /* Basic redisplay algorithm. */
  145. void
  146. rl_redisplay ()
  147. {
  148.   register int in, out, c, linenum;
  149.   register char *line = invisible_line;
  150.   char *prompt_this_line;
  151.   int c_pos = 0;
  152.   int inv_botlin = 0;        /* Number of lines in newly drawn buffer. */
  153.  
  154.   if (!readline_echoing_p)
  155.     return;
  156.  
  157.   if (!rl_display_prompt)
  158.     rl_display_prompt = "";
  159.  
  160.   if (!invisible_line)
  161.     {
  162.       visible_line = (char *)xmalloc (line_size);
  163.       invisible_line = (char *)xmalloc (line_size);
  164.       line = invisible_line;
  165.       for (in = 0; in < line_size; in++)
  166.     {
  167.       visible_line[in] = 0;
  168.       invisible_line[in] = 1;
  169.     }
  170.       rl_on_new_line ();
  171.     }
  172.  
  173.   /* Draw the line into the buffer. */
  174.   c_pos = -1;
  175.  
  176.   /* Mark the line as modified or not.  We only do this for history
  177.      lines. */
  178.   out = 0;
  179.   if (_rl_mark_modified_lines && current_history () && rl_undo_list)
  180.     {
  181.       line[out++] = '*';
  182.       line[out] = '\0';
  183.     }
  184.  
  185.   /* If someone thought that the redisplay was handled, but the currently
  186.      visible line has a different modification state than the one about
  187.      to become visible, then correct the caller's misconception. */
  188.   if (visible_line[0] != invisible_line[0])
  189.     rl_display_fixed = 0;
  190.  
  191.   prompt_this_line = strrchr (rl_display_prompt, '\n');
  192.   if (!prompt_this_line)
  193.     prompt_this_line = rl_display_prompt;
  194.   else
  195.     {
  196.       prompt_this_line++;
  197.       if (forced_display)
  198.     _rl_output_some_chars
  199.       (rl_display_prompt, prompt_this_line - rl_display_prompt);
  200.     }
  201.  
  202.   strncpy (line + out,  prompt_this_line, strlen (prompt_this_line));
  203.   out += strlen (prompt_this_line);
  204.   line[out] = '\0';
  205.  
  206.   for (in = 0; in < rl_end; in++)
  207.     {
  208.       c = (unsigned char)rl_line_buffer[in];
  209.  
  210.       if (out + 8 >= line_size)        /* XXX - 8 for \t */
  211.     {
  212.       line_size *= 2;
  213.       visible_line = (char *)xrealloc (visible_line, line_size);
  214.       invisible_line = (char *)xrealloc (invisible_line, line_size);
  215.       line = invisible_line;
  216.     }
  217.  
  218.       if (in == rl_point)
  219.     c_pos = out;
  220.  
  221.       if (META_CHAR (c))
  222.     {
  223.       if (_rl_convert_meta_chars_to_ascii)
  224.         {
  225.           sprintf (line + out, "\\%o", c);
  226.           out += 4;
  227.         }
  228.       else
  229.         line[out++] = c;      
  230.     }
  231. #define DISPLAY_TABS
  232. #if defined (DISPLAY_TABS)
  233.       else if (c == '\t')
  234.     {
  235.       register int newout = (out | (int)7) + 1;
  236.       while (out < newout)
  237.         line[out++] = ' ';
  238.     }
  239. #endif
  240.       else if (c < ' ')
  241.     {
  242.       line[out++] = '^';
  243.       line[out++] = UNCTRL (c);    /* XXX was c ^ 0x40 */
  244.     }
  245.       else if (c == 127)
  246.     {
  247.       line[out++] = '^';
  248.       line[out++] = '?';
  249.     }
  250.       else
  251.     line[out++] = c;
  252.     }
  253.   line[out] = '\0';
  254.   if (c_pos < 0)
  255.     c_pos = out;
  256.  
  257.   /* PWP: now is when things get a bit hairy.  The visible and invisible
  258.      line buffers are really multiple lines, which would wrap every
  259.      (screenwidth - 1) characters.  Go through each in turn, finding
  260.      the changed region and updating it.  The line order is top to bottom. */
  261.  
  262.   /* If we can move the cursor up and down, then use multiple lines,
  263.      otherwise, let long lines display in a single terminal line, and
  264.      horizontally scroll it. */
  265.  
  266.   if (!_rl_horizontal_scroll_mode && term_up && *term_up)
  267.     {
  268.       int total_screen_chars = (screenwidth * screenheight);
  269.  
  270.       if (!rl_display_fixed || forced_display)
  271.     {
  272.       forced_display = 0;
  273.  
  274.       /* If we have more than a screenful of material to display, then
  275.          only display a screenful.  We should display the last screen,
  276.          not the first.  I'll fix this in a minute. */
  277.       if (out >= total_screen_chars)
  278.         out = total_screen_chars - 1;
  279.  
  280.       /* Number of screen lines to display. */
  281.       inv_botlin = out / screenwidth;
  282.  
  283.       /* For each line in the buffer, do the updating display. */
  284.       for (linenum = 0; linenum <= inv_botlin; linenum++)
  285.         update_line (linenum > _rl_vis_botlin ? ""
  286.              : &visible_line[linenum * screenwidth],
  287.              &invisible_line[linenum * screenwidth],
  288.              linenum);
  289.  
  290.       /* We may have deleted some lines.  If so, clear the left over
  291.          blank ones at the bottom out. */
  292.       if (_rl_vis_botlin > inv_botlin)
  293.         {
  294.           char *tt;
  295.           for (; linenum <= _rl_vis_botlin; linenum++)
  296.         {
  297.           tt = &visible_line[linenum * screenwidth];
  298.           _rl_move_vert (linenum);
  299.           _rl_move_cursor_relative (0, tt);
  300.           clear_to_eol
  301.             ((linenum == _rl_vis_botlin) ? strlen (tt) : screenwidth);
  302.         }
  303.         }
  304.       _rl_vis_botlin = inv_botlin;
  305.  
  306.       /* Move the cursor where it should be. */
  307.       _rl_move_vert (c_pos / screenwidth);
  308.       _rl_move_cursor_relative (c_pos % screenwidth,
  309.                 &invisible_line[(c_pos / screenwidth) * screenwidth]);
  310.     }
  311.     }
  312.   else                /* Do horizontal scrolling. */
  313.     {
  314.       int lmargin;
  315.  
  316.       /* Always at top line. */
  317.       _rl_last_v_pos = 0;
  318.  
  319.       /* If the display position of the cursor would be off the edge
  320.      of the screen, start the display of this line at an offset that
  321.      leaves the cursor on the screen. */
  322.       if (c_pos - last_lmargin > screenwidth - 2)
  323.     lmargin = (c_pos / (screenwidth / 3) - 2) * (screenwidth / 3);
  324.       else if (c_pos - last_lmargin < 1)
  325.     lmargin = ((c_pos - 1) / (screenwidth / 3)) * (screenwidth / 3);
  326.       else
  327.     lmargin = last_lmargin;
  328.  
  329.       /* If the first character on the screen isn't the first character
  330.      in the display line, indicate this with a special character. */
  331.       if (lmargin > 0)
  332.     line[lmargin] = '<';
  333.  
  334.       if (lmargin + screenwidth < out)
  335.     line[lmargin + screenwidth - 1] = '>';
  336.  
  337.       if (!rl_display_fixed || forced_display || lmargin != last_lmargin)
  338.     {
  339.       forced_display = 0;
  340.       update_line (&visible_line[last_lmargin],
  341.                &invisible_line[lmargin], 0);
  342.  
  343.       _rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]);
  344.       last_lmargin = lmargin;
  345.     }
  346.     }
  347.   fflush (rl_outstream);
  348.  
  349.   /* Swap visible and non-visible lines. */
  350.   {
  351.     char *temp = visible_line;
  352.     visible_line = invisible_line;
  353.     invisible_line = temp;
  354.     rl_display_fixed = 0;
  355.   }
  356. }
  357.  
  358. /* PWP: update_line() is based on finding the middle difference of each
  359.    line on the screen; vis:
  360.  
  361.                  /old first difference
  362.     /beginning of line   |              /old last same       /old EOL
  363.     v             v              v                    v
  364. old:    eddie> Oh, my little gruntle-buggy is to me, as lurgid as
  365. new:    eddie> Oh, my little buggy says to me, as lurgid as
  366.     ^             ^        ^               ^
  367.     \beginning of line   |        \new last same       \new end of line
  368.                  \new first difference
  369.  
  370.    All are character pointers for the sake of speed.  Special cases for
  371.    no differences, as well as for end of line additions must be handeled.
  372.  
  373.    Could be made even smarter, but this works well enough */
  374. static void
  375. update_line (old, new, current_line)
  376.      register char *old, *new;
  377.      int current_line;
  378. {
  379.   register char *ofd, *ols, *oe, *nfd, *nls, *ne;
  380.   int lendiff, wsatend;
  381.  
  382.   /* Find first difference. */
  383.   for (ofd = old, nfd = new;
  384.        (ofd - old < screenwidth) && *ofd && (*ofd == *nfd);
  385.        ofd++, nfd++)
  386.     ;
  387.  
  388.   /* Move to the end of the screen line. */
  389.   for (oe = ofd; ((oe - old) < screenwidth) && *oe; oe++);
  390.   for (ne = nfd; ((ne - new) < screenwidth) && *ne; ne++);
  391.  
  392.   /* If no difference, continue to next line. */
  393.   if (ofd == oe && nfd == ne)
  394.     return;
  395.  
  396.   wsatend = 1;            /* flag for trailing whitespace */
  397.   ols = oe - 1;            /* find last same */
  398.   nls = ne - 1;
  399.   while ((ols > ofd) && (nls > nfd) && (*ols == *nls))
  400.     {
  401.       if (*ols != ' ')
  402.     wsatend = 0;
  403.       ols--;
  404.       nls--;
  405.     }
  406.  
  407.   if (wsatend)
  408.     {
  409.       ols = oe;
  410.       nls = ne;
  411.     }
  412.   else if (*ols != *nls)
  413.     {
  414.       if (*ols)            /* don't step past the NUL */
  415.     ols++;
  416.       if (*nls)
  417.     nls++;
  418.     }
  419.  
  420.   _rl_move_vert (current_line);
  421.   _rl_move_cursor_relative (ofd - old, old);
  422.  
  423.   /* if (len (new) > len (old)) */
  424.   lendiff = (nls - nfd) - (ols - ofd);
  425.  
  426.   /* Insert (diff (len (old), len (new)) ch. */
  427.   if (lendiff > 0)
  428.     {
  429.       if (terminal_can_insert)
  430.     {
  431.       /* Sometimes it is cheaper to print the characters rather than
  432.          use the terminal's capabilities. */
  433.       if ((2 * (ne - nfd)) < lendiff && !term_IC)
  434.         {
  435.           _rl_output_some_chars (nfd, (ne - nfd));
  436.           _rl_last_c_pos += (ne - nfd);
  437.         }
  438.       else
  439.         {
  440.           if (*ols)
  441.         {
  442.           insert_some_chars (nfd, lendiff);
  443.           _rl_last_c_pos += lendiff;
  444.         }
  445.           else
  446.         {
  447.           /* At the end of a line the characters do not have to
  448.              be "inserted".  They can just be placed on the screen. */
  449.           _rl_output_some_chars (nfd, lendiff);
  450.           _rl_last_c_pos += lendiff;
  451.         }
  452.           /* Copy (new) chars to screen from first diff to last match. */
  453.           if (((nls - nfd) - lendiff) > 0)
  454.         {
  455.           _rl_output_some_chars (&nfd[lendiff], ((nls - nfd) - lendiff));
  456.           _rl_last_c_pos += ((nls - nfd) - lendiff);
  457.         }
  458.         }
  459.     }
  460.       else
  461.     {        /* cannot insert chars, write to EOL */
  462.       _rl_output_some_chars (nfd, (ne - nfd));
  463.       _rl_last_c_pos += (ne - nfd);
  464.     }
  465.     }
  466.   else                /* Delete characters from line. */
  467.     {
  468.       /* If possible and inexpensive to use terminal deletion, then do so. */
  469.       if (term_dc && (2 * (ne - nfd)) >= (-lendiff))
  470.     {
  471.       if (lendiff)
  472.         delete_chars (-lendiff); /* delete (diff) characters */
  473.  
  474.       /* Copy (new) chars to screen from first diff to last match */
  475.       if ((nls - nfd) > 0)
  476.         {
  477.           _rl_output_some_chars (nfd, (nls - nfd));
  478.           _rl_last_c_pos += (nls - nfd);
  479.         }
  480.     }
  481.       /* Otherwise, print over the existing material. */
  482.       else
  483.     {
  484.       _rl_output_some_chars (nfd, (ne - nfd));
  485.       _rl_last_c_pos += (ne - nfd);
  486.       clear_to_eol ((oe - old) - (ne - new));
  487.     }
  488.     }
  489. }
  490.  
  491. /* Tell the update routines that we have moved onto a new (empty) line. */
  492. int
  493. rl_on_new_line ()
  494. {
  495.   if (visible_line)
  496.     visible_line[0] = '\0';
  497.  
  498.   _rl_last_c_pos = _rl_last_v_pos = 0;
  499.   _rl_vis_botlin = last_lmargin = 0;
  500.  
  501.   return 0;
  502. }
  503.  
  504. /* Actually update the display, period. */
  505. int
  506. rl_forced_update_display ()
  507. {
  508.   if (visible_line)
  509.     {
  510.       register char *temp = visible_line;
  511.  
  512.       while (*temp) *temp++ = '\0';
  513.     }
  514.   rl_on_new_line ();
  515.   forced_display++;
  516.   rl_redisplay ();
  517.  
  518.   return 0;
  519. }
  520.  
  521. /* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
  522.    DATA is the contents of the screen line of interest; i.e., where
  523.    the movement is being done. */
  524. void
  525. _rl_move_cursor_relative (new, data)
  526.      int new;
  527.      char *data;
  528. {
  529.   register int i;
  530.  
  531.   /* It may be faster to output a CR, and then move forwards instead
  532.      of moving backwards. */
  533.   if (new + 1 < _rl_last_c_pos - new)
  534.     {
  535.       tputs (term_cr, 1, _rl_output_character_function);
  536.       _rl_last_c_pos = 0;
  537.     }
  538.  
  539.   if (_rl_last_c_pos == new) return;
  540.  
  541.   if (_rl_last_c_pos < new)
  542.     {
  543.       /* Move the cursor forward.  We do it by printing the command
  544.      to move the cursor forward if there is one, else print that
  545.      portion of the output buffer again.  Which is cheaper? */
  546.  
  547.       /* The above comment is left here for posterity.  It is faster
  548.      to print one character (non-control) than to print a control
  549.      sequence telling the terminal to move forward one character.
  550.      That kind of control is for people who don't know what the
  551.      data is underneath the cursor. */
  552. #if defined (HACK_TERMCAP_MOTION)
  553.       extern char *term_forward_char;
  554.  
  555.       if (term_forward_char)
  556.     for (i = _rl_last_c_pos; i < new; i++)
  557.       tputs (term_forward_char, 1, _rl_output_character_function);
  558.       else
  559.     for (i = _rl_last_c_pos; i < new; i++)
  560.       putc (data[i], rl_outstream);
  561. #else
  562.       for (i = _rl_last_c_pos; i < new; i++)
  563.     putc (data[i], rl_outstream);
  564. #endif                /* HACK_TERMCAP_MOTION */
  565.     }
  566.   else
  567.     backspace (_rl_last_c_pos - new);
  568.   _rl_last_c_pos = new;
  569. }
  570.  
  571. /* PWP: move the cursor up or down. */
  572. void
  573. _rl_move_vert (to)
  574.      int to;
  575. {
  576.   register int delta, i;
  577.  
  578.   if (_rl_last_v_pos == to || to > screenheight)
  579.     return;
  580.  
  581. #if defined (_GO32_)
  582.   {
  583.     int row, col;
  584.  
  585.     ScreenGetCursor (&row, &col);
  586.     ScreenSetCursor ((row + to - _rl_last_v_pos), col);
  587.   }
  588. #else /* !_GO32_ */
  589.  
  590.   if ((delta = to - _rl_last_v_pos) > 0)
  591.     {
  592.       for (i = 0; i < delta; i++)
  593.     putc ('\n', rl_outstream);
  594.       tputs (term_cr, 1, _rl_output_character_function);
  595.       _rl_last_c_pos = 0;
  596.     }
  597.   else
  598.     {            /* delta < 0 */
  599.       if (term_up && *term_up)
  600.     for (i = 0; i < -delta; i++)
  601.       tputs (term_up, 1, _rl_output_character_function);
  602.     }
  603. #endif /* !_GO32_ */
  604.   _rl_last_v_pos = to;        /* Now TO is here */
  605. }
  606.  
  607. /* Physically print C on rl_outstream.  This is for functions which know
  608.    how to optimize the display. */
  609. int
  610. rl_show_char (c)
  611.      int c;
  612. {
  613.   if (META_CHAR (c) && _rl_convert_meta_chars_to_ascii)
  614.     {
  615.       fprintf (rl_outstream, "M-");
  616.       c = UNMETA (c);
  617.     }
  618.  
  619. #if defined (DISPLAY_TABS)
  620.   if (c < 32 && c != '\t')
  621. #else
  622.   if (c < 32)
  623. #endif /* !DISPLAY_TABS */
  624.     {
  625.       c += 64;
  626.     }
  627.  
  628.   putc (c, rl_outstream);
  629.   fflush (rl_outstream);
  630.  
  631.   return 0;
  632. }
  633.  
  634. int
  635. rl_character_len (c, pos)
  636.      register int c, pos;
  637. {
  638.   if (META_CHAR (c))
  639.     return (_rl_convert_meta_chars_to_ascii ? 4 : 1);
  640.  
  641.   if (c == '\t')
  642.     {
  643. #if defined (DISPLAY_TABS)
  644.       return (((pos | (int)7) + 1) - pos);
  645. #else
  646.       return (2);
  647. #endif /* !DISPLAY_TABS */
  648.     }
  649.  
  650.   if (isprint (c))
  651.     return (1);
  652.   else
  653.     return (2);
  654. }
  655.  
  656. /* How to print things in the "echo-area".  The prompt is treated as a
  657.    mini-modeline. */
  658.  
  659. #if defined (HAVE_VARARGS_H)
  660. int
  661. rl_message (va_alist)
  662.      va_dcl
  663. {
  664.   char *format;
  665.   va_list args;
  666.  
  667.   va_start (args);
  668.   format = va_arg (args, char *);
  669.   vsprintf (msg_buf, format, args);
  670.   va_end (args);
  671.  
  672.   rl_display_prompt = msg_buf;
  673.   rl_redisplay ();
  674.  
  675.   return 0;
  676. }
  677. #else /* !HAVE_VARARGS_H */
  678. int
  679. rl_message (format, arg1, arg2)
  680.      char *format;
  681. {
  682.   sprintf (msg_buf, format, arg1, arg2);
  683.   rl_display_prompt = msg_buf;
  684.   rl_redisplay ();
  685.  
  686.   return 0;
  687. }
  688. #endif /* !HAVE_VARARGS_H */
  689.  
  690. /* How to clear things from the "echo-area". */
  691. int
  692. rl_clear_message ()
  693. {
  694.   rl_display_prompt = rl_prompt;
  695.   rl_redisplay ();
  696.   return 0;
  697. }
  698.  
  699. int
  700. rl_reset_line_state ()
  701. {
  702.   rl_on_new_line ();
  703.  
  704.   rl_display_prompt = rl_prompt ? rl_prompt : "";
  705.   forced_display = 1;
  706.  
  707.   return 0;
  708. }
  709.  
  710. /* Quick redisplay hack when erasing characters at the end of the line. */
  711. void
  712. _rl_erase_at_end_of_line (l)
  713.      int l;
  714. {
  715.   register int i;
  716.  
  717.   backspace (l);
  718.   for (i = 0; i < l; i++)
  719.     putc (' ', rl_outstream);
  720.   backspace (l);
  721.   for (i = 0; i < l; i++)
  722.     visible_line[--_rl_last_c_pos] = '\0';
  723.   rl_display_fixed++;
  724. }
  725.  
  726. /* Clear to the end of the line.  COUNT is the minimum
  727.    number of character spaces to clear, */
  728. static void
  729. clear_to_eol (count)
  730.      int count;
  731. {
  732. #if !defined (_GO32_)
  733.   if (term_clreol)
  734.     {
  735.       tputs (term_clreol, 1, _rl_output_character_function);
  736.     }
  737.   else
  738. #endif /* !_GO32_ */
  739.     {
  740.       register int i;
  741.  
  742.       /* Do one more character space. */
  743.       count++;
  744.  
  745.       for (i = 0; i < count; i++)
  746.     putc (' ', rl_outstream);
  747.  
  748.       backspace (count);
  749.     }
  750. }
  751.  
  752. /* Insert COUNT characters from STRING to the output stream. */
  753. static void
  754. insert_some_chars (string, count)
  755.      char *string;
  756.      int count;
  757. {
  758. #if defined (_GO32_)
  759.   int row, col, width;
  760.   char *row_start;
  761.  
  762.   ScreenGetCursor (&row, &col);
  763.   width = ScreenCols ();
  764.   row_start = ScreenPrimary + (row * width);
  765.  
  766.   memcpy (row_start + col + count, row_start + col, width - col - count);
  767.  
  768.   /* Place the text on the screen. */
  769.   _rl_output_some_chars (string, count);
  770. #else /* !_GO32 */
  771.  
  772.   /* If IC is defined, then we do not have to "enter" insert mode. */
  773.   if (term_IC)
  774.     {
  775.       char *tgoto (), *buffer;
  776.       buffer = tgoto (term_IC, 0, count);
  777.       tputs (buffer, 1, _rl_output_character_function);
  778.       _rl_output_some_chars (string, count);
  779.     }
  780.   else
  781.     {
  782.       register int i;
  783.  
  784.       /* If we have to turn on insert-mode, then do so. */
  785.       if (term_im && *term_im)
  786.     tputs (term_im, 1, _rl_output_character_function);
  787.  
  788.       /* If there is a special command for inserting characters, then
  789.      use that first to open up the space. */
  790.       if (term_ic && *term_ic)
  791.     {
  792.       for (i = count; i--; )
  793.         tputs (term_ic, 1, _rl_output_character_function);
  794.     }
  795.  
  796.       /* Print the text. */
  797.       _rl_output_some_chars (string, count);
  798.  
  799.       /* If there is a string to turn off insert mode, we had best use
  800.      it now. */
  801.       if (term_ei && *term_ei)
  802.     tputs (term_ei, 1, _rl_output_character_function);
  803.     }
  804. #endif /* !_GO32_ */
  805. }
  806.  
  807. /* Delete COUNT characters from the display line. */
  808. static void
  809. delete_chars (count)
  810.      int count;
  811. {
  812. #if defined (_GO32_)
  813.   int row, col, width;
  814.   char *row_start;
  815.  
  816.   ScreenGetCursor (&row, &col);
  817.   width = ScreenCols ();
  818.   row_start = ScreenPrimary + (row * width);
  819.  
  820.   memcpy (row_start + col, row_start + col + count, width - col - count);
  821.   memset (row_start + width - count, 0, count * 2);
  822. #else /* !_GO32 */
  823.  
  824.   if (count > screenwidth)
  825.     return;
  826.  
  827.   if (term_DC && *term_DC)
  828.     {
  829.       char *tgoto (), *buffer;
  830.       buffer = tgoto (term_DC, count, count);
  831.       tputs (buffer, count, _rl_output_character_function);
  832.     }
  833.   else
  834.     {
  835.       if (term_dc && *term_dc)
  836.     while (count--)
  837.       tputs (term_dc, 1, _rl_output_character_function);
  838.     }
  839. #endif /* !_GO32_ */
  840. }
  841.