/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1981 Regents of the University of California */
#include "ex.h"
#include "ex_tune.h"
#include "ex_tty.h"
#include "ex_vis.h"
/*
* Routines to deal with management of logical versus physical
* display, opening and redisplaying lines on the screen, and
* use of intelligent terminal operations. Routines to deal with
* screen cleanup after a change.
*/
/*
* Display a new line at physical line p, returning
* the depth of the newly displayed line. We may decide
* to expand the window on an intelligent terminal if it is
* less than a full screen by deleting a line above the top of the
* window before doing an insert line to keep all the good text
* on the screen in which case the line may actually end up
* somewhere other than line p.
*/
void
{
int cnt;
#ifdef ADEBUG
#endif
if (vcnt)
vup1();
else
vclean();
/*
* Forget all that we once knew.
*/
}
vcnt++;
/*
* Dirtying all the lines is rather inefficient
* internally, but number mode is used rarely
* and so it's not worth optimizing.
*/
/*
* If we are opening at the top of the window, can try a window
* expansion at the top.
*/
if (cnt > 0) {
p -= cnt;
if (p < ZERO)
p = ZERO;
WTOP = p;
}
}
}
/*
* Redisplay logical line l at physical line p with line number lineno.
*/
int
{
int d;
/*
* Try to win by making the screen larger rather than inserting
* a line and driving text off the bottom.
*/
p = vglitchup(l, 0);
/*
* BUG: Should consider using clr_eol here to clear to end of line.
* As it stands we always strike over the current text.
* Since often the current text is the same as what
* we are overstriking with, it tends not to show.
* On the other hand if it is different and we end up
* spacing out a lot of text, we could have won with
* a clr_eol. This is probably worthwhile at low speed
* only however, since clearly computation will be
* necessary to determine which way to go.
*/
vigoto(p, 0);
vscrap();
return (d);
}
/*
* When we are typing part of a line for hardcopy open, don't
* want to type the '$' marking an end of line if in list mode.
*/
return (d);
putchar('$');
/*
* Optimization of cursor motion may prevent screen rollup if the
* on the last line segment.
*/
vcsync();
/*
* Switch into hardcopy open mode if we are in one line (adm3)
* open mode and this line is now too long. If in hardcopy
* open mode, then call sethard to move onto the next line
* with appropriate positioning.
*/
if (vdepth() > 1) {
sethard();
} else
sethard();
/*
* Unless we filled (completely) the last line we typed on,
* we have to clear to the end of the line
* in case stuff is left from before.
*/
vclreol();
}
return (d);
}
/*
* Real work for winning growing of window at top
* when inserting in the middle of a partially full
* screen on an intelligent terminal. We have as argument
* the logical line number to be inserted after, and the offset
* from that line where the insert will go.
* We look at the picture of depths and positions, and if we can
* delete some (blank) lines from the top of the screen so that
* later inserts will not push stuff off the bottom.
*/
int
vglitchup(int l, int o)
{
int need;
bool glitched = 0;
if (l < vcnt - 1) {
if (need > 0) {
glitched++;
p -= need;
if (p + o == WTOP) {
return (WTOP + o);
}
}
if (glitched) {
}
}
} else
return (p + o);
}
/*
* Insert cnt blank lines before line p,
* logically and (if supported) physically.
*/
void
{
int i;
#ifdef ADEBUG
if (trace)
#endif
/*
* Really quick -- clear to end of screen.
*/
vclrech(1);
/*
* Use reverse scroll mode of the terminal, at
* the top of the window. Reverse linefeed works
* too, since we only use it from line WTOP.
*/
for (i = cnt; i > 0; i--) {
putchar('@');
/*
* If we are at the top of the screen, and the
* terminal retains display above, then we
* should try to clear to end of line.
* Have to use clr_eol since we don't remember what is
* actually on the line.
*/
if (clr_eol && (memory_above || p != 0))
}
} else if (insert_line) {
/*
* Use insert line.
*/
vgoto(p, 0);
/* insert cnt lines. Should do @'s too. */
}
else if (change_scroll_region && *insert_line==0) {
/* vt100 change scrolling region to fake insert_line */
for (i=cnt; i>0; i--)
}
else {
for (i = cnt - 1; i > 0; i--) {
putchar('@');
}
}
} else
could = 0;
}
/*
* Logically open up after line l, cnt of them.
* We need to know if it was done ``physically'' since in this
* case we accept what the hardware gives us. If we have to do
* it ourselves (brute force) we will squish out @ lines in the process
* if this will save us work.
*/
void
{
#ifdef ADEBUG
if (trace)
#endif
if (could)
/*
* This will push @ lines down the screen,
* just as the hardware did. Since the default
* for intelligent terminals is to never have @
* lines on the screen, this should never happen,
* and the code makes no special effort to be nice in this
* case, e.g. squishing out the @ lines by delete lines
* before doing append lines.
*/
else {
/*
* Will have to clean up brute force eventually,
* so push the line data around as little as possible.
*/
vc++;
break;
}
}
vscrap();
}
/*
* Adjust data structure internally to account for insertion of
* blank lines on the screen.
*/
void
{
#ifdef ADEBUG
if (trace)
#endif
}
/*
* Have to clear the echo area since its contents aren't
* necessarily consistent with the rest of the display.
*/
vclrech(0);
}
/*
* Roll the screen up logically and physically
* so that line dl is the bottom line on the screen.
*/
void
{
int cnt;
#ifdef ADEBUG
if (trace)
#endif
holdupd = 1;
}
void
vup1(void)
{
}
/*
* Scroll the screen up cnt lines physically.
* If doclr is true, do a clear eol if the terminal
* has standout (to prevent it from scrolling up)
*/
void
{
if (cnt == 0)
return;
#ifdef ADEBUG
if (trace)
#endif
if (doclr)
vclrech(0);
if (scroll_forward) {
fgoto();
while (cnt > 0)
}
else {
fgoto();
}
}
/* Get rid of line we just rolled up */
vclrech(0);
}
/*
* Scroll the screen up cnt lines logically.
*/
void
{
#ifdef ADEBUG
if (trace)
#endif
if (cnt == 0)
return;
}
}
/*
* Discard logical lines due to physical wandering off the screen.
*/
void
vscrap(void)
{
int i, j;
#ifdef ADEBUG
if (trace)
#endif
if (splitw)
return;
}
for (j = 0; j < vcnt; j++)
if (j == 0)
break;
/*
* Discard the first j physical lines off the top.
*/
for (i = 0; i <= vcnt; i++)
break;
}
/*
* Discard lines off the bottom.
*/
if (vcnt) {
for (j = 0; j <= vcnt; j++)
vcnt = j;
break;
}
if (vcnt == 0)
LASTLINE = 0;
else
}
#ifdef ADEBUG
if (trace)
tvliny();
#endif
/*
* May have no lines!
*/
}
/*
* Repaint the screen, with cursor at curs, aftern an arbitrary change.
* Handle notification on large changes.
*/
void
{
/*
* In open want to notify first.
*/
noteit(0);
vscrap();
/*
* Deal with a totally useless display.
*/
vcnt = 0;
if (holdupd)
(void)peekkey();
else
vup1();
holdupd = 0;
fixzero();
noteit(1);
linebuf[0] = 0;
splitw = 0;
}
return;
}
/*
* Have some useful displayed text; refresh it.
*/
getDOT();
/*
* This is for boundary conditions in open mode.
*/
/*
* If the current line is after the last displayed line
* or the bottom of the screen, then special effort is needed
* to get it on the screen. We first try a redraw at the
* last line on the screen, hoping it will fill in where @
* lines are now. If this doesn't work, then roll it onto
* the screen.
*/
dot -= i;
vcline -= i;
vroll(i);
} else
vsyncCL();
} else
/*
* Notification on large change for visual
* has to be done last or we may lose
* the echo area with redisplay.
*/
noteit(1);
/*
* Finally. Move the cursor onto the current line.
*/
}
/*
* Fully cleanup the screen, leaving no @ lines except at end when
* line after last won't completely fit. The routine vsync is
* more conservative and much less work on dumb terminals.
*/
void
vredraw(int p)
{
int l;
bool anydl = 0;
#ifdef ADEBUG
if (trace)
#endif
if (holdupd) {
holdupd = 3;
return;
}
return;
if (p < 0 /* || p > WECHO */)
/*
* Trim the ragged edges (lines which are off the screen but
* not yet logically discarded), save the current line, and
* search for first logical line affected by the redraw.
*/
vscrap();
l = 0;
if (vcnt == 0)
l++, tp++;
/*
* We hold off echo area clearing during the redraw in deference
* to a final clear of the echo area at the end if appropriate.
*/
heldech = 0;
if (l == vcline)
else
/*
* Delete junk between displayed lines.
*/
vclrech(0);
anydl = 1;
heldech = 0;
}
}
/*
* If line image is not know to be up to date, then
* redisplay it; else just skip onward.
*/
LINE(l) = p;
vscrap();
break;
}
} else
p += DEPTH(l);
tp++;
}
/*
* That takes care of lines which were already partially displayed.
* Now try to fill the rest of the screen with text.
*/
vcline = l;
break;
vcline++;
}
}
/*
* That's all the text we can get on.
* Now rest of lines (if any) get either a ~ if they
* are past end of file, or an @ if the next line won't fit.
*/
if (heldech)
vclrech(0);
#ifdef ADEBUG
if (trace)
tvliny();
#endif
}
/*
* Do the real work in deleting cnt lines starting at line p from
* the display. First affected line is line l.
*/
void
{
int i;
if (cnt == 0)
return;
/*
* Can't do it; just remember that line l is munged.
*/
return;
}
#ifdef ADEBUG
if (trace)
#endif
/*
* Send the deletes to the screen and then adjust logical
* and physical internal data structures.
*/
vgoto(p, 0);
}
else if (change_scroll_region && *delete_line==0) {
/* vt100: fake delete_line by changing scrolling region */
for (i=0; i<cnt; i++) /* .. and scroll cnt times */
}
else {
for (i = 0; i < cnt; i++)
}
}
/*
* Adjust internal physical screen image to account for deleted lines.
*/
void
{
#ifdef ADEBUG
if (trace)
#endif
/*
* Would like to use structured assignment but early
* v7 compiler (released with phototypesetter for v6)
* can't hack it.
*/
}
}
/*
* Sync the screen, like redraw but more lazy and willing to leave
* @ lines on the screen. VsyncCL syncs starting at the current line.
* In any case, if the redraw option is set then all syncs map to redraws
* as if vsync didn't exist.
*/
void
vsyncCL(void)
{
}
void
vsync(int p)
{
vredraw(p);
else
vsync1(p);
}
/*
* The guts of a sync. Similar to redraw but
* just less ambitious.
*/
void
vsync1(int p)
{
int l;
#ifdef ADEBUG
if (trace)
#endif
if (holdupd) {
if (holdupd < 3)
holdupd = 2;
return;
}
return;
vscrap();
if (vcnt == 0)
l = 0;
l++, vp++;
heldech = 0;
/*
* Want to put a line here if not in visual and first line
* or if there are lies left and this line starts before
* the current line, or if this line is piled under the
* next line (vreplace does this and we undo it).
*/
if (l == vcline)
else
/*
* Be careful that a long line doesn't cause the
* screen to shoot up.
*/
break;
}
}
vp++;
l++;
} else
/*
* A physical line between logical lines,
* so we settle for an @ at the beginning.
*/
}
if (heldech)
vclrech(0);
}
/*
* Subtract (logically) cnt physical lines from the
* displayed position of lines starting with line l.
*/
void
{
int i;
#ifdef ADEBUG
if (trace)
#endif
for (i = l + 1; i <= vcnt; i++)
}
/*
* Workhorse for rearranging line descriptors on changes.
* The idea here is that, starting with line l, cnt lines
* have been replaced with newcnt lines. All of these may
* be ridiculous, i.e. l may be -1000, cnt 50 and newcnt 0,
* since we may be called from an undo after the screen has
* moved a lot. Thus we have to be careful.
*
* Many boundary conditions here.
*/
void
{
bool savenote = 0;
#ifdef ADEBUG
if (trace) {
tvliny();
}
#endif
if (l >= vcnt)
return;
if (l < 0) {
if (l + cnt < 0) {
/*
* Nothing on the screen is relevant.
* Settle for redrawing from scratch (later).
*/
vcnt = 0;
return;
}
/*
* Normalize l to top of screen; the add is
* really a subtract from cnt since l is negative.
*/
cnt += l;
l = 0;
/*
* Unseen lines were affected so notify (later).
*/
savenote++;
}
/*
* These shouldn't happen
* but would cause great havoc.
*/
if (cnt < 0)
cnt = 0;
if (newcnt < 0)
newcnt = 0;
/*
* Surely worthy of note if more than report
* lines were changed.
*/
savenote++;
/*
* Same number of lines affected as on screen, and we
* can insert and delete lines. Thus we just type
* over them, since otherwise we will push them
* slowly off the screen, a clear lose.
*/
savenote++;
} else {
/*
* Lines are going away, squish them out.
*/
if (cnt > 0) {
/*
* If non-displayed lines went away,
* always notify.
*/
savenote++;
else
}
/*
* Open up space for new lines appearing.
* All new lines are piled in the same place,
* inserts lines in front as it unpiles.
*/
if (newcnt > 0) {
/*
* Newlines are appearing which may not show,
* so notify (this is only approximately correct
* when long lines are present).
*/
savenote++;
/*
* If there will be more lines than fit, then
* just throw way the rest of the stuff on the screen.
*/
vcnt = l;
goto skip;
}
if (i < 0)
}
}
}
skip:
/*
* When lines positions are shifted, the numbers
* will be wrong.
*/
if (!savenote)
notecnt = 0;
#ifdef ADEBUG
if (trace)
tvliny();
#endif
}
/*
* Start harcopy open.
* Print an image of the line to the left of the cursor
* under the full print of the line and position the cursor.
* If we are in a scroll ^D within hardcopy open then all this
* is suppressed.
*/
void
sethard(void)
{
return;
rubble = 0;
return;
vup1();
}
/*
* Mark the lines starting at base for i lines
* as dirty so that they will be checked for correct
*/
void
{
int l;
if (--i < 0)
return;
}
}