File: options.c

package info (click to toggle)
regina 3.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,928 kB
  • ctags: 7,233
  • sloc: ansic: 50,555; sh: 2,727; lex: 2,298; yacc: 1,498; makefile: 1,010; cpp: 117
file content (132 lines) | stat: -rw-r--r-- 3,784 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef lint
static char *RCSid = "$Id: options.c,v 1.14 2004/02/22 09:25:29 florian Exp $";
#endif

/*
 *  The Regina Rexx Interpreter
 *  Copyright (C) 1992-1994  Anders Christensen <anders@pvv.unit.no>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "rexx.h"

#include <assert.h>
#include <string.h>


#define OPTION(opt) { #opt, EXT_##opt, NULL }
#define METAOP(name,value) { #name, -1, value }


static const struct __regina_option all_options[] = {  /* Must be alphabetically sorted! */
   OPTION( AREXX_BIFS ),
   OPTION( AREXX_SEMANTICS ),
   OPTION( BROKEN_ADDRESS_COMMAND ),
   METAOP( BUFFERS, "BUFTYPE_BIF DESBUF_BIF DROPBUF_BIF MAKEBUF_BIF" ),
   OPTION( BUFTYPE_BIF ),
   OPTION( CACHEEXT ),
   OPTION( CALLS_AS_FUNCS ),
   OPTION( DESBUF_BIF ),
   OPTION( DROPBUF_BIF ),
   OPTION( EXT_COMMANDS_AS_FUNCS ),
   OPTION( FAST_LINES_BIF_DEFAULT ),
   OPTION( FLUSHSTACK ),
   OPTION( INTERNAL_QUEUES ),
   OPTION( LINEOUTTRUNC ),
   OPTION( MAKEBUF_BIF ),
   OPTION( PRUNE_TRACE ),
   OPTION( QUEUES_301 ),
   OPTION( REGINA_BIFS ),
   OPTION( STDOUT_FOR_STDERR ),
   OPTION( STRICT_ANSI ),
   OPTION( STRICT_WHITE_SPACE_COMPARISONS ),
   OPTION( TRACE_HTML ),
   { NULL, 0 }
} ;


void do_options( const tsd_t *TSD, proclevel pl, streng *options, int toggle )
{
   char *cptr,*eptr,*start;
   int length,inverse=0,tmp;
   const struct __regina_option *lower,*upper,*middle=NULL;

   cptr = options->value;
   eptr = cptr + options->len;

   while ( cptr < eptr )
   {
      for ( ; cptr < eptr && rx_isspace( *cptr ); cptr++ )
         ;
      for ( start = cptr; cptr < eptr && !rx_isspace( *cptr ); cptr++ )
         *cptr = (char) rx_toupper( *cptr );

      if ( cptr > start+2 )
      {
         if ( ( inverse = ( *start == 'N' && *( start + 1) == 'O') ) != 0 )
            start += 2;
      }
      length = cptr - start;

      lower = all_options;
      upper = lower + sizeof( all_options ) / sizeof( all_options[0] ) - 2;

      while ( upper >= lower )
      {
         middle = lower + ( upper - lower ) / 2;
         tmp = strncmp( middle->name, start, length );
         if ( tmp == 0 && middle->name[length] == '\0' )
            break;

         if ( tmp > 0 )
            upper = middle - 1;
         else
            lower = middle + 1;
      }

      /* If option is unknown, don't care ... */
      if ( upper >= lower )
      {
         assert ( middle->name );
         if ( middle->offset == -1 )
         {
            do_options( TSD, pl, Str_creTSD( middle->contains ),
                        toggle ^ inverse );
         }
         else
         {
            if (inverse ^ toggle)
               set_options_flag( pl, middle->offset, 0 );
            else
               set_options_flag( pl, middle->offset, 1 );
         }
      }
   }
   Free_stringTSD( options );
}

int get_options_flag( cproclevel pl, int offset )
{
   return pl->options & ( 1ul << offset );
}

void set_options_flag( proclevel pl, int offset, int status )
{
   if ( status )
      pl->options |= ( 1ul << offset );
   else
      pl->options &= ~( 1ul << offset );
}