| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992-1994 Anders Christensen <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "rexx.h" |
| 21 |
|
| 22 |
#include <assert.h> |
| 23 |
#include <string.h> |
| 24 |
|
| 25 |
|
| 26 |
#define OPTION(opt) { #opt, EXT_##opt, NULL } |
| 27 |
#define METAOP(name,value) { #name, -1, value } |
| 28 |
|
| 29 |
|
| 30 |
static const struct __regina_option all_options[] = { /* Must be alphabetically sorted! */ |
| 31 |
METAOP( ANSI, "NOCALLS_AS_FUNCS NOEXT_COMMANDS_AS_FUNCS FAST_LINES_BIF_DEFAULT STRICT_ANSI STRICT_WHITE_SPACE_COMPARISONS NOSINGLE_LINE_COMMENTS" ), |
| 32 |
OPTION( AREXX_BIFS ), |
| 33 |
OPTION( AREXX_SEMANTICS ), |
| 34 |
OPTION( BROKEN_ADDRESS_COMMAND ), |
| 35 |
METAOP( BUFFERS, "BUFTYPE_BIF DESBUF_BIF DROPBUF_BIF MAKEBUF_BIF" ), |
| 36 |
OPTION( BUFTYPE_BIF ), |
| 37 |
OPTION( CACHEEXT ), |
| 38 |
OPTION( CALLS_AS_FUNCS ), |
| 39 |
OPTION( DESBUF_BIF ), |
| 40 |
OPTION( DROPBUF_BIF ), |
| 41 |
OPTION( EXT_COMMANDS_AS_FUNCS ), |
| 42 |
OPTION( FAST_LINES_BIF_DEFAULT ), |
| 43 |
OPTION( FLUSHSTACK ), |
| 44 |
OPTION( HALT_ON_EXT_CALL_FAIL ), |
| 45 |
OPTION( INTERNAL_QUEUES ), |
| 46 |
OPTION( LINEOUTTRUNC ), |
| 47 |
OPTION( MAKEBUF_BIF ), |
| 48 |
OPTION( PRUNE_TRACE ), |
| 49 |
OPTION( QUEUES_301 ), |
| 50 |
METAOP( REGINA, "NOCALLS_AS_FUNCS EXT_COMMANDS_AS_FUNCS FAST_LINES_BIF_DEFAULT, NOHALT_ON_EXT_CALL_FAIL " ), |
| 51 |
OPTION( REGINA_BIFS ), |
| 52 |
METAOP( SAA, "NOCALLS_AS_FUNCS NOEXT_COMMANDS_AS_FUNCS" ), |
| 53 |
OPTION( SINGLE_INTERPRETER ), |
| 54 |
OPTION( SINGLE_LINE_COMMENTS ), |
| 55 |
OPTION( STDOUT_FOR_STDERR ), |
| 56 |
OPTION( STRICT_ANSI ), |
| 57 |
OPTION( STRICT_WHITE_SPACE_COMPARISONS ), |
| 58 |
OPTION( TRACE_HTML ), |
| 59 |
METAOP( TRL1, "NOCALLS_AS_FUNCS NOEXT_COMMANDS_AS_FUNCS" ), |
| 60 |
METAOP( TRL2, "NOCALLS_AS_FUNCS NOEXT_COMMANDS_AS_FUNCS" ), |
| 61 |
{ NULL, 0 } |
| 62 |
} ; |
| 63 |
|
| 64 |
|
| 65 |
void do_options( const tsd_t *TSD, proclevel pl, streng *options, int toggle ) |
| 66 |
{ |
| 67 |
char *cptr,*eptr,*start; |
| 68 |
int length,inverse=0,tmp; |
| 69 |
const struct __regina_option *lower,*upper,*middle=NULL; |
| 70 |
|
| 71 |
cptr = options->value; |
| 72 |
eptr = cptr + options->len; |
| 73 |
|
| 74 |
while ( cptr < eptr ) |
| 75 |
{ |
| 76 |
for ( ; cptr < eptr && rx_isspace( *cptr ); cptr++ ) |
| 77 |
; |
| 78 |
for ( start = cptr; cptr < eptr && !rx_isspace( *cptr ); cptr++ ) |
| 79 |
*cptr = (char) rx_toupper( *cptr ); |
| 80 |
|
| 81 |
if ( cptr > start+2 ) |
| 82 |
{ |
| 83 |
if ( ( inverse = ( *start == 'N' && *( start + 1) == 'O') ) != 0 ) |
| 84 |
start += 2; |
| 85 |
} |
| 86 |
length = cptr - start; |
| 87 |
|
| 88 |
lower = all_options; |
| 89 |
upper = lower + sizeof( all_options ) / sizeof( all_options[0] ) - 2; |
| 90 |
|
| 91 |
while ( upper >= lower ) |
| 92 |
{ |
| 93 |
middle = lower + ( upper - lower ) / 2; |
| 94 |
tmp = strncmp( middle->name, start, length ); |
| 95 |
if ( tmp == 0 && middle->name[length] == '\0' ) |
| 96 |
break; |
| 97 |
|
| 98 |
if ( tmp > 0 ) |
| 99 |
upper = middle - 1; |
| 100 |
else |
| 101 |
lower = middle + 1; |
| 102 |
} |
| 103 |
|
| 104 |
/* If option is unknown, don't care ... */ |
| 105 |
if ( upper >= lower ) |
| 106 |
{ |
| 107 |
assert ( middle->name ); |
| 108 |
if ( middle->offset == -1 ) |
| 109 |
{ |
| 110 |
do_options( TSD, pl, Str_creTSD( middle->contains ), |
| 111 |
toggle ^ inverse ); |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
if (inverse ^ toggle) |
| 116 |
set_options_flag( pl, middle->offset, 0 ); |
| 117 |
else |
| 118 |
set_options_flag( pl, middle->offset, 1 ); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
Free_stringTSD( options ); |
| 123 |
/* |
| 124 |
* Check if SINGLE_INTERPRTER option is set; save the current TSD globally |
| 125 |
*/ |
| 126 |
if ( get_options_flag( pl, EXT_SINGLE_INTERPRETER ) ) |
| 127 |
{ |
| 128 |
setGlobalTSD( TSD ); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
int get_options_flag( cproclevel pl, int offset ) |
| 133 |
{ |
| 134 |
return pl->options & ( 1ul << offset ); |
| 135 |
} |
| 136 |
|
| 137 |
void set_options_flag( proclevel pl, int offset, int status ) |
| 138 |
{ |
| 139 |
if ( status ) |
| 140 |
pl->options |= ( 1ul << offset ); |
| 141 |
else |
| 142 |
pl->options &= ~( 1ul << offset ); |
| 143 |
} |