2013-05-18 01:40:11 -04:00
|
|
|
/* display.c -- implements display.h */
|
|
|
|
|
|
|
|
#include "display.h"
|
|
|
|
|
2013-10-11 02:09:29 -04:00
|
|
|
#define REVSTA 1 /* Status line appears in reverse video */
|
|
|
|
|
2010-08-14 23:11:27 -04:00
|
|
|
/* display.c
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2010-11-14 21:10:03 -05:00
|
|
|
* The functions in this file handle redisplay. There are two halves, the
|
|
|
|
* ones that update the virtual display screen, and the ones that make the
|
|
|
|
* physical display screen the same as the virtual display screen. These
|
|
|
|
* functions use hints that are left in the windows by the commands.
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2010-11-14 21:10:03 -05:00
|
|
|
* Modified by Petri Kutvonen
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
|
|
|
|
2010-08-14 23:11:27 -04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <string.h>
|
2010-08-14 23:11:27 -04:00
|
|
|
#include <unistd.h>
|
2010-11-14 21:10:03 -05:00
|
|
|
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "buffer.h"
|
2010-08-14 23:11:27 -04:00
|
|
|
#include "estruct.h"
|
2013-10-08 05:41:49 -04:00
|
|
|
#include "input.h"
|
2010-11-14 21:10:03 -05:00
|
|
|
#include "line.h"
|
2013-05-28 05:21:40 -04:00
|
|
|
#include "termio.h"
|
2013-09-25 09:45:05 -04:00
|
|
|
#include "terminal.h"
|
2010-08-14 23:11:27 -04:00
|
|
|
#include "version.h"
|
2010-12-16 18:37:50 -05:00
|
|
|
#include "wrapper.h"
|
2012-07-10 19:21:35 -04:00
|
|
|
#include "utf8.h"
|
2013-05-18 02:43:13 -04:00
|
|
|
#include "window.h"
|
2012-07-10 17:24:23 -04:00
|
|
|
|
2010-05-31 21:50:16 -04:00
|
|
|
struct video {
|
2005-09-30 18:26:09 -04:00
|
|
|
int v_flag; /* Flags */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
int v_fcolor; /* current forground color */
|
|
|
|
int v_bcolor; /* current background color */
|
|
|
|
int v_rfcolor; /* requested forground color */
|
|
|
|
int v_rbcolor; /* requested background color */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t v_text[1]; /* Screen data. */
|
2010-05-31 21:50:16 -04:00
|
|
|
};
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#define VFCHG 0x0001 /* Changed flag */
|
|
|
|
#define VFEXT 0x0002 /* extended (beyond column 80) */
|
|
|
|
#define VFREV 0x0004 /* reverse video status */
|
|
|
|
#define VFREQ 0x0008 /* reverse video request */
|
|
|
|
#define VFCOL 0x0010 /* color change requested */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2010-05-31 21:50:16 -04:00
|
|
|
static struct video **vscreen; /* Virtual screen. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if MEMMAP == 0 || SCROLLCODE
|
2010-05-31 21:50:16 -04:00
|
|
|
static struct video **pscreen; /* Physical screen. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2006-11-19 14:22:04 -05:00
|
|
|
static int displaying = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if UNIX
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
/* for window size changes */
|
|
|
|
int chg_width, chg_height;
|
|
|
|
#endif
|
|
|
|
|
2013-09-29 09:58:54 -04:00
|
|
|
static int currow ; /* Cursor row */
|
|
|
|
static int curcol ; /* Cursor column */
|
|
|
|
static int vtrow = 0 ; /* Row location of SW cursor */
|
|
|
|
static int vtcol = 0 ; /* Column location of SW cursor */
|
|
|
|
static int lbound = 0 ; /* leftmost column of current line being displayed */
|
|
|
|
static int taboff = 0 ; /* tab offset for display */
|
|
|
|
|
|
|
|
int mpresf = FALSE ; /* TRUE if message in last line */
|
2013-10-09 02:38:55 -04:00
|
|
|
int scrollcount = 1 ; /* number of lines to scroll */
|
2013-10-09 04:58:33 -04:00
|
|
|
int discmd = TRUE ; /* display command flag */
|
2013-09-29 09:58:54 -04:00
|
|
|
|
2010-08-01 17:37:28 -04:00
|
|
|
static int reframe(struct window *wp);
|
|
|
|
static void updone(struct window *wp);
|
|
|
|
static void updall(struct window *wp);
|
2006-11-19 14:22:04 -05:00
|
|
|
static int scrolls(int inserts);
|
|
|
|
static void scrscroll(int from, int to, int count);
|
|
|
|
static int texttest(int vrow, int prow);
|
2012-07-10 17:24:23 -04:00
|
|
|
static int endofline(unicode_t *s, int n);
|
2006-11-19 14:22:04 -05:00
|
|
|
static void updext(void);
|
2010-05-31 21:50:16 -04:00
|
|
|
static int updateline(int row, struct video *vp1, struct video *vp2);
|
2010-08-01 17:37:28 -04:00
|
|
|
static void modeline(struct window *wp);
|
2006-11-19 14:22:04 -05:00
|
|
|
static void mlputi(int i, int r);
|
|
|
|
static void mlputli(long l, int r);
|
|
|
|
static void mlputf(int s);
|
2015-02-12 00:15:45 -05:00
|
|
|
static void mlputs( unsigned char *s) ;
|
2014-06-18 02:59:40 -04:00
|
|
|
#if SIGWINCH
|
2013-09-14 09:31:42 -04:00
|
|
|
static int newscreensize(int h, int w);
|
2014-06-18 02:59:40 -04:00
|
|
|
#endif
|
2006-11-19 14:22:04 -05:00
|
|
|
|
|
|
|
#if RAINBOW
|
|
|
|
static void putline(int row, int col, char *buf);
|
|
|
|
#endif
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* Initialize the data structures used by the display code. The edge vectors
|
|
|
|
* used to access the screens are set up. The operating system's terminal I/O
|
|
|
|
* channel is set up. All the other things get initialized at compile time.
|
|
|
|
* The original window has "WFCHG" set, so that it will get completely
|
|
|
|
* redrawn on the first call to "update".
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
void vtinit(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2010-05-31 21:50:16 -04:00
|
|
|
struct video *vp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
TTopen(); /* open the screen */
|
|
|
|
TTkopen(); /* open the keyboard */
|
|
|
|
TTrev(FALSE);
|
2010-12-16 18:37:50 -05:00
|
|
|
vscreen = xmalloc(term.t_mrow * sizeof(struct video *));
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if MEMMAP == 0 || SCROLLCODE
|
2010-12-16 18:37:50 -05:00
|
|
|
pscreen = xmalloc(term.t_mrow * sizeof(struct video *));
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
for (i = 0; i < term.t_mrow; ++i) {
|
2012-07-10 17:24:23 -04:00
|
|
|
vp = xmalloc(sizeof(struct video) + term.t_mcol*4);
|
2005-09-30 18:26:09 -04:00
|
|
|
vp->v_flag = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
vp->v_rfcolor = 7;
|
|
|
|
vp->v_rbcolor = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
vscreen[i] = vp;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if MEMMAP == 0 || SCROLLCODE
|
2012-07-10 17:24:23 -04:00
|
|
|
vp = xmalloc(sizeof(struct video) + term.t_mcol*4);
|
2005-09-30 18:26:09 -04:00
|
|
|
vp->v_flag = 0;
|
|
|
|
pscreen[i] = vp;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if CLEAN
|
|
|
|
/* free up all the dynamically allocated video structures */
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
void vtfree(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < term.t_mrow; ++i) {
|
|
|
|
free(vscreen[i]);
|
|
|
|
#if MEMMAP == 0 || SCROLLCODE
|
|
|
|
free(pscreen[i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
free(vscreen);
|
|
|
|
#if MEMMAP == 0 || SCROLLCODE
|
|
|
|
free(pscreen);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up the virtual terminal system, in anticipation for a return to the
|
|
|
|
* operating system. Move down to the last line and clear it out (the next
|
|
|
|
* system prompt will be written in the line). Shut down the channel to the
|
|
|
|
* terminal.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
void vttidy(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-22 07:26:22 -05:00
|
|
|
mlerase() ; /* ends with movecursor( term.t_nrow, 0) and TTflush() */
|
2005-09-30 18:26:09 -04:00
|
|
|
TTclose();
|
|
|
|
TTkclose();
|
2005-05-31 11:50:56 -04:00
|
|
|
#ifdef PKCODE
|
2015-01-02 01:20:07 -05:00
|
|
|
{
|
|
|
|
int ret ;
|
|
|
|
ret = write( 1, "\r", 1) ;
|
|
|
|
if( ret != 1) {
|
|
|
|
/* some error handling here */
|
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the virtual cursor to the specified row and column on the virtual
|
|
|
|
* screen. There is no checking for nonsense values; this might be a good
|
|
|
|
* idea during the early stages.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
void vtmove(int row, int col)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
vtrow = row;
|
|
|
|
vtcol = col;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* Write a character to the virtual screen. The virtual row and
|
|
|
|
* column are updated. If we are not yet on left edge, don't print
|
|
|
|
* it yet. If the line is too long put a "$" in the last column.
|
|
|
|
*
|
|
|
|
* This routine only puts printing characters into the virtual
|
|
|
|
* terminal buffers. Only column overflow is checked.
|
|
|
|
*/
|
2012-07-11 14:23:32 -04:00
|
|
|
static void vtputc(int c)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-05-31 21:50:16 -04:00
|
|
|
struct video *vp; /* ptr to line being updated */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2012-07-11 14:23:32 -04:00
|
|
|
/* In case somebody passes us a signed char.. */
|
|
|
|
if (c < 0) {
|
|
|
|
c += 256;
|
|
|
|
if (c < 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
vp = vscreen[vtrow];
|
|
|
|
|
|
|
|
if (vtcol >= term.t_ncol) {
|
|
|
|
++vtcol;
|
|
|
|
vp->v_text[term.t_ncol - 1] = '$';
|
2005-10-01 13:46:09 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\t') {
|
|
|
|
do {
|
|
|
|
vtputc(' ');
|
|
|
|
} while (((vtcol + taboff) & tabmask) != 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c < 0x20) {
|
|
|
|
vtputc('^');
|
|
|
|
vtputc(c ^ 0x40);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == 0x7f) {
|
|
|
|
vtputc('^');
|
|
|
|
vtputc('?');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-22 12:25:04 -04:00
|
|
|
if (c >= 0x80 && c <= 0xA0) {
|
2005-10-01 13:46:09 -04:00
|
|
|
static const char hex[] = "0123456789abcdef";
|
|
|
|
vtputc('\\');
|
|
|
|
vtputc(hex[c >> 4]);
|
|
|
|
vtputc(hex[c & 15]);
|
|
|
|
return;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-10-01 13:46:09 -04:00
|
|
|
|
|
|
|
if (vtcol >= 0)
|
|
|
|
vp->v_text[vtcol] = c;
|
|
|
|
++vtcol;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2015-04-13 06:26:06 -04:00
|
|
|
static int vtputs( const char *s) {
|
|
|
|
int n = 0 ;
|
|
|
|
|
|
|
|
while( *s) {
|
|
|
|
vtputc( *s++) ;
|
|
|
|
n += 1 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n ;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* Erase from the end of the software cursor to the end of the line on which
|
|
|
|
* the software cursor is located.
|
|
|
|
*/
|
2006-11-19 14:22:04 -05:00
|
|
|
static void vteeol(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-05-31 21:50:16 -04:00
|
|
|
/* struct video *vp; */
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t *vcp = vscreen[vtrow]->v_text;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* vp = vscreen[vtrow]; */
|
2005-09-30 18:26:09 -04:00
|
|
|
while (vtcol < term.t_ncol)
|
2005-05-31 11:50:56 -04:00
|
|
|
/* vp->v_text[vtcol++] = ' '; */
|
2005-09-30 18:26:09 -04:00
|
|
|
vcp[vtcol++] = ' ';
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* upscreen:
|
|
|
|
* user routine to force a screen update
|
|
|
|
* always finishes complete update
|
|
|
|
*/
|
|
|
|
int upscreen(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
update(TRUE);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if SCROLLCODE
|
2006-11-19 14:22:04 -05:00
|
|
|
static int scrflags;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that the display is right. This is a three part process. First,
|
|
|
|
* scan through all of the windows looking for dirty ones. Check the framing,
|
|
|
|
* and refresh the screen. Second, make sure that "currow" and "curcol" are
|
|
|
|
* correct for the current window. Third, make the virtual and physical
|
|
|
|
* screens the same.
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* int force; force update past type ahead?
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int update(int force)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if TYPEAH && ! PKCODE
|
|
|
|
if (force == FALSE && typahead())
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if VISMAC == 0
|
|
|
|
if (force == FALSE && kbdmode == PLAY)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
displaying = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if SCROLLCODE
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
/* first, propagate mode line changes to all instances of
|
|
|
|
a buffer displayed in more than one window */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_flag & WFMODE) {
|
|
|
|
if (wp->w_bufp->b_nwnd > 1) {
|
|
|
|
/* make sure all previous windows have this */
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *owp;
|
2005-09-30 18:26:09 -04:00
|
|
|
owp = wheadp;
|
|
|
|
while (owp != NULL) {
|
|
|
|
if (owp->w_bufp == wp->w_bufp)
|
|
|
|
owp->w_flag |= WFMODE;
|
|
|
|
owp = owp->w_wndp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* update any windows that need refreshing */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_flag) {
|
|
|
|
/* if the window has changed, service it */
|
|
|
|
reframe(wp); /* check the framing */
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wp->w_flag & (WFKILLS | WFINS)) {
|
|
|
|
scrflags |=
|
|
|
|
(wp->w_flag & (WFINS | WFKILLS));
|
|
|
|
wp->w_flag &= ~(WFKILLS | WFINS);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
if ((wp->w_flag & ~WFMODE) == WFEDIT)
|
|
|
|
updone(wp); /* update EDITed line */
|
|
|
|
else if (wp->w_flag & ~WFMOVE)
|
|
|
|
updall(wp); /* update all lines */
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if (scrflags || (wp->w_flag & WFMODE))
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
|
|
|
if (wp->w_flag & WFMODE)
|
|
|
|
#endif
|
|
|
|
modeline(wp); /* update modeline */
|
|
|
|
wp->w_flag = 0;
|
|
|
|
wp->w_force = 0;
|
|
|
|
}
|
|
|
|
/* on to the next window */
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recalc the current hardware cursor location */
|
|
|
|
updpos();
|
|
|
|
|
|
|
|
#if MEMMAP && ! SCROLLCODE
|
|
|
|
/* update the cursor and flush the buffers */
|
|
|
|
movecursor(currow, curcol - lbound);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check for lines to de-extend */
|
|
|
|
upddex();
|
|
|
|
|
|
|
|
/* if screen is garbage, re-plot it */
|
|
|
|
if (sgarbf != FALSE)
|
|
|
|
updgar();
|
|
|
|
|
|
|
|
/* update the virtual screen to the physical screen */
|
|
|
|
updupd(force);
|
|
|
|
|
|
|
|
/* update the cursor and flush the buffers */
|
|
|
|
movecursor(currow, curcol - lbound);
|
|
|
|
TTflush();
|
2005-09-30 18:26:09 -04:00
|
|
|
displaying = FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if SIGWINCH
|
2005-09-30 18:26:09 -04:00
|
|
|
while (chg_width || chg_height)
|
|
|
|
newscreensize(chg_height, chg_width);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* reframe:
|
|
|
|
* check to see if the cursor is on in the window
|
|
|
|
* and re-frame it if needed or wanted
|
|
|
|
*/
|
2010-08-01 17:37:28 -04:00
|
|
|
static int reframe(struct window *wp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp, *lp0;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if not a requested reframe, check for a needed one */
|
|
|
|
if ((wp->w_flag & WFFORCE) == 0) {
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
/* loop from one line above the window to one line after */
|
|
|
|
lp = wp->w_linep;
|
|
|
|
lp0 = lback(lp);
|
|
|
|
if (lp0 == wp->w_bufp->b_linep)
|
|
|
|
i = 0;
|
|
|
|
else {
|
|
|
|
i = -1;
|
|
|
|
lp = lp0;
|
|
|
|
}
|
|
|
|
for (; i <= (int) (wp->w_ntrows); i++)
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
|
|
|
lp = wp->w_linep;
|
|
|
|
for (i = 0; i < wp->w_ntrows; i++)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* if the line is in the window, no reframe */
|
|
|
|
if (lp == wp->w_dotp) {
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
/* if not _quite_ in, we'll reframe gently */
|
|
|
|
if (i < 0 || i == wp->w_ntrows) {
|
|
|
|
/* if the terminal can't help, then
|
|
|
|
we're simply outside */
|
|
|
|
if (term.t_scroll == NULL)
|
2005-05-31 11:50:56 -04:00
|
|
|
i = wp->w_force;
|
|
|
|
break;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we are at the end of the file, reframe */
|
|
|
|
if (lp == wp->w_bufp->b_linep)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* on to the next line */
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if (i == -1) { /* we're just above the window */
|
|
|
|
i = scrollcount; /* put dot at first line */
|
|
|
|
scrflags |= WFINS;
|
|
|
|
} else if (i == wp->w_ntrows) { /* we're just below the window */
|
|
|
|
i = -scrollcount; /* put dot at last line */
|
|
|
|
scrflags |= WFKILLS;
|
|
|
|
} else /* put dot where requested */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
i = wp->w_force; /* (is 0, unless reposition() was called) */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_flag |= WFMODE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* how far back to reframe? */
|
|
|
|
if (i > 0) { /* only one screen worth of lines max */
|
|
|
|
if (--i >= wp->w_ntrows)
|
|
|
|
i = wp->w_ntrows - 1;
|
|
|
|
} else if (i < 0) { /* negative update???? */
|
|
|
|
i += wp->w_ntrows;
|
|
|
|
if (i < 0)
|
|
|
|
i = 0;
|
|
|
|
} else
|
|
|
|
i = wp->w_ntrows / 2;
|
|
|
|
|
|
|
|
/* backup to new line at top of window */
|
|
|
|
lp = wp->w_dotp;
|
|
|
|
while (i != 0 && lback(lp) != wp->w_bufp->b_linep) {
|
|
|
|
--i;
|
|
|
|
lp = lback(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and reset the current line at top of window */
|
|
|
|
wp->w_linep = lp;
|
|
|
|
wp->w_flag |= WFHARD;
|
|
|
|
wp->w_flag &= ~WFFORCE;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2012-07-10 16:38:41 -04:00
|
|
|
static void show_line(struct line *lp)
|
|
|
|
{
|
2013-02-22 17:29:43 -05:00
|
|
|
int i = 0, len = llength(lp);
|
2012-07-10 18:08:17 -04:00
|
|
|
|
|
|
|
while (i < len) {
|
|
|
|
unicode_t c;
|
2012-07-11 14:23:32 -04:00
|
|
|
i += utf8_to_unicode(lp->l_text, i, len, &c);
|
|
|
|
vtputc(c);
|
2012-07-10 18:08:17 -04:00
|
|
|
}
|
2012-07-10 16:38:41 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updone:
|
|
|
|
* update the current line to the virtual screen
|
|
|
|
*
|
2010-08-01 17:37:28 -04:00
|
|
|
* struct window *wp; window to update current line in
|
2005-09-30 19:34:11 -04:00
|
|
|
*/
|
2010-08-01 17:37:28 -04:00
|
|
|
static void updone(struct window *wp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp; /* line to update */
|
2010-02-27 05:38:22 -05:00
|
|
|
int sline; /* physical screen line to update */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* search down the line we want */
|
|
|
|
lp = wp->w_linep;
|
|
|
|
sline = wp->w_toprow;
|
|
|
|
while (lp != wp->w_dotp) {
|
|
|
|
++sline;
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and update the virtual line */
|
|
|
|
vscreen[sline]->v_flag |= VFCHG;
|
|
|
|
vscreen[sline]->v_flag &= ~VFREQ;
|
|
|
|
vtmove(sline, 0);
|
2012-07-10 16:38:41 -04:00
|
|
|
show_line(lp);
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
|
|
|
vscreen[sline]->v_rfcolor = wp->w_fcolor;
|
|
|
|
vscreen[sline]->v_rbcolor = wp->w_bcolor;
|
|
|
|
#endif
|
|
|
|
vteeol();
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updall:
|
|
|
|
* update all the lines in a window on the virtual screen
|
|
|
|
*
|
2010-08-01 17:37:28 -04:00
|
|
|
* struct window *wp; window to update lines in
|
2005-09-30 19:34:11 -04:00
|
|
|
*/
|
2010-08-01 17:37:28 -04:00
|
|
|
static void updall(struct window *wp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp; /* line to update */
|
2010-02-27 05:38:22 -05:00
|
|
|
int sline; /* physical screen line to update */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* search down the lines, updating them */
|
|
|
|
lp = wp->w_linep;
|
|
|
|
sline = wp->w_toprow;
|
|
|
|
while (sline < wp->w_toprow + wp->w_ntrows) {
|
|
|
|
|
|
|
|
/* and update the virtual line */
|
|
|
|
vscreen[sline]->v_flag |= VFCHG;
|
|
|
|
vscreen[sline]->v_flag &= ~VFREQ;
|
|
|
|
vtmove(sline, 0);
|
|
|
|
if (lp != wp->w_bufp->b_linep) {
|
|
|
|
/* if we are not at the end */
|
2012-07-10 16:38:41 -04:00
|
|
|
show_line(lp);
|
2005-05-31 11:50:56 -04:00
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* on to the next one */
|
|
|
|
#if COLOR
|
|
|
|
vscreen[sline]->v_rfcolor = wp->w_fcolor;
|
|
|
|
vscreen[sline]->v_rbcolor = wp->w_bcolor;
|
|
|
|
#endif
|
|
|
|
vteeol();
|
|
|
|
++sline;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updpos:
|
|
|
|
* update the position of the hardware cursor and handle extended
|
|
|
|
* lines. This is the only update for simple moves.
|
|
|
|
*/
|
|
|
|
void updpos(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* find the current row */
|
|
|
|
lp = curwp->w_linep;
|
|
|
|
currow = curwp->w_toprow;
|
|
|
|
while (lp != curwp->w_dotp) {
|
|
|
|
++currow;
|
|
|
|
lp = lforw(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the current column */
|
|
|
|
curcol = 0;
|
|
|
|
i = 0;
|
|
|
|
while (i < curwp->w_doto) {
|
2012-07-10 19:40:36 -04:00
|
|
|
unicode_t c;
|
2015-02-03 23:37:57 -05:00
|
|
|
|
|
|
|
i += utf8_to_unicode( lp->l_text, i, curwp->w_doto, &c) ;
|
|
|
|
if( c == '\t')
|
|
|
|
curcol |= tabmask ;
|
|
|
|
else if( c < 0x20 || c == 0x7F)
|
2015-01-30 18:57:26 -05:00
|
|
|
curcol += 1 ; /* displayed as ^c */
|
2015-02-03 23:37:57 -05:00
|
|
|
else if( c >= 0x80 && c <= 0xA0)
|
2015-01-30 18:57:26 -05:00
|
|
|
curcol += 2 ; /* displayed as \xx */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
++curcol;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if extended, flag so and update the virtual line image */
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curcol >= term.t_ncol - 1) {
|
2005-05-31 11:50:56 -04:00
|
|
|
vscreen[currow]->v_flag |= (VFEXT | VFCHG);
|
|
|
|
updext();
|
|
|
|
} else
|
|
|
|
lbound = 0;
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* upddex:
|
|
|
|
* de-extend any line that derserves it
|
|
|
|
*/
|
|
|
|
void upddex(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp;
|
2012-07-10 16:38:41 -04:00
|
|
|
int i;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
wp = wheadp;
|
|
|
|
|
|
|
|
while (wp != NULL) {
|
|
|
|
lp = wp->w_linep;
|
|
|
|
i = wp->w_toprow;
|
|
|
|
|
|
|
|
while (i < wp->w_toprow + wp->w_ntrows) {
|
|
|
|
if (vscreen[i]->v_flag & VFEXT) {
|
|
|
|
if ((wp != curwp) || (lp != wp->w_dotp) ||
|
2005-09-30 18:26:09 -04:00
|
|
|
(curcol < term.t_ncol - 1)) {
|
2005-05-31 11:50:56 -04:00
|
|
|
vtmove(i, 0);
|
2012-07-10 16:38:41 -04:00
|
|
|
show_line(lp);
|
2005-05-31 11:50:56 -04:00
|
|
|
vteeol();
|
|
|
|
|
|
|
|
/* this line no longer is extended */
|
|
|
|
vscreen[i]->v_flag &= ~VFEXT;
|
|
|
|
vscreen[i]->v_flag |= VFCHG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lp = lforw(lp);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
/* and onward to the next window */
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updgar:
|
|
|
|
* if the screen is garbage, clear the physical screen and
|
|
|
|
* the virtual screen and force a full update
|
|
|
|
*/
|
|
|
|
void updgar(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t *txt;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i, j;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
for (i = 0; i < term.t_nrow; ++i) {
|
|
|
|
vscreen[i]->v_flag |= VFCHG;
|
|
|
|
#if REVSTA
|
|
|
|
vscreen[i]->v_flag &= ~VFREV;
|
|
|
|
#endif
|
|
|
|
#if COLOR
|
|
|
|
vscreen[i]->v_fcolor = gfcolor;
|
|
|
|
vscreen[i]->v_bcolor = gbcolor;
|
|
|
|
#endif
|
|
|
|
#if MEMMAP == 0 || SCROLLCODE
|
|
|
|
txt = pscreen[i]->v_text;
|
|
|
|
for (j = 0; j < term.t_ncol; ++j)
|
|
|
|
txt[j] = ' ';
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
movecursor(0, 0); /* Erase the screen. */
|
|
|
|
(*term.t_eeop) ();
|
|
|
|
sgarbf = FALSE; /* Erase-page clears */
|
|
|
|
mpresf = FALSE; /* the message area. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
mlerase(); /* needs to be cleared if colored */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updupd:
|
|
|
|
* update the physical screen from the virtual screen
|
|
|
|
*
|
|
|
|
* int force; forced update flag
|
|
|
|
*/
|
|
|
|
int updupd(int force)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-05-31 21:50:16 -04:00
|
|
|
struct video *vp1;
|
2010-02-27 05:38:22 -05:00
|
|
|
int i;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if (scrflags & WFKILLS)
|
|
|
|
scrolls(FALSE);
|
|
|
|
if (scrflags & WFINS)
|
|
|
|
scrolls(TRUE);
|
|
|
|
scrflags = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < term.t_nrow; ++i) {
|
|
|
|
vp1 = vscreen[i];
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
/* for each line that needs to be updated */
|
2005-05-31 11:50:56 -04:00
|
|
|
if ((vp1->v_flag & VFCHG) != 0) {
|
|
|
|
#if TYPEAH && ! PKCODE
|
|
|
|
if (force == FALSE && typahead())
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if MEMMAP && ! SCROLLCODE
|
|
|
|
updateline(i, vp1);
|
|
|
|
#else
|
|
|
|
updateline(i, vp1, pscreen[i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if SCROLLCODE
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* optimize out scrolls (line breaks, and newlines)
|
|
|
|
* arg. chooses between looking for inserts or deletes
|
|
|
|
*/
|
2006-11-19 14:22:04 -05:00
|
|
|
static int scrolls(int inserts)
|
2005-09-30 18:26:09 -04:00
|
|
|
{ /* returns true if it does something */
|
2010-05-31 21:50:16 -04:00
|
|
|
struct video *vpv; /* virtual screen image */
|
|
|
|
struct video *vpp; /* physical screen image */
|
2005-09-30 18:26:09 -04:00
|
|
|
int i, j, k;
|
|
|
|
int rows, cols;
|
2006-11-19 14:22:04 -05:00
|
|
|
int first, match, count, target, end;
|
2005-09-30 18:26:09 -04:00
|
|
|
int longmatch, longcount;
|
|
|
|
int from, to;
|
|
|
|
|
|
|
|
if (!term.t_scroll) /* no way to scroll */
|
2005-05-31 11:50:56 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
rows = term.t_nrow;
|
|
|
|
cols = term.t_ncol;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
first = -1;
|
2005-05-31 11:50:56 -04:00
|
|
|
for (i = 0; i < rows; i++) { /* find first wrong line */
|
2005-09-30 18:26:09 -04:00
|
|
|
if (!texttest(i, i)) {
|
2005-05-31 11:50:56 -04:00
|
|
|
first = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first < 0)
|
2005-09-30 18:26:09 -04:00
|
|
|
return FALSE; /* no text changes */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
vpv = vscreen[first];
|
|
|
|
vpp = pscreen[first];
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
if (inserts) {
|
|
|
|
/* determine types of potential scrolls */
|
2005-09-30 18:26:09 -04:00
|
|
|
end = endofline(vpv->v_text, cols);
|
|
|
|
if (end == 0)
|
2006-11-19 14:22:04 -05:00
|
|
|
target = first; /* newlines */
|
2012-07-10 17:24:23 -04:00
|
|
|
else if (memcmp(vpp->v_text, vpv->v_text, 4*end) == 0)
|
2006-11-19 14:22:04 -05:00
|
|
|
target = first + 1; /* broken line newlines */
|
2005-05-31 11:50:56 -04:00
|
|
|
else
|
2006-11-19 14:22:04 -05:00
|
|
|
target = first;
|
2005-05-31 11:50:56 -04:00
|
|
|
} else {
|
2006-11-19 14:22:04 -05:00
|
|
|
target = first + 1;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find the matching shifted area */
|
2005-09-30 18:26:09 -04:00
|
|
|
match = -1;
|
2005-05-31 11:50:56 -04:00
|
|
|
longmatch = -1;
|
|
|
|
longcount = 0;
|
2006-11-19 14:22:04 -05:00
|
|
|
from = target;
|
2005-09-30 18:26:09 -04:00
|
|
|
for (i = from + 1; i < rows - longcount /* P.K. */ ; i++) {
|
|
|
|
if (inserts ? texttest(i, from) : texttest(from, i)) {
|
|
|
|
match = i;
|
|
|
|
count = 1;
|
|
|
|
for (j = match + 1, k = from + 1;
|
|
|
|
j < rows && k < rows; j++, k++) {
|
|
|
|
if (inserts ? texttest(j, k) :
|
|
|
|
texttest(k, j))
|
|
|
|
count++;
|
2005-05-31 11:50:56 -04:00
|
|
|
else
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
if (longcount < count) {
|
|
|
|
longcount = count;
|
|
|
|
longmatch = match;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match = longmatch;
|
|
|
|
count = longcount;
|
|
|
|
|
|
|
|
if (!inserts) {
|
|
|
|
/* full kill case? */
|
2005-09-30 18:26:09 -04:00
|
|
|
if (match > 0 && texttest(first, match - 1)) {
|
2006-11-19 14:22:04 -05:00
|
|
|
target--;
|
2005-09-30 18:26:09 -04:00
|
|
|
match--;
|
|
|
|
count++;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do the scroll */
|
2005-09-30 18:26:09 -04:00
|
|
|
if (match > 0 && count > 2) { /* got a scroll */
|
2006-11-19 14:22:04 -05:00
|
|
|
/* move the count lines starting at target to match */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (inserts) {
|
2006-11-19 14:22:04 -05:00
|
|
|
from = target;
|
2005-05-31 11:50:56 -04:00
|
|
|
to = match;
|
|
|
|
} else {
|
|
|
|
from = match;
|
2006-11-19 14:22:04 -05:00
|
|
|
to = target;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
if (2 * count < abs(from - to))
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
scrscroll(from, to, count);
|
2005-05-31 11:50:56 -04:00
|
|
|
for (i = 0; i < count; i++) {
|
2005-09-30 18:26:09 -04:00
|
|
|
vpp = pscreen[to + i];
|
|
|
|
vpv = vscreen[to + i];
|
2012-07-10 17:24:23 -04:00
|
|
|
memcpy(vpp->v_text, vpv->v_text, 4*cols);
|
2005-09-30 18:26:09 -04:00
|
|
|
vpp->v_flag = vpv->v_flag; /* XXX */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (vpp->v_flag & VFREV) {
|
|
|
|
vpp->v_flag &= ~VFREV;
|
|
|
|
vpp->v_flag |= ~VFREQ;
|
|
|
|
}
|
|
|
|
#if MEMMAP
|
2005-09-30 18:26:09 -04:00
|
|
|
vscreen[to + i]->v_flag &= ~VFCHG;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (inserts) {
|
2006-11-19 14:22:04 -05:00
|
|
|
from = target;
|
2005-05-31 11:50:56 -04:00
|
|
|
to = match;
|
|
|
|
} else {
|
2006-11-19 14:22:04 -05:00
|
|
|
from = target + count;
|
2005-09-30 18:26:09 -04:00
|
|
|
to = match + count;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#if MEMMAP == 0
|
|
|
|
for (i = from; i < to; i++) {
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t *txt;
|
2005-05-31 11:50:56 -04:00
|
|
|
txt = pscreen[i]->v_text;
|
|
|
|
for (j = 0; j < term.t_ncol; ++j)
|
|
|
|
txt[j] = ' ';
|
|
|
|
vscreen[i]->v_flag |= VFCHG;
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* move the "count" lines starting at "from" to "to" */
|
2006-11-19 14:22:04 -05:00
|
|
|
static void scrscroll(int from, int to, int count)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
ttrow = ttcol = -1;
|
2005-09-30 18:26:09 -04:00
|
|
|
(*term.t_scroll) (from, to, count);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* return TRUE on text match
|
|
|
|
*
|
|
|
|
* int vrow, prow; virtual, physical rows
|
|
|
|
*/
|
2006-11-19 14:22:04 -05:00
|
|
|
static int texttest(int vrow, int prow)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-05-31 21:50:16 -04:00
|
|
|
struct video *vpv = vscreen[vrow]; /* virtual screen image */
|
|
|
|
struct video *vpp = pscreen[prow]; /* physical screen image */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2012-07-10 17:24:23 -04:00
|
|
|
return !memcmp(vpv->v_text, vpp->v_text, 4*term.t_ncol);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* return the index of the first blank of trailing whitespace
|
|
|
|
*/
|
2012-07-10 17:24:23 -04:00
|
|
|
static int endofline(unicode_t *s, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
int i;
|
2005-05-31 11:50:56 -04:00
|
|
|
for (i = n - 1; i >= 0; i--)
|
2005-09-30 18:26:09 -04:00
|
|
|
if (s[i] != ' ')
|
2010-08-29 06:03:55 -04:00
|
|
|
return i + 1;
|
|
|
|
return 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#endif /* SCROLLCODE */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updext:
|
|
|
|
* update the extended line which the cursor is currently
|
|
|
|
* on at a column greater than the terminal width. The line
|
|
|
|
* will be scrolled right or left to let the user see where
|
|
|
|
* the cursor is
|
|
|
|
*/
|
2006-11-19 14:22:04 -05:00
|
|
|
static void updext(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int rcursor; /* real cursor location */
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp; /* pointer to current line */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* calculate what column the real cursor will end up in */
|
|
|
|
rcursor = ((curcol - term.t_ncol) % term.t_scrsiz) + term.t_margin;
|
|
|
|
taboff = lbound = curcol - rcursor + 1;
|
|
|
|
|
|
|
|
/* scan through the line outputing characters to the virtual screen */
|
2005-09-30 18:26:09 -04:00
|
|
|
/* once we reach the left edge */
|
2005-05-31 11:50:56 -04:00
|
|
|
vtmove(currow, -lbound); /* start scanning offscreen */
|
2005-09-30 18:26:09 -04:00
|
|
|
lp = curwp->w_dotp; /* line to output */
|
2012-07-10 16:38:41 -04:00
|
|
|
show_line(lp);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* truncate the virtual line, restore tab offset */
|
|
|
|
vteeol();
|
|
|
|
taboff = 0;
|
|
|
|
|
|
|
|
/* and put a '$' in column 1 */
|
|
|
|
vscreen[currow]->v_text[0] = '$';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update a single line. This does not know how to use insert or delete
|
|
|
|
* character sequences; we are using VT52 functionality. Update the physical
|
|
|
|
* row and column variables. It does try an exploit erase to end of line. The
|
|
|
|
* RAINBOW version of this routine uses fast video.
|
|
|
|
*/
|
|
|
|
#if MEMMAP
|
|
|
|
/* UPDATELINE specific code for the IBM-PC and other compatables */
|
|
|
|
|
2010-05-31 21:50:16 -04:00
|
|
|
static int updateline(int row, struct video *vp1, struct video *vp2)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if SCROLLCODE
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t *cp1;
|
|
|
|
unicode_t *cp2;
|
2010-02-27 05:38:22 -05:00
|
|
|
int nch;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
cp1 = &vp1->v_text[0];
|
|
|
|
cp2 = &vp2->v_text[0];
|
|
|
|
nch = term.t_ncol;
|
2005-09-30 18:26:09 -04:00
|
|
|
do {
|
2005-05-31 11:50:56 -04:00
|
|
|
*cp2 = *cp1;
|
|
|
|
++cp2;
|
|
|
|
++cp1;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
while (--nch);
|
|
|
|
#endif
|
|
|
|
#if COLOR
|
|
|
|
scwrite(row, vp1->v_text, vp1->v_rfcolor, vp1->v_rbcolor);
|
|
|
|
vp1->v_fcolor = vp1->v_rfcolor;
|
|
|
|
vp1->v_bcolor = vp1->v_rbcolor;
|
|
|
|
#else
|
|
|
|
if (vp1->v_flag & VFREQ)
|
|
|
|
scwrite(row, vp1->v_text, 0, 7);
|
|
|
|
else
|
|
|
|
scwrite(row, vp1->v_text, 7, 0);
|
|
|
|
#endif
|
|
|
|
vp1->v_flag &= ~(VFCHG | VFCOL); /* flag this line as changed */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* updateline()
|
|
|
|
*
|
|
|
|
* int row; row of screen to update
|
2010-05-31 21:50:16 -04:00
|
|
|
* struct video *vp1; virtual screen image
|
|
|
|
* struct video *vp2; physical screen image
|
2005-09-30 19:34:11 -04:00
|
|
|
*/
|
2010-05-31 21:50:16 -04:00
|
|
|
static int updateline(int row, struct video *vp1, struct video *vp2)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if RAINBOW
|
|
|
|
/* UPDATELINE specific code for the DEC rainbow 100 micro */
|
|
|
|
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t *cp1;
|
|
|
|
unicode_t *cp2;
|
2010-02-27 05:38:22 -05:00
|
|
|
int nch;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
/* since we don't know how to make the rainbow do this, turn it off */
|
|
|
|
flags &= (~VFREV & ~VFREQ);
|
|
|
|
|
|
|
|
cp1 = &vp1->v_text[0]; /* Use fast video. */
|
|
|
|
cp2 = &vp2->v_text[0];
|
|
|
|
putline(row + 1, 1, cp1);
|
|
|
|
nch = term.t_ncol;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*cp2 = *cp1;
|
|
|
|
++cp2;
|
|
|
|
++cp1;
|
|
|
|
}
|
|
|
|
while (--nch);
|
|
|
|
*flags &= ~VFCHG;
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
|
|
|
/* UPDATELINE code for all other versions */
|
|
|
|
|
2012-07-10 17:24:23 -04:00
|
|
|
unicode_t *cp1;
|
|
|
|
unicode_t *cp2;
|
|
|
|
unicode_t *cp3;
|
|
|
|
unicode_t *cp4;
|
|
|
|
unicode_t *cp5;
|
2010-02-27 05:38:22 -05:00
|
|
|
int nbflag; /* non-blanks to the right flag? */
|
2013-06-13 21:12:31 -04:00
|
|
|
#if REVSTA
|
|
|
|
int rev; /* reverse video flag */
|
|
|
|
#endif
|
|
|
|
int req = FALSE ; /* reverse video request flag */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* set up pointers to virtual and physical lines */
|
|
|
|
cp1 = &vp1->v_text[0];
|
|
|
|
cp2 = &vp2->v_text[0];
|
|
|
|
|
|
|
|
#if COLOR
|
|
|
|
TTforg(vp1->v_rfcolor);
|
|
|
|
TTbacg(vp1->v_rbcolor);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if REVSTA | COLOR
|
|
|
|
/* if we need to change the reverse video status of the
|
|
|
|
current line, we need to re-write the entire line */
|
|
|
|
rev = (vp1->v_flag & VFREV) == VFREV;
|
|
|
|
req = (vp1->v_flag & VFREQ) == VFREQ;
|
|
|
|
if ((rev != req)
|
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
|| (vp1->v_fcolor != vp1->v_rfcolor)
|
|
|
|
|| (vp1->v_bcolor != vp1->v_rbcolor)
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
) {
|
2005-05-31 11:50:56 -04:00
|
|
|
movecursor(row, 0); /* Go to start of line. */
|
|
|
|
/* set rev video if needed */
|
|
|
|
if (rev != req)
|
2005-09-30 18:26:09 -04:00
|
|
|
(*term.t_rev) (req);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* scan through the line and dump it to the screen and
|
2005-09-30 18:26:09 -04:00
|
|
|
the virtual screen array */
|
2005-05-31 11:50:56 -04:00
|
|
|
cp3 = &vp1->v_text[term.t_ncol];
|
|
|
|
while (cp1 < cp3) {
|
|
|
|
TTputc(*cp1);
|
|
|
|
++ttcol;
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
}
|
|
|
|
/* turn rev video off */
|
|
|
|
if (rev != req)
|
2005-09-30 18:26:09 -04:00
|
|
|
(*term.t_rev) (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* update the needed flags */
|
|
|
|
vp1->v_flag &= ~VFCHG;
|
|
|
|
if (req)
|
|
|
|
vp1->v_flag |= VFREV;
|
|
|
|
else
|
|
|
|
vp1->v_flag &= ~VFREV;
|
|
|
|
#if COLOR
|
|
|
|
vp1->v_fcolor = vp1->v_rfcolor;
|
|
|
|
vp1->v_bcolor = vp1->v_rbcolor;
|
|
|
|
#endif
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* advance past any common chars at the left */
|
|
|
|
while (cp1 != &vp1->v_text[term.t_ncol] && cp1[0] == cp2[0]) {
|
|
|
|
++cp1;
|
|
|
|
++cp2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This can still happen, even though we only call this routine on changed
|
|
|
|
* lines. A hard update is always done when a line splits, a massive
|
|
|
|
* change is done, or a buffer is displayed twice. This optimizes out most
|
|
|
|
* of the excess updating. A lot of computes are used, but these tend to
|
|
|
|
* be hard operations that do a lot of update, so I don't really care.
|
|
|
|
*/
|
|
|
|
/* if both lines are the same, no update needs to be done */
|
|
|
|
if (cp1 == &vp1->v_text[term.t_ncol]) {
|
2005-09-30 18:26:09 -04:00
|
|
|
vp1->v_flag &= ~VFCHG; /* flag this line is changed */
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find out if there is a match on the right */
|
|
|
|
nbflag = FALSE;
|
|
|
|
cp3 = &vp1->v_text[term.t_ncol];
|
|
|
|
cp4 = &vp2->v_text[term.t_ncol];
|
|
|
|
|
|
|
|
while (cp3[-1] == cp4[-1]) {
|
|
|
|
--cp3;
|
|
|
|
--cp4;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (cp3[0] != ' ') /* Note if any nonblank */
|
|
|
|
nbflag = TRUE; /* in right match. */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cp5 = cp3;
|
|
|
|
|
|
|
|
/* Erase to EOL ? */
|
|
|
|
if (nbflag == FALSE && eolexist == TRUE && (req != TRUE)) {
|
2005-09-30 18:26:09 -04:00
|
|
|
while (cp5 != cp1 && cp5[-1] == ' ')
|
2005-05-31 11:50:56 -04:00
|
|
|
--cp5;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (cp3 - cp5 <= 3) /* Use only if erase is */
|
|
|
|
cp5 = cp3; /* fewer characters. */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
movecursor(row, cp1 - &vp1->v_text[0]); /* Go to start of line. */
|
|
|
|
#if REVSTA
|
|
|
|
TTrev(rev);
|
|
|
|
#endif
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
while (cp1 != cp5) { /* Ordinary. */
|
2005-05-31 11:50:56 -04:00
|
|
|
TTputc(*cp1);
|
|
|
|
++ttcol;
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (cp5 != cp3) { /* Erase. */
|
2005-05-31 11:50:56 -04:00
|
|
|
TTeeol();
|
|
|
|
while (cp1 != cp3)
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
}
|
|
|
|
#if REVSTA
|
|
|
|
TTrev(FALSE);
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
vp1->v_flag &= ~VFCHG; /* flag this line as updated */
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Redisplay the mode line for the window pointed to by the "wp". This is the
|
|
|
|
* only routine that has any idea of how the modeline is formatted. You can
|
|
|
|
* change the modeline format by hacking at this routine. Called by "update"
|
|
|
|
* any time there is a dirty window.
|
|
|
|
*/
|
2010-08-01 17:37:28 -04:00
|
|
|
static void modeline(struct window *wp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int n; /* cursor position count */
|
|
|
|
struct buffer *bp;
|
|
|
|
int i; /* loop index */
|
|
|
|
int lchar; /* character to draw line in buffer with */
|
|
|
|
int firstm; /* is this the first mode? */
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
n = wp->w_toprow + wp->w_ntrows; /* Location. */
|
|
|
|
vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL; /* Redraw next time. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
vscreen[n]->v_rfcolor = 0; /* black on */
|
|
|
|
vscreen[n]->v_rbcolor = 7; /* white..... */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
vtmove(n, 0); /* Seek to right line. */
|
|
|
|
if (wp == curwp) /* mark the current buffer */
|
2013-06-13 21:12:31 -04:00
|
|
|
#if PKCODE && REVSTA
|
2005-09-30 18:26:09 -04:00
|
|
|
lchar = '-';
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
lchar = '=';
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
else
|
2005-05-31 11:50:56 -04:00
|
|
|
#if REVSTA
|
|
|
|
if (revexist)
|
|
|
|
lchar = ' ';
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
lchar = '-';
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
bp = wp->w_bufp;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE == 0
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((bp->b_flag & BFTRUNC) != 0)
|
|
|
|
vtputc('#');
|
|
|
|
else
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
vtputc(lchar);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed. */
|
|
|
|
vtputc('*');
|
|
|
|
else
|
|
|
|
vtputc(lchar);
|
|
|
|
|
2015-02-02 06:20:48 -05:00
|
|
|
vtputc( ' ') ;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2015-04-18 23:59:31 -04:00
|
|
|
if( n == term.t_nrow - 1)
|
|
|
|
n = 3 + vtputs( PROGRAM_NAME_LONG " " VERSION ": ") ;
|
|
|
|
else
|
|
|
|
n = 3 ;
|
|
|
|
|
2015-04-13 06:26:06 -04:00
|
|
|
n += vtputs( bp->b_bname) ;
|
|
|
|
n += vtputs( " (") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
/* display the modes */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((bp->b_flag & BFTRUNC) != 0) {
|
2005-05-31 11:50:56 -04:00
|
|
|
firstm = FALSE;
|
2015-04-13 06:26:06 -04:00
|
|
|
n += vtputs( "Truncated") ;
|
|
|
|
} else
|
|
|
|
firstm = TRUE ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
for (i = 0; i < NUMMODES; i++) /* add in the mode flags */
|
|
|
|
if (wp->w_bufp->b_mode & (1 << i)) {
|
|
|
|
if (firstm != TRUE)
|
2015-04-13 06:26:06 -04:00
|
|
|
n += vtputs( " ") ;
|
|
|
|
else
|
|
|
|
firstm = FALSE ;
|
|
|
|
|
|
|
|
n += vtputs( modename[ i]) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2015-04-13 06:26:06 -04:00
|
|
|
n += vtputs( ") ") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if PKCODE
|
2015-04-13 06:26:06 -04:00
|
|
|
if (bp->b_fname[0] != 0 && strcmp(bp->b_bname, bp->b_fname) != 0) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2015-04-13 06:26:06 -04:00
|
|
|
if (bp->b_fname[0] != 0) { /* File name. */
|
|
|
|
n += vtputs( "File: ") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2015-04-13 06:26:06 -04:00
|
|
|
n += vtputs( bp->b_fname) ;
|
2005-09-30 18:26:09 -04:00
|
|
|
vtputc(' ');
|
|
|
|
++n;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
while (n < term.t_ncol) { /* Pad to full width. */
|
|
|
|
vtputc(lchar);
|
|
|
|
++n;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
{ /* determine if top line, bottom line, or both are visible */
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp = wp->w_linep;
|
2005-05-31 11:50:56 -04:00
|
|
|
int rows = wp->w_ntrows;
|
|
|
|
char *msg = NULL;
|
2015-04-13 06:26:06 -04:00
|
|
|
char tline[ 6] ; /* buffer for part of mode line */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
vtcol = n - 7; /* strlen(" top ") plus a couple */
|
2005-05-31 11:50:56 -04:00
|
|
|
while (rows--) {
|
|
|
|
lp = lforw(lp);
|
|
|
|
if (lp == wp->w_bufp->b_linep) {
|
|
|
|
msg = " Bot ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lback(wp->w_linep) == wp->w_bufp->b_linep) {
|
|
|
|
if (msg) {
|
|
|
|
if (wp->w_linep == wp->w_bufp->b_linep)
|
|
|
|
msg = " Emp ";
|
|
|
|
else
|
|
|
|
msg = " All ";
|
|
|
|
} else {
|
|
|
|
msg = " Top ";
|
|
|
|
}
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
if (!msg) {
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp;
|
2015-02-15 03:10:44 -05:00
|
|
|
int numlines, predlines ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
lp = lforw(bp->b_linep);
|
|
|
|
numlines = 0;
|
2006-11-19 14:22:04 -05:00
|
|
|
predlines = 0;
|
2005-09-30 18:26:09 -04:00
|
|
|
while (lp != bp->b_linep) {
|
2005-05-31 11:50:56 -04:00
|
|
|
if (lp == wp->w_linep) {
|
|
|
|
predlines = numlines;
|
|
|
|
}
|
|
|
|
++numlines;
|
|
|
|
lp = lforw(lp);
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
if (wp->w_dotp == bp->b_linep) {
|
|
|
|
msg = " Bot ";
|
|
|
|
} else {
|
2015-02-15 03:10:44 -05:00
|
|
|
int ratio = 0 ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
if (numlines != 0)
|
2005-09-30 18:26:09 -04:00
|
|
|
ratio =
|
|
|
|
(100L * predlines) / numlines;
|
2005-05-31 11:50:56 -04:00
|
|
|
if (ratio > 99)
|
|
|
|
ratio = 99;
|
2015-02-15 03:10:44 -05:00
|
|
|
|
|
|
|
tline[ 0] = ' ' ;
|
|
|
|
tline[ 1] = ratio / 10 + '0' ;
|
|
|
|
tline[ 2] = ratio % 10 + '0' ;
|
|
|
|
tline[ 3] = '%' ;
|
|
|
|
tline[ 4] = ' ' ;
|
|
|
|
tline[ 5] = 0 ;
|
|
|
|
if( tline[ 1] == '0')
|
|
|
|
tline[ 1] = ' ' ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
msg = tline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 06:26:06 -04:00
|
|
|
n += vtputs( msg) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
void upmode(void)
|
2005-09-30 18:26:09 -04:00
|
|
|
{ /* update all the mode lines */
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
wp->w_flag |= WFMODE;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a command to the terminal to move the hardware cursor to row "row"
|
|
|
|
* and column "col". The row and column arguments are origin 0. Optimize out
|
|
|
|
* random calls. Update "ttrow" and "ttcol".
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
void movecursor(int row, int col)
|
2005-09-30 18:26:09 -04:00
|
|
|
{
|
|
|
|
if (row != ttrow || col != ttcol) {
|
|
|
|
ttrow = row;
|
|
|
|
ttcol = col;
|
|
|
|
TTmove(row, col);
|
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Erase the message line. This is a special routine because the message line
|
|
|
|
* is not considered to be part of the virtual screen. It always works
|
|
|
|
* immediately; the terminal buffer is flushed via a call to the flusher.
|
|
|
|
*/
|
2015-01-22 07:26:22 -05:00
|
|
|
void mlerase( void) {
|
|
|
|
movecursor( term.t_nrow, 0) ;
|
|
|
|
if( discmd != FALSE) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2015-01-22 07:26:22 -05:00
|
|
|
TTforg( 7) ;
|
|
|
|
TTbacg( 0) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2015-01-22 07:26:22 -05:00
|
|
|
if( eolexist == TRUE)
|
|
|
|
TTeeol() ;
|
|
|
|
else {
|
2015-01-23 00:13:07 -05:00
|
|
|
for( ttcol = 0 ; ttcol < term.t_ncol ; ttcol++)
|
|
|
|
TTputc( ' ') ;
|
2015-01-22 04:36:11 -05:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
movecursor( term.t_nrow, 0) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
mpresf = FALSE ;
|
|
|
|
}
|
|
|
|
|
|
|
|
TTflush() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlputc( char c) {
|
|
|
|
if( ttcol < term.t_ncol) {
|
|
|
|
TTputc( c) ;
|
|
|
|
++ttcol ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a message into the message line. Keep track of the physical cursor
|
|
|
|
* position. A small class of printf like format items is handled. Assumes the
|
|
|
|
* stack grows down; this assumption is made by the "++" in the argument scan
|
|
|
|
* loop. Set the "message line" flag TRUE.
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* char *fmt; format string for output
|
|
|
|
* char *arg; pointer to first argument to print
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
void mlwrite(const char *fmt, ...)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int c; /* current char in format string */
|
2005-09-30 19:34:11 -04:00
|
|
|
va_list ap;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if we are not currently echoing on the command line, abort this */
|
|
|
|
if (discmd == FALSE) {
|
|
|
|
movecursor(term.t_nrow, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if COLOR
|
|
|
|
/* set up the proper colors for the command line */
|
|
|
|
TTforg(7);
|
|
|
|
TTbacg(0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* if we can not erase to end-of-line, do it manually */
|
2015-01-22 04:36:11 -05:00
|
|
|
if( eolexist == FALSE)
|
|
|
|
mlerase() ; /* ends with movecursor( term.t_nrow, 0) and TTflush() */
|
|
|
|
else
|
|
|
|
movecursor( term.t_nrow, 0) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-13 02:33:21 -05:00
|
|
|
mpresf = *fmt ? TRUE : FALSE ; /* flag if line has content or not */
|
2005-09-30 19:34:11 -04:00
|
|
|
va_start(ap, fmt);
|
2005-05-31 11:50:56 -04:00
|
|
|
while ((c = *fmt++) != 0) {
|
2015-01-22 07:26:22 -05:00
|
|
|
if (c != '%')
|
|
|
|
mlputc( c) ;
|
|
|
|
else {
|
2005-05-31 11:50:56 -04:00
|
|
|
c = *fmt++;
|
|
|
|
switch (c) {
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'd':
|
2005-09-30 19:34:11 -04:00
|
|
|
mlputi(va_arg(ap, int), 10);
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'o':
|
2005-09-30 19:34:11 -04:00
|
|
|
mlputi(va_arg(ap, int), 8);
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'x':
|
2005-09-30 19:34:11 -04:00
|
|
|
mlputi(va_arg(ap, int), 16);
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'D':
|
2005-09-30 19:34:11 -04:00
|
|
|
mlputli(va_arg(ap, long), 10);
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
case 's':
|
2015-02-12 00:15:45 -05:00
|
|
|
mlputs( (unsigned char *) va_arg( ap, char *)) ;
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'f':
|
2005-09-30 19:34:11 -04:00
|
|
|
mlputf(va_arg(ap, int));
|
2005-09-30 18:26:09 -04:00
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-21 01:12:24 -05:00
|
|
|
case 'B': /* ring a bell */
|
|
|
|
TTbeep() ;
|
|
|
|
break ;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
default:
|
2015-01-22 07:26:22 -05:00
|
|
|
mlputc( c) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-30 19:34:11 -04:00
|
|
|
va_end(ap);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if we can, erase to the end of screen */
|
2015-01-22 23:13:52 -05:00
|
|
|
if( eolexist == TRUE && ttcol < term.t_ncol)
|
|
|
|
TTeeol() ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
TTflush();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out a string. Update the physical cursor position. This assumes that
|
|
|
|
* the characters in the string all have width "1"; if this is not the case
|
|
|
|
* things will get screwed up a little.
|
|
|
|
*/
|
2015-02-12 00:15:45 -05:00
|
|
|
static void mlputs( unsigned char *s) {
|
|
|
|
unicode_t c ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
while( ((c = *s++) != 0) && (ttcol < term.t_ncol)) {
|
2015-02-12 00:15:45 -05:00
|
|
|
/* Accept UTF-8 sequence */
|
|
|
|
if( c > 0xC1 && c <= 0xF4) {
|
|
|
|
char utf[ 4] ;
|
|
|
|
char cc ;
|
|
|
|
int bytes ;
|
|
|
|
|
|
|
|
utf[ 0] = c ;
|
|
|
|
utf[ 1] = cc = *s ;
|
|
|
|
if( (c & 0x20) && ((cc & 0xC0) == 0x80)) { /* at least 3 bytes and a valid encoded char */
|
|
|
|
utf[ 2] = cc = s[ 1] ;
|
|
|
|
if( (c & 0x10) && ((cc & 0xC0) == 0x80)) /* at least 4 bytes and a valid encoded char */
|
|
|
|
utf[ 3] = s[ 2] ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) &c) ;
|
|
|
|
s += bytes - 1 ;
|
|
|
|
}
|
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
TTputc( c) ;
|
|
|
|
++ttcol ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out an integer, in the specified radix. Update the physical cursor
|
|
|
|
* position.
|
|
|
|
*/
|
2015-01-22 07:26:22 -05:00
|
|
|
static void mlputi( int i, int r) {
|
|
|
|
int q ;
|
2015-02-09 06:27:49 -05:00
|
|
|
unsigned u ;
|
2015-01-22 07:26:22 -05:00
|
|
|
static char hexdigits[] = "0123456789ABCDEF" ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-09 06:27:49 -05:00
|
|
|
if( r == 16 || i >= 0)
|
|
|
|
u = i ;
|
|
|
|
else {
|
|
|
|
u = -i ;
|
2015-01-22 07:26:22 -05:00
|
|
|
mlputc( '-') ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-09 06:27:49 -05:00
|
|
|
q = u / r ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
if( q != 0)
|
|
|
|
mlputi( q, r) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-09 06:27:49 -05:00
|
|
|
mlputc( hexdigits[ u % r]) ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* do the same except as a long integer.
|
|
|
|
*/
|
2015-01-22 07:26:22 -05:00
|
|
|
static void mlputli( long l, int r) {
|
|
|
|
long q ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
if( l < 0) {
|
|
|
|
l = -l ;
|
|
|
|
mlputc( '-') ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
q = l / r ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
if( q != 0)
|
|
|
|
mlputli( q, r) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-22 07:26:22 -05:00
|
|
|
mlputc( (int) (l % r) + '0') ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/*
|
2005-09-30 19:34:11 -04:00
|
|
|
* write out a scaled integer with two decimal places
|
|
|
|
*
|
|
|
|
* int s; scaled integer to output
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2015-01-22 07:26:22 -05:00
|
|
|
static void mlputf( int s) {
|
|
|
|
int i ; /* integer portion of number */
|
|
|
|
int f ; /* fractional portion of number */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* break it up */
|
2015-01-22 07:26:22 -05:00
|
|
|
i = s / 100 ;
|
|
|
|
f = s % 100 ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* send out the integer portion */
|
2015-01-22 07:26:22 -05:00
|
|
|
mlputi( i, 10) ;
|
|
|
|
mlputc('.') ;
|
|
|
|
mlputc((f / 10) + '0') ;
|
|
|
|
mlputc((f % 10) + '0') ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if RAINBOW
|
|
|
|
|
2006-11-19 14:22:04 -05:00
|
|
|
static void putline(int row, int col, char *buf)
|
2005-09-30 18:26:09 -04:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = strlen(buf);
|
|
|
|
if (col + n - 1 > term.t_ncol)
|
|
|
|
n = term.t_ncol - col + 1;
|
|
|
|
Put_Data(row, col, n, buf);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get terminal size from system.
|
|
|
|
Store number of lines into *heightp and width into *widthp.
|
|
|
|
If zero or a negative number is stored, the value is not valid. */
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
void getscreensize(int *widthp, int *heightp)
|
2005-09-30 18:26:09 -04:00
|
|
|
{
|
2005-05-31 11:50:56 -04:00
|
|
|
#ifdef TIOCGWINSZ
|
2005-09-30 18:26:09 -04:00
|
|
|
struct winsize size;
|
|
|
|
*widthp = 0;
|
|
|
|
*heightp = 0;
|
|
|
|
if (ioctl(0, TIOCGWINSZ, &size) < 0)
|
|
|
|
return;
|
|
|
|
*widthp = size.ws_col;
|
|
|
|
*heightp = size.ws_row;
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
*widthp = 0;
|
|
|
|
*heightp = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
#ifdef SIGWINCH
|
2005-09-30 19:34:11 -04:00
|
|
|
void sizesignal(int signr)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
int w, h;
|
|
|
|
int old_errno = errno;
|
|
|
|
|
|
|
|
getscreensize(&w, &h);
|
|
|
|
|
2015-01-02 07:26:34 -05:00
|
|
|
if( h > 0 && w > 0) {
|
|
|
|
term.t_mrow = h = h < MAXROW ? h : MAXROW ;
|
|
|
|
term.t_mcol = w = w < MAXCOL ? w : MAXCOL ;
|
2015-01-02 04:50:31 -05:00
|
|
|
if( h - 1 != term.t_nrow || w != term.t_ncol)
|
|
|
|
newscreensize( h, w) ;
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
signal(SIGWINCH, sizesignal);
|
|
|
|
errno = old_errno;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2006-11-19 14:22:04 -05:00
|
|
|
static int newscreensize(int h, int w)
|
2005-09-30 18:26:09 -04:00
|
|
|
{
|
|
|
|
/* do the change later */
|
|
|
|
if (displaying) {
|
|
|
|
chg_width = w;
|
|
|
|
chg_height = h;
|
2005-09-30 19:34:11 -04:00
|
|
|
return FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
|
|
|
chg_width = chg_height = 0;
|
2015-01-02 04:50:31 -05:00
|
|
|
if( h <= term.t_mrow)
|
2005-09-30 18:26:09 -04:00
|
|
|
newsize(TRUE, h);
|
2015-01-02 04:50:31 -05:00
|
|
|
if( w <= term.t_mcol)
|
2005-09-30 18:26:09 -04:00
|
|
|
newwidth(TRUE, w);
|
|
|
|
|
|
|
|
update(TRUE);
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#endif
|