Same fix as r45172 for classes/iconimage:
[AROS-Contrib.git] / regina / options.c
blobe2445a3150c077e7eab1745fc6001567c88b5553
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
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.
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.
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.
20 #include "rexx.h"
22 #include <assert.h>
23 #include <string.h>
26 #define OPTION(opt) { #opt, EXT_##opt, NULL }
27 #define METAOP(name,value) { #name, -1, value }
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" ),
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 OPTION( RESULTS ), /* ARexx option */
53 METAOP( SAA, "NOCALLS_AS_FUNCS NOEXT_COMMANDS_AS_FUNCS" ),
54 OPTION( SINGLE_INTERPRETER ),
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 } ;
65 void do_options( tsd_t *TSD, proclevel pl, streng *options, int toggle )
67 char *cptr,*eptr,*start;
68 int length,inverse=0,tmp;
69 const struct __regina_option *lower,*upper,*middle=NULL;
71 cptr = options->value;
72 eptr = cptr + options->len;
74 while ( cptr < eptr )
76 for ( ; cptr < eptr && rx_isspace( *cptr ); cptr++ )
78 for ( start = cptr; cptr < eptr && !rx_isspace( *cptr ); cptr++ )
79 *cptr = (char) rx_toupper( *cptr );
81 if ( cptr > start+2 )
83 if ( ( inverse = ( *start == 'N' && *( start + 1) == 'O') ) != 0 )
84 start += 2;
86 length = cptr - start;
88 lower = all_options;
89 upper = lower + sizeof( all_options ) / sizeof( all_options[0] ) - 2;
91 while ( upper >= lower )
93 middle = lower + ( upper - lower ) / 2;
94 tmp = strncmp( middle->name, start, length );
95 if ( tmp == 0 && middle->name[length] == '\0' )
96 break;
98 if ( tmp > 0 )
99 upper = middle - 1;
100 else
101 lower = middle + 1;
104 /* If option is unknown, don't care ... */
105 if ( upper >= lower )
107 assert ( middle->name );
108 if ( middle->offset == -1 )
110 do_options( TSD, pl, Str_creTSD( middle->contains ),
111 toggle ^ inverse );
113 else
115 if (inverse ^ toggle)
116 set_options_flag( pl, middle->offset, 0 );
117 else
118 set_options_flag( pl, middle->offset, 1 );
122 Free_stringTSD( options );
124 * Check if SINGLE_INTERPRTER option is set; save the current TSD globally
126 if ( get_options_flag( pl, EXT_SINGLE_INTERPRETER ) )
128 setGlobalTSD( TSD );
132 int get_options_flag( cproclevel pl, int offset )
134 return pl->options & ( 1ul << offset );
137 void set_options_flag( proclevel pl, int offset, int status )
139 if ( status )
140 pl->options |= ( 1ul << offset );
141 else
142 pl->options &= ~( 1ul << offset );