VPDF compiles and links but exits early after start.
[AROS-Contrib.git] / rexx / src / trace.c
blob281f7f41d47160127a8ecfcf9020fcb4725b3e0d
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:39 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.3 1999/11/26 13:13:47 bnv
8 * Changed: To use the new macros.
9 * Changed: To support 64-bit cpus.
11 * Revision 1.2 1999/03/10 16:55:35 bnv
12 * A bracket addition to keep compiler happy.
14 * Revision 1.1 1998/07/02 17:34:50 bnv
15 * Initial revision
19 #define __TRACE_C__
21 #include <stdlib.h>
22 #include <lstring.h>
24 #include <rexx.h>
25 #include <trace.h>
26 #include <compile.h>
27 #include <interpre.h>
28 #include <variable.h>
29 #include <nextsymb.h>
31 /* ---------- function prototypes ------------- */
32 void RxInitInterStr();
34 /* ---------- Extern variables ---------------- */
35 extern Clause *CompileClause; /* compile clauses */
36 extern int CompileCurClause; /* current clause */
37 extern ErrorMsg errortext[]; /* from lstring/errortxt.c */
38 extern bool _in_nextsymbol; /* from nextsymb.c */
39 extern int _trace; /* from interpret.c */
40 extern PLstr RxStck[]; /* -//- */
41 extern int RxStckTop; /* -//- */
42 extern Lstr _tmpstr[]; /* -//- */
44 static char TraceChar[] = {' ','>','L','V','C','O','F','.'};
46 /* ----------------- TraceCurline ----------------- */
47 int
48 TraceCurline( RxFile **rxf, int print )
50 size_t line;
51 size_t cl, codepos;
52 char *ch, *chend;
54 if (symbolptr==NULL) { /* we are in intepret */
55 if (CompileClause==NULL) {
56 if (rxf) *rxf = rxfile;
57 return -1;
60 codepos = (size_t)((byte huge *)Rxcip - (byte huge *)Rxcodestart);
61 /* search for clause */
62 cl = 0;
63 while (CompileClause[cl].ptr) {
64 if (CompileClause[cl].code >= codepos)
65 break;
66 cl++;
68 cl--;
69 line = CompileClause[cl].line;
70 ch = CompileClause[cl].ptr;
71 chend = CompileClause[cl+1].ptr;
72 if (chend==NULL)
73 for (chend=ch; *chend!='\n'; chend++) /*do nothing*/;;
74 _nesting = _rx_proc + CompileClause[cl].nesting;
75 if (rxf)
76 *rxf = CompileClause[ cl ].fptr;
77 } else { /* we are in compile */
78 if (CompileCurClause==0)
79 cl = 0;
80 else
81 cl = CompileCurClause-1;
83 _nesting = CompileClause[ cl ].nesting;
84 if (rxf) {
85 if (CompileCurClause==0)
86 *rxf = CompileRxFile;
87 else
88 *rxf = CompileClause[ cl ].fptr;
90 if (_in_nextsymbol) {
91 line = symboline;
92 ch = symbolptr;
93 while (ch>symbolprevptr)
94 if (*ch--=='\n') line--;
95 ch = symbolprevptr;
96 } else
97 if (cl==0) {
98 line = 1;
99 ch = LSTR((*rxf)->file);
100 } else {
101 cl = CompileCurClause-1;
102 line = CompileClause[ cl ].line;
103 ch = CompileClause[ cl ].ptr;
105 for (chend=ch; *chend!=';' && *chend!='\n'; chend++) /*do nothing*/;;
108 #ifndef WIN
109 if (print) {
110 int i;
112 fprintf(STDERR,"%6d *-* ",(int)line);
113 for (i=1; i<_nesting; i++) fputc(' ',STDERR);
115 while (*ch && ch<chend) {
116 if (*ch!='\n')
117 fputc(*ch,STDERR);
118 ch++;
120 fputc('\n',STDERR);
122 #else
123 if (print) {
124 int i;
126 PUTINT(line,6,10);
127 PUTS(" *-* ");
128 for (i=1; i<_nesting; i++) PUTCHAR(' ');
130 while (*ch && ch<chend) {
131 if (*ch!='\n')
132 PUTCHAR(*ch);
133 ch++;
135 PUTCHAR('\n');
137 #endif
138 return line;
139 } /* TraceCurline */
141 /* ---------------- TraceSet -------------------- */
142 void
143 TraceSet( PLstr trstr )
145 char *ch;
147 L2STR(trstr);
148 Lupper(trstr);
149 LASCIIZ(*trstr);
150 ch = LSTR(*trstr);
151 if (*ch=='!') {
152 ch++;
153 } else
154 if (*ch=='?') {
155 _Proc[_rx_proc].interactive_trace
156 = 1 - _Proc[_rx_proc].interactive_trace;
157 if (_Proc[_rx_proc].interactive_trace)
158 #ifndef WIN
159 fprintf(STDERR," +++ %s +++\n",errortext[2].errmsg);
160 #else
161 PUTS(" +++ ");
162 PUTS(errortext[0].errmsg);
163 PUTS(" +++\n");
164 #endif
165 ch++;
168 switch (*ch) {
169 case 'A':
170 _Proc[_rx_proc].trace = all_trace;
171 break;
172 case 'C':
173 _Proc[_rx_proc].trace = commands_trace;
174 break;
175 case 'E':
176 _Proc[_rx_proc].trace = error_trace;
177 break;
179 /// case 'F':
180 /// _Proc[_rx_proc].trace = ;
181 /// break;
183 case 'I':
184 _Proc[_rx_proc].trace = intermediates_trace;
185 break;
186 case 'L':
187 _Proc[_rx_proc].trace = labels_trace;
188 break;
189 case 'N':
190 _Proc[_rx_proc].trace = normal_trace;
191 break;
192 case 'O':
193 _Proc[_rx_proc].trace = off_trace;
194 _Proc[_rx_proc].interactive_trace = FALSE;
195 break;
196 case 'R':
197 _Proc[_rx_proc].trace = results_trace;
198 break;
199 case 'S':
200 _Proc[_rx_proc].trace = scan_trace;
201 break;
202 #ifdef __DEBUG__
203 case 'D':
204 __debug__ = 1-__debug__;
205 if (__debug__)
206 printf("\n\nInternal DEBUG starting...\n");
207 else
208 printf("\n\nInternal DEBUG ended\n");
209 break;
210 #endif
211 default:
212 Lerror(ERR_INVALID_TRACE,1,trstr);
214 } /* TraceSet */
216 /* --------------------- TraceByte -------------------- */
217 void
218 TraceByte( int middlechar )
220 byte tracebyte=0;
222 tracebyte |= (middlechar & TB_MIDDLECHAR);
223 tracebyte |= TB_TRACE;
225 _CodeAddByte( tracebyte );
226 } /* TraceByte */
228 /* ------------------ TraceClause ----------------- */
229 void
230 TraceClause( void )
232 if (_Proc[_rx_proc].interactive_trace) {
233 /* return if user specified a string for interactive trace */
234 if (TraceInteractive(TRUE))
235 return;
237 TraceCurline(NULL,TRUE);
238 } /* TraceClause */
240 /* ------------------ TraceInstruction ----------------- */
241 void
242 TraceInstruction( byte inst )
244 if ((inst & TB_MIDDLECHAR) != nothing_middle)
245 if (_Proc[_rx_proc].trace == intermediates_trace) {
246 int i;
247 #ifndef WIN
248 fprintf(STDERR," >%c> ",TraceChar[ inst & TB_MIDDLECHAR ]);
249 for (i=0; i<_nesting; i++) fputc(' ',STDERR);
250 fputc('\"',STDERR);
251 Lprint(STDERR,RxStck[RxStckTop]);
252 fprintf(STDERR,"\"\n");
253 #else
254 PUTS(" >");
255 PUTCHAR(TraceChar[ inst & TB_MIDDLECHAR ]);
256 PUTS("> ");
257 for (i=0; i<_nesting; i++) PUTCHAR(' ');
258 PUTCHAR('\"');
259 Lprint(NULL,RxStck[RxStckTop]);
260 PUTS("\"\n");
261 #endif
263 } /* TraceInstruction */
264 /* ---------------- TraceInteractive ------------------- */
266 TraceInteractive( int frominterpret )
268 /* Read the interactive string into a tmp var */
269 RxStckTop++;
270 RxStck[RxStckTop] = &(_tmpstr[RxStckTop]);
272 Lread(STDIN,RxStck[RxStckTop],LREADLINE);
273 if (!LLEN(*RxStck[RxStckTop])) {
274 RxStckTop--;
275 return FALSE;
278 _trace = FALSE;
280 RxInitInterStr();
281 _Proc[_rx_proc].calltype = CT_INTERACTIVE;
282 if (frominterpret) {
283 _Proc[_rx_proc].calltype = CT_INTERACTIVE;
284 /* lets go again to NEWCLAUSE */
285 #ifdef ALIGN
286 _Proc[_rx_proc].ip-=sizeof(dword);
287 #else
288 _Proc[_rx_proc].ip--;
289 #endif
291 return TRUE;
292 } /* TraceInteractive */