2003-04-02 22:36:33 +04:00
|
|
|
/* $NetBSD: hack.topl.c,v 1.7 2003/04/02 18:36:41 jsm Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
|
|
|
|
* Amsterdam
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - 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.
|
|
|
|
*
|
|
|
|
* - Neither the name of the Stichting Centrum voor Wiskunde en
|
|
|
|
* Informatica, 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
|
1993-08-02 21:18:41 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
2003-04-02 22:36:33 +04:00
|
|
|
__RCSID("$NetBSD: hack.topl.c,v 1.7 2003/04/02 18:36:41 jsm Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
char toplines[BUFSZ];
|
|
|
|
xchar tlx, tly; /* set by pline; used by addtopl */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
struct topl {
|
1997-10-19 20:56:41 +04:00
|
|
|
struct topl *next_topl;
|
|
|
|
char *topl_text;
|
|
|
|
} *old_toplines, *last_redone_topl;
|
1993-03-21 12:45:37 +03:00
|
|
|
#define OTLMAX 20 /* max nr of old toplines remembered */
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
doredotopl()
|
|
|
|
{
|
|
|
|
if (last_redone_topl)
|
1993-03-21 12:45:37 +03:00
|
|
|
last_redone_topl = last_redone_topl->next_topl;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!last_redone_topl)
|
1993-03-21 12:45:37 +03:00
|
|
|
last_redone_topl = old_toplines;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (last_redone_topl) {
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) strcpy(toplines, last_redone_topl->topl_text);
|
|
|
|
}
|
|
|
|
redotoplin();
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
redotoplin()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
home();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (strchr(toplines, '\n'))
|
|
|
|
cl_end();
|
1993-03-21 12:45:37 +03:00
|
|
|
putstr(toplines);
|
|
|
|
cl_end();
|
|
|
|
tlx = curx;
|
|
|
|
tly = cury;
|
|
|
|
flags.toplin = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (tly > 1)
|
1993-03-21 12:45:37 +03:00
|
|
|
more();
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
remember_topl()
|
|
|
|
{
|
|
|
|
struct topl *tl;
|
|
|
|
int cnt = OTLMAX;
|
|
|
|
if (last_redone_topl &&
|
|
|
|
!strcmp(toplines, last_redone_topl->topl_text))
|
|
|
|
return;
|
|
|
|
if (old_toplines &&
|
|
|
|
!strcmp(toplines, old_toplines->topl_text))
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
last_redone_topl = 0;
|
|
|
|
tl = (struct topl *)
|
1997-10-19 20:56:41 +04:00
|
|
|
alloc((unsigned) (strlen(toplines) + sizeof(struct topl) + 1));
|
1993-03-21 12:45:37 +03:00
|
|
|
tl->next_topl = old_toplines;
|
1997-10-19 20:56:41 +04:00
|
|
|
tl->topl_text = (char *) (tl + 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) strcpy(tl->topl_text, toplines);
|
|
|
|
old_toplines = tl;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (cnt && tl) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cnt--;
|
|
|
|
tl = tl->next_topl;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (tl && tl->next_topl) {
|
1993-03-21 12:45:37 +03:00
|
|
|
free((char *) tl->next_topl);
|
|
|
|
tl->next_topl = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
addtopl(s)
|
2001-03-26 00:43:58 +04:00
|
|
|
const char *s;
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
curs(tlx, tly);
|
|
|
|
if (tlx + strlen(s) > CO)
|
|
|
|
putsym('\n');
|
1993-03-21 12:45:37 +03:00
|
|
|
putstr(s);
|
|
|
|
tlx = curx;
|
|
|
|
tly = cury;
|
|
|
|
flags.toplin = 1;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
xmore(s)
|
2001-03-26 00:43:58 +04:00
|
|
|
const char *s; /* allowed chars besides space/return */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.toplin) {
|
1993-03-21 12:45:37 +03:00
|
|
|
curs(tlx, tly);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (tlx + 8 > CO)
|
|
|
|
putsym('\n'), tly++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.standout)
|
1993-03-21 12:45:37 +03:00
|
|
|
standoutbeg();
|
|
|
|
putstr("--More--");
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.standout)
|
1993-03-21 12:45:37 +03:00
|
|
|
standoutend();
|
|
|
|
|
|
|
|
xwaitforspace(s);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.toplin && tly > 1) {
|
1993-03-21 12:45:37 +03:00
|
|
|
home();
|
|
|
|
cl_end();
|
1997-10-19 20:56:41 +04:00
|
|
|
docorner(1, tly - 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
flags.toplin = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
more()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
xmore("");
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
cmore(s)
|
2001-03-26 00:43:58 +04:00
|
|
|
const char *s;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
xmore(s);
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
clrlin()
|
|
|
|
{
|
|
|
|
if (flags.toplin) {
|
1993-03-21 12:45:37 +03:00
|
|
|
home();
|
|
|
|
cl_end();
|
1997-10-19 20:56:41 +04:00
|
|
|
if (tly > 1)
|
|
|
|
docorner(1, tly - 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
remember_topl();
|
|
|
|
}
|
|
|
|
flags.toplin = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
pline(const char *fmt, ...)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
va_list ap;
|
2002-05-26 04:12:11 +04:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vpline(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
vpline(line, ap)
|
|
|
|
const char *line;
|
|
|
|
va_list ap;
|
|
|
|
{
|
|
|
|
char pbuf[BUFSZ];
|
|
|
|
char *bp = pbuf, *tl;
|
|
|
|
int n, n0;
|
|
|
|
|
|
|
|
if (!line || !*line)
|
|
|
|
return;
|
|
|
|
if (!strchr(line, '%'))
|
|
|
|
(void) strcpy(pbuf, line);
|
|
|
|
else
|
|
|
|
(void) vsprintf(pbuf, line, ap);
|
|
|
|
if (flags.toplin == 1 && !strcmp(pbuf, toplines))
|
|
|
|
return;
|
|
|
|
nscr(); /* %% */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* If there is room on the line, print message on same line */
|
|
|
|
/* But messages like "You die..." deserve their own line */
|
|
|
|
n0 = strlen(bp);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.toplin == 1 && tly == 1 &&
|
|
|
|
n0 + strlen(toplines) + 3 < CO - 8 && /* leave room for
|
|
|
|
* --More-- */
|
1993-03-21 12:45:37 +03:00
|
|
|
strncmp(bp, "You ", 4)) {
|
|
|
|
(void) strcat(toplines, " ");
|
|
|
|
(void) strcat(toplines, bp);
|
|
|
|
tlx += 2;
|
|
|
|
addtopl(bp);
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.toplin == 1)
|
|
|
|
more();
|
1993-03-21 12:45:37 +03:00
|
|
|
remember_topl();
|
|
|
|
toplines[0] = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (n0) {
|
|
|
|
if (n0 >= CO) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* look for appropriate cut point */
|
|
|
|
n0 = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (n = 0; n < CO; n++)
|
|
|
|
if (bp[n] == ' ')
|
|
|
|
n0 = n;
|
|
|
|
if (!n0)
|
|
|
|
for (n = 0; n < CO - 1; n++)
|
|
|
|
if (!letter(bp[n]))
|
|
|
|
n0 = n;
|
|
|
|
if (!n0)
|
|
|
|
n0 = CO - 2;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
(void) strncpy((tl = eos(toplines)), bp, n0);
|
|
|
|
tl[n0] = 0;
|
|
|
|
bp += n0;
|
|
|
|
|
|
|
|
/* remove trailing spaces, but leave one */
|
1997-10-19 20:56:41 +04:00
|
|
|
while (n0 > 1 && tl[n0 - 1] == ' ' && tl[n0 - 2] == ' ')
|
1993-03-21 12:45:37 +03:00
|
|
|
tl[--n0] = 0;
|
|
|
|
|
|
|
|
n0 = strlen(bp);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (n0 && tl[0])
|
|
|
|
(void) strcat(tl, "\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
redotoplin();
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
putsym(c)
|
|
|
|
char c;
|
|
|
|
{
|
|
|
|
switch (c) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case '\b':
|
|
|
|
backsp();
|
|
|
|
return;
|
|
|
|
case '\n':
|
|
|
|
curx = 1;
|
|
|
|
cury++;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (cury > tly)
|
|
|
|
tly = cury;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
default:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (curx == CO)
|
1993-03-21 12:45:37 +03:00
|
|
|
putsym('\n'); /* 1 <= curx <= CO; avoid CO */
|
|
|
|
else
|
|
|
|
curx++;
|
|
|
|
}
|
|
|
|
(void) putchar(c);
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
putstr(s)
|
2001-03-26 00:43:58 +04:00
|
|
|
const char *s;
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
while (*s)
|
|
|
|
putsym(*s++);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|