UilKeyTab.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-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. /*
  24. * @OSF_COPYRIGHT@
  25. * COPYRIGHT NOTICE
  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.
  29. */
  30. /*
  31. * HISTORY
  32. */
  33. #ifdef REV_INFO
  34. #ifndef lint
  35. static char rcsid[] = "$XConsortium: UilKeyTab.c /main/11 1995/07/14 09:34:29 drk $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. **++
  42. ** FACILITY:
  43. **
  44. ** User Interface Language Compiler (UIL)
  45. **
  46. ** ABSTRACT:
  47. **
  48. ** This module contains the keyword table used by the lexical analyzer
  49. ** to look up the keywords in the UIL.
  50. **
  51. **--
  52. **/
  53. /*
  54. **
  55. ** INCLUDE FILES
  56. **
  57. **/
  58. #include "UilDefI.h"
  59. /*
  60. **
  61. ** DEFINE and MACRO DEFINITIONS
  62. **
  63. **/
  64. /*
  65. **
  66. ** EXTERNAL VARIABLE DECLARATIONS
  67. **
  68. **/
  69. /*
  70. **
  71. ** GLOBAL VARIABLE DECLARATIONS
  72. **
  73. **/
  74. /*
  75. **
  76. ** OWN VARIABLE DECLARATIONS
  77. **
  78. **/
  79. /* Keyword table pointer. */
  80. static key_keytable_entry_type * key_keytable_ptr;
  81. /*
  82. **++
  83. ** FUNCTIONAL DESCRIPTION:
  84. **
  85. ** This routine searches for a symbol in the compiler's keyword table.
  86. ** There are two arguments to the routine, the length of the symbol and
  87. ** the address of the start of the symbol. The routine returns the
  88. ** address of the keyword entry found, or a NULL pointer if the
  89. ** symbol is not found in the table.
  90. **
  91. ** The search for the symbol is case sensitive depending upon the
  92. ** keytable binding that was established by the key_initialize routine.
  93. **
  94. ** The require file UilKeyTab.h defines and initializes the keyword
  95. ** tables. It is built automatically from other files, thus it should
  96. ** not be hand editted.
  97. **
  98. ** FORMAL PARAMETERS:
  99. **
  100. ** symbol_length.rl.v : length of symbol to look up
  101. ** symbol_ptr.ra.v : address of symbol to look up
  102. **
  103. ** IMPLICIT INPUTS:
  104. **
  105. ** key_keytable_ptr : current keyword table
  106. **
  107. ** IMPLICIT OUTPUTS:
  108. **
  109. ** none
  110. **
  111. ** FUNCTION VALUE:
  112. **
  113. ** NULL : if the symbol is not in the keyword table
  114. ** otherwise : the address of the keyword table entry for
  115. ** the specified symbol.
  116. **
  117. ** SIDE EFFECTS:
  118. **
  119. ** none
  120. **
  121. **--
  122. **/
  123. key_keytable_entry_type *
  124. key_find_keyword (symbol_length, symbol_ptr)
  125. unsigned int symbol_length;
  126. char * symbol_ptr;
  127. {
  128. int
  129. lower_limit,
  130. upper_limit;
  131. /* Check the arguments. */
  132. if (symbol_length > key_k_keyword_max_length)
  133. return NULL;
  134. /* Initialize region to search. */
  135. lower_limit = 0;
  136. upper_limit = key_k_keyword_count-1;
  137. /* Perform binary search on keyword index. */
  138. do {
  139. int mid_point, result;
  140. key_keytable_entry_type * keyword_entry_ptr;
  141. mid_point = (lower_limit + upper_limit) >> 1; /* divide by 2 */
  142. keyword_entry_ptr = & key_keytable_ptr [mid_point];
  143. result = strcmp (symbol_ptr, keyword_entry_ptr -> at_name);
  144. if (result == 0) {
  145. return keyword_entry_ptr; /* Found keyword. */
  146. } else if (result < 0) {
  147. upper_limit = mid_point - 1; /* Search lower half. */
  148. } else {
  149. lower_limit = mid_point + 1; /* Search upper half. */
  150. }
  151. } while (lower_limit <= upper_limit);
  152. /* If we fall out of the bottom of the loop, symbol was not found. */
  153. return NULL;
  154. }
  155. /*
  156. **++
  157. ** FUNCTIONAL DESCRIPTION:
  158. **
  159. ** This routine initializes the keyword lookup facility. It can be
  160. ** called multiple times during a single compilation. It must be called
  161. ** at least once before the keyword table is accessed.
  162. **
  163. ** FORMAL PARAMETERS:
  164. **
  165. ** none
  166. **
  167. ** IMPLICIT INPUTS:
  168. **
  169. ** uil_v_case_sensitive : case sensitive switch, determines which
  170. ** : keyword table to use.
  171. **
  172. ** IMPLICIT OUTPUTS:
  173. **
  174. ** key_keytable_ptr : pointer to the keyword table to
  175. ** use for keyword lookups.
  176. **
  177. ** FUNCTION VALUE:
  178. **
  179. ** none
  180. **
  181. ** SIDE EFFECTS:
  182. **
  183. ** none
  184. **
  185. **--
  186. **/
  187. void
  188. key_initialize ()
  189. {
  190. /* Use the correct keyword table based on the global case
  191. sensitivity. */
  192. if (uil_v_case_sensitive) {
  193. key_keytable_ptr = key_table;
  194. } else {
  195. key_keytable_ptr = key_table_case_ins;
  196. }
  197. }