* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
static char sccsid
[] = "@(#)fancy.c 5.5 (Berkeley) 6/1/90";
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) */
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};
/* "real" cursor positions, so
* it knows when to reposition.
* These are -1 if curr and curc
curmove (0,0); /* do top line */
curmove (15,0); /* do botttom line */
l
= 1; /* do vertical lines */
for (i
= 52; i
> -1; i
-= 28) {
curmove ( (l
== 1? 1: 15) ,i
);
for (j
= 0; j
< 14; j
++) {
l
= -l
; /* alternate directions */
curmove (2,1); /* label positions 13-18 */
for (i
= 13; i
< 18; i
++) {
curmove (2,29); /* label positions 19-24 */
for (i
= 20; i
< 25; i
++) {
curmove (14,1); /* label positions 12-7 */
for (i
= 11; i
> 6; i
--) {
fancyc (i
> 9? '1': ' ');
curmove (14,30); /* label positions 6-1 */
for (i
= 5; i
> 0; i
--) {
for (i
= 12; i
> 6; i
--) /* print positions 12-7 */
bsect (board
[i
],13,1+4*(12-i
),-1);
if (board
[0]) /* print red men on bar */
bsect (board
[0],13,25,-1);
for (i
= 6; i
> 0; i
--) /* print positions 6-1 */
bsect (board
[i
],13,29+4*(6-i
),-1);
l
= (off
[1] < 0? off
[1]+15: off
[1]); /* print white's home */
curmove (8,25); /* print the word BAR */
for (i
= 13; i
< 19; i
++) /* print positions 13-18 */
bsect (board
[i
],3,1+4*(i
-13),1);
if (board
[25]) /* print white's men on bar */
bsect (board
[25],3,25,1);
for (i
= 19; i
< 25; i
++) /* print positions 19-24 */
bsect (board
[i
],3,29+4*(i
-19),1);
l
= (off
[0] < 0? off
[0]+15: off
[0]); /* print red's home */
for (i
= 0; i
< 26; i
++) /* save board position
oldr
= (off
[1] < 0? off
[1]+15: off
[1]);
oldw
= -(off
[0] < 0? off
[0]+15: off
[0]);
* 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
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 */
register int j
; /* index */
register int n
; /* number of men on position */
register int bct
; /* counter */
char pc
; /* color of men on position */
n
= abs(b
); /* initialize n and pc */
if (n
< 6 && cpos
< 54) /* position cursor at start */
for (j
= 0; j
< 5; j
++) { /* print position row by row */
for (k
= 0; k
< 15; k
+= 5) /* print men */
if (j
< 4) { /* figure how far to
if (n
< 6) { /* stop if none left */
bct
= 1; /* single column */
if (n
< 11) { /* two columns */
if (cpos
== 54) { /* home pos */
if (cpos
< 54) { /* not home */
} else { /* three columns */
curmove (curr
+cnext
,curc
-bct
); /* reposition cursor */
r
= curr
; /* save current position */
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);
if (board
[0] != oldb
[0]) { /* fix red men on bar */
fixpos (oldb
[0],board
[0],13,25,-1);
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);
i
= -(off
[0] < 0? off
[0]+15: off
[0]); /* fix white's home */
fixpos (oldw
,i
,13,54,-1);
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);
if (board
[25] != oldb
[25]) { /* fix white men on bar */
fixpos (oldb
[25],board
[25],3,25,1);
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);
i
= (off
[1] < 0? off
[1]+15: off
[1]); /* fix red's home */
curmove (r
,c
); /* return to saved position */
col
= (old
+new > 0? 'r': 'w');
fixcol (r
+inc
*(nv
-n
*5),nc
,abs(ov
-nv
),' ',inc
);
fixcol (r
+inc
*(ov
-o
*5),nc
,abs(ov
-nv
),col
,inc
);
fixcol (r
,c
,abs(nv
-5),col
,inc
);
fixcol (r
+inc
*ov
,c
+1,abs(ov
-5),col
,inc
);
fixcol (r
,c
,abs(ov
-5),' ',inc
);
fixcol (r
+inc
*nv
,c
+1,abs(nv
-5),' ',inc
);
fixcol (r
+inc
*(ov
-5),c
,abs(ov
-10),col
,inc
);
fixcol (r
,c
+2,abs(nv
-10),col
,inc
);
fixcol (r
+inc
*(nv
-5),c
,abs(nv
-10),' ',inc
);
fixcol (r
,c
+2,abs(ov
-10),' ',inc
);
fixcol (r
+inc
*(ov
%5),c
+o
,abs(5*n
-ov
),col
,inc
);
fixcol (r
,c
+n
,abs(5*n
-nv
),col
,inc
);
fixcol (r
+inc
*(nv
%5),c
+n
,abs(5*n
-nv
),' ',inc
);
fixcol (r
,c
+o
,abs(5*o
-ov
),' ',inc
);
fixcol (r
,c
+1,nv
,new > 0? 'r': 'w',inc
);
if (abs(old
) <= abs(new))
fixcol (r
+inc
*new,c
+1,abs(old
+new),' ',inc
);
for (i
= 1; i
< l
; i
++) {
curmove (curr
+inc
,curc
-1);
if (curr
== r
&& curc
== c
)
register int r
; /* destination row */
register int c
; /* destination column */
register int mode
= -1; /* mode of movement */
int count
= 1000; /* character count */
int n
; /* temporary variable */
char *m
; /* string containing CM movement */
if (realr
== -1) /* see if already there */
r
= curr
; /* set current and dest. positions */
/* double check position */
if (curr
== r
&& curc
== c
) {
if (CM
) { /* try CM to get there */
m
= (char *)tgoto (CM
,c
,r
);
/* try HO and local movement */
if (HO
&& (n
= r
+c
*lND
+lHO
) < count
) {
/* try various LF combinations */
if ((n
= (r
-curr
)+c
*lND
+1) < count
) {
if (c
>= curc
&& (n
= (r
-curr
)+(c
-curc
)*lND
) < count
) {
if (c
< curc
&& (n
= (r
-curr
)+(curc
-c
)*lBC
) < count
) {
/* try corresponding UP combinations */
if ((n
= (curr
-r
)*lUP
+c
*lND
+1) < count
) {
if (c
>= curc
&& (n
= (curr
-r
)*lUP
+(c
-curc
)*lND
) < count
) {
if (c
< curc
&& (n
= (curr
-r
)*lUP
+(curc
-c
)*lBC
) < count
) {
if (curr
== r
&& c
> curc
&& linect
[r
] < curc
&& c
-curc
< count
)
write (2,"\r\nInternal cursor error.\r\n",26);
/* direct cursor motion */
tputs (m
,abs(curr
-r
),addbuf
);
/* CR and down and over */
for (i
= 0; i
< r
-curr
; i
++)
for (i
= 0; i
< r
-curr
; i
++)
for (i
= 0; i
< c
-curc
; i
++)
for (i
= 0; i
< r
-curr
; i
++)
for (i
= 0; i
< curc
-c
; i
++)
for (i
= 0; i
< curr
-r
; i
++)
for (i
= 0; i
< curr
-r
; i
++)
for (i
= 0; i
< c
-curc
; i
++)
for (i
= 0; i
< curr
-r
; i
++)
for (i
= 0; i
< curc
-c
; i
++) {
for (i
= 0; i
< c
-curc
; i
++)
/* double space if can't clear */
curr
= curc
= 0; /* fix position markers */
for (i
= 0; i
< 24; i
++) /* clear line counts */
buffnum
= -1; /* ignore leftover buffer contents */
tputs (CL
,CO
,addbuf
); /* put CL in buffer */
tos () { /* home cursor */
register char c
; /* character to output */
register int sp
; /* counts spaces in a tab */
if (c
== '\007') { /* bells go in blindly */
/* 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. */
sp
= (curc
+8) & (~ 7); /* compute spaces */
if (linect
[curr
] >= curc
|| sp
< 4) {
curc
= sp
; /* fix curc */
/* do newline be calling newline */
/* ignore any other control chars */
/* if an erasing space or non-space,
* just add it to buffer. Otherwise
* use cursor movement routine, so that
* multiple spaces will be grouped
if (c
> ' ' || linect
[curr
] >= curc
) {
newpos (); /* make sure position correct */
addbuf (c
); /* add character to buffer */
if (c
== ' ' && linect
[curr
] == curc
)
else if (linect
[curr
] < curc
)
/* use cursor movement routine */
tputs (CD
,CO
-curr
,addbuf
);
for (i
= curr
; i
< LI
; i
++)
while (linect
[curr
] > c
) {
register char *code
; /* two letter code */
register char ***cap
; /* pointer to cap string */
char *bufp
; /* pointer to cap buffer */
char tentry
[1024]; /* temporary uncoded caps buffer */
tgetent (tentry
,s
); /* get uncoded termcap entry */
LI
= tgetnum ("li"); /* get number of lines */
CO
= tgetnum ("co"); /* get number of columns */
bufp
= tbuf
; /* get padding character */
bufp
= tbuf
; /* get string entries */
for (code
= tcap
; *code
; code
+= 2)
**cap
++ = (char *)tgetstr (code
,&bufp
);
/* get pertinent lengths */
if (LI
< 24 || CO
< 72 || !(CL
&& UP
&& ND
))
linect
= (int *)calloc (LI
+1,sizeof(int));