1997-10-14 04:41:15 +04:00
|
|
|
/* $NetBSD: fancy.c,v 1.6 1997/10/14 00:41:20 lukem Exp $ */
|
1995-03-21 18:03:38 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-03-21 18:03:38 +03:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-21 18:03:38 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
1997-10-14 04:41:15 +04:00
|
|
|
__RCSID("$NetBSD: fancy.c,v 1.6 1997/10/14 00:41:20 lukem Exp $");
|
1995-03-21 18:03:38 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "back.h"
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
char PC; /* padding character */
|
|
|
|
char *BC; /* backspace sequence */
|
|
|
|
char *CD; /* clear to end of screen sequence */
|
|
|
|
char *CE; /* clear to end of line sequence */
|
|
|
|
char *CL; /* clear screen sequence */
|
|
|
|
char *CM; /* cursor movement instructions */
|
|
|
|
char *HO; /* home cursor sequence */
|
|
|
|
char *MC; /* column cursor movement map */
|
|
|
|
char *ML; /* row cursor movement map */
|
|
|
|
char *ND; /* forward cursor sequence */
|
|
|
|
char *UP; /* up cursor sequence */
|
|
|
|
|
|
|
|
int lHO; /* length of HO */
|
|
|
|
int lBC; /* length of BC */
|
|
|
|
int lND; /* length of ND */
|
|
|
|
int lUP; /* length of UP */
|
|
|
|
int CO; /* number of columns */
|
|
|
|
int LI; /* number of lines */
|
|
|
|
int *linect; /* array of lengths of lines on screen (the
|
|
|
|
* actual screen is not stored) */
|
|
|
|
|
|
|
|
/* two letter codes */
|
|
|
|
char tcap[] = "bccdceclcmhomcmlndup";
|
|
|
|
/* corresponding strings */
|
|
|
|
char **tstr[] = {&BC, &CD, &CE, &CL, &CM, &HO, &MC, &ML, &ND, &UP};
|
|
|
|
|
|
|
|
int buffnum; /* pointer to output buffer */
|
|
|
|
|
|
|
|
char tbuf[1024]; /* buffer for decoded termcap entries */
|
|
|
|
|
|
|
|
int oldb[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
|
|
|
int oldr;
|
|
|
|
int oldw;
|
|
|
|
/* "real" cursor positions, so it knows when to reposition. These are -1 if
|
|
|
|
* curr and curc are accurate */
|
|
|
|
int realr;
|
|
|
|
int realc;
|
|
|
|
|
|
|
|
void
|
|
|
|
fboard()
|
|
|
|
{
|
|
|
|
int i, j, l;
|
|
|
|
|
|
|
|
curmove(0, 0); /* do top line */
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < 53; i++)
|
1997-10-10 12:59:32 +04:00
|
|
|
fancyc('_');
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(15, 0); /* do botttom line */
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < 53; i++)
|
1997-10-10 12:59:32 +04:00
|
|
|
fancyc('_');
|
|
|
|
|
|
|
|
l = 1; /* do vertical lines */
|
|
|
|
for (i = 52; i > -1; i -= 28) {
|
|
|
|
curmove((l == 1 ? 1 : 15), i);
|
|
|
|
fancyc('|');
|
|
|
|
for (j = 0; j < 14; j++) {
|
|
|
|
curmove(curr + l, curc - 1);
|
|
|
|
fancyc('|');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
if (i == 24)
|
|
|
|
i += 32;
|
1997-10-10 12:59:32 +04:00
|
|
|
l = -l; /* alternate directions */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(2, 1); /* label positions 13-18 */
|
|
|
|
for (i = 13; i < 18; i++) {
|
|
|
|
fancyc('1');
|
|
|
|
fancyc((i % 10) + '0');
|
|
|
|
curmove(curr, curc + 2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
fancyc('1');
|
|
|
|
fancyc('8');
|
|
|
|
|
|
|
|
curmove(2, 29); /* label positions 19-24 */
|
|
|
|
fancyc('1');
|
|
|
|
fancyc('9');
|
|
|
|
for (i = 20; i < 25; i++) {
|
|
|
|
curmove(curr, curc + 2);
|
|
|
|
fancyc('2');
|
|
|
|
fancyc((i % 10) + '0');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(14, 1); /* label positions 12-7 */
|
|
|
|
fancyc('1');
|
|
|
|
fancyc('2');
|
|
|
|
for (i = 11; i > 6; i--) {
|
|
|
|
curmove(curr, curc + 2);
|
|
|
|
fancyc(i > 9 ? '1' : ' ');
|
|
|
|
fancyc((i % 10) + '0');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(14, 30); /* label positions 6-1 */
|
|
|
|
fancyc('6');
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 5; i > 0; i--) {
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(curr, curc + 3);
|
|
|
|
fancyc(i + '0');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 12; i > 6; i--)/* print positions 12-7 */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (board[i])
|
1997-10-10 12:59:32 +04:00
|
|
|
bsect(board[i], 13, 1 + 4 * (12 - i), -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (board[0]) /* print red men on bar */
|
|
|
|
bsect(board[0], 13, 25, -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 6; i > 0; i--) /* print positions 6-1 */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (board[i])
|
1997-10-10 12:59:32 +04:00
|
|
|
bsect(board[i], 13, 29 + 4 * (6 - i), -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
l = (off[1] < 0 ? off[1] + 15 : off[1]); /* print white's home */
|
|
|
|
bsect(l, 3, 54, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(8, 25); /* print the word BAR */
|
|
|
|
fancyc('B');
|
|
|
|
fancyc('A');
|
|
|
|
fancyc('R');
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 13; i < 19; i++) /* print positions 13-18 */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (board[i])
|
1997-10-10 12:59:32 +04:00
|
|
|
bsect(board[i], 3, 1 + 4 * (i - 13), 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (board[25]) /* print white's men on bar */
|
|
|
|
bsect(board[25], 3, 25, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 19; i < 25; i++) /* print positions 19-24 */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (board[i])
|
1997-10-10 12:59:32 +04:00
|
|
|
bsect(board[i], 3, 29 + 4 * (i - 19), 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
l = (off[0] < 0 ? off[0] + 15 : off[0]); /* print red's home */
|
|
|
|
bsect(-l, 13, 54, -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 0; i < 26; i++)/* save board position for refresh later */
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[i] = board[i];
|
1997-10-10 12:59:32 +04:00
|
|
|
oldr = (off[1] < 0 ? off[1] + 15 : off[1]);
|
|
|
|
oldw = -(off[0] < 0 ? off[0] + 15 : off[0]);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* bsect (b,rpos,cpos,cnext)
|
|
|
|
* Print the contents of a board position. "b" has the value of the
|
|
|
|
* position, "rpos" is the row to start printing, "cpos" is the column to
|
|
|
|
* start printing, and "cnext" is positive if the position starts at the top
|
|
|
|
* and negative if it starts at the bottom. The value of "cpos" is checked
|
|
|
|
* to see if the position is a player's home, since those are printed
|
|
|
|
* differently.
|
|
|
|
*/
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
bsect(b, rpos, cpos, cnext)
|
|
|
|
int b; /* contents of position */
|
|
|
|
int rpos; /* row of position */
|
|
|
|
int cpos; /* column of position */
|
|
|
|
int cnext; /* direction of position */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int j; /* index */
|
|
|
|
int n; /* number of men on position */
|
|
|
|
int bct; /* counter */
|
|
|
|
int k; /* index */
|
|
|
|
char pc; /* color of men on position */
|
|
|
|
|
|
|
|
bct = 0;
|
|
|
|
n = abs(b); /* initialize n and pc */
|
|
|
|
pc = (b > 0 ? 'r' : 'w');
|
|
|
|
|
|
|
|
if (n < 6 && cpos < 54) /* position cursor at start */
|
|
|
|
curmove(rpos, cpos + 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(rpos, cpos);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (j = 0; j < 5; j++) { /* print position row by row */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (k = 0; k < 15; k += 5) /* print men */
|
|
|
|
if (n > j + k)
|
|
|
|
fancyc(pc);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (j < 4) { /* figure how far to back up for next row */
|
|
|
|
if (n < 6) { /* stop if none left */
|
|
|
|
if (j + 1 == n)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
bct = 1; /* single column */
|
|
|
|
} else {
|
|
|
|
if (n < 11) { /* two columns */
|
|
|
|
if (cpos == 54) { /* home pos */
|
|
|
|
if (j + 5 >= n)
|
1993-03-21 12:45:37 +03:00
|
|
|
bct = 1;
|
|
|
|
else
|
|
|
|
bct = 2;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (cpos < 54) { /* not home */
|
|
|
|
if (j + 6 >= n)
|
1993-03-21 12:45:37 +03:00
|
|
|
bct = 1;
|
|
|
|
else
|
|
|
|
bct = 2;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
} else { /* three columns */
|
|
|
|
if (j + 10 >= n)
|
1993-03-21 12:45:37 +03:00
|
|
|
bct = 2;
|
|
|
|
else
|
|
|
|
bct = 3;
|
|
|
|
}
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(curr + cnext, curc - bct); /* reposition cursor */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
refresh()
|
|
|
|
{
|
|
|
|
int i, r, c;
|
|
|
|
|
|
|
|
r = curr; /* save current position */
|
1993-03-21 12:45:37 +03:00
|
|
|
c = curc;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 12; i > 6; i--)/* fix positions 12-7 */
|
|
|
|
if (board[i] != oldb[i]) {
|
|
|
|
fixpos(oldb[i], board[i], 13, 1 + (12 - i) * 4, -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[i] = board[i];
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (board[0] != oldb[0]) { /* fix red men on bar */
|
|
|
|
fixpos(oldb[0], board[0], 13, 25, -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[0] = board[0];
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 6; i > 0; i--) /* fix positions 6-1 */
|
|
|
|
if (board[i] != oldb[i]) {
|
|
|
|
fixpos(oldb[i], board[i], 13, 29 + (6 - i) * 4, -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[i] = board[i];
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
i = -(off[0] < 0 ? off[0] + 15 : off[0]); /* fix white's home */
|
|
|
|
if (oldw != i) {
|
|
|
|
fixpos(oldw, i, 13, 54, -1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldw = i;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 13; i < 19; i++) /* fix positions 13-18 */
|
|
|
|
if (board[i] != oldb[i]) {
|
|
|
|
fixpos(oldb[i], board[i], 3, 1 + (i - 13) * 4, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[i] = board[i];
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (board[25] != oldb[25]) { /* fix white men on bar */
|
|
|
|
fixpos(oldb[25], board[25], 3, 25, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[25] = board[25];
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 19; i < 25; i++) /* fix positions 19-24 */
|
|
|
|
if (board[i] != oldb[i]) {
|
|
|
|
fixpos(oldb[i], board[i], 3, 29 + (i - 19) * 4, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldb[i] = board[i];
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
i = (off[1] < 0 ? off[1] + 15 : off[1]); /* fix red's home */
|
|
|
|
if (oldr != i) {
|
|
|
|
fixpos(oldr, i, 3, 54, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldr = i;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(r, c); /* return to saved position */
|
1993-03-21 12:45:37 +03:00
|
|
|
newpos();
|
|
|
|
buflush();
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
fixpos(old, new, r, c, inc)
|
|
|
|
int old, new, r, c, inc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int o, n, nv;
|
|
|
|
int ov, nc;
|
|
|
|
char col;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
nc = 0;
|
|
|
|
if (old * new >= 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ov = abs(old);
|
|
|
|
nv = abs(new);
|
1997-10-10 12:59:32 +04:00
|
|
|
col = (old + new > 0 ? 'r' : 'w');
|
|
|
|
o = (ov - 1) / 5;
|
|
|
|
n = (nv - 1) / 5;
|
|
|
|
if (o == n) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (o == 2)
|
1997-10-10 12:59:32 +04:00
|
|
|
nc = c + 2;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (o == 1)
|
1997-10-10 12:59:32 +04:00
|
|
|
nc = c < 54 ? c : c + 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (o == 0)
|
1997-10-10 12:59:32 +04:00
|
|
|
nc = c < 54 ? c + 1 : c;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (ov > nv)
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * (nv - n * 5), nc, abs(ov - nv), ' ', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * (ov - o * 5), nc, abs(ov - nv), col, inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1997-10-10 12:59:32 +04:00
|
|
|
} else {
|
|
|
|
if (c < 54) {
|
|
|
|
if (o + n == 1) {
|
|
|
|
if (n) {
|
|
|
|
fixcol(r, c, abs(nv - 5), col, inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (ov != 5)
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * ov, c + 1,
|
|
|
|
abs(ov - 5), col, inc);
|
|
|
|
} else {
|
|
|
|
fixcol(r, c, abs(ov - 5), ' ', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (nv != 5)
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * nv, c + 1,
|
|
|
|
abs(nv - 5), ' ', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (n == 2) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (ov != 10)
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * (ov - 5), c,
|
|
|
|
abs(ov - 10), col, inc);
|
|
|
|
fixcol(r, c + 2, abs(nv - 10), col, inc);
|
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (nv != 10)
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * (nv - 5), c,
|
|
|
|
abs(nv - 10), ' ', inc);
|
|
|
|
fixcol(r, c + 2, abs(ov - 10), ' ', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (n > o) {
|
|
|
|
fixcol(r + inc * (ov % 5), c + o, abs(5 * n - ov), col, inc);
|
|
|
|
if (nv != 5 * n)
|
|
|
|
fixcol(r, c + n, abs(5 * n - nv), col, inc);
|
|
|
|
} else {
|
|
|
|
fixcol(r + inc * (nv % 5), c + n, abs(5 * n - nv), ' ', inc);
|
|
|
|
if (ov != 5 * o)
|
|
|
|
fixcol(r, c + o, abs(5 * o - ov), ' ', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nv = abs(new);
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r, c + 1, nv, new > 0 ? 'r' : 'w', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (abs(old) <= abs(new))
|
|
|
|
return;
|
1997-10-10 12:59:32 +04:00
|
|
|
fixcol(r + inc * new, c + 1, abs(old + new), ' ', inc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
fixcol(r, c, l, ch, inc)
|
|
|
|
int l, ch, r, c, inc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(r, c);
|
|
|
|
fancyc(ch);
|
|
|
|
for (i = 1; i < l; i++) {
|
|
|
|
curmove(curr + inc, curc - 1);
|
|
|
|
fancyc(ch);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
curmove(r, c)
|
|
|
|
int r, c;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (curr == r && curc == c)
|
|
|
|
return;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (realr == -1) {
|
1993-03-21 12:45:37 +03:00
|
|
|
realr = curr;
|
|
|
|
realc = curc;
|
|
|
|
}
|
|
|
|
curr = r;
|
|
|
|
curc = c;
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
newpos()
|
|
|
|
{
|
|
|
|
int r; /* destination row */
|
|
|
|
int c; /* destination column */
|
|
|
|
int mode = -1; /* mode of movement */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int count = 1000; /* character count */
|
|
|
|
int i; /* index */
|
|
|
|
int n; /* temporary variable */
|
|
|
|
char *m; /* string containing CM movement */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
m = NULL;
|
|
|
|
if (realr == -1) /* see if already there */
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
r = curr; /* set current and dest. positions */
|
1993-03-21 12:45:37 +03:00
|
|
|
c = curc;
|
|
|
|
curr = realr;
|
|
|
|
curc = realc;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* double check position */
|
|
|
|
if (curr == r && curc == c) {
|
1993-03-21 12:45:37 +03:00
|
|
|
realr = realc = -1;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (CM) { /* try CM to get there */
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 0;
|
1997-10-10 12:59:32 +04:00
|
|
|
m = (char *) tgoto(CM, c, r);
|
|
|
|
count = strlen(m);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* try HO and local movement */
|
|
|
|
if (HO && (n = r + c * lND + lHO) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 1;
|
|
|
|
count = n;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* try various LF combinations */
|
|
|
|
if (r >= curr) {
|
|
|
|
/* CR, LF, and ND */
|
|
|
|
if ((n = (r - curr) + c * lND + 1) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 2;
|
|
|
|
count = n;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* LF, ND */
|
|
|
|
if (c >= curc && (n = (r - curr) + (c - curc) * lND) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 3;
|
|
|
|
count = n;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* LF, BS */
|
|
|
|
if (c < curc && (n = (r - curr) + (curc - c) * lBC) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 4;
|
|
|
|
count = n;
|
|
|
|
}
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* try corresponding UP combinations */
|
|
|
|
if (r < curr) {
|
|
|
|
/* CR, UP, and ND */
|
|
|
|
if ((n = (curr - r) * lUP + c * lND + 1) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 5;
|
|
|
|
count = n;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* UP and ND */
|
|
|
|
if (c >= curc && (n = (curr - r) * lUP + (c - curc) * lND) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 6;
|
|
|
|
count = n;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* UP and BS */
|
|
|
|
if (c < curc && (n = (curr - r) * lUP + (curc - c) * lBC) < count) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 7;
|
|
|
|
count = n;
|
|
|
|
}
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* space over */
|
|
|
|
if (curr == r && c > curc && linect[r] < curc && c - curc < count)
|
1993-03-21 12:45:37 +03:00
|
|
|
mode = 8;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
switch (mode) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
case -1: /* error! */
|
|
|
|
write(2, "\r\nInternal cursor error.\r\n", 26);
|
|
|
|
getout(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* direct cursor motion */
|
|
|
|
case 0:
|
|
|
|
tputs(m, abs(curr - r), addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* relative to "home" */
|
|
|
|
case 1:
|
|
|
|
tputs(HO, r, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < r; i++)
|
1997-10-10 12:59:32 +04:00
|
|
|
addbuf('\012');
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < c; i++)
|
1997-10-10 12:59:32 +04:00
|
|
|
tputs(ND, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* CR and down and over */
|
|
|
|
case 2:
|
|
|
|
addbuf('\015');
|
|
|
|
for (i = 0; i < r - curr; i++)
|
|
|
|
addbuf('\012');
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < c; i++)
|
1997-10-10 12:59:32 +04:00
|
|
|
tputs(ND, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
|
|
|
|
/* down and over */
|
|
|
|
case 3:
|
|
|
|
for (i = 0; i < r - curr; i++)
|
|
|
|
addbuf('\012');
|
|
|
|
for (i = 0; i < c - curc; i++)
|
|
|
|
tputs(ND, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
|
|
|
|
/* down and back */
|
|
|
|
case 4:
|
|
|
|
for (i = 0; i < r - curr; i++)
|
|
|
|
addbuf('\012');
|
|
|
|
for (i = 0; i < curc - c; i++)
|
|
|
|
addbuf('\010');
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
|
|
|
|
/* CR and up and over */
|
|
|
|
case 5:
|
|
|
|
addbuf('\015');
|
|
|
|
for (i = 0; i < curr - r; i++)
|
|
|
|
tputs(UP, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < c; i++)
|
1997-10-10 12:59:32 +04:00
|
|
|
tputs(ND, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
|
|
|
|
/* up and over */
|
|
|
|
case 6:
|
|
|
|
for (i = 0; i < curr - r; i++)
|
|
|
|
tputs(UP, 1, addbuf);
|
|
|
|
for (i = 0; i < c - curc; i++)
|
|
|
|
tputs(ND, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
|
|
|
|
/* up and back */
|
|
|
|
case 7:
|
|
|
|
for (i = 0; i < curr - r; i++)
|
|
|
|
tputs(UP, 1, addbuf);
|
|
|
|
for (i = 0; i < curc - c; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (BC)
|
1997-10-10 12:59:32 +04:00
|
|
|
tputs(BC, 1, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
addbuf('\010');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* safe space */
|
|
|
|
case 8:
|
|
|
|
for (i = 0; i < c - curc; i++)
|
|
|
|
addbuf(' ');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* fix positions */
|
1993-03-21 12:45:37 +03:00
|
|
|
curr = r;
|
|
|
|
curc = c;
|
|
|
|
realr = -1;
|
|
|
|
realc = -1;
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
clear()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* double space if can't clear */
|
|
|
|
if (CL == 0) {
|
|
|
|
writel("\n\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
curr = curc = 0; /* fix position markers */
|
1993-03-21 12:45:37 +03:00
|
|
|
realr = realc = -1;
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 0; i < 24; i++)/* clear line counts */
|
1993-03-21 12:45:37 +03:00
|
|
|
linect[i] = -1;
|
1997-10-10 12:59:32 +04:00
|
|
|
buffnum = -1; /* ignore leftover buffer contents */
|
|
|
|
tputs(CL, CO, addbuf); /* put CL in buffer */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
tos()
|
|
|
|
{ /* home cursor */
|
|
|
|
curmove(0, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
fancyc(c)
|
|
|
|
char c; /* character to output */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int sp; /* counts spaces in a tab */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (c == '\007') { /* bells go in blindly */
|
|
|
|
addbuf(c);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* process tabs, use spaces if the the tab should be erasing things,
|
|
|
|
* otherwise use cursor movement routines. Note this does not use
|
|
|
|
* hardware tabs at all. */
|
|
|
|
if (c == '\t') {
|
|
|
|
sp = (curc + 8) & (~7); /* compute spaces */
|
|
|
|
/* check line length */
|
|
|
|
if (linect[curr] >= curc || sp < 4) {
|
1993-03-21 12:45:37 +03:00
|
|
|
for (; sp > curc; sp--)
|
1997-10-10 12:59:32 +04:00
|
|
|
addbuf(' ');
|
|
|
|
curc = sp; /* fix curc */
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(curr, sp);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* do newline be calling newline */
|
|
|
|
if (c == '\n') {
|
1993-03-21 12:45:37 +03:00
|
|
|
newline();
|
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
/* ignore any other control chars */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (c < ' ')
|
|
|
|
return;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* if an erasing space or non-space, just add it to buffer. Otherwise
|
|
|
|
* use cursor movement routine, so that multiple spaces will be
|
|
|
|
* grouped together */
|
|
|
|
if (c > ' ' || linect[curr] >= curc) {
|
|
|
|
newpos(); /* make sure position correct */
|
|
|
|
addbuf(c); /* add character to buffer */
|
|
|
|
/* fix line length */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (c == ' ' && linect[curr] == curc)
|
|
|
|
linect[curr]--;
|
1997-10-10 12:59:32 +04:00
|
|
|
else
|
|
|
|
if (linect[curr] < curc)
|
|
|
|
linect[curr] = curc;
|
|
|
|
curc++; /* fix curc */
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
/* use cursor movement routine */
|
|
|
|
curmove(curr, curc + 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
clend()
|
|
|
|
{
|
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (CD) {
|
|
|
|
tputs(CD, CO - curr, addbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = curr; i < LI; i++)
|
|
|
|
linect[i] = -1;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(i = curr, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
1997-10-10 12:59:32 +04:00
|
|
|
while (curr < LI - 1) {
|
|
|
|
curmove(curr + 1, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (linect[curr] > -1)
|
1997-10-10 12:59:32 +04:00
|
|
|
cline();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(i, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
cline()
|
|
|
|
{
|
|
|
|
int c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (curc > linect[curr])
|
|
|
|
return;
|
1997-10-10 12:59:32 +04:00
|
|
|
newpos();
|
|
|
|
if (CE) {
|
|
|
|
tputs(CE, 1, addbuf);
|
|
|
|
linect[curr] = curc - 1;
|
|
|
|
} else {
|
|
|
|
c = curc - 1;
|
|
|
|
while (linect[curr] > c) {
|
|
|
|
addbuf(' ');
|
1993-03-21 12:45:37 +03:00
|
|
|
curc++;
|
|
|
|
linect[curr]--;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(curr, c + 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
newline()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
1997-10-10 12:59:32 +04:00
|
|
|
if (curr == LI - 1)
|
|
|
|
curmove(begscr, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(curr + 1, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int
|
|
|
|
getcaps(s)
|
|
|
|
char *s;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
char *code; /* two letter code */
|
|
|
|
char ***cap; /* pointer to cap string */
|
|
|
|
char *bufp; /* pointer to cap buffer */
|
|
|
|
char tentry[1024]; /* temporary uncoded caps buffer */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
tgetent(tentry, s); /* get uncoded termcap entry */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
LI = tgetnum("li"); /* get number of lines */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (LI == -1)
|
|
|
|
LI = 12;
|
1997-10-10 12:59:32 +04:00
|
|
|
CO = tgetnum("co"); /* get number of columns */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (CO == -1)
|
|
|
|
CO = 65;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
bufp = tbuf; /* get padding character */
|
|
|
|
tgetstr("pc", &bufp);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (bufp != tbuf)
|
|
|
|
PC = *tbuf;
|
|
|
|
else
|
|
|
|
PC = 0;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
bufp = tbuf; /* get string entries */
|
1993-03-21 12:45:37 +03:00
|
|
|
cap = tstr;
|
|
|
|
for (code = tcap; *code; code += 2)
|
1997-10-10 12:59:32 +04:00
|
|
|
**cap++ = (char *) tgetstr(code, &bufp);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* get pertinent lengths */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (HO)
|
1997-10-10 12:59:32 +04:00
|
|
|
lHO = strlen(HO);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (BC)
|
1997-10-10 12:59:32 +04:00
|
|
|
lBC = strlen(BC);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
lBC = 1;
|
|
|
|
if (UP)
|
1997-10-10 12:59:32 +04:00
|
|
|
lUP = strlen(UP);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (ND)
|
1997-10-10 12:59:32 +04:00
|
|
|
lND = strlen(ND);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (LI < 24 || CO < 72 || !(CL && UP && ND))
|
|
|
|
return (0);
|
1997-10-10 12:59:32 +04:00
|
|
|
linect = (int *) calloc(LI + 1, sizeof(int));
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|