From 27ebab2255a9f0f58c8cb5cfdefcf535ee720914 Mon Sep 17 00:00:00 2001 From: Packit Date: Sep 15 2020 17:35:16 +0000 Subject: Apply patch motif-2.3.4-Fix-issues-with-Werror-format-security.patch patch_name: motif-2.3.4-Fix-issues-with-Werror-format-security.patch present_in_specfile: true --- diff --git a/lib/Mrm/Mrmhier.c b/lib/Mrm/Mrmhier.c index 2712742..2a8703c 100644 --- a/lib/Mrm/Mrmhier.c +++ b/lib/Mrm/Mrmhier.c @@ -264,10 +264,10 @@ Urm__OpenHierarchy (MrmCount num_files, case MrmSUCCESS: break; case MrmNOT_VALID: - sprintf (err_stg, _MrmMMsg_0113); + sprintf (err_stg, "%s", _MrmMMsg_0113); break; default: - sprintf (err_stg, _MrmMMsg_0114); + sprintf (err_stg, "%s", _MrmMMsg_0114); break; } } diff --git a/lib/Mrm/Mrmhier.c.format-security b/lib/Mrm/Mrmhier.c.format-security new file mode 100644 index 0000000..2712742 --- /dev/null +++ b/lib/Mrm/Mrmhier.c.format-security @@ -0,0 +1,779 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* + * HISTORY + */ +#ifdef HAVE_CONFIG_H +#include +#endif + + +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$XConsortium: Mrmhier.c /main/17 1996/11/13 14:01:19 drk $" +#endif +#endif + +/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + + +/* + *++ + * FACILITY: + * + * UIL Resource Manager (URM): + * + * ABSTRACT: + * + *-- + */ + +/* + * This file contains routines which assist in managing URM hierarchies + */ + + +/* + * + * INCLUDE FILES + * + */ + +#include +#include +#include + +#include /* for _XmOSInitPath() */ +#include /* for _XmGetDefaultDisplay() */ + +#include "MrmMsgI.h" + +#ifndef NO_MESSAGE_CATALOG +#if !defined(NL_CAT_LOCALE) +#define NL_CAT_LOCALE 0 +#endif +#endif + + +/* + * + * TABLE OF CONTENTS + * + * Urm__OpenHierarchy Open hierarchy (internal version) + * + * Urm__CloseHierarchy Close hierarchy (internal version) + * + * UrmHGetIndexedResource Get resource from hierarchy + * + */ + + +/* + * + * DEFINE and MACRO DEFINITIONS + * + */ + +static Cardinal I18NOpenFile (Display *display, + String name , + MrmOsOpenParamPtr os_ext , + IDBFile *file_id_return ); + + +/* + * + * OWN VARIABLE DECLARATIONS + * + */ +static char *uidPath; +static SubstitutionRec uidSubs[1]; + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine allocates a hierarchy descriptor, and opens + * all the IDB files in the hierarchy. It initializes the + * optimized search lists in the hierarchy from the open files. + * All files are closed if there are any errors. + * + * FORMAL PARAMETERS: + * + * num_files The number of files in the name list + * name_list A list of the file names + * os_ext_list A list of system-dependent ancillary + * structures corresponding to the files. + * This parameter may be NULL. + * hierarchy_id_return To return the hierarchy id + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmFAILURE allocation or other failure + * MrmDISPLAY_NOT_OPENED Display hasn't been opened yet + * Others see UrmIdbOpenFileRead + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__OpenHierarchy (MrmCount num_files, + String *name_list, + MrmOsOpenParamPtr *os_ext_list, + MrmHierarchy *hierarchy_id_return, + MrmFlag in_memory, + unsigned char *uid_buffer) +{ + + /* + * Local variables + */ + Cardinal result ; /* function result */ + MrmHierarchy hiptr ; /* hierarchy descriptor */ + MrmCount list_size ; /* # bytes for file lists */ + int ndx ; /* loop index */ + IDBFile *idvec ; /* current file id vector */ + int file_ndx ; /* file loop index */ + IDBFile cur_file ; /* current IDB file */ + URMResourceContextPtr class_ctx; /* for class compression table */ + URMResourceContextPtr resource_ctx; /* for resource compression table */ + Display *display; /* display for XtResolvePathNames */ + char err_stg[300]; + +#ifndef NO_MESSAGE_CATALOG + static Boolean first = True; + + /* + * We open the message catalog from MrmOpenHierarchy... routines. + * We cannot open it from MrmInitialize, since this call can be done + * before Xt has been initialized, so at that time the locale could + * be wrong. + */ + + /* We only want to open the message catalog once. */ + + if (first) + { + Mrm_catd = catopen("Mrm", NL_CAT_LOCALE); + first = False; + } +#endif + + if ( os_ext_list == NULL ) + { + display = NULL; + } + else + { + MrmOsOpenParamPtr os_data; + os_data = *os_ext_list; + if (os_data->display == NULL) + { + display = NULL; + } + else + { + display = os_data->display; + } + } + + if (display == NULL) + { + display = _XmGetDefaultDisplay(); + } + + if (display == NULL) + { + return Urm__UT_Error ("Urm__OpenHierarchy", _MrmMMsg_0030, + NULL, NULL, MrmDISPLAY_NOT_OPENED); + }; + + /* + * If the uidPath was previously set, XtFree it so we can try any + * new paths that may have been setup. + */ + if (uidPath != 0) + { + XtFree (uidPath); + uidPath = 0; + } + + /* + * Allocate a hierarchy, and allocate all file lists. + */ + hiptr = (MrmHierarchy) XtMalloc (sizeof(MrmHierarchyDesc)) ; + if ( hiptr == NULL ) return MrmFAILURE ; + + hiptr->validation = MrmHIERARCHY_VALID; + hiptr->num_file = 0 ; + + list_size = num_files * sizeof(IDBFile) ; + hiptr->file_list = (IDBFile *) XtMalloc (list_size) ; + if ( hiptr->file_list == NULL ) return MrmFAILURE ; + + for ( ndx=URMgMin ; ndx<=URMgMax ; ndx++ ) + { + hiptr->grp_num[ndx] = 0 ; + idvec = (IDBFile *) XtMalloc (list_size) ; + if ( idvec == NULL ) return MrmFAILURE ; + hiptr->grp_ids[ndx] = idvec ; + } + + hiptr->name_registry = NULL; + + /* + * Now open each file. Any failure causes an error return, with any + * open files closed and the descriptor and lists freed. + */ + for ( file_ndx=0 ; file_ndxfile_list[hiptr->num_file] = cur_file ; + hiptr->num_file++ ; + for ( ndx=URMgMin ; ndx<=URMgMax ; ndx++ ) + if ( cur_file->group_counts[ndx] > 0 ) + { + idvec = hiptr->grp_ids[ndx] ; + idvec[hiptr->grp_num[ndx]] = cur_file ; + hiptr->grp_num[ndx]++ ; + } + + /* + * Attempt to read in compression tables for this UID file. + * Retain and fixup the tables if they are found. + */ + cur_file->class_ctable = NULL; + cur_file->resource_ctable = NULL; + result = UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, + 0, &class_ctx); + if ( result != MrmSUCCESS ) return result; + result = UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, + 0, &resource_ctx); + if ( result != MrmSUCCESS ) return result; + result = UrmGetIndexedLiteral (cur_file, UilMrmClassTableIndex, + class_ctx); + if ( result != MrmSUCCESS ) continue; + result = UrmGetIndexedLiteral (cur_file, UilMrmResourceTableIndex, + resource_ctx); + if ( result != MrmSUCCESS ) continue; + + /* + * Retain the buffers from the contexts, but free the contexts + * themselves. Fixup the tables. + */ + cur_file->class_ctable = (UidCompressionTablePtr) + UrmRCBuffer (class_ctx); + UrmRCSetBuffer (class_ctx, NULL); + UrmFreeResourceContext (class_ctx); + Urm__FixupCompressionTable (cur_file->class_ctable, TRUE, + cur_file->byte_swapped); + cur_file->resource_ctable = (UidCompressionTablePtr) + UrmRCBuffer (resource_ctx); + UrmRCSetBuffer (resource_ctx, NULL); + UrmFreeResourceContext (resource_ctx); + Urm__FixupCompressionTable (cur_file->resource_ctable, FALSE, + cur_file->byte_swapped); + } + + /* + * successfully opened. Free the uidPath at this point + */ + XtFree (uidPath); + uidPath = 0; + *hierarchy_id_return = hiptr ; + return MrmSUCCESS ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This is the internal routine which closes a URM search hierarchy + * + * FORMAL PARAMETERS: + * + * hierarchy_id ID of an open URM database hierarchy + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_HIERARCHY invalid URM hierarchy + * MrmFAILURE operation failed, no further reason + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__CloseHierarchy (MrmHierarchy hierarchy_id) +{ + + /* + * Local variables + */ + int ndx ; /* loop index */ + URMHashTableEntryPtr cp, np; /* for fixing 7303 */ + + /* + * validity check the hierarchy, then close all files, deallocate all + * lists, and deallocate the descriptor + */ + if ( hierarchy_id == NULL ) + return Urm__UT_Error ("Urm__CloseHierarchy", _MrmMMsg_0023, + NULL, NULL, MrmBAD_HIERARCHY) ; + if ( ! MrmHierarchyValid(hierarchy_id) ) + return Urm__UT_Error ("Urm__CloseHierarchy", _MrmMMsg_0024, + NULL, NULL, MrmBAD_HIERARCHY) ; + + for ( ndx=0 ; ndxnum_file ; ndx++ ) + if (hierarchy_id->file_list[ndx]->in_memory == FALSE ) + UrmIdbCloseFile (hierarchy_id->file_list[ndx], FALSE) ; + + /* Begin fixing DTS 7303 */ + if(hierarchy_id->name_registry){ + for ( ndx=0 ; ndxname_registry[ndx]) != NULL) + while(cp){ + np = cp->az_next_entry; + XtFree((char*)cp); + cp = np; + }; + XtFree ((char*)hierarchy_id->name_registry); + } + /* End fixing DTS 7303 */ + + XtFree ((char*)hierarchy_id->file_list); + + for ( ndx=URMgMin ; ndx<=URMgMax ; ndx++ ) + XtFree ((char*)hierarchy_id->grp_ids[ndx]) ; + + hierarchy_id->validation = 0; + XtFree ((char*)hierarchy_id) ; + return MrmSUCCESS ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmHGetIndexedResource attempts to retrieve a resource + * from an open URM hierarchy. It functions exactly like + * UrmIdbGetIndexedResource except that it queries each file + * in the hierarchy in turn. It uses the optimized search lists + * where possible. + * + * FORMAL PARAMETERS: + * + * hierarchy_id open URM hierarchy to search + * index case-sensitive index for the entry to match + * group_filter if not null, entry found must match this group + * type_filter if not null, entry found must match this type + * context_id URM resource context to receieve data block + * file_id_return to return file in which resource was found + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_HIERARCHY invalid URM hierarchy + * MrmNOT_FOUND entry not found + * MrmWRONG_GROUP entry didn't match group filter + * MrmWRONG_TYPE entry didn't match type filter + * MrmFAILURE operation failed, no further reason + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmHGetIndexedResource (MrmHierarchy hierarchy_id, + String index , + MrmGroup group_filter, + MrmType type_filter, + URMResourceContextPtr context_id, + IDBFile *file_id_return) +{ + + /* + * Local variables + */ + Cardinal result ; /* function results */ + IDBFile *file_ids ; /* list of files to search */ + int num_ids ; /* number of entries in file_ids */ + int ndx ; /* loop index */ + + + /* + * Validate hierarchy. Then loop through the files which define the resource, + * searching for the desired resource. + */ + if ( hierarchy_id == NULL ) + return Urm__UT_Error ("UrmHGetIndexedResource", _MrmMMsg_0023, + NULL, NULL, MrmBAD_HIERARCHY) ; + if ( ! MrmHierarchyValid(hierarchy_id) ) + return Urm__UT_Error ("UrmHGetIndexedResource", _MrmMMsg_0024, + NULL, context_id, MrmBAD_HIERARCHY) ; + + if ( group_filter>=URMgMin && group_filter<=URMgMax) + { + file_ids = hierarchy_id->grp_ids[group_filter] ; + num_ids = hierarchy_id->grp_num[group_filter] ; + } + else + { + file_ids = hierarchy_id->file_list ; + num_ids = hierarchy_id->num_file ; + } + for ( ndx=0 ; ndxname_registry; + if ( name_table == NULL ) + { + name_table = (URMHashTableEntryPtr *) + XtMalloc(sizeof(URMHashTableEntryPtr)*k_hash_table_size); + /* Begin fixing DTS 7303 */ + for ( ndx=0 ; ndxname_registry = name_table; + hash_initialize (name_table, &inited); + } + + /* + * Store each name-value pair in the hash table. + */ + for (ndx = 0 ; ndx < num_cb ; ndx++) + { + current_name = names [ndx]; + current_value = values [ndx]; + hash_entry = (URMHashTableEntryPtr) + hash_insert_name (name_table, current_name); + hash_entry->az_value = current_value; + } + + return MrmSUCCESS; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine returns the value registered for a name. It first + * attempts to look up the name in the hierarchy's name registry. + * If that fails, or their is no registry, then a global lookup is + * attempted. + * + * FORMAL PARAMETERS: + * + * hierarchy_id open URM hierarchy to search. + * name case-sensitive name to be matched + * value_return to return value. + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmNOT_FOUND no match found + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__LookupNameInHierarchy (MrmHierarchy hierarchy_id, + String name, + XtPointer *value_return) + +{ + + URMHashTableEntryPtr *name_table; + URMHashTableEntryPtr hash_entry; + + + /* + * Look up in hierarchy first (if there is a registry) + */ + name_table = hierarchy_id->name_registry; + if ( name_table != NULL ) + { + hash_entry = (URMHashTableEntryPtr) hash_find_name (name_table, name); + if (hash_entry != NULL) + { + *value_return = hash_entry->az_value; + return MrmSUCCESS; + } + } + + /* + * Fall back on global table + */ + return Urm__WCI_LookupRegisteredName (name, value_return); + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine opens a single UID file in a platform-dependent way, + * performing i18n language switching in order to do so. + * + * Per the latest agreement on semantics, this routine does: + * - first, try to open in the local directory (that is, with + * no switching). + * - second, try language switching and open + * + * FORMAL PARAMETERS: + * + * name A system-dependent string specifying the IDB file + * to be opened. + * os_ext An operating-system specific structure which + * supports using specific file system features + * file_id_return returns the IDB file id used in all other IDB routines + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +static Cardinal +I18NOpenFile (Display *display, + String name, + MrmOsOpenParamPtr os_ext, + IDBFile *file_id_return) +{ + + /* + * Local variables + */ + Cardinal result; /* function results */ + char dummy[300]; /* file name (unused) */ + char err_stg[300]; + + /* + * Use XtResolvePathName. If the last 4 characters of the file name + * are not .uid then pass in the suffix of .uid. If a file is not + * found with the suffix passed in then try without the suffix. + */ + char *resolvedname; /* current resolved name */ + Boolean user_path ; + + uidSubs[0].substitution = name; + + if (uidPath == 0) + { + uidPath = _XmOSInitPath(name, "UIDPATH", &user_path); + if (user_path) uidSubs[0].match = 'U'; + else uidSubs[0].match = MATCH_CHAR ; + } + + resolvedname = 0; + + /* + * Check and see if the .uid suffix is already on the file. If not then try to + * resolve the pathname with .uid suffix first. If that fails or the suffix is + * already on the file then just try to resolve the pathname. + */ + if ( strcmp (&name[strlen(name)-4],".uid") != 0 ) + resolvedname = XtResolvePathname (display, + "uid", + NULL, + ".uid", + uidPath, + uidSubs, + XtNumber(uidSubs), + (XtFilePredicate)NULL); + + /* + * No .uid suffix or a failure to resolve the pathname with the .uid suffix + */ + if (resolvedname == 0) + resolvedname = XtResolvePathname (display, + "uid", + NULL, + NULL, + uidPath, + uidSubs, + XtNumber(uidSubs), + (XtFilePredicate)NULL); + + if (resolvedname == 0) + { + sprintf (err_stg, _MrmMMsg_0031, name) ; + return Urm__UT_Error ("I18NOpenFile", err_stg, NULL, NULL, MrmNOT_FOUND); + } + + result = UrmIdbOpenFileRead (resolvedname, os_ext, file_id_return, dummy) ; + switch ( result ) + { + case MrmSUCCESS: + break; + case MrmNOT_VALID: + sprintf (err_stg, _MrmMMsg_0032, resolvedname) ; + break; + case MrmNOT_FOUND: + default: + sprintf (err_stg, _MrmMMsg_0031, resolvedname) ; + break; + } + + XtFree(resolvedname); /* allocated in XtResolvePathName() */ + + if (result == MrmSUCCESS) + return result; + else + return Urm__UT_Error ("I18NOpenFile", err_stg, NULL, NULL, result); +} + diff --git a/lib/Mrm/Mrmicon.c b/lib/Mrm/Mrmicon.c index 95d4086..191e2d2 100644 --- a/lib/Mrm/Mrmicon.c +++ b/lib/Mrm/Mrmicon.c @@ -1176,7 +1176,7 @@ Urm__RealizeColorTable (Screen *screen, } break; default: - sprintf(err_msg, _MrmMMsg_0040); + sprintf(err_msg, "%s", _MrmMMsg_0040); return Urm__UT_Error ("Urm__RelizeColorTable", err_msg, NULL, NULL, MrmFAILURE) ; } @@ -1252,7 +1252,7 @@ Urm__RealizeColorTable (Screen *screen, break; default: result = MrmFAILURE; - sprintf (err_msg, _MrmMMsg_0040); + sprintf (err_msg, "%s", _MrmMMsg_0040); Urm__UT_Error ("Urm__RelizeColorTable", err_msg, NULL, NULL, MrmFAILURE) ; } diff --git a/lib/Mrm/Mrmicon.c.format-security b/lib/Mrm/Mrmicon.c.format-security new file mode 100644 index 0000000..95d4086 --- /dev/null +++ b/lib/Mrm/Mrmicon.c.format-security @@ -0,0 +1,1573 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* + * HISTORY + */ +#ifdef HAVE_CONFIG_H +#include +#endif + + +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$XConsortium: Mrmicon.c /main/14 1996/11/13 14:01:43 drk $" +#endif +#endif + +/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + + +/* + *++ + * FACILITY: + * + * UIL Resource Manager (URM) + * + * ABSTRACT: + * + * This module contains routines which operate on URM icon images - + * RGMIconImage structs. + * + *-- + */ + + +/* + * + * INCLUDE FILES + * + */ + +#include +#include +#include +#include "MrmMsgI.h" + + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine creates and returns an X pixmap from a URM icon + * for some widget. It uses the foreground and background obtainable + * from the widget as required. + * + * FORMAL PARAMETERS: + * + * icon URM icon image to be converted to X pixmap + * screen screen to use for pixmap + * display display to use for pixmap + * fgpix foreground color for pixmap + * bgpix background color for pixmap + * pixmap to return resulting X pixmap + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * URM status + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmCreatePixmap (RGMIconImagePtr icon, + Screen *screen, + Display *display, + Pixel fgpix, + Pixel bgpix, + Pixel *pixmap, + Widget parent) +{ + + /* + * Local variables + */ + Cardinal result; /* function results */ + RGMColorTablePtr ctable; /* color table in icon */ + unsigned maxbits; /* # bits required for X image */ + int srcpix; /* # bits per pixel in icon (actual) */ + int dds ; + + /* + * Convert the color table colors to pixels. + */ + ctable = icon->color_table.ctptr; + result = + Urm__RealizeColorTable (screen, display, fgpix, bgpix, ctable, parent); + if ( result != MrmSUCCESS ) return result; + + /* + * Use the depth of screen to infer the number of bits required to + * hold the pixels in X format. The ZPixmap format only supports 1, 8, 16, + * and 32 bit pixels, so we always map to one of these sizes. + */ + if (parent) dds = parent->core.depth; + else dds = DefaultDepthOfScreen(screen) ; + + if (dds == 1) + maxbits = 1; + else if (dds <= 8) + maxbits = 8; + else if (dds <= 16) + maxbits = 16; + else + maxbits = 32; + + + /* + * See if the icon can be mapped as a bitmap. This will be true if the + * color table has only FG/BG entries, or uses only those entries. + */ + if ( ctable->count <= 2 ) maxbits = 1; + + + /* + * Compute the number of bits available in the icon pixmap + */ + switch ( icon->pixel_size ) + { + case URMPixelSize1Bit: + srcpix = 1; + break; + case URMPixelSize2Bit: + srcpix = 2; + break; + case URMPixelSize4Bit: + srcpix = 4; + break; + case URMPixelSize8Bit: + srcpix = 8; + break; + default: + return MrmNOT_VALID; + } + + /* + * Map the icon image pixmap from color table indices to Pixel values. + * There are three cases: + * maxbits == 1; a bitmap is possible, so map to a bitmap. + * maxbits <= # bits/pixel in pixmap. Map in place. In fact, + * only works if maxbits == srcpix == 8. + * maxbits > # bits/pixel. Map to allocated pixmap. + * + * Each of the three routines which performs these mappings completes + * the entire process of doing the mapping and creating the X pixmap. + */ + if ( maxbits == 1 ) + return Urm__MapIconBitmap + (icon, srcpix, ctable, screen, display, pixmap); + if ((maxbits == 8) && (srcpix == 8)) + return Urm__MapIconReplace + (icon, srcpix, ctable, screen, display, pixmap, parent); + if ( maxbits > srcpix ) + return Urm__MapIconAllocate + (icon, srcpix, maxbits, ctable, screen, display, pixmap, parent); + + return MrmNOT_VALID; +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine creates and returns an X pixmap of depth 1 from a URM icon + * for some widget. + * + * FORMAL PARAMETERS: + * + * icon URM icon image to be converted to X pixmap + * screen screen to use for pixmap + * display display to use for pixmap + * pixmap to return resulting X pixmap + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * URM status + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmCreateBitmap (RGMIconImagePtr icon, + Screen *screen, + Display *display, + Pixel *pixmap) +{ + + /* + * Local variables + */ + int srcpix; /* # bits per pixel in icon (actual) */ + + + /* + * Compute the number of bits available in the icon pixmap + */ + switch ( icon->pixel_size ) + { + case URMPixelSize1Bit: + srcpix = URMPixelSize1Bit; + break; + default: + return MrmNOT_VALID; + } + + return Urm__MapIconBitmapDepth1 (icon, srcpix, screen, display, pixmap); + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine creates and returns an X pixmap from the X bitmap file + * name specified. It uses the foreground and background as needed. + * + * + * FORMAL PARAMETERS: + * + * filename file containing the bitmap to be converted to X pixmap + * screen screen to use for pixmap + * display display to use for pixmap - not used + * fgint foreground color for pixmap + * bgint background color for pixmap + * pixmap to return resulting X pixmap + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * URM status + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__CW_ReadBitmapFile (String filename, + Screen *screen, + Pixel fgint, + Pixel bgint, + Pixmap *pixmap, + Widget parent) +{ + int depth; + char err_msg[300]; + + /* + ** Create a pixmap from a X bitmap file specification + */ + depth = parent ? parent->core.depth : DefaultDepthOfScreen(screen); + + *pixmap = XmGetPixmapByDepth(screen, filename, fgint, bgint, depth); + + if (*pixmap == XmUNSPECIFIED_PIXMAP) + { + pixmap = 0; + sprintf (err_msg, _MrmMMsg_0033, filename); + return Urm__UT_Error ("UrmReadBitmapFile", err_msg, + NULL, NULL, MrmFAILURE); + } + + return MrmSUCCESS; +} + + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine maps the pixmap in the icon into a bitmap. The + * bitmap is written over pixmap data. The X pixmap is then + * constructed as an XYBitmap. + * + * FORMAL PARAMETERS: + * + * icon the IconImage being converted + * srcpix number of bits/pixel in icon + * ctable the color table for (in) icon + * screen screen for the X pixmap + * display display for the X pixmap + * pixmap to return the result + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__MapIconBitmap(RGMIconImagePtr icon, + int srcpix, + RGMColorTablePtr ctable, + Screen *screen, + Display *display, + Pixmap *pixmap) +{ + + /* + * Local variables + */ + Pixel fgpix; /* foreground pixel value */ + int iconwid; /* icon width */ + int srclinebyt; /* # bytes per icon line */ + int dstlinebyt; /* # bytes per bitmap line */ + char *srcbytptr; /* image byte pointer */ + char *dstbytptr; /* bitmap pointer */ + int lin; /* icon line number */ + int byt; /* line byte number */ + int pix; /* line pixel number */ + unsigned char srcbyt; /* icon image byte */ + unsigned char dstbyt; /* mapped image byte */ + int tndx; /* color table index */ + XImage *imagep; /* X image */ + GC gc; + XGCValues gcValues; + int endian; /* to determine which endian. */ + + /* + * Overwrite the icon data with a bitmap. Use 0 for background, 1 for + * foreground. + */ + fgpix = ctable->item[URMColorTableFG].color_pixel; + iconwid = icon->width; + srclinebyt = (iconwid*srcpix+7) / 8; + dstlinebyt = (iconwid+7) / 8; + srcbytptr = icon->pixel_data.pdptr; + for ( lin=0 ; linheight ; lin++ ) + { + pix = 0; + dstbytptr = icon->pixel_data.pdptr + lin*dstlinebyt; + dstbyt = 0; + for ( byt=0 ; bytpixel_size ) + { + case URMPixelSize1Bit: + *dstbytptr = srcbyt; + srcbytptr += 1; + dstbytptr += 1; + pix += 8; + /* + * NOTE: The original algorithm used here cleared any + * unused bits of the last byte. I don't think + * the protocol requires that... + if ( pix > iconwid ) + */ + continue; + case URMPixelSize2Bit: + tndx = srcbyt & 0x3; + if ( pix < iconwid ) + if ( ctable->item[tndx].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + srcbyt >>= 2; + tndx = srcbyt & 0x3; + if ( pix < iconwid ) + if ( ctable->item[tndx].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + srcbyt >>= 2; + tndx = srcbyt & 0x3; + if ( pix < iconwid ) + if ( ctable->item[tndx].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + srcbyt >>= 2; + tndx = srcbyt & 0x3; + if ( pix < iconwid ) + if ( ctable->item[tndx].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + break; + case URMPixelSize4Bit: + tndx = srcbyt & 0xF; + if ( pix < iconwid ) + if ( ctable->item[tndx].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + srcbyt >>= 4; + tndx = srcbyt & 0xF; + if ( pix < iconwid ) + if ( ctable->item[tndx].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + break; + case URMPixelSize8Bit: + if ( pix < iconwid ) + if ( ctable->item[srcbyt].color_pixel == fgpix) + dstbyt |= 1<<(pix%8); + pix += 1; + break; + } + /* + * NOTE: The "1Bit" case CONTINUEs directly and will never + * reach this point in the loop... + */ + srcbytptr += 1; + if ( pix%8 == 0 ) + { + *dstbytptr = dstbyt; + dstbytptr += 1; + dstbyt = 0; + } + } + if ( pix%8 != 0 ) + *dstbytptr = dstbyt; + } + + + imagep = XCreateImage(display, + DefaultVisualOfScreen(screen), + 1, + XYBitmap, + 0, + icon->pixel_data.pdptr, + (unsigned int)icon->width, + (unsigned int)icon->height, + 8, + dstlinebyt); + + if ( imagep == NULL ) + return Urm__UT_Error ("Urm__MapIconBitmap", _MrmMMsg_0034, + NULL, NULL, MrmFAILURE); + + /* + * Well, Uil creates a uid icon in its byteorder, on his side + * XCreateImage creates an image in the byte_order of the server, so + * its not correct, we have to adjust the byte_order fields of this + * image to match those of the icon. + */ + + endian = 1; + imagep->bitmap_unit = 8 ; + if (*(char *) &endian) { + imagep->byte_order = LSBFirst ; + imagep->bitmap_bit_order = LSBFirst ; + } + else { + imagep->byte_order = MSBFirst; + imagep->bitmap_bit_order = LSBFirst ; + } + + *pixmap = XCreatePixmap (display, + RootWindowOfScreen(screen), + icon->width, + icon->height, + (unsigned)DefaultDepthOfScreen(screen)); + if ( *pixmap == (Pixmap)0) + { + XFree((char*)imagep); + return Urm__UT_Error ("Urm__MapIconBitmap", _MrmMMsg_0035, + NULL, NULL, MrmFAILURE); + } + + /* + * Build a gc to use when drawing into the pixmap + */ + gcValues.foreground = ctable->item[URMColorTableFG].color_pixel; + gcValues.background = ctable->item[URMColorTableBG].color_pixel; + gcValues.fill_style = FillTiled; + gcValues.tile = *pixmap; + + gc = XCreateGC (display, + RootWindowOfScreen (screen), + GCForeground | GCBackground | GCFillStyle | GCTile, + &gcValues); + if ( gc == NULL ) + return Urm__UT_Error ("Urm__MapIconBitmap", _MrmMMsg_0036, + NULL, NULL, MrmFAILURE); + + /* + * Put bits into the pixmap + */ + XPutImage (display, + *pixmap, + gc, + imagep, + 0, 0, /* source x, y */ + 0, 0, icon->width, icon->height); /* dest, loc & size */ + + XFreeGC (display, gc); + XFree ((char*)imagep); + + /* + * Successfully created + */ + return MrmSUCCESS; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine maps the pixmap in the icon into a bitmap. The + * bitmap is written over pixmap data. The X pixmap is then + * constructed as an XYBitmap. + * + * FORMAL PARAMETERS: + * + * icon the IconImage being converted + * srcpix number of bits/pixel in icon + * screen screen for the X pixmap + * display display for the X pixmap + * pixmap to return the result + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__MapIconBitmapDepth1 (RGMIconImagePtr icon, + int srcpix, + Screen *screen, + Display *display, + Pixmap *pixmap) +{ + + /* + * Local variables + */ + int iconwid; /* icon width */ + int srclinebyt; /* # bytes per icon line */ + int dstlinebyt; /* # bytes per bitmap line */ + char *srcbytptr; /* image byte pointer */ + char *dstbytptr; /* bitmap pointer */ + int lin; /* icon line number */ + int byt; /* line byte number */ + int pix; /* line pixel number */ + unsigned char srcbyt; /* icon image byte */ + unsigned char dstbyt; /* mapped image byte */ + XImage *imagep; /* X image */ + GC gc; + XGCValues gcValues; + int endian; /* to determine which endian. */ + + + /* + * Overwrite the icon data with a bitmap. Use 0 for background, 1 for + * foreground. + */ + iconwid = icon->width; + srclinebyt = (iconwid*srcpix+7) / 8; + dstlinebyt = (iconwid+7) / 8; + srcbytptr = icon->pixel_data.pdptr; + for ( lin=0 ; linheight ; lin++ ) + { + pix = 0; + dstbytptr = icon->pixel_data.pdptr + lin*dstlinebyt; + dstbyt = 0; + for ( byt=0 ; bytpixel_size ) + { + case URMPixelSize1Bit: + *dstbytptr = srcbyt; + srcbytptr += 1; + dstbytptr += 1; + pix += 8; + /* + * NOTE: The original algorithm used here cleared any + * unused bits of the last byte. I don't think + * the protocol requires that... + if ( pix > iconwid ) + */ + continue; + default: + return MrmNOT_VALID; + } + } + if ( pix%8 != 0 ) + *dstbytptr = dstbyt; + } + + + imagep = XCreateImage(display, + DefaultVisualOfScreen(screen), + 1, + XYBitmap, + 0, + icon->pixel_data.pdptr, + (unsigned int)icon->width, + (unsigned int)icon->height, + 8, + dstlinebyt); + + if ( imagep == NULL ) + return Urm__UT_Error ("Urm__MapIconBitmapDepth1", _MrmMMsg_0034, + NULL, NULL, MrmFAILURE); + + /* Well, Uil creates a uid icon in its byteorder, on his side + XCreateImage creates an image in the byte_order of the server, so + its not correct, we have to adjust the byte_order fields of this + image to match those of the icon. */ + + endian = 1; + imagep->bitmap_unit = 8 ; + if (*(char *) &endian) { + imagep->byte_order = LSBFirst ; + imagep->bitmap_bit_order = LSBFirst ; + } + else { + imagep->byte_order = MSBFirst; + imagep->bitmap_bit_order = LSBFirst ; + } + + *pixmap = XCreatePixmap (display, + RootWindowOfScreen(screen), + icon->width, + icon->height, + 1); + if ( *pixmap == (Pixmap)0) + { + XFree((char*)imagep); + return Urm__UT_Error ("Urm__MapIconBitmapDepth1", _MrmMMsg_0035, + NULL, NULL, MrmFAILURE); + } + + + /* + * Build a gc to use when drawing into the pixmap + */ + gcValues.foreground = 1; + gcValues.background = 0; + gcValues.fill_style = FillTiled; + gcValues.tile = *pixmap; + + gc = XCreateGC (display, + *pixmap, + GCForeground | GCBackground | GCFillStyle | GCTile, + &gcValues); + + if ( gc == NULL ) + return Urm__UT_Error ("Urm__MapIconBitmapDepth1", _MrmMMsg_0036, + NULL, NULL, MrmFAILURE); + + /* + * Put bits into the pixmap + */ + XPutImage (display, + *pixmap, + gc, + imagep, + 0, 0, /* source x, y */ + 0, 0, icon->width, icon->height); /* dest, loc & size */ + + + XFreeGC (display, gc); + XFree ((char *)imagep); + + /* + * Successfully created + */ + return MrmSUCCESS; +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine maps the pixmap in the icon into a ZPixmap. The + * ZPixmap is written over the icon image pixmap data. The X pixmap + * is then constructed as a ZPixmap from the overwritten data. + * + * This routine is called only when srcpix == 8. + * + * FORMAL PARAMETERS: + * + * icon the IconImage being converted + * srcpix number of bits/pixel in icon + * ctable the color table for (in) icon + * screen screen for the X pixmap + * display display for the X pixmap + * pixmap to return the result + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__MapIconReplace (RGMIconImagePtr icon, + int srcpix, + RGMColorTablePtr ctable, + Screen *screen, + Display *display, + Pixmap *pixmap, + Widget parent) +{ + + /* + * Local variables + */ + int iconwid; /* icon width */ + int linebyt; /* # bytes per icon line */ + char *bytptr; /* image byte pointer */ + int lin; /* icon line number */ + int byt; /* line byte number */ + int pix; /* line pixel number */ + unsigned char srcbyt; /* icon image byte */ + XImage *imagep; /* X image */ + GC gc; + XGCValues gcValues; + int depth; /* depth of screen */ + + /* + * Overwrite the pixmap with actual Pixel values. The source and destination + * bit widths are the same (==8), and the same pointer can be used for + * both source and destination. + */ + iconwid = icon->width; + linebyt = (iconwid*srcpix+7) / 8; + bytptr = icon->pixel_data.pdptr; + for ( lin=0 ; linheight ; lin++ ) + { + pix = 0; + for ( byt=0 ; bytitem[srcbyt].color_pixel; + pix += 1; + bytptr += 1; + } + } + + depth = parent ? parent->core.depth : DefaultDepthOfScreen(screen); + + imagep = XCreateImage(display, + DefaultVisualOfScreen(screen), + depth, + ZPixmap, + 0, + icon->pixel_data.pdptr, + (unsigned int)icon->width, + (unsigned int)icon->height, + srcpix, + linebyt); + + if ( imagep == NULL ) + return Urm__UT_Error ("Urm__MapIconReplace", _MrmMMsg_0034, + NULL, NULL, MrmFAILURE); + + *pixmap = XCreatePixmap (display, + RootWindowOfScreen(screen), + icon->width, + icon->height, + (unsigned)depth); + if ( *pixmap == (Pixmap)0) + { + XFree((char*)imagep); + return Urm__UT_Error ("Urm__MapIconReplace", _MrmMMsg_0035, + NULL, NULL, MrmFAILURE); + } + + /* + * Build a gc to use when drawing into the pixmap + */ + gcValues.foreground = ctable->item[URMColorTableFG].color_pixel; + gcValues.background = ctable->item[URMColorTableBG].color_pixel; + gcValues.fill_style = FillTiled; + gcValues.tile = *pixmap; + + gc = XCreateGC (display, + RootWindowOfScreen (screen), + GCForeground | GCBackground | GCFillStyle | GCTile, + &gcValues); + if ( gc == NULL ) + return Urm__UT_Error ("Urm__MapIconReplace", _MrmMMsg_0036, + NULL, NULL, MrmFAILURE); + + /* + * Put bits into the pixmap + */ + XPutImage (display, + *pixmap, + gc, + imagep, + 0, 0, /* source x, y */ + 0, 0, icon->width, icon->height); /* dest, loc & size */ + + XFreeGC (display, gc); + XFree((char*)imagep); + + /* + * Successfully created + */ + return MrmSUCCESS; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine maps the pixmap in the icon into a ZPixmap. The + * ZPixmap is allocated 1 byte per pixel, as the icon image pixmap + * has too few bits per pixel to be replace in situ. The X pixmap + * is created from the allocated ZPixmap. + * + * FORMAL PARAMETERS: + * + * icon the IconImage being converted + * srcpix number of bits/pixel in icon + * dstpix number of bits/pixel in resulting image + * ctable the color table for (in) icon + * screen screen for the X pixmap + * display display for the X pixmap + * pixmap to return the result + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__MapIconAllocate (RGMIconImagePtr icon, + int srcpix, + int dstpix, + RGMColorTablePtr ctable, + Screen *screen, + Display *display, + Pixmap *pixmap, + Widget parent) +{ + + /* + * Local variables + */ + int iconwid; /* icon width */ + int iconhgt; /* icon height */ + char *alloc_pixmap; /* allocated pixmap */ + int dstbytsize; /* # 8-bit bytes per bitmap byte */ + int srclinebyt; /* # bytes per icon line */ + char *srcbytptr; /* image byte pointer */ + int lin; /* icon line number */ + int byt; /* line byte number */ + int bit; /* bit loop index */ + int pix; /* line pixel number */ + unsigned char srcbyt; /* icon image byte */ + int bitmask; /* mask all but significant bits */ + int num_bits; /* real (not coded) pixel size */ + int tndx; /* color table index */ + XImage *imagep; /* X image */ + GC gc; + XGCValues gcValues; + int depth; /* depth of screen */ + + /* + * Allocate a new pixmap image. + */ + iconwid = icon->width; + iconhgt = icon->height; + if (dstpix <= 8) dstpix = 8; + else if (dstpix <= 16) dstpix = 16; + else dstpix = 32; + dstbytsize = dstpix / 8; + alloc_pixmap = (char *) XtMalloc (iconwid * iconhgt * dstbytsize); + if (alloc_pixmap == NULL) + return Urm__UT_Error ("Urm__MapIconAllocate", _MrmMMsg_0037, + NULL, NULL, MrmFAILURE); + srclinebyt = (iconwid * srcpix + 7) / 8; + srcbytptr = icon->pixel_data.pdptr; + + depth = parent ? parent->core.depth : DefaultDepthOfScreen(screen); + + imagep = XCreateImage(display, + DefaultVisualOfScreen(screen), + depth, + ZPixmap, + 0, + alloc_pixmap, + iconwid, + iconhgt, + dstpix, + 0); /* Let Xlib calculate it. */ + + if ( imagep == NULL ) + { + XtFree (alloc_pixmap); + return Urm__UT_Error ("Urm__MapIconAllocate", _MrmMMsg_0034, + NULL, NULL, MrmFAILURE); + } + + if(icon->pixel_size == URMPixelSize1Bit) + { num_bits = 1; bitmask=0x1; } + else if(icon->pixel_size == URMPixelSize2Bit) + { num_bits = 2; bitmask=0x3; } + else if(icon->pixel_size == URMPixelSize4Bit) + { num_bits = 4; bitmask=0xF; } + else if(icon->pixel_size == URMPixelSize8Bit) + { num_bits = 8; bitmask=0xFF; } + for ( pix=0,lin=0 ; linheight ; pix=0,lin++ ) + { + for ( byt=0 ; bytitem[tndx].color_pixel); + pix++; + srcbyt >>= num_bits; + } + } + } + + *pixmap = XCreatePixmap (display, + RootWindowOfScreen(screen), + iconwid, + iconhgt, + (unsigned)depth); + if ( *pixmap == (Pixmap)0) + { + XtFree (alloc_pixmap); + XFree((char*)imagep); + return Urm__UT_Error ("Urm__MapIconAllocate", _MrmMMsg_0035, + NULL, NULL, MrmFAILURE); + } + + /* + * Build a gc to use when drawing into the pixmap + */ + gcValues.foreground = ctable->item[URMColorTableFG].color_pixel; + gcValues.background = ctable->item[URMColorTableBG].color_pixel; + gcValues.fill_style = FillTiled; + gcValues.tile = *pixmap; + + gc = XCreateGC (display, + RootWindowOfScreen (screen), + GCForeground | GCBackground | GCFillStyle | GCTile, + &gcValues); + if ( gc == NULL ) + { + XtFree (alloc_pixmap); + return Urm__UT_Error ("Urm__MapIconAllocate", _MrmMMsg_0036, + NULL, NULL, MrmFAILURE); + } + + /* + * Put bits into the pixmap + */ + XPutImage (display, + *pixmap, + gc, + imagep, + 0, 0, /* source x, y */ + 0, 0, iconwid, iconhgt); /* dest, loc & size */ + + /* + * don't deallocate with XDestroyImage, which would destroy alloc_pixmap + */ + XFree((char*)imagep); + XFreeGC (display, gc); + XtFree (alloc_pixmap); + + /* + * Successfully created + */ + return MrmSUCCESS; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine sets the Pixel values corresponding to each of the + * entries in the color table. Foreground and background are set by + * querying the widget for those values, or falling back on + * Black/WhitePixelOfScreen. All other colors are set by honoring + * FG/BG setting for monochrome devices, or by getting the xolor + * Pixel values from X. + * + * FORMAL PARAMETERS: + * + * screen screen to use for color table + * display display to use for color table + * fgpix foreground color for color table + * bgpix background color for color table + * ctable the color table + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__RealizeColorTable (Screen *screen, + Display *display, + Pixel fgpix, + Pixel bgpix, + RGMColorTablePtr ctable, + Widget parent) +{ + + /* + * Local variables + */ + Cardinal result; /* function results */ + Cardinal ndx; /* loop index */ + RGMColorTableEntryPtr citem; /* color table entry */ + Colormap cmap; /* default color map */ + int depth; /* # planes in screen */ + char err_msg[300]; + + + /* + * Load the foreground and background pixel values. + */ + ctable->item[URMColorTableFG].color_pixel = fgpix; + ctable->item[URMColorTableBG].color_pixel = bgpix; + + /* + * Get the Pixel for each defined color. Honor the FG/BG specification + * if present on monochrome displays. Otherwise, get the Pixel value for + * the color. Use the FG/BG specification as a fallback for unfound + * colors in non-monochrome. If no reasonable color Pixel can be found, + * return an error. + */ + cmap = parent ? parent->core.colormap : DefaultColormapOfScreen(screen); + depth = parent ? parent->core.depth : DefaultDepthOfScreen(screen); + + for ( ndx=URMColorTableUserMin ; ndxcount ; ndx++ ) + { + citem = &ctable->item[ndx]; + if ( depth == 1 ) + switch ( citem->color_item.cptr->mono_state ) + { + case URMColorMonochromeUnspecified: + switch (citem->color_item.cptr->desc_type) + { + case URMColorDescTypeName: + result = Urm__UT_GetNamedColorPixel + (display, cmap, citem->color_item.cptr, &citem->color_pixel, + ctable->item[URMColorTableBG].color_pixel); + if ( result != MrmSUCCESS) { + /* we use PARTIAL_SUCCESS only to indicate + the color allocation failed and we've + substituted the fallback color. We still + want a warning, though */ + if (result == MrmPARTIAL_SUCCESS) { + result = MrmSUCCESS; + sprintf (err_msg, _MrmMMsg_0038, + citem->color_item.cptr->desc.name); + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } else { + sprintf (err_msg, _MrmMMsg_0038, + citem->color_item.cptr->desc.name); + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } + } + break; + case URMColorDescTypeRGB: + result = Urm__UT_GetColorPixel + (display, cmap, citem->color_item.cptr, &citem->color_pixel, + ctable->item[URMColorTableBG].color_pixel); + if ( result != MrmSUCCESS ) { + /* we use PARTIAL_SUCCESS only to indicate + the color allocation failed and we've + substituted the fallback color. We still + want a warning, though */ + if (result == MrmPARTIAL_SUCCESS) { + result = MrmSUCCESS; + sprintf (err_msg, _MrmMMsg_0038, + citem->color_item.cptr->desc.name); + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } else { + sprintf (err_msg, _MrmMMsg_0039, + citem->color_item.cptr->desc.rgb.red, + citem->color_item.cptr->desc.rgb.green, + citem->color_item.cptr->desc.rgb.blue) ; + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } + } + break; + default: + sprintf(err_msg, _MrmMMsg_0040); + return Urm__UT_Error ("Urm__RelizeColorTable", + err_msg, NULL, NULL, MrmFAILURE) ; + } + break; + case URMColorMonochromeForeground: + citem->color_pixel = + ctable->item[URMColorTableFG].color_pixel; + break; + case URMColorMonochromeBackground: + citem->color_pixel = + ctable->item[URMColorTableBG].color_pixel; + break; + default: + sprintf (err_msg, _MrmMMsg_0041, + citem->color_item.cptr->mono_state); + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } + else + { + switch (citem->color_item.cptr->desc_type) + { + case URMColorDescTypeName: + result = Urm__UT_GetNamedColorPixel + (display, cmap, citem->color_item.cptr, &citem->color_pixel, + ((citem->color_item.cptr->mono_state == + URMColorMonochromeForeground) ? + ctable->item[URMColorTableFG].color_pixel : + ctable->item[URMColorTableBG].color_pixel)); + if (result != MrmSUCCESS) { + /* we use PARTIAL_SUCCESS only to indicate + the color allocation failed and we've + substituted the fallback color. We still + want a warning, though */ + if (result == MrmPARTIAL_SUCCESS) { + result = MrmSUCCESS; + sprintf (err_msg, _MrmMMsg_0038, + citem->color_item.cptr->desc.name); + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } else { + sprintf (err_msg, _MrmMMsg_0038, + citem->color_item.cptr->desc.name); + Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } + } + break; + case URMColorDescTypeRGB: + result = Urm__UT_GetColorPixel + (display, cmap, citem->color_item.cptr, &citem->color_pixel, + ctable->item[URMColorTableBG].color_pixel); + if (result != MrmSUCCESS) { + /* we use PARTIAL_SUCCESS only to indicate + the color allocation failed and we've + substituted the fallback color. We still + want a warning, though */ + if (result == MrmPARTIAL_SUCCESS) { + result = MrmSUCCESS; + sprintf (err_msg, _MrmMMsg_0038, + citem->color_item.cptr->desc.name); + return Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } else { + sprintf (err_msg, _MrmMMsg_0039, + citem->color_item.cptr->desc.rgb.red, + citem->color_item.cptr->desc.rgb.green, + citem->color_item.cptr->desc.rgb.blue) ; + Urm__UT_Error ("Urm__RealizeColorTable", + err_msg, NULL, NULL, result); + } + } + break; + default: + result = MrmFAILURE; + sprintf (err_msg, _MrmMMsg_0040); + Urm__UT_Error ("Urm__RelizeColorTable", + err_msg, NULL, NULL, MrmFAILURE) ; + } + if ( result != MrmSUCCESS ) + { + switch ( citem->color_item.cptr->mono_state ) + { + case URMColorMonochromeForeground: + citem->color_pixel = + ctable->item[URMColorTableFG].color_pixel; + break; + case URMColorMonochromeBackground: + citem->color_pixel = + ctable->item[URMColorTableBG].color_pixel; + break; + default: + return result; + } + } + } + } + + return MrmSUCCESS; +} + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine makes a copy of a URM icon into a memory block + * which has been pre-allocated. The block must be big enough + * to hold both the header and the bit vector. + * + * FORMAL PARAMETERS: + * + * dst_icon the memory block to receive the copy + * src_icon the URM icon descriptor to be copied. + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + + +RGMIconImagePtr +UrmCopyAllocatedIconImage (RGMIconImagePtr dst_icon, + RGMIconImagePtr src_icon) +{ + + /* + * Copy the header and bit vector into the new memory block. + */ + dst_icon->validation = URMIconImageValid; + dst_icon->pixel_size = src_icon->pixel_size; + dst_icon->width = src_icon->width; + dst_icon->height = src_icon->height; + dst_icon->hot_x = src_icon->hot_x; + dst_icon->hot_y = src_icon->hot_y; + + /* + * Copy the color table as an immediate. It is allocated immediately + * after the image header. + */ + + /* + * Copy the pixel data + */ + + return dst_icon; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine attempts to look up the name of a color, and return + * the pixel value required as a widget arglist value. It will use + * the default color map if necessary, and returns the closest color + * supported by the hardware (as defined by X), not the exact database + * definition. If the screen is depth 1 (monochrome), the routine will + * honor the monochrome rendition specified in the color descriptor. + * + * FORMAL PARAMETERS: + * + * display specifies the X server connection + * cmap color map ID. If NULL, the default color map is used + * colorptr color descriptor + * pixel_return to return the pixel value for the color + * fallback fallback color to use in case of alloc failure + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS color found and translated + * MrmNOT_FOUND conversion failure + * MrmPARTIAL_SUCCESS internal only, for allocation failure + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__UT_GetNamedColorPixel (Display *display, + Colormap cmap, + RGMColorDescPtr colorptr, + Pixel *pixel_return, + Pixel fallback) +{ + + /* + * Local variables + */ + XColor screen_def; /* realizable values */ + XColor exact_def; /* exact values */ + int status; /* function return */ + + + if ( cmap == (Colormap)0) + cmap = DefaultColormap (display, DefaultScreen(display)); + + /* CR 9891: Support new pixel constants. */ + if (XmeNamesAreEqual(colorptr->desc.name, "default_select_color")) + { + *pixel_return = XmDEFAULT_SELECT_COLOR; + return MrmSUCCESS; + } + else if (XmeNamesAreEqual(colorptr->desc.name, "reversed_ground_colors")) + { + *pixel_return = XmREVERSED_GROUND_COLORS; + return MrmSUCCESS; + } + else if (XmeNamesAreEqual(colorptr->desc.name, "highlight_color")) + { + *pixel_return = XmHIGHLIGHT_COLOR; + return MrmSUCCESS; + } + + status = XAllocNamedColor + (display, cmap, colorptr->desc.name, &screen_def, &exact_def); + + if ( status == 0) { + if (fallback) { + *pixel_return = fallback; + return MrmPARTIAL_SUCCESS; + } + else + return MrmFAILURE; + } + *pixel_return = screen_def.pixel; + return MrmSUCCESS; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine attempts to look up the RGB values of a color, and return + * the pixel value required as a widget arglist value. It will use + * the default color map if necessary, and returns the closest color + * supported by the hardware (as defined by X), not the exact database + * definition. If the screen is depth 1 (monochrome), the routine will + * honor the monochrome rendition specified in the color descriptor. + * + * FORMAL PARAMETERS: + * + * display specifies the X server connection + * cmap color map ID. If NULL, the default color map is used + * colorptr color descriptor + * pixel_return to return the pixel value for the color + * fallback fallback color to use in case of alloc failure + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS color found and translated + * MrmNOT_FOUND conversion failure + * MrmPARTIAL_SUCCESS internal only, for allocation failure + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__UT_GetColorPixel (Display *display, + Colormap cmap, + RGMColorDescPtr colorptr, + Pixel *pixel_return, + Pixel fallback) +{ + + /* + * Local variables + */ + XColor screen_in_out; /* realizable values */ + int status; /* function return */ + + + if ( cmap == (Colormap)0) + cmap = DefaultColormap (display, DefaultScreen(display)); + screen_in_out.red = colorptr->desc.rgb.red; + screen_in_out.green = colorptr->desc.rgb.green; + screen_in_out.blue = colorptr->desc.rgb.blue; + status = XAllocColor (display, cmap, &screen_in_out); + + if ( status == 0) { + if (fallback) { + *pixel_return = fallback; + return MrmPARTIAL_SUCCESS; + } else + return MrmFAILURE; + } + *pixel_return = screen_in_out.pixel; + return MrmSUCCESS; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine computes the number of bytes used by a URM icon + * + * FORMAL PARAMETERS: + * + * icon URM icon image + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * # bytes in the image + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmIconImageSize (RGMIconImagePtr icon) +{ + + /* + * Local variables + */ + int bytes_per_line; /* # bytes for padded width */ + int raster_len; /* bytes in image */ + Cardinal size; /* # bytes in descriptor */ + + + bytes_per_line = (icon->width+7) / 8; + raster_len = bytes_per_line * icon->height; + size = sizeof(RGMIconImage) + (raster_len-1)*sizeof(char); + return size; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine computes the number of bytes necessary to store + * the given color table in a single memory block. + * + * FORMAL PARAMETERS: + * + * ctable An allocated color table + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * table size in bytes + * + * SIDE EFFECTS: + * + *-- + */ + +/*ARGSUSED*/ +Cardinal +UrmColorTableSize (RGMColorTablePtr ctable) /* unused */ +{ + + return sizeof(RGMColorTable); + +} diff --git a/lib/Mrm/Mrmlread.c b/lib/Mrm/Mrmlread.c index c2fd94c..be433a3 100644 --- a/lib/Mrm/Mrmlread.c +++ b/lib/Mrm/Mrmlread.c @@ -698,7 +698,7 @@ MrmFetchColorLiteral (MrmHierarchy hierarchy_id, XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))); break; default: - sprintf(err_msg, _MrmMMsg_0040); + sprintf(err_msg, "%s", _MrmMMsg_0040); result = Urm__UT_Error ("MrmFetchColorLiteral", err_msg, NULL, NULL, MrmFAILURE) ; _MrmAppUnlock(app); diff --git a/lib/Mrm/Mrmlread.c.format-security b/lib/Mrm/Mrmlread.c.format-security new file mode 100644 index 0000000..c2fd94c --- /dev/null +++ b/lib/Mrm/Mrmlread.c.format-security @@ -0,0 +1,964 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* + * HISTORY + */ +#ifdef HAVE_CONFIG_H +#include +#endif + + +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$XConsortium: Mrmlread.c /main/16 1996/11/13 14:02:28 drk $" +#endif +#endif + +/* * + * (c) Copyright 1996 Hewlett-Packard Company * + * (c) Copyright 1996 International Business Machines Corp. * + * (c) Copyright 1996 Sun Microsystems, Inc. * + * (c) Copyright 1996 Novell, Inc. * + * (c) Copyright 1989, 1990, 1996 Digital Equipment Corporation. * + * (c) Copyright 1996 FUJITSU LIMITED. * + * (c) Copyright 1996 Hitachi. * + */ + +/* + *++ + * FACILITY: + * + * UIL Resource Manager (URM): + * + * ABSTRACT: + * + * This module contains the literal read routines. All these routines + * read a literal from a hierarchy or IDB file into a resource context. + * + *-- + */ + + +/* + * + * INCLUDE FILES + * + */ + +#include +#include +#include +#include "MrmosI.h" +#include "MrmMsgI.h" + +/* + * + * TABLE OF CONTENTS + * + * UrmGetIndexedLiteral Read indexed literal from IDB file + * + * UrmGetRIDLiteral Read RID literal from IDB file + * + * UrmHGetIndexedLiteral Read indexed literal from hierarchy + * + */ + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine is a service routine for the various XmFetch...Literal + * routine. It fetches a literal into a context. It also fetches any + * other literals which are referenced. + * + * FORMAL PARAMETERS: + * + * hierarchy_id id of an open hierarchy containing the literal + * index index of the desired literal + * context_id context in which to return literal. Literal will + * be fixed up. + * ctxlist list of other contexts created (if needed) + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__FetchLiteral (MrmHierarchy hierarchy_id, + String index, + URMResourceContextPtr context_id, + URMPointerListPtr *ctxlist) +{ + + /* + * Local variables + */ + Cardinal result; /* function results */ + IDBFile file_id = NULL; /* file containing literal */ + long val; /* literal value */ + MrmType type; /* literal type */ + char err_msg[300]; /* for error messages */ + Boolean swap_needed = FALSE ; + + + /* + * read the literal into the context + */ + result = Urm__HGetIndexedLiteral (hierarchy_id, index, context_id, &file_id); + if ( result != MrmSUCCESS ) + { + sprintf (err_msg, _MrmMMsg_0042, index); + return Urm__UT_Error ("Urm__FetchLiteral", err_msg, NULL, NULL, result); + } + + swap_needed = UrmRCByteSwap(context_id) ; + + /* + * Acquire the literal type and value, and do any fixups which are required. + */ + val = (long) UrmRCBuffer (context_id); + type = UrmRCType (context_id); + switch ( type ) + { + case MrmRtypeIconImage: + UrmPlistInit (10, ctxlist); + result = Urm__CW_LoadIconImage ((RGMIconImagePtr)val, (XtPointer)val, + hierarchy_id, file_id, *ctxlist); + /* LoadIconImage checks validations and handle swapping */ + swap_needed = FALSE ; + break; + case MrmRtypeFontList: + /* Check for old style font list, allocate new value if necessary. */ + if (strcmp(file_id->db_version, URM1_1version) <= 0) + { + int count = ((OldRGMFontListPtr)val)->count; + RGMFontListPtr fontlist = (RGMFontListPtr) + XtMalloc(sizeof(RGMFontList) + (sizeof(RGMFontItem) * (count - 1))); + Urm__CW_FixupValue ((long)fontlist, type, (XtPointer)val, file_id, + &swap_needed); + XtFree((char *)val); + UrmRCBuffer(context_id) = (char *)fontlist; + } + else + Urm__CW_FixupValue (val, type, (XtPointer)val, file_id, &swap_needed); + break; + case MrmRtypeInteger: + case MrmRtypeBoolean: + if ( swap_needed ) + { + swapbytes( (*(int *)UrmRCBuffer (context_id)) ); + swap_needed = FALSE ; + } + break; + case MrmRtypeSingleFloat: + if ( swap_needed ) + { + swapbytes( (*(int *)UrmRCBuffer (context_id)) ); + swap_needed = FALSE ; + } + _MrmOSIEEEFloatToHost( (float *)UrmRCBuffer (context_id)); + break; + case MrmRtypeFloat: + if ( swap_needed ) + { + swapdouble( (*(double *)UrmRCBuffer (context_id)) ); + swap_needed = FALSE ; + } + _MrmOSIEEEDoubleToHost( (double *)UrmRCBuffer (context_id)); + break; + + default: + Urm__CW_FixupValue (val, type, (XtPointer)val, file_id, &swap_needed); + break; + } + + UrmRCSetByteSwap(context_id, swap_needed); + return MrmSUCCESS; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine reads and returns the value of a literal (named value) + * stored as a public resource in a single UID file. It returns a + * pointer to value of the literal, fixed up and converted for + * use as a toolkit argument. The return is always a pointer -- an + * integer is returned as a pointer to an integer, and a string is + * returned as a pointer to a string. The caller is responsible for + * freeing the literal's storage, which was acquired with XtMalloc. + * + * This routine should not be used for fetching icon or color literals, + * as more information is required for converting them. If fetched, + * an error is returned. + * + * FORMAL PARAMETERS: + * + * hierarchy_id id of an open hierarchy containing the literal + * index index of the desired literal + * value_return to return pointer to literal value + * type_return will be set to the literal data type, from RGMrType... + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS - literal found and returned + * MrmWRONG_TYPE - unsupported literal type encountered + * MrmNOT_FOUND - literal not found + * MrmFAILURE - file system error + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +MrmFetchLiteral (MrmHierarchy hierarchy_id, + String index, + Display *display, + XtPointer *value_return, + MrmCode *type_return) +{ + + /* + * Local variables + */ + Cardinal result; /* function results */ + URMResourceContextPtr context_id; /* for the literal */ + URMPointerListPtr ctxlist = NULL; /* save added contexts */ + Cardinal ndx; /* loop index */ + int vec_size = 0; + int vec_count = 0; + _MrmDisplayToAppContext(display); + + _MrmAppLock(app); + _MrmProcessLock(); + + /* + * Read the literal, discard the context, and return. + */ + UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id); + result = Urm__FetchLiteral (hierarchy_id, index, context_id, &ctxlist); + if ( result == MrmSUCCESS ) + { + *value_return = (XtPointer) UrmRCBuffer (context_id); + (*type_return) = (MrmCode) UrmRCType (context_id); + vec_size = UrmRCSize (context_id); + switch ( *type_return ) + { + case MrmRtypeIconImage: + case MrmRtypeColor: + case MrmRtypeColorTable: + case MrmRtypeXBitmapFile: + if ( ctxlist != NULL ) + { + for ( ndx=0 ; ndxcount; + result = Urm__CW_ConvertValue (NULL, (long*)value_return, + (MrmType)*type_return, 0, display, + hierarchy_id, NULL) ; + if ( result != MrmSUCCESS ) + { + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return MrmFAILURE; + } + Urm__CW_SafeCopyValue ((long *)value_return, (MrmType)*type_return, + NULL, vec_count, vec_size); + UrmFreeResourceContext (context_id); + break; + + case MrmRtypeIntegerVector: + /* + ** Do necessary conversions (Fixups were done by Urm__FetchLiteral) + */ + vec_count = ((RGMIntegerVectorPtr)*value_return)->count; + vec_size = vec_count * sizeof ( int * ); + result = Urm__CW_ConvertValue (NULL, (long*)value_return, + (MrmType)*type_return, 0, display, + hierarchy_id, NULL) ; + if ( result != MrmSUCCESS ) + { + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return MrmFAILURE; + } + Urm__CW_SafeCopyValue ((long *)value_return, (MrmType)*type_return, + NULL, vec_count, vec_size); + UrmFreeResourceContext (context_id); + break; + + default : + /* + ** Do necessary conversions (Fixups were done by Urm__FetchLiteral) + */ + result = Urm__CW_ConvertValue (NULL, (long*)value_return, + (MrmType)*type_return, 0, display, + hierarchy_id, NULL) ; + + switch ( *type_return ) + { + /* + * Free the context id AND the buffer in these cases + */ + case MrmRtypeTransTable: + case MrmRtypeClassRecName: + case MrmRtypeKeysym: + UrmFreeResourceContext (context_id); + break; + + default: + /* + * Only free the context id in all other cases + */ + (*(context_id->free_func)) (context_id) ; + break; + } + + if ( result != MrmSUCCESS ) + { + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return MrmFAILURE; + } + break; + } + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return MrmSUCCESS; + } + else + { + (*(context_id->free_func)) (context_id) ; + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return result; + } +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine fetches an icon literal from a hierarchy. It converts + * the icon to an X pixmap. + * + * FORMAL PARAMETERS: + * + * hierarchy_id id of an open hierarchy containing the literal + * index index of the desired literal + * screen screen to use for pixmap + * display display to use for pixmap + * fgpix foreground color for pixmap + * bgpix background color for pixmap + * pixmap_return to return resulting X pixmap + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +MrmFetchIconLiteral (MrmHierarchy hierarchy_id, + String index, + Screen *screen, + Display *display, + Pixel fgpix, + Pixel bgpix, + Pixmap *pixmap_return) +{ + + /* + * Local variables + */ + Cardinal result; /* function results */ + URMResourceContextPtr context_id; /* for the literal */ + URMPointerListPtr ctxlist = NULL; /* save added contexts */ + Cardinal ndx; /* loop index */ + MrmType type; + _MrmDisplayToAppContext(display); + + _MrmAppLock(app); + _MrmProcessLock(); + + /* + * Read the literal, and deal with errors + */ + UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id); + result = Urm__FetchLiteral (hierarchy_id, index, context_id, &ctxlist); + if ( result == MrmSUCCESS ) { + type = UrmRCType(context_id); + } + else + { + if ( ctxlist != NULL ) + { + for ( ndx=0 ; ndxwidth; + *height = icon->height; + break; + /* + >>> Andy research here if we can do this for a depth of 1 + case MrmRtypeXBitmapFile: + result = Urm__CW_ReadBitmapFile (UrmRCBuffer(context_id), screen, + fgpix, bgpix, pixmap_return); + break; + */ + default: + result = MrmWRONG_TYPE; + } + + if ( ctxlist != NULL ) + { + for ( ndx=0 ; ndxdesc_type) + { + case URMColorDescTypeName: + result = Urm__UT_GetNamedColorPixel + (display, cmap, colorptr, pixel_return, + XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))); + break; + case URMColorDescTypeRGB: + result = Urm__UT_GetColorPixel + (display, cmap, colorptr, pixel_return, + XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))); + break; + default: + sprintf(err_msg, _MrmMMsg_0040); + result = Urm__UT_Error ("MrmFetchColorLiteral", + err_msg, NULL, NULL, MrmFAILURE) ; + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return result; + }; + UrmFreeResourceContext (context_id); + + /* partial success only returned when a color allocation fails, but + we've tried to make a reasonable substitution */ + if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS; + _MrmAppUnlock(app); + _MrmProcessUnlock(); + return result; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmGetIndexedLiteral searches a single database file for a literal + * given its index (i.e. it gets a public literal from a single file). + * It returns the literal as the contents of the context buffer. The + * group which is fetched is always URMgLiteral. The literal type + * filter is taken from the context; if unmodified in the context + * as obtained from UrmGetResourceContext, there is no filtering + * (type=RGMtNul). + * + * The buffer contents will be as follows for some common literal + * types obtained from a .UID file. Note that in some cases that + * the caller must fix up offsets to be memory pointers. + * + * UrmRCType(context_id) == MrmRtypeChar8: + * UrmRCBuffer(context_id) contains a nul-terminated + * ASCII string + * + * UrmRCType(context_id) == MrmRtypeCString: + * UrmRCBuffer(context_id) contains a compound string + * + * UrmRCType(context_id) == MrmRtypeChar8Vector: + * UrmRCType(context_id) == MrmRtypeCStringVector: + * UrmRCBuffer(context_id) contains an RGM text vector + * or stringtable (RGMTextVector). The items in the + * text vector contain offsets into the buffer which + * locate either nul-terminated ASCII strings or compound + * compound strings. These may be relocated to memory + * pointers by adding the buffer address to the offset, i.e. + * item[n].text_item.pointer = item[n].text_item.offset+bufadr + * + * FORMAL PARAMETERS: + * + * file_id id of an open URM database file (IDB file) + * index index of the desired literal + * context_id resource context into which to read the literal + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid resource context + * Other See UrmIdbGetIndexedResource + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmGetIndexedLiteral (IDBFile file_id , + String index , + URMResourceContextPtr context_id ) +{ + + /* + * Local variables + */ + MrmType lit_type ; /* the type of the literal */ + + + /* + * Validate context, then attempt the read. + */ + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("UrmGetIndexedLiteral", _MrmMMsg_0043, + file_id, context_id, MrmBAD_CONTEXT) ; + + lit_type = UrmRCType (context_id) ; + return UrmIdbGetIndexedResource + (file_id, index, URMgLiteral, lit_type, context_id) ; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmGetRIDLiteral retrieves a literal from a single database file + * given its resource id as an accessor. It returns the literal record. + * + * FORMAL PARAMETERS: + * + * file_id id of an open URM database file (IDB file) + * resource_id resource id for literal + * context_id literal context in which to return record read in + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmNOT_FOUND literal not found + * MrmFAILURE operation failed, further reason not given. + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmGetRIDLiteral (IDBFile file_id , + MrmResource_id resource_id , + URMResourceContextPtr context_id ) +{ + + /* + * Local variables + */ + MrmType lit_type ; /* the type of the literal */ + + + /* + * Validate context, then attempt the read. + */ + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("UrmGetRIDLiteral", _MrmMMsg_0043, + file_id, context_id, MrmBAD_CONTEXT) ; + + lit_type = UrmRCType (context_id) ; + return UrmIdbGetRIDResource + (file_id, resource_id, URMgLiteral, lit_type, context_id) ; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * Urm__HGetIndexedLiteral is exactly like UrmGetLiteral except + * that it searches a hierarchy for the literal rather than reading + * from a single file. + * + * FORMAL PARAMETERS: + * + * hierarchy_id hierarchy to be searched + * index index of the desired literal + * context_id resource context into which to read the literal + * file_id_return to return IDB file in which literal was found + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid resource context + * Other See UrmIdbGetIndexedResource + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__HGetIndexedLiteral (MrmHierarchy hierarchy_id , + String index , + URMResourceContextPtr context_id , + IDBFile *file_id_return ) +{ + + /* + * Local variables + */ + MrmType lit_type ; /* the type of the literal */ + + /* + * Validate hierarchy and context, then attempt the read. + */ + if ( hierarchy_id == NULL ) + return Urm__UT_Error ("Urm__HGetIndexedLiteral", _MrmMMsg_0023, + NULL, NULL, MrmBAD_HIERARCHY) ; + if ( ! MrmHierarchyValid(hierarchy_id) ) + return Urm__UT_Error ("Urm__HGetIndexedLiteral", _MrmMMsg_0024, + NULL, NULL, MrmBAD_HIERARCHY) ; + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("Urm__HGetIndexedLiteral", _MrmMMsg_0043, + NULL, context_id, MrmBAD_CONTEXT) ; + + lit_type = UrmRCType (context_id) ; + return UrmHGetIndexedResource + (hierarchy_id, index, URMgLiteral, lit_type, context_id, file_id_return) ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmHGetIndexedLiteral is exactly like UrmGetLiteral except + * that it searches a hierarchy for the literal rather than reading + * from a single file. + * + * FORMAL PARAMETERS: + * + * hierarchy_id hierarchy to be searched + * index index of the desired literal + * context_id resource context into which to read the literal + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid resource context + * Other See UrmIdbGetIndexedResource + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmHGetIndexedLiteral (MrmHierarchy hierarchy_id , + String index , + URMResourceContextPtr context_id ) +{ + + /* + * Local variables + */ + IDBFile dummy ; /* unused file return */ + + return Urm__HGetIndexedLiteral (hierarchy_id, index, context_id, &dummy) ; +} + diff --git a/lib/Mrm/Mrmwcrw.c b/lib/Mrm/Mrmwcrw.c index fe3db52..3c5857f 100644 --- a/lib/Mrm/Mrmwcrw.c +++ b/lib/Mrm/Mrmwcrw.c @@ -1390,7 +1390,7 @@ Urm__CW_CreateArglist (Widget parent, } break; default: - sprintf (err_msg, _MrmMMsg_0040); + sprintf (err_msg, "%s", _MrmMMsg_0040); result = Urm__UT_Error ("Urm__CW_ConvertValue", err_msg, NULL, NULL, MrmFAILURE) ; }; @@ -2426,7 +2426,7 @@ Urm__CW_ConvertValue (Widget parent, } break; default: - sprintf(err_msg, _MrmMMsg_0040); + sprintf(err_msg, "%s", _MrmMMsg_0040); return Urm__UT_Error ("Urm__CW_ConvertValue", err_msg, NULL, NULL, MrmFAILURE) ; }; diff --git a/lib/Mrm/Mrmwcrw.c.format-security b/lib/Mrm/Mrmwcrw.c.format-security new file mode 100644 index 0000000..fe3db52 --- /dev/null +++ b/lib/Mrm/Mrmwcrw.c.format-security @@ -0,0 +1,3639 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* + * HISTORY + */ +#ifdef HAVE_CONFIG_H +#include +#endif + + +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$TOG: Mrmwcrw.c /main/20 1999/05/19 15:26:23 mgreess $" +#endif +#endif + +/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + +/* + *++ + * FACILITY: + * + * UIL Resource Manager (URM): + * + * ABSTRACT: + * + * This module contains the routine which implement widget creation + * and management at runtime from a widget stored in a resource context. + * + *-- + */ + + +/* + * + * INCLUDE FILES + * + */ +#include +#include +#include +#include "MrmosI.h" +#include "MrmMsgI.h" +#include +#include /* for ALLOCATE/DEALLOCATE_LOCAL */ +#include /* for XmGetTearOffControl */ +#include /* for XmDisplay */ + +#include +#include +#include + +/* + * + * TABLE OF CONTENTS + * + * UrmCreateWidgetTree Create a widget and its subtree + * + * UrmCreateWidgetInstance Create a widget instance + * + * Urm__CW_CreateArglist Create a widget arglist + * + * Urm__CW_FixupCallback Complete a callback item + * + * Urm__CW_EvaluateResource Evaluate a resource ref value + * + */ + + +static void DisplayDestroyCallback (Widget w, + XtPointer client_data, + XtPointer call_data ); + +/* + * + * DEFINE and MACRO DEFINITIONS + * + */ + +#define MAKEINT(float_value) ((int) (((float_value) > 0.0) ? \ + ((float_value) + 0.5) : \ + ((float_value) - 0.5))) + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmCreateWidgetInstanceCleanup determines from a RGM widget + * record if the widget instance is real. If it is and it has + * a cleanup, the cleanup is called. This mechanism is + * used to clean up dangling XmRenderTable and XmRendition handles + * left dangling in calls to UrmCreateWidgetInstance. + * + * FORMAL PARAMETERS: + * + * context_id context containing widget record describing widget + * to create + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * child id of child widget + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid context + * MrmBAD_WIDGET_REC invalid widget record + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmCreateWidgetInstanceCleanup (URMResourceContextPtr context_id, + Widget child, + IDBFile file_id) +{ + /* + * Local variables + */ + RGMWidgetRecordPtr widgetrec ; /* widget record in the context */ + WCIClassDescPtr cldesc ; /* class descriptor */ + Cardinal result; + + /* + * Validate the context and the widget record in the context. + * Check the variety and call the appropriate set or create function. + */ + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0043, + NULL, NULL, MrmBAD_CONTEXT) ; + widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ; + if ( ! UrmWRValid(widgetrec) ) + return Urm__UT_Error ("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0026, + NULL, context_id, MrmBAD_WIDGET_REC) ; + + if (widgetrec->variety == UilMrmWidgetVariety) + { + result = Urm__FindClassDescriptor (file_id, + widgetrec->type, + (XtPointer) + ((char *)widgetrec+widgetrec->class_offs), + &cldesc) ; + if ( result != MrmSUCCESS ) return result ; + + if (NULL != cldesc->cleanup) (*(cldesc->cleanup)) (child) ; + } + else if (widgetrec->variety != UilMrmAutoChildVariety) + return Urm__UT_Error("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0055, + NULL, context_id, MrmBAD_WIDGET_REC); + + return MrmSUCCESS; +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmCreateWidgetTree is the recursive routine + * which recurses down a widget subtree and instantiates all widgets + * in the tree. The recursion process is: + * + * o Create this widget. + * o Create a new context. Read each child of this widget + * into the context in succession. Create each child, + * saving its id. + * o manage the children + * + * This routine accepts override parameters for the widget name, and + * to override arguments in the creation arglist. The latter are appended + * to the list created from the UID file, and do not replace all values. + * The parameters are not passed down to any children in the subtree. + * + * FORMAL PARAMETERS: + * + * context_id context containing widget record describing widget + * to create + * parent id of parent widget + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * ov_name Name to override widget name (NULL for no override) + * ov_args Override arglist, exactly as would be given to + * XtCreateWidget (conversion complete, etc). NULL + * for no override. + * ov_num_args # args in ov_args; 0 for no override + * keytype type of key which accessed this widget + * kindex index for URMrIndex access + * krid resource id for URMrRID access + * svlist list of SetValues descriptors for widgets in tree + * wref_id to accumulate widget reference definitions + * w_return To return id of newly created widget + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid context + * MrmBAD_WIDGET_REC invalid widget record + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmCreateWidgetTree (URMResourceContextPtr context_id, + Widget parent, + MrmHierarchy hierarchy_id, + IDBFile file_id, + String ov_name, + ArgList ov_args, + Cardinal ov_num_args, + MrmCode keytype, + String kindex, + MrmResource_id krid, + MrmManageFlag manage, + URMPointerListPtr *svlist, + URMResourceContextPtr wref_id, + Widget *w_return) +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + Widget widget_id ; /* this widget id */ + URMResourceContextPtr child_ctx ; /* context for children */ + Widget child_id ; /* current child */ + IDBFile loc_file_id ; /* local file id, may be modified */ + RGMWidgetRecordPtr widgetrec ; /* the widget record in the context */ + int ndx ; /* loop index */ + RGMChildrenDescPtr childrendesc ; /* children list descriptor */ + RGMChildDescPtr childptr ; /* current child */ + String child_idx = NULL ; /* current child index */ + char err_msg[300] ; + char *w_name; + + /* + * Create the widget instance. + */ + result = UrmCreateOrSetWidgetInstance (context_id, parent, hierarchy_id, + file_id, ov_name, ov_args, ov_num_args, + keytype, kindex, krid, manage, svlist, + wref_id, &widget_id, &w_name) ; + if ( result != MrmSUCCESS ) return result ; + *w_return = widget_id ; + + /* + * Initialize a context, and create all the children, Saving their ids. + * Note there are no interior returns from the processing loop, and that + * all locally acquired resources are returned at the routine exit. + * + * Initialize a sibling reference context for any class which allows + * sibling widget references. + */ + widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ; + if ( widgetrec->children_offs > 0) + { + UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &child_ctx); + childrendesc = + (RGMChildrenDescPtr)((char *)widgetrec+widgetrec->children_offs); + + for ( ndx=0 ; ndxcount ; ndx++ ) + { + childptr = &childrendesc->child[ndx] ; + + /* + * Read the next child into the child context. Continue looping if it + * can't be found. Reading the child from a hierarchy may modify the + * file id, but only for reading the child's subtree. + */ + loc_file_id = file_id ; + switch ( childptr->type ) + { + case URMrIndex: + child_idx = (char *) widgetrec+childptr->key.index_offs ; + if ( childptr->access == URMaPublic ) + result = UrmHGetWidget (hierarchy_id, child_idx, + child_ctx, &loc_file_id) ; + else + result = UrmGetIndexedWidget (file_id, child_idx, child_ctx) ; + if ( result != MrmSUCCESS ) + sprintf (err_msg, _MrmMMsg_0052, child_idx) ; + break ; + case URMrRID: + result = UrmGetRIDWidget (file_id, childptr->key.id, + child_ctx) ; + if ( result != MrmSUCCESS ) + sprintf (err_msg, _MrmMMsg_0053, childptr->key.id) ; + break ; + default: + result = MrmFAILURE ; + sprintf (err_msg, _MrmMMsg_0054, childptr->type) ; + break ; + } + if ( result != MrmSUCCESS ) + { + Urm__UT_Error ("UrmCreateWidgetTree", + err_msg, NULL, NULL, result) ; + continue ; + } + + /* + * Create the child and its subtree. + */ + result = UrmCreateWidgetTree (child_ctx, widget_id, hierarchy_id, + loc_file_id, NULL, NULL, 0, + childptr->type, child_idx, + childptr->key.id, + ((childptr->manage) ? + MrmManageManage : MrmManageUnmanage), + svlist, wref_id, &child_id) ; + UrmCreateWidgetInstanceCleanup(child_ctx, child_id, loc_file_id); + if ( result != MrmSUCCESS ) continue ; + + /* + * loop end + */ + } + /* + * done. Deallocate local resources. + */ + UrmFreeResourceContext (child_ctx) ; + } + + /* + * Add the parent widget to the widget reference structure, and update the + * SetValues descriptors if appropriate + */ + if ((w_name != NULL) && (*svlist != NULL)) + Urm__CW_ResolveSVWidgetRef(svlist, w_name, *w_return); + + return MrmSUCCESS ; +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmCreateOrSetWidgetInstance determines from a RGM widget + * record if the widget instance is real and has to be created by + * a call to UrmCreateWidgetInstance or is an automatic child widget + * and has to be set by a call to UrmSetWidgetInstance. + * + * Once UrmCreateOrSetWidgetInstance has been called, then the only + * information in the RGM record which may still be required is the + * privacy information and the widget children list. This information + * may be copied and the resource context reused by users who are doing + * recursive widget access, and wish to avoid recursive accumulation + * of resource contexts in memory. + * + * The URM hierarchy for public resources and the IDB file for private + * resources are required to evaluate resource references occurring in + * the widget arglist. + * + * This routine accepts override parameters for the widget name, and + * to override arguments in the creation arglist. The latter are appended + * to the list created from the UID file, and do not replace all values. + * + * FORMAL PARAMETERS: + * + * context_id context containing widget record describing widget + * to create + * parent id of parent widget + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * ov_name Name to override widget name (NULL for no override) + * ov_args Override arglist, exactly as would be given to + * XtCreateWidget (conversion complete, etc). NULL + * for no override. + * ov_num_args # args in ov_args; 0 for no override + * keytype type of key which accessed this widget + * kindex index for URMrIndex access + * krid resource id for URMrRID access + * manage create-managed flag + * svlist list of SetValues descriptors + * wref_id structure in which to resolve references to widgets + * which have already been defined. + * w_return To return id of newly created widget + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid context + * MrmBAD_WIDGET_REC invalid widget record + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +UrmCreateOrSetWidgetInstance (URMResourceContextPtr context_id, + Widget parent, + MrmHierarchy hierarchy_id, + IDBFile file_id, + String ov_name, + ArgList ov_args, + Cardinal ov_num_args, + MrmCode keytype, + String kindex, + MrmResource_id krid, + MrmManageFlag manage, + URMPointerListPtr *svlist, + URMResourceContextPtr wref_id, + Widget *w_return, + char **w_name) +{ + /* + * Local variables + */ + RGMWidgetRecordPtr widgetrec ; /* widget record in the context */ + + /* + * Validate the context and the widget record in the context. + * Check the variety and call the appropriate set or create function. + */ + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("UrmCreateOrSetWidgetInstance", _MrmMMsg_0043, + NULL, NULL, MrmBAD_CONTEXT) ; + widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ; + if ( ! UrmWRValid(widgetrec) ) + return Urm__UT_Error ("UrmCreateOrSetWidgetInstance", _MrmMMsg_0026, + NULL, context_id, MrmBAD_WIDGET_REC) ; + + if (widgetrec->variety == UilMrmWidgetVariety) + { + return UrmCreateWidgetInstance(context_id, parent, hierarchy_id, file_id, + ov_name, ov_args, ov_num_args, keytype, + kindex, krid, manage, svlist, wref_id, + w_return, w_name); + } + else if (widgetrec->variety == UilMrmAutoChildVariety) + { + *w_name = NULL; + return UrmSetWidgetInstance(context_id, parent, hierarchy_id, file_id, + ov_args, ov_num_args, keytype, kindex, + krid, manage, svlist, wref_id, w_return); + } + else + return Urm__UT_Error("UrmCreateOrSetWidgetInstance", _MrmMMsg_0055, + NULL, context_id, MrmBAD_WIDGET_REC); +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmCreateWidgetInstance creates a widget instance from a RGM widget + * record by: + * + * o Creating a legal XtCreateWidget arglist from the RGM + * arglist by expanding compressed tags, evaluating values, + * and doing type conversion. + * + * o Deriving the correct low-level widget creation routine + * from the RGM record's class specifier, and calling with + * the given parent and the arglist. + * + * Once UrmCreateWidgetInstance has been called, then the only + * information in the RGM record which may still be required is the + * privacy information and the widget children list. This information + * may be copied and the resource context reused by users who are doing + * recursive widget access, and wish to avoid recursive accumulation + * of resource contexts in memory (see next routine). + * + * The URM hierarchy for public resources and the IDB file for private + * resources are required to evaluate resource references occurring in + * the widget arglist. + * + * This routine accepts override parameters for the widget name, and + * to override arguments in the creation arglist. The latter are appended + * to the list created from the UID file, and do not replace all values. + * + * FORMAL PARAMETERS: + * + * context_id context containing widget record describing widget + * to create + * parent id of parent widget + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * ov_name Name to override widget name (NULL for no override) + * ov_args Override arglist, exactly as would be given to + * XtCreateWidget (conversion complete, etc). NULL + * for no override. + * ov_num_args # args in ov_args; 0 for no override + * keytype type of key which accessed this widget + * kindex index for URMrIndex access + * krid resource id for URMrRID access + * manage create-managed flag + * svlist list of SetValues descriptors + * wref_id structure in which to resolve references to widgets + * which have already been defined. + * w_return To return id of newly created widget + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid context + * MrmBAD_WIDGET_REC invalid widget record + * + * SIDE EFFECTS: + * + *-- + */ + +/*ARGSUSED*/ +Cardinal +UrmCreateWidgetInstance (URMResourceContextPtr context_id, + Widget parent, + MrmHierarchy hierarchy_id, + IDBFile file_id, + String ov_name, + ArgList ov_args, + Cardinal ov_num_args, + MrmCode keytype, /* unused */ + String kindex, /* unused */ + MrmResource_id krid, /* unused */ + MrmManageFlag manage, + URMPointerListPtr *svlist, + URMResourceContextPtr wref_id, + Widget *w_return, + char **w_name) +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + RGMWidgetRecordPtr widgetrec ; /* widget record in the context */ + RGMArgListDescPtr argdesc = NULL ; /* arg list descriptor in record */ + Arg *args = NULL ; /* arg list argument for create */ + Cardinal num_used = 0 ; /* number of args used in arglist */ + MrmCount num_listent = ov_num_args ; /* # entries in args */ + WCIClassDescPtr cldesc ; /* class descriptor */ + URMPointerListPtr ptrlist = NULL ; /* to hold scratch callbacks */ + URMPointerListPtr cblist = NULL ; /* to hold scratch contexts */ + URMPointerListPtr ftllist = NULL ; /* to hold scratch fontlists */ + int ndx ; /* loop index */ + RGMCallbackDescPtr cbptr ; /* creation callback descriptor */ + RGMCallbackItemPtr itmptr ; /* current callback item */ + void (* cb_rtn) () ; /* current callback routine */ + /* BEGIN OSF Fix pir 1860, 2813 */ + XmAnyCallbackStruct cb_reason; /* creation callback reason */ + /* END OSF Fix pir 1860, 2813 */ + + /* + * Validate the context and the widget record in the context. + * Get the low-level creation routine pointer. + */ + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("UrmCreateWidgetInstance", _MrmMMsg_0043, + NULL, NULL, MrmBAD_CONTEXT) ; + widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ; + if ( ! UrmWRValid(widgetrec) ) + return Urm__UT_Error ("UrmCreateWidgetInstance", _MrmMMsg_0026, + NULL, context_id, MrmBAD_WIDGET_REC) ; + + result = Urm__FindClassDescriptor (file_id, + widgetrec->type, + (XtPointer) + ((char *)widgetrec+widgetrec->class_offs), + &cldesc) ; + if ( result != MrmSUCCESS ) + return result ; + + /* + * Allocate the args list, big enough for all the arguments in the widget + * record plus all the override arguments. Also initialize a pointer list + * to save any contexts created to evaluate resources. + */ + if ( widgetrec->arglist_offs != 0) + { + argdesc = (RGMArgListDescPtr) + ((char *)widgetrec + widgetrec->arglist_offs) ; + num_listent += argdesc->count + argdesc->extra ; + UrmPlistInit (10, &ftllist) ; + } + if ( num_listent > 0 ) + { + args = (Arg *) XtMalloc (num_listent*sizeof(Arg)) ; + UrmPlistInit (10, &ptrlist) ; + } + + /* + * Set up the structure for the callback list to free memory on destory widget + */ + UrmPlistInit (10, &cblist); + + /* + * Set the arg list from the widget record argument list + */ + if ( argdesc != NULL ) + { + Urm__CW_CreateArglist + (parent, widgetrec, argdesc, ptrlist, cblist, ftllist, + hierarchy_id, file_id, args, svlist, wref_id, &num_used) ; + } + + /* + * Copy in any override args + */ + for ( ndx=0 ; ndxname_offs; + *w_return = (*(cldesc->creator)) (parent, *w_name, args, num_used) ; + + Urm__CW_AddWRef (wref_id, *w_name, *w_return) ; + if ( *svlist != NULL ) + Urm__CW_UpdateSVWidgetRef (svlist, *w_return) ; + + if ( manage==MrmManageManage )XtManageChild(*w_return); + + /* + * Call the creation callbacks if there are any. + */ + if ( widgetrec->creation_offs != 0) + { + if (strcmp(file_id->db_version, URM1_1version) <= 0) + cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr) + ((char *)widgetrec + + widgetrec->creation_offs)); + else + cbptr = (RGMCallbackDescPtr) ((char *)widgetrec + + widgetrec->creation_offs) ; + + if ( ptrlist == NULL ) + UrmPlistInit (10, &ptrlist) ; + result = Urm__CW_FixupCallback (parent, (XtPointer)widgetrec, cbptr, + ptrlist, cblist, hierarchy_id, + file_id, wref_id) ; + if ( result == MrmSUCCESS ) + for ( ndx=0 ; ndxcount ; ndx++ ) + { + itmptr = &cbptr->item[ndx] ; + + cb_rtn = (void (*)()) itmptr->runtime.callback.callback ; + if ( cb_rtn != (XtCallbackProc)NULL ) + /* BEGIN OSF Fix pir 2813 */ + { + cb_reason.reason = MrmCR_CREATE; + cb_reason.event = NULL; + (*cb_rtn) (*w_return, itmptr->runtime.callback.closure, + &cb_reason) ; + } + /* END OSF Fix pir 2813 */ + } + else if (result == MrmUNRESOLVED_REFS) + Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0056, + NULL, NULL, MrmFAILURE) ; + else + return Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0057, + NULL, NULL, MrmFAILURE); + + if (strcmp(file_id->db_version, URM1_1version) <= 0) + XtFree((char *)cbptr); + } + + /* + * successfully created (as far as we can tell). Deallocate all local + * resources, including any contexts in the pointer list. + */ + if ( args != NULL ) XtFree ((char*)args) ; + if ( ptrlist != NULL ) + { + for ( ndx=0 ; ndxnum_ptrs > 0) + { + XtAddCallback (*w_return, XmNdestroyCallback, + (XtCallbackProc) UrmDestroyCallback, cblist); + } + else + { + UrmPlistFree (cblist); + } + + /* + ** We should really let Xt take care of handling the fontlists by using its + ** converters; but for the meanwhile avoid freeing the fontlists here, as the + ** widget may be one which doesn't do an XmFontListCopy. Instead, later free + ** our extra copy. + */ + if (ftllist != NULL) + { + if (UrmPlistNum(ftllist) > 0) + XtAddCallback(*w_return, XmNdestroyCallback, + (XtCallbackProc) UrmDestroyCallback, ftllist); + else + UrmPlistFree (ftllist) ; + } + + return MrmSUCCESS ; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * UrmSetWidgetInstance sets the appropriate resources from a RGM widget + * record on the appropriate automatically created child of parent by: + * + * o Creating a legal XtSetValues arglist from the RGM + * arglist by expanding compressed tags, evaluating values, + * and doing type conversion. + * + * o Finding the correct widget child of parent by uncompressing + * the resource compression code found in the RGM record's + * type specifier, and calling XtNameToWidget on the result. + * + * Once UrmSetWidgetInstance has been called, then the only + * information in the RGM record which may still be required is the + * privacy information and the widget children list. This information + * may be copied and the resource context reused by users who are doing + * recursive widget access, and wish to avoid recursive accumulation + * of resource contexts in memory (see next routine). + * + * The URM hierarchy for public resources and the IDB file for private + * resources are required to evaluate resource references occurring in + * the widget arglist. + * + * This routine accepts override parameters to override + * arguments in the setvalues arglist. They are appended + * to the list created from the UID file, and do not replace all values. + * + * FORMAL PARAMETERS: + * + * context_id context containing widget record describing widget + * to create + * parent id of parent widget + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * ov_args Override arglist, exactly as would be given to + * XtCreateWidget (conversion complete, etc). NULL + * for no override. + * ov_num_args # args in ov_args; 0 for no override + * keytype type of key which accessed this widget + * kindex index for URMrIndex access + * krid resource id for URMrRID access + * manage create-managed flag + * svlist list of SetValues descriptors + * wref_id structure in which to resolve references to widgets + * which have already been defined. + * w_return To return id of newly created widget + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmBAD_CONTEXT invalid context + * MrmBAD_WIDGET_REC invalid widget record + * + * SIDE EFFECTS: + * + *-- + */ + +/*ARGSUSED*/ +Cardinal +UrmSetWidgetInstance (URMResourceContextPtr context_id, + Widget parent, + MrmHierarchy hierarchy_id, + IDBFile file_id, + ArgList ov_args, + Cardinal ov_num_args, + MrmCode keytype, /* unused */ + String kindex, /* unused */ + MrmResource_id krid, /* unused */ + MrmManageFlag manage, + URMPointerListPtr *svlist, + URMResourceContextPtr wref_id, + Widget *w_return) +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + RGMWidgetRecordPtr widgetrec ; /* widget record in the context */ + String c_name ; /* child name */ + String c_name_tmp ; /* child name - temporary */ + RGMArgListDescPtr argdesc = NULL ; /* arg list descriptor in record */ + Arg *args = NULL ; /* arg list argument for create */ + Cardinal num_used = 0 ; /* number of args used in arglist */ + MrmCount num_listent = ov_num_args ; /* # entries in args */ + URMPointerListPtr ptrlist = NULL ;/* to hold scratch contexts */ + URMPointerListPtr cblist = NULL ; /* to hold scratch callbacks */ + URMPointerListPtr ftllist = NULL ;/* to hold scratch fontlists */ + int ndx ; /* loop index */ + RGMCallbackDescPtr cbptr ; /* creation callback descriptor */ + RGMCallbackItemPtr itmptr ; /* current callback item */ + void (* cb_rtn) () ; /* current callback routine */ + /* BEGIN OSF Fix pir 1860, 2813 */ + XmAnyCallbackStruct cb_reason; /* creation callback reason */ + /* END OSF Fix pir 1860, 2813 */ + + /* + * Validate the context and the widget record in the context. + */ + if ( ! UrmRCValid(context_id) ) + return Urm__UT_Error ("UrmSetWidgetInstance", _MrmMMsg_0043, + NULL, NULL, MrmBAD_CONTEXT) ; + widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ; + if ( ! UrmWRValid(widgetrec) ) + return Urm__UT_Error ("UrmSetWidgetInstance", _MrmMMsg_0026, + NULL, context_id, MrmBAD_WIDGET_REC) ; + + result = Urm__UncompressCode (file_id, widgetrec->type, &c_name) ; + if ( result != MrmSUCCESS ) + return Urm__UT_Error("UrmSetWidgetInstance", _MrmMMsg_0058, + NULL, context_id, result) ; + + /* Find the widget */ + if (strcmp(c_name, "TearOffControl") == 0) /* Special case */ + *w_return = XmGetTearOffControl(parent); + else + { + /* Need to add * for ScrolledText and ScrolledList */ + c_name_tmp = (String)ALLOCATE_LOCAL((strlen(c_name) + 2) * sizeof(char)); + sprintf(c_name_tmp, "*%s", c_name); + *w_return = XtNameToWidget(parent, c_name_tmp); + + /* Deal with ScrollBars for ScrolledList and ScrolledText subclasses. */ + if ((*w_return == NULL) && + ((strcmp(c_name, "VertScrollBar") == 0) || + (strcmp(c_name, "HorScrollBar") == 0))) + { + *w_return = XtNameToWidget(XtParent(parent), c_name_tmp); + } + + DEALLOCATE_LOCAL(c_name_tmp); + } + + if (*w_return == NULL) + return Urm__UT_Error("UrmSetWidgetInstance", _MrmMMsg_0059, + NULL, context_id, MrmFAILURE) ; + + /* + * Allocate the args list, big enough for all the arguments in the widget + * record plus all the override arguments. Also initialize a pointer list + * to save any contexts created to evaluate resources. + */ + if ( widgetrec->arglist_offs != 0) + { + argdesc = (RGMArgListDescPtr) + ((char *)widgetrec + widgetrec->arglist_offs) ; + num_listent += argdesc->count + argdesc->extra ; + UrmPlistInit (10, &ftllist) ; + } + if ( num_listent > 0 ) + { + args = (Arg *) XtMalloc (num_listent*sizeof(Arg)) ; + UrmPlistInit (10, &ptrlist) ; + } + + /* + * Set up the structure for the callback list to free memory on destroy widget + */ + UrmPlistInit (10, &cblist); + + /* + * Set the arg list from the widget record argument list + */ + if ( argdesc != NULL ) + { + Urm__CW_CreateArglist + (parent, widgetrec, argdesc, ptrlist, cblist, ftllist, + hierarchy_id, file_id, args, svlist, wref_id, &num_used) ; + } + + /* + * Copy in any override args + */ + for ( ndx=0 ; ndxcreation_offs != 0) + { + if (strcmp(file_id->db_version, URM1_1version) <= 0) + cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr) + ((char *)widgetrec + + widgetrec->creation_offs)); + else + cbptr = (RGMCallbackDescPtr) ((char *)widgetrec + + widgetrec->creation_offs) ; + + if ( ptrlist == NULL ) + UrmPlistInit (10, &ptrlist) ; + result = Urm__CW_FixupCallback (parent, (XtPointer)widgetrec, + cbptr, ptrlist, cblist, hierarchy_id, + file_id, wref_id) ; + if ( result == MrmSUCCESS ) + for ( ndx=0 ; ndxcount ; ndx++ ) + { + itmptr = &cbptr->item[ndx] ; + + cb_rtn = (void (*)()) itmptr->runtime.callback.callback ; + if ( cb_rtn != (XtCallbackProc)NULL ) + /* BEGIN OSF Fix pir 2813 */ + { + cb_reason.reason = MrmCR_CREATE; + cb_reason.event = NULL; + (*cb_rtn) (*w_return, itmptr->runtime.callback.closure, + &cb_reason) ; + } + /* END OSF Fix pir 2813 */ + } + else if (result == MrmUNRESOLVED_REFS) + Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0056, + NULL, NULL, MrmFAILURE) ; + else + return Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0057, + NULL, NULL, MrmFAILURE); + + if (strcmp(file_id->db_version, URM1_1version) <= 0) + XtFree((char *)cbptr); + } + + /* + * successfully set (as far as we can tell). Deallocate all local + * resources, including any contexts in the pointer list. + */ + if ( args != NULL ) XtFree ((char*)args) ; + if ( ptrlist != NULL ) + { + for ( ndx=0 ; ndxnum_ptrs > 0) + { + XtAddCallback (*w_return, XmNdestroyCallback, + (XtCallbackProc) UrmDestroyCallback, cblist); + } + else + { + UrmPlistFree (cblist); + } + + /* + ** We should really let Xt take care of handling the fontlists by using its + ** converters; but for the meanwhile avoid freeing the fontlists here, as the + ** widget may be one which doesn't do an XmFontListCopy. Instead, later free + ** our extra copy. + */ + if (ftllist != NULL) + { + if (UrmPlistNum(ftllist) > 0) + XtAddCallback(*w_return, XmNdestroyCallback, + (XtCallbackProc) UrmDestroyCallback, ftllist); + else + UrmPlistFree (ftllist) ; + } + + return MrmSUCCESS ; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * Urm__CW_CreateArglist reads the arglist descriptor in an RGM widget + * record and produces a legal arglist for XtCreateWidget in the args + * parameter. Any argument which encounters an error, or which must + * be done with a SetValues, does not appear in the list. + * + * FORMAL PARAMETERS: + * + * parent parent of the widget being created + * widgetrec widget record pointer + * argdesc arglist descriptor in widget record + * ctxlist A pointer list to save contexts created to + * evaluate literals. + * ftllist A pointer list to save fontlists created for use + * as resource values, and which must be freed + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * args buffer in which the arglist array of longwords is to + * be created. Caller guarantees that it is big enough + * (since caller knows number of arguments). + * svlist SetValues descriptor list. This routine will add + * any SetValues widget arguments to this list. + * wref_id reference structure from which references to + * previously created widgets in the tree can be + * resolved. + * num_used Returns number of arguments actually set in args + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +void +Urm__CW_CreateArglist (Widget parent, + RGMWidgetRecordPtr widgetrec, + RGMArgListDescPtr argdesc, + URMPointerListPtr ctxlist, + URMPointerListPtr cblist, + URMPointerListPtr ftllist, + MrmHierarchy hierarchy_id, + IDBFile file_id, + ArgList args, + URMPointerListPtr *svlist, + URMResourceContextPtr wref_id, + Cardinal *num_used) + +{ + /* + * Local structures + */ + typedef struct { + RGMIconImagePtr icon ; /* icon to be converted */ + RGMArgumentPtr pixarg ; /* argument in widget record */ + String filename; /* file name if pixtype is bitmap */ + MrmType pixtype ; /* MrmRtypeIconImage or */ + /* MrmRtypeXBitmapFile */ + } _SavePixmapItem, *_SavePixmapItemPtr ; + + /* + * Local variables + */ + Cardinal result ; /* function results */ + int ndx, cbndx; /* loop indices */ + RGMArgumentPtr argptr ; /* current argument descriptor */ + MrmType reptype ; /* arg value representation type */ + long argval ; /* arg value as it is in record */ + int vec_count ; /* count of items in the vector */ + long val ; /* value as immediate or pointer */ + RGMCallbackDescPtr cbptr ; /* val as callback descriptor */ + RGMCallbackItemPtr items; /* Callback items as RGM items */ + XtCallbackRec *callbacks; /* Callback items as Xt callbacks */ + RGMIconImagePtr icon ; /* val as icon image */ + RGMResourceDescPtr resptr ; /* values as resource reference */ + String ref_name ; /* referenced widget name */ + Widget ref_id ; /* referenced widget id */ + IDBFile act_file ; /* file from which literals read */ + RGMTextVectorPtr vecptr ; /* text vector arg value */ + char err_msg[300] ; + _SavePixmapItem pixargs[10] ; /* to save pixmap args */ + Cardinal pixargs_cnt = 0 ; /* # pixargs saved */ + _SavePixmapItemPtr savepix ; /* current saved pixmap entry */ + Screen *screen ; /* screen for pixmaps */ + Display *display ; /* display for pixmaps */ + Pixel fgint = (Pixel) -1 ; /* fg for pixmaps */ + Pixel bgint = (Pixel) -1 ; /* background for pixmaps */ + Pixmap pixmap ; /* result of icon conversion */ + Cardinal uncmp_res ; /* string uncompression result */ + WCIClassDescPtr class_desc ; /* for URM__FindClassDescriptor */ + String resource_name ; /* resource name for comparison */ + int vec_size ; + RGMFontListPtr fontlist; /* for converting old style fontlist */ + Boolean swap_needed; /* for resource arguments */ + + /* + * Loop through all the arguments in descriptor. An entry is made in the + * in the arglist for each entry which can be successfully evaluated, + * fixed up, and converted. + * + * Some arguments may be affected by other arg values in the arglist. These + * are deferred so that these other values will + * be available if they are present in the arglist. This removes order + * dependency. All such arguments are handled as special cases: + * IconImages: saved in pixargs vector + * + * Ordering may have an important effect on finding widget references. In + * particular, references to widgets in submenus depends on the submenus + * being created before the reference, as the referenced widget then + * appears in the widget reference structure. This is currently done + * by the compiler, which orders submenus first in an arglist. + */ + for ( ndx=0 ; ndxcount ; ndx++ ) + { + argptr = &argdesc->args[ndx] ; + reptype = argptr->arg_val.rep_type ; + swap_needed = FALSE ; + + /* + * Create the value. Some representation types and arguments require + * special handling. First, the immediate value or pointer is evaluated. + * then special handling is done. If no special handling is required, then + * the value is fixed up, converted, and put in the args list. + * + * Icon images are loaded (i.e. brought into memory and all pointer + * fixups done), but they are then treated as SetValues args, and saved + * for processing after the widget is created. + */ + argval = Urm__CW_EvaluateValOrOffset (reptype, (XtPointer)widgetrec, + argptr->arg_val.datum.ival, + argptr->arg_val.datum.offset) ; + val = argval ; + switch ( reptype ) + { + case MrmRtypeCallback: + if (strcmp(file_id->db_version, URM1_1version) <= 0) + cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)val); + else + cbptr = (RGMCallbackDescPtr)val; + + result = Urm__CW_FixupCallback(parent, (XtPointer)widgetrec, cbptr, + ctxlist, cblist, hierarchy_id, + file_id, wref_id) ; + switch (result) + { + case MrmSUCCESS: + /* Move individual items so array functions as callback list */ + items = cbptr->item; + callbacks = (XtCallbackRec *)((RGMCallbackDescPtr)val)->item; + + for (cbndx = 0; cbndx <= cbptr->count; cbndx++) + /* <= so that null item is copied. */ + { + callbacks[cbndx].callback = (XtCallbackProc) + items[cbndx].runtime.callback.callback; + callbacks[cbndx].closure = (XtPointer) + items[cbndx].runtime.callback.closure; + } + + val = (long)callbacks; + break; + case MrmUNRESOLVED_REFS: + Urm__CW_AppendCBSVWidgetRef + (file_id, svlist, cbptr, argptr->tag_code, + (String) ((char *)widgetrec+argptr->stg_or_relcode.tag_offs)); + /* No break */ + default: + continue; + } + if (strcmp(file_id->db_version, URM1_1version) <= 0) + XtFree((char *)cbptr); + break ; + case MrmRtypeResource: + resptr = (RGMResourceDescPtr) val ; + if (resptr->cvt_type & MrmResourceUnswapped) + { + resptr->cvt_type &= ~MrmResourceUnswapped; + swap_needed = TRUE; + } + + switch ( resptr->res_group ) + { + case URMgWidget: + if ( ((unsigned char)resptr->cvt_type==RGMwrTypeSubTree) || + Urm__IsSubtreeResource(file_id,argptr->tag_code) ) + { + result = + Urm__CW_LoadWidgetResource (parent, widgetrec, resptr, + ctxlist, hierarchy_id, file_id, + svlist, wref_id, &val) ; + if ( result != MrmSUCCESS ) continue ; + } + else + { + if ( resptr->type != URMrIndex ) + { + Urm__UT_Error ("Urm__CW_CreateArglist", _MrmMMsg_0060, + NULL, NULL, MrmFAILURE) ; + continue; + } + ref_name = (String) resptr->key.index; + result = Urm__CW_FindWRef (wref_id, ref_name, &ref_id) ; + if ( result != MrmSUCCESS ) + { + Urm__CW_AppendSVWidgetRef + (file_id, svlist, ref_name, argptr->tag_code, + (String)widgetrec+ + argptr->stg_or_relcode.tag_offs); + continue ; + } + val = (long) ref_id ; + } + break ; + case URMgLiteral: + result = Urm__CW_ReadLiteral (resptr, hierarchy_id, file_id, + ctxlist, &reptype, &argval, + &vec_count, &act_file, &vec_size) ; + val = argval ; + if ( result != MrmSUCCESS ) continue ; + switch ( reptype ) + { + case MrmRtypeIconImage: + savepix = &pixargs[pixargs_cnt] ; + savepix->icon = (RGMIconImagePtr) val ; + savepix->pixarg = argptr ; + savepix->pixtype = reptype ; + pixargs_cnt += 1 ; + continue ; + case MrmRtypeXBitmapFile: + savepix = &pixargs[pixargs_cnt] ; + savepix->filename = (String) val ; + savepix->pixarg = argptr ; + savepix->pixtype = reptype ; + pixargs_cnt += 1 ; + continue ; + case MrmRtypeInteger: + case MrmRtypeBoolean: + if ( swap_needed ) + { + swapbytes( val ); + swap_needed = FALSE ; + } + break; + case MrmRtypeFontList: + if (strcmp(file_id->db_version, URM1_1version) <= 0) + { + int count = ((OldRGMFontListPtr)val)->count; + fontlist = (RGMFontListPtr) + XtMalloc(sizeof(RGMFontList) + + (sizeof(RGMFontItem) * (count - 1))); + result = Urm__CW_FixupValue((long)fontlist, reptype, + (XtPointer)val, file_id, + &swap_needed); + val = (long)fontlist; + } + else + result = Urm__CW_FixupValue(val, reptype, + (XtPointer)val, + file_id, &swap_needed) ; + break; + case MrmRtypeSingleFloat: + if ( swap_needed ) + { + swapbytes( val ); + swap_needed = FALSE ; + } + _MrmOSIEEEFloatToHost( (float *) &val ); + break; + case MrmRtypeFloat: + if ( swap_needed ) + { + swapdouble( *(double *)val ); + swap_needed = FALSE ; + } + _MrmOSIEEEDoubleToHost( (double *) val ); + break; + default: + result = Urm__CW_FixupValue(val,reptype,(XtPointer)val, + file_id, &swap_needed) ; + } + if ( result != MrmSUCCESS ) continue ; + + /* + * Fix for CR 5410 - Do not run ConvertValue on Colors + * because the parent's colormap should be used when + * allocating the colors which is currently impossible + * in ConvertValue. Convert the colors separately. + */ + if (reptype == MrmRtypeColor) + { + Pixel pix; + RGMColorDescPtr colorptr; + Colormap cmap; + + uncmp_res = Urm__FindClassDescriptor + (file_id, widgetrec->type, + (XtPointer)((char *)widgetrec+widgetrec->class_offs), + &class_desc) ; + if ((uncmp_res == MrmSUCCESS) && + (class_desc->creator == _XmCreateRendition)) + { + display = _XmRenderTableDisplay((XmRenderTable)parent); + cmap = XDefaultColormap(display, XDefaultScreen(display)); + } + else { + display = XtDisplay(parent); + cmap = parent->core.colormap; + } + + colorptr = (RGMColorDescPtr) val; + switch (colorptr->desc_type) + { + case URMColorDescTypeName: + result = Urm__UT_GetNamedColorPixel + (display, cmap, colorptr, &pix, + XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))); + if ( result != MrmSUCCESS ) + { + sprintf (err_msg, _MrmMMsg_0061, + (String)(colorptr->desc.name)) ; + result = Urm__UT_Error("Urm__CW_ConvertValue",err_msg, + NULL, NULL, MrmNOT_FOUND) ; + } + break; + case URMColorDescTypeRGB: + result = Urm__UT_GetColorPixel + (display, cmap, colorptr, &pix, + XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))); + if ( result != MrmSUCCESS ) + { + sprintf (err_msg, _MrmMMsg_0039, + colorptr->desc.rgb.red, + colorptr->desc.rgb.green, + colorptr->desc.rgb.blue) ; + result = Urm__UT_Error("Urm__CW_ConvertValue",err_msg, + NULL, NULL, MrmNOT_FOUND) ; + } + break; + default: + sprintf (err_msg, _MrmMMsg_0040); + result = Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmFAILURE) ; + }; + val = (long) pix ; + } + else + /* + * End Fix for CR 5410 + */ + { + uncmp_res = Urm__FindClassDescriptor + (file_id, widgetrec->type, + (XtPointer)((char *)widgetrec+widgetrec->class_offs), + &class_desc) ; + if ((uncmp_res == MrmSUCCESS) && + (class_desc->creator == _XmCreateRendition)) + display = _XmRenderTableDisplay((XmRenderTable)parent); + else + display = XtDisplay(parent); + + result = Urm__CW_ConvertValue (parent, &val, reptype, + resptr->cvt_type, display, + hierarchy_id, ftllist) ; + } + + if ( result != MrmSUCCESS ) continue ; + if ( argptr->tag_code == UilMrmUnknownCode ) + { + resource_name = (char *) + ((char *)widgetrec+argptr->stg_or_relcode.tag_offs) ; + } + else + { + uncmp_res = Urm__UncompressCode + (file_id, argptr->tag_code, &resource_name) ; + if ( uncmp_res != MrmSUCCESS ) + { + sprintf (err_msg, _MrmMMsg_0062, + argptr->tag_code) ; + Urm__UT_Error ("Urm__CW_CreateArglist", + err_msg, NULL, NULL, uncmp_res) ; + } + } + + if ( strcmp(resource_name, XmNuserData) == 0) + { + switch (reptype) + { + case MrmRtypeChar8Vector: + case MrmRtypeCStringVector: + vec_size -= (sizeof ( RGMTextVector ) - + sizeof ( RGMTextEntry )); + break; + default: + break; + } + Urm__CW_SafeCopyValue (&val, reptype, cblist, + vec_count, vec_size); + } + + /* + * Fix for CR 3281 - check to see if the resource_name + * is XmNaccelerators. If it is, run + * XtParseAcceleratorTable and assign the output to val. + */ + if ( strcmp(resource_name, XmNaccelerators) == 0) + { + val = (long)XtParseAcceleratorTable((String)argval); + } + /* + * End fix for CR 3281 + */ + break ; + + default: + Urm__UT_Error ("Urm__CW_CreateArglist", _MrmMMsg_0063, + NULL, NULL, MrmFAILURE) ; + continue ; + } + break ; + case MrmRtypeIconImage: + icon = (RGMIconImagePtr) val ; + result = Urm__CW_LoadIconImage (icon, (XtPointer)widgetrec, + hierarchy_id, file_id, ctxlist) ; + if ( result != MrmSUCCESS ) continue ; + savepix = &pixargs[pixargs_cnt] ; + savepix->icon = icon ; + savepix->pixarg = argptr ; + savepix->pixtype = reptype ; + pixargs_cnt += 1 ; + continue ; + case MrmRtypeXBitmapFile: + savepix = &pixargs[pixargs_cnt] ; + savepix->filename = (String) val ; + savepix->pixarg = argptr ; + savepix->pixtype = reptype ; + pixargs_cnt += 1 ; + continue ; + default: + result = Urm__CW_FixupValue (val, reptype, (XtPointer)widgetrec, + file_id, &swap_needed) ; + if ( result != MrmSUCCESS ) continue ; + uncmp_res = Urm__FindClassDescriptor + (file_id, widgetrec->type, + (XtPointer)((char *)widgetrec+widgetrec->class_offs), + &class_desc); + if ((uncmp_res == MrmSUCCESS) && + (class_desc->creator == _XmCreateRendition)) + display = _XmRenderTableDisplay((XmRenderTable)parent); + else if ((uncmp_res == MrmSUCCESS) && + (class_desc->creator == _XmCreateTab)) + display = NULL; + else display = XtDisplay(parent); + result = Urm__CW_ConvertValue + (parent, &val, reptype, 0, display, + hierarchy_id, ftllist) ; + if ( result != MrmSUCCESS ) continue ; + break ; + } + + args[*num_used].value = (XtArgVal)val ; + + /* + * Create the tag string in the name slot of the current entry. Also + * do any special processing based on tag code: + * - Retain values of foreground and background if they are + * explicitly set + * - Set the count for some lists + * + * 'argval' has preserved the pointer to RGM structures which may have + * been replaced in 'val' by a pointer to structures (lists) required by + * the toolkit + */ + if ( argptr->tag_code == UilMrmUnknownCode ) + { + args[*num_used].name = (char *) + widgetrec+argptr->stg_or_relcode.tag_offs ; + *num_used += 1 ; + } + else + { + uncmp_res = Urm__UncompressCode + (file_id, argptr->tag_code, &(args[*num_used].name)) ; + if ( uncmp_res == MrmSUCCESS ) + *num_used += 1 ; + else + { + sprintf (err_msg, _MrmMMsg_0062, argptr->tag_code) ; + Urm__UT_Error ("Urm__CW_CreateArglist", err_msg, + NULL, NULL, uncmp_res) ; + } + } + + /* + * Special processing: + * retain the value pointer for foreground or background. + * Note reference to name in arglist from previous operation. + */ + /* Begin fixing OSF 5473 */ + if(*num_used){ + if ( strcmp(args[*num_used-1].name,XmNforeground) == 0 ) + fgint = val ; + if ( strcmp(args[*num_used-1].name,XmNbackground) == 0 ) + bgint = val ; + } + /* End fixing OSF 5473 */ + + /* + * Create an additional arglist entry for the count field for any argument + * which has a related argument (which is always a counter) + */ + if ( argptr->tag_code != UilMrmUnknownCode ) + if ( argptr->stg_or_relcode.related_code != 0) + { + switch ( reptype ) + { + case MrmRtypeChar8Vector: + case MrmRtypeCStringVector: + /* + * Fix for HaL DTS 10226 - If the type is Integer Vector + * (used mainly in the XmNselectionArray resource on + * the Text and TextField widgets), load in the count + * for the XmNselectionArrayCount resource. + */ + case MrmRtypeIntegerVector: + vecptr = (RGMTextVectorPtr) argval; + args[*num_used].value = (XtArgVal)vecptr->count; + break; + } + uncmp_res = Urm__UncompressCode + (file_id, argptr->stg_or_relcode.related_code, + &args[*num_used].name); + if ( uncmp_res == MrmSUCCESS ) + *num_used += 1; + else + { + sprintf (err_msg, _MrmMMsg_0062, argptr->tag_code) ; + Urm__UT_Error ("Urm__CW_CreateArglist", err_msg, + NULL, NULL, uncmp_res) ; + } + } + + } /* Loop end */ + + + /* + * Now set any pixmap arguments. This requires finding the display, screen, + * foreground, and background values for this widget. These values are + * available from the parent widget and the arglist. + */ + if ( pixargs_cnt > 0 ) + { + Urm__CW_GetPixmapParms (parent, &screen, &display, &fgint, &bgint) ; + for ( ndx=0,savepix=pixargs ; ndxpixtype == MrmRtypeXBitmapFile ) { + result = Urm__CW_ReadBitmapFile + (savepix->filename, screen, + fgint, bgint, &pixmap, parent); + if ( result != MrmSUCCESS ) continue ; + } + else { + /* + ** Create a pixmap from an Icon definition + */ + result = UrmCreatePixmap (savepix->icon, screen, display, + fgint, bgint, &pixmap, parent) ; + if ( result != MrmSUCCESS ) continue ; + } + + /* + ** Place resultant Pixmap in arglist + */ + args[*num_used].value = (XtArgVal) pixmap ; + argptr = savepix->pixarg ; + if ( argptr->tag_code == UilMrmUnknownCode ) + args[*num_used].name = (char *) + (widgetrec+argptr->stg_or_relcode.tag_offs) ; + else + Urm__UncompressCode + (file_id, argptr->tag_code, &(args[*num_used].name)) ; + *num_used += 1 ; + } + } + + /* + * arglist creation complete. + */ + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * Return either a immediate value (ival) or a widget record memory + * pointer depending on the representation type. + * + * FORMAL PARAMETERS: + * + * reptype representation type, from RGMrType... + * bufptr buffer address for offset + * ival immediate value + * offset offset in widget record + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +long +Urm__CW_EvaluateValOrOffset (MrmType reptype, + XtPointer bufptr, + long ival, + MrmOffset offset) +{ + + switch ( reptype ) + { + case MrmRtypeInteger: + case MrmRtypeBoolean: + case MrmRtypeSingleFloat: + return ival ; + case MrmRtypeNull: + return 0; + default: + return (long) ((char *)bufptr+offset) ; + } + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine does any fixups required on a value. The fixups are + * usually relocation of pointers within the object located by the + * value interpreted as a pointer to a data structure. + * + * FORMAL PARAMETERS: + * + * val value of an argument (may be a pointer) + * reptype vaue representation type, from RGMrType... + * bufptr the buffer (base address) for any fixed-up + * values + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS ; + * + * SIDE EFFECTS: + * + *-- + */ + +/*ARGSUSED*/ +Cardinal +Urm__CW_FixupValue (long val, + MrmType reptype, + XtPointer bufptr, + IDBFile file_id, /* unused */ + Boolean *swap_needed) +{ + /* + * Local variables + */ + RGMTextVectorPtr vecptr ; /* text vector arg value */ + int fixndx ; /* list fixup loop index */ + /* BEGIN OSF Fix CR 4859 */ + RGMWCharEntryPtr wcharentry; /* Resource as wide character string */ + wchar_t *wcstr_r; + size_t max_size, str_size; + /* END OSF Fix CR 4859 */ + RGMFontItemPtr fontitem; /* resource as font item */ + OldRGMFontItemPtr olditem; /* old style font item */ + RGMFontListPtr fontlist ; /* resource as font list */ + OldRGMFontListPtr oldlist ; /* resource as old style font list */ + + switch ( reptype ) + { + case MrmRtypeChar8Vector: + case MrmRtypeCStringVector: + vecptr = (RGMTextVectorPtr) val ; + if ( *swap_needed ) + { + swapbytes(vecptr->count); + swapbytes(vecptr->validation); + } + for ( fixndx=0 ; fixndxcount ; fixndx++ ) + { + if ( *swap_needed ) + { +#ifdef WORD64 + swap4bytes(vecptr->item[fixndx].text_item.rep_type); + swap4bytes(vecptr->item[fixndx].text_item.offset); +#else + swap2bytes(vecptr->item[fixndx].text_item.rep_type); + swap2bytes(vecptr->item[fixndx].text_item.offset); +#endif + } + if (reptype == MrmRtypeChar8Vector) + vecptr->item[fixndx].pointer = (XtPointer) + ((char *)bufptr+vecptr->item[fixndx].text_item.offset) ; + else + vecptr->item[fixndx].pointer = (XtPointer) + XmCvtByteStreamToXmString((unsigned char *)bufptr + + vecptr->item[fixndx].text_item.offset); + } + *swap_needed = FALSE; + break ; + + /* BEGIN OSF Fix CR 4859 */ + case MrmRtypeWideCharacter: + wcharentry = (RGMWCharEntryPtr)val; + if (*swap_needed) + swapbytes(wcharentry->wchar_item.count); + /* Allocate memory */ + max_size = wcharentry->wchar_item.count; + wcstr_r = (wchar_t *)XtMalloc(sizeof(wchar_t) * (max_size + 1)); + + /* Convert, realloc, store */ + str_size = mbstowcs(wcstr_r, wcharentry->wchar_item.bytes, max_size); + if (str_size == -1) + return(Urm__UT_Error("Urm__CW_FixupValue", _MrmMMsg_0110, + NULL, NULL, MrmFAILURE)); + if (str_size != max_size) + wcstr_r = (wchar_t *)XtRealloc((char *)wcstr_r, + sizeof(wchar_t) * (str_size + 1)); + else + wcstr_r[str_size] = (wchar_t)0L; + wcharentry->pointer = (XtPointer)wcstr_r; + *swap_needed = FALSE; + break; + + /* END OSF Fix CR 4859 */ + case MrmRtypeFont: + case MrmRtypeFontSet: + fontitem = (RGMFontItemPtr) val; + if ( *swap_needed ) + { + swapbytes( fontitem->cset.cs_offs ); + swapbytes( fontitem->font.font_offs ); + } + fontitem->cset.charset = (/*XmStringCharset*/String) + bufptr+fontitem->cset.cs_offs; + fontitem->font.font = (String) + bufptr+fontitem->font.font_offs; + *swap_needed = FALSE; + break; + case MrmRtypeFontList: + if (strcmp(file_id->db_version, URM1_1version) <= 0) + /* Converting an old style fontlist */ + { + oldlist = (OldRGMFontListPtr)bufptr; + + fontlist = (RGMFontListPtr)val; + + fontlist->validation = oldlist->validation; + fontlist->count = oldlist->count; + + for ( fixndx=0 ; fixndxcount ; fixndx++ ) + { + olditem = &oldlist->item[fixndx]; + fontitem = &fontlist->item[fixndx]; + + fontitem->cset.charset = + XtNewString(( /*XmStringCharset*/String) + bufptr+olditem->cset.cs_offs); + fontitem->font.font = + XtNewString((String)bufptr+olditem->font.font_offs); + fontitem->type = MrmRtypeFont; + } + } + else + { + fontlist = (RGMFontListPtr) val ; + if ( *swap_needed ) + { + swapbytes( fontlist->validation ); + swapbytes( fontlist->count ); + } + for ( fixndx=0 ; fixndxcount ; fixndx++ ) + { + fontitem = &fontlist->item[fixndx]; + if ( *swap_needed ) + { + swapbytes( fontitem->cset.cs_offs ); + swapbytes( fontitem->font.font_offs ); + swapbytes( fontitem->type ); + } + fontitem->cset.charset = ( /*XmStringCharset*/String) + bufptr+fontitem->cset.cs_offs; + fontitem->font.font = (String) + bufptr+fontitem->font.font_offs; + } + } + *swap_needed = FALSE; + break ; + case MrmRtypeHorizontalInteger: + case MrmRtypeVerticalInteger: + { + RGMUnitsIntegerPtr unitsvalue; + + unitsvalue = (RGMUnitsIntegerPtr) val; + if ( *swap_needed ) + { + swapbytes( unitsvalue->value ); + swapbytes( unitsvalue->units ); + *swap_needed = FALSE; + } + } + break ; + case MrmRtypeHorizontalFloat: + case MrmRtypeVerticalFloat: + { + RGMUnitsFloatPtr unitsvalue; + double *floatval; + + unitsvalue = (RGMUnitsFloatPtr) val; + floatval = (double *)(&unitsvalue->value[0]); + if ( *swap_needed ) + { + swapdouble(*floatval); + swapbytes( unitsvalue->units ); + } + *swap_needed = FALSE; + _MrmOSIEEEDoubleToHost( floatval ); + *((double *)(&unitsvalue->value[0])) = *floatval; + } + break ; + default: + break ; + } + return MrmSUCCESS ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine converts the display into a string byte by + * byte. Any Null bytes are not (?) omitted in returned string. + * + * FORMAL PARAMETERS: + * + * val the value to be converted (may be a pointer) + * add_sting a string to be added to the returned string + * after the display. + * add_string_size the additional string length when Calloc on + * the return value is done. + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * returns the string if one is created, otherwise returns null + * + * SIDE EFFECTS: + * + *-- + */ + +String +Urm__CW_DisplayToString (char *val, + String add_string, + int add_string_size) +{ + /* + * Local variables + */ + String return_val; + unsigned int dpysize = sizeof(Display *); + int ndx; + int count=0; + + return_val = XtCalloc (1, dpysize + add_string_size); + if (return_val == NULL) + { + return (return_val); + } + + for (ndx=0 ; ndxcount; + tbl = (String *)vecptr->item; + for (ndx = 0; ndx < vec_count; ndx++) + tbl[ndx] = (String)(vecptr->item[ndx].pointer); + *val = (long)tbl; + break ; + } + case MrmRtypeCStringVector: + { + XmStringTable tbl; + + vecptr = (RGMTextVectorPtr) (*val) ; + /* Have to pack vecptr */ + vec_count = vecptr->count; + tbl = (XmStringTable)vecptr->item; + for (ndx = 0; ndx < vec_count; ndx++) + tbl[ndx] = (XmString)(vecptr->item[ndx].pointer); + *val = (long)tbl; + break; + } + case MrmRtypeCString: + cstg = XmCvtByteStreamToXmString((unsigned char *)*val); + *val = (long)cstg; + /* BEGIN OSF Fix CR 8392 */ + /* fix memory leak */ + if ( ftllist != NULL ) + { + UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype); + UrmPlistAppendPointer (ftllist, (XtPointer)*val); + } + /* END OSF Fix CR 8392 */ + break; + case MrmRtypeIntegerVector: + { + RGMIntegerVectorPtr vecptr ; /* val as integer vector */ + + vecptr = (RGMIntegerVectorPtr) (*val) ; + *val = (long) vecptr->item ; + break ; + } + case MrmRtypeAddrName: + result = Urm__LookupNameInHierarchy (hierarchy_id, (String)(*val), &addr); + if ( result != MrmSUCCESS ) + { + sprintf (err_msg, _MrmMMsg_0066, (String)(*val)) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, result) ; + } + *val = (long) addr ; + break ; + case MrmRtypeIconImage: + Urm__CW_GetPixmapParms(parent, &screen, &display, &fgint, &bgint); + result = UrmCreatePixmap((RGMIconImagePtr)(*val), screen, display, + fgint, bgint, &pixmap, parent); + if (result != MrmSUCCESS) + return (Urm__UT_Error("Urm__CW_ConvertValue", _MrmMMsg_0112, + NULL, NULL, MrmFAILURE)); + *val = (long)pixmap; + break; + + case MrmRtypeXBitmapFile: + Urm__CW_GetPixmapParms(parent, &screen, &display, &fgint, &bgint); + result = Urm__CW_ReadBitmapFile((char *)(*val), screen, + fgint, bgint, &pixmap, parent); + if (result != MrmSUCCESS) + return (Urm__UT_Error("Urm__CW_ConvertValue", _MrmMMsg_0112, + NULL, NULL, MrmFAILURE)); + *val = (long)pixmap; + break; + + case MrmRtypeFont: + case MrmRtypeFontSet: + fontptr = (RGMFontItemPtr) (*val) ; + fontstg = fontptr->font.font; + dpyandfontstr = Urm__CW_DisplayToString ((char*)&display, + fontstg, strlen(fontstg) + 1); + if ( dpyandfontstr == NULL) + { + return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0069, + NULL, NULL, MrmFAILURE) ; + } + switch (reptype) + { + case MrmRtypeFont: + result = + Urm__WCI_LookupRegisteredName(dpyandfontstr, (XtPointer *)&font); + + if ( result != MrmSUCCESS ) + { + font = XLoadQueryFont (display, fontstg); + if ( font == NULL ) + { + sprintf (err_msg, _MrmMMsg_0070, fontstg); + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + Urm__WCI_RegisterNames (&dpyandfontstr, (XtPointer *)&font, 1); + { + XmDisplay dd = (XmDisplay) XmGetXmDisplay(display); + if (dd) + XtAddCallback((Widget)dd,XtNdestroyCallback, + DisplayDestroyCallback, (XtPointer) + XtNewString(dpyandfontstr)); + } + } + break; + + case MrmRtypeFontSet: + result = Urm__WCI_LookupRegisteredName(dpyandfontstr, + (XtPointer *)&fontset); + + if ( result != MrmSUCCESS ) + { + fontset = XCreateFontSet(display, fontstg, &missing_csets, + &missing_cset_cnt, &def_string); + if (fontset == NULL) + { + sprintf(err_msg, _MrmMMsg_0071, fontstg); + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + Urm__WCI_RegisterNames(&dpyandfontstr, + (XtPointer *)&fontset, 1); + } + break; + } + XtFree (dpyandfontstr); + if ( cvttype == MrmRtypeFontList ) + { + switch(reptype) + { + case MrmRtypeFont: + dfontlist = XmFontListCreate (font, fontptr->cset.charset) ; + break; + + case MrmRtypeFontSet: + fontset_entry = XmFontListEntryCreate(fontptr->cset.charset, + XmFONT_IS_FONTSET, + fontset); + dfontlist = XmFontListAppendEntry(NULL, fontset_entry); + break; + } + + if ( ftllist != NULL ) + { + UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype); + UrmPlistAppendPointer (ftllist, (XtPointer)dfontlist); + } + *val = (long) dfontlist ; + } + else + *val = (long) font ; + break ; + case MrmRtypeFontList: + fontlist = (RGMFontListPtr) (*val) ; + dfontlist = NULL ; + for ( ndx=0 ; ndxcount ; ndx++ ) + { + fontstg = fontlist->item[ndx].font.font; + dpyandfontstr = Urm__CW_DisplayToString((char*)&display, + fontstg, + strlen(fontstg) + 1); + if ( dpyandfontstr == NULL) + { + return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0069, + NULL, NULL, MrmFAILURE) ; + } + + switch (fontlist->item[ndx].type) + { + case MrmRtypeFont: + result = Urm__WCI_LookupRegisteredName(dpyandfontstr, + (XtPointer *)&font); + if ( result != MrmSUCCESS ) + { + font = XLoadQueryFont (display, fontstg); + if ( font == NULL ) + { + sprintf (err_msg, _MrmMMsg_0070, fontstg); + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + Urm__WCI_RegisterNames(&dpyandfontstr, (XtPointer *)&font, 1); + { + XmDisplay dd = (XmDisplay) XmGetXmDisplay(display); + if (dd) + XtAddCallback((Widget)dd,XtNdestroyCallback, + DisplayDestroyCallback, (XtPointer) + XtNewString(dpyandfontstr)); + } + } + break; + + case MrmRtypeFontSet: + result = Urm__WCI_LookupRegisteredName(dpyandfontstr, + (XtPointer *)&fontset); + if ( result != MrmSUCCESS ) + { + fontset = XCreateFontSet(display, fontstg, &missing_csets, + &missing_cset_cnt, &def_string); + if (fontset == NULL) + { + sprintf(err_msg, _MrmMMsg_0071, fontstg); + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + + if (missing_csets != NULL) + { + sprintf(err_msg, _MrmMMsg_0072, fontstg); + XFreeStringList(missing_csets); + } + Urm__WCI_RegisterNames(&dpyandfontstr, + (XtPointer *)&fontset, 1); + } + break; + } + + XtFree (dpyandfontstr); + switch(fontlist->item[ndx].type) + { + case MrmRtypeFont: + if ( dfontlist == NULL ) + dfontlist = XmFontListCreate + (font, fontlist->item[ndx].cset.charset) ; + else + dfontlist = XmFontListAdd + (dfontlist, font, fontlist->item[ndx].cset.charset) ; + if ( dfontlist == NULL ) + { + sprintf (err_msg, _MrmMMsg_0073, + fontlist->item[ndx].font.font) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmFAILURE) ; + } + break; + case MrmRtypeFontSet: + fontset_entry = + XmFontListEntryCreate(fontlist->item[ndx].cset.charset, + XmFONT_IS_FONTSET, + fontset); + dfontlist = XmFontListAppendEntry(NULL, fontset_entry); + if ( dfontlist == NULL ) + { + sprintf (err_msg, _MrmMMsg_0074, + fontlist->item[ndx].font.font) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmFAILURE) ; + } + break; + } + } + + *val = (long) dfontlist ; + /* + * Save only the final fontlist to be freed later. All intermediate + * ones are freed by XmFontListAdd + */ + if ( ftllist != NULL ) + { + UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype); + UrmPlistAppendPointer (ftllist, (XtPointer)dfontlist); + } + break ; + case MrmRtypeColor: + colorptr = (RGMColorDescPtr) (*val) ; + switch (colorptr->desc_type) + { + case URMColorDescTypeName: + result = Urm__UT_GetNamedColorPixel + (display, (Colormap)0, colorptr, &pix, + XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))) ; + if ( result != MrmSUCCESS ) + { + if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS; + sprintf (err_msg, _MrmMMsg_0061, (String)(colorptr->desc.name)) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + break; + case URMColorDescTypeRGB: + result = Urm__UT_GetColorPixel + (display, (Colormap)0, colorptr, &pix, + XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))) ; + if ( result != MrmSUCCESS ) + { + if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS; + sprintf (err_msg, _MrmMMsg_0039, + colorptr->desc.rgb.red, + colorptr->desc.rgb.green, + colorptr->desc.rgb.blue) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + break; + default: + sprintf(err_msg, _MrmMMsg_0040); + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmFAILURE) ; + }; + *val = (long) pix ; + break ; + /* BEGIN OSF Fix CR 4859 */ + case MrmRtypeWideCharacter: + { + RGMWCharEntryPtr wcharentry; + + wcharentry = (RGMWCharEntryPtr)*val; + *val = (long)wcharentry->pointer; + break; + } + /* END OSF Fix CR 4859 */ + case MrmRtypeTransTable: + /* + * WARNING: memory leak created... + */ + trans = XtParseTranslationTable ((String)(*val)) ; + if ( trans == NULL ) + { + sprintf (err_msg, _MrmMMsg_0065, (String)(*val)) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmFAILURE) ; + } + *val = (long) trans ; + break ; + case MrmRtypeClassRecName: + clrec = Urm__WCI_GetClRecOfName ((String)*val) ; + if ( clrec == NULL ) + { + sprintf (err_msg, _MrmMMsg_0075, (String)(*val)) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + *val = (long) clrec ; + break ; + case MrmRtypeKeysym: + xkey = XStringToKeysym ((String)*val); + if ( xkey == NoSymbol ) + { + sprintf (err_msg, _MrmMMsg_0076, (String)(*val)) ; + return Urm__UT_Error ("Urm__CW_ConvertValue", + err_msg, NULL, NULL, MrmNOT_FOUND) ; + } + *val = (long) xkey; + break; + case MrmRtypeHorizontalInteger: + orientation = XmHORIZONTAL; + /* fall through */ + case MrmRtypeVerticalInteger: + if (orientation == XmNO_ORIENTATION) + { + orientation = XmVERTICAL; + } + /* get a screen that we can use */ + screen = DefaultScreenOfDisplay(display); + unitsintvalue = (RGMUnitsIntegerPtr) *val; + if (unitsintvalue->value != 0) + { + *val = _XmConvertUnits(screen, orientation, unitsintvalue->units, + unitsintvalue->value, XmPIXELS); + if (*val == 0) + { + return Urm__UT_Error ("Urm__CW_ConvertValue", + _MrmMMsg_0115, NULL, NULL, MrmNOT_FOUND) ; + } + } + else *val = 0; + break; + case MrmRtypeHorizontalFloat: + orientation = XmHORIZONTAL; + /* fall through */ + case MrmRtypeVerticalFloat: + { + float float_val, int_value; + int int_units, float_units; + + if (orientation == XmNO_ORIENTATION) + { + orientation = XmVERTICAL; + } + /* get a screen that we can use */ + screen = DefaultScreenOfDisplay(display); + unitsfloatvalue = (RGMUnitsFloatPtr) *val; + float_units = unitsfloatvalue->units; + float_val = (float)(*((double *)(&unitsfloatvalue->value[0]))); + + if (float_val != 0) + { + if (_XmConvertFloatUnitsToIntUnits(float_units, float_val, + &int_units, &int_value, + XmPIXELS) == False) + { + return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0116, + NULL, NULL, MrmFAILURE); + } + *val = _XmConvertUnits(screen, orientation, int_units, + MAKEINT(int_value), XmPIXELS); + if (*val == 0) + { + return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0115, + NULL, NULL, MrmFAILURE); + } + } + else *val = 0; + } + break; + default: + break ; + } + + return MrmSUCCESS ; + +} + +/* +** Remove the font from the hash table so it won't later cause a protocol +** error if the display is closed and reopened and the same value is fetched. +*/ +/*ARGSUSED*/ +static void +DisplayDestroyCallback ( Widget w, + XtPointer client_data, + XtPointer call_data ) /* unused */ +{ + String dpyandfontstr = (String) client_data; + XFontStruct *font ; + + if (MrmSUCCESS == Urm__WCI_LookupRegisteredName(dpyandfontstr, + (XtPointer *)&font)) + XFreeFont(XtDisplay(w), font); + Urm__WCI_UnregisterName (dpyandfontstr); + XtFree(dpyandfontstr); +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine copies a value to an 'eternal' block in order + * to guarantee that callback tag values will live forever. + * + * FORMAL PARAMETERS: + * + * val the value to be copied (may be a pointer) + * reptype value representation type + * vec_count number of elements in the vector (for vector types) + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +static char* staticNull = NULL; + +void +Urm__CW_SafeCopyValue (long *val, + MrmType reptype, + URMPointerListPtr cblist, + int vec_count, + int vec_size) +{ + /* + * Local variables + */ + int *int_src ; /* to copy integer values */ + int *int_dst ; + String char8_src ; /* to copy string values */ + String char8_dst ; + float *single_float_src ; /* to copy FP values */ + float *single_float_dst ; + double *float_src ; /* to copy FP values */ + double *float_dst ; + XmString cstr_src ; /* to copy compound strings */ + XmString *cstr_table_src; /* to copy compound string table */ + XmString *cstr_table_dst ; + String *char8_table_src ; /* to coy string table */ + String *char8_table_dst ; + wchar_t *wchar_src; /* to copy wide character strings */ + wchar_t *wchar_dst; + size_t size; + int cnt ; + + /* + * Make copies of all primitive data structures. Note this has the side + * effect of converting integer values to by-reference. + */ + switch ( reptype ) + { + case MrmRtypeIntegerVector: + int_src = (int *) *val ; + int_dst = (int *) XtMalloc ((unsigned int)vec_size) ; + UrmBCopy (int_src, int_dst, vec_size) ; + *val = (long) int_dst ; + if (cblist != NULL) + { + UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype); + UrmPlistAppendPointer (cblist, (XtPointer)*val); + } + break ; + + case MrmRtypeCStringVector: + cstr_table_src = (XmString *)*val; + cstr_table_dst = + (XmString *)XtMalloc(vec_count * sizeof(XmString)) ; + for (cnt=0; cntnum_ptrs ; ndx++) + { + reptype = (MrmType)(long)list_id->ptr_vec[ndx]; + ndx++; + switch ( reptype ) + { + case MrmRtypeCString: + XmStringFree ((XmString)list_id->ptr_vec[ndx]); + break ; + /* BEGIN OSF Fix CR 6224 */ + case MrmRtypeFont: + /* Do not free the fontstruct. */ + break; + /* END OSF Fix CR 6224 */ + case MrmRtypeFontList: + XmFontListFree ((XmFontList)list_id->ptr_vec[ndx]); + break; + default: + /* BEGIN OSF Fix CR 6843 */ + /* Check for duplicates on list before freeing. */ + if (list_id->ptr_vec[ndx] != NULL) + { + for (i = ndx + 1; i < list_id->num_ptrs; ++i) + if (list_id->ptr_vec[ndx] == list_id->ptr_vec[i]) + list_id->ptr_vec[i] = NULL; + + XtFree (list_id->ptr_vec[ndx]); + } + /* END OSF Fix CR 6843 */ + break ; + } + } + + UrmPlistFree (list_id); + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine reads a literal resource from either a hierarchy or + * a file. It returns the resource type and either a pointer to the + * value or its immediate value. + * + * FORMAL PARAMETERS: + * + * resptr resource reference to literal + * hierarchy_id hierarchy from which to read public resource + * file_id file from which to read private resource + * ctxlist list in which to save resource contexts + * type to return representation type + * val to return immediate value or pointer + * vec_count to return number of items if type is a vector + * act_file_id to return id of file from which literal was read + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + * MrmSUCCESS operation succeeded + * other some failure, usually reading the literal + * + *-- + */ + +Cardinal +Urm__CW_ReadLiteral (RGMResourceDescPtr resptr , + MrmHierarchy hierarchy_id , + IDBFile file_id , + URMPointerListPtr ctxlist , + MrmType *type , + long *val , + int *vec_count , + IDBFile *act_file_id , + int *vec_size ) +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + URMResourceContextPtr context_id ; /* context for reading literal */ + char err_msg[300] ; + long *bufptr ; /* context buffer */ + + /* + * Acquire a context and read the literal into it. + */ + UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id) ; + switch ( resptr->type ) + { + case URMrIndex: + if ( resptr->access == URMaPublic ) + result = Urm__HGetIndexedLiteral + (hierarchy_id, resptr->key.index, context_id, act_file_id) ; + else + result = UrmGetIndexedLiteral + (file_id, resptr->key.index, context_id) ; + if ( result != MrmSUCCESS ) + { + UrmFreeResourceContext (context_id) ; + sprintf (err_msg, _MrmMMsg_0077, resptr->key.index) ; + return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg, + NULL, NULL, result) ; + } + break ; + case URMrRID: + result = UrmGetRIDLiteral (file_id, resptr->key.id, context_id) ; + *act_file_id = file_id ; + if ( result != MrmSUCCESS ) + { + UrmFreeResourceContext (context_id) ; + sprintf (err_msg, _MrmMMsg_0078, resptr->key.id) ; + return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg, + NULL, NULL, result) ; + } + break ; + default: + result = MrmFAILURE ; + UrmFreeResourceContext (context_id) ; + sprintf ( err_msg, _MrmMMsg_0079, resptr->type) ; + return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg, + NULL, NULL, result) ; + } + + /* + * return the rep type, size, and value. Save the resource context. + */ + *type = UrmRCType (context_id) ; + *vec_size = UrmRCSize(context_id); + *vec_count = 0; + bufptr = (long *) UrmRCBuffer (context_id) ; + *val = Urm__CW_EvaluateValOrOffset (*type, (XtPointer)bufptr, *bufptr, 0) ; + UrmPlistAppendPointer (ctxlist, (XtPointer)context_id) ; + + /* + * Handle literals which may have further embedded literal references. Note + * that the file for private references is the local file, possibly changed + * by the HGetIndexedLiteral + */ + switch ( *type ) + { + case MrmRtypeIntegerVector: + *vec_count = ((RGMIntegerVectorPtr)*val)->count ; + break; + case MrmRtypeChar8Vector: + case MrmRtypeCStringVector: + *vec_count = ((RGMTextVectorPtr)*val)->count ; + break; + case MrmRtypeIconImage: + result = Urm__CW_LoadIconImage ((RGMIconImagePtr)*val, + (XtPointer)*val, hierarchy_id, + *act_file_id, ctxlist) ; + if ( result != MrmSUCCESS ) return result ; + break ; + } + + return MrmSUCCESS ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine completes the loading and fixup of a URM + * icon image. Iconimages may have several other literal + * resource references embedded within their definition. + * These are all read and turned into memory references. + * + * FORMAL PARAMETERS: + * + * iconptr The (unfixedup) icon image now in memory + * bufptr buffer for offsets + * hierarchy_id hierarchy from which to read public resource + * file_id file from which to read private resource + * ctxlist list in which to save resource contexts + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * other failures from ReadLiteral + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__CW_LoadIconImage (RGMIconImagePtr iconptr , + XtPointer bufptr , + MrmHierarchy hierarchy_id , + IDBFile file_id , + URMPointerListPtr ctxlist ) +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + RGMResourceDescPtr resptr ; /* to read resource literals */ + RGMColorTablePtr ctable ; /* color table in icon image */ + Cardinal ndx ; /* loop index */ + RGMColorTableEntryPtr citem ; /* color table entry */ + MrmType cttype = MrmRtypeColorTable ; /* expected type */ + XtPointer ctbufptr ; /* buffer base addr for table */ + MrmType ctype ; /* color entry type */ + IDBFile act_file ; /* file from which literals read */ + char err_msg[300] ; + int vec_size ; + Boolean swap_needed = FALSE ; + + /* + * Fixup pointers as required. Read the color table if it is a resource. + * Note that bufptr is reset to a color table resource read in in order + * provide the correct relocation for color items. + */ + if (iconptr->validation != URMIconImageValid) + if ( Urm__SwapValidation(iconptr->validation) == URMIconImageValid ) + { + swapbytes( iconptr->validation ); + swapbytes( iconptr->width ); + swapbytes( iconptr->height ); + swapbytes( iconptr->hot_x ); + swapbytes( iconptr->hot_y ); + swapbytes( iconptr->ct_type ); + swapbytes( iconptr->annex1 ); + swapbytes( iconptr->color_table.ctoff ); + swapbytes( iconptr->pixel_data.pdoff ); + swap_needed = TRUE; + } + else + /* CR9259 */ + return Urm__UT_Error ("Urm__CW_LoadIconImage", + _MrmMMsg_0028, NULL, NULL, MrmNOT_VALID) ; + + iconptr->pixel_data.pdptr = (char *) bufptr+iconptr->pixel_data.pdoff ; + switch ( iconptr->ct_type ) + { + case MrmRtypeColorTable: + iconptr->color_table.ctptr = (RGMColorTablePtr) + ((char *)bufptr+iconptr->color_table.ctoff) ; + ctbufptr = bufptr ; + break ; + case MrmRtypeResource: { + int vec_count; + resptr = (RGMResourceDescPtr) + ((char *)bufptr+iconptr->color_table.ctoff) ; + if ( swap_needed ) Urm__SwapRGMResourceDesc(resptr); + result = Urm__CW_ReadLiteral + (resptr, hierarchy_id, file_id, ctxlist, + &cttype, (long *)(&iconptr->color_table.ctptr), + &vec_count, &act_file, &vec_size) ; + if ( result != MrmSUCCESS ) return result ; + if ( cttype != MrmRtypeColorTable ) + { + sprintf (err_msg, _MrmMMsg_0080, cttype) ; + return Urm__UT_Error ("Urm__CW_LoadIconImage", + err_msg, NULL, NULL, MrmNOT_VALID) ; + } + ctbufptr = (XtPointer) iconptr->color_table.ctptr ; + break ; + } + default: + sprintf (err_msg, _MrmMMsg_0081, iconptr->ct_type) ; + return Urm__UT_Error ("Urm__CW_LoadIconImage", + err_msg, NULL, NULL, MrmNOT_VALID) ; + } + + /* + * Load any resource colors in the color table. + */ + ctable = iconptr->color_table.ctptr ; + if (ctable->validation != URMColorTableValid) + if ( Urm__SwapValidation(ctable->validation) == URMColorTableValid ) + { + swapbytes( ctable->validation ); + swapbytes( ctable->count ); + swap_needed = TRUE; + } + else + /* CR9259 */ + return Urm__UT_Error ("Urm__CW_LoadIconImage", + _MrmMMsg_0028, NULL, NULL, MrmNOT_VALID) ; + + for ( ndx=URMColorTableUserMin ; ndxcount ; ndx++ ) + { + citem = &ctable->item[ndx] ; + if ( swap_needed ) + { + swapbytes( citem->type ); + swapbytes( citem->annex1 ); + swapbytes( citem->color_item.coffs ); + } + switch ( citem->type ) + { + case MrmRtypeColor: + citem->color_item.cptr = (RGMColorDescPtr) + ((char *)ctbufptr+citem->color_item.coffs) ; + break ; + case MrmRtypeResource: { + int vec_count; + resptr = (RGMResourceDescPtr) + ((char *)ctbufptr+citem->color_item.coffs) ; + if ( swap_needed ) Urm__SwapRGMResourceDesc(resptr); + ctype = MrmRtypeColor ; + result = Urm__CW_ReadLiteral + (resptr, hierarchy_id, file_id, + ctxlist, &ctype, (long *)(&citem->color_item.cptr), + &vec_count, &act_file, &vec_size) ; + if ( result != MrmSUCCESS ) return result ; + if ( ctype != MrmRtypeColor ) + { + sprintf (err_msg, _MrmMMsg_0082, ctype) ; + return Urm__UT_Error ("Urm__CW_LoadIconImage", + err_msg, NULL, NULL, MrmNOT_VALID) ; + } + break ; + } + default: + sprintf ( err_msg, _MrmMMsg_0083, citem->type) ; + return Urm__UT_Error ("Urm__CW_LoadIconImage", + err_msg, NULL, NULL, MrmNOT_VALID) ; + } + } + return MrmSUCCESS ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine fixes up a callback list in a record to function + * as the callback list passed to create. It must turn routine + * names into addresses, and evaluate tag values. + * + * FORMAL PARAMETERS: + * + * parent this widget's parent + * bufptr buffer (base address) for resolving offsets + * cbdesc Callback descriptor in record. Its pointers + * must be fixed up and its tag values evaluated. + * ctxlist A pointer list to save contexts created to + * evaluate literals. + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * wref_id reference structure from which references to + * previously created widgets in the tree can be + * resolved. + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * MrmUNRESOLVED_REFS unresolved references to widgets remain + * other conversion or resource evaluation failure + * + * SIDE EFFECTS: + * + *-- + */ + +Cardinal +Urm__CW_FixupCallback (Widget parent , + XtPointer bufptr , + RGMCallbackDescPtr cbdesc , + URMPointerListPtr ctxlist , + URMPointerListPtr cblist , + MrmHierarchy hierarchy_id , + IDBFile file_id , + URMResourceContextPtr wref_id) +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + int ndx ; /* loop index */ + RGMCallbackItemPtr itmptr ; /* current list item */ + String rtn_name ; /* routine name in item */ + MrmType reptype ; /* arg value representation type */ + RGMResourceDescPtr resptr ; /* resource descriptor in tag */ + IDBFile act_file ; /* file from which literals read */ + XtPointer rtn_addr ; /* routine address */ + long tag_val ; /* to save value */ + int vec_count ; /* number of items in the vector */ + char err_msg[300] ; + MrmCount unres_ref_count = 0; /* num unres. widgets in cblist */ + String ref_name; /* referenced widget name */ + Widget ref_id ; /* referenced widget id */ + int vec_size ; + RGMFontListPtr fontlist; /* for converting old style fontlist */ + Boolean swap_needed = FALSE; + + /* + * Loop through all the items in the callback list + */ + for ( ndx=0 ; ndxcount ; ndx++ ) + { + itmptr = &cbdesc->item[ndx] ; + + /* + * Set the routine pointer to the actual routine address. This + * routine name must be a registered URM callback. + */ + rtn_name = (String) bufptr + itmptr->cb_item.routine ; + result = Urm__LookupNameInHierarchy (hierarchy_id, rtn_name, &rtn_addr) ; + if ( result != MrmSUCCESS ) + { + sprintf (err_msg, _MrmMMsg_0084, rtn_name) ; + return Urm__UT_Error ("Urm__CW_FixupCallback", + err_msg, NULL, NULL, result) ; + } + + /* + * Evaluate the tag value, and set in the item. + */ + reptype = itmptr->cb_item.rep_type ; + tag_val = Urm__CW_EvaluateValOrOffset (reptype, bufptr, + itmptr->cb_item.datum.ival, + itmptr->cb_item.datum.offset) ; + switch ( reptype ) + { + case MrmRtypeResource: + resptr = (RGMResourceDescPtr) tag_val ; + switch ( resptr->res_group ) + { + case URMgWidget: + /* Do we need to worry about subtree resources here? */ + if (resptr->type != URMrIndex) + { + Urm__UT_Error("Urm__CW_FixupCallback", _MrmMMsg_0085, + NULL, NULL, MrmNOT_VALID); + continue; + } + ref_name = (String) resptr->key.index; + /* See if reference can be resolved immediatetly. */ + result = Urm__CW_FindWRef(wref_id, ref_name, &ref_id) ; + if ( result == MrmSUCCESS ) tag_val = (long)ref_id; + else { /* Save to resolve later */ + itmptr->runtime.resolved = FALSE; + itmptr->runtime.wname = Urm__UT_AllocString(ref_name); + tag_val = 0L; + unres_ref_count++; + } + break; + + case URMgLiteral: + result = Urm__CW_ReadLiteral + (resptr, hierarchy_id, file_id, ctxlist, + &reptype, &tag_val, &vec_count, &act_file, &vec_size); + if ( result != MrmSUCCESS ) continue ; + + if ((reptype == MrmRtypeFontList) && + (strcmp(file_id->db_version, URM1_1version) <= 0)) + { + int count = ((OldRGMFontListPtr)tag_val)->count; + + fontlist = (RGMFontListPtr) + XtMalloc(sizeof(RGMFontList) + + (sizeof(RGMFontItem) * (count - 1))); + result = Urm__CW_FixupValue((long)fontlist, reptype, + (XtPointer)tag_val, file_id, + &swap_needed); + XtFree((char *)tag_val); + tag_val = (long)fontlist; + } + else + result = Urm__CW_FixupValue (tag_val, reptype, + (XtPointer)tag_val, file_id, + &swap_needed) ; + + if ( result != MrmSUCCESS ) continue ; + result = Urm__CW_ConvertValue + (parent, &tag_val, reptype, (MrmType)0, XtDisplay(parent), + hierarchy_id, NULL) ; + if ( result != MrmSUCCESS ) continue ; + + switch (reptype) + { + case MrmRtypeChar8Vector: + case MrmRtypeCStringVector: + vec_size -= (sizeof ( RGMTextVector ) - + sizeof ( RGMTextEntry )); + break; + default: + break; + } + + Urm__CW_SafeCopyValue (&tag_val, reptype, cblist, + vec_count, vec_size) ; + itmptr->runtime.resolved = TRUE; + break ; + default: + return Urm__UT_Error ("Urm__CW_FixupCallback", _MrmMMsg_0063, + NULL, NULL, MrmFAILURE) ; + } + break ; + default: + result = Urm__CW_FixupValue (tag_val, reptype, bufptr, file_id, + &swap_needed) ; + if ( result != MrmSUCCESS ) continue ; + result = Urm__CW_ConvertValue + (parent, &tag_val, reptype, (MrmType)0, XtDisplay(parent), + hierarchy_id, NULL) ; + Urm__CW_SafeCopyValue (&tag_val, reptype, cblist, 0, 0) ; + itmptr->runtime.resolved = TRUE; + break ; + } + + itmptr->runtime.callback.callback = (XtCallbackProc)rtn_addr; + itmptr->runtime.callback.closure = (XtPointer) tag_val ; + } + + cbdesc->unres_ref_count = unres_ref_count; + if (unres_ref_count == 0) + /* + * callback list successfully fixed up + */ + return MrmSUCCESS ; + else return MrmUNRESOLVED_REFS; + +} + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine evaluates a resource reference to a widget by loading + * the widget definition and instantiating the widget tree. It returns + * the widget id. + * This routine evaluates a resource reference, resulting in setting + * + * FORMAL PARAMETERS: + * + * parent parent of the widget being created + * widgetrec widget record pointer + * resptr the resource to be evaluated + * ctxlist A pointer list to save contexts created to + * evaluate literals. + * hierarchy_id URM hierarchy from which to read public resources + * file_id URM file from which to read private resources + * wref_id widget reference structure + * svlist SetValues descriptor list + * val to return the value (widget id) + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * MrmSUCCESS operation succeeded + * other load or instantiate failure + * + * SIDE EFFECTS: + * + *-- + */ + +/*ARGSUSED*/ +Cardinal +Urm__CW_LoadWidgetResource (Widget parent , + RGMWidgetRecordPtr widgetrec , /* unused */ + RGMResourceDescPtr resptr , + URMPointerListPtr ctxlist , /* unused */ + MrmHierarchy hierarchy_id , + IDBFile file_id , + URMPointerListPtr *svlist , + URMResourceContextPtr wref_id , + long *val ) + +{ + /* + * Local variables + */ + Cardinal result ; /* function results */ + URMResourceContextPtr context_id ; /* context for widget record */ + IDBFile loc_fileid = file_id ; /* file id from HGet */ + char err_msg[300] ; /* to format error messages */ + + + /* + * Acquire a context, then load the widget and instantiate the tree. + * An HGet call may replace the file for private references. + */ + UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id) ; + switch ( resptr->type ) + { + case URMrIndex: + if ( resptr->access == URMaPublic ) + result = UrmHGetWidget + (hierarchy_id, resptr->key.index, context_id, &loc_fileid) ; + else + result = UrmGetIndexedWidget + (file_id, resptr->key.index, context_id) ; + if ( result != MrmSUCCESS ) + sprintf (err_msg, _MrmMMsg_0086, resptr->key.index) ; + break ; + + case URMrRID: + result = UrmGetRIDWidget (file_id, resptr->key.id, context_id) ; + if ( result != MrmSUCCESS ) + sprintf (err_msg, _MrmMMsg_0087, resptr->key.id) ; + break ; + + default: + result = MrmFAILURE ; + sprintf ( err_msg, _MrmMMsg_0088, resptr->type) ; + } + + if ( result != MrmSUCCESS ) + { + UrmFreeResourceContext (context_id) ; + return Urm__UT_Error ("Urm__CW_LoadWidgetResource", + err_msg, NULL, NULL, result) ; + } + + /* + * Now create the widget subtree. The pointer result is the widget id of + * the widget we now have (the root of the tree). + */ + result = UrmCreateWidgetTree + (context_id, parent, hierarchy_id, loc_fileid, NULL, NULL, 0, + resptr->type, resptr->key.index, resptr->key.id, MrmManageDefault, + (URMPointerListPtr *)svlist, wref_id, (Widget *)val) ; + if ( result != MrmSUCCESS ) + Urm__UT_Error ("Urm__CW_LoadWidgetResource", _MrmMMsg_0089, + NULL, NULL, result) ; + UrmFreeResourceContext (context_id) ; + return result ; + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine returns parameters needed to create a pixmap from + * an IconImage. It extracts the screen and display from the given + * widget. It then determines the foreground and background colors + * for the widget. The setting of these values is idiosyncratic, due + * to the fact that all widgets have a Background attribute from core, + * but are not guaranteed to have a Foreground attribute. + * - if value is already set, do nothing + * - else choose the value for the widget if available + * - else choose white/black PixelOfScreen + * - make sure we haven't ended up with identical values + * for both foreground and background. If we have, accept + * the background value and set the foreground to something + * else (black or white). + * + * FORMAL PARAMETERS: + * + * w widget to use for default values + * screen to return screen for pixmap + * display to return display for pixmap + * fgint to return foreground value for pixmap. A value of + * -1 on input means this must be set; else ignored + * bgint to return background value for pixmap. -1 is used + * as above to signal value needed + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * SIDE EFFECTS: + * + *-- + */ + +void +Urm__CW_GetPixmapParms (Widget w , + Screen **screen , + Display **display , + Pixel *fgint , + Pixel *bgint ) +{ + /* + * Local variables + */ + Arg pixarg[2] ; /* to read FG/BG values */ + Cardinal pcnt = 0 ; /* # entries in arglist */ + + /* + * Screen and display come straight from widget + */ + *screen = XtScreen (w) ; + *display = XtDisplay (w) ; + + /* + * Else load the foreground and background pixel values from the + * widget. Fallback to Black/WhitePixelOfScreen if the widget + * doesn't have these values. + */ + if ( *fgint == -1 ) + { + XtSetArg (pixarg[pcnt], XmNforeground, fgint) ; + pcnt += 1 ; + } + if ( *bgint == -1 ) + { + XtSetArg (pixarg[pcnt], XmNbackground, bgint) ; + pcnt += 1 ; + } + if ( pcnt > 0 ) + XtGetValues (w, pixarg, pcnt) ; + + /* + * Fall back on ...PixelOfScreen + */ + if ( *fgint == -1 ) + *fgint = BlackPixelOfScreen (*screen) ; + if ( *bgint == -1 ) + *bgint = WhitePixelOfScreen (*screen) ; + + /* + * Make sure we haven't ended with identical values + */ + if ( *fgint == *bgint ) + { + if ( *bgint == BlackPixelOfScreen(*screen) ) + *fgint = WhitePixelOfScreen (*screen) ; + else + *fgint = BlackPixelOfScreen (*screen) ; + } + +} + + + +/* + *++ + * + * PROCEDURE DESCRIPTION: + * + * This routine translates an RGMCallbackDescPtr stored in a 1.1 uid + * file into the equivalent 1.2+ structure. This routine allocates + * memory which must later be freed using XtFree. + * + * FORMAL PARAMETERS: + * + * oldptr Pointer into the buffer where the 1.1 callback + * descriptor starts. + * + * IMPLICIT INPUTS: + * + * IMPLICIT OUTPUTS: + * + * FUNCTION VALUE: + * + * This function returns a pointer to a new RGMCallbackDesc containing + * all the information from the structure stored in the uid file. + * + * SIDE EFFECTS: + * + * Memory is allocated which must be freed using XtFree. + * + *-- + */ + +RGMCallbackDescPtr +Urm__CW_TranslateOldCallback (OldRGMCallbackDescPtr oldptr) +{ + /* + * Local variables + */ + RGMCallbackDescPtr cbptr; /* pointer to new callback descriptor */ + RGMCallbackItemPtr itmptr; /* current callback item */ + OldRGMCallbackItemPtr olditmptr; /* callback item being converted */ + int ndx; /* loop index */ + + cbptr = (RGMCallbackDescPtr) XtMalloc(sizeof(RGMCallbackDesc) + + oldptr->count*sizeof(RGMCallbackItem)); + + cbptr->validation = oldptr->validation; + cbptr->count = oldptr->count; + + /* Loop through all items in old callback list copying to new. */ + for (ndx = 0; ndx <= cbptr->count; ndx++) + /* <= so that null item is copied. */ + { + olditmptr = &oldptr->item[ndx]; + itmptr = &cbptr->item[ndx]; + + itmptr->cb_item.routine = olditmptr->cb_item.routine; + itmptr->cb_item.rep_type = olditmptr->cb_item.rep_type; + itmptr->cb_item.datum = olditmptr->cb_item.datum; + } + + return cbptr; +} + diff --git a/tools/wml/wmldbcreate.c b/tools/wml/wmldbcreate.c index 07c0a3c..6de585a 100644 --- a/tools/wml/wmldbcreate.c +++ b/tools/wml/wmldbcreate.c @@ -425,7 +425,7 @@ int table_id; { fprintf (afile, "%d, ", entry_vec[j]); } - fprintf (afile, "\n"); + fprintf (afile, "%s", "\n"); } } } diff --git a/tools/wml/wmldbcreate.c.format-security b/tools/wml/wmldbcreate.c.format-security new file mode 100644 index 0000000..07c0a3c --- /dev/null +++ b/tools/wml/wmldbcreate.c.format-security @@ -0,0 +1,687 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA +*/ +/* + * HISTORY +*/ +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$TOG: wmldbcreate.c /main/8 1997/04/14 12:55:30 dbl $" +#endif +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + + +/* +* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + +/* + * This is the program creates binary databases from WML output. + */ + + +#include +#ifndef X_NOT_STDC_ENV +#include +#endif + +#include +#include +#include + +#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+ + + +/* + * User supplied widget public.h and/or private.h files are to be added here + * #ifdef for automatic use in uilwmdcreate script file + */ + + +/* + * End of User supplied widget files + */ + + +#include "UilDBDef.h" +#include "UilLexPars.h" + +#include "UilSymGen.h" /* from WML */ +#include "UilSymArTy.h" /* from WML */ +#include "UilSymRArg.h" /* from WML */ +#include "UilSymArTa.h" /* from WML */ +#include "UilSymReas.h" /* from WML */ +#include "UilSymCtl.h" /* from WML */ +#include "UilConst.h" /* from WML */ +#include "UilSymNam.h" /* from WML */ +#include "UilSymEnum.h" /* from WML */ +#include "UilSymCSet.h" /* from WML */ +#include "UilUrmClas.h" /* from WML */ +#include "UilKeyTab.h" /* from WML */ +#include "UilSymChCl.h" /* from WML */ +#include "UilSymChTa.h" /* from WML */ + +void emit_globals(); +void emit_header(_db_header_ptr header); +void emit_chars(int table_id); +void emit_ints_and_string( int table_id); +void emit_char_table( int table_id); +void emit_length_and_string( int table_id); +void emit_shorts( int table_id); +void emit_int_and_table_shorts( int table_id); +void emit_ints( int table_id); + +FILE *bfile, *afile; +int DEBUG=FALSE; +char outfilename[80]; +char debugfilename[80]; + +int main(argc, argv) +int argc; +char **argv; +{ + _db_header header; + + strcpy(outfilename, "motif.wmd"); + strcpy(debugfilename, "motif.dbg"); + + for (argc--, argv++; argc; argc--, argv++) + { + if (strcmp("-debug", *argv) == 0) + { + DEBUG=TRUE; + } + else if ((strcmp("-o", *argv) == 0)) + { + strcpy(outfilename, argv[1]); + } + } + + bfile = fopen(outfilename, "w"); + if (bfile == (FILE *) NULL) + { + printf("\nCouldnt't open %s", outfilename); + exit (1); + } + if (DEBUG) + { + afile = fopen(debugfilename, "w"); + if (afile == (FILE *) NULL) + { + printf("\nCouldn't open %s", debugfilename); + exit (1); + } + } + + emit_globals(); + +/* + * UilConst + * UilSymArty + * UilSymCset - parts of it + * UilSymChCl + */ + emit_chars(Constraint_Tab); + emit_chars(Argument_Type_Table_Value); + emit_chars(Charset_Wrdirection_Table); + emit_chars(Charset_Parsdirection_Table); + emit_chars(Charset_Charsize_Table); + emit_chars(Child_Class_Table); +/* + * UilKeyTab + */ + emit_ints_and_string (Key_Table); + emit_ints_and_string (Key_Table_Case_Ins); +/* + * UilSymArTa + * UilSymCtl + * UilSymReas + * UilSymChTa + */ + emit_char_table (Allowed_Argument_Table); + emit_char_table (Allowed_Control_Table); + emit_char_table (Allowed_Reason_Table); + emit_char_table (Allowed_Child_Table); +/* + * UilSymCset + * UilSymNam + * UilUrmClas + */ + emit_length_and_string (Charset_Xmstring_Names_Table); + emit_length_and_string (Charset_Lang_Names_Table); + emit_length_and_string (Uil_Widget_Names); + emit_length_and_string (Uil_Argument_Names); + emit_length_and_string (Uil_Reason_Names); + emit_length_and_string (Uil_Enumval_names); + emit_length_and_string (Uil_Charset_Names); + emit_length_and_string (Uil_Widget_Funcs); + emit_length_and_string (Uil_Argument_Toolkit_Names); + emit_length_and_string (Uil_Reason_Toolkit_Names); + emit_length_and_string (Uil_Children_Names); +/* + * UilSymCset + * UilSymEnum + * UilSymRArg + * UilUrmClas + */ + emit_shorts (Charset_Lang_Codes_Table); + emit_shorts (Argument_Enum_Set_Table); + emit_shorts (Related_Argument_Table); + emit_shorts (Uil_Gadget_Funcs); + emit_shorts (Uil_Urm_Nondialog_Class); + emit_shorts (Uil_Urm_Subtree_Resource); +/* + * UilSymEnum + */ + emit_int_and_table_shorts(Enum_Set_Table); +/* + * UilSymEnum + */ + emit_ints (Enumval_Values_Table); + + exit (0); + + return 0; /* make compiler happy */ +} + + +void emit_globals() +{ + _db_globals globals; + + globals.version = DB_Compiled_Version; + globals.uil_max_arg = uil_max_arg; + globals.uil_max_charset = uil_max_charset; + globals.charset_lang_table_max = charset_lang_table_max; + globals.uil_max_object = uil_max_object; + globals.uil_max_reason = uil_max_reason; + globals.uil_max_enumval = uil_max_enumval; + globals.uil_max_enumset = uil_max_enumset; + globals.key_k_keyword_count = key_k_keyword_count; + globals.key_k_keyword_max_length = key_k_keyword_max_length; + globals.uil_max_child = uil_max_child; + + fwrite (&globals, sizeof (_db_globals), 1, bfile); + if (DEBUG) + fprintf(afile, "%d %d %d %d %d %d %d %d %d %d ", globals.version, + globals.uil_max_arg, globals.uil_max_charset, + globals.charset_lang_table_max, globals.uil_max_object, + globals.uil_max_reason, globals.uil_max_enumval, + globals.uil_max_enumset, globals.key_k_keyword_count, + globals.key_k_keyword_max_length); + } + + + +void emit_header(header) +_db_header_ptr header; +{ + + fwrite (header, sizeof(_db_header), 1, bfile); + if (DEBUG) + fprintf(afile, + "\n\nTableId=%d, NumEntries=%d, TableSize=%d \n", + header->table_id, header->num_items, header->table_size); + } + + + +void emit_chars(table_id) + int table_id; +{ + _db_header header; + unsigned char *ptr; + int i; + + switch (table_id) + { + case Constraint_Tab: + /* + * NOTE: The first entry is not used but we copy it anyway + */ + header.table_size = sizeof(constraint_tab_vec); + header.num_items = header.table_size; + header.table_id = Constraint_Tab; + ptr = constraint_tab; + break; + case Argument_Type_Table_Value: + /* + * NOTE: The first entry is not used but we copy it anyway + */ + header.table_size = sizeof(argument_type_table_vec); + header.num_items = header.table_size; + header.table_id = Argument_Type_Table_Value; + ptr = argument_type_table; + break; + case Charset_Wrdirection_Table: + /* + * NOTE: The first entry is not used but we copy it anyway + */ + header.table_size = sizeof(charset_wrdirection_table_vec); + header.num_items = header.table_size; + header.table_id = Charset_Wrdirection_Table; + ptr = charset_writing_direction_table; + break; + case Charset_Parsdirection_Table: + /* + * NOTE: The first entry is not used but we copy it anyway + */ + header.table_size = sizeof(charset_parsdirection_table_vec); + header.num_items = header.table_size; + header.table_id = Charset_Parsdirection_Table; + ptr = charset_parsing_direction_table; + break; + case Charset_Charsize_Table: + /* + * NOTE: The first entry is not used but we copy it anyway + */ + header.table_size = sizeof(charset_charsize_table_vec); + header.num_items = header.table_size; + header.table_id = Charset_Charsize_Table; + ptr = charset_character_size_table; + break; + case Child_Class_Table: + /* + * NOTE: The first entry is not used but we copy it anyway + */ + header.table_size = sizeof(child_class_table_vec); + header.num_items = header.table_size; + header.table_id = Child_Class_Table; + ptr = child_class_table; + break; + } + + emit_header(&header); + + fwrite (ptr, header.table_size, 1, bfile); + if (DEBUG) + { + for (i=0; i<=header.num_items; i++) + { + fprintf(afile, "%d ", ptr[i]); + } + } +} + + +void emit_ints_and_string(table_id) + int table_id; +{ + _db_header header; + key_keytable_entry_type *table; + int i; + + switch (table_id) + { + /* + * All tables are zero based unless otherwise noted + */ + case Key_Table: + header.table_size = sizeof(key_table_vec); + header.num_items = key_k_keyword_count; + header.table_id = Key_Table; + table = key_table; + break; + case Key_Table_Case_Ins: + header.table_size = sizeof(key_table_case_ins_vec); + header.num_items = key_k_keyword_count; + header.table_id = Key_Table_Case_Ins; + table = key_table_case_ins; + break; + } + emit_header(&header); + + fwrite (table, header.table_size, 1, bfile); + for (i=0; icnt ; ndx++ ) { clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; @@ -244,7 +244,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Define the sym_k_..._reason literals */ -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); for ( ndx=0 ; ndxcnt ; ndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; @@ -258,7 +258,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Define the sym_k_..._arg literals */ -fprintf (outfil, canned4); +fprintf (outfil, "%s", canned4); for ( ndx=0 ; ndxcnt ; ndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; @@ -272,7 +272,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Define the sym_k_..._enumset structs and literals */ -fprintf (outfil, canned5); +fprintf (outfil, "%s", canned5); for ( ndx=0 ; ndxcnt ; ndx++ ) { enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; @@ -286,7 +286,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Define the sym_k_..._enumval literals */ -fprintf (outfil, canned6); +fprintf (outfil, "%s", canned6); for ( ndx=0 ; ndxcnt ; ndx++ ) { enumvalobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; @@ -301,7 +301,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) * Define the sym_k_..._charsize literals * Define the sym_k_..._charset literals */ -fprintf (outfil, canned7); +fprintf (outfil, "%s", canned7); for ( ndx=0 ; ndxcnt ; ndx++ ) { charsetobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; @@ -315,7 +315,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Define the sym_k_..._child literals */ -fprintf (outfil, canned8); +fprintf (outfil, "%s", canned8); for ( ndx=0 ; ndxcnt ; ndx++ ) { childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; @@ -379,12 +379,12 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymChCL.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Create table entries, similar to writing sym_k... */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); for ( ndx=0 ; ndxcnt ; ndx++ ) { childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; @@ -392,7 +392,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) fprintf (outfil, " sym_k_%s_object,\n", classobj->tkname); } -fprintf (outfil, canned1a); +fprintf (outfil, "%s", canned1a); /* * close the output file @@ -446,12 +446,12 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymArTy.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Create table entries, similar to writing sym_k... */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); for ( ndx=0 ; ndxcnt ; ndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; @@ -459,7 +459,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) fprintf (outfil, " sym_k_%s_value,\n", datobj->tkname); } -fprintf (outfil, canned1a); +fprintf (outfil, "%s", canned1a); /* * close the output file @@ -509,19 +509,19 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymRArg.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Create table entries, similar to writing sym_k... */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); for ( ndx=0 ; ndxcnt ; ndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; fprintf (outfil, " %d,\n", resobj->related_code); } -fprintf (outfil, canned1a); +fprintf (outfil, "%s", canned1a); /* * close the output file @@ -621,12 +621,12 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilUrmClas.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Write entries for widgets */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); for ( ndx=0 ; ndxcnt ; ndx++ ) { clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; @@ -637,7 +637,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) else fprintf (outfil, " \"%s\",\t\n", synobj->convfunc); } -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); /* * Write entries for gadget variants of widget classes @@ -661,7 +661,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) synobj->name); } } -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * Write entries for non-dialog widgets @@ -685,7 +685,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) synobj->name); } } -fprintf (outfil, canned4); +fprintf (outfil, "%s", canned4); /* * Write entries for the resource a widget's controls map to @@ -701,7 +701,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) else fprintf (outfil, " sym_k_%s_arg,\n", mapresobj->tkname); } -fprintf (outfil, canned5); +fprintf (outfil, "%s", canned5); /* * Write entries for arguments @@ -714,7 +714,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) fprintf (outfil, " %s,\n", synres->resliteral); } -fprintf (outfil, canned6); +fprintf (outfil, "%s", canned6); /* * Write entries for reasons @@ -727,7 +727,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) fprintf (outfil, " %s,\n", synres->resliteral); } -fprintf (outfil, canned7); +fprintf (outfil, "%s", canned7); /* * close the output file @@ -781,13 +781,13 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilConst.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Process the arguments in code order. We start with 1, and write out * the mask after processing 8 codes. */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); strcpy (maskbuf, "0"); for ( ndx=0 ; ndxcnt ; ndx++ ) { @@ -805,7 +805,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) } if ( bitno != 8 ) fprintf (outfil, "%s", maskbuf); -fprintf (outfil, canned1a); +fprintf (outfil, "%s", canned1a); /* * close the output file @@ -878,8 +878,8 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymReas.h"); return; } -fprintf (outfil, canned_warn); -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned_warn); +fprintf (outfil, "%s", canned1); /* * Generate the bit vectors for each class. Outer loop on the reason code, @@ -919,19 +919,19 @@ for ( resndx=0 ; resndxcnt ; resndx++ ) if ( itemno != 0 ) fprintf (outfil, "%s 0};\n", maskbuf); else - fprintf (outfil, "};\n"); + fprintf (outfil, "%s", "};\n"); } /* * Write the vector of vectors. */ -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); for ( resndx=0 ; resndxcnt ; resndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[resndx].objptr; fprintf (outfil, " reason_class_vec%d,\n", resobj->sym_code); } -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * close the output file @@ -1004,8 +1004,8 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymArTa.h"); return; } -fprintf (outfil, canned_warn); -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned_warn); +fprintf (outfil, "%s", canned1); /* * Generate the bit vectors for each class. Outer loop on the argument code, @@ -1045,19 +1045,19 @@ for ( resndx=0 ; resndxcnt ; resndx++ ) if ( itemno != 0 ) fprintf (outfil, "%s 0};\n", maskbuf); else - fprintf (outfil, "};\n"); + fprintf (outfil, "%s", "};\n"); } /* * Write the vector of vectors. */ -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); for ( resndx=0 ; resndxcnt ; resndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[resndx].objptr; fprintf (outfil, " arg_class_vec%d,\n", resobj->sym_code); } -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * close the output file @@ -1129,8 +1129,8 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymChTa.h"); return; } -fprintf (outfil, canned_warn); -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned_warn); +fprintf (outfil, "%s", canned1); /* * Generate the bit vectors for each class. Outer loop on the child code, @@ -1168,19 +1168,19 @@ for ( childndx=0 ; childndxcnt ; childndx++ ) if ( itemno != 0 ) fprintf (outfil, "%s 0};\n", maskbuf); else - fprintf (outfil, "};\n"); + fprintf (outfil, "%s", "};\n"); } /* * Write the vector of vectors. */ -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); for ( childndx=0 ; childndxcnt ; childndx++ ) { childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[childndx].objptr; fprintf (outfil, " child_class_vec%d,\n", childobj->sym_code); } -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * close the output file @@ -1251,8 +1251,8 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymCtl.h"); return; } -fprintf (outfil, canned_warn); -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned_warn); +fprintf (outfil, "%s", canned1); /* * Generate the bit vectors for each class. Outer loop on the class code, @@ -1290,19 +1290,19 @@ for ( ctlndx=0 ; ctlndxcnt ; ctlndx++ ) if ( itemno != 0 ) fprintf (outfil, "%s 0};\n", maskbuf); else - fprintf (outfil, "};\n"); + fprintf (outfil, "%s", "};\n"); } /* * Write the vector of vectors. */ -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); for ( ctlndx=0 ; ctlndxcnt ; ctlndx++ ) { clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ctlndx].objptr; fprintf (outfil, " object_class_vec%d,\n", clsobj->sym_code); } -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * close the output file @@ -1438,7 +1438,7 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymNam.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Write entries for widgets @@ -1517,7 +1517,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) fprintf (outfil, " \"%s\",\n", synch->name); } -fprintf (outfil, canned7); +fprintf (outfil, "%s", canned7); /* * close the output file @@ -1621,12 +1621,12 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymEnum.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Generate the enumeration value vectors for each enumeration set. */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); for ( ndx=0 ; ndxcnt ; ndx++ ) { enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; @@ -1637,13 +1637,13 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) fprintf (outfil, " %d,\n", evobj->sym_code); } - fprintf (outfil, " };\n"); + fprintf (outfil, "%s", " };\n"); } /* * Generate the enumeration set tables */ -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); for ( ndx=0 ; ndxcnt ; ndx++ ) { enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; @@ -1655,7 +1655,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Create enumset table entries for arguments, similar to writing sym_k... */ -fprintf (outfil, canned4); +fprintf (outfil, "%s", canned4); for ( ndx=0 ; ndxcnt ; ndx++ ) { resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; @@ -1669,13 +1669,13 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Create the enumval values table. */ -fprintf (outfil, canned5); +fprintf (outfil, "%s", canned5); for ( ndx=0 ; ndxcnt ; ndx++ ) { evobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; fprintf (outfil, " %s,\n", evobj->syndef->enumlit); } -fprintf (outfil, canned5a); +fprintf (outfil, "%s", canned5a); /* * close the output file @@ -1813,12 +1813,12 @@ if ( outfil == (FILE *) NULL ) printf ("\nCouldn't open UilSymCSet.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Generate the standards name table */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); for ( ndx=0 ; ndxcnt ; ndx++ ) { csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; @@ -1836,7 +1836,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Generate the writing direction table */ -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); for ( ndx=0 ; ndxcnt ; ndx++ ) { csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; @@ -1858,7 +1858,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Generate the parsing direction table */ -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); for ( ndx=0 ; ndxcnt ; ndx++ ) { csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; @@ -1880,7 +1880,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Generate the character size table */ -fprintf (outfil, canned4); +fprintf (outfil, "%s", canned4); for ( ndx=0 ; ndxcnt ; ndx++ ) { csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; @@ -1906,7 +1906,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Generate the $LANG name recognition table */ -fprintf (outfil, canned5); +fprintf (outfil, "%s", canned5); lang_max = 0; for ( ndx=0 ; ndxcnt ; ndx++ ) { @@ -1936,7 +1936,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * Generate the $LANG code lookup table, in upper case */ -fprintf (outfil, canned6); +fprintf (outfil, "%s", canned6); for ( ndx=0 ; ndxcnt ; ndx++ ) { csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; diff --git a/tools/wml/wmlouth.c.format-security b/tools/wml/wmlouth.c.format-security new file mode 100644 index 0000000..d2330e3 --- /dev/null +++ b/tools/wml/wmlouth.c.format-security @@ -0,0 +1,1964 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA +*/ +/* + * HISTORY +*/ +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$XConsortium: wmlouth.c /main/8 1995/08/29 11:10:46 drk $" +#endif +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + + +/* +* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + +/* + * This module contains routines responsible for writing the .h files + * produced by WML. All files are written into the current directory. + * + * Input: + * The resolved objects + * + * Output: + * UilSymGen.h + * UilSymArTy.h + * UilSymChCl.h + * UilSymRArg.h + * UilUrmClas.h + * UilConst.h + * UilSymReas.h + * UilSymArTa.h + * UilSymChTa.h + * UilSymCtl.h + * UilSymNam.h + * UilSymEnum.h + * UilSymCSet.h + */ + + +#include "wml.h" + +#if defined(__STDC__) +#include +#endif +#include + + +/* + * Routines used only in this module + */ +void wmlOutputUilSymGen (); +void wmlOutputUilSymArTy (); +void wmlOutputUilSymChCl (); +void wmlOutputUilSymRArg (); +void wmlOutputUilUrmClas (); +void wmlOutputUilConst (); +void wmlOutputUilSymReas (); +void wmlOutputUilSymArTa (); +void wmlOutputUilSymChTa (); +void wmlOutputUilSymCtl (); +void wmlOutputUilSymNam (); +void wmlOutputUilSymEnum (); +void wmlOutputUilSymCSet (); +int wmlResolveCtlIsMember (WmlClassDefPtr, WmlClassCtrlDefPtr); + +/* + * globals + */ + +static char *canned_warn = +"/*\n\ +**\tThis file is automatically generated. Do not edit it by hand.\n\ +**/\n"; + +/* + * Used to create masks for bytes in bit vectors. Accessed by bit numbers + * from 1 - 8. + */ +static char *bit_masks[] = {"" + ," | 1" /* bit 1 */ + ," | 2" /* bit 2 */ + ," | 4" /* bit 3 */ + ," | 8" /* bit 4 */ + ," | 16" /* bit 5 */ + ," | 32" /* bit 6 */ + ," | 64" /* bit 7 */ + ," | 128"}; /* bit 8 */ + +/* + * To pick up maximum code values + */ +static int max_object_code = 0; +static int max_reason_code = 0; +static int max_arg_code = 0; +static int max_enumset_code = 0; +static int max_enumval_code = 0; +static int max_charset_code = 0; +static int max_child_code = 0; + + + +/* + * Output control routine, which simply outputs each .h file in turn. + */ + +void wmlOutputHFiles () + +{ + +wmlOutputUilSymGen (); +wmlOutputUilSymArTy (); +wmlOutputUilSymChCl (); +wmlOutputUilSymRArg (); +wmlOutputUilUrmClas (); +wmlOutputUilConst (); +wmlOutputUilSymReas (); +wmlOutputUilSymArTa (); +wmlOutputUilSymChTa (); +wmlOutputUilSymCtl (); +wmlOutputUilSymNam (); +wmlOutputUilSymEnum (); +wmlOutputUilSymCSet (); + +} + + + +/* + * Routine to write out UilSymGen.h + * + * This file defines the sym_k... literals for UIL. Each set of literals + * typiclly increases monotonically from 1, with 0 used as en error value. + * + * sym_k__object + * is widget class name in lexicographic order + * gadgets are not include. + * + * bit masks for table access + * + * sym_k__reason + * literals specifying all reasons, lexicographically ordered + * + * sym_k__arg + * literals for all arguments, lexicographically ordered. + * Constraints are included, and ordered with the arguments. + * + * sym_k__child + * literals for all automatic children, lexicographically ordered. + * + * sym_k__enumset + * literals naming each enumeration set, lexicographically ordered + * + * Fixed literals naming character set character sizes + * sym_k__charset + * literals naming each character set, lexicographically ordered + */ + +void wmlOutputUilSymGen () + +{ + +char *canned1 = +"\n/* Define literals for objects */\n"; + + +char *canned3 = +"\n/* Define literals for reasons */\n\n"; + + +char *canned4 = +"\n/* Define literals for arguments */\n\n"; + +char *canned5 = +"\n/* Define literals for enumeration sets */\n\n"; + +char *canned6 = +"\n/* Define literals for enumeration values */\n\n"; + +char *canned7 = +"\n/* Define literals for character sets */\n\n"; + +char *canned8 = +"\n/* Define literals for automatic children */\n\n"; + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlClassDefPtr clsobj; /* class object */ +WmlDataTypeDefPtr datobj; /* data type object */ +WmlResourceDefPtr resobj; /* resource object */ +WmlEnumSetDefPtr enumsetobj; /* enumeration set object */ +WmlEnumValueDefPtr enumvalobj; /* enumeration value object */ +WmlCharSetDefPtr charsetobj; /* character set object */ +WmlChildDefPtr childobj; /* child object */ + +/* + * Open the output file. Write the canned header stuff + */ +outfil = fopen ("UilSymGen.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymGen.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Write the sym_k..._object literals + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_object\t%d\n", + clsobj->tkname, + clsobj->sym_code); + if ( clsobj->sym_code > max_object_code ) + max_object_code = clsobj->sym_code; + } + +/* + * Define the sym_k_..._reason literals + */ +fprintf (outfil, canned3); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_reason\t%d\n", + resobj->tkname, + resobj->sym_code); + if ( resobj->sym_code > max_reason_code ) + max_reason_code = resobj->sym_code; + } + +/* + * Define the sym_k_..._arg literals + */ +fprintf (outfil, canned4); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_arg\t%d\n", + resobj->tkname, + resobj->sym_code); + if ( resobj->sym_code > max_arg_code ) + max_arg_code = resobj->sym_code; + } + +/* + * Define the sym_k_..._enumset structs and literals + */ +fprintf (outfil, canned5); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_enumset\t%d\n", + enumsetobj->tkname, + enumsetobj->sym_code); + if ( enumsetobj->sym_code > max_enumset_code ) + max_enumset_code = enumsetobj->sym_code; + } + +/* + * Define the sym_k_..._enumval literals + */ +fprintf (outfil, canned6); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + enumvalobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_enumval\t%d\n", + enumvalobj->syndef->name, + enumvalobj->sym_code); + if ( enumvalobj->sym_code > max_enumval_code ) + max_enumval_code = enumvalobj->sym_code; + } + +/* + * Define the sym_k_..._charsize literals + * Define the sym_k_..._charset literals + */ +fprintf (outfil, canned7); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + charsetobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_charset\t%d\n", + charsetobj->syndef->name, + charsetobj->sym_code); + if ( charsetobj->sym_code > max_charset_code ) + max_charset_code = charsetobj->sym_code; + } + +/* + * Define the sym_k_..._child literals + */ +fprintf (outfil, canned8); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; + fprintf (outfil, "#define sym_k_%s_child\t%d\n", + childobj->syndef->name, + childobj->sym_code); + if ( childobj->sym_code > max_child_code ) + max_child_code = childobj->sym_code; + } + +/* + * close the output file + */ +printf ("\nCreated UilSymGen.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilSymChCl.h + * + * A table of classes accessed by child type (sym_k__child, in + * the form + * ... + * sym_k__class, + */ + +void wmlOutputUilSymChCl () + +{ + +char *canned1 = +"/* Table of the class type of children\n\ + The table is indexed by child with each entry the\n\ + permitted class for that child.\n\ +*/\n\ +\n\ +static unsigned char child_class_table_vec[] =\n\ + {\n\ + 0,\n"; + +char *canned1a = +" };\n\ +externaldef(uil_sym_glbl) unsigned char *child_class_table =\n\ +\t child_class_table_vec;\n"; + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlClassDefPtr classobj; /* data type object */ +WmlChildDefPtr childobj; /* resource object */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymChCl.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymChCL.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Create table entries, similar to writing sym_k... + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; + classobj = childobj->class; + fprintf (outfil, " sym_k_%s_object,\n", + classobj->tkname); + } +fprintf (outfil, canned1a); + +/* + * close the output file + */ +printf ("\nCreated UilSymChCl.h"); +fclose (outfil); + +} + + +/* + * Routine to write out UilSymArTy.h + * + * A table of data types accessed by argument type (sym_k__arg, in + * the form + * ... + * sym_k__value, + */ + +void wmlOutputUilSymArTy () + +{ + +char *canned1 = +"/* Table of the types of arguments\n\ + The table is indexed by argument with each entry the\n\ + permitted type for that argument.\n\ +*/\n\ +\n\ +static unsigned char argument_type_table_vec[] =\n\ + {\n\ + 0,\n"; + +char *canned1a = +" };\n\ +externaldef(uil_sym_glbl) unsigned char *argument_type_table =\n\ +\t argument_type_table_vec;\n"; + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlDataTypeDefPtr datobj; /* data type object */ +WmlResourceDefPtr resobj; /* resource object */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymArTy.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymArTy.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Create table entries, similar to writing sym_k... + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + datobj = resobj->dtype_def; + fprintf (outfil, " sym_k_%s_value,\n", + datobj->tkname); + } +fprintf (outfil, canned1a); + +/* + * close the output file + */ +printf ("\nCreated UilSymArTy.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilSymRArg.h + * + * Related argument table + */ + +void wmlOutputUilSymRArg () + +{ + +char *canned1 = +"/* Related argument table. Each non-zero entry is the code\n\ + of the related argument.\n\ + */\n\ +\n\ +static unsigned short int related_argument_table_vec[] =\n\ + {\n\ + 0,\n"; + +char *canned1a = +" };\n\ +externaldef(uil_sym_glbl) unsigned short int *related_argument_table =\n\ +\t\trelated_argument_table_vec;\n"; + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlResourceDefPtr resobj; /* resource object */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymRArg.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymRArg.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Create table entries, similar to writing sym_k... + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + fprintf (outfil, " %d,\n", + resobj->related_code); + } +fprintf (outfil, canned1a); + +/* + * close the output file + */ +printf ("\nCreated UilSymRArg.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilUrmClas.h + * + * Table of convenience function names indexed by the sym_k_ literal + * for both widgets and gadgets + * Table of resource names indexed by the sym_k__arg and + * sym_k__reason codes. + */ + +void wmlOutputUilUrmClas () + +{ + +char *canned1 = +"\n/* Define mapping of UIL widget types to convenience functions. */\n\ +static char *uil_widget_funcs_vec[] = {\n\ + \"\",\t /* NOT USED */\n"; + +char *canned2 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_widget_funcs = uil_widget_funcs_vec;\n\ +\n\ +/* Define mapping of UIL widget classes to matching gadget class. */\n\ +static unsigned short int uil_gadget_variants_vec[] = {\n\ + 0,\t /* NOT USED */\n"; + +char *canned3 = +"};\n\ +externaldef(uil_sym_glbl) unsigned short int *uil_gadget_variants =\n\ +\t\tuil_gadget_variants_vec;\n\ +\n\ +/* Define mapping of dialog types to non-dialog URM widget classes. */\n\ +static unsigned short int uil_urm_nondialog_class_vec[] = {\n\ + 0,\t/* NOT USED */\n"; + +char *canned4 = +"};\n\ +externaldef(uil_sym_glbl) unsigned short int *uil_urm_nondialog_class =\n\ +\t\tuil_urm_nondialog_class_vec;\n\ +\n\ +/* Define mapping of widget controls to a (subtree) resource. */\n\ +static unsigned short int uil_urm_subtree_resource_vec[] = {\n\ + 0,\t/* NOT USED */\n"; + +char *canned5 = +"};\n\ +externaldef(uil_sym_glbl) unsigned short int *uil_urm_subtree_resource =\n\ +\t\tuil_urm_subtree_resource_vec;\n\ +\n\ +/* Define mapping of arguments to toolkit names. */\n\ +static char *uil_argument_toolkit_names_vec[] = {\n\ + \"\",\t /* NOT USED */\n"; + +char *canned6 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_argument_toolkit_names =\n\ +\t\tuil_argument_toolkit_names_vec;\n\ +\n\ +/* Define mapping of reasons to toolkit names. */\n\ +static char *uil_reason_toolkit_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n"; + +char *canned7 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_reason_toolkit_names =\n\ +\t\tuil_reason_toolkit_names_vec;\n"; + + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlClassDefPtr clsobj; /* class object */ +WmlSynClassDefPtr synobj; /* syntactic object */ +WmlClassDefPtr varobj; /* variant (widget) class object */ +WmlResourceDefPtr resobj; /* argument/reason object */ +WmlSynResourceDefPtr synres; /* arg/reason syntactic object */ +WmlResourceDefPtr mapresobj; /* controls map to resource object */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilUrmClas.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilUrmClas.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Write entries for widgets + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + if ( clsobj->sym_code == 0 ) continue; + synobj = clsobj->syndef; + if ( synobj->int_lit != NULL ) + fprintf (outfil, " \"%s\",\n", synobj->convfunc); + else + fprintf (outfil, " \"%s\",\t\n", synobj->convfunc); + } +fprintf (outfil, canned2); + +/* + * Write entries for gadget variants of widget classes + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + if ( clsobj->sym_code == 0 ) continue; + varobj = clsobj->variant; + synobj = clsobj->syndef; + if ( varobj==NULL || synobj->type==WmlClassTypeGadget ) + fprintf (outfil, " 0,\n"); + else + { + synobj = varobj->syndef; + if ( synobj->int_lit != NULL ) + fprintf (outfil, " sym_k_%s_object,\n", + synobj->int_lit); + else + fprintf (outfil, " sym_k_%s_object,\n", + synobj->name); + } + } +fprintf (outfil, canned3); + +/* + * Write entries for non-dialog widgets + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + if ( clsobj->sym_code == 0 ) continue; + varobj = clsobj->nondialog; + synobj = clsobj->syndef; + if ( varobj == NULL ) + fprintf (outfil, " 0,\n"); + else + { + synobj = varobj->syndef; + if ( synobj->int_lit != NULL ) + fprintf (outfil, " sym_k_%s_object,\n", + synobj->int_lit); + else + fprintf (outfil, " sym_k_%s_object,\n", + synobj->name); + } + } +fprintf (outfil, canned4); + +/* + * Write entries for the resource a widget's controls map to + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + if ( clsobj->sym_code == 0 ) continue; + synobj = clsobj->syndef; + mapresobj = clsobj->ctrlmapto; + if ( mapresobj == NULL ) + fprintf (outfil, " 0,\n"); + else + fprintf (outfil, " sym_k_%s_arg,\n", mapresobj->tkname); + } +fprintf (outfil, canned5); + +/* + * Write entries for arguments + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + synres = resobj->syndef; + if ( resobj->sym_code == 0 ) continue; + fprintf (outfil, " %s,\n", + synres->resliteral); + } +fprintf (outfil, canned6); + +/* + * Write entries for reasons + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + synres = resobj->syndef; + if ( resobj->sym_code == 0 ) continue; + fprintf (outfil, " %s,\n", + synres->resliteral); + } +fprintf (outfil, canned7); + +/* + * close the output file + */ +printf ("\nCreated UilUrmClas.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilConst.h + * + * A bit vector showing which arguments are constraints. + */ + +void wmlOutputUilConst () + +{ + +char *canned1 = +"/* Table indexed by argument indicating whether\n\ + argument is a constraint (TRUE) or a regular\n\ + argument (FALSE). Each entry is one bit.\n\ + Index and mask macros are defined to simplify\n\ + access to the table\n\ +*/\n\ +\n\ +static unsigned char constraint_tab_vec[] = {\n"; + +char *canned1a = +"};\n\ +externaldef(uil_sym_glbl) unsigned char *constraint_tab =\n\ +\t\tconstraint_tab_vec;\n"; + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlResourceDefPtr resobj; /* resource object */ +WmlSynResourceDefPtr synobj; /* syntactic object */ +char maskbuf[100]; /* to constuct each mask */ +int bitno; /* current bit number, from code */ + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilConst.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilConst.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Process the arguments in code order. We start with 1, and write out + * the mask after processing 8 codes. + */ +fprintf (outfil, canned1); +strcpy (maskbuf, "0"); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + synobj = resobj->syndef; + bitno = resobj->sym_code % 8; + if ( bitno == 0 ) bitno = 8; + if ( synobj->type == WmlResourceTypeConstraint ) + strcat (maskbuf, bit_masks[bitno]); + if ( bitno == 8 ) + { + fprintf (outfil, "%s,\n", maskbuf); + strcpy (maskbuf, "0"); + } + } +if ( bitno != 8 ) + fprintf (outfil, "%s", maskbuf); +fprintf (outfil, canned1a); + +/* + * close the output file + */ +printf ("\nCreated UilConst.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilSymReas.h + * + * This file defines the reasons supported by each class. For each + * reason, there is a bit vector with the bit for each supporting class + * turned on if the reason is supported. There is then a vector pointing + * to these bit vectors for all reasons. This vector is accessed by + * sym_k_..._reason to find the reasons bit vector, then by sym_k_..._object + * to check the bit. + */ + +void wmlOutputUilSymReas () + +{ + +char *canned1 = +"\n/*\n\ + * Bit vectors for each reason. The entries in the vector correspond\n\ + * to each class.\n\ + */\n"; + +char *bvechdr = +"\n\ +/* sym_k_%s_reason */\n\ +static unsigned char reason_class_vec%d[] =\n\ + {\n"; + +char *canned2 = +"\n/*\n\ + * Table of bit vectors accessed by sym_k_..._reason\n\ + */\n\ +static unsigned char *allowed_reason_table_vec[] =\n\ + {\n\ + NULL,\t/* UNUSED */\n"; + +char *canned3 = +" };\n\ +externaldef(uil_sym_glbl) unsigned char **allowed_reason_table =\n\ +\t\tallowed_reason_table_vec;\n"; + +FILE *outfil; /* output file */ +int resndx; /* outer loop index */ +WmlResourceDefPtr resobj; /* current reason */ +int clsndx; /* inner loop index */ +WmlClassDefPtr clsobj; /* current class object */ +WmlClassResDefPtr resref; /* class' resource reference */ +int itemno; /* item in bye */ +char maskbuf[500]; /* current mask buffer */ +char itembuf[100]; /* for current item */ +int donl; /* TRUE if append \n to mask */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymReas.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymReas.h"); + return; + } +fprintf (outfil, canned_warn); +fprintf (outfil, canned1); + +/* + * Generate the bit vectors for each class. Outer loop on the reason code, + * inner loop on the class code. + */ +for ( resndx=0 ; resndxcnt ; resndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[resndx].objptr; + fprintf (outfil, bvechdr, resobj->tkname, resobj->sym_code); + + /* + * inner loop on widget class. + */ + strcpy (maskbuf, " "); + for ( clsndx=0 ; clsndxcnt ; clsndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[clsndx].objptr; + itemno = (clsobj->sym_code+1) % 8; + donl = FALSE; + resref = wmlResolveResIsMember (resobj, clsobj->reasons); + if ( resref != NULL ) + if ( resref->exclude != WmlAttributeTrue ) + { + sprintf (itembuf, " _BIT_MASK(sym_k_%s_object) |", + clsobj->tkname); + strcat (maskbuf, itembuf); + donl = TRUE; + } + if ( donl ) + strcat (maskbuf, "\n "); + if ( itemno == 0 ) + { + fprintf (outfil, "%s 0", maskbuf); + strcpy (maskbuf, ","); + } + } + if ( itemno != 0 ) + fprintf (outfil, "%s 0};\n", maskbuf); + else + fprintf (outfil, "};\n"); + } + +/* + * Write the vector of vectors. + */ +fprintf (outfil, canned2); +for ( resndx=0 ; resndxcnt ; resndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[resndx].objptr; + fprintf (outfil, " reason_class_vec%d,\n", resobj->sym_code); + } +fprintf (outfil, canned3); + +/* + * close the output file + */ +printf ("\nCreated UilSymReas.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilSymArTa.h + * + * This file defines the arguments supported by each class. For each + * argument, there is a bit vector with the bit for each supporting class + * turned on if the argument is supported. There is then a vector pointing + * to these bit vectors for all arguments. This vector is accessed by + * sym_k_..._arg to find the arguments bit vector, then by sym_k_..._object + * to check the bit. + */ + +void wmlOutputUilSymArTa () + +{ + +char *canned1 = +"\n/*\n\ + * Bit vectors for each argument. The entries in the vector correspond\n\ + * to each class.\n\ + */\n"; + +char *bvechdr = +"\n\ +/* sym_k_%s_arg */\n\ +static unsigned char arg_class_vec%d[] =\n\ + {\n"; + +char *canned2 = +"\n/*\n\ + * Table of bit vectors accessed by sym_k_..._arg\n\ + */\n\ +static unsigned char *allowed_argument_table_vec[] =\n\ + {\n\ + NULL,\t/* UNUSED */\n"; + +char *canned3 = +" };\n\ +externaldef(uil_sym_glbl) unsigned char **allowed_argument_table =\n\ +\t\tallowed_argument_table_vec;\n"; + +FILE *outfil; /* output file */ +int resndx; /* outer loop index */ +WmlResourceDefPtr resobj; /* current argument */ +int clsndx; /* inner loop index */ +WmlClassDefPtr clsobj; /* current class object */ +WmlClassResDefPtr resref; /* class' resource reference */ +int itemno; /* item in bye */ +char maskbuf[500]; /* current mask buffer */ +char itembuf[100]; /* for current item */ +int donl; /* TRUE if append \n to mask */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymArTa.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymArTa.h"); + return; + } +fprintf (outfil, canned_warn); +fprintf (outfil, canned1); + +/* + * Generate the bit vectors for each class. Outer loop on the argument code, + * inner loop on the class code. + */ +for ( resndx=0 ; resndxcnt ; resndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[resndx].objptr; + fprintf (outfil, bvechdr, resobj->tkname, resobj->sym_code); + + /* + * inner loop on widget class. + */ + strcpy (maskbuf, " "); + for ( clsndx=0 ; clsndxcnt ; clsndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[clsndx].objptr; + itemno = (clsobj->sym_code+1) % 8; + donl = FALSE; + resref = wmlResolveResIsMember (resobj, clsobj->arguments); + if ( resref != NULL ) + if ( resref->exclude != WmlAttributeTrue ) + { + sprintf (itembuf, " _BIT_MASK(sym_k_%s_object) |", + clsobj->tkname); + strcat (maskbuf, itembuf); + donl = TRUE; + } + if ( donl ) + strcat (maskbuf, "\n "); + if ( itemno == 0 ) + { + fprintf (outfil, "%s 0", maskbuf); + strcpy (maskbuf, ","); + } + } + if ( itemno != 0 ) + fprintf (outfil, "%s 0};\n", maskbuf); + else + fprintf (outfil, "};\n"); + } + +/* + * Write the vector of vectors. + */ +fprintf (outfil, canned2); +for ( resndx=0 ; resndxcnt ; resndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[resndx].objptr; + fprintf (outfil, " arg_class_vec%d,\n", resobj->sym_code); + } +fprintf (outfil, canned3); + +/* + * close the output file + */ +printf ("\nCreated UilSymArTa.h"); +fclose (outfil); + +} + + +/* + * Routine to write out UilSymChTa.h + * + * This file defines the automatic children supported by each class. For each + * child, there is a bit vector with the bit for each supporting class + * turned on if the child is supported. There is then a vector pointing + * to these bit vectors for all children. This vector is accessed by + * sym_k_..._child to find the child's bit vector, then by sym_k_..._object + * to check the bit. + */ + +void wmlOutputUilSymChTa () + +{ + +char *canned1 = +"\n/*\n\ + * Bit vectors for each child. The entries in the vector correspond\n\ + * to each class.\n\ + */\n"; + +char *bvechdr = +"\n\ +/* sym_k_%s_child */\n\ +static unsigned char child_class_vec%d[] =\n\ + {\n"; + +char *canned2 = +"\n/*\n\ + * Table of bit vectors accessed by sym_k_..._child\n\ + */\n\ +static unsigned char *allowed_child_table_vec[] =\n\ + {\n\ + NULL,\t/* UNUSED */\n"; + +char *canned3 = +" };\n\ +externaldef(uil_sym_glbl) unsigned char **allowed_child_table =\n\ +\t\tallowed_child_table_vec;\n"; + +FILE *outfil; /* output file */ +int childndx; /* outer loop index */ +WmlChildDefPtr childobj; /* current argument */ +int clsndx; /* inner loop index */ +WmlClassDefPtr clsobj; /* current class object */ +WmlClassChildDefPtr childref; /* class' child reference */ +int itemno; /* item in byte */ +char maskbuf[500]; /* current mask buffer */ +char itembuf[100]; /* for current item */ +int donl; /* TRUE if append \n to mask */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymChTa.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymChTa.h"); + return; + } +fprintf (outfil, canned_warn); +fprintf (outfil, canned1); + +/* + * Generate the bit vectors for each class. Outer loop on the child code, + * inner loop on the class code. + */ +for ( childndx=0 ; childndxcnt ; childndx++ ) + { + childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[childndx].objptr; + fprintf (outfil, bvechdr, childobj->tkname, childobj->sym_code); + + /* + * inner loop on widget class. + */ + strcpy (maskbuf, " "); + for ( clsndx=0 ; clsndxcnt ; clsndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[clsndx].objptr; + itemno = (clsobj->sym_code+1) % 8; + donl = FALSE; + childref = wmlResolveChildIsMember (childobj, clsobj->children); + if ( childref != NULL ) + { + sprintf (itembuf, " _BIT_MASK(sym_k_%s_object) |", clsobj->tkname); + strcat (maskbuf, itembuf); + donl = TRUE; + } + if ( donl ) + strcat (maskbuf, "\n "); + if ( itemno == 0 ) + { + fprintf (outfil, "%s 0", maskbuf); + strcpy (maskbuf, ","); + } + } + if ( itemno != 0 ) + fprintf (outfil, "%s 0};\n", maskbuf); + else + fprintf (outfil, "};\n"); + } + +/* + * Write the vector of vectors. + */ +fprintf (outfil, canned2); +for ( childndx=0 ; childndxcnt ; childndx++ ) + { + childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[childndx].objptr; + fprintf (outfil, " child_class_vec%d,\n", childobj->sym_code); + } +fprintf (outfil, canned3); + +/* + * close the output file + */ +printf ("\nCreated UilSymChTa.h"); +fclose (outfil); + +} + + +/* + * Routine to write out UilSymCtl.h + * + * This file defines the controls supported by each class. For each + * object, there is a bit vector with the bit for each supporting class + * turned on if the object is supported. There is then a vector pointing + * to these bit vectors for all objects. This vector is accessed by + * sym_k_..._object to find the objects bit vector, then by sym_k_..._object + * to check the bit. + */ + +void wmlOutputUilSymCtl () + +{ + +char *canned1 = +"\n/*\n\ + * Bit vectors for each control. The entries in the vector correspond\n\ + * to each class.\n\ + */\n"; + +char *bvechdr = +"\n\ +/* sym_k_%s_object */\n\ +static unsigned char object_class_vec%d[] =\n\ + {\n"; + +char *canned2 = +"\n/*\n\ + * Table of bit vectors accessed by sym_k_..._object\n\ + */\n\ +static unsigned char *allowed_control_table_vec[] =\n\ + {\n\ + NULL,\t/* UNUSED */\n"; + +char *canned3 = +" };\n\ +externaldef(uil_sym_glbl) unsigned char **allowed_control_table =\n\ +\t\tallowed_control_table_vec;\n"; + +FILE *outfil; /* output file */ +int ctlndx; /* outer loop index */ +WmlClassDefPtr ctlobj; /* current class allowing controls */ +int clsndx; /* inner loop index */ +WmlClassDefPtr clsobj; /* current class object */ +int itemno; /* item in bye */ +char maskbuf[500]; /* current mask buffer */ +char itembuf[100]; /* for current item */ +int donl; /* TRUE if append \n to mask */ + + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymCtl.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymCtl.h"); + return; + } +fprintf (outfil, canned_warn); +fprintf (outfil, canned1); + +/* + * Generate the bit vectors for each class. Outer loop on the class code, + * inner loop on the class code. + */ +for ( ctlndx=0 ; ctlndxcnt ; ctlndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ctlndx].objptr; + fprintf (outfil, bvechdr, clsobj->tkname, clsobj->sym_code); + + /* + * inner loop on widget class. + */ + strcpy (maskbuf, " "); + for ( clsndx=0 ; clsndxcnt ; clsndx++ ) + { + ctlobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[clsndx].objptr; + itemno = (ctlobj->sym_code+1) % 8; + donl = FALSE; + if ( wmlResolveCtlIsMember(clsobj,ctlobj->controls) == TRUE) + { + sprintf (itembuf, " _BIT_MASK(sym_k_%s_object) |", + ctlobj->tkname); + strcat (maskbuf, itembuf); + donl = TRUE; + } + if ( donl ) + strcat (maskbuf, "\n "); + if ( itemno == 0 ) + { + fprintf (outfil, "%s 0", maskbuf); + strcpy (maskbuf, ","); + } + } + if ( itemno != 0 ) + fprintf (outfil, "%s 0};\n", maskbuf); + else + fprintf (outfil, "};\n"); + } + +/* + * Write the vector of vectors. + */ +fprintf (outfil, canned2); +for ( ctlndx=0 ; ctlndxcnt ; ctlndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ctlndx].objptr; + fprintf (outfil, " object_class_vec%d,\n", clsobj->sym_code); + } +fprintf (outfil, canned3); + +/* + * close the output file + */ +printf ("\nCreated UilSymCtl.h"); +fclose (outfil); + +} + + + +/* + * Predicate to indicate if a class object is in a controls list. + */ + +int wmlResolveCtlIsMember (ctlobj, ctlref) + WmlClassDefPtr ctlobj; + WmlClassCtrlDefPtr ctlref; + +{ + +while ( ctlref != NULL ) + { + if ( ctlref->ctrl == ctlobj ) return TRUE; + ctlref = ctlref->next; + } +return FALSE; + +} + + + +/* + * Routine to write out UilSymNam.h + * + * Tables of names of object indexed by their various sym_k_ literals. + */ + +void wmlOutputUilSymNam () + +{ + +char *canned1 = +"/* Define mapping of sym_k_..._object codes to widget names. */\n\ +\n\ +externaldef(uil_sym_glbl) int uil_max_object = %d;\n\ +static char *uil_widget_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n"; + +char *canned2 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_widget_names =\n\ +\t\tuil_widget_names_vec;\n\ +\n\n\ +/* Define mapping of sym_k_..._arg codes to argument names. */\n\ +\n\ +externaldef(uil_sym_glbl) int uil_max_arg = %d;\n\ +static char *uil_argument_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n"; + +char *canned3 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_argument_names =\n\ +\t\tuil_argument_names_vec;\n\ +\n\n\ +/* Define mapping of sym_k_..._reason to reason names. */\n\ +\n\ +externaldef(uil_sym_glbl) int uil_max_reason = %d;\n\ +static char *uil_reason_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n"; + +char *canned4 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_reason_names =\n\ +\t\tuil_reason_names_vec;\n\ +\n\n\ +/* Define mapping of sym_k_..._enumval to enumeration value names. */\n\ +\n\ +externaldef(uil_sym_glbl) int uil_max_enumset = %d;\n\ +externaldef(uil_sym_glbl) int uil_max_enumval = %d;\n\ +static char *uil_enumval_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n"; + +char *canned5 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_enumval_names =\n\ +\t\tuil_enumval_names_vec;\n\ +\n\n\ +/* Define mapping of sym_k_..._charset to enumeration value names. */\n\ +\n\ +externaldef(uil_sym_glbl) int uil_max_charset = %d;\n\ +static char *uil_charset_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n\ + \"\",\n"; + +char *canned6 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_charset_names =\n\ +\t\tuil_charset_names_vec;\n\ +\n\n\ +/* Define mapping of sym_k_..._child codes to child names. */\n\ +\n\ +externaldef(uil_sym_glbl) int uil_max_child = %d;\n\ +static char *uil_child_names_vec[] = {\n\ + \"\",\t/* NOT USED */\n"; + +char *canned7 = +"};\n\ +externaldef(uil_sym_glbl) char **uil_child_names =\n\ +\t\tuil_child_names_vec;\n"; + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlClassDefPtr clsobj; /* class object */ +WmlClassDefPtr varobj; /* gadget class object */ +WmlSynClassDefPtr synobj; /* syntactic object */ +WmlResourceDefPtr resobj; /* argument/reason object */ +WmlSynResourceDefPtr synres; /* arg/reason syntactic object */ +WmlEnumValueDefPtr evobj; /* enumeration value object */ +WmlSynEnumValueDefPtr synev; /* enumeration value syntactic obj */ +WmlCharSetDefPtr csobj; /* character set object */ +WmlSynCharSetDefPtr syncs; /* character set syntactic obj */ +WmlChildDefPtr chobj; /* child object */ +WmlSynChildDefPtr synch; /* child syntactic object */ + +/* + * Open the output file. Write canned header. + */ +outfil = fopen ( "UilSymNam.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymNam.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Write entries for widgets + */ +fprintf (outfil, canned1, max_object_code); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + if ( clsobj->sym_code == 0 ) continue; + synobj = clsobj->syndef; + fprintf (outfil, " \"%s\",\n", + synobj->name); + } + +/* + * Write entries for arguments + */ +fprintf (outfil, canned2, max_arg_code); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + synres = resobj->syndef; + if ( resobj->sym_code == 0 ) continue; + fprintf (outfil, " \"%s\",\n", + synres->name); + } + +/* + * Write entries for reasons + */ +fprintf (outfil, canned3, max_reason_code); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + synres = resobj->syndef; + if ( resobj->sym_code == 0 ) continue; + fprintf (outfil, " \"%s\",\n", + synres->name); + } + +/* + * Write entries for enumeration values + */ +fprintf (outfil, canned4, max_enumset_code, max_enumval_code); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + evobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; + synev = evobj->syndef; + if ( evobj->sym_code == 0 ) continue; + fprintf (outfil, " \"%s\",\n", + synev->name); + } + +/* + * Write entries for character sets + */ +fprintf (outfil, canned5, max_charset_code); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + fprintf (outfil, " \"%s\",\n", + syncs->name); + } + +/* + * Write entries for children + */ +fprintf (outfil, canned6, max_child_code); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + chobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; + synch = chobj->syndef; + if ( chobj->sym_code == 0 ) continue; + fprintf (outfil, " \"%s\",\n", + synch->name); + } +fprintf (outfil, canned7); + +/* + * close the output file + */ +printf ("\nCreated UilSymNam.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilSymEnum.h + * + * This file defines the enumeration sets recognized by UIL. There is an + * entry in this file for each enumeration set. The definitions are accessed + * by the sym_k_..._enumset code. Each consists of a structure containing + * a vector of enumeration value descriptors, each of which is the name + * of the value and its value. + * + * UilSymEnum.h contains: + * - Vectors of value descriptors for each table entry + * - The table itself. + * - A table given the sym_k_..._enumset code for each argument which + * has an enumeration set. + * - A table accessed by sym_k_..._enumval code giving the actual value + * for each enumeration value. + * + * The typedefs for the tables are in UilSymGen.h + */ + +void wmlOutputUilSymEnum () + +{ + +char *canned1 = +"\n\ +/*\n\ + * Enumeration value vectors for each enumeration set\n\ + */\n\ +\n"; + +char *valhdr = +"\n\ +static unsigned short int enum_value_vec%d[] =\n\ + {\n"; + +char *canned3 = +"\n\ +/*\n\ + * Enumeration set descriptor table\n\ + */\n\ +static UilEnumSetDescDef enum_set_table_vec[] =\n\ + {\n\ + {0,NULL},\n"; + +char *canned4 = +" };\n\ +externaldef(uil_sym_glbl) UilEnumSetDescDef *enum_set_table =\n\ +\t\tenum_set_table_vec;\n\ +/*\n\ + * Enumeration set table, accessed by sym_k_..._arg code. Each non-zero entry\n\ + * is the sym_k_..._enumset code for the argument's enumeration set.\n\ + */\n\ +static unsigned short int argument_enumset_table_vec[] =\n\ + {\n\ + 0,\n"; + +char *canned5 = +" };\n\ +externaldef(uil_sym_glbl) unsigned short int *argument_enumset_table =\n\ +\t\targument_enumset_table_vec;\n\ +/*\n\ + * Enumeration value table, accessed by sym_k_..._enumval code. Each entry is\n\ + * the actual value associated with the code.\n\ + */\n\ +static int enumval_values_table_vec[] =\n\ + {\n\ + 0,\n"; + +char *canned5a = +" };\n\ +externaldef(uil_sym_glbl) int *enumval_values_table =\n\ +\t\tenumval_values_table_vec;\n"; + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlEnumSetDefPtr enumsetobj; /* enumeration set object */ +WmlEnumSetValDefPtr esvobj; /* current enum set value list element */ +WmlEnumValueDefPtr evobj; /* current enumeration value object */ +WmlResourceDefPtr resobj; /* resource object */ + + +/* + * Open the output file. Write the canned header stuff + */ +outfil = fopen ("UilSymEnum.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymEnum.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Generate the enumeration value vectors for each enumeration set. + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; + fprintf (outfil, valhdr, enumsetobj->sym_code); + for ( esvobj=enumsetobj->values ; esvobj!=NULL ; esvobj=esvobj->next ) + { + evobj = esvobj->value; + fprintf (outfil, " %d,\n", + evobj->sym_code); + } + fprintf (outfil, " };\n"); + } + +/* + * Generate the enumeration set tables + */ +fprintf (outfil, canned3); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; + fprintf (outfil, " {%d,enum_value_vec%d},\n", + enumsetobj->values_cnt, + enumsetobj->sym_code); + } + +/* + * Create enumset table entries for arguments, similar to writing sym_k... + */ +fprintf (outfil, canned4); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + if ( resobj->enumset_def == NULL ) + fprintf (outfil, " 0,\n"); + else + fprintf (outfil, " %d,\n", + resobj->enumset_def->sym_code); + } + +/* + * Create the enumval values table. + */ +fprintf (outfil, canned5); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + evobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; + fprintf (outfil, " %s,\n", evobj->syndef->enumlit); + } +fprintf (outfil, canned5a); + +/* + * close the output file + */ +printf ("\nCreated UilSymEnum.h"); +fclose (outfil); + +} + + + +/* + * Routine to write out UilSymCSet.h + * + * This file specifies the various attributes for the character sets + * recognized by UIL. There is a table for each of the following + * attributes: + * - Standards name associated with the character set + * - Writing direction, from XmSTRING_DIRECTION_... + * - Parsing direction, from XmSTRING_DIRECTION_... + * - Bytes per character, from sym_k_..._charsize (in UilSymGen.h) + * - A pair of tables for recognizing $LANG settings: + * o a table of all names under which a character set might + * be legally recognized (upper case). + * o the sym_k_..._charset code for each entry + * o a variable giving the number of entries in the table + * + * All tables are accessed by the sym_k_..._charset + * + */ + +void wmlOutputUilSymCSet () + +{ + +char *canned1 = +"\n\ +/*\n\ + * Character set XmString name table, accessed by sym_k_..._charset code.\n\ + * Each entry is the name which identifies the character set in a XmString.\n\ + */\n\ +static char *charset_xmstring_names_table_vec[] =\n\ + {\n\ + 0,\n\ + \"\",\n"; + +char *canned2 = +"};\n\ +externaldef(uil_sym_glbl) char **charset_xmstring_names_table =\n\ +\t\tcharset_xmstring_names_table_vec;\n\ +/*\n\ + * Character set writing direction table, accessed by sym_k_..._charset code.\n\ + * Each entry is the XmSTRING_DIRECTION_... code which identifies the\n\ + * writing direction for the character set in a XmString.\n\ + */\n\ +static unsigned char charset_wrdirection_table_vec[] =\n\ + {\n\ + 0,\n\ + 0,\t/* userdefined */\n"; + +char *canned3 = +"};\n\ +externaldef(uil_sym_glbl) unsigned char *charset_writing_direction_table =\n\ +\t\tcharset_wrdirection_table_vec;\n\ +/*\n\ + * Character set parsing direction table, accessed by sym_k_..._charset code.\n\ + * Each entry is the XmSTRING_DIRECTION_... code which identifies the\n\ + * parsing direction for the character set in a XmString.\n\ + */\n\ +static unsigned char charset_parsdirection_table_vec[] =\n\ + {\n\ + 0,\n\ + 0,\t/* userdefined */\n"; + +char *canned4 = +"};\n\ +externaldef(uil_sym_glbl) unsigned char *charset_parsing_direction_table =\n\ +\t\tcharset_parsdirection_table_vec;\n\ +/*\n\ + * Character set character size table, accessed by sym_k_..._charset code.\n\ + * Each entry is the sym_k_..._charsize literal which names the character\n\ + * size for the character set in a XmString.\n\ + */\n\ +static unsigned char charset_charsize_table_vec[] =\n\ + {\n\ + 0,\n\ + 0,\t/* userdefined */\n"; + +char *canned5 = +"};\n\ +externaldef(uil_sym_glbl) unsigned char *charset_character_size_table =\n\ +\t\tcharset_charsize_table_vec;\n\ +/*\n\ + * All the names under which a character set may be legally named in a \n\ + * $LANG variable (upper case).\n\ + */\n\ +static char *charset_lang_names_table_vec[] =\n\ + {\n"; + +char *canned6 = +"};\n\ +externaldef(uil_sym_glbl) char **charset_lang_names_table =\n\ +\t\tcharset_lang_names_table_vec;\n\ +/*\n\ + * The sym_k_..._charset codes for charset_lang_names\n\ + */\n\ +static unsigned short int charset_lang_codes_table_vec[] =\n\ + {\n"; + +char *canned7 = +"};\n\ +externaldef(uil_sym_glbl) unsigned short int *charset_lang_codes_table =\n\ +\t\tcharset_lang_codes_table_vec;\n\ +/*\n\ + * The number of entries in charset_lang_..._table tables\n\ + */\n\ +externaldef(uil_sym_glbl) unsigned short int charset_lang_table_max = %d;\n"; + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlCharSetDefPtr csobj; /* character set object */ +WmlSynCharSetDefPtr syncs; /* character set syntactic obj */ +int lang_max; /* max value for $LANG tables */ +int alias_ndx; /* alias loop index */ +char uname[200]; /* name converted to upper case */ + + +/* + * Open the output file. Write the canned header stuff + */ +outfil = fopen ("UilSymCSet.h", "w"); +if ( outfil == (FILE *) NULL ) + { + printf ("\nCouldn't open UilSymCSet.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Generate the standards name table + */ +fprintf (outfil, canned1); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + if ((strcmp(syncs->xms_name, "XmFONTLIST_DEFAULT_TAG") == 0) || + (strcmp(syncs->xms_name, "_MOTIF_DEFAULT_LOCALE") == 0)) + fprintf (outfil, " %s,\t/* %s */\n", + syncs->xms_name, syncs->name); + else + fprintf (outfil, " \"%s\",\t/* %s */\n", + syncs->xms_name, syncs->name); + } + +/* + * Generate the writing direction table + */ +fprintf (outfil, canned2); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + switch ( syncs->direction ) + { + case WmlCharSetDirectionLtoR: + fprintf (outfil, " XmSTRING_DIRECTION_L_TO_R,\t/* %s */\n", + syncs->name); + break; + case WmlCharSetDirectionRtoL: + fprintf (outfil, " XmSTRING_DIRECTION_R_TO_L,\t/* %s */\n", + syncs->name); + break; + } + } + +/* + * Generate the parsing direction table + */ +fprintf (outfil, canned3); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + switch ( syncs->parsedirection ) + { + case WmlCharSetDirectionLtoR: + fprintf (outfil, " XmSTRING_DIRECTION_L_TO_R,\t/* %s */\n", + syncs->name); + break; + case WmlCharSetDirectionRtoL: + fprintf (outfil, " XmSTRING_DIRECTION_R_TO_L,\t/* %s */\n", + syncs->name); + break; + } + } + +/* + * Generate the character size table + */ +fprintf (outfil, canned4); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + switch ( syncs->charsize ) + { + case WmlCharSizeOneByte: + fprintf (outfil, " sym_k_onebyte_charsize,\t/* %s */\n", + syncs->name); + break; + case WmlCharSizeTwoByte: + fprintf (outfil, " sym_k_twobyte_charsize,\t/* %s */\n", + syncs->name); + break; + case WmlCharSizeMixed1_2Byte: + fprintf (outfil, " sym_k_mixed1_2byte_charsize,\t/* %s */\n", + syncs->name); + break; + } + } + +/* + * Generate the $LANG name recognition table + */ +fprintf (outfil, canned5); +lang_max = 0; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + strcpy (uname, syncs->name); + wmlUpperCaseString (uname); + fprintf (outfil, " \"%s\",\t/* %s */\n", + uname, syncs->name); + lang_max += 1; + strcpy (uname, syncs->xms_name); + wmlUpperCaseString (uname); + fprintf (outfil, " \"%s\",\t/* %s */\n", + uname, syncs->name); + lang_max += 1; + for ( alias_ndx=0 ; alias_ndxalias_cnt ; alias_ndx++ ) + { + strcpy (uname, syncs->alias_list[alias_ndx]); + wmlUpperCaseString (uname); + fprintf (outfil, " \"%s\",\t/* %s */\n", + uname, syncs->name); + lang_max += 1; + } + } + +/* + * Generate the $LANG code lookup table, in upper case + */ +fprintf (outfil, canned6); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + syncs = csobj->syndef; + if ( csobj->sym_code == 0 ) continue; + fprintf (outfil, " sym_k_%s_charset,\n", syncs->name); + fprintf (outfil, " sym_k_%s_charset,\n", syncs->name); + for ( alias_ndx=0 ; alias_ndxalias_cnt ; alias_ndx++ ) + fprintf (outfil, " sym_k_%s_charset,\n", syncs->name); + } + +/* + * Generate the number of entries in the previous two tables + */ +fprintf (outfil, canned7, lang_max); + +/* + * close the output file + */ +printf ("\nCreated UilSymCSet.h"); +fclose (outfil); + +} + + diff --git a/tools/wml/wmloutkey.c b/tools/wml/wmloutkey.c index af42f22..4c14728 100644 --- a/tools/wml/wmloutkey.c +++ b/tools/wml/wmloutkey.c @@ -574,16 +574,16 @@ if ( outfil == NULL ) printf ("\nCouldn't open UilKeyTab.h"); return; } -fprintf (outfil, canned_warn); +fprintf (outfil, "%s", canned_warn); /* * Print the case sensitive and insensitive tables */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); wmlOutputUilKeyTabBody (outfil, wml_tok_sens_ptr, &maxlen, &maxkey); fprintf (outfil, canned2, maxlen, maxkey); wmlOutputUilKeyTabBody (outfil, wml_tok_insens_ptr, &maxlen, &maxkey); -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * close the output file @@ -812,8 +812,8 @@ if ( outfil == NULL ) printf ("\nCouldn't open UilTokName.h"); return; } -fprintf (outfil, canned_warn); -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned_warn); +fprintf (outfil, "%s", canned1); /* * Print the token name entries diff --git a/tools/wml/wmloutkey.c.format-security b/tools/wml/wmloutkey.c.format-security new file mode 100644 index 0000000..af42f22 --- /dev/null +++ b/tools/wml/wmloutkey.c.format-security @@ -0,0 +1,838 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA +*/ +/* + * HISTORY +*/ +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$TOG: wmloutkey.c /main/8 1997/04/14 12:55:51 dbl $" +#endif +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + + +/* +* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + +/* + * This module contains routines responsible for writing the .h files which + * define the UIL lexer's keyword (token) tables. All files are written + * into the current directory. + * + * Input: + * The resolved objects + * .dat files required to specify objects defined in Uil.y: + * keyword.dat + * reserved.dat + * + * Output: + * UilKeyTab.h + * + */ + + +#include "wml.h" + +#if defined(__STDC__) +#include +#include +#endif +#include + + +/* + * Routines used only in this module + */ +void wmlKeyWBuildTables (); +void wmlKeyWClassTokens (); +void wmlKeyWGrammarTokens (); +int wmlKeyWGrammarClass (); +void wmlKeyWArgTokens (); +void wmlKeyWReasonTokens (); +void wmlKeyWCharsetTokens (); +void wmlKeyWEnumvalTokens (); +void wmlKeyWChildTokens (); +void wmlKeyWMakeTokens (); +void wmlOutputUilKeyTab (); +void wmlOutputUilKeyTabBody (); +void wmlTokenClassString (); +void wmlTokenSymKString (); +void wmlTokenTokenString (); +void wmlOutputUilTokName (); + +/* + * globals + */ + +static char *canned_warn = +"/*\n\ +**\tThis file is automatically generated. Do not edit it by hand.\n\ +**/\n\n"; + +#define GrTokenMax 200 /* limit on grammar tokens */ +static int grtok_max_val = 0; +static WmlGrammarTokenPtr grtok_vec[GrTokenMax]; + + + +/* + * Output control routine + */ + +void wmlOutputKeyWordFiles () + +{ + +wmlKeyWBuildTables (); +wmlOutputUilKeyTab (); +wmlOutputUilTokName (); + +} + + + +/* + * Routine to construct token tables for building UilKeyTab.h + * + * This routine constructs token entries for each token class which appears + * in UilKeyTab.h (the token classes are defined in UilKeyDef.h). These + * tokens are defined both by WML objects in object vectors, and by + * tokens defined in Uil.y. + */ + +void wmlKeyWBuildTables () + +{ + +int ndx; + + +/* + * Initialize the token vectors + */ +wmlInitHList (wml_tok_sens_ptr, 1000, TRUE); +wmlInitHList (wml_tok_insens_ptr, 1000, TRUE); +for ( ndx=0 ; ndx true/TRUE + * UILFALSE -> false/FALSE + * UILfile -> file/FILE + * UILeof -> eof/EOF + */ +infil = fopen ("tokens.dat", "r"); +if ( infil == NULL ) + { + printf ("\nCouldn't open tokens.dat"); + return; + } + +while ( TRUE ) + { + scanres = fscanf (infil, "%s %d %s", token, &tokval, class); + if ( scanres == EOF ) break; + if ( scanres != 3 ) + { + printf ("\nBadly formatted at line %d in tokens.dat", lineno); + continue; + } + lineno += 1; + +/* + * Convert the token class, and construct a grammar token. + */ + grtok = (WmlGrammarTokenPtr) malloc(sizeof(WmlGrammarToken)); + grtok->class = wmlKeyWGrammarClass (class); + grtok->token = wmlAllocateString (token); + grtok->val = tokval; + +/* + * Save the token in the grammar token vector, indexed by its value + * (for UilTokName.h) + */ +if ( grtok->val < GrTokenMax ) + { + grtok_vec[grtok->val] = grtok; + if ( grtok->val > grtok_max_val ) + grtok_max_val = grtok->val; + } +else + printf ("\nToken id %d for %s exceed GrTokenMax", + grtok->val, grtok->token); + +/* + * Enter tokens which appear in the keyword tables as keyword tokens. + * These have their lower case names entered as the case-insensitive + * keyword token string. Do special token literal mapping. + */ + switch ( grtok->class ) + { + case WmlTokenClassKeyword: + case WmlTokenClassReserved: + strcpy (sens_name, grtok->token); + for ( ndx=0 ; ndx<(int)strlen(sens_name) ; ndx++ ) + sens_name[ndx] = _lower(sens_name[ndx]); + if ( strcmp(sens_name,"uiltrue") == 0 ) + strcpy (sens_name, "true"); + if ( strcmp(sens_name,"uilfalse") == 0 ) + strcpy (sens_name, "false"); + if ( strcmp(sens_name,"uilfile") == 0 ) + strcpy (sens_name, "file"); + if ( strcmp(sens_name,"uileof") == 0 ) + strcpy (sens_name, "eof"); + wmlKeyWMakeTokens (sens_name, grtok->class, (ObjectPtr)grtok); + } + } + +fclose (infil); + +} + + + +/* + * This routine translates a string identifying a token class into + * its matching internal literal. + */ +int wmlKeyWGrammarClass (token) + char *token; + +{ + +if ( strcmp(token,"argument") == 0 ) + return WmlTokenClassArgument; +if ( strcmp(token,"charset") == 0 ) + return WmlTokenClassCharset; +if ( strcmp(token,"color") == 0 ) + return WmlTokenClassColor; +if ( strcmp(token,"enumval") == 0 ) + return WmlTokenClassEnumval; +if ( strcmp(token,"font") == 0 ) + return WmlTokenClassFont; +if ( strcmp(token,"identifier") == 0 ) + return WmlTokenClassIdentifier; +if ( strcmp(token,"keyword") == 0 ) + return WmlTokenClassKeyword; +if ( strcmp(token,"literal") == 0 ) + return WmlTokenClassLiteral; +if ( strcmp(token,"reason") == 0 ) + return WmlTokenClassReason; +if ( strcmp(token,"reserved") == 0 ) + return WmlTokenClassReserved; +if ( strcmp(token,"special") == 0 ) + return WmlTokenClassSpecial; +if ( strcmp(token,"unused") == 0 ) + return WmlTokenClassUnused; +if ( strcmp(token,"class") == 0 ) + return WmlTokenClassClass; +if (strcmp(token,"child") == 0) return WmlTokenClassChild; + +printf ("\nUnrecognized token class %s", token); +return 0; + +} + + + +/* + * Routine to process the class objects and enter them in the token tables. + * Aliases are also entered, under their own names. + */ + +void wmlKeyWClassTokens () + +{ + +int ndx; /* loop index */ +WmlClassDefPtr clsobj; /* class object */ +WmlSynClassDefPtr synobj; /* syntactic object */ +int alias_ndx; /* alias loop index */ + + +/* + * Make tokens for all class entries + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + synobj = clsobj->syndef; + wmlKeyWMakeTokens (synobj->name, WmlTokenClassClass, (ObjectPtr)clsobj); + for ( alias_ndx=0 ; alias_ndxalias_cnt ; alias_ndx++ ) + wmlKeyWMakeTokens (synobj->alias_list[alias_ndx], + WmlTokenClassClass, + (ObjectPtr)clsobj); + } + +} + + + +/* + * Routine to process the argument objects and enter them in the token tables. + * Aliases are also entered, under their own names. + */ + +void wmlKeyWArgTokens () + +{ + +int ndx; /* loop index */ +WmlResourceDefPtr resobj; /* resource object */ +WmlSynResourceDefPtr synobj; /* syntactic object */ +int alias_ndx; /* alias loop index */ + + +/* + * Make tokens for all argument entries + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + synobj = resobj->syndef; + wmlKeyWMakeTokens (synobj->name, WmlTokenClassArgument, (ObjectPtr)resobj); + for ( alias_ndx=0 ; alias_ndxalias_cnt ; alias_ndx++ ) + wmlKeyWMakeTokens (synobj->alias_list[alias_ndx], + WmlTokenClassArgument, + (ObjectPtr)resobj); + } + +} + + + +/* + * Routine to process the reason objects and enter them in the token tables. + */ + +void wmlKeyWReasonTokens () + +{ + +int ndx; /* loop index */ +WmlResourceDefPtr resobj; /* resource object */ +WmlSynResourceDefPtr synobj; /* syntactic object */ +int alias_ndx; /* alias loop index */ + + +/* + * Make tokens for all reason entries + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + synobj = resobj->syndef; + wmlKeyWMakeTokens (synobj->name, WmlTokenClassReason, (ObjectPtr)resobj); + for ( alias_ndx=0 ; alias_ndxalias_cnt ; alias_ndx++ ) + wmlKeyWMakeTokens (synobj->alias_list[alias_ndx], + WmlTokenClassReason, + (ObjectPtr)resobj); + } + +} + + +/* + * Routine to process the child objects and enter them in the token tables. + */ + +void wmlKeyWChildTokens () + +{ + +int ndx; /* loop index */ +WmlChildDefPtr childobj; /* child object */ +WmlSynChildDefPtr synobj; /* syntactic object */ + +/* + * Make tokens for all child entries + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; + synobj = childobj->syndef; + wmlKeyWMakeTokens (synobj->name, WmlTokenClassChild, (ObjectPtr)childobj); + } + +} + + + +/* + * Routine to process the charset objects and enter them in the token tables. + */ + +void wmlKeyWCharsetTokens () + +{ + +int ndx; /* loop index */ +WmlCharSetDefPtr csobj; /* character set object */ +WmlSynCharSetDefPtr synobj; /* syntactic object */ +int alias_ndx; /* alias loop index */ + + +/* + * Make tokens for all charset entries + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + synobj = csobj->syndef; + wmlKeyWMakeTokens (synobj->name, WmlTokenClassCharset, (ObjectPtr)csobj); + for ( alias_ndx=0 ; alias_ndxalias_cnt ; alias_ndx++ ) + wmlKeyWMakeTokens (synobj->alias_list[alias_ndx], + WmlTokenClassCharset, + (ObjectPtr)csobj); + } + +} + + + +/* + * Routine to process the enumval objects and enter them in the token tables. + */ + +void wmlKeyWEnumvalTokens () + +{ + +int ndx; /* loop index */ +WmlEnumValueDefPtr esobj; /* enumeration value object */ +WmlSynEnumValueDefPtr synobj; /* syntactic object */ + + +/* + * Make tokens for all enumval entries + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + esobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; + synobj = esobj->syndef; + wmlKeyWMakeTokens (synobj->name, WmlTokenClassEnumval, (ObjectPtr)esobj); + } + +} + + + +/* + * Routine to create tokens and enter them in the token list. + * + * This routine constructs a case-sensitive and a case-insensitive token + * and enters them the token vectors. + */ +void wmlKeyWMakeTokens (sens_name, class, obj) + char *sens_name; + int class; + ObjectPtr obj; + +{ + +WmlKeyWTokenPtr senstok; /* case-sensitive token */ +WmlKeyWTokenPtr insenstok; /* case-insensitive token */ +char insens_name[100]; +int ndx; + + +/* + * Create both tokens, with one having an upper-case name. The names are + * entered only in the order vector, not in the token itself. + */ +senstok = (WmlKeyWTokenPtr) malloc (sizeof(WmlKeyWToken)); +insenstok = (WmlKeyWTokenPtr) malloc (sizeof(WmlKeyWToken)); +senstok->class = class; +senstok->objdef = obj; +insenstok->class = class; +insenstok->objdef = obj; + +strcpy (insens_name, sens_name); +for ( ndx=0 ; ndx<(int)strlen(insens_name) ; ndx++ ) + insens_name[ndx] = _upper (insens_name[ndx]); + +wmlInsertInKeyList(wml_tok_sens_ptr, sens_name, senstok); +wmlInsertInKeyList(wml_tok_insens_ptr, insens_name, insenstok); +} + + +/* + * Routine to output UilKeyTab.h + * + * This routine dumps the tokens defined in the token tables into + * UilKeyTab.h. Both the case-sensitive and case-insensitive token + * lists are used. + */ + +void wmlOutputUilKeyTab () + +{ + +char *canned1 = +"\n/* case sensitive keyword table */\n\ +static key_keytable_entry_type key_table_vec[] =\n\ + {\n"; + +char *canned2 = +" };\n\ +externaldef(uil_sym_glbl) key_keytable_entry_type *key_table =\n\ +\t\tkey_table_vec;\n\n\ +/* Maximum length of a keyword, and table size */\n\ +externaldef(uil_sym_glbl) int key_k_keyword_max_length = %d;\n\ +externaldef(uil_sym_glbl) int key_k_keyword_count = %d;\n\n\ +/* case insensitive keyword table */\n\ +static key_keytable_entry_type key_table_case_ins_vec[] =\n\ + {\n"; + +char *canned3 = +" };\n\ +externaldef(uil_sym_glbl) key_keytable_entry_type *key_table_case_ins =\n\ +\t\tkey_table_case_ins_vec;\n"; + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +int maxlen = 0; /* max keyword length */ +int maxkey = 0; /* # entries in keyword table */ + + +/* + * Open the output file. + */ +outfil = fopen ("UilKeyTab.h", "w"); +if ( outfil == NULL ) + { + printf ("\nCouldn't open UilKeyTab.h"); + return; + } +fprintf (outfil, canned_warn); + +/* + * Print the case sensitive and insensitive tables + */ +fprintf (outfil, canned1); +wmlOutputUilKeyTabBody (outfil, wml_tok_sens_ptr, &maxlen, &maxkey); +fprintf (outfil, canned2, maxlen, maxkey); +wmlOutputUilKeyTabBody (outfil, wml_tok_insens_ptr, &maxlen, &maxkey); +fprintf (outfil, canned3); + +/* + * close the output file + */ +printf ("\nCreated UilKeyTab.h"); +fclose (outfil); + +} + + + +/* + * Routine to output the body of a keyword table + */ +void wmlOutputUilKeyTabBody (outfil, tokvec, maxlen, maxkey) + FILE *outfil; + DynamicHandleListDefPtr tokvec; + int *maxlen; + int *maxkey; + +{ + +int ndx; /* loop index */ +WmlKeyWTokenPtr tok; /* current token */ +char *tokstg; /* string for token (keyword) */ +char tkclass[100]; /* token class string */ +char tksym[100]; /* token sym_k string */ +char tktoken[100]; /* token tkn_k_num string */ + + +/* + * Loop over all tokens, and put out an entry for each. + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + tok = (WmlKeyWTokenPtr) tokvec->hvec[ndx].objptr; + tokstg = tokvec->hvec[ndx].objname; + wmlTokenClassString (tkclass, tok); + wmlTokenSymKString (tksym, tok); + wmlTokenTokenString (tktoken, tok); + fprintf (outfil, " {%s, %s, %d, %s, \"%s\"},\n", + tkclass, + tksym, + strlen(tokstg), + tktoken, + tokstg); + if ( (int)strlen(tokstg) > *maxlen ) + *maxlen = strlen (tokstg); + *maxkey += 1; + } + +} + + + +/* + * Routine to return the string for a token class, tkn_k_class_... + */ +void wmlTokenClassString (dststg, tok) + char *dststg; + WmlKeyWTokenPtr tok; + +{ + +switch ( tok->class ) + { + case WmlTokenClassArgument: + strcpy (dststg, "tkn_k_class_argument"); + return; + case WmlTokenClassCharset: + strcpy (dststg, "tkn_k_class_charset"); + return; + case WmlTokenClassEnumval: + strcpy (dststg, "tkn_k_class_enumval"); + return; + case WmlTokenClassKeyword: + strcpy (dststg, "tkn_k_class_keyword"); + return; + case WmlTokenClassReason: + strcpy (dststg, "tkn_k_class_reason"); + return; + case WmlTokenClassReserved: + strcpy (dststg, "tkn_k_class_reserved"); + return; + case WmlTokenClassClass: + strcpy (dststg, "tkn_k_class_class"); + return; + case WmlTokenClassChild: + strcpy (dststg, "tkn_k_class_child"); + return; + } + +} + + + +/* + * Routine to return the string for a sym_k_... for some object + */ +void wmlTokenSymKString (dststg, tok) + char *dststg; + WmlKeyWTokenPtr tok; + +{ + +WmlClassDefPtr clsobj; /* class object */ +WmlResourceDefPtr resobj; /* resource object */ +WmlCharSetDefPtr csobj; /* character set object */ +WmlEnumValueDefPtr esobj; /* enumeration value object */ +WmlChildDefPtr chobj; /* child object */ + + +switch ( tok->class ) + { + case WmlTokenClassArgument: + resobj = (WmlResourceDefPtr) tok->objdef; + sprintf (dststg, "sym_k_%s_arg", resobj->tkname); + return; + case WmlTokenClassCharset: + csobj = (WmlCharSetDefPtr) tok->objdef; + sprintf (dststg, "sym_k_%s_charset", csobj->syndef->name); + return; + case WmlTokenClassEnumval: + esobj = (WmlEnumValueDefPtr) tok->objdef; + sprintf (dststg, "sym_k_%s_enumval", esobj->syndef->name); + return; + case WmlTokenClassKeyword: + strcpy (dststg, "0"); + return; + case WmlTokenClassReason: + resobj = (WmlResourceDefPtr) tok->objdef; + sprintf (dststg, "sym_k_%s_reason", resobj->tkname); + return; + case WmlTokenClassReserved: + strcpy (dststg, "0"); + return; + case WmlTokenClassClass: + clsobj = (WmlClassDefPtr) tok->objdef; + sprintf (dststg, "sym_k_%s_object", clsobj->tkname); + return; + case WmlTokenClassChild: + chobj = (WmlChildDefPtr) tok->objdef; + sprintf (dststg, "sym_k_%s_child", chobj->tkname); + return; + } + +} + + + +/* + * Routine to return the string for a token number, tkn_k_num_... + */ +void wmlTokenTokenString (dststg, tok) + char *dststg; + WmlKeyWTokenPtr tok; + +{ + +WmlGrammarTokenPtr grtok; /* grammar token */ + + +switch ( tok->class ) + { + case WmlTokenClassArgument: + strcpy (dststg, "ARGUMENT_NAME"); + return; + case WmlTokenClassCharset: + strcpy (dststg, "CHARSET_NAME"); + return; + case WmlTokenClassEnumval: + strcpy (dststg, "ENUMVAL_NAME"); + return; + case WmlTokenClassReason: + strcpy (dststg, "REASON_NAME"); + return; + case WmlTokenClassKeyword: + case WmlTokenClassReserved: + grtok = (WmlGrammarTokenPtr) tok->objdef; + strcpy (dststg, grtok->token); + return; + case WmlTokenClassClass: + strcpy (dststg, "CLASS_NAME"); + return; + case WmlTokenClassChild: + strcpy (dststg, "CHILD_NAME"); + return; + } + +} + + + +/* + * routine to output UilTokName.h + */ + +void wmlOutputUilTokName () + +{ + +char *canned1 = +"/*\tToken name table */\n\ +static char *tok_token_name_table_vec[] = \n\ + {\n"; + +char *canned2 = +" };\n\ +externaldef(uil_sym_glbl) char **tok_token_name_table =\n\ +\t\ttok_token_name_table_vec;\n\n\ +/*\tNumber of entries in table */\n\ +externaldef(uil_sym_glbl) int tok_num_tokens = %d;\n"; + + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlGrammarTokenPtr grtok; /* current grammar token */ + + +/* + * Open the output file. + */ +outfil = fopen ("UilTokName.h", "w"); +if ( outfil == NULL ) + { + printf ("\nCouldn't open UilTokName.h"); + return; + } +fprintf (outfil, canned_warn); +fprintf (outfil, canned1); + +/* + * Print the token name entries + * Note: vector size is max_val + 1 for zeroth token + */ +for ( ndx=0 ; ndxtoken); + else + fprintf (outfil, " \"UNKNOWN_TOKEN\",\n"); + } + +/* + * close the output file + */ +fprintf (outfil, canned2, grtok_max_val+1); +printf ("\nCreated UilTokName.h"); +fclose (outfil); + +} diff --git a/tools/wml/wmloutmm.c b/tools/wml/wmloutmm.c index 84a97bb..dc8ec09 100644 --- a/tools/wml/wmloutmm.c +++ b/tools/wml/wmloutmm.c @@ -209,9 +209,9 @@ int ctlndx; /* to access ordered vector */ /* * Write out header information */ -fprintf (outfil, canned1); +fprintf (outfil, "%s", canned1); fprintf (outfil, "%s\n", name); -fprintf (outfil, canned2); +fprintf (outfil, "%s", canned2); /* * Alphabetize the controls, reason, and argument lists @@ -264,7 +264,7 @@ while ( ctlref != NULL ) rsnndx = 0; ctlndx = 0; if ( mm_ctl_ptr->cnt == 0 ) - fprintf (outfil, "No children are supported"); + fprintf (outfil, "%s", "No children are supported"); while ( rsnndxcnt || ctlndxcnt ) { if ( ctlndx < mm_ctl_ptr->cnt ) @@ -275,7 +275,7 @@ while ( rsnndxcnt || ctlndxcnt ) ctlndx += 1; } else - fprintf (outfil, "@"); + fprintf (outfil, "%s", "@"); if ( rsnndx < mm_rsn_ptr->cnt ) { @@ -285,9 +285,9 @@ while ( rsnndxcnt || ctlndxcnt ) rsnndx += 1; } else - fprintf (outfil, "\n"); + fprintf (outfil, "%s", "\n"); } -fprintf (outfil, canned3); +fprintf (outfil, "%s", canned3); /* * Write out the argument table @@ -319,11 +319,11 @@ while ( argndx < mm_arg_ptr->cnt ) argref->act_resource->syndef->dflt); } else - fprintf (outfil, " \n"); + fprintf (outfil, "%s", " \n"); } argndx += 1; } -fprintf (outfil, canned4); +fprintf (outfil, "%s", canned4); } diff --git a/tools/wml/wmloutmm.c.format-security b/tools/wml/wmloutmm.c.format-security new file mode 100644 index 0000000..84a97bb --- /dev/null +++ b/tools/wml/wmloutmm.c.format-security @@ -0,0 +1,331 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA +*/ +/* + * HISTORY +*/ +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$XConsortium: wmloutmm.c /main/9 1995/08/29 11:10:59 drk $" +#endif +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + + +/* +* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + +/* + * This module contains routines responsible for writing the .mm files + * produced by WML. All files are written into the current directory. + * + * Input: + * The resolved objects + * + * Output: + * wml-uil.mm + * + */ + + +#include "wml.h" + +#if defined(__STDC__) +#include +#endif +#include + + +/* + * Routines used only in this module + */ +void wmlOutputWmlUilMm (); +void wmlOutputWmlUilMmClass (); + +/* + * globals + */ +int tabno = 1; /* table number */ + +/* + * lists re-used repeatedly to order lists for printing + */ +DynamicHandleListDef mm_arg; +DynamicHandleListDefPtr mm_arg_ptr = &mm_arg; +DynamicHandleListDef mm_rsn; +DynamicHandleListDefPtr mm_rsn_ptr = &mm_rsn; +DynamicHandleListDef mm_ctl; +DynamicHandleListDefPtr mm_ctl_ptr = &mm_ctl; + + + +/* + * Output control routine, which simply outputs each .mm file in turn. + */ + +void wmlOutputMmFiles () + +{ + +wmlOutputWmlUilMm (); + +} + + + +/* + * Routine to write out wml-uil.mm + * + * This .mm file contains the tables which are to be included as an + * appendix to the Uil manual. The tables give the arguments with their + * default values, reasons, constraints, and controls for each class + * in the class vectors. + */ + +void wmlOutputWmlUilMm () + +{ + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlClassDefPtr clsobj; /* class object */ + + + +/* + * Open the output file. Write the canned header stuff + */ +outfil = fopen ("wml-uil.mm", "w"); +if ( outfil == NULL ) + { + printf ("\nCouldn't open wml-uil.mm"); + return; + } + +/* + * Initialize order lists for the tables. + */ +wmlInitHList (mm_arg_ptr, 200, TRUE); +wmlInitHList (mm_rsn_ptr, 200, TRUE); +wmlInitHList (mm_ctl_ptr, 200, TRUE); + +/* + * Write out a table for each class, for both widget and gadget variants + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + wmlOutputWmlUilMmClass (outfil, clsobj, clsobj->syndef->name); + } + +/* + * close the output file + */ +printf ("\nCreated wml-uil.mm"); +fclose (outfil); + +} + + + +/* + * Routine to write a table for a class entry + */ + +void wmlOutputWmlUilMmClass (outfil, clsobj, name) + FILE *outfil; + WmlClassDefPtr clsobj; + char *name; + +{ + +char *canned1 = +".bp\n\ +.ps 12\n"; + +char *canned2 = +".ps 10\n\ +.vs 12\n\ +.LP\n\ +.TS H\n\ +tab(@);\n\ +lB lB\n\ +l l.\n\ +_\n\ +.sp 6p\n\ +Controls@Reasons\n\ +.sp 6p\n\ +_\n\ +.sp 6p\n\ +.TH\n"; + +char *canned3 = +".TE\n\ +.TS H\n\ +tab(@);\n\ +lB lB lB\n\ +l l l.\n\ +_\n\ +.sp 6p\n\ +UIL Argument Name@Argument Type@Default Value\n\ +.sp 6p\n\ +_\n\ +.sp 6p\n\ +.TH\n"; + +char *canned4 = +".TE\n"; + +WmlClassResDefPtr argref; /* current argument reference */ +WmlClassResDefPtr rsnref; /* current reason reference */ +WmlClassCtrlDefPtr ctlref; /* current controls reference */ +int argndx; /* to access ordered vector */ +int rsnndx; /* to access ordered vector */ +int ctlndx; /* to access ordered vector */ + + +/* + * Write out header information + */ +fprintf (outfil, canned1); +fprintf (outfil, "%s\n", name); +fprintf (outfil, canned2); + +/* + * Alphabetize the controls, reason, and argument lists + */ +wmlClearHList (mm_arg_ptr); +wmlClearHList (mm_rsn_ptr); +wmlClearHList (mm_ctl_ptr); + +argref = clsobj->arguments; +while ( argref!= NULL ) + { + while ( argref != NULL && argref->exclude == WmlAttributeTrue ) + argref = argref->next; + if ( argref != NULL ) + { + wmlInsertInHList (mm_arg_ptr, + argref->act_resource->syndef->name, + (ObjectPtr)argref); + argref = argref->next; + } + } + +rsnref = clsobj->reasons; +while ( rsnref!=NULL ) + { + while ( rsnref != NULL && rsnref->exclude == WmlAttributeTrue ) + rsnref = rsnref->next; + if ( rsnref != NULL ) + { + wmlInsertInHList (mm_rsn_ptr, + rsnref->act_resource->syndef->name, + (ObjectPtr)rsnref); + + rsnref = rsnref->next; + } + } + +ctlref = clsobj->controls; +while ( ctlref != NULL ) + { + wmlInsertInHList (mm_ctl_ptr, + ctlref->ctrl->syndef->name, + (ObjectPtr)ctlref); + ctlref = ctlref->next; + } + +/* + * Write out the controls and reason table. + */ +rsnndx = 0; +ctlndx = 0; +if ( mm_ctl_ptr->cnt == 0 ) + fprintf (outfil, "No children are supported"); +while ( rsnndxcnt || ctlndxcnt ) + { + if ( ctlndx < mm_ctl_ptr->cnt ) + { + ctlref = (WmlClassCtrlDefPtr) mm_ctl_ptr->hvec[ctlndx].objptr; + fprintf (outfil, "%s@", + ctlref->ctrl->syndef->name); + ctlndx += 1; + } + else + fprintf (outfil, "@"); + + if ( rsnndx < mm_rsn_ptr->cnt ) + { + rsnref = (WmlClassResDefPtr) mm_rsn_ptr->hvec[rsnndx].objptr; + fprintf (outfil, "%s\n", + rsnref->act_resource->syndef->name); + rsnndx += 1; + } + else + fprintf (outfil, "\n"); + } +fprintf (outfil, canned3); + +/* + * Write out the argument table + */ +argndx = 0; +while ( argndx < mm_arg_ptr->cnt ) + { + argref = (WmlClassResDefPtr) mm_arg_ptr->hvec[argndx].objptr; + fprintf (outfil, "%s@%s@", + argref->act_resource->syndef->name, + argref->act_resource->dtype_def->syndef->name); + if ( argref->dflt != NULL ) + { + if ( strchr(argref->dflt,' ') != 0 ) + fprintf (outfil, "T{\n%s\nT}\n", + argref->dflt); + else + fprintf (outfil, "%s\n", + argref->dflt); + } + else + { + if (argref->act_resource->syndef->dflt != NULL) { + if ( strchr(argref->act_resource->syndef->dflt,' ') != 0 ) + fprintf (outfil, "T{\n%s\nT}\n", + argref->act_resource->syndef->dflt); + else + fprintf (outfil, "%s\n", + argref->act_resource->syndef->dflt); + } + else + fprintf (outfil, " \n"); + } + argndx += 1; + } +fprintf (outfil, canned4); + +} + + + diff --git a/tools/wml/wmlresolve.c b/tools/wml/wmlresolve.c index 464ef29..3b8642c 100644 --- a/tools/wml/wmlresolve.c +++ b/tools/wml/wmlresolve.c @@ -1340,7 +1340,7 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) /* * close the output file */ -fprintf (outfil, "\n\n"); +fprintf (outfil, "%s", "\n\n"); printf ("\nCreated report file wml.report"); fclose (outfil); @@ -1369,14 +1369,14 @@ fprintf (outfil, "\n\n\nClass %s:", synobj->name); switch ( synobj->type ) { case WmlClassTypeMetaclass: - fprintf (outfil, "\n Type: Metaclass\t"); + fprintf (outfil, "%s", "\n Type: Metaclass\t"); if ( synobj->superclass != NULL ) fprintf (outfil, "Superclass: %s\t", synobj->superclass); if ( synobj->parentclass != NULL ) fprintf (outfil, "Parentclass: %s\t", synobj->parentclass); break; case WmlClassTypeWidget: - fprintf (outfil, "\n Type: Widget\t"); + fprintf (outfil, "%s", "\n Type: Widget\t"); if ( synobj->superclass != NULL ) fprintf (outfil, "Superclass: %s\t", synobj->superclass); if ( synobj->parentclass != NULL ) @@ -1388,7 +1388,7 @@ switch ( synobj->type ) fprintf (outfil, "Convenience function: %s", synobj->convfunc); break; case WmlClassTypeGadget: - fprintf (outfil, "\n Type: Gadget\t"); + fprintf (outfil, "%s", "\n Type: Gadget\t"); if ( synobj->superclass != NULL ) fprintf (outfil, "Superclass: %s\t", synobj->superclass); if ( synobj->parentclass != NULL ) @@ -1414,19 +1414,19 @@ if ( clsobj->nondialog != NULL ) * is intended to match the way resources are printed in the toolkit manual, * so that checking is as easy as possible. */ -fprintf (outfil, "\n Arguments:"); +fprintf (outfil, "%s", "\n Arguments:"); wmlResolvePrintClassArgs (outfil, clsobj); /* * Print the reasons valid in the class */ -fprintf (outfil, "\n Reasons:"); +fprintf (outfil, "%s", "\n Reasons:"); wmlResolvePrintClassReasons (outfil, clsobj); /* * Print the controls valid in the class */ -fprintf (outfil, "\n Controls:"); +fprintf (outfil, "%s", "\n Controls:"); for ( ndx=0 ; ndxcnt ; ndx++ ) { ctrlobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; @@ -1512,10 +1512,10 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) switch ( resref->exclude ) { case WmlAttributeTrue: - fprintf (outfil, "\n\tExclude = True;"); + fprintf (outfil, "%s", "\n\tExclude = True;"); break; case WmlAttributeFalse: - fprintf (outfil, "\n\tExclude = False;"); + fprintf (outfil, "%s", "\n\tExclude = False;"); break; } if ( resref->dflt != NULL ) @@ -1558,10 +1558,10 @@ if ( constr ) switch ( resref->exclude ) { case WmlAttributeTrue: - fprintf (outfil, "\n\tExclude = True;"); + fprintf (outfil, "%s", "\n\tExclude = True;"); break; case WmlAttributeFalse: - fprintf (outfil, "\n\tExclude = False;"); + fprintf (outfil, "%s", "\n\tExclude = False;"); break; } if ( resref->dflt != NULL ) @@ -1632,10 +1632,10 @@ for ( ndx=0 ; ndxcnt ; ndx++ ) switch ( resref->exclude ) { case WmlAttributeTrue: - fprintf (outfil, "\n\tExclude = True;"); + fprintf (outfil, "%s", "\n\tExclude = True;"); break; case WmlAttributeFalse: - fprintf (outfil, "\n\tExclude = False;"); + fprintf (outfil, "%s", "\n\tExclude = False;"); break; } resobj->ref_ptr = NULL; diff --git a/tools/wml/wmlresolve.c.format-security b/tools/wml/wmlresolve.c.format-security new file mode 100644 index 0000000..464ef29 --- /dev/null +++ b/tools/wml/wmlresolve.c.format-security @@ -0,0 +1,1828 @@ +/* + * Motif + * + * Copyright (c) 1987-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA +*/ +/* + * HISTORY +*/ +#ifdef REV_INFO +#ifndef lint +static char rcsid[] = "$XConsortium: wmlresolve.c /main/9 1995/08/29 11:11:05 drk $" +#endif +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + + +/* +* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */ + +/* + * This module contains all routines which perform semantic analysis of + * the parsed WML specification. It is responsible for building all + * ordered structures which can be directly translated into literal + * code values for the various .h files. It is responsible for performing + * inheritance of resources for all classes. + * + * Input: + * the ordered list of syntactic objects in wml_synobj_ptr + * + * Output: + * + */ + + +#include "wml.h" + +#if defined(__STDC__) +#include +#endif +#include + +/* + * Routines used only in this module + */ +void wmlResolveGenerateSymK (); +void wmlResolveValidateClass (); +void wmlResolvePrintReport (); + +void wmlResolveSymKDataType (); +void wmlResolveSymKChild (); +void wmlResolveSymKEnumVal (); +void wmlResolveSymKEnumSet (); +void wmlResolveSymKReason (); +void wmlResolveSymKArgument (); +void wmlResolveSymKRelated (); +void wmlResolveSymKClass (); +void wmlResolveSymKCtrlList (); +void wmlResolveSymKCharSet (); + +void wmlResolveClassInherit (); +void wmlResolveClearRefPointers (); +void wmlResolveInitRefObj (); +void wmlResolveInitChildRefObj (); + +void wmlResolvePrintClass (); +void wmlResolvePrintClassArgs (); +void wmlResolvePrintClassReasons (); + +ObjectPtr wmlResolveFindObject (); +void wmlIssueReferenceError (); +void wmlIssueIllegalReferenceError (); +void wmlIssueError (); + + + +/* + * The control routine for semantic analysis. It calls the various phases. + */ + +void wmlResolveDescriptors () + +{ + +/* + * Perform the code assignment pass. This results in assignment of sym_k_... + * codes to all entities. Also, all objects and cross-linking are validated. + */ +wmlResolveGenerateSymK (); +printf ("\nInitial validation and reference resolution complete"); + +/* + * Perform class inheritance and validation + */ +wmlResolveValidateClass (); +printf ("\nClass validation and inheritance complete"); + +/* + * Print a report + */ +if ( wml_err_count > 0 ) return; +wmlResolvePrintReport (); + +} + + + +/* + * Routine to linearize and assign sym_k... literals for objects. Simply + * a dispatching routine. + */ + +void wmlResolveGenerateSymK () + +{ + +/* + * Process the datatype objects + */ +wmlResolveSymKDataType (); + +/* + * Process the enumeration value and enumeration sets + */ +wmlResolveSymKEnumVal (); +wmlResolveSymKEnumSet (); + +/* + * Process the resources, producing argument and reason vectors. + */ +wmlResolveSymKReason (); +wmlResolveSymKArgument (); + +/* + * Bind related arguments + */ +wmlResolveSymKRelated (); + +/* + * Process the class definitions + */ +wmlResolveSymKClass (); + +/* + * Process the controls list definitions + */ +wmlResolveSymKCtrlList (); + +/* + * Process the charset objects + */ +wmlResolveSymKCharSet (); + +/* Process the child definitions. */ +wmlResolveSymKChild(); + +} + + + +/* + * Routine to linearize data types + * + * - Generate the wml_obj_datatype... vector of resolved data type objects, + * ordered lexicographically. + * Do name processing, and acquire links to any other objects named in + * the syntactic descriptor. + */ + +void wmlResolveSymKDataType () + +{ + +WmlSynDataTypeDefPtr cursyn; /* current syntactic object */ +WmlDataTypeDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each datatype object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_datatype_ptr, 50, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynDataTypeDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlDataTypeDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlDataTypeDefPtr) malloc (sizeof(WmlDataTypeDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + if ( cursyn->int_lit != NULL ) + newobj->tkname = cursyn->int_lit; + else + newobj->tkname = cursyn->name; + wmlInsertInHList (wml_obj_datatype_ptr, newobj->tkname, (ObjectPtr)newobj); + +/* + * Validate any object references in the syntactic object + */ + + } + +} + + +/* + * Routine to linearize children + * + * - Generate the wml_obj_child... vector of resolved child objects, + * ordered lexicographically. Assign sym_k_... values while doing so. + * Link child to its class. + */ + +void wmlResolveSymKChild () + +{ + +WmlSynChildDefPtr cursyn; /* current syntactic object */ +WmlChildDefPtr newobj; /* new resolved object */ +int code; /* assigned sym_k code value */ +int ndx; /* loop index */ + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each child object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_child_ptr, 50, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynChildDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlChildDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlChildDefPtr) malloc (sizeof(WmlChildDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + newobj->tkname = cursyn->name; + wmlInsertInHList (wml_obj_child_ptr, newobj->tkname, (ObjectPtr)newobj); + +/* Link class to the resolved object. */ +if (cursyn->class != NULL) + newobj->class = (WmlClassDefPtr) + wmlResolveFindObject(cursyn->class, WmlClassDefValid, cursyn->name); + } + +/* + * All objects are in the vector. The order is the code order, so + * process it again and assign codes to each object + */ +code = 1; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + } + +} + + + +/* + * Routine to linearize and assign sym_k values to enumeration values + * + * - Generate the wml_obj_datatype... vector of resolved data type objects, + * ordered lexicographically. No sym_k_... values are needed for + * enumeration values, so don't assign any. + */ + +void wmlResolveSymKEnumVal () + +{ + +WmlSynEnumSetDefPtr cures; /* current enumeration set */ +WmlSynEnumSetValDefPtr curesv; /* current enum set value */ +WmlSynEnumValueDefPtr cursyn; /* current syntactic object */ +WmlEnumValueDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ +int code; /* sym_k_... code */ + + +/* + * Perform defaulting. Process all the enumeration sets, and define a + * syntactic object for every enumeration value named in an enumeration set + * which has no syntactic entry. If there is an error in a name, then + * this error won't be detected until we attempt to compile the output .h files. + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cures = (WmlSynEnumSetDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cures->validation != WmlEnumSetDefValid ) continue; + for (curesv=cures->values ; curesv!=NULL ; curesv=curesv->next) + if ( wmlFindInHList(wml_synobj_ptr,curesv->name) < 0 ) + wmlCreateEnumValue (curesv->name); + } + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each enumeration value object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_enumval_ptr, 50, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynEnumValueDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlEnumValueDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlEnumValueDefPtr) malloc (sizeof(WmlEnumValueDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + wmlInsertInHList (wml_obj_enumval_ptr, cursyn->name, (ObjectPtr)newobj); + } + +/* + * All objects are in the vector. That order is the code order, so + * process it again and assign codes to each object + */ +code = 1; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + } + +} + + + +/* + * Routine to linearize and assign sym_k values to enumeration sets + * + * - Generate the wml_obj_datatype... vector of resolved data type objects, + * ordered lexicographically. No sym_k_... values are needed for + * enumeration values, so don't assign any. + */ + +void wmlResolveSymKEnumSet () + +{ + +WmlSynEnumSetDefPtr cursyn; /* current syntactic object */ +WmlEnumSetDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ +int code; /* sym_k_... code */ +WmlSynEnumSetValDefPtr esvelm; /* current syntactic list element */ +WmlEnumValueDefPtr evobj; /* current enumeration value */ +WmlEnumSetValDefPtr esvobj; /* current list element */ + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each enumeration set object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_enumset_ptr, 20, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynEnumSetDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlEnumSetDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlEnumSetDefPtr) malloc (sizeof(WmlEnumSetDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + newobj->tkname = cursyn->name; + newobj->dtype_def = (WmlDataTypeDefPtr) + wmlResolveFindObject (cursyn->datatype, + WmlDataTypeDefValid, + cursyn->name); + wmlInsertInHList (wml_obj_enumset_ptr, newobj->tkname, (ObjectPtr)newobj); + } + +/* + * All objects are in the vector. That order is the code order, so + * process it again and assign codes to each object. Simultaneously construct + * a vector of resolved enumeration values, and count them. + */ +code = 1; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + +/* + * Validate and construct a resolved enumeration value list + */ + cursyn = newobj->syndef; + newobj->values_cnt = 0; + newobj->values = NULL; + for ( esvelm=cursyn->values ; esvelm!=NULL ; esvelm=esvelm->next ) + { + evobj = (WmlEnumValueDefPtr) + wmlResolveFindObject (esvelm->name, + WmlEnumValueDefValid, + cursyn->name); + if ( evobj == NULL ) continue; + esvobj = (WmlEnumSetValDefPtr) malloc (sizeof(WmlEnumSetValDef)); + esvobj->value = evobj; + esvobj->next = newobj->values; + newobj->values = esvobj; + newobj->values_cnt += 1; + } + } + +} + + + +/* + * Routine to linearize and assign sym_k values to reasons. + * + * - Generate the wml_obj_reason... vector of resolved reason objects, + * ordered lexicographically. Assign a sym_k_... value as this is done. + * Do name processing, and acquire links to any other objects named in + * the syntactic descriptor. + */ + +void wmlResolveSymKReason () + +{ + +WmlSynResourceDefPtr cursyn; /* current syntactic object */ +WmlResourceDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ +int code; /* assigned sym_k code value */ +char errmsg[300]; + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each reason resource object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_reason_ptr, 100, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynResourceDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlResourceDefValid ) continue; + if ( cursyn->type != WmlResourceTypeReason ) continue; + newobj = (WmlResourceDefPtr) malloc (sizeof(WmlResourceDef)); + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + if ( cursyn->int_lit != NULL ) + newobj->tkname = cursyn->int_lit; + else + newobj->tkname = cursyn->name; + newobj->dtype_def = NULL; + newobj->enumset_def = NULL; + newobj->related_code = 0; + wmlInsertInHList (wml_obj_reason_ptr, newobj->tkname, (ObjectPtr)newobj); + +/* + * Validate any object references in the syntactic object + * Reason can't bind to some objects. + */ + if ( cursyn->datatype != NULL ) + wmlIssueIllegalReferenceError (cursyn->name, "DataType"); + + } + +/* + * All objects are in the vector. That order is the code order, so + * process it again and assign codes to each object + */ +code = 1; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + } + +} + + + +/* + * Routine to linearize and assign sym_k values to arguments. + * + * - Generate the wml_obj_arg... vector of resovled reason objects, + * ordered lexicographically. Assign a sym_k_... values while doing so. + * validate the data type for each argument, and link it to its data type + * object. + * Do name processing, and acquire links to any other objects named in + * the syntactic descriptor. + */ + +void wmlResolveSymKArgument () + +{ + + +WmlSynResourceDefPtr cursyn; /* current syntactic object */ +WmlResourceDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ +int code; /* assigned sym_k code value */ +char errmsg[300]; + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each reason resource object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_arg_ptr, 500, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynResourceDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlResourceDefValid ) continue; + if ( cursyn->type == WmlResourceTypeReason ) continue; + newobj = (WmlResourceDefPtr) malloc (sizeof(WmlResourceDef)); + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + if ( cursyn->int_lit != NULL ) + newobj->tkname = cursyn->int_lit; + else + newobj->tkname = cursyn->name; + newobj->related_code = 0; + newobj->enumset_def = NULL; + wmlInsertInHList (wml_obj_arg_ptr, newobj->tkname, (ObjectPtr)newobj); + +/* + * Validate any object references in the syntactic object + */ + newobj->dtype_def = (WmlDataTypeDefPtr) + wmlResolveFindObject (cursyn->datatype, + WmlDataTypeDefValid, + cursyn->name); + if ( cursyn->enumset != NULL ) + newobj->enumset_def = (WmlEnumSetDefPtr) + wmlResolveFindObject (cursyn->enumset, + WmlEnumSetDefValid, + cursyn->name); + + } + +/* + * All objects are in the vector. The order is the code order, so + * process it again and assign codes to each object + */ +code = 1; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + } + +} + + + +/* + * Routine to resolve related argument references. + * + * Search the argument vector for any argument with its related + * argument set. Find the related argument, and bind the relation. + * The binding only goes one way. + */ + +void wmlResolveSymKRelated () + +{ + +WmlResourceDefPtr srcobj; /* object with related reference */ +WmlResourceDefPtr dstobj; /* other object in binding */ +WmlSynResourceDefPtr srcsynobj; /* source syntactic object */ +int ndx; /* loop index */ + + +/* + * Scan all arguments for related argument bindings. + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + srcobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + srcsynobj = srcobj->syndef; + if ( srcsynobj->related != NULL ) + { + dstobj = (WmlResourceDefPtr) + wmlResolveFindObject (srcsynobj->related, + WmlResourceDefValid, + srcsynobj->name); + if ( dstobj != NULL ) + srcobj->related_code = dstobj->sym_code; + } + } +} + + + +/* + * Routine to linearize and assign sym_k values to classes + * + * There are two linearizations of classes: + * - all classes in wml_obj_allclass... + * - all widgets and gadgets in wml_obj_class... + * Create and linearize all class objects into these vectors. Assign sym_k + * codes. Link all subclasses to their superclasses. Perform name processing + * and link to any other named object. + * + * Resources are not inherited and linked at this time. + */ + +void wmlResolveSymKClass () + +{ + +WmlSynClassDefPtr cursyn; /* current syntactic object */ +WmlClassDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ +int code; /* assigned sym_k code value */ +char errmsg[300]; + + +/* + * Initialize the object vectors. Then process the syntactic vector, + * processing each class object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_allclass_ptr, 200, TRUE); +wmlInitHList (wml_obj_class_ptr, 200, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynClassDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlClassDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlClassDefPtr) malloc (sizeof(WmlClassDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + newobj->superclass = NULL; + newobj->parentclass = NULL; + if ( cursyn->int_lit != NULL ) + newobj->tkname = cursyn->int_lit; + else + newobj->tkname = cursyn->name; + newobj->inherit_done = FALSE; + newobj->arguments = NULL; + newobj->reasons = NULL; + newobj->controls = NULL; + newobj->children = NULL; + newobj->variant = NULL; + newobj->nondialog = NULL; + newobj->ctrlmapto = NULL; + switch ( cursyn->type ) + { + case WmlClassTypeMetaclass: + wmlInsertInHList + (wml_obj_allclass_ptr, newobj->tkname, (ObjectPtr)newobj); + break; + case WmlClassTypeGadget: + case WmlClassTypeWidget: + wmlInsertInHList + (wml_obj_allclass_ptr, newobj->tkname, (ObjectPtr)newobj); + wmlInsertInHList + (wml_obj_class_ptr, newobj->tkname, (ObjectPtr)newobj); + break; + } + +/* + * Require a convenience function name + */ + if ( cursyn->type != WmlClassTypeMetaclass ) + if ( cursyn->convfunc == NULL ) + { + sprintf (errmsg, "Class %s does not have a convenience function", + cursyn->name); + wmlIssueError (errmsg); + } + +/* + * Validate any object references in the syntactic object + */ + if ( cursyn->ctrlmapto != NULL ) + newobj->ctrlmapto = (WmlResourceDefPtr) + wmlResolveFindObject (cursyn->ctrlmapto, + WmlResourceDefValid, + cursyn->name); + + } + +/* + * All objects are in the vector. That order is the code order, so + * process it again and assign codes to each object + */ +code = 1; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + } + +} + + + +/* + * Routine to validate controls lists + * + * Construct and linearize resolved controls lists. The linearized list + * is used to resolve references. + */ + +void wmlResolveSymKCtrlList () + +{ + +WmlSynCtrlListDefPtr cursyn; /* current syntactic object */ +WmlCtrlListDefPtr newobj; /* new resolved object */ +WmlSynClassCtrlDefPtr refptr; /* current controls reference */ +WmlClassCtrlDefPtr ctrlobj; /* resolved control reference */ +WmlClassDefPtr classobj; /* the controlled class */ +int ndx; /* loop index */ + + +/* + * Process each control list. Construct a resolved control list for each + */ +wmlInitHList (wml_obj_ctrlist_ptr, 20, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynCtrlListDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlCtrlListDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlCtrlListDefPtr) malloc (sizeof(WmlCtrlListDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + newobj->controls = NULL; + wmlInsertInHList (wml_obj_ctrlist_ptr, cursyn->name, (ObjectPtr)newobj); + +/* + * Validate and construct a resolved controls reference list. + */ + for ( refptr=cursyn->controls ; refptr!=NULL ; refptr=refptr->next ) + { + classobj = (WmlClassDefPtr) + wmlResolveFindObject (refptr->name, + WmlClassDefValid, + cursyn->name); + if ( classobj == NULL ) continue; + ctrlobj = (WmlClassCtrlDefPtr) malloc (sizeof(WmlClassCtrlDef)); + ctrlobj->next = newobj->controls; + newobj->controls = ctrlobj; + ctrlobj->ctrl = classobj; + } + } + +} + + + +/* + * Routine to linearize and assign sym_k values to character sets + * + * - Generate the wml_obj_charset... vector of resolved data type objects, + * ordered lexicographically. Assign a sym_k... value as this is done. + * Do name processing, and acquire links to any other objects named in + * the syntactic descriptor. + */ + +void wmlResolveSymKCharSet () + +{ + +WmlSynCharSetDefPtr cursyn; /* current syntactic object */ +WmlCharSetDefPtr newobj; /* new resolved object */ +int ndx; /* loop index */ +int code; /* assigned sym_k code value */ +char errmsg[300]; + + +/* + * Initialize the object vector. Then process the syntactic vector, + * processing each charset object encountered (the vector is ordered). + * create and append a resolved object for each one encountered. This + * will be ordered as well. + */ +wmlInitHList (wml_obj_charset_ptr, 50, TRUE); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + cursyn = (WmlSynCharSetDefPtr) wml_synobj_ptr->hvec[ndx].objptr; + if ( cursyn->validation != WmlCharSetDefValid ) continue; + +/* + * Create and initialize new object. Append to resolved object vector. + */ + newobj = (WmlCharSetDefPtr) malloc (sizeof(WmlCharSetDef)); + newobj->syndef = cursyn; + cursyn->rslvdef = newobj; + if ( cursyn->int_lit != NULL ) + newobj->tkname = cursyn->int_lit; + else + newobj->tkname = cursyn->name; + wmlInsertInHList (wml_obj_charset_ptr, newobj->tkname, (ObjectPtr)newobj); + +/* + * Parsing direction defaults to writing direction if unspecified + */ + if ( cursyn->parsedirection == WmlAttributeUnspecified ) + cursyn->parsedirection = cursyn->direction; + +/* + * Require StandardsName attribute for character set + */ + if ( cursyn->xms_name == NULL ) + { + sprintf (errmsg, "CharacterSet %s does not have a StandardsName", + cursyn->name); + wmlIssueError (errmsg); + } + + } + +/* + * All objects are in the vector. That order is the code order, so + * process it again and assign codes to each object. We start at code + * 2 since 1 is reserved for sym_k_userdefined_charset + */ +code = 2; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + newobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr; + newobj->sym_code = code; + code += 1; + } + +} + + + +/* + * Routine to perform class inheritance and validation. + * + * This routine has two major phases: + * - Complete resolution of class references, and expand out + * controls list. + * - Perform inheritance of resources, partitioning them into + * into arguments and reasons. When complete, the class has + * a list of all its resources, including copies from a + * superclass and possibly a parentclass. + * Excluded resources remain in the list, and are simply marked. + */ + +void wmlResolveValidateClass () + +{ + +int ndx; /* loop index */ +int max; /* maximum code value */ +WmlClassDefPtr clsobj; /* current class object */ +WmlSynClassDefPtr synobj; /* syntactic class object */ +WmlClassDefPtr superobj; /* superclass */ +WmlClassDefPtr parentobj; /* parentclass */ +WmlClassDefPtr widgobj; /* gadget's widget class */ +WmlSynClassCtrlDefPtr refptr; /* current controls reference */ +WmlClassCtrlDefPtr ctrlobj; /* resolved control reference */ +int refndx; /* index in vector */ +WmlClassDefPtr refcls; /* referenced class object */ +WmlCtrlListDefPtr reflist; /* controls list object */ +WmlClassCtrlDefPtr listelem; /* control reference in list */ +char errmsg[300]; + + +/* + * Acquire the superclass pointer for each widget and gadget class + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr; + synobj = clsobj->syndef; + if ( synobj->superclass != NULL ) + { + superobj = (WmlClassDefPtr) + wmlResolveFindObject (synobj->superclass, + WmlClassDefValid, + synobj->name); + if ( superobj == NULL ) continue; + clsobj->superclass = superobj; + } + } + +/* + * Acquire the parentclass pointer (if one exists), + * for each widget and gadget class + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr; + synobj = clsobj->syndef; + if ( synobj->parentclass != NULL ) + { + parentobj = (WmlClassDefPtr) + wmlResolveFindObject (synobj->parentclass, + WmlClassDefValid, + synobj->name); + if ( parentobj == NULL ) continue; + clsobj->parentclass = parentobj; + } + } + +/* + * Link each gadget class with its widget class (both ways). + * Link any class with a non-dialog version to the non-dialog class. + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + synobj = clsobj->syndef; + if ( synobj->type == WmlClassTypeGadget ) + { + if ( synobj->widgetclass == NULL ) + { + sprintf (errmsg, "Gadget class %s has no widgetclass reference", + synobj->name); + wmlIssueError (errmsg); + } + else + { + widgobj = (WmlClassDefPtr) + wmlResolveFindObject + (synobj->widgetclass, + WmlClassDefValid, + synobj->name); + if ( widgobj != NULL ) + { + clsobj->variant = widgobj; + widgobj->variant = clsobj; + } + } + } + if ( synobj->dialog == TRUE ) + { + clsobj->nondialog = clsobj->superclass; + while ( clsobj->nondialog->syndef->dialog == TRUE ) + clsobj->nondialog = clsobj->nondialog->superclass; + } + else + if ( clsobj->superclass != NULL ) + { + synobj->dialog = clsobj->superclass->syndef->dialog; + clsobj->nondialog = clsobj->superclass->nondialog; + } + } + +/* + * Construct the list of resolved controls. Control lists are expanded + * in place. + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + synobj = clsobj->syndef; + for ( refptr=synobj->controls ; refptr!= NULL ; refptr=refptr->next ) + { + refndx = wmlFindInHList (wml_obj_class_ptr, refptr->name); + if ( refndx >= 0 ) + { + refcls = (WmlClassDefPtr) wml_obj_class_ptr->hvec[refndx].objptr; + ctrlobj = (WmlClassCtrlDefPtr) malloc (sizeof(WmlClassCtrlDef)); + ctrlobj->next = clsobj->controls; + clsobj->controls = ctrlobj; + ctrlobj->ctrl = refcls; + continue; + } + refndx = wmlFindInHList (wml_obj_ctrlist_ptr, refptr->name); + if ( refndx >= 0 ) + { + reflist = (WmlCtrlListDefPtr) + wml_obj_ctrlist_ptr->hvec[refndx].objptr; + for ( listelem=reflist->controls ; + listelem!=NULL ; + listelem=listelem->next) + { + ctrlobj = (WmlClassCtrlDefPtr) + malloc (sizeof(WmlClassCtrlDef)); + ctrlobj->next = clsobj->controls; + clsobj->controls = ctrlobj; + ctrlobj->ctrl = listelem->ctrl; + } + continue; + } + wmlIssueReferenceError (synobj->name, refptr->name); + continue; + } + } + +/* + * Perform resource inheritance for each class. This constructs the + * arguments and reasons reference vectors. + */ +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr; + wmlResolveClassInherit (clsobj); + } + +} + + + +/* + * Routine to perform resource inheritance for a class. + * + * This routine constructs the argument and reason resource and child reference + * vectors for a class. It first ensures the superclass (if any) has + * been inited. It then makes a copy of the superclass lists. It repeats this + * procedure for the parentclass (if any.) Finally, it + * merges in the resources from the syntactic object. It uses the + * resolved resource or child object to point to the matching reference object + * in the list being created as an aid to search doing overrides. This also + * detects whether a resource or child is already in the list (if so, it is + * assumed to be inherited). + */ + +void wmlResolveClassInherit (clsobj) + WmlClassDefPtr clsobj; + +{ + +WmlClassDefPtr superobj; /* superclass object */ +WmlClassDefPtr parentobj; /* parentclass object */ +int ndx; /* loop index */ +WmlResourceDefPtr resobj; /* current resource object */ +WmlClassResDefPtr refobj; /* current resource reference */ +WmlClassResDefPtr srcref; /* source of copy */ +WmlChildDefPtr childobj; /* current child object */ +WmlClassChildDefPtr crefobj; /* current child reference */ +WmlClassChildDefPtr csrcref; /* child source of copy */ +WmlSynClassDefPtr synobj; /* this class' syntactic object */ +WmlSynClassResDefPtr refptr; /* syntactic resource reference */ +WmlSynClassChildDefPtr crefptr; /* syntactic child reference */ + + +/* + * Done if inheritance previously performed. Ensure the superclass is + * done. + */ +if ( clsobj == NULL ) return; +if ( clsobj->inherit_done ) return; +superobj = clsobj->superclass; +wmlResolveClassInherit (superobj); +parentobj = clsobj->parentclass; +wmlResolveClassInherit (parentobj); +synobj = clsobj->syndef; + +/* + * Clear the active reference pointer in the resolved resource objects. + */ +wmlResolveClearRefPointers (); + +/* + * Copy the superclass resources, setting the reference pointer as we go. + */ +if ( superobj != NULL ) + { + for ( srcref=superobj->arguments ; srcref!=NULL ; srcref=srcref->next ) + { + refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef)); + refobj->next = clsobj->arguments; + clsobj->arguments = refobj; + wmlResolveInitRefObj (refobj, srcref); + } + for ( srcref=superobj->reasons ; srcref!=NULL ; srcref=srcref->next ) + { + refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef)); + refobj->next = clsobj->reasons; + clsobj->reasons = refobj; + wmlResolveInitRefObj (refobj, srcref); + } + for (csrcref = superobj->children ; csrcref!=NULL ; csrcref=csrcref->next) + { + crefobj = (WmlClassChildDefPtr) malloc (sizeof(WmlClassChildDef)); + crefobj->next = clsobj->children; + clsobj->children = crefobj; + wmlResolveInitChildRefObj (crefobj, csrcref); + } + } + +/* + * Copy the parentclass resources, setting the reference pointer as we go. + */ +if ( parentobj != NULL ) + { + for ( srcref=parentobj->arguments ; srcref!=NULL ; srcref=srcref->next ) + { + if (srcref->act_resource->ref_ptr == NULL) + { + refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef)); + refobj->next = clsobj->arguments; + clsobj->arguments = refobj; + wmlResolveInitRefObj (refobj, srcref); + } + } + for ( srcref=parentobj->reasons ; srcref!=NULL ; srcref=srcref->next ) + { + if (srcref->act_resource->ref_ptr == NULL) + { + refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef)); + refobj->next = clsobj->reasons; + clsobj->reasons = refobj; + wmlResolveInitRefObj (refobj, srcref); + } + } + for (csrcref = parentobj->children ; csrcref!=NULL ; csrcref=csrcref->next) + { + if (csrcref->act_child->ref_ptr == NULL) + { + crefobj = (WmlClassChildDefPtr) malloc (sizeof(WmlClassChildDef)); + crefobj->next = clsobj->children; + clsobj->children = crefobj; + wmlResolveInitChildRefObj (crefobj, csrcref); + } + } + } + +/* + * Process the resources belonging to this class. They may either be + * new resources, or override ones already in the list. Partition them + * into arguments and reasons. + */ +for ( refptr=synobj->resources ; refptr!=NULL ; refptr=refptr->next ) + { + resobj = (WmlResourceDefPtr) wmlResolveFindObject (refptr->name, + WmlResourceDefValid, + synobj->name); + if ( resobj == NULL ) continue; + + /* + * Acquire the resolved resource object, and the resource reference. + * New references are linked in to the proper list, and have their + * defaults set. + */ + if ( resobj->ref_ptr != NULL ) + refobj = resobj->ref_ptr; + else + { + refobj = (WmlClassResDefPtr) malloc (sizeof(WmlClassResDef)); + refobj->act_resource = resobj; + resobj->ref_ptr = refobj; + refobj->over_dtype = NULL; + refobj->dflt = NULL; + refobj->exclude = WmlAttributeUnspecified; + if ( resobj->syndef->type == WmlResourceTypeReason ) + { + refobj->next = clsobj->reasons; + clsobj->reasons = refobj; + } + else + { + refobj->next = clsobj->arguments; + clsobj->arguments = refobj; + } + } + + /* + * Override any values in the reference which are explicit in the + * syntactic reference. + */ + if ( refptr->type != NULL ) + refobj->over_dtype = (WmlDataTypeDefPtr) + wmlResolveFindObject (refptr->type, + WmlDataTypeDefValid, + synobj->name); + if ( refptr->dflt != NULL ) + refobj->dflt = refptr->dflt; + if ( refptr->exclude != WmlAttributeUnspecified ) + refobj->exclude = refptr->exclude; + } + +/* + * Process the children belonging to this class. + */ +for ( crefptr = synobj->children ; crefptr!=NULL ; crefptr = crefptr->next ) + { + childobj = (WmlChildDefPtr) wmlResolveFindObject (crefptr->name, + WmlChildDefValid, + synobj->name); + if ( childobj == NULL ) continue; + + /* + * Acquire the resolved child object, and the child reference. + * New references are linked in to the proper list, and have their + * defaults set. + */ + if ( childobj->ref_ptr != NULL ) + crefobj = childobj->ref_ptr; + else + { + crefobj = (WmlClassChildDefPtr) malloc (sizeof(WmlClassChildDef)); + crefobj->act_child = childobj; + childobj->ref_ptr = crefobj; + crefobj->next = clsobj->children; + clsobj->children = crefobj; + } + } + +/* + * inheritance complete + */ +clsobj->inherit_done = TRUE; + +} + + + +/* + * Routine to copy a resource reference + */ + +void wmlResolveInitRefObj (dstobj, srcobj) + WmlClassResDefPtr dstobj; + WmlClassResDefPtr srcobj; + +{ + +WmlResourceDefPtr resobj; + + +resobj = srcobj->act_resource; +dstobj->act_resource = resobj; +resobj->ref_ptr = dstobj; +dstobj->over_dtype = srcobj->over_dtype; +dstobj->dflt = srcobj->dflt; +dstobj->exclude = srcobj->exclude; + +} + + +/* + * Routine to copy a child reference + */ + +void wmlResolveInitChildRefObj (dstobj, srcobj) + WmlClassChildDefPtr dstobj; + WmlClassChildDefPtr srcobj; + +{ + +WmlChildDefPtr childobj; + +childobj = srcobj->act_child; +dstobj->act_child = childobj; +childobj->ref_ptr = dstobj; + +} + + + +/* + * Routine to print a report in a file. + * + * This routine dumps the developed database into the file 'wml.report' + */ + +void wmlResolvePrintReport () + +{ + +FILE *outfil; /* output file */ +int ndx; /* loop index */ +WmlClassDefPtr clsobj; /* current class */ + + +/* + * Open the output file. + */ +outfil = fopen ( "wml.report", "w"); +if ( outfil == NULL ) + { + printf ("\nCouldn't open wml.report"); + return; + } + +/* + * Go through all classes. Print basic information, then dump their + * resources. The main purpose of this report is to show the actual + * resources and controls for the class. + */ + +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + clsobj = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr; + wmlMarkReferencePointers (clsobj); + wmlResolvePrintClass (outfil, clsobj); + } + + +/* + * close the output file + */ +fprintf (outfil, "\n\n"); +printf ("\nCreated report file wml.report"); +fclose (outfil); + +} + + + +/* + * Print the information for a class + */ + +void wmlResolvePrintClass (outfil, clsobj) + FILE *outfil; + WmlClassDefPtr clsobj; + +{ + +int ndx; /* loop index */ +WmlSynClassDefPtr synobj; /* syntactic object */ +WmlClassCtrlDefPtr ctrlref; /* controls reference */ +WmlClassDefPtr ctrlobj; /* current class in control */ + + +synobj = clsobj->syndef; +fprintf (outfil, "\n\n\nClass %s:", synobj->name); +switch ( synobj->type ) + { + case WmlClassTypeMetaclass: + fprintf (outfil, "\n Type: Metaclass\t"); + if ( synobj->superclass != NULL ) + fprintf (outfil, "Superclass: %s\t", synobj->superclass); + if ( synobj->parentclass != NULL ) + fprintf (outfil, "Parentclass: %s\t", synobj->parentclass); + break; + case WmlClassTypeWidget: + fprintf (outfil, "\n Type: Widget\t"); + if ( synobj->superclass != NULL ) + fprintf (outfil, "Superclass: %s\t", synobj->superclass); + if ( synobj->parentclass != NULL ) + fprintf (outfil, "Parentclass: %s\t", synobj->parentclass); + if ( clsobj->variant != NULL ) + fprintf (outfil, "\n Associated gadget class: %s\t", + clsobj->variant->syndef->name); + if ( synobj->convfunc != NULL ) + fprintf (outfil, "Convenience function: %s", synobj->convfunc); + break; + case WmlClassTypeGadget: + fprintf (outfil, "\n Type: Gadget\t"); + if ( synobj->superclass != NULL ) + fprintf (outfil, "Superclass: %s\t", synobj->superclass); + if ( synobj->parentclass != NULL ) + fprintf (outfil, "Parentclass: %s\t", synobj->parentclass); + if ( clsobj->variant != NULL ) + fprintf (outfil, "\n Associated widget class: %s\t", + clsobj->variant->syndef->name); + if ( synobj->convfunc != NULL ) + fprintf (outfil, "Convenience function: %s", synobj->convfunc); + break; + } + +/* + * Print associated non-dialog class + */ +if ( clsobj->nondialog != NULL ) + fprintf (outfil, "\n DialogClass: True\tNon-dialog ancestor: %s\t", + clsobj->nondialog->syndef->name); + +/* + * Print the arguments valid in the class. First the new resources for the + * class are printed, then each ancestor's contribution is printed. This + * is intended to match the way resources are printed in the toolkit manual, + * so that checking is as easy as possible. + */ +fprintf (outfil, "\n Arguments:"); +wmlResolvePrintClassArgs (outfil, clsobj); + +/* + * Print the reasons valid in the class + */ +fprintf (outfil, "\n Reasons:"); +wmlResolvePrintClassReasons (outfil, clsobj); + +/* + * Print the controls valid in the class + */ +fprintf (outfil, "\n Controls:"); +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + ctrlobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr; + if ( ctrlobj->ref_ptr == NULL ) continue; + fprintf (outfil, "\n %s", ctrlobj->syndef->name); + } + +} + + + +/* + * Routine to print the arguments for a class + * + * This routine prints out the currently marked arguments which are + * present in this class. Each argument which is printed is remarked + * so that it won't be printed again. This routine first prints the + * superclass arguments, so that the printing order becomes the top-down + * inheritance order. + */ + +void wmlResolvePrintClassArgs (outfil, clsobj) + FILE *outfil; + WmlClassDefPtr clsobj; + +{ + +int prthdr = TRUE; /* print header line */ +int ndx; /* loop index */ +WmlSynClassDefPtr synobj; /* syntactic object */ +WmlClassResDefPtr resref; /* resource reference */ +int constr = FALSE; /* check for constraints */ +WmlResourceDefPtr resobj; /* current resource */ +WmlSynResourceDefPtr synres; /* syntactic resource object */ + + +/* + * Print the superclass arguments + */ +if ( clsobj->superclass != NULL ) + wmlResolvePrintClassArgs (outfil, clsobj->superclass); + +/* + * Print the parentclass arguments + */ +if ( clsobj->parentclass != NULL ) + wmlResolvePrintClassArgs (outfil, clsobj->parentclass); + +/* + * Print the arguments for this class. Unmark the reference so it won't + * be printed again. + */ +synobj = clsobj->syndef; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + resref = resobj->ref_ptr; + if ( resref == NULL ) continue; + if ( wmlResolveResIsMember(resobj,clsobj->arguments) == NULL ) continue; + synres = resobj->syndef; + switch ( synres->type ) + { + case WmlResourceTypeArgument: + case WmlResourceTypeSubResource: + break; + case WmlResourceTypeConstraint: + constr = TRUE; + break; + default: + continue; + break; + } + if ( prthdr ) + { + fprintf (outfil, "\n %s argument set:", synobj->name); + prthdr = FALSE; + } + + fprintf (outfil, "\n %s", synres->name); + fprintf (outfil, "\n\tType = %s", resobj->dtype_def->syndef->name); + if ( strcmp(synres->name,synres->resliteral) != 0 ) + fprintf (outfil, "\tResourceLiteral = %s", synres->resliteral); + switch ( resref->exclude ) + { + case WmlAttributeTrue: + fprintf (outfil, "\n\tExclude = True;"); + break; + case WmlAttributeFalse: + fprintf (outfil, "\n\tExclude = False;"); + break; + } + if ( resref->dflt != NULL ) + fprintf (outfil, "\n\tDefault = \"%s\"", resref->dflt); + else + if ( synres->dflt != NULL ) + fprintf (outfil, "\n\tDefault = \"%s\"", synres->dflt); + resobj->ref_ptr = NULL; + } + +/* + * Print the constraints valid in the class + */ +if ( constr ) + { + prthdr = TRUE; + for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + resref = resobj->ref_ptr; + if ( resref == NULL ) continue; + if ( wmlResolveResIsMember(resobj,clsobj->arguments) == NULL ) continue; + synres = resobj->syndef; + switch ( synres->type ) + { + case WmlResourceTypeConstraint: + break; + default: + continue; + break; + } + if ( prthdr ) + { + fprintf (outfil, "\n %s constraint set:", synobj->name); + prthdr = FALSE; + } + fprintf (outfil, "\n %s", synres->name); + if ( strcmp(synres->name,synres->resliteral) != 0 ) + fprintf (outfil, "\tResourceLiteral = %s", synres->resliteral); + switch ( resref->exclude ) + { + case WmlAttributeTrue: + fprintf (outfil, "\n\tExclude = True;"); + break; + case WmlAttributeFalse: + fprintf (outfil, "\n\tExclude = False;"); + break; + } + if ( resref->dflt != NULL ) + fprintf (outfil, "\n\tDefault = \"%s\"", resref->dflt); + else + if ( synres->dflt != NULL ) + fprintf (outfil, "\n\tDefault = \"%s\"", synres->dflt); + resobj->ref_ptr = NULL; + } + } + +} + + + +/* + * Routine to print reasons in a class. + * + * Like printing arguments, only reasons instead. + */ + +void wmlResolvePrintClassReasons (outfil, clsobj) + FILE *outfil; + WmlClassDefPtr clsobj; + +{ + +int prthdr = TRUE; /* print header flag */ +int ndx; /* loop index */ +WmlSynClassDefPtr synobj; /* syntactic object */ +WmlClassResDefPtr resref; /* resource reference */ +WmlResourceDefPtr resobj; /* current resource */ +WmlSynResourceDefPtr synres; /* syntactic resource object */ + + +/* + * Print the superclass reasons + */ +if ( clsobj->superclass != NULL ) + wmlResolvePrintClassReasons (outfil, clsobj->superclass); + +/* + * Print the parentclass reasons + */ +if ( clsobj->parentclass != NULL ) + wmlResolvePrintClassReasons (outfil, clsobj->parentclass); + +/* + * Print the reasons for this class. Unmark the reference so it won't + * be printed again. + */ +synobj = clsobj->syndef; +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + resref = resobj->ref_ptr; + if ( resref == NULL ) continue; + if ( wmlResolveResIsMember(resobj,clsobj->reasons) == NULL ) continue; + synres = resobj->syndef; + if ( prthdr ) + { + fprintf (outfil, "\n %s reason set:", synobj->name); + prthdr = FALSE; + } + fprintf (outfil, "\n %s", synres->name); + if ( strcmp(synres->name,synres->resliteral) != 0 ) + fprintf (outfil, "\tResourceLiteral = %s", synres->resliteral); + switch ( resref->exclude ) + { + case WmlAttributeTrue: + fprintf (outfil, "\n\tExclude = True;"); + break; + case WmlAttributeFalse: + fprintf (outfil, "\n\tExclude = False;"); + break; + } + resobj->ref_ptr = NULL; + } +} + + + +/* + * Routine to mark reference pointers for a class + * + * This routine clears all reference pointers, then marks the class and + * resource objects to flag those contained in the current class. This + * allows processing of the widget and resource vectors in order to produce + * bit masks or reports. + */ + +void wmlMarkReferencePointers (clsobj) + WmlClassDefPtr clsobj; + +{ + +int ndx; /* loop index */ +WmlClassDefPtr mrkcls; /* class object to mark */ +WmlResourceDefPtr mrkres; /* resource object to mark */ +WmlClassResDefPtr resref; /* resource reference */ +WmlClassCtrlDefPtr ctrlref; /* controls reference */ + + +/* + * Clear the reference pointers. Then go through the arguments, reasons, + * and controls lists, and mark the referenced classes. + */ +wmlResolveClearRefPointers (); +for ( resref=clsobj->arguments ; resref!= NULL ; resref=resref->next ) + resref->act_resource->ref_ptr = resref; +for ( resref=clsobj->reasons ; resref!= NULL ; resref=resref->next ) + resref->act_resource->ref_ptr = resref; +for ( ctrlref=clsobj->controls ; ctrlref!=NULL ; ctrlref=ctrlref->next ) + ctrlref->ctrl->ref_ptr = ctrlref; + +} + + + +/* + * Routine to clear reference pointers + */ + +void wmlResolveClearRefPointers () + +{ + +int ndx; /* loop index */ +WmlClassDefPtr mrkcls; /* class object to mark */ +WmlResourceDefPtr mrkres; /* resource object to mark */ +WmlChildDefPtr mrkcld; /* child object to mark */ + +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + mrkcls = (WmlClassDefPtr) wml_obj_allclass_ptr->hvec[ndx].objptr; + mrkcls->ref_ptr = NULL; + } +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + mrkres = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr; + mrkres->ref_ptr = NULL; + } +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + mrkres = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr; + mrkres->ref_ptr = NULL; + } +for ( ndx=0 ; ndxcnt ; ndx++ ) + { + mrkcld = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr; + mrkcld->ref_ptr = NULL; + } + +} + + + +/* + * Routine to find an object for binding. The name is always looked + * in the syntactic object list, since all references made by the + * user are in that list (resolved objects may be entered under + * an internal literal, and not be found). This routine always attempts to + * return a resolved object (which depends on object type). It also guarantees + * that the object it finds matches the given type. + * + * name the object to be found + * type type the object should match + * requester requester name, for error messages + * + * Returns: pointer to the object found + */ + +ObjectPtr wmlResolveFindObject (name, type, requester) + char *name; + int type; + char *requester; + +{ + +int objndx; /* the object index in the list */ +WmlSynDefPtr synobj; /* syntactic object */ +char errmsg[300]; + + +objndx = wmlFindInHList (wml_synobj_ptr, name); +if ( objndx < 0 ) + { + wmlIssueReferenceError (requester, name); + return NULL; + } +synobj = (WmlSynDefPtr) wml_synobj_ptr ->hvec[objndx].objptr; +if ( synobj->validation != type ) + { + sprintf (errmsg, + "Object %s references object %s\n\tin a context where a different type of object is required", + requester, name); + wmlIssueError (errmsg); + return NULL; + } +switch ( synobj->validation ) + { + case WmlClassDefValid: + case WmlResourceDefValid: + case WmlDataTypeDefValid: + case WmlCtrlListDefValid: + case WmlEnumSetDefValid: + case WmlEnumValueDefValid: + case WmlChildDefValid: + return (ObjectPtr) synobj->rslvdef; + break; + default: + return (ObjectPtr) synobj; + } + +} + + +/* + * Report an object reference error + * + * srcname the object making the reference + * badname the missing object + */ + +void wmlIssueReferenceError (srcname, badname) + char *srcname; + char *badname; + +{ + +printf ("\nObject %s references undefined object %s", srcname, badname); +wml_err_count += 1; + +} + + +/* + * Report an attempt to make a reference which is not supported. + */ + +void wmlIssueIllegalReferenceError (srcname, badname) + char *srcname; + char *badname; + +{ + +printf ("\nObject %s cannot reference a %s object", srcname, badname); +wml_err_count += 1; + +} + + +/* + * Report an error string. + */ +void wmlIssueError (errstg) + char *errstg; + +{ + +printf ("\n%s", errstg); +wml_err_count += 1; + +}