-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv_debug.c
184 lines (161 loc) · 3.49 KB
/
v_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
/*
* V_DEBUG Version 1.0 4/16/85
* Jordan K. Hubbard
*/
#include "vstr.h"
#include <stdio.h>
#include <stdlib.h>
#define PUSH 1
#define POP 2
#define LOOK 3
#ifdef DEBUG
char *id();
ROUTINE void yelp(fmt, p1, p2, p3, p4, p5, p6)
register char *fmt;
register unsigned char *p1, *p2, *p3, *p4, *p5, *p6;
{
fprintf(stderr, "DEBUG: [%s] ", id(0, LOOK));
fprintf(stderr, fmt, p1, p2, p3, p4, p5, p6);
return;
}
ROUTINE char *id(s, mode)
register char *s;
register int mode;
{
/* if we get more than 50 subroutine levels deep, something's wrong */
/* with our program anyway (or we've taken modular programming too far!) */
static char *stack[50];
static int pointer = 0;
switch (mode) {
case PUSH:
stack[pointer++] = s;
if (pointer == 50) {
yelp("stack overflow in id!\n");
exit(1);
}
break;
case POP:
if (pointer - 1 < 0) {
yelp("stack underflow in id!\n");
exit(1);
}
return(stack[--pointer]);
break;
case LOOK:
if (pointer - 1 < 0) {
yelp("empty stack for 'look' in id!\n");
exit(1);
}
return(stack[pointer - 1]);
break;
}
}
ROUTINE void _end()
{
yelp("Exiting with no returned value\n");
id(0, POP);
return;
}
ROUTINE void _entry(s)
register char *s;
{
id(s, PUSH);
yelp("Entering\n");
return;
}
ROUTINE void _ret(l)
unsigned char *l;
{
yelp("Exiting with %u (hex: %x)\n", l, l);
id(0, POP);
return;
}
#else
EXPORT char *_Curr_rtn;
#endif
/* Makes character 'visible' by turning it into a printable control */
/* character if it is one or its octal \nnn form if it is greater than */
/* the upper limit for printable ascii */
ROUTINE char *visible(ch)
register char ch;
{
static char buf[5];
entry(visible)
buf[0] = '\0';
if (ch < 32) {
buf[0] = '^';
ch += 64;
}
if (ch > 31 && ch < 127) {
if (buf[0]) {
buf[1] = ch;
buf[2] = '\0';
}
else {
buf[0] = ch;
buf[1] = '\0';
}
}
else if (ch > 126) {
sprintf(buf, "\\%03o", ch);
buf[4] = '\0';
}
ret(buf)
}
ROUTINE void v_show(v)
register p_vstr v;
{
register p_unit temp;
register int n_units = 0, n_chars = 0, l;
register int n_funits = 0;
entry(v_show)
if (!v) {
fprintf(stderr, "v_show: vstr is NIL\n");
end
}
fprintf(stderr, "Debugging information for vstr at %p\n", v);
fprintf(stderr, "Head is at %p, Tail at %p\n", v->head, v->tail);
fprintf(stderr, "Unit size is %d\n", v->unit_size);
fprintf(stderr, "Cursor points to unit %p, position %d\n\n",
v->cur.here, v->cur.u_pos);
temp = v->head;
while (temp) {
fprintf(stderr, "prev unit next\n");
fprintf(stderr, "(%p) <= [%p] => (%p) ", temp->prev, temp,
temp->next);
if (temp == v->head)
fprintf(stderr, "HEAD ");
if (temp == v->tail)
fprintf(stderr, "TAIL ");
fprintf(stderr, "#%d\n", n_units);
fprintf(stderr, "\tLength = %d", temp->len);
if (temp->len) {
n_chars += temp->len;
fprintf(stderr, " Data = '");
for (l = 0; l < temp->len; l++)
fprintf(stderr, "%s", visible(temp->data[l]));
fprintf(stderr, "'\n\n");
if (temp->len == v->unit_size)
n_funits++;
}
else
fprintf(stderr, "\n\n");
temp = temp->next;
n_units++;
}
fprintf(stderr, "\n\nTotal: %d characters in %d units. %d full, %d not.\n",
n_chars, n_units, n_funits, n_units - n_funits);
end
}
ROUTINE void freak_out(fmt, p1, p2, p3, p4, p5, p6)
register char *fmt;
register int p1, p2, p3, p4, p5, p6;
{
#ifdef DEBUG
fprintf(stderr, "%s: ", id(0, LOOK));
#else
fprintf(stderr, "%s: ", _Curr_rtn);
#endif
fprintf(stderr, fmt, p1, p2, p3, p4, p5, p6);
exit(1);
}