-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathio.c
249 lines (215 loc) · 4.94 KB
/
io.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Various input/output functions
*
* @(#)io.c 3.10 (Berkeley) 6/15/81
*/
#include "curses.h"
#include "io.h"
#include "rogue.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
/*
* msg:
* Display a message at the top of the screen.
*/
static char msgbuf[COLS+1];
static char end = 0;
static int next_pos = 0;
/*VARARGS1*/
void msg(const char* fmt, ...)
{
va_list varargs;
/*
* if the string is "", just clear the line
*/
if (*fmt == '\0')
{
wmove(cw, 0, 0);
wclrtoeol(cw);
mpos = 0;
return;
}
/*
* otherwise add to the message and flush it out
*/
va_start(varargs, fmt);
doadd(fmt, varargs);
va_end(varargs);
endmsg();
}
/*
* add things to the current message
*/
void addmsg(char *fmt, ...)
{
va_list varargs;
va_start(varargs, fmt);
doadd(fmt, varargs);
va_end(varargs);
}
/*
* Display a new msg (giving him a chance to see the previous one if it
* is up there with the --More--)
*/
void endmsg(void)
{
strcpy(huh, msgbuf);
if (mpos)
{
wmove(cw, 0, mpos);
waddstr(cw, "--More--");
//draw(cw);
wait_for(' ');
}
mvwaddstr(cw, 0, 0, msgbuf);
mvwinch(cw, 0, next_pos);
wclrtoeol(cw);
mpos = next_pos;
next_pos = 0;
//draw(cw);
}
void doadd(const char* fmt, va_list varargs)
{
// debug_char("do add msgbuf[0]", msgbuf[0]);
// debug_char("do add msgbuf[1]", msgbuf[1]);
// debug_char("do add msgbuf[2]", msgbuf[2]);
// debug_char("do add msgbuf[3]", msgbuf[3]);
// debug_char("do add msgbuf[4]", msgbuf[4]);
// debug_char("do add msgbuf[5]", msgbuf[5]);
// debug_char("do add msgbuf[6]", msgbuf[6]);
// debug_char("do add msgbuf[7]", msgbuf[7]);
// debug_char("do add msgbuf[8]", msgbuf[8]);
// debug_char("do add msgbuf[9]", msgbuf[9]);
// debug_char("do add msgbuf[10]", msgbuf[10]);
// debug_char("do add msgbuf[11]", msgbuf[11]);
vsprintf(&msgbuf[next_pos], fmt, varargs);
// debug_char("msgbuf[0]", msgbuf[0]);
// debug_char("msgbuf[1]", msgbuf[1]);
// debug_char("msgbuf[2]", msgbuf[2]);
// debug_char("msgbuf[3]", msgbuf[3]);
// debug_char("msgbuf[4]", msgbuf[4]);
// debug_char("msgbuf[5]", msgbuf[5]);
// debug_char("msgbuf[6]", msgbuf[6]);
// debug_char("msgbuf[7]", msgbuf[7]);
// debug_char("msgbuf[8]", msgbuf[8]);
// debug_char("msgbuf[9]", msgbuf[9]);
// debug_char("msgbuf[10]", msgbuf[10]);
// debug_char("msgbuf[11]", msgbuf[11]);
next_pos = strlen(msgbuf);
// debug_num("next_pos", next_pos);
// static FILE junk;
/*
* Do the printf into buf
*/
// junk._flag = _IOWRT + _IOSTRG;
// junk._ptr = &msgbuf[newpos];
// junk._cnt = 32767;
// _doprnt(fmt, args, &junk);
// putc('\0', &junk);
// newpos = strlen(msgbuf);
}
/*
* step_ok:
* returns true if it is ok to step on ch
*/
bool step_ok(char ch)
{
switch (ch)
{
case ' ':
case '|':
case '-':
case SECRETDOOR:
return FALSE;
default:
return (!isalpha(ch));
}
}
/*
* readchar:
* flushes stdout so that screen is up to date and then returns
* getchar.
*/
//readchar()
//{
// char c;
//
// fflush(stdout);
// while (read(0, &c, 1) < 0)
// continue;
// return c;
//}
/*
* unctrl:
* Print a readable version of a certain character
*/
//char *
//unctrl(ch)
//char ch;
//{
// extern char *_unctrl[]; /* Defined in curses library */
//
// return _unctrl[ch&0177];
//}
/*
* status:
* Display the important stats line. Keep the cursor where it was.
*/
void status(void)
{
char *hungry_description, *status_bar;
switch (hungry_state)
{
case 1: hungry_description = " Hungry";
case 2: hungry_description = " Weak";
case 3: hungry_description = " Fainting";
default: hungry_description = "";
}
sprintf(msgbuf, "Level: %d Gold: %-5d Hp: %d(%d) Str: %-2d/%d Ac: %-2d Exp: %d/%ld %s",
level,
purse,
pstats.s_hpt,
max_hp,
pstats.s_str.st_str,
pstats.s_str.st_add,
cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm,
pstats.s_lvl,
pstats.s_exp,
/*get_hunger_state()*/ "Hungry");
cputsxy(0, 23, msgbuf);
}
//const char *get_hunger_state() {
//
//}
/*
* wait_for
* Sit around until the guy types the right key
*/
void wait_for(char ch)
{
register char c;
// if (ch == '\n')
// while ((c = cgetc()) != '\n' && c != '\r')
// continue;
// else
while (cgetc() != ch)
continue;
}
/*
* show_win:
* function used to display a window and wait before returning
*/
//show_win(scr, message)
//register WINDOW *scr;
//char *message;
//{
// mvwaddstr(scr, 0, 0, message);
// touchwin(scr);
// wmove(scr, hero.y, hero.x);
// draw(scr);
// wait_for(' ');
// clearok(cw, TRUE);
// touchwin(cw);
//}