1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.topl.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.topl.c,v 1.3 1999/11/16 02:57:12 billf Exp $ */
9 xchar tlx, tly; /* set by pline; used by addtopl */
12 struct topl *next_topl;
14 } *old_toplines, *last_redone_topl;
15 #define OTLMAX 20 /* max nr of old toplines remembered */
17 static void redotoplin(void);
18 static void xmore(const char *);
24 last_redone_topl = last_redone_topl->next_topl;
25 if (!last_redone_topl)
26 last_redone_topl = old_toplines;
28 strcpy(toplines, last_redone_topl->topl_text);
37 if (strchr(toplines, '\n'))
54 if (last_redone_topl &&
55 !strcmp(toplines, last_redone_topl->topl_text))
58 !strcmp(toplines, old_toplines->topl_text))
60 last_redone_topl = NULL;
61 tl = alloc((unsigned)(strlen(toplines) + sizeof(struct topl) + 1));
62 tl->next_topl = old_toplines;
63 tl->topl_text = (char *)(tl + 1);
64 strcpy(tl->topl_text, toplines);
70 if (tl && tl->next_topl) {
77 addtopl(const char *s)
80 if (tlx + (int)strlen(s) > CO)
89 xmore(const char *s) /* allowed chars besides space/return */
104 if (flags.toplin && tly > 1) {
107 docorner(1, tly - 1);
131 docorner(1, tly - 1);
138 pline(const char *line, ...)
148 vpline(const char *line, va_list ap)
151 char *bp = pbuf, *tl;
156 if (!strchr(line, '%'))
159 vsprintf(pbuf, line, ap);
160 if (flags.toplin == 1 && !strcmp(pbuf, toplines))
164 /* If there is room on the line, print message on same line */
165 /* But messages like "You die..." deserve their own line */
167 if (flags.toplin == 1 && tly == 1 &&
168 n0 + (int)strlen(toplines) + 3 < CO - 8 && /* room for --More-- */
169 strncmp(bp, "You ", 4)) {
170 strcat(toplines, " ");
171 strcat(toplines, bp);
176 if (flags.toplin == 1)
182 /* look for appropriate cut point */
184 for (n = 0; n < CO; n++)
188 for (n = 0; n < CO - 1; n++)
194 strncpy((tl = eos(toplines)), bp, n0);
198 /* remove trailing spaces, but leave one */
199 while (n0 > 1 && tl[n0 - 1] == ' ' && tl[n0 - 2] == ' ')
224 putsym('\n'); /* 1 <= curx <= CO; avoid CO */
232 putstr(const char *s)