Blame lib/Mrm/Mrmtable.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 HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: Mrmtable.c /main/13 1996/11/13 14:04:22 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *  FACILITY:
Packit b099d7
 *
Packit b099d7
 *      UIL Manager (URM)
Packit b099d7
 *
Packit b099d7
 *  ABSTRACT:
Packit b099d7
 *
Packit b099d7
 *      This module contains the keyword tables and functions used by to
Packit b099d7
 *	support the compressing and uncompressing of strings in URM.
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 <X11/Intrinsic.h>
Packit b099d7
#include <Mrm/MrmAppl.h>
Packit b099d7
#include <Mrm/Mrm.h>
Packit b099d7
#include "MrmMsgI.h"
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  TABLE of CONTENTS
Packit b099d7
 *
Packit b099d7
 *	Urm__FixupCompressionTable	make table memory resident
Packit b099d7
 *
Packit b099d7
 *	Urm__FindClassDescriptor	find descriptor in file/memory
Packit b099d7
 *
Packit b099d7
 *	Urm__UncompressCode		uncompress a code
Packit b099d7
 *
Packit b099d7
 *	Urm__IsSubtreeResource		predicate for subtree resources
Packit b099d7
 */
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  FUNCTIONAL DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine fixes up a file-based compression table. It resolves
Packit b099d7
 *	offsets into memory pointers. If requested, it then looks up
Packit b099d7
 *	each resulting string and attempts to replace it with a
Packit b099d7
 *	function pointer (from the function hash table).
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	ctable		the compression table to fix up
Packit b099d7
 *	qfindcldesc	if TRUE, attempt to look up the strings as
Packit b099d7
 *			indexes of class descriptors
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *      none
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	if all fixup operations succeed
Packit b099d7
 *	MrmFAILURE	if any operation fails (usually function lookup)    
Packit b099d7
 *
Packit b099d7
 * SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *	none
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
Urm__FixupCompressionTable (UidCompressionTablePtr	ctable,
Packit b099d7
			    Boolean			qfindcldesc,
Packit b099d7
			    Boolean			byte_swapped)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  int			fixndx ;	/* table fixup loop index */
Packit b099d7
  Cardinal		result = MrmSUCCESS;
Packit b099d7
  WCIClassDescPtr	cldesc;		/* for class descriptor */
Packit b099d7
  Cardinal		clres;		/* lookup result */
Packit b099d7
  /*
Packit b099d7
   * Swap bytes if necessary and fix up the table offsets to be pointers
Packit b099d7
   */
Packit b099d7
  if ( byte_swapped )
Packit b099d7
    {
Packit b099d7
      swapbytes(ctable->validation);
Packit b099d7
      swapbytes(ctable->num_entries);
Packit b099d7
    }
Packit b099d7
  for ( fixndx=UilMrmMinValidCode ; fixndx<ctable->num_entries ; fixndx++ )
Packit b099d7
    {
Packit b099d7
      if ( byte_swapped ) swapbytes(ctable->entry[fixndx].stoffset);
Packit b099d7
      ctable->entry[fixndx].cstring = 
Packit b099d7
	((char *)ctable+ctable->entry[fixndx].stoffset);
Packit b099d7
    }	
Packit b099d7
  /*
Packit b099d7
   * Look up each string as a function if requested
Packit b099d7
   */
Packit b099d7
  if ( qfindcldesc )
Packit b099d7
    for ( fixndx=UilMrmMinValidCode ; fixndx<ctable->num_entries ; fixndx++ )
Packit b099d7
      {
Packit b099d7
	clres = Urm__WCI_LookupClassDescriptor
Packit b099d7
	  (ctable->entry[fixndx].cstring, &cldesc);
Packit b099d7
	if ( clres == MrmSUCCESS )
Packit b099d7
	  ctable->entry[fixndx].cldesc = cldesc;
Packit b099d7
	else
Packit b099d7
	  {
Packit b099d7
	    ctable->entry[fixndx].cldesc = NULL;
Packit b099d7
	    result = MrmFAILURE;
Packit b099d7
	  }
Packit b099d7
      }
Packit b099d7
Packit b099d7
  return result;
Packit b099d7
Packit b099d7
}    
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  FUNCTIONAL DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine finds a class descriptor corresponding to a class
Packit b099d7
 *	compression code or name. It looks up the class in the file's
Packit b099d7
 *	compression table if possible. Otherwise, it uses the older built-in
Packit b099d7
 *	tables.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	cfile		IDB file in which to find compression table
