| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992-1994 Anders Christensen <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "rexx.h" |
| 21 |
#include <stdio.h> |
| 22 |
#include <string.h> |
| 23 |
#include <limits.h> |
| 24 |
#ifndef VMS |
| 25 |
# ifdef HAVE_UNISTD_H |
| 26 |
# include <unistd.h> |
| 27 |
# endif |
| 28 |
#endif |
| 29 |
#ifdef HAVE_ASSERT_H |
| 30 |
# include <assert.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#define XOR(a,b) (( (a) && (!(b)) )||( (!(a)) && (b) )) |
| 34 |
|
| 35 |
#ifdef WIN32 |
| 36 |
/* Asynchroneous scheduled in another thread: */ |
| 37 |
volatile int __regina_Win32CtrlCRaised = 0; |
| 38 |
#endif |
| 39 |
|
| 40 |
static const char default_action[SIGNALS] = { 1, 1, 0, 1, 1, 0 } ; |
| 41 |
static const char default_ignore[SIGNALS] = { 1, 1, 0, 0, 1, 0 } ; |
| 42 |
|
| 43 |
#define NSTACKELEMS 32 /* nstack elements will be allocated in this size */ |
| 44 |
typedef struct _nstackbox { |
| 45 |
struct _nstackbox *next; |
| 46 |
struct _nstackbox *prev; |
| 47 |
unsigned used; |
| 48 |
unsigned sum; /* To provide safe triggers, never use ptrs */ |
| 49 |
nodeptr elems[NSTACKELEMS]; |
| 50 |
} nstackbox; |
| 51 |
|
| 52 |
typedef struct _stackelem { |
| 53 |
#ifdef OPT_DO |
| 54 |
int strmath; /* 0 if we can do binary arithmetic for this DO loop */ |
| 55 |
/* DO ... FOR x: value of x */ |
| 56 |
num_descr * do_for_val; |
| 57 |
rx_64 do_for_val_num ; |
| 58 |
#else |
| 59 |
int number; |
| 60 |
#endif |
| 61 |
int incrdir ; |
| 62 |
num_descr * increment ; |
| 63 |
/* DO ... TO x: value of x */ |
| 64 |
num_descr * stopval ; |
| 65 |
#ifdef OPT_DO |
| 66 |
rx_64 stopval_num; |
| 67 |
#endif |
| 68 |
nodeptr thisptr ; |
| 69 |
cnodeptr incr_node; |
| 70 |
struct _stackelem *prev ; /* needed for a look back */ |
| 71 |
} stackelem; |
| 72 |
|
| 73 |
#define STACKELEMS 64 /* nstack elements will be allocated in this size */ |
| 74 |
typedef struct _stackbox { |
| 75 |
struct _stackbox *next; |
| 76 |
struct _stackbox *prev; |
| 77 |
unsigned used; |
| 78 |
unsigned sum; /* To provide safe triggers, never use ptrs */ |
| 79 |
stackelem elems[STACKELEMS]; |
| 80 |
} stackbox; |
| 81 |
|
| 82 |
typedef struct { /* itp_tsd: static variables of this module (thread-safe) */ |
| 83 |
nstackbox nbox; |
| 84 |
nstackbox *nbox_top; |
| 85 |
stackbox sbox; |
| 86 |
stackbox *stk_top; |
| 87 |
unsigned long options; |
| 88 |
int opts_set; |
| 89 |
} itp_tsd_t; /* thread-specific but only needed by this module. see |
| 90 |
* init_spec_vars |
| 91 |
*/ |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
static void expose_indir( tsd_t *TSD, const streng *list ) ; |
| 96 |
|
| 97 |
#ifdef TRACEMEM |
| 98 |
static void mark_spec_vars(const tsd_t *TSD) |
| 99 |
{ |
| 100 |
itp_tsd_t *it; |
| 101 |
|
| 102 |
it = (itp_tsd_t *) TSD->itp_tsd; |
| 103 |
} |
| 104 |
#endif /* TRACEMEM */ |
| 105 |
|
| 106 |
|
| 107 |
/* |
| 108 |
* The function returns 1 on success, 0 if memory is short. |
| 109 |
*/ |
| 110 |
int init_spec_vars( tsd_t *TSD ) |
| 111 |
{ |
| 112 |
itp_tsd_t *it; |
| 113 |
|
| 114 |
if (TSD->itp_tsd != NULL) |
| 115 |
return(1); |
| 116 |
|
| 117 |
if ( ( TSD->itp_tsd = MallocTSD( sizeof(itp_tsd_t) ) ) == NULL ) |
| 118 |
return(0); |
| 119 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 120 |
memset(it,0,sizeof(itp_tsd_t)); |
| 121 |
|
| 122 |
it->nbox_top = &it->nbox; |
| 123 |
it->stk_top = &it->sbox; |
| 124 |
|
| 125 |
#ifdef TRACEMEM |
| 126 |
regmarker( TSD, mark_spec_vars ) ; |
| 127 |
#endif |
| 128 |
return(1); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
void update_envirs( const tsd_t *TSD, proclevel level ) |
| 133 |
{ |
| 134 |
proclevel lptr=NULL ; |
| 135 |
|
| 136 |
if (!level->environment) |
| 137 |
{ |
| 138 |
for (lptr=level->prev; lptr; lptr=lptr->prev) |
| 139 |
{ |
| 140 |
if (lptr->environment) |
| 141 |
{ |
| 142 |
level->environment = Str_dupTSD(lptr->environment) ; |
| 143 |
break ; |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
if (!level->prev_env) |
| 148 |
{ |
| 149 |
for (lptr=level->prev; lptr; lptr=lptr->prev) |
| 150 |
{ |
| 151 |
if (lptr->prev_env) |
| 152 |
{ |
| 153 |
level->prev_env = Str_dupTSD(lptr->prev_env) ; |
| 154 |
break ; |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
assert( level->environment ) ; |
| 160 |
assert( level->prev_env ) ; |
| 161 |
} |
| 162 |
|
| 163 |
/* nstackpush pushes the arg pnode on the nstack. (copy, then increment) |
| 164 |
*/ |
| 165 |
static void nstackpush(const tsd_t *TSD,nodeptr pnode) |
| 166 |
{ |
| 167 |
itp_tsd_t *it; |
| 168 |
nstackbox *ns; |
| 169 |
|
| 170 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 171 |
ns = it->nbox_top; |
| 172 |
ns->elems[ns->used++] = pnode; |
| 173 |
if (ns->used >= NSTACKELEMS) |
| 174 |
{ |
| 175 |
if (ns->next == NULL) |
| 176 |
{ |
| 177 |
ns->next = (nstackbox *)MallocTSD(sizeof(nstackbox)); |
| 178 |
ns->next->prev = ns; |
| 179 |
ns->next->next = NULL; |
| 180 |
ns->next->used = 0; |
| 181 |
ns->next->sum = ns->sum + NSTACKELEMS; |
| 182 |
} |
| 183 |
assert( ns->next->used == 0 ) ; /* be sure to have an empty block */ |
| 184 |
it->nbox_top = ns->next; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/* nstackpop pops an element from the nstack. (decrement, then copy) |
| 189 |
* The return is the saved value formerly saved by a call to nstackpush. |
| 190 |
* nstackpush/nstackpop calls may be nested. |
| 191 |
* The return value is NULL in case of an empty stack. |
| 192 |
* We use a delayed cleanup (one free nstackbox is available while popping). |
| 193 |
*/ |
| 194 |
static nodeptr nstackpop(const tsd_t *TSD) |
| 195 |
{ |
| 196 |
itp_tsd_t *it; |
| 197 |
nstackbox *ns; |
| 198 |
|
| 199 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 200 |
ns = it->nbox_top; |
| 201 |
if (ns->used == 0) |
| 202 |
{ |
| 203 |
/* For a delayed deletion preserve this box and delete the next one */ |
| 204 |
if (ns->next) |
| 205 |
{ |
| 206 |
FreeTSD(ns->next); |
| 207 |
ns->next = NULL; |
| 208 |
} |
| 209 |
assert(ns->prev); |
| 210 |
if (!ns->prev) |
| 211 |
{ |
| 212 |
return(NULL); |
| 213 |
} |
| 214 |
it->nbox_top = ns = ns->prev; |
| 215 |
} |
| 216 |
ns->used--; |
| 217 |
return(ns->elems[ns->used]); |
| 218 |
} |
| 219 |
|
| 220 |
/* nstacktrigger returns a stack descriptor which allow the caller to return |
| 221 |
* to the current state by using nstackcleanup() later. |
| 222 |
*/ |
| 223 |
static unsigned nstacktrigger(const tsd_t *TSD) |
| 224 |
{ |
| 225 |
itp_tsd_t *it; |
| 226 |
nstackbox *ns; |
| 227 |
|
| 228 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 229 |
ns = it->nbox_top; |
| 230 |
return(ns->sum + ns->used); |
| 231 |
} |
| 232 |
|
| 233 |
/* nstackcleanup cleans up the stack until either the trigger from a |
| 234 |
* nstacktrigger() is reached or the node encounters, whatever comes first. |
| 235 |
* In the first case the state is as during the call to nstacktrigger(). |
| 236 |
* In the second case the matching node is NOT popped. To allow a search for |
| 237 |
* NULL the matching pointer is indexed. Giving NULL means don't use the |
| 238 |
* matching algorithm. Give |
| 239 |
* "cnodeptr m=NULL; nstackcleanup(TSD,?,&m);" to match a NULL pointer. |
| 240 |
* node may be NULL. |
| 241 |
*/ |
| 242 |
static void nstackcleanup(const tsd_t *TSD, |
| 243 |
unsigned trigger, |
| 244 |
const nodeptr *match) |
| 245 |
{ |
| 246 |
itp_tsd_t *it; |
| 247 |
nstackbox *ns; |
| 248 |
cnodeptr m = NULL; /* Keep the compiler happy */ |
| 249 |
|
| 250 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 251 |
ns = it->nbox_top; |
| 252 |
if (match) |
| 253 |
m = *match; |
| 254 |
while (trigger < ns->sum) /* The complete block may be killed! */ |
| 255 |
{ |
| 256 |
if (match) |
| 257 |
{ |
| 258 |
while (ns->used) |
| 259 |
{ |
| 260 |
if (ns->elems[--ns->used] == m) |
| 261 |
{ |
| 262 |
ns->used++; |
| 263 |
return; |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
else |
| 268 |
{ |
| 269 |
ns->used = 0 ; |
| 270 |
} |
| 271 |
/* For a delayed deletion preserve this box and delete the next one */ |
| 272 |
if (ns->next) |
| 273 |
{ |
| 274 |
FreeTSD(ns->next); |
| 275 |
ns->next = NULL; |
| 276 |
} |
| 277 |
assert(ns->prev); |
| 278 |
if (!ns->prev) |
| 279 |
{ |
| 280 |
ns->used = 0; |
| 281 |
return; |
| 282 |
} |
| 283 |
it->nbox_top = ns = ns->prev; |
| 284 |
} |
| 285 |
|
| 286 |
/* The trigger is within the current box. Do an alignment to force |
| 287 |
* trigger to be used in conjunction with ns->used. |
| 288 |
*/ |
| 289 |
trigger -= ns->sum; |
| 290 |
if (trigger >= ns->used) /* Be safety. Imagine a wild trigger! */ |
| 291 |
return; |
| 292 |
|
| 293 |
if (!match) /* Things may be simple */ |
| 294 |
{ |
| 295 |
ns->used = trigger; |
| 296 |
return; |
| 297 |
} |
| 298 |
|
| 299 |
while (trigger != ns->used) |
| 300 |
if (ns->elems[--ns->used] == m) |
| 301 |
{ |
| 302 |
ns->used++; |
| 303 |
return; |
| 304 |
} |
| 305 |
ns->used = trigger; |
| 306 |
} |
| 307 |
|
| 308 |
/* stackpush pushes the contents of the arg sbox on the stack. (copy, then |
| 309 |
* increment) |
| 310 |
*/ |
| 311 |
static void stackpush(const tsd_t *TSD,const stackelem *sbox) |
| 312 |
{ |
| 313 |
itp_tsd_t *it; |
| 314 |
stackbox *sb; |
| 315 |
|
| 316 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 317 |
sb = it->stk_top; |
| 318 |
sb->elems[sb->used] = *sbox; |
| 319 |
if (sb->used) |
| 320 |
sb->elems[sb->used].prev = sb->elems + sb->used - 1; |
| 321 |
else if (sb->prev) |
| 322 |
sb->elems[0].prev = sb->prev->elems + STACKELEMS - 1; |
| 323 |
else |
| 324 |
sb->elems[0].prev = NULL; |
| 325 |
sb->used++; |
| 326 |
|
| 327 |
if (sb->used >= STACKELEMS) |
| 328 |
{ |
| 329 |
if (sb->next == NULL) |
| 330 |
{ |
| 331 |
sb->next = (stackbox *)MallocTSD(sizeof(stackbox)); |
| 332 |
sb->next->prev = sb; |
| 333 |
sb->next->next = NULL; |
| 334 |
sb->next->sum = sb->sum + STACKELEMS; /* const to each block */ |
| 335 |
} |
| 336 |
assert( sb->next->used == 0 ) ; /* be sure to have an empty block */ |
| 337 |
it->stk_top = sb->next; |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
/* stackpop pops an element from the stack. (decrement, then copy) |
| 342 |
* The return is the saved value formerly saved by a call to stackpush. |
| 343 |
* stackpush/stackpop calls may be nested. |
| 344 |
* The return value is filled with 0 in case of an empty stack. |
| 345 |
* We use a delayed cleanup (one free stackbox is available while popping). |
| 346 |
*/ |
| 347 |
static stackelem stackpop(const tsd_t *TSD) |
| 348 |
{ |
| 349 |
itp_tsd_t *it; |
| 350 |
stackbox *sb; |
| 351 |
stackelem zero; |
| 352 |
|
| 353 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 354 |
sb = it->stk_top; |
| 355 |
if (sb->used == 0) |
| 356 |
{ |
| 357 |
/* For a delayed deletion preserve this box and delete the next one */ |
| 358 |
if (sb->next) |
| 359 |
{ |
| 360 |
FreeTSD(sb->next); |
| 361 |
sb->next = NULL; |
| 362 |
} |
| 363 |
assert(sb->prev); |
| 364 |
if (!sb->prev) |
| 365 |
{ |
| 366 |
memset(&zero,0,sizeof(zero)); |
| 367 |
return(zero); |
| 368 |
} |
| 369 |
it->stk_top = sb = sb->prev; |
| 370 |
} |
| 371 |
sb->used--; |
| 372 |
return(sb->elems[sb->used]); |
| 373 |
} |
| 374 |
|
| 375 |
/* stacktrigger returns a stack descriptor which allow the caller to return |
| 376 |
* to the current state by using stackcleanup() later. See also stacktop(). |
| 377 |
*/ |
| 378 |
static unsigned stacktrigger(const tsd_t *TSD) |
| 379 |
{ |
| 380 |
itp_tsd_t *it; |
| 381 |
stackbox *sb; |
| 382 |
|
| 383 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 384 |
sb = it->stk_top; |
| 385 |
return(sb->sum + sb->used); |
| 386 |
} |
| 387 |
|
| 388 |
/* stacktop returns a pointer to the top element of the stack. This may be |
| 389 |
* useful to manipulate stack elements or have a look back. Be careful with |
| 390 |
* the stack and don't use elements which were not pushed by the current |
| 391 |
* incarnation of interpret(). See also stacktrigger(). |
| 392 |
* NULL is returned if the stack is empty. |
| 393 |
*/ |
| 394 |
static stackelem * stacktop(const tsd_t *TSD) |
| 395 |
{ |
| 396 |
itp_tsd_t *it; |
| 397 |
stackbox *sb; |
| 398 |
|
| 399 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 400 |
sb = it->stk_top; |
| 401 |
if (sb->used) |
| 402 |
return(sb->elems + sb->used - 1); |
| 403 |
if (sb->prev) |
| 404 |
return(sb->prev->elems + STACKELEMS - 1); |
| 405 |
return(NULL); |
| 406 |
} |
| 407 |
|
| 408 |
/* stack_destroyelement kill the increment and stopval values of a stack |
| 409 |
* elements if they exist. The values are reset to zero after the deletion. |
| 410 |
*/ |
| 411 |
static void stack_destroyelement(const tsd_t *TSD,stackelem *se) |
| 412 |
{ |
| 413 |
if (se->stopval) |
| 414 |
{ |
| 415 |
free_a_descr(TSD,se->stopval); |
| 416 |
se->stopval = NULL; |
| 417 |
} |
| 418 |
#ifdef OPT_DO |
| 419 |
if (se->do_for_val) |
| 420 |
{ |
| 421 |
free_a_descr(TSD,se->do_for_val); |
| 422 |
se->do_for_val = NULL; |
| 423 |
} |
| 424 |
#endif |
| 425 |
if (se->increment) |
| 426 |
{ |
| 427 |
free_a_descr(TSD,se->increment); |
| 428 |
se->increment = NULL; |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
/* stackcleanup cleans up the stack until the trigger from a |
| 434 |
* stacktrigger() is reached. After the call the stack is in the same state as |
| 435 |
* during the call to stacktrigger. |
| 436 |
* Warning: The elements increment and stopval will be deleted for each |
| 437 |
* deleted stack elements if they exist. Do a stacktop() and use the |
| 438 |
* prev value of each entry for the appropriate count do set the |
| 439 |
* values to NULL if you don't want this. |
| 440 |
*/ |
| 441 |
static void stackcleanup(const tsd_t *TSD,unsigned trigger) |
| 442 |
{ |
| 443 |
itp_tsd_t *it; |
| 444 |
stackbox *sb; |
| 445 |
unsigned tokill = stacktrigger(TSD); |
| 446 |
|
| 447 |
if (tokill <= trigger) |
| 448 |
return; |
| 449 |
|
| 450 |
tokill -= trigger; |
| 451 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 452 |
sb = it->stk_top; |
| 453 |
while (tokill--) |
| 454 |
{ |
| 455 |
if (sb->used == 0) |
| 456 |
{ |
| 457 |
/* For a delayed deletion preserve this box and delete the next one */ |
| 458 |
if (sb->next) |
| 459 |
{ |
| 460 |
FreeTSD(sb->next); |
| 461 |
sb->next = NULL; |
| 462 |
} |
| 463 |
assert(sb->prev); |
| 464 |
if (!sb->prev) |
| 465 |
return; |
| 466 |
it->stk_top = sb = sb->prev; |
| 467 |
} |
| 468 |
sb->used--; |
| 469 |
stack_destroyelement(TSD,sb->elems + sb->used); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
void SaveInterpreterStatus(const tsd_t *TSD,unsigned *state) |
| 474 |
{ |
| 475 |
assert(IPRT_BUFSIZE >= 2); |
| 476 |
state[0] = nstacktrigger(TSD); |
| 477 |
state[1] = stacktrigger(TSD); |
| 478 |
} |
| 479 |
|
| 480 |
void RestoreInterpreterStatus(const tsd_t *TSD,const unsigned *state) |
| 481 |
{ |
| 482 |
nstackcleanup(TSD,state[0],NULL); |
| 483 |
stackcleanup(TSD,state[1]); |
| 484 |
} |
| 485 |
|
| 486 |
streng *CallInternalFunction( tsd_t *TSD, nodeptr node, nodeptr thisptr, |
| 487 |
paramboxptr args ) |
| 488 |
{ |
| 489 |
int stackmark; |
| 490 |
streng *result; |
| 491 |
proclevel oldlevel; |
| 492 |
nodeptr savecurrentnode; |
| 493 |
|
| 494 |
oldlevel = TSD->currlevel; |
| 495 |
TSD->currlevel = newlevel( TSD, TSD->currlevel ); |
| 496 |
TSD->currlevel->args = args; |
| 497 |
stackmark = pushcallstack( TSD, thisptr ); |
| 498 |
|
| 499 |
savecurrentnode = TSD->currentnode; |
| 500 |
result = interpret( TSD, node ); |
| 501 |
TSD->currentnode = savecurrentnode; |
| 502 |
|
| 503 |
popcallstack( TSD, stackmark ); |
| 504 |
removelevel( TSD, TSD->currlevel ); |
| 505 |
TSD->currlevel = oldlevel; |
| 506 |
TSD->currlevel->next = NULL; |
| 507 |
TSD->trace_stat = TSD->currlevel->tracestat; |
| 508 |
|
| 509 |
return result; |
| 510 |
} |
| 511 |
|
| 512 |
streng *interpret(tsd_t * volatile TSD, treenode * volatile thisptr) |
| 513 |
{ |
| 514 |
int i ; |
| 515 |
int stackmark ; |
| 516 |
proclevel oldlevel ; |
| 517 |
treenode *entry=NULL ; |
| 518 |
int no_next_interactive=0 ; |
| 519 |
stackelem s; |
| 520 |
volatile unsigned stktrigger ; |
| 521 |
volatile unsigned nstktrigger ; |
| 522 |
nodeptr innerloop=NULL ; |
| 523 |
num_descr *doiterdescr=NULL ; |
| 524 |
volatile nodeptr secure_this ; |
| 525 |
tsd_t * volatile secure_TSD ; |
| 526 |
itp_tsd_t * volatile it; |
| 527 |
|
| 528 |
it = (itp_tsd_t *)TSD->itp_tsd; |
| 529 |
|
| 530 |
nstktrigger = nstacktrigger(TSD); |
| 531 |
stktrigger = stacktrigger(TSD); |
| 532 |
|
| 533 |
secure_TSD = TSD; /* vars used until here */ |
| 534 |
secure_this = thisptr; |
| 535 |
|
| 536 |
if ( TSD->currlevel->signal_continue == NULL ) |
| 537 |
{ |
| 538 |
TSD->currlevel->signal_continue = (jmp_buf *)MallocTSD( sizeof( jmp_buf ) ); |
| 539 |
|
| 540 |
assert( !TSD->in_protected ); |
| 541 |
if ( setjmp( *TSD->currlevel->signal_continue ) ) |
| 542 |
{ |
| 543 |
/* A signal arrived and a longjmp from anywhere jumps here. |
| 544 |
* We can't believe in anything and have to rebuild it from |
| 545 |
* scratch or volatile pointers. Even an unoptimized compiler |
| 546 |
* may have optimized the access to values of any kind. |
| 547 |
* We have to do the full reinitialization. |
| 548 |
* prevents bugs like 592393 |
| 549 |
*/ |
| 550 |
thisptr = secure_this ; |
| 551 |
TSD = secure_TSD ; |
| 552 |
it = (itp_tsd_t *)TSD->itp_tsd ; |
| 553 |
|
| 554 |
doiterdescr = NULL ; |
| 555 |
innerloop = NULL ; |
| 556 |
memset(&s,0,sizeof(s)); |
| 557 |
|
| 558 |
nstackcleanup(TSD,nstktrigger,NULL); |
| 559 |
stackcleanup(TSD,stktrigger); |
| 560 |
no_next_interactive = 0 ; |
| 561 |
|
| 562 |
goto fakerecurse ; |
| 563 |
} |
| 564 |
} |
| 565 |
memset(&s,0,sizeof(s)); |
| 566 |
no_next_interactive = 0 ; |
| 567 |
doiterdescr = NULL ; |
| 568 |
innerloop = NULL ; |
| 569 |
|
| 570 |
reinterpret: |
| 571 |
#ifdef WIN32 |
| 572 |
/* |
| 573 |
* Braindamaged Win32 systems raise ^C in a different thread. We catch the |
| 574 |
* global flag set the thread's own halt-flag. |
| 575 |
*/ |
| 576 |
if ( __regina_Win32CtrlCRaised ) |
| 577 |
{ |
| 578 |
TSD->HaltRaised = __regina_Win32CtrlCRaised; |
| 579 |
__regina_Win32CtrlCRaised = 0; |
| 580 |
} |
| 581 |
#endif |
| 582 |
if ( TSD->HaltRaised ) |
| 583 |
halt_raised( TSD ); |
| 584 |
|
| 585 |
if (thisptr==NULL) |
| 586 |
goto fakereturn ; |
| 587 |
|
| 588 |
secure_this = thisptr; |
| 589 |
|
| 590 |
TSD->currentnode = thisptr ; |
| 591 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 592 |
{ |
| 593 |
if (thisptr->type != X_DO) /* let do-stats trace themselves */ |
| 594 |
traceline( TSD, thisptr, TSD->trace_stat, 0 ); |
| 595 |
} |
| 596 |
|
| 597 |
if (thisptr->now) |
| 598 |
{ |
| 599 |
FreeTSD(thisptr->now); |
| 600 |
thisptr->now = NULL; |
| 601 |
} |
| 602 |
|
| 603 |
thisptr->o.called = 0; |
| 604 |
|
| 605 |
switch ( /*(unsigned char)*/ (thisptr->type) ) |
| 606 |
{ |
| 607 |
case X_PROGRAM: |
| 608 |
case X_STATS: |
| 609 |
|
| 610 |
case X_WHENS: |
| 611 |
case X_OTHERWISE: |
| 612 |
thisptr = thisptr->p[0] ; |
| 613 |
goto reinterpret ; |
| 614 |
|
| 615 |
|
| 616 |
case 0: |
| 617 |
case 255: |
| 618 |
case X_DO: |
| 619 |
{ |
| 620 |
streng *tmpstr,*tmpkill=NULL; |
| 621 |
|
| 622 |
if (innerloop==thisptr) |
| 623 |
{ |
| 624 |
assert( thisptr->p[3] ) ; |
| 625 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 626 |
{ |
| 627 |
traceline( TSD, thisptr->p[3], TSD->trace_stat, -1 ); |
| 628 |
traceline( TSD, thisptr, TSD->trace_stat, -1 ); |
| 629 |
} |
| 630 |
goto one ; |
| 631 |
} |
| 632 |
else |
| 633 |
{ |
| 634 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 635 |
traceline( TSD, thisptr, TSD->trace_stat, 0 ); |
| 636 |
} |
| 637 |
|
| 638 |
if (!((thisptr->p[0])||(thisptr->p[1]))) |
| 639 |
{ |
| 640 |
nstackpush(TSD,thisptr->next); |
| 641 |
thisptr = thisptr->p[2] ; |
| 642 |
goto fakerecurse ; |
| 643 |
} |
| 644 |
|
| 645 |
nstackpush(TSD,thisptr->next); /* for use with leave */ |
| 646 |
|
| 647 |
if (innerloop) |
| 648 |
{ |
| 649 |
s.thisptr = innerloop; |
| 650 |
stackpush(TSD,&s); |
| 651 |
} |
| 652 |
|
| 653 |
s.incr_node = NULL; |
| 654 |
#ifdef OPT_DO |
| 655 |
s.increment = s.do_for_val = s.stopval = doiterdescr = NULL ; |
| 656 |
s.do_for_val_num = -1 ; |
| 657 |
s.strmath = 0; /* do numeric calculations by default */ |
| 658 |
#else |
| 659 |
s.increment = s.stopval = doiterdescr = NULL ; |
| 660 |
s.number = -1; |
| 661 |
#endif |
| 662 |
s.incrdir = 1 ; |
| 663 |
tmpstr = NULL ; |
| 664 |
/* |
| 665 |
* If we have a named variable as the iterator, get itl its in tmpstr |
| 666 |
*/ |
| 667 |
if ((thisptr->p[0])&&(thisptr->p[0]->name)) |
| 668 |
tmpstr = evaluate( TSD, thisptr->p[0]->p[0], &tmpkill ); |
| 669 |
/* |
| 670 |
* For each of the 4 types of options for the DO command that involve evaluation of a number |
| 671 |
* at the start of the loop, evaluate the starting value of that expression |
| 672 |
*/ |
| 673 |
for (i=1;i<4;i++) |
| 674 |
{ |
| 675 |
if ((thisptr->p[0])&&(thisptr->p[0]->p[i])) |
| 676 |
{ |
| 677 |
nodeptr tmpptr ; |
| 678 |
switch( thisptr->p[0]->p[i]->type ) |
| 679 |
{ |
| 680 |
case X_DO_TO: |
| 681 |
{ |
| 682 |
#ifdef OPT_DO |
| 683 |
int error ; |
| 684 |
rx_64 iptr; |
| 685 |
streng *chptr,*chkill; |
| 686 |
num_descr *tmpnum; |
| 687 |
#endif |
| 688 |
/* DO ... TO x: s.stopval is the value of x; x evaluates to any decimal number */ |
| 689 |
tmpptr = thisptr->p[0]->p[i]->p[0] ; |
| 690 |
#ifdef OPT_DO |
| 691 |
chptr = evaluate(TSD, tmpptr, &chkill ); |
| 692 |
if ( !myiswnumber( TSD, chptr, &s.stopval, 1 ) ) |
| 693 |
exiterror( ERR_INVALID_INTEGER, (thisptr->p[0]->p[i]->type==X_DO_EXPR) ? 2 : 3, chptr->value ); |
| 694 |
s.stopval_num = streng_to_rx64(TSD, chptr, &error); |
| 695 |
if ( error ) |
| 696 |
s.strmath = 1; /* have to use string math for this loop */ |
| 697 |
if ( chkill ) |
| 698 |
Free_stringTSD( chkill ); |
| 699 |
#else |
| 700 |
s.stopval = calcul( TSD, tmpptr, NULL, SIDE_LEFT, X_DO_TO ) ; |
| 701 |
#endif |
| 702 |
break ; |
| 703 |
} |
| 704 |
case X_DO_BY: |
| 705 |
/* DO ... BY x: s.increment is the value of x; x evaluates to any decimal number, s.incrdir is the "direction", +ve or -ve */ |
| 706 |
s.incr_node = thisptr->p[0]->p[i]->p[0] ; |
| 707 |
tmpptr = thisptr->p[0]->p[i]->p[0] ; |
| 708 |
s.increment = calcul( TSD, tmpptr, NULL, SIDE_LEFT, X_DO_BY ) ; |
| 709 |
s.incrdir = descr_sign( s.increment ) ; |
| 710 |
/* |
| 711 |
fprintf(stderr,"%s %d: direction: %d increment %s neg %d exp %d\n",__FILE__,__LINE__, s.incrdir, |
| 712 |
s.increment->num, |
| 713 |
s.increment->negative , |
| 714 |
s.increment->exp |
| 715 |
); |
| 716 |
*/ |
| 717 |
break ; |
| 718 |
|
| 719 |
case X_DO_FOR: |
| 720 |
case X_DO_EXPR: |
| 721 |
{ |
| 722 |
/* DO x or DO .. FOR x: s.do_for_val_num is the value of x; x evaluates to any WHOLE number */ |
| 723 |
#ifdef OPT_DO |
| 724 |
int error ; |
| 725 |
rx_64 iptr; |
| 726 |
#else |
| 727 |
int iptr, error ; |
| 728 |
#endif |
| 729 |
streng *chptr,*chkill; |
| 730 |
#ifdef OPT_DO |
| 731 |
num_descr *tmpnum; |
| 732 |
#endif |
| 733 |
|
| 734 |
tmpptr = thisptr->p[0]->p[i]->p[0] ; |
| 735 |
chptr = evaluate(TSD, tmpptr, &chkill ); |
| 736 |
#ifdef OPT_DO |
| 737 |
if ( !myiswnumber( TSD, chptr, &tmpnum, 1 ) |
| 738 |
|| tmpnum->negative ) |
| 739 |
exiterror( ERR_INVALID_INTEGER, (thisptr->p[0]->p[i]->type==X_DO_EXPR) ? 2 : 3, chptr->value ); |
| 740 |
|
| 741 |
s.do_for_val = calcul(TSD,tmpptr,NULL) ; |
| 742 |
iptr = streng_to_rx64(TSD, chptr, &error); |
| 743 |
#else |
| 744 |
iptr = streng_to_int(TSD, chptr, &error); |
| 745 |
#endif |
| 746 |
if ( error ) |
| 747 |
#ifdef OPT_DO |
| 748 |
s.strmath = 1; /* have to use string math for this loop */ |
| 749 |
s.do_for_val_num = iptr ; |
| 750 |
#else |
| 751 |
exiterror( ERR_INVALID_INTEGER, (thisptr->p[0]->p[i]->type==X_DO_EXPR) ? 2 : 3, chptr->value ); |
| 752 |
if ( iptr < 0 ) |
| 753 |
exiterror( ERR_INVALID_RESULT, 0 ); |
| 754 |
s.number = iptr; |
| 755 |
#endif |
| 756 |
if ( chkill ) |
| 757 |
Free_stringTSD( chkill ); |
| 758 |
break ; |
| 759 |
} |
| 760 |
} |
| 761 |
} |
| 762 |
} |
| 763 |
if ( tmpstr ) |
| 764 |
{ |
| 765 |
/* |
| 766 |
* Normalise the iterator for the DO loop; must be a number. |
| 767 |
*/ |
| 768 |
setshortcut( TSD, thisptr->p[0], str_normalize( TSD, tmpstr ) ); |
| 769 |
doiterdescr = shortcutnum( TSD, thisptr->p[0] ); |
| 770 |
if ( tmpkill ) |
| 771 |
Free_stringTSD( tmpkill ); |
| 772 |
/* |
| 773 |
fprintf(stderr,"%s %d: After normalise: iter %s neg %d exp %d\n",__FILE__,__LINE__, |
| 774 |
doiterdescr->num, |
| 775 |
doiterdescr->negative , |
| 776 |
doiterdescr->exp |
| 777 |
); |
| 778 |
*/ |
| 779 |
} |
| 780 |
#ifdef OPT_DO |
| 781 |
fprintf(stderr,"%s %d: Using %s arithmetic for DO\n",__FILE__,__LINE__,(s.strmath) ? "string" : "numeric" ); |
| 782 |
#endif |
| 783 |
if (TSD->systeminfo->interactive) |
| 784 |
{ |
| 785 |
if (intertrace(TSD)) |
| 786 |
{ |
| 787 |
nstackpop(TSD); |
| 788 |
if (s.increment) |
| 789 |
{ |
| 790 |
free_a_descr( TSD, s.increment ) ; |
| 791 |
s.increment = NULL ; |
| 792 |
} |
| 793 |
if (s.stopval) |
| 794 |
{ |
| 795 |
free_a_descr( TSD, s.stopval ) ; |
| 796 |
s.stopval = NULL ; |
| 797 |
} |
| 798 |
#ifdef OPT_DO |
| 799 |
if (s.do_for_val) |
| 800 |
{ |
| 801 |
free_a_descr( TSD, s.do_for_val ) ; |
| 802 |
s.do_for_val = NULL ; |
| 803 |
} |
| 804 |
#endif |
| 805 |
goto fakerecurse ; |
| 806 |
} |
| 807 |
} |
| 808 |
startloop: |
| 809 |
if (thisptr->p[0]) |
| 810 |
{ |
| 811 |
/* |
| 812 |
* If we have a TO value to terminate the loop, check if the value of the iterator (doiterdescr) |
| 813 |
* ??? |
| 814 |
*/ |
| 815 |
if (s.stopval) |
| 816 |
{ |
| 817 |
int tsign ; |
| 818 |
|
| 819 |
tsign = string_test( TSD, doiterdescr, s.stopval ) ; |
| 820 |
/* |
| 821 |
fprintf(stderr,"%s %d: tsign %d\n",__FILE__,__LINE__,tsign); |
| 822 |
*/ |
| 823 |
if (!(tsign ^ s.incrdir)) |
| 824 |
goto endloop ; |
| 825 |
/* |
| 826 |
fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
| 827 |
*/ |
| 828 |
} |
| 829 |
|
| 830 |
/* |
| 831 |
* If we have a FOR value to terminate the loop, check if it has decremented to less than |
| 832 |
* or equal to zero |
| 833 |
*/ |
| 834 |
#ifdef OPT_DO |
| 835 |
if ((s.do_for_val_num>=0) && (s.do_for_val_num--<=0)) |
| 836 |
#else |
| 837 |
if ((s.number>=0) && (s.number--<=0)) |
| 838 |
#endif |
| 839 |
goto endloop ; |
| 840 |
|
| 841 |
} |
| 842 |
/* |
| 843 |
* If there is WHILE clause, check if the expression is false before execution of the DO block |
| 844 |
*/ |
| 845 |
if ((thisptr->p[1])&&((thisptr->p[1]->type)==X_WHILE)) |
| 846 |
{ |
| 847 |
if (!isboolean(TSD,thisptr->p[1]->p[0],3, NULL)) |
| 848 |
goto endloop ; |
| 849 |
} |
| 850 |
/* |
| 851 |
* Execute the code in the DO block |
| 852 |
*/ |
| 853 |
if (thisptr->p[2]) |
| 854 |
{ |
| 855 |
nstackpush(TSD,thisptr); |
| 856 |
pushcallstack(TSD,NULL) ; |
| 857 |
|
| 858 |
innerloop = thisptr ; |
| 859 |
thisptr = thisptr->p[2] ; |
| 860 |
goto fakerecurse ; |
| 861 |
|
| 862 |
one: |
| 863 |
popcallstack(TSD,-1) ; |
| 864 |
} |
| 865 |
/* |
| 866 |
* If there is an UNTIL clause, check if the expression is false after execution of the DO block |
| 867 |
*/ |
| 868 |
if ((thisptr->p[1])&&((thisptr->p[1]->type)==X_UNTIL)) |
| 869 |
{ |
| 870 |
if (isboolean(TSD,thisptr->p[1]->p[0],4, NULL)) |
| 871 |
goto endloop ; |
| 872 |
} |
| 873 |
|
| 874 |
if ((thisptr->p[0])&&(thisptr->p[0]->name)) |
| 875 |
{ |
| 876 |
doiterdescr = shortcutnum( TSD, thisptr->p[0] ) ; |
| 877 |
/* |
| 878 |
* Check if we still have a valid number. If not |
| 879 |
* exit with arithmetic error. |
| 880 |
*/ |
| 881 |
if (!doiterdescr) |
| 882 |
exiterror( ERR_BAD_ARITHMETIC, 0 ) ; |
| 883 |
|
| 884 |
/* |
| 885 |
* Increment our loop iterator |
| 886 |
*/ |
| 887 |
if (s.increment) |
| 888 |
{ |
| 889 |
string_add( TSD, doiterdescr, s.increment, doiterdescr, thisptr->p[0], s.incr_node ) ; |
| 890 |
/* |
| 891 |
fprintf(stderr,"%s %d: After add: iter %s neg %d exp %d\n",__FILE__,__LINE__, |
| 892 |
doiterdescr->num, |
| 893 |
doiterdescr->negative , |
| 894 |
doiterdescr->exp |
| 895 |
); |
| 896 |
*/ |
| 897 |
/* fixes bug 1109729: */ |
| 898 |
str_round( doiterdescr, TSD->currlevel->currnumsize ) ; |
| 899 |
/* |
| 900 |
fprintf(stderr,"%s %d: After round: iter %s neg %d exp %d\n",__FILE__,__LINE__, |
| 901 |
doiterdescr->num, |
| 902 |
doiterdescr->negative , |
| 903 |
doiterdescr->exp |
| 904 |
); |
| 905 |
*/ |
| 906 |
} |
| 907 |
else |
| 908 |
string_incr( TSD, doiterdescr, thisptr->p[0] ) ; |
| 909 |
|
| 910 |
if (thisptr->p[0]->u.varbx) |
| 911 |
{ |
| 912 |
thisptr->p[0]->u.varbx->num = doiterdescr ; |
| 913 |
thisptr->p[0]->u.varbx->flag = VFLAG_NUM ; |
| 914 |
if ( TSD->trace_stat == 'I' ) |
| 915 |
tracenumber( TSD, doiterdescr, 'V'); |
| 916 |
} |
| 917 |
else |
| 918 |
setshortcut( TSD, thisptr->p[0], str_norm( TSD, doiterdescr, NULL )) ; |
| 919 |
} |
| 920 |
|
| 921 |
if (TSD->nextsig) |
| 922 |
goto fakerecurse ; |
| 923 |
|
| 924 |
/* |
| 925 |
* Check for ^C before iterating. Fixes bug 882878. |
| 926 |
*/ |
| 927 |
#ifdef WIN32 |
| 928 |
if ( __regina_Win32CtrlCRaised ) |
| 929 |
{ |
| 930 |
TSD->HaltRaised = __regina_Win32CtrlCRaised; |
| 931 |
__regina_Win32CtrlCRaised = 0; |
| 932 |
} |
| 933 |
#endif |
| 934 |
if ( TSD->HaltRaised ) |
| 935 |
goto fakerecurse ; |
| 936 |
|
| 937 |
goto startloop ; |
| 938 |
|
| 939 |
endloop: if (s.increment) |
| 940 |
{ |
| 941 |
free_a_descr( TSD, s.increment ) ; |
| 942 |
s.increment = NULL ; |
| 943 |
} |
| 944 |
if (s.stopval) |
| 945 |
{ |
| 946 |
free_a_descr( TSD, s.stopval ) ; |
| 947 |
s.stopval = NULL ; |
| 948 |
} |
| 949 |
#ifdef OPT_DO |
| 950 |
if (s.do_for_val) |
| 951 |
{ |
| 952 |
free_a_descr( TSD, s.do_for_val ) ; |
| 953 |
s.do_for_val = NULL ; |
| 954 |
} |
| 955 |
#endif |
| 956 |
no_next_interactive = 1 ; |
| 957 |
nstackpop(TSD); |
| 958 |
|
| 959 |
if (stacktrigger(TSD) > stktrigger) |
| 960 |
{ |
| 961 |
s = stackpop(TSD); |
| 962 |
innerloop = s.thisptr; |
| 963 |
} |
| 964 |
else |
| 965 |
innerloop = NULL ; |
| 966 |
|
| 967 |
break ; |
| 968 |
} |
| 969 |
case X_IF: |
| 970 |
{ |
| 971 |
treenode *othis = thisptr, *n; |
| 972 |
int retval = isboolean( TSD, thisptr->p[0], 1, NULL ); |
| 973 |
|
| 974 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 975 |
{ |
| 976 |
n = thisptr->p[0]->next; |
| 977 |
while ( n != NULL ) { |
| 978 |
traceline( TSD, n, TSD->trace_stat, 0 ); |
| 979 |
n = n->next; |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
nstackpush(TSD,thisptr->next); |
| 984 |
thisptr = thisptr->p[retval ? 1 : 2]; |
| 985 |
if (TSD->systeminfo->interactive) |
| 986 |
{ |
| 987 |
if (intertrace(TSD)) |
| 988 |
{ |
| 989 |
thisptr = othis ; |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
goto fakerecurse ; |
| 994 |
} |
| 995 |
case X_NASSIGN: |
| 996 |
{ |
| 997 |
num_descr *ntmp; |
| 998 |
streng *preferred_str; |
| 999 |
int type; |
| 1000 |
|
| 1001 |
ntmp = calcul( TSD, thisptr->p[1], NULL, SIDE_LEFT, X_NASSIGN ); |
| 1002 |
assert( ntmp->size ); |
| 1003 |
|
| 1004 |
type = thisptr->p[1]->type; |
| 1005 |
if ( ( type == X_STRING ) || ( type == X_CON_SYMBOL ) ) |
| 1006 |
preferred_str = Str_dupTSD( thisptr->p[1]->name ); |
| 1007 |
else |
| 1008 |
preferred_str = NULL; |
| 1009 |
|
| 1010 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1011 |
{ |
| 1012 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, preferred_str ); |
| 1013 |
} |
| 1014 |
else |
| 1015 |
{ |
| 1016 |
setshortcutnum( TSD, thisptr->p[0], ntmp, preferred_str ); |
| 1017 |
} |
| 1018 |
/* trace the result of assignment */ |
| 1019 |
if ( TSD->trace_stat == 'R' ) |
| 1020 |
{ |
| 1021 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1022 |
tracevalue( TSD, ptr, '=' ); |
| 1023 |
FreeTSD( ptr ); |
| 1024 |
} |
| 1025 |
break ; |
| 1026 |
} |
| 1027 |
|
| 1028 |
case X_ASSIGN: |
| 1029 |
{ |
| 1030 |
/* This is a CMS-ism; CMS allows the expression in an assignment to |
| 1031 |
* be omitted, while TRL does _not_. If a CMS mode is implemented, the |
| 1032 |
* code below should be changed to allow p[0] to be null only iff |
| 1033 |
* CMS mode is active. |
| 1034 |
*/ |
| 1035 |
streng *value ; |
| 1036 |
|
| 1037 |
value = thisptr->p[1] ? evaluate(TSD,thisptr->p[1],NULL) : nullstringptr() ; |
| 1038 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1039 |
fix_compound( TSD, thisptr->p[0], value ) ; |
| 1040 |
else |
| 1041 |
setshortcut( TSD, thisptr->p[0], value ) ; |
| 1042 |
/* trace the result of assignment */ |
| 1043 |
if ( TSD->trace_stat == 'R' ) |
| 1044 |
{ |
| 1045 |
tracevalue( TSD, value, '=' ); |
| 1046 |
} |
| 1047 |
break ; |
| 1048 |
} |
| 1049 |
|
| 1050 |
case X_PLUSASSIGN: |
| 1051 |
{ |
| 1052 |
num_descr *ntmp; |
| 1053 |
|
| 1054 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1055 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "+=" ) ; |
| 1056 |
|
| 1057 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_PLUSASSIGN ); |
| 1058 |
assert( ntmp->size ); |
| 1059 |
|
| 1060 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1061 |
{ |
| 1062 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1063 |
} |
| 1064 |
else |
| 1065 |
{ |
| 1066 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1067 |
} |
| 1068 |
/* trace the result of assignment */ |
| 1069 |
if ( TSD->trace_stat == 'R' ) |
| 1070 |
{ |
| 1071 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1072 |
tracevalue( TSD, ptr, '=' ); |
| 1073 |
FreeTSD( ptr ); |
| 1074 |
} |
| 1075 |
break ; |
| 1076 |
} |
| 1077 |
|
| 1078 |
case X_MINUSASSIGN: |
| 1079 |
{ |
| 1080 |
num_descr *ntmp; |
| 1081 |
|
| 1082 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1083 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "-=" ) ; |
| 1084 |
|
| 1085 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_MINUSASSIGN ); |
| 1086 |
assert( ntmp->size ); |
| 1087 |
|
| 1088 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1089 |
{ |
| 1090 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1091 |
} |
| 1092 |
else |
| 1093 |
{ |
| 1094 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1095 |
} |
| 1096 |
/* trace the result of assignment */ |
| 1097 |
if ( TSD->trace_stat == 'R' ) |
| 1098 |
{ |
| 1099 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1100 |
tracevalue( TSD, ptr, '=' ); |
| 1101 |
FreeTSD( ptr ); |
| 1102 |
} |
| 1103 |
break ; |
| 1104 |
} |
| 1105 |
|
| 1106 |
case X_MULTASSIGN: |
| 1107 |
{ |
| 1108 |
num_descr *ntmp; |
| 1109 |
|
| 1110 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1111 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "*=" ) ; |
| 1112 |
|
| 1113 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_MULTASSIGN ); |
| 1114 |
assert( ntmp->size ); |
| 1115 |
|
| 1116 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1117 |
{ |
| 1118 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1119 |
} |
| 1120 |
else |
| 1121 |
{ |
| 1122 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1123 |
} |
| 1124 |
/* trace the result of assignment */ |
| 1125 |
if ( TSD->trace_stat == 'R' ) |
| 1126 |
{ |
| 1127 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1128 |
tracevalue( TSD, ptr, '=' ); |
| 1129 |
FreeTSD( ptr ); |
| 1130 |
} |
| 1131 |
break ; |
| 1132 |
} |
| 1133 |
|
| 1134 |
case X_DIVASSIGN: |
| 1135 |
{ |
| 1136 |
num_descr *ntmp; |
| 1137 |
|
| 1138 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1139 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "/=" ) ; |
| 1140 |
|
| 1141 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_DIVASSIGN ); |
| 1142 |
assert( ntmp->size ); |
| 1143 |
|
| 1144 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1145 |
{ |
| 1146 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1147 |
} |
| 1148 |
else |
| 1149 |
{ |
| 1150 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1151 |
} |
| 1152 |
/* trace the result of assignment */ |
| 1153 |
if ( TSD->trace_stat == 'R' ) |
| 1154 |
{ |
| 1155 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1156 |
tracevalue( TSD, ptr, '=' ); |
| 1157 |
FreeTSD( ptr ); |
| 1158 |
} |
| 1159 |
break ; |
| 1160 |
} |
| 1161 |
|
| 1162 |
case X_INTDIVASSIGN: |
| 1163 |
{ |
| 1164 |
num_descr *ntmp; |
| 1165 |
|
| 1166 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1167 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "%=" ) ; |
| 1168 |
|
| 1169 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_INTDIVASSIGN ); |
| 1170 |
assert( ntmp->size ); |
| 1171 |
|
| 1172 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1173 |
{ |
| 1174 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1175 |
} |
| 1176 |
else |
| 1177 |
{ |
| 1178 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1179 |
} |
| 1180 |
/* trace the result of assignment */ |
| 1181 |
if ( TSD->trace_stat == 'R' ) |
| 1182 |
{ |
| 1183 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1184 |
tracevalue( TSD, ptr, '=' ); |
| 1185 |
FreeTSD( ptr ); |
| 1186 |
} |
| 1187 |
break ; |
| 1188 |
} |
| 1189 |
|
| 1190 |
case X_MODULUSASSIGN: |
| 1191 |
{ |
| 1192 |
num_descr *ntmp; |
| 1193 |
|
| 1194 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1195 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "//=" ) ; |
| 1196 |
|
| 1197 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_MODULUSASSIGN ); |
| 1198 |
assert( ntmp->size ); |
| 1199 |
|
| 1200 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1201 |
{ |
| 1202 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1203 |
} |
| 1204 |
else |
| 1205 |
{ |
| 1206 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1207 |
} |
| 1208 |
/* trace the result of assignment */ |
| 1209 |
if ( TSD->trace_stat == 'R' ) |
| 1210 |
{ |
| 1211 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1212 |
tracevalue( TSD, ptr, '=' ); |
| 1213 |
FreeTSD( ptr ); |
| 1214 |
} |
| 1215 |
break ; |
| 1216 |
} |
| 1217 |
|
| 1218 |
case X_ORASSIGN: |
| 1219 |
{ |
| 1220 |
num_descr *ntmp; |
| 1221 |
|
| 1222 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1223 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "|=" ) ; |
| 1224 |
|
| 1225 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_ORASSIGN ); |
| 1226 |
assert( ntmp->size ); |
| 1227 |
|
| 1228 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1229 |
{ |
| 1230 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1231 |
} |
| 1232 |
else |
| 1233 |
{ |
| 1234 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1235 |
} |
| 1236 |
/* trace the result of assignment */ |
| 1237 |
if ( TSD->trace_stat == 'R' ) |
| 1238 |
{ |
| 1239 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1240 |
tracevalue( TSD, ptr, '=' ); |
| 1241 |
FreeTSD( ptr ); |
| 1242 |
} |
| 1243 |
break ; |
| 1244 |
} |
| 1245 |
|
| 1246 |
case X_XORASSIGN: |
| 1247 |
{ |
| 1248 |
num_descr *ntmp; |
| 1249 |
|
| 1250 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1251 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "&&=" ) ; |
| 1252 |
|
| 1253 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_XORASSIGN ); |
| 1254 |
assert( ntmp->size ); |
| 1255 |
|
| 1256 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1257 |
{ |
| 1258 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1259 |
} |
| 1260 |
else |
| 1261 |
{ |
| 1262 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1263 |
} |
| 1264 |
/* trace the result of assignment */ |
| 1265 |
if ( TSD->trace_stat == 'R' ) |
| 1266 |
{ |
| 1267 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1268 |
tracevalue( TSD, ptr, '=' ); |
| 1269 |
FreeTSD( ptr ); |
| 1270 |
} |
| 1271 |
break ; |
| 1272 |
} |
| 1273 |
|
| 1274 |
case X_ANDASSIGN: |
| 1275 |
{ |
| 1276 |
num_descr *ntmp; |
| 1277 |
|
| 1278 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1279 |
exiterror( ERR_NON_ANSI_FEATURE, 4, "&=" ) ; |
| 1280 |
|
| 1281 |
ntmp = calcul( TSD, thisptr, NULL, SIDE_LEFT, X_ANDASSIGN ); |
| 1282 |
assert( ntmp->size ); |
| 1283 |
|
| 1284 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1285 |
{ |
| 1286 |
fix_compoundnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1287 |
} |
| 1288 |
else |
| 1289 |
{ |
| 1290 |
setshortcutnum( TSD, thisptr->p[0], ntmp, NULL ); |
| 1291 |
} |
| 1292 |
/* trace the result of assignment */ |
| 1293 |
if ( TSD->trace_stat == 'R' ) |
| 1294 |
{ |
| 1295 |
streng *ptr = str_norm( TSD, ntmp, NULL ); |
| 1296 |
tracevalue( TSD, ptr, '=' ); |
| 1297 |
FreeTSD( ptr ); |
| 1298 |
} |
| 1299 |
break ; |
| 1300 |
} |
| 1301 |
|
| 1302 |
case X_CONCATASSIGN: |
| 1303 |
{ |
| 1304 |
streng *value ; |
| 1305 |
|
| 1306 |
value = evaluate( TSD, thisptr, NULL ) ; |
| 1307 |
if (thisptr->p[0]->type==X_HEAD_SYMBOL) |
| 1308 |
fix_compound( TSD, thisptr->p[0], value ) ; |
| 1309 |
else |
| 1310 |
setshortcut( TSD, thisptr->p[0], value ) ; |
| 1311 |
/* trace the result of assignment */ |
| 1312 |
if ( TSD->trace_stat == 'R' ) |
| 1313 |
{ |
| 1314 |
tracevalue( TSD, value, '=' ); |
| 1315 |
} |
| 1316 |
break ; |
| 1317 |
} |
| 1318 |
|
| 1319 |
case X_IPRET: |
| 1320 |
{ |
| 1321 |
streng *retval, *tptr = evaluate(TSD,thisptr->p[0],NULL) ; |
| 1322 |
retval = dointerpret( TSD, tptr ) ; |
| 1323 |
if (retval != NULL) /* we interpreted a RETURN WITH a value */ |
| 1324 |
{ |
| 1325 |
stackelem *top = stacktop(TSD); |
| 1326 |
unsigned i1; |
| 1327 |
for (i1 = stacktrigger(TSD);i1 > stktrigger;i1--,top = top->prev) |
| 1328 |
{ |
| 1329 |
if (top->increment == s.increment) |
| 1330 |
s.increment = NULL; |
| 1331 |
if (top->stopval == s.stopval) |
| 1332 |
s.stopval = NULL; |
| 1333 |
#ifdef OPT_DO |
| 1334 |
if (top->do_for_val == s.do_for_val) |
| 1335 |
s.do_for_val = NULL; |
| 1336 |
#endif |
| 1337 |
} |
| 1338 |
|
| 1339 |
stackcleanup(TSD,stktrigger); |
| 1340 |
nstackcleanup(TSD,nstktrigger,NULL); |
| 1341 |
return( retval ) ; |
| 1342 |
} |
| 1343 |
break ; |
| 1344 |
} |
| 1345 |
|
| 1346 |
case X_NO_OTHERWISE: |
| 1347 |
exiterror( ERR_WHEN_EXPECTED, 0 ) ; |
| 1348 |
break ; |
| 1349 |
|
| 1350 |
case X_SELECT: |
| 1351 |
nstackpush(TSD,thisptr->next); |
| 1352 |
nstackpush(TSD,thisptr->p[1]); |
| 1353 |
thisptr = thisptr->p[0] ; |
| 1354 |
goto fakerecurse ; |
| 1355 |
|
| 1356 |
case X_WHEN: |
| 1357 |
{ |
| 1358 |
int retval = isboolean( TSD, thisptr->p[0], 2, NULL ); |
| 1359 |
nodeptr n; |
| 1360 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 1361 |
{ |
| 1362 |
n = thisptr->p[0]->next; |
| 1363 |
while ( n != NULL ) { |
| 1364 |
traceline( TSD, n, TSD->trace_stat, 0 ); |
| 1365 |
n = n->next; |
| 1366 |
} |
| 1367 |
} |
| 1368 |
if ( retval ) |
| 1369 |
{ |
| 1370 |
nstackpop(TSD); /* kill the OTHERWISE on the stack */ |
| 1371 |
thisptr = thisptr->p[1] ; |
| 1372 |
goto fakerecurse ; |
| 1373 |
} |
| 1374 |
break ; |
| 1375 |
} |
| 1376 |
|
| 1377 |
case X_SAY: |
| 1378 |
{ |
| 1379 |
int ok=HOOK_GO_ON ; |
| 1380 |
streng *stringen,*kill=NULL; |
| 1381 |
|
| 1382 |
if (thisptr->p[0]) |
| 1383 |
stringen = evaluate( TSD, thisptr->p[0], &kill ); |
| 1384 |
else |
| 1385 |
stringen = NULL ; |
| 1386 |
|
| 1387 |
if (TSD->systeminfo->hooks & HOOK_MASK(HOOK_STDOUT)) |
| 1388 |
ok = hookup_output( TSD, HOOK_STDOUT, stringen ) ; |
| 1389 |
|
| 1390 |
if (ok==HOOK_GO_ON) |
| 1391 |
{ |
| 1392 |
if (stringen) |
| 1393 |
{ |
| 1394 |
#ifdef WIN32 |
| 1395 |
/* |
| 1396 |
* Due to a bug in Windows that gives an error |
| 1397 |
* if you try to write too many characters to the |
| 1398 |
* console in one attempt, split the output |
| 1399 |
* up into chunks. |
| 1400 |
* Bug: 1455211 |
| 1401 |
*/ |
| 1402 |
char *buf = stringen->value; |
| 1403 |
long done,chunk; |
| 1404 |
long todo = Str_len(stringen); |
| 1405 |
do |
| 1406 |
{ |
| 1407 |
chunk = min( todo, 0x8000); |
| 1408 |
done = fwrite( buf, chunk, 1, stdout ) ; |
| 1409 |
buf += chunk ; |
| 1410 |
todo -= chunk ; |
| 1411 |
} while ( todo > 0 ) ; |
| 1412 |
#else |
| 1413 |
fwrite( stringen->value, Str_len(stringen), 1, stdout ) ; |
| 1414 |
#endif |
| 1415 |
} |
| 1416 |
#if defined(DOS) || defined(OS2) || defined(WIN32) |
| 1417 |
/* |
| 1418 |
* stdout is open in binary mode, so we need to add the |
| 1419 |
* extra CR to the end of the line. |
| 1420 |
*/ |
| 1421 |
fputc( REGINA_CR, stdout ) ; |
| 1422 |
#endif |
| 1423 |
fputc( REGINA_EOL, stdout ) ; |
| 1424 |
fflush( stdout ) ; |
| 1425 |
} |
| 1426 |
|
| 1427 |
if (stringen && kill) |
| 1428 |
Free_stringTSD( kill ); |
| 1429 |
|
| 1430 |
break ; |
| 1431 |
} |
| 1432 |
|
| 1433 |
case X_TRACE: |
| 1434 |
{ |
| 1435 |
streng *tptr ; |
| 1436 |
|
| 1437 |
if (!TSD->systeminfo->trace_override) |
| 1438 |
{ |
| 1439 |
if (thisptr->name) |
| 1440 |
{ |
| 1441 |
set_trace( TSD, thisptr->name ) ; |
| 1442 |
} |
| 1443 |
else if (thisptr->p[0]) |
| 1444 |
{ |
| 1445 |
set_trace( TSD, evaluate(TSD,thisptr->p[0], &tptr ) ); |
| 1446 |
if ( tptr ) |
| 1447 |
Free_stringTSD( tptr ) ; |
| 1448 |
} |
| 1449 |
else |
| 1450 |
{ |
| 1451 |
/* default setting for TRACE with no arguments is "N" */ |
| 1452 |
streng *tmp = Str_ncre_TSD( TSD, "N", 1 ); |
| 1453 |
set_trace( TSD, tmp ); |
| 1454 |
Free_stringTSD( tmp ); |
| 1455 |
} |
| 1456 |
} |
| 1457 |
|
| 1458 |
break ; |
| 1459 |
} |
| 1460 |
|
| 1461 |
case X_EXIT: |
| 1462 |
{ |
| 1463 |
streng *result; |
| 1464 |
|
| 1465 |
if ( thisptr->p[0] ) |
| 1466 |
result = evaluate( TSD, thisptr->p[0], NULL ); |
| 1467 |
else |
| 1468 |
result = NULL; |
| 1469 |
|
| 1470 |
TSD->instore_is_errorfree = 1; |
| 1471 |
jump_script_exit( TSD, result ); |
| 1472 |
|
| 1473 |
break; |
| 1474 |
} |
| 1475 |
|
| 1476 |
case X_COMMAND: |
| 1477 |
{ |
| 1478 |
streng *stmp,*kill; |
| 1479 |
|
| 1480 |
update_envirs( TSD, TSD->currlevel ) ; |
| 1481 |
if (thisptr->p[0]) |
| 1482 |
{ |
| 1483 |
/* bja - added Free_stringTSD() around perform() */ |
| 1484 |
stmp = evaluate( TSD, thisptr->p[0], &kill ); |
| 1485 |
Free_stringTSD(perform(TSD, stmp, TSD->currlevel->environment, thisptr, NULL)) ; |
| 1486 |
if ( kill ) |
| 1487 |
Free_stringTSD( kill ); |
| 1488 |
break ; |
| 1489 |
} |
| 1490 |
} |
| 1491 |
|
| 1492 |
case X_ADDR_N: /* ADDRESS environment [expr] */ |
| 1493 |
{ |
| 1494 |
streng *envir,*tmp,*kill; |
| 1495 |
update_envirs( TSD, TSD->currlevel ) ; |
| 1496 |
envir = thisptr->name ; |
| 1497 |
if (thisptr->p[0]) |
| 1498 |
{ |
| 1499 |
/* |
| 1500 |
* This path is executed when the command is: |
| 1501 |
* ADDRESS env [command] WITH [expr] |
| 1502 |
* ie. executing a command |
| 1503 |
*/ |
| 1504 |
/* bja - added Free_stringTSD() around perform() */ |
| 1505 |
/* the IO-redirection is temporarily in this case. */ |
| 1506 |
tmp = evaluate( TSD, thisptr->p[0], &kill ); |
| 1507 |
Free_stringTSD(perform(TSD, tmp, envir, thisptr, thisptr->p[1])); |
| 1508 |
if ( kill ) |
| 1509 |
Free_stringTSD( kill ) ; |
| 1510 |
} |
| 1511 |
else |
| 1512 |
{ |
| 1513 |
/* |
| 1514 |
* This path is executed when the command is: |
| 1515 |
* ADDRESS env WITH [expr] |
| 1516 |
* ie. setting the default address, but not executing anything |
| 1517 |
*/ |
| 1518 |
set_envir( TSD, envir, thisptr->p[1] ) ; |
| 1519 |
Free_stringTSD( TSD->currlevel->prev_env ) ; |
| 1520 |
TSD->currlevel->prev_env = TSD->currlevel->environment ; |
| 1521 |
TSD->currlevel->environment = Str_dupTSD(envir) ; |
| 1522 |
} |
| 1523 |
break ; |
| 1524 |
} |
| 1525 |
|
| 1526 |
|
| 1527 |
case X_ADDR_V: /* ADDRESS [VALUE] expr */ |
| 1528 |
{ |
| 1529 |
streng *cptr ; |
| 1530 |
|
| 1531 |
if ( thisptr->u.nonansi && |
| 1532 |
get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1533 |
exiterror( ERR_NON_ANSI_FEATURE, 2, "ADDRESS \"(\"...\")\"") ; |
| 1534 |
|
| 1535 |
update_envirs( TSD, TSD->currlevel ) ; |
| 1536 |
cptr = evaluate(TSD,thisptr->p[0],NULL) ; |
| 1537 |
set_envir( TSD, cptr, thisptr->p[1] ) ; |
| 1538 |
Free_stringTSD( TSD->currlevel->prev_env ) ; |
| 1539 |
TSD->currlevel->prev_env = TSD->currlevel->environment ; |
| 1540 |
TSD->currlevel->environment = cptr ; |
| 1541 |
break ; |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
case X_ADDR_S: /* ADDRESS */ |
| 1546 |
{ |
| 1547 |
streng *tptr ; |
| 1548 |
|
| 1549 |
update_envirs( TSD, TSD->currlevel ) ; |
| 1550 |
tptr = TSD->currlevel->environment ; |
| 1551 |
TSD->currlevel->environment = TSD->currlevel->prev_env ; |
| 1552 |
TSD->currlevel->prev_env = tptr ; |
| 1553 |
break ; |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
case X_DROP: |
| 1558 |
{ |
| 1559 |
nodeptr nptr ; |
| 1560 |
for (nptr=thisptr->p[0]; nptr; nptr=nptr->p[0] ) |
| 1561 |
{ |
| 1562 |
if (nptr->name) |
| 1563 |
{ |
| 1564 |
if (nptr->type == X_SIM_SYMBOL) |
| 1565 |
{ |
| 1566 |
drop_var( TSD, nptr->name ) ; |
| 1567 |
} |
| 1568 |
else |
| 1569 |
{ |
| 1570 |
if (nptr->type == X_IND_SYMBOL) |
| 1571 |
{ |
| 1572 |
int begin,end; |
| 1573 |
streng *name; |
| 1574 |
const streng *value = shortcut(TSD,nptr) ; |
| 1575 |
|
| 1576 |
/* Chop space separated words and drop them one by one */ |
| 1577 |
for (end = 0;;) |
| 1578 |
{ |
| 1579 |
begin = end; /* end of last word processed + 1 */ |
| 1580 |
while ((begin < Str_len(value)) && |
| 1581 |
rx_isspace(value->value[begin])) |
| 1582 |
begin++; |
| 1583 |
if (begin == Str_len(value)) |
| 1584 |
break; |
| 1585 |
end = begin + 1; /* find next separator */ |
| 1586 |
while ((end < Str_len(value)) && |
| 1587 |
!rx_isspace(value->value[end])) |
| 1588 |
end++; |
| 1589 |
/* end now on space after word or past end of string */ |
| 1590 |
name = Str_makeTSD(end - begin); |
| 1591 |
name->len = end - begin; |
| 1592 |
memcpy(name->value, value->value + begin, Str_len(name)); |
| 1593 |
Str_upper(name); |
| 1594 |
drop_var( TSD, name ) ; |
| 1595 |
Free_stringTSD( name ) ; |
| 1596 |
} |
| 1597 |
} |
| 1598 |
} |
| 1599 |
} |
| 1600 |
} |
| 1601 |
break ; |
| 1602 |
} |
| 1603 |
|
| 1604 |
case X_UPPER_VAR: |
| 1605 |
{ |
| 1606 |
/* |
| 1607 |
* If we are running in STRICT_ANSI mode, disallow this |
| 1608 |
* keyword. |
| 1609 |
* Copy the code above for DROP. |
| 1610 |
* Need to cause error if stem variable is specified |
| 1611 |
* Need to handle NOVALUE |
| 1612 |
*/ |
| 1613 |
nodeptr nptr ; |
| 1614 |
|
| 1615 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1616 |
exiterror( ERR_NON_ANSI_FEATURE, 2, "UPPER" ) ; |
| 1617 |
for (nptr=thisptr->p[0]; nptr; nptr=nptr->p[0] ) |
| 1618 |
{ |
| 1619 |
if (nptr->name) |
| 1620 |
{ |
| 1621 |
if (nptr->type == X_SIM_SYMBOL) |
| 1622 |
{ |
| 1623 |
upper_var( TSD, nptr->name ) ; |
| 1624 |
} |
| 1625 |
else |
| 1626 |
{ |
| 1627 |
if (nptr->type == X_IND_SYMBOL) |
| 1628 |
{ |
| 1629 |
int begin,end; |
| 1630 |
streng *name; |
| 1631 |
const streng *value = shortcut(TSD,nptr) ; |
| 1632 |
|
| 1633 |
/* Chop space separated words and drop them one by one */ |
| 1634 |
for (end = 0;;) |
| 1635 |
{ |
| 1636 |
begin = end; /* end of last word processed + 1 */ |
| 1637 |
while ((begin < Str_len(value)) && |
| 1638 |
rx_isspace(value->value[begin])) |
| 1639 |
begin++; |
| 1640 |
if (begin == Str_len(value)) |
| 1641 |
break; |
| 1642 |
end = begin + 1; /* find next separator */ |
| 1643 |
while ((end < Str_len(value)) && |
| 1644 |
!rx_isspace(value->value[end])) |
| 1645 |
end++; |
| 1646 |
/* end now on space after word or past end of string */ |
| 1647 |
name = Str_makeTSD(end - begin); |
| 1648 |
name->len = end - begin; |
| 1649 |
memcpy(name->value, value->value + begin, Str_len(name)); |
| 1650 |
Str_upper(name); |
| 1651 |
upper_var( TSD, name ) ; |
| 1652 |
Free_stringTSD( name ) ; |
| 1653 |
} |
| 1654 |
} |
| 1655 |
} |
| 1656 |
} |
| 1657 |
} |
| 1658 |
break ; |
| 1659 |
} |
| 1660 |
|
| 1661 |
case X_SIG_SET: |
| 1662 |
case X_CALL_SET: |
| 1663 |
{ |
| 1664 |
int type ; |
| 1665 |
trap *traps = gettraps( TSD, TSD->currlevel ) ; |
| 1666 |
|
| 1667 |
/* which kind of condition is this? */ |
| 1668 |
type = identify_trap( thisptr->p[1]->type ) ; |
| 1669 |
|
| 1670 |
/* We always set this */ |
| 1671 |
traps[type].invoked = (thisptr->type == X_SIG_SET) ; |
| 1672 |
traps[type].delayed = 0 ; |
| 1673 |
traps[type].on_off = (thisptr->p[0]->type == X_ON ) ; |
| 1674 |
|
| 1675 |
/* set the name of the variable to work on */ |
| 1676 |
FREE_IF_DEFINED( TSD, traps[type].name ) ; |
| 1677 |
if (thisptr->name) |
| 1678 |
traps[type].name = Str_dupTSD( thisptr->name ) ; |
| 1679 |
else if (thisptr->p[0]->type == X_ON) |
| 1680 |
traps[type].name = Str_creTSD( signalnames[type] ) ; |
| 1681 |
|
| 1682 |
break ; |
| 1683 |
} |
| 1684 |
|
| 1685 |
case X_SIG_VAL: |
| 1686 |
case X_SIG_LAB: |
| 1687 |
{ |
| 1688 |
streng *cptr, *kill=NULL; |
| 1689 |
volatile char *tmp_str; |
| 1690 |
stackelem *top; |
| 1691 |
unsigned i1; |
| 1692 |
|
| 1693 |
cptr = (thisptr->name) ? thisptr->name : evaluate( TSD, thisptr->p[0], &kill ); |
| 1694 |
nstackcleanup( TSD, nstktrigger, NULL ); |
| 1695 |
top = stacktop( TSD ); |
| 1696 |
for ( i1 = stacktrigger( TSD ); i1 > stktrigger; i1--, top = top->prev ) |
| 1697 |
{ |
| 1698 |
if ( top->increment == s.increment ) |
| 1699 |
s.increment = NULL; |
| 1700 |
if ( top->stopval == s.stopval ) |
| 1701 |
s.stopval = NULL; |
| 1702 |
#ifdef OPT_DO |
| 1703 |
if ( top->do_for_val == s.do_for_val ) |
| 1704 |
s.do_for_val = NULL; |
| 1705 |
#endif |
| 1706 |
} |
| 1707 |
|
| 1708 |
stackcleanup( TSD, stktrigger ); |
| 1709 |
/* |
| 1710 |
* Fixes bug 764458 |
| 1711 |
*/ |
| 1712 |
innerloop = NULL; |
| 1713 |
|
| 1714 |
entry = getlabel( TSD, cptr ); |
| 1715 |
/* |
| 1716 |
* We have to make a temporary copy of the label we are signalling |
| 1717 |
* in case it doesn't exist because the "kill" processing will destroy |
| 1718 |
* the value. |
| 1719 |
* Also set_reserved_value() also destroys the value. |
| 1720 |
*/ |
| 1721 |
tmp_str = tmpstr_of( TSD, cptr ); |
| 1722 |
|
| 1723 |
set_reserved_value( TSD, POOL0_SIGL, NULL, thisptr->lineno, VFLAG_NUM ); |
| 1724 |
|
| 1725 |
if ( kill ) |
| 1726 |
Free_stringTSD( kill ); |
| 1727 |
|
| 1728 |
if ( entry == NULL ) |
| 1729 |
exiterror( ERR_UNEXISTENT_LABEL, 1, tmp_str ); |
| 1730 |
if ( entry->u.trace_only ) |
| 1731 |
exiterror( ERR_UNEXISTENT_LABEL, 2, tmpstr_of( TSD, entry->name) ); |
| 1732 |
thisptr = entry->next; |
| 1733 |
goto fakerecurse; |
| 1734 |
} |
| 1735 |
case X_PROC: |
| 1736 |
{ |
| 1737 |
treenode *ptr; |
| 1738 |
|
| 1739 |
if (TSD->currlevel->varflag) |
| 1740 |
exiterror( ERR_UNEXPECTED_PROC, 1 ) ; |
| 1741 |
|
| 1742 |
for (ptr=thisptr->p[0];(ptr);ptr=ptr->p[0]) |
| 1743 |
{ |
| 1744 |
if (ptr->name) |
| 1745 |
{ |
| 1746 |
expose_var(TSD,ptr->name) ; |
| 1747 |
if (ptr->type==X_IND_SYMBOL) |
| 1748 |
expose_indir( TSD, getvalue( TSD, ptr->name, -1 ) ); |
| 1749 |
else |
| 1750 |
assert( ptr->type==X_SIM_SYMBOL) ; |
| 1751 |
} |
| 1752 |
else |
| 1753 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 1754 |
} |
| 1755 |
expose_var(TSD,NULL) ; |
| 1756 |
break ; |
| 1757 |
} |
| 1758 |
case X_CALL: |
| 1759 |
{ |
| 1760 |
nodeptr n; |
| 1761 |
|
| 1762 |
/* |
| 1763 |
* Find an internal label matching the label on the CALL |
| 1764 |
* statement, and determine if its in internal of external |
| 1765 |
* subroutine call. |
| 1766 |
*/ |
| 1767 |
n = getlabel( TSD, thisptr->name ); |
| 1768 |
if ( n ) |
| 1769 |
{ |
| 1770 |
if ( n->u.trace_only ) |
| 1771 |
exiterror( ERR_UNEXISTENT_LABEL, 3, tmpstr_of( TSD, n->name ) ); |
| 1772 |
thisptr->type = X_IS_INTERNAL; |
| 1773 |
} |
| 1774 |
else |
| 1775 |
thisptr->type = X_IS_BUILTIN; |
| 1776 |
thisptr->u.node = n; |
| 1777 |
thisptr->o.called = 1; |
| 1778 |
} |
| 1779 |
/* THIS IS MEANT TO FALL THROUGH! */ |
| 1780 |
case X_IS_INTERNAL: |
| 1781 |
{ |
| 1782 |
paramboxptr args; |
| 1783 |
streng *result; |
| 1784 |
|
| 1785 |
if ( thisptr->u.node ) |
| 1786 |
{ |
| 1787 |
no_next_interactive = 1; |
| 1788 |
args = initplist( TSD, thisptr ); |
| 1789 |
set_reserved_value( TSD, POOL0_SIGL, NULL, thisptr->lineno, VFLAG_NUM ); |
| 1790 |
|
| 1791 |
result = CallInternalFunction( TSD, thisptr->u.node, thisptr, args ); |
| 1792 |
|
| 1793 |
TSD->systeminfo->interactive = TSD->currlevel->traceint; |
| 1794 |
|
| 1795 |
set_reserved_value( TSD, POOL0_RESULT, result, 0, ( result ) ? VFLAG_STR : VFLAG_NONE ); |
| 1796 |
break; |
| 1797 |
} |
| 1798 |
} |
| 1799 |
/* THIS IS MEANT TO FALL THROUGH! */ |
| 1800 |
case X_EX_FUNC: |
| 1801 |
case X_IS_BUILTIN: |
| 1802 |
{ |
| 1803 |
streng *result ; |
| 1804 |
|
| 1805 |
/* |
| 1806 |
* Call a builtin procedure... |
| 1807 |
*/ |
| 1808 |
if ((result = buildtinfunc( TSD, thisptr )) == NOFUNC) |
| 1809 |
{ |
| 1810 |
/* |
| 1811 |
* ... and it wasn't a builtin procedure so assume its an external function |
| 1812 |
*/ |
| 1813 |
thisptr->type = X_IS_EXTERNAL ; |
| 1814 |
} |
| 1815 |
else |
| 1816 |
{ |
| 1817 |
/* |
| 1818 |
* ... and if it was a builtin procedure set RESULT and break |
| 1819 |
*/ |
| 1820 |
set_reserved_value( TSD, POOL0_RESULT, result, 0, |
| 1821 |
( result ) ? VFLAG_STR : VFLAG_NONE ); |
| 1822 |
|
| 1823 |
break ; |
| 1824 |
} |
| 1825 |
} |
| 1826 |
/* THIS IS MEANT TO FALL THROUGH! */ |
| 1827 |
case X_IS_EXTERNAL: |
| 1828 |
{ |
| 1829 |
streng *ptr, *command; |
| 1830 |
paramboxptr args, targs; |
| 1831 |
int len,err; |
| 1832 |
|
| 1833 |
if ( TSD->restricted ) |
| 1834 |
exiterror( ERR_RESTRICTED, 5 ); |
| 1835 |
|
| 1836 |
update_envirs( TSD, TSD->currlevel ); |
| 1837 |
|
| 1838 |
args = targs = initplist( TSD, thisptr ); |
| 1839 |
stackmark = pushcallstack( TSD, TSD->currentnode ); |
| 1840 |
ptr = execute_external( TSD, |
| 1841 |
thisptr->name, |
| 1842 |
args, |
| 1843 |
TSD->systeminfo->environment, |
| 1844 |
&err, |
| 1845 |
/* Fixes bug 604219 */ |
| 1846 |
TSD->systeminfo->hooks, |
| 1847 |
INVO_SUBROUTINE ); |
| 1848 |
popcallstack( TSD, stackmark ); |
| 1849 |
|
| 1850 |
if ( ptr == thisptr->name ) |
| 1851 |
{ |
| 1852 |
/* |
| 1853 |
* FIXME,MH: no idea what this does |
| 1854 |
* FGC: agreed, added an assert. Remove this block in |
| 1855 |
* complete in 2005 if nothing happens. |
| 1856 |
*/ |
| 1857 |
assert( ptr ); |
| 1858 |
ptr = NULL; |
| 1859 |
} |
| 1860 |
|
| 1861 |
if ( err == -ERR_PROG_UNREADABLE ) |
| 1862 |
{ |
| 1863 |
/* |
| 1864 |
* "thisptr->name" wasn't an external Rexx program, so |
| 1865 |
* see if it is an OS command |
| 1866 |
* Only do this if the OPTIONS EXT_COMMANDS_AS_FUNCS is |
| 1867 |
* set and STRICT_ANSI is NOT set. |
| 1868 |
*/ |
| 1869 |
if ( get_options_flag( TSD->currlevel, EXT_EXT_COMMANDS_AS_FUNCS ) |
| 1870 |
&& !get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1871 |
{ |
| 1872 |
len = Str_len( thisptr->name ); |
| 1873 |
for( targs = args; targs; targs = targs->next ) |
| 1874 |
{ |
| 1875 |
if ( targs->value ) |
| 1876 |
len += 1 + Str_len( targs->value ); |
| 1877 |
} |
| 1878 |
command = Str_makeTSD( len ); |
| 1879 |
command = Str_catTSD( command, thisptr->name ); |
| 1880 |
for( targs = args; targs; targs = targs->next ) |
| 1881 |
{ |
| 1882 |
if ( targs->value ) |
| 1883 |
{ |
| 1884 |
command = Str_catstrTSD( command, " " ); |
| 1885 |
command = Str_catTSD( command, targs->value ); |
| 1886 |
} |
| 1887 |
} |
| 1888 |
ptr = run_popen( TSD, command, TSD->currlevel->environment ); |
| 1889 |
if ( ptr != NULL ) |
| 1890 |
err = 0; |
| 1891 |
Free_stringTSD( command ); |
| 1892 |
} |
| 1893 |
} |
| 1894 |
|
| 1895 |
deallocplink( TSD, args ); |
| 1896 |
|
| 1897 |
if ( ptr && ( TSD->trace_stat == 'I' ) ) |
| 1898 |
tracevalue( TSD, ptr, 'F' ); |
| 1899 |
|
| 1900 |
if ( ptr ) |
| 1901 |
set_reserved_value( TSD, POOL0_RESULT, ptr, 0, VFLAG_STR ); |
| 1902 |
else |
| 1903 |
set_reserved_value( TSD, POOL0_RESULT, NULL, 0, VFLAG_NONE ); |
| 1904 |
|
| 1905 |
if ( err == -ERR_PROG_UNREADABLE ) |
| 1906 |
{ |
| 1907 |
exiterror( ERR_ROUTINE_NOT_FOUND, 1, tmpstr_of( TSD, thisptr->name ) ); |
| 1908 |
} |
| 1909 |
else if ( err ) |
| 1910 |
{ |
| 1911 |
post_process_system_call( TSD, thisptr->name, -err, NULL, thisptr ); |
| 1912 |
} |
| 1913 |
|
| 1914 |
break; |
| 1915 |
} |
| 1916 |
|
| 1917 |
case X_PARSE: |
| 1918 |
{ |
| 1919 |
/* |
| 1920 |
* We always have to produce a duplicate of the content we have to |
| 1921 |
* parse. We can't use variable locking and we can't assume that |
| 1922 |
* the content doesn't contain variable names used in the template. |
| 1923 |
* This fixes bug 688503. |
| 1924 |
*/ |
| 1925 |
|
| 1926 |
if ( thisptr->u.parseflags & ( PARSE_LOWER | PARSE_CASELESS ) ) |
| 1927 |
{ |
| 1928 |
if ( get_options_flag( TSD->currlevel, EXT_STRICT_ANSI ) ) |
| 1929 |
exiterror( ERR_NON_ANSI_FEATURE, 2, |
| 1930 |
( thisptr->u.parseflags & PARSE_LOWER ) ? "PARSE LOWER" : |
| 1931 |
"PARSE CASELESS" ) ; |
| 1932 |
} |
| 1933 |
if ( thisptr->p[0]->type == X_PARSE_ARG ) |
| 1934 |
{ |
| 1935 |
parseargtree( TSD, TSD->currlevel->args, thisptr->p[1], |
| 1936 |
thisptr->u.parseflags ); |
| 1937 |
} |
| 1938 |
else |
| 1939 |
{ |
| 1940 |
streng *source = NULL; |
| 1941 |
nodeptr templ; |
| 1942 |
|
| 1943 |
switch ( thisptr->p[0]->type ) |
| 1944 |
{ |
| 1945 |
case X_PARSE_VAR: |
| 1946 |
/* must duplicate, parsing may have side effects */ |
| 1947 |
/* else, we must have locking of variables */ |
| 1948 |
source = Str_dupTSD( shortcut( TSD, thisptr->p[0] ) ); |
| 1949 |
break ; |
| 1950 |
|
| 1951 |
case X_PARSE_VAL: |
| 1952 |
{ |
| 1953 |
/* |
| 1954 |
* Must duplicate, parsing may have side effects, we must |
| 1955 |
* have locking of variables otherwise. |
| 1956 |
* fixes bug ? |
| 1957 |
*/ |
| 1958 |
/* |
| 1959 |
* Empty value allowed. |
| 1960 |
* Fixes bug 952229 |
| 1961 |
*/ |
| 1962 |
if ( thisptr->p[0]->p[0] ) |
| 1963 |
source = evaluate( TSD, thisptr->p[0]->p[0], NULL ); |
| 1964 |
else |
| 1965 |
source = nullstringptr(); |
| 1966 |
break ; |
| 1967 |
} |
| 1968 |
|
| 1969 |
case X_PARSE_PULL: |
| 1970 |
source = popline( TSD, NULL, NULL, 0 ); |
| 1971 |
break ; |
| 1972 |
|
| 1973 |
case X_PARSE_VER: |
| 1974 |
source = Str_creTSD( PARSE_VERSION_STRING ); |
| 1975 |
break ; |
| 1976 |
|
| 1977 |
case X_PARSE_EXT: |
| 1978 |
source = readkbdline( TSD ); |
| 1979 |
break ; |
| 1980 |
|
| 1981 |
case X_PARSE_SRC: |
| 1982 |
{ |
| 1983 |
const char *stype ; |
| 1984 |
streng *inpfile; |
| 1985 |
|
| 1986 |
stype = system_type(); |
| 1987 |
inpfile = TSD->systeminfo->input_file; |
| 1988 |
source = Str_makeTSD( strlen( stype ) + 4 + |
| 1989 |
strlen( invo_strings[TSD->systeminfo->invoked] ) + |
| 1990 |
Str_len( inpfile ) ); |
| 1991 |
source->len = 0; |
| 1992 |
|
| 1993 |
Str_catstrTSD( source, stype ); |
| 1994 |
Str_catstrTSD( source, " " ); |
| 1995 |
Str_catstrTSD( source, invo_strings[TSD->systeminfo->invoked] ); |
| 1996 |
Str_catstrTSD( source, " " ); |
| 1997 |
Str_catTSD( source, inpfile ); |
| 1998 |
break; |
| 1999 |
} |
| 2000 |
} |
| 2001 |
|
| 2002 |
if ( thisptr->u.parseflags & PARSE_UPPER ) |
| 2003 |
{ |
| 2004 |
Str_upper( source ); |
| 2005 |
} |
| 2006 |
if ( thisptr->u.parseflags & PARSE_LOWER ) |
| 2007 |
{ |
| 2008 |
Str_lower( source ); |
| 2009 |
} |
| 2010 |
|
| 2011 |
doparse( TSD, source, thisptr->p[1], |
| 2012 |
thisptr->u.parseflags & PARSE_CASELESS ); |
| 2013 |
|
| 2014 |
for ( templ = thisptr->p[1]->next; templ != NULL; templ = templ->next ) |
| 2015 |
{ |
| 2016 |
/* |
| 2017 |
* This fixes bug 755801. |
| 2018 |
* Actually, this will happen rarely, but we have to assign the |
| 2019 |
* empty string to all template members of all comma-separated |
| 2020 |
* lists of templates except of the first one. |
| 2021 |
* We use the slow and long-term reliable code of doparse(). |
| 2022 |
*/ |
| 2023 |
Str_len( source ) = 0; |
| 2024 |
doparse( TSD, source, templ, 0 ); |
| 2025 |
} |
| 2026 |
|
| 2027 |
|
| 2028 |
Free_stringTSD( source ); |
| 2029 |
} |
| 2030 |
break; |
| 2031 |
} |
| 2032 |
|
| 2033 |
case X_PULL: |
| 2034 |
{ |
| 2035 |
streng *stmp ; |
| 2036 |
|
| 2037 |
doparse(TSD, stmp=Str_upper(popline( TSD, NULL, NULL, 0 )), thisptr->p[0], 0 ) ; |
| 2038 |
Free_stringTSD( stmp ) ; |
| 2039 |
break ; |
| 2040 |
} |
| 2041 |
|
| 2042 |
case X_PUSH: |
| 2043 |
stack_lifo( TSD, (thisptr->p[0]) ? evaluate(TSD,thisptr->p[0],NULL) : nullstringptr(), NULL ) ; |
| 2044 |
break ; |
| 2045 |
|
| 2046 |
case X_QUEUE: |
| 2047 |
stack_fifo( TSD, (thisptr->p[0]) ? evaluate(TSD,thisptr->p[0],NULL) : nullstringptr(), NULL ) ; |
| 2048 |
break ; |
| 2049 |
|
| 2050 |
case X_OPTIONS: /* fixes 1116894 */ |
| 2051 |
do_options(TSD, TSD->currlevel, (thisptr->p[0]) ? evaluate(TSD,thisptr->p[0],NULL) : nullstringptr(), 0) ; |
| 2052 |
break ; |
| 2053 |
|
| 2054 |
case X_RETURN: |
| 2055 |
{ |
| 2056 |
stackelem *top; |
| 2057 |
unsigned i1; |
| 2058 |
streng *retval; |
| 2059 |
|
| 2060 |
/* buggy, need to deallocate procbox and vars ... */ |
| 2061 |
if (thisptr->p[0]) |
| 2062 |
retval = evaluate(TSD,thisptr->p[0],NULL) ; |
| 2063 |
else |
| 2064 |
retval = NULL ; |
| 2065 |
|
| 2066 |
top = stacktop(TSD); |
| 2067 |
for (i1 = stacktrigger(TSD);i1 > stktrigger;i1--,top = top->prev) |
| 2068 |
{ |
| 2069 |
if (top->increment == s.increment) |
| 2070 |
s.increment = NULL; |
| 2071 |
if (top->stopval == s.stopval) |
| 2072 |
s.stopval = NULL; |
| 2073 |
#ifdef OPT_DO |
| 2074 |
if (top->do_for_val == s.do_for_val) |
| 2075 |
s.do_for_val = NULL; |
| 2076 |
#endif |
| 2077 |
} |
| 2078 |
|
| 2079 |
stackcleanup(TSD,stktrigger); |
| 2080 |
nstackcleanup(TSD,nstktrigger,NULL); |
| 2081 |
return( retval ) ; |
| 2082 |
break ; |
| 2083 |
} |
| 2084 |
case X_LEAVE: |
| 2085 |
case X_ITERATE: |
| 2086 |
{ |
| 2087 |
int Stacked; |
| 2088 |
stackelem *top; |
| 2089 |
treenode *iptr; |
| 2090 |
|
| 2091 |
Stacked = stacktrigger(TSD) - stktrigger; |
| 2092 |
|
| 2093 |
if ( innerloop ) |
| 2094 |
{ /* push the current count to let it been found below if "LEAVE name". */ |
| 2095 |
s.thisptr = innerloop; |
| 2096 |
stackpush( TSD, &s ); |
| 2097 |
Stacked++; |
| 2098 |
} |
| 2099 |
|
| 2100 |
top = stacktop(TSD); |
| 2101 |
for ( ;; ) /* while iteration counter name not found */ |
| 2102 |
{ |
| 2103 |
if ( Stacked <= 0 ) |
| 2104 |
{ |
| 2105 |
if ( innerloop ) |
| 2106 |
exiterror( ERR_INVALID_LEAVE, (thisptr->type==X_LEAVE)?3:4, tmpstr_of( TSD, thisptr->name ) ); |
| 2107 |
else |
| 2108 |
exiterror( ERR_INVALID_LEAVE, (thisptr->type==X_LEAVE)?1:2 ); |
| 2109 |
} |
| 2110 |
|
| 2111 |
iptr = top->thisptr; |
| 2112 |
|
| 2113 |
if ( thisptr->name == NULL ) |
| 2114 |
{ |
| 2115 |
/* |
| 2116 |
* LEAVE/ITERATE without any argument. Automatically pop one |
| 2117 |
* stack element later. |
| 2118 |
*/ |
| 2119 |
break; |
| 2120 |
} |
| 2121 |
|
| 2122 |
/* |
| 2123 |
* Backtrace all pending loops and compare the iterator name if |
| 2124 |
* one exists. We have to keep care for unnamed loops like |
| 2125 |
* "do 5 ; say fred ; end". |
| 2126 |
*/ |
| 2127 |
if ( ( iptr->p[0] != NULL ) && |
| 2128 |
( iptr->p[0]->name != NULL ) && |
| 2129 |
( Str_cmp( thisptr->name, iptr->p[0]->name ) == 0 ) ) |
| 2130 |
{ |
| 2131 |
/* |
| 2132 |
* Iterator name equals our argument. Automatically pop one |
| 2133 |
* stack element later. |
| 2134 |
*/ |
| 2135 |
break; |
| 2136 |
} |
| 2137 |
|
| 2138 |
/* |
| 2139 |
* Unnamed loop or a loop with a nonmatching name, cleanup! |
| 2140 |
* fixes bug 672864 |
| 2141 |
*/ |
| 2142 |
popcallstack( TSD, -1 ); |
| 2143 |
if ( top->stopval == s.stopval ) |
| 2144 |
s.stopval = NULL; |
| 2145 |
#ifdef OPT_DO |
| 2146 |
if ( top->do_for_val == s.do_for_val ) |
| 2147 |
s.do_for_val = NULL; |
| 2148 |
#endif |
| 2149 |
if ( top->increment == s.increment ) |
| 2150 |
s.increment = NULL; |
| 2151 |
stack_destroyelement( TSD, top ); |
| 2152 |
|
| 2153 |
Stacked--; |
| 2154 |
top = top->prev; |
| 2155 |
} |
| 2156 |
|
| 2157 |
nstackcleanup(TSD,nstktrigger,&iptr); |
| 2158 |
|
| 2159 |
if (Stacked<=0) |
| 2160 |
exiterror( ERR_INVALID_LEAVE, 0 ); |
| 2161 |
if (thisptr->type==X_LEAVE) |
| 2162 |
{ |
| 2163 |
popcallstack(TSD,-1) ; |
| 2164 |
if (top->stopval == s.stopval ) |
| 2165 |
s.stopval = NULL ; |
| 2166 |
#ifdef OPT_DO |
| 2167 |
if (top->do_for_val == s.do_for_val ) |
| 2168 |
s.do_for_val = NULL ; |
| 2169 |
#endif |
| 2170 |
if ( top->increment == s.increment ) |
| 2171 |
s.increment = NULL ; |
| 2172 |
stack_destroyelement(TSD,top); |
| 2173 |
Stacked--; |
| 2174 |
top = top->prev; |
| 2175 |
|
| 2176 |
nstackpop(TSD); |
| 2177 |
} |
| 2178 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 2179 |
traceline( TSD, iptr, TSD->trace_stat, 0 ); |
| 2180 |
stackcleanup(TSD,stktrigger + Stacked); |
| 2181 |
|
| 2182 |
if (TSD->systeminfo->interactive) |
| 2183 |
{ |
| 2184 |
if (intertrace(TSD)) |
| 2185 |
goto fakerecurse ; |
| 2186 |
} |
| 2187 |
|
| 2188 |
thisptr = nstackpop(TSD); |
| 2189 |
|
| 2190 |
if (Stacked) |
| 2191 |
{ |
| 2192 |
s = stackpop(TSD); |
| 2193 |
innerloop = s.thisptr; |
| 2194 |
} |
| 2195 |
else |
| 2196 |
innerloop = NULL; |
| 2197 |
goto fakereturn ; |
| 2198 |
break ; |
| 2199 |
} |
| 2200 |
case X_NUM_D: |
| 2201 |
{ |
| 2202 |
int tmp, error ; |
| 2203 |
streng *cptr,*kill; |
| 2204 |
volatile char *err ; |
| 2205 |
|
| 2206 |
cptr = evaluate( TSD, thisptr->p[0], &kill ); |
| 2207 |
tmp = streng_to_int( TSD, cptr, &error ); |
| 2208 |
if ( error || tmp <= 0 ) |
| 2209 |
{ |
| 2210 |
err = tmpstr_of( TSD, cptr ); |
| 2211 |
if ( kill ) |
| 2212 |
Free_stringTSD( kill ); |
| 2213 |
exiterror( ERR_INVALID_INTEGER, 5, err ) ; |
| 2214 |
} |
| 2215 |
if ( kill ) |
| 2216 |
Free_stringTSD( kill ); |
| 2217 |
if (TSD->currlevel->numfuzz >= tmp) |
| 2218 |
exiterror( ERR_INVALID_RESULT, 1, tmp, TSD->currlevel->numfuzz ); |
| 2219 |
if (tmp > INT_MAX) |
| 2220 |
exiterror( ERR_INVALID_RESULT, 2, tmp, INT_MAX ) ; |
| 2221 |
TSD->currlevel->currnumsize = tmp ; |
| 2222 |
break ; |
| 2223 |
} |
| 2224 |
|
| 2225 |
case X_NUM_DDEF: |
| 2226 |
if (TSD->currlevel->numfuzz >= DEFAULT_NUMERIC_SIZE) |
| 2227 |
exiterror( ERR_INVALID_RESULT, 1, DEFAULT_NUMERIC_SIZE, TSD->currlevel->numfuzz ) ; |
| 2228 |
TSD->currlevel->currnumsize = DEFAULT_NUMERIC_SIZE ; |
| 2229 |
break ; |
| 2230 |
|
| 2231 |
case X_NUM_FDEF: |
| 2232 |
if (TSD->currlevel->currnumsize <= DEFAULT_NUMERIC_FUZZ) |
| 2233 |
exiterror( ERR_INVALID_RESULT, 1, TSD->currlevel->currnumsize, DEFAULT_NUMERIC_FUZZ ) ; |
| 2234 |
TSD->currlevel->numfuzz = DEFAULT_NUMERIC_FUZZ ; |
| 2235 |
break ; |
| 2236 |
|
| 2237 |
case X_NUM_FRMDEF: |
| 2238 |
TSD->currlevel->numfuzz = DEFAULT_NUMFORM ; |
| 2239 |
break ; |
| 2240 |
|
| 2241 |
case X_NUM_FUZZ: |
| 2242 |
{ |
| 2243 |
int tmp, error ; |
| 2244 |
streng *cptr,*kill; |
| 2245 |
volatile char *err ; |
| 2246 |
|
| 2247 |
cptr = evaluate( TSD, thisptr->p[0], &kill ); |
| 2248 |
tmp = streng_to_int( TSD, cptr, &error ); |
| 2249 |
if ( error || tmp < 0 ) |
| 2250 |
{ |
| 2251 |
err = tmpstr_of( TSD, cptr ); |
| 2252 |
if ( kill ) |
| 2253 |
Free_stringTSD( kill ); |
| 2254 |
exiterror( ERR_INVALID_INTEGER, 6, err ) ; |
| 2255 |
} |
| 2256 |
if ( kill ) |
| 2257 |
Free_stringTSD( kill ); |
| 2258 |
if (TSD->currlevel->currnumsize <= tmp) |
| 2259 |
exiterror( ERR_INVALID_RESULT, 1, TSD->currlevel->currnumsize, tmp ) ; |
| 2260 |
TSD->currlevel->numfuzz = tmp ; |
| 2261 |
break ; |
| 2262 |
} |
| 2263 |
|
| 2264 |
case X_NUM_F: |
| 2265 |
{ |
| 2266 |
if (thisptr->p[0]->type == X_NUM_SCI) |
| 2267 |
TSD->currlevel->numform = NUM_FORM_SCI ; |
| 2268 |
else if (thisptr->p[0]->type == X_NUM_ENG) |
| 2269 |
TSD->currlevel->numform = NUM_FORM_ENG ; |
| 2270 |
else |
| 2271 |
assert( 0 ) ; |
| 2272 |
break ; |
| 2273 |
} |
| 2274 |
|
| 2275 |
case X_NUM_V: |
| 2276 |
{ |
| 2277 |
streng *tmpstr,*kill; |
| 2278 |
int len; |
| 2279 |
char *s1; |
| 2280 |
|
| 2281 |
tmpstr = evaluate( TSD, thisptr->p[0], &kill ); |
| 2282 |
len = tmpstr->len; |
| 2283 |
s1 = tmpstr->value; |
| 2284 |
|
| 2285 |
if ( ( len == 10 ) && ( mem_cmpic( s1, "SCIENTIFIC", 10 ) == 0 ) ) |
| 2286 |
TSD->currlevel->numform = NUM_FORM_SCI ; |
| 2287 |
else if ( ( len == 11 ) && ( mem_cmpic( s1, "ENGINEERING", 11 ) == 0 ) ) |
| 2288 |
TSD->currlevel->numform = NUM_FORM_ENG ; |
| 2289 |
else if ( ( len == 1 ) && ( rx_toupper( *s1 ) == 'S' ) ) |
| 2290 |
TSD->currlevel->numform = NUM_FORM_SCI ; |
| 2291 |
else if ( ( len == 1 ) && ( rx_toupper( *s1 ) == 'E' ) ) |
| 2292 |
TSD->currlevel->numform = NUM_FORM_ENG ; |
| 2293 |
else |
| 2294 |
exiterror( ERR_INVALID_RESULT, 0 ) ; |
| 2295 |
if ( kill ) |
| 2296 |
Free_stringTSD( kill ); |
| 2297 |
break ; |
| 2298 |
} |
| 2299 |
|
| 2300 |
case X_LABEL: |
| 2301 |
case X_NULL: |
| 2302 |
break ; |
| 2303 |
|
| 2304 |
default: |
| 2305 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 2306 |
break ; |
| 2307 |
} |
| 2308 |
|
| 2309 |
if ((TSD->systeminfo->interactive)&&(!no_next_interactive)) |
| 2310 |
{ |
| 2311 |
if (intertrace(TSD)) |
| 2312 |
goto fakerecurse ; |
| 2313 |
} |
| 2314 |
|
| 2315 |
no_next_interactive = 0 ; |
| 2316 |
|
| 2317 |
if (thisptr) |
| 2318 |
thisptr = thisptr->next ; |
| 2319 |
|
| 2320 |
fakereturn: |
| 2321 |
if (!thisptr) |
| 2322 |
{ |
| 2323 |
if (nstacktrigger(TSD) <= nstktrigger) |
| 2324 |
{ |
| 2325 |
stackcleanup(TSD,stktrigger); |
| 2326 |
return NULL ; |
| 2327 |
} |
| 2328 |
else |
| 2329 |
thisptr = nstackpop(TSD); |
| 2330 |
} |
| 2331 |
|
| 2332 |
fakerecurse: |
| 2333 |
|
| 2334 |
/* check if there is any traps to process */ |
| 2335 |
while (TSD->nextsig) |
| 2336 |
{ |
| 2337 |
trap *traps = gettraps( TSD, TSD->currlevel ) ; |
| 2338 |
|
| 2339 |
i = TSD->nextsig->type ; |
| 2340 |
|
| 2341 |
if (i == SIGNAL_NOTREADY) |
| 2342 |
fixup_file( TSD, TSD->nextsig->descr ) ; |
| 2343 |
|
| 2344 |
/* if this condition is in delayed mode, ignore it for now */ |
| 2345 |
if (traps[i].delayed) |
| 2346 |
goto aftersignals ; |
| 2347 |
|
| 2348 |
/* if this condition is no begin trapped, use default action */ |
| 2349 |
if (traps[i].on_off == 0) |
| 2350 |
{ |
| 2351 |
if (traps[i].def_act) |
| 2352 |
goto aftersignals ; /* default==1 ==> ignore it */ |
| 2353 |
else |
| 2354 |
exiterror( TSD->nextsig->rc, 0 ) ; |
| 2355 |
} |
| 2356 |
if (traps[i].invoked) /* invoke as SIGNAL */ |
| 2357 |
{ |
| 2358 |
/* simulate a SIGNAL, first empty the stack */ |
| 2359 |
/* Sorry, not safe to operate on these at this point, we just have to |
| 2360 |
accept that some memory is lost ... "can't make omelette without..." */ |
| 2361 |
/* if (stkidx) |
| 2362 |
* for (stkidx--;stkidx;stkidx--) |
| 2363 |
* { |
| 2364 |
* FREE_IF_DEFINED(TSD,stack[stkidx].increment) ; |
| 2365 |
* FREE_IF_DEFINED(TSD,stack[stkidx].stopval) ; |
| 2366 |
* } |
| 2367 |
*/ /* hey, this should really be ok, .... must be a BUG */ |
| 2368 |
stackcleanup(TSD,stktrigger); /* think it, too. stackcleanup |
| 2369 |
* (re-)introduced Feb. 2000 */ |
| 2370 |
|
| 2371 |
/* turn off the condition */ |
| 2372 |
traps[i].on_off = 0 ; |
| 2373 |
traps[i].delayed = 0 ; |
| 2374 |
/* traps[i].trapped = 0 ; */ |
| 2375 |
|
| 2376 |
/* set the current condition information */ |
| 2377 |
if (TSD->currlevel->sig) |
| 2378 |
{ |
| 2379 |
FREE_IF_DEFINED( TSD, TSD->currlevel->sig->info ) ; |
| 2380 |
FREE_IF_DEFINED( TSD, TSD->currlevel->sig->descr ) ; |
| 2381 |
FreeTSD( TSD->currlevel->sig ) ; |
| 2382 |
} |
| 2383 |
TSD->currlevel->sig = TSD->nextsig ; |
| 2384 |
TSD->nextsig = NULL ; |
| 2385 |
|
| 2386 |
/* simulate the SIGNAL statement */ |
| 2387 |
entry = getlabel( TSD, traps[i].name ) ; |
| 2388 |
set_reserved_value( TSD, POOL0_SIGL, NULL, |
| 2389 |
TSD->currlevel->sig->lineno, VFLAG_NUM ); |
| 2390 |
if (TSD->currlevel->sig->type == SIGNAL_SYNTAX ) |
| 2391 |
set_reserved_value( TSD, POOL0_RC, NULL, TSD->currlevel->sig->rc, |
| 2392 |
VFLAG_NUM ); |
| 2393 |
|
| 2394 |
if ( entry == NULL ) |
| 2395 |
exiterror( ERR_UNEXISTENT_LABEL, 1, tmpstr_of( TSD, traps[i].name ) ); |
| 2396 |
if ( entry->u.trace_only ) |
| 2397 |
exiterror( ERR_UNEXISTENT_LABEL, 2, tmpstr_of( TSD, entry->name ) ); |
| 2398 |
thisptr = entry; |
| 2399 |
nstackcleanup( TSD, nstktrigger, NULL ); |
| 2400 |
goto reinterpret; |
| 2401 |
} |
| 2402 |
else /*if ((i<SIGNALS))*/ /* invoke as CALL */ |
| 2403 |
{ |
| 2404 |
nodeptr savecurrentnode; /* pgb */ |
| 2405 |
streng *h; |
| 2406 |
|
| 2407 |
if ( ( entry = getlabel( TSD, traps[i].name ) ) == NULL ) |
| 2408 |
exiterror( ERR_UNEXISTENT_LABEL, 1, tmpstr_of( TSD, traps[i].name ) ); |
| 2409 |
if ( entry->u.trace_only ) |
| 2410 |
exiterror( ERR_UNEXISTENT_LABEL, 3, tmpstr_of( TSD, entry->name ) ); |
| 2411 |
|
| 2412 |
traps[i].delayed = 1; |
| 2413 |
|
| 2414 |
set_reserved_value( TSD, POOL0_SIGL, NULL, TSD->nextsig->lineno, |
| 2415 |
VFLAG_NUM ); |
| 2416 |
oldlevel = TSD->currlevel; |
| 2417 |
TSD->currlevel = newlevel( TSD, TSD->currlevel ); |
| 2418 |
TSD->currlevel->sig = TSD->nextsig; |
| 2419 |
TSD->nextsig = NULL; |
| 2420 |
|
| 2421 |
stackmark = pushcallstack( TSD, thisptr ); |
| 2422 |
if ( TSD->trace_stat != 'O' && TSD->trace_stat != 'N' && TSD->trace_stat != 'F' ) |
| 2423 |
traceline( TSD, entry, TSD->trace_stat, 0 ); |
| 2424 |
|
| 2425 |
savecurrentnode = TSD->currentnode; /* pgb */ |
| 2426 |
h = interpret( TSD, entry->next ); |
| 2427 |
if ( h != NULL ) |
| 2428 |
Free_stringTSD( h ); |
| 2429 |
TSD->currentnode = savecurrentnode; /* pgb */ |
| 2430 |
|
| 2431 |
traps[i].delayed = 0; |
| 2432 |
popcallstack( TSD, stackmark ); |
| 2433 |
removelevel( TSD, TSD->currlevel ); |
| 2434 |
TSD->currlevel = oldlevel; |
| 2435 |
TSD->currlevel->next = NULL; |
| 2436 |
TSD->trace_stat = TSD->currlevel->tracestat; |
| 2437 |
TSD->systeminfo->interactive = TSD->currlevel->traceint; /* MDW 30012002 */ |
| 2438 |
} |
| 2439 |
} |
| 2440 |
|
| 2441 |
aftersignals: |
| 2442 |
|
| 2443 |
goto reinterpret; |
| 2444 |
|
| 2445 |
} |
| 2446 |
|
| 2447 |
/* getlabel searches for a label (procedure) in the current rexx program. |
| 2448 |
* The label is case-insensitively searched. Its name must be name. The first |
| 2449 |
* name found matches. The returned value is either NULL or the node of the |
| 2450 |
* name. |
| 2451 |
* This function uses a lazy evaluation mechanism and creates from the linked |
| 2452 |
* list an array. The hash value of each entry is generated during the copy. |
| 2453 |
* This function may become faster or much faster if the array is sorted |
| 2454 |
* by the hashvalue which allows a bsearch() call. But, and this is the |
| 2455 |
* problem, it is useful only if labels are search often and the number of |
| 2456 |
* labels are more than a few. I think, external functions which are registered |
| 2457 |
* in huge amounts are better candidates for this. |
| 2458 |
*/ |
| 2459 |
nodeptr getlabel( const tsd_t *TSD, const streng *name ) |
| 2460 |
{ |
| 2461 |
labelboxptr lptr, h; |
| 2462 |
internal_parser_type *ipt = &TSD->systeminfo->tree; |
| 2463 |
unsigned i, hash; |
| 2464 |
|
| 2465 |
if (ipt->sort_labels == NULL) |
| 2466 |
{ |
| 2467 |
if (ipt->first_label == NULL) |
| 2468 |
return(NULL); |
| 2469 |
|
| 2470 |
ipt->sort_labels = (labelboxptr)MallocTSD(ipt->numlabels * sizeof(ipt->sort_labels[0])); |
| 2471 |
for (i = 0, lptr = ipt->first_label;i < ipt->numlabels;i++) |
| 2472 |
{ |
| 2473 |
lptr->hash = hashvalue_ic(lptr->entry->name->value, lptr->entry->name->len); |
| 2474 |
ipt->sort_labels[i] = *lptr; |
| 2475 |
h = lptr->next; |
| 2476 |
FreeTSD(lptr); |
| 2477 |
lptr = h; |
| 2478 |
} |
| 2479 |
ipt->first_label = ipt->last_label = NULL; |
| 2480 |
} |
| 2481 |
|
| 2482 |
hash = hashvalue_ic(name->value, name->len); |
| 2483 |
for (i = 0;i < ipt->numlabels;i++) |
| 2484 |
{ |
| 2485 |
if (hash != ipt->sort_labels[i].hash) |
| 2486 |
continue; |
| 2487 |
if (Str_ccmp(ipt->sort_labels[i].entry->name, name) == 0) |
| 2488 |
return(ipt->sort_labels[i].entry); |
| 2489 |
} |
| 2490 |
return(NULL); |
| 2491 |
} |
| 2492 |
|
| 2493 |
|
| 2494 |
void removelevel( tsd_t *TSD, proclevel level ) |
| 2495 |
{ |
| 2496 |
int i=0 ; |
| 2497 |
|
| 2498 |
if ( level->next ) |
| 2499 |
{ |
| 2500 |
removelevel( TSD, level->next ) ; |
| 2501 |
/* level->next = NULL; */ |
| 2502 |
} |
| 2503 |
|
| 2504 |
if (level->varflag==1) /* does not belong *here* !!! */ |
| 2505 |
kill_variables( TSD, level->vars ) ; |
| 2506 |
|
| 2507 |
if (level->args) |
| 2508 |
deallocplink( TSD, level->args ) ; |
| 2509 |
|
| 2510 |
if (level->environment) |
| 2511 |
Free_stringTSD( level->environment ) ; |
| 2512 |
|
| 2513 |
if (level->prev_env) |
| 2514 |
Free_stringTSD( level->prev_env ) ; |
| 2515 |
|
| 2516 |
if (level->prev) |
| 2517 |
level->prev->next = NULL ; |
| 2518 |
|
| 2519 |
FREE_IF_DEFINED( TSD, level->signal_continue ); |
| 2520 |
|
| 2521 |
if (level->sig) |
| 2522 |
{ |
| 2523 |
FREE_IF_DEFINED( TSD, level->sig->info ) ; |
| 2524 |
FREE_IF_DEFINED( TSD, level->sig->descr ) ; |
| 2525 |
FreeTSD( level->sig ) ; |
| 2526 |
} |
| 2527 |
|
| 2528 |
if (level->traps) |
| 2529 |
{ |
| 2530 |
for (i=0; i<SIGNALS; i++) |
| 2531 |
FREE_IF_DEFINED( TSD, level->traps[i].name ) ; |
| 2532 |
|
| 2533 |
FreeTSD( level->traps ) ; |
| 2534 |
} |
| 2535 |
|
| 2536 |
FreeTSD(level) ; |
| 2537 |
} |
| 2538 |
|
| 2539 |
|
| 2540 |
/* |
| 2541 |
* NOTE: The ->buf variable is not set here, It must be set. When |
| 2542 |
* an old level is duplicated, the old ->buf is also duplicated, |
| 2543 |
* but DO_NO_USE_IT, since it will point to the reentring point |
| 2544 |
* of the mother-routine |
| 2545 |
*/ |
| 2546 |
proclevel newlevel( tsd_t *TSD, proclevel oldlevel ) |
| 2547 |
{ |
| 2548 |
itp_tsd_t *it = (itp_tsd_t *)TSD->itp_tsd; |
| 2549 |
proclevel level; |
| 2550 |
int i; |
| 2551 |
char *str; |
| 2552 |
streng *opts; |
| 2553 |
|
| 2554 |
level = (proclevel) MallocTSD( sizeof( proclevbox ) ); |
| 2555 |
|
| 2556 |
if ( oldlevel == NULL ) |
| 2557 |
{ |
| 2558 |
/* |
| 2559 |
* This is executed only once on startup of the interpreter. |
| 2560 |
*/ |
| 2561 |
#ifdef __CHECKER__ |
| 2562 |
/* There is a memcpy below which Checker don't like. The reason |
| 2563 |
* may be the aligned "char"s which will use one machine word |
| 2564 |
* but are initialized simply by an assignment of one byte. |
| 2565 |
* Checker sees 3 byte of uninitialized data --> error. |
| 2566 |
* (Of course, this isn't an error.) |
| 2567 |
* Always double-check the initializations below in case of |
| 2568 |
* any changes. |
| 2569 |
* FGC |
| 2570 |
*/ |
| 2571 |
memset( level, 0, sizeof( proclevbox ) ); |
| 2572 |
#endif |
| 2573 |
level->numfuzz = DEFAULT_NUMERIC_FUZZ; |
| 2574 |
level->currnumsize = DEFAULT_NUMERIC_SIZE; |
| 2575 |
level->numform = DEFAULT_NUMFORM; |
| 2576 |
level->rx_time.sec = 0; |
| 2577 |
level->rx_time.usec = 0; |
| 2578 |
level->mathtype = DEFAULT_MATH_TYPE; |
| 2579 |
level->prev = NULL; |
| 2580 |
level->next = NULL; |
| 2581 |
level->args = NULL; |
| 2582 |
level->options = 0; |
| 2583 |
|
| 2584 |
if ( it->opts_set ) |
| 2585 |
level->options = it->options; |
| 2586 |
else |
| 2587 |
{ |
| 2588 |
/* never call set_options_flag() on MATAOP options */ |
| 2589 |
set_options_flag( level, EXT_LINEOUTTRUNC, DEFAULT_LINEOUTTRUNC ); |
| 2590 |
set_options_flag( level, EXT_FLUSHSTACK, DEFAULT_FLUSHSTACK ); |
| 2591 |
set_options_flag( level, EXT_MAKEBUF_BIF, DEFAULT_MAKEBUF_BIF ); |
| 2592 |
set_options_flag( level, EXT_DROPBUF_BIF, DEFAULT_DROPBUF_BIF ); |
| 2593 |
set_options_flag( level, EXT_DESBUF_BIF, DEFAULT_DESBUF_BIF ); |
| 2594 |
set_options_flag( level, EXT_BUFTYPE_BIF, DEFAULT_BUFTYPE_BIF ); |
| 2595 |
set_options_flag( level, EXT_CACHEEXT, DEFAULT_CACHEEXT ); |
| 2596 |
set_options_flag( level, EXT_PRUNE_TRACE, DEFAULT_PRUNE_TRACE ); |
| 2597 |
set_options_flag( level, EXT_EXT_COMMANDS_AS_FUNCS, DEFAULT_EXT_COMMANDS_AS_FUNCS ); |
| 2598 |
set_options_flag( level, EXT_STDOUT_FOR_STDERR, DEFAULT_STDOUT_FOR_STDERR ); |
| 2599 |
set_options_flag( level, EXT_TRACE_HTML, DEFAULT_TRACE_HTML ); |
| 2600 |
set_options_flag( level, EXT_FAST_LINES_BIF_DEFAULT, DEFAULT_FAST_LINES_BIF_DEFAULT ); |
| 2601 |
set_options_flag( level, EXT_STRICT_ANSI, DEFAULT_STRICT_ANSI ); |
| 2602 |
set_options_flag( level, EXT_INTERNAL_QUEUES, DEFAULT_INTERNAL_QUEUES ); |
| 2603 |
set_options_flag( level, EXT_REGINA_BIFS, DEFAULT_REGINA_BIFS ); |
| 2604 |
set_options_flag( level, EXT_STRICT_WHITE_SPACE_COMPARISONS, DEFAULT_STRICT_WHITE_SPACE_COMPARISONS ); |
| 2605 |
set_options_flag( level, EXT_AREXX_SEMANTICS, DEFAULT_AREXX_SEMANTICS ); |
| 2606 |
set_options_flag( level, EXT_AREXX_BIFS, DEFAULT_AREXX_BIFS ); |
| 2607 |
set_options_flag( level, EXT_BROKEN_ADDRESS_COMMAND, DEFAULT_BROKEN_ADDRESS_COMMAND ); |
| 2608 |
set_options_flag( level, EXT_CALLS_AS_FUNCS, DEFAULT_CALLS_AS_FUNCS ); |
| 2609 |
set_options_flag( level, EXT_QUEUES_301, DEFAULT_QUEUES_301 ); |
| 2610 |
set_options_flag( level, EXT_HALT_ON_EXT_CALL_FAIL, DEFAULT_HALT_ON_EXT_CALL_FAIL ); |
| 2611 |
set_options_flag( level, EXT_SINGLE_INTERPRETER, DEFAULT_SINGLE_INTERPRETER ); |
| 2612 |
set_options_flag( level, EXT_SINGLE_LINE_COMMENTS, DEFAULT_SINGLE_LINE_COMMENTS ); |
| 2613 |
|
| 2614 |
if ( ( str = mygetenv( TSD, "REGINA_OPTIONS", NULL, 0 ) ) != NULL ) |
| 2615 |
{ |
| 2616 |
opts = Str_creTSD( str ); |
| 2617 |
FreeTSD( str ); |
| 2618 |
do_options( TSD, level, opts, 0 ); |
| 2619 |
} |
| 2620 |
it->opts_set = 1; |
| 2621 |
it->options = level->options; |
| 2622 |
} |
| 2623 |
|
| 2624 |
level->varflag = 1; |
| 2625 |
level->tracestat = (char) TSD->systeminfo->tracing; |
| 2626 |
level->traceint = (char) TSD->systeminfo->interactive; |
| 2627 |
level->environment = Str_dupTSD( TSD->systeminfo->environment ); |
| 2628 |
level->prev_env = Str_dupTSD( TSD->systeminfo->environment ); |
| 2629 |
level->vars = create_new_varpool( TSD, 0 ); |
| 2630 |
level->signal_continue = NULL; |
| 2631 |
level->sig = NULL; |
| 2632 |
level->traps = (trap *)MallocTSD( sizeof(trap) * SIGNALS ); |
| 2633 |
#ifdef __CHECKER__ |
| 2634 |
/* See above */ |
| 2635 |
memset( level->traps, 0, sizeof(trap) * SIGNALS ); |
| 2636 |
#endif |
| 2637 |
for (i=0; i<SIGNALS; i++) |
| 2638 |
{ |
| 2639 |
level->traps[i].name = NULL; |
| 2640 |
level->traps[i].on_off = 0; |
| 2641 |
level->traps[i].delayed = 0; |
| 2642 |
level->traps[i].def_act = default_action[i]; |
| 2643 |
level->traps[i].ignored = default_ignore[i]; |
| 2644 |
level->traps[i].invoked = 0; |
| 2645 |
} |
| 2646 |
level->pool = 1; |
| 2647 |
} |
| 2648 |
else |
| 2649 |
{ |
| 2650 |
/* Stupid SunOS acc gives incorrect warning for the next line */ |
| 2651 |
memcpy( level, oldlevel, sizeof( proclevbox ) ); |
| 2652 |
#ifdef DONT_DO_THIS |
| 2653 |
level->prev_env = NULL; |
| 2654 |
level->environment = NULL; |
| 2655 |
#else |
| 2656 |
level->prev_env = Str_dupTSD( oldlevel->prev_env ); |
| 2657 |
level->environment = Str_dupTSD( oldlevel->environment ); |
| 2658 |
#endif |
| 2659 |
level->prev = oldlevel; |
| 2660 |
level->varflag = 0; |
| 2661 |
oldlevel->next = level; |
| 2662 |
level->signal_continue = NULL; |
| 2663 |
level->args = NULL; |
| 2664 |
/* level->next = NULL;*/ |
| 2665 |
level->sig = NULL; |
| 2666 |
level->traps = NULL; |
| 2667 |
level->pool++; |
| 2668 |
} |
| 2669 |
|
| 2670 |
TSD->trace_stat = level->tracestat; |
| 2671 |
return level; |
| 2672 |
} |
| 2673 |
|
| 2674 |
|
| 2675 |
static void expose_indir( tsd_t *TSD, const streng *list ) |
| 2676 |
{ |
| 2677 |
const char *cptr=NULL, *eptr=NULL, *sptr=NULL ; |
| 2678 |
streng *tmp=NULL ; |
| 2679 |
|
| 2680 |
cptr = list->value ; |
| 2681 |
eptr = cptr + list->len ; |
| 2682 |
tmp = Str_makeTSD( 64 ) ; |
| 2683 |
for (;cptr<eptr;) |
| 2684 |
{ |
| 2685 |
for (; cptr<eptr && rx_isspace(*cptr); cptr++ ) ; |
| 2686 |
for (sptr=cptr; cptr<eptr && !rx_isspace(*cptr); cptr++ ) ; |
| 2687 |
if (cptr-sptr >= 64) |
| 2688 |
exiterror( ERR_TOO_LONG_STRING, 0 ) ; |
| 2689 |
if (cptr==sptr) |
| 2690 |
continue; |
| 2691 |
|
| 2692 |
memcpy( tmp->value, sptr, cptr-sptr ) ; |
| 2693 |
tmp->len = cptr-sptr ; |
| 2694 |
/* need to uppercase each variable in the list!! */ |
| 2695 |
Str_upper( tmp ); |
| 2696 |
expose_var( TSD, tmp ) ; |
| 2697 |
} |
| 2698 |
Free_stringTSD( tmp ) ; |
| 2699 |
} |
| 2700 |
|
| 2701 |
|
| 2702 |
/* |
| 2703 |
* jump_rexx_signal should be used when a "SIGNAL ON" condition happens. |
| 2704 |
* This function jumps to the previously assigned handler. This function |
| 2705 |
* ensures a proper cleanup if the global lock flag "in_protected" is set. |
| 2706 |
*/ |
| 2707 |
void jump_rexx_signal( tsd_t *TSD ) |
| 2708 |
{ |
| 2709 |
if ( TSD->in_protected ) |
| 2710 |
{ |
| 2711 |
/* |
| 2712 |
* The lexer is running. We have to terminate him and let him do his |
| 2713 |
* cleanup. After it, we'll be called again but without "in_protected". |
| 2714 |
*/ |
| 2715 |
TSD->delayed_error_type = PROTECTED_DelayedRexxSignal; |
| 2716 |
longjmp( TSD->protect_return, 1 ); |
| 2717 |
} |
| 2718 |
longjmp( *TSD->currlevel->signal_continue, 1 ); |
| 2719 |
} |
| 2720 |
|
| 2721 |
|
| 2722 |
/* |
| 2723 |
* jump_interpreter_exit should be used when the whole interpreter should |
| 2724 |
* terminate. This usually happens in case of a hard error or when the main |
| 2725 |
* script ends. |
| 2726 |
* |
| 2727 |
* processExitCode tells the interpreter what return code shall be used on the |
| 2728 |
* last exit. |
| 2729 |
* |
| 2730 |
* DON'T GET CONFUSED WITH jump_script_exit! |
| 2731 |
* |
| 2732 |
* This function jumps to the previously assigned handler. This function |
| 2733 |
* ensures a proper cleanup if the global lock flag "in_protected" is set. |
| 2734 |
*/ |
| 2735 |
void jump_interpreter_exit( tsd_t *TSD, int processExitCode ) |
| 2736 |
{ |
| 2737 |
if ( TSD->in_protected ) |
| 2738 |
{ |
| 2739 |
/* |
| 2740 |
* The lexer is running. We have to terminate him and let him do his |
| 2741 |
* cleanup. After it, we'll be called again but without "in_protected". |
| 2742 |
*/ |
| 2743 |
TSD->expected_exit_error = processExitCode; |
| 2744 |
TSD->delayed_error_type = PROTECTED_DelayedInterpreterExit; |
| 2745 |
longjmp( TSD->protect_return, 1 ); |
| 2746 |
} |
| 2747 |
TSD->MTExit( processExitCode ); |
| 2748 |
} |
| 2749 |
|
| 2750 |
|
| 2751 |
/* |
| 2752 |
* jump_script_exit should be used when a script ends or enters an EXIT |
| 2753 |
* instraction. |
| 2754 |
* |
| 2755 |
* result tells the interpreter what return string shall be returned to the |
| 2756 |
* caller. |
| 2757 |
* |
| 2758 |
* DON'T GET CONFUSED WITH jump_interpreter_exit! |
| 2759 |
* |
| 2760 |
* This function jumps to the previously assigned handler. This function |
| 2761 |
* ensures a proper cleanup if the global lock flag "in_protected" is set. |
| 2762 |
*/ |
| 2763 |
void jump_script_exit( tsd_t *TSD, streng *result ) |
| 2764 |
{ |
| 2765 |
TSD->systeminfo->result = result; |
| 2766 |
|
| 2767 |
if ( TSD->in_protected && TSD->systeminfo->script_exit ) |
| 2768 |
{ |
| 2769 |
/* |
| 2770 |
* The lexer is running. We have to terminate him and let him do his |
| 2771 |
* cleanup. After it, we'll be called again but without "in_protected". |
| 2772 |
*/ |
| 2773 |
TSD->delayed_error_type = PROTECTED_DelayedScriptExit; |
| 2774 |
longjmp( TSD->protect_return, 1 ); |
| 2775 |
} |
| 2776 |
|
| 2777 |
if ( !TSD->systeminfo->script_exit ) |
| 2778 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, |
| 2779 |
"script EXIT not registered" ); |
| 2780 |
|
| 2781 |
longjmp( *TSD->systeminfo->script_exit, 1 ); |
| 2782 |
} |