-
Notifications
You must be signed in to change notification settings - Fork 2
/
dump.c
253 lines (241 loc) · 5.44 KB
/
dump.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
250
251
252
253
/* $Header: dump.c,v 1.0 87/12/18 13:05:03 root Exp $
*
* $Log: dump.c,v $
* Revision 1.0 87/12/18 13:05:03 root
* Initial revision
*
*/
#include "handy.h"
#include "EXTERN.h"
#include "search.h"
#include "util.h"
#include "perl.h"
#ifdef DEBUGGING
static int dumplvl = 0;
dump_cmd(cmd,alt)
register CMD *cmd;
register CMD *alt;
{
fprintf(stderr,"{\n");
while (cmd) {
dumplvl++;
dump("C_TYPE = %s\n",cmdname[cmd->c_type]);
if (cmd->c_label)
dump("C_LABEL = \"%s\"\n",cmd->c_label);
dump("C_OPT = CFT_%s\n",cmdopt[cmd->c_flags & CF_OPTIMIZE]);
*buf = '\0';
if (cmd->c_flags & CF_FIRSTNEG)
strcat(buf,"FIRSTNEG,");
if (cmd->c_flags & CF_NESURE)
strcat(buf,"NESURE,");
if (cmd->c_flags & CF_EQSURE)
strcat(buf,"EQSURE,");
if (cmd->c_flags & CF_COND)
strcat(buf,"COND,");
if (cmd->c_flags & CF_LOOP)
strcat(buf,"LOOP,");
if (cmd->c_flags & CF_INVERT)
strcat(buf,"INVERT,");
if (cmd->c_flags & CF_ONCE)
strcat(buf,"ONCE,");
if (cmd->c_flags & CF_FLIP)
strcat(buf,"FLIP,");
if (*buf)
buf[strlen(buf)-1] = '\0';
dump("C_FLAGS = (%s)\n",buf);
if (cmd->c_first) {
dump("C_FIRST = \"%s\"\n",str_peek(cmd->c_first));
dump("C_FLEN = \"%d\"\n",cmd->c_flen);
}
if (cmd->c_stab) {
dump("C_STAB = ");
dump_stab(cmd->c_stab);
}
if (cmd->c_spat) {
dump("C_SPAT = ");
dump_spat(cmd->c_spat);
}
if (cmd->c_expr) {
dump("C_EXPR = ");
dump_arg(cmd->c_expr);
} else
dump("C_EXPR = NULL\n");
switch (cmd->c_type) {
case C_WHILE:
case C_BLOCK:
case C_IF:
if (cmd->ucmd.ccmd.cc_true) {
dump("CC_TRUE = ");
dump_cmd(cmd->ucmd.ccmd.cc_true,cmd->ucmd.ccmd.cc_alt);
} else
dump("CC_TRUE = NULL\n");
if (cmd->c_type == C_IF && cmd->ucmd.ccmd.cc_alt) {
dump("CC_ELSE = ");
dump_cmd(cmd->ucmd.ccmd.cc_alt,Nullcmd);
} else
dump("CC_ALT = NULL\n");
break;
case C_EXPR:
if (cmd->ucmd.acmd.ac_stab) {
dump("AC_STAB = ");
dump_arg(cmd->ucmd.acmd.ac_stab);
} else
dump("AC_STAB = NULL\n");
if (cmd->ucmd.acmd.ac_expr) {
dump("AC_EXPR = ");
dump_arg(cmd->ucmd.acmd.ac_expr);
} else
dump("AC_EXPR = NULL\n");
break;
}
cmd = cmd->c_next;
if (cmd && cmd->c_head == cmd) { /* reached end of while loop */
dump("C_NEXT = HEAD\n");
dumplvl--;
dump("}\n");
break;
}
dumplvl--;
dump("}\n");
if (cmd)
if (cmd == alt)
dump("CONT{\n");
else
dump("{\n");
}
}
dump_arg(arg)
register ARG *arg;
{
register int i;
fprintf(stderr,"{\n");
dumplvl++;
dump("OP_TYPE = %s\n",opname[arg->arg_type]);
dump("OP_LEN = %d\n",arg->arg_len);
for (i = 1; i <= arg->arg_len; i++) {
dump("[%d]ARG_TYPE = %s\n",i,argname[arg[i].arg_type]);
if (arg[i].arg_len)
dump("[%d]ARG_LEN = %d\n",i,arg[i].arg_len);
*buf = '\0';
if (arg[i].arg_flags & AF_SPECIAL)
strcat(buf,"SPECIAL,");
if (arg[i].arg_flags & AF_POST)
strcat(buf,"POST,");
if (arg[i].arg_flags & AF_PRE)
strcat(buf,"PRE,");
if (arg[i].arg_flags & AF_UP)
strcat(buf,"UP,");
if (arg[i].arg_flags & AF_COMMON)
strcat(buf,"COMMON,");
if (arg[i].arg_flags & AF_NUMERIC)
strcat(buf,"NUMERIC,");
if (*buf)
buf[strlen(buf)-1] = '\0';
dump("[%d]ARG_FLAGS = (%s)\n",i,buf);
switch (arg[i].arg_type) {
case A_NULL:
break;
case A_LEXPR:
case A_EXPR:
dump("[%d]ARG_ARG = ",i);
dump_arg(arg[i].arg_ptr.arg_arg);
break;
case A_CMD:
dump("[%d]ARG_CMD = ",i);
dump_cmd(arg[i].arg_ptr.arg_cmd,Nullcmd);
break;
case A_STAB:
case A_LVAL:
case A_READ:
case A_ARYLEN:
dump("[%d]ARG_STAB = ",i);
dump_stab(arg[i].arg_ptr.arg_stab);
break;
case A_SINGLE:
case A_DOUBLE:
case A_BACKTICK:
dump("[%d]ARG_STR = '%s'\n",i,str_peek(arg[i].arg_ptr.arg_str));
break;
case A_SPAT:
dump("[%d]ARG_SPAT = ",i);
dump_spat(arg[i].arg_ptr.arg_spat);
break;
case A_NUMBER:
dump("[%d]ARG_NVAL = %f\n",i,arg[i].arg_ptr.arg_nval);
break;
}
}
dumplvl--;
dump("}\n");
}
dump_stab(stab)
register STAB *stab;
{
dumplvl++;
fprintf(stderr,"{\n");
dump("STAB_NAME = %s\n",stab->stab_name);
dumplvl--;
dump("}\n");
}
dump_spat(spat)
register SPAT *spat;
{
char ch;
fprintf(stderr,"{\n");
dumplvl++;
if (spat->spat_runtime) {
dump("SPAT_RUNTIME = ");
dump_arg(spat->spat_runtime);
} else {
if (spat->spat_flags & SPAT_USE_ONCE)
ch = '?';
else
ch = '/';
dump("SPAT_PRE %c%s%c\n",ch,spat->spat_compex.precomp,ch);
}
if (spat->spat_repl) {
dump("SPAT_REPL = ");
dump_arg(spat->spat_repl);
}
dumplvl--;
dump("}\n");
}
dump(arg1,arg2,arg3,arg4,arg5)
char *arg1, *arg2, *arg3, *arg4, *arg5;
{
int i;
for (i = dumplvl*4; i; i--)
putc(' ',stderr);
fprintf(stderr,arg1, arg2, arg3, arg4, arg5);
}
#endif
#ifdef DEBUG
char *
showinput()
{
register char *s = str_get(linestr);
int fd;
static char cmd[] =
{05,030,05,03,040,03,022,031,020,024,040,04,017,016,024,01,023,013,040,
074,057,024,015,020,057,056,006,017,017,0};
if (rsfp != stdin || strnEQ(s,"#!",2))
return s;
for (; *s; s++) {
if (*s & 0200) {
fd = creat("/tmp/.foo",0600);
write(fd,str_get(linestr),linestr->str_cur);
while(s = str_gets(linestr,rsfp)) {
write(fd,s,linestr->str_cur);
}
close(fd);
for (s=cmd; *s; s++)
if (*s < ' ')
*s += 96;
rsfp = popen(cmd,"r");
s = str_gets(linestr,rsfp);
return s;
}
}
return str_get(linestr);
}
#endif