2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
26 * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
27 * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
28 * the full copyright text.
35 static char rcsid[] = "$XConsortium: UilKeyTab.c /main/11 1995/07/14 09:34:29 drk $"
40 * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
46 ** User Interface Language Compiler (UIL)
50 ** This module contains the keyword table used by the lexical analyzer
51 ** to look up the keywords in the UIL.
68 ** DEFINE and MACRO DEFINITIONS
75 ** EXTERNAL VARIABLE DECLARATIONS
82 ** GLOBAL VARIABLE DECLARATIONS
89 ** OWN VARIABLE DECLARATIONS
93 /* Keyword table pointer. */
95 static key_keytable_entry_type * key_keytable_ptr;
100 ** FUNCTIONAL DESCRIPTION:
102 ** This routine searches for a symbol in the compiler's keyword table.
103 ** There are two arguments to the routine, the length of the symbol and
104 ** the address of the start of the symbol. The routine returns the
105 ** address of the keyword entry found, or a NULL pointer if the
106 ** symbol is not found in the table.
108 ** The search for the symbol is case sensitive depending upon the
109 ** keytable binding that was established by the key_initialize routine.
111 ** The require file UilKeyTab.h defines and initializes the keyword
112 ** tables. It is built automatically from other files, thus it should
113 ** not be hand editted.
115 ** FORMAL PARAMETERS:
117 ** symbol_length.rl.v : length of symbol to look up
118 ** symbol_ptr.ra.v : address of symbol to look up
122 ** key_keytable_ptr : current keyword table
130 ** NULL : if the symbol is not in the keyword table
131 ** otherwise : the address of the keyword table entry for
132 ** the specified symbol.
140 key_keytable_entry_type *
141 key_find_keyword (symbol_length, symbol_ptr)
143 unsigned int symbol_length;
152 /* Check the arguments. */
154 if (symbol_length > key_k_keyword_max_length)
157 /* Initialize region to search. */
160 upper_limit = key_k_keyword_count-1;
162 /* Perform binary search on keyword index. */
165 int mid_point, result;
167 key_keytable_entry_type * keyword_entry_ptr;
169 mid_point = (lower_limit + upper_limit) >> 1; /* divide by 2 */
171 keyword_entry_ptr = & key_keytable_ptr [mid_point];
173 result = strcmp (symbol_ptr, keyword_entry_ptr -> at_name);
176 return keyword_entry_ptr; /* Found keyword. */
177 } else if (result < 0) {
178 upper_limit = mid_point - 1; /* Search lower half. */
180 lower_limit = mid_point + 1; /* Search upper half. */
183 } while (lower_limit <= upper_limit);
185 /* If we fall out of the bottom of the loop, symbol was not found. */
193 ** FUNCTIONAL DESCRIPTION:
195 ** This routine initializes the keyword lookup facility. It can be
196 ** called multiple times during a single compilation. It must be called
197 ** at least once before the keyword table is accessed.
199 ** FORMAL PARAMETERS:
205 ** uil_v_case_sensitive : case sensitive switch, determines which
206 ** : keyword table to use.
210 ** key_keytable_ptr : pointer to the keyword table to
211 ** use for keyword lookups.
228 /* Use the correct keyword table based on the global case
231 if (uil_v_case_sensitive) {
232 key_keytable_ptr = key_table;
234 key_keytable_ptr = key_table_case_ins;