Packit b099d7
 *	code		compression code to be uncompressed
Packit b099d7
 *	name		the class name; the convenience function name.
Packit b099d7
 *	class_return	to return the class descriptor
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *      none
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	if class descriptor found
Packit b099d7
 *	MrmFAILURE	otherwise
Packit b099d7
 *
Packit b099d7
 * SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *	none
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
Urm__FindClassDescriptor (IDBFile		cfile,
Packit b099d7
			  MrmCode		code,
Packit b099d7
			  char			*name,
Packit b099d7
			  WCIClassDescPtr	*class_return)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Use the built-in tables if the file has none. Else a simple lookup.
Packit b099d7
   */
Packit b099d7
  if ( code == UilMrmUnknownCode )
Packit b099d7
    return Urm__WCI_LookupClassDescriptor (name, class_return);
Packit b099d7
  if ( cfile->class_ctable == NULL )
Packit b099d7
    return Urm__UT_Error ("Urm__FindClassDescriptor", _MrmMMsg_0050,
Packit b099d7
			  NULL, NULL, MrmFAILURE);
Packit b099d7
  if ( code < UilMrmMinValidCode )
Packit b099d7
    return MrmFAILURE;
Packit b099d7
  if ( code >= cfile->class_ctable->num_entries )
Packit b099d7
    return MrmFAILURE;
Packit b099d7
  *class_return = cfile->class_ctable->entry[code].cldesc;
Packit b099d7
  if ( *class_return == NULL )
Packit b099d7
    return MrmFAILURE;
Packit b099d7
  return MrmSUCCESS;
Packit b099d7
Packit b099d7
}    
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  FUNCTIONAL DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine returns the string corresponding to a compression code.
Packit b099d7
 *	It looks up the code in the file's compression table if it has
Packit b099d7
 *	one, else falls back on the old built-in tables. The code is looked
Packit b099d7
 *	up in the resource tables.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	cfile		IDB file in which to find compression table
Packit b099d7
 *	code		compression code to be uncompressed
Packit b099d7
 *	stg_return	to return result of uncompression
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *      none
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	if uncompression successful
Packit b099d7
 *	MrmFAILURE	otherwise
Packit b099d7
 *
Packit b099d7
 * SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *	none
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal
Packit b099d7
Urm__UncompressCode (IDBFile			cfile,
Packit b099d7
		     MrmCode			code,
Packit b099d7
		     String			*stg_return)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * A simple lookup in the file's compression tables.
Packit b099d7
   */
Packit b099d7
  if ( cfile->resource_ctable == NULL )
Packit b099d7
    return Urm__UT_Error ("Urm__UncompressCode", _MrmMMsg_0050,
Packit b099d7
			  NULL, NULL, MrmFAILURE);
Packit b099d7
  if ( code < UilMrmMinValidCode )
Packit b099d7
    return MrmFAILURE;
Packit b099d7
  if ( code >= cfile->resource_ctable->num_entries )
Packit b099d7
    return MrmFAILURE;
Packit b099d7
  *stg_return = cfile->resource_ctable->entry[code].cstring;
Packit b099d7
  return MrmSUCCESS;
Packit b099d7
Packit b099d7
}    
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  FUNCTIONAL DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine checks to see if a resource is marked as rooting a
Packit b099d7
 *	widget subtree, that is, is a resource which requires that a
Packit b099d7
 *	widget subtree be instantiated as its value.
Packit b099d7
 *
Packit b099d7
 *	Initial version uses crude check. To be replaced by table lookup.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	cfile		file containing table information
Packit b099d7
 *	code		code to be checked
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *      none
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	TRUE		if subtree value is required
Packit b099d7
 *	FALSE		otherwise
Packit b099d7
 *
Packit b099d7
 * SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *	none
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean 
Packit b099d7
Urm__IsSubtreeResource (IDBFile			cfile,
Packit b099d7
			MrmCode			code)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Do a string comparison for for the subtree resources.
Packit b099d7
   */
Packit b099d7
  if ( code < UilMrmMinValidCode )
Packit b099d7
    return FALSE;
Packit b099d7
  if ( code >= cfile->resource_ctable->num_entries )
Packit b099d7
    return FALSE;
Packit b099d7
Packit b099d7
  if ( strcmp(cfile->resource_ctable->entry[code].cstring,XmNsubMenuId) == 0 )
Packit b099d7
    return TRUE;
Packit b099d7
  return FALSE;
Packit b099d7
Packit b099d7
}    
Packit b099d7
Packit b099d7