/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1995-1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* LINTLIBRARY */
/*
*
* XCurses Library
*
* Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
*
*/
#ifdef M_RCSID
#ifndef lint
static char const rcsID[] =
"$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
"libxcurses/src/libc/xcurses/rcs/doupdate.c 1.22 1998/06/04 12:13:38 "
"cbates Exp $";
#endif
#endif
#include <sys/isa_defs.h>
#include <private.h>
#include <string.h>
#include <signal.h>
/*
* This value is the ideal length for the cursor addressing sequence
* being four bytes long, ie. "<escape><cursor addressing code><row><col>".
* eg. VT52 - "\EYrc" or ADM3A - "\E=rc"
*/
/*
* This value is the ideal length for the clear-to-eol sequence
* being two bytes long, ie "<escape><clear eol code>".
*/
typedef struct cost_op {
short cost;
short op;
} lcost;
typedef void (*t_action)(int, int);
#if defined(_LP64)
#else
#endif
static void erase_bottom(int, int);
static void clear_bottom(int);
static void complex(void);
static int cost(int, int);
static void lines_delete(int, int);
static void lines_insert(int, int);
static void lines_replace(int, int);
static void script(int, int);
static int scroll_up(int);
static void simple(void);
static void text_replace(int);
#if 0
static int scroll_dn(int);
#endif
/*
* Wrapper that streams Curses output.
*
* All escape sequences going to the screen come through here.
* All ordinary characters go to the screen via the putc in doupdate.c
*/
int
{
}
/*
* Allocate or grow doupdate() structures.
*/
int
__m_doupdate_init(void)
{
void *new;
static short nlines = 0;
if (lines <= 0)
return (-1);
return (0);
return (-1);
return (-1);
return (-1);
#if defined(_LP64)
#else
#endif
return (0);
}
static void
{
int i;
}
}
/*
* Clear from the start of the current row to bottom of screen.
*/
static void
clear_bottom(int y)
{
/* Restore default color pair before doing area clears. */
if (back_color_erase)
if (y == 0 && clear_screen != NULL) {
} else {
for (;;) {
if (LINES <= y)
break;
++y;
}
}
}
}
/*
* Rewrite of text_replace() implementation by C. Bates of MKS
*
* This code creates a list of 'regions' for each test line which
* is to be replaced. Each region describes a portion of the line.
* Logic is performed on the list of regions, then the regions
* are used to generate output.
*/
typedef struct LineRegion {
/* 0: Difference Region, 1: Common Region, 2: Delete Region */
int type;
} LineRegion;
#define REGION_DIFFERENT 0
int nRegions = 0;
/*
* Return the first column of the completely blank End-of-line
*/
static int
{
if (!clr_eol)
return (COLS);
/*
* Find start of blank tail region.
*/
break;
}
return (tail);
}
/*
* Send all the characters in the region to the terminal
*/
static void
{
short npair;
int i;
/*
* Change attribute state.
*/
}
/*
* Don't display internal characters.
*/
(void) __m_cc_write(nptr);
/*
* Update copy of screen image.
*/
}
}
/*
* Delete some characters from the terminal for this region
*/
static void
{
int i;
} else {
}
/*
* Delete the chars in the image of the real screen
*/
optr++;
}
}
/*
* Use clr_eol control if possible
*/
static void
{
/*
* Restore default color pair before area clear.
*/
if (back_color_erase)
}
}
/*
* Delete leading common region
*/
static void
_normalizeRegions1(void)
{
int iRegion;
/*
* Delete leading common region
*/
nRegions--;
}
}
}
/*
* Give each region a size, then delete all trailing common regions
*/
static void
_normalizeRegions2(void)
{
int iRegion;
}
/*
* Delete trailing common regions
*/
nRegions--;
}
/*
* Tiny common regions are merged into adjacent difference regions
*/
static void
_mergeTinyRegions(void)
{
int from;
int to;
/*
* Merge out tiny common regions
*/
/*
* Now join adjacent non-common regions
*/
} else {
}
}
}
/*
* Create the initial list of regions for this row
*/
static int
{
int cmp;
int old_cmp;
int col;
int bestDeleteCount;
col = 0;
nRegions = 0;
bestDeleteCount = 0;
(parm_dch || delete_character)) {
int bestFit = 0;
int deletePoint;
int deleteCount;
int matches;
/*
* Skip to first difference
*/
break;
}
deletePoint = col;
deleteCount++) {
matches = 0;
col++) {
matches++;
else
break;
}
}
}
if (bestFit > DELETE_THRESHOLD) {
nRegions++;
} else {
col = 0;
nRegions = 0;
/* Forget trying to use character delete */
bestDeleteCount = 0;
}
}
nRegions++;
}
}
if (bestDeleteCount) {
/*
* Force update of end-of-line if delete is to be used
*/
nRegions++;
}
if (nRegions == 0)
return (0); /* No difference regions */
return (1);
}
/*
* Determine if Clr-EOL optimization can be used, and
* adjust regions accordingly
*/
static int
{
int iRegion;
case REGION_DIFFERENT:
/*
* Delete this and all following regions
*/
return (blankEolStart);
}
/*
* Truncate this region to end
* where blank EOL starts
*/
/*
* Delete all following regions
*/
return (blankEolStart);
}
break;
case REGION_COMMON:
break;
case REGION_DELETE: /* Scrap the whole thing */
return (COLS);
}
}
return (COLS); /* Couldn't use Clear EOL optimization */
}
/*
* Generate output, based on region list
*/
static void
{
int ceolStart;
int iRegion;
/*
* regions are guaranteed to start with a non-common region.
* tiny common regions have also been merged into
* bracketting common-regions.
*/
if (nRegions) {
case REGION_COMMON:
break;
case REGION_DELETE:
/*
* Start of non-common region
*/
break;
case REGION_DIFFERENT:
/*
* Star of non-common region
*/
break;
}
}
}
}
}
/*
* The new text_replace algorithm, which uses regions
*/
static void
{
if (!_findRegions(row))
return;
/*
* Line wrapping checks.
*/
if (eat_newline_glitch) {
(void) __m_outc('\r');
(void) __m_outc('\n');
}
}
}
}
/*
* Replace a block of lines.
* Only ever used for complex().
*/
static void
{
}
/*
* Delete a block of lines.
* Only ever used for complex().
*/
static void
{
} else {
if (parm_delete_line != NULL) {
/*
* Assume that the sequence to delete more than one
* line is faster than repeated single delete_lines.
*/
} else if (delete_line != NULL) {
} else {
/* Error -- what to do. */
return;
}
}
}
/*
* Insert a block of lines.
* Only ever used for complex().
*
* We must assume that insert_line and parm_insert_line reset the
* cursor column to zero. Therefore it is text_replace() responsiblity
* to move the cursor to the correct column to begin the update.
*/
static void
{
int row;
/*
* Position the cursor and insert a block of lines into the screen
* image now, insert lines into the physical screen, then draw the
* new screen lines.
*/
if (parm_insert_line != NULL) {
/*
* Assume that the sequence to insert more than one line is
* faster than repeated single insert_lines.
*/
} else if (insert_line != NULL) {
/*
* For the single line insert we use to iterate moving
* the cursor, inserting, and then drawing a line. That
* would appear to be slow but visually appealing. However,
* people on slow terminals want speed and those on fast
* terminal won't see it.
*/
} else {
/* Error -- what to do. */
return;
}
}
static int
scroll_up(int n)
{
int count = n;
if (scroll_forward != NULL) {
while (0 < n--)
GOTO(0, 0);
0, 0, 0, 0, 0, 0, 0, 0), n, __m_outc);
} else if (delete_line != NULL) {
GOTO(0, 0);
while (0 < n--)
} else {
return (0);
}
/* Scroll recorded image. */
start = 0;
simple();
return (1);
}
#if 0
static int
scroll_dn(int n)
{
int count = n;
if (LINES < n)
return (0);
if (scroll_reverse != NULL) {
GOTO(0, 0);
while (0 < n--)
GOTO(0, 0);
0, 0, 0, 0, 0, 0, 0, 0), n, __m_outc);
} else if (insert_line != NULL) {
GOTO(0, 0);
while (0 < n--)
} else {
return (0);
}
/* Scroll recorded image. */
to = 0;
simple();
return (1);
}
#endif
/*
* Dynamic programming algorithm for the string edit problem.
*
* This is a modified Gosling cost algorithm that takes into account
*
* Costs for move, delete, replace, and insert are 0, 1, 2, and 3
* repectively.
*/
#define MOVE_COST 0
static int
{
#if defined(_LP64)
#else
#endif
/*
* Prepare initial row and column of cost matrix.
*
* 0 3 6 9 ...
* 1
* 2
* 3
* :
*/
/* Top row is 3, 6, 9, ... */
/* Left column is 1, 2, 3, ... */
}
/* Assume move op. */
/* Lines are different, assume replace op. */
}
/* Compare insert op. */
}
/* Compare delete op. */
}
}
}
}
/*
* Build edit script.
*
* Normally this would be a recursve routine doing the deletes, inserts,
* and replaces on individual lines. Instead we build the script so that
* we can later do the operations on a block basis. For terminals with
* parm_delete or parm_insert strings this will be better in terms of the
* number of characters sent to delete and insert a block of lines.
*
* Also we can optimize the script so that tail inserts become replaces.
* This saves unnecessary inserts operations when the tail can just be
* overwritten.
*/
static void
{
int i, j;
i = j = lr + 1;
do {
/*
* We don't have to bounds check i or j becuase row fr and
* column fr of lc have been preset in order to guarantee the
* correct motion.
*/
case 'i':
--j;
ins_rep[j] = lines_insert;
break;
case 'd':
--i;
del[i] = lines_delete;
break;
case 'm':
--i;
--j;
break;
case 'r':
--i;
--j;
ins_rep[j] = lines_replace;
break;
}
/* Optimize Tail Inserts */
/* Make each character in the screen line image invalid. */
ins_rep[i] = lines_replace;
}
}
/*
*
* References:
* [MyM86] E.W. Myers & W. Miller, Row Replacement Algorithms for
* Screen Editors, TR 86-19, Dept. Computer Science, U. of Arizona
* [MyM87] E.W. Myers & W. Miller, A Simple Row Replacement Method,
* TR 86-28, Dept. Computer Science, U. of Arizona
* [Mil87] W. Miller, A Software Tools Sampler, Prentice-Hall, 1987
* [Gos81] James Gosling, A redisplay algorithm, Proceedings of the
* ACM Symposium on Text Manipulation, SIGPLAN Notices,
* 16(6) June 1981, pg 123-129
*
* All the above were reviewed and experimented with. Due to the nature of
* Curses' having to handling overlapping WINDOWs, the only suitable
* algorithum is [Gos81]. The others are better suited to editor type
* applications that have one window being the entire terminal screen.
*
*/
static void
complex(void)
{
int i, j, lr;
/* Find block of lines to change */
for (i = 0; i < LINES; ++i) {
/* Compute new hash. */
if (fr == -1)
fr = i;
lr = i;
} else {
/* Line not dirty so hash same as before. */
}
}
if (fr != -1) {
/* Gosling */
/* Do deletes first in reverse order. */
for (i = j-1; fr <= i; --i)
break;
j = i;
}
}
/* Find size of block */
;
(*func)(i, j);
i = j - 1;
}
}
/*
* _line[], which contains pointers to screen lines,
* may be shuffled.
*/
/* Save new hash for next update. */
/* Mark line as untouched. */
}
}
}
/*
* Simple screen update algorithm
*
* We perform a simple incremental update of the terminal screen.
* Only the segment of a line that was touched is replaced on the
* line.
*/
static void
simple(void)
{
int row;
/* Mark line as untouched. */
}
}
}
void
{
int last;
for (; (y < w->_maxy) && (0 < n); ++y, --n) {
/*
* Force compare in doupdate to fail.
* Touch should be unconditional
*/
}
}
/*
* Send all changes made to _newscr to the physical terminal.
*
* If idlok() is set TRUE then doupdate will try and use hardware insert
* and delete line sequences in an effort to optimize output. idlok()
* should really only be used in applications that want a proper scrolling
* effect.
*
* Added scroll heuristic to handle special case where a full size window
* with full size scroll region, will scroll the window and replace dirty
*/
int
doupdate(void)
{
#ifdef SIGTSTP
#endif
if (pollTypeahead()) {
return (OK);
}
/* Return from temporary escape done with endwin(). */
(void) reset_prog_mode();
if (enter_ca_mode != NULL)
if (keypad_xmit != NULL)
/* Force redraw of screen. */
}
/*
* When redrawwing a window, we not only assume that line
* noise may have lost characters, but line noise may have
* generated bogus characters on the screen outside the
* the window in question, in which case redraw the entire
* screen to be sure.
*/
clear_bottom(0);
}
/*
* Scrolling heuristic should only be used if lines being
* scrolled are clean because scrolling overrides updates
*
* Right now, the following code should always turn off
* scrolling, because the internal scroll touches the
* scrolled lines. This thing requires a lot more care
* than I have right now...
*/
int y;
}
}
}
simple();
} else {
complex();
} else {
simple();
}
} else {
complex();
} else {
simple();
}
}
}
}
}
}
/* Send labels to terminal that supports them. */
#ifdef SIGTSTP
#endif
return (OK);
}
/*
* If true, the implementation may use hardware insert and delete,
* character features of the terminal. The window parameter
* is ignored.
*/
/* ARGSUSED */
void
{
if (bf)
}
/*
* If true, the implementation may use hardware insert, delete,
* and scroll line features of the terminal. The window parameter
* is ignored.
*/
/* ARGSUSED */
int
{
return (OK);
}
/*
* Use the POSIX 32-bit CRC function to compute a hash value
* for the window line.
*/
void
#if defined(_LP64)
#else
#endif
{
array[y] = 0;
}