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 $ */
4 /* $DragonFly: src/games/hack/hack.topl.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
10 xchar tlx, tly; /* set by pline; used by addtopl */
13 struct topl *next_topl;
15 } *old_toplines, *last_redone_topl;
16 #define OTLMAX 20 /* max nr of old toplines remembered */
18 static void redotoplin(void);
19 static void xmore(const char *);
25 last_redone_topl = last_redone_topl->next_topl;
26 if (!last_redone_topl)
27 last_redone_topl = old_toplines;
29 strcpy(toplines, last_redone_topl->topl_text);
38 if (strchr(toplines, '\n'))
55 if (last_redone_topl &&
56 !strcmp(toplines, last_redone_topl->topl_text))
59 !strcmp(toplines, old_toplines->topl_text))
62 tl = alloc((unsigned)(strlen(toplines) + sizeof(struct topl) + 1));
63 tl->next_topl = old_toplines;
64 tl->topl_text = (char *)(tl + 1);
65 strcpy(tl->topl_text, toplines);
71 if (tl && tl->next_topl) {
78 addtopl(const char *s)
81 if (tlx + (int)strlen(s) > CO)
90 xmore(const char *s) /* allowed chars besides space/return */
105 if (flags.toplin && tly > 1) {
108 docorner(1, tly - 1);
132 docorner(1, tly - 1);
139 pline(const char *line, ...)
149 vpline(const char *line, va_list ap)
152 char *bp = pbuf, *tl;
157 if (!strchr(line, '%'))
160 vsprintf(pbuf, line, ap);
161 if (flags.toplin == 1 && !strcmp(pbuf, toplines))
165 /* If there is room on the line, print message on same line */
166 /* But messages like "You die..." deserve their own line */
168 if (flags.toplin == 1 && tly == 1 &&
169 n0 + (int)strlen(toplines) + 3 < CO - 8 && /* room for --More-- */
170 strncmp(bp, "You ", 4)) {
171 strcat(toplines, " ");
172 strcat(toplines, bp);
177 if (flags.toplin == 1)
183 /* look for appropriate cut point */
185 for (n = 0; n < CO; n++)
189 for (n = 0; n < CO - 1; n++)
195 strncpy((tl = eos(toplines)), bp, n0);
199 /* remove trailing spaces, but leave one */
200 while (n0 > 1 && tl[n0 - 1] == ' ' && tl[n0 - 2] == ' ')
225 putsym('\n'); /* 1 <= curx <= CO; avoid CO */
233 putstr(const char *s)