bringing SDL 1.2.14 from vendor into the main branch
[AROS-Contrib.git] / regina / options.c
blob81517f09716b9cf6cc1da1c3218ae6ba245b9ca7
1 #ifndef lint
2 static char *RCSid = "$Id$";
3 #endif
5 /*
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rexx.h"
26 #include <assert.h>
27 #include <string.h>
28 #include <ctype.h>
31 #define OPTION(opt) { #opt, EXT_##opt, NULL }
32 #define METAOP(name,value) { #name, -1, value }
35 static const struct __regina_option all_options[] = { /* Must be alphabetically sorted! */
36 METAOP( BUFFERS, "BUFTYPE_BIF DESBUF_BIF DROPBUF_BIF MAKEBUF_BIF" ),
37 OPTION( BUFTYPE_BIF ),
38 OPTION( CACHEEXT ),
39 OPTION( CLOSE_BIF ),
40 OPTION( DESBUF_BIF ),
41 OPTION( DROPBUF_BIF ),
42 OPTION( EXT_COMMANDS_AS_FUNCS ),
43 OPTION( FAST_LINES_BIF_DEFAULT ),
44 METAOP( FILEIO, "OPEN_BIF CLOSE_BIF" ),
45 OPTION( FIND_BIF ),
46 OPTION( FLUSHSTACK ),
47 OPTION( INTERNAL_QUEUES ),
48 OPTION( LINEOUTTRUNC ),
49 OPTION( MAKEBUF_BIF ),
50 OPTION( OPEN_BIF ),
51 OPTION( PRUNE_TRACE ),
52 OPTION( REGINA_BIFS ),
53 OPTION( STDOUT_FOR_STDERR ),
54 OPTION( STRICT_ANSI ),
55 OPTION( TRACE_HTML ),
56 { NULL, 0 }
57 } ;
60 void do_options( const tsd_t *TSD, streng *options, int toggle )
62 char *cptr=NULL, *eptr=NULL, *start=NULL ;
63 int length=0, inverse=0, tmp=0 ;
64 const struct __regina_option *lower=NULL, *upper=NULL, *middle=NULL ;
66 cptr = options->value ;
67 eptr = cptr + options->len ;
69 while (cptr<eptr)
71 for (;cptr<eptr && isspace(*cptr); cptr++) ;
72 for (start=cptr; cptr<eptr && !isspace(*cptr); cptr++ )
73 *cptr = (char) toupper( *cptr ) ;
75 if (((inverse=(*start=='N' && *(start+1)=='O'))!=0) && cptr>start+2)
76 start += 2 ;
78 length = cptr - start ;
80 lower = all_options ;
81 upper = lower + (sizeof(all_options)/sizeof(struct __regina_option)) - 2 ;
83 while( upper >= lower )
85 middle = lower + (upper-lower)/2 ;
86 tmp = strncmp(middle->name,start,length) ;
87 if (tmp==0 && middle->name[length]==0x00)
88 break ;
90 if (tmp>0)
91 upper = middle - 1 ;
92 else
93 lower = middle + 1 ;
96 /* If option is unknown, don't care ... */
97 if ( upper >= lower )
99 assert ( middle->name ) ;
100 if (middle->offset == -1)
102 do_options( TSD, Str_creTSD(middle->contains), toggle^inverse ) ;
104 else
107 if (inverse^toggle)
108 set_options_flag( TSD->currlevel, middle->offset, 0 ) ;
109 else
110 set_options_flag( TSD->currlevel, middle->offset, 1 ) ;
114 Free_stringTSD( options ) ;
117 int get_options_flag( cproclevel pl, int offset )
119 register int obyte = offset / ( sizeof( unsigned char ) * 8 ) ;
120 register int obit = offset % ( sizeof( unsigned char ) * 8 ) ;
122 return ( pl->u.flags[obyte] & ( 1 << ( 7 - obit ) ) ) ;
125 void set_options_flag( proclevel pl, int offset, int status )
127 register int obyte = offset / ( sizeof( unsigned char ) * 8 ) ;
128 register int obit = offset % ( sizeof( unsigned char ) * 8 ) ;
130 if ( status )
131 pl->u.flags[obyte] |= (unsigned char)(1<<(7-obit)) ;
132 else
133 pl->u.flags[obyte] &= (unsigned char)(~(1<<(7-obit))) ;