2017-03-21 01:05:27 +03:00
|
|
|
/* $NetBSD: screen.c,v 1.33 2017/03/20 22:05:27 christos Exp $ */
|
1995-04-22 11:42:31 +04:00
|
|
|
|
1994-05-06 10:50:50 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Chris Torek and Darren F. Provine.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-06 10:50:50 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)screen.c 8.1 (Berkeley) 5/31/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tetris screen control.
|
|
|
|
*/
|
|
|
|
|
2007-12-15 19:32:05 +03:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-06 10:50:50 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-02-03 18:34:37 +03:00
|
|
|
#include <term.h>
|
1995-04-29 02:09:25 +04:00
|
|
|
#include <termios.h>
|
1994-05-06 10:50:50 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#ifndef sigmask
|
|
|
|
#define sigmask(s) (1 << ((s) - 1))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "screen.h"
|
|
|
|
#include "tetris.h"
|
|
|
|
|
|
|
|
static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */
|
|
|
|
static int curscore;
|
|
|
|
static int isset; /* true => terminal is in game mode */
|
1995-04-29 02:09:25 +04:00
|
|
|
static struct termios oldtt;
|
2004-01-27 23:30:28 +03:00
|
|
|
static void (*tstp)(int);
|
1994-05-06 10:50:50 +04:00
|
|
|
|
2004-01-27 23:30:28 +03:00
|
|
|
static void scr_stop(int);
|
2007-12-15 22:44:37 +03:00
|
|
|
static void stopset(int) __dead;
|
1994-05-06 10:50:50 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine used by tputs().
|
|
|
|
*/
|
1999-10-05 03:26:59 +04:00
|
|
|
int
|
2009-05-25 08:33:53 +04:00
|
|
|
put(int c)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
|
|
|
|
1999-10-05 03:26:59 +04:00
|
|
|
return (putchar(c));
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* putstr() is for unpadded strings (either as in termcap(5) or
|
|
|
|
* simply literal strings); putpad() is for padded strings with
|
|
|
|
* count=1. (See screen.h for putpad().)
|
|
|
|
*/
|
|
|
|
#define putstr(s) (void)fputs(s, stdout)
|
2000-05-22 16:42:46 +04:00
|
|
|
|
2009-08-12 12:44:45 +04:00
|
|
|
static void
|
2000-05-22 16:42:46 +04:00
|
|
|
moveto(int r, int c)
|
|
|
|
{
|
2010-02-03 18:34:37 +03:00
|
|
|
char *buf;
|
2000-05-22 16:42:46 +04:00
|
|
|
|
2011-10-03 16:32:15 +04:00
|
|
|
buf = tiparm(cursor_address, r, c);
|
2010-02-03 18:34:37 +03:00
|
|
|
if (buf != NULL)
|
2000-05-22 16:42:46 +04:00
|
|
|
putpad(buf);
|
|
|
|
}
|
1994-05-06 10:50:50 +04:00
|
|
|
|
2014-06-11 20:47:39 +04:00
|
|
|
static void
|
|
|
|
setcolor(int c)
|
|
|
|
{
|
|
|
|
char *buf;
|
2015-07-08 01:53:25 +03:00
|
|
|
char monochrome[] = "\033[0m";
|
2014-07-13 20:23:55 +04:00
|
|
|
if (nocolor == 1)
|
|
|
|
return;
|
2014-06-11 20:47:39 +04:00
|
|
|
if (set_a_foreground == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-07-08 01:53:25 +03:00
|
|
|
if (c == 0 || c == 7)
|
|
|
|
buf = monochrome;
|
|
|
|
else
|
|
|
|
buf = tiparm(set_a_foreground, c);
|
2014-06-11 20:47:39 +04:00
|
|
|
if (buf != NULL)
|
|
|
|
putpad(buf);
|
|
|
|
}
|
|
|
|
|
1994-05-06 10:50:50 +04:00
|
|
|
/*
|
|
|
|
* Set up from termcap.
|
|
|
|
*/
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_init(void)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
|
|
|
|
2010-02-03 18:34:37 +03:00
|
|
|
setupterm(NULL, 0, NULL);
|
|
|
|
if (clear_screen == NULL)
|
1994-05-06 10:50:50 +04:00
|
|
|
stop("cannot clear screen");
|
2010-02-03 18:34:37 +03:00
|
|
|
if (cursor_address == NULL || cursor_up == NULL)
|
|
|
|
stop("cannot do random cursor positioning");
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this foolery is needed to modify tty state `atomically' */
|
|
|
|
static jmp_buf scr_onstop;
|
|
|
|
|
|
|
|
static void
|
2009-05-25 08:33:53 +04:00
|
|
|
stopset(int sig)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
2008-01-28 04:38:59 +03:00
|
|
|
sigset_t set;
|
1995-04-29 02:09:25 +04:00
|
|
|
|
1994-05-06 10:50:50 +04:00
|
|
|
(void) signal(sig, SIG_DFL);
|
|
|
|
(void) kill(getpid(), sig);
|
2008-01-28 04:38:59 +03:00
|
|
|
sigemptyset(&set);
|
|
|
|
sigaddset(&set, sig);
|
|
|
|
(void) sigprocmask(SIG_UNBLOCK, &set, (sigset_t *)0);
|
1994-05-06 10:50:50 +04:00
|
|
|
longjmp(scr_onstop, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_stop(int sig)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
2008-01-28 04:38:59 +03:00
|
|
|
sigset_t set;
|
1995-04-29 02:09:25 +04:00
|
|
|
|
1994-05-06 10:50:50 +04:00
|
|
|
scr_end();
|
1995-04-29 02:09:25 +04:00
|
|
|
(void) kill(getpid(), sig);
|
2008-01-28 04:38:59 +03:00
|
|
|
sigemptyset(&set);
|
|
|
|
sigaddset(&set, sig);
|
|
|
|
(void) sigprocmask(SIG_UNBLOCK, &set, (sigset_t *)0);
|
1994-05-06 10:50:50 +04:00
|
|
|
scr_set();
|
|
|
|
scr_msg(key_msg, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up screen mode.
|
|
|
|
*/
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_set(void)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
|
|
|
struct winsize ws;
|
1995-04-29 02:09:25 +04:00
|
|
|
struct termios newtt;
|
2008-01-28 04:38:59 +03:00
|
|
|
sigset_t nsigset, osigset;
|
2004-01-27 23:30:28 +03:00
|
|
|
void (*ttou)(int);
|
1994-05-06 10:50:50 +04:00
|
|
|
|
2008-01-28 04:38:59 +03:00
|
|
|
sigemptyset(&nsigset);
|
|
|
|
sigaddset(&nsigset, SIGTSTP);
|
|
|
|
sigaddset(&nsigset, SIGTTOU);
|
|
|
|
(void) sigprocmask(SIG_BLOCK, &nsigset, &osigset);
|
1994-05-06 10:50:50 +04:00
|
|
|
if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN)
|
|
|
|
(void) signal(SIGTSTP, SIG_IGN);
|
1995-04-29 02:09:25 +04:00
|
|
|
if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN)
|
|
|
|
(void) signal(SIGTTOU, SIG_IGN);
|
1994-05-06 10:50:50 +04:00
|
|
|
/*
|
|
|
|
* At last, we are ready to modify the tty state. If
|
|
|
|
* we stop while at it, stopset() above will longjmp back
|
|
|
|
* to the setjmp here and we will start over.
|
|
|
|
*/
|
|
|
|
(void) setjmp(scr_onstop);
|
1995-04-29 02:09:25 +04:00
|
|
|
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
1994-05-06 10:50:50 +04:00
|
|
|
Rows = 0, Cols = 0;
|
|
|
|
if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
|
|
|
|
Rows = ws.ws_row;
|
|
|
|
Cols = ws.ws_col;
|
|
|
|
}
|
|
|
|
if (Rows == 0)
|
2010-02-03 18:34:37 +03:00
|
|
|
Rows = lines;
|
1994-05-06 10:50:50 +04:00
|
|
|
if (Cols == 0)
|
2010-02-03 18:34:37 +03:00
|
|
|
Cols = columns;
|
1994-05-06 10:50:50 +04:00
|
|
|
if (Rows < MINROWS || Cols < MINCOLS) {
|
|
|
|
(void) fprintf(stderr,
|
1999-01-03 05:00:17 +03:00
|
|
|
"the screen is too small: must be at least %dx%d, ",
|
|
|
|
MINCOLS, MINROWS);
|
1994-05-06 10:50:50 +04:00
|
|
|
stop(""); /* stop() supplies \n */
|
|
|
|
}
|
2016-03-04 00:38:55 +03:00
|
|
|
Offset = (Rows - D_LAST + D_FIRST - 2) / 2;
|
1995-04-29 02:09:25 +04:00
|
|
|
if (tcgetattr(0, &oldtt) < 0)
|
|
|
|
stop("tcgetattr() fails");
|
1994-05-06 10:50:50 +04:00
|
|
|
newtt = oldtt;
|
1995-04-29 02:09:25 +04:00
|
|
|
newtt.c_lflag &= ~(ICANON|ECHO);
|
|
|
|
newtt.c_oflag &= ~OXTABS;
|
|
|
|
if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
|
|
|
|
stop("tcsetattr() fails");
|
|
|
|
ospeed = cfgetospeed(&newtt);
|
2008-01-28 04:38:59 +03:00
|
|
|
(void) sigprocmask(SIG_BLOCK, &nsigset, &osigset);
|
1994-05-06 10:50:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We made it. We are now in screen mode, modulo TIstr
|
|
|
|
* (which we will fix immediately).
|
|
|
|
*/
|
2017-03-21 01:05:27 +03:00
|
|
|
const char *tstr;
|
|
|
|
if ((tstr = enter_ca_mode) != NULL)
|
|
|
|
putstr(tstr);
|
|
|
|
if ((tstr = cursor_invisible) != NULL)
|
|
|
|
putstr(tstr);
|
1994-05-06 10:50:50 +04:00
|
|
|
if (tstp != SIG_IGN)
|
|
|
|
(void) signal(SIGTSTP, scr_stop);
|
1995-04-29 02:09:25 +04:00
|
|
|
if (ttou != SIG_IGN)
|
|
|
|
(void) signal(SIGTTOU, ttou);
|
1994-05-06 10:50:50 +04:00
|
|
|
|
|
|
|
isset = 1;
|
1995-04-29 02:09:25 +04:00
|
|
|
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
1994-05-06 10:50:50 +04:00
|
|
|
scr_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End screen mode.
|
|
|
|
*/
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_end(void)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
2008-01-28 04:38:59 +03:00
|
|
|
sigset_t nsigset, osigset;
|
1994-05-06 10:50:50 +04:00
|
|
|
|
2008-01-28 04:38:59 +03:00
|
|
|
sigemptyset(&nsigset);
|
|
|
|
sigaddset(&nsigset, SIGTSTP);
|
|
|
|
sigaddset(&nsigset, SIGTTOU);
|
|
|
|
(void) sigprocmask(SIG_BLOCK, &nsigset, &osigset);
|
1994-05-06 10:50:50 +04:00
|
|
|
/* move cursor to last line */
|
2017-03-21 01:05:27 +03:00
|
|
|
const char *tstr;
|
|
|
|
if ((tstr = cursor_to_ll) != NULL)
|
|
|
|
putstr(tstr);
|
1994-05-06 10:50:50 +04:00
|
|
|
else
|
|
|
|
moveto(Rows - 1, 0);
|
|
|
|
/* exit screen mode */
|
2017-03-21 01:05:27 +03:00
|
|
|
if ((tstr = exit_ca_mode) != NULL)
|
|
|
|
putstr(tstr);
|
|
|
|
if ((tstr = cursor_normal) != NULL)
|
|
|
|
putstr(tstr);
|
1994-05-06 10:50:50 +04:00
|
|
|
(void) fflush(stdout);
|
1995-04-29 02:09:25 +04:00
|
|
|
(void) tcsetattr(0, TCSADRAIN, &oldtt);
|
1994-05-06 10:50:50 +04:00
|
|
|
isset = 0;
|
|
|
|
/* restore signals */
|
|
|
|
(void) signal(SIGTSTP, tstp);
|
1995-04-29 02:09:25 +04:00
|
|
|
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
stop(const char *why)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (isset)
|
|
|
|
scr_end();
|
|
|
|
(void) fprintf(stderr, "aborting: %s\n", why);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the screen, forgetting the current contents in the process.
|
|
|
|
*/
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_clear(void)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
|
|
|
|
2010-02-03 18:34:37 +03:00
|
|
|
putpad(clear_screen);
|
1994-05-06 10:50:50 +04:00
|
|
|
curscore = -1;
|
1998-08-10 06:23:45 +04:00
|
|
|
memset((char *)curscreen, 0, sizeof(curscreen));
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if vax && !__GNUC__
|
|
|
|
typedef int regcell; /* pcc is bad at `register char', etc */
|
|
|
|
#else
|
|
|
|
typedef cell regcell;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the screen.
|
|
|
|
*/
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_update(void)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
2002-06-03 02:17:37 +04:00
|
|
|
cell *bp, *sp;
|
|
|
|
regcell so, cur_so = 0;
|
|
|
|
int i, ccol, j;
|
2008-01-28 04:38:59 +03:00
|
|
|
sigset_t nsigset, osigset;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
static const struct shape *lastshape;
|
1995-04-29 02:09:25 +04:00
|
|
|
|
2008-01-28 04:38:59 +03:00
|
|
|
sigemptyset(&nsigset);
|
|
|
|
sigaddset(&nsigset, SIGTSTP);
|
|
|
|
(void) sigprocmask(SIG_BLOCK, &nsigset, &osigset);
|
1994-05-06 10:50:50 +04:00
|
|
|
|
|
|
|
/* always leave cursor after last displayed point */
|
|
|
|
curscreen[D_LAST * B_COLS - 1] = -1;
|
|
|
|
|
|
|
|
if (score != curscore) {
|
2010-02-03 18:34:37 +03:00
|
|
|
if (cursor_home)
|
|
|
|
putpad(cursor_home);
|
1994-05-06 10:50:50 +04:00
|
|
|
else
|
|
|
|
moveto(0, 0);
|
2015-07-08 01:53:25 +03:00
|
|
|
setcolor(0);
|
1999-01-03 05:00:17 +03:00
|
|
|
(void) printf("Score: %d", score);
|
1994-05-06 10:50:50 +04:00
|
|
|
curscore = score;
|
|
|
|
}
|
|
|
|
|
1999-01-03 05:00:17 +03:00
|
|
|
/* draw preview of nextpattern */
|
1999-01-03 20:13:51 +03:00
|
|
|
if (showpreview && (nextshape != lastshape)) {
|
1999-01-03 05:00:17 +03:00
|
|
|
static int r=5, c=2;
|
|
|
|
int tr, tc, t;
|
|
|
|
|
|
|
|
lastshape = nextshape;
|
|
|
|
|
|
|
|
/* clean */
|
2010-02-03 18:34:37 +03:00
|
|
|
putpad(exit_standout_mode);
|
1999-01-03 05:00:17 +03:00
|
|
|
moveto(r-1, c-1); putstr(" ");
|
|
|
|
moveto(r, c-1); putstr(" ");
|
|
|
|
moveto(r+1, c-1); putstr(" ");
|
|
|
|
moveto(r+2, c-1); putstr(" ");
|
|
|
|
|
|
|
|
moveto(r-3, c-2);
|
|
|
|
putstr("Next shape:");
|
|
|
|
|
|
|
|
/* draw */
|
2014-06-11 20:47:39 +04:00
|
|
|
setcolor(nextshape->color);
|
2015-11-06 22:53:37 +03:00
|
|
|
putpad(enter_standout_mode);
|
1999-01-03 05:00:17 +03:00
|
|
|
moveto(r, 2*c);
|
|
|
|
putstr(" ");
|
|
|
|
for(i=0; i<3; i++) {
|
|
|
|
t = c + r*B_COLS;
|
|
|
|
t += nextshape->off[i];
|
|
|
|
|
|
|
|
tr = t / B_COLS;
|
|
|
|
tc = t % B_COLS;
|
|
|
|
|
|
|
|
moveto(tr, 2*tc);
|
|
|
|
putstr(" ");
|
|
|
|
}
|
2010-02-03 18:34:37 +03:00
|
|
|
putpad(exit_standout_mode);
|
1999-01-03 05:00:17 +03:00
|
|
|
}
|
|
|
|
|
1994-05-06 10:50:50 +04:00
|
|
|
bp = &board[D_FIRST * B_COLS];
|
|
|
|
sp = &curscreen[D_FIRST * B_COLS];
|
|
|
|
for (j = D_FIRST; j < D_LAST; j++) {
|
|
|
|
ccol = -1;
|
|
|
|
for (i = 0; i < B_COLS; bp++, sp++, i++) {
|
|
|
|
if (*sp == (so = *bp))
|
|
|
|
continue;
|
|
|
|
*sp = so;
|
|
|
|
if (i != ccol) {
|
2010-02-03 18:34:37 +03:00
|
|
|
if (cur_so && move_standout_mode) {
|
|
|
|
putpad(exit_standout_mode);
|
1994-05-06 10:50:50 +04:00
|
|
|
cur_so = 0;
|
|
|
|
}
|
2016-03-04 00:38:55 +03:00
|
|
|
moveto(RTOD(j + Offset), CTOD(i));
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
2010-02-03 18:34:37 +03:00
|
|
|
if (enter_standout_mode) {
|
1994-05-06 10:50:50 +04:00
|
|
|
if (so != cur_so) {
|
2015-07-08 01:53:25 +03:00
|
|
|
setcolor(so);
|
2010-02-03 18:34:37 +03:00
|
|
|
putpad(so ?
|
|
|
|
enter_standout_mode :
|
|
|
|
exit_standout_mode);
|
1994-05-06 10:50:50 +04:00
|
|
|
cur_so = so;
|
|
|
|
}
|
2014-06-11 20:47:39 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
char buf[3];
|
|
|
|
snprintf(buf, sizeof(buf), "%d%d", so, so);
|
|
|
|
putstr(buf);
|
|
|
|
#else
|
1994-05-06 10:50:50 +04:00
|
|
|
putstr(" ");
|
2014-06-11 20:47:39 +04:00
|
|
|
#endif
|
1994-05-06 10:50:50 +04:00
|
|
|
} else
|
|
|
|
putstr(so ? "XX" : " ");
|
|
|
|
ccol = i + 1;
|
|
|
|
/*
|
|
|
|
* Look ahead a bit, to avoid extra motion if
|
|
|
|
* we will be redrawing the cell after the next.
|
|
|
|
* Motion probably takes four or more characters,
|
|
|
|
* so we save even if we rewrite two cells
|
|
|
|
* `unnecessarily'. Skip it all, though, if
|
|
|
|
* the next cell is a different color.
|
|
|
|
*/
|
|
|
|
#define STOP (B_COLS - 3)
|
|
|
|
if (i > STOP || sp[1] != bp[1] || so != bp[1])
|
|
|
|
continue;
|
|
|
|
if (sp[2] != bp[2])
|
|
|
|
sp[1] = -1;
|
|
|
|
else if (i < STOP && so == bp[2] && sp[3] != bp[3]) {
|
|
|
|
sp[2] = -1;
|
|
|
|
sp[1] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur_so)
|
2010-02-03 18:34:37 +03:00
|
|
|
putpad(exit_standout_mode);
|
1994-05-06 10:50:50 +04:00
|
|
|
(void) fflush(stdout);
|
1995-04-29 02:09:25 +04:00
|
|
|
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a message (set!=0), or clear the same message (set==0).
|
|
|
|
* (We need its length in case we have to overwrite with blanks.)
|
|
|
|
*/
|
|
|
|
void
|
2009-05-25 08:33:53 +04:00
|
|
|
scr_msg(char *s, int set)
|
1994-05-06 10:50:50 +04:00
|
|
|
{
|
|
|
|
|
2010-02-03 18:34:37 +03:00
|
|
|
if (set || clr_eol == NULL) {
|
2002-06-03 02:17:37 +04:00
|
|
|
int l = strlen(s);
|
1994-05-06 10:50:50 +04:00
|
|
|
|
|
|
|
moveto(Rows - 2, ((Cols - l) >> 1) - 1);
|
|
|
|
if (set)
|
|
|
|
putstr(s);
|
|
|
|
else
|
|
|
|
while (--l >= 0)
|
|
|
|
(void) putchar(' ');
|
|
|
|
} else {
|
|
|
|
moveto(Rows - 2, 0);
|
2010-02-03 18:34:37 +03:00
|
|
|
putpad(clr_eol);
|
1994-05-06 10:50:50 +04:00
|
|
|
}
|
|
|
|
}
|