Blame clients/uil/UilKeyTab.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
*/ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
*/ 
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: UilKeyTab.c /main/11 1995/07/14 09:34:29 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
*  (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
Packit b099d7
Packit b099d7
/*
Packit b099d7
**++
Packit b099d7
**  FACILITY:
Packit b099d7
**
Packit b099d7
**      User Interface Language Compiler (UIL)
Packit b099d7
**
Packit b099d7
**  ABSTRACT:
Packit b099d7
**
Packit b099d7
**      This module contains the keyword table used by the lexical analyzer
Packit b099d7
**	to look up the keywords in the UIL.
Packit b099d7
**
Packit b099d7
**--
Packit b099d7
**/
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
**
Packit b099d7
**  INCLUDE FILES
Packit b099d7
**
Packit b099d7
**/
Packit b099d7
Packit b099d7
#include "UilDefI.h"
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
**
Packit b099d7
**  DEFINE and MACRO DEFINITIONS
Packit b099d7
**
Packit b099d7
**/
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
**
Packit b099d7
**  EXTERNAL VARIABLE DECLARATIONS
Packit b099d7
**
Packit b099d7
**/
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
**
Packit b099d7
**  GLOBAL VARIABLE DECLARATIONS
Packit b099d7
**
Packit b099d7
**/
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
**
Packit b099d7
**  OWN VARIABLE DECLARATIONS
Packit b099d7
**
Packit b099d7
**/
Packit b099d7
Packit b099d7
/*    Keyword table pointer.    */
Packit b099d7
Packit b099d7
static key_keytable_entry_type * key_keytable_ptr;
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
**++
Packit b099d7
**  FUNCTIONAL DESCRIPTION:
Packit b099d7
**
Packit b099d7
**	This routine searches for a symbol in the compiler's keyword table.
Packit b099d7
**	There are two arguments to the routine, the length of the symbol and
Packit b099d7
**      the address of the start of the symbol.  The routine returns the
Packit b099d7
**	address of the keyword entry found, or a NULL pointer if the
Packit b099d7
**	symbol is not found in the table.
Packit b099d7
**
Packit b099d7
**	The search for the symbol is case sensitive depending upon the
Packit b099d7
**	keytable binding that was established by the key_initialize routine.
Packit b099d7
**
Packit b099d7
**	The require file UilKeyTab.h defines and initializes the keyword
Packit b099d7
**	tables.  It is built automatically from other files, thus it should
Packit b099d7
**	not be hand editted.
Packit b099d7
**
Packit b099d7
**  FORMAL PARAMETERS:
Packit b099d7
**
Packit b099d7
**	symbol_length.rl.v : 	length of symbol to look up
Packit b099d7
**	symbol_ptr.ra.v : 	address of symbol to look up
Packit b099d7
**
Packit b099d7
**  IMPLICIT INPUTS:
Packit b099d7
**
Packit b099d7
**      key_keytable_ptr		: current keyword table
Packit b099d7
**
Packit b099d7
**  IMPLICIT OUTPUTS:
Packit b099d7
**
Packit b099d7
**      none
Packit b099d7
**
Packit b099d7
**  FUNCTION VALUE:
Packit b099d7
**
Packit b099d7
**	NULL		: if the symbol is not in the keyword table
Packit b099d7
**	otherwise	: the address of the keyword table entry for
Packit b099d7
**			  the specified symbol.
Packit b099d7
**
Packit b099d7
** SIDE EFFECTS:
Packit b099d7
**
Packit b099d7
**	none
Packit b099d7
**
Packit b099d7
**--
Packit b099d7
**/
Packit b099d7
key_keytable_entry_type *
Packit b099d7
	key_find_keyword (symbol_length, symbol_ptr)
Packit b099d7
Packit b099d7
unsigned int	symbol_length;
Packit b099d7
char		* symbol_ptr;
Packit b099d7
Packit b099d7
{
Packit b099d7
    
Packit b099d7
    int
Packit b099d7
	lower_limit,
Packit b099d7
	upper_limit;
Packit b099d7
    
Packit b099d7
/*    Check the arguments.    */
Packit b099d7
Packit b099d7
    if (symbol_length > key_k_keyword_max_length)
Packit b099d7
	return NULL;
Packit b099d7
Packit b099d7
/*    Initialize region to search.    */
Packit b099d7
    
Packit b099d7
    lower_limit = 0;
Packit b099d7
    upper_limit = key_k_keyword_count-1;
Packit b099d7
    
Packit b099d7
/*    Perform binary search on keyword index.    */
Packit b099d7
    
Packit b099d7
    do {
Packit b099d7
	int		mid_point, result;
Packit b099d7
Packit b099d7
	key_keytable_entry_type * keyword_entry_ptr;
Packit b099d7
Packit b099d7
	mid_point = (lower_limit + upper_limit) >> 1;	/* divide by 2 */
Packit b099d7
Packit b099d7
	keyword_entry_ptr = & key_keytable_ptr [mid_point];
Packit b099d7
Packit b099d7
	result = strcmp (symbol_ptr, keyword_entry_ptr -> at_name);
Packit b099d7
Packit b099d7
	if (result == 0) {
Packit b099d7
	    return keyword_entry_ptr;		/*    Found keyword.    */
Packit b099d7
	} else if (result < 0) {
Packit b099d7
	    upper_limit = mid_point - 1;	/*    Search lower half.    */
Packit b099d7
	} else {
Packit b099d7
	    lower_limit = mid_point + 1;	/*    Search upper half.    */
Packit b099d7
	}
Packit b099d7
Packit b099d7
    } while (lower_limit <= upper_limit);
Packit b099d7
Packit b099d7
/*    If we fall out of the bottom of the loop, symbol was not found.    */
Packit b099d7
Packit b099d7
    return NULL;
Packit b099d7
Packit b099d7
}
Packit b099d7

Packit b099d7
/*
Packit b099d7
**++
Packit b099d7
**  FUNCTIONAL DESCRIPTION:
Packit b099d7
**
Packit b099d7
**	This routine initializes the keyword lookup facility.  It can be
Packit b099d7
**	called multiple times during a single compilation.  It must be called
Packit b099d7
**	at least once before the keyword table is accessed.
Packit b099d7
**
Packit b099d7
**  FORMAL PARAMETERS:
Packit b099d7
**
Packit b099d7
**	none
Packit b099d7
**
Packit b099d7
**  IMPLICIT INPUTS:
Packit b099d7
**
Packit b099d7
**      uil_v_case_sensitive	: case sensitive switch, determines which
Packit b099d7
**				: keyword table to use.
Packit b099d7
**
Packit b099d7
**  IMPLICIT OUTPUTS:
Packit b099d7
**
Packit b099d7
**      key_keytable_ptr	: pointer to the keyword table to
Packit b099d7
**				  use for keyword lookups.
Packit b099d7
**
Packit b099d7
**  FUNCTION VALUE:
Packit b099d7
**
Packit b099d7
**	none
Packit b099d7
**
Packit b099d7
** SIDE EFFECTS:
Packit b099d7
**
Packit b099d7
**	none
Packit b099d7
**
Packit b099d7
**--
Packit b099d7
**/
Packit b099d7
void
Packit b099d7
	key_initialize ()
Packit b099d7
Packit b099d7
{
Packit b099d7
Packit b099d7
/*    Use the correct keyword table based on the global case
Packit b099d7
      sensitivity.   */
Packit b099d7
Packit b099d7
    if (uil_v_case_sensitive) {
Packit b099d7
	key_keytable_ptr = key_table;
Packit b099d7
    } else {
Packit b099d7
	key_keytable_ptr = key_table_case_ins;
Packit b099d7
    }
Packit b099d7
Packit b099d7
}    
Packit b099d7