diff options
author | marha <marha@users.sourceforge.net> | 2011-04-27 06:58:32 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-04-27 06:58:32 +0000 |
commit | 96d6df5da9cddedf4931bf8e17f96e242467c661 (patch) | |
tree | 07977c913b04e80b7dbd302e7a5890422aeacb1b /libX11/src | |
parent | 71372d36e1a3f0230b88808f70d35446fda12260 (diff) | |
download | vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.tar.gz vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.tar.bz2 vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.zip |
xserver libX11 libxtrans mesa pixman xkeyboard-config git update 27 Apr 2011
Diffstat (limited to 'libX11/src')
-rw-r--r-- | libX11/src/FSWrap.c | 3 | ||||
-rw-r--r-- | libX11/src/InitExt.c | 3 | ||||
-rw-r--r-- | libX11/src/Quarks.c | 3 | ||||
-rw-r--r-- | libX11/src/SetLocale.c | 3 | ||||
-rw-r--r-- | libX11/src/Xrm.c | 6 | ||||
-rw-r--r-- | libX11/src/xcms/PrOfId.c | 11 | ||||
-rw-r--r-- | libX11/src/xkb/XKBGAlloc.c | 2027 | ||||
-rw-r--r-- | libX11/src/xlibi18n/XDefaultIMIF.c | 940 | ||||
-rw-r--r-- | libX11/src/xlibi18n/XDefaultOMIF.c | 41 | ||||
-rw-r--r-- | libX11/src/xlibi18n/XlcDL.c | 1264 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcCharSet.c | 3 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcDB.c | 18 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcFile.c | 14 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcGeneric.c | 33 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcPublic.c | 9 |
15 files changed, 2138 insertions, 2240 deletions
diff --git a/libX11/src/FSWrap.c b/libX11/src/FSWrap.c index 94d94fbe9..45a2c34e3 100644 --- a/libX11/src/FSWrap.c +++ b/libX11/src/FSWrap.c @@ -85,10 +85,9 @@ _XParseBaseFontNameList( if (!*str) return (char **)NULL; - if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) { + if (!(ptr = strdup(str))) { return (char **)NULL; } - strcpy(ptr, str); psave = ptr; /* somebody who specifies more than XMAXLIST basefontnames will lose */ diff --git a/libX11/src/InitExt.c b/libX11/src/InitExt.c index cb9191de6..19515ccd0 100644 --- a/libX11/src/InitExt.c +++ b/libX11/src/InitExt.c @@ -50,14 +50,13 @@ XExtCodes *XInitExtension ( LockDisplay (dpy); if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) || - ! (ext->name = Xmalloc((unsigned) strlen(name) + 1))) { + ! (ext->name = strdup(name))) { if (ext) Xfree((char *) ext); UnlockDisplay(dpy); return (XExtCodes *) NULL; } codes.extension = dpy->ext_number++; ext->codes = codes; - (void) strcpy(ext->name, name); /* chain it onto the display list */ ext->next = dpy->ext_procs; diff --git a/libX11/src/Quarks.c b/libX11/src/Quarks.c index d0eb69018..7a704b101 100644 --- a/libX11/src/Quarks.c +++ b/libX11/src/Quarks.c @@ -210,10 +210,9 @@ ExpandQuarkTable(void) #endif newmask = 0x1ff; } - entries = (Entry *)Xmalloc(sizeof(Entry) * (newmask + 1)); + entries = Xcalloc(newmask + 1, sizeof(Entry)); if (!entries) return False; - bzero((char *)entries, sizeof(Entry) * (newmask + 1)); quarkTable = entries; quarkMask = newmask; quarkRehash = quarkMask - 2; diff --git a/libX11/src/SetLocale.c b/libX11/src/SetLocale.c index 00c76ee45..c49cb2e4e 100644 --- a/libX11/src/SetLocale.c +++ b/libX11/src/SetLocale.c @@ -103,13 +103,12 @@ _Xsetlocale( if (!methods) return NULL; name = (*methods->lcname)(state); - xsl_name = Xmalloc(strlen(name) + 1); + xsl_name = strdup(name); if (!xsl_name) { xsl_name = old_name; (*methods->destroy)(state); return NULL; } - strcpy(xsl_name, name); if (old_name) Xfree(old_name); (*methods->destroy)(state); diff --git a/libX11/src/Xrm.c b/libX11/src/Xrm.c index c466cae7f..53467aedc 100644 --- a/libX11/src/Xrm.c +++ b/libX11/src/Xrm.c @@ -581,23 +581,21 @@ static void GrowTable( ltable = (LTable)table; /* cons up a copy to make MoveValues look symmetric */ otable = *ltable; - ltable->buckets = (VEntry *)Xmalloc(i * sizeof(VEntry)); + ltable->buckets = Xcalloc(i, sizeof(VEntry)); if (!ltable->buckets) { ltable->buckets = otable.buckets; return; } ltable->table.mask = i - 1; - bzero((char *)ltable->buckets, i * sizeof(VEntry)); MoveValues(&otable, ltable); } else { register NTable ntable; - ntable = (NTable)Xmalloc(sizeof(NTableRec) + i * sizeof(NTable)); + ntable = Xcalloc(1, sizeof(NTableRec) + (i * sizeof(NTable))); if (!ntable) return; *ntable = *table; ntable->mask = i - 1; - bzero((char *)NodeBuckets(ntable), i * sizeof(NTable)); *prev = ntable; MoveTables(table, ntable); } diff --git a/libX11/src/xcms/PrOfId.c b/libX11/src/xcms/PrOfId.c index 831f17ab9..a96d28cec 100644 --- a/libX11/src/xcms/PrOfId.c +++ b/libX11/src/xcms/PrOfId.c @@ -66,7 +66,6 @@ XcmsPrefixOfFormat( */ { XcmsColorSpace **papColorSpaces; - char *prefix; /* * First try Device-Independent color spaces @@ -75,10 +74,7 @@ XcmsPrefixOfFormat( if (papColorSpaces != NULL) { while (*papColorSpaces != NULL) { if ((*papColorSpaces)->id == id) { - prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) + - 1) * sizeof(char)); - strcpy(prefix, (*papColorSpaces)->prefix); - return(prefix); + return strdup((*papColorSpaces)->prefix); } papColorSpaces++; } @@ -91,10 +87,7 @@ XcmsPrefixOfFormat( if (papColorSpaces != NULL) { while (*papColorSpaces != NULL) { if ((*papColorSpaces)->id == id) { - prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) + - 1) * sizeof(char)); - strcpy(prefix, (*papColorSpaces)->prefix); - return(prefix); + return strdup((*papColorSpaces)->prefix); } papColorSpaces++; } diff --git a/libX11/src/xkb/XKBGAlloc.c b/libX11/src/xkb/XKBGAlloc.c index 832d28530..7679496e3 100644 --- a/libX11/src/xkb/XKBGAlloc.c +++ b/libX11/src/xkb/XKBGAlloc.c @@ -1,1016 +1,1011 @@ -/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-Permission to use, copy, modify, and distribute this
-software and its documentation for any purpose and without
-fee is hereby granted, provided that the above copyright
-notice appear in all copies and that both that copyright
-notice and this permission notice appear in supporting
-documentation, and that the name of Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
-THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-********************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#elif defined(HAVE_CONFIG_H)
-#include <config.h>
-#endif
-
-#ifndef XKB_IN_SERVER
-
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XKBlibint.h"
-#include <X11/extensions/XKBgeom.h>
-#include <X11/extensions/XKBproto.h>
-
-#else
-
-#include <stdio.h>
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
-#include <X11/extensions/XKBgeom.h>
-
-#endif /* XKB_IN_SERVER */
-
-#ifdef X_NOT_POSIX
-#define Size_t unsigned int
-#else
-#define Size_t size_t
-#endif
-
-/***====================================================================***/
-
-static void
-_XkbFreeGeomLeafElems( Bool freeAll,
- int first,
- int count,
- unsigned short * num_inout,
- unsigned short * sz_inout,
- char ** elems,
- unsigned int elem_sz)
-{
- if ((freeAll)||(*elems==NULL)) {
- *num_inout= *sz_inout= 0;
- if (*elems!=NULL) {
- _XkbFree(*elems);
- *elems= NULL;
- }
- return;
- }
-
- if ((first>=(*num_inout))||(first<0)||(count<1))
- return;
-
- if (first+count>=(*num_inout)) {
- /* truncating the array is easy */
- (*num_inout)= first;
- }
- else {
- char * ptr;
- int extra;
- ptr= *elems;
- extra= ((*num_inout)-(first+count))*elem_sz;
- if (extra>0)
- memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra);
- (*num_inout)-= count;
- }
- return;
-}
-
-typedef void (*ContentsClearFunc)(
- char * /* priv */
-);
-
-static void
-_XkbFreeGeomNonLeafElems( Bool freeAll,
- int first,
- int count,
- unsigned short * num_inout,
- unsigned short * sz_inout,
- char ** elems,
- unsigned int elem_sz,
- ContentsClearFunc freeFunc)
-{
-register int i;
-register char *ptr;
-
- if (freeAll) {
- first= 0;
- count= (*num_inout);
- }
- else if ((first>=(*num_inout))||(first<0)||(count<1))
- return;
- else if (first+count>(*num_inout))
- count= (*num_inout)-first;
- if (*elems==NULL)
- return;
-
- if (freeFunc) {
- ptr= *elems;
- ptr+= first*elem_sz;
- for (i=0;i<count;i++) {
- (*freeFunc)(ptr);
- ptr+= elem_sz;
- }
- }
- if (freeAll) {
- (*num_inout)= (*sz_inout)= 0;
- if (*elems) {
- _XkbFree(*elems);
- *elems= NULL;
- }
- }
- else if (first+count>=(*num_inout))
- *num_inout= first;
- else {
- i= ((*num_inout)-(first+count))*elem_sz;
- ptr= *elems;
- memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i);
- (*num_inout)-= count;
- }
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearProperty(char *prop_in)
-{
-XkbPropertyPtr prop= (XkbPropertyPtr)prop_in;
-
- if (prop->name) {
- _XkbFree(prop->name);
- prop->name= NULL;
- }
- if (prop->value) {
- _XkbFree(prop->value);
- prop->value= NULL;
- }
- return;
-}
-
-void
-XkbFreeGeomProperties( XkbGeometryPtr geom,
- int first,
- int count,
- Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_properties,&geom->sz_properties,
- (char **)&geom->properties,
- sizeof(XkbPropertyRec),_XkbClearProperty);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomKeyAliases( XkbGeometryPtr geom,
- int first,
- int count,
- Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &geom->num_key_aliases,&geom->sz_key_aliases,
- (char **)&geom->key_aliases,
- sizeof(XkbKeyAliasRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearColor(char *color_in)
-{
-XkbColorPtr color= (XkbColorPtr)color_in;
-
- if (color->spec)
- _XkbFree(color->spec);
- return;
-}
-
-void
-XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_colors,&geom->sz_colors,
- (char **)&geom->colors,
- sizeof(XkbColorRec),_XkbClearColor);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &outline->num_points,&outline->sz_points,
- (char **)&outline->points,
- sizeof(XkbPointRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOutline(char *outline_in)
-{
-XkbOutlinePtr outline= (XkbOutlinePtr)outline_in;
-
- if (outline->points!=NULL)
- XkbFreeGeomPoints(outline,0,outline->num_points,True);
- return;
-}
-
-void
-XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &shape->num_outlines,&shape->sz_outlines,
- (char **)&shape->outlines,
- sizeof(XkbOutlineRec),_XkbClearOutline);
-
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearShape(char *shape_in)
-{
-XkbShapePtr shape= (XkbShapePtr)shape_in;
-
- if (shape->outlines)
- XkbFreeGeomOutlines(shape,0,shape->num_outlines,True);
- return;
-}
-
-void
-XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_shapes,&geom->sz_shapes,
- (char **)&geom->shapes,
- sizeof(XkbShapeRec),_XkbClearShape);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &row->num_keys,&row->sz_keys,
- (char **)&row->keys,
- sizeof(XkbOverlayKeyRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOverlayRow(char *row_in)
-{
-XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in;
-
- if (row->keys!=NULL)
- XkbFreeGeomOverlayKeys(row,0,row->num_keys,True);
- return;
-}
-
-void
-XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &overlay->num_rows,&overlay->sz_rows,
- (char **)&overlay->rows,
- sizeof(XkbOverlayRowRec),_XkbClearOverlayRow);
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOverlay(char *overlay_in)
-{
-XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in;
-
- if (overlay->rows!=NULL)
- XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True);
- return;
-}
-
-void
-XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- §ion->num_overlays,§ion->sz_overlays,
- (char **)§ion->overlays,
- sizeof(XkbOverlayRec),_XkbClearOverlay);
- return;
-}
-
-/***====================================================================***/
-
-void
-XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll,first,count,
- &row->num_keys,&row->sz_keys,
- (char **)&row->keys,
- sizeof(XkbKeyRec));
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearRow(char *row_in)
-{
-XkbRowPtr row= (XkbRowPtr)row_in;
-
- if (row->keys!=NULL)
- XkbFreeGeomKeys(row,0,row->num_keys,True);
- return;
-}
-
-void
-XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- §ion->num_rows,§ion->sz_rows,
- (char **)§ion->rows,
- sizeof(XkbRowRec),_XkbClearRow);
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearSection(char *section_in)
-{
-XkbSectionPtr section= (XkbSectionPtr)section_in;
-
- if (section->rows!=NULL)
- XkbFreeGeomRows(section,0,section->num_rows,True);
- if (section->doodads!=NULL) {
- XkbFreeGeomDoodads(section->doodads,section->num_doodads,True);
- section->doodads= NULL;
- }
- return;
-}
-
-void
-XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
-{
- _XkbFreeGeomNonLeafElems(freeAll,first,count,
- &geom->num_sections,&geom->sz_sections,
- (char **)&geom->sections,
- sizeof(XkbSectionRec),_XkbClearSection);
- return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearDoodad(char *doodad_in)
-{
-XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in;
-
- switch (doodad->any.type) {
- case XkbTextDoodad:
- {
- if (doodad->text.text!=NULL) {
- _XkbFree(doodad->text.text);
- doodad->text.text= NULL;
- }
- if (doodad->text.font!=NULL) {
- _XkbFree(doodad->text.font);
- doodad->text.font= NULL;
- }
- }
- break;
- case XkbLogoDoodad:
- {
- if (doodad->logo.logo_name!=NULL) {
- _XkbFree(doodad->logo.logo_name);
- doodad->logo.logo_name= NULL;
- }
- }
- break;
- }
- return;
-}
-
-void
-XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll)
-{
-register int i;
-register XkbDoodadPtr doodad;
-
- if (doodads) {
- for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) {
- _XkbClearDoodad((char *)doodad);
- }
- if (freeAll)
- _XkbFree(doodads);
- }
- return;
-}
-
-void
-XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
-{
- if (geom==NULL)
- return;
- if (freeMap)
- which= XkbGeomAllMask;
- if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL))
- XkbFreeGeomProperties(geom,0,geom->num_properties,True);
- if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL))
- XkbFreeGeomColors(geom,0,geom->num_colors,True);
- if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL))
- XkbFreeGeomShapes(geom,0,geom->num_shapes,True);
- if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL))
- XkbFreeGeomSections(geom,0,geom->num_sections,True);
- if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) {
- XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True);
- geom->doodads= NULL;
- geom->num_doodads= geom->sz_doodads= 0;
- }
- if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
- XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True);
- if (freeMap) {
- if (geom->label_font!=NULL) {
- _XkbFree(geom->label_font);
- geom->label_font= NULL;
- }
- _XkbFree(geom);
- }
- return;
-}
-
-/***====================================================================***/
-
-static Status
-_XkbGeomAlloc( XPointer * old,
- unsigned short * num,
- unsigned short * total,
- int num_new,
- Size_t sz_elem)
-{
- if (num_new<1)
- return Success;
- if ((*old)==NULL)
- *num= *total= 0;
-
- if ((*num)+num_new<=(*total))
- return Success;
-
- *total= (*num)+num_new;
- if ((*old)!=NULL)
- (*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem);
- else (*old)= (XPointer)_XkbCalloc((*total),sz_elem);
- if ((*old)==NULL) {
- *total= *num= 0;
- return BadAlloc;
- }
-
- if (*num>0) {
- char *tmp= (char *)(*old);
- bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem));
- }
- return Success;
-}
-
-#define _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\
- &(g)->num_properties,&(g)->sz_properties,\
- (n),sizeof(XkbPropertyRec))
-#define _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\
- &(g)->num_colors,&(g)->sz_colors,\
- (n),sizeof(XkbColorRec))
-#define _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\
- &(g)->num_shapes,&(g)->sz_shapes,\
- (n),sizeof(XkbShapeRec))
-#define _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\
- &(g)->num_sections,&(g)->sz_sections,\
- (n),sizeof(XkbSectionRec))
-#define _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\
- &(g)->num_doodads,&(g)->sz_doodads,\
- (n),sizeof(XkbDoodadRec))
-#define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\
- &(g)->num_key_aliases,&(g)->sz_key_aliases,\
- (n),sizeof(XkbKeyAliasRec))
-
-#define _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\
- &(s)->num_outlines,&(s)->sz_outlines,\
- (n),sizeof(XkbOutlineRec))
-#define _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\
- &(s)->num_rows,&(s)->sz_rows,\
- (n),sizeof(XkbRowRec))
-#define _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\
- &(o)->num_points,&(o)->sz_points,\
- (n),sizeof(XkbPointRec))
-#define _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
- &(r)->num_keys,&(r)->sz_keys,\
- (n),sizeof(XkbKeyRec))
-#define _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\
- &(s)->num_overlays,&(s)->sz_overlays,\
- (n),sizeof(XkbOverlayRec))
-#define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\
- &(o)->num_rows,&(o)->sz_rows,\
- (n),sizeof(XkbOverlayRowRec))
-#define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
- &(r)->num_keys,&(r)->sz_keys,\
- (n),sizeof(XkbOverlayKeyRec))
-
-Status
-XkbAllocGeomProps(XkbGeometryPtr geom,int nProps)
-{
- return _XkbAllocProps(geom,nProps);
-}
-
-Status
-XkbAllocGeomColors(XkbGeometryPtr geom,int nColors)
-{
- return _XkbAllocColors(geom,nColors);
-}
-
-Status
-XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases)
-{
- return _XkbAllocKeyAliases(geom,nKeyAliases);
-}
-
-Status
-XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes)
-{
- return _XkbAllocShapes(geom,nShapes);
-}
-
-Status
-XkbAllocGeomSections(XkbGeometryPtr geom,int nSections)
-{
- return _XkbAllocSections(geom,nSections);
-}
-
-Status
-XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays)
-{
- return _XkbAllocOverlays(section,nOverlays);
-}
-
-Status
-XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows)
-{
- return _XkbAllocOverlayRows(overlay,nRows);
-}
-
-Status
-XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys)
-{
- return _XkbAllocOverlayKeys(row,nKeys);
-}
-
-Status
-XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads)
-{
- return _XkbAllocDoodads(geom,nDoodads);
-}
-
-Status
-XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads)
-{
- return _XkbAllocDoodads(section,nDoodads);
-}
-
-Status
-XkbAllocGeomOutlines(XkbShapePtr shape,int nOL)
-{
- return _XkbAllocOutlines(shape,nOL);
-}
-
-Status
-XkbAllocGeomRows(XkbSectionPtr section,int nRows)
-{
- return _XkbAllocRows(section,nRows);
-}
-
-Status
-XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts)
-{
- return _XkbAllocPoints(ol,nPts);
-}
-
-Status
-XkbAllocGeomKeys(XkbRowPtr row,int nKeys)
-{
- return _XkbAllocKeys(row,nKeys);
-}
-
-Status
-XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes)
-{
-XkbGeometryPtr geom;
-Status rtrn;
-
- if (xkb->geom==NULL) {
- xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec);
- if (!xkb->geom)
- return BadAlloc;
- }
- geom= xkb->geom;
- if ((sizes->which&XkbGeomPropertiesMask)&&
- ((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomColorsMask)&&
- ((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomShapesMask)&&
- ((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomSectionsMask)&&
- ((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomDoodadsMask)&&
- ((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) {
- goto BAIL;
- }
- if ((sizes->which&XkbGeomKeyAliasesMask)&&
- ((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) {
- goto BAIL;
- }
- return Success;
-BAIL:
- XkbFreeGeometry(geom,XkbGeomAllMask,True);
- xkb->geom= NULL;
- return rtrn;
-}
-
-/***====================================================================***/
-
-XkbPropertyPtr
-XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value)
-{
-register int i;
-register XkbPropertyPtr prop;
-
- if ((!geom)||(!name)||(!value))
- return NULL;
- for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
- if ((prop->name)&&(strcmp(name,prop->name)==0)) {
- if (prop->value)
- _XkbFree(prop->value);
- prop->value= (char *)_XkbAlloc(strlen(value)+1);
- if (prop->value)
- strcpy(prop->value,value);
- return prop;
- }
- }
- if ((geom->num_properties>=geom->sz_properties)&&
- (_XkbAllocProps(geom,1)!=Success)) {
- return NULL;
- }
- prop= &geom->properties[geom->num_properties];
- prop->name= (char *)_XkbAlloc(strlen(name)+1);
- if (!prop->name)
- return NULL;
- strcpy(prop->name,name);
- prop->value= (char *)_XkbAlloc(strlen(value)+1);
- if (!prop->value) {
- _XkbFree(prop->name);
- prop->name= NULL;
- return NULL;
- }
- strcpy(prop->value,value);
- geom->num_properties++;
- return prop;
-}
-
-XkbKeyAliasPtr
-XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr)
-{
-register int i;
-register XkbKeyAliasPtr alias;
-
- if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0]))
- return NULL;
- for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
- if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
- bzero(alias->real,XkbKeyNameLength);
- strncpy(alias->real,realStr,XkbKeyNameLength);
- return alias;
- }
- }
- if ((geom->num_key_aliases>=geom->sz_key_aliases)&&
- (_XkbAllocKeyAliases(geom,1)!=Success)) {
- return NULL;
- }
- alias= &geom->key_aliases[geom->num_key_aliases];
- bzero(alias,sizeof(XkbKeyAliasRec));
- strncpy(alias->alias,aliasStr,XkbKeyNameLength);
- strncpy(alias->real,realStr,XkbKeyNameLength);
- geom->num_key_aliases++;
- return alias;
-}
-
-XkbColorPtr
-XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel)
-{
-register int i;
-register XkbColorPtr color;
-
- if ((!geom)||(!spec))
- return NULL;
- for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
- if ((color->spec)&&(strcmp(color->spec,spec)==0)) {
- color->pixel= pixel;
- return color;
- }
- }
- if ((geom->num_colors>=geom->sz_colors)&&
- (_XkbAllocColors(geom,1)!=Success)) {
- return NULL;
- }
- color= &geom->colors[geom->num_colors];
- color->pixel= pixel;
- color->spec= (char *)_XkbAlloc(strlen(spec)+1);
- if (!color->spec)
- return NULL;
- strcpy(color->spec,spec);
- geom->num_colors++;
- return color;
-}
-
-XkbOutlinePtr
-XkbAddGeomOutline(XkbShapePtr shape,int sz_points)
-{
-XkbOutlinePtr outline;
-
- if ((!shape)||(sz_points<0))
- return NULL;
- if ((shape->num_outlines>=shape->sz_outlines)&&
- (_XkbAllocOutlines(shape,1)!=Success)) {
- return NULL;
- }
- outline= &shape->outlines[shape->num_outlines];
- bzero(outline,sizeof(XkbOutlineRec));
- if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success))
- return NULL;
- shape->num_outlines++;
- return outline;
-}
-
-XkbShapePtr
-XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines)
-{
-XkbShapePtr shape;
-register int i;
-
- if ((!geom)||(!name)||(sz_outlines<0))
- return NULL;
- if (geom->num_shapes>0) {
- for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) {
- if (name==shape->name)
- return shape;
- }
- }
- if ((geom->num_shapes>=geom->sz_shapes)&&
- (_XkbAllocShapes(geom,1)!=Success))
- return NULL;
- shape= &geom->shapes[geom->num_shapes];
- bzero(shape,sizeof(XkbShapeRec));
- if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success))
- return NULL;
- shape->name= name;
- shape->primary= shape->approx= NULL;
- geom->num_shapes++;
- return shape;
-}
-
-XkbKeyPtr
-XkbAddGeomKey(XkbRowPtr row)
-{
-XkbKeyPtr key;
- if (!row)
- return NULL;
- if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success))
- return NULL;
- key= &row->keys[row->num_keys++];
- bzero(key,sizeof(XkbKeyRec));
- return key;
-}
-
-XkbRowPtr
-XkbAddGeomRow(XkbSectionPtr section,int sz_keys)
-{
-XkbRowPtr row;
-
- if ((!section)||(sz_keys<0))
- return NULL;
- if ((section->num_rows>=section->sz_rows)&&
- (_XkbAllocRows(section,1)!=Success))
- return NULL;
- row= §ion->rows[section->num_rows];
- bzero(row,sizeof(XkbRowRec));
- if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success))
- return NULL;
- section->num_rows++;
- return row;
-}
-
-XkbSectionPtr
-XkbAddGeomSection( XkbGeometryPtr geom,
- Atom name,
- int sz_rows,
- int sz_doodads,
- int sz_over)
-{
-register int i;
-XkbSectionPtr section;
-
- if ((!geom)||(name==None)||(sz_rows<0))
- return NULL;
- for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
- if (section->name!=name)
- continue;
- if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))||
- ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))||
- ((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success)))
- return NULL;
- return section;
- }
- if ((geom->num_sections>=geom->sz_sections)&&
- (_XkbAllocSections(geom,1)!=Success))
- return NULL;
- section= &geom->sections[geom->num_sections];
- if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))
- return NULL;
- if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) {
- if (section->rows) {
- _XkbFree(section->rows);
- section->rows= NULL;
- section->sz_rows= section->num_rows= 0;
- }
- return NULL;
- }
- section->name= name;
- geom->num_sections++;
- return section;
-}
-
-XkbDoodadPtr
-XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name)
-{
-XkbDoodadPtr old,doodad;
-register int i,nDoodads;
-
- if ((!geom)||(name==None))
- return NULL;
- if ((section!=NULL)&&(section->num_doodads>0)) {
- old= section->doodads;
- nDoodads= section->num_doodads;
- }
- else {
- old= geom->doodads;
- nDoodads= geom->num_doodads;
- }
- for (i=0,doodad=old;i<nDoodads;i++,doodad++) {
- if (doodad->any.name==name)
- return doodad;
- }
- if (section) {
- if ((section->num_doodads>=geom->sz_doodads)&&
- (_XkbAllocDoodads(section,1)!=Success)) {
- return NULL;
- }
- doodad= §ion->doodads[section->num_doodads++];
- }
- else {
- if ((geom->num_doodads>=geom->sz_doodads)&&
- (_XkbAllocDoodads(geom,1)!=Success))
- return NULL;
- doodad= &geom->doodads[geom->num_doodads++];
- }
- bzero(doodad,sizeof(XkbDoodadRec));
- doodad->any.name= name;
- return doodad;
-}
-
-XkbOverlayKeyPtr
-XkbAddGeomOverlayKey( XkbOverlayPtr overlay,
- XkbOverlayRowPtr row,
- char * over,
- char * under)
-{
-register int i;
-XkbOverlayKeyPtr key;
-XkbSectionPtr section;
-XkbRowPtr row_under;
-Bool found;
-
- if ((!overlay)||(!row)||(!over)||(!under))
- return NULL;
- section= overlay->section_under;
- if (row->row_under>=section->num_rows)
- return NULL;
- row_under= §ion->rows[row->row_under];
- for (i=0,found=False;i<row_under->num_keys;i++) {
- if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) {
- found= True;
- break;
- }
- }
- if (!found)
- return NULL;
- if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success))
- return NULL;
- key= &row->keys[row->num_keys];
- strncpy(key->under.name,under,XkbKeyNameLength);
- strncpy(key->over.name,over,XkbKeyNameLength);
- row->num_keys++;
- return key;
-}
-
-XkbOverlayRowPtr
-XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys)
-{
-register int i;
-XkbOverlayRowPtr row;
-
- if ((!overlay)||(sz_keys<0))
- return NULL;
- if (row_under>=overlay->section_under->num_rows)
- return NULL;
- for (i=0;i<overlay->num_rows;i++) {
- if (overlay->rows[i].row_under==row_under) {
- row= &overlay->rows[i];
- if ((row->sz_keys<sz_keys)&&
- (_XkbAllocOverlayKeys(row,sz_keys)!=Success)) {
- return NULL;
- }
- return &overlay->rows[i];
- }
- }
- if ((overlay->num_rows>=overlay->sz_rows)&&
- (_XkbAllocOverlayRows(overlay,1)!=Success))
- return NULL;
- row= &overlay->rows[overlay->num_rows];
- bzero(row,sizeof(XkbOverlayRowRec));
- if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success))
- return NULL;
- row->row_under= row_under;
- overlay->num_rows++;
- return row;
-}
-
-XkbOverlayPtr
-XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows)
-{
-register int i;
-XkbOverlayPtr overlay;
-
- if ((!section)||(name==None)||(sz_rows==0))
- return NULL;
-
- for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) {
- if (overlay->name==name) {
- if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
- return NULL;
- return overlay;
- }
- }
- if ((section->num_overlays>=section->sz_overlays)&&
- (_XkbAllocOverlays(section,1)!=Success))
- return NULL;
- overlay= §ion->overlays[section->num_overlays];
- if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
- return NULL;
- overlay->name= name;
- overlay->section_under= section;
- section->num_overlays++;
- return overlay;
-}
+/************************************************************ +Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. + +Permission to use, copy, modify, and distribute this +software and its documentation for any purpose and without +fee is hereby granted, provided that the above copyright +notice appear in all copies and that both that copyright +notice and this permission notice appear in supporting +documentation, and that the name of Silicon Graphics not be +used in advertising or publicity pertaining to distribution +of the software without specific prior written permission. +Silicon Graphics makes no representation about the suitability +of this software for any purpose. It is provided "as is" +without any express or implied warranty. + +SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON +GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH +THE USE OR PERFORMANCE OF THIS SOFTWARE. + +********************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#elif defined(HAVE_CONFIG_H) +#include <config.h> +#endif + +#ifndef XKB_IN_SERVER + +#include <stdio.h> +#include "Xlibint.h" +#include "XKBlibint.h" +#include <X11/extensions/XKBgeom.h> +#include <X11/extensions/XKBproto.h> + +#else + +#include <stdio.h> +#include <X11/X.h> +#include <X11/Xproto.h> +#include "misc.h" +#include "inputstr.h" +#include <X11/extensions/XKBsrv.h> +#include <X11/extensions/XKBgeom.h> + +#endif /* XKB_IN_SERVER */ + +#ifdef X_NOT_POSIX +#define Size_t unsigned int +#else +#define Size_t size_t +#endif + +/***====================================================================***/ + +static void +_XkbFreeGeomLeafElems( Bool freeAll, + int first, + int count, + unsigned short * num_inout, + unsigned short * sz_inout, + char ** elems, + unsigned int elem_sz) +{ + if ((freeAll)||(*elems==NULL)) { + *num_inout= *sz_inout= 0; + if (*elems!=NULL) { + _XkbFree(*elems); + *elems= NULL; + } + return; + } + + if ((first>=(*num_inout))||(first<0)||(count<1)) + return; + + if (first+count>=(*num_inout)) { + /* truncating the array is easy */ + (*num_inout)= first; + } + else { + char * ptr; + int extra; + ptr= *elems; + extra= ((*num_inout)-(first+count))*elem_sz; + if (extra>0) + memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra); + (*num_inout)-= count; + } + return; +} + +typedef void (*ContentsClearFunc)( + char * /* priv */ +); + +static void +_XkbFreeGeomNonLeafElems( Bool freeAll, + int first, + int count, + unsigned short * num_inout, + unsigned short * sz_inout, + char ** elems, + unsigned int elem_sz, + ContentsClearFunc freeFunc) +{ +register int i; +register char *ptr; + + if (freeAll) { + first= 0; + count= (*num_inout); + } + else if ((first>=(*num_inout))||(first<0)||(count<1)) + return; + else if (first+count>(*num_inout)) + count= (*num_inout)-first; + if (*elems==NULL) + return; + + if (freeFunc) { + ptr= *elems; + ptr+= first*elem_sz; + for (i=0;i<count;i++) { + (*freeFunc)(ptr); + ptr+= elem_sz; + } + } + if (freeAll) { + (*num_inout)= (*sz_inout)= 0; + if (*elems) { + _XkbFree(*elems); + *elems= NULL; + } + } + else if (first+count>=(*num_inout)) + *num_inout= first; + else { + i= ((*num_inout)-(first+count))*elem_sz; + ptr= *elems; + memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i); + (*num_inout)-= count; + } + return; +} + +/***====================================================================***/ + +static void +_XkbClearProperty(char *prop_in) +{ +XkbPropertyPtr prop= (XkbPropertyPtr)prop_in; + + if (prop->name) { + _XkbFree(prop->name); + prop->name= NULL; + } + if (prop->value) { + _XkbFree(prop->value); + prop->value= NULL; + } + return; +} + +void +XkbFreeGeomProperties( XkbGeometryPtr geom, + int first, + int count, + Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + &geom->num_properties,&geom->sz_properties, + (char **)&geom->properties, + sizeof(XkbPropertyRec),_XkbClearProperty); + return; +} + +/***====================================================================***/ + +void +XkbFreeGeomKeyAliases( XkbGeometryPtr geom, + int first, + int count, + Bool freeAll) +{ + _XkbFreeGeomLeafElems(freeAll,first,count, + &geom->num_key_aliases,&geom->sz_key_aliases, + (char **)&geom->key_aliases, + sizeof(XkbKeyAliasRec)); + return; +} + +/***====================================================================***/ + +static void +_XkbClearColor(char *color_in) +{ +XkbColorPtr color= (XkbColorPtr)color_in; + + if (color->spec) + _XkbFree(color->spec); + return; +} + +void +XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + &geom->num_colors,&geom->sz_colors, + (char **)&geom->colors, + sizeof(XkbColorRec),_XkbClearColor); + return; +} + +/***====================================================================***/ + +void +XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll) +{ + _XkbFreeGeomLeafElems(freeAll,first,count, + &outline->num_points,&outline->sz_points, + (char **)&outline->points, + sizeof(XkbPointRec)); + return; +} + +/***====================================================================***/ + +static void +_XkbClearOutline(char *outline_in) +{ +XkbOutlinePtr outline= (XkbOutlinePtr)outline_in; + + if (outline->points!=NULL) + XkbFreeGeomPoints(outline,0,outline->num_points,True); + return; +} + +void +XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + &shape->num_outlines,&shape->sz_outlines, + (char **)&shape->outlines, + sizeof(XkbOutlineRec),_XkbClearOutline); + + return; +} + +/***====================================================================***/ + +static void +_XkbClearShape(char *shape_in) +{ +XkbShapePtr shape= (XkbShapePtr)shape_in; + + if (shape->outlines) + XkbFreeGeomOutlines(shape,0,shape->num_outlines,True); + return; +} + +void +XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + &geom->num_shapes,&geom->sz_shapes, + (char **)&geom->shapes, + sizeof(XkbShapeRec),_XkbClearShape); + return; +} + +/***====================================================================***/ + +void +XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll) +{ + _XkbFreeGeomLeafElems(freeAll,first,count, + &row->num_keys,&row->sz_keys, + (char **)&row->keys, + sizeof(XkbOverlayKeyRec)); + return; +} + +/***====================================================================***/ + +static void +_XkbClearOverlayRow(char *row_in) +{ +XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in; + + if (row->keys!=NULL) + XkbFreeGeomOverlayKeys(row,0,row->num_keys,True); + return; +} + +void +XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + &overlay->num_rows,&overlay->sz_rows, + (char **)&overlay->rows, + sizeof(XkbOverlayRowRec),_XkbClearOverlayRow); + return; +} + +/***====================================================================***/ + +static void +_XkbClearOverlay(char *overlay_in) +{ +XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in; + + if (overlay->rows!=NULL) + XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True); + return; +} + +void +XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + §ion->num_overlays,§ion->sz_overlays, + (char **)§ion->overlays, + sizeof(XkbOverlayRec),_XkbClearOverlay); + return; +} + +/***====================================================================***/ + +void +XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll) +{ + _XkbFreeGeomLeafElems(freeAll,first,count, + &row->num_keys,&row->sz_keys, + (char **)&row->keys, + sizeof(XkbKeyRec)); + return; +} + +/***====================================================================***/ + +static void +_XkbClearRow(char *row_in) +{ +XkbRowPtr row= (XkbRowPtr)row_in; + + if (row->keys!=NULL) + XkbFreeGeomKeys(row,0,row->num_keys,True); + return; +} + +void +XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + §ion->num_rows,§ion->sz_rows, + (char **)§ion->rows, + sizeof(XkbRowRec),_XkbClearRow); +} + +/***====================================================================***/ + +static void +_XkbClearSection(char *section_in) +{ +XkbSectionPtr section= (XkbSectionPtr)section_in; + + if (section->rows!=NULL) + XkbFreeGeomRows(section,0,section->num_rows,True); + if (section->doodads!=NULL) { + XkbFreeGeomDoodads(section->doodads,section->num_doodads,True); + section->doodads= NULL; + } + return; +} + +void +XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll) +{ + _XkbFreeGeomNonLeafElems(freeAll,first,count, + &geom->num_sections,&geom->sz_sections, + (char **)&geom->sections, + sizeof(XkbSectionRec),_XkbClearSection); + return; +} + +/***====================================================================***/ + +static void +_XkbClearDoodad(char *doodad_in) +{ +XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in; + + switch (doodad->any.type) { + case XkbTextDoodad: + { + if (doodad->text.text!=NULL) { + _XkbFree(doodad->text.text); + doodad->text.text= NULL; + } + if (doodad->text.font!=NULL) { + _XkbFree(doodad->text.font); + doodad->text.font= NULL; + } + } + break; + case XkbLogoDoodad: + { + if (doodad->logo.logo_name!=NULL) { + _XkbFree(doodad->logo.logo_name); + doodad->logo.logo_name= NULL; + } + } + break; + } + return; +} + +void +XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll) +{ +register int i; +register XkbDoodadPtr doodad; + + if (doodads) { + for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) { + _XkbClearDoodad((char *)doodad); + } + if (freeAll) + _XkbFree(doodads); + } + return; +} + +void +XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap) +{ + if (geom==NULL) + return; + if (freeMap) + which= XkbGeomAllMask; + if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL)) + XkbFreeGeomProperties(geom,0,geom->num_properties,True); + if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL)) + XkbFreeGeomColors(geom,0,geom->num_colors,True); + if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL)) + XkbFreeGeomShapes(geom,0,geom->num_shapes,True); + if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL)) + XkbFreeGeomSections(geom,0,geom->num_sections,True); + if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) { + XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True); + geom->doodads= NULL; + geom->num_doodads= geom->sz_doodads= 0; + } + if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL)) + XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True); + if (freeMap) { + if (geom->label_font!=NULL) { + _XkbFree(geom->label_font); + geom->label_font= NULL; + } + _XkbFree(geom); + } + return; +} + +/***====================================================================***/ + +static Status +_XkbGeomAlloc( XPointer * old, + unsigned short * num, + unsigned short * total, + int num_new, + Size_t sz_elem) +{ + if (num_new<1) + return Success; + if ((*old)==NULL) + *num= *total= 0; + + if ((*num)+num_new<=(*total)) + return Success; + + *total= (*num)+num_new; + if ((*old)!=NULL) + (*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem); + else (*old)= (XPointer)_XkbCalloc((*total),sz_elem); + if ((*old)==NULL) { + *total= *num= 0; + return BadAlloc; + } + + if (*num>0) { + char *tmp= (char *)(*old); + bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem)); + } + return Success; +} + +#define _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\ + &(g)->num_properties,&(g)->sz_properties,\ + (n),sizeof(XkbPropertyRec)) +#define _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\ + &(g)->num_colors,&(g)->sz_colors,\ + (n),sizeof(XkbColorRec)) +#define _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\ + &(g)->num_shapes,&(g)->sz_shapes,\ + (n),sizeof(XkbShapeRec)) +#define _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\ + &(g)->num_sections,&(g)->sz_sections,\ + (n),sizeof(XkbSectionRec)) +#define _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\ + &(g)->num_doodads,&(g)->sz_doodads,\ + (n),sizeof(XkbDoodadRec)) +#define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\ + &(g)->num_key_aliases,&(g)->sz_key_aliases,\ + (n),sizeof(XkbKeyAliasRec)) + +#define _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\ + &(s)->num_outlines,&(s)->sz_outlines,\ + (n),sizeof(XkbOutlineRec)) +#define _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\ + &(s)->num_rows,&(s)->sz_rows,\ + (n),sizeof(XkbRowRec)) +#define _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\ + &(o)->num_points,&(o)->sz_points,\ + (n),sizeof(XkbPointRec)) +#define _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\ + &(r)->num_keys,&(r)->sz_keys,\ + (n),sizeof(XkbKeyRec)) +#define _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\ + &(s)->num_overlays,&(s)->sz_overlays,\ + (n),sizeof(XkbOverlayRec)) +#define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\ + &(o)->num_rows,&(o)->sz_rows,\ + (n),sizeof(XkbOverlayRowRec)) +#define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\ + &(r)->num_keys,&(r)->sz_keys,\ + (n),sizeof(XkbOverlayKeyRec)) + +Status +XkbAllocGeomProps(XkbGeometryPtr geom,int nProps) +{ + return _XkbAllocProps(geom,nProps); +} + +Status +XkbAllocGeomColors(XkbGeometryPtr geom,int nColors) +{ + return _XkbAllocColors(geom,nColors); +} + +Status +XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases) +{ + return _XkbAllocKeyAliases(geom,nKeyAliases); +} + +Status +XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes) +{ + return _XkbAllocShapes(geom,nShapes); +} + +Status +XkbAllocGeomSections(XkbGeometryPtr geom,int nSections) +{ + return _XkbAllocSections(geom,nSections); +} + +Status +XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays) +{ + return _XkbAllocOverlays(section,nOverlays); +} + +Status +XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows) +{ + return _XkbAllocOverlayRows(overlay,nRows); +} + +Status +XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys) +{ + return _XkbAllocOverlayKeys(row,nKeys); +} + +Status +XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads) +{ + return _XkbAllocDoodads(geom,nDoodads); +} + +Status +XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads) +{ + return _XkbAllocDoodads(section,nDoodads); +} + +Status +XkbAllocGeomOutlines(XkbShapePtr shape,int nOL) +{ + return _XkbAllocOutlines(shape,nOL); +} + +Status +XkbAllocGeomRows(XkbSectionPtr section,int nRows) +{ + return _XkbAllocRows(section,nRows); +} + +Status +XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts) +{ + return _XkbAllocPoints(ol,nPts); +} + +Status +XkbAllocGeomKeys(XkbRowPtr row,int nKeys) +{ + return _XkbAllocKeys(row,nKeys); +} + +Status +XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes) +{ +XkbGeometryPtr geom; +Status rtrn; + + if (xkb->geom==NULL) { + xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec); + if (!xkb->geom) + return BadAlloc; + } + geom= xkb->geom; + if ((sizes->which&XkbGeomPropertiesMask)&& + ((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) { + goto BAIL; + } + if ((sizes->which&XkbGeomColorsMask)&& + ((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) { + goto BAIL; + } + if ((sizes->which&XkbGeomShapesMask)&& + ((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) { + goto BAIL; + } + if ((sizes->which&XkbGeomSectionsMask)&& + ((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) { + goto BAIL; + } + if ((sizes->which&XkbGeomDoodadsMask)&& + ((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) { + goto BAIL; + } + if ((sizes->which&XkbGeomKeyAliasesMask)&& + ((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) { + goto BAIL; + } + return Success; +BAIL: + XkbFreeGeometry(geom,XkbGeomAllMask,True); + xkb->geom= NULL; + return rtrn; +} + +/***====================================================================***/ + +XkbPropertyPtr +XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value) +{ +register int i; +register XkbPropertyPtr prop; + + if ((!geom)||(!name)||(!value)) + return NULL; + for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) { + if ((prop->name)&&(strcmp(name,prop->name)==0)) { + if (prop->value) + _XkbFree(prop->value); + prop->value= strdup(value); + return prop; + } + } + if ((geom->num_properties>=geom->sz_properties)&& + (_XkbAllocProps(geom,1)!=Success)) { + return NULL; + } + prop= &geom->properties[geom->num_properties]; + prop->name= strdup(name); + if (!prop->name) + return NULL; + prop->value= strdup(value); + if (!prop->value) { + _XkbFree(prop->name); + prop->name= NULL; + return NULL; + } + geom->num_properties++; + return prop; +} + +XkbKeyAliasPtr +XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr) +{ +register int i; +register XkbKeyAliasPtr alias; + + if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0])) + return NULL; + for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) { + if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) { + bzero(alias->real,XkbKeyNameLength); + strncpy(alias->real,realStr,XkbKeyNameLength); + return alias; + } + } + if ((geom->num_key_aliases>=geom->sz_key_aliases)&& + (_XkbAllocKeyAliases(geom,1)!=Success)) { + return NULL; + } + alias= &geom->key_aliases[geom->num_key_aliases]; + bzero(alias,sizeof(XkbKeyAliasRec)); + strncpy(alias->alias,aliasStr,XkbKeyNameLength); + strncpy(alias->real,realStr,XkbKeyNameLength); + geom->num_key_aliases++; + return alias; +} + +XkbColorPtr +XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel) +{ +register int i; +register XkbColorPtr color; + + if ((!geom)||(!spec)) + return NULL; + for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) { + if ((color->spec)&&(strcmp(color->spec,spec)==0)) { + color->pixel= pixel; + return color; + } + } + if ((geom->num_colors>=geom->sz_colors)&& + (_XkbAllocColors(geom,1)!=Success)) { + return NULL; + } + color= &geom->colors[geom->num_colors]; + color->pixel= pixel; + color->spec= strdup(spec); + if (!color->spec) + return NULL; + geom->num_colors++; + return color; +} + +XkbOutlinePtr +XkbAddGeomOutline(XkbShapePtr shape,int sz_points) +{ +XkbOutlinePtr outline; + + if ((!shape)||(sz_points<0)) + return NULL; + if ((shape->num_outlines>=shape->sz_outlines)&& + (_XkbAllocOutlines(shape,1)!=Success)) { + return NULL; + } + outline= &shape->outlines[shape->num_outlines]; + bzero(outline,sizeof(XkbOutlineRec)); + if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success)) + return NULL; + shape->num_outlines++; + return outline; +} + +XkbShapePtr +XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines) +{ +XkbShapePtr shape; +register int i; + + if ((!geom)||(!name)||(sz_outlines<0)) + return NULL; + if (geom->num_shapes>0) { + for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) { + if (name==shape->name) + return shape; + } + } + if ((geom->num_shapes>=geom->sz_shapes)&& + (_XkbAllocShapes(geom,1)!=Success)) + return NULL; + shape= &geom->shapes[geom->num_shapes]; + bzero(shape,sizeof(XkbShapeRec)); + if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success)) + return NULL; + shape->name= name; + shape->primary= shape->approx= NULL; + geom->num_shapes++; + return shape; +} + +XkbKeyPtr +XkbAddGeomKey(XkbRowPtr row) +{ +XkbKeyPtr key; + if (!row) + return NULL; + if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success)) + return NULL; + key= &row->keys[row->num_keys++]; + bzero(key,sizeof(XkbKeyRec)); + return key; +} + +XkbRowPtr +XkbAddGeomRow(XkbSectionPtr section,int sz_keys) +{ +XkbRowPtr row; + + if ((!section)||(sz_keys<0)) + return NULL; + if ((section->num_rows>=section->sz_rows)&& + (_XkbAllocRows(section,1)!=Success)) + return NULL; + row= §ion->rows[section->num_rows]; + bzero(row,sizeof(XkbRowRec)); + if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success)) + return NULL; + section->num_rows++; + return row; +} + +XkbSectionPtr +XkbAddGeomSection( XkbGeometryPtr geom, + Atom name, + int sz_rows, + int sz_doodads, + int sz_over) +{ +register int i; +XkbSectionPtr section; + + if ((!geom)||(name==None)||(sz_rows<0)) + return NULL; + for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) { + if (section->name!=name) + continue; + if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))|| + ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))|| + ((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success))) + return NULL; + return section; + } + if ((geom->num_sections>=geom->sz_sections)&& + (_XkbAllocSections(geom,1)!=Success)) + return NULL; + section= &geom->sections[geom->num_sections]; + if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success)) + return NULL; + if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) { + if (section->rows) { + _XkbFree(section->rows); + section->rows= NULL; + section->sz_rows= section->num_rows= 0; + } + return NULL; + } + section->name= name; + geom->num_sections++; + return section; +} + +XkbDoodadPtr +XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name) +{ +XkbDoodadPtr old,doodad; +register int i,nDoodads; + + if ((!geom)||(name==None)) + return NULL; + if ((section!=NULL)&&(section->num_doodads>0)) { + old= section->doodads; + nDoodads= section->num_doodads; + } + else { + old= geom->doodads; + nDoodads= geom->num_doodads; + } + for (i=0,doodad=old;i<nDoodads;i++,doodad++) { + if (doodad->any.name==name) + return doodad; + } + if (section) { + if ((section->num_doodads>=geom->sz_doodads)&& + (_XkbAllocDoodads(section,1)!=Success)) { + return NULL; + } + doodad= §ion->doodads[section->num_doodads++]; + } + else { + if ((geom->num_doodads>=geom->sz_doodads)&& + (_XkbAllocDoodads(geom,1)!=Success)) + return NULL; + doodad= &geom->doodads[geom->num_doodads++]; + } + bzero(doodad,sizeof(XkbDoodadRec)); + doodad->any.name= name; + return doodad; +} + +XkbOverlayKeyPtr +XkbAddGeomOverlayKey( XkbOverlayPtr overlay, + XkbOverlayRowPtr row, + char * over, + char * under) +{ +register int i; +XkbOverlayKeyPtr key; +XkbSectionPtr section; +XkbRowPtr row_under; +Bool found; + + if ((!overlay)||(!row)||(!over)||(!under)) + return NULL; + section= overlay->section_under; + if (row->row_under>=section->num_rows) + return NULL; + row_under= §ion->rows[row->row_under]; + for (i=0,found=False;i<row_under->num_keys;i++) { + if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) { + found= True; + break; + } + } + if (!found) + return NULL; + if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success)) + return NULL; + key= &row->keys[row->num_keys]; + strncpy(key->under.name,under,XkbKeyNameLength); + strncpy(key->over.name,over,XkbKeyNameLength); + row->num_keys++; + return key; +} + +XkbOverlayRowPtr +XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys) +{ +register int i; +XkbOverlayRowPtr row; + + if ((!overlay)||(sz_keys<0)) + return NULL; + if (row_under>=overlay->section_under->num_rows) + return NULL; + for (i=0;i<overlay->num_rows;i++) { + if (overlay->rows[i].row_under==row_under) { + row= &overlay->rows[i]; + if ((row->sz_keys<sz_keys)&& + (_XkbAllocOverlayKeys(row,sz_keys)!=Success)) { + return NULL; + } + return &overlay->rows[i]; + } + } + if ((overlay->num_rows>=overlay->sz_rows)&& + (_XkbAllocOverlayRows(overlay,1)!=Success)) + return NULL; + row= &overlay->rows[overlay->num_rows]; + bzero(row,sizeof(XkbOverlayRowRec)); + if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success)) + return NULL; + row->row_under= row_under; + overlay->num_rows++; + return row; +} + +XkbOverlayPtr +XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows) +{ +register int i; +XkbOverlayPtr overlay; + + if ((!section)||(name==None)||(sz_rows==0)) + return NULL; + + for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) { + if (overlay->name==name) { + if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success)) + return NULL; + return overlay; + } + } + if ((section->num_overlays>=section->sz_overlays)&& + (_XkbAllocOverlays(section,1)!=Success)) + return NULL; + overlay= §ion->overlays[section->num_overlays]; + if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success)) + return NULL; + overlay->name= name; + overlay->section_under= section; + section->num_overlays++; + return overlay; +} diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c index c7a2fe9d3..e97d2f444 100644 --- a/libX11/src/xlibi18n/XDefaultIMIF.c +++ b/libX11/src/xlibi18n/XDefaultIMIF.c @@ -1,471 +1,469 @@ -/*
-Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions: The above copyright notice and this
-permission notice shall be included in all copies or substantial
-portions of the Software.
-
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-X Window System is a trademark of The Open Group
-
-OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
-logo, LBX, X Window System, and Xinerama are trademarks of the Open
-Group. All other trademarks and registered trademarks mentioned herein
-are the property of their respective owners. No right, title or
-interest in or to any trademark, service mark, logo or trade name of
-Sun Microsystems, Inc. or its licensors is granted.
-
-*/
-/*
- * Copyright 2000 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcGeneric.h"
-
-#ifndef MAXINT
-#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1))
-#endif /* !MAXINT */
-
-typedef struct _StaticXIM *StaticXIM;
-
-typedef struct _XIMStaticXIMRec {
- /* for CT => MB,WC converter */
- XlcConv ctom_conv;
- XlcConv ctow_conv;
-} XIMStaticXIMRec;
-
-typedef enum {
- CREATE_IC = 1,
- SET_ICVAL = 2,
- GET_ICVAL = 3
-} XICOp_t;
-
-typedef struct _StaticXIM {
- XIMMethods methods;
- XIMCoreRec core;
- XIMStaticXIMRec *private;
-} StaticXIMRec;
-
-static Status _CloseIM(
- XIM
-);
-
-static char *_SetIMValues(
- XIM, XIMArg *
-);
-
-static char *_GetIMValues(
- XIM, XIMArg*
-);
-
-static XIC _CreateIC(
- XIM, XIMArg*
-);
-
-static _Xconst XIMMethodsRec local_im_methods = {
- _CloseIM, /* close */
- _SetIMValues, /* set_values */
- _GetIMValues, /* get_values */
- _CreateIC, /* create_ic */
- NULL, /* ctstombs */
- NULL /* ctstowcs */
-};
-
-static void _DestroyIC(
- XIC
-);
-static void _SetFocus(
- XIC
-);
-static void _UnsetFocus(
- XIC
-);
-static char* _SetICValues(
- XIC, XIMArg *
-);
-static char* _GetICValues(
- XIC, XIMArg *
-);
-static char *_MbReset(
- XIC
-);
-static wchar_t *_WcReset(
- XIC
-);
-static int _MbLookupString(
- XIC, XKeyEvent *, char *, int, KeySym *, Status *
-);
-static int _WcLookupString(
- XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status *
-);
-
-static _Xconst XICMethodsRec local_ic_methods = {
- _DestroyIC, /* destroy */
- _SetFocus, /* set_focus */
- _UnsetFocus, /* unset_focus */
- _SetICValues, /* set_values */
- _GetICValues, /* get_values */
- _MbReset, /* mb_reset */
- _WcReset, /* wc_reset */
- NULL, /* utf8_reset */ /* ??? */
- _MbLookupString, /* mb_lookup_string */
- _WcLookupString, /* wc_lookup_string */
- NULL /* utf8_lookup_string */ /* ??? */
-};
-
-XIM
-_XDefaultOpenIM(
- XLCd lcd,
- Display *dpy,
- XrmDatabase rdb,
- char *res_name,
- char *res_class)
-{
- StaticXIM im;
- XIMStaticXIMRec *local_impart;
- XlcConv ctom_conv, ctow_conv;
- int i;
- char *mod;
- char buf[BUFSIZ];
-
- if (!(ctom_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNMultiByte))) {
- return((XIM)NULL);
- }
-
- if (!(ctow_conv = _XlcOpenConverter(lcd,
- XlcNCompoundText, lcd, XlcNWideChar))) {
- return((XIM)NULL);
- }
-
- if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
- return((XIM)NULL);
- }
- if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec)))
- == (XIMStaticXIMRec *)NULL) {
- Xfree(im);
- return((XIM)NULL);
- }
- memset(im, 0, sizeof(StaticXIMRec));
- memset(local_impart, 0, sizeof(XIMStaticXIMRec));
-
- buf[0] = '\0';
- i = 0;
- if ((lcd->core->modifiers) && (*lcd->core->modifiers)) {
-#define MODIFIER "@im="
- mod = strstr(lcd->core->modifiers, MODIFIER);
- if (mod) {
- mod += strlen(MODIFIER);
- while (*mod && *mod != '@' && i < BUFSIZ - 1) {
- buf[i++] = *mod++;
- }
- buf[i] = '\0';
- }
- }
-#undef MODIFIER
- if ((im->core.im_name = Xmalloc(i+1)) == NULL)
- goto Error2;
- strcpy(im->core.im_name, buf);
-
- im->private = local_impart;
- im->methods = (XIMMethods)&local_im_methods;
- im->core.lcd = lcd;
- im->core.ic_chain = (XIC)NULL;
- im->core.display = dpy;
- im->core.rdb = rdb;
- im->core.res_name = NULL;
- im->core.res_class = NULL;
-
- local_impart->ctom_conv = ctom_conv;
- local_impart->ctow_conv = ctow_conv;
-
- if ((res_name != NULL) && (*res_name != '\0')){
- im->core.res_name = (char *)Xmalloc(strlen(res_name)+1);
- strcpy(im->core.res_name,res_name);
- }
- if ((res_class != NULL) && (*res_class != '\0')){
- im->core.res_class = (char *)Xmalloc(strlen(res_class)+1);
- strcpy(im->core.res_class,res_class);
- }
-
- return (XIM)im;
-Error2 :
- Xfree(im->private);
- Xfree(im->core.im_name);
- Xfree(im);
- _XlcCloseConverter(ctom_conv);
- _XlcCloseConverter(ctow_conv);
- return(NULL);
-}
-
-static Status
-_CloseIM(XIM xim)
-{
- StaticXIM im = (StaticXIM)xim;
- _XlcCloseConverter(im->private->ctom_conv);
- _XlcCloseConverter(im->private->ctow_conv);
- XFree(im->private);
- XFree(im->core.im_name);
- if (im->core.res_name) XFree(im->core.res_name);
- if (im->core.res_class) XFree(im->core.res_class);
- return 1; /*bugID 4163122*/
-}
-
-static char *
-_SetIMValues(
- XIM xim,
- XIMArg *arg)
-{
- return(arg->name); /* evil */
-}
-
-static char *
-_GetIMValues(
- XIM xim,
- XIMArg *values)
-{
- XIMArg *p;
- XIMStyles *styles;
-
- for (p = values; p->name != NULL; p++) {
- if (strcmp(p->name, XNQueryInputStyle) == 0) {
- styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles));
- *(XIMStyles **)p->value = styles;
- styles->count_styles = 1;
- styles->supported_styles =
- (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle));
- styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
- } else {
- break;
- }
- }
- return (p->name);
-}
-
-static char*
-_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
-{
- XIMArg *p;
- char *return_name = NULL;
-
- for (p = values; p != NULL && p->name != NULL; p++) {
- if(strcmp(p->name, XNInputStyle) == 0) {
- if (mode == CREATE_IC)
- ic->core.input_style = (XIMStyle)p->value;
- } else if (strcmp(p->name, XNClientWindow) == 0) {
- ic->core.client_window = (Window)p->value ;
- } else if (strcmp(p->name, XNFocusWindow) == 0) {
- ic->core.focus_window = (Window)p->value ;
- } else if (strcmp(p->name, XNPreeditAttributes) == 0
- || strcmp(p->name, XNStatusAttributes) == 0) {
- return_name = _SetICValueData(ic, (XIMArg*)p->value, mode);
- if (return_name) break;
- } else {
- return_name = p->name;
- break;
- }
- }
- return(return_name);
-}
-
-static char*
-_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
-{
- XIMArg *p;
- char *return_name = NULL;
-
- for (p = values; p->name != NULL; p++) {
- if(strcmp(p->name, XNInputStyle) == 0) {
- *((XIMStyle *)(p->value)) = ic->core.input_style;
- } else if (strcmp(p->name, XNClientWindow) == 0) {
- *((Window *)(p->value)) = ic->core.client_window;
- } else if (strcmp(p->name, XNFocusWindow) == 0) {
- *((Window *)(p->value)) = ic->core.focus_window;
- } else if (strcmp(p->name, XNFilterEvents) == 0) {
- *((unsigned long *)(p->value))= ic->core.filter_events;
- } else if (strcmp(p->name, XNPreeditAttributes) == 0
- || strcmp(p->name, XNStatusAttributes) == 0) {
- return_name = _GetICValueData(ic, (XIMArg*)p->value, mode);
- if (return_name) break;
- } else {
- return_name = p->name;
- break;
- }
- }
- return(return_name);
-}
-
-static XIC
-_CreateIC(XIM im, XIMArg *arg)
-{
- XIC ic;
-
- if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
- return ((XIC)NULL);
- }
- memset(ic, 0, sizeof(XICRec));
-
- ic->methods = (XICMethods)&local_ic_methods;
- ic->core.im = im;
- ic->core.filter_events = KeyPressMask;
-
- if (_SetICValueData(ic, arg, CREATE_IC) != NULL)
- goto err_return;
- if (!(ic->core.input_style))
- goto err_return;
-
- return (XIC)ic;
-err_return:
- XFree(ic);
- return ((XIC)NULL);
-}
-
-static void
-_DestroyIC(XIC ic)
-{
-/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already.
- if(ic)
- XFree(ic); */
-}
-
-static void
-_SetFocus(XIC ic)
-{
-}
-
-static void
-_UnsetFocus(XIC ic)
-{
-}
-
-static char*
-_SetICValues(XIC ic, XIMArg *args)
-{
- char *ret = NULL;
- if (!ic) {
- return (args->name);
- }
- ret = _SetICValueData(ic, args, SET_ICVAL);
- return(ret);
-}
-
-static char*
-_GetICValues(XIC ic, XIMArg *args)
-{
- char *ret = NULL;
- if (!ic) {
- return (args->name);
- }
- ret = _GetICValueData(ic, args, GET_ICVAL);
- return(ret);
-}
-
-static char *
-_MbReset(XIC xic)
-{
- return(NULL);
-}
-
-static wchar_t *
-_WcReset(XIC xic)
-{
- return(NULL);
-}
-
-static int
-_MbLookupString(
- XIC xic,
- XKeyEvent *ev,
- char * buffer,
- int bytes,
- KeySym *keysym,
- Status *status)
-{
- XComposeStatus NotSupportedYet ;
- int length;
-
- length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet);
-
- if (keysym && *keysym == NoSymbol){
- *status = XLookupNone;
- } else if (length > 0) {
- *status = XLookupBoth;
- } else {
- *status = XLookupKeySym;
- }
- return(length);
-}
-
-static int
-_WcLookupString(
- XIC xic,
- XKeyEvent *ev,
- wchar_t * buffer,
- int wlen,
- KeySym *keysym,
- Status *status)
-{
- XComposeStatus NotSupportedYet ;
- int length;
- /* In single-byte, mb_len = wc_len */
- char *mb_buf = (char *)Xmalloc(wlen);
-
- length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet);
-
- if (keysym && *keysym == NoSymbol){
- *status = XLookupNone;
- } else if (length > 0) {
- *status = XLookupBoth;
- } else {
- *status = XLookupKeySym;
- }
- mbstowcs(buffer, mb_buf, length);
- XFree(mb_buf);
- return(length);
-}
+/* +Copyright 1985, 1986, 1987, 1991, 1998 The Open Group + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: The above copyright notice and this +permission notice shall be included in all copies or substantial +portions of the Software. + + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE +EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES. + + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +X Window System is a trademark of The Open Group + +OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF +logo, LBX, X Window System, and Xinerama are trademarks of the Open +Group. All other trademarks and registered trademarks mentioned herein +are the property of their respective owners. No right, title or +interest in or to any trademark, service mark, logo or trade name of +Sun Microsystems, Inc. or its licensors is granted. + +*/ +/* + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <stdio.h> +#include "Xlibint.h" +#include "Xlcint.h" +#include "XlcGeneric.h" + +#ifndef MAXINT +#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1)) +#endif /* !MAXINT */ + +typedef struct _StaticXIM *StaticXIM; + +typedef struct _XIMStaticXIMRec { + /* for CT => MB,WC converter */ + XlcConv ctom_conv; + XlcConv ctow_conv; +} XIMStaticXIMRec; + +typedef enum { + CREATE_IC = 1, + SET_ICVAL = 2, + GET_ICVAL = 3 +} XICOp_t; + +typedef struct _StaticXIM { + XIMMethods methods; + XIMCoreRec core; + XIMStaticXIMRec *private; +} StaticXIMRec; + +static Status _CloseIM( + XIM +); + +static char *_SetIMValues( + XIM, XIMArg * +); + +static char *_GetIMValues( + XIM, XIMArg* +); + +static XIC _CreateIC( + XIM, XIMArg* +); + +static _Xconst XIMMethodsRec local_im_methods = { + _CloseIM, /* close */ + _SetIMValues, /* set_values */ + _GetIMValues, /* get_values */ + _CreateIC, /* create_ic */ + NULL, /* ctstombs */ + NULL /* ctstowcs */ +}; + +static void _DestroyIC( + XIC +); +static void _SetFocus( + XIC +); +static void _UnsetFocus( + XIC +); +static char* _SetICValues( + XIC, XIMArg * +); +static char* _GetICValues( + XIC, XIMArg * +); +static char *_MbReset( + XIC +); +static wchar_t *_WcReset( + XIC +); +static int _MbLookupString( + XIC, XKeyEvent *, char *, int, KeySym *, Status * +); +static int _WcLookupString( + XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status * +); + +static _Xconst XICMethodsRec local_ic_methods = { + _DestroyIC, /* destroy */ + _SetFocus, /* set_focus */ + _UnsetFocus, /* unset_focus */ + _SetICValues, /* set_values */ + _GetICValues, /* get_values */ + _MbReset, /* mb_reset */ + _WcReset, /* wc_reset */ + NULL, /* utf8_reset */ /* ??? */ + _MbLookupString, /* mb_lookup_string */ + _WcLookupString, /* wc_lookup_string */ + NULL /* utf8_lookup_string */ /* ??? */ +}; + +XIM +_XDefaultOpenIM( + XLCd lcd, + Display *dpy, + XrmDatabase rdb, + char *res_name, + char *res_class) +{ + StaticXIM im; + XIMStaticXIMRec *local_impart; + XlcConv ctom_conv, ctow_conv; + int i; + char *mod; + char buf[BUFSIZ]; + + if (!(ctom_conv = _XlcOpenConverter(lcd, + XlcNCompoundText, lcd, XlcNMultiByte))) { + return((XIM)NULL); + } + + if (!(ctow_conv = _XlcOpenConverter(lcd, + XlcNCompoundText, lcd, XlcNWideChar))) { + return((XIM)NULL); + } + + if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) { + return((XIM)NULL); + } + if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec))) + == (XIMStaticXIMRec *)NULL) { + Xfree(im); + return((XIM)NULL); + } + memset(im, 0, sizeof(StaticXIMRec)); + memset(local_impart, 0, sizeof(XIMStaticXIMRec)); + + buf[0] = '\0'; + i = 0; + if ((lcd->core->modifiers) && (*lcd->core->modifiers)) { +#define MODIFIER "@im=" + mod = strstr(lcd->core->modifiers, MODIFIER); + if (mod) { + mod += strlen(MODIFIER); + while (*mod && *mod != '@' && i < BUFSIZ - 1) { + buf[i++] = *mod++; + } + buf[i] = '\0'; + } + } +#undef MODIFIER + if ((im->core.im_name = Xmalloc(i+1)) == NULL) + goto Error2; + strcpy(im->core.im_name, buf); + + im->private = local_impart; + im->methods = (XIMMethods)&local_im_methods; + im->core.lcd = lcd; + im->core.ic_chain = (XIC)NULL; + im->core.display = dpy; + im->core.rdb = rdb; + im->core.res_name = NULL; + im->core.res_class = NULL; + + local_impart->ctom_conv = ctom_conv; + local_impart->ctow_conv = ctow_conv; + + if ((res_name != NULL) && (*res_name != '\0')){ + im->core.res_name = strdup(res_name); + } + if ((res_class != NULL) && (*res_class != '\0')){ + im->core.res_class = strdup(res_class); + } + + return (XIM)im; +Error2 : + Xfree(im->private); + Xfree(im->core.im_name); + Xfree(im); + _XlcCloseConverter(ctom_conv); + _XlcCloseConverter(ctow_conv); + return(NULL); +} + +static Status +_CloseIM(XIM xim) +{ + StaticXIM im = (StaticXIM)xim; + _XlcCloseConverter(im->private->ctom_conv); + _XlcCloseConverter(im->private->ctow_conv); + XFree(im->private); + XFree(im->core.im_name); + if (im->core.res_name) XFree(im->core.res_name); + if (im->core.res_class) XFree(im->core.res_class); + return 1; /*bugID 4163122*/ +} + +static char * +_SetIMValues( + XIM xim, + XIMArg *arg) +{ + return(arg->name); /* evil */ +} + +static char * +_GetIMValues( + XIM xim, + XIMArg *values) +{ + XIMArg *p; + XIMStyles *styles; + + for (p = values; p->name != NULL; p++) { + if (strcmp(p->name, XNQueryInputStyle) == 0) { + styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles)); + *(XIMStyles **)p->value = styles; + styles->count_styles = 1; + styles->supported_styles = + (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle)); + styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone); + } else { + break; + } + } + return (p->name); +} + +static char* +_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode) +{ + XIMArg *p; + char *return_name = NULL; + + for (p = values; p != NULL && p->name != NULL; p++) { + if(strcmp(p->name, XNInputStyle) == 0) { + if (mode == CREATE_IC) + ic->core.input_style = (XIMStyle)p->value; + } else if (strcmp(p->name, XNClientWindow) == 0) { + ic->core.client_window = (Window)p->value ; + } else if (strcmp(p->name, XNFocusWindow) == 0) { + ic->core.focus_window = (Window)p->value ; + } else if (strcmp(p->name, XNPreeditAttributes) == 0 + || strcmp(p->name, XNStatusAttributes) == 0) { + return_name = _SetICValueData(ic, (XIMArg*)p->value, mode); + if (return_name) break; + } else { + return_name = p->name; + break; + } + } + return(return_name); +} + +static char* +_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode) +{ + XIMArg *p; + char *return_name = NULL; + + for (p = values; p->name != NULL; p++) { + if(strcmp(p->name, XNInputStyle) == 0) { + *((XIMStyle *)(p->value)) = ic->core.input_style; + } else if (strcmp(p->name, XNClientWindow) == 0) { + *((Window *)(p->value)) = ic->core.client_window; + } else if (strcmp(p->name, XNFocusWindow) == 0) { + *((Window *)(p->value)) = ic->core.focus_window; + } else if (strcmp(p->name, XNFilterEvents) == 0) { + *((unsigned long *)(p->value))= ic->core.filter_events; + } else if (strcmp(p->name, XNPreeditAttributes) == 0 + || strcmp(p->name, XNStatusAttributes) == 0) { + return_name = _GetICValueData(ic, (XIMArg*)p->value, mode); + if (return_name) break; + } else { + return_name = p->name; + break; + } + } + return(return_name); +} + +static XIC +_CreateIC(XIM im, XIMArg *arg) +{ + XIC ic; + + if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) { + return ((XIC)NULL); + } + memset(ic, 0, sizeof(XICRec)); + + ic->methods = (XICMethods)&local_ic_methods; + ic->core.im = im; + ic->core.filter_events = KeyPressMask; + + if (_SetICValueData(ic, arg, CREATE_IC) != NULL) + goto err_return; + if (!(ic->core.input_style)) + goto err_return; + + return (XIC)ic; +err_return: + XFree(ic); + return ((XIC)NULL); +} + +static void +_DestroyIC(XIC ic) +{ +/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already. + if(ic) + XFree(ic); */ +} + +static void +_SetFocus(XIC ic) +{ +} + +static void +_UnsetFocus(XIC ic) +{ +} + +static char* +_SetICValues(XIC ic, XIMArg *args) +{ + char *ret = NULL; + if (!ic) { + return (args->name); + } + ret = _SetICValueData(ic, args, SET_ICVAL); + return(ret); +} + +static char* +_GetICValues(XIC ic, XIMArg *args) +{ + char *ret = NULL; + if (!ic) { + return (args->name); + } + ret = _GetICValueData(ic, args, GET_ICVAL); + return(ret); +} + +static char * +_MbReset(XIC xic) +{ + return(NULL); +} + +static wchar_t * +_WcReset(XIC xic) +{ + return(NULL); +} + +static int +_MbLookupString( + XIC xic, + XKeyEvent *ev, + char * buffer, + int bytes, + KeySym *keysym, + Status *status) +{ + XComposeStatus NotSupportedYet ; + int length; + + length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet); + + if (keysym && *keysym == NoSymbol){ + *status = XLookupNone; + } else if (length > 0) { + *status = XLookupBoth; + } else { + *status = XLookupKeySym; + } + return(length); +} + +static int +_WcLookupString( + XIC xic, + XKeyEvent *ev, + wchar_t * buffer, + int wlen, + KeySym *keysym, + Status *status) +{ + XComposeStatus NotSupportedYet ; + int length; + /* In single-byte, mb_len = wc_len */ + char *mb_buf = (char *)Xmalloc(wlen); + + length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet); + + if (keysym && *keysym == NoSymbol){ + *status = XLookupNone; + } else if (length > 0) { + *status = XLookupBoth; + } else { + *status = XLookupKeySym; + } + mbstowcs(buffer, mb_buf, length); + XFree(mb_buf); + return(length); +} diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c index ae8ac79e4..b1dc66df6 100644 --- a/libX11/src/xlibi18n/XDefaultOMIF.c +++ b/libX11/src/xlibi18n/XDefaultOMIF.c @@ -128,10 +128,9 @@ init_fontset( data = XOM_GENERIC(oc->core.om)->data; - font_set = (FontSet) Xmalloc(sizeof(FontSetRec)); + font_set = Xcalloc(1, sizeof(FontSetRec)); if (font_set == NULL) return False; - bzero((char *) font_set, sizeof(FontSetRec)); gen = XOC_GENERIC(oc); gen->font_set = font_set; @@ -217,9 +216,8 @@ check_fontname( fname = prop_fname; } if (data) { - font_set->font_name = (char *) Xmalloc(strlen(fname) + 1); + font_set->font_name = strdup(fname); if (font_set->font_name) { - strcpy(font_set->font_name, fname); found_num++; } } @@ -388,9 +386,7 @@ get_font_name( list = XListFonts(dpy, pattern, 1, &count); if (list != NULL) { - name = (char *) Xmalloc(strlen(*list) + 1); - if (name) - strcpy(name, *list); + name = strdup(*list); XFreeFontNames(list); } else { @@ -460,13 +456,11 @@ parse_fontname( if (font_data == NULL) continue; - font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1); + font_set->font_name = strdup(font_name); + Xfree(font_name); if (font_set->font_name == NULL) { - Xfree(font_name); goto err; } - strcpy(font_set->font_name, font_name); - Xfree(font_name); found_num++; goto found; } @@ -549,11 +543,10 @@ Limit the length of the string copy to prevent stack corruption. } } found: - base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + base_name = strdup(oc->core.base_name_list); if (base_name == NULL) goto err; - strcpy(base_name, oc->core.base_name_list); oc->core.base_name_list = base_name; XFreeStringList(name_list); @@ -1005,10 +998,9 @@ create_oc( { XOC oc; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1126,15 +1118,13 @@ add_data( XOMGenericPart *gen = XOM_GENERIC(om); OMData new; - new = (OMData) Xmalloc(sizeof(OMDataRec)); + new = Xcalloc(1, sizeof(OMDataRec)); if (new == NULL) return NULL; gen->data = new; - bzero((char *) new, sizeof(OMDataRec)); - return new; } @@ -1168,10 +1158,9 @@ init_om( if (data == NULL) return False; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return False; - bzero((char *) font_data, sizeof(FontDataRec) * count); data->font_data = font_data; data->font_data_count = count; @@ -1182,10 +1171,9 @@ This one is fine. *value points to one of the local strings in supported_charset_list[]. */ strcpy(buf, *value++); - font_data->name = (char *) Xmalloc(strlen(buf) + 1); + font_data->name = strdup(buf); if (font_data->name == NULL) return False; - strcpy(font_data->name, buf); } length += strlen(data->font_data->name) + 1; @@ -1237,26 +1225,23 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = (XOMMethods)&methods; om->core.lcd = lcd; om->core.display = dpy; om->core.rdb = rdb; if (res_name) { - om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1); + om->core.res_name = strdup(res_name); if (om->core.res_name == NULL) goto err; - strcpy(om->core.res_name, res_name); } if (res_class) { - om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1); + om->core.res_class = strdup(res_class); if (om->core.res_class == NULL) goto err; - strcpy(om->core.res_class, res_class); } if (om_resources[0].xrm_name == NULLQUARK) diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c index 58e9ade87..75e193c05 100644 --- a/libX11/src/xlibi18n/XlcDL.c +++ b/libX11/src/xlibi18n/XlcDL.c @@ -1,652 +1,612 @@ -/*
-Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions: The above copyright notice and this
-permission notice shall be included in all copies or substantial
-portions of the Software.
-
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-X Window System is a trademark of The Open Group
-
-OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
-logo, LBX, X Window System, and Xinerama are trademarks of the Open
-Group. All other trademarks and registered trademarks mentioned herein
-are the property of their respective owners. No right, title or
-interest in or to any trademark, service mark, logo or trade name of
-Sun Microsystems, Inc. or its licensors is granted.
-
-*/
-/*
- * Copyright 2000 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#else
-# if defined(hpux)
-# define HAVE_DL_H
-# else
-# define HAVE_DLFCN_H
-# endif
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_DL_H
-#include <dl.h>
-#endif
-
-#ifdef HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-#include <ctype.h>
-
-#include "Xlibint.h"
-#include "XlcPublic.h"
-#include "XlcPubI.h"
-
-#if defined(_LP64) && defined(__sparcv9)
-# define _MACH64_NAME "sparcv9"
-#else
-# undef _MACH64_NAME
-#endif /* defined(_LP64) && defined(__sparcv9) */
-
-#ifdef _MACH64_NAME
-# define _MACH64_NAME_LEN (sizeof (_MACH64_NAME) - 1)
-#endif
-
-#define XI18N_DLREL 2
-
-#define iscomment(ch) ((ch) == '\0' || (ch) == '#')
-
-typedef enum {
- XLC_OBJECT,
- XIM_OBJECT,
- XOM_OBJECT
-} XI18NDLType;
-
-typedef struct {
- XI18NDLType type;
- int locale_name_len;
- char *locale_name;
- char *dl_name;
- char *open;
- char *im_register;
- char *im_unregister;
- int dl_release;
- unsigned int refcount;
-#if defined(hpux)
- shl_t dl_module;
-#else
- void *dl_module;
-#endif
-} XI18NObjectsListRec, *XI18NObjectsList;
-
-#define OBJECT_INIT_LEN 8
-#define OBJECT_INC_LEN 4
-static int lc_len = 0;
-static XI18NObjectsListRec *xi18n_objects_list = NULL;
-static int lc_count = 0;
-
-static int
-parse_line(char *line, char **argv, int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (iscomment(*p)){
- break;
- }
- argv[argc++] = p;
- while (!isspace(*p)) {
- ++p;
- }
- if (iscomment(*p)) {
- break;
- }
- *p++ = '\0';
- }
- return argc;
-}
-
-static char *
-strdup_with_underscore(const char *symbol)
-{
- char *result;
-
- if ((result = malloc(strlen(symbol) + 2)) == NULL)
- return NULL;
- result[0] = '_';
- strcpy(result + 1, symbol);
- return result;
-}
-
-#ifndef hpux
-static void *
-try_both_dlsym (void *handle, char *name)
-{
- void *ret;
-
- ret = dlsym (handle, name);
- if (!ret)
- {
- name = strdup_with_underscore (name);
- if (name)
- {
- ret = dlsym (handle, name);
- free (name);
- }
- }
- return ret;
-}
-#endif
-
-static void
-resolve_object(char *path, const char *lc_name)
-{
- char filename[BUFSIZ];
- FILE *fp;
- char buf[BUFSIZ];
-
- if (lc_len == 0) { /* True only for the 1st time */
- lc_len = OBJECT_INIT_LEN;
- xi18n_objects_list = (XI18NObjectsList)
- Xmalloc(sizeof(XI18NObjectsListRec) * lc_len);
- if (!xi18n_objects_list) return;
- }
-/*
-1266793
-Limit the length of path to prevent stack buffer corruption.
- sprintf(filename, "%s/%s", path, "XI18N_OBJS");
-*/
- sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS");
- fp = fopen(filename, "r");
- if (fp == (FILE *)NULL){
- return;
- }
-
- while (fgets(buf, BUFSIZ, fp) != NULL){
- char *p = buf;
- int n;
- char *args[6];
- while (isspace(*p)){
- ++p;
- }
- if (iscomment(*p)){
- continue;
- }
-
- if (lc_count == lc_len) {
- lc_len += OBJECT_INC_LEN;
- xi18n_objects_list = (XI18NObjectsList)
- Xrealloc(xi18n_objects_list,
- sizeof(XI18NObjectsListRec) * lc_len);
- if (!xi18n_objects_list) return;
- }
- n = parse_line(p, args, 6);
-
- if (n == 3 || n == 5) {
- if (!strcmp(args[0], "XLC")){
- xi18n_objects_list[lc_count].type = XLC_OBJECT;
- } else if (!strcmp(args[0], "XOM")){
- xi18n_objects_list[lc_count].type = XOM_OBJECT;
- } else if (!strcmp(args[0], "XIM")){
- xi18n_objects_list[lc_count].type = XIM_OBJECT;
- }
- xi18n_objects_list[lc_count].dl_name = strdup(args[1]);
- xi18n_objects_list[lc_count].open = strdup(args[2]);
- xi18n_objects_list[lc_count].dl_release = XI18N_DLREL;
- xi18n_objects_list[lc_count].locale_name = strdup(lc_name);
- xi18n_objects_list[lc_count].refcount = 0;
- xi18n_objects_list[lc_count].dl_module = (void*)NULL;
- if (n == 5) {
- xi18n_objects_list[lc_count].im_register = strdup(args[3]);
- xi18n_objects_list[lc_count].im_unregister = strdup(args[4]);
- } else {
- xi18n_objects_list[lc_count].im_register = NULL;
- xi18n_objects_list[lc_count].im_unregister = NULL;
- }
- lc_count++;
- }
- }
- fclose(fp);
-}
-
-static char*
-__lc_path(const char *dl_name, const char *lc_dir)
-{
- char *path;
- size_t len;
-
- /*
- * reject this for possible security issue
- */
- if (strstr (dl_name, "../"))
- return NULL;
-
-#if defined (_LP64) && defined (_MACH64_NAME)
- len = (lc_dir ? strlen(lc_dir) : 0 ) +
- (dl_name ? strlen(dl_name) : 0) + _MACH64_NAME_LEN + 10;
- path = Xmalloc(len + 1);
-
- if (strchr(dl_name, '/') != NULL) {
- char *tmp = strdup(dl_name);
- char *dl_dir, *dl_file;
- char *slash_p;
- slash_p = strchr(tmp, '/');
- *slash_p = '\0';
- dl_dir = tmp;
- dl_file = ++slash_p;
-
- slash_p = strrchr(lc_dir, '/');
- *slash_p = '\0';
- strcpy(path, lc_dir); strcat(path, "/");
- strcat(path, dl_dir); strcat(path, "/");
- strcat(path, _MACH64_NAME); strcat(path, "/");
- strcat(path, dl_file); strcat(path, ".so.2");
-
- *slash_p = '/';
- Xfree(tmp);
- } else {
- strcpy(path, lc_dir); strcat(path, "/");
- strcat(path, _MACH64_NAME); strcat(path, "/");
- strcat(path, dl_name); strcat(path, ".so.2");
- }
-#else
- len = (lc_dir ? strlen(lc_dir) : 0 ) +
- (dl_name ? strlen(dl_name) : 0) + 10;
-#if defined POSTLOCALELIBDIR
- len += (strlen(POSTLOCALELIBDIR) + 1);
-#endif
- path = Xmalloc(len + 1);
-
- if (strchr(dl_name, '/') != NULL) {
- char *slash_p;
- slash_p = strrchr(lc_dir, '/');
- *slash_p = '\0';
- strcpy(path, lc_dir); strcat(path, "/");
-#if defined POSTLOCALELIBDIR
- strcat(path, POSTLOCALELIBDIR); strcat(path, "/");
-#endif
- strcat(path, dl_name); strcat(path, ".so.2");
- *slash_p = '/';
- } else {
- strcpy(path, lc_dir); strcat(path, "/");
-#if defined POSTLOCALELIBDIR
- strcat(path, POSTLOCALELIBDIR); strcat(path, "/");
-#endif
- strcat(path, dl_name); strcat(path, ".so.2");
- }
-#endif
- return path;
-}
-
-/* We reference count dlopen() and dlclose() of modules; unfortunately,
- * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly
- * call the close method of the object, we leak a reference count every
- * time we open then close a module. Fixing this would require
- * either creating proxy objects or hooks for close_im/close_om
- * in XLCd
- */
-static Bool
-open_object(
- XI18NObjectsList object,
- char *lc_dir)
-{
- char *path;
-
- if (object->refcount == 0) {
- path = __lc_path(object->dl_name, lc_dir);
- if (!path)
- return False;
-#if defined(hpux)
- object->dl_module = shl_load(path, BIND_DEFERRED, 0L);
-#else
- object->dl_module = dlopen(path, RTLD_LAZY);
-#endif
- Xfree(path);
-
- if (!object->dl_module)
- return False;
- }
-
- object->refcount++;
- return True;
-}
-
-static void *
-fetch_symbol(
- XI18NObjectsList object,
- char *symbol)
-{
- void *result = NULL;
-#if defined(hpux)
- int getsyms_cnt, i;
- struct shl_symbol *symbols;
-#endif
-
- if (symbol == NULL)
- return NULL;
-
-#if defined(hpux)
- getsyms_cnt = shl_getsymbols(object->dl_module, TYPE_PROCEDURE,
- EXPORT_SYMBOLS, malloc, &symbols);
-
- for(i=0; i<getsyms_cnt; i++) {
- if(!strcmp(symbols[i].name, symbol)) {
- result = symbols[i].value;
- break;
- }
- }
-
- if(getsyms_cnt > 0) {
- free(symbols);
- }
-#else
- result = try_both_dlsym(object->dl_module, symbol);
-#endif
-
- return result;
-}
-
-static void
-close_object(XI18NObjectsList object)
-{
- object->refcount--;
- if (object->refcount == 0)
- {
-#if defined(hpux)
- shl_unload(object->dl_module);
-#else
- dlclose(object->dl_module);
-#endif
- object->dl_module = NULL;
- }
-}
-
-
-typedef XLCd (*dynamicLoadProc)(const char *);
-
-XLCd
-_XlcDynamicLoad(const char *lc_name)
-{
- XLCd lcd = (XLCd)NULL;
- dynamicLoadProc lc_loader = (dynamicLoadProc)NULL;
- int count;
- XI18NObjectsList objects_list;
- char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE];
-
- if (lc_name == NULL) return (XLCd)NULL;
-
- if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL)
- return (XLCd)NULL;
- if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL)
- return (XLCd)NULL;
-
- resolve_object(lc_dir, lc_name);
- resolve_object(lc_lib_dir, lc_name);
-
- objects_list = xi18n_objects_list;
- count = lc_count;
- for (; count-- > 0; objects_list++) {
- if (objects_list->type != XLC_OBJECT ||
- strcmp(objects_list->locale_name, lc_name)) continue;
- if (!open_object (objects_list, lc_dir) && \
- !open_object (objects_list, lc_lib_dir))
- continue;
-
- lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open);
- if (!lc_loader) continue;
- lcd = (*lc_loader)(lc_name);
- if (lcd != (XLCd)NULL) {
- break;
- }
-
- close_object (objects_list);
- }
- return (XLCd)lcd;
-}
-
-
-typedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *);
-
-static XIM
-_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb,
- char *res_name, char *res_class)
-{
- XIM im = (XIM)NULL;
- char lc_dir[BUFSIZE];
- char *lc_name;
- dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL;
- int count;
- XI18NObjectsList objects_list = xi18n_objects_list;
-
- lc_name = lcd->core->name;
-
- if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0;
-
- count = lc_count;
- for (; count-- > 0; objects_list++) {
- if (objects_list->type != XIM_OBJECT ||
- strcmp(objects_list->locale_name, lc_name)) continue;
-
- if (!open_object (objects_list, lc_dir))
- continue;
-
- im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open);
- if (!im_openIM) continue;
- im = (*im_openIM)(lcd, display, rdb, res_name, res_class);
- if (im != (XIM)NULL) {
- break;
- }
-
- close_object (objects_list);
- }
- return (XIM)im;
-}
-
-typedef Bool (*dynamicRegisterCBProcp)(
- XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer);
-
-static Bool
-_XDynamicRegisterIMInstantiateCallback(
- XLCd lcd,
- Display *display,
- XrmDatabase rdb,
- char *res_name,
- char *res_class,
- XIDProc callback,
- XPointer client_data)
-{
- char lc_dir[BUFSIZE];
- char *lc_name;
- dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL;
- Bool ret_flag = False;
- int count;
- XI18NObjectsList objects_list = xi18n_objects_list;
-#if defined(hpux)
- int getsyms_cnt, i;
- struct shl_symbol *symbols;
-#endif
-
- lc_name = lcd->core->name;
-
- if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False;
-
- count = lc_count;
- for (; count-- > 0; objects_list++) {
- if (objects_list->type != XIM_OBJECT ||
- strcmp(objects_list->locale_name, lc_name)) continue;
-
- if (!open_object (objects_list, lc_dir))
- continue;
- im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list,
- objects_list->im_register);
- if (!im_registerIM) continue;
- ret_flag = (*im_registerIM)(lcd, display, rdb,
- res_name, res_class,
- callback, client_data);
- if (ret_flag) break;
-
- close_object (objects_list);
- }
- return (Bool)ret_flag;
-}
-
-typedef Bool (*dynamicUnregisterProcp)(
- XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer);
-
-static Bool
-_XDynamicUnRegisterIMInstantiateCallback(
- XLCd lcd,
- Display *display,
- XrmDatabase rdb,
- char *res_name,
- char *res_class,
- XIDProc callback,
- XPointer client_data)
-{
- char lc_dir[BUFSIZE];
- char *lc_name;
- dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL;
- Bool ret_flag = False;
- int count;
- XI18NObjectsList objects_list = xi18n_objects_list;
-#if defined(hpux)
- int getsyms_cnt, i;
- struct shl_symbol *symbols;
-#endif
-
- lc_name = lcd->core->name;
- if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False;
-
- count = lc_count;
- for (; count-- > 0; objects_list++) {
- if (objects_list->type != XIM_OBJECT ||
- strcmp(objects_list->locale_name, lc_name)) continue;
-
- if (!objects_list->refcount) /* Must already be opened */
- continue;
-
- im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list,
- objects_list->im_unregister);
-
- if (!im_unregisterIM) continue;
- ret_flag = (*im_unregisterIM)(lcd, display, rdb,
- res_name, res_class,
- callback, client_data);
- if (ret_flag) {
- close_object (objects_list); /* opened in RegisterIMInstantiateCallback */
- break;
- }
- }
- return (Bool)ret_flag;
-}
-
-Bool
-_XInitDynamicIM(XLCd lcd)
-{
- if(lcd == (XLCd)NULL)
- return False;
- lcd->methods->open_im = _XDynamicOpenIM;
- lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback;
- lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback;
- return True;
-}
-
-
-typedef XOM (*dynamicIOpenProcp)(
- XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *);
-
-static XOM
-_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb,
- _Xconst char *res_name, _Xconst char *res_class)
-{
- XOM om = (XOM)NULL;
- int count;
- char lc_dir[BUFSIZE];
- char *lc_name;
- dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL;
- XI18NObjectsList objects_list = xi18n_objects_list;
-#if defined(hpux)
- int getsyms_cnt, i;
- struct shl_symbol *symbols;
-#endif
-
- lc_name = lcd->core->name;
-
- if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0;
-
- count = lc_count;
- for (; count-- > 0; objects_list++) {
- if (objects_list->type != XOM_OBJECT ||
- strcmp(objects_list->locale_name, lc_name)) continue;
- if (!open_object (objects_list, lc_dir))
- continue;
-
- om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open);
- if (!om_openOM) continue;
- om = (*om_openOM)(lcd, display, rdb, res_name, res_class);
- if (om != (XOM)NULL) {
- break;
- }
- close_object(objects_list);
- }
- return (XOM)om;
-}
-
-Bool
-_XInitDynamicOM(XLCd lcd)
-{
- if(lcd == (XLCd)NULL)
- return False;
-
- lcd->methods->open_om = _XDynamicOpenOM;
-
- return True;
-}
+/* +Copyright 1985, 1986, 1987, 1991, 1998 The Open Group + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: The above copyright notice and this +permission notice shall be included in all copies or substantial +portions of the Software. + + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE +EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES. + + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +X Window System is a trademark of The Open Group + +OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF +logo, LBX, X Window System, and Xinerama are trademarks of the Open +Group. All other trademarks and registered trademarks mentioned herein +are the property of their respective owners. No right, title or +interest in or to any trademark, service mark, logo or trade name of +Sun Microsystems, Inc. or its licensors is granted. + +*/ +/* + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#ifdef HAVE_CONFIG_H +# include <config.h> +#else +# if defined(hpux) +# define HAVE_DL_H +# else +# define HAVE_DLFCN_H +# endif +#endif + +#include <stdio.h> + +#ifdef HAVE_DL_H +#include <dl.h> +#endif + +#ifdef HAVE_DLFCN_H +#include <dlfcn.h> +#endif + +#include <ctype.h> + +#include "Xlibint.h" +#include "XlcPublic.h" +#include "XlcPubI.h" + +#define XI18N_DLREL 2 + +#define iscomment(ch) ((ch) == '\0' || (ch) == '#') + +typedef enum { + XLC_OBJECT, + XIM_OBJECT, + XOM_OBJECT +} XI18NDLType; + +typedef struct { + XI18NDLType type; + int locale_name_len; + char *locale_name; + char *dl_name; + char *open; + char *im_register; + char *im_unregister; + int dl_release; + unsigned int refcount; +#if defined(hpux) + shl_t dl_module; +#else + void *dl_module; +#endif +} XI18NObjectsListRec, *XI18NObjectsList; + +#define OBJECT_INIT_LEN 8 +#define OBJECT_INC_LEN 4 +static int lc_len = 0; +static XI18NObjectsListRec *xi18n_objects_list = NULL; +static int lc_count = 0; + +static int +parse_line(char *line, char **argv, int argsize) +{ + int argc = 0; + char *p = line; + + while (argc < argsize) { + while (isspace(*p)) { + ++p; + } + if (iscomment(*p)){ + break; + } + argv[argc++] = p; + while (!isspace(*p)) { + ++p; + } + if (iscomment(*p)) { + break; + } + *p++ = '\0'; + } + return argc; +} + +static char * +strdup_with_underscore(const char *symbol) +{ + char *result; + + if ((result = malloc(strlen(symbol) + 2)) == NULL) + return NULL; + result[0] = '_'; + strcpy(result + 1, symbol); + return result; +} + +#ifndef hpux +static void * +try_both_dlsym (void *handle, char *name) +{ + void *ret; + + ret = dlsym (handle, name); + if (!ret) + { + name = strdup_with_underscore (name); + if (name) + { + ret = dlsym (handle, name); + free (name); + } + } + return ret; +} +#endif + +static void +resolve_object(char *path, const char *lc_name) +{ + char filename[BUFSIZ]; + FILE *fp; + char buf[BUFSIZ]; + + if (lc_len == 0) { /* True only for the 1st time */ + lc_len = OBJECT_INIT_LEN; + xi18n_objects_list = (XI18NObjectsList) + Xmalloc(sizeof(XI18NObjectsListRec) * lc_len); + if (!xi18n_objects_list) return; + } +/* +1266793 +Limit the length of path to prevent stack buffer corruption. + sprintf(filename, "%s/%s", path, "XI18N_OBJS"); +*/ + sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS"); + fp = fopen(filename, "r"); + if (fp == (FILE *)NULL){ + return; + } + + while (fgets(buf, BUFSIZ, fp) != NULL){ + char *p = buf; + int n; + char *args[6]; + while (isspace(*p)){ + ++p; + } + if (iscomment(*p)){ + continue; + } + + if (lc_count == lc_len) { + lc_len += OBJECT_INC_LEN; + xi18n_objects_list = (XI18NObjectsList) + Xrealloc(xi18n_objects_list, + sizeof(XI18NObjectsListRec) * lc_len); + if (!xi18n_objects_list) return; + } + n = parse_line(p, args, 6); + + if (n == 3 || n == 5) { + if (!strcmp(args[0], "XLC")){ + xi18n_objects_list[lc_count].type = XLC_OBJECT; + } else if (!strcmp(args[0], "XOM")){ + xi18n_objects_list[lc_count].type = XOM_OBJECT; + } else if (!strcmp(args[0], "XIM")){ + xi18n_objects_list[lc_count].type = XIM_OBJECT; + } + xi18n_objects_list[lc_count].dl_name = strdup(args[1]); + xi18n_objects_list[lc_count].open = strdup(args[2]); + xi18n_objects_list[lc_count].dl_release = XI18N_DLREL; + xi18n_objects_list[lc_count].locale_name = strdup(lc_name); + xi18n_objects_list[lc_count].refcount = 0; + xi18n_objects_list[lc_count].dl_module = (void*)NULL; + if (n == 5) { + xi18n_objects_list[lc_count].im_register = strdup(args[3]); + xi18n_objects_list[lc_count].im_unregister = strdup(args[4]); + } else { + xi18n_objects_list[lc_count].im_register = NULL; + xi18n_objects_list[lc_count].im_unregister = NULL; + } + lc_count++; + } + } + fclose(fp); +} + +static char* +__lc_path(const char *dl_name, const char *lc_dir) +{ + char *path; + size_t len; + + /* + * reject this for possible security issue + */ + if (strstr (dl_name, "../")) + return NULL; + + len = (lc_dir ? strlen(lc_dir) : 0 ) + + (dl_name ? strlen(dl_name) : 0) + 10; +#if defined POSTLOCALELIBDIR + len += (strlen(POSTLOCALELIBDIR) + 1); +#endif + path = Xmalloc(len + 1); + + if (strchr(dl_name, '/') != NULL) { + char *slash_p; + slash_p = strrchr(lc_dir, '/'); + *slash_p = '\0'; + strcpy(path, lc_dir); strcat(path, "/"); +#if defined POSTLOCALELIBDIR + strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); +#endif + strcat(path, dl_name); strcat(path, ".so.2"); + *slash_p = '/'; + } else { + strcpy(path, lc_dir); strcat(path, "/"); +#if defined POSTLOCALELIBDIR + strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); +#endif + strcat(path, dl_name); strcat(path, ".so.2"); + } + return path; +} + +/* We reference count dlopen() and dlclose() of modules; unfortunately, + * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly + * call the close method of the object, we leak a reference count every + * time we open then close a module. Fixing this would require + * either creating proxy objects or hooks for close_im/close_om + * in XLCd + */ +static Bool +open_object( + XI18NObjectsList object, + char *lc_dir) +{ + char *path; + + if (object->refcount == 0) { + path = __lc_path(object->dl_name, lc_dir); + if (!path) + return False; +#if defined(hpux) + object->dl_module = shl_load(path, BIND_DEFERRED, 0L); +#else + object->dl_module = dlopen(path, RTLD_LAZY); +#endif + Xfree(path); + + if (!object->dl_module) + return False; + } + + object->refcount++; + return True; +} + +static void * +fetch_symbol( + XI18NObjectsList object, + char *symbol) +{ + void *result = NULL; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + if (symbol == NULL) + return NULL; + +#if defined(hpux) + getsyms_cnt = shl_getsymbols(object->dl_module, TYPE_PROCEDURE, + EXPORT_SYMBOLS, malloc, &symbols); + + for(i=0; i<getsyms_cnt; i++) { + if(!strcmp(symbols[i].name, symbol)) { + result = symbols[i].value; + break; + } + } + + if(getsyms_cnt > 0) { + free(symbols); + } +#else + result = try_both_dlsym(object->dl_module, symbol); +#endif + + return result; +} + +static void +close_object(XI18NObjectsList object) +{ + object->refcount--; + if (object->refcount == 0) + { +#if defined(hpux) + shl_unload(object->dl_module); +#else + dlclose(object->dl_module); +#endif + object->dl_module = NULL; + } +} + + +typedef XLCd (*dynamicLoadProc)(const char *); + +XLCd +_XlcDynamicLoad(const char *lc_name) +{ + XLCd lcd = (XLCd)NULL; + dynamicLoadProc lc_loader = (dynamicLoadProc)NULL; + int count; + XI18NObjectsList objects_list; + char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE]; + + if (lc_name == NULL) return (XLCd)NULL; + + if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL) + return (XLCd)NULL; + if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL) + return (XLCd)NULL; + + resolve_object(lc_dir, lc_name); + resolve_object(lc_lib_dir, lc_name); + + objects_list = xi18n_objects_list; + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XLC_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + if (!open_object (objects_list, lc_dir) && \ + !open_object (objects_list, lc_lib_dir)) + continue; + + lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open); + if (!lc_loader) continue; + lcd = (*lc_loader)(lc_name); + if (lcd != (XLCd)NULL) { + break; + } + + close_object (objects_list); + } + return (XLCd)lcd; +} + + +typedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *); + +static XIM +_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb, + char *res_name, char *res_class) +{ + XIM im = (XIM)NULL; + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL; + int count; + XI18NObjectsList objects_list = xi18n_objects_list; + + lc_name = lcd->core->name; + + if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XIM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + + if (!open_object (objects_list, lc_dir)) + continue; + + im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open); + if (!im_openIM) continue; + im = (*im_openIM)(lcd, display, rdb, res_name, res_class); + if (im != (XIM)NULL) { + break; + } + + close_object (objects_list); + } + return (XIM)im; +} + +typedef Bool (*dynamicRegisterCBProcp)( + XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); + +static Bool +_XDynamicRegisterIMInstantiateCallback( + XLCd lcd, + Display *display, + XrmDatabase rdb, + char *res_name, + char *res_class, + XIDProc callback, + XPointer client_data) +{ + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL; + Bool ret_flag = False; + int count; + XI18NObjectsList objects_list = xi18n_objects_list; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + lc_name = lcd->core->name; + + if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XIM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + + if (!open_object (objects_list, lc_dir)) + continue; + im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list, + objects_list->im_register); + if (!im_registerIM) continue; + ret_flag = (*im_registerIM)(lcd, display, rdb, + res_name, res_class, + callback, client_data); + if (ret_flag) break; + + close_object (objects_list); + } + return (Bool)ret_flag; +} + +typedef Bool (*dynamicUnregisterProcp)( + XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); + +static Bool +_XDynamicUnRegisterIMInstantiateCallback( + XLCd lcd, + Display *display, + XrmDatabase rdb, + char *res_name, + char *res_class, + XIDProc callback, + XPointer client_data) +{ + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL; + Bool ret_flag = False; + int count; + XI18NObjectsList objects_list = xi18n_objects_list; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + lc_name = lcd->core->name; + if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XIM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + + if (!objects_list->refcount) /* Must already be opened */ + continue; + + im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list, + objects_list->im_unregister); + + if (!im_unregisterIM) continue; + ret_flag = (*im_unregisterIM)(lcd, display, rdb, + res_name, res_class, + callback, client_data); + if (ret_flag) { + close_object (objects_list); /* opened in RegisterIMInstantiateCallback */ + break; + } + } + return (Bool)ret_flag; +} + +Bool +_XInitDynamicIM(XLCd lcd) +{ + if(lcd == (XLCd)NULL) + return False; + lcd->methods->open_im = _XDynamicOpenIM; + lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback; + lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback; + return True; +} + + +typedef XOM (*dynamicIOpenProcp)( + XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *); + +static XOM +_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb, + _Xconst char *res_name, _Xconst char *res_class) +{ + XOM om = (XOM)NULL; + int count; + char lc_dir[BUFSIZE]; + char *lc_name; + dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL; + XI18NObjectsList objects_list = xi18n_objects_list; +#if defined(hpux) + int getsyms_cnt, i; + struct shl_symbol *symbols; +#endif + + lc_name = lcd->core->name; + + if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0; + + count = lc_count; + for (; count-- > 0; objects_list++) { + if (objects_list->type != XOM_OBJECT || + strcmp(objects_list->locale_name, lc_name)) continue; + if (!open_object (objects_list, lc_dir)) + continue; + + om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open); + if (!om_openOM) continue; + om = (*om_openOM)(lcd, display, rdb, res_name, res_class); + if (om != (XOM)NULL) { + break; + } + close_object(objects_list); + } + return (XOM)om; +} + +Bool +_XInitDynamicOM(XLCd lcd) +{ + if(lcd == (XLCd)NULL) + return False; + + lcd->methods->open_om = _XDynamicOpenOM; + + return True; +} diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c index 0fa39d869..5d287811c 100644 --- a/libX11/src/xlibi18n/lcCharSet.c +++ b/libX11/src/xlibi18n/lcCharSet.c @@ -176,10 +176,9 @@ _XlcCreateDefaultCharSet( const char *colon; char *tmp; - charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec)); + charset = Xcalloc(1, sizeof(XlcCharSetRec)); if (charset == NULL) return (XlcCharSet) NULL; - bzero((char *) charset, sizeof(XlcCharSetRec)); name_len = strlen(name); ct_sequence_len = strlen(ct_sequence); diff --git a/libX11/src/xlibi18n/lcDB.c b/libX11/src/xlibi18n/lcDB.c index afff17455..97b22ac44 100644 --- a/libX11/src/xlibi18n/lcDB.c +++ b/libX11/src/xlibi18n/lcDB.c @@ -591,26 +591,23 @@ store_to_database( goto err; } - new = (Database)Xmalloc(sizeof(DatabaseRec)); + new = Xcalloc(1, sizeof(DatabaseRec)); if (new == (Database)NULL) { goto err; } - bzero(new, sizeof(DatabaseRec)); - new->category = (char *)Xmalloc(strlen(parse_info.category) + 1); + new->category = strdup(parse_info.category); if (new->category == NULL) { goto err; } - strcpy(new->category, parse_info.category); if (! construct_name(name, sizeof(name))) { goto err; } - new->name = (char *)Xmalloc(strlen(name) + 1); + new->name = strdup(name); if (new->name == NULL) { goto err; } - strcpy(new->name, name); new->next = *db; new->value = parse_info.value; new->value_num = parse_info.value_num; @@ -944,10 +941,9 @@ f_default( case S_NULL: if (parse_info.category != NULL) goto err; - p = (char *)Xmalloc(strlen(wordp) + 1); + p = strdup(wordp); if (p == NULL) goto err; - strcpy(p, wordp); parse_info.category = p; parse_info.pre_state = S_CATEGORY; break; @@ -961,10 +957,9 @@ f_default( break; } } - p = (char *)Xmalloc(strlen(wordp) + 1); + p = strdup(wordp); if (p == NULL) goto err; - strcpy(p, wordp); if (parse_info.name[parse_info.nest_depth] != NULL) { Xfree(parse_info.name[parse_info.nest_depth]); } @@ -1309,10 +1304,9 @@ _XlcCreateLocaleDataBase( return (XPointer)NULL; } n = CountDatabase(database); - lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1)); + lc_db = Xcalloc(n + 1, sizeof(XlcDatabaseRec)); if (lc_db == (XlcDatabase)NULL) goto err; - bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1)); for (p = database, i = 0; p && i < n; p = p->next, ++i) { lc_db[i].category_q = XrmStringToQuark(p->category); lc_db[i].name_q = XrmStringToQuark(p->name); diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c index 18756c1ca..4e4439773 100644 --- a/libX11/src/xlibi18n/lcFile.c +++ b/libX11/src/xlibi18n/lcFile.c @@ -423,10 +423,7 @@ resolve_name( from = args[1], to = args[0]; /* right to left */ } if (! strcmp(from, lc_name)) { - name = Xmalloc(strlen(to) + 1); - if (name != NULL) { - strcpy(name, to); - } + name = strdup(to); break; } } @@ -579,8 +576,7 @@ _XlcResolveLocaleName( if (name == NULL) { /* vendor locale name == Xlocale name, no expansion of alias */ - pub->siname = Xmalloc (strlen (lc_name) + 1); - strcpy (pub->siname, lc_name); + pub->siname = strdup (lc_name); } else { pub->siname = name; } @@ -729,8 +725,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); - last_lc_name = Xmalloc (strlen (lc_name) + 1); - strcpy (last_lc_name, lc_name); + last_lc_name = strdup (lc_name); return dir_name; } @@ -828,8 +823,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); - last_lc_name = Xmalloc (strlen (lc_name) + 1); - strcpy (last_lc_name, lc_name); + last_lc_name = strdup (lc_name); return dir_name; } diff --git a/libX11/src/xlibi18n/lcGeneric.c b/libX11/src/xlibi18n/lcGeneric.c index 688a4cfc4..619cb47f9 100644 --- a/libX11/src/xlibi18n/lcGeneric.c +++ b/libX11/src/xlibi18n/lcGeneric.c @@ -60,15 +60,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec)); + lcd->core = Xcalloc(1, sizeof(XLCdGenericRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdGenericRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) @@ -180,10 +178,9 @@ add_codeset( CodeSet new, *new_list; int num; - new = (CodeSet) Xmalloc(sizeof(CodeSetRec)); + new = Xcalloc(1, sizeof(CodeSetRec)); if (new == NULL) return NULL; - bzero((char *) new, sizeof(CodeSetRec)); if ((num = gen->codeset_num)) new_list = (CodeSet *) Xrealloc(gen->codeset_list, @@ -218,21 +215,18 @@ add_parse_list( unsigned char ch; int num; - str = (char *) Xmalloc(strlen(encoding) + 1); + str = strdup(encoding); if (str == NULL) return False; - strcpy(str, encoding); - new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec)); + new = Xcalloc(1, sizeof(ParseInfoRec)); if (new == NULL) goto err; - bzero((char *) new, sizeof(ParseInfoRec)); if (gen->mb_parse_table == NULL) { - gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */ + gen->mb_parse_table = Xcalloc(1, 256); /* 2^8 */ if (gen->mb_parse_table == NULL) goto err; - bzero((char *) gen->mb_parse_table, 256); } if ((num = gen->mb_parse_list_num)) @@ -468,10 +462,9 @@ read_charset_define( break; } if (new) { - tmp = (char *)Xmalloc(strlen(cset_name)+1); + tmp = strdup(cset_name); if (tmp == NULL) return; - strcpy(tmp,cset_name); charsetd->name = tmp; } /* side */ @@ -527,8 +520,7 @@ read_charset_define( Xfree(charsetd->encoding_name); } */ - tmp = (char *)Xmalloc(strlen(value[0])+1); - strcpy(tmp,value[0]); + tmp = strdup(value[0]); charsetd->encoding_name = tmp; charsetd->xrm_encoding_name = XrmStringToQuark(tmp); } @@ -598,10 +590,9 @@ read_segmentconversion( if (num > 0) { char *tmp; _XlcDbg_printValue(name,value,num); - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = strdup(value[0]); if (tmp == NULL) return; - strcpy(tmp,value[0]); conversion->source_encoding = tmp; conversion->source = srch_charset_define(tmp,&new); } @@ -611,10 +602,9 @@ read_segmentconversion( if (num > 0) { char *tmp; _XlcDbg_printValue(name,value,num); - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = strdup(value[0]); if (tmp == NULL) return; - strcpy(tmp,value[0]); conversion->destination_encoding = tmp; conversion->dest = srch_charset_define(tmp,&new); } @@ -650,12 +640,11 @@ create_ctextseg( ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec)); if (ret == NULL) return NULL; - ret->name = (char *)Xmalloc(strlen(value[0]) + 1); + ret->name = strdup(value[0]); if (ret->name == NULL) { Xfree (ret); return NULL; } - strcpy(ret->name,value[0]); cset_name = (char*) Xmalloc (strlen(ret->name) + 1); if (cset_name == NULL) { Xfree (ret->name); diff --git a/libX11/src/xlibi18n/lcPublic.c b/libX11/src/xlibi18n/lcPublic.c index 2c02f5fba..1b1fb548a 100644 --- a/libX11/src/xlibi18n/lcPublic.c +++ b/libX11/src/xlibi18n/lcPublic.c @@ -80,15 +80,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec)); + lcd->core = Xcalloc(1, sizeof(XLCdPublicRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdPublicRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) @@ -130,10 +128,9 @@ load_public( _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num); str = (num > 0) ? values[0] : "STRING"; - pub->encoding_name = (char*) Xmalloc(strlen(str) + 1); + pub->encoding_name = strdup(str); if (pub->encoding_name == NULL) return False; - strcpy(pub->encoding_name, str); return True; } |