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
;
27 last_redone_topl
= old_toplines
;
29 strcpy(toplines
, last_redone_topl
->topl_text
);
39 if(index(toplines
, '\n')) cl_end();
54 if(last_redone_topl
&&
55 !strcmp(toplines
, last_redone_topl
->topl_text
)) return;
57 !strcmp(toplines
, old_toplines
->topl_text
)) return;
60 alloc((unsigned)(strlen(toplines
) + sizeof(struct topl
) + 1));
61 tl
->next_topl
= old_toplines
;
62 tl
->topl_text
= (char *)(tl
+ 1);
63 strcpy(tl
->topl_text
, toplines
);
69 if(tl
&& tl
->next_topl
){
70 free((char *) tl
->next_topl
);
76 addtopl(const char *s
)
79 if(tlx
+ (int)strlen(s
) > CO
) putsym('\n');
87 xmore(const char *s
) /* allowed chars besides space/return */
91 if(tlx
+ 8 > CO
) putsym('\n'), tly
++;
101 if(flags
.toplin
&& tly
> 1) {
127 if(tly
> 1) docorner(1, tly
-1);
134 pline(const char *line
, ...)
144 vpline(const char *line
, va_list ap
)
147 char *bp
= pbuf
, *tl
;
150 if(!line
|| !*line
) return;
151 if(!index(line
, '%')) strcpy(pbuf
,line
); else
152 vsprintf(pbuf
, line
, ap
);
153 if(flags
.toplin
== 1 && !strcmp(pbuf
, toplines
)) return;
156 /* If there is room on the line, print message on same line */
157 /* But messages like "You die..." deserve their own line */
159 if(flags
.toplin
== 1 && tly
== 1 &&
160 n0
+ (int)strlen(toplines
) + 3 < CO
-8 && /* room for --More-- */
161 strncmp(bp
, "You ", 4)) {
162 strcat(toplines
, " ");
163 strcat(toplines
, bp
);
168 if(flags
.toplin
== 1) more();
173 /* look for appropriate cut point */
175 for(n
= 0; n
< CO
; n
++) if(bp
[n
] == ' ')
177 if(!n0
) for(n
= 0; n
< CO
-1; n
++)
178 if(!letter(bp
[n
])) n0
= n
;
181 strncpy((tl
= eos(toplines
)), bp
, n0
);
185 /* remove trailing spaces, but leave one */
186 while(n0
> 1 && tl
[n0
-1] == ' ' && tl
[n0
-2] == ' ')
190 if(n0
&& tl
[0]) strcat(tl
, "\n");
205 if(cury
> tly
) tly
= cury
;
209 putsym('\n'); /* 1 <= curx <= CO; avoid CO */
217 putstr(const char *s
)
219 while(*s
) putsym(*s
++);