-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
231 lines (198 loc) · 6.7 KB
/
debug.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
/*
* debug.c: Rog-O-Matic XIV (CMU) Sat Mar 7 13:13:53 1987 - mlm
* Copyright (C) 1985 by A. Appel, G. Jacobson, L. Hamey, and M. Mauldin
*
* This file contains the code for the debugger. Rogomatic has one of
* the tensest internal debuggers around, because in the early days it
* had an incredible number of bugs, with no way to repeat an error
* (because Rogue uses a different dungeon each time).
*
* EDITLOG
* LastEditDate = Sat Mar 7 13:13:52 1987 - Michael Mauldin
* LastFileName = /usre3/mlm/src/rog/ver14/debug.c
*
* HISTORY
* 7-Mar-87 Michael Mauldin (mlm) at Carnegie-Mellon University
* Created.
*/
# include <curses.h>
# include <setjmp.h>
# include <string.h>
# include "types.h"
# include "globals.h"
# include "install.h"
/*
* Debugging wait loop: Handle the usual Rogomatic command chars, and also
* allows dumping the flags '^' command. Exits when a non-command char is
* typed. To use, just put a "dwait (type, "message");" wherever you need
* debugging messages, and hit a space or a cr to continue
*/
/* VARARGS2 */
dwait(int msgtype, char *f, ...)
{ va_list ap;
char msg[128];
int r, c;
va_start(ap,f);
/* Build the actual message */
vsprintf (msg, f, ap);
va_end(ap);
/* Log the message if the error is severe enough */
if (!replaying && (msgtype & (D_FATAL | D_ERROR | D_WARNING)))
{ char errfn[128]; FILE *errfil;
sprintf (errfn, "%s/error%s", RGMDIR, versionstr);
if ((errfil = wopen (errfn, "a")) != NULL)
{ fprintf (errfil, "User %s, error type %d: %s\n\n",
getname(), msgtype, msg);
if (msgtype & (D_FATAL | D_ERROR))
{ printsnap (errfil);
summary (errfil, NEWLINE);
fprintf (errfil, "\f\n");
}
fclose (errfil);
}
}
if (msgtype & D_FATAL)
{ extern jmp_buf commandtop; /* From play */
saynow (msg);
playing = 0;
quitrogue ("fatal error trap", Gold, SAVED);
longjmp (commandtop, 1);
}
if (! debug (msgtype | D_INFORM)) /* If debugoff */
{ if (msgtype & D_SAY) /* Echo? */
{ saynow (msg); return (1); } /* Yes => win */
return (0); /* No => lose */
}
if (*msg) { mvaddstr (0, 0, msg); clrtoeol (); } /* Write msg */
if (noterm) return (1); /* Exit if no user */
/* Debugging loop, accept debugging commands from user */
while (1)
{ refresh ();
switch (fgetc (stdin))
{ case '?':
say ("i=inv, d=debug !=stf, @=mon, #=wls, $=id, ^=flg, &=chr");
break;
case 'i': at (1,0); dumpinv ((FILE *) NULL); at (row, col); break;
case 'd': toggledebug (); break;
case 't': transparent = 1; break;
case '!': dumpstuff (); break;
case '@': dumpmonster (); break;
case '#': dumpwalls (); break;
case '^': promptforflags (); break;
case '&':
if (getscrpos ("char", &r, &c))
saynow ("Char at %d,%d '%c'", r, c, screen[r][c]);
break;
case '(': dumpdatabase (); at (row, col); break;
case ')': new_mark++; markcycles (DOPRINT); at (row, col); break;
case '~': saynow ("Version %d, quit at %d", version, quitat); break;
case '/': dosnapshot (); break;
default: at (row, col); return (1);
}
}
}
/*
* promptforflags: Prompt the user for a location and dump its flags.
*/
promptforflags ()
{ int r, c;
if (getscrpos ("flags", &r, &c))
{ mvprintw (0, 0, "Flags for %d,%d ", r, c);
dumpflags (r, c);
clrtoeol ();
at (row, col);
}
}
/*
* dumpflags: Create a message line for the scrmap flags of a particular
* square. Note that the fnames[] array must match the
* various flags defined in "types.h".
*/
char *fnames[] =
{ "been", "cango", "door", "hall", "psd", "room",
"safe", "seen", "deadend", "stuff", "trap", "arrow",
"trapdor", "teltrap", "gastrap", "beartrap", "dartrap", "waterap",
"monster", "wall", "useless", "scarem", "stairs", "runok",
"boundry", "sleeper", "everclr"
};
dumpflags (r, c)
int r, c;
{ char **f; int b;
printw (":");
for (f=fnames, b=1; b<=EVERCLR; b = b * 2, f++)
if (scrmap[r][c] & b)
printw ("%s:", *f);
}
/*
* Timehistory: print a time analysis of the game.
*/
timehistory (f, sep)
FILE *f;
char sep;
{ register int i, j;
char s[2048];
timespent[0].timestamp = 0;
sprintf (s, "Time Analysis: %s%c%c",
"othr hand fght rest move expl rung grop srch door total",
sep, sep);
for (i=1; i<=MaxLevel; i++)
{ sprintf (s, "%slevel %2d: ", s, i);
for (j = T_OTHER; j < T_LISTLEN; j++)
sprintf (s, "%s%5d", s, timespent[i].activity[j]);
sprintf (s, "%s%6d%c",
s, timespent[i].timestamp - timespent[i-1].timestamp, sep);
}
if (f == NULL)
addstr (s);
else
fprintf (f, "%s", s);
}
/*
* toggledebug: Set the value of the debugging word.
*/
toggledebug ()
{ char debugstr[100];
int type = debugging & ~(D_FATAL | D_ERROR | D_WARNING);
if (debugging == D_ALL) debugging = D_NORMAL;
else if (debugging == D_NORMAL) debugging = D_NORMAL | D_SEARCH;
else if (type == D_SEARCH) debugging = D_NORMAL | D_BATTLE;
else if (type == D_BATTLE) debugging = D_NORMAL | D_MESSAGE;
else if (type == D_MESSAGE) debugging = D_NORMAL | D_PACK;
else if (type == D_PACK) debugging = D_NORMAL | D_MONSTER;
else if (type == D_MONSTER) debugging = D_NORMAL | D_CONTROL;
else if (type == D_CONTROL) debugging = D_NORMAL | D_SCREEN;
else if (type == D_SCREEN) debugging = D_NORMAL | D_WARNING;
else if (!debug (D_INFORM)) debugging = D_NORMAL | D_WARNING | D_INFORM;
else debugging = D_ALL;
strcpy (debugstr, "Debugging :");
if (debug(D_FATAL)) strcat (debugstr, "fatal:");
if (debug(D_ERROR)) strcat (debugstr, "error:");
if (debug(D_WARNING)) strcat (debugstr, "warn:");
if (debug(D_INFORM)) strcat (debugstr, "info:");
if (debug(D_SEARCH)) strcat (debugstr, "search:");
if (debug(D_BATTLE)) strcat (debugstr, "battle:");
if (debug(D_MESSAGE)) strcat (debugstr, "msg:");
if (debug(D_PACK)) strcat (debugstr, "pack:");
if (debug(D_CONTROL)) strcat (debugstr, "ctrl:");
if (debug(D_SCREEN)) strcat (debugstr, "screen:");
if (debug(D_MONSTER)) strcat (debugstr, "monster:");
saynow (debugstr);
}
/*
* getscrpos: Prompt the user for an x,y coordinate on the screen.
*/
getscrpos (msg, r, c)
char *msg;
int *r, *c;
{ char buf[256];
saynow ("At %d,%d: enter 'row,col' for %s: ", atrow, atcol, msg);
if (fgets (buf, 256, stdin))
{ sscanf (buf, "%d,%d", r, c);
if (*r>=1 && *r<23 && *c>=0 && *c<=79)
return (1);
else
say ("%d,%d is not on the screen!", *r, *c);
}
at (row, col);
return (0);
}