1 /* 2 * Motif 3 * 4 * Copyright (c) 1987-2012, The Open Group. All rights reserved. 5 * 6 * These libraries and programs are free software; you can 7 * redistribute them and/or modify them under the terms of the GNU 8 * Lesser General Public License as published by the Free Software 9 * Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * These libraries and programs are distributed in the hope that 13 * they will be useful, but WITHOUT ANY WARRANTY; without even the 14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 * PURPOSE. See the GNU Lesser General Public License for more 16 * details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with these librararies and programs; if not, write 20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 21 * Floor, Boston, MA 02110-1301 USA 22 */ 23 #ifdef REV_INFO 24 #ifndef lint 25 static char rcsid[] = "$XConsortium: UilKeyTab.c /main/11 1995/07/14 09:34:29 drk $" 26 #endif 27 #endif 28 29 #ifdef HAVE_CONFIG_H 30 #include <config.h> 31 #endif 32 33 34 /* 35 **++ 36 ** FACILITY: 37 ** 38 ** User Interface Language Compiler (UIL) 39 ** 40 ** ABSTRACT: 41 ** 42 ** This module contains the keyword table used by the lexical analyzer 43 ** to look up the keywords in the UIL. 44 ** 45 **-- 46 **/ 47 48 49 /* 50 ** 51 ** INCLUDE FILES 52 ** 53 **/ 54 55 #include "UilDefI.h" 56 57 58 /* 59 ** 60 ** DEFINE and MACRO DEFINITIONS 61 ** 62 **/ 63 64 65 /* 66 ** 67 ** EXTERNAL VARIABLE DECLARATIONS 68 ** 69 **/ 70 71 72 /* 73 ** 74 ** GLOBAL VARIABLE DECLARATIONS 75 ** 76 **/ 77 78 79 /* 80 ** 81 ** OWN VARIABLE DECLARATIONS 82 ** 83 **/ 84 85 /* Keyword table pointer. */ 86 87 static key_keytable_entry_type * key_keytable_ptr; 88 89 90 /* 91 **++ 92 ** FUNCTIONAL DESCRIPTION: 93 ** 94 ** This routine searches for a symbol in the compiler's keyword table. 95 ** There are two arguments to the routine, the length of the symbol and 96 ** the address of the start of the symbol. The routine returns the 97 ** address of the keyword entry found, or a NULL pointer if the 98 ** symbol is not found in the table. 99 ** 100 ** The search for the symbol is case sensitive depending upon the 101 ** keytable binding that was established by the key_initialize routine. 102 ** 103 ** The require file UilKeyTab.h defines and initializes the keyword 104 ** tables. It is built automatically from other files, thus it should 105 ** not be hand editted. 106 ** 107 ** FORMAL PARAMETERS: 108 ** 109 ** symbol_length.rl.v : length of symbol to look up 110 ** symbol_ptr.ra.v : address of symbol to look up 111 ** 112 ** IMPLICIT INPUTS: 113 ** 114 ** key_keytable_ptr : current keyword table 115 ** 116 ** IMPLICIT OUTPUTS: 117 ** 118 ** none 119 ** 120 ** FUNCTION VALUE: 121 ** 122 ** NULL : if the symbol is not in the keyword table 123 ** otherwise : the address of the keyword table entry for 124 ** the specified symbol. 125 ** 126 ** SIDE EFFECTS: 127 ** 128 ** none 129 ** 130 **-- 131 **/ 132 key_keytable_entry_type * key_find_keyword(symbol_length,symbol_ptr)133 key_find_keyword (symbol_length, symbol_ptr) 134 135 unsigned int symbol_length; 136 char * symbol_ptr; 137 138 { 139 140 int 141 lower_limit, 142 upper_limit; 143 144 /* Check the arguments. */ 145 146 if (symbol_length > key_k_keyword_max_length) 147 return NULL; 148 149 /* Initialize region to search. */ 150 151 lower_limit = 0; 152 upper_limit = key_k_keyword_count-1; 153 154 /* Perform binary search on keyword index. */ 155 156 do { 157 int mid_point, result; 158 159 key_keytable_entry_type * keyword_entry_ptr; 160 161 mid_point = (lower_limit + upper_limit) >> 1; /* divide by 2 */ 162 163 keyword_entry_ptr = & key_keytable_ptr [mid_point]; 164 165 result = strcmp (symbol_ptr, keyword_entry_ptr -> at_name); 166 167 if (result == 0) { 168 return keyword_entry_ptr; /* Found keyword. */ 169 } else if (result < 0) { 170 upper_limit = mid_point - 1; /* Search lower half. */ 171 } else { 172 lower_limit = mid_point + 1; /* Search upper half. */ 173 } 174 175 } while (lower_limit <= upper_limit); 176 177 /* If we fall out of the bottom of the loop, symbol was not found. */ 178 179 return NULL; 180 181 } 182 183 /* 184 **++ 185 ** FUNCTIONAL DESCRIPTION: 186 ** 187 ** This routine initializes the keyword lookup facility. It can be 188 ** called multiple times during a single compilation. It must be called 189 ** at least once before the keyword table is accessed. 190 ** 191 ** FORMAL PARAMETERS: 192 ** 193 ** none 194 ** 195 ** IMPLICIT INPUTS: 196 ** 197 ** uil_v_case_sensitive : case sensitive switch, determines which 198 ** : keyword table to use. 199 ** 200 ** IMPLICIT OUTPUTS: 201 ** 202 ** key_keytable_ptr : pointer to the keyword table to 203 ** use for keyword lookups. 204 ** 205 ** FUNCTION VALUE: 206 ** 207 ** none 208 ** 209 ** SIDE EFFECTS: 210 ** 211 ** none 212 ** 213 **-- 214 **/ 215 void key_initialize()216 key_initialize () 217 218 { 219 220 /* Use the correct keyword table based on the global case 221 sensitivity. */ 222 223 if (uil_v_case_sensitive) { 224 key_keytable_ptr = key_table; 225 } else { 226 key_keytable_ptr = key_table_case_ins; 227 } 228 229 } 230 231