| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992 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 |
/* |
| 21 |
* Concept: Each REXX procedure (the top - or main - by default) has |
| 22 |
* an array of hash-pointers. Routines that don't keep local |
| 23 |
* variables (i.e hasn't seen a PROCEDURE) are using the hashpointers |
| 24 |
* of the routine above them. The initial size of the array is |
| 25 |
* vt->initialHashTableLength |
| 26 |
* |
| 27 |
* Each cell in this array is a pointer to a single-linked list of |
| 28 |
* boxes. In common for all these boxes is that their name returns |
| 29 |
* the same value when given as parameter to the hashfunc() function. |
| 30 |
* |
| 31 |
* Each of these boxes contains five variables: name, value, index, |
| 32 |
* realbox and next. 'next' points to next box in the list. |
| 33 |
* |
| 34 |
* 'name' is the name of the variable, and 'value' is the value it |
| 35 |
* contains. However, if 'realbox' is set, it points to another |
| 36 |
* box which contains the real value of the variable. This mechanism |
| 37 |
* gives support for EXPOSE'ing variables in PROCEDUREs. |
| 38 |
* |
| 39 |
* The 'index' is a pointer to another hashtable, and gives support |
| 40 |
* for compound variables. If a variable is compound, its 'index' is |
| 41 |
* set to point at the hashtable, each entry in this table do also |
| 42 |
* point at the start of a single linked list of variable boxes, but |
| 43 |
* these boxes has the 'after-the-period' part of the compound name |
| 44 |
* as 'name'. The 'realbox', but not the 'index' may be set in these |
| 45 |
* boxes. |
| 46 |
* |
| 47 |
* A variable is set when it exists in the datastructures, and the |
| 48 |
* relevant 'value' pointer is non-NULL. When dropping a variable |
| 49 |
* that is EXPOSE'ed, the 'value' is set to NULL. |
| 50 |
* |
| 51 |
* The 'test' and the 'test.' variables have two different |
| 52 |
* variableboxes, and 'index' is only set in the box for 'test.'. A |
| 53 |
* 'realbox' existing for 'test' makes it exposed. A 'realbox' |
| 54 |
* 'test.' make the whole "array" exposed. |
| 55 |
* |
| 56 |
* A 'value' existing for 'test.' denotes the default value. |
| 57 |
* |
| 58 |
* Major performance improvements without much to do which should be |
| 59 |
* implemented (FIXME): |
| 60 |
* |
| 61 |
* 1) Introduce a comparison function which uppercases the second argument |
| 62 |
* only. The variable box itself always has the correct case. Just the |
| 63 |
* script's name of the variable may have the "wrong" case. |
| 64 |
* Check for contents when uppercasing numbers as well. |
| 65 |
*/ |
| 66 |
|
| 67 |
#include "rexx.h" |
| 68 |
#include <string.h> |
| 69 |
#include <stdarg.h> |
| 70 |
#include <assert.h> |
| 71 |
#include <stdio.h> /* f*ck sun, they can't write a proper assert!!! */ |
| 72 |
|
| 73 |
typedef struct { |
| 74 |
void **Elems; |
| 75 |
unsigned size; |
| 76 |
} Pool; |
| 77 |
|
| 78 |
typedef struct { /* var_tsd: static variables of this module (thread-safe) */ |
| 79 |
#ifdef TRACEMEM |
| 80 |
variableptr first_invalid; |
| 81 |
#endif |
| 82 |
#ifdef DEBUG |
| 83 |
int DoDebug; |
| 84 |
FILE * DebugFile; |
| 85 |
char PoolNameBuf[20]; |
| 86 |
Pool NamePool; |
| 87 |
Pool ValuePool; |
| 88 |
Pool NumPool; |
| 89 |
Pool VarPool; |
| 90 |
#endif |
| 91 |
int foundflag; |
| 92 |
variableptr thespot; |
| 93 |
long current_valid; |
| 94 |
/* We CAN'T increment current_valid on each new procedure (which results |
| 95 |
* into create_new_varpool) and decrement it in procedure exit (which |
| 96 |
* executes kill_variables). Imagine the following: |
| 97 |
* >call proc1 |
| 98 |
* >exit 0 |
| 99 |
* >proc1: procedure |
| 100 |
* > locvar = 1 |
| 101 |
* > call proc2 |
| 102 |
* > call proc1 (not endlessly, but at least one time) |
| 103 |
* > return |
| 104 |
* >proc2: procedure expose locvar |
| 105 |
* > return |
| 106 |
* In the first call to proc2 current_valid will be 3, proc2 returns, proc1 |
| 107 |
* will be executed at least once more and current_valid is 3, too. This is |
| 108 |
* OK if and only if the variable accessment in proc1 and proc2 are distinct |
| 109 |
* by a procedure counter (each procedure has its own number). This is NOT |
| 110 |
* realized. Thus, we increment a separate counter (next_current_valid) each |
| 111 |
* time a new procedure is called and assign the value to current_valid. |
| 112 |
* On procedure return we set back current_valid to the current_value of |
| 113 |
* this procedure instance which may be, but don't MUST be, current_level-1. |
| 114 |
* Of course, this is bogus! The next_current_valid counter may wrap around |
| 115 |
* and we run into trouble once more. We can reset next_current_valid to |
| 116 |
* 2 (initial current_valid+1) savely iff current_valid==1. This prevents |
| 117 |
* some problems with multiple calls to Rexx when started but don't help in |
| 118 |
* one execution run. Since Regina is dog slow this will PROBABLY never |
| 119 |
* happen. |
| 120 |
* For a correct way of operation see many compiler building books of |
| 121 |
* languages with call by name. |
| 122 |
* Former releases uses stupid generation counter mechanisms. |
| 123 |
* FGC 27.09.98 (09/27/98) |
| 124 |
*/ |
| 125 |
long next_current_valid; |
| 126 |
int subst; |
| 127 |
unsigned hashval; |
| 128 |
unsigned fullhash; |
| 129 |
int ignore_novalue; |
| 130 |
int notrace; |
| 131 |
streng * tmpindex; |
| 132 |
streng * ovalue; |
| 133 |
streng * xvalue; |
| 134 |
num_descr * odescr; |
| 135 |
variableptr pstem; |
| 136 |
variableptr ptail; |
| 137 |
variableptr rstem; |
| 138 |
variableptr rtail; |
| 139 |
unsigned stemidx; |
| 140 |
unsigned tailidx; |
| 141 |
var_hashtable *var_table; |
| 142 |
var_hashtable *pool0; |
| 143 |
treenode pool0nodes[POOL0_CNT][2]; |
| 144 |
int initialHashTableLength; |
| 145 |
} var_tsd_t; |
| 146 |
|
| 147 |
#define SEEK_EXPOSED(ptr) if (ptr) \ |
| 148 |
{ \ |
| 149 |
for ( ; (ptr)->realbox; ptr = (ptr)->realbox ) \ |
| 150 |
; \ |
| 151 |
} |
| 152 |
#define REPLACE_VALUE(val,p) { if ( p->value ) \ |
| 153 |
Free_stringTSD( p->value ); \ |
| 154 |
p->value = val; \ |
| 155 |
p->guard = 0; \ |
| 156 |
p->flag = ( val ) ? VFLAG_STR : VFLAG_NONE; \ |
| 157 |
} |
| 158 |
|
| 159 |
#define REPLACE_NUMBER(val,p) { if ( p->num ) \ |
| 160 |
{ \ |
| 161 |
FreeTSD( p->num->num ); \ |
| 162 |
FreeTSD( p->num ); \ |
| 163 |
} \ |
| 164 |
p->num = val; \ |
| 165 |
p->guard = 0; \ |
| 166 |
p->flag = ( val ) ? VFLAG_NUM : VFLAG_NONE; \ |
| 167 |
} |
| 168 |
|
| 169 |
#ifdef DEBUG |
| 170 |
static void regina_dprintf( const tsd_t *TSD, const char *fmt, ... ) |
| 171 |
{ |
| 172 |
va_list marker; |
| 173 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 174 |
|
| 175 |
if ( !vt->DoDebug ) |
| 176 |
return; |
| 177 |
va_start( marker, fmt ); |
| 178 |
vfprintf( vt->DebugFile, fmt, marker ); |
| 179 |
fflush( vt->DebugFile ); |
| 180 |
va_end( marker ); |
| 181 |
} |
| 182 |
# define DPRINT(x) if ( vt->DoDebug & 1) regina_dprintf x |
| 183 |
# define DPRINT_2(x) if ( vt->DoDebug & 2 ) regina_dprintf x |
| 184 |
# define DPRINT_3(x) if ( vt->DoDebug & 4 ) regina_dprintf x |
| 185 |
# define DSTART DPRINT(( TSD, "%2u %4d ", TSD->thread_id, __LINE__ )) |
| 186 |
# define DSTART_2 DPRINT_2(( TSD, "%2u %4d ", TSD->thread_id, __LINE__ )) |
| 187 |
# define DSTART_3 DPRINT_3(( TSD, "%2u %4d ", TSD->thread_id, __LINE__ )) |
| 188 |
# define DEND DPRINT(( TSD, "\n" )) |
| 189 |
# define DEND_2 DPRINT_2(( TSD, "\n" )) |
| 190 |
# define DEND_3 DPRINT_3(( TSD, "\n" )) |
| 191 |
|
| 192 |
static const volatile char *PoolName( const tsd_t *TSD, Pool *pool, |
| 193 |
const void *elem ) |
| 194 |
{ |
| 195 |
unsigned i; |
| 196 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 197 |
|
| 198 |
if ( !vt->DoDebug ) /* PoolName's return value isn't really used if */ |
| 199 |
return NULL; /* debugging is turned off. */ |
| 200 |
if ( pool == &vt->NamePool ) |
| 201 |
strcpy( vt->PoolNameBuf, "NAME" ); |
| 202 |
else if ( pool == &vt->ValuePool ) |
| 203 |
strcpy( vt->PoolNameBuf, "VAL" ); |
| 204 |
else if ( pool == &vt->NumPool ) |
| 205 |
strcpy( vt->PoolNameBuf, "NUM" ); |
| 206 |
else if ( pool == &vt->VarPool ) |
| 207 |
strcpy( vt->PoolNameBuf, "VAR" ); |
| 208 |
else |
| 209 |
return "????"; |
| 210 |
for ( i = 0; i < pool->size; i++ ) |
| 211 |
if ( pool->Elems[i] == elem ) |
| 212 |
break; |
| 213 |
sprintf( vt->PoolNameBuf + strlen( vt->PoolNameBuf ), "%u", |
| 214 |
i + 1 ); |
| 215 |
if ( i >= pool->size ) |
| 216 |
{ |
| 217 |
pool->size++; |
| 218 |
if ( ( pool->Elems = (void **)realloc( pool->Elems, |
| 219 |
pool->size * sizeof( void * ) ) ) == NULL ) |
| 220 |
{ |
| 221 |
exiterror( ERR_STORAGE_EXHAUSTED, 0 ) ; |
| 222 |
} |
| 223 |
} |
| 224 |
pool->Elems[i] = (void *) elem; |
| 225 |
return vt->PoolNameBuf; |
| 226 |
} |
| 227 |
|
| 228 |
#define DNAME(TSD,name,n) if ( vt->DoDebug & 1 ) DNAME2( TSD, name, n ) |
| 229 |
static void DNAME2( const tsd_t *TSD, const char *name, const streng* n ) |
| 230 |
{ |
| 231 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 232 |
|
| 233 |
if ( !vt->DoDebug ) |
| 234 |
return; |
| 235 |
if ( name != NULL ) |
| 236 |
regina_dprintf( TSD, "%s=", |
| 237 |
name ); |
| 238 |
if ( n == NULL ) |
| 239 |
{ |
| 240 |
regina_dprintf( TSD, "NULL" ); |
| 241 |
return; |
| 242 |
} |
| 243 |
regina_dprintf( TSD, "\"%*.*s\"%s", |
| 244 |
Str_len( n ), |
| 245 |
Str_len( n ), |
| 246 |
n->value, |
| 247 |
PoolName( TSD, &vt->NamePool, n ) ); |
| 248 |
} |
| 249 |
|
| 250 |
#define DVALUE(TSD,name,v) if ( vt->DoDebug & 1 ) DVALUE2( TSD, name, v ) |
| 251 |
static void DVALUE2( const tsd_t *TSD, const char *name, const streng* v ) |
| 252 |
{ |
| 253 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 254 |
|
| 255 |
if ( !vt->DoDebug ) |
| 256 |
return; |
| 257 |
if ( name != NULL ) |
| 258 |
regina_dprintf( TSD, "%s=", |
| 259 |
name ); |
| 260 |
if ( v == NULL ) |
| 261 |
{ |
| 262 |
regina_dprintf( TSD, "NULL" ); |
| 263 |
return; |
| 264 |
} |
| 265 |
regina_dprintf( TSD, "\"%*.*s\"%s", |
| 266 |
Str_len( v ), |
| 267 |
Str_len( v ), |
| 268 |
v->value, |
| 269 |
PoolName( TSD, &vt->ValuePool, v ) ); |
| 270 |
} |
| 271 |
|
| 272 |
#define DNUM(TSD,name,n) if ( vt->DoDebug & 1 ) DNUM2( TSD, name, n ) |
| 273 |
static void DNUM2( const tsd_t *TSD, const char *name, const num_descr* n) |
| 274 |
{ |
| 275 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 276 |
|
| 277 |
if ( !vt->DoDebug ) |
| 278 |
return; |
| 279 |
if ( name != NULL ) |
| 280 |
regina_dprintf( TSD, "%s=", |
| 281 |
name ); |
| 282 |
if ( n == NULL ) |
| 283 |
{ |
| 284 |
regina_dprintf( TSD, "NULL" ); |
| 285 |
return; |
| 286 |
} |
| 287 |
regina_dprintf( TSD, "\"%*.*s\"%s", |
| 288 |
n->size, |
| 289 |
n->size, |
| 290 |
n->num, |
| 291 |
PoolName( TSD, &vt->NumPool, n ) ); |
| 292 |
} |
| 293 |
|
| 294 |
static int Dfindlevel(const tsd_t *TSD, cvariableptr v) |
| 295 |
{ |
| 296 |
proclevel curr; |
| 297 |
int lvl=0; |
| 298 |
unsigned i; |
| 299 |
|
| 300 |
curr = TSD->currlevel; |
| 301 |
|
| 302 |
while ( curr ) |
| 303 |
{ |
| 304 |
if (curr->vars) |
| 305 |
{ |
| 306 |
for ( i = 0; i < curr->vars->size; i++ ) |
| 307 |
{ |
| 308 |
if ( curr->vars->tbl[i] == v ) |
| 309 |
goto found; |
| 310 |
} |
| 311 |
} |
| 312 |
curr = curr->prev; |
| 313 |
lvl++; |
| 314 |
} |
| 315 |
return -1; |
| 316 |
found: |
| 317 |
while ( curr->prev ) |
| 318 |
{ |
| 319 |
curr = curr->prev; |
| 320 |
lvl++; |
| 321 |
} |
| 322 |
return lvl; |
| 323 |
} |
| 324 |
|
| 325 |
#define DVAR(TSD,name,v) if ( vt->DoDebug & 1 ) DVAR2( TSD, name, v ) |
| 326 |
static void DVAR2( const tsd_t *TSD, const char *name, cvariableptr v ) |
| 327 |
{ |
| 328 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 329 |
|
| 330 |
if ( !vt->DoDebug ) |
| 331 |
return; |
| 332 |
if ( name != NULL ) |
| 333 |
regina_dprintf( TSD, "%s=", |
| 334 |
name ); |
| 335 |
if ( v == NULL ) |
| 336 |
{ |
| 337 |
regina_dprintf( TSD, "NULL" ); |
| 338 |
return; |
| 339 |
} |
| 340 |
|
| 341 |
regina_dprintf( TSD, "%s,l=%d(", |
| 342 |
PoolName( TSD, &vt->VarPool, v ), |
| 343 |
Dfindlevel( TSD, v ) ); |
| 344 |
if ( v->valid == 0 ) |
| 345 |
regina_dprintf( TSD, "?" ); |
| 346 |
else |
| 347 |
{ |
| 348 |
DNAME( TSD, NULL, v->name ); |
| 349 |
regina_dprintf( TSD, "," ); |
| 350 |
DVALUE( TSD, NULL, v->value ); |
| 351 |
regina_dprintf( TSD, "=" ); |
| 352 |
DNUM( TSD, NULL, v->num ); |
| 353 |
} |
| 354 |
regina_dprintf( TSD, ",hwired=%ld,valid=%ld", |
| 355 |
v->hwired, v->valid ); |
| 356 |
if ( v->realbox ) |
| 357 |
{ |
| 358 |
regina_dprintf( TSD, "->" ); |
| 359 |
DVAR( TSD, NULL, v->realbox ); |
| 360 |
} |
| 361 |
regina_dprintf( TSD, ")" ); |
| 362 |
} |
| 363 |
# define DPRINTF(x) DSTART;DPRINT(x);DEND |
| 364 |
# define DPRINTF_2(x) DSTART_2;DPRINT_2(x);DEND_2 |
| 365 |
# define DPRINTF_3(x) DSTART_3;DPRINT_3(x);DEND_3 |
| 366 |
# define DARG(x,y) x |
| 367 |
#else /* !define(DEBUG) */ |
| 368 |
# define DPRINT(x) |
| 369 |
# define DPRINT_2(x) |
| 370 |
# define DPRINT_3(x) |
| 371 |
# define DSTART |
| 372 |
# define DSTART_2 |
| 373 |
# define DSTART_3 |
| 374 |
# define DEND |
| 375 |
# define DEND_2 |
| 376 |
# define DEND_3 |
| 377 |
# define DNAME(t,n,v) |
| 378 |
# define DVALUE(t,n,v) |
| 379 |
# define DNUM(t,n,v) |
| 380 |
# define DVAR(t,n,v) |
| 381 |
# define DPRINTF(x) |
| 382 |
# define DPRINTF_2(x) |
| 383 |
# define DPRINTF_3(x) |
| 384 |
# define DARG(x,y) y |
| 385 |
#endif /* DEBUG */ |
| 386 |
|
| 387 |
/* |
| 388 |
* NEW_HASHTABLE_CHECK is invoked after a new entry has been added to the |
| 389 |
* hashtable. Do a check for this special condition and set flag to 1 if |
| 390 |
* a hashtable reorganisation should happen. |
| 391 |
* One (maybe wrong) idea is to increase the table if 100% has been filled. |
| 392 |
* NEVER EVER USE LESS THAN 40% CAPACITY! THIS MAY BE THE LOW WATER MARK! |
| 393 |
*/ |
| 394 |
#define NEW_HASHTABLE_CHECK(tbl,flag) /* */ \ |
| 395 |
(flag |= (((tbl)->elements * 3 > (tbl)->size * 2) ? 1 : 0)) /* set to 5/4 for 80%*/ |
| 396 |
|
| 397 |
/* |
| 398 |
* COLLISION_CHECK is invoked after a collision has been detected. |
| 399 |
* The check may happen rather often. KEEP IT SIMPLE! |
| 400 |
* A hashtable reorganisation should/may happen in this case; this must be |
| 401 |
* indicated by setting flag to 1. |
| 402 |
* One (maybe wrong) idea is to increase the table if the number of collisions |
| 403 |
* is bigger than ten time of the number of read/write accesses. |
| 404 |
* An additional test verifies the collisions were not caused by a bad |
| 405 |
* hash function or badly chosen variable names. |
| 406 |
*/ |
| 407 |
#define COLLISION_CHECK(tbl,flag) /* */ \ |
| 408 |
(flag |= ((((tbl)->elements * 10 > (tbl)->size) && ((tbl)->writes + (tbl)->reads < (tbl)->collisions / 10)) ? 1 : 0)) |
| 409 |
|
| 410 |
|
| 411 |
/* |
| 412 |
* The SEEK_VAR_... functions walk through the list of variable candidates |
| 413 |
* in the bucket of the found hash with more or less help by other informations |
| 414 |
* to minimize expensive comparisons. |
| 415 |
*/ |
| 416 |
#define SEEK_VAR_CMP(run,var,fullhash,tbl,flag) /* */ \ |
| 417 |
for ( ; (run); (run) = (run)->next ) \ |
| 418 |
{ \ |
| 419 |
if ( ( (run)->hash == (fullhash) ) && \ |
| 420 |
( (run)->name->len == (var)->len ) && \ |
| 421 |
( Str_cmp( run->name, var ) == 0 ) ) \ |
| 422 |
break; \ |
| 423 |
\ |
| 424 |
(tbl)->collisions++; \ |
| 425 |
COLLISION_CHECK(tbl, flag); \ |
| 426 |
} |
| 427 |
|
| 428 |
#define SEEK_VAR_CCMP(run,var,fullhash,tbl,flag) /* */ \ |
| 429 |
for ( ; (run); (run) = (run)->next ) \ |
| 430 |
{ \ |
| 431 |
if ( ( (run)->hash == (fullhash) ) && \ |
| 432 |
( (run)->name->len == (var)->len ) && \ |
| 433 |
( Str_ccmp( run->name, var ) == 0 ) ) \ |
| 434 |
break; \ |
| 435 |
\ |
| 436 |
(tbl)->collisions++; \ |
| 437 |
COLLISION_CHECK(tbl, flag); \ |
| 438 |
} |
| 439 |
|
| 440 |
#define SEEK_VAR_CNCMP(run,var,fullhash,tbl,l,flag) /* */ \ |
| 441 |
for ( ; (run); (run) = (run)->next ) \ |
| 442 |
{ \ |
| 443 |
if ( ( (run)->hash == (fullhash) ) && \ |
| 444 |
( (run)->name->len == (l) ) && \ |
| 445 |
( Str_cncmp( run->name, var, l ) == 0 ) ) \ |
| 446 |
break; \ |
| 447 |
\ |
| 448 |
(tbl)->collisions++; \ |
| 449 |
COLLISION_CHECK(tbl, flag); \ |
| 450 |
} |
| 451 |
|
| 452 |
#define SEEK_VAR_CNOCMP(run,var,fullhash,tbl,l,off,flag) /* */ \ |
| 453 |
for ( ; (run); (run) = (run)->next ) \ |
| 454 |
{ \ |
| 455 |
if ( ( (run)->hash == (fullhash) ) && \ |
| 456 |
( (run)->name->len == (l) ) && \ |
| 457 |
( Str_cnocmp( run->name, var, l, off ) == 0 ) ) \ |
| 458 |
break; \ |
| 459 |
\ |
| 460 |
(tbl)->collisions++; \ |
| 461 |
COLLISION_CHECK(tbl, flag); \ |
| 462 |
} |
| 463 |
|
| 464 |
static const streng *getdirvalue_compound( tsd_t *TSD, var_hashtable *vars, |
| 465 |
const streng *name ); |
| 466 |
|
| 467 |
/* |
| 468 |
* Allocates and initializes a hashtable for the variables. Can be used |
| 469 |
* both for the main variable hash table, or for an compound variable. |
| 470 |
*/ |
| 471 |
static var_hashtable *make_hash_table( const tsd_t *TSD, int size ) |
| 472 |
{ |
| 473 |
var_hashtable *tab = (var_hashtable *)MallocTSD( sizeof( var_hashtable ) ); |
| 474 |
|
| 475 |
tab->size = size; |
| 476 |
tab->reads = 0; |
| 477 |
tab->writes = 0; |
| 478 |
tab->collisions = 0; |
| 479 |
tab->elements = 0; |
| 480 |
size = ( size + 1 ) * sizeof( variableptr ); |
| 481 |
/* Last element needed to save current_valid */ |
| 482 |
|
| 483 |
tab->tbl = (variableptr *)MallocTSD( size ); |
| 484 |
memset( tab->tbl, 0, size ); |
| 485 |
|
| 486 |
return tab; |
| 487 |
} |
| 488 |
|
| 489 |
/* |
| 490 |
* known_reserved_variable returns 0 if the arguments don't be a known |
| 491 |
* reserved variable as described in ANSI 6.2.3.1. The value is a |
| 492 |
* POOL0_??? value otherwise. |
| 493 |
* |
| 494 |
* The argument don't has to be uppercased but must not contain whitespaces or |
| 495 |
* garbage. |
| 496 |
*/ |
| 497 |
int known_reserved_variable( const char *name, unsigned length ) |
| 498 |
{ |
| 499 |
char upper[20]; /* good maximum for predefined variable names */ |
| 500 |
|
| 501 |
/* |
| 502 |
* a fast breakout switch |
| 503 |
*/ |
| 504 |
if ( ( length < 3 /* ".RC" */) |
| 505 |
|| ( length > 10 /* ".ENDOFLINE" */) |
| 506 |
|| ( *name != '.' ) ) |
| 507 |
return POOL0_NOT_RESERVED; |
| 508 |
name++; |
| 509 |
length--; |
| 510 |
|
| 511 |
memcpy( upper, name, length ); |
| 512 |
mem_upper( upper, (int) length ); |
| 513 |
|
| 514 |
/* |
| 515 |
* some magic stuff to reduce further errors |
| 516 |
*/ |
| 517 |
#define RET_IF(s) if ( ( length == sizeof( #s ) - 1 ) \ |
| 518 |
&& ( memcmp( upper, #s, sizeof( #s ) - 1 ) == 0 ) ) \ |
| 519 |
return POOL0_##s |
| 520 |
RET_IF( RC ); |
| 521 |
RET_IF( RESULT ); |
| 522 |
RET_IF( SIGL ); |
| 523 |
RET_IF( RS ); |
| 524 |
RET_IF( MN ); |
| 525 |
RET_IF( LINE ); |
| 526 |
RET_IF( FILE ); |
| 527 |
RET_IF( ENDOFLINE ); |
| 528 |
RET_IF( DIRSEP ); |
| 529 |
#undef REF_IF |
| 530 |
|
| 531 |
return POOL0_NOT_RESERVED; |
| 532 |
} |
| 533 |
|
| 534 |
void detach( const tsd_t *TSD, variableptr ptr ) |
| 535 |
{ |
| 536 |
#ifdef DEBUG |
| 537 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 538 |
#endif |
| 539 |
|
| 540 |
assert( ptr->hwired > 0 ); |
| 541 |
|
| 542 |
ptr->hwired--; |
| 543 |
DSTART;DPRINT((TSD,"detach: "));DVAR(TSD,NULL,ptr);DEND; |
| 544 |
} |
| 545 |
|
| 546 |
#ifdef TRACEMEM |
| 547 |
static void mark_ht( var_hashtable *tab ) |
| 548 |
{ |
| 549 |
variableptr vvptr, vptr; |
| 550 |
unsigned i, j; |
| 551 |
|
| 552 |
if ( !tab ) |
| 553 |
return; |
| 554 |
|
| 555 |
markmemory( (char*)tab->tbl, TRC_HASHTAB ); |
| 556 |
for ( i = 0; i < tab->size; i++ ) |
| 557 |
{ |
| 558 |
for ( vptr = tab->tbl[i]; vptr; vptr = vptr->next ) |
| 559 |
{ |
| 560 |
markmemory( (char*)vptr, TRC_VARBOX ); |
| 561 |
if ( vptr->name ) |
| 562 |
markmemory( (char*)vptr->name, TRC_VARNAME ); |
| 563 |
if ( vptr->num ) |
| 564 |
{ |
| 565 |
markmemory( vptr->num, TRC_VARVALUE ); |
| 566 |
markmemory( vptr->num->num, TRC_VARVALUE ); |
| 567 |
} |
| 568 |
if ( vptr->value ) |
| 569 |
markmemory( (char*)vptr->value, TRC_VARVALUE ); |
| 570 |
if ( vptr->index ) |
| 571 |
{ |
| 572 |
markmemory( vptr->index, TRC_VARNAME ); |
| 573 |
for ( j = 0; j < vptr->index->size; j++ ) |
| 574 |
{ |
| 575 |
for ( vvptr = (vptr->index->tbl)[j]; vvptr; vvptr = vvptr->next ) |
| 576 |
{ |
| 577 |
markmemory( (char*)vvptr, TRC_VARBOX ); |
| 578 |
if ( vvptr->name ) |
| 579 |
markmemory( (char*)vvptr->name, TRC_VARNAME ); |
| 580 |
if ( vvptr->num ) |
| 581 |
{ |
| 582 |
markmemory( vvptr->num, TRC_VARVALUE ); |
| 583 |
markmemory( vvptr->num->num, TRC_VARVALUE ); |
| 584 |
} |
| 585 |
if ( vvptr->value ) |
| 586 |
markmemory( (char*)vvptr->value, TRC_VARVALUE ); |
| 587 |
} |
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
} |
| 594 |
|
| 595 |
void markvariables( const tsd_t *TSD, cproclevel procptr ) |
| 596 |
{ |
| 597 |
variableptr vptr; |
| 598 |
paramboxptr pptr; |
| 599 |
int i; |
| 600 |
var_tsd_t *vt; |
| 601 |
|
| 602 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 603 |
|
| 604 |
for ( ; procptr; procptr = procptr->next ) |
| 605 |
{ |
| 606 |
if ( procptr->environment ) |
| 607 |
markmemory( procptr->environment, TRC_VARBOX ); |
| 608 |
if ( procptr->prev_env ) |
| 609 |
markmemory( procptr->prev_env, TRC_VARBOX ); |
| 610 |
if ( procptr->sig ) |
| 611 |
{ |
| 612 |
markmemory( procptr->sig, TRC_VARBOX ); |
| 613 |
if ( procptr->sig->info ) |
| 614 |
markmemory( procptr->sig->info, TRC_VARBOX ); |
| 615 |
if ( procptr->sig->descr ) |
| 616 |
markmemory( procptr->sig->descr, TRC_VARBOX ); |
| 617 |
} |
| 618 |
if ( procptr->signal_continue ) |
| 619 |
markmemory( procptr->signal_continue, TRC_VARBOX ); |
| 620 |
if ( procptr->traps ) |
| 621 |
{ |
| 622 |
markmemory( procptr->traps, TRC_VARBOX ); |
| 623 |
for ( i = 0; i < SIGNALS; i++ ) |
| 624 |
{ |
| 625 |
if ( procptr->traps[i].name ) |
| 626 |
markmemory( procptr->traps[i].name, TRC_VARBOX ); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
mark_ht( procptr->vars ); |
| 631 |
markmemory( (char*)procptr,TRC_PROCBOX ); |
| 632 |
|
| 633 |
markmemory( (char*)procptr->vars, TRC_HASHTAB ); |
| 634 |
if ( procptr->args ) |
| 635 |
{ |
| 636 |
for ( pptr = procptr->args; pptr; pptr = pptr->next ) |
| 637 |
{ |
| 638 |
markmemory( (char*) pptr, TRC_PROCARG ); |
| 639 |
if ( pptr->value ) |
| 640 |
markmemory( (char*) pptr->value, TRC_PROCARG ); |
| 641 |
} |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
mark_ht( vt->pool0 ); |
| 646 |
markmemory( (char*)vt->pool0, TRC_HASHTAB ); |
| 647 |
|
| 648 |
for ( vptr = vt->first_invalid; vptr; vptr = vptr->prev ) |
| 649 |
{ |
| 650 |
markmemory( vptr, TRC_VARBOX ); |
| 651 |
} |
| 652 |
} |
| 653 |
#endif /* TRACEMEM */ |
| 654 |
|
| 655 |
static variableptr newbox( const tsd_t *TSD, const streng *name, |
| 656 |
streng *value, variableptr *oldptr, unsigned hash) |
| 657 |
{ |
| 658 |
variableptr newptr; |
| 659 |
var_tsd_t *vt; |
| 660 |
|
| 661 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 662 |
|
| 663 |
DSTART;DPRINT((TSD,"newbox: "));DNAME(TSD,NULL,name);DPRINT((TSD," replaces ")); |
| 664 |
DVAR(TSD,NULL,*oldptr);DEND; |
| 665 |
newptr = (variableptr)MallocTSD( sizeof( variable ) ); |
| 666 |
|
| 667 |
newptr->index = NULL; |
| 668 |
newptr->next = *oldptr; |
| 669 |
newptr->prev = NULL; |
| 670 |
newptr->realbox = NULL; |
| 671 |
if ( name ) |
| 672 |
newptr->name = Str_dupTSD( name ); |
| 673 |
else |
| 674 |
newptr->name = NULL; |
| 675 |
newptr->value = value; |
| 676 |
newptr->guard = 0; |
| 677 |
newptr->num = NULL; |
| 678 |
newptr->flag = value ? VFLAG_STR : VFLAG_NONE; |
| 679 |
newptr->hash = hash; |
| 680 |
newptr->hwired = 0; |
| 681 |
newptr->valid = (long) vt->current_valid; |
| 682 |
newptr->stem = NULL; |
| 683 |
|
| 684 |
*oldptr = newptr; |
| 685 |
DSTART;DPRINT((TSD,"newbox: "));DVAR(TSD,"rc",newptr);DEND; |
| 686 |
return newptr; |
| 687 |
} |
| 688 |
|
| 689 |
static variableptr make_stem( const tsd_t *TSD, const streng *name, |
| 690 |
streng *value, variableptr *oldptr, int len, |
| 691 |
unsigned hash ) |
| 692 |
{ |
| 693 |
variableptr ptr; |
| 694 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 695 |
|
| 696 |
ptr = newbox( TSD, NULL, value, oldptr, hash ); |
| 697 |
ptr->index = make_hash_table( TSD, vt->initialHashTableLength ); |
| 698 |
DPRINTF((TSD,"make_hash_table: rc=%p",ptr->index)); |
| 699 |
ptr->name = Str_ndupTSD( name, len ); |
| 700 |
DSTART;DPRINT((TSD,"makestem: "));DVAR(TSD,"rc",ptr);DEND; |
| 701 |
return ptr; |
| 702 |
} |
| 703 |
|
| 704 |
#define RXDIGIT 0x01 |
| 705 |
#define RXUPPER 0x02 |
| 706 |
#define RXLOWER 0x04 |
| 707 |
#define RXEXTRA 0x08 |
| 708 |
#define RXDOT 0x10 |
| 709 |
#define RXWHITE 0x20 |
| 710 |
#define RXVAR ( RXUPPER | RXLOWER | RXEXTRA ) |
| 711 |
#define RXCONST ( RXUPPER | RXLOWER | RXEXTRA | RXDIGIT | RXDOT ) |
| 712 |
#define RXMANT ( RXDIGIT | RXDOT ) |
| 713 |
#define CHAR_TYPE(c) char_types[(unsigned char) ( c )] |
| 714 |
#define RXISDIGIT(a) ( CHAR_TYPE( a ) & RXDIGIT ) |
| 715 |
#define RXISUPPER(a) ( CHAR_TYPE( a ) & RXUPPER ) |
| 716 |
#define RXISLOWER(a) ( CHAR_TYPE( a ) & RXLOWER ) |
| 717 |
#define RXISEXTRA(a) ( CHAR_TYPE( a ) & RXEXTRA ) |
| 718 |
#define RXISDOT(a) ( CHAR_TYPE( a ) & RXDOT ) |
| 719 |
#define RXISWHITE(a) ( CHAR_TYPE( a ) & RXWHITE ) |
| 720 |
#define RXISVAR(a) ( CHAR_TYPE( a ) & RXVAR ) |
| 721 |
#define RXISCONST(a) ( CHAR_TYPE( a ) & RXCONST ) |
| 722 |
#define RXISMANT(a) ( CHAR_TYPE( a ) & RXMANT ) |
| 723 |
|
| 724 |
/* |
| 725 |
* 04.10.2003, FGC, FIXME: Is it allowed to move to the new scheme of |
| 726 |
* character manipulation as defined in misc.c? I don't think so, because |
| 727 |
* the lexer isn't/can't be changed to support CHANGING extended character |
| 728 |
* sets. If you have a good idea, please let me know. |
| 729 |
*/ |
| 730 |
static const unsigned char char_types[256] = |
| 731 |
{ |
| 732 |
0, 0, 0, 0, 0, 0, 0, 0, /* nul - bel */ |
| 733 |
0, RXWHITE, RXWHITE, 0, RXWHITE, 0, 0, RXWHITE, /* bs - si */ |
| 734 |
0, 0, 0, 0, 0, 0, 0, 0, /* dle - etb */ |
| 735 |
0, 0, 0, 0, 0, 0, 0, 0, /* can - us */ |
| 736 |
RXWHITE, RXEXTRA, 0, RXEXTRA, RXEXTRA, 0, 0, 0, /* sp - ' */ |
| 737 |
0, 0, 0, 0, 0, 0, RXDOT, 0, /* ( - / */ |
| 738 |
RXDIGIT, RXDIGIT, RXDIGIT, RXDIGIT, RXDIGIT, RXDIGIT, RXDIGIT, RXDIGIT, /* 0 - 7 */ |
| 739 |
RXDIGIT, RXDIGIT, 0, 0, 0, 0, 0, RXEXTRA, /* 8 - ? */ |
| 740 |
RXEXTRA, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, /* @ - G */ |
| 741 |
RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, /* H - O */ |
| 742 |
RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, RXUPPER, /* P - W */ |
| 743 |
RXUPPER, RXUPPER, RXUPPER, 0, 0, 0, 0, RXEXTRA, /* X - _ */ |
| 744 |
0, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, /* ` - g */ |
| 745 |
RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, /* h - o */ |
| 746 |
RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, RXLOWER, /* p - w */ |
| 747 |
RXLOWER, RXLOWER, RXLOWER, 0, 0, 0, 0, 0, /* x - del */ |
| 748 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 749 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 750 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 751 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 752 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 753 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 754 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 755 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 756 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 757 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 758 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 759 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 760 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 761 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 762 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 763 |
0, 0, 0, 0, 0, 0, 0, 0 |
| 764 |
} ; |
| 765 |
|
| 766 |
/* |
| 767 |
* valid_var_symbol matches a symbol, which can be either a number, a |
| 768 |
* var_symbol, or a const_symbol in terms of ANSI 6.3.2.96. |
| 769 |
* see also: ANSI 6.2.2.29, 6.2.2.31, 6.2.2.35 |
| 770 |
* Note that 6.2.2.32 means to parse an exponential character only if it |
| 771 |
* it part of a number. Thus, we have to parse the following: |
| 772 |
* var_symbol=RXVAR RXCONST* |
| 773 |
* const_symbol=RXCONST+ |
| 774 |
* number=( '.' RXDIGIT+ | ( RXDIGIT+ ( '.' RXDIGIT* )? ) ) exp? |
| 775 |
* exp=( 'e' | 'E' ) ( '-' | '+' )? RXDIGIT+ |
| 776 |
* We split var_symbol into simple, stem, compound and return all |
| 777 |
* SYMBOL_??? values. |
| 778 |
*/ |
| 779 |
int valid_var_symbol( const streng *name ) |
| 780 |
{ |
| 781 |
const unsigned char *cptr,*eptr; |
| 782 |
unsigned char ch; |
| 783 |
int dots,sign; |
| 784 |
|
| 785 |
if ( name->len == 0 ) |
| 786 |
return SYMBOL_BAD; |
| 787 |
|
| 788 |
cptr = (const unsigned char *) name->value; |
| 789 |
eptr = cptr + name->len; |
| 790 |
|
| 791 |
ch = *cptr++; |
| 792 |
if ( RXISVAR( ch ) ) |
| 793 |
{ |
| 794 |
/* |
| 795 |
* valid begin of a variable name. Lets check it. This can't be |
| 796 |
* a number, thus we don't care about sign characters. |
| 797 |
*/ |
| 798 |
dots = 0; |
| 799 |
do { |
| 800 |
if ( cptr == eptr ) |
| 801 |
{ |
| 802 |
/* |
| 803 |
* the last character is properly loaded in ch |
| 804 |
*/ |
| 805 |
if ( RXISDOT( ch ) && ( dots == 1 ) ) |
| 806 |
return SYMBOL_STEM; |
| 807 |
else if ( dots ) |
| 808 |
return SYMBOL_COMPOUND; |
| 809 |
return SYMBOL_SIMPLE; |
| 810 |
} |
| 811 |
ch = *cptr++; |
| 812 |
if ( RXISDOT( ch ) ) |
| 813 |
dots = 1; |
| 814 |
/* |
| 815 |
* characters after the first character are the same as of |
| 816 |
* const_symbol. They don't share the sign behaviour, though. |
| 817 |
*/ |
| 818 |
} while ( RXISCONST( ch ) ); |
| 819 |
|
| 820 |
return SYMBOL_BAD; |
| 821 |
} |
| 822 |
|
| 823 |
/* |
| 824 |
* Check for a reserved variable first. |
| 825 |
* In all other cases we may have a number or a const_symbol. |
| 826 |
*/ |
| 827 |
if ( KNOWN_RESERVED( (char *)cptr - 1, name->len ) ) |
| 828 |
return SYMBOL_SIMPLE; |
| 829 |
|
| 830 |
sign = 0; |
| 831 |
/* |
| 832 |
* Breaking/ending the following loops means to check for a const_symbol |
| 833 |
* with respect to the absense of a sign character. |
| 834 |
*/ |
| 835 |
for ( ; ; ) { |
| 836 |
/* |
| 837 |
* A number is a const_symbol with the exception of the sign within |
| 838 |
* an exponent. Try parsing a number first and fall back to a const |
| 839 |
* detection on error but keep a seen sign in mind. |
| 840 |
*/ |
| 841 |
if ( RXISDOT( ch ) ) |
| 842 |
{ |
| 843 |
/* |
| 844 |
* Check for a plain dot, which isn't a number, and for a following |
| 845 |
* digit. |
| 846 |
*/ |
| 847 |
if ( cptr == eptr ) |
| 848 |
return SYMBOL_CONSTANT; |
| 849 |
ch = *cptr++; |
| 850 |
if ( !RXISDIGIT( ch ) ) |
| 851 |
break; |
| 852 |
|
| 853 |
do { |
| 854 |
if ( cptr == eptr ) |
| 855 |
return SYMBOL_NUMBER; |
| 856 |
|
| 857 |
ch = *cptr++; |
| 858 |
/* |
| 859 |
* expect just RXDIGITs as the mantissa. |
| 860 |
*/ |
| 861 |
} while ( RXISDIGIT( ch ) ); |
| 862 |
} |
| 863 |
else |
| 864 |
{ |
| 865 |
if ( !RXISDIGIT( ch ) ) |
| 866 |
break; |
| 867 |
/* |
| 868 |
* expect RXDIGITs [ '.' RXDIGITs ] as the mantissa. |
| 869 |
*/ |
| 870 |
|
| 871 |
do { |
| 872 |
if ( cptr == eptr ) |
| 873 |
return SYMBOL_NUMBER; |
| 874 |
|
| 875 |
ch = *cptr++; |
| 876 |
} while ( RXISDIGIT( ch ) ); |
| 877 |
if ( RXISDOT( ch ) ) |
| 878 |
{ |
| 879 |
if ( cptr == eptr ) |
| 880 |
return SYMBOL_NUMBER; |
| 881 |
|
| 882 |
ch = *cptr++; |
| 883 |
if ( RXISDIGIT( ch ) ) |
| 884 |
{ |
| 885 |
do { |
| 886 |
if ( cptr == eptr ) |
| 887 |
return SYMBOL_NUMBER; |
| 888 |
|
| 889 |
ch = *cptr++; |
| 890 |
} while ( RXISDIGIT( ch ) ); |
| 891 |
} |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
/* |
| 896 |
* We have to parse an exponent. ch has the current character. |
| 897 |
*/ |
| 898 |
if ( ( ch != 'e' ) && ( ch != 'E' ) ) |
| 899 |
break; |
| 900 |
|
| 901 |
if ( cptr == eptr ) |
| 902 |
return SYMBOL_CONSTANT; |
| 903 |
|
| 904 |
ch = *cptr++; |
| 905 |
if ( ( ch == '+' ) || ( ch == '-' ) ) |
| 906 |
{ |
| 907 |
sign = 1; |
| 908 |
if ( cptr == eptr ) |
| 909 |
return SYMBOL_BAD; /* something like "1.2E+" */ |
| 910 |
ch = *cptr++; |
| 911 |
} |
| 912 |
/* |
| 913 |
* parse the exponent value |
| 914 |
*/ |
| 915 |
if ( !RXISDIGIT( ch ) ) |
| 916 |
break; |
| 917 |
do { |
| 918 |
if ( cptr == eptr ) |
| 919 |
return SYMBOL_NUMBER; |
| 920 |
|
| 921 |
ch = *cptr++; |
| 922 |
} while ( RXISDIGIT( ch ) ); |
| 923 |
|
| 924 |
break; |
| 925 |
} |
| 926 |
|
| 927 |
/* |
| 928 |
* We have to check for a const_symbol. If a sign has occurred until now |
| 929 |
* we have a bad symbol. |
| 930 |
* ch is loaded with the current character. |
| 931 |
*/ |
| 932 |
if ( sign || !RXISCONST( ch ) ) |
| 933 |
return SYMBOL_BAD; |
| 934 |
|
| 935 |
do { |
| 936 |
if ( cptr == eptr ) |
| 937 |
return SYMBOL_CONSTANT; |
| 938 |
|
| 939 |
ch = *cptr++; |
| 940 |
} while ( RXISCONST( ch ) ); |
| 941 |
|
| 942 |
/* |
| 943 |
* garbage in ch |
| 944 |
*/ |
| 945 |
return SYMBOL_BAD; |
| 946 |
} |
| 947 |
|
| 948 |
/* |
| 949 |
* Note: This is one of the most time-consuming routines. Be careful. |
| 950 |
* It is a define to remove one time-consuming function call. |
| 951 |
*/ |
| 952 |
#define hashfunc(vt,name,start,stop,mod) /**/ \ |
| 953 |
(vt->hashval = ( (vt->fullhash = hashvalue_var( name, start, stop )) % \ |
| 954 |
(mod) ) ) |
| 955 |
|
| 956 |
/* |
| 957 |
* create a standard sized variable pool in a hash table. |
| 958 |
*/ |
| 959 |
var_hashtable *create_new_varpool( const tsd_t *TSD, int size ) |
| 960 |
{ |
| 961 |
var_tsd_t *vt; |
| 962 |
var_hashtable *retval; |
| 963 |
|
| 964 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 965 |
if (size <= 10) |
| 966 |
{ |
| 967 |
size = vt->initialHashTableLength; |
| 968 |
} |
| 969 |
retval = make_hash_table( TSD, size ); |
| 970 |
|
| 971 |
DPRINTF((TSD,"make_hash_table: rc=%p", retval)); |
| 972 |
DPRINTF((TSD,"create_new_varpool:current_valid:new=%d, old=%d", |
| 973 |
vt->next_current_valid,vt->current_valid)); |
| 974 |
retval->tbl[size] = (variableptr) vt->current_valid; |
| 975 |
vt->current_valid = vt->next_current_valid++; |
| 976 |
|
| 977 |
return retval; |
| 978 |
} |
| 979 |
|
| 980 |
void set_ignore_novalue( const tsd_t *TSD ) |
| 981 |
{ |
| 982 |
var_tsd_t *vt; |
| 983 |
|
| 984 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 985 |
vt->ignore_novalue = 1; |
| 986 |
DPRINTF((TSD,"set_ignore_novalue")); |
| 987 |
} |
| 988 |
|
| 989 |
void clear_ignore_novalue( const tsd_t *TSD ) |
| 990 |
{ |
| 991 |
var_tsd_t *vt; |
| 992 |
|
| 993 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 994 |
vt->ignore_novalue = 0; |
| 995 |
DPRINTF((TSD,"clear_ignore_novalue")); |
| 996 |
} |
| 997 |
|
| 998 |
/* |
| 999 |
* variables_per_SAA changes the variable pool's interface so that an access by |
| 1000 |
* the SAA API works in the defined way, that is without tracing and without |
| 1001 |
* signalling a NOVALUE condition. |
| 1002 |
* The returned value must be used to feed restore_variable_state() after the |
| 1003 |
* SAA access. |
| 1004 |
*/ |
| 1005 |
int variables_per_SAA( tsd_t *TSD ) |
| 1006 |
{ |
| 1007 |
int retval; |
| 1008 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1009 |
|
| 1010 |
retval = vt->notrace ? 2 : 0; |
| 1011 |
retval |= vt->ignore_novalue ? 1 : 0; |
| 1012 |
vt->notrace = 1; |
| 1013 |
vt->ignore_novalue = 1; |
| 1014 |
DPRINTF((TSD,"variables_per_SAA")); |
| 1015 |
return retval; |
| 1016 |
} |
| 1017 |
|
| 1018 |
/* |
| 1019 |
* restore_variable_state restores the state that was before the call to |
| 1020 |
* variables_per_SAA(). Look there. |
| 1021 |
*/ |
| 1022 |
void restore_variable_state( const tsd_t *TSD, int state ) |
| 1023 |
{ |
| 1024 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1025 |
|
| 1026 |
vt->notrace = ( state >> 1 ) & 1; |
| 1027 |
vt->ignore_novalue = state & 1; |
| 1028 |
DPRINTF((TSD,"restore_variable_state")); |
| 1029 |
} |
| 1030 |
|
| 1031 |
const streng *get_it_anyway( tsd_t *TSD, const streng *str, int pool ) |
| 1032 |
{ |
| 1033 |
const streng *ptr; |
| 1034 |
var_tsd_t *vt; |
| 1035 |
|
| 1036 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 1037 |
|
| 1038 |
vt->notrace = 1; |
| 1039 |
vt->ignore_novalue = 1; |
| 1040 |
ptr = getvalue( TSD, str, pool ); /* changes the pool */ |
| 1041 |
vt->ignore_novalue = 0; |
| 1042 |
vt->notrace = 0; |
| 1043 |
|
| 1044 |
if ( !ptr ) |
| 1045 |
exiterror( ERR_SYMBOL_EXPECTED, 1, tmpstr_of( TSD, str ) ); |
| 1046 |
|
| 1047 |
DSTART;DPRINT((TSD,"get_it_anyway: "));DNAME(TSD,"str",str);DVALUE(TSD,", rc",ptr);DEND; |
| 1048 |
return ptr; |
| 1049 |
} |
| 1050 |
|
| 1051 |
const streng *get_it_anyway_compound( tsd_t *TSD, const streng *str ) |
| 1052 |
/* as get_it_anyway but specific to getdirvalue_compound */ |
| 1053 |
{ |
| 1054 |
const streng *ptr; |
| 1055 |
var_tsd_t *vt; |
| 1056 |
|
| 1057 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 1058 |
|
| 1059 |
vt->notrace = 1; |
| 1060 |
vt->ignore_novalue = 1; |
| 1061 |
ptr = getdirvalue_compound( TSD, TSD->currlevel->vars, str ); |
| 1062 |
vt->ignore_novalue = 0; |
| 1063 |
vt->notrace = 0; |
| 1064 |
|
| 1065 |
if ( !ptr ) |
| 1066 |
exiterror( ERR_SYMBOL_EXPECTED, 1, tmpstr_of( TSD, str ) ); |
| 1067 |
|
| 1068 |
DSTART;DPRINT((TSD,"get_it_anyway_compound:"));DNAME(TSD,"str",str);DVALUE(TSD,", rc",ptr);DEND; |
| 1069 |
return ptr; |
| 1070 |
} |
| 1071 |
|
| 1072 |
int var_was_found( const tsd_t *TSD ) |
| 1073 |
{ |
| 1074 |
var_tsd_t *vt; |
| 1075 |
|
| 1076 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 1077 |
DPRINTF((TSD,"var_was_found: rc=%d",vt->foundflag)); |
| 1078 |
return vt->foundflag; |
| 1079 |
} |
| 1080 |
|
| 1081 |
const streng *isvariable( tsd_t *TSD, const streng *str ) |
| 1082 |
{ |
| 1083 |
const streng *ptr; |
| 1084 |
var_tsd_t *vt; |
| 1085 |
|
| 1086 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 1087 |
vt->ignore_novalue = 1 ; |
| 1088 |
ptr = getvalue( TSD, str, -1 ); /* changes the pool */ |
| 1089 |
vt->ignore_novalue = 0; |
| 1090 |
DSTART;DPRINT((TSD,"isvariable: "));DNAME(TSD,"str",str); |
| 1091 |
DVALUE(TSD,", rc",(vt->foundflag)?ptr:NULL);DEND; |
| 1092 |
if ( vt->foundflag ) |
| 1093 |
return ptr; |
| 1094 |
|
| 1095 |
return NULL; |
| 1096 |
} |
| 1097 |
|
| 1098 |
#ifdef TRACEMEM |
| 1099 |
static void mark_variables( const tsd_t *TSD ) |
| 1100 |
{ |
| 1101 |
unsigned i,j; |
| 1102 |
var_tsd_t *vt; |
| 1103 |
|
| 1104 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 1105 |
markmemory( vt->tmpindex, TRC_STATIC ); |
| 1106 |
if ( vt->ovalue ) |
| 1107 |
markmemory( vt->ovalue, TRC_STATIC ); |
| 1108 |
if ( vt->xvalue ) |
| 1109 |
markmemory( vt->xvalue, TRC_STATIC ); |
| 1110 |
if ( vt->odescr ) |
| 1111 |
{ |
| 1112 |
markmemory( vt->odescr, TRC_STATIC ); |
| 1113 |
markmemory( vt->odescr->num, TRC_STATIC ); |
| 1114 |
} |
| 1115 |
for ( i = 0; i < POOL0_CNT; i++ ) |
| 1116 |
{ |
| 1117 |
for ( j = 0; j < 2; j++ ) |
| 1118 |
{ |
| 1119 |
if ( vt->pool0nodes[i][j].name != NULL ) |
| 1120 |
{ |
| 1121 |
markmemory( vt->pool0nodes[i][j].name, TRC_SPCV_NAME ); |
| 1122 |
|
| 1123 |
} |
| 1124 |
} |
| 1125 |
} |
| 1126 |
} |
| 1127 |
#endif |
| 1128 |
|
| 1129 |
/* init_vars initializes the module. |
| 1130 |
* Currently, we set up the thread specific data and check for environment |
| 1131 |
* variables to change debugging behaviour. |
| 1132 |
* The function returns 1 on success, 0 if memory is short. |
| 1133 |
*/ |
| 1134 |
int init_vars( tsd_t *TSD ) |
| 1135 |
{ |
| 1136 |
var_tsd_t *vt; |
| 1137 |
int i, j; |
| 1138 |
char buf[3]; |
| 1139 |
streng *ptr; |
| 1140 |
|
| 1141 |
if ( TSD->var_tsd != NULL ) |
| 1142 |
return 1; |
| 1143 |
|
| 1144 |
if ( ( TSD->var_tsd = MallocTSD( sizeof( var_tsd_t ) ) ) == NULL ) |
| 1145 |
return 0; |
| 1146 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 1147 |
memset( vt, 0, sizeof( var_tsd_t ) ); |
| 1148 |
vt->initialHashTableLength = 2003; |
| 1149 |
|
| 1150 |
#ifdef DEBUG |
| 1151 |
{ |
| 1152 |
char junk[100]; |
| 1153 |
if ( mygetenv( TSD, "DEBUG_VARIABLE", junk, sizeof( junk ) ) != NULL ) |
| 1154 |
{ |
| 1155 |
vt->DoDebug = 1; |
| 1156 |
if (rx_isdigit(junk[0]) && ((junk[1] == ',') || (junk[1] == '\0'))) { |
| 1157 |
vt->DoDebug = junk[0] - '0'; |
| 1158 |
} |
| 1159 |
vt->DebugFile = stderr; |
| 1160 |
if (junk[0] && (junk[1] == ',')) { |
| 1161 |
if ((vt->DebugFile = fopen(junk + 2, "ab")) == NULL) |
| 1162 |
{ |
| 1163 |
vt->DebugFile = stderr; |
| 1164 |
} |
| 1165 |
} |
| 1166 |
} |
| 1167 |
if ( mygetenv( TSD, "DEBUG_HASHTABLENGTH", junk, sizeof( junk ) ) != NULL ) |
| 1168 |
{ |
| 1169 |
int v; |
| 1170 |
char c; |
| 1171 |
|
| 1172 |
if (sscanf(junk, "%d %c", &v, &c) == 1) |
| 1173 |
{ |
| 1174 |
if ((v >= 4) && (v <= 10000)) |
| 1175 |
{ |
| 1176 |
vt->initialHashTableLength = v; |
| 1177 |
} |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
#endif |
| 1182 |
|
| 1183 |
# ifdef TRACEMEM |
| 1184 |
regmarker( TSD, mark_variables ); |
| 1185 |
# endif |
| 1186 |
vt->current_valid = 1; |
| 1187 |
vt->next_current_valid = 2; |
| 1188 |
vt->tmpindex = Str_makeTSD( MAX_INDEX_LENGTH ); |
| 1189 |
/* |
| 1190 |
* pool 0 is not used by the user in most cases. Keep it small. |
| 1191 |
*/ |
| 1192 |
vt->pool0 = create_new_varpool( TSD, 17 ); |
| 1193 |
|
| 1194 |
/* |
| 1195 |
* .RC, .RESULT, and .SIGL have dotless counterparts. |
| 1196 |
*/ |
| 1197 |
vt->pool0nodes[POOL0_RC][0].name = Str_creTSD( ".RC" ); |
| 1198 |
vt->pool0nodes[POOL0_RC][1].name = Str_creTSD( "RC" ); |
| 1199 |
vt->pool0nodes[POOL0_RESULT][0].name = Str_creTSD( ".RESULT" ); |
| 1200 |
vt->pool0nodes[POOL0_RESULT][1].name = Str_creTSD( "RESULT" ); |
| 1201 |
vt->pool0nodes[POOL0_SIGL][0].name = Str_creTSD( ".SIGL" ); |
| 1202 |
vt->pool0nodes[POOL0_SIGL][1].name = Str_creTSD( "SIGL" ); |
| 1203 |
vt->pool0nodes[POOL0_RS][0].name = Str_creTSD( ".RS" ); |
| 1204 |
vt->pool0nodes[POOL0_MN][0].name = Str_creTSD( ".MN" ); |
| 1205 |
vt->pool0nodes[POOL0_LINE][0].name = Str_creTSD( ".LINE" ); |
| 1206 |
vt->pool0nodes[POOL0_FILE][0].name = Str_creTSD( ".FILE" ); |
| 1207 |
vt->pool0nodes[POOL0_DIRSEP][0].name = Str_creTSD( ".DIRSEP" ); |
| 1208 |
vt->pool0nodes[POOL0_ENDOFLINE][0].name = Str_creTSD( ".ENDOFLINE" ); |
| 1209 |
for ( i = 0; i < POOL0_CNT; i++ ) |
| 1210 |
{ |
| 1211 |
for ( j = 0; j < 2; j++ ) |
| 1212 |
{ |
| 1213 |
if ( vt->pool0nodes[i][j].name != NULL ) |
| 1214 |
vt->pool0nodes[i][j].type = X_SIM_SYMBOL; |
| 1215 |
} |
| 1216 |
} |
| 1217 |
/* |
| 1218 |
* We can set .ENDOFLINE and DIRSEP here |
| 1219 |
* Yes its crude! |
| 1220 |
*/ |
| 1221 |
#if defined(UNIX) |
| 1222 |
buf[0] = 0x0a; buf[1] = 0x00; |
| 1223 |
#elif defined(MAC) |
| 1224 |
buf[0] = 0x0d; buf[1] = 0x00; |
| 1225 |
#else |
| 1226 |
buf[0] = 0x0d; buf[1] = 0x0a; buf[2] = 0x00; |
| 1227 |
#endif |
| 1228 |
ptr = Str_creTSD( buf ); |
| 1229 |
set_reserved_value( TSD, POOL0_ENDOFLINE, ptr, 0, VFLAG_STR ); |
| 1230 |
strcpy( buf, FILE_SEPARATOR_STR ); |
| 1231 |
ptr = Str_creTSD( buf ); |
| 1232 |
set_reserved_value( TSD, POOL0_DIRSEP, ptr, 0, VFLAG_STR ); |
| 1233 |
|
| 1234 |
DPRINTF((TSD,"init_vars")); |
| 1235 |
return(1); |
| 1236 |
} |
| 1237 |
|
| 1238 |
/* |
| 1239 |
* This routine takes a ptr to a linked list of nodes, each describing |
| 1240 |
* one element in a tail of a compound variable. Each of the elements |
| 1241 |
* will eventually be cached, since they are retrieved through the |
| 1242 |
* shortcut() routine. |
| 1243 |
*/ |
| 1244 |
static streng *fix_index( tsd_t *TSD, nodeptr thisptr ) |
| 1245 |
{ |
| 1246 |
char *cptr; |
| 1247 |
const streng *value; |
| 1248 |
int osetting; |
| 1249 |
int freespc; |
| 1250 |
streng *large; |
| 1251 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1252 |
|
| 1253 |
assert( thisptr ) ; |
| 1254 |
osetting = vt->ignore_novalue ; |
| 1255 |
vt->ignore_novalue = 1 ; |
| 1256 |
|
| 1257 |
DPRINTF((TSD,"fix_index, start: thisptr=%p",thisptr)); |
| 1258 |
freespc = vt->tmpindex->max ; |
| 1259 |
cptr = vt->tmpindex->value ; |
| 1260 |
|
| 1261 |
for ( ; ; ) |
| 1262 |
{ |
| 1263 |
assert( thisptr->type==X_CTAIL_SYMBOL || thisptr->type==X_VTAIL_SYMBOL) ; |
| 1264 |
if ( thisptr->type == X_CTAIL_SYMBOL ) |
| 1265 |
value = thisptr->name ; |
| 1266 |
else |
| 1267 |
{ |
| 1268 |
vt->subst = 1 ; |
| 1269 |
value = shortcut( TSD, thisptr ) ; |
| 1270 |
} |
| 1271 |
|
| 1272 |
freespc -= value->len; |
| 1273 |
if ( freespc-- <= 0 ) |
| 1274 |
{ |
| 1275 |
large = Str_makeTSD( vt->tmpindex->max * 2 + value->len ) ; |
| 1276 |
memcpy( large->value, vt->tmpindex->value, (cptr-vt->tmpindex->value)) ; |
| 1277 |
cptr = large->value + (cptr-vt->tmpindex->value) ; |
| 1278 |
freespc += (large->max - vt->tmpindex->max) ; |
| 1279 |
Free_stringTSD( vt->tmpindex ) ; |
| 1280 |
vt->tmpindex = large ; |
| 1281 |
|
| 1282 |
assert( freespc >= 0 ) ; |
| 1283 |
} |
| 1284 |
|
| 1285 |
memcpy( cptr, value->value, value->len ) ; |
| 1286 |
cptr += value->len ; |
| 1287 |
thisptr = thisptr->p[0] ; |
| 1288 |
if ( thisptr ) |
| 1289 |
*(cptr++) = '.' ; |
| 1290 |
else |
| 1291 |
break ; |
| 1292 |
} |
| 1293 |
vt->tmpindex->len = cptr - vt->tmpindex->value ; |
| 1294 |
assert( vt->tmpindex->len <= vt->tmpindex->max ) ; |
| 1295 |
vt->ignore_novalue = osetting ; |
| 1296 |
DSTART;DPRINT((TSD,"fix_index, end: thisptr=%p, "));DVALUE(TSD,"rc",vt->tmpindex);DEND; |
| 1297 |
return vt->tmpindex ; |
| 1298 |
} |
| 1299 |
|
| 1300 |
void expand_to_str( const tsd_t *TSD, variableptr ptr ) |
| 1301 |
{ |
| 1302 |
int flag; |
| 1303 |
#ifdef DEBUG |
| 1304 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1305 |
#endif |
| 1306 |
|
| 1307 |
flag = ptr->flag; |
| 1308 |
|
| 1309 |
DSTART;DPRINT((TSD,"expand_to_str: "));DVAR(TSD,"ptr",ptr);DEND; |
| 1310 |
if ( flag & VFLAG_STR ) |
| 1311 |
return; |
| 1312 |
|
| 1313 |
if ( flag & VFLAG_NUM ) |
| 1314 |
{ |
| 1315 |
assert( ptr->num ); |
| 1316 |
ptr->value = str_norm( TSD, ptr->num, ptr->value ); |
| 1317 |
ptr->flag |= VFLAG_STR; |
| 1318 |
} |
| 1319 |
DSTART;DPRINT((TSD,"expand_to_str: "));DVAR(TSD,"ptr",ptr);DEND; |
| 1320 |
} |
| 1321 |
|
| 1322 |
static streng *subst_index( const tsd_t *TSD, const streng *name, int start, |
| 1323 |
var_hashtable *vars, int *expand ) |
| 1324 |
{ |
| 1325 |
int i=0, length=0 ; |
| 1326 |
variableptr nptr; |
| 1327 |
int stop; |
| 1328 |
char *cptr=NULL ; |
| 1329 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1330 |
|
| 1331 |
assert( start < name->len ) ; |
| 1332 |
|
| 1333 |
DPRINTF((TSD,"subst_index: ?")); |
| 1334 |
vt->tmpindex->len = 0; |
| 1335 |
vt->subst = 0; |
| 1336 |
|
| 1337 |
for ( ; ; ) |
| 1338 |
{ |
| 1339 |
nptr = vars->tbl[hashfunc( vt, name, start, &stop, vars->size )]; |
| 1340 |
vars->reads++; |
| 1341 |
|
| 1342 |
length = stop - start; |
| 1343 |
SEEK_VAR_CNOCMP( nptr, name, vt->fullhash, vars, length, start, *expand ); |
| 1344 |
SEEK_EXPOSED( nptr ); |
| 1345 |
|
| 1346 |
if ( nptr ) |
| 1347 |
expand_to_str( TSD, nptr ); |
| 1348 |
|
| 1349 |
if ( nptr && nptr->value ) |
| 1350 |
{ |
| 1351 |
Str_catTSD( vt->tmpindex, nptr->value ); |
| 1352 |
vt->subst = 1; |
| 1353 |
} |
| 1354 |
else |
| 1355 |
{ |
| 1356 |
cptr = vt->tmpindex->value + vt->tmpindex->len; |
| 1357 |
for ( i = start; i < stop; i++ ) |
| 1358 |
*cptr++ = (char) rx_toupper( name->value[i] ); |
| 1359 |
vt->tmpindex->len = cptr - vt->tmpindex->value; |
| 1360 |
} |
| 1361 |
|
| 1362 |
if ( stop >= Str_len( name ) ) |
| 1363 |
break ; |
| 1364 |
|
| 1365 |
start = stop + 1; |
| 1366 |
vt->tmpindex->value[vt->tmpindex->len++] = '.'; |
| 1367 |
} |
| 1368 |
|
| 1369 |
return vt->tmpindex; |
| 1370 |
} |
| 1371 |
|
| 1372 |
/* |
| 1373 |
* TRACEMEM_RELINK relinks a variablebox in the queue of vt->first_invalid. |
| 1374 |
*/ |
| 1375 |
#ifdef TRACEMEM |
| 1376 |
# define TRACEMEM_RELINK(ptr) { \ |
| 1377 |
ptr->prev = vt->first_invalid; \ |
| 1378 |
ptr->next = NULL; \ |
| 1379 |
if ( vt->first_invalid ) \ |
| 1380 |
vt->first_invalid->next = ptr; \ |
| 1381 |
vt->first_invalid = ptr; \ |
| 1382 |
} |
| 1383 |
#else |
| 1384 |
# define TRACEMEM_RELINK(ptr) |
| 1385 |
#endif |
| 1386 |
|
| 1387 |
/* |
| 1388 |
* REMOVE_ELEMENT deletes the content of a variableptr. |
| 1389 |
* The variable itself is NOT freed in most cases. The hollow body of the |
| 1390 |
* variable persists. As far as I understood my old stuff, this prevents a |
| 1391 |
* new variable lookup. |
| 1392 |
*/ |
| 1393 |
#define REMOVE_ELEMENT(ptr, hashtbl) { \ |
| 1394 |
DSTART;DPRINT((TSD," "));DVAR(TSD,"ptr(del)",ptr);DEND; \ |
| 1395 |
Free_stringTSD( ptr->name ); \ |
| 1396 |
if ( ptr->value ) \ |
| 1397 |
Free_stringTSD( ptr->value ); \ |
| 1398 |
\ |
| 1399 |
if ( ptr->num ) \ |
| 1400 |
{ \ |
| 1401 |
FreeTSD( ptr->num->num ); \ |
| 1402 |
FreeTSD( ptr->num ); \ |
| 1403 |
} \ |
| 1404 |
\ |
| 1405 |
if ( ptr->hwired ) \ |
| 1406 |
{ \ |
| 1407 |
ptr->valid = 0; \ |
| 1408 |
TRACEMEM_RELINK( ptr ); \ |
| 1409 |
} \ |
| 1410 |
else \ |
| 1411 |
{ \ |
| 1412 |
FreeTSD( ptr ); \ |
| 1413 |
(hashtbl)->elements--; \ |
| 1414 |
} \ |
| 1415 |
} |
| 1416 |
|
| 1417 |
/* |
| 1418 |
* remove_foliage removes all elements of a stem unconditionally. |
| 1419 |
* Exposed values, better the values and variables the current elements points |
| 1420 |
* to, are not affected. |
| 1421 |
* The stem's index itself is freed, too. |
| 1422 |
*/ |
| 1423 |
static void remove_foliage( const tsd_t *TSD, var_hashtable *index ) |
| 1424 |
{ |
| 1425 |
#if defined(DEBUG) || defined(TRACEMEM) |
| 1426 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1427 |
unsigned start = index->elements; |
| 1428 |
#endif |
| 1429 |
unsigned i; |
| 1430 |
variableptr ptr, tptr; |
| 1431 |
|
| 1432 |
DPRINTF((TSD,"remove_foliage: ?")); |
| 1433 |
|
| 1434 |
assert(index); |
| 1435 |
|
| 1436 |
for ( i = 0; i < index->size; i++ ) |
| 1437 |
{ |
| 1438 |
if ( ( ptr = index->tbl[i] ) == NULL ) |
| 1439 |
continue; |
| 1440 |
|
| 1441 |
do { |
| 1442 |
/* |
| 1443 |
* Not needed here but it indicates an error elsewhere: |
| 1444 |
*/ |
| 1445 |
/*assert( ptr->stem );*/ |
| 1446 |
|
| 1447 |
tptr = ptr->next; |
| 1448 |
|
| 1449 |
if ( ptr->index ) |
| 1450 |
{ |
| 1451 |
/* |
| 1452 |
* This indicates a serious problem. Regina doesn't allow branches |
| 1453 |
* currently. (branch = stem within a stem) |
| 1454 |
*/ |
| 1455 |
assert( ptr->index ); |
| 1456 |
remove_foliage( TSD, ptr->index ); |
| 1457 |
} |
| 1458 |
|
| 1459 |
REMOVE_ELEMENT( ptr, index ); |
| 1460 |
|
| 1461 |
ptr = tptr; |
| 1462 |
} while ( ptr != NULL ); |
| 1463 |
} |
| 1464 |
FreeTSD( index->tbl ); |
| 1465 |
DPRINTF((TSD," kill=%p",index)); |
| 1466 |
DPRINTF_2((TSD,"STATISTICS: %u(%u) in %u buckets, %u r, %u w, %u colls", |
| 1467 |
index->elements, start, index->size, index->reads, |
| 1468 |
index->writes, index->collisions)); |
| 1469 |
FreeTSD( index ); |
| 1470 |
} |
| 1471 |
|
| 1472 |
/* |
| 1473 |
* assign_foliage manipulates the index of a stem. The index is the list of all |
| 1474 |
* variables in the stem. |
| 1475 |
* value is the value for the replacement and is read-only. The value may be |
| 1476 |
* NULL. |
| 1477 |
* Each element in the index is either removed or reassigned depending on the |
| 1478 |
* fact whether the element is local or exposed. A value of NULL leads to a |
| 1479 |
* complete removal of the element which is equivalent to a "drop". |
| 1480 |
* This fixes bug 732146, which removed all elements unconditionally after |
| 1481 |
* an assignment. |
| 1482 |
* ANSI 7.1.2 and 7.1.4 forces us to assign all exposed elements or to delete |
| 1483 |
* all exposed elements. Note that a dropped and exposed variable should be |
| 1484 |
* assigned in the formerly used variable pool (aka index), so we use a |
| 1485 |
* technique which allows us to lookup such values (we don't delete the realbox |
| 1486 |
* chain). On the other hand we really remove local variables to save space. |
| 1487 |
*/ |
| 1488 |
static void assign_foliage( const tsd_t *TSD, var_hashtable *index, |
| 1489 |
const streng *val ) |
| 1490 |
{ |
| 1491 |
#if defined(DEBUG) || defined(TRACEMEM) |
| 1492 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1493 |
#endif |
| 1494 |
unsigned i; |
| 1495 |
streng *copy; |
| 1496 |
variableptr ptr, tptr, *queue, real; |
| 1497 |
streng *nullptr = NULL; /* allow REPLACE_VALUE macro to pass NULL value under C++ */ |
| 1498 |
|
| 1499 |
DPRINTF((TSD,"assign_foliage: ?")); |
| 1500 |
|
| 1501 |
assert(index); |
| 1502 |
|
| 1503 |
for ( i = 0; i < index->size; i++ ) |
| 1504 |
{ |
| 1505 |
if ( ( ptr = index->tbl[i] ) == NULL ) |
| 1506 |
continue; |
| 1507 |
|
| 1508 |
queue = &index->tbl[i]; |
| 1509 |
|
| 1510 |
do { |
| 1511 |
/* |
| 1512 |
* Not needed here but it indicates an error elsewhere: |
| 1513 |
*/ |
| 1514 |
assert( ptr->stem ); |
| 1515 |
|
| 1516 |
tptr = ptr->next; |
| 1517 |
|
| 1518 |
/* |
| 1519 |
* We can't handle sub-stems. |
| 1520 |
*/ |
| 1521 |
assert( ptr->index == NULL ); |
| 1522 |
|
| 1523 |
if ( ptr->realbox ) |
| 1524 |
{ |
| 1525 |
real = ptr; |
| 1526 |
SEEK_EXPOSED(real); |
| 1527 |
if ( val ) |
| 1528 |
{ |
| 1529 |
copy = Str_dupTSD( val ); |
| 1530 |
REPLACE_VALUE( copy, real ); |
| 1531 |
DSTART;DPRINT((TSD," "));DVAR(TSD,"real(now)",real);DEND; |
| 1532 |
} |
| 1533 |
else if ( real->value ) |
| 1534 |
{ |
| 1535 |
REPLACE_VALUE( nullptr, real ); |
| 1536 |
DSTART;DPRINT((TSD," "));DVAR(TSD,"real(now)",real);DEND; |
| 1537 |
} |
| 1538 |
|
| 1539 |
*queue = ptr; |
| 1540 |
queue = &(ptr->next); |
| 1541 |
} |
| 1542 |
else |
| 1543 |
{ |
| 1544 |
if ( val == NULL ) |
| 1545 |
{ |
| 1546 |
REMOVE_ELEMENT( ptr, index ); |
| 1547 |
} |
| 1548 |
else |
| 1549 |
{ |
| 1550 |
copy = Str_dupTSD( val ); |
| 1551 |
REPLACE_VALUE( copy, ptr ); |
| 1552 |
DSTART;DPRINT((TSD," "));DVAR(TSD,"ptr(now)",ptr);DEND; |
| 1553 |
*queue = ptr; |
| 1554 |
queue = &(ptr->next); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
ptr = tptr; |
| 1559 |
} while ( ptr != NULL ); |
| 1560 |
|
| 1561 |
*queue = NULL; |
| 1562 |
} |
| 1563 |
} |
| 1564 |
#undef REMOVE_ELEMENT |
| 1565 |
#undef TRACEMEM_RELINK |
| 1566 |
|
| 1567 |
/* |
| 1568 |
* reorgHashtable reorganises the hash table vars if a potential for better |
| 1569 |
* results in the future is seen. |
| 1570 |
* returns 0 if the table has its original structure. |
| 1571 |
* returns 1 if the table has been reorganised. |
| 1572 |
*/ |
| 1573 |
static int reorgHashtable( const tsd_t *TSD, var_hashtable *vars ) |
| 1574 |
{ |
| 1575 |
int f1 = 0, f2 = 0; |
| 1576 |
unsigned newSize, i; |
| 1577 |
variableptr *newTbl, *dest; |
| 1578 |
variableptr thisptr, run; |
| 1579 |
#ifdef DEBUG |
| 1580 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1581 |
#endif |
| 1582 |
|
| 1583 |
NEW_HASHTABLE_CHECK( vars, f1 ); |
| 1584 |
COLLISION_CHECK( vars, f2 ); |
| 1585 |
if ( !(f1 | f2 ) ) |
| 1586 |
{ |
| 1587 |
/* |
| 1588 |
* May happen in case of f2 where a ->reads or ->writes is set after the |
| 1589 |
* collision detection. Ignore it. That is no bug. |
| 1590 |
*/ |
| 1591 |
DPRINTF_2((TSD,"reorgHashtable: %p/%p: BLIND ALERT", vars, vars->tbl)); |
| 1592 |
return 0; |
| 1593 |
} |
| 1594 |
|
| 1595 |
/* |
| 1596 |
* Increase the current size by factor 2 and add 1. Don't keep this at |
| 1597 |
* a specific factor, the hash function may map to same values and we |
| 1598 |
* are lost. |
| 1599 |
*/ |
| 1600 |
newSize = vars->size * 2; |
| 1601 |
newSize++; |
| 1602 |
|
| 1603 |
if ( vars->size >= newSize ) |
| 1604 |
{ |
| 1605 |
/* |
| 1606 |
* We can't help. Check the stupid hashfunc() in this case. |
| 1607 |
*/ |
| 1608 |
DPRINTF_2((TSD,"reorgHashtable: %p/%p: heavy collisions %u", |
| 1609 |
vars, vars->tbl, vars->collisions)); |
| 1610 |
vars->reads = 0; |
| 1611 |
vars->writes = 0; |
| 1612 |
vars->collisions = 0; |
| 1613 |
return 0; |
| 1614 |
} |
| 1615 |
|
| 1616 |
newTbl = (variableptr *)MallocTSD( sizeof(variableptr) * newSize ); |
| 1617 |
memset( newTbl, 0, sizeof(variableptr) * newSize ); |
| 1618 |
DPRINTF((TSD,"reorgHashtable: %p -> %p Old(%u) New(%u) %u %u", |
| 1619 |
vars->tbl,newTbl,vars->size, newSize, f1, f2)); |
| 1620 |
DPRINTF_2((TSD,"reorgHashtable: changing size of %p/%p (%u) to %p/%p (%u), c=%u(%d)", |
| 1621 |
vars,vars->tbl,vars->size,vars,newTbl,newSize, vars->collisions,f2)); |
| 1622 |
|
| 1623 |
for ( i = 0; i < vars->size; i++ ) |
| 1624 |
{ |
| 1625 |
run = vars->tbl[i]; |
| 1626 |
|
| 1627 |
while ( run ) |
| 1628 |
{ |
| 1629 |
thisptr = run; |
| 1630 |
run = run->next; |
| 1631 |
|
| 1632 |
dest = newTbl + (thisptr->hash % newSize); |
| 1633 |
if (*dest) |
| 1634 |
{ |
| 1635 |
(*dest)->prev = thisptr; |
| 1636 |
} |
| 1637 |
thisptr->next = *dest; |
| 1638 |
*dest = thisptr; |
| 1639 |
thisptr->prev = NULL; |
| 1640 |
} |
| 1641 |
} |
| 1642 |
|
| 1643 |
FreeTSD( vars->tbl ); |
| 1644 |
vars->tbl = newTbl; |
| 1645 |
vars->size = newSize; |
| 1646 |
vars->reads = 0; |
| 1647 |
vars->writes = 0; |
| 1648 |
vars->collisions = 0; |
| 1649 |
return 1; |
| 1650 |
} |
| 1651 |
|
| 1652 |
static variableptr findsimple( const tsd_t *TSD, var_hashtable *vars, |
| 1653 |
const streng *name, int *expand ) |
| 1654 |
{ |
| 1655 |
variableptr ptr; |
| 1656 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1657 |
|
| 1658 |
ptr = vars->tbl[hashfunc( vt, name, 0, NULL, vars->size)]; |
| 1659 |
SEEK_VAR_CCMP( ptr, name, vt->fullhash, vars, *expand ); |
| 1660 |
SEEK_EXPOSED( ptr ); |
| 1661 |
|
| 1662 |
vt->thespot = ptr; |
| 1663 |
DSTART;DPRINT((TSD,"findsimple: "));DNAME(TSD,"name",name); |
| 1664 |
DVAR(TSD,", vt->thespot=ptr",ptr);DEND; |
| 1665 |
|
| 1666 |
return ptr; |
| 1667 |
} |
| 1668 |
|
| 1669 |
static int setvalue_simple( const tsd_t *TSD, var_hashtable *vars, |
| 1670 |
const streng *name, streng *value ) |
| 1671 |
{ |
| 1672 |
variableptr ptr; |
| 1673 |
int rehash = 0; |
| 1674 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1675 |
|
| 1676 |
vars->writes++; |
| 1677 |
ptr = findsimple( TSD, vars, name, &rehash ); |
| 1678 |
if ( ptr ) |
| 1679 |
{ |
| 1680 |
vt->foundflag = ptr->flag & VFLAG_BOTH; |
| 1681 |
REPLACE_VALUE( value, ptr ); |
| 1682 |
DSTART;DPRINT((TSD,"setvalue_simple: "));DVAR(TSD,"replacement",ptr);DEND; |
| 1683 |
} |
| 1684 |
else |
| 1685 |
{ |
| 1686 |
vt->foundflag = 0; |
| 1687 |
vt->thespot = newbox( TSD, name, value, &vars->tbl[vt->hashval], |
| 1688 |
vt->fullhash ); |
| 1689 |
vars->elements++; |
| 1690 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 1691 |
DSTART;DPRINT((TSD,"setvalue_simple: "));DVAR(TSD,"new, vt->thespot",ptr);DEND; |
| 1692 |
} |
| 1693 |
if ( rehash ) |
| 1694 |
{ |
| 1695 |
return reorgHashtable( TSD, vars ); |
| 1696 |
} |
| 1697 |
return 0; |
| 1698 |
} |
| 1699 |
|
| 1700 |
static const streng *getvalue_simple( tsd_t *TSD, var_hashtable *vars, |
| 1701 |
const streng *name ) |
| 1702 |
{ |
| 1703 |
variableptr ptr; |
| 1704 |
const streng *value; |
| 1705 |
int rehash = 0; |
| 1706 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1707 |
|
| 1708 |
vars->reads++; |
| 1709 |
ptr = findsimple( TSD, vars, name, &rehash ); |
| 1710 |
if ( rehash ) |
| 1711 |
{ |
| 1712 |
reorgHashtable( TSD, vars ); |
| 1713 |
} |
| 1714 |
|
| 1715 |
vt->foundflag = ptr && ( ptr->flag & VFLAG_BOTH ); |
| 1716 |
|
| 1717 |
if ( ptr ) |
| 1718 |
expand_to_str( TSD, ptr ); |
| 1719 |
|
| 1720 |
if ( vt->foundflag ) |
| 1721 |
value = ptr->value; |
| 1722 |
else |
| 1723 |
{ |
| 1724 |
value = name; |
| 1725 |
vt->thespot = NULL; |
| 1726 |
if ( !vt->ignore_novalue ) |
| 1727 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( value ), NULL ); |
| 1728 |
} |
| 1729 |
|
| 1730 |
if ( !vt->notrace ) |
| 1731 |
tracevalue( TSD, value,(char) ( (ptr) ? 'V' : 'L' ) ); |
| 1732 |
|
| 1733 |
DSTART;DPRINT((TSD,"getvalue_simple: "));DNAME(TSD,"name",name); |
| 1734 |
DVALUE(TSD," rc",value);DEND; |
| 1735 |
return value; |
| 1736 |
} |
| 1737 |
|
| 1738 |
static int setvalue_stem( const tsd_t *TSD, var_hashtable *vars, |
| 1739 |
const streng *name, streng *value ) |
| 1740 |
{ |
| 1741 |
variableptr ptr; |
| 1742 |
int rehash = 0; |
| 1743 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1744 |
|
| 1745 |
DPRINTF((TSD,"setvalue_stem: ?")); |
| 1746 |
|
| 1747 |
vars->writes++; |
| 1748 |
ptr = findsimple( TSD, vars, name, &rehash ); |
| 1749 |
|
| 1750 |
if ( ptr ) |
| 1751 |
{ |
| 1752 |
vt->foundflag = ( ptr->flag & VFLAG_BOTH ); |
| 1753 |
REPLACE_VALUE( value, ptr ); |
| 1754 |
if ( ptr->index ) |
| 1755 |
assign_foliage( TSD, ptr->index, value ); |
| 1756 |
} |
| 1757 |
else |
| 1758 |
{ |
| 1759 |
vt->foundflag = 0; |
| 1760 |
make_stem( TSD, name, value, &vars->tbl[vt->hashval], name->len, |
| 1761 |
vt->fullhash ); |
| 1762 |
vars->elements++; |
| 1763 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 1764 |
} |
| 1765 |
vt->thespot = NULL; |
| 1766 |
if ( rehash ) |
| 1767 |
{ |
| 1768 |
return reorgHashtable( TSD, vars ); |
| 1769 |
} |
| 1770 |
return 0; |
| 1771 |
} |
| 1772 |
|
| 1773 |
static int setvalue_compound( tsd_t *TSD, var_hashtable *vars, |
| 1774 |
const streng *name, streng *value ) |
| 1775 |
{ |
| 1776 |
variableptr ptr, nptr, *nnptr, *pptr; |
| 1777 |
int stop, rehash = 0, rehashIdx = 0; |
| 1778 |
streng *indexstr; |
| 1779 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1780 |
|
| 1781 |
DPRINTF((TSD,"setvalue_compound: ?")); |
| 1782 |
vt->foundflag = 0 ; |
| 1783 |
pptr = &vars->tbl[hashfunc( vt, name, 0, &stop, vars->size )]; |
| 1784 |
stop++; |
| 1785 |
ptr = *pptr; |
| 1786 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, stop, rehash ); |
| 1787 |
SEEK_EXPOSED( ptr ); |
| 1788 |
|
| 1789 |
if ( !ptr ) |
| 1790 |
{ |
| 1791 |
ptr = make_stem( TSD, name, NULL, pptr, stop, vt->fullhash ); |
| 1792 |
vars->elements++; |
| 1793 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 1794 |
vars->writes++; |
| 1795 |
} |
| 1796 |
else |
| 1797 |
{ |
| 1798 |
vars->reads++; |
| 1799 |
} |
| 1800 |
|
| 1801 |
indexstr = subst_index( TSD, name, stop, vars, &rehash ); |
| 1802 |
|
| 1803 |
if ( rehash ) |
| 1804 |
{ |
| 1805 |
rehash = reorgHashtable( TSD, vars ); |
| 1806 |
} |
| 1807 |
|
| 1808 |
if ( vt->subst ) /* trace it */ |
| 1809 |
tracecompound( TSD, name, stop - 1, indexstr, 'C' ); |
| 1810 |
|
| 1811 |
vars->writes++; |
| 1812 |
nnptr = &(ptr->index->tbl[hashfunc( vt, indexstr, 0, NULL, ptr->index->size )]); |
| 1813 |
nptr = *nnptr; |
| 1814 |
SEEK_VAR_CMP( nptr, indexstr, vt->fullhash, ptr->index, rehashIdx ); |
| 1815 |
SEEK_EXPOSED( nptr ); |
| 1816 |
|
| 1817 |
if ( nptr ) |
| 1818 |
{ |
| 1819 |
vt->foundflag = nptr && ( nptr->flag & VFLAG_BOTH ) ; |
| 1820 |
REPLACE_VALUE( value, nptr ); |
| 1821 |
} |
| 1822 |
else |
| 1823 |
{ |
| 1824 |
newbox( TSD, indexstr, value, nnptr, vt->fullhash ); |
| 1825 |
ptr->index->elements++; |
| 1826 |
NEW_HASHTABLE_CHECK( ptr->index, rehashIdx ); |
| 1827 |
(*nnptr)->stem = ptr; |
| 1828 |
} |
| 1829 |
|
| 1830 |
vt->thespot = NULL; |
| 1831 |
if ( rehashIdx ) |
| 1832 |
{ |
| 1833 |
rehashIdx = reorgHashtable( TSD, ptr->index ); |
| 1834 |
} |
| 1835 |
return rehash | rehashIdx; |
| 1836 |
} |
| 1837 |
|
| 1838 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 1839 |
/**************************************************************************** |
| 1840 |
* |
| 1841 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 1842 |
* |
| 1843 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 1844 |
* - Adapted from setvalue_compound(). |
| 1845 |
* - Started using the global variable, vt->tmpindex, in place of the local, |
| 1846 |
* indexstr. |
| 1847 |
* - manually move the first stem name into vt->tmpindex, do not call |
| 1848 |
* subst_index(), as that not only uppercases the tail, but also |
| 1849 |
* does not uppercase the tail. |
| 1850 |
* |
| 1851 |
* |
| 1852 |
****************************************************************************/ |
| 1853 |
static int setdirvalue_compound( tsd_t *TSD, var_hashtable *vars, |
| 1854 |
const streng *name, streng *value ) |
| 1855 |
{ |
| 1856 |
variableptr ptr, nptr, *nnptr, *pptr; |
| 1857 |
int rehash = 0, rehashIdx = 0; |
| 1858 |
int stop; |
| 1859 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1860 |
|
| 1861 |
DPRINTF((TSD,"setdirvalue_compound: ?")); |
| 1862 |
vt->foundflag = 0; |
| 1863 |
|
| 1864 |
/* |
| 1865 |
* Get a good starting point, and find the stem/index separater. |
| 1866 |
*/ |
| 1867 |
pptr = &vars->tbl[hashfunc( vt, name, 0, &stop, vars->size )]; |
| 1868 |
stop++; |
| 1869 |
|
| 1870 |
/* |
| 1871 |
* Find the stem in the variable pool. |
| 1872 |
*/ |
| 1873 |
ptr = *pptr; |
| 1874 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, stop, rehash ); |
| 1875 |
SEEK_EXPOSED( ptr ); |
| 1876 |
|
| 1877 |
/* |
| 1878 |
* If the stem does not exist, make one. |
| 1879 |
*/ |
| 1880 |
if ( !ptr ) |
| 1881 |
{ |
| 1882 |
ptr = make_stem( TSD, name, NULL, pptr, stop, vt->fullhash ); |
| 1883 |
vars->elements++; |
| 1884 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 1885 |
vars->writes++; |
| 1886 |
} |
| 1887 |
else |
| 1888 |
{ |
| 1889 |
vars->reads++; |
| 1890 |
} |
| 1891 |
|
| 1892 |
if ( rehash ) |
| 1893 |
{ |
| 1894 |
rehash = reorgHashtable( TSD, vars ); |
| 1895 |
} |
| 1896 |
|
| 1897 |
vt->tmpindex->len = 0; |
| 1898 |
vt->tmpindex = Str_nocatTSD( vt->tmpindex, name, name->len - stop, stop ); |
| 1899 |
|
| 1900 |
/* |
| 1901 |
* FIXME, FGC: vt->subst from "if" removed, but what shall we do here really? |
| 1902 |
*/ |
| 1903 |
if ( !vt->notrace ) /* trace it */ |
| 1904 |
tracecompound( TSD, name, stop - 1, vt->tmpindex, 'C' ); |
| 1905 |
|
| 1906 |
nnptr = &((ptr->index->tbl)[hashfunc( vt, vt->tmpindex, 0, NULL, |
| 1907 |
ptr->index->size)]); |
| 1908 |
vars->reads++; |
| 1909 |
nptr = *nnptr; |
| 1910 |
SEEK_VAR_CMP( nptr, vt->tmpindex, vt->fullhash, ptr->index, rehashIdx ); |
| 1911 |
SEEK_EXPOSED( nptr ); |
| 1912 |
|
| 1913 |
if ( nptr ) |
| 1914 |
{ |
| 1915 |
vt->foundflag = nptr && ( nptr->flag & VFLAG_BOTH ); |
| 1916 |
REPLACE_VALUE( value, nptr ); |
| 1917 |
} |
| 1918 |
else |
| 1919 |
{ |
| 1920 |
newbox( TSD, vt->tmpindex, value, nnptr, vt->fullhash ); |
| 1921 |
ptr->index->elements++; |
| 1922 |
NEW_HASHTABLE_CHECK( ptr->index, rehashIdx ); |
| 1923 |
(*nnptr)->stem = ptr; |
| 1924 |
} |
| 1925 |
|
| 1926 |
vt->thespot = NULL; |
| 1927 |
if ( rehashIdx ) |
| 1928 |
{ |
| 1929 |
rehashIdx = reorgHashtable( TSD, ptr->index ); |
| 1930 |
} |
| 1931 |
return rehash | rehashIdx; |
| 1932 |
} |
| 1933 |
|
| 1934 |
static void expose_simple( const tsd_t *TSD, var_hashtable *vars, |
| 1935 |
const streng *name ) |
| 1936 |
{ |
| 1937 |
unsigned hashv, hashn; |
| 1938 |
variableptr ptr; |
| 1939 |
int rehash = 0; |
| 1940 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1941 |
|
| 1942 |
hashv = hashfunc( vt, name, 0, NULL, vt->var_table->size ); |
| 1943 |
ptr = vt->var_table->tbl[hashv]; |
| 1944 |
vt->var_table->reads++; |
| 1945 |
SEEK_VAR_CCMP( ptr, name, vt->fullhash, vt->var_table, rehash ); |
| 1946 |
|
| 1947 |
if ( ptr ) /* hey, you just exposed that one! */ |
| 1948 |
return; |
| 1949 |
|
| 1950 |
rehash = 0; /* ignore here */ |
| 1951 |
hashn = vt->fullhash % vars->size; |
| 1952 |
ptr = vars->tbl[hashn]; |
| 1953 |
vars->writes++; |
| 1954 |
SEEK_VAR_CCMP( ptr, name, vt->fullhash, vars, rehash ); |
| 1955 |
SEEK_EXPOSED( ptr ); |
| 1956 |
|
| 1957 |
if ( !ptr ) |
| 1958 |
{ |
| 1959 |
newbox( TSD, name, NULL, &vars->tbl[hashn], vt->fullhash ); |
| 1960 |
vars->elements++; |
| 1961 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 1962 |
ptr = vars->tbl[hashn]; |
| 1963 |
} |
| 1964 |
|
| 1965 |
if ( rehash ) |
| 1966 |
{ |
| 1967 |
reorgHashtable( TSD, vars ); |
| 1968 |
rehash = 0; |
| 1969 |
} |
| 1970 |
|
| 1971 |
newbox( TSD, name, NULL, &vt->var_table->tbl[hashv], vt->fullhash ); |
| 1972 |
vt->var_table->elements++; |
| 1973 |
NEW_HASHTABLE_CHECK( vt->var_table, rehash ); |
| 1974 |
vt->var_table->tbl[hashv]->realbox = ptr; |
| 1975 |
/* |
| 1976 |
* exposing is done after create_new_varpool/assignment of current_valid: |
| 1977 |
*/ |
| 1978 |
vt->var_table->tbl[hashv]->realbox->valid = vt->current_valid; |
| 1979 |
if ( rehash ) |
| 1980 |
{ |
| 1981 |
reorgHashtable( TSD, vt->var_table ); |
| 1982 |
} |
| 1983 |
|
| 1984 |
DSTART;DPRINT((TSD,"expose_simple: "));DNAME(TSD,"name",name);DEND; |
| 1985 |
} |
| 1986 |
|
| 1987 |
static void expose_stem( const tsd_t *TSD, var_hashtable *vars, |
| 1988 |
const streng *name ) |
| 1989 |
{ |
| 1990 |
variableptr ptr,tptr; |
| 1991 |
unsigned hashv, hashn; |
| 1992 |
int junk, rehash = 0; |
| 1993 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 1994 |
|
| 1995 |
DPRINTF((TSD,"expose_stem: ?")); |
| 1996 |
hashv = hashfunc(vt, name, 0, &junk, vt->var_table->size ); |
| 1997 |
ptr = vt->var_table->tbl[hashv]; |
| 1998 |
vt->var_table->reads++; |
| 1999 |
SEEK_VAR_CCMP( ptr, name, vt->fullhash, vt->var_table, rehash ); |
| 2000 |
|
| 2001 |
if ( ptr && ptr->realbox ) |
| 2002 |
return; /* once is enough !!! */ |
| 2003 |
|
| 2004 |
rehash = 0; |
| 2005 |
hashn = vt->fullhash % vars->size; |
| 2006 |
tptr = vars->tbl[hashn]; |
| 2007 |
vars->writes++; |
| 2008 |
SEEK_VAR_CCMP( tptr, name, vt->fullhash, vars, rehash ); |
| 2009 |
SEEK_EXPOSED( tptr ); |
| 2010 |
|
| 2011 |
if ( !tptr ) |
| 2012 |
{ |
| 2013 |
newbox( TSD, name, NULL, &vars->tbl[hashn], vt->fullhash ); |
| 2014 |
vars->elements++; |
| 2015 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 2016 |
tptr = vars->tbl[hashn]; |
| 2017 |
tptr->index = make_hash_table( TSD, vt->initialHashTableLength ); |
| 2018 |
DPRINTF((TSD,"make_hash_table: rc=%p",tptr->index)); |
| 2019 |
} |
| 2020 |
if ( rehash ) |
| 2021 |
{ |
| 2022 |
reorgHashtable( TSD, vars ); |
| 2023 |
rehash = 0; |
| 2024 |
} |
| 2025 |
|
| 2026 |
if ( ptr ) |
| 2027 |
{ |
| 2028 |
/* |
| 2029 |
* The stem has been generated by an "expose STEM.x ... " and we now |
| 2030 |
* have the variable "STEM.". The "STEM.x" had produced a new copy of |
| 2031 |
* "STEM." because of the need to access "STEM.x", but now we have to |
| 2032 |
* expose everything of "STEM.". We remove the index with the |
| 2033 |
* realbox-chain of ".x" and make this "STEM." point to the exposed one. |
| 2034 |
*/ |
| 2035 |
remove_foliage( TSD, ptr->index ); |
| 2036 |
ptr->index = NULL; |
| 2037 |
assert( ( ptr->realbox == NULL ) || ( ptr->realbox == tptr ) ); |
| 2038 |
ptr->realbox = tptr; |
| 2039 |
} |
| 2040 |
else |
| 2041 |
{ |
| 2042 |
newbox( TSD, name, NULL, &vt->var_table->tbl[hashv], vt->fullhash ); |
| 2043 |
vt->var_table->elements++; |
| 2044 |
NEW_HASHTABLE_CHECK( vt->var_table, rehash ); |
| 2045 |
vt->var_table->tbl[hashv]->realbox = tptr; /* dont need ->index */ |
| 2046 |
} |
| 2047 |
if ( rehash ) |
| 2048 |
{ |
| 2049 |
reorgHashtable( TSD, vt->var_table ); |
| 2050 |
} |
| 2051 |
} |
| 2052 |
|
| 2053 |
static void expose_compound( tsd_t *TSD, var_hashtable *vars, |
| 2054 |
const streng *name ) |
| 2055 |
{ |
| 2056 |
unsigned hashv, hashn, fh, hashv2, hashn2; |
| 2057 |
int length, rehash = 0; |
| 2058 |
|
| 2059 |
variableptr ptr, nptr, tptr, tiptr; |
| 2060 |
int cptr; |
| 2061 |
streng *indexstr; |
| 2062 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2063 |
|
| 2064 |
DPRINTF((TSD,"expose_compound: ?")); |
| 2065 |
hashv = hashfunc( vt, name, 0, &cptr, vt->var_table->size ); |
| 2066 |
ptr = vt->var_table->tbl[hashv]; |
| 2067 |
length = ++cptr; |
| 2068 |
vt->var_table->reads++; |
| 2069 |
fh = vt->fullhash; |
| 2070 |
SEEK_VAR_CNCMP( ptr, name, fh, vt->var_table, length, rehash ); |
| 2071 |
if ( ptr && ptr->realbox ) |
| 2072 |
return; /* whole array already exposed */ |
| 2073 |
|
| 2074 |
hashn = fh % vars->size; |
| 2075 |
if ( !ptr ) /* array does not exist */ |
| 2076 |
{ |
| 2077 |
make_stem( TSD, name, NULL, &vt->var_table->tbl[hashv], length, fh ); |
| 2078 |
vt->var_table->elements++; |
| 2079 |
NEW_HASHTABLE_CHECK( vt->var_table, rehash ); |
| 2080 |
ptr = vt->var_table->tbl[hashv]; |
| 2081 |
} |
| 2082 |
|
| 2083 |
indexstr = subst_index( TSD, name, cptr, vt->var_table, &rehash ); |
| 2084 |
|
| 2085 |
if ( rehash ) |
| 2086 |
{ |
| 2087 |
reorgHashtable( TSD, vt->var_table ); |
| 2088 |
rehash = 0; |
| 2089 |
} |
| 2090 |
|
| 2091 |
if ( vt->subst ) /* trace it */ |
| 2092 |
tracecompound( TSD, name, cptr - 1, indexstr, 'C'); |
| 2093 |
|
| 2094 |
hashv2 = hashfunc( vt, indexstr, 0, NULL, ptr->index->size ); |
| 2095 |
nptr = ptr->index->tbl[hashv2]; |
| 2096 |
ptr->index->reads++; |
| 2097 |
SEEK_VAR_CMP( nptr, indexstr, vt->fullhash, ptr->index, rehash ); |
| 2098 |
|
| 2099 |
if ( nptr && nptr->realbox ) |
| 2100 |
return; |
| 2101 |
else |
| 2102 |
{ |
| 2103 |
newbox( TSD, indexstr, NULL, &ptr->index->tbl[hashv2], vt->fullhash ); |
| 2104 |
ptr->index->elements++; |
| 2105 |
NEW_HASHTABLE_CHECK( ptr->index, rehash ); |
| 2106 |
nptr = ptr->index->tbl[hashv2]; |
| 2107 |
nptr->stem = ptr; |
| 2108 |
} |
| 2109 |
if ( rehash ) |
| 2110 |
{ |
| 2111 |
reorgHashtable( TSD, ptr->index ); |
| 2112 |
rehash = 0; |
| 2113 |
} |
| 2114 |
|
| 2115 |
tptr = vars->tbl[hashn]; |
| 2116 |
vars->writes++; |
| 2117 |
SEEK_VAR_CNCMP( tptr, name, fh, vars, length, rehash ); |
| 2118 |
SEEK_EXPOSED( tptr ); |
| 2119 |
|
| 2120 |
if ( !tptr ) |
| 2121 |
{ |
| 2122 |
make_stem( TSD, name, NULL, &vars->tbl[hashn], length, fh ); |
| 2123 |
vars->elements++; |
| 2124 |
NEW_HASHTABLE_CHECK( vars, rehash ); |
| 2125 |
tptr = vars->tbl[hashn]; |
| 2126 |
} |
| 2127 |
if ( rehash ) |
| 2128 |
{ |
| 2129 |
reorgHashtable( TSD, vars ); |
| 2130 |
rehash = 0; |
| 2131 |
} |
| 2132 |
|
| 2133 |
hashn2 = vt->fullhash % tptr->index->size; |
| 2134 |
tiptr = tptr->index->tbl[hashn2]; |
| 2135 |
tptr->index->writes++; |
| 2136 |
SEEK_VAR_CMP( tiptr, indexstr, vt->fullhash, tptr->index, rehash ); |
| 2137 |
SEEK_EXPOSED( tiptr ); |
| 2138 |
|
| 2139 |
if ( !tiptr ) |
| 2140 |
{ |
| 2141 |
/* |
| 2142 |
* hopefully no new setting of vt->fullhash has happened during the last |
| 2143 |
* lines. |
| 2144 |
*/ |
| 2145 |
newbox( TSD, indexstr, NULL, &tptr->index->tbl[hashn2], vt->fullhash ); |
| 2146 |
tptr->index->elements++; |
| 2147 |
NEW_HASHTABLE_CHECK( tptr->index, rehash ); |
| 2148 |
tiptr = tptr->index->tbl[hashn2]; |
| 2149 |
tiptr->stem = tptr; |
| 2150 |
} |
| 2151 |
if ( rehash ) |
| 2152 |
{ |
| 2153 |
reorgHashtable( TSD, tptr->index ); |
| 2154 |
} |
| 2155 |
|
| 2156 |
nptr->realbox = tiptr; |
| 2157 |
} |
| 2158 |
|
| 2159 |
static const streng *getvalue_compound( tsd_t *TSD, var_hashtable *vars, |
| 2160 |
const streng *name ) |
| 2161 |
{ |
| 2162 |
int baselength; |
| 2163 |
int rehash = 0; |
| 2164 |
unsigned hashv; |
| 2165 |
variableptr ptr, nptr; |
| 2166 |
streng *value; |
| 2167 |
streng *indexstr; |
| 2168 |
int stop; |
| 2169 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2170 |
|
| 2171 |
DPRINTF((TSD,"getvalue_compound: ?")); |
| 2172 |
hashv = hashfunc( vt, name, 0, &stop, vars->size ); |
| 2173 |
ptr = vars->tbl[hashv]; |
| 2174 |
baselength = ++stop; |
| 2175 |
vars->reads++; |
| 2176 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, baselength, rehash ); |
| 2177 |
SEEK_EXPOSED( ptr ); |
| 2178 |
|
| 2179 |
indexstr = subst_index( TSD, name, stop, vars, &rehash ); |
| 2180 |
|
| 2181 |
if ( rehash ) |
| 2182 |
{ |
| 2183 |
reorgHashtable( TSD, vars ); |
| 2184 |
rehash = 0; |
| 2185 |
} |
| 2186 |
|
| 2187 |
if ( vt->subst && !vt->notrace ) /* trace it */ |
| 2188 |
tracecompound( TSD, name, baselength - 1, indexstr, 'C' ); |
| 2189 |
|
| 2190 |
if ( ptr ) |
| 2191 |
{ |
| 2192 |
hashv = hashfunc( vt, indexstr, 0, NULL, ptr->index->size ); |
| 2193 |
nptr = ptr->index->tbl[hashv]; |
| 2194 |
ptr->index->reads++; |
| 2195 |
SEEK_VAR_CMP( nptr, indexstr, vt->fullhash, ptr->index, rehash ); |
| 2196 |
SEEK_EXPOSED( nptr ); |
| 2197 |
|
| 2198 |
if ( !nptr ) /* find default value */ |
| 2199 |
nptr = ptr; |
| 2200 |
|
| 2201 |
vt->foundflag = nptr->flag & VFLAG_BOTH; |
| 2202 |
expand_to_str( TSD, nptr ); |
| 2203 |
} |
| 2204 |
else |
| 2205 |
{ |
| 2206 |
vt->foundflag = 0; |
| 2207 |
nptr = NULL; |
| 2208 |
} |
| 2209 |
if ( rehash ) |
| 2210 |
{ |
| 2211 |
reorgHashtable( TSD, ptr->index ); |
| 2212 |
} |
| 2213 |
|
| 2214 |
if ( vt->foundflag ) |
| 2215 |
value = nptr->value; |
| 2216 |
else |
| 2217 |
{ |
| 2218 |
if ( !vt->ignore_novalue ) |
| 2219 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( name ), NULL ) ; |
| 2220 |
|
| 2221 |
if ( vt->ovalue ) |
| 2222 |
Free_stringTSD( vt->ovalue ); |
| 2223 |
|
| 2224 |
vt->ovalue = value = Str_makeTSD( stop + 1 + Str_len( indexstr ) ); |
| 2225 |
Str_ncatTSD( value, name, stop ); |
| 2226 |
Str_catTSD( value, indexstr ); |
| 2227 |
} |
| 2228 |
|
| 2229 |
vt->thespot = NULL; |
| 2230 |
return value; |
| 2231 |
} |
| 2232 |
|
| 2233 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 2234 |
/**************************************************************************** |
| 2235 |
* |
| 2236 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 2237 |
* |
| 2238 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 2239 |
* - Adapted from getvalue_compound(). |
| 2240 |
* - Started using the global variable, vt->tmpindex, in place of the local, |
| 2241 |
* indexstr. |
| 2242 |
* - manually move the first stem name into vt->tmpindex, do not call |
| 2243 |
* subst_index(), as that not only uppercases the tail, but also |
| 2244 |
* does not uppercase the tail. |
| 2245 |
* |
| 2246 |
* |
| 2247 |
****************************************************************************/ |
| 2248 |
static const streng *getdirvalue_compound( tsd_t *TSD, var_hashtable *vars, |
| 2249 |
const streng *name ) |
| 2250 |
{ |
| 2251 |
int baselength, rehash = 0; |
| 2252 |
unsigned hashv; |
| 2253 |
variableptr ptr, nptr; |
| 2254 |
streng *value; |
| 2255 |
int stop; |
| 2256 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2257 |
|
| 2258 |
DPRINTF((TSD,"getdirvalue_compound: ?")); |
| 2259 |
/* |
| 2260 |
* Get a good starting point, and find the stem/index separater. |
| 2261 |
*/ |
| 2262 |
hashv = hashfunc( vt, name, 0, &stop, vars->size ); |
| 2263 |
ptr = vars->tbl[hashv]; |
| 2264 |
baselength = ++stop; |
| 2265 |
vars->reads++; |
| 2266 |
/* |
| 2267 |
* Find the stem in the variable pool. |
| 2268 |
*/ |
| 2269 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, baselength, rehash ); |
| 2270 |
SEEK_EXPOSED( ptr ); |
| 2271 |
|
| 2272 |
if ( rehash ) |
| 2273 |
{ |
| 2274 |
reorgHashtable( TSD, vars ); |
| 2275 |
rehash = 0; |
| 2276 |
} |
| 2277 |
|
| 2278 |
vt->tmpindex->len = 0; |
| 2279 |
vt->tmpindex = Str_nocatTSD( vt->tmpindex, name, name->len - stop, stop ); |
| 2280 |
|
| 2281 |
/* |
| 2282 |
* FIXME, FGC: vt->subst from "if" removed, but what shall we do here really? |
| 2283 |
*/ |
| 2284 |
if ( !vt->notrace ) /* trace it */ |
| 2285 |
tracecompound( TSD, name, baselength - 1, vt->tmpindex, 'C' ); |
| 2286 |
|
| 2287 |
if ( ptr ) |
| 2288 |
{ |
| 2289 |
hashv = hashfunc( vt, vt->tmpindex, 0, NULL, ptr->index->size ); |
| 2290 |
nptr = ptr->index->tbl[hashv]; |
| 2291 |
ptr->index->reads++; |
| 2292 |
/* |
| 2293 |
* Find the index in the variable pool. |
| 2294 |
*/ |
| 2295 |
SEEK_VAR_CMP( nptr, vt->tmpindex, vt->fullhash, ptr->index, rehash ); |
| 2296 |
SEEK_EXPOSED( nptr ); |
| 2297 |
|
| 2298 |
/* |
| 2299 |
* If the stem exists, but the index doesn't, this counts as found. |
| 2300 |
*/ |
| 2301 |
if ( !nptr ) /* find default value */ |
| 2302 |
nptr = ptr; |
| 2303 |
|
| 2304 |
vt->foundflag = nptr->flag & VFLAG_BOTH; |
| 2305 |
expand_to_str( TSD, nptr ); |
| 2306 |
} |
| 2307 |
else |
| 2308 |
{ |
| 2309 |
vt->foundflag = 0; |
| 2310 |
nptr = NULL; |
| 2311 |
} |
| 2312 |
if ( rehash ) |
| 2313 |
{ |
| 2314 |
reorgHashtable( TSD, ptr->index ); |
| 2315 |
} |
| 2316 |
|
| 2317 |
|
| 2318 |
if ( vt->foundflag ) |
| 2319 |
value = nptr->value; |
| 2320 |
else |
| 2321 |
{ |
| 2322 |
if ( !vt->ignore_novalue ) |
| 2323 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( name ), NULL ) ; |
| 2324 |
|
| 2325 |
/* |
| 2326 |
* Since this is a direct, we can use the name without change. |
| 2327 |
*/ |
| 2328 |
value = (streng *) name; |
| 2329 |
} |
| 2330 |
|
| 2331 |
vt->thespot = NULL; |
| 2332 |
return value; |
| 2333 |
} |
| 2334 |
|
| 2335 |
/* |
| 2336 |
* getPool returns the variable pool of the specified pool number. The number |
| 2337 |
* may be -1 for "autoselect". *isRes is set to 1 if the name is a reserved |
| 2338 |
* variable, 0 otherwise. |
| 2339 |
*/ |
| 2340 |
static var_hashtable *getPool( const tsd_t *TSD, const streng *name, int pool, |
| 2341 |
int *isRes ) |
| 2342 |
{ |
| 2343 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2344 |
sysinfo s; |
| 2345 |
proclevel p; |
| 2346 |
|
| 2347 |
if ( KNOWN_RESERVED( name->value, Str_len( name ) ) ) |
| 2348 |
{ |
| 2349 |
*isRes = 1; |
| 2350 |
if ( ( pool == 0 ) || ( pool == -1 ) ) |
| 2351 |
return vt->pool0; |
| 2352 |
} |
| 2353 |
else |
| 2354 |
*isRes = 0; |
| 2355 |
|
| 2356 |
if ( pool == 0 ) |
| 2357 |
return vt->pool0; |
| 2358 |
|
| 2359 |
if ( pool == -1 ) |
| 2360 |
return TSD->currlevel->vars; |
| 2361 |
|
| 2362 |
/* |
| 2363 |
* The slow part. We have to find the true pool for the given number. |
| 2364 |
* Each system manages a part of the proclevels. We have to walk back |
| 2365 |
* through the sysinfo chain until we find the containing system and |
| 2366 |
* pick up the desired proclevel afterwards. |
| 2367 |
*/ |
| 2368 |
s = TSD->systeminfo; |
| 2369 |
while ( s->currlevel0->pool > pool ) |
| 2370 |
{ |
| 2371 |
s = s->previous; |
| 2372 |
assert( s != NULL ); |
| 2373 |
} |
| 2374 |
|
| 2375 |
if ( s == TSD->systeminfo ) |
| 2376 |
{ |
| 2377 |
/* |
| 2378 |
* We can use the previous-chain which may be faster. |
| 2379 |
*/ |
| 2380 |
if ( pool > ( TSD->currlevel->pool - s->currlevel0->pool ) / 2 |
| 2381 |
+ s->currlevel0->pool ) |
| 2382 |
{ |
| 2383 |
p = TSD->currlevel; |
| 2384 |
while ( p->pool != pool ) |
| 2385 |
{ |
| 2386 |
p = p->prev; |
| 2387 |
assert( p != NULL ); |
| 2388 |
} |
| 2389 |
return p->vars; |
| 2390 |
} |
| 2391 |
} |
| 2392 |
|
| 2393 |
p = s->currlevel0; |
| 2394 |
while ( p->pool != pool ) |
| 2395 |
{ |
| 2396 |
p = p->next; |
| 2397 |
assert( p != NULL ); |
| 2398 |
} |
| 2399 |
return p->vars; |
| 2400 |
} |
| 2401 |
|
| 2402 |
/* |
| 2403 |
* This is the entry-level routine that will take the parameters, |
| 2404 |
* decide what kind of variable it is (simple, stem or compound) and |
| 2405 |
* call the appropriate routine to do the dirty work. |
| 2406 |
* pool is -1 (select the appropriate one) or a pool number. |
| 2407 |
*/ |
| 2408 |
void setvalue( tsd_t *TSD, const streng *name, streng *value, int pool ) |
| 2409 |
{ |
| 2410 |
int i, isRes, len=Str_len( name ); |
| 2411 |
var_hashtable *vars; |
| 2412 |
|
| 2413 |
assert( value->len <= value->max ); |
| 2414 |
|
| 2415 |
vars = getPool( TSD, name, pool, &isRes ); |
| 2416 |
|
| 2417 |
if ( isRes ) |
| 2418 |
setvalue_simple( TSD, vars, name, value ); |
| 2419 |
else |
| 2420 |
{ |
| 2421 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2422 |
; |
| 2423 |
|
| 2424 |
if ( i == len ) |
| 2425 |
setvalue_simple( TSD, vars, name, value ); |
| 2426 |
else if ( i + 1 == len ) |
| 2427 |
setvalue_stem( TSD, vars, name, value ); |
| 2428 |
else |
| 2429 |
setvalue_compound( TSD, vars, name, value ); |
| 2430 |
} |
| 2431 |
} |
| 2432 |
|
| 2433 |
/* |
| 2434 |
* This is the entry-level routine used by the Variable Pool Interface |
| 2435 |
* to set stem variables directly. (no translation on the index name.) |
| 2436 |
* As setvalue() does, it will take the parameters, |
| 2437 |
* decide what kind of variable it is (simple, stem or compound) and |
| 2438 |
* call the appropriate routine to do the dirty work |
| 2439 |
*/ |
| 2440 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 2441 |
/**************************************************************************** |
| 2442 |
* |
| 2443 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 2444 |
* |
| 2445 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 2446 |
* - Adapted from setvalue(). |
| 2447 |
* - changed call from setvalue_compound() to setdirvalue_compound(). |
| 2448 |
* |
| 2449 |
* |
| 2450 |
****************************************************************************/ |
| 2451 |
void setdirvalue( tsd_t *TSD, const streng *name, streng *value ) |
| 2452 |
{ |
| 2453 |
var_tsd_t *vt; |
| 2454 |
int i, len=Str_len( name ); |
| 2455 |
var_hashtable *vars; |
| 2456 |
|
| 2457 |
assert( value->len <= value->max ); |
| 2458 |
|
| 2459 |
if ( KNOWN_RESERVED( name->value, len ) ) |
| 2460 |
{ |
| 2461 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 2462 |
setvalue_simple( TSD, vt->pool0, name, value ); |
| 2463 |
} |
| 2464 |
else |
| 2465 |
{ |
| 2466 |
vars = TSD->currlevel->vars; |
| 2467 |
|
| 2468 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2469 |
; |
| 2470 |
|
| 2471 |
if ( i == len ) |
| 2472 |
setvalue_simple( TSD, vars, name, value ); |
| 2473 |
else if ( i + 1 == len ) |
| 2474 |
setvalue_stem( TSD, vars, name, value ); |
| 2475 |
else |
| 2476 |
setdirvalue_compound( TSD, vars, name, value ); |
| 2477 |
} |
| 2478 |
} |
| 2479 |
|
| 2480 |
void expose_var( tsd_t *TSD, const streng *name ) |
| 2481 |
{ |
| 2482 |
int i, len; |
| 2483 |
var_hashtable *vars; |
| 2484 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2485 |
|
| 2486 |
if ( !vt->var_table ) |
| 2487 |
{ |
| 2488 |
/* |
| 2489 |
* First call to expose_var of X_PROC in interpret(). |
| 2490 |
* Open a new table. |
| 2491 |
*/ |
| 2492 |
vt->var_table = create_new_varpool( TSD, 0 ); |
| 2493 |
} |
| 2494 |
|
| 2495 |
if ( !name ) |
| 2496 |
{ |
| 2497 |
/* |
| 2498 |
* Last call to expose_var of X_PROC in interpret(). |
| 2499 |
* Use the new table as the current table. |
| 2500 |
*/ |
| 2501 |
TSD->currlevel->vars = vt->var_table; |
| 2502 |
TSD->currlevel->varflag = 1; |
| 2503 |
vt->var_table = NULL; |
| 2504 |
return; |
| 2505 |
} |
| 2506 |
|
| 2507 |
len = Str_len( name ); |
| 2508 |
if ( KNOWN_RESERVED( name->value, len ) ) |
| 2509 |
expose_simple( TSD, vt->pool0, name ); |
| 2510 |
else |
| 2511 |
{ |
| 2512 |
vars = TSD->currlevel->vars; |
| 2513 |
|
| 2514 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2515 |
; |
| 2516 |
|
| 2517 |
if ( i == len ) |
| 2518 |
expose_simple( TSD, vars, name ); |
| 2519 |
else if ( i + 1 == len ) |
| 2520 |
expose_stem( TSD, vars, name ); |
| 2521 |
else |
| 2522 |
expose_compound( TSD, vars, name ); |
| 2523 |
} |
| 2524 |
} |
| 2525 |
|
| 2526 |
const streng *getvalue( tsd_t *TSD, const streng *name, int pool ) |
| 2527 |
{ |
| 2528 |
int i, isRes, len=Str_len( name ); |
| 2529 |
var_hashtable *vars; |
| 2530 |
|
| 2531 |
vars = getPool( TSD, name, pool, &isRes ); |
| 2532 |
|
| 2533 |
if ( isRes ) |
| 2534 |
return getvalue_simple( TSD, vars, name ); |
| 2535 |
|
| 2536 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2537 |
; |
| 2538 |
|
| 2539 |
/* |
| 2540 |
* getvalue_stem is equivalent to getvalue_simple |
| 2541 |
*/ |
| 2542 |
if ( i == 0 || i >= len - 1 ) |
| 2543 |
return getvalue_simple( TSD, vars, name ); |
| 2544 |
|
| 2545 |
return getvalue_compound( TSD, vars, name ); |
| 2546 |
} |
| 2547 |
|
| 2548 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 2549 |
/**************************************************************************** |
| 2550 |
* |
| 2551 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 2552 |
* |
| 2553 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 2554 |
* - Adapted from getvalue(). |
| 2555 |
* - changed call from getvalue_compound() to getdirvalue_compound(). |
| 2556 |
* |
| 2557 |
* |
| 2558 |
****************************************************************************/ |
| 2559 |
const streng *getdirvalue( tsd_t *TSD, const streng *name ) |
| 2560 |
{ |
| 2561 |
var_tsd_t *vt; |
| 2562 |
int i, len=Str_len( name ); |
| 2563 |
var_hashtable *vars; |
| 2564 |
|
| 2565 |
if ( ( i = KNOWN_RESERVED( name->value, len ) ) != 0 ) |
| 2566 |
{ |
| 2567 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 2568 |
return getvalue_simple( TSD, vt->pool0, name ); |
| 2569 |
} |
| 2570 |
|
| 2571 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2572 |
; |
| 2573 |
|
| 2574 |
vars = TSD->currlevel->vars; |
| 2575 |
|
| 2576 |
if ( i >= len - 1 ) |
| 2577 |
return getvalue_simple( TSD, vars, name ); |
| 2578 |
|
| 2579 |
return getdirvalue_compound( TSD, vars, name ); |
| 2580 |
} |
| 2581 |
|
| 2582 |
static void drop_var_simple( const tsd_t *TSD, var_hashtable *vars, |
| 2583 |
const streng *name ) |
| 2584 |
{ |
| 2585 |
variableptr ptr; |
| 2586 |
int rehash = 0; |
| 2587 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2588 |
|
| 2589 |
vars->writes++; |
| 2590 |
ptr = findsimple( TSD, vars, name, &rehash ); |
| 2591 |
DSTART;DPRINT((TSD,"drop_var_simple: "));DNAME(TSD,"name",name);DVAR(TSD,", var",ptr); |
| 2592 |
DEND; |
| 2593 |
|
| 2594 |
vt->foundflag = 0; |
| 2595 |
if ( ptr ) |
| 2596 |
{ |
| 2597 |
vt->foundflag = ptr->flag & VFLAG_BOTH; |
| 2598 |
ptr->flag = VFLAG_NONE; |
| 2599 |
if ( ptr->value ) |
| 2600 |
{ |
| 2601 |
Free_stringTSD( ptr->value ); |
| 2602 |
ptr->value = NULL; |
| 2603 |
} |
| 2604 |
if ( ptr->num ) |
| 2605 |
{ |
| 2606 |
FreeTSD( ptr->num->num ); |
| 2607 |
FreeTSD( ptr->num ); |
| 2608 |
ptr->num = NULL; |
| 2609 |
} |
| 2610 |
} |
| 2611 |
if ( rehash ) |
| 2612 |
{ |
| 2613 |
reorgHashtable( TSD, vars ); |
| 2614 |
} |
| 2615 |
} |
| 2616 |
|
| 2617 |
static void drop_var_stem( const tsd_t *TSD, var_hashtable *vars, |
| 2618 |
const streng *name ) |
| 2619 |
{ |
| 2620 |
variableptr ptr; |
| 2621 |
int rehash = 0; |
| 2622 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2623 |
|
| 2624 |
DPRINTF((TSD,"drop_var_stem: ?")); |
| 2625 |
vars->writes++; |
| 2626 |
ptr = findsimple( TSD, vars, name, &rehash ); |
| 2627 |
|
| 2628 |
vt->foundflag = 0; |
| 2629 |
if ( ptr ) |
| 2630 |
{ |
| 2631 |
vt->foundflag = ptr->flag & VFLAG_BOTH; |
| 2632 |
ptr->flag = VFLAG_NONE; |
| 2633 |
if ( ptr->value ) |
| 2634 |
{ |
| 2635 |
Free_stringTSD( ptr->value ); |
| 2636 |
ptr->value = NULL; |
| 2637 |
} |
| 2638 |
if ( ptr->num ) |
| 2639 |
{ |
| 2640 |
FreeTSD( ptr->num->num ); |
| 2641 |
FreeTSD( ptr->num ); |
| 2642 |
ptr->num = NULL; |
| 2643 |
} |
| 2644 |
|
| 2645 |
assert( ptr->index ); |
| 2646 |
if ( ptr->index ) |
| 2647 |
assign_foliage( TSD, ptr->index, NULL ); |
| 2648 |
} |
| 2649 |
if ( rehash ) |
| 2650 |
{ |
| 2651 |
reorgHashtable( TSD, vars ); |
| 2652 |
} |
| 2653 |
} |
| 2654 |
|
| 2655 |
static void drop_var_compound( tsd_t *TSD, var_hashtable *vars, |
| 2656 |
const streng *name ) |
| 2657 |
{ |
| 2658 |
int baselength; |
| 2659 |
unsigned hashv; |
| 2660 |
variableptr ptr, nptr=NULL; |
| 2661 |
streng *indexstr; |
| 2662 |
int stop, rehash = 0; |
| 2663 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2664 |
|
| 2665 |
DPRINTF((TSD,"drop_var_compound: ?")); |
| 2666 |
hashv = hashfunc( vt, name, 0, &stop, vars->size ); |
| 2667 |
ptr = vars->tbl[hashv]; |
| 2668 |
baselength = ++stop; |
| 2669 |
vars->reads++; |
| 2670 |
|
| 2671 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, baselength, rehash ); |
| 2672 |
SEEK_EXPOSED( ptr ); |
| 2673 |
|
| 2674 |
indexstr = subst_index( TSD, name, stop, vars, &rehash ); |
| 2675 |
|
| 2676 |
if ( rehash ) |
| 2677 |
{ |
| 2678 |
reorgHashtable( TSD, vars ); |
| 2679 |
rehash = 0; |
| 2680 |
} |
| 2681 |
|
| 2682 |
if ( vt->subst && !vt->notrace ) /* trace it */ |
| 2683 |
tracecompound( TSD, name, baselength - 1, indexstr, 'C' ); |
| 2684 |
|
| 2685 |
if ( ptr ) |
| 2686 |
{ |
| 2687 |
hashv = hashfunc( vt, indexstr, 0, NULL, ptr->index->size ); |
| 2688 |
nptr = ptr->index->tbl[hashv]; |
| 2689 |
ptr->index->writes++; |
| 2690 |
SEEK_VAR_CMP( nptr, indexstr, vt->fullhash, ptr->index, rehash ); |
| 2691 |
SEEK_EXPOSED( nptr ); |
| 2692 |
|
| 2693 |
if ( rehash ) |
| 2694 |
{ |
| 2695 |
reorgHashtable( TSD, ptr->index ); |
| 2696 |
} |
| 2697 |
} |
| 2698 |
|
| 2699 |
vt->foundflag = nptr && ( nptr->flag & VFLAG_BOTH ); |
| 2700 |
|
| 2701 |
if ( nptr ) |
| 2702 |
{ |
| 2703 |
nptr->flag = VFLAG_NONE; |
| 2704 |
if ( nptr->value ) |
| 2705 |
{ |
| 2706 |
FreeTSD( nptr->value ); |
| 2707 |
nptr->value = NULL; |
| 2708 |
} |
| 2709 |
if ( nptr->num ) |
| 2710 |
{ |
| 2711 |
FreeTSD( nptr->num->num ); |
| 2712 |
FreeTSD( nptr->num ); |
| 2713 |
nptr->num = NULL; |
| 2714 |
} |
| 2715 |
} |
| 2716 |
else |
| 2717 |
{ |
| 2718 |
/* |
| 2719 |
* We are playing with the NULL-ptr ... take care ! |
| 2720 |
*/ |
| 2721 |
if ( ptr ) |
| 2722 |
setvalue_compound( TSD, vars, name, NULL ); |
| 2723 |
} |
| 2724 |
} |
| 2725 |
|
| 2726 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 2727 |
/**************************************************************************** |
| 2728 |
* |
| 2729 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 2730 |
* |
| 2731 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 2732 |
* - Adapted from drop_var_compound(). |
| 2733 |
* - Started using the global variable, vt->tmpindex, in place of the local, |
| 2734 |
* indexstr. |
| 2735 |
* - manually move the first stem name into vt->tmpindex, do not call |
| 2736 |
* subst_index(), as that not only uppercases the tail, but also |
| 2737 |
* does not uppercase the tail. |
| 2738 |
* - changed call from setvalue_compound() to setdirvalue_compound(). |
| 2739 |
* |
| 2740 |
* |
| 2741 |
****************************************************************************/ |
| 2742 |
static void drop_dirvar_compound( tsd_t *TSD, var_hashtable *vars, |
| 2743 |
const streng *name ) |
| 2744 |
{ |
| 2745 |
int baselength; |
| 2746 |
unsigned hashv; |
| 2747 |
variableptr ptr, nptr=NULL; |
| 2748 |
int stop, rehash = 0; |
| 2749 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2750 |
|
| 2751 |
DPRINTF((TSD,"drop_dirvar_compound: ?")); |
| 2752 |
hashv = hashfunc( vt, name, 0, &stop, vars->size ); |
| 2753 |
ptr = vars->tbl[hashv]; |
| 2754 |
baselength = ++stop; |
| 2755 |
vars->reads++; |
| 2756 |
|
| 2757 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, baselength, rehash ); |
| 2758 |
SEEK_EXPOSED( ptr ); |
| 2759 |
|
| 2760 |
vt->tmpindex->len = 0; |
| 2761 |
vt->tmpindex = Str_nocatTSD( vt->tmpindex, name, name->len - stop, stop ); |
| 2762 |
|
| 2763 |
if ( rehash ) |
| 2764 |
{ |
| 2765 |
reorgHashtable( TSD, vars ); |
| 2766 |
rehash = 0; |
| 2767 |
} |
| 2768 |
|
| 2769 |
/* |
| 2770 |
* FIXME, FGC: vt->subst isn't set anywhere. |
| 2771 |
*/ |
| 2772 |
if ( vt->subst && !vt->notrace ) /* trace it */ |
| 2773 |
tracecompound( TSD, name, baselength - 1, vt->tmpindex, 'C' ); |
| 2774 |
|
| 2775 |
if ( ptr ) |
| 2776 |
{ |
| 2777 |
hashv = hashfunc( vt, vt->tmpindex, 0, NULL, ptr->index->size ); |
| 2778 |
nptr = ptr->index->tbl[hashv]; |
| 2779 |
ptr->index->writes++; |
| 2780 |
SEEK_VAR_CMP( nptr, vt->tmpindex, vt->fullhash, ptr->index, rehash ); |
| 2781 |
SEEK_EXPOSED( nptr ); |
| 2782 |
|
| 2783 |
if ( rehash ) |
| 2784 |
{ |
| 2785 |
reorgHashtable( TSD, ptr->index ); |
| 2786 |
} |
| 2787 |
} |
| 2788 |
|
| 2789 |
vt->foundflag = nptr && ( nptr->flag & VFLAG_BOTH ); |
| 2790 |
|
| 2791 |
if ( nptr ) |
| 2792 |
{ |
| 2793 |
nptr->flag = VFLAG_NONE; |
| 2794 |
if ( nptr->value ) |
| 2795 |
{ |
| 2796 |
FreeTSD( nptr->value ); |
| 2797 |
nptr->value = NULL; |
| 2798 |
} |
| 2799 |
if ( nptr->num ) |
| 2800 |
{ |
| 2801 |
FreeTSD( nptr->num->num ); |
| 2802 |
FreeTSD( nptr->num ); |
| 2803 |
nptr->num = NULL; |
| 2804 |
} |
| 2805 |
} |
| 2806 |
else |
| 2807 |
{ |
| 2808 |
/* |
| 2809 |
* We are playing with the NULL-ptr ... take care ! |
| 2810 |
*/ |
| 2811 |
if ( ptr ) |
| 2812 |
setdirvalue_compound( TSD, vars, name, NULL ); |
| 2813 |
} |
| 2814 |
} |
| 2815 |
|
| 2816 |
void drop_var( tsd_t *TSD, const streng *name ) |
| 2817 |
{ |
| 2818 |
var_tsd_t *vt; |
| 2819 |
int i, len=Str_len( name ); |
| 2820 |
var_hashtable *vars; |
| 2821 |
|
| 2822 |
if ( ( i = KNOWN_RESERVED( name->value, len ) ) != 0 ) |
| 2823 |
{ |
| 2824 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 2825 |
drop_var_simple( TSD, vt->pool0, name ); |
| 2826 |
} |
| 2827 |
else |
| 2828 |
{ |
| 2829 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2830 |
; |
| 2831 |
|
| 2832 |
vars = TSD->currlevel->vars; |
| 2833 |
|
| 2834 |
if ( i == len ) |
| 2835 |
drop_var_simple( TSD, vars, name ); |
| 2836 |
else if ( i + 1 == len ) |
| 2837 |
drop_var_stem( TSD, vars, name ); |
| 2838 |
else |
| 2839 |
drop_var_compound( TSD, vars, name ); |
| 2840 |
} |
| 2841 |
} |
| 2842 |
|
| 2843 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 2844 |
/**************************************************************************** |
| 2845 |
* |
| 2846 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 2847 |
* |
| 2848 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 2849 |
* - Adapted from drop_var(). Changed call drop_var_compound() to |
| 2850 |
* drop_dirvar_compound(). *** May need to do the same for drop_var_stem(). **** |
| 2851 |
* |
| 2852 |
****************************************************************************/ |
| 2853 |
void drop_dirvar( tsd_t *TSD, const streng *name ) |
| 2854 |
{ |
| 2855 |
var_tsd_t *vt; |
| 2856 |
int i, len=Str_len( name ); |
| 2857 |
var_hashtable *vars; |
| 2858 |
|
| 2859 |
if ( ( i = KNOWN_RESERVED( name->value, len ) ) != 0 ) |
| 2860 |
{ |
| 2861 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 2862 |
drop_var_simple( TSD, vt->pool0, name ); |
| 2863 |
} |
| 2864 |
else |
| 2865 |
{ |
| 2866 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 2867 |
; |
| 2868 |
|
| 2869 |
vars = TSD->currlevel->vars; |
| 2870 |
|
| 2871 |
if ( i == len ) |
| 2872 |
drop_var_simple( TSD, vars, name ); |
| 2873 |
else if ( i + 1 == len ) |
| 2874 |
drop_var_stem( TSD, vars, name ); |
| 2875 |
else |
| 2876 |
drop_dirvar_compound( TSD, vars, name ); |
| 2877 |
} |
| 2878 |
} |
| 2879 |
|
| 2880 |
static void upper_var_simple( tsd_t *TSD, var_hashtable *vars, |
| 2881 |
const streng *name ) |
| 2882 |
{ |
| 2883 |
variableptr ptr; |
| 2884 |
streng *value=NULL; |
| 2885 |
int rehash = 0; |
| 2886 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2887 |
|
| 2888 |
vars->writes++; |
| 2889 |
ptr = findsimple( TSD, vars, name, &rehash ); |
| 2890 |
if ( rehash ) |
| 2891 |
{ |
| 2892 |
reorgHashtable( TSD, vars ); |
| 2893 |
} |
| 2894 |
|
| 2895 |
vt->foundflag = ptr && (ptr->flag & VFLAG_BOTH ); |
| 2896 |
|
| 2897 |
if ( ptr ) |
| 2898 |
{ |
| 2899 |
expand_to_str( TSD, ptr ); |
| 2900 |
} |
| 2901 |
|
| 2902 |
if ( vt->foundflag ) |
| 2903 |
{ |
| 2904 |
value = ptr->value; |
| 2905 |
Str_upper( value ); |
| 2906 |
if ( !vt->notrace ) |
| 2907 |
tracevalue( TSD, value, 'V' ); |
| 2908 |
} |
| 2909 |
else |
| 2910 |
{ |
| 2911 |
vt->thespot = NULL; |
| 2912 |
if ( !vt->notrace ) |
| 2913 |
tracevalue( TSD, name, 'L' ); |
| 2914 |
if ( !vt->ignore_novalue ) |
| 2915 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( name ), NULL ) ; |
| 2916 |
} |
| 2917 |
|
| 2918 |
DSTART;DPRINT((TSD,"upper_var_simple: "));DNAME(TSD,"name",name); |
| 2919 |
DVALUE(TSD," rc",value);DEND; |
| 2920 |
} |
| 2921 |
|
| 2922 |
static void upper_var_compound( tsd_t *TSD, var_hashtable *vars, |
| 2923 |
const streng *name ) |
| 2924 |
{ |
| 2925 |
int baselength, rehash = 0; |
| 2926 |
unsigned hashv; |
| 2927 |
variableptr ptr, nptr; |
| 2928 |
streng *indexstr; |
| 2929 |
streng *value; |
| 2930 |
int stop; |
| 2931 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 2932 |
|
| 2933 |
DPRINTF((TSD,"upper_var_compound: ?")); |
| 2934 |
|
| 2935 |
hashv = hashfunc( vt, name, 0, &stop, vars->size ); |
| 2936 |
ptr = vars->tbl[hashv]; |
| 2937 |
baselength = ++stop; |
| 2938 |
vars->reads++; |
| 2939 |
SEEK_VAR_CNCMP( ptr, name, vt->fullhash, vars, baselength, rehash ); |
| 2940 |
SEEK_EXPOSED( ptr); |
| 2941 |
|
| 2942 |
indexstr = subst_index( TSD, name, stop, vars, &rehash ); |
| 2943 |
|
| 2944 |
if ( rehash ) |
| 2945 |
{ |
| 2946 |
reorgHashtable( TSD, vars ); |
| 2947 |
rehash = 0; |
| 2948 |
} |
| 2949 |
|
| 2950 |
if ( vt->subst && !vt->notrace ) /* trace it */ |
| 2951 |
tracecompound( TSD, name, baselength - 1, indexstr, 'C' ); |
| 2952 |
|
| 2953 |
if ( ptr ) |
| 2954 |
{ |
| 2955 |
hashv = hashfunc( vt, indexstr, 0, NULL, ptr->index->size ); |
| 2956 |
nptr = ptr->index->tbl[hashv]; |
| 2957 |
ptr->index->writes++; |
| 2958 |
SEEK_VAR_CMP( nptr, indexstr, vt->fullhash, ptr->index, rehash ); |
| 2959 |
SEEK_EXPOSED( nptr ); |
| 2960 |
|
| 2961 |
if ( rehash ) |
| 2962 |
{ |
| 2963 |
reorgHashtable( TSD, ptr->index ); |
| 2964 |
} |
| 2965 |
} |
| 2966 |
else |
| 2967 |
nptr = NULL; |
| 2968 |
|
| 2969 |
vt->foundflag = nptr && ( nptr->flag & VFLAG_BOTH ); |
| 2970 |
if ( nptr ) |
| 2971 |
{ |
| 2972 |
expand_to_str( TSD, nptr ); |
| 2973 |
} |
| 2974 |
if ( vt->foundflag ) |
| 2975 |
{ |
| 2976 |
value = nptr->value; |
| 2977 |
Str_upper( value ); |
| 2978 |
if ( !vt->notrace ) |
| 2979 |
tracevalue( TSD, value, 'V' ); |
| 2980 |
} |
| 2981 |
else |
| 2982 |
{ |
| 2983 |
if ( !vt->notrace ) |
| 2984 |
tracevalue( TSD, name, 'L' ); |
| 2985 |
if ( !vt->ignore_novalue ) |
| 2986 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( name ), NULL ) ; |
| 2987 |
} |
| 2988 |
|
| 2989 |
vt->thespot = NULL; |
| 2990 |
} |
| 2991 |
|
| 2992 |
void upper_var( tsd_t *TSD, const streng *name ) |
| 2993 |
{ |
| 2994 |
var_tsd_t *vt; |
| 2995 |
int i, len=Str_len( name ); |
| 2996 |
var_hashtable *vars; |
| 2997 |
|
| 2998 |
if ( ( i = KNOWN_RESERVED( name->value, len ) ) != 0 ) |
| 2999 |
{ |
| 3000 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3001 |
upper_var_simple( TSD, vt->pool0, name ); |
| 3002 |
} |
| 3003 |
else |
| 3004 |
{ |
| 3005 |
for ( i = 0; ( i < len ) && ( name->value[i] != '.' ); i++ ) |
| 3006 |
; |
| 3007 |
|
| 3008 |
vars = TSD->currlevel->vars; |
| 3009 |
|
| 3010 |
if ( i == len ) |
| 3011 |
upper_var_simple( TSD, vars, name ); |
| 3012 |
else if ( i + 1 == len ) |
| 3013 |
exiterror( ERR_INVALID_STEM, 0 ); |
| 3014 |
else |
| 3015 |
{ |
| 3016 |
set_ignore_novalue( TSD ); |
| 3017 |
upper_var_compound( TSD, vars, name ); |
| 3018 |
clear_ignore_novalue( TSD ); |
| 3019 |
} |
| 3020 |
} |
| 3021 |
} |
| 3022 |
|
| 3023 |
void kill_variables( const tsd_t *TSD, var_hashtable *array ) |
| 3024 |
{ |
| 3025 |
var_tsd_t *vt; |
| 3026 |
|
| 3027 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3028 |
DPRINTF((TSD,"kill_variables: current_valid:old=%ld, new=%ld", |
| 3029 |
vt->current_valid,(long) array->tbl[array->size])); |
| 3030 |
|
| 3031 |
vt->current_valid = (long) array->tbl[array->size]; |
| 3032 |
|
| 3033 |
remove_foliage( TSD, array ); |
| 3034 |
|
| 3035 |
if ( vt->current_valid == 1 ) |
| 3036 |
vt->next_current_valid = 2; |
| 3037 |
assert( vt->current_valid ); |
| 3038 |
} |
| 3039 |
|
| 3040 |
/* |
| 3041 |
* This is the shortcut method for retrieving the value of a variable. |
| 3042 |
* It requires you to have a nodeptr, which may contain a shortcut |
| 3043 |
* pointer into the variable pool. Unless, such a shortcut pointer is |
| 3044 |
* established, if possible. |
| 3045 |
* Note: This is one of the most time-consuming routines. Be careful. |
| 3046 |
*/ |
| 3047 |
const streng *shortcut( tsd_t *TSD, nodeptr thisptr ) |
| 3048 |
{ |
| 3049 |
const streng *result; |
| 3050 |
char ch; |
| 3051 |
variableptr vptr; |
| 3052 |
var_tsd_t *vt; |
| 3053 |
|
| 3054 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3055 |
|
| 3056 |
DSTART;DPRINT((TSD,"shortcut: "));DNAME(TSD,"thisptr->name",thisptr->name);DEND; |
| 3057 |
if ( ( vptr = thisptr->u.varbx ) != NULL ) |
| 3058 |
{ |
| 3059 |
if ( vptr->valid == vt->current_valid ) |
| 3060 |
{ |
| 3061 |
DSTART;DPRINT((TSD,"shortcut: "));DVAR(TSD,"valid vptr",vptr); |
| 3062 |
DPRINT((TSD," on start"));DEND; |
| 3063 |
ch = 'V'; |
| 3064 |
SEEK_EXPOSED( vptr ); |
| 3065 |
if ( vptr->flag & VFLAG_STR ) |
| 3066 |
result = vptr->value; |
| 3067 |
else if ( vptr->flag & VFLAG_NUM ) |
| 3068 |
{ |
| 3069 |
expand_to_str( TSD, vptr ); |
| 3070 |
result = vptr->value; |
| 3071 |
} |
| 3072 |
else |
| 3073 |
{ |
| 3074 |
ch = 'L'; |
| 3075 |
result = vptr->name; |
| 3076 |
if ( !vt->ignore_novalue ) |
| 3077 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( result ), NULL ); |
| 3078 |
} |
| 3079 |
DSTART;DPRINT((TSD,"shortcut: "));DVAR(TSD,"valid vptr",vptr); |
| 3080 |
DPRINT((TSD," on end"));DEND; |
| 3081 |
|
| 3082 |
if ( TSD->trace_stat == 'I' ) |
| 3083 |
tracevalue( TSD, result, ch ); |
| 3084 |
|
| 3085 |
assert( !result || result->len <= result->max ); |
| 3086 |
DSTART;DPRINT((TSD,"shortcut: "));DVALUE(TSD,"rc",result);DEND; |
| 3087 |
return result; |
| 3088 |
} |
| 3089 |
else |
| 3090 |
{ |
| 3091 |
DSTART;DPRINT((TSD,"shortcut: "));DVAR(TSD,"INVALID vptr",vptr); |
| 3092 |
DPRINT((TSD," on start"));DEND; |
| 3093 |
if ( --vptr->hwired == 0 ) |
| 3094 |
if ( !vptr->valid ) |
| 3095 |
{ |
| 3096 |
#ifdef TRACEMEM |
| 3097 |
if ( vptr->prev ) |
| 3098 |
vptr->prev->next = vptr->next; |
| 3099 |
if ( vptr->next ) |
| 3100 |
vptr->next->prev = vptr->prev; |
| 3101 |
else |
| 3102 |
vt->first_invalid = vptr->prev; |
| 3103 |
#endif |
| 3104 |
/* |
| 3105 |
* See comment on REMOVE_ELEMENT why we just remove the body |
| 3106 |
*/ |
| 3107 |
FreeTSD( vptr ); |
| 3108 |
} |
| 3109 |
thisptr->u.varbx = NULL; |
| 3110 |
} |
| 3111 |
} |
| 3112 |
|
| 3113 |
result = getvalue( TSD, thisptr->name, -1 ); /* changes the pool */ |
| 3114 |
if ( vt->thespot ) |
| 3115 |
{ |
| 3116 |
vt->thespot->hwired++; |
| 3117 |
thisptr->u.varbx = vt->thespot; |
| 3118 |
} |
| 3119 |
|
| 3120 |
DSTART;DPRINT((TSD,"shortcut: "));DVAR(TSD,"new vt->thespot",vt->thespot);DEND; |
| 3121 |
DSTART;DPRINT((TSD,"shortcut: "));DVALUE(TSD,"rc",result);DEND; |
| 3122 |
assert( !result || result->len <= result->max ); |
| 3123 |
return result; |
| 3124 |
} |
| 3125 |
|
| 3126 |
num_descr *shortcutnum( tsd_t *TSD, nodeptr thisptr ) |
| 3127 |
{ |
| 3128 |
variableptr vptr; |
| 3129 |
num_descr *result; |
| 3130 |
const streng *resstr; |
| 3131 |
var_tsd_t *vt; |
| 3132 |
|
| 3133 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3134 |
|
| 3135 |
DSTART;DPRINT((TSD,"shortcutnum: "));DNAME(TSD,"thisptr->name",thisptr->name);DEND; |
| 3136 |
if ( ( vptr = thisptr->u.varbx ) != NULL ) |
| 3137 |
{ |
| 3138 |
if ( vptr->valid == vt->current_valid ) |
| 3139 |
{ |
| 3140 |
DSTART;DPRINT((TSD,"shortcutnum: "));DVAR(TSD,"valid vptr",vptr); |
| 3141 |
DPRINT((TSD," on start"));DEND; |
| 3142 |
SEEK_EXPOSED( vptr ); |
| 3143 |
if ( vptr->flag & VFLAG_NUM ) |
| 3144 |
{ |
| 3145 |
result = vptr->num; |
| 3146 |
if ( TSD->trace_stat == 'I' ) |
| 3147 |
tracenumber( TSD, result, 'V' ); |
| 3148 |
} |
| 3149 |
else if ( vptr->flag & VFLAG_STR ) |
| 3150 |
{ |
| 3151 |
if ( vptr->num ) |
| 3152 |
{ |
| 3153 |
FreeTSD( vptr->num->num ); |
| 3154 |
FreeTSD( vptr->num ); |
| 3155 |
} |
| 3156 |
if ( TSD->trace_stat == 'I' ) |
| 3157 |
tracevalue( TSD, vptr->value, 'V' ); |
| 3158 |
vptr->num = is_a_descr( TSD, vptr->value ); |
| 3159 |
if ( vptr->num ) |
| 3160 |
vptr->flag |= VFLAG_NUM; |
| 3161 |
result = vptr->num; |
| 3162 |
} |
| 3163 |
else |
| 3164 |
{ |
| 3165 |
result = NULL; |
| 3166 |
if ( TSD->trace_stat == 'I' ) |
| 3167 |
tracevalue( TSD, thisptr->name, 'L' ); |
| 3168 |
if ( !vt->ignore_novalue ) |
| 3169 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( thisptr->name ), NULL ); |
| 3170 |
} |
| 3171 |
DSTART;DPRINT((TSD,"shortcutnum: "));DVAR(TSD,"valid vptr",vptr); |
| 3172 |
DPRINT((TSD," on end"));DEND; |
| 3173 |
DSTART;DPRINT((TSD,"shortcutnum: "));DNUM(TSD,"rc",result);DEND; |
| 3174 |
return result; |
| 3175 |
} |
| 3176 |
else |
| 3177 |
{ |
| 3178 |
DSTART;DPRINT((TSD,"shortcutnum: "));DVAR(TSD,"INVALID vptr",vptr); |
| 3179 |
DPRINT((TSD," on start"));DEND; |
| 3180 |
if ( --vptr->hwired == 0 ) |
| 3181 |
if ( !vptr->valid ) |
| 3182 |
{ |
| 3183 |
#ifdef TRACEMEM |
| 3184 |
if ( vptr->prev ) |
| 3185 |
vptr->prev->next = vptr->next; |
| 3186 |
if ( vptr->next ) |
| 3187 |
vptr->next->prev = vptr->prev; |
| 3188 |
else |
| 3189 |
vt->first_invalid = vptr->prev; |
| 3190 |
#endif |
| 3191 |
/* |
| 3192 |
* See comment on REMOVE_ELEMENT why we just remove the body |
| 3193 |
*/ |
| 3194 |
FreeTSD( thisptr->u.varbx ); |
| 3195 |
} |
| 3196 |
thisptr->u.varbx = NULL; |
| 3197 |
} |
| 3198 |
} |
| 3199 |
|
| 3200 |
resstr = getvalue( TSD, thisptr->name, -1 ); /* changes the pool */ |
| 3201 |
if ( vt->thespot ) |
| 3202 |
{ |
| 3203 |
vt->thespot->hwired++; |
| 3204 |
thisptr->u.varbx = vt->thespot; |
| 3205 |
if ( vt->thespot->num ) |
| 3206 |
{ |
| 3207 |
if ( vt->thespot->flag & VFLAG_NUM ) |
| 3208 |
return vt->thespot->num; |
| 3209 |
FreeTSD( vt->thespot->num->num ); |
| 3210 |
FreeTSD( vt->thespot->num ); |
| 3211 |
|
| 3212 |
} |
| 3213 |
vt->thespot->num = is_a_descr( TSD, resstr ); |
| 3214 |
if ( vt->thespot->num ) |
| 3215 |
vt->thespot->flag |= VFLAG_NUM; |
| 3216 |
} |
| 3217 |
else |
| 3218 |
{ |
| 3219 |
if ( vt->odescr ) |
| 3220 |
{ |
| 3221 |
FreeTSD( vt->odescr->num ); |
| 3222 |
FreeTSD( vt->odescr ); |
| 3223 |
} |
| 3224 |
vt->odescr = is_a_descr( TSD, resstr ); |
| 3225 |
DSTART;DPRINT((TSD,"shortcutnum: "));DVALUE(TSD,"NO!!! vt->thespot, resstr",resstr);DEND; |
| 3226 |
DSTART;DPRINT((TSD,"shortcutnum: "));DNUM(TSD,"rc",vt->odescr);DEND; |
| 3227 |
return vt->odescr; |
| 3228 |
} |
| 3229 |
DSTART;DPRINT((TSD,"shortcutnum: "));DVAR(TSD,"new vt->thespot",vt->thespot);DEND; |
| 3230 |
DSTART;DPRINT((TSD,"shortcutnum: "));DNUM(TSD,"rc",vt->thespot->num);DEND; |
| 3231 |
|
| 3232 |
return vt->thespot->num; |
| 3233 |
} |
| 3234 |
|
| 3235 |
/* |
| 3236 |
* Note: This is one of the most time-consuming routines. Be careful. |
| 3237 |
*/ |
| 3238 |
void setshortcut( tsd_t *TSD, nodeptr thisptr, streng *value ) |
| 3239 |
{ |
| 3240 |
variableptr vptr; |
| 3241 |
var_tsd_t *vt; |
| 3242 |
|
| 3243 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3244 |
|
| 3245 |
assert( !value || value->len <= value->max ); |
| 3246 |
DSTART;DPRINT((TSD,"setshortcut: "));DNAME(TSD,"thisptr->name",thisptr->name); |
| 3247 |
DVALUE(TSD,", value",value);DEND; |
| 3248 |
|
| 3249 |
if ( ( vptr = thisptr->u.varbx ) != NULL ) |
| 3250 |
{ |
| 3251 |
if ( vptr->valid == vt->current_valid ) |
| 3252 |
{ |
| 3253 |
DSTART;DPRINT((TSD,"setshortcut: "));DVAR(TSD,"valid vptr",vptr); |
| 3254 |
DPRINT((TSD," on start"));DEND; |
| 3255 |
SEEK_EXPOSED( vptr ); |
| 3256 |
if ( vptr->value ) |
| 3257 |
Free_stringTSD( vptr->value ); |
| 3258 |
if ( vptr->num ) |
| 3259 |
{ |
| 3260 |
FreeTSD( vptr->num->num ); |
| 3261 |
FreeTSD( vptr->num ); |
| 3262 |
vptr->num = 0; |
| 3263 |
} |
| 3264 |
vptr->flag = value ? VFLAG_STR : VFLAG_NONE; |
| 3265 |
vptr->value = value; |
| 3266 |
DSTART;DPRINT((TSD,"setshortcut: "));DVAR(TSD,"valid vptr",vptr); |
| 3267 |
DPRINT((TSD," on end"));DEND; |
| 3268 |
return; |
| 3269 |
} |
| 3270 |
else |
| 3271 |
{ |
| 3272 |
DSTART;DPRINT((TSD,"setshortcut: "));DVAR(TSD,"INVALID vptr",vptr); |
| 3273 |
DPRINT((TSD," on start"));DEND; |
| 3274 |
if ( --vptr->hwired == 0 ) |
| 3275 |
if ( !vptr->valid ) |
| 3276 |
{ |
| 3277 |
#ifdef TRACEMEM |
| 3278 |
if ( vptr->prev ) |
| 3279 |
vptr->prev->next = vptr->next; |
| 3280 |
if ( vptr->next ) |
| 3281 |
vptr->next->prev = vptr->prev; |
| 3282 |
else |
| 3283 |
vt->first_invalid = vptr->prev; |
| 3284 |
#endif |
| 3285 |
/* |
| 3286 |
* See comment on REMOVE_ELEMENT why we just remove the body |
| 3287 |
*/ |
| 3288 |
FreeTSD( thisptr->u.varbx ); |
| 3289 |
} |
| 3290 |
thisptr->u.varbx = NULL; |
| 3291 |
} |
| 3292 |
} |
| 3293 |
|
| 3294 |
setvalue( TSD, thisptr->name, value, -1 ); |
| 3295 |
if ( vt->thespot ) |
| 3296 |
{ |
| 3297 |
vt->thespot->hwired++; |
| 3298 |
thisptr->u.varbx = vt->thespot; |
| 3299 |
} |
| 3300 |
DSTART;DPRINT((TSD,"setshortcut: "));DVAR(TSD,"vt->thespot",vt->thespot); |
| 3301 |
DPRINT((TSD," on end"));DEND; |
| 3302 |
} |
| 3303 |
|
| 3304 |
/* |
| 3305 |
* sets the varbox in this to the given value, creating it if it doesn't |
| 3306 |
* exists. this->name is set to the string-representation of value; if |
| 3307 |
* string_val is non-NULL, string_val is used instead. string_val must not |
| 3308 |
* be used later. |
| 3309 |
*/ |
| 3310 |
void setshortcutnum( tsd_t *TSD, nodeptr thisptr, num_descr *value, |
| 3311 |
streng *string_val ) |
| 3312 |
{ |
| 3313 |
variableptr vptr; |
| 3314 |
var_tsd_t *vt; |
| 3315 |
|
| 3316 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3317 |
assert( value->size ); |
| 3318 |
|
| 3319 |
DSTART;DPRINT((TSD,"setshortcutnum: "));DNAME(TSD,"thisptr->name",thisptr->name); |
| 3320 |
DNUM(TSD,", value",value);DEND; |
| 3321 |
if ( ( vptr = thisptr->u.varbx ) != NULL ) |
| 3322 |
{ |
| 3323 |
if ( vptr->valid == vt->current_valid ) |
| 3324 |
{ |
| 3325 |
DSTART;DPRINT((TSD,"setshortcutnum: "));DVAR(TSD,"valid vptr",vptr); |
| 3326 |
DPRINT((TSD," on start"));DEND; |
| 3327 |
SEEK_EXPOSED( vptr ); |
| 3328 |
if ( vptr->num ) |
| 3329 |
{ |
| 3330 |
FreeTSD( vptr->num->num ); |
| 3331 |
FreeTSD( vptr->num ); |
| 3332 |
} |
| 3333 |
if ( vptr->value ) |
| 3334 |
{ |
| 3335 |
Free_stringTSD( vptr->value ); |
| 3336 |
vptr->value = NULL; |
| 3337 |
} |
| 3338 |
vptr->flag = value ? VFLAG_NUM : VFLAG_NONE; |
| 3339 |
vptr->num = value; |
| 3340 |
DSTART;DPRINT((TSD,"setshortcutnum: "));DVAR(TSD,"valid vptr",vptr); |
| 3341 |
DPRINT((TSD," on end"));DEND; |
| 3342 |
return; |
| 3343 |
} |
| 3344 |
else |
| 3345 |
{ |
| 3346 |
DSTART;DPRINT((TSD,"setshortcutnum: "));DVAR(TSD,"INVALID vptr",vptr); |
| 3347 |
DPRINT((TSD," on start"));DEND; |
| 3348 |
if ( --vptr->hwired == 0 ) |
| 3349 |
if ( !vptr->valid ) |
| 3350 |
{ |
| 3351 |
#ifdef TRACEMEM |
| 3352 |
if ( vptr->prev ) |
| 3353 |
vptr->prev->next = vptr->next; |
| 3354 |
if ( vptr->next ) |
| 3355 |
vptr->next->prev = vptr->prev; |
| 3356 |
else |
| 3357 |
vt->first_invalid = vptr->prev; |
| 3358 |
#endif |
| 3359 |
/* |
| 3360 |
* See comment on REMOVE_ELEMENT why we just remove the body |
| 3361 |
*/ |
| 3362 |
FreeTSD( thisptr->u.varbx ); |
| 3363 |
} |
| 3364 |
thisptr->u.varbx = NULL; |
| 3365 |
} |
| 3366 |
} |
| 3367 |
|
| 3368 |
if ( string_val == NULL ) |
| 3369 |
string_val = str_norm( TSD, value, NULL ); |
| 3370 |
setvalue( TSD, thisptr->name, string_val, -1 ); |
| 3371 |
if ( vt->thespot ) |
| 3372 |
{ |
| 3373 |
vt->thespot->hwired++; |
| 3374 |
if ( value ) |
| 3375 |
{ |
| 3376 |
if ( vt->thespot->num ) |
| 3377 |
{ |
| 3378 |
FreeTSD( vt->thespot->num->num ); |
| 3379 |
FreeTSD( vt->thespot->num ); |
| 3380 |
} |
| 3381 |
vt->thespot->num = value; |
| 3382 |
vt->thespot->flag |= VFLAG_NUM; |
| 3383 |
} |
| 3384 |
thisptr->u.varbx = vt->thespot; |
| 3385 |
} |
| 3386 |
else |
| 3387 |
{ |
| 3388 |
FreeTSD( value->num ); |
| 3389 |
FreeTSD( value ); |
| 3390 |
} |
| 3391 |
DSTART;DPRINT((TSD,"setshortcutnum: "));DVAR(TSD,"vt->thespot",vt->thespot);DEND; |
| 3392 |
DSTART;DPRINT((TSD,"setshortcutnum: "));DVAR(TSD,"thisptr->u.varbx",thisptr->u.varbx); |
| 3393 |
DPRINT((TSD," on end"));DEND; |
| 3394 |
} |
| 3395 |
|
| 3396 |
streng *fix_compound( tsd_t *TSD, nodeptr thisptr, streng *newstr ) |
| 3397 |
{ |
| 3398 |
variableptr iptr,ptr; |
| 3399 |
streng *value=NULL; |
| 3400 |
streng *indeks; |
| 3401 |
unsigned hhash, thash, hfh = 0; |
| 3402 |
int rehash = 0, rehashIdx = 0; |
| 3403 |
var_tsd_t *vt; |
| 3404 |
|
| 3405 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3406 |
DPRINTF((TSD,"fix_compound: ?")); |
| 3407 |
value = NULL; |
| 3408 |
hhash = (unsigned) -1; /* Intentionally erroneous */ |
| 3409 |
|
| 3410 |
assert( !newstr || newstr->len <= newstr->max ); |
| 3411 |
|
| 3412 |
iptr = thisptr->u.varbx; |
| 3413 |
if ( iptr ) |
| 3414 |
{ |
| 3415 |
if ( iptr->valid != vt->current_valid ) |
| 3416 |
{ |
| 3417 |
if ( ( --iptr->hwired == 0 ) && !iptr->valid ) |
| 3418 |
{ |
| 3419 |
#ifdef TRACEMEM |
| 3420 |
if ( iptr->prev ) |
| 3421 |
iptr->prev->next = iptr->next; |
| 3422 |
if ( thisptr->u.varbx->next ) |
| 3423 |
iptr->next->prev = iptr->prev; |
| 3424 |
else |
| 3425 |
vt->first_invalid = iptr->prev; |
| 3426 |
#endif |
| 3427 |
/* |
| 3428 |
* See comment on REMOVE_ELEMENT why we just remove the body |
| 3429 |
*/ |
| 3430 |
FreeTSD( iptr ); |
| 3431 |
} |
| 3432 |
iptr = thisptr->u.varbx = NULL; |
| 3433 |
} |
| 3434 |
} |
| 3435 |
|
| 3436 |
if ( !iptr ) |
| 3437 |
{ |
| 3438 |
hhash = hashfunc( vt, thisptr->name, 0, NULL, TSD->currlevel->vars->size ); |
| 3439 |
iptr = TSD->currlevel->vars->tbl[hhash]; |
| 3440 |
hfh = vt->fullhash; |
| 3441 |
TSD->currlevel->vars->reads++; |
| 3442 |
/* |
| 3443 |
* The stem's name is uppercased both in the parsing tree as in our |
| 3444 |
* variable pool --> no need to Str_ccmp the elements. |
| 3445 |
*/ |
| 3446 |
SEEK_VAR_CMP( iptr, thisptr->name, hfh, TSD->currlevel->vars, rehash ); |
| 3447 |
SEEK_EXPOSED( iptr ); |
| 3448 |
|
| 3449 |
if ( iptr ) |
| 3450 |
{ |
| 3451 |
thisptr->u.varbx = iptr; |
| 3452 |
iptr->hwired++; |
| 3453 |
} |
| 3454 |
else if ( newstr && thisptr->p[0] ) |
| 3455 |
{ |
| 3456 |
if ( setvalue_simple( TSD, TSD->currlevel->vars, thisptr->name, NULL ) ) |
| 3457 |
{ |
| 3458 |
rehash = 0; |
| 3459 |
hhash = hfh % TSD->currlevel->vars->size; |
| 3460 |
} |
| 3461 |
iptr = vt->thespot; |
| 3462 |
iptr->index = make_hash_table( TSD, vt->initialHashTableLength ); |
| 3463 |
DPRINTF((TSD,"make_hash_table: rc=%p",iptr->index)); |
| 3464 |
} |
| 3465 |
|
| 3466 |
} |
| 3467 |
|
| 3468 |
assert( thisptr->p[0] ); |
| 3469 |
indeks = fix_index( TSD, thisptr->p[0] ); |
| 3470 |
|
| 3471 |
if ( vt->subst ) |
| 3472 |
tracecompound( TSD, thisptr->name, thisptr->name->len - 1, indeks, 'C' ); |
| 3473 |
|
| 3474 |
if ( iptr ) |
| 3475 |
{ |
| 3476 |
thash = hashfunc( vt, indeks, 0, NULL, iptr->index->size ); |
| 3477 |
ptr = iptr->index->tbl[thash]; |
| 3478 |
iptr->index->writes++; |
| 3479 |
SEEK_VAR_CMP( ptr, indeks, vt->fullhash, iptr->index, rehashIdx ); |
| 3480 |
SEEK_EXPOSED( ptr ); |
| 3481 |
|
| 3482 |
if ( newstr ) |
| 3483 |
{ |
| 3484 |
vt->foundflag = ptr != NULL; |
| 3485 |
if ( vt->foundflag ) |
| 3486 |
{ |
| 3487 |
REPLACE_VALUE( newstr, ptr ); |
| 3488 |
} |
| 3489 |
else |
| 3490 |
{ |
| 3491 |
newbox( TSD, indeks, newstr, &iptr->index->tbl[thash], vt->fullhash ); |
| 3492 |
iptr->index->elements++; |
| 3493 |
NEW_HASHTABLE_CHECK( iptr->index, rehashIdx ); |
| 3494 |
iptr->index->tbl[thash]->stem = iptr; |
| 3495 |
} |
| 3496 |
} |
| 3497 |
else |
| 3498 |
{ |
| 3499 |
vt->foundflag = ptr && ( ptr->flag & VFLAG_BOTH ); |
| 3500 |
if ( ptr ) |
| 3501 |
{ |
| 3502 |
if ( ptr->flag & VFLAG_STR ) |
| 3503 |
value = ptr->value; |
| 3504 |
else if ( ptr->flag & VFLAG_NUM ) |
| 3505 |
{ |
| 3506 |
expand_to_str( TSD, ptr ); |
| 3507 |
value = ptr->value; |
| 3508 |
} |
| 3509 |
else |
| 3510 |
goto the_default; |
| 3511 |
} |
| 3512 |
else if ( iptr->flag & VFLAG_STR ) |
| 3513 |
value = iptr->value; |
| 3514 |
else if ( iptr->flag & VFLAG_NUM ) |
| 3515 |
{ |
| 3516 |
expand_to_str( TSD, iptr ); |
| 3517 |
value = iptr->value; |
| 3518 |
} |
| 3519 |
else |
| 3520 |
goto the_default ; |
| 3521 |
|
| 3522 |
tracevalue( TSD, value, 'V' ); |
| 3523 |
} |
| 3524 |
} |
| 3525 |
else |
| 3526 |
{ |
| 3527 |
if ( newstr ) |
| 3528 |
{ |
| 3529 |
iptr = newbox( TSD, thisptr->name, NULL, |
| 3530 |
&TSD->currlevel->vars->tbl[hhash], hfh ); |
| 3531 |
TSD->currlevel->vars->elements++; |
| 3532 |
NEW_HASHTABLE_CHECK( TSD->currlevel->vars, rehash ); |
| 3533 |
iptr->index = make_hash_table( TSD, vt->initialHashTableLength ); |
| 3534 |
DPRINTF((TSD,"make_hash_table: rc=%p",iptr->index)); |
| 3535 |
thash = hashfunc( vt, indeks, 0, NULL, iptr->index->size ); |
| 3536 |
iptr->index->writes++; |
| 3537 |
newbox( TSD, indeks, newstr, &iptr->index->tbl[thash], vt->fullhash ); |
| 3538 |
iptr->index->elements++; |
| 3539 |
NEW_HASHTABLE_CHECK( iptr->index, rehashIdx ); |
| 3540 |
iptr->index->tbl[thash]->stem = iptr; |
| 3541 |
} |
| 3542 |
else |
| 3543 |
{ |
| 3544 |
the_default: |
| 3545 |
if ( vt->xvalue ) |
| 3546 |
Free_stringTSD( vt->xvalue ); |
| 3547 |
vt->xvalue = Str_makeTSD( thisptr->name->len + indeks->len ); |
| 3548 |
vt->xvalue = Str_catTSD( vt->xvalue, thisptr->name ); |
| 3549 |
vt->xvalue = Str_catTSD( vt->xvalue, indeks ); |
| 3550 |
tracevalue( TSD, vt->xvalue, 'L' ); |
| 3551 |
if ( !vt->ignore_novalue ) |
| 3552 |
condition_hook( TSD, SIGNAL_NOVALUE, 0, 0, -1, Str_dupTSD( vt->xvalue ), NULL ) ; |
| 3553 |
value = vt->xvalue; |
| 3554 |
} |
| 3555 |
} |
| 3556 |
|
| 3557 |
if ( rehashIdx ) |
| 3558 |
{ |
| 3559 |
reorgHashtable( TSD, iptr->index ); |
| 3560 |
} |
| 3561 |
if ( rehash ) |
| 3562 |
{ |
| 3563 |
reorgHashtable( TSD, TSD->currlevel->vars ); |
| 3564 |
} |
| 3565 |
|
| 3566 |
assert( !value || value->len <= value->max ); |
| 3567 |
return value; |
| 3568 |
} |
| 3569 |
|
| 3570 |
/* |
| 3571 |
* queries or sets the varbox in this depending on the presence of new. If |
| 3572 |
* new is set, varbox in this is set to the given value, creating it if it |
| 3573 |
* doesn't exists. this->name is set in this case to the string-representation |
| 3574 |
* of value; if string_val is non-NULL, string_val is used instead. |
| 3575 |
* string_val must not be used later. |
| 3576 |
* The current or new value of the variable is returned in all cases, it may |
| 3577 |
* be NULL. |
| 3578 |
*/ |
| 3579 |
num_descr *fix_compoundnum( tsd_t *TSD, nodeptr thisptr, num_descr *newdescr, |
| 3580 |
streng *string_val ) |
| 3581 |
{ |
| 3582 |
variableptr iptr, ptr; |
| 3583 |
num_descr *value; |
| 3584 |
streng *indeks; |
| 3585 |
int rehash = 0, rehashIdx = 0; |
| 3586 |
unsigned hhash, hfh = 0, thash; |
| 3587 |
var_tsd_t *vt; |
| 3588 |
|
| 3589 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3590 |
DPRINTF((TSD,"fix_compoundnum: ?")); |
| 3591 |
value = NULL; |
| 3592 |
thash = hhash = 0x12345678; /* Intentionally errorneous */ |
| 3593 |
|
| 3594 |
iptr = thisptr->u.varbx; |
| 3595 |
if ( iptr ) |
| 3596 |
{ |
| 3597 |
if ( iptr->valid != vt->current_valid ) |
| 3598 |
{ |
| 3599 |
if ( ( --iptr->hwired == 0 ) && !iptr->valid ) |
| 3600 |
{ |
| 3601 |
#ifdef TRACEMEM |
| 3602 |
if ( iptr->prev ) |
| 3603 |
iptr->prev->next = iptr->next; |
| 3604 |
if ( thisptr->u.varbx->next ) |
| 3605 |
iptr->next->prev = iptr->prev; |
| 3606 |
else |
| 3607 |
vt->first_invalid = iptr->prev; |
| 3608 |
#endif |
| 3609 |
/* |
| 3610 |
* See comment on REMOVE_ELEMENT why we just remove the body |
| 3611 |
*/ |
| 3612 |
FreeTSD( iptr ); |
| 3613 |
} |
| 3614 |
iptr = thisptr->u.varbx = NULL; |
| 3615 |
} |
| 3616 |
} |
| 3617 |
|
| 3618 |
if ( !iptr ) |
| 3619 |
{ |
| 3620 |
hhash = hashfunc( vt, thisptr->name, 0, NULL, TSD->currlevel->vars->size ); |
| 3621 |
iptr = TSD->currlevel->vars->tbl[hhash]; |
| 3622 |
hfh = vt->fullhash; |
| 3623 |
TSD->currlevel->vars->reads++; |
| 3624 |
/* |
| 3625 |
* The stem's name is uppercased both in the parsing tree as in our |
| 3626 |
* variable pool --> no need to Str_ccmp the elements. |
| 3627 |
*/ |
| 3628 |
SEEK_VAR_CMP( iptr, thisptr->name, hfh, TSD->currlevel->vars, rehash ); |
| 3629 |
SEEK_EXPOSED( iptr ); |
| 3630 |
|
| 3631 |
if ( iptr ) |
| 3632 |
{ |
| 3633 |
thisptr->u.varbx = iptr; |
| 3634 |
iptr->hwired++; |
| 3635 |
} |
| 3636 |
else if ( newdescr && thisptr->p[0] ) |
| 3637 |
{ |
| 3638 |
if ( setvalue_simple( TSD, TSD->currlevel->vars, thisptr->name, NULL ) ) |
| 3639 |
{ |
| 3640 |
rehash = 0; |
| 3641 |
hhash = hfh % TSD->currlevel->vars->size; |
| 3642 |
} |
| 3643 |
iptr = vt->thespot; |
| 3644 |
iptr->index = make_hash_table( TSD, vt->initialHashTableLength ); |
| 3645 |
DPRINTF((TSD,"make_hash_table: rc=%p",iptr->index)); |
| 3646 |
} |
| 3647 |
} |
| 3648 |
|
| 3649 |
assert( thisptr->p[0] ); |
| 3650 |
indeks = fix_index( TSD, thisptr->p[0] ); |
| 3651 |
|
| 3652 |
if ( vt->subst ) |
| 3653 |
tracecompound( TSD, thisptr->name, thisptr->name->len - 1, indeks, 'C' ); |
| 3654 |
|
| 3655 |
if ( iptr ) |
| 3656 |
{ |
| 3657 |
thash = hashfunc( vt, indeks, 0, NULL, iptr->index->size ); |
| 3658 |
ptr = iptr->index->tbl[thash]; |
| 3659 |
iptr->index->writes++; |
| 3660 |
SEEK_VAR_CMP( ptr, indeks, vt->fullhash, iptr->index, rehashIdx ); |
| 3661 |
SEEK_EXPOSED( ptr ); |
| 3662 |
|
| 3663 |
if ( newdescr ) |
| 3664 |
{ |
| 3665 |
vt->foundflag = ptr != NULL; |
| 3666 |
if ( vt->foundflag ) |
| 3667 |
{ |
| 3668 |
REPLACE_NUMBER( newdescr, ptr ); |
| 3669 |
} |
| 3670 |
else |
| 3671 |
{ |
| 3672 |
newbox( TSD, indeks, NULL, &iptr->index->tbl[thash], vt->fullhash ); |
| 3673 |
iptr->index->elements++; |
| 3674 |
NEW_HASHTABLE_CHECK( iptr->index, rehashIdx ); |
| 3675 |
ptr = iptr->index->tbl[thash]; |
| 3676 |
ptr->stem = iptr; |
| 3677 |
ptr->num = newdescr; |
| 3678 |
ptr->flag = VFLAG_NUM; |
| 3679 |
} |
| 3680 |
if ( ptr->value != NULL ) |
| 3681 |
Free_stringTSD( ptr->value ); |
| 3682 |
|
| 3683 |
if ( string_val != NULL ) |
| 3684 |
ptr->flag |= VFLAG_STR; |
| 3685 |
else |
| 3686 |
ptr->flag &= ~VFLAG_STR; |
| 3687 |
ptr->value = string_val; |
| 3688 |
} |
| 3689 |
else |
| 3690 |
{ |
| 3691 |
vt->foundflag = ptr && ( ptr->flag & VFLAG_BOTH ); |
| 3692 |
if ( ptr ) |
| 3693 |
{ |
| 3694 |
if ( ptr->flag & VFLAG_NUM ) |
| 3695 |
{ |
| 3696 |
value = ptr->num; |
| 3697 |
tracenumber( TSD, value, 'V' ); |
| 3698 |
} |
| 3699 |
else if ( ptr->flag & VFLAG_STR ) |
| 3700 |
{ |
| 3701 |
if ( ptr->num ) |
| 3702 |
{ |
| 3703 |
FreeTSD( ptr->num->num ); |
| 3704 |
FreeTSD( ptr->num ); |
| 3705 |
} |
| 3706 |
ptr->num = is_a_descr( TSD, ptr->value ); |
| 3707 |
if ( ( value = ptr->num ) != NULL ) |
| 3708 |
{ |
| 3709 |
tracevalue( TSD, ptr->value, 'V' ); |
| 3710 |
ptr->flag |= VFLAG_NUM; |
| 3711 |
} |
| 3712 |
} |
| 3713 |
else |
| 3714 |
goto the_default; |
| 3715 |
} |
| 3716 |
else if ( iptr->flag & VFLAG_NUM ) |
| 3717 |
{ |
| 3718 |
value = iptr->num; |
| 3719 |
tracenumber( TSD, value, 'V' ); |
| 3720 |
} |
| 3721 |
else if ( iptr->flag & VFLAG_STR ) |
| 3722 |
{ |
| 3723 |
if ( iptr->num ) |
| 3724 |
{ |
| 3725 |
FreeTSD( iptr->num->num ); |
| 3726 |
FreeTSD( iptr->num ); |
| 3727 |
} |
| 3728 |
iptr->num = is_a_descr( TSD, iptr->value ); |
| 3729 |
if ( ( value = iptr->num ) != NULL ) |
| 3730 |
{ |
| 3731 |
iptr->flag |= VFLAG_NUM; |
| 3732 |
tracevalue( TSD, iptr->value, 'V' ); |
| 3733 |
} |
| 3734 |
} |
| 3735 |
else |
| 3736 |
goto the_default; |
| 3737 |
} |
| 3738 |
|
| 3739 |
} |
| 3740 |
else |
| 3741 |
{ |
| 3742 |
if ( newdescr ) |
| 3743 |
{ |
| 3744 |
/* |
| 3745 |
* Happens on: |
| 3746 |
* a) first access |
| 3747 |
* b) left part of X_NASSIGN |
| 3748 |
* c) thisptr->p[0] is NULL |
| 3749 |
* according to this function, interprt.c and yaccsrc.y. |
| 3750 |
* |
| 3751 |
* We have to be a X_HEAD_SYMBOL. X_HEAD_SYMBOL are created by |
| 3752 |
* create_head in yaccsrc.y only if thisptr->p[0] != NULL. |
| 3753 |
* |
| 3754 |
* --> This code will never be executed! |
| 3755 |
* Reenable this only if you check the presence of stringval and |
| 3756 |
* know what you do. |
| 3757 |
* Comment last visited on 12.12.2003, this makes sense. |
| 3758 |
* If no response by users are made, the else-part of "#if 1" should |
| 3759 |
* be removed at the end of 2010. |
| 3760 |
*/ |
| 3761 |
#if 1 |
| 3762 |
fprintf( stderr, "Regina internal error detected in %s, line %u.\n" |
| 3763 |
"Please, send an email to [email protected].\n", |
| 3764 |
__FILE__, __LINE__ ); |
| 3765 |
} |
| 3766 |
#else |
| 3767 |
iptr = newbox( TSD, thisptr->name, NULL, &TSD->currlevel->vars[hhash], |
| 3768 |
hfh ); |
| 3769 |
TSD->currlevel->vars->elements++; |
| 3770 |
NEW_HASHTABLE_CHECK( TSD->currlevel->vars, rehash ); |
| 3771 |
iptr->index = make_hash_table( TSD, vt->initialHashTableLength ); |
| 3772 |
DPRINTF((TSD,"make_hash_table: rc=%p",iptr->index)); |
| 3773 |
thash = hashfunc( vt, indeks, 0, NULL ); |
| 3774 |
iptr->index->reads++; |
| 3775 |
newbox( TSD, indeks, NULL, &iptr->index->tbl[thash], vt->fullhash ); |
| 3776 |
iptr->index->elements++; |
| 3777 |
NEW_HASHTABLE_CHECK( iptr->index, rehashIdx ); |
| 3778 |
ptr = iptr->index[thash]; |
| 3779 |
ptr->stem = iptr; |
| 3780 |
ptr->num = newdescr; |
| 3781 |
ptr->flag = VFLAG_NUM; |
| 3782 |
if ( string_val != NULL ) |
| 3783 |
ptr->flag |= VFLAG_STR; |
| 3784 |
ptr->value = string_val; |
| 3785 |
} |
| 3786 |
else |
| 3787 |
#endif |
| 3788 |
{ |
| 3789 |
the_default: |
| 3790 |
tracecompound( TSD, thisptr->name, thisptr->name->len - 1, indeks, 'L' ); |
| 3791 |
return NULL; |
| 3792 |
} |
| 3793 |
} |
| 3794 |
if ( rehashIdx ) |
| 3795 |
{ |
| 3796 |
reorgHashtable( TSD, iptr->index ); |
| 3797 |
} |
| 3798 |
if ( rehash ) |
| 3799 |
{ |
| 3800 |
reorgHashtable( TSD, TSD->currlevel->vars ); |
| 3801 |
} |
| 3802 |
|
| 3803 |
return value; |
| 3804 |
} |
| 3805 |
|
| 3806 |
/* |
| 3807 |
* get_realbox returns either p or the realbox associated with p if it exists. |
| 3808 |
* This function is NULL-pointer safe. |
| 3809 |
*/ |
| 3810 |
static variableptr get_realbox( variableptr p ) |
| 3811 |
{ |
| 3812 |
if ( p == NULL ) |
| 3813 |
return p; |
| 3814 |
if ( p->realbox == NULL ) |
| 3815 |
return p; |
| 3816 |
for ( p = p->realbox; p->realbox; p = p->realbox ) |
| 3817 |
; |
| 3818 |
return p; |
| 3819 |
} |
| 3820 |
|
| 3821 |
/* |
| 3822 |
* get_next_variable either initializes the iteration system (reset != 0) or |
| 3823 |
* it returns the next variable of the variable's array. We have to do some |
| 3824 |
* extra housekeeping to become reentrant in each call. |
| 3825 |
* |
| 3826 |
* NULL is returned in initializing or after all variables are processed. |
| 3827 |
* |
| 3828 |
* This function returns the variables of the current PROCEDURE frame only |
| 3829 |
* and has a similar function dumpvars in debug.c. |
| 3830 |
*/ |
| 3831 |
variableptr get_next_variable( tsd_t *TSD, int reset ) |
| 3832 |
{ |
| 3833 |
variableptr retval; |
| 3834 |
var_tsd_t *vt; |
| 3835 |
|
| 3836 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3837 |
|
| 3838 |
DPRINTF((TSD,"get_next_variable: ?")); |
| 3839 |
if ( reset ) |
| 3840 |
{ |
| 3841 |
/* |
| 3842 |
* Initializes the 4 loop variables and returns NULL. |
| 3843 |
* rstem and rtail are the corresponding "realbox" shadows of pstem |
| 3844 |
* and ptail. This fixes bug 681991. |
| 3845 |
*/ |
| 3846 |
vt->pstem = vt->ptail = NULL; |
| 3847 |
vt->stemidx = vt->tailidx = 0; |
| 3848 |
vt->rstem = vt->rtail = NULL; |
| 3849 |
return NULL; |
| 3850 |
} |
| 3851 |
|
| 3852 |
/* |
| 3853 |
* We have to do some tricks to change the four nested loops (see dumpvars) |
| 3854 |
* into a reentrant loop system. The loop itself is identical to that one |
| 3855 |
* of dumpvars. |
| 3856 |
*/ |
| 3857 |
for ( ; ; ) |
| 3858 |
{ |
| 3859 |
/* |
| 3860 |
* While the masterindex stemidx isn't out of range. |
| 3861 |
*/ |
| 3862 |
if ( vt->rstem ) |
| 3863 |
{ |
| 3864 |
/* |
| 3865 |
* Something's left in the masterindex's iterator pstem. |
| 3866 |
*/ |
| 3867 |
if ( vt->rstem->index ) |
| 3868 |
{ |
| 3869 |
/* |
| 3870 |
* This works as the outer loop pair, but for stem variables. |
| 3871 |
*/ |
| 3872 |
for ( ; ; ) |
| 3873 |
{ |
| 3874 |
if ( vt->rtail ) |
| 3875 |
{ |
| 3876 |
retval = vt->rtail; |
| 3877 |
vt->ptail = vt->ptail->next; |
| 3878 |
vt->rtail = get_realbox( vt->ptail ); |
| 3879 |
return retval; |
| 3880 |
} |
| 3881 |
|
| 3882 |
if ( vt->tailidx >= vt->rstem->index->size ) |
| 3883 |
break; |
| 3884 |
|
| 3885 |
vt->ptail = vt->rstem->index->tbl[vt->tailidx++]; |
| 3886 |
vt->rtail = get_realbox( vt->ptail ); |
| 3887 |
} |
| 3888 |
} |
| 3889 |
|
| 3890 |
vt->ptail = vt->rtail = NULL; |
| 3891 |
vt->tailidx = 0; |
| 3892 |
|
| 3893 |
retval = vt->rstem; |
| 3894 |
vt->pstem = vt->pstem->next; |
| 3895 |
vt->rstem = get_realbox( vt->pstem ); |
| 3896 |
return retval; |
| 3897 |
} |
| 3898 |
|
| 3899 |
if ( vt->stemidx >= TSD->currlevel->vars->size ) |
| 3900 |
break; |
| 3901 |
|
| 3902 |
vt->pstem = TSD->currlevel->vars->tbl[vt->stemidx++]; |
| 3903 |
vt->rstem = get_realbox( vt->pstem ); |
| 3904 |
vt->ptail = NULL; |
| 3905 |
vt->tailidx = 0; |
| 3906 |
} |
| 3907 |
|
| 3908 |
return NULL; |
| 3909 |
} |
| 3910 |
|
| 3911 |
#if 0 |
| 3912 |
/* this was an attempt to mimic the behaviour of Object Rexx stem |
| 3913 |
* assignment, but proved non-ANSI complient, so was dropped. I leave |
| 3914 |
* it here so I can remember how to work with the variable pool ;-) |
| 3915 |
*/ |
| 3916 |
void copy_stem( tsd_t *TSD, nodeptr dststem, cnodeptr srcstem ) |
| 3917 |
{ |
| 3918 |
Changed too much, never try to use it anyway! FGC |
| 3919 |
/* |
| 3920 |
* Drop dststem |
| 3921 |
* set default value of dststem to default value of srcstem |
| 3922 |
* for each valid stem of srcstem, set dststem value to src value |
| 3923 |
*/ |
| 3924 |
variableptr ptr; |
| 3925 |
|
| 3926 |
var_tsd_t *vt; |
| 3927 |
|
| 3928 |
vt = (var_tsd_t *)TSD->var_tsd; |
| 3929 |
|
| 3930 |
DPRINTF((TSD,"copy_stem: ?")); |
| 3931 |
drop_var( dststem->name ); |
| 3932 |
ptr = findsimple( TSD, srcstem->name ); |
| 3933 |
if ( ptr ) |
| 3934 |
{ |
| 3935 |
if ( ptr->value ) |
| 3936 |
{ |
| 3937 |
/* |
| 3938 |
* The srcstem has a default value, so set the dststem's |
| 3939 |
* default value to this... |
| 3940 |
*/ |
| 3941 |
setvalue_stem( TSD, dststem->name, ptr->value ); |
| 3942 |
} |
| 3943 |
else |
| 3944 |
{ |
| 3945 |
/* |
| 3946 |
* The srcstem does not have a default value, so set the dststem's |
| 3947 |
* default value to the name of the srcstem... |
| 3948 |
*/ |
| 3949 |
setvalue_stem( TSD, dststem->name, ptr->name ); |
| 3950 |
} |
| 3951 |
#if 0 |
| 3952 |
/* |
| 3953 |
* THE following code copies all explicitly set variables in the srcstem |
| 3954 |
* to the equivalent dststem compound values, but this is NOT the way |
| 3955 |
* that the ANSI standard states the behaviour should be :-( |
| 3956 |
* |
| 3957 |
* Find each variable for srcstem, and set dststem equivalents... |
| 3958 |
*/ |
| 3959 |
if ( ptr->index ) |
| 3960 |
{ |
| 3961 |
for ( j = 0; j < HASHTABLENGTH; j++ ) |
| 3962 |
{ |
| 3963 |
if ( ( tptr = (ptr->index)[j] ) != NULL ) |
| 3964 |
{ |
| 3965 |
for ( ; tptr; tptr = tptr->next ) |
| 3966 |
{ |
| 3967 |
if ( tptr->name ) |
| 3968 |
{ |
| 3969 |
newname = Str_makeTSD( Str_len( dststem->name ) + 1 + Str_len( tptr->name ) ); |
| 3970 |
Str_ncpyTSD( newname, dststem->name, Str_len( dststem->name) ); |
| 3971 |
Str_catTSD( newname, tptr->name ); |
| 3972 |
if ( tptr->value ) |
| 3973 |
{ |
| 3974 |
setvalue_compound( TSD, newname, tptr->value ); |
| 3975 |
} |
| 3976 |
else |
| 3977 |
{ |
| 3978 |
/* |
| 3979 |
* If the srcstem compund variable was dropped, |
| 3980 |
* then to make the destination compund variable |
| 3981 |
* also "appear" to be dropped, call the following |
| 3982 |
* line, otherwise leave it excluded. |
| 3983 |
*/ |
| 3984 |
#if 0 |
| 3985 |
setvalue_compound( TSD, newname, NULL ); |
| 3986 |
#endif |
| 3987 |
} |
| 3988 |
Free_stringTSD( newname ); |
| 3989 |
} |
| 3990 |
} |
| 3991 |
} |
| 3992 |
} |
| 3993 |
} |
| 3994 |
#endif |
| 3995 |
} |
| 3996 |
else |
| 3997 |
{ |
| 3998 |
/* |
| 3999 |
* The source stem doesn't exist, so set the default value of |
| 4000 |
* dststem to the name of the srcstem. |
| 4001 |
*/ |
| 4002 |
setvalue_stem( TSD, dststem->name, srcstem->name ); |
| 4003 |
} |
| 4004 |
} |
| 4005 |
#endif |
| 4006 |
|
| 4007 |
|
| 4008 |
/* |
| 4009 |
* set_reserved_value sets reserved values (those with a leading dot) and |
| 4010 |
* their normal counterparts. |
| 4011 |
* poolid is one of the POOL0_??? ids and one of var_str or val_int is |
| 4012 |
* honoured depending on vflag, which may be either VFLAG_NONE, VFLAG_STR, |
| 4013 |
* VFLAG_NUM. |
| 4014 |
* We do our best to maximize the throughput here, but keep in mind that |
| 4015 |
* a plain setvalue invoked by the external variable interface may interfere |
| 4016 |
* with our values. So we can't hurry ahead the dot-variables any more. |
| 4017 |
*/ |
| 4018 |
void set_reserved_value( tsd_t *TSD, int poolid, streng *val_str, int val_int, |
| 4019 |
int vflag ) |
| 4020 |
{ |
| 4021 |
var_tsd_t *vt = (var_tsd_t *)TSD->var_tsd; |
| 4022 |
int cv; |
| 4023 |
|
| 4024 |
assert( ( poolid > 0 ) && ( poolid < POOL0_CNT ) ); |
| 4025 |
|
| 4026 |
if ( vflag == VFLAG_NONE ) |
| 4027 |
{ |
| 4028 |
drop_var_simple( TSD, vt->pool0, vt->pool0nodes[poolid][0].name ); |
| 4029 |
drop_var_simple( TSD, TSD->currlevel->vars, |
| 4030 |
vt->pool0nodes[poolid][1].name ); |
| 4031 |
return; |
| 4032 |
} |
| 4033 |
|
| 4034 |
if ( vflag == VFLAG_NUM ) |
| 4035 |
val_str = int_to_streng( TSD, val_int ); |
| 4036 |
|
| 4037 |
/* |
| 4038 |
* We can prevent a variable-box-switch by setting the current_valid flag |
| 4039 |
* to a const value. Because the value always uses pool0 we can safely set |
| 4040 |
* the flag. Don't do it for non-dot variables. |
| 4041 |
*/ |
| 4042 |
cv = vt->current_valid; |
| 4043 |
vt->current_valid = 1; |
| 4044 |
setshortcut( TSD, &vt->pool0nodes[poolid][0], val_str ); |
| 4045 |
vt->current_valid = cv; |
| 4046 |
|
| 4047 |
if ( vt->pool0nodes[poolid][1].name ) |
| 4048 |
{ |
| 4049 |
if ( val_str ) |
| 4050 |
val_str = Str_dupTSD( val_str ); |
| 4051 |
setshortcut( TSD, &vt->pool0nodes[poolid][1], val_str ); |
| 4052 |
} |
| 4053 |
} |