2 static char *RCSid
= "$Id$";
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 void dumpvars( const tsd_t
*TSD
, cvariableptr
*hashptr
)
35 /* change by bja: dumpvars to use stderr, as trace or listleaked do */
36 /* modified my mh: respect stdout_for_stderr OPTION also */
37 /* change by bja: display variable's length in front of value */
38 cvariableptr ptr
=NULL
, tptr
=NULL
;
42 if ( get_options_flag( TSD
->currlevel
, EXT_STDOUT_FOR_STDERR
) )
45 hashptr
= (cvariableptr
*) TSD
->currlevel
->vars
;
47 fprintf(fp
,"\nDumping variables to <stdout>\n") ;
48 for (i
=0;i
!=HASHTABLENGTH
;i
++)
51 fprintf(fp
," Variables from bin no %d\n",i
) ;
52 for (ptr
=hashptr
[i
];ptr
!=NULL
;ptr
=ptr
->next
)
54 if ((ptr
->name
->value
)[ptr
->name
->len
-1]=='.')
57 fprintf(fp
," >>> Stem : //%s// Default: //%s// Values:\n",
58 ptr
->name
->value
,(ptr
->value
)?(ptr
->value
->value
):"<none>") ;
60 fprintf(fp
," >>> Stem : ");
61 fprintf(fp
,"(%d) :",ptr
->name
->len
);
62 for (k
=0;k
<ptr
->name
->len
;k
++)
63 putc(ptr
->name
->value
[k
],fp
);
64 /* avoid problems with exposed variables bja */
67 fprintf(fp
," Exposed!\n");
70 /* end of avoid problems with exposed variables bja */
71 fprintf(fp
, " Default: [");
74 fprintf(fp
,"(%d) :",ptr
->value
->len
);
75 for (k
=0;k
<ptr
->value
->len
;k
++)
76 putc(ptr
->value
->value
[k
],fp
);
79 fprintf(fp
, "<none>");
80 fprintf(fp
, "] Values:\n");
82 for (j
=0;j
<HASHTABLENGTH
;j
++)
84 if ((tptr
=((ptr
->index
))[j
])!=NULL
)
86 fprintf(fp
, " Sub-bin no %d\n",j
) ;
87 for (;tptr
;tptr
=tptr
->next
)
92 fprintf(fp
, " >>> Variable: //%s// Value: //%s//\n",
93 tptr
->name
->value
,tptr
->value
->value
) ;
95 fprintf(fp
, " >>> Tail: ");
96 fprintf(fp
, "(%d) :",tptr
->name
->len
);
97 for (k
=0;k
<tptr
->name
->len
;k
++)
98 putc(tptr
->name
->value
[k
],fp
);
99 if ( tptr
->num
) /* variable is a number */
101 /* try printing numbers a bit better... bja
102 fprintf(fp, " (number: %s) ",ptr->num->num );
104 fprintf(fp
, " (number: "); /* bja */
105 if (tptr
->num
->negative
) fprintf(fp
,"-"); /* bja */
106 fprintf(fp
, "%.*s) ",tptr
->num
->size
, tptr
->num
->num
);/* bja */
108 fprintf(fp
," Flag: %d hwired: %ld valid: %ld ",ptr
->flag
, ptr
->hwired
, ptr
->valid
);
109 fprintf(fp
," Value: [");
112 fprintf(fp
,"(%d) :",tptr
->value
->len
);
113 for (k
=0;k
<tptr
->value
->len
;k
++)
114 putc(tptr
->value
->value
[k
],fp
);
118 fprintf(fp
,"<none>"); /* added bja */
130 fprintf(fp
," >>> Variable: //%s// Value: //%s//\n",
131 ptr
->name
->value
,ptr
->value
->value
) ;
133 fprintf(fp
," >>> Variable: ");
134 fprintf(fp
,"(%d) :",ptr
->name
->len
);
135 for (k
=0;k
<ptr
->name
->len
;k
++)
136 putc(ptr
->name
->value
[k
],fp
);
137 /* avoid problems with exposed variables bja */
140 fprintf(fp
," Exposed\n");
143 /* end of avoid problems with exposed variables bja */
144 fprintf(fp
," Value: [");
147 fprintf(fp
,"(%d) :",ptr
->value
->len
);
148 for (k
=0;k
<ptr
->value
->len
;k
++)
149 putc(ptr
->value
->value
[k
],fp
);
161 void dumptree(const tsd_t
*TSD
, const treenode
*this, int level
, int newline
)
167 if ( get_options_flag( TSD
->currlevel
, EXT_STDOUT_FOR_STDERR
) )
169 if ((this->charnr
)!=0
170 && (this->charnr
)!=(-1))
174 for (i
=0;i
!=level
;i
++) fprintf(fp
," ") ;
175 fprintf(fp
,"Lineno: %d Charno: %d", this->lineno
, this->charnr
) ;
178 ptr
= getsourceline(TSD
, this->lineno
, this->charnr
,
179 &TSD
->systeminfo
->tree
) ;
180 fprintf(fp
," Sourceline: [");
181 for(i
=0;i
<ptr
->len
;i
++)
182 putc(ptr
->value
[i
],fp
);
188 for (i
=0;i
!=level
;i
++)
190 fprintf(fp
,">>> in type=%d == %s\n", this->type
, getsym(this->type
)) ;
192 for (i
=0;i
!=level
;i
++) fprintf(fp
," ") ;
193 fprintf(fp
,"Flags: lnum %d rnum %d lsvar %d rsvar %d lcvar %d rcvar %d\n",
199 this->u
.flags
.rcvar
);
201 if ((this->name
)!=NULL
)
203 for (i
=0;i
!=level
;i
++) fprintf(fp
," ") ;
204 fprintf(fp
,"Name: [");
205 for (i
=0;i
<this->name
->len
;i
++)
206 putc(this->name
->value
[i
],fp
);
210 for (j
=0;j
<sizeof(this->p
)/sizeof(this->p
[0]);j
++)
211 if (this->p
[j
]!=NULL
)
213 for (i
=0;i
!=level
;i
++)
215 fprintf(fp
,"==> (%d) going down in branch %d, type %d = %s\n",
216 this->type
,j
+1,this->p
[j
]->type
,getsym(this->p
[j
]->type
)) ;
217 dumptree( TSD
, this->p
[j
], level
+1, 0 ) ;
220 for (i
=0;i
!=level
;i
++)
222 fprintf(fp
,"<<< out type=%d == %s\n", this->type
,getsym(this->type
)) ;
225 dumptree( TSD
, this->next
, level
, 1 ) ;
233 void marksource( clineboxptr ptr
)
235 for (;ptr
;ptr
=ptr
->next
) {
236 markmemory( ptr
->line
,TRC_SOURCEL
) ;
237 markmemory( (char *)ptr
, TRC_SOURCE
) ; }
242 static const char *sourceline( int line
, const internal_parser_type
*ipt
, unsigned *size
)
247 if (ipt
->first_source_line
== NULL
)
248 { /* must be incore_source but that value may be NULL because of a failed
249 * instore[0] of RexxStart!
251 otp
= ipt
->srclines
; /* NULL if incore_source==NULL */
252 while (otp
&& (otp
->num
< (unsigned long) line
)) {
262 *size
= otp
->elems
[line
].length
;
263 return ipt
->incore_source
+ otp
->elems
[line
].offset
;
265 first
= ipt
->first_source_line
;
268 if (first
->lineno
==line
)
270 *size
= first
->line
->len
;
271 return first
->line
->value
;
274 first
= (first
->lineno
<line
) ? first
->next
: first
->prev
;
283 streng
*getsourceline( const tsd_t
*TSD
, int line
, int charnr
, const internal_parser_type
*ipt
)
285 int dquote
=0, squote
=0 ;
288 const char *ptr
, *chptr
, *chend
, *tmptr
;
291 assert( charnr
>=0 ) ;
295 ptr
= sourceline(line
,ipt
,&len
) ;
296 /* assert( ptr ) ; */
297 if (!ptr
|| (charnr
>= (int) len
))
298 return nullstringptr() ;
300 chptr
= ptr
+ --charnr
;
302 for (; (chptr
< chend
) && isspace(*chptr
); chptr
++) ;
303 string
= Str_makeTSD(BUFFERSIZE
+1) ;
304 outptr
= string
->value
;
309 if (chptr
>=chend
|| outptr
>= string
->value
+ BUFFERSIZE
)
312 if (!squote
&& *chptr
=='\"')
315 else if (!dquote
&& *chptr
=='\'')
318 else if (!(dquote
|| squote
))
323 for(tmptr
=chptr
+1; tmptr
<chend
&& isspace(*tmptr
); tmptr
++ ) ;
324 assert( tmptr
<=chend
) ;
328 chptr
= sourceline(++line
,ipt
,&len
) ;
329 chend
= chptr
+ len
;
330 for(; chptr
<chend
&& isspace(*chptr
); chptr
++) ;
336 *(outptr
++) = *chptr
;
344 *(outptr
++) = *(chptr
++) ;
348 assert( outptr
- string
->value
<= BUFFERSIZE
) ;
349 *outptr
= '\0'; /* needs to be 0-terminated */
350 string
->len
= outptr
- string
->value
;