diff options
author | marha <marha@users.sourceforge.net> | 2013-08-26 10:26:21 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-08-26 10:26:21 +0200 |
commit | be8a3ecf0bebc7134452778070cd83b7decf7f71 (patch) | |
tree | e3a5d81a99754c393062ed811bece6e0787e3767 /libX11/src | |
parent | 7403278d95051a554e2cbec3fafdde8ce9c6d200 (diff) | |
parent | 5ee5b91b019005aa27273dff01388a68c12be293 (diff) | |
download | vcxsrv-be8a3ecf0bebc7134452778070cd83b7decf7f71.tar.gz vcxsrv-be8a3ecf0bebc7134452778070cd83b7decf7f71.tar.bz2 vcxsrv-be8a3ecf0bebc7134452778070cd83b7decf7f71.zip |
Merge remote-tracking branch 'origin/released'
* origin/released:
xserver mesa fontconfig libX11 libxcb libxcb/xcb-proto xkeyboard-config git update 26 Aug 2013
Diffstat (limited to 'libX11/src')
95 files changed, 9128 insertions, 9564 deletions
diff --git a/libX11/src/Context.c b/libX11/src/Context.c index 4bb465b1a..8a078713a 100644 --- a/libX11/src/Context.c +++ b/libX11/src/Context.c @@ -126,7 +126,7 @@ static void ResizeTable(DB db) *head = entry; } } - Xfree((char *) otable); + Xfree(otable); } static void _XFreeContextDB(Display *display) @@ -140,12 +140,12 @@ static void _XFreeContextDB(Display *display) for (i = db->mask + 1, pentry = db->table ; --i >= 0; pentry++) { for (entry = *pentry; entry; entry = next) { next = entry->next; - Xfree((char *)entry); + Xfree(entry); } } - Xfree((char *) db->table); + Xfree(db->table); _XFreeMutex(&db->linfo); - Xfree((char *) db); + Xfree(db); } } @@ -186,7 +186,7 @@ int XSaveContext( db->mask = INITHASHMASK; db->table = Xcalloc(db->mask + 1, sizeof(TableEntry)); if (!db->table) { - Xfree((char *)db); + Xfree(db); return XCNOMEM; } db->numentries = 0; @@ -289,7 +289,7 @@ int XDeleteContext(Display *display, XID rid, XContext context) prev = &entry->next) { if (entry->rid == rid && entry->context == context) { *prev = entry->next; - Xfree((char *) entry); + Xfree(entry); db->numentries--; if (db->numentries < db->mask && db->mask > INITHASHMASK) ResizeTable(db); diff --git a/libX11/src/FetchName.c b/libX11/src/FetchName.c index 22bd4607a..8605a6dfc 100644 --- a/libX11/src/FetchName.c +++ b/libX11/src/FetchName.c @@ -58,7 +58,7 @@ Status XFetchName ( *name = (char *)data; return(1); } - if (data) Xfree ((char *)data); + if (data) Xfree (data); *name = NULL; return(0); } @@ -89,7 +89,7 @@ Status XGetIconName ( *icon_name = (char*)data; return(1); } - if (data) Xfree ((char *)data); + if (data) Xfree (data); *icon_name = NULL; return(0); } diff --git a/libX11/src/Font.c b/libX11/src/Font.c index ac1802428..6fadd5877 100644 --- a/libX11/src/Font.c +++ b/libX11/src/Font.c @@ -166,13 +166,13 @@ XFreeFont( #ifdef USE_XF86BIGFONT _XF86BigfontFreeFontMetrics(fs); #else - Xfree ((char *) fs->per_char); + Xfree (fs->per_char); #endif } _XFreeExtData(fs->ext_data); if (fs->properties) - Xfree ((char *) fs->properties); - Xfree ((char *) fs); + Xfree (fs->properties); + Xfree (fs); return 1; } @@ -249,7 +249,7 @@ _XQueryFont ( fs->properties = Xmalloc (pbytes); } if (! fs->properties) { - Xfree((char *) fs); + Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -271,8 +271,8 @@ _XQueryFont ( } } if (! fs->per_char) { - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -493,7 +493,7 @@ _XF86BigfontQueryFont ( fs->properties = Xmalloc (pbytes); } if (! fs->properties) { - Xfree((char *) fs); + Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -507,8 +507,8 @@ _XF86BigfontQueryFont ( any real font needs, so the combined total doesn't overflow either */ if (reply.nUniqCharInfos > ((ULONG_MAX / 2) / SIZEOF(xCharInfo)) || reply.nCharInfos > ((ULONG_MAX / 2) / sizeof(CARD16))) { - Xfree((char *) fs->properties); - Xfree((char *) fs); + Xfree(fs->properties); + Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -524,15 +524,15 @@ _XF86BigfontQueryFont ( + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16); pUniqCI = Xmalloc (nbytes); if (!pUniqCI) { - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) { - Xfree((char *) pUniqCI); - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + Xfree(pUniqCI); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -541,15 +541,15 @@ _XF86BigfontQueryFont ( for (i = 0; i < reply.nCharInfos; i++) { if (pIndex2UniqIndex[i] >= reply.nUniqCharInfos) { fprintf(stderr, "_XF86BigfontQueryFont: server returned wrong data\n"); - Xfree((char *) pUniqCI); - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + Xfree(pUniqCI); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); return (XFontStruct *)NULL; } /* XXX the next statement won't work if short isn't 16 bits */ fs->per_char[i] = * (XCharStruct *) &pUniqCI[pIndex2UniqIndex[i]]; } - Xfree((char *) pUniqCI); + Xfree(pUniqCI); } else { #ifdef HAS_SHM XExtData *pData; @@ -558,8 +558,8 @@ _XF86BigfontQueryFont ( pData = Xmalloc(sizeof(XExtData)); if (!pData) { - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); return (XFontStruct *)NULL; } @@ -577,9 +577,9 @@ _XF86BigfontQueryFont ( if ((addr = shmat(reply.shmid, NULL, SHM_RDONLY)) == (char *)-1) { if (extcodes->serverCapabilities & CAP_VerifiedLocal) fprintf(stderr, "_XF86BigfontQueryFont: could not attach shm segment\n"); - Xfree((char *) pData); - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + Xfree(pData); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; return (XFontStruct *)NULL; @@ -592,9 +592,9 @@ _XF86BigfontQueryFont ( && buf.shm_segsz >= reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct) + sizeof(CARD32) && *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) { shmdt(addr); - Xfree((char *) pData); - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + Xfree(pData); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; return (XFontStruct *)NULL; @@ -611,8 +611,8 @@ _XF86BigfontQueryFont ( fs->per_char = (XCharStruct *) (addr + reply.shmsegoffset); #else fprintf(stderr, "_XF86BigfontQueryFont: try recompiling libX11 with HasShm, Xserver has shm support\n"); - if (fs->properties) Xfree((char *) fs->properties); - Xfree((char *) fs); + if (fs->properties) Xfree(fs->properties); + Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; return (XFontStruct *)NULL; @@ -638,9 +638,9 @@ _XF86BigfontFreeFontMetrics (XFontStruct *fs) XF86BigfontNumber))) shmdt ((char *) pData->private_data); else - Xfree ((char *) fs->per_char); + Xfree (fs->per_char); #else - Xfree ((char *) fs->per_char); + Xfree (fs->per_char); #endif } @@ -693,14 +693,14 @@ int _XF86LoadQueryLocaleFont( #ifdef USE_XF86BIGFONT _XF86BigfontFreeFontMetrics(fs); #else - Xfree ((char *) fs->per_char); + Xfree (fs->per_char); #endif } _XFreeExtData(fs->ext_data); if (fs->properties) - Xfree ((char *) fs->properties); + Xfree (fs->properties); *fidp = fs->fid; - Xfree ((char *) fs); + Xfree (fs); } else { XFreeFont(dpy, fs); } diff --git a/libX11/src/FontInfo.c b/libX11/src/FontInfo.c index 0cb5b1910..763aafb3d 100644 --- a/libX11/src/FontInfo.c +++ b/libX11/src/FontInfo.c @@ -107,7 +107,7 @@ XFontStruct **info) /* RETURN */ if (! (finfo = Xmalloc(sizeof(XFontStruct) * size))) goto clearwire; if (! (flist = Xmalloc(sizeof(char *) * (size+1)))) { - Xfree((char *) finfo); + Xfree(finfo); goto clearwire; } } @@ -152,7 +152,7 @@ XFontStruct **info) /* RETURN */ nbytes++; /* make first string 1 byte longer, to match XListFonts */ flist[i] = Xmalloc (nbytes); if (! flist[i]) { - if (finfo[i].properties) Xfree((char *) finfo[i].properties); + if (finfo[i].properties) Xfree(finfo[i].properties); goto badmem; } if (!i) { @@ -177,10 +177,10 @@ XFontStruct **info) /* RETURN */ if (j == 0) flist[j]--; /* was incremented above */ Xfree(flist[j]); - if (finfo[j].properties) Xfree((char *) finfo[j].properties); + if (finfo[j].properties) Xfree(finfo[j].properties); } - if (flist) Xfree((char *) flist); - if (finfo) Xfree((char *) finfo); + if (flist) Xfree(flist); + if (finfo) Xfree(finfo); clearwire: /* Clear the wire. */ @@ -208,7 +208,7 @@ XFreeFontInfo ( for (i = 1; i < actualCount; i++) { Xfree (names[i]); } - Xfree((char *) names); + Xfree(names); } if (info) { for (i = 0; i < actualCount; i++) { @@ -216,12 +216,12 @@ XFreeFontInfo ( #ifdef USE_XF86BIGFONT _XF86BigfontFreeFontMetrics(&info[i]); #else - Xfree ((char *) info[i].per_char); + Xfree (info[i].per_char); #endif if (info[i].properties) - Xfree ((char *) info[i].properties); + Xfree (info[i].properties); } - Xfree((char *) info); + Xfree(info); } return 1; } diff --git a/libX11/src/FontNames.c b/libX11/src/FontNames.c index 764711559..c50de2eeb 100644 --- a/libX11/src/FontNames.c +++ b/libX11/src/FontNames.c @@ -73,7 +73,7 @@ int *actualCount) /* RETURN */ } if ((! flist) || (! ch)) { - if (flist) Xfree((char *) flist); + if (flist) Xfree(flist); if (ch) Xfree(ch); _XEatDataWords(dpy, rep.length); *actualCount = 0; @@ -116,7 +116,7 @@ XFreeFontNames(char **list) Xfree (*names); } Xfree (list[0]-1); - Xfree ((char *)list); + Xfree (list); } return 1; } diff --git a/libX11/src/FreeEData.c b/libX11/src/FreeEData.c index 3a7abca74..ce78467d3 100644 --- a/libX11/src/FreeEData.c +++ b/libX11/src/FreeEData.c @@ -36,9 +36,9 @@ _XFreeExtData (XExtData *extension) while (extension) { if (extension->free_private) (*extension->free_private)(extension); - else Xfree ((char *)extension->private_data); + else Xfree (extension->private_data); temp = extension->next; - Xfree ((char *)extension); + Xfree (extension); extension = temp; } return 0; diff --git a/libX11/src/FreeGC.c b/libX11/src/FreeGC.c index ab994bc64..926d50745 100644 --- a/libX11/src/FreeGC.c +++ b/libX11/src/FreeGC.c @@ -44,7 +44,7 @@ XFreeGC ( UnlockDisplay(dpy); SyncHandle(); _XFreeExtData(gc->ext_data); - Xfree ((char *) gc); + Xfree (gc); return 1; } diff --git a/libX11/src/GetFPath.c b/libX11/src/GetFPath.c index 8f8c6144a..76ff7327b 100644 --- a/libX11/src/GetFPath.c +++ b/libX11/src/GetFPath.c @@ -57,7 +57,7 @@ char **XGetFontPath( } if ((! flist) || (! ch)) { - if (flist) Xfree((char *) flist); + if (flist) Xfree(flist); if (ch) Xfree(ch); _XEatDataWords(dpy, rep.length); UnlockDisplay(dpy); @@ -93,7 +93,7 @@ XFreeFontPath (char **list) { if (list != NULL) { Xfree (list[0]-1); - Xfree ((char *)list); + Xfree (list); } return 1; } diff --git a/libX11/src/GetHints.c b/libX11/src/GetHints.c index 3c410d33d..5cca0bc93 100644 --- a/libX11/src/GetHints.c +++ b/libX11/src/GetHints.c @@ -75,7 +75,7 @@ Status XGetSizeHints ( if ((actual_type != XA_WM_SIZE_HINTS) || (nitems < OldNumPropSizeElements) || (actual_format != 32)) { - if (prop != NULL) Xfree ((char *)prop); + if (prop != NULL) Xfree (prop); return(0); } hints->flags = (prop->flags & (USPosition|USSize|PAllHints)); @@ -93,7 +93,7 @@ Status XGetSizeHints ( hints->min_aspect.y = cvtINT32toInt (prop->minAspectY); hints->max_aspect.x = cvtINT32toInt (prop->maxAspectX); hints->max_aspect.y = cvtINT32toInt (prop->maxAspectY); - Xfree((char *)prop); + Xfree(prop); return(1); } @@ -124,7 +124,7 @@ XWMHints *XGetWMHints ( if ((actual_type != XA_WM_HINTS) || (nitems < (NumPropWMHintsElements - 1)) || (actual_format != 32)) { - if (prop != NULL) Xfree ((char *)prop); + if (prop != NULL) Xfree (prop); return(NULL); } /* static copies not allowed in library, due to reentrancy constraint*/ @@ -142,7 +142,7 @@ XWMHints *XGetWMHints ( else hints->window_group = 0; } - Xfree ((char *)prop); + Xfree (prop); return(hints); } @@ -196,7 +196,7 @@ Status XGetIconSizes ( (nitems < NumPropIconSizeElements) || (nitems % NumPropIconSizeElements != 0) || (actual_format != 32)) { - if (prop != NULL) Xfree ((char *)prop); + if (prop != NULL) Xfree (prop); return(0); } @@ -204,7 +204,7 @@ Status XGetIconSizes ( nitems /= NumPropIconSizeElements; if (! (hp = hints = Xcalloc (nitems, sizeof(XIconSize)))) { - if (prop) Xfree ((char *) prop); + if (prop) Xfree (prop); return 0; } @@ -221,7 +221,7 @@ Status XGetIconSizes ( } *count = nitems; *size_list = hints; - Xfree ((char *)prop); + Xfree (prop); return(1); } @@ -239,7 +239,7 @@ Status XGetCommand ( if (!XGetTextProperty (dpy, w, &tp, XA_WM_COMMAND)) return 0; if (tp.encoding != XA_STRING || tp.format != 8) { - if (tp.value) Xfree ((char *) tp.value); + if (tp.value) Xfree (tp.value); return 0; } @@ -254,11 +254,11 @@ Status XGetCommand ( * create a string list and return if successful */ if (!XTextPropertyToStringList (&tp, &argv, &argc)) { - if (tp.value) Xfree ((char *) tp.value); + if (tp.value) Xfree (tp.value); return (0); } - if (tp.value) Xfree ((char *) tp.value); + if (tp.value) Xfree (tp.value); *argvp = argv; *argcp = argc; return 1; @@ -317,7 +317,7 @@ XGetClassHint( if ( (actual_type == XA_STRING) && (actual_format == 8) ) { len_name = strlen((char *) data); if (! (classhint->res_name = Xmalloc(len_name + 1))) { - Xfree((char *) data); + Xfree(data); return (0); } strcpy(classhint->res_name, (char *) data); @@ -326,7 +326,7 @@ XGetClassHint( if (! (classhint->res_class = Xmalloc(len_class + 1))) { Xfree(classhint->res_name); classhint->res_name = (char *) NULL; - Xfree((char *) data); + Xfree(data); return (0); } strcpy(classhint->res_class, (char *) (data+len_name+1)); diff --git a/libX11/src/GetNrmHint.c b/libX11/src/GetNrmHint.c index 6f328e8fd..5e4143b28 100644 --- a/libX11/src/GetNrmHint.c +++ b/libX11/src/GetNrmHint.c @@ -83,7 +83,7 @@ Status XGetWMSizeHints ( if ((actual_type != XA_WM_SIZE_HINTS) || (nitems < OldNumPropSizeElements) || (actual_format != 32)) { - if (prop != NULL) Xfree ((char *)prop); + if (prop != NULL) Xfree (prop); return False; } @@ -112,7 +112,7 @@ Status XGetWMSizeHints ( *supplied |= (PBaseSize | PWinGravity); } hints->flags &= (*supplied); /* get rid of unwanted bits */ - Xfree((char *)prop); + Xfree(prop); return True; } diff --git a/libX11/src/GetRGBCMap.c b/libX11/src/GetRGBCMap.c index 2f0b752a8..d8a1b3f05 100644 --- a/libX11/src/GetRGBCMap.c +++ b/libX11/src/GetRGBCMap.c @@ -63,7 +63,7 @@ Status XGetRGBColormaps ( /* if wrong type or format, or too small for us, then punt */ if ((actual_type != XA_RGB_COLOR_MAP) || (actual_format != 32) || (nitems < OldNumPropStandardColormapElements)) { - if (data) Xfree ((char *) data); + if (data) Xfree (data); return False; } @@ -78,7 +78,7 @@ Status XGetRGBColormaps ( Screen *sp = _XScreenOfWindow (dpy, w); if (!sp) { - if (data) Xfree ((char *) data); + if (data) Xfree (data); return False; } def_visual = sp->root_visual->visualid; @@ -90,7 +90,7 @@ Status XGetRGBColormaps ( ncmaps = (nitems / NumPropStandardColormapElements); if ((((unsigned long) ncmaps) * NumPropStandardColormapElements) != nitems) { - if (data) Xfree ((char *) data); + if (data) Xfree (data); return False; } } @@ -101,7 +101,7 @@ Status XGetRGBColormaps ( */ cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap)); if (!cmaps) { - if (data) Xfree ((char *) data); + if (data) Xfree (data); return False; } @@ -126,7 +126,7 @@ Status XGetRGBColormaps ( map->killid = (old_style ? None : prop->killid); } } - Xfree ((char *) data); + Xfree (data); *stdcmap = cmaps; *count = ncmaps; return True; diff --git a/libX11/src/GetStCmap.c b/libX11/src/GetStCmap.c index 82fb2134e..ac5b0fa88 100644 --- a/libX11/src/GetStCmap.c +++ b/libX11/src/GetStCmap.c @@ -81,7 +81,7 @@ Status XGetStandardColormap ( int i; if (!sp) { - if (stdcmaps) Xfree ((char *) stdcmaps); + if (stdcmaps) Xfree (stdcmaps); return False; } vid = sp->root_visual->visualid; @@ -91,7 +91,7 @@ Status XGetStandardColormap ( } if (i == nstdcmaps) { /* not found */ - Xfree ((char *) stdcmaps); + Xfree (stdcmaps); return False; } use = &stdcmaps[i]; @@ -111,7 +111,7 @@ Status XGetStandardColormap ( cmap->blue_mult = use->blue_mult; cmap->base_pixel = use->base_pixel; - Xfree ((char *) stdcmaps); /* don't need alloced memory */ + Xfree (stdcmaps); /* don't need alloced memory */ } return stat; } diff --git a/libX11/src/GetWMCMapW.c b/libX11/src/GetWMCMapW.c index 5d54cc1ce..27f1e232c 100644 --- a/libX11/src/GetWMCMapW.c +++ b/libX11/src/GetWMCMapW.c @@ -77,7 +77,7 @@ Status XGetWMColormapWindows ( return False; if (actual_type != XA_WINDOW || actual_format != 32) { - if (data) Xfree ((char *) data); + if (data) Xfree (data); return False; } diff --git a/libX11/src/GetWMProto.c b/libX11/src/GetWMProto.c index d8f8bdab4..4e9f12c22 100644 --- a/libX11/src/GetWMProto.c +++ b/libX11/src/GetWMProto.c @@ -77,7 +77,7 @@ Status XGetWMProtocols ( return False; if (actual_type != XA_ATOM || actual_format != 32) { - if (data) Xfree ((char *) data); + if (data) Xfree (data); return False; } diff --git a/libX11/src/ImUtil.c b/libX11/src/ImUtil.c index 240a26181..4fc060cb8 100644 --- a/libX11/src/ImUtil.c +++ b/libX11/src/ImUtil.c @@ -434,9 +434,9 @@ Status XInitImage (XImage *image) static int _XDestroyImage (XImage *ximage) { - if (ximage->data != NULL) Xfree((char *)ximage->data); - if (ximage->obdata != NULL) Xfree((char *)ximage->obdata); - Xfree((char *)ximage); + if (ximage->data != NULL) Xfree(ximage->data); + if (ximage->obdata != NULL) Xfree(ximage->obdata); + Xfree(ximage); return 1; } @@ -869,7 +869,7 @@ static XImage *_XSubImage ( dsize = subimage->bytes_per_line * height; if (subimage->format == XYPixmap) dsize = dsize * subimage->depth; if (((data = Xcalloc (1, dsize)) == NULL) && (dsize > 0)) { - Xfree((char *) subimage); + Xfree(subimage); return (XImage *) NULL; } subimage->data = data; diff --git a/libX11/src/InitExt.c b/libX11/src/InitExt.c index f50b54984..1d58e879f 100644 --- a/libX11/src/InitExt.c +++ b/libX11/src/InitExt.c @@ -52,7 +52,7 @@ XExtCodes *XInitExtension ( LockDisplay (dpy); if (! (ext = Xcalloc (1, sizeof (_XExtension))) || ! (ext->name = strdup(name))) { - if (ext) Xfree((char *) ext); + if (ext) Xfree(ext); UnlockDisplay(dpy); return (XExtCodes *) NULL; } diff --git a/libX11/src/IntAtom.c b/libX11/src/IntAtom.c index 25466ca20..3042b65dd 100644 --- a/libX11/src/IntAtom.c +++ b/libX11/src/IntAtom.c @@ -47,9 +47,9 @@ _XFreeAtomTable(Display *dpy) table = dpy->atoms->table; for (i = TABLESIZE; --i >= 0; ) { if ((e = *table++) && (e != RESERVED)) - Xfree((char *)e); + Xfree(e); } - Xfree((char *)dpy->atoms); + Xfree(dpy->atoms); } } @@ -153,7 +153,7 @@ _XUpdateAtomCache( e->atom = atom; strcpy(EntryName(e), name); if ((oe = dpy->atoms->table[idx]) && (oe != RESERVED)) - Xfree((char *)oe); + Xfree(oe); dpy->atoms->table[idx] = e; } } diff --git a/libX11/src/KeyBind.c b/libX11/src/KeyBind.c index 2110772ce..a49de3d78 100644 --- a/libX11/src/KeyBind.c +++ b/libX11/src/KeyBind.c @@ -239,7 +239,7 @@ XRefreshKeyboardMapping(register XMappingEvent *event) */ LockDisplay(event->display); if (event->display->keysyms) { - Xfree ((char *)event->display->keysyms); + Xfree (event->display->keysyms); event->display->keysyms = NULL; } UnlockDisplay(event->display); @@ -277,7 +277,7 @@ _XKeyInitialize( LockDisplay(dpy); if (dpy->keysyms) - Xfree ((char *)dpy->keysyms); + Xfree (dpy->keysyms); dpy->keysyms = keysyms; dpy->keysyms_per_keycode = per; if (dpy->modifiermap) @@ -974,8 +974,8 @@ _XFreeKeyBindings( for (p = dpy->key_bindings; p; p = np) { np = p->next; Xfree(p->string); - Xfree((char *)p->modifiers); - Xfree((char *)p); + Xfree(p->modifiers); + Xfree(p); } } @@ -1002,8 +1002,8 @@ XRebindKeysym ( ((! (p->modifiers = Xmalloc(nb))) && (nb > 0))) { if (p) { if (p->string) Xfree(p->string); - if (p->modifiers) Xfree((char *) p->modifiers); - Xfree((char *) p); + if (p->modifiers) Xfree(p->modifiers); + Xfree(p); } UnlockDisplay(dpy); return 0; diff --git a/libX11/src/ListExt.c b/libX11/src/ListExt.c index 59599d1a6..f40924df7 100644 --- a/libX11/src/ListExt.c +++ b/libX11/src/ListExt.c @@ -62,8 +62,8 @@ char **XListExtensions( } if ((!list) || (!ch)) { - if (list) Xfree((char *) list); - if (ch) Xfree((char *) ch); + if (list) Xfree(list); + if (ch) Xfree(ch); _XEatDataWords(dpy, rep.length); UnlockDisplay(dpy); SyncHandle(); @@ -99,7 +99,7 @@ XFreeExtensionList (char **list) { if (list != NULL) { Xfree (list[0]-1); - Xfree ((char *)list); + Xfree (list); } return 1; } diff --git a/libX11/src/Makefile.am b/libX11/src/Makefile.am index db8f4d40a..d46b49301 100644 --- a/libX11/src/Makefile.am +++ b/libX11/src/Makefile.am @@ -332,10 +332,6 @@ if OS2 libX11_la_SOURCES+=os2Stubs.c endif OS2 -if UDC -libX11_la_SOURCES+=udcInf.c -endif - if THRSTUBS libX11_la_SOURCES+=UIThrStubs.c endif @@ -346,7 +342,6 @@ x11data_DATA = XErrorDB EXTRA_DIST = \ $(x11data_DATA) \ os2Stubs.c \ - udcInf.c \ UIThrStubs.c libX11_xcb_la_SOURCES = x11_xcb.c Xxcbint.h diff --git a/libX11/src/ModMap.c b/libX11/src/ModMap.c index 2fabc560c..78d635bf5 100644 --- a/libX11/src/ModMap.c +++ b/libX11/src/ModMap.c @@ -50,7 +50,7 @@ XGetModifierMapping(register Display *dpy) } else res = NULL; if ((! res) || (! res->modifiermap)) { - if (res) Xfree((char *) res); + if (res) Xfree(res); res = (XModifierKeymap *) NULL; _XEatDataWords(dpy, rep.length); } else { @@ -102,7 +102,7 @@ XNewModifiermap(int keyspermodifier) Xmalloc(8 * keyspermodifier) : (KeyCode *) NULL); if (keyspermodifier && (res->modifiermap == NULL)) { - Xfree((char *) res); + Xfree(res); return (XModifierKeymap *) NULL; } } @@ -115,8 +115,8 @@ XFreeModifiermap(XModifierKeymap *map) { if (map) { if (map->modifiermap) - Xfree((char *) map->modifiermap); - Xfree((char *) map); + Xfree(map->modifiermap); + Xfree(map); } return 1; } diff --git a/libX11/src/OpenDis.c b/libX11/src/OpenDis.c index 90ac8b36c..607b5a077 100644 --- a/libX11/src/OpenDis.c +++ b/libX11/src/OpenDis.c @@ -593,7 +593,7 @@ void _XFreeDisplayStructure(Display *dpy) dpy->ext_procs = ext->next; if (ext->name) Xfree (ext->name); - Xfree ((char *)ext); + Xfree (ext); } if (dpy->im_filters) (*dpy->free_funcs->im_filters)(dpy); @@ -635,17 +635,17 @@ void _XFreeDisplayStructure(Display *dpy) for (k = 0; k < dp->nvisuals; k++) _XFreeExtData (dp->visuals[k].ext_data); - Xfree ((char *) dp->visuals); + Xfree (dp->visuals); } } - Xfree ((char *) sp->depths); + Xfree (sp->depths); } _XFreeExtData (sp->ext_data); } - Xfree ((char *)dpy->screens); + Xfree (dpy->screens); } if (dpy->pixmap_format) { @@ -653,7 +653,7 @@ void _XFreeDisplayStructure(Display *dpy) for (i = 0; i < dpy->nformats; i++) _XFreeExtData (dpy->pixmap_format[i].ext_data); - Xfree ((char *)dpy->pixmap_format); + Xfree (dpy->pixmap_format); } free(dpy->display_name); @@ -663,15 +663,15 @@ void _XFreeDisplayStructure(Display *dpy) if (dpy->buffer) Xfree (dpy->buffer); if (dpy->keysyms) - Xfree ((char *) dpy->keysyms); + Xfree (dpy->keysyms); if (dpy->xdefaults) Xfree (dpy->xdefaults); if (dpy->error_vec) - Xfree ((char *)dpy->error_vec); + Xfree (dpy->error_vec); _XFreeExtData (dpy->ext_data); if (dpy->free_funcs) - Xfree ((char *)dpy->free_funcs); + Xfree (dpy->free_funcs); if (dpy->scratch_buffer) Xfree (dpy->scratch_buffer); FreeDisplayLock(dpy); @@ -681,7 +681,7 @@ void _XFreeDisplayStructure(Display *dpy) while (qelt) { register _XQEvent *qnxt = qelt->next; - Xfree ((char *) qelt); + Xfree (qelt); qelt = qnxt; } } @@ -702,7 +702,7 @@ void _XFreeDisplayStructure(Display *dpy) _XFreeX11XCBStructure(dpy); - Xfree ((char *)dpy); + Xfree (dpy); } /* OutOfMemory is called if malloc fails. XOpenDisplay returns NULL diff --git a/libX11/src/PolyReg.c b/libX11/src/PolyReg.c index 6d0277332..7266d3b0b 100644 --- a/libX11/src/PolyReg.c +++ b/libX11/src/PolyReg.c @@ -378,7 +378,7 @@ FreeStorage( while (pSLLBlock) { tmpSLLBlock = pSLLBlock->next; - Xfree((char *)pSLLBlock); + Xfree(pSLLBlock); pSLLBlock = tmpSLLBlock; } } @@ -627,9 +627,9 @@ XPolygonRegion( (void) PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { tmpPtBlock = curPtBlock->next; - Xfree((char *)curPtBlock); + Xfree(curPtBlock); curPtBlock = tmpPtBlock; } - Xfree((char *)pETEs); + Xfree(pETEs); return(region); } diff --git a/libX11/src/PutImage.c b/libX11/src/PutImage.c index 934fabe0f..e6ac9a23f 100644 --- a/libX11/src/PutImage.c +++ b/libX11/src/PutImage.c @@ -794,7 +794,7 @@ SendZImage( ((req_yoffset + req->height) < (unsigned)image->height))) { Data(dpy, (char *)src, length); if (shifted_src) - Xfree((char *)shifted_src); + Xfree(shifted_src); return; } @@ -804,7 +804,7 @@ SendZImage( else if ((dest = (unsigned char *) _XAllocScratch(dpy, length)) == NULL) { - if (shifted_src) Xfree((char *) shifted_src); + if (shifted_src) Xfree(shifted_src); UnGetReq(PutImage); return; } @@ -832,7 +832,7 @@ SendZImage( _XSend(dpy, (char *)dest, length); if (shifted_src) - Xfree((char *)shifted_src); + Xfree(shifted_src); } static void diff --git a/libX11/src/QuColors.c b/libX11/src/QuColors.c index af7102297..add2376bf 100644 --- a/libX11/src/QuColors.c +++ b/libX11/src/QuColors.c @@ -64,7 +64,7 @@ _XQueryColors( def->blue = rgb->blue; def->flags = DoRed | DoGreen | DoBlue; } - Xfree((char *)color); + Xfree(color); } else _XEatDataWords(dpy, rep.length); diff --git a/libX11/src/Quarks.c b/libX11/src/Quarks.c index 60fe127bd..cfdfe07aa 100644 --- a/libX11/src/Quarks.c +++ b/libX11/src/Quarks.c @@ -230,7 +230,7 @@ ExpandQuarkTable(void) } } if (oldmask) - Xfree((char *)oldentries); + Xfree(oldentries); return True; } diff --git a/libX11/src/RdBitF.c b/libX11/src/RdBitF.c index d20731215..7f6750d64 100644 --- a/libX11/src/RdBitF.c +++ b/libX11/src/RdBitF.c @@ -138,7 +138,7 @@ XReadBitmapFileData ( /* error cleanup and return macro */ #define RETURN(code) \ -{ if (bits) Xfree ((char *)bits); fclose (fstream); return code; } +{ if (bits) Xfree (bits); fclose (fstream); return code; } while (fgets(line, MAX_SIZE, fstream)) { if (strlen(line) == MAX_SIZE-1) @@ -255,7 +255,7 @@ XReadBitmapFile ( if (res != BitmapSuccess) return res; *pixmap = XCreateBitmapFromData(display, d, (char *)data, *width, *height); - Xfree((char *)data); + Xfree(data); if (*pixmap == None) return (BitmapNoMemory); return (BitmapSuccess); diff --git a/libX11/src/Region.c b/libX11/src/Region.c index d3d431a64..d5dd5561f 100644 --- a/libX11/src/Region.c +++ b/libX11/src/Region.c @@ -142,7 +142,7 @@ XCreateRegion(void) if (! (temp = Xmalloc(sizeof( REGION )))) return (Region) NULL; if (! (temp->rects = Xmalloc(sizeof( BOX )))) { - Xfree((char *) temp); + Xfree(temp); return (Region) NULL; } temp->numRects = 0; @@ -507,7 +507,7 @@ XIntersectRegion( return 1; } -static void +static int miRegionCopy( register Region dstrgn, register Region rgn) @@ -525,7 +525,8 @@ miRegionCopy( rgn->numRects * (sizeof(BOX))); if (! dstrgn->rects) { Xfree(prevRects); - return; + dstrgn->size = 0; + return 0; } } dstrgn->size = rgn->numRects; @@ -539,6 +540,7 @@ miRegionCopy( memcpy((char *) dstrgn->rects, (char *) rgn->rects, (int) (rgn->numRects * sizeof(BOX))); } + return 1; } /*====================================================================== @@ -978,11 +980,12 @@ miRegionOp( if (REGION_NOT_EMPTY(newReg)) { BoxPtr prev_rects = newReg->rects; - newReg->size = newReg->numRects; newReg->rects = Xrealloc (newReg->rects, - sizeof(BoxRec) * newReg->size); + sizeof(BoxRec) * newReg->numRects); if (! newReg->rects) newReg->rects = prev_rects; + else + newReg->size = newReg->numRects; } else { @@ -991,11 +994,11 @@ miRegionOp( * the region is empty */ newReg->size = 1; - Xfree((char *) newReg->rects); + Xfree(newReg->rects); newReg->rects = Xmalloc(sizeof(BoxRec)); } } - Xfree ((char *) oldRects); + Xfree (oldRects); return; } @@ -1150,7 +1153,7 @@ XUnionRegion( if ( (reg1 == reg2) || (!(reg1->numRects)) ) { if (newReg != reg2) - miRegionCopy(newReg, reg2); + return miRegionCopy(newReg, reg2); return 1; } @@ -1160,7 +1163,7 @@ XUnionRegion( if (!(reg2->numRects)) { if (newReg != reg1) - miRegionCopy(newReg, reg1); + return miRegionCopy(newReg, reg1); return 1; } @@ -1174,7 +1177,7 @@ XUnionRegion( (reg1->extents.y2 >= reg2->extents.y2)) { if (newReg != reg1) - miRegionCopy(newReg, reg1); + return miRegionCopy(newReg, reg1); return 1; } @@ -1188,7 +1191,7 @@ XUnionRegion( (reg2->extents.y2 >= reg1->extents.y2)) { if (newReg != reg2) - miRegionCopy(newReg, reg2); + return miRegionCopy(newReg, reg2); return 1; } @@ -1429,8 +1432,7 @@ XSubtractRegion( if ( (!(regM->numRects)) || (!(regS->numRects)) || (!EXTENTCHECK(®M->extents, ®S->extents)) ) { - miRegionCopy(regD, regM); - return 1; + return miRegionCopy(regD, regM); } miRegionOp (regD, regM, regS, miSubtractO, diff --git a/libX11/src/RegstFlt.c b/libX11/src/RegstFlt.c index 5a1faa7e9..077ea424c 100644 --- a/libX11/src/RegstFlt.c +++ b/libX11/src/RegstFlt.c @@ -66,7 +66,7 @@ _XFreeIMFilters( while ((fl = display->im_filters)) { display->im_filters = fl->next; - Xfree((char *)fl); + Xfree(fl); } } @@ -148,7 +148,7 @@ _XUnregisterFilter( if (fl->window == window && fl->filter == filter && fl->client_data == client_data) { *prev = fl->next; - Xfree((char *)fl); + Xfree(fl); } else prev = &fl->next; } diff --git a/libX11/src/SetFPath.c b/libX11/src/SetFPath.c index b1afd8201..60aaef01e 100644 --- a/libX11/src/SetFPath.c +++ b/libX11/src/SetFPath.c @@ -65,7 +65,7 @@ XSetFontPath ( p += length + 1; } Data (dpy, tmp, nbytes); - Xfree ((char *) tmp); + Xfree (tmp); retCode = 1; } else diff --git a/libX11/src/SetHints.c b/libX11/src/SetHints.c index 0ae076438..5f0a4d4c8 100644 --- a/libX11/src/SetHints.c +++ b/libX11/src/SetHints.c @@ -198,7 +198,7 @@ XSetIconSizes ( XChangeProperty (dpy, w, XA_WM_ICON_SIZE, XA_WM_ICON_SIZE, 32, PropModeReplace, (unsigned char *) prop, count * NumPropIconSizeElements); - Xfree ((char *)prop); + Xfree (prop); } return 1; } diff --git a/libX11/src/SetRGBCMap.c b/libX11/src/SetRGBCMap.c index d2cbb5b5b..a52de261b 100644 --- a/libX11/src/SetRGBCMap.c +++ b/libX11/src/SetRGBCMap.c @@ -95,6 +95,6 @@ void XSetRGBColormaps ( XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32, PropModeReplace, (unsigned char *) data, (int) (count * NumPropStandardColormapElements)); - Xfree ((char *) data); + Xfree (data); } } diff --git a/libX11/src/StBytes.c b/libX11/src/StBytes.c index 07ee441ab..ec6c2e295 100644 --- a/libX11/src/StBytes.c +++ b/libX11/src/StBytes.c @@ -74,7 +74,7 @@ char *XFetchBuffer ( *nbytes = nitems; return((char *)data); } - if ((char *) data != NULL) Xfree ((char *)data); + if ((char *) data != NULL) Xfree (data); return(NULL); } diff --git a/libX11/src/TextToStr.c b/libX11/src/TextToStr.c index 36d9f0706..de9897ae1 100644 --- a/libX11/src/TextToStr.c +++ b/libX11/src/TextToStr.c @@ -77,7 +77,7 @@ Status XTextPropertyToStringList ( start = Xmalloc ((datalen + 1) * sizeof (char)); /* for <NUL> */ if (!start) { - Xfree ((char *) list); + Xfree (list); return False; } @@ -111,7 +111,7 @@ void XFreeStringList (char **list) { if (list) { if (list[0]) Xfree (list[0]); - Xfree ((char *) list); + Xfree (list); list = NULL; } } diff --git a/libX11/src/VisUtil.c b/libX11/src/VisUtil.c index aa679928a..17ca3631f 100644 --- a/libX11/src/VisUtil.c +++ b/libX11/src/VisUtil.c @@ -133,7 +133,7 @@ XVisualInfo *XGetVisualInfo( total += 10; if (! (vip_base = Xrealloc(vip_base, sizeof(XVisualInfo) * total))) { - Xfree((char *) old_vip_base); + Xfree(old_vip_base); UnlockDisplay(dpy); return (XVisualInfo *) NULL; } @@ -170,7 +170,7 @@ XVisualInfo *XGetVisualInfo( return vip_base; } - Xfree((char *) vip_base); + Xfree(vip_base); *nitems = 0; return NULL; } diff --git a/libX11/src/Xrm.c b/libX11/src/Xrm.c index d8272ee78..36b71d699 100644 --- a/libX11/src/Xrm.c +++ b/libX11/src/Xrm.c @@ -531,7 +531,7 @@ static void MoveValues( fentry->next = tentry; } } - Xfree((char *)ftable->buckets); + Xfree(ftable->buckets); } /* move all tables from ftable to ttable, and free ftable. @@ -558,7 +558,7 @@ static void MoveTables( fentry->next = tentry; } } - Xfree((char *)ftable); + Xfree(ftable); } /* grow the table, based on current number of entries */ @@ -649,7 +649,7 @@ static void MergeValues( fentry = *prev; *prev = tentry->next; /* free the overridden entry */ - Xfree((char *)tentry); + Xfree(tentry); /* get next tentry */ tentry = *prev; } else { @@ -658,7 +658,7 @@ static void MergeValues( tentry = fentry; /* use as a temp var */ fentry = fentry->next; /* free the overpowered entry */ - Xfree((char *)tentry); + Xfree(tentry); /* get next tentry */ tentry = *prev; } @@ -676,8 +676,8 @@ static void MergeValues( } } } - Xfree((char *)ftable->buckets); - Xfree((char *)ftable); + Xfree(ftable->buckets); + Xfree(ftable); /* resize if necessary, now that we're all done */ GROW(pprev); } @@ -751,7 +751,7 @@ static void MergeTables( } } } - Xfree((char *)ftable); + Xfree(ftable); /* resize if necessary, now that we're all done */ GROW(pprev); } @@ -801,7 +801,7 @@ void XrmCombineDatabase( (from->methods->destroy)(from->mbstate); _XUnlockMutex(&from->linfo); _XFreeMutex(&from->linfo); - Xfree((char *)from); + Xfree(from); _XUnlockMutex(&(*into)->linfo); } } @@ -929,7 +929,7 @@ static void PutEntry( } /* splice out and free old entry */ *vprev = entry->next; - Xfree((char *)entry); + Xfree(entry); (*pprev)->entries--; } /* this is where to insert */ @@ -2605,11 +2605,11 @@ static void DestroyLTable( for (i = table->table.mask; i >= 0; i--, buckets++) { for (next = *buckets; (entry = next); ) { next = entry->next; - Xfree((char *)entry); + Xfree(entry); } } - Xfree((char *)table->buckets); - Xfree((char *)table); + Xfree(table->buckets); + Xfree(table); } /* destroy all contained tables, plus table itself */ @@ -2630,7 +2630,7 @@ static void DestroyNTable( DestroyNTable(entry); } } - Xfree((char *)table); + Xfree(table); } const char * @@ -2661,6 +2661,6 @@ void XrmDestroyDatabase( _XUnlockMutex(&db->linfo); _XFreeMutex(&db->linfo); (*db->methods->destroy)(db->mbstate); - Xfree((char *)db); + Xfree(db); } } diff --git a/libX11/src/locking.c b/libX11/src/locking.c index 7c09c44d2..9f4fe0677 100644 --- a/libX11/src/locking.c +++ b/libX11/src/locking.c @@ -312,8 +312,8 @@ static void _XPopReader( dpy->lock->num_free_cvls++; } else { xcondition_clear(front->cv); - Xfree((char *)front->cv); - Xfree((char *)front); + Xfree(front->cv); + Xfree(front); } } @@ -419,14 +419,14 @@ static void _XFreeDisplayLock( while ((cvl = dpy->lock->free_cvls)) { dpy->lock->free_cvls = cvl->next; xcondition_clear(cvl->cv); - Xfree((char *)cvl->cv); - Xfree((char *)cvl); + Xfree(cvl->cv); + Xfree(cvl); } - Xfree((char *)dpy->lock); + Xfree(dpy->lock); dpy->lock = NULL; } if (dpy->lock_fns != NULL) { - Xfree((char *)dpy->lock_fns); + Xfree(dpy->lock_fns); dpy->lock_fns = NULL; } } diff --git a/libX11/src/udcInf.c b/libX11/src/udcInf.c deleted file mode 100644 index 9ecf1566e..000000000 --- a/libX11/src/udcInf.c +++ /dev/null @@ -1,715 +0,0 @@ -/* -Copyright 1996, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -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. - -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. -*/ -/* - * Copyright 1995 by FUJITSU LIMITED - * This is source code modified by FUJITSU LIMITED under the Joint - * Development Agreement for the CDE/Motif PST. - * - * Modifier: Takanori Tateno FUJITSU LIMITED - * - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <stdio.h> -#include <locale.h> -#include <Xlib.h> -#include <Xlibint.h> -#include <Xlcint.h> -#include <XlcPubI.h> -#include <XlcGeneric.h> -#include <XomGeneric.h> - -/* - external symbols -*/ -extern FontData read_EncodingInfo(); -extern int _xudc_get_codeset(); - -extern int _xudc_utyderror ; -extern int _xudc_utyerror ; - -extern unsigned long _xudc_utyerrno ; - -#define _XUDC_ERROR -1 - - -/* - UDC structure define -*/ -typedef struct __XUDCGlyphRegion { - unsigned long start; - unsigned long end; -} _XUDCGlyphRegion ; - -/* - * "code" no jyoui "i" byte me wo "unsigned char" toshite kaesu. - */ -static unsigned char getbyte(code,i) -unsigned long code; -int i; -{ - unsigned long byteL; - unsigned char byte; - byteL = code >> (8*(3-i)); - byte = (unsigned char)(0x000000ff & byteL); - return(byte); -} -/* - get codeset which described by charset_str and locale. - for examples ... - locale : ja_JP - charset_str : JISX0208.1983-0 -*/ - -_xudc_get_codeset(locale,charset_str,codeset,num_codeset) -char *locale; -char *charset_str; -int **codeset; -int *num_codeset; -{ - XLCdRec lcdrec; - XLCd lcd; - XLCdPublicRec xlcdp; - XPointer rdb; - int num = 0,count,num_ret=0,i,*ret; - char **value,buf[128],*ptr; - - - _xudc_utyderror = 0; - _xudc_utyerror = 0; - - if((locale == NULL) || (charset_str == NULL)){ - _xudc_utyerror = 5; - _xudc_utyderror = 1; - _xudc_utyerrno = 0x04 ; - return(_XUDC_ERROR); - } - if(codeset == NULL){ - _xudc_utyerror = 5; - _xudc_utyderror = 2; - _xudc_utyerrno = 0x04 ; - return(_XUDC_ERROR); - } - - /* create XLCd */ - xlcdp.pub.siname = locale; - lcdrec.core = (XLCdCore)&xlcdp; - lcd = &lcdrec; - /* create X RDB (X NLS DB) */ - rdb = _XlcCreateLocaleDataBase(lcd); - if(rdb == NULL){ - _xudc_utyerror = 1; - _xudc_utyerrno = 0x15 ; - return(_XUDC_ERROR); - } - - for(num=0;;num++){ - /* XLC_FONTSET */ - sprintf(buf, "fs%d.font.primary", num); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count < 1){ - break ; - } - for(i=0;i<count;i++){ - if (strlen(value[i]) >= sizeof(buf)) - continue; - strcpy(buf,value[i]); - ptr = (char *)strchr(buf,(int)':'); - *ptr = 0; - if(!_XlcCompareISOLatin1(charset_str,buf)){ - num_ret += 1; - if(num_ret == 1){ - ret = Xmalloc(sizeof(int)); - } else { - int *prev_ret = ret; - - ret = Xrealloc(ret, num_ret * sizeof(int)); - if (ret == NULL){ - Xfree(prev_ret); - } - } - if(ret == NULL){ - _xudc_utyerrno = 0x03 ; - return(_XUDC_ERROR); - } - ret[num_ret-1]=num; - break ; - } - } - } - if(num_ret == 0){ - *num_codeset = 0; - *codeset = NULL; - return (0xff); - } - - *num_codeset = num_ret; - *codeset = ret; - return 0; -} - -static Bool gi_to_vgi(gi,vgi,scope) -unsigned long gi,*vgi; -FontScope scope; -{ - if(scope->shift_direction == (unsigned long)'+'){ - gi -= scope->shift; - } else { - gi += scope->shift; - } - if(gi >= scope->start && gi <= scope->end){ - *vgi = gi; - return(True); - } - return(False); -} - -static void shift_area(udc,scope) -_XUDCGlyphRegion *udc; -FontScope scope; -{ - if(scope->shift_direction == (unsigned long)'+'){ - udc->start += scope->shift; - udc->end += scope->shift; - } else { - udc->start -= scope->shift; - udc->end -= scope->shift; - } -} - -/* - get UDC area with glyph index. - for examples ... - locale : ja_JP - charset_str : JISX0208.1983-0 -*/ -_XUDCGetUDCGIArea(locale,codeset,charset_str,gr,num_gr) -char *locale; -int codeset; -char *charset_str; -_XUDCGlyphRegion **gr; -int *num_gr; -{ - XLCdRec lcdrec; - XLCd lcd; - XLCdPublicRec xlcdp; - XPointer rdb; - _XUDCGlyphRegion *udc; - int num = 0,count,num_ret=0; - int i,j,k; - char **value,buf[128],ptr; - FontData font_data; - - - _xudc_utyderror = 0; - _xudc_utyerror = 0; - _xudc_utyerrno = 0x00 ; - - if((locale == NULL) || (charset_str == NULL)){ - _xudc_utyerror = 5; - _xudc_utyderror = 1; - _xudc_utyerrno = 0x04; - _xudc_utyerrno |= (0x0b<<8) ; - return(_XUDC_ERROR); - } - if(gr == NULL){ - _xudc_utyerror = 5; - _xudc_utyderror = 1; - _xudc_utyerrno = 0x04; - _xudc_utyerrno |= (0x0b<<8) ; - return(_XUDC_ERROR); - } - if(num_gr == NULL){ - _xudc_utyerror = 5; - _xudc_utyderror = 2; - _xudc_utyerrno = 0x04; - _xudc_utyerrno |= (0x0b<<8) ; - return(_XUDC_ERROR); - } - - /* create XLCd */ - xlcdp.pub.siname = locale; - lcdrec.core = (XLCdCore)&xlcdp; - lcd = &lcdrec; - /* create X RDB (X NLS DB) */ - rdb = _XlcCreateLocaleDataBase(lcd); - if(rdb == NULL){ - _xudc_utyerror = 1; - _xudc_utyerrno = 0x15 ; - _xudc_utyerrno |= (0x0b<<8) ; - return(_XUDC_ERROR); - } - udc = NULL; - - /* XLC_FONTSET */ - sprintf(buf, "fs%d.charset.udc_area", codeset-1); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - udc = Xmalloc(count * sizeof(_XUDCGlyphRegion)); - if(udc == NULL){ - _xudc_utyerrno = 0x03 ; - _xudc_utyerrno |= (0x0b<<8) ; - return(_XUDC_ERROR); - } - for(i=0;i<count;i++){ - sscanf(value[i],"\\x%lx,\\x%lx", &(udc[i].start), &(udc[i].end)); - } - } - - *num_gr = count; - - sprintf(buf, "fs%d.font.primary", codeset-1); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - font_data = read_EncodingInfo(count,value); - for(i=0;i<count;i++){ - if( !_XlcCompareISOLatin1(font_data[i].name,charset_str)){ - for(j=0;j<(*num_gr);j++){ - for(k=0;k<font_data[i].scopes_num;k++){ - if(udc[j].start == font_data[i].scopes[k].start - && font_data[i].scopes[k].shift){ - shift_area(&udc[j],&(font_data[i].scopes[k])); - } - } - } - } - } - } - - *gr = udc; - return 0; -} - -/* - * Code convert wo tomonau UDC area no kakutoku - * GetUDCCPArea() / glyph_to_code() - * - */ - -static int -_xudc_gi_to_vgi(lcd,locale,charset_str,codeset,gi,vgi,charsetname,size) -XLCd lcd; -char *locale; -char *charset_str; -int codeset; -unsigned long gi; -unsigned long *vgi; -char *charsetname; -int size; -{ - _XUDCGlyphRegion *udc; - int num = 0,count,num_ret=0; - int i,j,k; - char **value,buf[128],ptr; - FontData font_data; - - - sprintf(buf, "fs%d.charset.name", codeset-1); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - strcpy(charsetname,value[0]); - } - if (count >= size) - return False; - sprintf(buf, "fs%d.font.primary", codeset-1); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - font_data = read_EncodingInfo(count,value); - for(i=0;i<count;i++){ - if( !_XlcCompareISOLatin1(font_data[i].name,charset_str)){ - for(k=0;k<font_data[i].scopes_num;k++){ - if( gi_to_vgi(gi,vgi,&(font_data[i].scopes[k])) == True){ - return(True); - } - } - } - } - } -/* - free_fontdata(font_data); -*/ - *vgi = gi; - return(True); -} - -Bool non_standard(lcd,charset) -XLCd lcd; -XlcCharSet charset; -{ - char buf[256]; - int count,i; - char **value; - if(charset->ct_sequence == NULL){ - return(False); - } - for(i=0;;i++){ - sprintf(buf, "csd%d.charset_name", i); - _XlcGetLocaleDataBase(lcd, "XLC_CHARSET_DEFINE", buf, &value, &count); - if(count > 0){ - if(!_XlcNCompareISOLatin1(value[0], - charset->name,strlen(value[0])) ){ - return(True); - } - } else { - return(False); - } - } -} - -static Bool -make_none_standard(from,charset,src,size) -char *from; -XlcCharSet charset; -char *src; -int size; -{ - int name_len,seq_len,rest_len,i; - name_len = 2 + strlen(charset->encoding_name) + 1; - seq_len = strlen(charset->ct_sequence); - rest_len = strlen(charset->encoding_name) + 1 + strlen(src); - if (name_len + seq_len + strlen(src) >= size || rest_len >= 0x4000) - return False; - strcpy(from,charset->ct_sequence); - from[seq_len] = (rest_len >> 7) + 128; - from[seq_len+1] = (rest_len & 0x7f) + 128; - strcpy(&from[seq_len + 2],charset->encoding_name); - from[seq_len+name_len-1] = 0x02; /* STX */ - strcpy(&from[seq_len + name_len],src); - return True; -} -int -_xudc_glyph_to_code(locale,charset_str,codeset,glyph_index,codepoint) -char *locale; -char *charset_str; -int codeset; -unsigned long glyph_index; -unsigned long *codepoint; -{ - XLCd lcd; - unsigned char *from; int from_left; - unsigned char *to ; int to_left = 10; - unsigned char *dst; - unsigned char byte; - unsigned long from32[25]; - unsigned long to32[25]; - int i,j; - char charsetname[256],src[10]; - XlcConv conv; - XlcCharSet charset; - XPointer args[2]; - - from = (unsigned char *)from32; - to = (unsigned char *)to32; - dst = (unsigned char *)to32; - - memset(dst,0,25); - - lcd = (XLCd)_XlcGenericLoader(locale); - - if (!_xudc_gi_to_vgi(lcd,locale,charset_str,codeset, - glyph_index,&glyph_index,charsetname,sizeof(charsetname))) - return(_XUDC_ERROR); - - for(i=0,j=0;i<4;i++){ - byte = getbyte(glyph_index,i); - if(byte){ - src[j] = byte; - j ++; - } - } - src[j] = 0; - - - /* get charset */ -/* - sprintf(tmp,"%s%s",charset_str,":GL"); - charset_name = strdup(tmp); -*/ - charset = _XlcGetCharSet(charsetname); - if(charset == NULL){ - _xudc_utyerrno = 0x16 ; - return(_XUDC_ERROR); - } - /* make ct */ - if( non_standard(lcd,charset)) { - if (!make_none_standard(from,charset,src,sizeof(from32))) - return(_XUDC_ERROR); - } else if(charset->ct_sequence){ - if (strlen(charset->ct_sequence) + strlen(src) >= sizeof(from32)) - return(_XUDC_ERROR); - sprintf((char *)from,"%s%s",charset->ct_sequence,src); - } else { - sprintf((char *)from,"%s\0",src); - } - /* compound text -> multi byte */ - conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte); - from_left = strlen((char *)from); - _XlcConvert(conv,(XPointer *)&from,&from_left, - (XPointer *)&to, &to_left,args,0); - _XlcCloseConverter(conv); - _XlcDestroyLC(lcd); - - *codepoint = 0; - for(i=0;dst[i];i++){ - *codepoint = ((*codepoint << 8) | dst[i]) ; - } - return(0); -} - -typedef struct __XUDCCodeRegion { - unsigned long start,end; -} _XUDCCodeRegion ; - -int -_XUDCGetUDCCPArea(locale,codeset,charset_str,cr,num_cr) -char *locale; -int codeset; -char *charset_str; -_XUDCCodeRegion **cr; -int *num_cr; -{ - int i,num_gr,ret; - _XUDCGlyphRegion *gr; - _XUDCCodeRegion *crr; - - _xudc_utyerror = 0; - _xudc_utyderror = 0; - - if(cr == NULL){ - _xudc_utyerror = 5; - _xudc_utyderror = 1; - _xudc_utyerrno = 0x04 ; - _xudc_utyerrno |= (0x0a<<8) ; - return(_XUDC_ERROR); - } - if(num_cr == NULL){ - _xudc_utyerror = 5; - _xudc_utyderror = 2; - _xudc_utyerrno = 0x04 ; - _xudc_utyerrno |= (0x0a<<8) ; - return(_XUDC_ERROR); - } - - ret = _XUDCGetUDCGIArea(locale,codeset,charset_str,&gr,&num_gr); - if(ret == _XUDC_ERROR){ - _xudc_utyerrno &= 0xff ; - _xudc_utyerrno |= (0x0a<<8) ; - return(ret); - } - - crr = Xmalloc(num_gr * sizeof(_XUDCCodeRegion)); - if(crr == NULL){ - Xfree(gr); - _xudc_utyerrno = 0x03 ; - _xudc_utyerrno |= (0x0a<<8) ; - return(_XUDC_ERROR); - } - - for(i=0;i<num_gr;i++){ - ret = _xudc_glyph_to_code(locale,charset_str,codeset, - gr[i].start, &(crr[i].start)); - if(ret == _XUDC_ERROR){ - _xudc_utyerrno |= (0x0a<<8) ; - Xfree(gr); - Xfree(crr); - return(ret); - } - ret = _xudc_glyph_to_code(locale,charset_str,codeset, - gr[i].end, &(crr[i].end)); - if(ret == _XUDC_ERROR){ - _xudc_utyerrno |= (0x0a<<8) ; - Xfree(gr); - Xfree(crr); - return(ret); - } - } - Xfree(gr); - *cr = crr; - *num_cr = num_gr; - return(0); -} - -/* - * code_to_glyph() - * - */ -typedef struct __XUDCGIInf { - char *charset_str; - unsigned long glyph_index; -} _XUDCGIInf ; - -/* - * - * - */ -static Bool vgi_to_gi(gi,vgi,scope) -unsigned long *gi,vgi; -FontScope scope; -{ - if(vgi >= scope->start && vgi <= scope->end){ - if(scope->shift_direction == (unsigned long)'+'){ - *gi = vgi + scope->shift; - } else { - *gi = vgi - scope->shift; - } - return(True); - } - return(False); -} -/* - * - * - */ -static Bool -_xudc_vgi_to_gi(lcd,locale,vglyph,glyph,charset,charsetname,size) -XLCd lcd; -char *locale; -unsigned long vglyph; -unsigned long *glyph; -XlcCharSet charset; -char *charsetname; -int size; -{ - int num = 0,count,num_ret=0; - int i,j,k; - char **value,buf[128],ptr; - FontData font_data; - CodeSet cs; - - - for(i=0;;i++){ - sprintf(buf, "fs%d.charset.name",i); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - if(!_XlcNCompareISOLatin1(charset->name,value[0], - strlen(charset->name))){ - break; - } - } else { - _xudc_utyerrno = 0x17 ; - return(False); - } - } -/* - sprintf(buf, "fs%d.charset.name", codeset-1); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - strcpy(charsetname,value[0]); - } -*/ - sprintf(buf, "fs%d.font.primary", i); - _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); - if(count > 0){ - font_data = read_EncodingInfo(count,value); - for(i=0;i<count;i++){ - for(k=0;k<font_data[i].scopes_num;k++){ - if( vgi_to_gi(glyph,vglyph,&(font_data[i].scopes[k])) == True){ - if (strlen(font_data[i].name) >= size) - return(False); - strcpy(charsetname,font_data[i].name); - return(True); - } - } - } - } - *glyph = vglyph; - return(True); -} -int -_xudc_code_to_glyph(locale,codepoint,gi,num_gi) -char *locale; -unsigned long codepoint; -_XUDCGIInf **gi; -int *num_gi; -{ - XLCd lcd; - unsigned char *from; int from_left; - unsigned char *to ; int to_left = 10; - unsigned char *dst; - unsigned char byte; - unsigned int from32[25]; - unsigned int to32[25]; - int i,j; - char charsetname[256],src[10]; - XlcConv conv; - XlcCharSet charset; - XPointer args[2]; - unsigned long glyph,vglyph; - - from = (unsigned char *)from32; - to = (unsigned char *)to32; - dst = (unsigned char *)to32; - memset(dst,0,25); - - lcd = (XLCd)_XlcGenericLoader(locale); - - for(i=0,j=0;i<4;i++){ - byte = getbyte(codepoint,i); - if(byte){ - src[j] = byte; - j ++; - } - } - src[j] = 0; - sprintf((char *)from,"%s\0",src); - /* multi byte -> vgi */ - conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet); - from_left = strlen((char *)from); - args[0] = (XPointer) &charset; - _XlcConvert(conv,(XPointer *)&from,&from_left, - (XPointer *)&to, &to_left,args,1); - - /* vgi -> gi */ - vglyph = 0; - for(i=0;dst[i];i++){ - vglyph = ((vglyph << 8) | dst[i]) ; - } - if(_xudc_vgi_to_gi(lcd,locale,vglyph,&glyph,charset,charsetname, - sizeof(charsetname))==False){ - _XlcCloseConverter(conv); - _XlcDestroyLC(lcd); - *num_gi = 0; - return(0); - } - - _XlcCloseConverter(conv); - _XlcDestroyLC(lcd); - - *gi = Xmalloc(sizeof(_XUDCGIInf)); - if(*gi == NULL){ - _xudc_utyerrno = 0x03 ; - return(_XUDC_ERROR); - } - (*gi)->charset_str = Xmalloc(strlen(charsetname)+1); - strcpy((*gi)->charset_str,charsetname); - (*gi)->glyph_index = glyph; - *num_gi = 1; - return(0); -} - diff --git a/libX11/src/xcms/CCC.c b/libX11/src/xcms/CCC.c index 090b1078c..de6d6318a 100644 --- a/libX11/src/xcms/CCC.c +++ b/libX11/src/xcms/CCC.c @@ -111,7 +111,7 @@ XcmsCreateCCC( XcmsPerScrnInfo *pNewScrnInfo; if (pDefaultCCC == NULL || - !(newccc = (XcmsCCC) Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) { + !(newccc = Xcalloc(1, sizeof(XcmsCCCRec)))) { return(NULL); } @@ -144,8 +144,7 @@ XcmsCreateCCC( * If one exists replace the pPerScrnInfo. */ if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) { - if (!(pNewScrnInfo = (XcmsPerScrnInfo *) - Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { + if (!(pNewScrnInfo = Xcalloc(1, sizeof(XcmsPerScrnInfo)))) { Xfree(newccc); return(NULL); } diff --git a/libX11/src/xcms/CvCols.c b/libX11/src/xcms/CvCols.c index ed3582663..87d49311c 100644 --- a/libX11/src/xcms/CvCols.c +++ b/libX11/src/xcms/CvCols.c @@ -796,7 +796,7 @@ XcmsConvertColors( * Make copy of array of color specifications */ if (nColors > 1) { - pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor)); + pColors_tmp = Xmalloc(nColors * sizeof(XcmsColor)); } else { pColors_tmp = &Color1; } @@ -987,13 +987,13 @@ XcmsConvertColors( nColors * sizeof(XcmsColor)); } if (nColors > 1) { - Xfree((char *)pColors_tmp); + Xfree(pColors_tmp); } return(retval); Failure: if (nColors > 1) { - Xfree((char *)pColors_tmp); + Xfree(pColors_tmp); } return(XcmsFailure); } diff --git a/libX11/src/xcms/IdOfPr.c b/libX11/src/xcms/IdOfPr.c index 3a92e0a11..e15f34fec 100644 --- a/libX11/src/xcms/IdOfPr.c +++ b/libX11/src/xcms/IdOfPr.c @@ -67,7 +67,7 @@ XcmsFormatOfPrefix(char *prefix) * While copying prefix to string_lowered, convert to lowercase */ if ((len = strlen(prefix)) >= sizeof(string_buf)) { - string_lowered = (char *) Xmalloc(len+1); + string_lowered = Xmalloc(len+1); } else { string_lowered = string_buf; } diff --git a/libX11/src/xcms/LRGB.c b/libX11/src/xcms/LRGB.c index 5ecb7d120..461d07d87 100644 --- a/libX11/src/xcms/LRGB.c +++ b/libX11/src/xcms/LRGB.c @@ -511,7 +511,7 @@ LINEAR_RGB_InitSCCData( *pValue++ = (long)_XcmsGetElement(format_return, &pChar, &nitems) / (XcmsFloat)XDCCC_NUMBER; } - Xfree ((char *)property_return); + Xfree (property_return); pPerScrnInfo->screenWhitePt.spec.CIEXYZ.X = pScreenData->RGBtoXYZmatrix[0][0] + pScreenData->RGBtoXYZmatrix[0][1] + @@ -662,7 +662,7 @@ LINEAR_RGB_InitSCCData( /* Create, initialize, and add map */ if (!(pNewMap = (XcmsIntensityMap *) Xcalloc (1, sizeof(XcmsIntensityMap)))) { - Xfree((char *)pScreenData); + Xfree(pScreenData); goto Free_property_return; } pNewMap->visualID = visualID; @@ -782,7 +782,7 @@ LINEAR_RGB_InitSCCData( #endif /* ALLDEBUG */ } - Xfree ((char *)property_return); + Xfree (property_return); /* Free the old memory and use the new structure created. */ LINEAR_RGB_FreeSCCData(pPerScrnInfo->screenData); @@ -796,28 +796,28 @@ LINEAR_RGB_InitSCCData( return(XcmsSuccess); FreeBlueTblElements: - Xfree((char *)pScreenData->pBlueTbl->pBase); + Xfree(pScreenData->pBlueTbl->pBase); FreeBlueTbl: - Xfree((char *)pScreenData->pBlueTbl); + Xfree(pScreenData->pBlueTbl); FreeGreenTblElements: - Xfree((char *)pScreenData->pGreenTbl->pBase); + Xfree(pScreenData->pGreenTbl->pBase); FreeGreenTbl: - Xfree((char *)pScreenData->pGreenTbl); + Xfree(pScreenData->pGreenTbl); FreeRedTblElements: - Xfree((char *)pScreenData->pRedTbl->pBase); + Xfree(pScreenData->pRedTbl->pBase); FreeRedTbl: - Xfree((char *)pScreenData->pRedTbl); + Xfree(pScreenData->pRedTbl); Free_property_return: - Xfree ((char *)property_return); + Xfree (property_return); FreeSCCData: - Xfree((char *)pScreenDefaultData); + Xfree(pScreenDefaultData); pPerScrnInfo->state = XcmsInitNone; return(XcmsFailure); } @@ -849,30 +849,30 @@ LINEAR_RGB_FreeSCCData( if (pScreenData->pRedTbl->pBase != pScreenData->pGreenTbl->pBase) { if (pScreenData->pGreenTbl->pBase) { - Xfree ((char *)pScreenData->pGreenTbl->pBase); + Xfree (pScreenData->pGreenTbl->pBase); } } if (pScreenData->pGreenTbl != pScreenData->pRedTbl) { - Xfree ((char *)pScreenData->pGreenTbl); + Xfree (pScreenData->pGreenTbl); } } if (pScreenData->pBlueTbl) { if (pScreenData->pRedTbl->pBase != pScreenData->pBlueTbl->pBase) { if (pScreenData->pBlueTbl->pBase) { - Xfree ((char *)pScreenData->pBlueTbl->pBase); + Xfree (pScreenData->pBlueTbl->pBase); } } if (pScreenData->pBlueTbl != pScreenData->pRedTbl) { - Xfree ((char *)pScreenData->pBlueTbl); + Xfree (pScreenData->pBlueTbl); } } if (pScreenData->pRedTbl->pBase) { - Xfree ((char *)pScreenData->pRedTbl->pBase); + Xfree (pScreenData->pRedTbl->pBase); } - Xfree ((char *)pScreenData->pRedTbl); + Xfree (pScreenData->pRedTbl); } - Xfree ((char *)pScreenData); + Xfree (pScreenData); } } diff --git a/libX11/src/xcms/SetGetCols.c b/libX11/src/xcms/SetGetCols.c index 9b548dbb2..83fa4c200 100644 --- a/libX11/src/xcms/SetGetCols.c +++ b/libX11/src/xcms/SetGetCols.c @@ -237,7 +237,7 @@ _XcmsSetGetColors( /* * Allocate space for XColors */ - if ((pXColors_in_out = (XColor *)Xcalloc(nColors, sizeof(XColor))) == + if ((pXColors_in_out = Xcalloc(nColors, sizeof(XColor))) == NULL) { return(XcmsFailure); } @@ -251,7 +251,7 @@ _XcmsSetGetColors( */ if ((retval = XcmsConvertColors(ccc, pColors_in_out, nColors, XcmsRGBFormat, pCompressed)) == XcmsFailure) { - Xfree((char *)pXColors_in_out); + Xfree(pXColors_in_out); return(XcmsFailure); } @@ -268,12 +268,12 @@ Query: /* Note: XQueryColors and XStoreColors do not return any Status */ (*xColorProc)(ccc->dpy, cmap, pXColors_in_out, nColors); } else { - Xfree((char *)pXColors_in_out); + Xfree(pXColors_in_out); return(XcmsFailure); } if (*xColorProc == XStoreColors) { - Xfree((char *)pXColors_in_out); + Xfree(pXColors_in_out); return(retval); } @@ -281,7 +281,7 @@ Query: * Now, convert the returned XColor (i.e., rgb) to XcmsColor structures */ _XColor_to_XcmsRGB(ccc, pXColors_in_out, pColors_in_out, nColors); - Xfree((char *)pXColors_in_out); + Xfree(pXColors_in_out); /* * Then, convert XcmsColor structures to the original specification diff --git a/libX11/src/xcms/StCols.c b/libX11/src/xcms/StCols.c index 24ccd386f..42a29cd7f 100644 --- a/libX11/src/xcms/StCols.c +++ b/libX11/src/xcms/StCols.c @@ -85,7 +85,7 @@ XcmsStoreColors( * overwrite the contents. */ if (nColors > 1) { - pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor)); + pColors_tmp = Xmalloc(nColors * sizeof(XcmsColor)); } else { pColors_tmp = &Color1; } @@ -102,7 +102,7 @@ XcmsStoreColors( * Free copies as needed. */ if (nColors > 1) { - Xfree((char *)pColors_tmp); + Xfree(pColors_tmp); } /* diff --git a/libX11/src/xcms/cmsCmap.c b/libX11/src/xcms/cmsCmap.c index 00816ce03..c5401c05d 100644 --- a/libX11/src/xcms/cmsCmap.c +++ b/libX11/src/xcms/cmsCmap.c @@ -191,7 +191,7 @@ CmapRecForColormap( SyncHandle(); } while (async_state.error_count > 0 && ++j < nVisualsMatched); - Xfree((char *)visualList); + Xfree(visualList); /* * if successful @@ -250,8 +250,7 @@ _XcmsAddCmapRec( { XcmsCmapRec *pNew; - if ((pNew = (XcmsCmapRec *) Xcalloc(1, (unsigned) sizeof(XcmsCmapRec))) - == NULL) { + if ((pNew = Xcalloc(1, sizeof(XcmsCmapRec))) == NULL) { return((XcmsCmapRec *)NULL); } @@ -301,7 +300,7 @@ _XcmsCopyCmapRecAndFree( pRec_copy =_XcmsAddCmapRec(dpy, copy_cmap, pRec_src->windowID, pRec_src->visual); if (pRec_copy != NULL && pRec_src->ccc) { - pRec_copy->ccc = (XcmsCCC)Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)); + pRec_copy->ccc = Xcalloc(1, sizeof(XcmsCCCRec)); memcpy((char *)pRec_copy->ccc, (char *)pRec_src->ccc, sizeof(XcmsCCCRec)); } @@ -353,7 +352,7 @@ _XcmsDeleteCmapRec( XcmsFreeCCC(pRec->ccc); } *pPrevPtr = pRec->pNext; - Xfree((char *)pRec); + Xfree(pRec); } } @@ -388,7 +387,7 @@ _XcmsFreeClientCmaps( XcmsFreeCCC(pRecFree->ccc); } /* Now free the XcmsCmapRec structure */ - Xfree((char *)pRecFree); + Xfree(pRecFree); } dpy->cms.clientCmaps = (XPointer)NULL; } diff --git a/libX11/src/xcms/cmsColNm.c b/libX11/src/xcms/cmsColNm.c index 8d0d4a771..ecf19b37e 100644 --- a/libX11/src/xcms/cmsColNm.c +++ b/libX11/src/xcms/cmsColNm.c @@ -209,7 +209,7 @@ _XcmsParseColorString( * While copying color_string to string_lowered, convert to lowercase */ if ((len = strlen(color_string)) >= sizeof(string_buf)) { - string_lowered = (char *) Xmalloc(len+1); + string_lowered = Xmalloc(len+1); } else { string_lowered = string_buf; } @@ -418,7 +418,7 @@ _XcmsLookupColorName( Retry: if ((len = strlen(tmpName)) > 63) { - name_lowered = (char *) Xmalloc(len+1); + name_lowered = Xmalloc(len+1); } else { name_lowered = name_lowered_64; } @@ -760,8 +760,8 @@ LoadColornameDB(void) } rewind(stream); - strings = (char *) Xmalloc(size); - pairs = (XcmsPair *)Xcalloc(nEntries, sizeof(XcmsPair)); + strings = Xmalloc(size); + pairs = Xcalloc(nEntries, sizeof(XcmsPair)); ReadColornameDB(stream, pairs, strings); (void) fclose(stream); diff --git a/libX11/src/xcms/cmsInt.c b/libX11/src/xcms/cmsInt.c index b7c321472..f4aef04ff 100644 --- a/libX11/src/xcms/cmsInt.c +++ b/libX11/src/xcms/cmsInt.c @@ -82,7 +82,7 @@ _XcmsCopyPointerArray( for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++); n++; /* add 1 to include the NULL pointer */ - if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) { + if ((newArray = Xmalloc(n * sizeof(XPointer)))) { memcpy((char *)newArray, (char *)pap, (unsigned)(n * sizeof(XPointer))); } @@ -141,7 +141,7 @@ _XcmsPushPointerArray( /* add 2: 1 for the new pointer and another for the NULL pointer */ n += 2; - if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) { + if ((newArray = Xmalloc(n * sizeof(XPointer)))) { memcpy((char *)(newArray+1),(char *)pap, (unsigned)((n-1) * sizeof(XPointer))); *newArray = p; @@ -183,8 +183,7 @@ _XcmsInitDefaultCCCs( * Create an array of XcmsCCC structures, one for each screen. * They serve as the screen's default CCC. */ - if (!(ccc = (XcmsCCC) - Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) { + if (!(ccc = Xcalloc((unsigned)nScrn, sizeof(XcmsCCCRec)))) { return(0); } dpy->cms.defaultCCCs = (XPointer)ccc; @@ -322,8 +321,8 @@ _XcmsInitScrnInfo( * for the latter (see XcmsCreateCCC). The ones created * here are referenced by the default CCC. */ - if (!(defaultccc->pPerScrnInfo = (XcmsPerScrnInfo *) - Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { + if (!(defaultccc->pPerScrnInfo = + Xcalloc(1, sizeof(XcmsPerScrnInfo)))) { return(0); } defaultccc->pPerScrnInfo->state = XcmsInitNone; diff --git a/libX11/src/xkb/XKB.c b/libX11/src/xkb/XKB.c index 374e27d2d..7a66b3668 100644 --- a/libX11/src/xkb/XKB.c +++ b/libX11/src/xkb/XKB.c @@ -37,45 +37,47 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <X11/extensions/XKBproto.h> #include "XKBlibint.h" -XkbInternAtomFunc _XkbInternAtomFunc= XInternAtom; -XkbGetAtomNameFunc _XkbGetAtomNameFunc= XGetAtomName; +XkbInternAtomFunc _XkbInternAtomFunc = XInternAtom; +XkbGetAtomNameFunc _XkbGetAtomNameFunc = XGetAtomName; Bool -XkbQueryExtension( Display *dpy, - int * opcodeReturn, - int * eventBaseReturn, - int * errorBaseReturn, - int * majorReturn, - int * minorReturn) +XkbQueryExtension(Display *dpy, + int *opcodeReturn, + int *eventBaseReturn, + int *errorBaseReturn, + int *majorReturn, + int *minorReturn) { - if (!XkbUseExtension(dpy,majorReturn,minorReturn)) - return False; + if (!XkbUseExtension(dpy, majorReturn, minorReturn)) + return False; if (opcodeReturn) - *opcodeReturn = dpy->xkb_info->codes->major_opcode; + *opcodeReturn = dpy->xkb_info->codes->major_opcode; if (eventBaseReturn) - *eventBaseReturn = dpy->xkb_info->codes->first_event; + *eventBaseReturn = dpy->xkb_info->codes->first_event; if (errorBaseReturn) - *errorBaseReturn = dpy->xkb_info->codes->first_error; + *errorBaseReturn = dpy->xkb_info->codes->first_error; if (majorReturn) - *majorReturn = dpy->xkb_info->srv_major; + *majorReturn = dpy->xkb_info->srv_major; if (minorReturn) - *minorReturn = dpy->xkb_info->srv_minor; + *minorReturn = dpy->xkb_info->srv_minor; return True; } Bool -XkbLibraryVersion(int *libMajorRtrn,int *libMinorRtrn) +XkbLibraryVersion(int *libMajorRtrn, int *libMinorRtrn) { -int supported; + int supported; if (*libMajorRtrn != XkbMajorVersion) { - /* version 0.65 is (almost) compatible with 1.00 */ - if ((XkbMajorVersion==1)&&(((*libMajorRtrn)==0)&&((*libMinorRtrn)==65))) - supported= True; - else supported= False; + /* version 0.65 is (almost) compatible with 1.00 */ + if ((XkbMajorVersion == 1) && + (((*libMajorRtrn) == 0) && ((*libMinorRtrn) == 65))) + supported = True; + else + supported = False; } else { - supported = True; + supported = True; } *libMajorRtrn = XkbMajorVersion; @@ -84,49 +86,52 @@ int supported; } Bool -XkbSelectEvents( Display * dpy, - unsigned int deviceSpec, - unsigned int affect, - unsigned int selectAll) +XkbSelectEvents(Display *dpy, + unsigned int deviceSpec, + unsigned int affect, + unsigned int selectAll) { register xkbSelectEventsReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; - xkbi->selected_events&= ~affect; - xkbi->selected_events|= (affect&selectAll); + xkbi->selected_events &= ~affect; + xkbi->selected_events |= (affect & selectAll); GetReq(kbSelectEvents, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSelectEvents; req->deviceSpec = deviceSpec; - req->affectWhich = (CARD16)affect; - req->clear = affect&(~selectAll); - req->selectAll = affect&selectAll; - if (affect&XkbMapNotifyMask) { - req->affectMap= XkbAllMapComponentsMask; - /* the implicit support needs the client info */ - /* even if the client itself doesn't want it */ - if (selectAll&XkbMapNotifyMask) - req->map= XkbAllMapEventsMask; - else req->map= XkbAllClientInfoMask; - if (selectAll&XkbMapNotifyMask) - xkbi->selected_map_details= XkbAllMapEventsMask; - else xkbi->selected_map_details= 0; + req->affectWhich = (CARD16) affect; + req->clear = affect & (~selectAll); + req->selectAll = affect & selectAll; + if (affect & XkbMapNotifyMask) { + req->affectMap = XkbAllMapComponentsMask; + /* the implicit support needs the client info */ + /* even if the client itself doesn't want it */ + if (selectAll & XkbMapNotifyMask) + req->map = XkbAllMapEventsMask; + else + req->map = XkbAllClientInfoMask; + if (selectAll & XkbMapNotifyMask) + xkbi->selected_map_details = XkbAllMapEventsMask; + else + xkbi->selected_map_details = 0; } - if (affect&XkbNewKeyboardNotifyMask) { - if (selectAll&XkbNewKeyboardNotifyMask) - xkbi->selected_nkn_details= XkbAllNewKeyboardEventsMask; - else xkbi->selected_nkn_details= 0; - if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) { - /* we want it, even if the client doesn't. Don't mess */ - /* around with details -- ask for all of them and throw */ - /* away the ones we don't need */ - req->selectAll|= XkbNewKeyboardNotifyMask; - } + if (affect & XkbNewKeyboardNotifyMask) { + if (selectAll & XkbNewKeyboardNotifyMask) + xkbi->selected_nkn_details = XkbAllNewKeyboardEventsMask; + else + xkbi->selected_nkn_details = 0; + if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) { + /* we want it, even if the client doesn't. Don't mess */ + /* around with details -- ask for all of them and throw */ + /* away the ones we don't need */ + req->selectAll |= XkbNewKeyboardNotifyMask; + } } UnlockDisplay(dpy); SyncHandle(); @@ -134,91 +139,94 @@ XkbSelectEvents( Display * dpy, } Bool -XkbSelectEventDetails( Display * dpy, - unsigned deviceSpec, - unsigned eventType, - unsigned long int affect, - unsigned long int details) +XkbSelectEventDetails(Display *dpy, + unsigned deviceSpec, + unsigned eventType, + unsigned long int affect, + unsigned long int details) { register xkbSelectEventsReq *req; - XkbInfoPtr xkbi; - int size = 0; - char *out; + XkbInfoPtr xkbi; + int size = 0; + char *out; union { - CARD8 *c8; - CARD16 *c16; - CARD32 *c32; + CARD8 *c8; + CARD16 *c16; + CARD32 *c32; } u; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; - if (affect&details) xkbi->selected_events|= (1<<eventType); - else xkbi->selected_events&= ~(1<<eventType); + if (affect & details) + xkbi->selected_events |= (1 << eventType); + else + xkbi->selected_events &= ~(1 << eventType); GetReq(kbSelectEvents, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSelectEvents; req->deviceSpec = deviceSpec; - req->clear= req->selectAll= 0; - if (eventType==XkbMapNotify) { - /* we need all of the client info, even if the application */ - /* doesn't. Make sure that we always request the stuff */ - /* that the implicit support needs, and just filter out anything */ - /* the client doesn't want later */ - req->affectWhich = 0; - req->selectAll = 0; - req->clear = 0; - req->affectMap = (CARD16)affect; - req->map = (CARD16)details|(XkbAllClientInfoMask&affect); - req->affectWhich = XkbMapNotifyMask; - xkbi->selected_map_details&= ~affect; - xkbi->selected_map_details|= (details&affect); + req->clear = req->selectAll = 0; + if (eventType == XkbMapNotify) { + /* we need all of the client info, even if the application */ + /* doesn't. Make sure that we always request the stuff */ + /* that the implicit support needs, and just filter out anything */ + /* the client doesn't want later */ + req->affectWhich = 0; + req->selectAll = 0; + req->clear = 0; + req->affectMap = (CARD16) affect; + req->map = (CARD16) details | (XkbAllClientInfoMask & affect); + req->affectWhich = XkbMapNotifyMask; + xkbi->selected_map_details &= ~affect; + xkbi->selected_map_details |= (details & affect); } else { - req->affectMap = req->map = 0; - req->affectWhich= (1<<eventType); - switch (eventType) { - case XkbNewKeyboardNotify: - xkbi->selected_nkn_details&= ~affect; - xkbi->selected_nkn_details|= (details&affect); - if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) - details= (affect&XkbAllNewKeyboardEventsMask); - case XkbStateNotify: - case XkbNamesNotify: - case XkbAccessXNotify: - case XkbExtensionDeviceNotify: - size= 2; - req->length+= 1; - break; - case XkbControlsNotify: - case XkbIndicatorStateNotify: - case XkbIndicatorMapNotify: - size= 4; - req->length+= 2; - break; - case XkbBellNotify: - case XkbActionMessage: - case XkbCompatMapNotify: - size= 1; - req->length+= 1; - break; - } - BufAlloc(char *,out,(((size*2)+(unsigned)3)/4)*4); - u.c8= (CARD8 *)out; - if (size==2) { - u.c16[0]= (CARD16)affect; - u.c16[1]= (CARD16)details; - } - else if (size==4) { - u.c32[0]= (CARD32)affect; - u.c32[1]= (CARD32)details; - } - else { - u.c8[0]= (CARD8)affect; - u.c8[1]= (CARD8)details; - } + req->affectMap = req->map = 0; + req->affectWhich = (1 << eventType); + switch (eventType) { + case XkbNewKeyboardNotify: + xkbi->selected_nkn_details &= ~affect; + xkbi->selected_nkn_details |= (details & affect); + if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) + details = (affect & XkbAllNewKeyboardEventsMask); + case XkbStateNotify: + case XkbNamesNotify: + case XkbAccessXNotify: + case XkbExtensionDeviceNotify: + size = 2; + req->length += 1; + break; + case XkbControlsNotify: + case XkbIndicatorStateNotify: + case XkbIndicatorMapNotify: + size = 4; + req->length += 2; + break; + case XkbBellNotify: + case XkbActionMessage: + case XkbCompatMapNotify: + size = 1; + req->length += 1; + break; + } + BufAlloc(char *, out, (((size * 2) + (unsigned) 3) / 4) * 4); + + u.c8 = (CARD8 *) out; + if (size == 2) { + u.c16[0] = (CARD16) affect; + u.c16[1] = (CARD16) details; + } + else if (size == 4) { + u.c32[0] = (CARD32) affect; + u.c32[1] = (CARD32) details; + } + else { + u.c8[0] = (CARD8) affect; + u.c8[1] = (CARD8) details; + } } UnlockDisplay(dpy); SyncHandle(); @@ -226,24 +234,24 @@ XkbSelectEventDetails( Display * dpy, } Bool -XkbLockModifiers( Display * dpy, - unsigned int deviceSpec, - unsigned int affect, - unsigned int values) +XkbLockModifiers(Display *dpy, + unsigned int deviceSpec, + unsigned int affect, + unsigned int values) { register xkbLatchLockStateReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbLatchLockState, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbLatchLockState; req->deviceSpec = deviceSpec; - req->affectModLocks= affect; + req->affectModLocks = affect; req->modLocks = values; req->lockGroup = False; req->groupLock = 0; @@ -257,17 +265,17 @@ XkbLockModifiers( Display * dpy, } Bool -XkbLatchModifiers( Display * dpy, - unsigned int deviceSpec, - unsigned int affect, - unsigned int values) +XkbLatchModifiers(Display *dpy, + unsigned int deviceSpec, + unsigned int affect, + unsigned int values) { register xkbLatchLockStateReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbLatchLockState, req); @@ -275,7 +283,7 @@ XkbLatchModifiers( Display * dpy, req->xkbReqType = X_kbLatchLockState; req->deviceSpec = deviceSpec; - req->affectModLatches= affect; + req->affectModLatches = affect; req->modLatches = values; req->latchGroup = False; req->groupLatch = 0; @@ -290,21 +298,21 @@ XkbLatchModifiers( Display * dpy, } Bool -XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) +XkbLockGroup(Display *dpy, unsigned int deviceSpec, unsigned int group) { register xkbLatchLockStateReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbLatchLockState, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbLatchLockState; req->deviceSpec = deviceSpec; - req->affectModLocks= 0; + req->affectModLocks = 0; req->modLocks = 0; req->lockGroup = True; req->groupLock = group; @@ -318,14 +326,14 @@ XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) } Bool -XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) +XkbLatchGroup(Display *dpy, unsigned int deviceSpec, unsigned int group) { register xkbLatchLockStateReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbLatchLockState, req); @@ -333,7 +341,7 @@ XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) req->xkbReqType = X_kbLatchLockState; req->deviceSpec = deviceSpec; - req->affectModLatches= 0; + req->affectModLatches = 0; req->modLatches = 0; req->latchGroup = True; req->groupLatch = group; @@ -348,15 +356,15 @@ XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) } unsigned -XkbSetXlibControls(Display *dpy,unsigned affect,unsigned values) +XkbSetXlibControls(Display *dpy, unsigned affect, unsigned values) { if (!dpy->xkb_info) - XkbUseExtension(dpy,NULL,NULL); + XkbUseExtension(dpy, NULL, NULL); if (!dpy->xkb_info) - return 0; - affect&= XkbLC_AllControls; - dpy->xkb_info->xlib_ctrls&= ~affect; - dpy->xkb_info->xlib_ctrls|= (affect&values); + return 0; + affect &= XkbLC_AllControls; + dpy->xkb_info->xlib_ctrls &= ~affect; + dpy->xkb_info->xlib_ctrls |= (affect & values); return dpy->xkb_info->xlib_ctrls; } @@ -364,9 +372,9 @@ unsigned XkbGetXlibControls(Display *dpy) { if (!dpy->xkb_info) - XkbUseExtension(dpy,NULL,NULL); + XkbUseExtension(dpy, NULL, NULL); if (!dpy->xkb_info) - return 0; + return 0; return dpy->xkb_info->xlib_ctrls; } @@ -376,155 +384,157 @@ XkbXlibControlsImplemented(void) #ifdef __sgi return XkbLC_AllControls; #else - return XkbLC_AllControls&~XkbLC_AllComposeControls; + return XkbLC_AllControls & ~XkbLC_AllComposeControls; #endif } Bool -XkbSetDebuggingFlags( Display * dpy, - unsigned int mask, - unsigned int flags, - char * msg, - unsigned int ctrls_mask, - unsigned int ctrls, - unsigned int * rtrn_flags, - unsigned int * rtrn_ctrls) +XkbSetDebuggingFlags(Display *dpy, + unsigned int mask, + unsigned int flags, + char *msg, + unsigned int ctrls_mask, + unsigned int ctrls, + unsigned int *rtrn_flags, + unsigned int *rtrn_ctrls) { register xkbSetDebuggingFlagsReq *req; xkbSetDebuggingFlagsReply rep; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetDebuggingFlags, req); - req->reqType= xkbi->codes->major_opcode; - req->xkbReqType= X_kbSetDebuggingFlags; - req->affectFlags= mask; - req->flags= flags; - req->affectCtrls= ctrls_mask; - req->ctrls= ctrls; + req->reqType = xkbi->codes->major_opcode; + req->xkbReqType = X_kbSetDebuggingFlags; + req->affectFlags = mask; + req->flags = flags; + req->affectCtrls = ctrls_mask; + req->ctrls = ctrls; if (msg) { - char *out; - req->msgLength= (unsigned short)strlen(msg)+1; - req->length+= (req->msgLength+(unsigned)3)>>2; - BufAlloc(char *,out,((req->msgLength+(unsigned)3)/4)*4); - memcpy(out,msg,req->msgLength); + char *out; + + req->msgLength = (unsigned short) strlen(msg) + 1; + req->length += (req->msgLength + (unsigned) 3) >> 2; + BufAlloc(char *, out, ((req->msgLength + (unsigned) 3) / 4) * 4); + memcpy(out, msg, req->msgLength); } - else req->msgLength= 0; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + else + req->msgLength = 0; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } if (rtrn_flags) - *rtrn_flags= rep.currentFlags; + *rtrn_flags = rep.currentFlags; if (rtrn_ctrls) - *rtrn_ctrls= rep.currentCtrls; + *rtrn_ctrls = rep.currentCtrls; UnlockDisplay(dpy); SyncHandle(); return True; } Bool -XkbComputeEffectiveMap( XkbDescPtr xkb, - XkbKeyTypePtr type, - unsigned char * map_rtrn) +XkbComputeEffectiveMap(XkbDescPtr xkb, + XkbKeyTypePtr type, + unsigned char *map_rtrn) { -register int i; -unsigned tmp; -XkbKTMapEntryPtr entry = NULL; - - if ((!xkb)||(!type)||(!xkb->server)) - return False; - - if (type->mods.vmods!=0) { - if (!XkbVirtualModsToReal(xkb,type->mods.vmods,&tmp)) - return False; - - type->mods.mask= tmp|type->mods.real_mods; - entry= type->map; - for (i=0;i<type->map_count;i++,entry++) { - tmp= 0; - if (entry->mods.vmods!=0) { - if (!XkbVirtualModsToReal(xkb,entry->mods.vmods,&tmp)) - return False; - if (tmp==0) { - entry->active= False; - continue; - } - } - entry->active= True; - entry->mods.mask= (entry->mods.real_mods|tmp)&type->mods.mask; - } + register int i; + unsigned tmp; + XkbKTMapEntryPtr entry = NULL; + + if ((!xkb) || (!type) || (!xkb->server)) + return False; + + if (type->mods.vmods != 0) { + if (!XkbVirtualModsToReal(xkb, type->mods.vmods, &tmp)) + return False; + + type->mods.mask = tmp | type->mods.real_mods; + entry = type->map; + for (i = 0; i < type->map_count; i++, entry++) { + tmp = 0; + if (entry->mods.vmods != 0) { + if (!XkbVirtualModsToReal(xkb, entry->mods.vmods, &tmp)) + return False; + if (tmp == 0) { + entry->active = False; + continue; + } + } + entry->active = True; + entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask; + } } else { - type->mods.mask= type->mods.real_mods; + type->mods.mask = type->mods.real_mods; } - if (map_rtrn!=NULL) { - bzero(map_rtrn,type->mods.mask+1); - for (i=0;i<type->map_count;i++) { - if (entry && entry->active) { - map_rtrn[type->map[i].mods.mask]= type->map[i].level; - } - } + if (map_rtrn != NULL) { + bzero(map_rtrn, type->mods.mask + 1); + for (i = 0; i < type->map_count; i++) { + if (entry && entry->active) { + map_rtrn[type->map[i].mods.mask] = type->map[i].level; + } + } } return True; } Status -XkbGetState(Display *dpy,unsigned deviceSpec,XkbStatePtr rtrn) +XkbGetState(Display *dpy, unsigned deviceSpec, XkbStatePtr rtrn) { - register xkbGetStateReq *req; + register xkbGetStateReq *req; xkbGetStateReply rep; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetState, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetState; req->deviceSpec = deviceSpec; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadImplementation; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadImplementation; } - rtrn->mods= rep.mods; - rtrn->base_mods= rep.baseMods; - rtrn->latched_mods= rep.latchedMods; - rtrn->locked_mods= rep.lockedMods; - rtrn->group= rep.group; - rtrn->base_group= rep.baseGroup; - rtrn->latched_group= rep.latchedGroup; - rtrn->locked_group= rep.lockedGroup; - rtrn->compat_state= rep.compatState; - rtrn->grab_mods= rep.grabMods; - rtrn->compat_grab_mods= rep.compatGrabMods; - rtrn->lookup_mods= rep.lookupMods; - rtrn->compat_lookup_mods= rep.compatLookupMods; - rtrn->ptr_buttons= rep.ptrBtnState; + rtrn->mods = rep.mods; + rtrn->base_mods = rep.baseMods; + rtrn->latched_mods = rep.latchedMods; + rtrn->locked_mods = rep.lockedMods; + rtrn->group = rep.group; + rtrn->base_group = rep.baseGroup; + rtrn->latched_group = rep.latchedGroup; + rtrn->locked_group = rep.lockedGroup; + rtrn->compat_state = rep.compatState; + rtrn->grab_mods = rep.grabMods; + rtrn->compat_grab_mods = rep.compatGrabMods; + rtrn->lookup_mods = rep.lookupMods; + rtrn->compat_lookup_mods = rep.compatLookupMods; + rtrn->ptr_buttons = rep.ptrBtnState; UnlockDisplay(dpy); SyncHandle(); return Success; } Bool -XkbSetDetectableAutoRepeat(Display *dpy,Bool detectable,Bool *supported) +XkbSetDetectableAutoRepeat(Display *dpy, Bool detectable, Bool *supported) { -register xkbPerClientFlagsReq * req; -xkbPerClientFlagsReply rep; -XkbInfoPtr xkbi; + register xkbPerClientFlagsReq *req; + xkbPerClientFlagsReply rep; + XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbPerClientFlags, req); @@ -533,31 +543,32 @@ XkbInfoPtr xkbi; req->deviceSpec = XkbUseCoreKbd; req->change = XkbPCF_DetectableAutoRepeatMask; if (detectable) - req->value = XkbPCF_DetectableAutoRepeatMask; - else req->value = 0; - req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->value = XkbPCF_DetectableAutoRepeatMask; + else + req->value = 0; + req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); - if (supported!=NULL) - *supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0); - return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0); + if (supported != NULL) + *supported = ((rep.supported & XkbPCF_DetectableAutoRepeatMask) != 0); + return ((rep.value & XkbPCF_DetectableAutoRepeatMask) != 0); } Bool -XkbGetDetectableAutoRepeat(Display *dpy,Bool *supported) +XkbGetDetectableAutoRepeat(Display *dpy, Bool *supported) { -register xkbPerClientFlagsReq * req; -xkbPerClientFlagsReply rep; -XkbInfoPtr xkbi; + register xkbPerClientFlagsReq *req; + xkbPerClientFlagsReply rep; + XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbPerClientFlags, req); @@ -566,32 +577,32 @@ XkbInfoPtr xkbi; req->deviceSpec = XkbUseCoreKbd; req->change = 0; req->value = 0; - req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); - if (supported!=NULL) - *supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0); - return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0); + if (supported != NULL) + *supported = ((rep.supported & XkbPCF_DetectableAutoRepeatMask) != 0); + return ((rep.value & XkbPCF_DetectableAutoRepeatMask) != 0); } Bool -XkbSetAutoResetControls( Display * dpy, - unsigned changes, - unsigned * auto_ctrls, - unsigned * auto_values) +XkbSetAutoResetControls(Display *dpy, + unsigned changes, + unsigned *auto_ctrls, + unsigned *auto_values) { -register xkbPerClientFlagsReq * req; -xkbPerClientFlagsReply rep; -XkbInfoPtr xkbi; + register xkbPerClientFlagsReq *req; + xkbPerClientFlagsReply rep; + XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbPerClientFlags, req); @@ -600,33 +611,33 @@ XkbInfoPtr xkbi; req->change = XkbPCF_AutoResetControlsMask; req->deviceSpec = XkbUseCoreKbd; req->value = XkbPCF_AutoResetControlsMask; - req->ctrlsToChange= changes; - req->autoCtrls= *auto_ctrls; - req->autoCtrlValues= *auto_values; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->ctrlsToChange = changes; + req->autoCtrls = *auto_ctrls; + req->autoCtrlValues = *auto_values; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); - *auto_ctrls= rep.autoCtrls; - *auto_values= rep.autoCtrlValues; - return ((rep.value&XkbPCF_AutoResetControlsMask)!=0); + *auto_ctrls = rep.autoCtrls; + *auto_values = rep.autoCtrlValues; + return ((rep.value & XkbPCF_AutoResetControlsMask) != 0); } Bool -XkbGetAutoResetControls( Display * dpy, - unsigned * auto_ctrls, - unsigned * auto_ctrl_values) +XkbGetAutoResetControls(Display *dpy, + unsigned *auto_ctrls, + unsigned *auto_ctrl_values) { -register xkbPerClientFlagsReq * req; -xkbPerClientFlagsReply rep; -XkbInfoPtr xkbi; + register xkbPerClientFlagsReq *req; + xkbPerClientFlagsReply rep; + XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbPerClientFlags, req); @@ -635,35 +646,35 @@ XkbInfoPtr xkbi; req->deviceSpec = XkbUseCoreKbd; req->change = 0; req->value = 0; - req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); if (auto_ctrls) - *auto_ctrls= rep.autoCtrls; + *auto_ctrls = rep.autoCtrls; if (auto_ctrl_values) - *auto_ctrl_values= rep.autoCtrlValues; - return ((rep.value&XkbPCF_AutoResetControlsMask)!=0); + *auto_ctrl_values = rep.autoCtrlValues; + return ((rep.value & XkbPCF_AutoResetControlsMask) != 0); } Bool -XkbSetPerClientControls( Display * dpy, - unsigned change, - unsigned * values) +XkbSetPerClientControls(Display *dpy, unsigned change, unsigned *values) { -register xkbPerClientFlagsReq * req; -xkbPerClientFlagsReply rep; -XkbInfoPtr xkbi; -unsigned value_hold = *values; + register xkbPerClientFlagsReq *req; + xkbPerClientFlagsReply rep; + XkbInfoPtr xkbi; + unsigned value_hold = *values; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || - (change & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || + (change & ~(XkbPCF_GrabsUseXKBStateMask | + XkbPCF_LookupStateWhenGrabbed | + XkbPCF_SendEventUsesXKBState))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbPerClientFlags, req); @@ -672,30 +683,31 @@ unsigned value_hold = *values; req->change = change; req->deviceSpec = XkbUseCoreKbd; req->value = *values; - req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues= 0; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); *values = rep.value; - return ((rep.value&value_hold)!=0); + return ((rep.value & value_hold) != 0); } Bool -XkbGetPerClientControls( Display * dpy, - unsigned * ctrls) +XkbGetPerClientControls(Display *dpy, unsigned *ctrls) { -register xkbPerClientFlagsReq * req; -xkbPerClientFlagsReply rep; -XkbInfoPtr xkbi; + register xkbPerClientFlagsReq *req; + xkbPerClientFlagsReply rep; + XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || - (*ctrls & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || + (*ctrls & ~(XkbPCF_GrabsUseXKBStateMask | + XkbPCF_LookupStateWhenGrabbed | + XkbPCF_SendEventUsesXKBState))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbPerClientFlags, req); @@ -704,69 +716,71 @@ XkbInfoPtr xkbi; req->deviceSpec = XkbUseCoreKbd; req->change = 0; req->value = 0; - req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); if (ctrls) - *ctrls= (rep.value & (XkbPCF_GrabsUseXKBStateMask | - XkbPCF_LookupStateWhenGrabbed | - XkbPCF_SendEventUsesXKBState)); + *ctrls = (rep.value & (XkbPCF_GrabsUseXKBStateMask | + XkbPCF_LookupStateWhenGrabbed | + XkbPCF_SendEventUsesXKBState)); return (True); } Display * -XkbOpenDisplay( char * name, - int * ev_rtrn, - int * err_rtrn, - int * major_rtrn, - int * minor_rtrn, - int * reason) +XkbOpenDisplay(char *name, + int *ev_rtrn, + int *err_rtrn, + int *major_rtrn, + int *minor_rtrn, + int *reason) { - Display* dpy; - int major_num,minor_num; - - if ((major_rtrn!=NULL) && (minor_rtrn!=NULL)) { - if (!XkbLibraryVersion(major_rtrn,minor_rtrn)) { - if (reason!=NULL) - *reason= XkbOD_BadLibraryVersion; - return NULL; - } + Display *dpy; + int major_num, minor_num; + + if ((major_rtrn != NULL) && (minor_rtrn != NULL)) { + if (!XkbLibraryVersion(major_rtrn, minor_rtrn)) { + if (reason != NULL) + *reason = XkbOD_BadLibraryVersion; + return NULL; + } } else { - major_num= XkbMajorVersion; - minor_num= XkbMinorVersion; - major_rtrn= &major_num; - minor_rtrn= &minor_num; + major_num = XkbMajorVersion; + minor_num = XkbMinorVersion; + major_rtrn = &major_num; + minor_rtrn = &minor_num; } - dpy= XOpenDisplay(name); - if (dpy==NULL) { - if (reason!=NULL) - *reason= XkbOD_ConnectionRefused; - return NULL; + dpy = XOpenDisplay(name); + if (dpy == NULL) { + if (reason != NULL) + *reason = XkbOD_ConnectionRefused; + return NULL; } - if (!XkbQueryExtension(dpy,NULL,ev_rtrn,err_rtrn,major_rtrn,minor_rtrn)) { - if (reason!=NULL) { - if ((*major_rtrn!=0)||(*minor_rtrn!=0)) - *reason= XkbOD_BadServerVersion; - else *reason= XkbOD_NonXkbServer; - } - XCloseDisplay(dpy); - return NULL; + if (!XkbQueryExtension(dpy, NULL, ev_rtrn, err_rtrn, + major_rtrn, minor_rtrn)) { + if (reason != NULL) { + if ((*major_rtrn != 0) || (*minor_rtrn != 0)) + *reason = XkbOD_BadServerVersion; + else + *reason = XkbOD_NonXkbServer; + } + XCloseDisplay(dpy); + return NULL; } - if (reason!=NULL) - *reason= XkbOD_Success; + if (reason != NULL) + *reason = XkbOD_Success; return dpy; } void -XkbSetAtomFuncs(XkbInternAtomFunc getAtom,XkbGetAtomNameFunc getName) +XkbSetAtomFuncs(XkbInternAtomFunc getAtom, XkbGetAtomNameFunc getName) { - _XkbInternAtomFunc= (getAtom?getAtom:XInternAtom); - _XkbGetAtomNameFunc= (getName?getName:XGetAtomName); + _XkbInternAtomFunc = (getAtom ? getAtom : XInternAtom); + _XkbGetAtomNameFunc = (getName ? getName : XGetAtomName); return; } diff --git a/libX11/src/xkb/XKBAlloc.c b/libX11/src/xkb/XKBAlloc.c index 034539b67..5cfef0fb8 100644 --- a/libX11/src/xkb/XKBAlloc.c +++ b/libX11/src/xkb/XKBAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -43,73 +41,73 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /*ARGSUSED*/ Status -XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI) +XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI) { -XkbCompatMapPtr compat; -XkbSymInterpretRec *prev_interpret; + XkbCompatMapPtr compat; + XkbSymInterpretRec *prev_interpret; if (!xkb) - return BadMatch; + return BadMatch; if (xkb->compat) { - if (xkb->compat->size_si>=nSI) - return Success; - compat= xkb->compat; - compat->size_si= nSI; - if (compat->sym_interpret==NULL) - compat->num_si= 0; - prev_interpret = compat->sym_interpret; - compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret, - nSI,XkbSymInterpretRec); - if (compat->sym_interpret==NULL) { - _XkbFree(prev_interpret); - compat->size_si= compat->num_si= 0; - return BadAlloc; - } - if (compat->num_si!=0) { - _XkbClearElems(compat->sym_interpret,compat->num_si, - compat->size_si-1,XkbSymInterpretRec); - } - return Success; + if (xkb->compat->size_si >= nSI) + return Success; + compat = xkb->compat; + compat->size_si = nSI; + if (compat->sym_interpret == NULL) + compat->num_si = 0; + prev_interpret = compat->sym_interpret; + compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret, + nSI, XkbSymInterpretRec); + if (compat->sym_interpret == NULL) { + _XkbFree(prev_interpret); + compat->size_si = compat->num_si = 0; + return BadAlloc; + } + if (compat->num_si != 0) { + _XkbClearElems(compat->sym_interpret, compat->num_si, + compat->size_si - 1, XkbSymInterpretRec); + } + return Success; } - compat= _XkbTypedCalloc(1,XkbCompatMapRec); - if (compat==NULL) - return BadAlloc; - if (nSI>0) { - compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec); - if (!compat->sym_interpret) { - _XkbFree(compat); - return BadAlloc; - } + compat = _XkbTypedCalloc(1, XkbCompatMapRec); + if (compat == NULL) + return BadAlloc; + if (nSI > 0) { + compat->sym_interpret = _XkbTypedCalloc(nSI, XkbSymInterpretRec); + if (!compat->sym_interpret) { + _XkbFree(compat); + return BadAlloc; + } } - compat->size_si= nSI; - compat->num_si= 0; - bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); - xkb->compat= compat; + compat->size_si = nSI; + compat->num_si = 0; + bzero((char *) &compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec)); + xkb->compat = compat; return Success; } void -XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap) +XkbFreeCompatMap(XkbDescPtr xkb, unsigned which, Bool freeMap) { -register XkbCompatMapPtr compat; + register XkbCompatMapPtr compat; - if ((xkb==NULL)||(xkb->compat==NULL)) - return; - compat= xkb->compat; + if ((xkb == NULL) || (xkb->compat == NULL)) + return; + compat = xkb->compat; if (freeMap) - which= XkbAllCompatMask; - if (which&XkbGroupCompatMask) - bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); - if (which&XkbSymInterpMask) { - if ((compat->sym_interpret)&&(compat->size_si>0)) - _XkbFree(compat->sym_interpret); - compat->size_si= compat->num_si= 0; - compat->sym_interpret= NULL; + which = XkbAllCompatMask; + if (which & XkbGroupCompatMask) + bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec)); + if (which & XkbSymInterpMask) { + if ((compat->sym_interpret) && (compat->size_si > 0)) + _XkbFree(compat->sym_interpret); + compat->size_si = compat->num_si = 0; + compat->sym_interpret = NULL; } if (freeMap) { - _XkbFree(compat); - xkb->compat= NULL; + _XkbFree(compat); + xkb->compat = NULL; } return; } @@ -117,127 +115,132 @@ register XkbCompatMapPtr compat; /***===================================================================***/ Status -XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases) +XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases) { -XkbNamesPtr names; - - if (xkb==NULL) - return BadMatch; - if (xkb->names==NULL) { - xkb->names = _XkbTypedCalloc(1,XkbNamesRec); - if (xkb->names==NULL) - return BadAlloc; + XkbNamesPtr names; + + if (xkb == NULL) + return BadMatch; + if (xkb->names == NULL) { + xkb->names = _XkbTypedCalloc(1, XkbNamesRec); + if (xkb->names == NULL) + return BadAlloc; } - names= xkb->names; - if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){ - register int i; - XkbKeyTypePtr type; - - type= xkb->map->types; - for (i=0;i<xkb->map->num_types;i++,type++) { - if (type->level_names==NULL) { - type->level_names= _XkbTypedCalloc(type->num_levels,Atom); - if (type->level_names==NULL) - return BadAlloc; - } - } + names = xkb->names; + if ((which & XkbKTLevelNamesMask) && (xkb->map != NULL) && + (xkb->map->types != NULL)) { + register int i; + XkbKeyTypePtr type = xkb->map->types; + + for (i = 0; i < xkb->map->num_types; i++, type++) { + if (type->level_names == NULL) { + type->level_names = _XkbTypedCalloc(type->num_levels, Atom); + if (type->level_names == NULL) + return BadAlloc; + } + } } - if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadValue; - names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec); - if (names->keys==NULL) - return BadAlloc; + if ((which & XkbKeyNamesMask) && (names->keys == NULL)) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadValue; + names->keys = _XkbTypedCalloc((xkb->max_key_code + 1), XkbKeyNameRec); + if (names->keys == NULL) + return BadAlloc; } - if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) { - if (names->key_aliases==NULL) { - names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec); - } - else if (nTotalAliases>names->num_key_aliases) { - XkbKeyAliasRec *prev_aliases = names->key_aliases; - - names->key_aliases= _XkbTypedRealloc(names->key_aliases, - nTotalAliases,XkbKeyAliasRec); - if (names->key_aliases!=NULL) { - _XkbClearElems(names->key_aliases,names->num_key_aliases, - nTotalAliases-1,XkbKeyAliasRec); - } else { - _XkbFree(prev_aliases); - } - } - if (names->key_aliases==NULL) { - names->num_key_aliases= 0; - return BadAlloc; - } - names->num_key_aliases= nTotalAliases; + if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) { + if (names->key_aliases == NULL) { + names->key_aliases = _XkbTypedCalloc(nTotalAliases, XkbKeyAliasRec); + } + else if (nTotalAliases > names->num_key_aliases) { + XkbKeyAliasRec *prev_aliases = names->key_aliases; + + names->key_aliases = _XkbTypedRealloc(names->key_aliases, + nTotalAliases, + XkbKeyAliasRec); + if (names->key_aliases != NULL) { + _XkbClearElems(names->key_aliases, names->num_key_aliases, + nTotalAliases - 1, XkbKeyAliasRec); + } + else { + _XkbFree(prev_aliases); + } + } + if (names->key_aliases == NULL) { + names->num_key_aliases = 0; + return BadAlloc; + } + names->num_key_aliases = nTotalAliases; } - if ((which&XkbRGNamesMask)&&(nTotalRG>0)) { - if (names->radio_groups==NULL) { - names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom); - } - else if (nTotalRG>names->num_rg) { - Atom *prev_radio_groups = names->radio_groups; - - names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG, - Atom); - if (names->radio_groups!=NULL) { - _XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1, - Atom); - } else { - _XkbFree(prev_radio_groups); - } - } - if (names->radio_groups==NULL) - return BadAlloc; - names->num_rg= nTotalRG; + if ((which & XkbRGNamesMask) && (nTotalRG > 0)) { + if (names->radio_groups == NULL) { + names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom); + } + else if (nTotalRG > names->num_rg) { + Atom *prev_radio_groups = names->radio_groups; + + names->radio_groups = + _XkbTypedRealloc(names->radio_groups, nTotalRG, Atom); + if (names->radio_groups != NULL) { + _XkbClearElems(names->radio_groups, names->num_rg, nTotalRG - 1, + Atom); + } + else { + _XkbFree(prev_radio_groups); + } + } + if (names->radio_groups == NULL) + return BadAlloc; + names->num_rg = nTotalRG; } return Success; } void -XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap) +XkbFreeNames(XkbDescPtr xkb, unsigned which, Bool freeMap) { -XkbNamesPtr names; + XkbNamesPtr names; - if ((xkb==NULL)||(xkb->names==NULL)) - return; - names= xkb->names; + if ((xkb == NULL) || (xkb->names == NULL)) + return; + names = xkb->names; if (freeMap) - which= XkbAllNamesMask; - if (which&XkbKTLevelNamesMask) { - XkbClientMapPtr map= xkb->map; - if ((map!=NULL)&&(map->types!=NULL)) { - register int i; - register XkbKeyTypePtr type; - type= map->types; - for (i=0;i<map->num_types;i++,type++) { - if (type->level_names!=NULL) { - _XkbFree(type->level_names); - type->level_names= NULL; - } - } - } + which = XkbAllNamesMask; + if (which & XkbKTLevelNamesMask) { + XkbClientMapPtr map = xkb->map; + + if ((map != NULL) && (map->types != NULL)) { + register int i; + register XkbKeyTypePtr type; + + type = map->types; + for (i = 0; i < map->num_types; i++, type++) { + if (type->level_names != NULL) { + _XkbFree(type->level_names); + type->level_names = NULL; + } + } + } } - if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { - _XkbFree(names->keys); - names->keys= NULL; - names->num_keys= 0; + if ((which & XkbKeyNamesMask) && (names->keys != NULL)) { + _XkbFree(names->keys); + names->keys = NULL; + names->num_keys = 0; } - if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){ - _XkbFree(names->key_aliases); - names->key_aliases=NULL; - names->num_key_aliases=0; + if ((which & XkbKeyAliasesMask) && (names->key_aliases)) { + _XkbFree(names->key_aliases); + names->key_aliases = NULL; + names->num_key_aliases = 0; } - if ((which&XkbRGNamesMask)&&(names->radio_groups)) { - _XkbFree(names->radio_groups); - names->radio_groups= NULL; - names->num_rg= 0; + if ((which & XkbRGNamesMask) && (names->radio_groups)) { + _XkbFree(names->radio_groups); + names->radio_groups = NULL; + names->num_rg = 0; } if (freeMap) { - _XkbFree(names); - xkb->names= NULL; + _XkbFree(names); + xkb->names = NULL; } return; } @@ -246,26 +249,26 @@ XkbNamesPtr names; /*ARGSUSED*/ Status -XkbAllocControls(XkbDescPtr xkb,unsigned which) +XkbAllocControls(XkbDescPtr xkb, unsigned which) { - if (xkb==NULL) - return BadMatch; + if (xkb == NULL) + return BadMatch; - if (xkb->ctrls==NULL) { - xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec); - if (!xkb->ctrls) - return BadAlloc; + if (xkb->ctrls == NULL) { + xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec); + if (!xkb->ctrls) + return BadAlloc; } return Success; } /*ARGSUSED*/ void -XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap) +XkbFreeControls(XkbDescPtr xkb, unsigned which, Bool freeMap) { - if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) { - _XkbFree(xkb->ctrls); - xkb->ctrls= NULL; + if (freeMap && (xkb != NULL) && (xkb->ctrls != NULL)) { + _XkbFree(xkb->ctrls); + xkb->ctrls = NULL; } return; } @@ -275,12 +278,12 @@ XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap) Status XkbAllocIndicatorMaps(XkbDescPtr xkb) { - if (xkb==NULL) - return BadMatch; - if (xkb->indicators==NULL) { - xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec); - if (!xkb->indicators) - return BadAlloc; + if (xkb == NULL) + return BadMatch; + if (xkb->indicators == NULL) { + xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec); + if (!xkb->indicators) + return BadAlloc; } return Success; } @@ -288,199 +291,206 @@ XkbAllocIndicatorMaps(XkbDescPtr xkb) void XkbFreeIndicatorMaps(XkbDescPtr xkb) { - if ((xkb!=NULL)&&(xkb->indicators!=NULL)) { - _XkbFree(xkb->indicators); - xkb->indicators= NULL; + if ((xkb != NULL) && (xkb->indicators != NULL)) { + _XkbFree(xkb->indicators); + xkb->indicators = NULL; } return; } /***====================================================================***/ -XkbDescRec * +XkbDescRec * XkbAllocKeyboard(void) { -XkbDescRec *xkb; + XkbDescRec *xkb; - xkb = _XkbTypedCalloc(1,XkbDescRec); + xkb = _XkbTypedCalloc(1, XkbDescRec); if (xkb) - xkb->device_spec= XkbUseCoreKbd; + xkb->device_spec = XkbUseCoreKbd; return xkb; } void -XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll) +XkbFreeKeyboard(XkbDescPtr xkb, unsigned which, Bool freeAll) { - if (xkb==NULL) - return; + if (xkb == NULL) + return; if (freeAll) - which= XkbAllComponentsMask; - if (which&XkbClientMapMask) - XkbFreeClientMap(xkb,XkbAllClientInfoMask,True); - if (which&XkbServerMapMask) - XkbFreeServerMap(xkb,XkbAllServerInfoMask,True); - if (which&XkbCompatMapMask) - XkbFreeCompatMap(xkb,XkbAllCompatMask,True); - if (which&XkbIndicatorMapMask) - XkbFreeIndicatorMaps(xkb); - if (which&XkbNamesMask) - XkbFreeNames(xkb,XkbAllNamesMask,True); - if ((which&XkbGeometryMask) && (xkb->geom!=NULL)) - XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True); - if (which&XkbControlsMask) - XkbFreeControls(xkb,XkbAllControlsMask,True); + which = XkbAllComponentsMask; + if (which & XkbClientMapMask) + XkbFreeClientMap(xkb, XkbAllClientInfoMask, True); + if (which & XkbServerMapMask) + XkbFreeServerMap(xkb, XkbAllServerInfoMask, True); + if (which & XkbCompatMapMask) + XkbFreeCompatMap(xkb, XkbAllCompatMask, True); + if (which & XkbIndicatorMapMask) + XkbFreeIndicatorMaps(xkb); + if (which & XkbNamesMask) + XkbFreeNames(xkb, XkbAllNamesMask, True); + if ((which & XkbGeometryMask) && (xkb->geom != NULL)) + XkbFreeGeometry(xkb->geom, XkbGeomAllMask, True); + if (which & XkbControlsMask) + XkbFreeControls(xkb, XkbAllControlsMask, True); if (freeAll) - _XkbFree(xkb); + _XkbFree(xkb); return; } /***====================================================================***/ XkbDeviceLedInfoPtr -XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId) +XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId) { -XkbDeviceLedInfoPtr devli; -register int i; - - if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId))) - return NULL; - for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) { - if ((devli->led_class==ledClass)&&(devli->led_id==ledId)) - return devli; + XkbDeviceLedInfoPtr devli; + register int i; + + if ((!devi) || (!XkbSingleXIClass(ledClass)) || (!XkbSingleXIId(ledId))) + return NULL; + for (i = 0, devli = devi->leds; i < devi->num_leds; i++, devli++) { + if ((devli->led_class == ledClass) && (devli->led_id == ledId)) + return devli; } - if (devi->num_leds>=devi->sz_leds) { - XkbDeviceLedInfoRec *prev_leds = devi->leds; - - if (devi->sz_leds>0) devi->sz_leds*= 2; - else devi->sz_leds= 1; - devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds, - XkbDeviceLedInfoRec); - if (!devi->leds) { - _XkbFree(prev_leds); - devi->sz_leds= devi->num_leds= 0; - return NULL; - } - i= devi->num_leds; - for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) { - bzero(devli,sizeof(XkbDeviceLedInfoRec)); - devli->led_class= XkbXINone; - devli->led_id= XkbXINone; - } + if (devi->num_leds >= devi->sz_leds) { + XkbDeviceLedInfoRec *prev_leds = devi->leds; + + if (devi->sz_leds > 0) + devi->sz_leds *= 2; + else + devi->sz_leds = 1; + devi->leds = _XkbTypedRealloc(devi->leds, devi->sz_leds, + XkbDeviceLedInfoRec); + if (!devi->leds) { + _XkbFree(prev_leds); + devi->sz_leds = devi->num_leds = 0; + return NULL; + } + i = devi->num_leds; + for (devli = &devi->leds[i]; i < devi->sz_leds; i++, devli++) { + bzero(devli, sizeof(XkbDeviceLedInfoRec)); + devli->led_class = XkbXINone; + devli->led_id = XkbXINone; + } } - devli= &devi->leds[devi->num_leds++]; - bzero(devli,sizeof(XkbDeviceLedInfoRec)); - devli->led_class= ledClass; - devli->led_id= ledId; + devli = &devi->leds[devi->num_leds++]; + bzero(devli, sizeof(XkbDeviceLedInfoRec)); + devli->led_class = ledClass; + devli->led_id = ledId; return devli; } Status -XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal) +XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal) { XkbAction *prev_btn_acts; - if ((!devi)||(newTotal>255)) - return BadValue; - if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns)) - return Success; - if (newTotal==0) { - if (devi->btn_acts!=NULL) { - _XkbFree(devi->btn_acts); - devi->btn_acts= NULL; - } - devi->num_btns= 0; - return Success; + if ((!devi) || (newTotal > 255)) + return BadValue; + if ((devi->btn_acts != NULL) && (newTotal == devi->num_btns)) + return Success; + if (newTotal == 0) { + if (devi->btn_acts != NULL) { + _XkbFree(devi->btn_acts); + devi->btn_acts = NULL; + } + devi->num_btns = 0; + return Success; } prev_btn_acts = devi->btn_acts; - devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction); - if (devi->btn_acts==NULL) { - _XkbFree(prev_btn_acts); - devi->num_btns= 0; - return BadAlloc; + devi->btn_acts = _XkbTypedRealloc(devi->btn_acts, newTotal, XkbAction); + if (devi->btn_acts == NULL) { + _XkbFree(prev_btn_acts); + devi->num_btns = 0; + return BadAlloc; } - if (newTotal>devi->num_btns) { - XkbAction *act; - act= &devi->btn_acts[devi->num_btns]; - bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction)); + if (newTotal > devi->num_btns) { + XkbAction *act; + + act = &devi->btn_acts[devi->num_btns]; + bzero((char *) act, (newTotal - devi->num_btns) * sizeof(XkbAction)); } - devi->num_btns= newTotal; + devi->num_btns = newTotal; return Success; } /*ARGSUSED*/ XkbDeviceInfoPtr -XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds) +XkbAllocDeviceInfo(unsigned deviceSpec, unsigned nButtons, unsigned szLeds) { -XkbDeviceInfoPtr devi; - - devi= _XkbTypedCalloc(1,XkbDeviceInfoRec); - if (devi!=NULL) { - devi->device_spec= deviceSpec; - devi->has_own_state= False; - devi->num_btns= 0; - devi->btn_acts= NULL; - if (nButtons>0) { - devi->num_btns= nButtons; - devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction); - if (!devi->btn_acts) { - _XkbFree(devi); - return NULL; - } - } - devi->dflt_kbd_fb= XkbXINone; - devi->dflt_led_fb= XkbXINone; - devi->num_leds= 0; - devi->sz_leds= 0; - devi->leds= NULL; - if (szLeds>0) { - devi->sz_leds= szLeds; - devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec); - if (!devi->leds) { - if (devi->btn_acts) - _XkbFree(devi->btn_acts); - _XkbFree(devi); - return NULL; - } - } + XkbDeviceInfoPtr devi; + + devi = _XkbTypedCalloc(1, XkbDeviceInfoRec); + if (devi != NULL) { + devi->device_spec = deviceSpec; + devi->has_own_state = False; + devi->num_btns = 0; + devi->btn_acts = NULL; + if (nButtons > 0) { + devi->num_btns = nButtons; + devi->btn_acts = _XkbTypedCalloc(nButtons, XkbAction); + if (!devi->btn_acts) { + _XkbFree(devi); + return NULL; + } + } + devi->dflt_kbd_fb = XkbXINone; + devi->dflt_led_fb = XkbXINone; + devi->num_leds = 0; + devi->sz_leds = 0; + devi->leds = NULL; + if (szLeds > 0) { + devi->sz_leds = szLeds; + devi->leds = _XkbTypedCalloc(szLeds, XkbDeviceLedInfoRec); + if (!devi->leds) { + if (devi->btn_acts) + _XkbFree(devi->btn_acts); + _XkbFree(devi); + return NULL; + } + } } return devi; } void -XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI) +XkbFreeDeviceInfo(XkbDeviceInfoPtr devi, unsigned which, Bool freeDevI) { if (devi) { - if (freeDevI) { - which= XkbXI_AllDeviceFeaturesMask; - if (devi->name) { - _XkbFree(devi->name); - devi->name= NULL; - } - } - if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) { - _XkbFree(devi->btn_acts); - devi->num_btns= 0; - devi->btn_acts= NULL; - } - if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) { - register int i; - if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) { - _XkbFree(devi->leds); - devi->sz_leds= devi->num_leds= 0; - devi->leds= NULL; - } - else { - XkbDeviceLedInfoPtr devli; - for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) { - if (which&XkbXI_IndicatorMapsMask) - bzero((char *)&devli->maps[0],sizeof(devli->maps)); - else bzero((char *)&devli->names[0],sizeof(devli->names)); - } - } - } - if (freeDevI) - _XkbFree(devi); + if (freeDevI) { + which = XkbXI_AllDeviceFeaturesMask; + if (devi->name) { + _XkbFree(devi->name); + devi->name = NULL; + } + } + if ((which & XkbXI_ButtonActionsMask) && (devi->btn_acts)) { + _XkbFree(devi->btn_acts); + devi->num_btns = 0; + devi->btn_acts = NULL; + } + if ((which & XkbXI_IndicatorsMask) && (devi->leds)) { + register int i; + + if ((which & XkbXI_IndicatorsMask) == XkbXI_IndicatorsMask) { + _XkbFree(devi->leds); + devi->sz_leds = devi->num_leds = 0; + devi->leds = NULL; + } + else { + XkbDeviceLedInfoPtr devli; + + for (i = 0, devli = devi->leds; i < devi->num_leds; + i++, devli++) { + if (which & XkbXI_IndicatorMapsMask) + bzero((char *) &devli->maps[0], sizeof(devli->maps)); + else + bzero((char *) &devli->names[0], sizeof(devli->names)); + } + } + } + if (freeDevI) + _XkbFree(devi); } return; } diff --git a/libX11/src/xkb/XKBBell.c b/libX11/src/xkb/XKBBell.c index cf93ea79a..f40e86f4a 100644 --- a/libX11/src/xkb/XKBBell.c +++ b/libX11/src/xkb/XKBBell.c @@ -34,145 +34,146 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. Bool -XkbDeviceBell( Display * dpy, - Window window, - int deviceID, - int bellClass, - int bellID, - int percent, - Atom name) +XkbDeviceBell(Display *dpy, + Window window, + int deviceID, + int bellClass, + int bellID, + int percent, + Atom name) { register xkbBellReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; - GetReq(kbBell,req); + GetReq(kbBell, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbBell; req->deviceSpec = deviceID; - req->window = (CARD32)window; - req->bellClass = (CARD16)bellClass; - req->bellID = (CARD16)bellID; + req->window = (CARD32) window; + req->bellClass = (CARD16) bellClass; + req->bellID = (CARD16) bellID; req->percent = percent; req->forceSound = False; req->eventOnly = False; req->pitch = 0; req->duration = 0; - req->name = (CARD32)name; - req->pad1= 0; req->pad2= 0; + req->name = (CARD32) name; + req->pad1 = 0; + req->pad2 = 0; UnlockDisplay(dpy); SyncHandle(); return True; } Bool -XkbForceDeviceBell( Display * dpy, - int deviceID, - int bellClass, - int bellID, - int percent) +XkbForceDeviceBell(Display *dpy, + int deviceID, + int bellClass, + int bellID, + int percent) { register xkbBellReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; - GetReq(kbBell,req); + GetReq(kbBell, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbBell; req->deviceSpec = deviceID; - req->window = (CARD32)None; - req->bellClass = (CARD16)bellClass; - req->bellID = (CARD16)bellID; + req->window = (CARD32) None; + req->bellClass = (CARD16) bellClass; + req->bellID = (CARD16) bellID; req->percent = percent; req->forceSound = True; req->eventOnly = False; req->pitch = 0; req->duration = 0; req->name = None; - req->pad1= 0; req->pad2= 0; + req->pad1 = 0; + req->pad2 = 0; UnlockDisplay(dpy); SyncHandle(); return True; } Bool -XkbDeviceBellEvent( Display * dpy, - Window window, - int deviceID, - int bellClass, - int bellID, - int percent, - Atom name) +XkbDeviceBellEvent(Display *dpy, + Window window, + int deviceID, + int bellClass, + int bellID, + int percent, + Atom name) { register xkbBellReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; - GetReq(kbBell,req); + GetReq(kbBell, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbBell; req->deviceSpec = deviceID; - req->window = (CARD32)window; - req->bellClass = (CARD16)bellClass; - req->bellID = (CARD16)bellID; + req->window = (CARD32) window; + req->bellClass = (CARD16) bellClass; + req->bellID = (CARD16) bellID; req->percent = percent; req->forceSound = False; req->eventOnly = True; req->pitch = 0; req->duration = 0; - req->name = (CARD32)name; - req->pad1= 0; req->pad2= 0; + req->name = (CARD32) name; + req->pad1 = 0; + req->pad2 = 0; UnlockDisplay(dpy); SyncHandle(); return True; } Bool -XkbBell(Display *dpy,Window window,int percent,Atom name) +XkbBell(Display *dpy, Window window, int percent, Atom name) { if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { - XBell(dpy,percent); - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) { + XBell(dpy, percent); + return False; } - return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId, - percent,name); + return XkbDeviceBell(dpy, window, XkbUseCoreKbd, + XkbDfltXIClass, XkbDfltXIId, percent, name); } Bool -XkbForceBell(Display *dpy,int percent) +XkbForceBell(Display *dpy, int percent) { if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { - XBell(dpy,percent); - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) { + XBell(dpy, percent); + return False; } - return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId, - percent); + return XkbForceDeviceBell(dpy, XkbUseCoreKbd, XkbDfltXIClass, XkbDfltXIId, + percent); } Bool -XkbBellEvent(Display *dpy,Window window,int percent,Atom name) +XkbBellEvent(Display *dpy, Window window, int percent, Atom name) { if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) { + return False; } /* class 0 = KbdFeedbackClass (X Input Extension) */ - return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd, - XkbDfltXIClass,XkbDfltXIId, - percent,name); + return XkbDeviceBellEvent(dpy, window, XkbUseCoreKbd, + XkbDfltXIClass, XkbDfltXIId, percent, name); } - diff --git a/libX11/src/xkb/XKBBind.c b/libX11/src/xkb/XKBBind.c index c2305c57c..b08e9d3ba 100644 --- a/libX11/src/xkb/XKBBind.c +++ b/libX11/src/xkb/XKBBind.c @@ -26,7 +26,7 @@ from The Open Group. */ - /* the new monsters ate the old ones */ + /* the new monsters ate the old ones */ #ifdef HAVE_CONFIG_H #include <config.h> @@ -70,112 +70,116 @@ from The Open Group. #include "XKBlibint.h" #ifdef USE_OWN_COMPOSE -#define COMPOSE_NO_CONST_MEMBERS +#define COMPOSE_NO_CONST_MEMBERS #include "imComp.h" #endif #define AllMods (ShiftMask|LockMask|ControlMask| \ - Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask) + Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask) -static int _XkbLoadDpy( - Display *dpy -); +static int _XkbLoadDpy(Display *dpy); struct _XKeytrans { - struct _XKeytrans *next;/* next on list */ - char *string; /* string to return when the time comes */ - int len; /* length of string (since NULL is legit)*/ - KeySym key; /* keysym rebound */ - unsigned int state; /* modifier state */ - KeySym *modifiers; /* modifier keysyms you want */ - int mlen; /* length of modifier list */ + struct _XKeytrans *next; /* next on list */ + char *string; /* string to return when the time comes */ + int len; /* length of string (since NULL is legit) */ + KeySym key; /* keysym rebound */ + unsigned int state; /* modifier state */ + KeySym *modifiers; /* modifier keysyms you want */ + int mlen; /* length of modifier list */ }; KeySym XkbKeycodeToKeysym(Display *dpy, #if NeedWidePrototypes - unsigned int kc, + unsigned int kc, #else - KeyCode kc, + KeyCode kc, #endif - int group, - int level) + int group, + int level) { - XkbDescRec *xkb; + XkbDescRec *xkb; if (_XkbUnavailable(dpy)) - return NoSymbol; + return NoSymbol; - _XkbCheckPendingRefresh(dpy,dpy->xkb_info); + _XkbCheckPendingRefresh(dpy, dpy->xkb_info); xkb = dpy->xkb_info->desc; - if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code)) - return NoSymbol; - - if ((group<0)||(level<0)||(group>=XkbKeyNumGroups(xkb,kc))) - return NoSymbol; - if (level>=XkbKeyGroupWidth(xkb,kc,group)) { - /* for compatibility with the core protocol, _always_ allow */ - /* two symbols in the first two groups. If either of the */ - /* two is of type ONE_LEVEL, just replicate the first symbol */ - if ((group>XkbGroup2Index)||(XkbKeyGroupWidth(xkb,kc,group)!=1)|| - (level!=1)) { - return NoSymbol; - } - level= 0; + if ((kc < xkb->min_key_code) || (kc > xkb->max_key_code)) + return NoSymbol; + + if ((group < 0) || (level < 0) || (group >= XkbKeyNumGroups(xkb, kc))) + return NoSymbol; + if (level >= XkbKeyGroupWidth(xkb, kc, group)) { + /* for compatibility with the core protocol, _always_ allow */ + /* two symbols in the first two groups. If either of the */ + /* two is of type ONE_LEVEL, just replicate the first symbol */ + if ((group > XkbGroup2Index) || (XkbKeyGroupWidth(xkb, kc, group) != 1) + || (level != 1)) { + return NoSymbol; + } + level = 0; } - return XkbKeySymEntry(xkb,kc,level,group); + return XkbKeySymEntry(xkb, kc, level, group); } KeySym XKeycodeToKeysym(Display *dpy, #if NeedWidePrototypes - unsigned int kc, + unsigned int kc, #else - KeyCode kc, + KeyCode kc, #endif - int col) + int col) { - XkbDescRec *xkb; + XkbDescRec *xkb; if (_XkbUnavailable(dpy)) - return _XKeycodeToKeysym(dpy, kc, col); + return _XKeycodeToKeysym(dpy, kc, col); - _XkbCheckPendingRefresh(dpy,dpy->xkb_info); + _XkbCheckPendingRefresh(dpy, dpy->xkb_info); xkb = dpy->xkb_info->desc; - if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code)) - return NoSymbol; - - if (col>3) { - int lastSym,tmp,nGrp; - - lastSym= 3; - nGrp= XkbKeyNumGroups(xkb,kc); - if ((nGrp>0)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup1Index))>2)) { - if (col<=(lastSym+tmp-2)) - return XkbKeycodeToKeysym(dpy,kc,XkbGroup1Index,col-lastSym+2); - lastSym+= tmp-2; - } - if ((nGrp>1)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup2Index))>2)) { - if (col<=(lastSym+tmp-2)) - return XkbKeycodeToKeysym(dpy,kc,XkbGroup2Index,col-lastSym+2); - lastSym+= tmp-2; - } - if (nGrp>2) { - tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup3Index); - if (col<=lastSym+tmp) - return XkbKeycodeToKeysym(dpy,kc,XkbGroup3Index,col-lastSym); - lastSym+= tmp; - } - if (nGrp>3) { - tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup4Index); - if (col<=lastSym+tmp) - return XkbKeycodeToKeysym(dpy,kc,XkbGroup4Index,col-lastSym); - } - return NoSymbol; + if ((kc < xkb->min_key_code) || (kc > xkb->max_key_code)) + return NoSymbol; + + if (col > 3) { + int lastSym, tmp, nGrp; + + lastSym = 3; + nGrp = XkbKeyNumGroups(xkb, kc); + if ((nGrp > 0) && + ((tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup1Index)) > 2)) { + if (col <= (lastSym + tmp - 2)) + return XkbKeycodeToKeysym(dpy, kc, XkbGroup1Index, + col - lastSym + 2); + lastSym += tmp - 2; + } + if ((nGrp > 1) && + ((tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup2Index)) > 2)) { + if (col <= (lastSym + tmp - 2)) + return XkbKeycodeToKeysym(dpy, kc, XkbGroup2Index, + col - lastSym + 2); + lastSym += tmp - 2; + } + if (nGrp > 2) { + tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup3Index); + if (col <= lastSym + tmp) + return XkbKeycodeToKeysym(dpy, kc, XkbGroup3Index, + col - lastSym); + lastSym += tmp; + } + if (nGrp > 3) { + tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup4Index); + if (col <= lastSym + tmp) + return XkbKeycodeToKeysym(dpy, kc, XkbGroup4Index, + col - lastSym); + } + return NoSymbol; } - return XkbKeycodeToKeysym(dpy,kc,(col>>1),(col&1)); + return XkbKeycodeToKeysym(dpy, kc, (col >> 1), (col & 1)); } KeyCode @@ -184,21 +188,21 @@ XKeysymToKeycode(Display *dpy, KeySym ks) register int i, j, gotOne; if (_XkbUnavailable(dpy)) - return _XKeysymToKeycode(dpy,ks); - _XkbCheckPendingRefresh(dpy,dpy->xkb_info); + return _XKeysymToKeycode(dpy, ks); + _XkbCheckPendingRefresh(dpy, dpy->xkb_info); - j= 0; + j = 0; do { - register XkbDescRec *xkb = dpy->xkb_info->desc; - gotOne= 0; - for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) { - if ( j<(int)XkbKeyNumSyms(xkb,i) ) { - gotOne = 1; - if ((XkbKeySym(xkb,i,j)==ks)) - return i; - } - } - j++; + register XkbDescRec *xkb = dpy->xkb_info->desc; + gotOne = 0; + for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) { + if (j < (int) XkbKeyNumSyms(xkb, i)) { + gotOne = 1; + if ((XkbKeySym(xkb, i, j) == ks)) + return i; + } + } + j++; } while (gotOne); return 0; } @@ -206,50 +210,51 @@ XKeysymToKeycode(Display *dpy, KeySym ks) static int _XkbComputeModmap(Display *dpy) { -register XkbDescPtr xkb; + register XkbDescPtr xkb; - xkb= dpy->xkb_info->desc; - if (XkbGetUpdatedMap(dpy,XkbModifierMapMask,xkb)==Success) - return 1; + xkb = dpy->xkb_info->desc; + if (XkbGetUpdatedMap(dpy, XkbModifierMapMask, xkb) == Success) + return 1; return 0; } unsigned -XkbKeysymToModifiers(Display *dpy,KeySym ks) +XkbKeysymToModifiers(Display *dpy, KeySym ks) { XkbDescRec *xkb; - register int i,j; + register int i, j; register KeySym *pSyms; CARD8 mods; if (_XkbUnavailable(dpy)) - return _XKeysymToModifiers(dpy,ks); - _XkbCheckPendingRefresh(dpy,dpy->xkb_info); - - if (_XkbNeedModmap(dpy->xkb_info)&&(!_XkbComputeModmap(dpy))) - return _XKeysymToModifiers(dpy,ks); - - xkb= dpy->xkb_info->desc; - mods= 0; - for (i = xkb->min_key_code; i <= (int)xkb->max_key_code; i++) { - pSyms= XkbKeySymsPtr(xkb,i); - for (j=XkbKeyNumSyms(xkb,i)-1;j>=0;j--) { - if (pSyms[j]==ks) { - mods|= xkb->map->modmap[i]; - break; - } - } + return _XKeysymToModifiers(dpy, ks); + _XkbCheckPendingRefresh(dpy, dpy->xkb_info); + + if (_XkbNeedModmap(dpy->xkb_info) && (!_XkbComputeModmap(dpy))) + return _XKeysymToModifiers(dpy, ks); + + xkb = dpy->xkb_info->desc; + mods = 0; + for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++) { + pSyms = XkbKeySymsPtr(xkb, i); + for (j = XkbKeyNumSyms(xkb, i) - 1; j >= 0; j--) { + if (pSyms[j] == ks) { + mods |= xkb->map->modmap[i]; + break; + } + } } return mods; } KeySym -XLookupKeysym(register XKeyEvent *event, int col) +XLookupKeysym(register XKeyEvent * event, int col) { Display *dpy = event->display; + if (_XkbUnavailable(dpy)) - return _XLookupKeysym(event, col); - _XkbCheckPendingRefresh(dpy,dpy->xkb_info); + return _XLookupKeysym(event, col); + _XkbCheckPendingRefresh(dpy, dpy->xkb_info); return XKeycodeToKeysym(dpy, event->keycode, col); } @@ -259,159 +264,165 @@ XLookupKeysym(register XKeyEvent *event, int col) * version will continue to work in a shared library environment. */ int -XkbTranslateKey( register Display * dpy, - KeyCode key, - register unsigned int mods, - unsigned int * mods_rtrn, - KeySym * keysym_rtrn); +XkbTranslateKey(register Display *dpy, + KeyCode key, + register unsigned int mods, + unsigned int *mods_rtrn, + KeySym *keysym_rtrn); + int -XkbTranslateKey( register Display * dpy, - KeyCode key, - register unsigned int mods, - unsigned int * mods_rtrn, - KeySym * keysym_rtrn) +XkbTranslateKey(register Display *dpy, + KeyCode key, + register unsigned int mods, + unsigned int *mods_rtrn, + KeySym *keysym_rtrn) { - return XkbLookupKeySym(dpy,key,mods,mods_rtrn,keysym_rtrn); + return XkbLookupKeySym(dpy, key, mods, mods_rtrn, keysym_rtrn); } Bool -XkbLookupKeySym( register Display * dpy, - KeyCode key, - register unsigned int mods, - unsigned int * mods_rtrn, - KeySym * keysym_rtrn) +XkbLookupKeySym(register Display *dpy, + KeyCode key, + register unsigned int mods, + unsigned int *mods_rtrn, + KeySym *keysym_rtrn) { if (_XkbUnavailable(dpy)) - return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn); - _XkbCheckPendingRefresh(dpy,dpy->xkb_info); - return XkbTranslateKeyCode(dpy->xkb_info->desc,key,mods,mods_rtrn, - keysym_rtrn); + return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn); + _XkbCheckPendingRefresh(dpy, dpy->xkb_info); + return XkbTranslateKeyCode(dpy->xkb_info->desc, key, mods, mods_rtrn, + keysym_rtrn); } Bool -XkbTranslateKeyCode( register XkbDescPtr xkb, - KeyCode key, - register unsigned int mods, - unsigned int * mods_rtrn, - KeySym * keysym_rtrn) +XkbTranslateKeyCode(register XkbDescPtr xkb, + KeyCode key, + register unsigned int mods, + unsigned int *mods_rtrn, + KeySym *keysym_rtrn) { XkbKeyTypeRec *type; - int col,nKeyGroups; - unsigned preserve,effectiveGroup; + int col, nKeyGroups; + unsigned preserve, effectiveGroup; KeySym *syms; - if (mods_rtrn!=NULL) - *mods_rtrn = 0; + if (mods_rtrn != NULL) + *mods_rtrn = 0; - nKeyGroups= XkbKeyNumGroups(xkb,key); - if ((!XkbKeycodeInRange(xkb,key))||(nKeyGroups==0)) { - if (keysym_rtrn!=NULL) - *keysym_rtrn = NoSymbol; - return False; + nKeyGroups = XkbKeyNumGroups(xkb, key); + if ((!XkbKeycodeInRange(xkb, key)) || (nKeyGroups == 0)) { + if (keysym_rtrn != NULL) + *keysym_rtrn = NoSymbol; + return False; } - syms = XkbKeySymsPtr(xkb,key); + syms = XkbKeySymsPtr(xkb, key); /* find the offset of the effective group */ col = 0; - effectiveGroup= XkbGroupForCoreState(mods); - if ( effectiveGroup>=nKeyGroups ) { - unsigned groupInfo= XkbKeyGroupInfo(xkb,key); - switch (XkbOutOfRangeGroupAction(groupInfo)) { - default: - effectiveGroup %= nKeyGroups; - break; - case XkbClampIntoRange: - effectiveGroup = nKeyGroups-1; - break; - case XkbRedirectIntoRange: - effectiveGroup = XkbOutOfRangeGroupNumber(groupInfo); - if (effectiveGroup>=nKeyGroups) - effectiveGroup= 0; - break; - } + effectiveGroup = XkbGroupForCoreState(mods); + if (effectiveGroup >= nKeyGroups) { + unsigned groupInfo = XkbKeyGroupInfo(xkb, key); + + switch (XkbOutOfRangeGroupAction(groupInfo)) { + default: + effectiveGroup %= nKeyGroups; + break; + case XkbClampIntoRange: + effectiveGroup = nKeyGroups - 1; + break; + case XkbRedirectIntoRange: + effectiveGroup = XkbOutOfRangeGroupNumber(groupInfo); + if (effectiveGroup >= nKeyGroups) + effectiveGroup = 0; + break; + } } - col= effectiveGroup*XkbKeyGroupsWidth(xkb,key); - type = XkbKeyKeyType(xkb,key,effectiveGroup); - - preserve= 0; - if (type->map) { /* find the column (shift level) within the group */ - register int i; - register XkbKTMapEntryPtr entry; - for (i=0,entry=type->map;i<type->map_count;i++,entry++) { - if ((entry->active)&&((mods&type->mods.mask)==entry->mods.mask)) { - col+= entry->level; - if (type->preserve) - preserve= type->preserve[i].mask; - break; - } - } + col = effectiveGroup * XkbKeyGroupsWidth(xkb, key); + type = XkbKeyKeyType(xkb, key, effectiveGroup); + + preserve = 0; + if (type->map) { /* find the column (shift level) within the group */ + register int i; + register XkbKTMapEntryPtr entry; + + for (i = 0, entry = type->map; i < type->map_count; i++, entry++) { + if ((entry->active) && + ((mods & type->mods.mask) == entry->mods.mask)) { + col += entry->level; + if (type->preserve) + preserve = type->preserve[i].mask; + break; + } + } } - if (keysym_rtrn!=NULL) - *keysym_rtrn= syms[col]; + if (keysym_rtrn != NULL) + *keysym_rtrn = syms[col]; if (mods_rtrn) { - *mods_rtrn= type->mods.mask&(~preserve); - /* The Motif VTS doesn't get the help callback called if help - * is bound to Shift+<whatever>, and it appears as though it - * is XkbTranslateKeyCode that is causing the problem. The - * core X version of XTranslateKey always OR's in ShiftMask - * and LockMask for mods_rtrn, so this "fix" keeps this behavior - * and solves the VTS problem. - */ - if ((xkb->dpy)&&(xkb->dpy->xkb_info)&& - (xkb->dpy->xkb_info->xlib_ctrls&XkbLC_AlwaysConsumeShiftAndLock)) { - *mods_rtrn|= (ShiftMask|LockMask); - } + *mods_rtrn = type->mods.mask & (~preserve); + /* The Motif VTS doesn't get the help callback called if help + * is bound to Shift+<whatever>, and it appears as though it + * is XkbTranslateKeyCode that is causing the problem. The + * core X version of XTranslateKey always OR's in ShiftMask + * and LockMask for mods_rtrn, so this "fix" keeps this behavior + * and solves the VTS problem. + */ + if ((xkb->dpy) && (xkb->dpy->xkb_info) && + (xkb->dpy->xkb_info-> + xlib_ctrls & XkbLC_AlwaysConsumeShiftAndLock)) { + *mods_rtrn |= (ShiftMask | LockMask); + } } - return (syms[col]!=NoSymbol); + return (syms[col] != NoSymbol); } Status -XkbRefreshKeyboardMapping(register XkbMapNotifyEvent *event) +XkbRefreshKeyboardMapping(register XkbMapNotifyEvent * event) { Display *dpy = event->display; XkbInfoPtr xkbi; if (_XkbUnavailable(dpy)) { - _XRefreshKeyboardMapping((XMappingEvent *)event); - return Success; + _XRefreshKeyboardMapping((XMappingEvent *) event); + return Success; } - xkbi= dpy->xkb_info; + xkbi = dpy->xkb_info; - if (((event->type&0x7f)-xkbi->codes->first_event)!=XkbEventCode) - return BadMatch; - if (event->xkb_type==XkbNewKeyboardNotify) { - _XkbReloadDpy(dpy); - return Success; + if (((event->type & 0x7f) - xkbi->codes->first_event) != XkbEventCode) + return BadMatch; + if (event->xkb_type == XkbNewKeyboardNotify) { + _XkbReloadDpy(dpy); + return Success; } - if (event->xkb_type==XkbMapNotify) { - XkbMapChangesRec changes; - Status rtrn; - - if (xkbi->flags&XkbMapPending) - changes= xkbi->changes; - else bzero(&changes,sizeof(changes)); - XkbNoteMapChanges(&changes,event,XKB_XLIB_MAP_MASK); - if ((rtrn=XkbGetMapChanges(dpy,xkbi->desc,&changes))!=Success) { + if (event->xkb_type == XkbMapNotify) { + XkbMapChangesRec changes; + Status rtrn; + + if (xkbi->flags & XkbMapPending) + changes = xkbi->changes; + else + bzero(&changes, sizeof(changes)); + XkbNoteMapChanges(&changes, event, XKB_XLIB_MAP_MASK); + if ((rtrn = XkbGetMapChanges(dpy, xkbi->desc, &changes)) != Success) { #ifdef DEBUG - fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n"); + fprintf(stderr, "Internal Error! XkbGetMapChanges failed:\n"); #endif - xkbi->changes= changes; - } - else if (xkbi->flags&XkbMapPending) { - xkbi->flags&= ~XkbMapPending; - bzero(&xkbi->changes,sizeof(XkbMapChangesRec)); - } - return rtrn; + xkbi->changes = changes; + } + else if (xkbi->flags & XkbMapPending) { + xkbi->flags &= ~XkbMapPending; + bzero(&xkbi->changes, sizeof(XkbMapChangesRec)); + } + return rtrn; } return BadMatch; } int -XRefreshKeyboardMapping(register XMappingEvent *event) +XRefreshKeyboardMapping(register XMappingEvent * event) { - XkbEvent *xkbevent = (XkbEvent *)event; + XkbEvent *xkbevent = (XkbEvent *) event; Display *dpy = event->display; XkbMapChangesRec changes; XkbInfoPtr xkbi; @@ -420,99 +431,107 @@ XRefreshKeyboardMapping(register XMappingEvent *event) (void) _XRefreshKeyboardMapping(event); if (_XkbUnavailable(dpy)) - return 1; + return 1; xkbi = dpy->xkb_info; - if (((event->type&0x7f)-xkbi->codes->first_event)==XkbEventCode) - return XkbRefreshKeyboardMapping(&xkbevent->map); + if (((event->type & 0x7f) - xkbi->codes->first_event) == XkbEventCode) + return XkbRefreshKeyboardMapping(&xkbevent->map); - if (xkbi->flags&XkbXlibNewKeyboard) { - _XkbReloadDpy(dpy); - return 1; + if (xkbi->flags & XkbXlibNewKeyboard) { + _XkbReloadDpy(dpy); + return 1; } - if ((xkbi->flags&XkbMapPending)||(event->request==MappingKeyboard)) { - if (xkbi->flags&XkbMapPending) { - changes= xkbi->changes; - _XkbNoteCoreMapChanges(&changes,event,XKB_XLIB_MAP_MASK); - } - else { - bzero(&changes,sizeof(changes)); - changes.changed= XkbKeySymsMask; - if (xkbi->desc->min_key_code<xkbi->desc->max_key_code) { - changes.first_key_sym= xkbi->desc->min_key_code; - changes.num_key_syms= xkbi->desc->max_key_code- - xkbi->desc->min_key_code+1; - } - else { - changes.first_key_sym= event->first_keycode; - changes.num_key_syms= event->count; - } - } - - if (XkbGetMapChanges(dpy,xkbi->desc, &changes)!=Success) { + if ((xkbi->flags & XkbMapPending) || (event->request == MappingKeyboard)) { + if (xkbi->flags & XkbMapPending) { + changes = xkbi->changes; + _XkbNoteCoreMapChanges(&changes, event, XKB_XLIB_MAP_MASK); + } + else { + bzero(&changes, sizeof(changes)); + changes.changed = XkbKeySymsMask; + if (xkbi->desc->min_key_code < xkbi->desc->max_key_code) { + changes.first_key_sym = xkbi->desc->min_key_code; + changes.num_key_syms = xkbi->desc->max_key_code - + xkbi->desc->min_key_code + 1; + } + else { + changes.first_key_sym = event->first_keycode; + changes.num_key_syms = event->count; + } + } + + if (XkbGetMapChanges(dpy, xkbi->desc, &changes) != Success) { #ifdef DEBUG - fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n"); - if (changes.changed&XkbKeyTypesMask) { - int first= changes.first_type; - int last= changes.first_type+changes.num_types-1; - fprintf(stderr," types: %d..%d\n",first,last); - } - if (changes.changed&XkbKeySymsMask) { - int first= changes.first_key_sym; - int last= changes.first_key_sym+changes.num_key_syms-1; - fprintf(stderr," symbols: %d..%d\n",first,last); - } - if (changes.changed&XkbKeyActionsMask) { - int last,first= changes.first_key_act; - last= changes.first_key_act+changes.num_key_acts-1; - fprintf(stderr," acts: %d..%d\n",first,last); - } - if (changes.changed&XkbKeyBehaviorsMask) { - int last,first= changes.first_key_behavior; - last= first+changes.num_key_behaviors-1; - fprintf(stderr," behaviors: %d..%d\n",first,last); - } - if (changes.changed&XkbVirtualModsMask) { - fprintf(stderr,"virtual mods: 0x%04x\n", - changes.vmods); - } - if (changes.changed&XkbExplicitComponentsMask) { - int last,first= changes.first_key_explicit; - last= first+changes.num_key_explicit-1; - fprintf(stderr," explicit: %d..%d\n",first,last); - } + fprintf(stderr, "Internal Error! XkbGetMapChanges failed:\n"); + if (changes.changed & XkbKeyTypesMask) { + int first = changes.first_type; + int last = changes.first_type + changes.num_types - 1; + + fprintf(stderr, " types: %d..%d\n", first, last); + } + if (changes.changed & XkbKeySymsMask) { + int first = changes.first_key_sym; + int last = changes.first_key_sym + changes.num_key_syms - 1; + + fprintf(stderr, " symbols: %d..%d\n", first, last); + } + if (changes.changed & XkbKeyActionsMask) { + int first = changes.first_key_act; + int last = changes.first_key_act + changes.num_key_acts - 1; + + fprintf(stderr, " acts: %d..%d\n", first, last); + } + if (changes.changed & XkbKeyBehaviorsMask) { + int first = changes.first_key_behavior; + int last = first + changes.num_key_behaviors - 1; + + fprintf(stderr, " behaviors: %d..%d\n", first, last); + } + if (changes.changed & XkbVirtualModsMask) { + fprintf(stderr, "virtual mods: 0x%04x\n", changes.vmods); + } + if (changes.changed & XkbExplicitComponentsMask) { + int first = changes.first_key_explicit; + int last = first + changes.num_key_explicit - 1; + + fprintf(stderr, " explicit: %d..%d\n", first, last); + } #endif - } - LockDisplay(dpy); - if (xkbi->flags&XkbMapPending) { - xkbi->flags&= ~XkbMapPending; - bzero(&xkbi->changes,sizeof(XkbMapChangesRec)); - } - UnlockDisplay(dpy); + } + LockDisplay(dpy); + if (xkbi->flags & XkbMapPending) { + xkbi->flags &= ~XkbMapPending; + bzero(&xkbi->changes, sizeof(XkbMapChangesRec)); + } + UnlockDisplay(dpy); } - if (event->request==MappingModifier) { - LockDisplay(dpy); - if (xkbi->desc->map->modmap) { - _XkbFree(xkbi->desc->map->modmap); - xkbi->desc->map->modmap= NULL; - } - if (dpy->key_bindings) { - register struct _XKeytrans *p; - for (p = dpy->key_bindings; p; p = p->next) { - register int i; - p->state= 0; - if (p->mlen>0) { - for (i = 0; i < p->mlen; i++) { - p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]); - } - if (p->state) p->state &= AllMods; - else p->state = AnyModifier; - } - } - } - UnlockDisplay(dpy); + if (event->request == MappingModifier) { + LockDisplay(dpy); + if (xkbi->desc->map->modmap) { + _XkbFree(xkbi->desc->map->modmap); + xkbi->desc->map->modmap = NULL; + } + if (dpy->key_bindings) { + register struct _XKeytrans *p; + + for (p = dpy->key_bindings; p; p = p->next) { + register int i; + + p->state = 0; + if (p->mlen > 0) { + for (i = 0; i < p->mlen; i++) { + p->state |= XkbKeysymToModifiers(dpy, p->modifiers[i]); + } + if (p->state) + p->state &= AllMods; + else + p->state = AnyModifier; + } + } + } + UnlockDisplay(dpy); } return 1; } @@ -521,35 +540,36 @@ static int _XkbLoadDpy(Display *dpy) { XkbInfoPtr xkbi; - unsigned query,oldEvents; + unsigned query, oldEvents; XkbDescRec *desc; - if (!XkbUseExtension(dpy,NULL,NULL)) - return 0; + if (!XkbUseExtension(dpy, NULL, NULL)) + return 0; xkbi = dpy->xkb_info; query = XkbAllClientInfoMask; - desc = XkbGetMap(dpy,query,XkbUseCoreKbd); + desc = XkbGetMap(dpy, query, XkbUseCoreKbd); if (!desc) { #ifdef DEBUG - fprintf(stderr,"Warning! XkbGetMap failed!\n"); + fprintf(stderr, "Warning! XkbGetMap failed!\n"); #endif - return 0; + return 0; } LockDisplay(dpy); xkbi->desc = desc; UnlockDisplay(dpy); - oldEvents= xkbi->selected_events; - if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) { - XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbNewKeyboardNotify, - XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask, - XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask); + oldEvents = xkbi->selected_events; + if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) { + XkbSelectEventDetails(dpy, xkbi->desc->device_spec, + XkbNewKeyboardNotify, + XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask, + XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask); } - XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, - XkbAllClientInfoMask,XkbAllClientInfoMask); + XkbSelectEventDetails(dpy, xkbi->desc->device_spec, XkbMapNotify, + XkbAllClientInfoMask, XkbAllClientInfoMask); LockDisplay(dpy); - xkbi->selected_events= oldEvents; + xkbi->selected_events = oldEvents; UnlockDisplay(dpy); return 1; } @@ -559,166 +579,174 @@ _XkbReloadDpy(Display *dpy) { XkbInfoPtr xkbi; XkbDescRec *desc; - unsigned oldDeviceID; + unsigned oldDeviceID; if (_XkbUnavailable(dpy)) - return; + return; xkbi = dpy->xkb_info; LockDisplay(dpy); if (xkbi->desc) { - oldDeviceID= xkbi->desc->device_spec; - XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True); - xkbi->desc= NULL; - xkbi->flags&= ~(XkbMapPending|XkbXlibNewKeyboard); - xkbi->changes.changed= 0; + oldDeviceID = xkbi->desc->device_spec; + XkbFreeKeyboard(xkbi->desc, XkbAllComponentsMask, True); + xkbi->desc = NULL; + xkbi->flags &= ~(XkbMapPending | XkbXlibNewKeyboard); + xkbi->changes.changed = 0; } - else oldDeviceID= XkbUseCoreKbd; + else + oldDeviceID = XkbUseCoreKbd; UnlockDisplay(dpy); - desc = XkbGetMap(dpy,XkbAllClientInfoMask,XkbUseCoreKbd); + desc = XkbGetMap(dpy, XkbAllClientInfoMask, XkbUseCoreKbd); if (!desc) - return; + return; LockDisplay(dpy); xkbi->desc = desc; UnlockDisplay(dpy); - if (desc->device_spec!=oldDeviceID) { - /* transfer(?) event masks here */ + if (desc->device_spec != oldDeviceID) { + /* transfer(?) event masks here */ #ifdef NOTYET - unsigned oldEvents; - oldEvents= xkbi->selected_events; - XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, - XkbAllMapComponentsMask,XkbAllClientInfoMask); - LockDisplay(dpy); - xkbi->selected_events= oldEvents; - UnlockDisplay(dpy); + unsigned oldEvents; + + oldEvents = xkbi->selected_events; + XkbSelectEventDetails(dpy, xkbi->desc->device_spec, XkbMapNotify, + XkbAllMapComponentsMask, XkbAllClientInfoMask); + LockDisplay(dpy); + xkbi->selected_events = oldEvents; + UnlockDisplay(dpy); #endif } return; } int -XkbTranslateKeySym( register Display * dpy, - register KeySym * sym_rtrn, - unsigned int mods, - char * buffer, - int nbytes, - int * extra_rtrn) +XkbTranslateKeySym(register Display *dpy, + register KeySym *sym_rtrn, + unsigned int mods, + char *buffer, + int nbytes, + int *extra_rtrn) { - register XkbInfoPtr xkb; + register XkbInfoPtr xkb; XkbKSToMBFunc cvtr; XPointer priv; char tmp[4]; int n; - xkb= dpy->xkb_info; + xkb = dpy->xkb_info; if (!xkb->cvt.KSToMB) { - _XkbGetConverters(_XkbGetCharset(),&xkb->cvt); - _XkbGetConverters("ISO8859-1",&xkb->latin1cvt); + _XkbGetConverters(_XkbGetCharset(), &xkb->cvt); + _XkbGetConverters("ISO8859-1", &xkb->latin1cvt); } if (extra_rtrn) - *extra_rtrn= 0; + *extra_rtrn = 0; - if ((buffer==NULL)||(nbytes==0)) { - buffer= tmp; - nbytes= 4; + if ((buffer == NULL) || (nbytes == 0)) { + buffer = tmp; + nbytes = 4; } /* see if symbol rebound, if so, return that string. */ - n = XkbLookupKeyBinding(dpy,*sym_rtrn,mods,buffer,nbytes,extra_rtrn); + n = XkbLookupKeyBinding(dpy, *sym_rtrn, mods, buffer, nbytes, extra_rtrn); if (n) return n; - if ( nbytes>0 ) - buffer[0]= '\0'; + if (nbytes > 0) + buffer[0] = '\0'; - if ( xkb->cvt.KSToUpper && (mods&LockMask) ) { - *sym_rtrn = (*xkb->cvt.KSToUpper)(*sym_rtrn); + if (xkb->cvt.KSToUpper && (mods & LockMask)) { + *sym_rtrn = (*xkb->cvt.KSToUpper) (*sym_rtrn); } if (xkb->xlib_ctrls & XkbLC_ForceLatin1Lookup) { - cvtr = xkb->latin1cvt.KSToMB; - priv = xkb->latin1cvt.KSToMBPriv; - } else { - cvtr = xkb->cvt.KSToMB; - priv = xkb->cvt.KSToMBPriv; + cvtr = xkb->latin1cvt.KSToMB; + priv = xkb->latin1cvt.KSToMBPriv; + } + else { + cvtr = xkb->cvt.KSToMB; + priv = xkb->cvt.KSToMBPriv; } - n = (*cvtr)(priv,*sym_rtrn,buffer,nbytes,extra_rtrn); - - if ((!xkb->cvt.KSToUpper)&&( mods&LockMask )) { - register int i; - int change; - char ch; - for (i=change=0;i<n;i++) { - ch= toupper(buffer[i]); - change= (change||(buffer[i]!=ch)); - buffer[i] = ch; - } - if (change) { - if (n==1) - *sym_rtrn=(*xkb->cvt.MBToKS)(xkb->cvt.MBToKSPriv,buffer,n,NULL); - else *sym_rtrn= NoSymbol; - } + n = (*cvtr) (priv, *sym_rtrn, buffer, nbytes, extra_rtrn); + + if ((!xkb->cvt.KSToUpper) && (mods & LockMask)) { + register int i; + int change; + + for (i = change = 0; i < n; i++) { + char ch = toupper(buffer[i]); + change = (change || (buffer[i] != ch)); + buffer[i] = ch; + } + if (change) { + if (n == 1) + *sym_rtrn = + (*xkb->cvt.MBToKS) (xkb->cvt.MBToKSPriv, buffer, n, NULL); + else + *sym_rtrn = NoSymbol; + } } - if ( mods&ControlMask ) { - if ( n==1 ) { - buffer[0]= XkbToControl(buffer[0]); - if ( nbytes>1 ) - buffer[1]= '\0'; - return 1; - } - if ( nbytes > 0 ) - buffer[0]= '\0'; - return 0; + if (mods & ControlMask) { + if (n == 1) { + buffer[0] = XkbToControl(buffer[0]); + if (nbytes > 1) + buffer[1] = '\0'; + return 1; + } + if (nbytes > 0) + buffer[0] = '\0'; + return 0; } return n; } int -XLookupString ( register XKeyEvent * event, - char * buffer, - int nbytes, - KeySym * keysym, - XComposeStatus * status) +XLookupString(register XKeyEvent *event, + char *buffer, + int nbytes, + KeySym *keysym, + XComposeStatus *status) { - KeySym dummy; + KeySym dummy; int rtrnLen; unsigned int new_mods; Display *dpy = event->display; - if (keysym==NULL) - keysym= &dummy; - if (!XkbLookupKeySym(dpy,event->keycode,event->state, &new_mods,keysym)) - return 0; - new_mods= (event->state&(~new_mods)); + if (keysym == NULL) + keysym = &dummy; + if (!XkbLookupKeySym(dpy, event->keycode, event->state, &new_mods, keysym)) + return 0; + new_mods = (event->state & (~new_mods)); /* find the group where a symbol can be converted to control one */ - if (new_mods&ControlMask && *keysym > 0x7F && - (dpy->xkb_info->xlib_ctrls & XkbLC_ControlFallback)) { - XKeyEvent tmp_ev = *event; - KeySym tmp_keysym; - unsigned int tmp_new_mods; - if (_XkbUnavailable(dpy)) { - tmp_ev.state= event->state ^ dpy->mode_switch; + if (new_mods & ControlMask && *keysym > 0x7F && + (dpy->xkb_info->xlib_ctrls & XkbLC_ControlFallback)) { + XKeyEvent tmp_ev = *event; + KeySym tmp_keysym; + unsigned int tmp_new_mods; + + if (_XkbUnavailable(dpy)) { + tmp_ev.state = event->state ^ dpy->mode_switch; if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state, &tmp_new_mods, &tmp_keysym) && - tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) { + tmp_keysym != NoSymbol && tmp_keysym < 0x80) { *keysym = tmp_keysym; } - } else { + } + else { int n = XkbKeyNumGroups(dpy->xkb_info->desc, tmp_ev.keycode); int i; + for (i = 0; i < n; i++) { if (XkbGroupForCoreState(event->state) == i) continue; - tmp_ev.state= XkbBuildCoreState(tmp_ev.state, i); + tmp_ev.state = XkbBuildCoreState(tmp_ev.state, i); if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state, - &tmp_new_mods, &tmp_keysym) && - tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) { + &tmp_new_mods, &tmp_keysym) && + tmp_keysym != NoSymbol && tmp_keysym < 0x80) { *keysym = tmp_keysym; - new_mods= (event->state&(~tmp_new_mods)); + new_mods = (event->state & (~tmp_new_mods)); break; } } @@ -726,96 +754,99 @@ XLookupString ( register XKeyEvent * event, } #ifdef USE_OWN_COMPOSE - if ( status ) { - static int been_here= 0; - if ( !been_here ) { - XimCompInitTables(); - been_here = 1; - } - if ( !XimCompLegalStatus(status) ) { - status->compose_ptr = NULL; - status->chars_matched = 0; - } - if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) || - XimCompIsComposeKey(*keysym,event->keycode,status) ) { - XimCompRtrn rtrn; - - switch (XimCompProcessSym(status,*keysym,&rtrn)) { - case XIM_COMP_IGNORE: - break; - case XIM_COMP_IN_PROGRESS: - if ( keysym!=NULL ) - *keysym = NoSymbol; + if (status) { + static int been_here = 0; + + if (!been_here) { + XimCompInitTables(); + been_here = 1; + } + if (!XimCompLegalStatus(status)) { + status->compose_ptr = NULL; + status->chars_matched = 0; + } + if (((status->chars_matched > 0) && (status->compose_ptr != NULL)) || + XimCompIsComposeKey(*keysym, event->keycode, status)) { + XimCompRtrn rtrn; + + switch (XimCompProcessSym(status, *keysym, &rtrn)) { + case XIM_COMP_IGNORE: + break; + case XIM_COMP_IN_PROGRESS: + if (keysym != NULL) + *keysym = NoSymbol; #ifndef NO_COMPOSE_LED - if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) { - XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED, - True,True,False,NULL); - } + if (dpy->xkb_info->xlib_ctrls & XkbLC_ComposeLED) { + XkbSetNamedIndicator(dpy, dpy->xkb_info->composeLED, + True, True, False, NULL); + } #endif - return 0; - case XIM_COMP_FAIL: - { - static Atom _ComposeFail= None; - int n = 0, len= 0; + return 0; + case XIM_COMP_FAIL: + { + static Atom _ComposeFail = None; + int n = 0, len = 0; + #ifndef NO_COMPOSE_LED - if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) { - XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED, - True,False,False,NULL); - } + if (dpy->xkb_info->xlib_ctrls & XkbLC_ComposeLED) { + XkbSetNamedIndicator(dpy, dpy->xkb_info->composeLED, + True, False, False, NULL); + } #endif #ifndef NO_BELL_ON_COMPOSE_FAIL - if (dpy->xkb_info->xlib_ctrls&XkbLC_BeepOnComposeFail) { - if (_ComposeFail==None) - _ComposeFail= XInternAtom(dpy,"ComposeFail",0); - XkbBell(dpy,event->window,0,_ComposeFail); - } + if (dpy->xkb_info->xlib_ctrls & XkbLC_BeepOnComposeFail) { + if (_ComposeFail == None) + _ComposeFail = XInternAtom(dpy, "ComposeFail", 0); + XkbBell(dpy, event->window, 0, _ComposeFail); + } #endif - for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) { - if ( nbytes-len > 0 ) { - len+= XkbTranslateKeySym(dpy,&rtrn.sym[n],new_mods, - buffer+len,nbytes-len, - NULL); - } - } - if ( keysym!=NULL ) { - if ( n==1 ) *keysym = rtrn.sym[0]; - else *keysym = NoSymbol; - } - return len; - } - case XIM_COMP_SUCCEED: - { - int len,n = 0; + for (n = len = 0; rtrn.sym[n] != XK_VoidSymbol; n++) { + if (nbytes - len > 0) { + len += XkbTranslateKeySym(dpy, &rtrn.sym[n], new_mods, + buffer + len, nbytes - len, + NULL); + } + } + if (keysym != NULL) { + if (n == 1) + *keysym = rtrn.sym[0]; + else + *keysym = NoSymbol; + } + return len; + } + case XIM_COMP_SUCCEED: + { + int len, n = 0; #ifndef NO_COMPOSE_LED - if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) { - XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED, - True,False,False,NULL); - } + if (dpy->xkb_info->xlib_ctrls & XkbLC_ComposeLED) { + XkbSetNamedIndicator(dpy, dpy->xkb_info->composeLED, + True, False, False, NULL); + } #endif - *keysym = rtrn.matchSym; - if ( rtrn.str[0]!='\0' ) { - strncpy(buffer,rtrn.str,nbytes-1); - buffer[nbytes-1]= '\0'; - len = (int)strlen(buffer); - } - else { - len = XkbTranslateKeySym(dpy,keysym,new_mods, - buffer,nbytes, - NULL); - } - for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) { - if ( nbytes-len > 0 ) { - len+= XkbTranslateKeySym(dpy,&rtrn.sym[n], - event->state, - buffer+len,nbytes-len, - NULL); - } - } - return len; - } - } - } + *keysym = rtrn.matchSym; + if (rtrn.str[0] != '\0') { + strncpy(buffer, rtrn.str, nbytes - 1); + buffer[nbytes - 1] = '\0'; + len = (int) strlen(buffer); + } + else { + len = XkbTranslateKeySym(dpy, keysym, new_mods, + buffer, nbytes, NULL); + } + for (n = 0; rtrn.sym[n] != XK_VoidSymbol; n++) { + if (nbytes - len > 0) { + len += XkbTranslateKeySym(dpy, &rtrn.sym[n], + event->state, + buffer + len, nbytes - len, + NULL); + } + } + return len; + } + } + } } #endif @@ -823,54 +854,61 @@ XLookupString ( register XKeyEvent * event, /* that were used to compute the symbol here, but pre-XKB XLookupString */ /* did not and we have to remain compatible. Sigh. */ if (_XkbUnavailable(dpy) || - (dpy->xkb_info->xlib_ctrls&XkbLC_ConsumeLookupMods)==0) - new_mods= event->state; + (dpy->xkb_info->xlib_ctrls & XkbLC_ConsumeLookupMods) == 0) + new_mods = event->state; - rtrnLen= XkbLookupKeyBinding(dpy,*keysym,new_mods,buffer,nbytes,NULL); - if (rtrnLen>0) - return rtrnLen; + rtrnLen = XkbLookupKeyBinding(dpy, *keysym, new_mods, buffer, nbytes, NULL); + if (rtrnLen > 0) + return rtrnLen; - return XkbTranslateKeySym(dpy,keysym,new_mods,buffer,nbytes,NULL); + return XkbTranslateKeySym(dpy, keysym, new_mods, buffer, nbytes, NULL); } int -XkbLookupKeyBinding( Display * dpy, - register KeySym sym, - unsigned int mods, - char * buffer, - int nbytes, - int * extra_rtrn) +XkbLookupKeyBinding(Display *dpy, + register KeySym sym, + unsigned int mods, + char *buffer, + int nbytes, + int *extra_rtrn) { register struct _XKeytrans *p; if (extra_rtrn) - *extra_rtrn= 0; + *extra_rtrn = 0; for (p = dpy->key_bindings; p; p = p->next) { - if (((mods & AllMods) == p->state) && (sym == p->key)) { - int tmp = p->len; - if (tmp > nbytes) { - if (extra_rtrn) - *extra_rtrn= (tmp-nbytes); - tmp = nbytes; - } - memcpy (buffer, p->string, tmp); - if (tmp < nbytes) buffer[tmp]= '\0'; - return tmp; - } + if (((mods & AllMods) == p->state) && (sym == p->key)) { + int tmp = p->len; + + if (tmp > nbytes) { + if (extra_rtrn) + *extra_rtrn = (tmp - nbytes); + tmp = nbytes; + } + memcpy(buffer, p->string, tmp); + if (tmp < nbytes) + buffer[tmp] = '\0'; + return tmp; + } } return 0; } char -XkbToControl( char ch ) +XkbToControl(char ch) { register char c = ch; - if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F; - else if (c == '2') c = '\000'; - else if (c >= '3' && c <= '7') c -= ('3' - '\033'); - else if (c == '8') c = '\177'; - else if (c == '/') c = '_' & 0x1F; + if ((c >= '@' && c < '\177') || c == ' ') + c &= 0x1F; + else if (c == '2') + c = '\000'; + else if (c >= '3' && c <= '7') + c -= ('3' - '\033'); + else if (c == '8') + c = '\177'; + else if (c == '/') + c = '_' & 0x1F; return c; } diff --git a/libX11/src/xkb/XKBCompat.c b/libX11/src/xkb/XKBCompat.c index 206b0c90f..227791b9c 100644 --- a/libX11/src/xkb/XKBCompat.c +++ b/libX11/src/xkb/XKBCompat.c @@ -34,191 +34,196 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "XKBlibint.h" Status -_XkbReadGetCompatMapReply( Display * dpy, - xkbGetCompatMapReply * rep, - XkbDescPtr xkb, - int * nread_rtrn) +_XkbReadGetCompatMapReply(Display *dpy, + xkbGetCompatMapReply *rep, + XkbDescPtr xkb, + int *nread_rtrn) { -register int i; -XkbReadBufferRec buf; + register int i; + XkbReadBufferRec buf; - if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) - return BadAlloc; + if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4)) + return BadAlloc; if (nread_rtrn) - *nread_rtrn= (int)rep->length*4; - - i= rep->firstSI+rep->nSI; - if ((!xkb->compat)&& - (XkbAllocCompatMap(xkb,XkbAllCompatMask,i)!=Success)) - return BadAlloc; - - if (rep->nSI!=0) { - XkbSymInterpretRec *syms; - xkbSymInterpretWireDesc *wire; - - wire= (xkbSymInterpretWireDesc *)_XkbGetReadBufferPtr(&buf, - rep->nSI*SIZEOF(xkbSymInterpretWireDesc)); - if (wire==NULL) - goto BAILOUT; - syms= &xkb->compat->sym_interpret[rep->firstSI]; - - for (i=0;i<rep->nSI;i++,syms++,wire++) { - syms->sym= wire->sym; - syms->mods= wire->mods; - syms->match= wire->match; - syms->virtual_mod= wire->virtualMod; - syms->flags= wire->flags; - syms->act= *((XkbAnyAction *)&wire->act); - } - xkb->compat->num_si+= rep->nSI; + *nread_rtrn = (int) rep->length * 4; + + i = rep->firstSI + rep->nSI; + if ((!xkb->compat) && + (XkbAllocCompatMap(xkb, XkbAllCompatMask, i) != Success)) + return BadAlloc; + + if (rep->nSI != 0) { + XkbSymInterpretRec *syms; + xkbSymInterpretWireDesc *wire; + + wire = (xkbSymInterpretWireDesc *) _XkbGetReadBufferPtr(&buf, + rep->nSI * SIZEOF (xkbSymInterpretWireDesc)); + if (wire == NULL) + goto BAILOUT; + syms = &xkb->compat->sym_interpret[rep->firstSI]; + + for (i = 0; i < rep->nSI; i++, syms++, wire++) { + syms->sym = wire->sym; + syms->mods = wire->mods; + syms->match = wire->match; + syms->virtual_mod = wire->virtualMod; + syms->flags = wire->flags; + syms->act = *((XkbAnyAction *) &wire->act); + } + xkb->compat->num_si += rep->nSI; } - if (rep->groups&XkbAllGroupsMask) { - register unsigned bit,nGroups; - xkbModsWireDesc * wire; - for (i=0,nGroups=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { - if (rep->groups&bit) - nGroups++; - } - wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf, - nGroups*SIZEOF(xkbModsWireDesc)); - if (wire==NULL) - goto BAILOUT; - for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { - if ((rep->groups&bit)==0) - continue; - xkb->compat->groups[i].mask= wire->mask; - xkb->compat->groups[i].real_mods= wire->realMods; - xkb->compat->groups[i].vmods= wire->virtualMods; - wire++; - } + if (rep->groups & XkbAllGroupsMask) { + register unsigned bit, nGroups; + xkbModsWireDesc *wire; + + for (i = 0, nGroups = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) { + if (rep->groups & bit) + nGroups++; + } + wire = (xkbModsWireDesc *) + _XkbGetReadBufferPtr(&buf, nGroups * SIZEOF(xkbModsWireDesc)); + if (wire == NULL) + goto BAILOUT; + for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) { + if ((rep->groups & bit) == 0) + continue; + xkb->compat->groups[i].mask = wire->mask; + xkb->compat->groups[i].real_mods = wire->realMods; + xkb->compat->groups[i].vmods = wire->virtualMods; + wire++; + } } - i= _XkbFreeReadBuffer(&buf); + i = _XkbFreeReadBuffer(&buf); if (i) - fprintf(stderr,"CompatMapReply! Bad length (%d extra bytes)\n",i); + fprintf(stderr, "CompatMapReply! Bad length (%d extra bytes)\n", i); if (i || buf.error) - return BadLength; + return BadLength; return Success; -BAILOUT: + BAILOUT: _XkbFreeReadBuffer(&buf); return BadLength; } Status -XkbGetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb) +XkbGetCompatMap(Display *dpy, unsigned which, XkbDescPtr xkb) { register xkbGetCompatMapReq *req; - xkbGetCompatMapReply rep; - Status status; + xkbGetCompatMapReply rep; + Status status; XkbInfoPtr xkbi; - if ( (!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) || - ((xkb->dpy!=NULL)&&(xkb->dpy!=dpy)) || - (!dpy->xkb_info && (!XkbUseExtension(dpy,NULL,NULL)))) - return BadAccess; + if ((!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) || + ((xkb->dpy != NULL) && (xkb->dpy != dpy)) || + (!dpy->xkb_info && (!XkbUseExtension(dpy, NULL, NULL)))) + return BadAccess; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetCompatMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetCompatMap; req->deviceSpec = xkb->device_spec; - if (which&XkbSymInterpMask) - req->getAllSI= True; - else req->getAllSI= False; - req->firstSI= req->nSI= 0; - - if (which&XkbGroupCompatMask) - req->groups= XkbAllGroupsMask; - else req->groups= 0; - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadLength; + if (which & XkbSymInterpMask) + req->getAllSI = True; + else + req->getAllSI = False; + req->firstSI = req->nSI = 0; + + if (which & XkbGroupCompatMask) + req->groups = XkbAllGroupsMask; + else + req->groups = 0; + + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadLength; } - if (xkb->dpy==NULL) - xkb->dpy= dpy; - if (xkb->device_spec==XkbUseCoreKbd) - xkb->device_spec= rep.deviceID; + if (xkb->dpy == NULL) + xkb->dpy = dpy; + if (xkb->device_spec == XkbUseCoreKbd) + xkb->device_spec = rep.deviceID; - status = _XkbReadGetCompatMapReply(dpy,&rep,xkb,NULL); + status = _XkbReadGetCompatMapReply(dpy, &rep, xkb, NULL); UnlockDisplay(dpy); SyncHandle(); return status; } static Bool -_XkbWriteSetCompatMap(Display *dpy,xkbSetCompatMapReq *req,XkbDescPtr xkb) +_XkbWriteSetCompatMap(Display *dpy, xkbSetCompatMapReq *req, XkbDescPtr xkb) { -CARD16 firstSI; -CARD16 nSI; -int size; -register int i,nGroups; -register unsigned bit; -unsigned groups; -char * buf; + CARD16 firstSI; + CARD16 nSI; + int size; + register int i, nGroups; + register unsigned bit; + unsigned groups; + char *buf; firstSI = req->firstSI; nSI = req->nSI; - size= nSI*SIZEOF(xkbSymInterpretWireDesc); - nGroups= 0; - groups= req->groups; - if (groups&XkbAllGroupsMask) { - for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { - if (groups&bit) - nGroups++; - } - size+= SIZEOF(xkbModsWireDesc)*nGroups; + size = nSI * SIZEOF(xkbSymInterpretWireDesc); + nGroups = 0; + groups = req->groups; + if (groups & XkbAllGroupsMask) { + for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) { + if (groups & bit) + nGroups++; + } + size += SIZEOF(xkbModsWireDesc) * nGroups; } - req->length+= size/4; - BufAlloc(char *,buf,size); + req->length += size / 4; + BufAlloc(char *, buf, size); + if (!buf) - return False; + return False; if (nSI) { - XkbSymInterpretPtr sym= &xkb->compat->sym_interpret[firstSI]; - xkbSymInterpretWireDesc *wire= (xkbSymInterpretWireDesc *)buf; - for (i=0;i<nSI;i++,wire++,sym++) { - wire->sym= (CARD32)sym->sym; - wire->mods= sym->mods; - wire->match= sym->match; - wire->flags= sym->flags; - wire->virtualMod= sym->virtual_mod; - memcpy(&wire->act,&sym->act,sz_xkbActionWireDesc); - } - buf+= nSI*SIZEOF(xkbSymInterpretWireDesc); + XkbSymInterpretPtr sym = &xkb->compat->sym_interpret[firstSI]; + xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) buf; + + for (i = 0; i < nSI; i++, wire++, sym++) { + wire->sym = (CARD32) sym->sym; + wire->mods = sym->mods; + wire->match = sym->match; + wire->flags = sym->flags; + wire->virtualMod = sym->virtual_mod; + memcpy(&wire->act, &sym->act, sz_xkbActionWireDesc); + } + buf += nSI * SIZEOF(xkbSymInterpretWireDesc); } - if (groups&XkbAllGroupsMask) { - xkbModsWireDesc * out; - - out= (xkbModsWireDesc *)buf; - for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { - if ((groups&bit)!=0) { - out->mask= xkb->compat->groups[i].mask; - out->realMods= xkb->compat->groups[i].real_mods; - out->virtualMods= xkb->compat->groups[i].vmods; - out++; - } - } - buf+= nGroups*SIZEOF(xkbModsWireDesc); + if (groups & XkbAllGroupsMask) { + xkbModsWireDesc *out = (xkbModsWireDesc *) buf; + + for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) { + if ((groups & bit) != 0) { + out->mask = xkb->compat->groups[i].mask; + out->realMods = xkb->compat->groups[i].real_mods; + out->virtualMods = xkb->compat->groups[i].vmods; + out++; + } + } + buf += nGroups * SIZEOF(xkbModsWireDesc); } return True; } Bool -XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions) +XkbSetCompatMap(Display *dpy, unsigned which, XkbDescPtr xkb, + Bool updateActions) { register xkbSetCompatMapReq *req; - Status ok; + Status ok; XkbInfoPtr xkbi; - if ((dpy->flags & XlibDisplayNoXkb) || (dpy!=xkb->dpy) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + if ((dpy->flags & XlibDisplayNoXkb) || (dpy != xkb->dpy) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; if ((!xkb->compat) || - ((which&XkbSymInterpMask)&&(!xkb->compat->sym_interpret))) - return False; + ((which & XkbSymInterpMask) && (!xkb->compat->sym_interpret))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetCompatMap, req); @@ -226,22 +231,22 @@ XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions) req->xkbReqType = X_kbSetCompatMap; req->deviceSpec = xkb->device_spec; req->recomputeActions = updateActions; - if (which&XkbSymInterpMask) { - req->truncateSI = True; - req->firstSI= 0; - req->nSI= xkb->compat->num_si; + if (which & XkbSymInterpMask) { + req->truncateSI = True; + req->firstSI = 0; + req->nSI = xkb->compat->num_si; } else { - req->truncateSI = False; - req->firstSI= 0; - req->nSI= 0; + req->truncateSI = False; + req->firstSI = 0; + req->nSI = 0; } - if (which&XkbGroupCompatMask) - req->groups= XkbAllGroupsMask; - else req->groups= 0; - ok= _XkbWriteSetCompatMap(dpy,req,xkb); + if (which & XkbGroupCompatMask) + req->groups = XkbAllGroupsMask; + else + req->groups = 0; + ok = _XkbWriteSetCompatMap(dpy, req, xkb); UnlockDisplay(dpy); SyncHandle(); return ok; } - diff --git a/libX11/src/xkb/XKBCtrls.c b/libX11/src/xkb/XKBCtrls.c index 2b33b3059..35a34b8b2 100644 --- a/libX11/src/xkb/XKBCtrls.c +++ b/libX11/src/xkb/XKBCtrls.c @@ -34,32 +34,32 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. static xkbSetControlsReq * -_XkbGetSetControlsReq(Display *dpy,XkbInfoPtr xkbi,unsigned int deviceSpec) +_XkbGetSetControlsReq(Display *dpy, XkbInfoPtr xkbi, unsigned int deviceSpec) { -xkbSetControlsReq *req; + xkbSetControlsReq *req; - GetReq(kbSetControls,req); - bzero(req,SIZEOF(xkbSetControlsReq)); + GetReq(kbSetControls, req); + bzero(req, SIZEOF(xkbSetControlsReq)); req->reqType = xkbi->codes->major_opcode; - req->length = (SIZEOF(xkbSetControlsReq)>>2); + req->length = (SIZEOF(xkbSetControlsReq) >> 2); req->xkbReqType = X_kbSetControls; req->deviceSpec = deviceSpec; return req; } Bool -XkbSetAutoRepeatRate( Display *dpy, - unsigned int deviceSpec, - unsigned int timeout, - unsigned int interval) +XkbSetAutoRepeatRate(Display *dpy, + unsigned int deviceSpec, + unsigned int timeout, + unsigned int interval) { register xkbSetControlsReq *req; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); - req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); + req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec); req->changeCtrls = XkbRepeatKeysMask; req->repeatDelay = timeout; req->repeatInterval = interval; @@ -69,29 +69,29 @@ XkbSetAutoRepeatRate( Display *dpy, } Bool -XkbGetAutoRepeatRate( Display * dpy, - unsigned int deviceSpec, - unsigned int * timeoutp, - unsigned int * intervalp) +XkbGetAutoRepeatRate(Display *dpy, + unsigned int deviceSpec, + unsigned int *timeoutp, + unsigned int *intervalp) { register xkbGetControlsReq *req; xkbGetControlsReply rep; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetControls, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetControls; req->deviceSpec = deviceSpec; - if (!_XReply(dpy, (xReply *)&rep, - (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + if (!_XReply(dpy, (xReply *) &rep, + (SIZEOF(xkbGetControlsReply) - SIZEOF(xReply)) >> 2, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); @@ -101,24 +101,24 @@ XkbGetAutoRepeatRate( Display * dpy, } Bool -XkbSetServerInternalMods( Display * dpy, - unsigned deviceSpec, - unsigned affectReal, - unsigned realValues, - unsigned affectVirtual, - unsigned virtualValues) +XkbSetServerInternalMods(Display *dpy, + unsigned deviceSpec, + unsigned affectReal, + unsigned realValues, + unsigned affectVirtual, + unsigned virtualValues) { register xkbSetControlsReq *req; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); - req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); + req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec); req->affectInternalMods = affectReal; req->internalMods = realValues; - req->affectInternalVMods= affectVirtual; - req->internalVMods= virtualValues; + req->affectInternalVMods = affectVirtual; + req->internalVMods = virtualValues; req->changeCtrls = XkbInternalModsMask; UnlockDisplay(dpy); SyncHandle(); @@ -126,24 +126,24 @@ XkbSetServerInternalMods( Display * dpy, } Bool -XkbSetIgnoreLockMods( Display * dpy, - unsigned int deviceSpec, - unsigned affectReal, - unsigned realValues, - unsigned affectVirtual, - unsigned virtualValues) +XkbSetIgnoreLockMods(Display *dpy, + unsigned int deviceSpec, + unsigned affectReal, + unsigned realValues, + unsigned affectVirtual, + unsigned virtualValues) { register xkbSetControlsReq *req; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); - req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); - req->affectIgnoreLockMods= affectReal; + req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec); + req->affectIgnoreLockMods = affectReal; req->ignoreLockMods = realValues; - req->affectIgnoreLockVMods= affectVirtual; - req->ignoreLockVMods= virtualValues; + req->affectIgnoreLockVMods = affectVirtual; + req->ignoreLockVMods = virtualValues; req->changeCtrls = XkbIgnoreLockModsMask; UnlockDisplay(dpy); SyncHandle(); @@ -151,20 +151,20 @@ XkbSetIgnoreLockMods( Display * dpy, } Bool -XkbChangeEnabledControls( Display * dpy, - unsigned deviceSpec, - unsigned affect, - unsigned values) +XkbChangeEnabledControls(Display *dpy, + unsigned deviceSpec, + unsigned affect, + unsigned values) { register xkbSetControlsReq *req; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); - req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); - req->affectEnabledCtrls= affect; - req->enabledCtrls= (affect&values); + req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec); + req->affectEnabledCtrls = affect; + req->enabledCtrls = (affect & values); req->changeCtrls = XkbControlsEnabledMask; UnlockDisplay(dpy); SyncHandle(); @@ -176,91 +176,90 @@ XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) { register xkbGetControlsReq *req; xkbGetControlsReply rep; - XkbControlsPtr ctrls; + XkbControlsPtr ctrls; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; if ((!xkb) || (!which)) - return BadMatch; + return BadMatch; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetControls, req); - if (!xkb->ctrls) { - xkb->ctrls = _XkbTypedCalloc(1,XkbControlsRec); - if (!xkb->ctrls) { - UnlockDisplay(dpy); - SyncHandle(); - return BadAlloc; - } + if (!xkb->ctrls) { + xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec); + if (!xkb->ctrls) { + UnlockDisplay(dpy); + SyncHandle(); + return BadAlloc; + } } req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetControls; req->deviceSpec = xkb->device_spec; - if (!_XReply(dpy, (xReply *)&rep, - (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadImplementation; + if (!_XReply(dpy, (xReply *) &rep, + (SIZEOF(xkbGetControlsReply) - SIZEOF(xReply)) >> 2, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadImplementation; } - if (xkb->device_spec==XkbUseCoreKbd) - xkb->device_spec= rep.deviceID; - ctrls= xkb->ctrls; - if (which&XkbControlsEnabledMask) - ctrls->enabled_ctrls = rep.enabledCtrls; - ctrls->num_groups= rep.numGroups; - if (which&XkbGroupsWrapMask) - ctrls->groups_wrap= rep.groupsWrap; - if (which&XkbInternalModsMask) { - ctrls->internal.mask = rep.internalMods; - ctrls->internal.real_mods = rep.internalRealMods; - ctrls->internal.vmods = rep.internalVMods; + if (xkb->device_spec == XkbUseCoreKbd) + xkb->device_spec = rep.deviceID; + ctrls = xkb->ctrls; + if (which & XkbControlsEnabledMask) + ctrls->enabled_ctrls = rep.enabledCtrls; + ctrls->num_groups = rep.numGroups; + if (which & XkbGroupsWrapMask) + ctrls->groups_wrap = rep.groupsWrap; + if (which & XkbInternalModsMask) { + ctrls->internal.mask = rep.internalMods; + ctrls->internal.real_mods = rep.internalRealMods; + ctrls->internal.vmods = rep.internalVMods; } - if (which&XkbIgnoreLockModsMask) { - ctrls->ignore_lock.mask = rep.ignoreLockMods; - ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods; - ctrls->ignore_lock.vmods = rep.ignoreLockVMods; + if (which & XkbIgnoreLockModsMask) { + ctrls->ignore_lock.mask = rep.ignoreLockMods; + ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods; + ctrls->ignore_lock.vmods = rep.ignoreLockVMods; } - if (which&XkbRepeatKeysMask) { - ctrls->repeat_delay = rep.repeatDelay; - ctrls->repeat_interval = rep.repeatInterval; + if (which & XkbRepeatKeysMask) { + ctrls->repeat_delay = rep.repeatDelay; + ctrls->repeat_interval = rep.repeatInterval; } - if (which&XkbSlowKeysMask) - ctrls->slow_keys_delay = rep.slowKeysDelay; - if (which&XkbBounceKeysMask) - ctrls->debounce_delay = rep.debounceDelay; - if (which&XkbMouseKeysMask) { - ctrls->mk_dflt_btn = rep.mkDfltBtn; + if (which & XkbSlowKeysMask) + ctrls->slow_keys_delay = rep.slowKeysDelay; + if (which & XkbBounceKeysMask) + ctrls->debounce_delay = rep.debounceDelay; + if (which & XkbMouseKeysMask) { + ctrls->mk_dflt_btn = rep.mkDfltBtn; } - if (which&XkbMouseKeysAccelMask) { - ctrls->mk_delay = rep.mkDelay; - ctrls->mk_interval = rep.mkInterval; - ctrls->mk_time_to_max = rep.mkTimeToMax; - ctrls->mk_max_speed = rep.mkMaxSpeed; - ctrls->mk_curve = rep.mkCurve; + if (which & XkbMouseKeysAccelMask) { + ctrls->mk_delay = rep.mkDelay; + ctrls->mk_interval = rep.mkInterval; + ctrls->mk_time_to_max = rep.mkTimeToMax; + ctrls->mk_max_speed = rep.mkMaxSpeed; + ctrls->mk_curve = rep.mkCurve; } - if (which&XkbAccessXKeysMask) - ctrls->ax_options= rep.axOptions; - if (which&XkbStickyKeysMask) { - ctrls->ax_options &= ~XkbAX_SKOptionsMask; - ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask; + if (which & XkbAccessXKeysMask) + ctrls->ax_options = rep.axOptions; + if (which & XkbStickyKeysMask) { + ctrls->ax_options &= ~XkbAX_SKOptionsMask; + ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask; } - if (which&XkbAccessXFeedbackMask) { - ctrls->ax_options &= ~XkbAX_FBOptionsMask; - ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask; + if (which & XkbAccessXFeedbackMask) { + ctrls->ax_options &= ~XkbAX_FBOptionsMask; + ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask; } - if (which&XkbAccessXTimeoutMask) { - ctrls->ax_timeout = rep.axTimeout; - ctrls->axt_ctrls_mask = rep.axtCtrlsMask; - ctrls->axt_ctrls_values = rep.axtCtrlsValues; - ctrls->axt_opts_mask = rep.axtOptsMask; - ctrls->axt_opts_values= rep.axtOptsValues; + if (which & XkbAccessXTimeoutMask) { + ctrls->ax_timeout = rep.axTimeout; + ctrls->axt_ctrls_mask = rep.axtCtrlsMask; + ctrls->axt_ctrls_values = rep.axtCtrlsValues; + ctrls->axt_opts_mask = rep.axtOptsMask; + ctrls->axt_opts_values = rep.axtOptsValues; } - if (which&XkbPerKeyRepeatMask) { - memcpy(ctrls->per_key_repeat,rep.perKeyRepeat, - XkbPerKeyBitArraySize); + if (which & XkbPerKeyRepeatMask) { + memcpy(ctrls->per_key_repeat, rep.perKeyRepeat, XkbPerKeyBitArraySize); } UnlockDisplay(dpy); SyncHandle(); @@ -271,66 +270,66 @@ Bool XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) { register xkbSetControlsReq *req; - XkbControlsPtr ctrls; + XkbControlsPtr ctrls; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!xkb)||(!xkb->ctrls)) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!xkb) || (!xkb->ctrls)) + return False; - ctrls= xkb->ctrls; + ctrls = xkb->ctrls; LockDisplay(dpy); - req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,xkb->device_spec); - req->changeCtrls = (CARD32)which; - if (which&XkbInternalModsMask) { - req->affectInternalMods= ~0; - req->internalMods= ctrls->internal.real_mods; - req->affectInternalVMods = ~0; - req->internalVMods= ctrls->internal.vmods; + req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, xkb->device_spec); + req->changeCtrls = (CARD32) which; + if (which & XkbInternalModsMask) { + req->affectInternalMods = ~0; + req->internalMods = ctrls->internal.real_mods; + req->affectInternalVMods = ~0; + req->internalVMods = ctrls->internal.vmods; } - if (which&XkbIgnoreLockModsMask) { - req->affectIgnoreLockMods= ~0; - req->ignoreLockMods= ctrls->ignore_lock.real_mods; - req->affectIgnoreLockVMods= ~0; - req->ignoreLockVMods= ctrls->ignore_lock.vmods; + if (which & XkbIgnoreLockModsMask) { + req->affectIgnoreLockMods = ~0; + req->ignoreLockMods = ctrls->ignore_lock.real_mods; + req->affectIgnoreLockVMods = ~0; + req->ignoreLockVMods = ctrls->ignore_lock.vmods; } - if (which&XkbControlsEnabledMask) { - req->affectEnabledCtrls= XkbAllBooleanCtrlsMask; - req->enabledCtrls= ctrls->enabled_ctrls; + if (which & XkbControlsEnabledMask) { + req->affectEnabledCtrls = XkbAllBooleanCtrlsMask; + req->enabledCtrls = ctrls->enabled_ctrls; } - if (which&XkbRepeatKeysMask) { - req->repeatDelay = ctrls->repeat_delay; - req->repeatInterval = ctrls->repeat_interval; + if (which & XkbRepeatKeysMask) { + req->repeatDelay = ctrls->repeat_delay; + req->repeatInterval = ctrls->repeat_interval; } - if (which&XkbSlowKeysMask) - req->slowKeysDelay = ctrls->slow_keys_delay; - if (which&XkbBounceKeysMask) - req->debounceDelay = ctrls->debounce_delay; - if (which&XkbMouseKeysMask) { - req->mkDfltBtn = ctrls->mk_dflt_btn; + if (which & XkbSlowKeysMask) + req->slowKeysDelay = ctrls->slow_keys_delay; + if (which & XkbBounceKeysMask) + req->debounceDelay = ctrls->debounce_delay; + if (which & XkbMouseKeysMask) { + req->mkDfltBtn = ctrls->mk_dflt_btn; } - if (which&XkbGroupsWrapMask) - req->groupsWrap= ctrls->groups_wrap; - if (which&(XkbAccessXKeysMask|XkbStickyKeysMask|XkbAccessXFeedbackMask)) - req->axOptions= ctrls->ax_options; - if (which&XkbMouseKeysAccelMask) { - req->mkDelay = ctrls->mk_delay; - req->mkInterval = ctrls->mk_interval; - req->mkTimeToMax = ctrls->mk_time_to_max; - req->mkMaxSpeed = ctrls->mk_max_speed; - req->mkCurve = ctrls->mk_curve; + if (which & XkbGroupsWrapMask) + req->groupsWrap = ctrls->groups_wrap; + if (which & + (XkbAccessXKeysMask | XkbStickyKeysMask | XkbAccessXFeedbackMask)) + req->axOptions = ctrls->ax_options; + if (which & XkbMouseKeysAccelMask) { + req->mkDelay = ctrls->mk_delay; + req->mkInterval = ctrls->mk_interval; + req->mkTimeToMax = ctrls->mk_time_to_max; + req->mkMaxSpeed = ctrls->mk_max_speed; + req->mkCurve = ctrls->mk_curve; } - if (which&XkbAccessXTimeoutMask) { - req->axTimeout = ctrls->ax_timeout; - req->axtCtrlsMask = ctrls->axt_ctrls_mask; - req->axtCtrlsValues = ctrls->axt_ctrls_values; - req->axtOptsMask = ctrls->axt_opts_mask; - req->axtOptsValues=ctrls->axt_opts_values; + if (which & XkbAccessXTimeoutMask) { + req->axTimeout = ctrls->ax_timeout; + req->axtCtrlsMask = ctrls->axt_ctrls_mask; + req->axtCtrlsValues = ctrls->axt_ctrls_values; + req->axtOptsMask = ctrls->axt_opts_mask; + req->axtOptsValues = ctrls->axt_opts_values; } - if (which&XkbPerKeyRepeatMask) { - memcpy(req->perKeyRepeat,ctrls->per_key_repeat, - XkbPerKeyBitArraySize); + if (which & XkbPerKeyRepeatMask) { + memcpy(req->perKeyRepeat, ctrls->per_key_repeat, XkbPerKeyBitArraySize); } UnlockDisplay(dpy); SyncHandle(); @@ -340,13 +339,13 @@ XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) /***====================================================================***/ void -XkbNoteControlsChanges( XkbControlsChangesPtr old, - XkbControlsNotifyEvent * new, - unsigned int wanted) +XkbNoteControlsChanges(XkbControlsChangesPtr old, + XkbControlsNotifyEvent *new, + unsigned int wanted) { - old->changed_ctrls|= (new->changed_ctrls&wanted); - if (new->changed_ctrls&XkbControlsEnabledMask&wanted) - old->enabled_ctrls_changes^= new->enabled_ctrl_changes; + old->changed_ctrls |= (new->changed_ctrls & wanted); + if (new->changed_ctrls & XkbControlsEnabledMask & wanted) + old->enabled_ctrls_changes ^= new->enabled_ctrl_changes; /* num_groups_changed?? */ return; } diff --git a/libX11/src/xkb/XKBCvt.c b/libX11/src/xkb/XKBCvt.c index da74fc047..5317a0a5c 100644 --- a/libX11/src/xkb/XKBCvt.c +++ b/libX11/src/xkb/XKBCvt.c @@ -60,94 +60,99 @@ _XkbHandleSpecialSym(KeySym keysym, char *buffer, int nbytes, int *extra_rtrn) /* try to convert to Latin-1, handling ctrl */ if (!(((keysym >= XK_BackSpace) && (keysym <= XK_Clear)) || - (keysym == XK_Return) || (keysym == XK_Escape) || - (keysym == XK_KP_Space) || (keysym == XK_KP_Tab) || - (keysym == XK_KP_Enter) || - ((keysym >= XK_KP_Multiply) && (keysym <= XK_KP_9)) || - (keysym == XK_KP_Equal) || - (keysym == XK_Delete))) - return 0; - - if (nbytes<1) { - if (extra_rtrn) - *extra_rtrn= 1; - return 0; + (keysym == XK_Return) || (keysym == XK_Escape) || + (keysym == XK_KP_Space) || (keysym == XK_KP_Tab) || + (keysym == XK_KP_Enter) || + ((keysym >= XK_KP_Multiply) && (keysym <= XK_KP_9)) || + (keysym == XK_KP_Equal) || (keysym == XK_Delete))) + return 0; + + if (nbytes < 1) { + if (extra_rtrn) + *extra_rtrn = 1; + return 0; } /* if X keysym, convert to ascii by grabbing low 7 bits */ if (keysym == XK_KP_Space) - buffer[0] = XK_space & 0x7F; /* patch encoding botch */ + buffer[0] = XK_space & 0x7F; /* patch encoding botch */ else if (keysym == XK_hyphen) - buffer[0] = (char)(XK_minus & 0xFF); /* map to equiv character */ - else buffer[0] = (char)(keysym & 0x7F); + buffer[0] = (char) (XK_minus & 0xFF); /* map to equiv character */ + else + buffer[0] = (char) (keysym & 0x7F); return 1; } /*ARGSUSED*/ static int -_XkbKSToKnownSet ( XPointer priv, - KeySym keysym, - char * buffer, - int nbytes, - int * extra_rtrn) +_XkbKSToKnownSet(XPointer priv, + KeySym keysym, + char *buffer, + int nbytes, + int *extra_rtrn) { - char tbuf[8],*buf; + char tbuf[8], *buf; if (extra_rtrn) - *extra_rtrn= 0; + *extra_rtrn = 0; /* convert "dead" diacriticals for dumb applications */ - if ( (keysym&0xffffff00)== 0xfe00 ) { - switch ( keysym ) { - case XK_dead_grave: keysym = XK_grave; break; - case XK_dead_acute: keysym = XK_acute; break; - case XK_dead_circumflex: keysym = XK_asciicircum; break; - case XK_dead_tilde: keysym = XK_asciitilde; break; - case XK_dead_macron: keysym = XK_macron; break; - case XK_dead_breve: keysym = XK_breve; break; - case XK_dead_abovedot: keysym = XK_abovedot; break; - case XK_dead_diaeresis: keysym = XK_diaeresis; break; - case XK_dead_abovering: keysym = XK_degree; break; - case XK_dead_doubleacute: keysym = XK_doubleacute; break; - case XK_dead_caron: keysym = XK_caron; break; - case XK_dead_cedilla: keysym = XK_cedilla; break; - case XK_dead_ogonek : keysym = XK_ogonek; break; - case XK_dead_iota: keysym = XK_Greek_iota; break; + if ((keysym & 0xffffff00) == 0xfe00) { + switch (keysym) { + case XK_dead_grave: keysym = XK_grave; break; + case XK_dead_acute: keysym = XK_acute; break; + case XK_dead_circumflex: keysym = XK_asciicircum; break; + case XK_dead_tilde: keysym = XK_asciitilde; break; + case XK_dead_macron: keysym = XK_macron; break; + case XK_dead_breve: keysym = XK_breve; break; + case XK_dead_abovedot: keysym = XK_abovedot; break; + case XK_dead_diaeresis: keysym = XK_diaeresis; break; + case XK_dead_abovering: keysym = XK_degree; break; + case XK_dead_doubleacute: keysym = XK_doubleacute; break; + case XK_dead_caron: keysym = XK_caron; break; + case XK_dead_cedilla: keysym = XK_cedilla; break; + case XK_dead_ogonek: keysym = XK_ogonek; break; + case XK_dead_iota: keysym = XK_Greek_iota; break; #ifdef XK_KATAKANA - case XK_dead_voiced_sound: keysym = XK_voicedsound; break; - case XK_dead_semivoiced_sound:keysym = XK_semivoicedsound; break; + case XK_dead_voiced_sound: keysym = XK_voicedsound; break; + case XK_dead_semivoiced_sound: keysym = XK_semivoicedsound; break; #endif - } + } } - if (nbytes<1) buf= tbuf; - else buf= buffer; + if (nbytes < 1) + buf = tbuf; + else + buf = buffer; - if ((keysym&0xffffff00)==0xff00) { - return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn); + if ((keysym & 0xffffff00) == 0xff00) { + return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn); } - return _XimGetCharCode (priv, keysym, (unsigned char *)buf, nbytes); + return _XimGetCharCode(priv, keysym, (unsigned char *) buf, nbytes); } typedef struct _XkbToKS { - unsigned prefix; - char *map; + unsigned prefix; + char *map; } XkbToKS; /*ARGSUSED*/ static KeySym -_XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status) +_XkbKnownSetToKS(XPointer priv, char *buffer, int nbytes, Status *status) { - if (nbytes!=1) - return NoSymbol; - if (((buffer[0]&0x80)==0)&&(buffer[0]>=32)) - return buffer[0]; - else if ((buffer[0]&0x7f)>=32) { - XkbToKS *map= (XkbToKS *)priv; - if ( map ) { - if ( map->map ) return map->prefix|map->map[buffer[0]&0x7f]; - else return map->prefix|buffer[0]; - } - return buffer[0]; + if (nbytes != 1) + return NoSymbol; + if (((buffer[0] & 0x80) == 0) && (buffer[0] >= 32)) + return buffer[0]; + else if ((buffer[0] & 0x7f) >= 32) { + XkbToKS *map = (XkbToKS *) priv; + + if (map) { + if (map->map) + return map->prefix | map->map[buffer[0] & 0x7f]; + else + return map->prefix | buffer[0]; + } + return buffer[0]; } return NoSymbol; } @@ -155,7 +160,7 @@ _XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status) static KeySym __XkbDefaultToUpper(KeySym sym) { - KeySym lower,upper; + KeySym lower, upper; XConvertCase(sym, &lower, &upper); return upper; @@ -172,13 +177,13 @@ Strcmp(char *str1, char *str2) * unchecked strings from the environment can end up here, so check * the length before copying. */ - if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */ - return 1; + if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */ + return 1; - for (s = str; (c = *str1++); ) { - if (isupper(c)) - c = tolower(c); - *s++ = c; + for (s = str; (c = *str1++);) { + if (isupper(c)) + c = tolower(c); + *s++ = c; } *s = '\0'; return (strcmp(str, str2)); @@ -186,9 +191,10 @@ Strcmp(char *str1, char *str2) #endif int -_XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn) +_XkbGetConverters(const char *encoding_name, XkbConverters * cvt_rtrn) { - if ( !cvt_rtrn ) return 0; + if (!cvt_rtrn) + return 0; cvt_rtrn->KSToMB = _XkbKSToKnownSet; cvt_rtrn->KSToMBPriv = _XimGetLocaleCode(encoding_name); @@ -214,9 +220,14 @@ _XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn) */ #define CHARSET_FILE "/usr/lib/X11/input/charsets" -static char *_XkbKnownLanguages = "c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251"; - -char * +static char *_XkbKnownLanguages = + "c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:" + "eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:" + "tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:" + "th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:" + "vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251"; + +char * _XkbGetCharset(void) { /* @@ -225,49 +236,51 @@ _XkbGetCharset(void) */ static char buf[100] = { 0 }; char lang[256]; - char *start,*tmp,*end,*next,*set; - char *country,*charset; + char *start, *tmp, *end, *next, *set; + char *country, *charset; char *locale; - tmp = getenv( "_XKB_CHARSET" ); - if ( tmp ) - return tmp; - locale = setlocale(LC_CTYPE,NULL); + tmp = getenv("_XKB_CHARSET"); + if (tmp) + return tmp; + locale = setlocale(LC_CTYPE, NULL); - if ( locale == NULL ) - return NULL; + if (locale == NULL) + return NULL; if (strlen(locale) >= sizeof(lang)) - return NULL; + return NULL; for (tmp = lang; *tmp = *locale++; tmp++) { - if (isupper(*tmp)) - *tmp = tolower(*tmp); + if (isupper(*tmp)) + *tmp = tolower(*tmp); } - country = strchr( lang, '_'); - if ( country ) { - *country++ = '\0'; - charset = strchr( country, '.' ); - if ( charset ) *charset++ = '\0'; - if ( charset ) { - strncpy(buf,charset,99); - buf[99] = '\0'; - return buf; - } + country = strchr(lang, '_'); + if (country) { + *country++ = '\0'; + charset = strchr(country, '.'); + if (charset) + *charset++ = '\0'; + if (charset) { + strncpy(buf, charset, 99); + buf[99] = '\0'; + return buf; + } } else { - charset = NULL; + charset = NULL; } - if ((tmp = getenv("_XKB_LOCALE_CHARSETS"))!=NULL) { - start = _XkbAlloc(strlen(tmp) + 1); - strcpy(start, tmp); - tmp = start; - } else { - struct stat sbuf; - FILE *file; + if ((tmp = getenv("_XKB_LOCALE_CHARSETS")) != NULL) { + start = _XkbAlloc(strlen(tmp) + 1); + strcpy(start, tmp); + tmp = start; + } + else { + struct stat sbuf; + FILE *file; #ifndef __UNIXOS2__ - char *cf = CHARSET_FILE; + char *cf = CHARSET_FILE; #else char *cf = __XOS2RedirRoot(CHARSET_FILE); #endif @@ -276,62 +289,61 @@ _XkbGetCharset(void) # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) #endif - if ( (stat(cf,&sbuf)==0) && S_ISREG(sbuf.st_mode) && - (file = fopen(cf,"r")) ) { - tmp = _XkbAlloc(sbuf.st_size+1); - if (tmp!=NULL) { - sbuf.st_size = (long)fread(tmp,1,sbuf.st_size,file); - tmp[sbuf.st_size] = '\0'; - } - fclose(file); - } + if ((stat(cf, &sbuf) == 0) && S_ISREG(sbuf.st_mode) && + (file = fopen(cf, "r"))) { + tmp = _XkbAlloc(sbuf.st_size + 1); + if (tmp != NULL) { + sbuf.st_size = (long) fread(tmp, 1, sbuf.st_size, file); + tmp[sbuf.st_size] = '\0'; + } + fclose(file); + } } - if ( tmp == NULL ) { - tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1); - if (!tmp) - return NULL; - strcpy(tmp, _XkbKnownLanguages); + if (tmp == NULL) { + tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1); + if (!tmp) + return NULL; + strcpy(tmp, _XkbKnownLanguages); } start = tmp; do { - if ( (set=strchr(tmp,'=')) == NULL ) - break; - *set++ = '\0'; - if ( (next=strchr(set,':')) != NULL ) - *next++ = '\0'; - while ( tmp && *tmp ) { - if ( (end=strchr(tmp,',')) != NULL ) - *end++ = '\0'; - if ( Strcmp( tmp, lang ) == 0 ) { - strncpy(buf,set,100); - buf[99] = '\0'; - Xfree(start); - return buf; - } - tmp = end; - } - tmp = next; - } while ( tmp && *tmp ); + if ((set = strchr(tmp, '=')) == NULL) + break; + *set++ = '\0'; + if ((next = strchr(set, ':')) != NULL) + *next++ = '\0'; + while (tmp && *tmp) { + if ((end = strchr(tmp, ',')) != NULL) + *end++ = '\0'; + if (Strcmp(tmp, lang) == 0) { + strncpy(buf, set, 100); + buf[99] = '\0'; + Xfree(start); + return buf; + } + tmp = end; + } + tmp = next; + } while (tmp && *tmp); Xfree(start); return NULL; } #else -char * +char * _XkbGetCharset(void) { char *tmp; XLCd lcd; - tmp = getenv( "_XKB_CHARSET" ); - if ( tmp ) - return tmp; + tmp = getenv("_XKB_CHARSET"); + if (tmp) + return tmp; lcd = _XlcCurrentLC(); - if ( lcd ) - return XLC_PUBLIC(lcd,encoding_name); + if (lcd) + return XLC_PUBLIC(lcd, encoding_name); return NULL; } #endif - diff --git a/libX11/src/xkb/XKBExtDev.c b/libX11/src/xkb/XKBExtDev.c index dd383bc10..4065dcd0e 100644 --- a/libX11/src/xkb/XKBExtDev.c +++ b/libX11/src/xkb/XKBExtDev.c @@ -37,68 +37,72 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ extern void -XkbNoteDeviceChanges( XkbDeviceChangesPtr old, - XkbExtensionDeviceNotifyEvent * new, - unsigned int wanted) +XkbNoteDeviceChanges(XkbDeviceChangesPtr old, + XkbExtensionDeviceNotifyEvent *new, + unsigned int wanted) { - if ((!old)||(!new)||(!wanted)||((new->reason&wanted)==0)) - return; - if ((wanted&new->reason)&XkbXI_ButtonActionsMask) { - if (old->changed&XkbXI_ButtonActionsMask) { - int first,last,newLast; - if (new->first_btn<old->first_btn) - first= new->first_btn; - else first= old->first_btn; - last= old->first_btn+old->num_btns-1; - newLast= new->first_btn+new->num_btns-1; - if (newLast>last) - last= newLast; - old->first_btn= first; - old->num_btns= (last-first)+1; - } - else { - old->changed|= XkbXI_ButtonActionsMask; - old->first_btn= new->first_btn; - old->num_btns= new->num_btns; - } + if ((!old) || (!new) || (!wanted) || ((new->reason & wanted) == 0)) + return; + if ((wanted & new->reason) & XkbXI_ButtonActionsMask) { + if (old->changed & XkbXI_ButtonActionsMask) { + int first, last, newLast; + + if (new->first_btn < old->first_btn) + first = new->first_btn; + else + first = old->first_btn; + last = old->first_btn + old->num_btns - 1; + newLast = new->first_btn + new->num_btns - 1; + if (newLast > last) + last = newLast; + old->first_btn = first; + old->num_btns = (last - first) + 1; + } + else { + old->changed |= XkbXI_ButtonActionsMask; + old->first_btn = new->first_btn; + old->num_btns = new->num_btns; + } } - if ((wanted&new->reason)&XkbXI_IndicatorsMask) { - XkbDeviceLedChangesPtr this; - if (old->changed&XkbXI_IndicatorsMask) { - XkbDeviceLedChangesPtr found; - found= NULL; - for (this= &old->leds;this&&(!found);this=this->next) { - if ((this->led_class==new->led_class)&& - (this->led_id==new->led_id)) { - found= this; - } - } - if (!found) { - found= _XkbTypedCalloc(1,XkbDeviceLedChangesRec); - if (!found) - return; - found->next= old->leds.next; - found->led_class= new->led_class; - found->led_id= new->led_id; - old->leds.next= found; - } - if ((wanted&new->reason)&XkbXI_IndicatorNamesMask) - found->defined= new->leds_defined; - } - else { - old->changed|= ((wanted&new->reason)&XkbXI_IndicatorsMask); - old->leds.led_class= new->led_class; - old->leds.led_id= new->led_id; - old->leds.defined= new->leds_defined; - if (old->leds.next) { - XkbDeviceLedChangesPtr next; - for (this=old->leds.next;this;this=next) { - next= this->next; - _XkbFree(this); - } - old->leds.next= NULL; - } - } + if ((wanted & new->reason) & XkbXI_IndicatorsMask) { + XkbDeviceLedChangesPtr this; + + if (old->changed & XkbXI_IndicatorsMask) { + XkbDeviceLedChangesPtr found = NULL; + + for (this = &old->leds; this && (!found); this = this->next) { + if ((this->led_class == new->led_class) && + (this->led_id == new->led_id)) { + found = this; + } + } + if (!found) { + found = _XkbTypedCalloc(1, XkbDeviceLedChangesRec); + if (!found) + return; + found->next = old->leds.next; + found->led_class = new->led_class; + found->led_id = new->led_id; + old->leds.next = found; + } + if ((wanted & new->reason) & XkbXI_IndicatorNamesMask) + found->defined = new->leds_defined; + } + else { + old->changed |= ((wanted & new->reason) & XkbXI_IndicatorsMask); + old->leds.led_class = new->led_class; + old->leds.led_id = new->led_id; + old->leds.defined = new->leds_defined; + if (old->leds.next) { + XkbDeviceLedChangesPtr next; + + for (this = old->leds.next; this; this = next) { + next = this->next; + _XkbFree(this); + } + old->leds.next = NULL; + } + } } return; } @@ -106,162 +110,168 @@ XkbNoteDeviceChanges( XkbDeviceChangesPtr old, /***====================================================================***/ static Status -_XkbReadDeviceLedInfo( XkbReadBufferPtr buf, - unsigned present, - XkbDeviceInfoPtr devi) +_XkbReadDeviceLedInfo(XkbReadBufferPtr buf, + unsigned present, + XkbDeviceInfoPtr devi) { -register unsigned i,bit; -XkbDeviceLedInfoPtr devli; -xkbDeviceLedsWireDesc * wireli; + register unsigned i, bit; + XkbDeviceLedInfoPtr devli; + xkbDeviceLedsWireDesc *wireli; - wireli= _XkbGetTypedRdBufPtr(buf,1,xkbDeviceLedsWireDesc); + wireli = _XkbGetTypedRdBufPtr(buf, 1, xkbDeviceLedsWireDesc); if (!wireli) - return BadLength; - devli= XkbAddDeviceLedInfo(devi,wireli->ledClass,wireli->ledID); + return BadLength; + devli = XkbAddDeviceLedInfo(devi, wireli->ledClass, wireli->ledID); if (!devli) - return BadAlloc; - devli->phys_indicators= wireli->physIndicators; - - if (present&XkbXI_IndicatorStateMask) - devli->state= wireli->state; - - if (present&XkbXI_IndicatorNamesMask) { - devli->names_present= wireli->namesPresent; - if (devli->names_present) { - for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { - if (wireli->namesPresent&bit) { - if (!_XkbCopyFromReadBuffer(buf,(char *)&devli->names[i],4)) - return BadLength; - } - } - } + return BadAlloc; + devli->phys_indicators = wireli->physIndicators; + + if (present & XkbXI_IndicatorStateMask) + devli->state = wireli->state; + + if (present & XkbXI_IndicatorNamesMask) { + devli->names_present = wireli->namesPresent; + if (devli->names_present) { + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + if (wireli->namesPresent & bit) { + if (!_XkbCopyFromReadBuffer(buf, + (char *) &devli->names[i], 4)) + return BadLength; + } + } + } } - if (present&XkbXI_IndicatorMapsMask) { - devli->maps_present= wireli->mapsPresent; - if (devli->maps_present) { - XkbIndicatorMapPtr im; - xkbIndicatorMapWireDesc * wireim; - for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { - if (wireli->mapsPresent&bit) { - wireim= _XkbGetTypedRdBufPtr(buf,1,xkbIndicatorMapWireDesc); - if (!wireim) - return BadAlloc; - im= &devli->maps[i]; - im->flags= wireim->flags; - im->which_groups= wireim->whichGroups; - im->groups= wireim->groups; - im->which_mods= wireim->whichMods; - im->mods.mask= wireim->mods; - im->mods.real_mods= wireim->realMods; - im->mods.vmods= wireim->virtualMods; - im->ctrls= wireim->ctrls; - } - } - } + if (present & XkbXI_IndicatorMapsMask) { + devli->maps_present = wireli->mapsPresent; + if (devli->maps_present) { + XkbIndicatorMapPtr im; + xkbIndicatorMapWireDesc *wireim; + + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + if (wireli->mapsPresent & bit) { + wireim = + _XkbGetTypedRdBufPtr(buf, 1, xkbIndicatorMapWireDesc); + if (!wireim) + return BadAlloc; + im = &devli->maps[i]; + im->flags = wireim->flags; + im->which_groups = wireim->whichGroups; + im->groups = wireim->groups; + im->which_mods = wireim->whichMods; + im->mods.mask = wireim->mods; + im->mods.real_mods = wireim->realMods; + im->mods.vmods = wireim->virtualMods; + im->ctrls = wireim->ctrls; + } + } + } } return Success; } static Status -_XkbReadGetDeviceInfoReply( Display * dpy, - xkbGetDeviceInfoReply * rep, - XkbDeviceInfoPtr devi) +_XkbReadGetDeviceInfoReply(Display *dpy, + xkbGetDeviceInfoReply *rep, + XkbDeviceInfoPtr devi) { -XkbReadBufferRec buf; -XkbAction * act; -int tmp; + XkbReadBufferRec buf; + XkbAction *act; + int tmp; - if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) - return BadAlloc; + if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4)) + return BadAlloc; - if ((rep->totalBtns>0)&&(rep->totalBtns!=devi->num_btns)) { - tmp= XkbResizeDeviceButtonActions(devi,rep->totalBtns); - if (tmp!=Success) - return tmp; + if ((rep->totalBtns > 0) && (rep->totalBtns != devi->num_btns)) { + tmp = XkbResizeDeviceButtonActions(devi, rep->totalBtns); + if (tmp != Success) + return tmp; } - if (rep->nBtnsWanted>0) { - if (((unsigned short) rep->firstBtnWanted + rep->nBtnsWanted) - >= devi->num_btns) - goto BAILOUT; - act= &devi->btn_acts[rep->firstBtnWanted]; - bzero((char *)act,(rep->nBtnsWanted*sizeof(XkbAction))); + if (rep->nBtnsWanted > 0) { + if (((unsigned short) rep->firstBtnWanted + rep->nBtnsWanted) + >= devi->num_btns) + goto BAILOUT; + act = &devi->btn_acts[rep->firstBtnWanted]; + bzero((char *) act, (rep->nBtnsWanted * sizeof(XkbAction))); } - if (devi->name!=NULL) - _XkbFree(devi->name); - if (!_XkbGetReadBufferCountedString(&buf,&devi->name)) - goto BAILOUT; - if (rep->nBtnsRtrn>0) { - int size; - if (((unsigned short) rep->firstBtnRtrn + rep->nBtnsRtrn) - >= devi->num_btns) - goto BAILOUT; - act= &devi->btn_acts[rep->firstBtnRtrn]; - size= rep->nBtnsRtrn*SIZEOF(xkbActionWireDesc); - if (!_XkbCopyFromReadBuffer(&buf,(char *)act,size)) - goto BAILOUT; + if (devi->name != NULL) + _XkbFree(devi->name); + if (!_XkbGetReadBufferCountedString(&buf, &devi->name)) + goto BAILOUT; + if (rep->nBtnsRtrn > 0) { + int size; + + if (((unsigned short) rep->firstBtnRtrn + rep->nBtnsRtrn) + >= devi->num_btns) + goto BAILOUT; + act = &devi->btn_acts[rep->firstBtnRtrn]; + size = rep->nBtnsRtrn * SIZEOF(xkbActionWireDesc); + if (!_XkbCopyFromReadBuffer(&buf, (char *) act, size)) + goto BAILOUT; } - if (rep->nDeviceLedFBs>0) { - register int i; - for (i=0;i<rep->nDeviceLedFBs;i++) { - if ((tmp= _XkbReadDeviceLedInfo(&buf,rep->present,devi))!=Success) - return tmp; - } + if (rep->nDeviceLedFBs > 0) { + register int i; + + for (i = 0; i < rep->nDeviceLedFBs; i++) { + if ((tmp = _XkbReadDeviceLedInfo(&buf, rep->present, devi)) + != Success) + return tmp; + } } - tmp= _XkbFreeReadBuffer(&buf); + tmp = _XkbFreeReadBuffer(&buf); if (tmp) - fprintf(stderr,"GetDeviceInfo! Bad length (%d extra bytes)\n",tmp); + fprintf(stderr, "GetDeviceInfo! Bad length (%d extra bytes)\n", tmp); if (tmp || buf.error) - return BadLength; + return BadLength; return Success; -BAILOUT: + BAILOUT: _XkbFreeReadBuffer(&buf); return BadLength; } XkbDeviceInfoPtr -XkbGetDeviceInfo( Display * dpy, - unsigned which, - unsigned deviceSpec, - unsigned class, - unsigned id) +XkbGetDeviceInfo(Display *dpy, + unsigned which, + unsigned deviceSpec, + unsigned class, + unsigned id) { - register xkbGetDeviceInfoReq * req; - xkbGetDeviceInfoReply rep; - Status status; - XkbDeviceInfoPtr devi; + register xkbGetDeviceInfoReq *req; + xkbGetDeviceInfoReply rep; + Status status; + XkbDeviceInfoPtr devi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return NULL; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return NULL; LockDisplay(dpy); GetReq(kbGetDeviceInfo, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetDeviceInfo; req->deviceSpec = deviceSpec; - req->wanted= which; - req->allBtns= ((which&XkbXI_ButtonActionsMask)!=0); - req->firstBtn= req->nBtns= 0; - req->ledClass= class; - req->ledID= id; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return NULL; + req->wanted = which; + req->allBtns = ((which & XkbXI_ButtonActionsMask) != 0); + req->firstBtn = req->nBtns = 0; + req->ledClass = class; + req->ledID = id; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; } - devi= XkbAllocDeviceInfo(rep.deviceID,rep.totalBtns,rep.nDeviceLedFBs); + devi = XkbAllocDeviceInfo(rep.deviceID, rep.totalBtns, rep.nDeviceLedFBs); if (devi) { - devi->supported= rep.supported; - devi->unsupported= rep.unsupported; - devi->type= rep.devType; - devi->has_own_state= rep.hasOwnState; - devi->dflt_kbd_fb = rep.dfltKbdFB; - devi->dflt_led_fb = rep.dfltLedFB; - status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); - if (status!=Success) { - XkbFreeDeviceInfo(devi,XkbXI_AllDeviceFeaturesMask,True); - devi= NULL; - } + devi->supported = rep.supported; + devi->unsupported = rep.unsupported; + devi->type = rep.devType; + devi->has_own_state = rep.hasOwnState; + devi->dflt_kbd_fb = rep.dfltKbdFB; + devi->dflt_led_fb = rep.dfltLedFB; + status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi); + if (status != Success) { + XkbFreeDeviceInfo(devi, XkbXI_AllDeviceFeaturesMask, True); + devi = NULL; + } } UnlockDisplay(dpy); SyncHandle(); @@ -269,59 +279,61 @@ XkbGetDeviceInfo( Display * dpy, } Status -XkbGetDeviceInfoChanges( Display * dpy, - XkbDeviceInfoPtr devi, - XkbDeviceChangesPtr changes) +XkbGetDeviceInfoChanges(Display *dpy, + XkbDeviceInfoPtr devi, + XkbDeviceChangesPtr changes) { - register xkbGetDeviceInfoReq * req; - xkbGetDeviceInfoReply rep; - Status status; + register xkbGetDeviceInfoReq *req; + xkbGetDeviceInfoReply rep; + Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadMatch; - if ((changes->changed&XkbXI_AllDeviceFeaturesMask)==0) - return Success; - changes->changed&= ~XkbXI_AllDeviceFeaturesMask; - status= Success; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadMatch; + if ((changes->changed & XkbXI_AllDeviceFeaturesMask) == 0) + return Success; + changes->changed &= ~XkbXI_AllDeviceFeaturesMask; + status = Success; LockDisplay(dpy); - while ((changes->changed)&&(status==Success)) { - GetReq(kbGetDeviceInfo, req); - req->reqType = dpy->xkb_info->codes->major_opcode; - req->xkbReqType = X_kbGetDeviceInfo; - req->deviceSpec = devi->device_spec; - req->wanted= changes->changed; - req->allBtns= False; - if (changes->changed&XkbXI_ButtonActionsMask) { - req->firstBtn= changes->first_btn; - req->nBtns= changes->num_btns; - changes->changed&= ~XkbXI_ButtonActionsMask; - } - else req->firstBtn= req->nBtns= 0; - if (changes->changed&XkbXI_IndicatorsMask) { - req->ledClass= changes->leds.led_class; - req->ledID= changes->leds.led_id; - if (changes->leds.next==NULL) - changes->changed&= ~XkbXI_IndicatorsMask; - else { - XkbDeviceLedChangesPtr next; - next= changes->leds.next; - changes->leds= *next; - _XkbFree(next); - } - } - else { - req->ledClass= XkbDfltXIClass; - req->ledID= XkbDfltXIId; - } - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - status= BadLength; - break; - } - devi->supported|= rep.supported; - devi->unsupported|= rep.unsupported; - devi->type= rep.devType; - status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); + while ((changes->changed) && (status == Success)) { + GetReq(kbGetDeviceInfo, req); + req->reqType = dpy->xkb_info->codes->major_opcode; + req->xkbReqType = X_kbGetDeviceInfo; + req->deviceSpec = devi->device_spec; + req->wanted = changes->changed; + req->allBtns = False; + if (changes->changed & XkbXI_ButtonActionsMask) { + req->firstBtn = changes->first_btn; + req->nBtns = changes->num_btns; + changes->changed &= ~XkbXI_ButtonActionsMask; + } + else + req->firstBtn = req->nBtns = 0; + if (changes->changed & XkbXI_IndicatorsMask) { + req->ledClass = changes->leds.led_class; + req->ledID = changes->leds.led_id; + if (changes->leds.next == NULL) + changes->changed &= ~XkbXI_IndicatorsMask; + else { + XkbDeviceLedChangesPtr next; + + next = changes->leds.next; + changes->leds = *next; + _XkbFree(next); + } + } + else { + req->ledClass = XkbDfltXIClass; + req->ledID = XkbDfltXIId; + } + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + status = BadLength; + break; + } + devi->supported |= rep.supported; + devi->unsupported |= rep.unsupported; + devi->type = rep.devType; + status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi); } UnlockDisplay(dpy); SyncHandle(); @@ -329,83 +341,84 @@ XkbGetDeviceInfoChanges( Display * dpy, } Status -XkbGetDeviceButtonActions( Display * dpy, - XkbDeviceInfoPtr devi, - Bool all, - unsigned int first, - unsigned int num) +XkbGetDeviceButtonActions(Display *dpy, + XkbDeviceInfoPtr devi, + Bool all, + unsigned int first, + unsigned int num) { - register xkbGetDeviceInfoReq * req; - xkbGetDeviceInfoReply rep; - Status status; + register xkbGetDeviceInfoReq *req; + xkbGetDeviceInfoReply rep; + Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadMatch; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadMatch; if (!devi) - return BadValue; + return BadValue; LockDisplay(dpy); GetReq(kbGetDeviceInfo, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetDeviceInfo; req->deviceSpec = devi->device_spec; - req->wanted= XkbXI_ButtonActionsMask; - req->allBtns= all; - req->firstBtn= first; - req->nBtns= num; - req->ledClass= XkbDfltXIClass; - req->ledID= XkbDfltXIId; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadLength; + req->wanted = XkbXI_ButtonActionsMask; + req->allBtns = all; + req->firstBtn = first; + req->nBtns = num; + req->ledClass = XkbDfltXIClass; + req->ledID = XkbDfltXIId; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadLength; } - devi->type= rep.devType; - devi->supported= rep.supported; - devi->unsupported= rep.unsupported; - status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); + devi->type = rep.devType; + devi->supported = rep.supported; + devi->unsupported = rep.unsupported; + status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi); UnlockDisplay(dpy); SyncHandle(); return status; } Status -XkbGetDeviceLedInfo( Display * dpy, - XkbDeviceInfoPtr devi, - unsigned int ledClass, - unsigned int ledId, - unsigned int which) +XkbGetDeviceLedInfo(Display *dpy, + XkbDeviceInfoPtr devi, + unsigned int ledClass, + unsigned int ledId, + unsigned int which) { - register xkbGetDeviceInfoReq * req; - xkbGetDeviceInfoReply rep; - Status status; + register xkbGetDeviceInfoReq *req; + xkbGetDeviceInfoReply rep; + Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadMatch; - if (((which&XkbXI_IndicatorsMask)==0)||(which&(~XkbXI_IndicatorsMask))) - return BadMatch; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadMatch; + if (((which & XkbXI_IndicatorsMask) == 0) || + (which & (~XkbXI_IndicatorsMask))) + return BadMatch; if (!devi) - return BadValue; + return BadValue; LockDisplay(dpy); GetReq(kbGetDeviceInfo, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetDeviceInfo; req->deviceSpec = devi->device_spec; - req->wanted= which; - req->allBtns= False; - req->firstBtn= req->nBtns= 0; - req->ledClass= ledClass; - req->ledID= ledId; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadLength; + req->wanted = which; + req->allBtns = False; + req->firstBtn = req->nBtns = 0; + req->ledClass = ledClass; + req->ledID = ledId; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadLength; } - devi->type= rep.devType; - devi->supported= rep.supported; - devi->unsupported= rep.unsupported; - status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); + devi->type = rep.devType; + devi->supported = rep.supported; + devi->unsupported = rep.unsupported; + status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi); UnlockDisplay(dpy); SyncHandle(); return status; @@ -414,297 +427,298 @@ XkbGetDeviceLedInfo( Display * dpy, /***====================================================================***/ typedef struct _LedInfoStuff { - Bool used; - XkbDeviceLedInfoPtr devli; + Bool used; + XkbDeviceLedInfoPtr devli; } LedInfoStuff; typedef struct _SetLedStuff { - unsigned wanted; - int num_info; - int dflt_class; - LedInfoStuff * dflt_kbd_fb; - LedInfoStuff * dflt_led_fb; - LedInfoStuff * info; + unsigned wanted; + int num_info; + int dflt_class; + LedInfoStuff *dflt_kbd_fb; + LedInfoStuff *dflt_led_fb; + LedInfoStuff *info; } SetLedStuff; static void -_InitLedStuff(SetLedStuff *stuff,unsigned wanted,XkbDeviceInfoPtr devi) +_InitLedStuff(SetLedStuff *stuff, unsigned wanted, XkbDeviceInfoPtr devi) { -int i; -register XkbDeviceLedInfoPtr devli; - - bzero(stuff,sizeof(SetLedStuff)); - stuff->wanted= wanted; - stuff->dflt_class= XkbXINone; - if ((devi->num_leds<1)||((wanted&XkbXI_IndicatorsMask)==0)) - return; - stuff->info= _XkbTypedCalloc(devi->num_leds,LedInfoStuff); + int i; + register XkbDeviceLedInfoPtr devli; + + bzero(stuff, sizeof(SetLedStuff)); + stuff->wanted = wanted; + stuff->dflt_class = XkbXINone; + if ((devi->num_leds < 1) || ((wanted & XkbXI_IndicatorsMask) == 0)) + return; + stuff->info = _XkbTypedCalloc(devi->num_leds, LedInfoStuff); if (!stuff->info) - return; - stuff->num_info= devi->num_leds; - for (devli=&devi->leds[0],i=0;i<devi->num_leds;i++,devli++) { - stuff->info[i].devli= devli; - if (devli->led_class==KbdFeedbackClass) { - stuff->dflt_class= KbdFeedbackClass; - if (stuff->dflt_kbd_fb==NULL) - stuff->dflt_kbd_fb= &stuff->info[i]; - } - else if (devli->led_class==LedFeedbackClass) { - if (stuff->dflt_class==XkbXINone) - stuff->dflt_class= LedFeedbackClass; - if (stuff->dflt_led_fb==NULL) - stuff->dflt_led_fb= &stuff->info[i]; - } + return; + stuff->num_info = devi->num_leds; + for (devli = &devi->leds[0], i = 0; i < devi->num_leds; i++, devli++) { + stuff->info[i].devli = devli; + if (devli->led_class == KbdFeedbackClass) { + stuff->dflt_class = KbdFeedbackClass; + if (stuff->dflt_kbd_fb == NULL) + stuff->dflt_kbd_fb = &stuff->info[i]; + } + else if (devli->led_class == LedFeedbackClass) { + if (stuff->dflt_class == XkbXINone) + stuff->dflt_class = LedFeedbackClass; + if (stuff->dflt_led_fb == NULL) + stuff->dflt_led_fb = &stuff->info[i]; + } } return; } static void -_FreeLedStuff(SetLedStuff *stuff) +_FreeLedStuff(SetLedStuff * stuff) { - if ((stuff->num_info>0)&&(stuff->info!=NULL)) - _XkbFree(stuff->info); - bzero(stuff,sizeof(SetLedStuff)); + if ((stuff->num_info > 0) && (stuff->info != NULL)) + _XkbFree(stuff->info); + bzero(stuff, sizeof(SetLedStuff)); return; } static int -_XkbSizeLedInfo(unsigned changed,XkbDeviceLedInfoPtr devli) +_XkbSizeLedInfo(unsigned changed, XkbDeviceLedInfoPtr devli) { -register int i,size; -register unsigned bit,namesNeeded,mapsNeeded; - - size= SIZEOF(xkbDeviceLedsWireDesc); - namesNeeded= mapsNeeded= 0; - if (changed&XkbXI_IndicatorNamesMask) - namesNeeded= devli->names_present; - if (changed&XkbXI_IndicatorMapsMask) - mapsNeeded= devli->maps_present; - if ((namesNeeded)||(mapsNeeded)) { - for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { - if (namesNeeded&bit) - size+= 4; /* atoms are 4 bytes on the wire */ - if (mapsNeeded&bit) - size+= SIZEOF(xkbIndicatorMapWireDesc); - } + register int i, size; + register unsigned bit, namesNeeded, mapsNeeded; + + size = SIZEOF(xkbDeviceLedsWireDesc); + namesNeeded = mapsNeeded = 0; + if (changed & XkbXI_IndicatorNamesMask) + namesNeeded = devli->names_present; + if (changed & XkbXI_IndicatorMapsMask) + mapsNeeded = devli->maps_present; + if ((namesNeeded) || (mapsNeeded)) { + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + if (namesNeeded & bit) + size += 4; /* atoms are 4 bytes on the wire */ + if (mapsNeeded & bit) + size += SIZEOF(xkbIndicatorMapWireDesc); + } } return size; } static Bool -_SizeMatches( SetLedStuff * stuff, - XkbDeviceLedChangesPtr changes, - int * sz_rtrn, - int * nleds_rtrn) +_SizeMatches(SetLedStuff *stuff, + XkbDeviceLedChangesPtr changes, + int *sz_rtrn, + int *nleds_rtrn) { -int i,nMatch,class,id; -LedInfoStuff * linfo; -Bool match; - - nMatch= 0; - class= changes->led_class; - id= changes->led_id; - if (class==XkbDfltXIClass) - class= stuff->dflt_class; - for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) { - XkbDeviceLedInfoPtr devli; - LedInfoStuff * dflt; - - devli= linfo->devli; - match= ((class==devli->led_class)||(class==XkbAllXIClasses)); - if (devli->led_class==KbdFeedbackClass) dflt= stuff->dflt_kbd_fb; - else dflt= stuff->dflt_led_fb; - match = (match && (id == devli->led_id)) || - (id == XkbAllXIIds) || - ((id == XkbDfltXIId) && - (linfo == dflt)); - if (match) { - if (!linfo->used) { - *sz_rtrn+= _XkbSizeLedInfo(stuff->wanted,devli); - *nleds_rtrn+= 1; - linfo->used= True; - if ((class!=XkbAllXIClasses)&&(id!=XkbAllXIIds)) - return True; - } - nMatch++; - linfo->used= True; - } + int i, nMatch, class, id; + LedInfoStuff *linfo; + Bool match; + + nMatch = 0; + class = changes->led_class; + id = changes->led_id; + if (class == XkbDfltXIClass) + class = stuff->dflt_class; + for (i = 0, linfo = &stuff->info[0]; i < stuff->num_info; i++, linfo++) { + XkbDeviceLedInfoPtr devli; + LedInfoStuff *dflt; + + devli = linfo->devli; + match = ((class == devli->led_class) || (class == XkbAllXIClasses)); + if (devli->led_class == KbdFeedbackClass) + dflt = stuff->dflt_kbd_fb; + else + dflt = stuff->dflt_led_fb; + match = (match && (id == devli->led_id)) || + (id == XkbAllXIIds) || + ((id == XkbDfltXIId) && (linfo == dflt)); + if (match) { + if (!linfo->used) { + *sz_rtrn += _XkbSizeLedInfo(stuff->wanted, devli); + *nleds_rtrn += 1; + linfo->used = True; + if ((class != XkbAllXIClasses) && (id != XkbAllXIIds)) + return True; + } + nMatch++; + linfo->used = True; + } } - return (nMatch>0); + return (nMatch > 0); } /***====================================================================***/ static Status -_XkbSetDeviceInfoSize( XkbDeviceInfoPtr devi, - XkbDeviceChangesPtr changes, - SetLedStuff * stuff, - int * sz_rtrn, - int * num_leds_rtrn) +_XkbSetDeviceInfoSize(XkbDeviceInfoPtr devi, + XkbDeviceChangesPtr changes, + SetLedStuff *stuff, + int *sz_rtrn, + int *num_leds_rtrn) { - *sz_rtrn= 0; - if ((changes->changed&XkbXI_ButtonActionsMask)&&(changes->num_btns>0)) { - if (!XkbXI_LegalDevBtn(devi,(changes->first_btn+changes->num_btns-1))) - return BadMatch; - *sz_rtrn+= changes->num_btns*SIZEOF(xkbActionWireDesc); + *sz_rtrn = 0; + if ((changes->changed & XkbXI_ButtonActionsMask) && (changes->num_btns > 0)) { + if (!XkbXI_LegalDevBtn + (devi, (changes->first_btn + changes->num_btns - 1))) + return BadMatch; + *sz_rtrn += changes->num_btns * SIZEOF(xkbActionWireDesc); } else { - changes->changed&= ~XkbXI_ButtonActionsMask; - changes->first_btn= changes->num_btns= 0; + changes->changed &= ~XkbXI_ButtonActionsMask; + changes->first_btn = changes->num_btns = 0; } - if ((changes->changed&XkbXI_IndicatorsMask)&& - XkbLegalXILedClass(changes->leds.led_class)) { - XkbDeviceLedChangesPtr leds; - - for (leds=&changes->leds;leds!=NULL;leds= leds->next) { - if (!_SizeMatches(stuff,leds,sz_rtrn,num_leds_rtrn)) - return BadMatch; - } + if ((changes->changed & XkbXI_IndicatorsMask) && + XkbLegalXILedClass(changes->leds.led_class)) { + XkbDeviceLedChangesPtr leds; + + for (leds = &changes->leds; leds != NULL; leds = leds->next) { + if (!_SizeMatches(stuff, leds, sz_rtrn, num_leds_rtrn)) + return BadMatch; + } } else { - changes->changed&= ~XkbXI_IndicatorsMask; - *num_leds_rtrn= 0; + changes->changed &= ~XkbXI_IndicatorsMask; + *num_leds_rtrn = 0; } return Success; } static char * -_XkbWriteLedInfo(char *wire,unsigned changed,XkbDeviceLedInfoPtr devli) +_XkbWriteLedInfo(char *wire, unsigned changed, XkbDeviceLedInfoPtr devli) { -register int i; -register unsigned bit,namesNeeded,mapsNeeded; -xkbDeviceLedsWireDesc * lwire; - - namesNeeded= mapsNeeded= 0; - if (changed&XkbXI_IndicatorNamesMask) - namesNeeded= devli->names_present; - if (changed&XkbXI_IndicatorMapsMask) - mapsNeeded= devli->maps_present; - - lwire= (xkbDeviceLedsWireDesc *)wire; - lwire->ledClass= devli->led_class; - lwire->ledID= devli->led_id; - lwire->namesPresent= namesNeeded; - lwire->mapsPresent= mapsNeeded; - lwire->physIndicators= devli->phys_indicators; - lwire->state= devli->state; - wire= (char *)&lwire[1]; + register int i; + register unsigned bit, namesNeeded, mapsNeeded; + xkbDeviceLedsWireDesc *lwire; + + namesNeeded = mapsNeeded = 0; + if (changed & XkbXI_IndicatorNamesMask) + namesNeeded = devli->names_present; + if (changed & XkbXI_IndicatorMapsMask) + mapsNeeded = devli->maps_present; + + lwire = (xkbDeviceLedsWireDesc *) wire; + lwire->ledClass = devli->led_class; + lwire->ledID = devli->led_id; + lwire->namesPresent = namesNeeded; + lwire->mapsPresent = mapsNeeded; + lwire->physIndicators = devli->phys_indicators; + lwire->state = devli->state; + wire = (char *) &lwire[1]; if (namesNeeded) { - CARD32 *awire; - awire= (CARD32 *)wire; - for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { - if (namesNeeded&bit) { - *awire= (CARD32)devli->names[i]; - awire++; - } - } - wire= (char *)awire; + CARD32 *awire = (CARD32 *) wire; + + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + if (namesNeeded & bit) { + *awire = (CARD32) devli->names[i]; + awire++; + } + } + wire = (char *) awire; } if (mapsNeeded) { - xkbIndicatorMapWireDesc *mwire; - - mwire= (xkbIndicatorMapWireDesc *)wire; - for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { - if (mapsNeeded&bit) { - XkbIndicatorMapPtr map; - map= &devli->maps[i]; - mwire->flags= map->flags; - mwire->whichGroups= map->which_groups; - mwire->groups= map->groups; - mwire->whichMods= map->which_mods; - mwire->mods= map->mods.mask; - mwire->realMods= map->mods.real_mods; - mwire->virtualMods= map->mods.vmods; - mwire->ctrls= map->ctrls; - mwire++; - } - } - wire= (char *)mwire; + xkbIndicatorMapWireDesc *mwire = (xkbIndicatorMapWireDesc *) wire; + + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + if (mapsNeeded & bit) { + XkbIndicatorMapPtr map = &devli->maps[i]; + + mwire->flags = map->flags; + mwire->whichGroups = map->which_groups; + mwire->groups = map->groups; + mwire->whichMods = map->which_mods; + mwire->mods = map->mods.mask; + mwire->realMods = map->mods.real_mods; + mwire->virtualMods = map->mods.vmods; + mwire->ctrls = map->ctrls; + mwire++; + } + } + wire = (char *) mwire; } return wire; } static int -_XkbWriteSetDeviceInfo( char * wire, - XkbDeviceChangesPtr changes, - SetLedStuff * stuff, - XkbDeviceInfoPtr devi) +_XkbWriteSetDeviceInfo(char *wire, + XkbDeviceChangesPtr changes, + SetLedStuff *stuff, + XkbDeviceInfoPtr devi) { -char *start; - - start= wire; - if (changes->changed&XkbXI_ButtonActionsMask) { - int size; - size= changes->num_btns*SIZEOF(xkbActionWireDesc); - memcpy(wire,(char *)&devi->btn_acts[changes->first_btn],size); - wire+= size; + char *start = wire; + + if (changes->changed & XkbXI_ButtonActionsMask) { + int size = changes->num_btns * SIZEOF(xkbActionWireDesc); + + memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], size); + wire += size; } - if (changes->changed&XkbXI_IndicatorsMask) { - register int i; - register LedInfoStuff *linfo; - - for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) { - if (linfo->used) { - register char *new_wire; - new_wire= _XkbWriteLedInfo(wire,stuff->wanted,linfo->devli); - if (!new_wire) - return wire-start; - wire= new_wire; - } - } + if (changes->changed & XkbXI_IndicatorsMask) { + register int i; + register LedInfoStuff *linfo; + + for (i = 0, linfo = &stuff->info[0]; i < stuff->num_info; i++, linfo++) { + if (linfo->used) { + register char *new_wire; + + new_wire = _XkbWriteLedInfo(wire, stuff->wanted, linfo->devli); + if (!new_wire) + return wire - start; + wire = new_wire; + } + } } - return wire-start; + return wire - start; } Bool -XkbSetDeviceInfo( Display * dpy, - unsigned which, - XkbDeviceInfoPtr devi) +XkbSetDeviceInfo(Display *dpy, unsigned which, XkbDeviceInfoPtr devi) { register xkbSetDeviceInfoReq *req; - Status ok = 0; - int size,nLeds; - XkbInfoPtr xkbi; - XkbDeviceChangesRec changes; - SetLedStuff lstuff; + Status ok = 0; + int size, nLeds; + XkbInfoPtr xkbi; + XkbDeviceChangesRec changes; + SetLedStuff lstuff; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!devi) || (which&(~XkbXI_AllDeviceFeaturesMask)) || - ((which&XkbXI_ButtonActionsMask)&&(!XkbXI_DevHasBtnActs(devi)))|| - ((which&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi)))) - return False; - - bzero((char *)&changes,sizeof(XkbDeviceChangesRec)); - changes.changed= which; - changes.first_btn= 0; - changes.num_btns= devi->num_btns; - changes.leds.led_class= XkbAllXIClasses; - changes.leds.led_id= XkbAllXIIds; - changes.leds.defined= 0; - size= nLeds= 0; - _InitLedStuff(&lstuff,changes.changed,devi); - if (_XkbSetDeviceInfoSize(devi,&changes,&lstuff,&size,&nLeds)!=Success) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!devi) || (which & (~XkbXI_AllDeviceFeaturesMask)) || + ((which & XkbXI_ButtonActionsMask) && (!XkbXI_DevHasBtnActs(devi))) || + ((which & XkbXI_IndicatorsMask) && (!XkbXI_DevHasLeds(devi)))) + return False; + + bzero((char *) &changes, sizeof(XkbDeviceChangesRec)); + changes.changed = which; + changes.first_btn = 0; + changes.num_btns = devi->num_btns; + changes.leds.led_class = XkbAllXIClasses; + changes.leds.led_id = XkbAllXIIds; + changes.leds.defined = 0; + size = nLeds = 0; + _InitLedStuff(&lstuff, changes.changed, devi); + if (_XkbSetDeviceInfoSize(devi, &changes, &lstuff, &size, &nLeds) != + Success) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetDeviceInfo, req); - req->length+= size/4; - req->reqType= xkbi->codes->major_opcode; - req->xkbReqType= X_kbSetDeviceInfo; - req->deviceSpec= devi->device_spec; - req->firstBtn= changes.first_btn; - req->nBtns= changes.num_btns; - req->change= changes.changed; - req->nDeviceLedFBs= nLeds; - if (size>0) { - char * wire; - BufAlloc(char *,wire,size); - ok= (wire!=NULL)&& - (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size); + req->length += size / 4; + req->reqType = xkbi->codes->major_opcode; + req->xkbReqType = X_kbSetDeviceInfo; + req->deviceSpec = devi->device_spec; + req->firstBtn = changes.first_btn; + req->nBtns = changes.num_btns; + req->change = changes.changed; + req->nDeviceLedFBs = nLeds; + if (size > 0) { + char *wire; + + BufAlloc(char *, wire, size); + ok = (wire != NULL) && + (_XkbWriteSetDeviceInfo(wire, &changes, &lstuff, devi) == size); } UnlockDisplay(dpy); SyncHandle(); @@ -714,45 +728,47 @@ XkbSetDeviceInfo( Display * dpy, } Bool -XkbChangeDeviceInfo( Display * dpy, - XkbDeviceInfoPtr devi, - XkbDeviceChangesPtr changes) +XkbChangeDeviceInfo(Display *dpy, + XkbDeviceInfoPtr devi, + XkbDeviceChangesPtr changes) { register xkbSetDeviceInfoReq *req; - Status ok = 0; - int size,nLeds; - XkbInfoPtr xkbi; - SetLedStuff lstuff; + Status ok = 0; + int size, nLeds; + XkbInfoPtr xkbi; + SetLedStuff lstuff; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!devi) || (changes->changed&(~XkbXI_AllDeviceFeaturesMask)) || - ((changes->changed&XkbXI_ButtonActionsMask)&& - (!XkbXI_DevHasBtnActs(devi)))|| - ((changes->changed&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi)))) - return False; - - size= nLeds= 0; - _InitLedStuff(&lstuff,changes->changed,devi); - if (_XkbSetDeviceInfoSize(devi,changes,&lstuff,&size,&nLeds)!=Success) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!devi) || (changes->changed & (~XkbXI_AllDeviceFeaturesMask)) || + ((changes->changed & XkbXI_ButtonActionsMask) && + (!XkbXI_DevHasBtnActs(devi))) || + ((changes->changed & XkbXI_IndicatorsMask) && + (!XkbXI_DevHasLeds(devi)))) + return False; + + size = nLeds = 0; + _InitLedStuff(&lstuff, changes->changed, devi); + if (_XkbSetDeviceInfoSize(devi, changes, &lstuff, &size, &nLeds) != Success) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetDeviceInfo, req); - req->length+= size/4; - req->reqType= xkbi->codes->major_opcode; - req->xkbReqType= X_kbSetDeviceInfo; - req->deviceSpec= devi->device_spec; - req->firstBtn= changes->first_btn; - req->nBtns= changes->num_btns; - req->change= changes->changed; - req->nDeviceLedFBs= nLeds; - if (size>0) { - char * wire; - BufAlloc(char *,wire,size); - ok= (wire!=NULL)&& - (_XkbWriteSetDeviceInfo(wire,changes,&lstuff,devi)==size); + req->length += size / 4; + req->reqType = xkbi->codes->major_opcode; + req->xkbReqType = X_kbSetDeviceInfo; + req->deviceSpec = devi->device_spec; + req->firstBtn = changes->first_btn; + req->nBtns = changes->num_btns; + req->change = changes->changed; + req->nDeviceLedFBs = nLeds; + if (size > 0) { + char *wire; + + BufAlloc(char *, wire, size); + ok = (wire != NULL) && + (_XkbWriteSetDeviceInfo(wire, changes, &lstuff, devi) == size); } UnlockDisplay(dpy); SyncHandle(); @@ -762,62 +778,64 @@ XkbChangeDeviceInfo( Display * dpy, } Bool -XkbSetDeviceLedInfo( Display * dpy, - XkbDeviceInfoPtr devi, - unsigned ledClass, - unsigned ledID, - unsigned which) +XkbSetDeviceLedInfo(Display *dpy, + XkbDeviceInfoPtr devi, + unsigned ledClass, + unsigned ledID, + unsigned which) { return False; } Bool -XkbSetDeviceButtonActions( Display * dpy, - XkbDeviceInfoPtr devi, - unsigned int first, - unsigned int nBtns) +XkbSetDeviceButtonActions(Display *dpy, + XkbDeviceInfoPtr devi, + unsigned int first, + unsigned int nBtns) { register xkbSetDeviceInfoReq *req; - Status ok = 0; - int size,nLeds; - XkbInfoPtr xkbi; - XkbDeviceChangesRec changes; - SetLedStuff lstuff; + Status ok = 0; + int size, nLeds; + XkbInfoPtr xkbi; + XkbDeviceChangesRec changes; + SetLedStuff lstuff; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!devi)||(!XkbXI_DevHasBtnActs(devi))||(first+nBtns>devi->num_btns)) - return False; - if (nBtns==0) - return True; - - bzero((char *)&changes,sizeof(XkbDeviceChangesRec)); - changes.changed= XkbXI_ButtonActionsMask; - changes.first_btn= first; - changes.num_btns= nBtns; - changes.leds.led_class= XkbXINone; - changes.leds.led_id= XkbXINone; - changes.leds.defined= 0; - size= nLeds= 0; - if (_XkbSetDeviceInfoSize(devi,&changes,NULL,&size,&nLeds)!=Success) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!devi) || (!XkbXI_DevHasBtnActs(devi)) || + (first + nBtns > devi->num_btns)) + return False; + if (nBtns == 0) + return True; + + bzero((char *) &changes, sizeof(XkbDeviceChangesRec)); + changes.changed = XkbXI_ButtonActionsMask; + changes.first_btn = first; + changes.num_btns = nBtns; + changes.leds.led_class = XkbXINone; + changes.leds.led_id = XkbXINone; + changes.leds.defined = 0; + size = nLeds = 0; + if (_XkbSetDeviceInfoSize(devi, &changes, NULL, &size, &nLeds) != Success) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetDeviceInfo, req); - req->length+= size/4; - req->reqType= xkbi->codes->major_opcode; - req->xkbReqType= X_kbSetDeviceInfo; - req->deviceSpec= devi->device_spec; - req->firstBtn= changes.first_btn; - req->nBtns= changes.num_btns; - req->change= changes.changed; - req->nDeviceLedFBs= nLeds; - if (size>0) { - char * wire; - BufAlloc(char *,wire,size); - ok= (wire!=NULL)&& - (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size); + req->length += size / 4; + req->reqType = xkbi->codes->major_opcode; + req->xkbReqType = X_kbSetDeviceInfo; + req->deviceSpec = devi->device_spec; + req->firstBtn = changes.first_btn; + req->nBtns = changes.num_btns; + req->change = changes.changed; + req->nDeviceLedFBs = nLeds; + if (size > 0) { + char *wire; + + BufAlloc(char *, wire, size); + ok = (wire != NULL) && + (_XkbWriteSetDeviceInfo(wire, &changes, &lstuff, devi) == size); } UnlockDisplay(dpy); SyncHandle(); diff --git a/libX11/src/xkb/XKBGAlloc.c b/libX11/src/xkb/XKBGAlloc.c index 1c90af1e8..ecac4f33c 100755 --- a/libX11/src/xkb/XKBGAlloc.c +++ b/libX11/src/xkb/XKBGAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -42,92 +40,94 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ 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; +_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; + 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 */ +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; +_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); + 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; + 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; - } + 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; + (*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; + i = ((*num_inout) - (first + count)) * elem_sz; + ptr = *elems; + memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i); + (*num_inout) -= count; } return; } @@ -137,44 +137,38 @@ register char *ptr; static void _XkbClearProperty(char *prop_in) { -XkbPropertyPtr prop= (XkbPropertyPtr)prop_in; + XkbPropertyPtr prop = (XkbPropertyPtr) prop_in; if (prop->name) { - _XkbFree(prop->name); - prop->name= NULL; + _XkbFree(prop->name); + prop->name = NULL; } if (prop->value) { - _XkbFree(prop->value); - prop->value= NULL; + _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); +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)); +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; } @@ -183,32 +177,32 @@ XkbFreeGeomKeyAliases( XkbGeometryPtr geom, static void _XkbClearColor(char *color_in) { -XkbColorPtr color= (XkbColorPtr)color_in; + XkbColorPtr color = (XkbColorPtr) color_in; if (color->spec) - _XkbFree(color->spec); + _XkbFree(color->spec); return; } void -XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll) +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); + _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) +XkbFreeGeomPoints(XkbOutlinePtr outline, int first, int count, Bool freeAll) { - _XkbFreeGeomLeafElems(freeAll,first,count, - &outline->num_points,&outline->sz_points, - (char **)&outline->points, - sizeof(XkbPointRec)); + _XkbFreeGeomLeafElems(freeAll, first, count, + &outline->num_points, &outline->sz_points, + (char **) &outline->points, + sizeof(XkbPointRec)); return; } @@ -217,20 +211,20 @@ XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll) static void _XkbClearOutline(char *outline_in) { -XkbOutlinePtr outline= (XkbOutlinePtr)outline_in; + XkbOutlinePtr outline = (XkbOutlinePtr) outline_in; - if (outline->points!=NULL) - XkbFreeGeomPoints(outline,0,outline->num_points,True); + if (outline->points != NULL) + XkbFreeGeomPoints(outline, 0, outline->num_points, True); return; } void -XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll) +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); + _XkbFreeGeomNonLeafElems(freeAll, first, count, + &shape->num_outlines, &shape->sz_outlines, + (char **) &shape->outlines, + sizeof(XkbOutlineRec), _XkbClearOutline); return; } @@ -240,32 +234,32 @@ XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll) static void _XkbClearShape(char *shape_in) { -XkbShapePtr shape= (XkbShapePtr)shape_in; + XkbShapePtr shape = (XkbShapePtr) shape_in; if (shape->outlines) - XkbFreeGeomOutlines(shape,0,shape->num_outlines,True); + XkbFreeGeomOutlines(shape, 0, shape->num_outlines, True); return; } void -XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll) +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); + _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) +XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row, int first, int count, Bool freeAll) { - _XkbFreeGeomLeafElems(freeAll,first,count, - &row->num_keys,&row->sz_keys, - (char **)&row->keys, - sizeof(XkbOverlayKeyRec)); + _XkbFreeGeomLeafElems(freeAll, first, count, + &row->num_keys, &row->sz_keys, + (char **) &row->keys, + sizeof(XkbOverlayKeyRec)); return; } @@ -274,20 +268,21 @@ XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll) static void _XkbClearOverlayRow(char *row_in) { -XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in; + XkbOverlayRowPtr row = (XkbOverlayRowPtr) row_in; - if (row->keys!=NULL) - XkbFreeGeomOverlayKeys(row,0,row->num_keys,True); + if (row->keys != NULL) + XkbFreeGeomOverlayKeys(row, 0, row->num_keys, True); return; } void -XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll) +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); + _XkbFreeGeomNonLeafElems(freeAll, first, count, + &overlay->num_rows, &overlay->sz_rows, + (char **) &overlay->rows, + sizeof(XkbOverlayRowRec), _XkbClearOverlayRow); return; } @@ -296,32 +291,32 @@ XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll) static void _XkbClearOverlay(char *overlay_in) { -XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in; + XkbOverlayPtr overlay = (XkbOverlayPtr) overlay_in; - if (overlay->rows!=NULL) - XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True); + if (overlay->rows != NULL) + XkbFreeGeomOverlayRows(overlay, 0, overlay->num_rows, True); return; } void -XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll) +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); + _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) +XkbFreeGeomKeys(XkbRowPtr row, int first, int count, Bool freeAll) { - _XkbFreeGeomLeafElems(freeAll,first,count, - &row->num_keys,&row->sz_keys, - (char **)&row->keys, - sizeof(XkbKeyRec)); + _XkbFreeGeomLeafElems(freeAll, first, count, + &row->num_keys, &row->sz_keys, + (char **) &row->keys, + sizeof(XkbKeyRec)); return; } @@ -330,20 +325,20 @@ XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll) static void _XkbClearRow(char *row_in) { -XkbRowPtr row= (XkbRowPtr)row_in; + XkbRowPtr row = (XkbRowPtr) row_in; - if (row->keys!=NULL) - XkbFreeGeomKeys(row,0,row->num_keys,True); + if (row->keys != NULL) + XkbFreeGeomKeys(row, 0, row->num_keys, True); return; } void -XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll) +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); + _XkbFreeGeomNonLeafElems(freeAll, first, count, + §ion->num_rows, §ion->sz_rows, + (char **) §ion->rows, + sizeof(XkbRowRec), _XkbClearRow); } /***====================================================================***/ @@ -351,24 +346,24 @@ XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll) static void _XkbClearSection(char *section_in) { -XkbSectionPtr section= (XkbSectionPtr)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; + 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) +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); + _XkbFreeGeomNonLeafElems(freeAll, first, count, + &geom->num_sections, &geom->sz_sections, + (char **) &geom->sections, + sizeof(XkbSectionRec), _XkbClearSection); return; } @@ -377,77 +372,77 @@ XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll) static void _XkbClearDoodad(char *doodad_in) { -XkbDoodadPtr doodad= (XkbDoodadPtr)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; + 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) +XkbFreeGeomDoodads(XkbDoodadPtr doodads, int nDoodads, Bool freeAll) { -register int i; -register XkbDoodadPtr doodad; + register int i; + register XkbDoodadPtr doodad; if (doodads) { - for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) { - _XkbClearDoodad((char *)doodad); - } - if (freeAll) - _XkbFree(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) +XkbFreeGeometry(XkbGeometryPtr geom, unsigned which, Bool freeMap) { - if (geom==NULL) - return; + 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); + 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); + if (geom->label_font != NULL) { + _XkbFree(geom->label_font); + geom->label_font = NULL; + } + _XkbFree(geom); } return; } @@ -455,336 +450,339 @@ XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap) /***====================================================================***/ 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)); +_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)) +#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) +XkbAllocGeomProps(XkbGeometryPtr geom, int nProps) { - return _XkbAllocProps(geom,nProps); + return _XkbAllocProps(geom, nProps); } Status -XkbAllocGeomColors(XkbGeometryPtr geom,int nColors) +XkbAllocGeomColors(XkbGeometryPtr geom, int nColors) { - return _XkbAllocColors(geom,nColors); + return _XkbAllocColors(geom, nColors); } Status -XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases) +XkbAllocGeomKeyAliases(XkbGeometryPtr geom, int nKeyAliases) { - return _XkbAllocKeyAliases(geom,nKeyAliases); + return _XkbAllocKeyAliases(geom, nKeyAliases); } Status -XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes) +XkbAllocGeomShapes(XkbGeometryPtr geom, int nShapes) { - return _XkbAllocShapes(geom,nShapes); + return _XkbAllocShapes(geom, nShapes); } Status -XkbAllocGeomSections(XkbGeometryPtr geom,int nSections) +XkbAllocGeomSections(XkbGeometryPtr geom, int nSections) { - return _XkbAllocSections(geom,nSections); + return _XkbAllocSections(geom, nSections); } Status -XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays) +XkbAllocGeomOverlays(XkbSectionPtr section, int nOverlays) { - return _XkbAllocOverlays(section,nOverlays); + return _XkbAllocOverlays(section, nOverlays); } Status -XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows) +XkbAllocGeomOverlayRows(XkbOverlayPtr overlay, int nRows) { - return _XkbAllocOverlayRows(overlay,nRows); + return _XkbAllocOverlayRows(overlay, nRows); } Status -XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys) +XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row, int nKeys) { - return _XkbAllocOverlayKeys(row,nKeys); + return _XkbAllocOverlayKeys(row, nKeys); } Status -XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads) +XkbAllocGeomDoodads(XkbGeometryPtr geom, int nDoodads) { - return _XkbAllocDoodads(geom,nDoodads); + return _XkbAllocDoodads(geom, nDoodads); } Status -XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads) +XkbAllocGeomSectionDoodads(XkbSectionPtr section, int nDoodads) { - return _XkbAllocDoodads(section,nDoodads); + return _XkbAllocDoodads(section, nDoodads); } Status -XkbAllocGeomOutlines(XkbShapePtr shape,int nOL) +XkbAllocGeomOutlines(XkbShapePtr shape, int nOL) { - return _XkbAllocOutlines(shape,nOL); + return _XkbAllocOutlines(shape, nOL); } Status -XkbAllocGeomRows(XkbSectionPtr section,int nRows) +XkbAllocGeomRows(XkbSectionPtr section, int nRows) { - return _XkbAllocRows(section,nRows); + return _XkbAllocRows(section, nRows); } Status -XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts) +XkbAllocGeomPoints(XkbOutlinePtr ol, int nPts) { - return _XkbAllocPoints(ol,nPts); + return _XkbAllocPoints(ol, nPts); } Status -XkbAllocGeomKeys(XkbRowPtr row,int nKeys) +XkbAllocGeomKeys(XkbRowPtr row, int nKeys) { - return _XkbAllocKeys(row,nKeys); + return _XkbAllocKeys(row, nKeys); } Status -XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes) +XkbAllocGeometry(XkbDescPtr xkb, XkbGeometrySizesPtr sizes) { -XkbGeometryPtr geom; -Status rtrn; + XkbGeometryPtr geom; + Status rtrn; - if (xkb->geom==NULL) { - xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec); - if (!xkb->geom) - return BadAlloc; + 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; + 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 & 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 & 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 & 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 & XkbGeomDoodadsMask) && + ((rtrn = _XkbAllocDoodads(geom, sizes->num_doodads)) != Success)) { + goto BAIL; } - if ((sizes->which&XkbGeomKeyAliasesMask)&& - ((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=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; + 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); +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); + return NULL; + prop->value = strdup(value); if (!prop->value) { - _XkbFree(prop->name); - prop->name= NULL; - return NULL; + _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); +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); +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; + return NULL; geom->num_colors++; return color; } XkbOutlinePtr -XkbAddGeomOutline(XkbShapePtr shape,int sz_points) +XkbAddGeomOutline(XkbShapePtr shape, int sz_points) { -XkbOutlinePtr outline; + XkbOutlinePtr outline; - if ((!shape)||(sz_points<0)) - return NULL; - if ((shape->num_outlines>=shape->sz_outlines)&& - (_XkbAllocOutlines(shape,1)!=Success)) { - return NULL; + 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; + 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; +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; } @@ -792,203 +790,209 @@ register int i; XkbKeyPtr XkbAddGeomKey(XkbRowPtr row) { -XkbKeyPtr key; + 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 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; +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; +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) +XkbAddGeomDoodad(XkbGeometryPtr geom, XkbSectionPtr section, Atom name) { -XkbDoodadPtr old,doodad; -register int i,nDoodads; + 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; + 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; + old = geom->doodads; + nDoodads = geom->num_doodads; } - for (i=0,doodad=old;i<nDoodads;i++,doodad++) { - if (doodad->any.name==name) - return doodad; + 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++]; + 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++]; + 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; + 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; - } +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); + 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; +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; +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/xkb/XKBGeom.c b/libX11/src/xkb/XKBGeom.c index 1116bc67f..c3fd27f15 100644 --- a/libX11/src/xkb/XKBGeom.c +++ b/libX11/src/xkb/XKBGeom.c @@ -43,149 +43,160 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ static void -_XkbCheckBounds(XkbBoundsPtr bounds,int x,int y) +_XkbCheckBounds(XkbBoundsPtr bounds, int x, int y) { - if (x<bounds->x1) bounds->x1= x; - if (x>bounds->x2) bounds->x2= x; - if (y<bounds->y1) bounds->y1= y; - if (y>bounds->y2) bounds->y2= y; + if (x < bounds->x1) + bounds->x1 = x; + if (x > bounds->x2) + bounds->x2 = x; + if (y < bounds->y1) + bounds->y1 = y; + if (y > bounds->y2) + bounds->y2 = y; return; } Bool XkbComputeShapeBounds(XkbShapePtr shape) { -register int o,p; -XkbOutlinePtr outline; -XkbPointPtr pt; - - if ((!shape)||(shape->num_outlines<1)) - return False; - shape->bounds.x1= shape->bounds.y1= MAXSHORT; - shape->bounds.x2= shape->bounds.y2= MINSHORT; - for (outline=shape->outlines,o=0;o<shape->num_outlines;o++,outline++) { - for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) { - _XkbCheckBounds(&shape->bounds,pt->x,pt->y); - } - if (outline->num_points<2) { - _XkbCheckBounds(&shape->bounds,0,0); + register int o, p; + XkbOutlinePtr outline; + XkbPointPtr pt; + + if ((!shape) || (shape->num_outlines < 1)) + return False; + shape->bounds.x1 = shape->bounds.y1 = MAXSHORT; + shape->bounds.x2 = shape->bounds.y2 = MINSHORT; + for (outline = shape->outlines, o = 0; o < shape->num_outlines; + o++, outline++) { + for (pt = outline->points, p = 0; p < outline->num_points; p++, pt++) { + _XkbCheckBounds(&shape->bounds, pt->x, pt->y); + } + if (outline->num_points < 2) { + _XkbCheckBounds(&shape->bounds, 0, 0); } } return True; } Bool -XkbComputeShapeTop(XkbShapePtr shape,XkbBoundsPtr bounds) +XkbComputeShapeTop(XkbShapePtr shape, XkbBoundsPtr bounds) { -register int p; -XkbOutlinePtr outline; -XkbPointPtr pt; - - if ((!shape)||(shape->num_outlines<1)) - return False; - if (shape->approx) outline= shape->approx; - else outline= &shape->outlines[shape->num_outlines-1]; - if (outline->num_points<2) { - bounds->x1= bounds->y1= 0; - bounds->x2= bounds->y2= 0; + register int p; + XkbOutlinePtr outline; + XkbPointPtr pt; + + if ((!shape) || (shape->num_outlines < 1)) + return False; + if (shape->approx) + outline = shape->approx; + else + outline = &shape->outlines[shape->num_outlines - 1]; + if (outline->num_points < 2) { + bounds->x1 = bounds->y1 = 0; + bounds->x2 = bounds->y2 = 0; } else { - bounds->x1= bounds->y1= MAXSHORT; - bounds->x2= bounds->y2= MINSHORT; + bounds->x1 = bounds->y1 = MAXSHORT; + bounds->x2 = bounds->y2 = MINSHORT; } - for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) { - _XkbCheckBounds(bounds,pt->x,pt->y); + for (pt = outline->points, p = 0; p < outline->num_points; p++, pt++) { + _XkbCheckBounds(bounds, pt->x, pt->y); } return True; } Bool -XkbComputeRowBounds(XkbGeometryPtr geom,XkbSectionPtr section,XkbRowPtr row) +XkbComputeRowBounds(XkbGeometryPtr geom, XkbSectionPtr section, XkbRowPtr row) { -register int k,pos; -XkbKeyPtr key; -XkbBoundsPtr bounds,sbounds; - - if ((!geom)||(!section)||(!row)) - return False; - bounds= &row->bounds; - bzero(bounds,sizeof(XkbBoundsRec)); - for (key=row->keys,pos=k=0;k<row->num_keys;k++,key++) { - sbounds= &XkbKeyShape(geom,key)->bounds; - _XkbCheckBounds(bounds,pos,0); - if (!row->vertical) { - if (key->gap!=0) { - pos+= key->gap; - _XkbCheckBounds(bounds,pos,0); - } - _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1); - _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2); - pos+= sbounds->x2; - } - else { - if (key->gap!=0) { - pos+= key->gap; - _XkbCheckBounds(bounds,0,pos); - } - _XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1); - _XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2); - pos+= sbounds->y2; - } + register int k, pos; + XkbKeyPtr key; + XkbBoundsPtr bounds, sbounds; + + if ((!geom) || (!section) || (!row)) + return False; + bounds = &row->bounds; + bzero(bounds, sizeof(XkbBoundsRec)); + for (key = row->keys, pos = k = 0; k < row->num_keys; k++, key++) { + sbounds = &XkbKeyShape(geom, key)->bounds; + _XkbCheckBounds(bounds, pos, 0); + if (!row->vertical) { + if (key->gap != 0) { + pos += key->gap; + _XkbCheckBounds(bounds, pos, 0); + } + _XkbCheckBounds(bounds, pos + sbounds->x1, sbounds->y1); + _XkbCheckBounds(bounds, pos + sbounds->x2, sbounds->y2); + pos += sbounds->x2; + } + else { + if (key->gap != 0) { + pos += key->gap; + _XkbCheckBounds(bounds, 0, pos); + } + _XkbCheckBounds(bounds, pos + sbounds->x1, sbounds->y1); + _XkbCheckBounds(bounds, pos + sbounds->x2, sbounds->y2); + pos += sbounds->y2; + } } return True; } Bool -XkbComputeSectionBounds(XkbGeometryPtr geom,XkbSectionPtr section) +XkbComputeSectionBounds(XkbGeometryPtr geom, XkbSectionPtr section) { -register int i; -XkbShapePtr shape; -XkbRowPtr row; -XkbDoodadPtr doodad; -XkbBoundsPtr bounds,rbounds; - - if ((!geom)||(!section)) - return False; - bounds= §ion->bounds; - bzero(bounds,sizeof(XkbBoundsRec)); - for (i=0,row=section->rows;i<section->num_rows;i++,row++) { - if (!XkbComputeRowBounds(geom,section,row)) - return False; - rbounds= &row->bounds; - _XkbCheckBounds(bounds,row->left+rbounds->x1,row->top+rbounds->y1); - _XkbCheckBounds(bounds,row->left+rbounds->x2,row->top+rbounds->y2); + register int i; + XkbShapePtr shape; + XkbRowPtr row; + XkbDoodadPtr doodad; + XkbBoundsPtr bounds, rbounds; + + if ((!geom) || (!section)) + return False; + bounds = §ion->bounds; + bzero(bounds, sizeof(XkbBoundsRec)); + for (i = 0, row = section->rows; i < section->num_rows; i++, row++) { + if (!XkbComputeRowBounds(geom, section, row)) + return False; + rbounds = &row->bounds; + _XkbCheckBounds(bounds, row->left + rbounds->x1, + row->top + rbounds->y1); + _XkbCheckBounds(bounds, row->left + rbounds->x2, + row->top + rbounds->y2); } - for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) { - static XkbBoundsRec tbounds; - switch (doodad->any.type) { - case XkbOutlineDoodad: - case XkbSolidDoodad: - shape= XkbShapeDoodadShape(geom,&doodad->shape); - rbounds= &shape->bounds; - break; - case XkbTextDoodad: - tbounds.x1= doodad->text.left; - tbounds.y1= doodad->text.top; - tbounds.x2= tbounds.x1+doodad->text.width; - tbounds.y2= tbounds.y1+doodad->text.height; - rbounds= &tbounds; - break; - case XkbIndicatorDoodad: - shape= XkbIndicatorDoodadShape(geom,&doodad->indicator); - rbounds= &shape->bounds; - break; - case XkbLogoDoodad: - shape= XkbLogoDoodadShape(geom,&doodad->logo); - rbounds= &shape->bounds; - break; - default: - tbounds.x1= tbounds.x2= doodad->any.left; - tbounds.y1= tbounds.y2= doodad->any.top; - rbounds= &tbounds; - break; - } - _XkbCheckBounds(bounds,rbounds->x1,rbounds->y1); - _XkbCheckBounds(bounds,rbounds->x2,rbounds->y2); + for (i = 0, doodad = section->doodads; i < section->num_doodads; + i++, doodad++) { + static XkbBoundsRec tbounds; + + switch (doodad->any.type) { + case XkbOutlineDoodad: + case XkbSolidDoodad: + shape = XkbShapeDoodadShape(geom, &doodad->shape); + rbounds = &shape->bounds; + break; + case XkbTextDoodad: + tbounds.x1 = doodad->text.left; + tbounds.y1 = doodad->text.top; + tbounds.x2 = tbounds.x1 + doodad->text.width; + tbounds.y2 = tbounds.y1 + doodad->text.height; + rbounds = &tbounds; + break; + case XkbIndicatorDoodad: + shape = XkbIndicatorDoodadShape(geom, &doodad->indicator); + rbounds = &shape->bounds; + break; + case XkbLogoDoodad: + shape = XkbLogoDoodadShape(geom, &doodad->logo); + rbounds = &shape->bounds; + break; + default: + tbounds.x1 = tbounds.x2 = doodad->any.left; + tbounds.y1 = tbounds.y2 = doodad->any.top; + rbounds = &tbounds; + break; + } + _XkbCheckBounds(bounds, rbounds->x1, rbounds->y1); + _XkbCheckBounds(bounds, rbounds->x2, rbounds->y2); } return True; } @@ -193,39 +204,42 @@ XkbBoundsPtr bounds,rbounds; /***====================================================================***/ char * -XkbFindOverlayForKey(XkbGeometryPtr geom,XkbSectionPtr wanted,char *under) +XkbFindOverlayForKey(XkbGeometryPtr geom, XkbSectionPtr wanted, char *under) { -int s; -XkbSectionPtr section; + int s; + XkbSectionPtr section; - if ((geom==NULL)||(under==NULL)||(geom->num_sections<1)) - return NULL; + if ((geom == NULL) || (under == NULL) || (geom->num_sections < 1)) + return NULL; if (wanted) - section= wanted; - else section= geom->sections; - - for (s=0;s<geom->num_sections;s++,section++) { - XkbOverlayPtr ol; - int o; - - if (section->num_overlays<1) - continue; - for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) { - XkbOverlayRowPtr row; - int r; - - for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) { - XkbOverlayKeyPtr key; - int k; - for (k=0,key=row->keys;k<row->num_keys;k++,key++) { - if (strncmp(under,key->under.name,XkbKeyNameLength)==0) - return key->over.name; - } - } - } - if (wanted!=NULL) - break; + section = wanted; + else + section = geom->sections; + + for (s = 0; s < geom->num_sections; s++, section++) { + XkbOverlayPtr ol; + int o; + + if (section->num_overlays < 1) + continue; + for (o = 0, ol = section->overlays; o < section->num_overlays; + o++, ol++) { + XkbOverlayRowPtr row; + int r; + + for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) { + XkbOverlayKeyPtr key; + int k; + + for (k = 0, key = row->keys; k < row->num_keys; k++, key++) { + if (strncmp(under, key->under.name, XkbKeyNameLength) == 0) + return key->over.name; + } + } + } + if (wanted != NULL) + break; } return NULL; } @@ -233,463 +247,475 @@ XkbSectionPtr section; /***====================================================================***/ static Status -_XkbReadGeomProperties( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - xkbGetGeometryReply * rep) +_XkbReadGeomProperties(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + xkbGetGeometryReply *rep) { -Status rtrn; - - if (rep->nProperties<1) - return Success; - if ((rtrn=XkbAllocGeomProps(geom,rep->nProperties))==Success) { - register int i; - register Bool ok; - char *name,*value; - ok= True; - for (i=0;(i<rep->nProperties)&&ok;i++) { - name=NULL; - value=NULL; - ok= _XkbGetReadBufferCountedString(buf,&name)&&ok; - ok= _XkbGetReadBufferCountedString(buf,&value)&&ok; - ok= ok&&(XkbAddGeomProperty(geom,name,value)!=NULL); - if (name) - _XkbFree(name); - if (value) - _XkbFree(value); - } - if (ok) rtrn= Success; - else rtrn= BadLength; + Status rtrn; + + if (rep->nProperties < 1) + return Success; + if ((rtrn = XkbAllocGeomProps(geom, rep->nProperties)) == Success) { + register int i; + register Bool ok = True; + + for (i = 0; (i < rep->nProperties) && ok; i++) { + char *name = NULL; + char *value = NULL; + ok = _XkbGetReadBufferCountedString(buf, &name) && ok; + ok = _XkbGetReadBufferCountedString(buf, &value) && ok; + ok = ok && (XkbAddGeomProperty(geom, name, value) != NULL); + if (name) + _XkbFree(name); + if (value) + _XkbFree(value); + } + if (ok) + rtrn = Success; + else + rtrn = BadLength; } return rtrn; } static Status -_XkbReadGeomKeyAliases( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - xkbGetGeometryReply * rep) +_XkbReadGeomKeyAliases(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + xkbGetGeometryReply *rep) { -Status rtrn; - - if (rep->nKeyAliases<1) - return Success; - if ((rtrn=XkbAllocGeomKeyAliases(geom,rep->nKeyAliases))==Success) { - if (!_XkbCopyFromReadBuffer(buf,(char *)geom->key_aliases, - (rep->nKeyAliases*XkbKeyNameLength*2))) - return BadLength; - geom->num_key_aliases= rep->nKeyAliases; - return Success; + Status rtrn; + + if (rep->nKeyAliases < 1) + return Success; + if ((rtrn = XkbAllocGeomKeyAliases(geom, rep->nKeyAliases)) == Success) { + if (!_XkbCopyFromReadBuffer(buf, (char *) geom->key_aliases, + (rep->nKeyAliases * XkbKeyNameLength * 2))) + return BadLength; + geom->num_key_aliases = rep->nKeyAliases; + return Success; } - else { /* alloc failed, just skip the aliases */ - _XkbSkipReadBufferData(buf,(rep->nKeyAliases*XkbKeyNameLength*2)); + else { /* alloc failed, just skip the aliases */ + _XkbSkipReadBufferData(buf, (rep->nKeyAliases * XkbKeyNameLength * 2)); } return rtrn; } static Status -_XkbReadGeomColors( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - xkbGetGeometryReply * rep) +_XkbReadGeomColors(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + xkbGetGeometryReply *rep) { -Status rtrn; - - if (rep->nColors<1) - return Success; - if ((rtrn=XkbAllocGeomColors(geom,rep->nColors))==Success) { - register int i; - char *spec; - for (i=0;i<rep->nColors;i++) { - spec = NULL; - if (!_XkbGetReadBufferCountedString(buf,&spec)) - rtrn = BadLength; - else if (XkbAddGeomColor(geom,spec,geom->num_colors)==NULL) - rtrn = BadAlloc; - if (spec) - _XkbFree(spec); - if (rtrn != Success) - return rtrn; - } - return Success; + Status rtrn; + + if (rep->nColors < 1) + return Success; + if ((rtrn = XkbAllocGeomColors(geom, rep->nColors)) == Success) { + register int i; + + for (i = 0; i < rep->nColors; i++) { + char *spec = NULL; + if (!_XkbGetReadBufferCountedString(buf, &spec)) + rtrn = BadLength; + else if (XkbAddGeomColor(geom, spec, geom->num_colors) == NULL) + rtrn = BadAlloc; + if (spec) + _XkbFree(spec); + if (rtrn != Success) + return rtrn; + } + return Success; } return rtrn; } static Status -_XkbReadGeomShapes( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - xkbGetGeometryReply * rep) +_XkbReadGeomShapes(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + xkbGetGeometryReply *rep) { -register int i; -Status rtrn; - - if (rep->nShapes<1) - return Success; - if ((rtrn=XkbAllocGeomShapes(geom,rep->nShapes))!=Success) - return rtrn; - for (i=0;i<rep->nShapes;i++) { - xkbShapeWireDesc *shapeWire; - XkbShapePtr shape; - register int o; - shapeWire= (xkbShapeWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbShapeWireDesc)); - if (!shapeWire) - return BadLength; - shape= XkbAddGeomShape(geom,shapeWire->name,shapeWire->nOutlines); - if (!shape) - return BadAlloc; - for (o=0;o<shapeWire->nOutlines;o++) { - xkbOutlineWireDesc *olWire; - XkbOutlinePtr ol; - register int p; - XkbPointPtr pt; - olWire= (xkbOutlineWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbOutlineWireDesc)); - if (!olWire) - return BadLength; - ol= XkbAddGeomOutline(shape,olWire->nPoints); - if (!ol) - return BadAlloc; - ol->corner_radius= olWire->cornerRadius; - for (p=0,pt=ol->points;p<olWire->nPoints;p++,pt++) { - xkbPointWireDesc * ptWire; - ptWire= (xkbPointWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbPointWireDesc)); - if (!ptWire) - return BadLength; - pt->x= ptWire->x; - pt->y= ptWire->y; - } - ol->num_points= olWire->nPoints; - } - if ((shapeWire->primaryNdx!=XkbNoShape) && - (shapeWire->primaryNdx < shapeWire->nOutlines)) - shape->primary= &shape->outlines[shapeWire->primaryNdx]; - else - shape->primary= NULL; - if ((shapeWire->approxNdx!=XkbNoShape) && - (shapeWire->approxNdx < shapeWire->nOutlines)) - shape->approx= &shape->outlines[shapeWire->approxNdx]; - else - shape->approx= NULL; - XkbComputeShapeBounds(shape); + register int i; + Status rtrn; + + if (rep->nShapes < 1) + return Success; + if ((rtrn = XkbAllocGeomShapes(geom, rep->nShapes)) != Success) + return rtrn; + for (i = 0; i < rep->nShapes; i++) { + xkbShapeWireDesc *shapeWire; + XkbShapePtr shape; + register int o; + + shapeWire = (xkbShapeWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbShapeWireDesc)); + if (!shapeWire) + return BadLength; + shape = XkbAddGeomShape(geom, shapeWire->name, shapeWire->nOutlines); + if (!shape) + return BadAlloc; + for (o = 0; o < shapeWire->nOutlines; o++) { + xkbOutlineWireDesc *olWire; + XkbOutlinePtr ol; + register int p; + XkbPointPtr pt; + + olWire = (xkbOutlineWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbOutlineWireDesc)); + if (!olWire) + return BadLength; + ol = XkbAddGeomOutline(shape, olWire->nPoints); + if (!ol) + return BadAlloc; + ol->corner_radius = olWire->cornerRadius; + for (p = 0, pt = ol->points; p < olWire->nPoints; p++, pt++) { + xkbPointWireDesc *ptWire; + + ptWire = (xkbPointWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbPointWireDesc)); + if (!ptWire) + return BadLength; + pt->x = ptWire->x; + pt->y = ptWire->y; + } + ol->num_points = olWire->nPoints; + } + if ((shapeWire->primaryNdx != XkbNoShape) && + (shapeWire->primaryNdx < shapeWire->nOutlines)) + shape->primary = &shape->outlines[shapeWire->primaryNdx]; + else + shape->primary = NULL; + if ((shapeWire->approxNdx != XkbNoShape) && + (shapeWire->approxNdx < shapeWire->nOutlines)) + shape->approx = &shape->outlines[shapeWire->approxNdx]; + else + shape->approx = NULL; + XkbComputeShapeBounds(shape); } return Success; } static Status -_XkbReadGeomDoodad( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - XkbSectionPtr section) +_XkbReadGeomDoodad(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + XkbSectionPtr section) { -XkbDoodadPtr doodad; -xkbDoodadWireDesc * doodadWire; + XkbDoodadPtr doodad; + xkbDoodadWireDesc *doodadWire; - doodadWire= (xkbDoodadWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbDoodadWireDesc)); + doodadWire = (xkbDoodadWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbDoodadWireDesc)); if (!doodadWire) - return BadLength; - doodad= XkbAddGeomDoodad(geom,section,doodadWire->any.name); + return BadLength; + doodad = XkbAddGeomDoodad(geom, section, doodadWire->any.name); if (!doodad) - return BadAlloc; - doodad->any.type= doodadWire->any.type; - doodad->any.priority= doodadWire->any.priority; - doodad->any.top= doodadWire->any.top; - doodad->any.left= doodadWire->any.left; - doodad->any.angle= doodadWire->any.angle; + return BadAlloc; + doodad->any.type = doodadWire->any.type; + doodad->any.priority = doodadWire->any.priority; + doodad->any.top = doodadWire->any.top; + doodad->any.left = doodadWire->any.left; + doodad->any.angle = doodadWire->any.angle; switch (doodad->any.type) { - case XkbOutlineDoodad: - case XkbSolidDoodad: - doodad->shape.color_ndx= doodadWire->shape.colorNdx; - doodad->shape.shape_ndx= doodadWire->shape.shapeNdx; - break; - case XkbTextDoodad: - doodad->text.width= doodadWire->text.width; - doodad->text.height= doodadWire->text.height; - doodad->text.color_ndx= doodadWire->text.colorNdx; - if (!_XkbGetReadBufferCountedString(buf,&doodad->text.text)) - return BadLength; - if (!_XkbGetReadBufferCountedString(buf,&doodad->text.font)) - return BadLength; - break; - case XkbIndicatorDoodad: - doodad->indicator.shape_ndx= doodadWire->indicator.shapeNdx; - doodad->indicator.on_color_ndx= doodadWire->indicator.onColorNdx; - doodad->indicator.off_color_ndx= doodadWire->indicator.offColorNdx; - break; - case XkbLogoDoodad: - doodad->logo.color_ndx= doodadWire->logo.colorNdx; - doodad->logo.shape_ndx= doodadWire->logo.shapeNdx; - if (!_XkbGetReadBufferCountedString(buf,&doodad->logo.logo_name)) - return BadLength; - break; - default: - return BadValue; + case XkbOutlineDoodad: + case XkbSolidDoodad: + doodad->shape.color_ndx = doodadWire->shape.colorNdx; + doodad->shape.shape_ndx = doodadWire->shape.shapeNdx; + break; + case XkbTextDoodad: + doodad->text.width = doodadWire->text.width; + doodad->text.height = doodadWire->text.height; + doodad->text.color_ndx = doodadWire->text.colorNdx; + if (!_XkbGetReadBufferCountedString(buf, &doodad->text.text)) + return BadLength; + if (!_XkbGetReadBufferCountedString(buf, &doodad->text.font)) + return BadLength; + break; + case XkbIndicatorDoodad: + doodad->indicator.shape_ndx = doodadWire->indicator.shapeNdx; + doodad->indicator.on_color_ndx = doodadWire->indicator.onColorNdx; + doodad->indicator.off_color_ndx = doodadWire->indicator.offColorNdx; + break; + case XkbLogoDoodad: + doodad->logo.color_ndx = doodadWire->logo.colorNdx; + doodad->logo.shape_ndx = doodadWire->logo.shapeNdx; + if (!_XkbGetReadBufferCountedString(buf, &doodad->logo.logo_name)) + return BadLength; + break; + default: + return BadValue; } return Success; } static Status -_XkbReadGeomOverlay( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - XkbSectionPtr section) +_XkbReadGeomOverlay(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + XkbSectionPtr section) { -XkbOverlayPtr ol; -xkbOverlayWireDesc * olWire; -register int r; - - olWire= (xkbOverlayWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayWireDesc)); - if (olWire==NULL) - return BadLength; - ol= XkbAddGeomOverlay(section,olWire->name,olWire->nRows); - if (ol==NULL) - return BadLength; - for (r=0;r<olWire->nRows;r++) { - register int k; - XkbOverlayRowPtr row; - xkbOverlayRowWireDesc * rowWire; - xkbOverlayKeyWireDesc * keyWire; - rowWire= (xkbOverlayRowWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayRowWireDesc)); - if (rowWire==NULL) - return BadLength; - row= XkbAddGeomOverlayRow(ol,rowWire->rowUnder,rowWire->nKeys); - row->row_under= rowWire->rowUnder; - if (!row) - return BadAlloc; - if (rowWire->nKeys<1) - continue; - keyWire= (xkbOverlayKeyWireDesc *) - _XkbGetReadBufferPtr(buf, - SIZEOF(xkbOverlayKeyWireDesc)*rowWire->nKeys); - if (keyWire==NULL) - return BadLength; - for (k=0;k<rowWire->nKeys;k++,keyWire++,row->num_keys++) { - memcpy(row->keys[row->num_keys].over.name,keyWire->over, - XkbKeyNameLength); - memcpy(row->keys[row->num_keys].under.name,keyWire->under, - XkbKeyNameLength); - } + XkbOverlayPtr ol; + xkbOverlayWireDesc *olWire; + register int r; + + olWire = (xkbOverlayWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbOverlayWireDesc)); + if (olWire == NULL) + return BadLength; + ol = XkbAddGeomOverlay(section, olWire->name, olWire->nRows); + if (ol == NULL) + return BadLength; + for (r = 0; r < olWire->nRows; r++) { + register int k; + XkbOverlayRowPtr row; + xkbOverlayRowWireDesc *rowWire; + xkbOverlayKeyWireDesc *keyWire; + + rowWire = (xkbOverlayRowWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbOverlayRowWireDesc)); + if (rowWire == NULL) + return BadLength; + row = XkbAddGeomOverlayRow(ol, rowWire->rowUnder, rowWire->nKeys); + row->row_under = rowWire->rowUnder; + if (!row) + return BadAlloc; + if (rowWire->nKeys < 1) + continue; + keyWire = (xkbOverlayKeyWireDesc *) + _XkbGetReadBufferPtr(buf, + SIZEOF(xkbOverlayKeyWireDesc) * rowWire->nKeys); + if (keyWire == NULL) + return BadLength; + for (k = 0; k < rowWire->nKeys; k++, keyWire++, row->num_keys++) { + memcpy(row->keys[row->num_keys].over.name, keyWire->over, + XkbKeyNameLength); + memcpy(row->keys[row->num_keys].under.name, keyWire->under, + XkbKeyNameLength); + } } return Success; } static Status -_XkbReadGeomSections( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - xkbGetGeometryReply * rep) +_XkbReadGeomSections(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + xkbGetGeometryReply *rep) { -register int s; -XkbSectionPtr section; -xkbSectionWireDesc * sectionWire; -Status rtrn; - - if (rep->nSections<1) - return Success; - if ((rtrn=XkbAllocGeomSections(geom,rep->nSections))!=Success) - return rtrn; - for (s=0;s<rep->nSections;s++) { - sectionWire= (xkbSectionWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbSectionWireDesc)); - if (!sectionWire) - return BadLength; - section= XkbAddGeomSection(geom,sectionWire->name,sectionWire->nRows, - sectionWire->nDoodads, - sectionWire->nOverlays); - if (!section) - return BadAlloc; - section->top= sectionWire->top; - section->left= sectionWire->left; - section->width= sectionWire->width; - section->height= sectionWire->height; - section->angle= sectionWire->angle; - section->priority= sectionWire->priority; - if (sectionWire->nRows>0) { - register int r; - XkbRowPtr row; - xkbRowWireDesc * rowWire; - for (r=0;r<sectionWire->nRows;r++) { - rowWire= (xkbRowWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbRowWireDesc)); - if (!rowWire) - return BadLength; - row= XkbAddGeomRow(section,rowWire->nKeys); - if (!row) - return BadAlloc; - row->top= rowWire->top; - row->left= rowWire->left; - row->vertical= rowWire->vertical; - if (rowWire->nKeys>0) { - register int k; - XkbKeyPtr key; - xkbKeyWireDesc * keyWire; - for (k=0;k<rowWire->nKeys;k++) { - keyWire= (xkbKeyWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbKeyWireDesc)); - if (!keyWire) - return BadLength; - key= XkbAddGeomKey(row); - if (!key) - return BadAlloc; - memcpy(key->name.name,keyWire->name,XkbKeyNameLength); - key->gap= keyWire->gap; - key->shape_ndx= keyWire->shapeNdx; - key->color_ndx= keyWire->colorNdx; - } - } - } - } - if (sectionWire->nDoodads>0) { - register int d; - for (d=0;d<sectionWire->nDoodads;d++) { - if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success) - return rtrn; - } - } - if (sectionWire->nOverlays>0) { - register int o; - for (o=0;o<sectionWire->nOverlays;o++) { - if ((rtrn=_XkbReadGeomOverlay(buf,geom,section))!=Success) - return rtrn; - } - } + register int s; + XkbSectionPtr section; + xkbSectionWireDesc *sectionWire; + Status rtrn; + + if (rep->nSections < 1) + return Success; + if ((rtrn = XkbAllocGeomSections(geom, rep->nSections)) != Success) + return rtrn; + for (s = 0; s < rep->nSections; s++) { + sectionWire = (xkbSectionWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbSectionWireDesc)); + if (!sectionWire) + return BadLength; + section = XkbAddGeomSection(geom, sectionWire->name, sectionWire->nRows, + sectionWire->nDoodads, + sectionWire->nOverlays); + if (!section) + return BadAlloc; + section->top = sectionWire->top; + section->left = sectionWire->left; + section->width = sectionWire->width; + section->height = sectionWire->height; + section->angle = sectionWire->angle; + section->priority = sectionWire->priority; + if (sectionWire->nRows > 0) { + register int r; + + for (r = 0; r < sectionWire->nRows; r++) { + XkbRowPtr row; + xkbRowWireDesc *rowWire; + + rowWire = (xkbRowWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbRowWireDesc)); + if (!rowWire) + return BadLength; + row = XkbAddGeomRow(section, rowWire->nKeys); + if (!row) + return BadAlloc; + row->top = rowWire->top; + row->left = rowWire->left; + row->vertical = rowWire->vertical; + if (rowWire->nKeys > 0) { + register int k; + + for (k = 0; k < rowWire->nKeys; k++) { + XkbKeyPtr key; + xkbKeyWireDesc *keyWire; + + keyWire = (xkbKeyWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbKeyWireDesc)); + if (!keyWire) + return BadLength; + key = XkbAddGeomKey(row); + if (!key) + return BadAlloc; + memcpy(key->name.name, keyWire->name, XkbKeyNameLength); + key->gap = keyWire->gap; + key->shape_ndx = keyWire->shapeNdx; + key->color_ndx = keyWire->colorNdx; + } + } + } + } + if (sectionWire->nDoodads > 0) { + register int d; + + for (d = 0; d < sectionWire->nDoodads; d++) { + if ((rtrn = _XkbReadGeomDoodad(buf, geom, section)) != Success) + return rtrn; + } + } + if (sectionWire->nOverlays > 0) { + register int o; + + for (o = 0; o < sectionWire->nOverlays; o++) { + if ((rtrn = _XkbReadGeomOverlay(buf, geom, section)) != Success) + return rtrn; + } + } } return Success; } static Status -_XkbReadGeomDoodads( XkbReadBufferPtr buf, - XkbGeometryPtr geom, - xkbGetGeometryReply * rep) +_XkbReadGeomDoodads(XkbReadBufferPtr buf, + XkbGeometryPtr geom, + xkbGetGeometryReply *rep) { -register int d; -Status rtrn; - - if (rep->nDoodads<1) - return Success; - if ((rtrn=XkbAllocGeomDoodads(geom,rep->nDoodads))!=Success) - return rtrn; - for (d=0;d<rep->nDoodads;d++) { - if ((rtrn=_XkbReadGeomDoodad(buf,geom,NULL))!=Success) - return rtrn; + register int d; + Status rtrn; + + if (rep->nDoodads < 1) + return Success; + if ((rtrn = XkbAllocGeomDoodads(geom, rep->nDoodads)) != Success) + return rtrn; + for (d = 0; d < rep->nDoodads; d++) { + if ((rtrn = _XkbReadGeomDoodad(buf, geom, NULL)) != Success) + return rtrn; } return Success; } Status -_XkbReadGetGeometryReply( Display * dpy, - xkbGetGeometryReply * rep, - XkbDescPtr xkb, - int * nread_rtrn) +_XkbReadGetGeometryReply(Display *dpy, + xkbGetGeometryReply *rep, + XkbDescPtr xkb, + int *nread_rtrn) { -XkbGeometryPtr geom; + XkbGeometryPtr geom; - geom= _XkbTypedCalloc(1,XkbGeometryRec); + geom = _XkbTypedCalloc(1, XkbGeometryRec); if (!geom) - return BadAlloc; + return BadAlloc; if (xkb->geom) - XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True); - xkb->geom= geom; + XkbFreeGeometry(xkb->geom, XkbGeomAllMask, True); + xkb->geom = geom; - geom->name= rep->name; - geom->width_mm= rep->widthMM; - geom->height_mm= rep->heightMM; + geom->name = rep->name; + geom->width_mm = rep->widthMM; + geom->height_mm = rep->heightMM; if (rep->length) { - XkbReadBufferRec buf; - int left; - if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) { - Status status= Success; - if (nread_rtrn) - *nread_rtrn= (int)rep->length*4; - if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font)) - status= BadLength; - if (status==Success) - status= _XkbReadGeomProperties(&buf,geom,rep); - if (status==Success) - status= _XkbReadGeomColors(&buf,geom,rep); - if (status==Success) - status= _XkbReadGeomShapes(&buf,geom,rep); - if (status==Success) - status= _XkbReadGeomSections(&buf,geom,rep); - if (status==Success) - status= _XkbReadGeomDoodads(&buf,geom,rep); - if (status==Success) - status= _XkbReadGeomKeyAliases(&buf,geom,rep); - left= _XkbFreeReadBuffer(&buf); - if ((rep->baseColorNdx > geom->num_colors) || - (rep->labelColorNdx > geom->num_colors)) - status = BadLength; - if ((status!=Success) || left || buf.error) { - if (status==Success) - status= BadLength; - XkbFreeGeometry(geom,XkbGeomAllMask,True); - xkb->geom= NULL; - return status; - } - geom->base_color= &geom->colors[rep->baseColorNdx]; - geom->label_color= &geom->colors[rep->labelColorNdx]; - } - else { - XkbFreeGeometry(geom,XkbGeomAllMask,True); - xkb->geom= NULL; - return BadAlloc; - } + XkbReadBufferRec buf; + int left; + + if (_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4)) { + Status status = Success; + + if (nread_rtrn) + *nread_rtrn = (int) rep->length * 4; + if (!_XkbGetReadBufferCountedString(&buf, &geom->label_font)) + status = BadLength; + if (status == Success) + status = _XkbReadGeomProperties(&buf, geom, rep); + if (status == Success) + status = _XkbReadGeomColors(&buf, geom, rep); + if (status == Success) + status = _XkbReadGeomShapes(&buf, geom, rep); + if (status == Success) + status = _XkbReadGeomSections(&buf, geom, rep); + if (status == Success) + status = _XkbReadGeomDoodads(&buf, geom, rep); + if (status == Success) + status = _XkbReadGeomKeyAliases(&buf, geom, rep); + left = _XkbFreeReadBuffer(&buf); + if ((rep->baseColorNdx > geom->num_colors) || + (rep->labelColorNdx > geom->num_colors)) + status = BadLength; + if ((status != Success) || left || buf.error) { + if (status == Success) + status = BadLength; + XkbFreeGeometry(geom, XkbGeomAllMask, True); + xkb->geom = NULL; + return status; + } + geom->base_color = &geom->colors[rep->baseColorNdx]; + geom->label_color = &geom->colors[rep->labelColorNdx]; + } + else { + XkbFreeGeometry(geom, XkbGeomAllMask, True); + xkb->geom = NULL; + return BadAlloc; + } } return Success; } Status -XkbGetGeometry(Display *dpy,XkbDescPtr xkb) +XkbGetGeometry(Display *dpy, XkbDescPtr xkb) { -xkbGetGeometryReq *req; -xkbGetGeometryReply rep; -Status status; + xkbGetGeometryReq *req; + xkbGetGeometryReply rep; + Status status; - if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + if ((!xkb) || (dpy->flags & XlibDisplayNoXkb) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); GetReq(kbGetGeometry, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetGeometry; req->deviceSpec = xkb->device_spec; - req->name= None; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) - status = BadImplementation; + req->name = None; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) + status = BadImplementation; else if (!rep.found) - status = BadName; + status = BadName; else - status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL); + status = _XkbReadGetGeometryReply(dpy, &rep, xkb, NULL); UnlockDisplay(dpy); SyncHandle(); return status; } Status -XkbGetNamedGeometry(Display *dpy,XkbDescPtr xkb,Atom name) +XkbGetNamedGeometry(Display *dpy, XkbDescPtr xkb, Atom name) { -xkbGetGeometryReq *req; -xkbGetGeometryReply rep; -Status status; + xkbGetGeometryReq *req; + xkbGetGeometryReply rep; + Status status; - if ( (name==None) || (dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ) - return BadAccess; + if ((name == None) || (dpy->flags & XlibDisplayNoXkb) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); GetReq(kbGetGeometry, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetGeometry; req->deviceSpec = xkb->device_spec; - req->name= (CARD32)name; - if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.found)) - status = BadImplementation; + req->name = (CARD32) name; + if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.found)) + status = BadImplementation; else if (!rep.found) - status = BadName; + status = BadName; else - status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL); + status = _XkbReadGetGeometryReply(dpy, &rep, xkb, NULL); UnlockDisplay(dpy); SyncHandle(); return status; } - diff --git a/libX11/src/xkb/XKBGetByName.c b/libX11/src/xkb/XKBGetByName.c index 8e4f55458..973052ce6 100644 --- a/libX11/src/xkb/XKBGetByName.c +++ b/libX11/src/xkb/XKBGetByName.c @@ -35,32 +35,32 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ XkbDescPtr -XkbGetKeyboardByName( Display * dpy, - unsigned deviceSpec, - XkbComponentNamesPtr names, - unsigned want, - unsigned need, - Bool load) +XkbGetKeyboardByName(Display *dpy, + unsigned deviceSpec, + XkbComponentNamesPtr names, + unsigned want, + unsigned need, + Bool load) { - register xkbGetKbdByNameReq * req; - xkbGetKbdByNameReply rep; - int len,extraLen; - char * str; - XkbDescPtr xkb; - int mapLen,codesLen,typesLen,compatLen; - int symsLen,geomLen; - XkbInfoPtr xkbi; - - if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ) - return NULL; - - xkbi= dpy->xkb_info; - xkb = (XkbDescRec *)_XkbCalloc(1,sizeof(XkbDescRec)); + register xkbGetKbdByNameReq *req; + xkbGetKbdByNameReply rep; + int len, extraLen; + char *str; + XkbDescPtr xkb; + int mapLen, codesLen, typesLen, compatLen; + int symsLen, geomLen; + XkbInfoPtr xkbi; + + if ((dpy == NULL) || (dpy->flags & XlibDisplayNoXkb) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return NULL; + + xkbi = dpy->xkb_info; + xkb = (XkbDescRec *) _XkbCalloc(1, sizeof(XkbDescRec)); if (!xkb) - return NULL; + return NULL; xkb->device_spec = deviceSpec; - xkb->map = (XkbClientMapRec *)_XkbCalloc(1,sizeof(XkbClientMapRec)); + xkb->map = (XkbClientMapRec *) _XkbCalloc(1, sizeof(XkbClientMapRec)); xkb->dpy = dpy; LockDisplay(dpy); @@ -68,147 +68,155 @@ XkbGetKeyboardByName( Display * dpy, req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetKbdByName; req->deviceSpec = xkb->device_spec; - req->want= want; - req->need= need; - req->load= load; + req->want = want; + req->need = need; + req->load = load; - mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; + mapLen = codesLen = typesLen = compatLen = symsLen = geomLen = 0; if (names) { - if (names->keymap) - mapLen= (int)strlen(names->keymap); - if (names->keycodes) - codesLen= (int)strlen(names->keycodes); - if (names->types) - typesLen= (int)strlen(names->types); - if (names->compat) - compatLen= (int)strlen(names->compat); - if (names->symbols) - symsLen= (int)strlen(names->symbols); - if (names->geometry) - geomLen= (int)strlen(names->geometry); - if (mapLen>255) mapLen= 255; - if (codesLen>255) codesLen= 255; - if (typesLen>255) typesLen= 255; - if (compatLen>255) compatLen= 255; - if (symsLen>255) symsLen= 255; - if (geomLen>255) geomLen= 255; + if (names->keymap) + mapLen = (int) strlen(names->keymap); + if (names->keycodes) + codesLen = (int) strlen(names->keycodes); + if (names->types) + typesLen = (int) strlen(names->types); + if (names->compat) + compatLen = (int) strlen(names->compat); + if (names->symbols) + symsLen = (int) strlen(names->symbols); + if (names->geometry) + geomLen = (int) strlen(names->geometry); + if (mapLen > 255) + mapLen = 255; + if (codesLen > 255) + codesLen = 255; + if (typesLen > 255) + typesLen = 255; + if (compatLen > 255) + compatLen = 255; + if (symsLen > 255) + symsLen = 255; + if (geomLen > 255) + geomLen = 255; } - else mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; - - len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; - len= XkbPaddedSize(len); - req->length+= len/4; - BufAlloc(char *,str,len); - *str++= mapLen; - if (mapLen>0) { - memcpy(str,names->keymap,mapLen); - str+= mapLen; + else + mapLen = codesLen = typesLen = compatLen = symsLen = geomLen = 0; + + len = mapLen + codesLen + typesLen + compatLen + symsLen + geomLen + 6; + len = XkbPaddedSize(len); + req->length += len / 4; + BufAlloc(char *, str, len); + + *str++ = mapLen; + if (mapLen > 0) { + memcpy(str, names->keymap, mapLen); + str += mapLen; } - *str++= codesLen; - if (codesLen>0) { - memcpy(str,names->keycodes,codesLen); - str+= codesLen; + *str++ = codesLen; + if (codesLen > 0) { + memcpy(str, names->keycodes, codesLen); + str += codesLen; } - *str++= typesLen; - if (typesLen>0) { - memcpy(str,names->types,typesLen); - str+= typesLen; + *str++ = typesLen; + if (typesLen > 0) { + memcpy(str, names->types, typesLen); + str += typesLen; } - *str++= compatLen; - if (compatLen>0) { - memcpy(str,names->compat,compatLen); - str+= compatLen; + *str++ = compatLen; + if (compatLen > 0) { + memcpy(str, names->compat, compatLen); + str += compatLen; } - *str++= symsLen; - if (symsLen>0) { - memcpy(str,names->symbols,symsLen); - str+= symsLen; + *str++ = symsLen; + if (symsLen > 0) { + memcpy(str, names->symbols, symsLen); + str += symsLen; } - *str++= geomLen; - if (geomLen>0) { - memcpy(str,names->geometry,geomLen); - str+= geomLen; + *str++ = geomLen; + if (geomLen > 0) { + memcpy(str, names->geometry, geomLen); + str += geomLen; } - if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.reported)) - goto BAILOUT; - extraLen= (int)rep.length*4; + if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.reported)) + goto BAILOUT; + extraLen = (int) rep.length * 4; - xkb->device_spec= rep.deviceID; + xkb->device_spec = rep.deviceID; xkb->min_key_code = rep.minKeyCode; xkb->max_key_code = rep.maxKeyCode; - if (rep.reported&(XkbGBN_SymbolsMask|XkbGBN_TypesMask)) { - xkbGetMapReply mrep; - Status status; - int nread= 0; - - _XRead(dpy, (char *)&mrep, SIZEOF(xkbGetMapReply)); - extraLen-= SIZEOF(xkbGetMapReply); - status= _XkbReadGetMapReply(dpy,&mrep,xkb,&nread); - extraLen-= nread; - if (status!=Success) - goto BAILOUT; + if (rep.reported & (XkbGBN_SymbolsMask | XkbGBN_TypesMask)) { + xkbGetMapReply mrep; + Status status; + int nread = 0; + + _XRead(dpy, (char *) &mrep, SIZEOF(xkbGetMapReply)); + extraLen -= SIZEOF(xkbGetMapReply); + status = _XkbReadGetMapReply(dpy, &mrep, xkb, &nread); + extraLen -= nread; + if (status != Success) + goto BAILOUT; } - if (rep.reported&XkbGBN_CompatMapMask) { - xkbGetCompatMapReply crep; - Status status; - int nread= 0; - - _XRead(dpy, (char *)&crep, SIZEOF(xkbGetCompatMapReply)); - extraLen-= SIZEOF(xkbGetCompatMapReply); - status= _XkbReadGetCompatMapReply(dpy,&crep,xkb,&nread); - extraLen-= nread; - if (status!=Success) - goto BAILOUT; + if (rep.reported & XkbGBN_CompatMapMask) { + xkbGetCompatMapReply crep; + Status status; + int nread = 0; + + _XRead(dpy, (char *) &crep, SIZEOF(xkbGetCompatMapReply)); + extraLen -= SIZEOF(xkbGetCompatMapReply); + status = _XkbReadGetCompatMapReply(dpy, &crep, xkb, &nread); + extraLen -= nread; + if (status != Success) + goto BAILOUT; } - if (rep.reported&XkbGBN_IndicatorMapMask) { - xkbGetIndicatorMapReply irep; - Status status; - int nread= 0; - - _XRead(dpy, (char *)&irep, SIZEOF(xkbGetIndicatorMapReply)); - extraLen-= SIZEOF(xkbGetIndicatorMapReply); - status= _XkbReadGetIndicatorMapReply(dpy,&irep,xkb,&nread); - extraLen-= nread; - if (status!=Success) - goto BAILOUT; + if (rep.reported & XkbGBN_IndicatorMapMask) { + xkbGetIndicatorMapReply irep; + Status status; + int nread = 0; + + _XRead(dpy, (char *) &irep, SIZEOF(xkbGetIndicatorMapReply)); + extraLen -= SIZEOF(xkbGetIndicatorMapReply); + status = _XkbReadGetIndicatorMapReply(dpy, &irep, xkb, &nread); + extraLen -= nread; + if (status != Success) + goto BAILOUT; } - if (rep.reported&(XkbGBN_KeyNamesMask|XkbGBN_OtherNamesMask)) { - xkbGetNamesReply nrep; - Status status; - int nread= 0; - - _XRead(dpy, (char *)&nrep, SIZEOF(xkbGetNamesReply)); - extraLen-= SIZEOF(xkbGetNamesReply); - status= _XkbReadGetNamesReply(dpy,&nrep,xkb,&nread); - extraLen-= nread; - if (status!=Success) - goto BAILOUT; + if (rep.reported & (XkbGBN_KeyNamesMask | XkbGBN_OtherNamesMask)) { + xkbGetNamesReply nrep; + Status status; + int nread = 0; + + _XRead(dpy, (char *) &nrep, SIZEOF(xkbGetNamesReply)); + extraLen -= SIZEOF(xkbGetNamesReply); + status = _XkbReadGetNamesReply(dpy, &nrep, xkb, &nread); + extraLen -= nread; + if (status != Success) + goto BAILOUT; } - if (rep.reported&XkbGBN_GeometryMask) { - xkbGetGeometryReply grep; - Status status; - int nread= 0; - - _XRead(dpy, (char *)&grep, SIZEOF(xkbGetGeometryReply)); - extraLen-= SIZEOF(xkbGetGeometryReply); - status= _XkbReadGetGeometryReply(dpy,&grep,xkb,&nread); - extraLen-= nread; - if (status!=Success) - goto BAILOUT; + if (rep.reported & XkbGBN_GeometryMask) { + xkbGetGeometryReply grep; + Status status; + int nread = 0; + + _XRead(dpy, (char *) &grep, SIZEOF(xkbGetGeometryReply)); + extraLen -= SIZEOF(xkbGetGeometryReply); + status = _XkbReadGetGeometryReply(dpy, &grep, xkb, &nread); + extraLen -= nread; + if (status != Success) + goto BAILOUT; } UnlockDisplay(dpy); SyncHandle(); return xkb; -BAILOUT: - if (xkb!=NULL) - XkbFreeKeyboard(xkb,XkbAllComponentsMask,xTrue); + BAILOUT: + if (xkb != NULL) + XkbFreeKeyboard(xkb, XkbAllComponentsMask, xTrue); UnlockDisplay(dpy); SyncHandle(); return NULL; } XkbDescPtr -XkbGetKeyboard(Display *dpy,unsigned which,unsigned deviceSpec) +XkbGetKeyboard(Display *dpy, unsigned which, unsigned deviceSpec) { - return XkbGetKeyboardByName(dpy,deviceSpec,NULL,which,which,False); + return XkbGetKeyboardByName(dpy, deviceSpec, NULL, which, which, False); } diff --git a/libX11/src/xkb/XKBGetMap.c b/libX11/src/xkb/XKBGetMap.c index 738fbc38f..0e4c567ee 100644 --- a/libX11/src/xkb/XKBGetMap.c +++ b/libX11/src/xkb/XKBGetMap.c @@ -61,429 +61,445 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "XKBlibint.h" static Status -_XkbReadKeyTypes(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) +_XkbReadKeyTypes(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) { -int i,n,lastMapCount; -XkbKeyTypePtr type; - - if ( rep->nTypes>0 ) { - n = rep->firstType+rep->nTypes; - if (xkb->map->num_types>=n) - n= xkb->map->num_types; - else if (XkbAllocClientMap(xkb,XkbKeyTypesMask,n)!=Success) - return BadAlloc; - - type = &xkb->map->types[rep->firstType]; - for (i=0;i<(int)rep->nTypes;i++,type++) { - xkbKeyTypeWireDesc *desc; - register int ndx; - - ndx= i+rep->firstType; - if (ndx>=xkb->map->num_types) - xkb->map->num_types= ndx+1; - - desc= (xkbKeyTypeWireDesc *)_XkbGetReadBufferPtr(buf, - SIZEOF(xkbKeyTypeWireDesc)); - if (desc==NULL) - return BadLength; - - lastMapCount= type->map_count; - if ( desc->nMapEntries>0 ) { - if ((type->map==NULL)||(desc->nMapEntries>type->map_count)) { - XkbKTMapEntryRec *prev_map = type->map; - - type->map= _XkbTypedRealloc(type->map,desc->nMapEntries, - XkbKTMapEntryRec); - if (type->map==NULL) { - _XkbFree(prev_map); - return BadAlloc; - } - } - } - else if (type->map!=NULL) { - Xfree(type->map); - type->map_count= 0; - type->map= NULL; - } - - if ( desc->preserve && (desc->nMapEntries>0) ) { - if ((!type->preserve)|| - (desc->nMapEntries>lastMapCount)) { - XkbModsRec *prev_preserve = type->preserve; - - type->preserve= _XkbTypedRealloc(type->preserve, - desc->nMapEntries, - XkbModsRec); - if (type->preserve==NULL) { - _XkbFree(prev_preserve); - return BadAlloc; - } - } - } - else if (type->preserve!=NULL) { - Xfree(type->preserve); - type->preserve= NULL; - } - - type->mods.mask = desc->mask; - type->mods.real_mods = desc->realMods; - type->mods.vmods = desc->virtualMods; - type->num_levels = desc->numLevels; - type->map_count = desc->nMapEntries; - if (desc->nMapEntries>0) { - register xkbKTMapEntryWireDesc *wire; - register XkbKTMapEntryPtr entry; - register int size; - - size= type->map_count*SIZEOF(xkbKTMapEntryWireDesc); - wire= (xkbKTMapEntryWireDesc *)_XkbGetReadBufferPtr(buf,size); - if (wire==NULL) - return BadLength; - entry= type->map; - for (n=0;n<type->map_count;n++,wire++,entry++) { - entry->active= wire->active; - entry->level= wire->level; - entry->mods.mask= wire->mask; - entry->mods.real_mods= wire->realMods; - entry->mods.vmods= wire->virtualMods; - } - - if (desc->preserve) { - register xkbModsWireDesc * pwire; - register XkbModsPtr preserve; - register int sz; - - sz= desc->nMapEntries*SIZEOF(xkbModsWireDesc); - pwire=(xkbModsWireDesc *)_XkbGetReadBufferPtr(buf,sz); - if (pwire==NULL) - return BadLength; - preserve= type->preserve; - for (n=0;n<desc->nMapEntries;n++,pwire++,preserve++) { - preserve->mask= pwire->mask; - preserve->vmods= pwire->virtualMods; - preserve->real_mods= pwire->realMods; - } - } - } - } + int i, n, lastMapCount; + XkbKeyTypePtr type; + + if (rep->nTypes > 0) { + n = rep->firstType + rep->nTypes; + if (xkb->map->num_types >= n) + n = xkb->map->num_types; + else if (XkbAllocClientMap(xkb, XkbKeyTypesMask, n) != Success) + return BadAlloc; + + type = &xkb->map->types[rep->firstType]; + for (i = 0; i < (int) rep->nTypes; i++, type++) { + xkbKeyTypeWireDesc *desc; + register int ndx; + + ndx = i + rep->firstType; + if (ndx >= xkb->map->num_types) + xkb->map->num_types = ndx + 1; + + desc = (xkbKeyTypeWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbKeyTypeWireDesc)); + if (desc == NULL) + return BadLength; + + lastMapCount = type->map_count; + if (desc->nMapEntries > 0) { + if ((type->map == NULL) || + (desc->nMapEntries > type->map_count)) { + XkbKTMapEntryRec *prev_map = type->map; + + type->map = _XkbTypedRealloc(type->map, desc->nMapEntries, + XkbKTMapEntryRec); + if (type->map == NULL) { + _XkbFree(prev_map); + return BadAlloc; + } + } + } + else if (type->map != NULL) { + Xfree(type->map); + type->map_count = 0; + type->map = NULL; + } + + if (desc->preserve && (desc->nMapEntries > 0)) { + if ((!type->preserve) || (desc->nMapEntries > lastMapCount)) { + XkbModsRec *prev_preserve = type->preserve; + + type->preserve = _XkbTypedRealloc(type->preserve, + desc->nMapEntries, + XkbModsRec); + if (type->preserve == NULL) { + _XkbFree(prev_preserve); + return BadAlloc; + } + } + } + else if (type->preserve != NULL) { + Xfree(type->preserve); + type->preserve = NULL; + } + + type->mods.mask = desc->mask; + type->mods.real_mods = desc->realMods; + type->mods.vmods = desc->virtualMods; + type->num_levels = desc->numLevels; + type->map_count = desc->nMapEntries; + if (desc->nMapEntries > 0) { + register xkbKTMapEntryWireDesc *wire; + register XkbKTMapEntryPtr entry; + register int size; + + size = type->map_count * SIZEOF(xkbKTMapEntryWireDesc); + wire = + (xkbKTMapEntryWireDesc *) _XkbGetReadBufferPtr(buf, size); + if (wire == NULL) + return BadLength; + entry = type->map; + for (n = 0; n < type->map_count; n++, wire++, entry++) { + entry->active = wire->active; + entry->level = wire->level; + entry->mods.mask = wire->mask; + entry->mods.real_mods = wire->realMods; + entry->mods.vmods = wire->virtualMods; + } + + if (desc->preserve) { + register xkbModsWireDesc *pwire; + register XkbModsPtr preserve; + register int sz; + + sz = desc->nMapEntries * SIZEOF(xkbModsWireDesc); + pwire = (xkbModsWireDesc *) _XkbGetReadBufferPtr(buf, sz); + if (pwire == NULL) + return BadLength; + preserve = type->preserve; + for (n = 0; n < desc->nMapEntries; n++, pwire++, preserve++) { + preserve->mask = pwire->mask; + preserve->vmods = pwire->virtualMods; + preserve->real_mods = pwire->realMods; + } + } + } + } } return Success; } static Status -_XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) +_XkbReadKeySyms(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) { -register int i; -XkbClientMapPtr map; - - map= xkb->map; - if (map->key_sym_map==NULL) { - register int offset; - int size = xkb->max_key_code + 1; - XkbSymMapPtr oldMap; - xkbSymMapWireDesc *newMap; - if (((unsigned short)rep->firstKeySym + rep->nKeySyms) > size) - return BadLength; - map->key_sym_map= _XkbTypedCalloc(size,XkbSymMapRec); - if (map->key_sym_map==NULL) - return BadAlloc; - if (map->syms==NULL) { - int sz; - sz= (rep->totalSyms*12)/10; - sz= ((sz+(unsigned)128)/128)*128; - map->syms = _XkbTypedCalloc(sz,KeySym); - if (map->syms==NULL) - return BadAlloc; - map->size_syms = sz; - } - offset = 1; - oldMap = &map->key_sym_map[rep->firstKeySym]; - for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) { - newMap= (xkbSymMapWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc)); - if (newMap==NULL) - return BadLength; - oldMap->kt_index[0]= newMap->ktIndex[0]; - oldMap->kt_index[1]= newMap->ktIndex[1]; - oldMap->kt_index[2]= newMap->ktIndex[2]; - oldMap->kt_index[3]= newMap->ktIndex[3]; - oldMap->group_info= newMap->groupInfo; - oldMap->width= newMap->width; - oldMap->offset= offset; - if (offset+newMap->nSyms>=map->size_syms) { - register int sz; - KeySym *prev_syms = map->syms; - - sz= map->size_syms+128; - map->syms= _XkbTypedRealloc(map->syms,sz,KeySym); - if (map->syms==NULL) { - _XkbFree(prev_syms); - map->size_syms= 0; - return BadAlloc; - } - map->size_syms= sz; - } - if (newMap->nSyms>0) { - _XkbReadBufferCopyKeySyms(buf,(KeySym *)&map->syms[offset], - newMap->nSyms); - offset+= newMap->nSyms; - } - else { - map->syms[offset]= 0; - } - } - map->num_syms= offset; + register int i; + XkbClientMapPtr map; + int size = xkb->max_key_code + 1; + + if (((unsigned short) rep->firstKeySym + rep->nKeySyms) > size) + return BadLength; + + map = xkb->map; + if (map->key_sym_map == NULL) { + register int offset; + XkbSymMapPtr oldMap; + xkbSymMapWireDesc *newMap; + + map->key_sym_map = _XkbTypedCalloc(size, XkbSymMapRec); + if (map->key_sym_map == NULL) + return BadAlloc; + if (map->syms == NULL) { + int sz; + + sz = (rep->totalSyms * 12) / 10; + sz = ((sz + (unsigned) 128) / 128) * 128; + map->syms = _XkbTypedCalloc(sz, KeySym); + if (map->syms == NULL) + return BadAlloc; + map->size_syms = sz; + } + offset = 1; + oldMap = &map->key_sym_map[rep->firstKeySym]; + for (i = 0; i < (int) rep->nKeySyms; i++, oldMap++) { + newMap = (xkbSymMapWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbSymMapWireDesc)); + if (newMap == NULL) + return BadLength; + oldMap->kt_index[0] = newMap->ktIndex[0]; + oldMap->kt_index[1] = newMap->ktIndex[1]; + oldMap->kt_index[2] = newMap->ktIndex[2]; + oldMap->kt_index[3] = newMap->ktIndex[3]; + oldMap->group_info = newMap->groupInfo; + oldMap->width = newMap->width; + oldMap->offset = offset; + if (offset + newMap->nSyms >= map->size_syms) { + register int sz; + KeySym *prev_syms = map->syms; + + sz = map->size_syms + 128; + map->syms = _XkbTypedRealloc(map->syms, sz, KeySym); + if (map->syms == NULL) { + _XkbFree(prev_syms); + map->size_syms = 0; + return BadAlloc; + } + map->size_syms = sz; + } + if (newMap->nSyms > 0) { + _XkbReadBufferCopyKeySyms(buf, (KeySym *) &map->syms[offset], + newMap->nSyms); + offset += newMap->nSyms; + } + else { + map->syms[offset] = 0; + } + } + map->num_syms = offset; } else { - xkbSymMapWireDesc * newMap; - XkbSymMapPtr oldMap; - KeySym * newSyms; - int tmp; - - if (((unsigned short)rep->firstKeySym + rep->nKeySyms) > map->num_syms) - return BadLength; - oldMap = &map->key_sym_map[rep->firstKeySym]; - for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) { - newMap= (xkbSymMapWireDesc *) - _XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc)); - if (newMap==NULL) - return BadLength; - - if (newMap->nSyms>0) - tmp= newMap->nSyms; - else tmp= 0; - - newSyms = XkbResizeKeySyms(xkb,i+rep->firstKeySym,tmp); - if (newSyms==NULL) - return BadAlloc; - if (newMap->nSyms>0) - _XkbReadBufferCopyKeySyms(buf,newSyms,newMap->nSyms); - else newSyms[0]= NoSymbol; - oldMap->kt_index[0] = newMap->ktIndex[0]; - oldMap->kt_index[1] = newMap->ktIndex[1]; - oldMap->kt_index[2] = newMap->ktIndex[2]; - oldMap->kt_index[3] = newMap->ktIndex[3]; - oldMap->group_info = newMap->groupInfo; - oldMap->width = newMap->width; - } + XkbSymMapPtr oldMap = &map->key_sym_map[rep->firstKeySym]; + + for (i = 0; i < (int) rep->nKeySyms; i++, oldMap++) { + xkbSymMapWireDesc *newMap; + KeySym *newSyms; + int tmp; + + newMap = (xkbSymMapWireDesc *) + _XkbGetReadBufferPtr(buf, SIZEOF(xkbSymMapWireDesc)); + if (newMap == NULL) + return BadLength; + + if (newMap->nSyms > 0) + tmp = newMap->nSyms; + else + tmp = 0; + + newSyms = XkbResizeKeySyms(xkb, i + rep->firstKeySym, tmp); + if (newSyms == NULL) + return BadAlloc; + if (newMap->nSyms > 0) + _XkbReadBufferCopyKeySyms(buf, newSyms, newMap->nSyms); + else + newSyms[0] = NoSymbol; + oldMap->kt_index[0] = newMap->ktIndex[0]; + oldMap->kt_index[1] = newMap->ktIndex[1]; + oldMap->kt_index[2] = newMap->ktIndex[2]; + oldMap->kt_index[3] = newMap->ktIndex[3]; + oldMap->group_info = newMap->groupInfo; + oldMap->width = newMap->width; + } } return Success; } static Status -_XkbReadKeyActions(XkbReadBufferPtr buf,XkbDescPtr info,xkbGetMapReply *rep) +_XkbReadKeyActions(XkbReadBufferPtr buf, XkbDescPtr info, xkbGetMapReply *rep) { -int i; -CARD8 numDescBuf[248]; -CARD8* numDesc = NULL; -register int nKeyActs; -Status ret = Success; - - if ( (nKeyActs=rep->nKeyActs)>0 ) { - XkbSymMapPtr symMap; - - if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf; - else numDesc = Xmalloc (nKeyActs * sizeof(CARD8)); - - if (!_XkbCopyFromReadBuffer(buf, (char *)numDesc, nKeyActs)) { - ret = BadLength; - goto done; - } - i= XkbPaddedSize(nKeyActs)-nKeyActs; - if ((i>0)&&(!_XkbSkipReadBufferData(buf,i))) { - ret = BadLength; - goto done; - } - symMap = &info->map->key_sym_map[rep->firstKeyAct]; - for (i=0;i<(int)rep->nKeyActs;i++,symMap++) { - if (numDesc[i]==0) { - if ((i + rep->firstKeyAct) > (info->max_key_code + 1)) { - ret = BadLength; - goto done; - } - info->server->key_acts[i+rep->firstKeyAct]= 0; - } - else { - XkbAction *newActs; - /* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */ - /* either zero or XkbKeyNumSyms(info,key) */ - newActs=XkbResizeKeyActions(info,i+rep->firstKeyAct, - numDesc[i]); - if (newActs==NULL) { - ret = BadAlloc; - goto done; - } - if (!_XkbCopyFromReadBuffer(buf,(char *)newActs, - (int)(numDesc[i]*sizeof(XkbAction)))) { - ret = BadLength; - goto done; - } - } - } + int i; + CARD8 numDescBuf[248]; + CARD8 *numDesc = NULL; + register int nKeyActs; + Status ret = Success; + + if ((nKeyActs = rep->nKeyActs) > 0) { + XkbSymMapPtr symMap; + + if (nKeyActs < sizeof numDescBuf) + numDesc = numDescBuf; + else + numDesc = Xmalloc(nKeyActs * sizeof(CARD8)); + + if (!_XkbCopyFromReadBuffer(buf, (char *) numDesc, nKeyActs)) { + ret = BadLength; + goto done; + } + i = XkbPaddedSize(nKeyActs) - nKeyActs; + if ((i > 0) && (!_XkbSkipReadBufferData(buf, i))) { + ret = BadLength; + goto done; + } + symMap = &info->map->key_sym_map[rep->firstKeyAct]; + for (i = 0; i < (int) rep->nKeyActs; i++, symMap++) { + if (numDesc[i] == 0) { + if ((i + rep->firstKeyAct) > (info->max_key_code + 1)) { + ret = BadLength; + goto done; + } + info->server->key_acts[i + rep->firstKeyAct] = 0; + } + else { + XkbAction *newActs; + + /* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */ + /* either zero or XkbKeyNumSyms(info,key) */ + newActs = XkbResizeKeyActions(info, i + rep->firstKeyAct, + numDesc[i]); + if (newActs == NULL) { + ret = BadAlloc; + goto done; + } + if (!_XkbCopyFromReadBuffer(buf, (char *) newActs, + (int) (numDesc[i] * sizeof(XkbAction)))) { + ret = BadLength; + goto done; + } + } + } } -done: - if (numDesc != NULL && numDesc != numDescBuf) Xfree (numDesc); + done: + if (numDesc != NULL && numDesc != numDescBuf) + Xfree(numDesc); return ret; } static Status -_XkbReadKeyBehaviors(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) +_XkbReadKeyBehaviors(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) { -register int i; -xkbBehaviorWireDesc *wire; - - if ( rep->totalKeyBehaviors>0 ) { - int size = xkb->max_key_code + 1; - if ( ((int) rep->firstKeyBehavior + rep->nKeyBehaviors) > size) - return BadLength; - if ( xkb->server->behaviors == NULL ) { - xkb->server->behaviors = _XkbTypedCalloc(size,XkbBehavior); - if (xkb->server->behaviors==NULL) - return BadAlloc; - } - else { - bzero(&xkb->server->behaviors[rep->firstKeyBehavior], - (rep->nKeyBehaviors*sizeof(XkbBehavior))); - } - for (i=0;i<rep->totalKeyBehaviors;i++) { - wire= (xkbBehaviorWireDesc *)_XkbGetReadBufferPtr(buf, - SIZEOF(xkbBehaviorWireDesc)); - if (wire==NULL || wire->key >= size) - return BadLength; - xkb->server->behaviors[wire->key].type= wire->type; - xkb->server->behaviors[wire->key].data= wire->data; - } + register int i; + + if (rep->totalKeyBehaviors > 0) { + int size = xkb->max_key_code + 1; + + if (((int) rep->firstKeyBehavior + rep->nKeyBehaviors) > size) + return BadLength; + if (xkb->server->behaviors == NULL) { + xkb->server->behaviors = _XkbTypedCalloc(size, XkbBehavior); + if (xkb->server->behaviors == NULL) + return BadAlloc; + } + else { + bzero(&xkb->server->behaviors[rep->firstKeyBehavior], + (rep->nKeyBehaviors * sizeof(XkbBehavior))); + } + for (i = 0; i < rep->totalKeyBehaviors; i++) { + xkbBehaviorWireDesc *wire; + + wire = (xkbBehaviorWireDesc *) _XkbGetReadBufferPtr(buf, + SIZEOF(xkbBehaviorWireDesc)); + if (wire == NULL || wire->key >= size) + return BadLength; + xkb->server->behaviors[wire->key].type = wire->type; + xkb->server->behaviors[wire->key].data = wire->data; + } } return Success; } static Status -_XkbReadVirtualMods(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) +_XkbReadVirtualMods(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) { - if ( rep->virtualMods ) { - register int i,bit,nVMods; - register char *data; - - for (i=nVMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { - if (rep->virtualMods&bit) - nVMods++; - } - data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods)); - if (data==NULL) - return BadLength; - for (i=0,bit=1;(i<XkbNumVirtualMods)&&(nVMods>0);i++,bit<<=1) { - if (rep->virtualMods&bit) { - xkb->server->vmods[i]= *data++; - nVMods--; - } - } + if (rep->virtualMods) { + register int i, bit, nVMods; + register char *data; + + for (i = nVMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { + if (rep->virtualMods & bit) + nVMods++; + } + data = _XkbGetReadBufferPtr(buf, XkbPaddedSize(nVMods)); + if (data == NULL) + return BadLength; + for (i = 0, bit = 1; (i < XkbNumVirtualMods) && (nVMods > 0); + i++, bit <<= 1) { + if (rep->virtualMods & bit) { + xkb->server->vmods[i] = *data++; + nVMods--; + } + } } return Success; } static Status -_XkbReadExplicitComponents( XkbReadBufferPtr buf, - XkbDescPtr xkb, - xkbGetMapReply * rep) +_XkbReadExplicitComponents(XkbReadBufferPtr buf, + XkbDescPtr xkb, + xkbGetMapReply *rep) { -register int i; -unsigned char *wire; - - if ( rep->totalKeyExplicit>0 ) { - int size = xkb->max_key_code + 1; - if ( ((int) rep->firstKeyExplicit + rep->nKeyExplicit) > size) - return BadLength; - if ( xkb->server->explicit == NULL ) { - xkb->server->explicit = _XkbTypedCalloc(size,unsigned char); - if (xkb->server->explicit==NULL) - return BadAlloc; - } - else { - bzero(&xkb->server->explicit[rep->firstKeyExplicit], - rep->nKeyExplicit); - } - i= XkbPaddedSize(2*rep->totalKeyExplicit); - wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i); - if (!wire) - return BadLength; - for (i=0;i<rep->totalKeyExplicit;i++,wire+=2) { - if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code) - return BadLength; - xkb->server->explicit[wire[0]]= wire[1]; - } + register int i; + unsigned char *wire; + + if (rep->totalKeyExplicit > 0) { + int size = xkb->max_key_code + 1; + + if (((int) rep->firstKeyExplicit + rep->nKeyExplicit) > size) + return BadLength; + if (xkb->server->explicit == NULL) { + xkb->server->explicit = _XkbTypedCalloc(size, unsigned char); + + if (xkb->server->explicit == NULL) + return BadAlloc; + } + else { + bzero(&xkb->server->explicit[rep->firstKeyExplicit], + rep->nKeyExplicit); + } + i = XkbPaddedSize(2 * rep->totalKeyExplicit); + wire = (unsigned char *) _XkbGetReadBufferPtr(buf, i); + if (!wire) + return BadLength; + for (i = 0; i < rep->totalKeyExplicit; i++, wire += 2) { + if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code) + return BadLength; + xkb->server->explicit[wire[0]] = wire[1]; + } } return Success; } static Status -_XkbReadModifierMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) +_XkbReadModifierMap(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) { -register int i; -unsigned char *wire; - - if ( rep->totalModMapKeys>0 ) { - if ( ((int)rep->firstModMapKey + rep->nModMapKeys) > - (xkb->max_key_code + 1)) - return BadLength; - if ((xkb->map->modmap==NULL)&& - (XkbAllocClientMap(xkb,XkbModifierMapMask,0)!=Success)) { - return BadAlloc; - } - else { - bzero(&xkb->map->modmap[rep->firstModMapKey],rep->nModMapKeys); - } - i= XkbPaddedSize(2*rep->totalModMapKeys); - wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i); - if (!wire) - return BadLength; - for (i=0;i<rep->totalModMapKeys;i++,wire+=2) { - if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code) - return BadLength; - xkb->map->modmap[wire[0]]= wire[1]; - } + register int i; + unsigned char *wire; + + if (rep->totalModMapKeys > 0) { + if (((int) rep->firstModMapKey + rep->nModMapKeys) > + (xkb->max_key_code + 1)) + return BadLength; + if ((xkb->map->modmap == NULL) && + (XkbAllocClientMap(xkb, XkbModifierMapMask, 0) != Success)) { + return BadAlloc; + } + else { + bzero(&xkb->map->modmap[rep->firstModMapKey], rep->nModMapKeys); + } + i = XkbPaddedSize(2 * rep->totalModMapKeys); + wire = (unsigned char *) _XkbGetReadBufferPtr(buf, i); + if (!wire) + return BadLength; + for (i = 0; i < rep->totalModMapKeys; i++, wire += 2) { + if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code) + return BadLength; + xkb->map->modmap[wire[0]] = wire[1]; + } } return Success; } static Status -_XkbReadVirtualModMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) +_XkbReadVirtualModMap(XkbReadBufferPtr buf, + XkbDescPtr xkb, + xkbGetMapReply *rep) { -register int i; -xkbVModMapWireDesc * wire; -XkbServerMapPtr srv; - - if ( rep->totalVModMapKeys>0 ) { - if (((int) rep->firstVModMapKey + rep->nVModMapKeys) - > xkb->max_key_code + 1) - return BadLength; - if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&& - (XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) { - return BadAlloc; - } - else { - srv= xkb->server; - if (rep->nVModMapKeys > rep->firstVModMapKey) - bzero((char *)&srv->vmodmap[rep->firstVModMapKey], - (rep->nVModMapKeys - rep->firstVModMapKey) * - sizeof(unsigned short)); - } - srv= xkb->server; - i= rep->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc); - wire=(xkbVModMapWireDesc *)_XkbGetReadBufferPtr(buf,i); - if (!wire) - return BadLength; - for (i=0;i<rep->totalVModMapKeys;i++,wire++) { - if ((wire->key>=xkb->min_key_code)&&(wire->key<=xkb->max_key_code)) - srv->vmodmap[wire->key]= wire->vmods; - } + register int i; + xkbVModMapWireDesc *wire; + XkbServerMapPtr srv; + + if (rep->totalVModMapKeys > 0) { + if (((int) rep->firstVModMapKey + rep->nVModMapKeys) + > xkb->max_key_code + 1) + return BadLength; + if (((xkb->server == NULL) || (xkb->server->vmodmap == NULL)) && + (XkbAllocServerMap(xkb, XkbVirtualModMapMask, 0) != Success)) { + return BadAlloc; + } + else { + srv = xkb->server; + if (rep->nVModMapKeys > rep->firstVModMapKey) + bzero((char *) &srv->vmodmap[rep->firstVModMapKey], + (rep->nVModMapKeys - rep->firstVModMapKey) * + sizeof(unsigned short)); + } + srv = xkb->server; + i = rep->totalVModMapKeys * SIZEOF(xkbVModMapWireDesc); + wire = (xkbVModMapWireDesc *) _XkbGetReadBufferPtr(buf, i); + if (!wire) + return BadLength; + for (i = 0; i < rep->totalVModMapKeys; i++, wire++) { + if ((wire->key >= xkb->min_key_code) && + (wire->key <= xkb->max_key_code)) + srv->vmodmap[wire->key] = wire->vmods; + } } return Success; } static xkbGetMapReq * -_XkbGetGetMapReq(Display *dpy,XkbDescPtr xkb) +_XkbGetGetMapReq(Display *dpy, XkbDescPtr xkb) { -xkbGetMapReq *req; + xkbGetMapReq *req; GetReq(kbGetMap, req); req->reqType = dpy->xkb_info->codes->major_opcode; @@ -502,142 +518,147 @@ xkbGetMapReq *req; } Status -_XkbReadGetMapReply( Display * dpy, - xkbGetMapReply *rep, - XkbDescPtr xkb, - int * nread_rtrn) +_XkbReadGetMapReply(Display *dpy, + xkbGetMapReply *rep, + XkbDescPtr xkb, + int *nread_rtrn) { -int extraData; -unsigned mask; + int extraData; + unsigned mask; - if ( xkb->device_spec == XkbUseCoreKbd ) - xkb->device_spec= rep->deviceID; - if ( rep->maxKeyCode < rep->minKeyCode ) - return BadImplementation; + if (xkb->device_spec == XkbUseCoreKbd) + xkb->device_spec = rep->deviceID; + if (rep->maxKeyCode < rep->minKeyCode) + return BadImplementation; xkb->min_key_code = rep->minKeyCode; xkb->max_key_code = rep->maxKeyCode; if (!xkb->map) { - mask= rep->present&XkbAllClientInfoMask; - if (mask&&(XkbAllocClientMap(xkb,mask,rep->nTypes)!=Success)) - return BadAlloc; + mask = rep->present & XkbAllClientInfoMask; + if (mask && (XkbAllocClientMap(xkb, mask, rep->nTypes) != Success)) + return BadAlloc; } if (!xkb->server) { - mask= rep->present&XkbAllServerInfoMask; - if (mask&&(XkbAllocServerMap(xkb,mask,rep->totalActs)!=Success)) - return BadAlloc; + mask = rep->present & XkbAllServerInfoMask; + if (mask && (XkbAllocServerMap(xkb, mask, rep->totalActs) != Success)) + return BadAlloc; } - extraData= (int)(rep->length*4); - extraData-= (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)); + extraData = (int) (rep->length * 4); + extraData -= (SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)); if (rep->length) { - XkbReadBufferRec buf; - int left; - if (_XkbInitReadBuffer(dpy,&buf,extraData)) { - Status status= Success; - if (nread_rtrn!=NULL) - *nread_rtrn= extraData; - if (status==Success) - status= _XkbReadKeyTypes(&buf,xkb,rep); - if (status==Success) - status= _XkbReadKeySyms(&buf,xkb,rep); - if (status==Success) - status= _XkbReadKeyActions(&buf,xkb,rep); - if (status==Success) - status= _XkbReadKeyBehaviors(&buf,xkb,rep); - if (status==Success) - status= _XkbReadVirtualMods(&buf,xkb,rep); - if (status==Success) - status= _XkbReadExplicitComponents(&buf,xkb,rep); - if (status==Success) - status= _XkbReadModifierMap(&buf,xkb,rep); - if (status==Success) - status= _XkbReadVirtualModMap(&buf,xkb,rep); - left= _XkbFreeReadBuffer(&buf); - if (status!=Success) return status; - else if ( left || buf.error ) return BadLength; - } - else return BadAlloc; + XkbReadBufferRec buf; + int left; + + if (_XkbInitReadBuffer(dpy, &buf, extraData)) { + Status status = Success; + + if (nread_rtrn != NULL) + *nread_rtrn = extraData; + if (status == Success) + status = _XkbReadKeyTypes(&buf, xkb, rep); + if (status == Success) + status = _XkbReadKeySyms(&buf, xkb, rep); + if (status == Success) + status = _XkbReadKeyActions(&buf, xkb, rep); + if (status == Success) + status = _XkbReadKeyBehaviors(&buf, xkb, rep); + if (status == Success) + status = _XkbReadVirtualMods(&buf, xkb, rep); + if (status == Success) + status = _XkbReadExplicitComponents(&buf, xkb, rep); + if (status == Success) + status = _XkbReadModifierMap(&buf, xkb, rep); + if (status == Success) + status = _XkbReadVirtualModMap(&buf, xkb, rep); + left = _XkbFreeReadBuffer(&buf); + if (status != Success) + return status; + else if (left || buf.error) + return BadLength; + } + else + return BadAlloc; } return Success; } static Status -_XkbHandleGetMapReply(Display *dpy,XkbDescPtr xkb) +_XkbHandleGetMapReply(Display *dpy, XkbDescPtr xkb) { -xkbGetMapReply rep; + xkbGetMapReply rep; - if (!_XReply(dpy, (xReply *)&rep, - ( (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)) >> 2 ), - xFalse)) { - return BadImplementation; + if (!_XReply(dpy, (xReply *) &rep, + ((SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)) >> 2), + xFalse)) { + return BadImplementation; } - return _XkbReadGetMapReply(dpy,&rep,xkb,NULL); + return _XkbReadGetMapReply(dpy, &rep, xkb, NULL); } Status -XkbGetUpdatedMap(Display *dpy,unsigned which,XkbDescPtr xkb) +XkbGetUpdatedMap(Display *dpy, unsigned which, XkbDescPtr xkb) { if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; if (which) { - register xkbGetMapReq *req; - Status status; + register xkbGetMapReq *req; + Status status; - LockDisplay(dpy); + LockDisplay(dpy); - req = _XkbGetGetMapReq(dpy, xkb); - req->full = which; - status= _XkbHandleGetMapReply(dpy, xkb); + req = _XkbGetGetMapReq(dpy, xkb); + req->full = which; + status = _XkbHandleGetMapReply(dpy, xkb); - UnlockDisplay(dpy); - SyncHandle(); - return status; + UnlockDisplay(dpy); + SyncHandle(); + return status; } return Success; } XkbDescPtr -XkbGetMap(Display *dpy,unsigned which,unsigned deviceSpec) +XkbGetMap(Display *dpy, unsigned which, unsigned deviceSpec) { -XkbDescPtr xkb; + XkbDescPtr xkb; - xkb = _XkbTypedCalloc(1,XkbDescRec); + xkb = _XkbTypedCalloc(1, XkbDescRec); if (xkb) { - xkb->device_spec = deviceSpec; - xkb->map = _XkbTypedCalloc(1,XkbClientMapRec); - if ((xkb->map==NULL)|| - ((which)&&(XkbGetUpdatedMap(dpy,which,xkb)!=Success))) { - if (xkb->map) { - Xfree(xkb->map); - xkb->map= NULL; - } - Xfree(xkb); - return NULL; - } - xkb->dpy= dpy; + xkb->device_spec = deviceSpec; + xkb->map = _XkbTypedCalloc(1, XkbClientMapRec); + if ((xkb->map == NULL) || + ((which) && (XkbGetUpdatedMap(dpy, which, xkb) != Success))) { + if (xkb->map) { + Xfree(xkb->map); + xkb->map = NULL; + } + Xfree(xkb); + return NULL; + } + xkb->dpy = dpy; } return xkb; } Status -XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) +XkbGetKeyTypes(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; - if ((num<1)||(num>XkbMaxKeyTypes)) - return BadValue; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; + if ((num < 1) || (num > XkbMaxKeyTypes)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstType = first; req->nTypes = num; - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); UnlockDisplay(dpy); SyncHandle(); @@ -645,24 +666,24 @@ XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) } Status -XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) +XkbGetKeyActions(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; - if ((num<1)||(num>XkbMaxKeyCount)) - return BadValue; + if ((num < 1) || (num > XkbMaxKeyCount)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstKeyAct = first; req->nKeyActs = num; - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); UnlockDisplay(dpy); SyncHandle(); @@ -670,24 +691,24 @@ XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) } Status -XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) +XkbGetKeySyms(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; - if ((num<1)||(num>XkbMaxKeyCount)) - return BadValue; + if ((num < 1) || (num > XkbMaxKeyCount)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstKeySym = first; req->nKeySyms = num; - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); UnlockDisplay(dpy); SyncHandle(); @@ -696,24 +717,24 @@ XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) } Status -XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) +XkbGetKeyBehaviors(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; - if ((num<1)||(num>XkbMaxKeyCount)) - return BadValue; + if ((num < 1) || (num > XkbMaxKeyCount)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstKeyBehavior = first; req->nKeyBehaviors = num; - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); UnlockDisplay(dpy); SyncHandle(); @@ -721,20 +742,20 @@ XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) } Status -XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb) +XkbGetVirtualMods(Display *dpy, unsigned which, XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->virtualMods = which; - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); UnlockDisplay(dpy); SyncHandle(); @@ -742,32 +763,34 @@ XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb) } Status -XkbGetKeyExplicitComponents( Display * dpy, - unsigned first, - unsigned num, - XkbDescPtr xkb) +XkbGetKeyExplicitComponents(Display *dpy, + unsigned first, + unsigned num, + XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; - if ((num<1)||(num>XkbMaxKeyCount)) - return BadValue; + if ((num < 1) || (num > XkbMaxKeyCount)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstKeyExplicit = first; req->nKeyExplicit = num; - if ((xkb!=NULL) && (xkb->server!=NULL) && (xkb->server->explicit!=NULL)) { - if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code)) - bzero(&xkb->server->explicit[first],num); + if ((xkb != NULL) && (xkb->server != NULL) && + (xkb->server->explicit != NULL)) { + if ((num > 0) && (first >= xkb->min_key_code) && + (first + num <= xkb->max_key_code)) + bzero(&xkb->server->explicit[first], num); } if (xkb) - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); else status = BadMatch; @@ -777,29 +800,33 @@ XkbGetKeyExplicitComponents( Display * dpy, } Status -XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) +XkbGetKeyModifierMap(Display *dpy, + unsigned first, + unsigned num, + XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; - if ((num<1)||(num>XkbMaxKeyCount)) - return BadValue; + if ((num < 1) || (num > XkbMaxKeyCount)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstModMapKey = first; req->nModMapKeys = num; - if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) { - if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code)) - bzero(&xkb->map->modmap[first],num); + if ((xkb != NULL) && (xkb->map != NULL) && (xkb->map->modmap != NULL)) { + if ((num > 0) && (first >= xkb->min_key_code) && + (first + num <= xkb->max_key_code)) + bzero(&xkb->map->modmap[first], num); } if (xkb) - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); else status = BadMatch; @@ -809,30 +836,32 @@ XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) } Status -XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) +XkbGetKeyVirtualModMap(Display *dpy, unsigned first, unsigned num, + XkbDescPtr xkb) { register xkbGetMapReq *req; Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; - if ((num<1)||(num>XkbMaxKeyCount)) - return BadValue; + if ((num < 1) || (num > XkbMaxKeyCount)) + return BadValue; LockDisplay(dpy); req = _XkbGetGetMapReq(dpy, xkb); req->firstVModMapKey = first; req->nVModMapKeys = num; - if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) { - if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code)) - bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short)); + if ((xkb != NULL) && (xkb->map != NULL) && (xkb->map->modmap != NULL)) { + if ((num > 0) && (first >= xkb->min_key_code) && + (first + num <= xkb->max_key_code)) + bzero(&xkb->server->vmodmap[first], num * sizeof(unsigned short)); } if (xkb) - status= _XkbHandleGetMapReply(dpy, xkb); + status = _XkbHandleGetMapReply(dpy, xkb); else status = BadMatch; @@ -842,40 +871,40 @@ XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) } Status -XkbGetMapChanges(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes) +XkbGetMapChanges(Display *dpy, XkbDescPtr xkb, XkbMapChangesPtr changes) { xkbGetMapReq *req; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); if (changes->changed) { - Status status= Success; - req = _XkbGetGetMapReq(dpy, xkb); - req->full = 0; - req->partial = changes->changed; - req->firstType = changes->first_type; - req->nTypes = changes->num_types; - req->firstKeySym = changes->first_key_sym; - req->nKeySyms = changes->num_key_syms; - req->firstKeyAct = changes->first_key_act; - req->nKeyActs = changes->num_key_acts; - req->firstKeyBehavior = changes->first_key_behavior; - req->nKeyBehaviors = changes->num_key_behaviors; - req->virtualMods = changes->vmods; - req->firstKeyExplicit = changes->first_key_explicit; - req->nKeyExplicit = changes->num_key_explicit; - req->firstModMapKey = changes->first_modmap_key; - req->nModMapKeys = changes->num_modmap_keys; - req->firstVModMapKey = changes->first_vmodmap_key; - req->nVModMapKeys = changes->num_vmodmap_keys; - status= _XkbHandleGetMapReply(dpy, xkb); - UnlockDisplay(dpy); - SyncHandle(); - return status; + Status status = Success; + + req = _XkbGetGetMapReq(dpy, xkb); + req->full = 0; + req->partial = changes->changed; + req->firstType = changes->first_type; + req->nTypes = changes->num_types; + req->firstKeySym = changes->first_key_sym; + req->nKeySyms = changes->num_key_syms; + req->firstKeyAct = changes->first_key_act; + req->nKeyActs = changes->num_key_acts; + req->firstKeyBehavior = changes->first_key_behavior; + req->nKeyBehaviors = changes->num_key_behaviors; + req->virtualMods = changes->vmods; + req->firstKeyExplicit = changes->first_key_explicit; + req->nKeyExplicit = changes->num_key_explicit; + req->firstModMapKey = changes->first_modmap_key; + req->nModMapKeys = changes->num_modmap_keys; + req->firstVModMapKey = changes->first_vmodmap_key; + req->nVModMapKeys = changes->num_vmodmap_keys; + status = _XkbHandleGetMapReply(dpy, xkb); + UnlockDisplay(dpy); + SyncHandle(); + return status; } UnlockDisplay(dpy); return Success; } - diff --git a/libX11/src/xkb/XKBList.c b/libX11/src/xkb/XKBList.c index 8f245f245..55a37b806 100644 --- a/libX11/src/xkb/XKBList.c +++ b/libX11/src/xkb/XKBList.c @@ -35,18 +35,18 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ static void -_FreeComponentNames(int num,XkbComponentNamePtr names) +_FreeComponentNames(int num, XkbComponentNamePtr names) { -int i; -XkbComponentNamePtr tmp; - - if ((num<1)||(names==NULL)) - return; - for (i=0,tmp=names;i<num;i++,tmp++) { - if (tmp->name) { - _XkbFree(tmp->name); - tmp->name= NULL; - } + int i; + XkbComponentNamePtr tmp; + + if ((num < 1) || (names == NULL)) + return; + for (i = 0, tmp = names; i < num; i++, tmp++) { + if (tmp->name) { + _XkbFree(tmp->name); + tmp->name = NULL; + } } _XkbFree(names); return; @@ -55,172 +55,179 @@ XkbComponentNamePtr tmp; /***====================================================================***/ static XkbComponentNamePtr -_ReadListing(XkbReadBufferPtr buf,int count,Status *status_rtrn) +_ReadListing(XkbReadBufferPtr buf, int count, Status * status_rtrn) { -XkbComponentNamePtr first,this; -register int i; -CARD16 * flags; -int slen,wlen; -char * str; - - if (count<1) - return NULL; - first= _XkbTypedCalloc(count,XkbComponentNameRec); + XkbComponentNamePtr first, this; + register int i; + CARD16 *flags; + int slen, wlen; + char *str; + + if (count < 1) + return NULL; + first = _XkbTypedCalloc(count, XkbComponentNameRec); if (!first) - return NULL; - for (this=first,i=0;i<count;i++,this++) { - flags= (CARD16 *)_XkbGetReadBufferPtr(buf,2*sizeof(CARD16)); - if (!flags) - goto BAILOUT; - this->flags= flags[0]; - slen= flags[1]; - wlen= ((slen+1)/2)*2; /* pad to 2 byte boundary */ - this->name= _XkbTypedCalloc(slen+1,char); - if (!this->name) - goto BAILOUT; - str= (char *)_XkbGetReadBufferPtr(buf,wlen); - if (!str) - goto BAILOUT; - memcpy(this->name,str,slen); + return NULL; + for (this = first, i = 0; i < count; i++, this++) { + flags = (CARD16 *) _XkbGetReadBufferPtr(buf, 2 * sizeof(CARD16)); + if (!flags) + goto BAILOUT; + this->flags = flags[0]; + slen = flags[1]; + wlen = ((slen + 1) / 2) * 2; /* pad to 2 byte boundary */ + this->name = _XkbTypedCalloc(slen + 1, char); + + if (!this->name) + goto BAILOUT; + str = (char *) _XkbGetReadBufferPtr(buf, wlen); + if (!str) + goto BAILOUT; + memcpy(this->name, str, slen); } return first; -BAILOUT: - *status_rtrn= BadAlloc; - _FreeComponentNames(i,first); + BAILOUT: + *status_rtrn = BadAlloc; + _FreeComponentNames(i, first); return NULL; } /***====================================================================***/ XkbComponentListPtr -XkbListComponents( Display * dpy, - unsigned deviceSpec, - XkbComponentNamesPtr ptrns, - int * max_inout) +XkbListComponents(Display *dpy, + unsigned deviceSpec, + XkbComponentNamesPtr ptrns, + int *max_inout) { -register xkbListComponentsReq* req; -xkbListComponentsReply rep; -XkbInfoPtr xkbi; -XkbComponentListPtr list; -XkbReadBufferRec buf; -int left; -char * str; -int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen; - - if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || - (ptrns==NULL) || (max_inout==NULL)) - return NULL; - - xkbi= dpy->xkb_info; + register xkbListComponentsReq *req; + xkbListComponentsReply rep; + XkbInfoPtr xkbi; + XkbComponentListPtr list; + XkbReadBufferRec buf; + int left; + char *str; + int extraLen, len, mapLen, codesLen, typesLen, compatLen, symsLen, geomLen; + + if ((dpy == NULL) || (dpy->flags & XlibDisplayNoXkb) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || + (ptrns == NULL) || (max_inout == NULL)) + return NULL; + + xkbi = dpy->xkb_info; LockDisplay(dpy); GetReq(kbListComponents, req); - req->reqType = xkbi->codes->major_opcode; - req->xkbReqType = X_kbListComponents; - req->deviceSpec = deviceSpec; - req->maxNames = *max_inout; + req->reqType = xkbi->codes->major_opcode; + req->xkbReqType = X_kbListComponents; + req->deviceSpec = deviceSpec; + req->maxNames = *max_inout; - mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; + mapLen = codesLen = typesLen = compatLen = symsLen = geomLen = 0; if (ptrns->keymap) - mapLen= (int)strlen(ptrns->keymap); + mapLen = (int) strlen(ptrns->keymap); if (ptrns->keycodes) - codesLen= (int)strlen(ptrns->keycodes); + codesLen = (int) strlen(ptrns->keycodes); if (ptrns->types) - typesLen= (int)strlen(ptrns->types); + typesLen = (int) strlen(ptrns->types); if (ptrns->compat) - compatLen= (int)strlen(ptrns->compat); + compatLen = (int) strlen(ptrns->compat); if (ptrns->symbols) - symsLen= (int)strlen(ptrns->symbols); + symsLen = (int) strlen(ptrns->symbols); if (ptrns->geometry) - geomLen= (int)strlen(ptrns->geometry); - if (mapLen>255) mapLen= 255; - if (codesLen>255) codesLen= 255; - if (typesLen>255) typesLen= 255; - if (compatLen>255) compatLen= 255; - if (symsLen>255) symsLen= 255; - if (geomLen>255) geomLen= 255; - - len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; - len= XkbPaddedSize(len); - req->length+= len/4; - BufAlloc(char *,str,len); - *str++= mapLen; - if (mapLen>0) { - memcpy(str,ptrns->keymap,mapLen); - str+= mapLen; + geomLen = (int) strlen(ptrns->geometry); + if (mapLen > 255) + mapLen = 255; + if (codesLen > 255) + codesLen = 255; + if (typesLen > 255) + typesLen = 255; + if (compatLen > 255) + compatLen = 255; + if (symsLen > 255) + symsLen = 255; + if (geomLen > 255) + geomLen = 255; + + len = mapLen + codesLen + typesLen + compatLen + symsLen + geomLen + 6; + len = XkbPaddedSize(len); + req->length += len / 4; + BufAlloc(char *, str, len); + + *str++ = mapLen; + if (mapLen > 0) { + memcpy(str, ptrns->keymap, mapLen); + str += mapLen; } - *str++= codesLen; - if (codesLen>0) { - memcpy(str,ptrns->keycodes,codesLen); - str+= codesLen; + *str++ = codesLen; + if (codesLen > 0) { + memcpy(str, ptrns->keycodes, codesLen); + str += codesLen; } - *str++= typesLen; - if (typesLen>0) { - memcpy(str,ptrns->types,typesLen); - str+= typesLen; + *str++ = typesLen; + if (typesLen > 0) { + memcpy(str, ptrns->types, typesLen); + str += typesLen; } - *str++= compatLen; - if (compatLen>0) { - memcpy(str,ptrns->compat,compatLen); - str+= compatLen; + *str++ = compatLen; + if (compatLen > 0) { + memcpy(str, ptrns->compat, compatLen); + str += compatLen; } - *str++= symsLen; - if (symsLen>0) { - memcpy(str,ptrns->symbols,symsLen); - str+= symsLen; + *str++ = symsLen; + if (symsLen > 0) { + memcpy(str, ptrns->symbols, symsLen); + str += symsLen; } - *str++= geomLen; - if (geomLen>0) { - memcpy(str,ptrns->geometry,geomLen); - str+= geomLen; + *str++ = geomLen; + if (geomLen > 0) { + memcpy(str, ptrns->geometry, geomLen); + str += geomLen; } - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) - goto BAILOUT; - extraLen= (int)rep.length*4; - *max_inout= rep.extra; - if (extraLen==0) { /* no matches, but we don't want to report a failure */ - list= _XkbTypedCalloc(1,XkbComponentListRec); - UnlockDisplay(dpy); - SyncHandle(); - return list; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) + goto BAILOUT; + extraLen = (int) rep.length * 4; + *max_inout = rep.extra; + if (extraLen == 0) { /* no matches, but we don't want to report a failure */ + list = _XkbTypedCalloc(1, XkbComponentListRec); + UnlockDisplay(dpy); + SyncHandle(); + return list; } - if (_XkbInitReadBuffer(dpy,&buf,extraLen)) { - Status status; - - status= Success; - list= _XkbTypedCalloc(1,XkbComponentListRec); - if (!list) { - _XkbFreeReadBuffer(&buf); - goto BAILOUT; - } - list->num_keymaps= rep.nKeymaps; - list->num_keycodes= rep.nKeycodes; - list->num_types= rep.nTypes; - list->num_compat= rep.nCompatMaps; - list->num_symbols= rep.nSymbols; - list->num_geometry= rep.nGeometries; - if ((status==Success)&&(list->num_keymaps>0)) - list->keymaps= _ReadListing(&buf,list->num_keymaps,&status); - if ((status==Success)&&(list->num_keycodes>0)) - list->keycodes= _ReadListing(&buf,list->num_keycodes,&status); - if ((status==Success)&&(list->num_types>0)) - list->types= _ReadListing(&buf,list->num_types,&status); - if ((status==Success)&&(list->num_compat>0)) - list->compat= _ReadListing(&buf,list->num_compat,&status); - if ((status==Success)&&(list->num_symbols>0)) - list->symbols= _ReadListing(&buf,list->num_symbols,&status); - if ((status==Success)&&(list->num_geometry>0)) - list->geometry= _ReadListing(&buf,list->num_geometry,&status); - left= _XkbFreeReadBuffer(&buf); - if ((status!=Success)||(buf.error)||(left>2)) { - XkbFreeComponentList(list); - goto BAILOUT; - } - UnlockDisplay(dpy); - SyncHandle(); - return list; + if (_XkbInitReadBuffer(dpy, &buf, extraLen)) { + Status status = Success; + + list = _XkbTypedCalloc(1, XkbComponentListRec); + if (!list) { + _XkbFreeReadBuffer(&buf); + goto BAILOUT; + } + list->num_keymaps = rep.nKeymaps; + list->num_keycodes = rep.nKeycodes; + list->num_types = rep.nTypes; + list->num_compat = rep.nCompatMaps; + list->num_symbols = rep.nSymbols; + list->num_geometry = rep.nGeometries; + if ((status == Success) && (list->num_keymaps > 0)) + list->keymaps = _ReadListing(&buf, list->num_keymaps, &status); + if ((status == Success) && (list->num_keycodes > 0)) + list->keycodes = _ReadListing(&buf, list->num_keycodes, &status); + if ((status == Success) && (list->num_types > 0)) + list->types = _ReadListing(&buf, list->num_types, &status); + if ((status == Success) && (list->num_compat > 0)) + list->compat = _ReadListing(&buf, list->num_compat, &status); + if ((status == Success) && (list->num_symbols > 0)) + list->symbols = _ReadListing(&buf, list->num_symbols, &status); + if ((status == Success) && (list->num_geometry > 0)) + list->geometry = _ReadListing(&buf, list->num_geometry, &status); + left = _XkbFreeReadBuffer(&buf); + if ((status != Success) || (buf.error) || (left > 2)) { + XkbFreeComponentList(list); + goto BAILOUT; + } + UnlockDisplay(dpy); + SyncHandle(); + return list; } -BAILOUT: + BAILOUT: UnlockDisplay(dpy); SyncHandle(); return NULL; @@ -230,20 +237,20 @@ void XkbFreeComponentList(XkbComponentListPtr list) { if (list) { - if (list->keymaps) - _FreeComponentNames(list->num_keymaps,list->keymaps); - if (list->keycodes) - _FreeComponentNames(list->num_keycodes,list->keycodes); - if (list->types) - _FreeComponentNames(list->num_types,list->types); - if (list->compat) - _FreeComponentNames(list->num_compat,list->compat); - if (list->symbols) - _FreeComponentNames(list->num_symbols,list->symbols); - if (list->geometry) - _FreeComponentNames(list->num_geometry,list->geometry); - bzero((char *)list,sizeof(XkbComponentListRec)); - _XkbFree(list); + if (list->keymaps) + _FreeComponentNames(list->num_keymaps, list->keymaps); + if (list->keycodes) + _FreeComponentNames(list->num_keycodes, list->keycodes); + if (list->types) + _FreeComponentNames(list->num_types, list->types); + if (list->compat) + _FreeComponentNames(list->num_compat, list->compat); + if (list->symbols) + _FreeComponentNames(list->num_symbols, list->symbols); + if (list->geometry) + _FreeComponentNames(list->num_geometry, list->geometry); + bzero((char *) list, sizeof(XkbComponentListRec)); + _XkbFree(list); } return; } diff --git a/libX11/src/xkb/XKBMAlloc.c b/libX11/src/xkb/XKBMAlloc.c index fd75f0c8a..f27fe4ec3 100644 --- a/libX11/src/xkb/XKBMAlloc.c +++ b/libX11/src/xkb/XKBMAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -41,176 +39,182 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ Status -XkbAllocClientMap(XkbDescPtr xkb,unsigned which,unsigned nTotalTypes) +XkbAllocClientMap(XkbDescPtr xkb, unsigned which, unsigned nTotalTypes) { -register int i; -XkbClientMapPtr map; - - if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes))) - return BadValue; - if ((which&XkbKeySymsMask)&& - ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code))) { + register int i; + XkbClientMapPtr map; + + if ((xkb == NULL) || + ((nTotalTypes > 0) && (nTotalTypes < XkbNumRequiredTypes))) + return BadValue; + if ((which & XkbKeySymsMask) && + ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code))) { #ifdef DEBUG -fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n", - xkb->min_key_code,xkb->max_key_code); + fprintf(stderr, "bad keycode (%d,%d) in XkbAllocClientMap\n", + xkb->min_key_code, xkb->max_key_code); #endif - return BadValue; - } - - if (xkb->map==NULL) { - map= _XkbTypedCalloc(1,XkbClientMapRec); - if (map==NULL) - return BadAlloc; - xkb->map= map; - } - else map= xkb->map; - - if ((which&XkbKeyTypesMask)&&(nTotalTypes>0)) { - if (map->types==NULL) { - map->types= _XkbTypedCalloc(nTotalTypes,XkbKeyTypeRec); - if (map->types==NULL) - return BadAlloc; - map->num_types= 0; - map->size_types= nTotalTypes; - } - else if (map->size_types<nTotalTypes) { - XkbKeyTypeRec *prev_types = map->types; - - map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec); - if (map->types==NULL) { - _XkbFree(prev_types); - map->num_types= map->size_types= 0; - return BadAlloc; - } - map->size_types= nTotalTypes; - bzero(&map->types[map->num_types], - ((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec))); - } - } - if (which&XkbKeySymsMask) { - int nKeys= XkbNumKeys(xkb); - if (map->syms==NULL) { - map->size_syms= (nKeys*15)/10; - map->syms= _XkbTypedCalloc(map->size_syms,KeySym); - if (!map->syms) { - map->size_syms= 0; - return BadAlloc; - } - map->num_syms= 1; - map->syms[0]= NoSymbol; - } - if (map->key_sym_map==NULL) { - i= xkb->max_key_code+1; - map->key_sym_map= _XkbTypedCalloc(i,XkbSymMapRec); - if (map->key_sym_map==NULL) - return BadAlloc; - } - } - if (which&XkbModifierMapMask) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadMatch; - if (map->modmap==NULL) { - i= xkb->max_key_code+1; - map->modmap= _XkbTypedCalloc(i,unsigned char); - if (map->modmap==NULL) - return BadAlloc; - } + return BadValue; + } + + if (xkb->map == NULL) { + map = _XkbTypedCalloc(1, XkbClientMapRec); + if (map == NULL) + return BadAlloc; + xkb->map = map; + } + else + map = xkb->map; + + if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) { + if (map->types == NULL) { + map->types = _XkbTypedCalloc(nTotalTypes, XkbKeyTypeRec); + if (map->types == NULL) + return BadAlloc; + map->num_types = 0; + map->size_types = nTotalTypes; + } + else if (map->size_types < nTotalTypes) { + XkbKeyTypeRec *prev_types = map->types; + + map->types = + _XkbTypedRealloc(map->types, nTotalTypes, XkbKeyTypeRec); + if (map->types == NULL) { + _XkbFree(prev_types); + map->num_types = map->size_types = 0; + return BadAlloc; + } + map->size_types = nTotalTypes; + bzero(&map->types[map->num_types], + ((map->size_types - map->num_types) * sizeof(XkbKeyTypeRec))); + } + } + if (which & XkbKeySymsMask) { + int nKeys = XkbNumKeys(xkb); + + if (map->syms == NULL) { + map->size_syms = (nKeys * 15) / 10; + map->syms = _XkbTypedCalloc(map->size_syms, KeySym); + if (!map->syms) { + map->size_syms = 0; + return BadAlloc; + } + map->num_syms = 1; + map->syms[0] = NoSymbol; + } + if (map->key_sym_map == NULL) { + i = xkb->max_key_code + 1; + map->key_sym_map = _XkbTypedCalloc(i, XkbSymMapRec); + if (map->key_sym_map == NULL) + return BadAlloc; + } + } + if (which & XkbModifierMapMask) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadMatch; + if (map->modmap == NULL) { + i = xkb->max_key_code + 1; + map->modmap = _XkbTypedCalloc(i, unsigned char); + if (map->modmap == NULL) + return BadAlloc; + } } return Success; } Status -XkbAllocServerMap(XkbDescPtr xkb,unsigned which,unsigned nNewActions) +XkbAllocServerMap(XkbDescPtr xkb, unsigned which, unsigned nNewActions) { -register int i; -XkbServerMapPtr map; - - if (xkb==NULL) - return BadMatch; - if (xkb->server==NULL) { - map= _XkbTypedCalloc(1,XkbServerMapRec); - if (map==NULL) - return BadAlloc; - for (i=0;i<XkbNumVirtualMods;i++) { - map->vmods[i]= XkbNoModifierMask; - } - xkb->server= map; - } - else map= xkb->server; - if (which&XkbExplicitComponentsMask) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadMatch; - if (map->explicit==NULL) { - i= xkb->max_key_code+1; - map->explicit= _XkbTypedCalloc(i,unsigned char); - if (map->explicit==NULL) - return BadAlloc; - } - } - if (which&XkbKeyActionsMask) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadMatch; - if (nNewActions<1) - nNewActions= 1; - if (map->acts==NULL) { - map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction); - if (map->acts==NULL) - return BadAlloc; - map->num_acts= 1; - map->size_acts= nNewActions+1; - } - else if ((map->size_acts-map->num_acts)<nNewActions) { - unsigned need; - XkbAction *prev_acts = map->acts; - need= map->num_acts+nNewActions; - map->acts= _XkbTypedRealloc(map->acts,need,XkbAction); - if (map->acts==NULL) { - _XkbFree(prev_acts); - map->num_acts= map->size_acts= 0; - return BadAlloc; - } - map->size_acts= need; - bzero(&map->acts[map->num_acts], - ((map->size_acts-map->num_acts)*sizeof(XkbAction))); - } - if (map->key_acts==NULL) { - i= xkb->max_key_code+1; - map->key_acts= _XkbTypedCalloc(i,unsigned short); - if (map->key_acts==NULL) - return BadAlloc; - } - } - if (which&XkbKeyBehaviorsMask) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadMatch; - if (map->behaviors==NULL) { - i= xkb->max_key_code+1; - map->behaviors= _XkbTypedCalloc(i,XkbBehavior); - if (map->behaviors==NULL) - return BadAlloc; - } - } - if (which&XkbVirtualModMapMask) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadMatch; - if (map->vmodmap==NULL) { - i= xkb->max_key_code+1; - map->vmodmap= _XkbTypedCalloc(i,unsigned short); - if (map->vmodmap==NULL) - return BadAlloc; - } + register int i; + XkbServerMapPtr map; + + if (xkb == NULL) + return BadMatch; + if (xkb->server == NULL) { + map = _XkbTypedCalloc(1, XkbServerMapRec); + if (map == NULL) + return BadAlloc; + for (i = 0; i < XkbNumVirtualMods; i++) { + map->vmods[i] = XkbNoModifierMask; + } + xkb->server = map; + } + else + map = xkb->server; + if (which & XkbExplicitComponentsMask) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadMatch; + if (map->explicit == NULL) { + i = xkb->max_key_code + 1; + map->explicit = _XkbTypedCalloc(i, unsigned char); + if (map->explicit == NULL) + return BadAlloc; + } + } + if (which & XkbKeyActionsMask) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadMatch; + if (nNewActions < 1) + nNewActions = 1; + if (map->acts == NULL) { + map->acts = _XkbTypedCalloc((nNewActions + 1), XkbAction); + if (map->acts == NULL) + return BadAlloc; + map->num_acts = 1; + map->size_acts = nNewActions + 1; + } + else if ((map->size_acts - map->num_acts) < nNewActions) { + unsigned need; + XkbAction *prev_acts = map->acts; + + need = map->num_acts + nNewActions; + map->acts = _XkbTypedRealloc(map->acts, need, XkbAction); + if (map->acts == NULL) { + _XkbFree(prev_acts); + map->num_acts = map->size_acts = 0; + return BadAlloc; + } + map->size_acts = need; + bzero(&map->acts[map->num_acts], + ((map->size_acts - map->num_acts) * sizeof(XkbAction))); + } + if (map->key_acts == NULL) { + i = xkb->max_key_code + 1; + map->key_acts = _XkbTypedCalloc(i, unsigned short); + if (map->key_acts == NULL) + return BadAlloc; + } + } + if (which & XkbKeyBehaviorsMask) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadMatch; + if (map->behaviors == NULL) { + i = xkb->max_key_code + 1; + map->behaviors = _XkbTypedCalloc(i, XkbBehavior); + if (map->behaviors == NULL) + return BadAlloc; + } + } + if (which & XkbVirtualModMapMask) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadMatch; + if (map->vmodmap == NULL) { + i = xkb->max_key_code + 1; + map->vmodmap = _XkbTypedCalloc(i, unsigned short); + if (map->vmodmap == NULL) + return BadAlloc; + } } return Success; } @@ -218,211 +222,218 @@ XkbServerMapPtr map; /***====================================================================***/ Status -XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into) +XkbCopyKeyType(XkbKeyTypePtr from, XkbKeyTypePtr into) { - if ((!from)||(!into)) - return BadMatch; + if ((!from) || (!into)) + return BadMatch; if (into->map) { - _XkbFree(into->map); - into->map= NULL; + _XkbFree(into->map); + into->map = NULL; } if (into->preserve) { - _XkbFree(into->preserve); - into->preserve= NULL; + _XkbFree(into->preserve); + into->preserve = NULL; } if (into->level_names) { - _XkbFree(into->level_names); - into->level_names= NULL; - } - *into= *from; - if ((from->map)&&(into->map_count>0)) { - into->map= _XkbTypedCalloc(into->map_count,XkbKTMapEntryRec); - if (!into->map) - return BadAlloc; - memcpy(into->map,from->map,into->map_count*sizeof(XkbKTMapEntryRec)); - } - if ((from->preserve)&&(into->map_count>0)) { - into->preserve= _XkbTypedCalloc(into->map_count,XkbModsRec); - if (!into->preserve) - return BadAlloc; - memcpy(into->preserve,from->preserve, - into->map_count*sizeof(XkbModsRec)); - } - if ((from->level_names)&&(into->num_levels>0)) { - into->level_names= _XkbTypedCalloc(into->num_levels,Atom); - if (!into->level_names) - return BadAlloc; - memcpy(into->level_names,from->level_names, - into->num_levels*sizeof(Atom)); + _XkbFree(into->level_names); + into->level_names = NULL; + } + *into = *from; + if ((from->map) && (into->map_count > 0)) { + into->map = _XkbTypedCalloc(into->map_count, XkbKTMapEntryRec); + if (!into->map) + return BadAlloc; + memcpy(into->map, from->map, + into->map_count * sizeof(XkbKTMapEntryRec)); + } + if ((from->preserve) && (into->map_count > 0)) { + into->preserve = _XkbTypedCalloc(into->map_count, XkbModsRec); + if (!into->preserve) + return BadAlloc; + memcpy(into->preserve, from->preserve, + into->map_count * sizeof(XkbModsRec)); + } + if ((from->level_names) && (into->num_levels > 0)) { + into->level_names = _XkbTypedCalloc(into->num_levels, Atom); + if (!into->level_names) + return BadAlloc; + memcpy(into->level_names, from->level_names, + into->num_levels * sizeof(Atom)); } return Success; } Status -XkbCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types) +XkbCopyKeyTypes(XkbKeyTypePtr from, XkbKeyTypePtr into, int num_types) { -register int i,rtrn; + register int i, rtrn; - if ((!from)||(!into)||(num_types<0)) - return BadMatch; - for (i=0;i<num_types;i++) { - if ((rtrn= XkbCopyKeyType(from++,into++))!=Success) - return rtrn; + if ((!from) || (!into) || (num_types < 0)) + return BadMatch; + for (i = 0; i < num_types; i++) { + if ((rtrn = XkbCopyKeyType(from++, into++)) != Success) + return rtrn; } return Success; } XkbKeyTypePtr -XkbAddKeyType( XkbDescPtr xkb, - Atom name, - int map_count, - Bool want_preserve, - int num_lvls) +XkbAddKeyType(XkbDescPtr xkb, + Atom name, + int map_count, + Bool want_preserve, + int num_lvls) { -register int i; -unsigned tmp; -XkbKeyTypePtr type; -XkbClientMapPtr map; - - if ((!xkb)||(num_lvls<1)) - return NULL; - map= xkb->map; - if ((map)&&(map->types)) { - for (i=0;i<map->num_types;i++) { - if (map->types[i].name==name) { - Status status; - status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls); - return (status==Success?&map->types[i]:NULL); - } - } - } - if ((!map)||(!map->types)||(!map->num_types<XkbNumRequiredTypes)) { - tmp= XkbNumRequiredTypes+1; - if (XkbAllocClientMap(xkb,XkbKeyTypesMask,tmp)!=Success) - return NULL; + register int i; + unsigned tmp; + XkbKeyTypePtr type; + XkbClientMapPtr map; + + if ((!xkb) || (num_lvls < 1)) + return NULL; + map = xkb->map; + if ((map) && (map->types)) { + for (i = 0; i < map->num_types; i++) { + if (map->types[i].name == name) { + Status status = + XkbResizeKeyType(xkb, i, map_count, want_preserve, + num_lvls); + return (status == Success ? &map->types[i] : NULL); + } + } + } + if ((!map) || (!map->types) || (!map->num_types < XkbNumRequiredTypes)) { + tmp = XkbNumRequiredTypes + 1; + if (XkbAllocClientMap(xkb, XkbKeyTypesMask, tmp) != Success) + return NULL; if (!map) map = xkb->map; - tmp= 0; - if (map->num_types<=XkbKeypadIndex) - tmp|= XkbKeypadMask; - if (map->num_types<=XkbAlphabeticIndex) - tmp|= XkbAlphabeticMask; - if (map->num_types<=XkbTwoLevelIndex) - tmp|= XkbTwoLevelMask; - if (map->num_types<=XkbOneLevelIndex) - tmp|= XkbOneLevelMask; - if (XkbInitCanonicalKeyTypes(xkb,tmp,XkbNoModifier)==Success) { - for (i=0;i<map->num_types;i++) { - Status status; - if (map->types[i].name!=name) - continue; - status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls); - return (status==Success?&map->types[i]:NULL); - } - } - } - if ((map->num_types<=map->size_types)&& - (XkbAllocClientMap(xkb,XkbKeyTypesMask,map->num_types+1)!=Success)) { - return NULL; - } - type= &map->types[map->num_types]; + tmp = 0; + if (map->num_types <= XkbKeypadIndex) + tmp |= XkbKeypadMask; + if (map->num_types <= XkbAlphabeticIndex) + tmp |= XkbAlphabeticMask; + if (map->num_types <= XkbTwoLevelIndex) + tmp |= XkbTwoLevelMask; + if (map->num_types <= XkbOneLevelIndex) + tmp |= XkbOneLevelMask; + if (XkbInitCanonicalKeyTypes(xkb, tmp, XkbNoModifier) == Success) { + for (i = 0; i < map->num_types; i++) { + Status status; + + if (map->types[i].name != name) + continue; + status = XkbResizeKeyType(xkb, i, map_count, want_preserve, + num_lvls); + return (status == Success ? &map->types[i] : NULL); + } + } + } + if ((map->num_types <= map->size_types) && + (XkbAllocClientMap(xkb, XkbKeyTypesMask, map->num_types + 1) != + Success)) { + return NULL; + } + type = &map->types[map->num_types]; map->num_types++; - bzero((char *)type,sizeof(XkbKeyTypeRec)); - type->num_levels= num_lvls; - type->map_count= map_count; - type->name= name; - if (map_count>0) { - type->map= _XkbTypedCalloc(map_count,XkbKTMapEntryRec); - if (!type->map) { - map->num_types--; - return NULL; - } - if (want_preserve) { - type->preserve= _XkbTypedCalloc(map_count,XkbModsRec); - if (!type->preserve) { - _XkbFree(type->map); - map->num_types--; - return NULL; - } - } + bzero((char *) type, sizeof(XkbKeyTypeRec)); + type->num_levels = num_lvls; + type->map_count = map_count; + type->name = name; + if (map_count > 0) { + type->map = _XkbTypedCalloc(map_count, XkbKTMapEntryRec); + if (!type->map) { + map->num_types--; + return NULL; + } + if (want_preserve) { + type->preserve = _XkbTypedCalloc(map_count, XkbModsRec); + if (!type->preserve) { + _XkbFree(type->map); + map->num_types--; + return NULL; + } + } } return type; } Status -XkbResizeKeyType( XkbDescPtr xkb, - int type_ndx, - int map_count, - Bool want_preserve, - int new_num_lvls) +XkbResizeKeyType(XkbDescPtr xkb, + int type_ndx, + int map_count, + Bool want_preserve, + int new_num_lvls) { -XkbKeyTypePtr type; -KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys; + XkbKeyTypePtr type; + KeyCode matchingKeys[XkbMaxKeyCount], nMatchingKeys; - if ((type_ndx<0)||(type_ndx>=xkb->map->num_types)||(map_count<0)|| - (new_num_lvls<1)) - return BadValue; + if ((type_ndx < 0) || (type_ndx >= xkb->map->num_types) || (map_count < 0) + || (new_num_lvls < 1)) + return BadValue; switch (type_ndx) { - case XkbOneLevelIndex: - if (new_num_lvls!=1) - return BadMatch; - break; - case XkbTwoLevelIndex: - case XkbAlphabeticIndex: - case XkbKeypadIndex: - if (new_num_lvls!=2) - return BadMatch; - break; - } - type= &xkb->map->types[type_ndx]; - if (map_count==0) { - if (type->map!=NULL) - _XkbFree(type->map); - type->map= NULL; - if (type->preserve!=NULL) - _XkbFree(type->preserve); - type->preserve= NULL; - type->map_count= 0; + case XkbOneLevelIndex: + if (new_num_lvls != 1) + return BadMatch; + break; + case XkbTwoLevelIndex: + case XkbAlphabeticIndex: + case XkbKeypadIndex: + if (new_num_lvls != 2) + return BadMatch; + break; + } + type = &xkb->map->types[type_ndx]; + if (map_count == 0) { + if (type->map != NULL) + _XkbFree(type->map); + type->map = NULL; + if (type->preserve != NULL) + _XkbFree(type->preserve); + type->preserve = NULL; + type->map_count = 0; } else { - XkbKTMapEntryRec *prev_map = type->map; - - if ((map_count>type->map_count)||(type->map==NULL)) - type->map=_XkbTypedRealloc(type->map,map_count,XkbKTMapEntryRec); - if (!type->map) { - if (prev_map) - _XkbFree(prev_map); - return BadAlloc; - } - if (want_preserve) { - XkbModsRec *prev_preserve = type->preserve; - - if ((map_count>type->map_count)||(type->preserve==NULL)) { - type->preserve= _XkbTypedRealloc(type->preserve,map_count, - XkbModsRec); - } - if (!type->preserve) { - if (prev_preserve) - _XkbFree(prev_preserve); - return BadAlloc; - } - } - else if (type->preserve!=NULL) { - _XkbFree(type->preserve); - type->preserve= NULL; - } - type->map_count= map_count; - } - - if ((new_num_lvls>type->num_levels)||(type->level_names==NULL)) { - Atom * prev_level_names = type->level_names; - - type->level_names=_XkbTypedRealloc(type->level_names,new_num_lvls,Atom); - if (!type->level_names) { - if (prev_level_names) - _XkbFree(prev_level_names); - return BadAlloc; - } + XkbKTMapEntryRec *prev_map = type->map; + + if ((map_count > type->map_count) || (type->map == NULL)) + type->map = + _XkbTypedRealloc(type->map, map_count, XkbKTMapEntryRec); + if (!type->map) { + if (prev_map) + _XkbFree(prev_map); + return BadAlloc; + } + if (want_preserve) { + XkbModsRec *prev_preserve = type->preserve; + + if ((map_count > type->map_count) || (type->preserve == NULL)) { + type->preserve = _XkbTypedRealloc(type->preserve, map_count, + XkbModsRec); + } + if (!type->preserve) { + if (prev_preserve) + _XkbFree(prev_preserve); + return BadAlloc; + } + } + else if (type->preserve != NULL) { + _XkbFree(type->preserve); + type->preserve = NULL; + } + type->map_count = map_count; + } + + if ((new_num_lvls > type->num_levels) || (type->level_names == NULL)) { + Atom *prev_level_names = type->level_names; + + type->level_names = + _XkbTypedRealloc(type->level_names, new_num_lvls, Atom); + if (!type->level_names) { + if (prev_level_names) + _XkbFree(prev_level_names); + return BadAlloc; + } } /* * Here's the theory: @@ -445,156 +456,165 @@ KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys; * The possibilities marked with '+' require us to examine the key types * associated with each group for the key. */ - bzero(matchingKeys,XkbMaxKeyCount*sizeof(KeyCode)); - nMatchingKeys= 0; - if (new_num_lvls>type->num_levels) { - int nTotal; - KeySym * newSyms; - int width,match,nResize; - register int i,g,nSyms; - - nResize= 0; - for (nTotal=1,i=xkb->min_key_code;i<=xkb->max_key_code;i++) { - width= XkbKeyGroupsWidth(xkb,i); - if (width<type->num_levels) - continue; - for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) { - if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) { - matchingKeys[nMatchingKeys++]= i; - match= 1; - } - } - if ((!match)||(width>=new_num_lvls)) - nTotal+= XkbKeyNumSyms(xkb,i); - else { - nTotal+= XkbKeyNumGroups(xkb,i)*new_num_lvls; - nResize++; - } - } - if (nResize>0) { - int nextMatch; - xkb->map->size_syms= (nTotal*12)/10; - newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym); - if (newSyms==NULL) - return BadAlloc; - nextMatch= 0; - nSyms= 1; - for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) { - if (matchingKeys[nextMatch]==i) { - KeySym *pOld; - nextMatch++; - width= XkbKeyGroupsWidth(xkb,i); - pOld= XkbKeySymsPtr(xkb,i); - for (g=XkbKeyNumGroups(xkb,i)-1;g>=0;g--) { - memcpy(&newSyms[nSyms+(new_num_lvls*g)],&pOld[width*g], - width*sizeof(KeySym)); - } - xkb->map->key_sym_map[i].offset= nSyms; - nSyms+= XkbKeyNumGroups(xkb,i)*new_num_lvls; - } - else { - memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i), - XkbKeyNumSyms(xkb,i)*sizeof(KeySym)); - xkb->map->key_sym_map[i].offset= nSyms; - nSyms+= XkbKeyNumSyms(xkb,i); - } - } - type->num_levels= new_num_lvls; - _XkbFree(xkb->map->syms); - xkb->map->syms= newSyms; - xkb->map->num_syms= nSyms; - return Success; - } - } - else if (new_num_lvls<type->num_levels) { - int width,match; - register int g,i; - for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) { - width= XkbKeyGroupsWidth(xkb,i); - if (width<type->num_levels) - continue; - for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) { - if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) { - matchingKeys[nMatchingKeys++]= i; - match= 1; - } - } - } - } - if (nMatchingKeys>0) { - int key,firstClear; - register int i,g; - if (new_num_lvls>type->num_levels) - firstClear= type->num_levels; - else firstClear= new_num_lvls; - for (i=0;i<nMatchingKeys;i++) { - KeySym * pSyms; - int width,nClear; - - key= matchingKeys[i]; - width= XkbKeyGroupsWidth(xkb,key); - nClear= width-firstClear; - pSyms= XkbKeySymsPtr(xkb,key); - for (g=XkbKeyNumGroups(xkb,key)-1;g>=0;g--) { - if (XkbKeyKeyTypeIndex(xkb,key,g)==type_ndx) { - if (nClear>0) - bzero(&pSyms[g*width+firstClear],nClear*sizeof(KeySym)); - } - } - } - } - type->num_levels= new_num_lvls; + bzero(matchingKeys, XkbMaxKeyCount * sizeof(KeyCode)); + nMatchingKeys = 0; + if (new_num_lvls > type->num_levels) { + int nTotal; + KeySym *newSyms; + int width, match, nResize; + register int i, g, nSyms; + + nResize = 0; + for (nTotal = 1, i = xkb->min_key_code; i <= xkb->max_key_code; i++) { + width = XkbKeyGroupsWidth(xkb, i); + if (width < type->num_levels) + continue; + for (match = 0, g = XkbKeyNumGroups(xkb, i) - 1; + (g >= 0) && (!match); g--) { + if (XkbKeyKeyTypeIndex(xkb, i, g) == type_ndx) { + matchingKeys[nMatchingKeys++] = i; + match = 1; + } + } + if ((!match) || (width >= new_num_lvls)) + nTotal += XkbKeyNumSyms(xkb, i); + else { + nTotal += XkbKeyNumGroups(xkb, i) * new_num_lvls; + nResize++; + } + } + if (nResize > 0) { + int nextMatch; + + xkb->map->size_syms = (nTotal * 12) / 10; + newSyms = _XkbTypedCalloc(xkb->map->size_syms, KeySym); + if (newSyms == NULL) + return BadAlloc; + nextMatch = 0; + nSyms = 1; + for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) { + if (matchingKeys[nextMatch] == i) { + KeySym *pOld; + + nextMatch++; + width = XkbKeyGroupsWidth(xkb, i); + pOld = XkbKeySymsPtr(xkb, i); + for (g = XkbKeyNumGroups(xkb, i) - 1; g >= 0; g--) { + memcpy(&newSyms[nSyms + (new_num_lvls * g)], + &pOld[width * g], width * sizeof(KeySym)); + } + xkb->map->key_sym_map[i].offset = nSyms; + nSyms += XkbKeyNumGroups(xkb, i) * new_num_lvls; + } + else { + memcpy(&newSyms[nSyms], XkbKeySymsPtr(xkb, i), + XkbKeyNumSyms(xkb, i) * sizeof(KeySym)); + xkb->map->key_sym_map[i].offset = nSyms; + nSyms += XkbKeyNumSyms(xkb, i); + } + } + type->num_levels = new_num_lvls; + _XkbFree(xkb->map->syms); + xkb->map->syms = newSyms; + xkb->map->num_syms = nSyms; + return Success; + } + } + else if (new_num_lvls < type->num_levels) { + int width, match; + register int g, i; + + for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) { + width = XkbKeyGroupsWidth(xkb, i); + if (width < type->num_levels) + continue; + for (match = 0, g = XkbKeyNumGroups(xkb, i) - 1; + (g >= 0) && (!match); g--) { + if (XkbKeyKeyTypeIndex(xkb, i, g) == type_ndx) { + matchingKeys[nMatchingKeys++] = i; + match = 1; + } + } + } + } + if (nMatchingKeys > 0) { + int key, firstClear; + register int i, g; + + if (new_num_lvls > type->num_levels) + firstClear = type->num_levels; + else + firstClear = new_num_lvls; + for (i = 0; i < nMatchingKeys; i++) { + KeySym *pSyms; + int width, nClear; + + key = matchingKeys[i]; + width = XkbKeyGroupsWidth(xkb, key); + nClear = width - firstClear; + pSyms = XkbKeySymsPtr(xkb, key); + for (g = XkbKeyNumGroups(xkb, key) - 1; g >= 0; g--) { + if (XkbKeyKeyTypeIndex(xkb, key, g) == type_ndx) { + if (nClear > 0) + bzero(&pSyms[g * width + firstClear], + nClear * sizeof(KeySym)); + } + } + } + } + type->num_levels = new_num_lvls; return Success; } KeySym * -XkbResizeKeySyms(XkbDescPtr xkb,int key,int needed) +XkbResizeKeySyms(XkbDescPtr xkb, int key, int needed) { -register int i,nSyms,nKeySyms; -unsigned nOldSyms; -KeySym *newSyms; - - if (needed==0) { - xkb->map->key_sym_map[key].offset= 0; - return xkb->map->syms; - } - nOldSyms= XkbKeyNumSyms(xkb,key); - if (nOldSyms>=(unsigned)needed) { - return XkbKeySymsPtr(xkb,key); - } - if (xkb->map->size_syms-xkb->map->num_syms>=(unsigned)needed) { - if (nOldSyms>0) { - memcpy(&xkb->map->syms[xkb->map->num_syms],XkbKeySymsPtr(xkb,key), - nOldSyms*sizeof(KeySym)); - } - if ((needed-nOldSyms)>0) { - bzero(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb,key)], - (needed-nOldSyms)*sizeof(KeySym)); - } - xkb->map->key_sym_map[key].offset = xkb->map->num_syms; - xkb->map->num_syms+= needed; - return &xkb->map->syms[xkb->map->key_sym_map[key].offset]; - } - xkb->map->size_syms+= (needed>32?needed:32); - newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym); - if (newSyms==NULL) - return NULL; - newSyms[0]= NoSymbol; + register int i, nSyms, nKeySyms; + unsigned nOldSyms; + KeySym *newSyms; + + if (needed == 0) { + xkb->map->key_sym_map[key].offset = 0; + return xkb->map->syms; + } + nOldSyms = XkbKeyNumSyms(xkb, key); + if (nOldSyms >= (unsigned) needed) { + return XkbKeySymsPtr(xkb, key); + } + if (xkb->map->size_syms - xkb->map->num_syms >= (unsigned) needed) { + if (nOldSyms > 0) { + memcpy(&xkb->map->syms[xkb->map->num_syms], XkbKeySymsPtr(xkb, key), + nOldSyms * sizeof(KeySym)); + } + if ((needed - nOldSyms) > 0) { + bzero(&xkb->map->syms[xkb->map->num_syms + XkbKeyNumSyms(xkb, key)], + (needed - nOldSyms) * sizeof(KeySym)); + } + xkb->map->key_sym_map[key].offset = xkb->map->num_syms; + xkb->map->num_syms += needed; + return &xkb->map->syms[xkb->map->key_sym_map[key].offset]; + } + xkb->map->size_syms += (needed > 32 ? needed : 32); + newSyms = _XkbTypedCalloc(xkb->map->size_syms, KeySym); + if (newSyms == NULL) + return NULL; + newSyms[0] = NoSymbol; nSyms = 1; - for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) { - int nCopy; - - nCopy= nKeySyms= XkbKeyNumSyms(xkb,i); - if ((nKeySyms==0)&&(i!=key)) - continue; - if (i==key) - nKeySyms= needed; - if (nCopy!=0) - memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),nCopy*sizeof(KeySym)); - if (nKeySyms>nCopy) - bzero(&newSyms[nSyms+nCopy],(nKeySyms-nCopy)*sizeof(KeySym)); - xkb->map->key_sym_map[i].offset = nSyms; - nSyms+= nKeySyms; + for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++) { + int nCopy; + + nCopy = nKeySyms = XkbKeyNumSyms(xkb, i); + if ((nKeySyms == 0) && (i != key)) + continue; + if (i == key) + nKeySyms = needed; + if (nCopy != 0) + memcpy(&newSyms[nSyms], XkbKeySymsPtr(xkb, i), + nCopy * sizeof(KeySym)); + if (nKeySyms > nCopy) + bzero(&newSyms[nSyms + nCopy], (nKeySyms - nCopy) * sizeof(KeySym)); + xkb->map->key_sym_map[i].offset = nSyms; + nSyms += nKeySyms; } _XkbFree(xkb->map->syms); xkb->map->syms = newSyms; @@ -603,375 +623,381 @@ KeySym *newSyms; } static unsigned -_ExtendRange( unsigned int old_flags, - unsigned int flag, - KeyCode newKC, - KeyCode * old_min, - unsigned char * old_num) +_ExtendRange(unsigned int old_flags, + unsigned int flag, + KeyCode newKC, + KeyCode *old_min, + unsigned char *old_num) { - if ((old_flags&flag)==0) { - old_flags|= flag; - *old_min= newKC; - *old_num= 1; + if ((old_flags & flag) == 0) { + old_flags |= flag; + *old_min = newKC; + *old_num = 1; } else { - int last= (*old_min)+(*old_num)-1; - if (newKC<*old_min) { - *old_min= newKC; - *old_num= (last-newKC)+1; - } - else if (newKC>last) { - *old_num= (newKC-(*old_min))+1; - } + int last = (*old_min) + (*old_num) - 1; + + if (newKC < *old_min) { + *old_min = newKC; + *old_num = (last - newKC) + 1; + } + else if (newKC > last) { + *old_num = (newKC - (*old_min)) + 1; + } } return old_flags; } Status -XkbChangeKeycodeRange( XkbDescPtr xkb, - int minKC, - int maxKC, - XkbChangesPtr changes) +XkbChangeKeycodeRange(XkbDescPtr xkb, + int minKC, + int maxKC, + XkbChangesPtr changes) { -int tmp; - - if ((!xkb)||(minKC<XkbMinLegalKeyCode)||(maxKC>XkbMaxLegalKeyCode)) - return BadValue; - if (minKC>maxKC) - return BadMatch; - if (minKC<xkb->min_key_code) { - if (changes) - changes->map.min_key_code= minKC; - tmp= xkb->min_key_code-minKC; - if (xkb->map) { - if (xkb->map->key_sym_map) { - bzero((char *)&xkb->map->key_sym_map[minKC], - tmp*sizeof(XkbSymMapRec)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbKeySymsMask,minKC, - &changes->map.first_key_sym, - &changes->map.num_key_syms); - } - } - if (xkb->map->modmap) { - bzero((char *)&xkb->map->modmap[minKC],tmp); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbModifierMapMask,minKC, - &changes->map.first_modmap_key, - &changes->map.num_modmap_keys); - } - } - } - if (xkb->server) { - if (xkb->server->behaviors) { - bzero((char *)&xkb->server->behaviors[minKC], - tmp*sizeof(XkbBehavior)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbKeyBehaviorsMask,minKC, - &changes->map.first_key_behavior, - &changes->map.num_key_behaviors); - } - } - if (xkb->server->key_acts) { - bzero((char *)&xkb->server->key_acts[minKC], - tmp*sizeof(unsigned short)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbKeyActionsMask,minKC, - &changes->map.first_key_act, - &changes->map.num_key_acts); - } - } - if (xkb->server->vmodmap) { - bzero((char *)&xkb->server->vmodmap[minKC], - tmp*sizeof(unsigned short)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbVirtualModMapMask,minKC, - &changes->map.first_modmap_key, - &changes->map.num_vmodmap_keys); - } - } - } - if ((xkb->names)&&(xkb->names->keys)) { - bzero((char *)&xkb->names->keys[minKC],tmp*sizeof(XkbKeyNameRec)); - if (changes) { - changes->names.changed= _ExtendRange(changes->names.changed, - XkbKeyNamesMask,minKC, - &changes->names.first_key, - &changes->names.num_keys); - } - } - xkb->min_key_code= minKC; - } - if (maxKC>xkb->max_key_code) { - if (changes) - changes->map.max_key_code= maxKC; - tmp= maxKC-xkb->max_key_code; - if (xkb->map) { - if (xkb->map->key_sym_map) { - XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map; - - xkb->map->key_sym_map= _XkbTypedRealloc(xkb->map->key_sym_map, - (maxKC+1),XkbSymMapRec); - if (!xkb->map->key_sym_map) { - _XkbFree(prev_key_sym_map); - return BadAlloc; - } - bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code], - tmp*sizeof(XkbSymMapRec)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbKeySymsMask,maxKC, - &changes->map.first_key_sym, - &changes->map.num_key_syms); - } - } - if (xkb->map->modmap) { - unsigned char *prev_modmap = xkb->map->modmap; - - xkb->map->modmap= _XkbTypedRealloc(xkb->map->modmap, - (maxKC+1),unsigned char); - if (!xkb->map->modmap) { - _XkbFree(prev_modmap); - return BadAlloc; - } - bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbModifierMapMask,maxKC, - &changes->map.first_modmap_key, - &changes->map.num_modmap_keys); - } - } - } - if (xkb->server) { - if (xkb->server->behaviors) { - XkbBehavior *prev_behaviors = xkb->server->behaviors; - - xkb->server->behaviors=_XkbTypedRealloc(xkb->server->behaviors, - (maxKC+1),XkbBehavior); - if (!xkb->server->behaviors) { - _XkbFree(prev_behaviors); - return BadAlloc; - } - bzero((char *)&xkb->server->behaviors[xkb->max_key_code], - tmp*sizeof(XkbBehavior)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbKeyBehaviorsMask,maxKC, - &changes->map.first_key_behavior, - &changes->map.num_key_behaviors); - } - } - if (xkb->server->key_acts) { - unsigned short *prev_key_acts = xkb->server->key_acts; - - xkb->server->key_acts= _XkbTypedRealloc(xkb->server->key_acts, - (maxKC+1),unsigned short); - if (!xkb->server->key_acts) { - _XkbFree(prev_key_acts); - return BadAlloc; - } - bzero((char *)&xkb->server->key_acts[xkb->max_key_code], - tmp*sizeof(unsigned short)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbKeyActionsMask,maxKC, - &changes->map.first_key_act, - &changes->map.num_key_acts); - } - } - if (xkb->server->vmodmap) { - unsigned short *prev_vmodmap = xkb->server->vmodmap; - - xkb->server->vmodmap= _XkbTypedRealloc(xkb->server->vmodmap, - (maxKC+1),unsigned short); - if (!xkb->server->vmodmap) { - _XkbFree(prev_vmodmap); - return BadAlloc; - } - bzero((char *)&xkb->server->vmodmap[xkb->max_key_code], - tmp*sizeof(unsigned short)); - if (changes) { - changes->map.changed= _ExtendRange(changes->map.changed, - XkbVirtualModMapMask,maxKC, - &changes->map.first_modmap_key, - &changes->map.num_vmodmap_keys); - } - } - } - if ((xkb->names)&&(xkb->names->keys)) { - XkbKeyNameRec *prev_keys = xkb->names->keys; - - xkb->names->keys= _XkbTypedRealloc(xkb->names->keys, - (maxKC+1),XkbKeyNameRec); - if (!xkb->names->keys) { - _XkbFree(prev_keys); - return BadAlloc; - } - bzero((char *)&xkb->names->keys[xkb->max_key_code], - tmp*sizeof(XkbKeyNameRec)); - if (changes) { - changes->names.changed= _ExtendRange(changes->names.changed, - XkbKeyNamesMask,maxKC, - &changes->names.first_key, - &changes->names.num_keys); - } - } - xkb->max_key_code= maxKC; + int tmp; + + if ((!xkb) || (minKC < XkbMinLegalKeyCode) || (maxKC > XkbMaxLegalKeyCode)) + return BadValue; + if (minKC > maxKC) + return BadMatch; + if (minKC < xkb->min_key_code) { + if (changes) + changes->map.min_key_code = minKC; + tmp = xkb->min_key_code - minKC; + if (xkb->map) { + if (xkb->map->key_sym_map) { + bzero((char *) &xkb->map->key_sym_map[minKC], + tmp * sizeof(XkbSymMapRec)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbKeySymsMask, minKC, + &changes->map.first_key_sym, + &changes->map.num_key_syms); + } + } + if (xkb->map->modmap) { + bzero((char *) &xkb->map->modmap[minKC], tmp); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbModifierMapMask, minKC, + &changes->map.first_modmap_key, + &changes->map.num_modmap_keys); + } + } + } + if (xkb->server) { + if (xkb->server->behaviors) { + bzero((char *) &xkb->server->behaviors[minKC], + tmp * sizeof(XkbBehavior)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbKeyBehaviorsMask, minKC, + &changes->map.first_key_behavior, + &changes->map.num_key_behaviors); + } + } + if (xkb->server->key_acts) { + bzero((char *) &xkb->server->key_acts[minKC], + tmp * sizeof(unsigned short)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbKeyActionsMask, minKC, + &changes->map.first_key_act, + &changes->map.num_key_acts); + } + } + if (xkb->server->vmodmap) { + bzero((char *) &xkb->server->vmodmap[minKC], + tmp * sizeof(unsigned short)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbVirtualModMapMask, minKC, + &changes->map.first_modmap_key, + &changes->map.num_vmodmap_keys); + } + } + } + if ((xkb->names) && (xkb->names->keys)) { + bzero((char *) &xkb->names->keys[minKC], + tmp * sizeof(XkbKeyNameRec)); + if (changes) { + changes->names.changed = _ExtendRange(changes->names.changed, + XkbKeyNamesMask, minKC, + &changes->names.first_key, + &changes->names.num_keys); + } + } + xkb->min_key_code = minKC; + } + if (maxKC > xkb->max_key_code) { + if (changes) + changes->map.max_key_code = maxKC; + tmp = maxKC - xkb->max_key_code; + if (xkb->map) { + if (xkb->map->key_sym_map) { + XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map; + + xkb->map->key_sym_map = _XkbTypedRealloc(xkb->map->key_sym_map, + (maxKC + 1), XkbSymMapRec); + if (!xkb->map->key_sym_map) { + _XkbFree(prev_key_sym_map); + return BadAlloc; + } + bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code], + tmp * sizeof(XkbSymMapRec)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbKeySymsMask, maxKC, + &changes->map.first_key_sym, + &changes->map.num_key_syms); + } + } + if (xkb->map->modmap) { + unsigned char *prev_modmap = xkb->map->modmap; + + xkb->map->modmap = _XkbTypedRealloc(xkb->map->modmap, + (maxKC + 1), unsigned char); + if (!xkb->map->modmap) { + _XkbFree(prev_modmap); + return BadAlloc; + } + bzero((char *) &xkb->map->modmap[xkb->max_key_code], tmp); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbModifierMapMask, maxKC, + &changes->map.first_modmap_key, + &changes->map.num_modmap_keys); + } + } + } + if (xkb->server) { + if (xkb->server->behaviors) { + XkbBehavior *prev_behaviors = xkb->server->behaviors; + + xkb->server->behaviors = + _XkbTypedRealloc(xkb->server->behaviors, (maxKC + 1), + XkbBehavior); + if (!xkb->server->behaviors) { + _XkbFree(prev_behaviors); + return BadAlloc; + } + bzero((char *) &xkb->server->behaviors[xkb->max_key_code], + tmp * sizeof(XkbBehavior)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbKeyBehaviorsMask, maxKC, + &changes->map.first_key_behavior, + &changes->map.num_key_behaviors); + } + } + if (xkb->server->key_acts) { + unsigned short *prev_key_acts = xkb->server->key_acts; + + xkb->server->key_acts = _XkbTypedRealloc(xkb->server->key_acts, + (maxKC + 1), unsigned short); + if (!xkb->server->key_acts) { + _XkbFree(prev_key_acts); + return BadAlloc; + } + bzero((char *) &xkb->server->key_acts[xkb->max_key_code], + tmp * sizeof(unsigned short)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbKeyActionsMask, maxKC, + &changes->map.first_key_act, + &changes->map.num_key_acts); + } + } + if (xkb->server->vmodmap) { + unsigned short *prev_vmodmap = xkb->server->vmodmap; + + xkb->server->vmodmap = _XkbTypedRealloc(xkb->server->vmodmap, + (maxKC + 1), unsigned short); + if (!xkb->server->vmodmap) { + _XkbFree(prev_vmodmap); + return BadAlloc; + } + bzero((char *) &xkb->server->vmodmap[xkb->max_key_code], + tmp * sizeof(unsigned short)); + if (changes) { + changes->map.changed = _ExtendRange(changes->map.changed, + XkbVirtualModMapMask, maxKC, + &changes->map.first_modmap_key, + &changes->map.num_vmodmap_keys); + } + } + } + if ((xkb->names) && (xkb->names->keys)) { + XkbKeyNameRec *prev_keys = xkb->names->keys; + + xkb->names->keys = _XkbTypedRealloc(xkb->names->keys, + (maxKC + 1), XkbKeyNameRec); + if (!xkb->names->keys) { + _XkbFree(prev_keys); + return BadAlloc; + } + bzero((char *) &xkb->names->keys[xkb->max_key_code], + tmp * sizeof(XkbKeyNameRec)); + if (changes) { + changes->names.changed = _ExtendRange(changes->names.changed, + XkbKeyNamesMask, maxKC, + &changes->names.first_key, + &changes->names.num_keys); + } + } + xkb->max_key_code = maxKC; } return Success; } XkbAction * -XkbResizeKeyActions(XkbDescPtr xkb,int key,int needed) +XkbResizeKeyActions(XkbDescPtr xkb, int key, int needed) { -register int i,nActs; -XkbAction *newActs; - - if (needed==0) { - xkb->server->key_acts[key]= 0; - return NULL; - } - if (XkbKeyHasActions(xkb,key)&&(XkbKeyNumSyms(xkb,key)>=(unsigned)needed)) - return XkbKeyActionsPtr(xkb,key); - if (xkb->server->size_acts-xkb->server->num_acts>=(unsigned)needed) { - xkb->server->key_acts[key]= xkb->server->num_acts; - xkb->server->num_acts+= needed; - return &xkb->server->acts[xkb->server->key_acts[key]]; - } - xkb->server->size_acts= xkb->server->num_acts+needed+8; - newActs = _XkbTypedCalloc(xkb->server->size_acts,XkbAction); - if (newActs==NULL) - return NULL; + register int i, nActs; + XkbAction *newActs; + + if (needed == 0) { + xkb->server->key_acts[key] = 0; + return NULL; + } + if (XkbKeyHasActions(xkb, key) && + (XkbKeyNumSyms(xkb, key) >= (unsigned) needed)) + return XkbKeyActionsPtr(xkb, key); + if (xkb->server->size_acts - xkb->server->num_acts >= (unsigned) needed) { + xkb->server->key_acts[key] = xkb->server->num_acts; + xkb->server->num_acts += needed; + return &xkb->server->acts[xkb->server->key_acts[key]]; + } + xkb->server->size_acts = xkb->server->num_acts + needed + 8; + newActs = _XkbTypedCalloc(xkb->server->size_acts, XkbAction); + if (newActs == NULL) + return NULL; newActs[0].type = XkbSA_NoAction; nActs = 1; - for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) { - int nKeyActs,nCopy; - - if ((xkb->server->key_acts[i]==0)&&(i!=key)) - continue; - - nCopy= nKeyActs= XkbKeyNumActions(xkb,i); - if (i==key) { - nKeyActs= needed; - if (needed<nCopy) - nCopy= needed; - } - - if (nCopy>0) - memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i), - nCopy*sizeof(XkbAction)); - if (nCopy<nKeyActs) - bzero(&newActs[nActs+nCopy],(nKeyActs-nCopy)*sizeof(XkbAction)); - xkb->server->key_acts[i]= nActs; - nActs+= nKeyActs; + for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++) { + int nKeyActs, nCopy; + + if ((xkb->server->key_acts[i] == 0) && (i != key)) + continue; + + nCopy = nKeyActs = XkbKeyNumActions(xkb, i); + if (i == key) { + nKeyActs = needed; + if (needed < nCopy) + nCopy = needed; + } + + if (nCopy > 0) + memcpy(&newActs[nActs], XkbKeyActionsPtr(xkb, i), + nCopy * sizeof(XkbAction)); + if (nCopy < nKeyActs) + bzero(&newActs[nActs + nCopy], + (nKeyActs - nCopy) * sizeof(XkbAction)); + xkb->server->key_acts[i] = nActs; + nActs += nKeyActs; } _XkbFree(xkb->server->acts); xkb->server->acts = newActs; - xkb->server->num_acts= nActs; + xkb->server->num_acts = nActs; return &xkb->server->acts[xkb->server->key_acts[key]]; } void -XkbFreeClientMap(XkbDescPtr xkb,unsigned what,Bool freeMap) +XkbFreeClientMap(XkbDescPtr xkb, unsigned what, Bool freeMap) { -XkbClientMapPtr map; + XkbClientMapPtr map; - if ((xkb==NULL)||(xkb->map==NULL)) - return; + if ((xkb == NULL) || (xkb->map == NULL)) + return; if (freeMap) - what= XkbAllClientInfoMask; - map= xkb->map; - if (what&XkbKeyTypesMask) { - if (map->types!=NULL) { - if (map->num_types>0) { - register int i; - XkbKeyTypePtr type; - for (i=0,type=map->types;i<map->num_types;i++,type++) { - if (type->map!=NULL) { - _XkbFree(type->map); - type->map= NULL; - } - if (type->preserve!=NULL) { - _XkbFree(type->preserve); - type->preserve= NULL; - } - type->map_count= 0; - if (type->level_names!=NULL) { - _XkbFree(type->level_names); - type->level_names= NULL; - } - } - } - _XkbFree(map->types); - map->num_types= map->size_types= 0; - map->types= NULL; - } - } - if (what&XkbKeySymsMask) { - if (map->key_sym_map!=NULL) { - _XkbFree(map->key_sym_map); - map->key_sym_map= NULL; - } - if (map->syms!=NULL) { - _XkbFree(map->syms); - map->size_syms= map->num_syms= 0; - map->syms= NULL; - } - } - if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) { - _XkbFree(map->modmap); - map->modmap= NULL; + what = XkbAllClientInfoMask; + map = xkb->map; + if (what & XkbKeyTypesMask) { + if (map->types != NULL) { + if (map->num_types > 0) { + register int i; + XkbKeyTypePtr type; + + for (i = 0, type = map->types; i < map->num_types; i++, type++) { + if (type->map != NULL) { + _XkbFree(type->map); + type->map = NULL; + } + if (type->preserve != NULL) { + _XkbFree(type->preserve); + type->preserve = NULL; + } + type->map_count = 0; + if (type->level_names != NULL) { + _XkbFree(type->level_names); + type->level_names = NULL; + } + } + } + _XkbFree(map->types); + map->num_types = map->size_types = 0; + map->types = NULL; + } + } + if (what & XkbKeySymsMask) { + if (map->key_sym_map != NULL) { + _XkbFree(map->key_sym_map); + map->key_sym_map = NULL; + } + if (map->syms != NULL) { + _XkbFree(map->syms); + map->size_syms = map->num_syms = 0; + map->syms = NULL; + } + } + if ((what & XkbModifierMapMask) && (map->modmap != NULL)) { + _XkbFree(map->modmap); + map->modmap = NULL; } if (freeMap) { - _XkbFree(xkb->map); - xkb->map= NULL; + _XkbFree(xkb->map); + xkb->map = NULL; } return; } void -XkbFreeServerMap(XkbDescPtr xkb,unsigned what,Bool freeMap) +XkbFreeServerMap(XkbDescPtr xkb, unsigned what, Bool freeMap) { -XkbServerMapPtr map; + XkbServerMapPtr map; - if ((xkb==NULL)||(xkb->server==NULL)) - return; + if ((xkb == NULL) || (xkb->server == NULL)) + return; if (freeMap) - what= XkbAllServerInfoMask; - map= xkb->server; - if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) { - _XkbFree(map->explicit); - map->explicit= NULL; - } - if (what&XkbKeyActionsMask) { - if (map->key_acts!=NULL) { - _XkbFree(map->key_acts); - map->key_acts= NULL; - } - if (map->acts!=NULL) { - _XkbFree(map->acts); - map->num_acts= map->size_acts= 0; - map->acts= NULL; - } - } - if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) { - _XkbFree(map->behaviors); - map->behaviors= NULL; - } - if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) { - _XkbFree(map->vmodmap); - map->vmodmap= NULL; + what = XkbAllServerInfoMask; + map = xkb->server; + if ((what & XkbExplicitComponentsMask) && (map->explicit != NULL)) { + _XkbFree(map->explicit); + map->explicit = NULL; + } + if (what & XkbKeyActionsMask) { + if (map->key_acts != NULL) { + _XkbFree(map->key_acts); + map->key_acts = NULL; + } + if (map->acts != NULL) { + _XkbFree(map->acts); + map->num_acts = map->size_acts = 0; + map->acts = NULL; + } + } + if ((what & XkbKeyBehaviorsMask) && (map->behaviors != NULL)) { + _XkbFree(map->behaviors); + map->behaviors = NULL; + } + if ((what & XkbVirtualModMapMask) && (map->vmodmap != NULL)) { + _XkbFree(map->vmodmap); + map->vmodmap = NULL; } if (freeMap) { - _XkbFree(xkb->server); - xkb->server= NULL; + _XkbFree(xkb->server); + xkb->server = NULL; } return; } diff --git a/libX11/src/xkb/XKBMisc.c b/libX11/src/xkb/XKBMisc.c index 37ebda6ad..d25aa217b 100755 --- a/libX11/src/xkb/XKBMisc.c +++ b/libX11/src/xkb/XKBMisc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -44,94 +42,97 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ #define mapSize(m) (sizeof(m)/sizeof(XkbKTMapEntryRec)) -static XkbKTMapEntryRec map2Level[]= { - { True, ShiftMask, {1, ShiftMask, 0} } +static XkbKTMapEntryRec map2Level[] = { + { True, ShiftMask, {1, ShiftMask, 0} } }; -static XkbKTMapEntryRec mapAlpha[]= { - { True, ShiftMask, { 1, ShiftMask, 0 } }, - { True, LockMask, { 0, LockMask, 0 } } +static XkbKTMapEntryRec mapAlpha[] = { + { True, ShiftMask, {1, ShiftMask, 0} }, + { True, LockMask, {0, LockMask, 0} } }; -static XkbModsRec preAlpha[]= { - { 0, 0, 0 }, - { LockMask, LockMask, 0 } +static XkbModsRec preAlpha[] = { + { 0, 0, 0 }, + { LockMask, LockMask, 0 } }; #define NL_VMOD_MASK 0 -static XkbKTMapEntryRec mapKeypad[]= { - { True, ShiftMask, { 1, ShiftMask, 0 } }, - { False, 0, { 1, 0, NL_VMOD_MASK } } +static XkbKTMapEntryRec mapKeypad[] = { + { True, ShiftMask, { 1, ShiftMask, 0 } }, + { False, 0, { 1, 0, NL_VMOD_MASK } } }; -static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = { - { { 0, 0, 0 }, - 1, /* num_levels */ - 0, /* map_count */ - NULL, NULL, - None, NULL - }, - { { ShiftMask, ShiftMask, 0 }, - 2, /* num_levels */ - mapSize(map2Level), /* map_count */ - map2Level, NULL, - None, NULL - }, - { { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, - 2, /* num_levels */ - mapSize(mapAlpha), /* map_count */ - mapAlpha, preAlpha, - None, NULL - }, - { { ShiftMask, ShiftMask, NL_VMOD_MASK }, - 2, /* num_levels */ - mapSize(mapKeypad), /* map_count */ - mapKeypad, NULL, - None, NULL - } +static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = { + { { 0, 0, 0 }, + 1, /* num_levels */ + 0, /* map_count */ + NULL, NULL, + None, NULL + }, + { { ShiftMask, ShiftMask, 0 }, + 2, /* num_levels */ + mapSize(map2Level), /* map_count */ + map2Level, NULL, + None, NULL + }, + { { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, + 2, /* num_levels */ + mapSize(mapAlpha), /* map_count */ + mapAlpha, preAlpha, + None, NULL + }, + { { ShiftMask, ShiftMask, NL_VMOD_MASK }, + 2, /* num_levels */ + mapSize(mapKeypad), /* map_count */ + mapKeypad, NULL, + None, NULL + } }; Status -XkbInitCanonicalKeyTypes(XkbDescPtr xkb,unsigned which,int keypadVMod) +XkbInitCanonicalKeyTypes(XkbDescPtr xkb, unsigned which, int keypadVMod) { -XkbClientMapPtr map; -XkbKeyTypePtr from,to; -Status rtrn; + XkbClientMapPtr map; + XkbKeyTypePtr from, to; + Status rtrn; if (!xkb) - return BadMatch; - rtrn= XkbAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes); - if (rtrn!=Success) - return rtrn; - map= xkb->map; - if ((which&XkbAllRequiredTypes)==0) - return Success; - rtrn= Success; - from= canonicalTypes; - to= map->types; - if (which&XkbOneLevelMask) - rtrn= XkbCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]); - if ((which&XkbTwoLevelMask)&&(rtrn==Success)) - rtrn= XkbCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]); - if ((which&XkbAlphabeticMask)&&(rtrn==Success)) - rtrn= XkbCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]); - if ((which&XkbKeypadMask)&&(rtrn==Success)) { - XkbKeyTypePtr type; - rtrn= XkbCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]); - type= &to[XkbKeypadIndex]; - if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) { - type->mods.vmods= (1<<keypadVMod); - type->map[0].active= True; - type->map[0].mods.mask= ShiftMask; - type->map[0].mods.real_mods= ShiftMask; - type->map[0].mods.vmods= 0; - type->map[0].level= 1; - type->map[1].active= False; - type->map[1].mods.mask= 0; - type->map[1].mods.real_mods= 0; - type->map[1].mods.vmods= (1<<keypadVMod); - type->map[1].level= 1; - } + return BadMatch; + rtrn = XkbAllocClientMap(xkb, XkbKeyTypesMask, XkbNumRequiredTypes); + if (rtrn != Success) + return rtrn; + map = xkb->map; + if ((which & XkbAllRequiredTypes) == 0) + return Success; + rtrn = Success; + from = canonicalTypes; + to = map->types; + if (which & XkbOneLevelMask) + rtrn = XkbCopyKeyType(&from[XkbOneLevelIndex], &to[XkbOneLevelIndex]); + if ((which & XkbTwoLevelMask) && (rtrn == Success)) + rtrn = XkbCopyKeyType(&from[XkbTwoLevelIndex], &to[XkbTwoLevelIndex]); + if ((which & XkbAlphabeticMask) && (rtrn == Success)) + rtrn = + XkbCopyKeyType(&from[XkbAlphabeticIndex], &to[XkbAlphabeticIndex]); + if ((which & XkbKeypadMask) && (rtrn == Success)) { + XkbKeyTypePtr type; + + rtrn = XkbCopyKeyType(&from[XkbKeypadIndex], &to[XkbKeypadIndex]); + type = &to[XkbKeypadIndex]; + if ((keypadVMod >= 0) && (keypadVMod < XkbNumVirtualMods) && + (rtrn == Success)) { + type->mods.vmods = (1 << keypadVMod); + type->map[0].active = True; + type->map[0].mods.mask = ShiftMask; + type->map[0].mods.real_mods = ShiftMask; + type->map[0].mods.vmods = 0; + type->map[0].level = 1; + type->map[1].active = False; + type->map[1].mods.mask = 0; + type->map[1].mods.real_mods = 0; + type->map[1].mods.vmods = (1 << keypadVMod); + type->map[1].level = 1; + } } return Success; } @@ -142,264 +143,283 @@ Status rtrn; #define XKB_OFFSET(g,l) (((g)*groupsWidth)+(l)) int -XkbKeyTypesForCoreSymbols( XkbDescPtr xkb, - int map_width, - KeySym * core_syms, - unsigned int protected, - int * types_inout, - KeySym * xkb_syms_rtrn) +XkbKeyTypesForCoreSymbols(XkbDescPtr xkb, + int map_width, + KeySym *core_syms, + unsigned int protected, + int *types_inout, + KeySym *xkb_syms_rtrn) { -register int i; -unsigned int empty; -int nSyms[XkbNumKbdGroups]; -int nGroups,tmp,groupsWidth; + register int i; + unsigned int empty; + int nSyms[XkbNumKbdGroups]; + int nGroups, tmp, groupsWidth; /* Section 12.2 of the protocol describes this process in more detail */ /* Step 1: find the # of symbols in the core mapping per group */ - groupsWidth= 2; - for (i=0;i<XkbNumKbdGroups;i++) { - if ((protected&(1<<i))&&(types_inout[i]<xkb->map->num_types)) { - nSyms[i]= xkb->map->types[types_inout[i]].num_levels; - if (nSyms[i]>groupsWidth) - groupsWidth= nSyms[i]; - } - else { - types_inout[i]= XkbTwoLevelIndex; /* don't really know, yet */ - nSyms[i]= 2; - } - } - if (nSyms[XkbGroup1Index]<2) - nSyms[XkbGroup1Index]= 2; - if (nSyms[XkbGroup2Index]<2) - nSyms[XkbGroup2Index]= 2; - /* Step 2: Copy the symbols from the core ordering to XKB ordering */ - /* symbols in the core are in the order: */ - /* G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*] */ - xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,0)]= CORE_SYM(0); - xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,1)]= CORE_SYM(1); - for (i=2;i<nSyms[XkbGroup1Index];i++) { - xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,i)]= CORE_SYM(2+i); - } - xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,0)]= CORE_SYM(2); - xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,1)]= CORE_SYM(3); - tmp= 2+(nSyms[XkbGroup1Index]-2); /* offset to extra group2 syms */ - for (i=2;i<nSyms[XkbGroup2Index];i++) { - xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,i)]= CORE_SYM(tmp+i); - } - tmp= nSyms[XkbGroup1Index]+nSyms[XkbGroup2Index]; - if ((tmp>=map_width)&& - ((protected&(XkbExplicitKeyType3Mask|XkbExplicitKeyType4Mask))==0)) { - nSyms[XkbGroup3Index]= 0; - nSyms[XkbGroup4Index]= 0; - nGroups= 2; + groupsWidth = 2; + for (i = 0; i < XkbNumKbdGroups; i++) { + if ((protected & (1 << i)) && (types_inout[i] < xkb->map->num_types)) { + nSyms[i] = xkb->map->types[types_inout[i]].num_levels; + if (nSyms[i] > groupsWidth) + groupsWidth = nSyms[i]; + } + else { + types_inout[i] = XkbTwoLevelIndex; /* don't really know, yet */ + nSyms[i] = 2; + } + } + if (nSyms[XkbGroup1Index] < 2) + nSyms[XkbGroup1Index] = 2; + if (nSyms[XkbGroup2Index] < 2) + nSyms[XkbGroup2Index] = 2; + /* Step 2: Copy the symbols from the core ordering to XKB ordering */ + /* symbols in the core are in the order: */ + /* G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*] */ + xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index, 0)] = CORE_SYM(0); + xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index, 1)] = CORE_SYM(1); + for (i = 2; i < nSyms[XkbGroup1Index]; i++) { + xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index, i)] = CORE_SYM(2 + i); + } + xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index, 0)] = CORE_SYM(2); + xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index, 1)] = CORE_SYM(3); + tmp = 2 + (nSyms[XkbGroup1Index] - 2); /* offset to extra group2 syms */ + for (i = 2; i < nSyms[XkbGroup2Index]; i++) { + xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index, i)] = CORE_SYM(tmp + i); + } + tmp = nSyms[XkbGroup1Index] + nSyms[XkbGroup2Index]; + if ((tmp >= map_width) && + ((protected & (XkbExplicitKeyType3Mask | XkbExplicitKeyType4Mask)) == + 0)) { + nSyms[XkbGroup3Index] = 0; + nSyms[XkbGroup4Index] = 0; + nGroups = 2; } else { - nGroups= 3; - for (i=0;i<nSyms[XkbGroup3Index];i++,tmp++) { - xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index,i)]= CORE_SYM(tmp); - } - if ((tmp<map_width)||(protected&XkbExplicitKeyType4Mask)) { - nGroups= 4; - for (i=0;i<nSyms[XkbGroup4Index];i++,tmp++) { - xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index,i)]= CORE_SYM(tmp); - } - } - else { - nSyms[XkbGroup4Index]= 0; - } + nGroups = 3; + for (i = 0; i < nSyms[XkbGroup3Index]; i++, tmp++) { + xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index, i)] = CORE_SYM(tmp); + } + if ((tmp < map_width) || (protected & XkbExplicitKeyType4Mask)) { + nGroups = 4; + for (i = 0; i < nSyms[XkbGroup4Index]; i++, tmp++) { + xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index, i)] = CORE_SYM(tmp); + } + } + else { + nSyms[XkbGroup4Index] = 0; + } } /* steps 3&4: alphanumeric expansion, assign canonical types */ - empty= 0; - for (i=0;i<nGroups;i++) { - KeySym *syms; - syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)]; - if ((nSyms[i]>1)&&(syms[1]==NoSymbol)&&(syms[0]!=NoSymbol)) { - KeySym upper,lower; - XConvertCase(syms[0],&lower,&upper); - if (upper!=lower) { - xkb_syms_rtrn[XKB_OFFSET(i,0)]= lower; - xkb_syms_rtrn[XKB_OFFSET(i,1)]= upper; - if ((protected&(1<<i))==0) - types_inout[i]= XkbAlphabeticIndex; - } - else if ((protected&(1<<i))==0) { - types_inout[i]= XkbOneLevelIndex; - /* nSyms[i]= 1;*/ - } - } - if (((protected&(1<<i))==0)&&(types_inout[i]==XkbTwoLevelIndex)) { - if (IsKeypadKey(syms[0])||IsKeypadKey(syms[1])) - types_inout[i]= XkbKeypadIndex; - else { - KeySym upper,lower; - XConvertCase(syms[0],&lower,&upper); - if ((syms[0]==lower)&&(syms[1]==upper)) - types_inout[i]= XkbAlphabeticIndex; - } - } - if (syms[0]==NoSymbol) { - register int n; - Bool found; - for (n=1,found=False;(!found)&&(n<nSyms[i]);n++) { - found= (syms[n]!=NoSymbol); - } - if (!found) - empty|= (1<<i); - } + empty = 0; + for (i = 0; i < nGroups; i++) { + KeySym *syms; + + syms = &xkb_syms_rtrn[XKB_OFFSET(i, 0)]; + if ((nSyms[i] > 1) && (syms[1] == NoSymbol) && (syms[0] != NoSymbol)) { + KeySym upper, lower; + + XConvertCase(syms[0], &lower, &upper); + if (upper != lower) { + xkb_syms_rtrn[XKB_OFFSET(i, 0)] = lower; + xkb_syms_rtrn[XKB_OFFSET(i, 1)] = upper; + if ((protected & (1 << i)) == 0) + types_inout[i] = XkbAlphabeticIndex; + } + else if ((protected & (1 << i)) == 0) { + types_inout[i] = XkbOneLevelIndex; + /* nSyms[i]= 1; */ + } + } + if (((protected & (1 << i)) == 0) && + (types_inout[i] == XkbTwoLevelIndex)) { + if (IsKeypadKey(syms[0]) || IsKeypadKey(syms[1])) + types_inout[i] = XkbKeypadIndex; + else { + KeySym upper, lower; + + XConvertCase(syms[0], &lower, &upper); + if ((syms[0] == lower) && (syms[1] == upper)) + types_inout[i] = XkbAlphabeticIndex; + } + } + if (syms[0] == NoSymbol) { + register int n; + Bool found; + + for (n = 1, found = False; (!found) && (n < nSyms[i]); n++) { + found = (syms[n] != NoSymbol); + } + if (!found) + empty |= (1 << i); + } } /* step 5: squoosh out empty groups */ if (empty) { - for (i=nGroups-1;i>=0;i--) { - if (((empty&(1<<i))==0)||(protected&(1<<i))) - break; - nGroups--; - } + for (i = nGroups - 1; i >= 0; i--) { + if (((empty & (1 << i)) == 0) || (protected & (1 << i))) + break; + nGroups--; + } } - if (nGroups<1) - return 0; + if (nGroups < 1) + return 0; /* step 6: replicate group 1 into group two, if necessary */ - if ((nGroups>1)&&((empty&(XkbGroup1Mask|XkbGroup2Mask))==XkbGroup2Mask)) { - if ((protected&(XkbExplicitKeyType1Mask|XkbExplicitKeyType2Mask))==0) { - nSyms[XkbGroup2Index]= nSyms[XkbGroup1Index]; - types_inout[XkbGroup2Index]= types_inout[XkbGroup1Index]; - memcpy((char *)&xkb_syms_rtrn[2],(char *)xkb_syms_rtrn, - 2*sizeof(KeySym)); - } - else if (types_inout[XkbGroup1Index]==types_inout[XkbGroup2Index]) { - memcpy((char *)&xkb_syms_rtrn[nSyms[XkbGroup1Index]], - (char *)xkb_syms_rtrn, - nSyms[XkbGroup1Index]*sizeof(KeySym)); - } + if ((nGroups > 1) && + ((empty & (XkbGroup1Mask | XkbGroup2Mask)) == XkbGroup2Mask)) { + if ((protected & (XkbExplicitKeyType1Mask | XkbExplicitKeyType2Mask)) == + 0) { + nSyms[XkbGroup2Index] = nSyms[XkbGroup1Index]; + types_inout[XkbGroup2Index] = types_inout[XkbGroup1Index]; + memcpy((char *) &xkb_syms_rtrn[2], (char *) xkb_syms_rtrn, + 2 * sizeof(KeySym)); + } + else if (types_inout[XkbGroup1Index] == types_inout[XkbGroup2Index]) { + memcpy((char *) &xkb_syms_rtrn[nSyms[XkbGroup1Index]], + (char *) xkb_syms_rtrn, + nSyms[XkbGroup1Index] * sizeof(KeySym)); + } } /* step 7: check for all groups identical or all width 1 */ - if (nGroups>1) { - Bool sameType,allOneLevel; - allOneLevel= (xkb->map->types[types_inout[0]].num_levels==1); - for (i=1,sameType=True;(allOneLevel||sameType)&&(i<nGroups);i++) { - sameType=(sameType&&(types_inout[i]==types_inout[XkbGroup1Index])); - if (allOneLevel) - allOneLevel= (xkb->map->types[types_inout[i]].num_levels==1); - } - if ((sameType)&& - (!(protected&(XkbExplicitKeyTypesMask&~XkbExplicitKeyType1Mask)))){ - register int s; - Bool identical; - for (i=1,identical=True;identical&&(i<nGroups);i++) { - KeySym *syms; - syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)]; - for (s=0;identical&&(s<nSyms[i]);s++) { - if (syms[s]!=xkb_syms_rtrn[s]) - identical= False; - } - } - if (identical) - nGroups= 1; - } - if (allOneLevel && (nGroups>1)) { - KeySym *syms; - syms= &xkb_syms_rtrn[nSyms[XkbGroup1Index]]; - nSyms[XkbGroup1Index]= 1; - for (i=1;i<nGroups;i++) { - xkb_syms_rtrn[i]= syms[0]; - syms+= nSyms[i]; - nSyms[i]= 1; - } - } + if (nGroups > 1) { + Bool sameType, allOneLevel; + + allOneLevel = (xkb->map->types[types_inout[0]].num_levels == 1); + for (i = 1, sameType = True; (allOneLevel || sameType) && (i < nGroups); + i++) { + sameType = (sameType && + (types_inout[i] == types_inout[XkbGroup1Index])); + if (allOneLevel) + allOneLevel = (xkb->map->types[types_inout[i]].num_levels == 1); + } + if ((sameType) && + (!(protected & + (XkbExplicitKeyTypesMask & ~XkbExplicitKeyType1Mask)))) { + register int s; + Bool identical; + + for (i = 1, identical = True; identical && (i < nGroups); i++) { + KeySym *syms; + + syms = &xkb_syms_rtrn[XKB_OFFSET(i, 0)]; + for (s = 0; identical && (s < nSyms[i]); s++) { + if (syms[s] != xkb_syms_rtrn[s]) + identical = False; + } + } + if (identical) + nGroups = 1; + } + if (allOneLevel && (nGroups > 1)) { + KeySym *syms; + + syms = &xkb_syms_rtrn[nSyms[XkbGroup1Index]]; + nSyms[XkbGroup1Index] = 1; + for (i = 1; i < nGroups; i++) { + xkb_syms_rtrn[i] = syms[0]; + syms += nSyms[i]; + nSyms[i] = 1; + } + } } return nGroups; } static XkbSymInterpretPtr -_XkbFindMatchingInterp( XkbDescPtr xkb, - KeySym sym, - unsigned int real_mods, - unsigned int level) +_XkbFindMatchingInterp(XkbDescPtr xkb, + KeySym sym, + unsigned int real_mods, + unsigned int level) { -register unsigned i; -XkbSymInterpretPtr interp,rtrn; -CARD8 mods; - - rtrn= NULL; - interp= xkb->compat->sym_interpret; - for (i=0;i<xkb->compat->num_si;i++,interp++) { - if ((interp->sym==NoSymbol)||(sym==interp->sym)) { - int match; - if ((level==0)||((interp->match&XkbSI_LevelOneOnly)==0)) - mods= real_mods; - else mods= 0; - switch (interp->match&XkbSI_OpMask) { - case XkbSI_NoneOf: - match= ((interp->mods&mods)==0); - break; - case XkbSI_AnyOfOrNone: - match= ((mods==0)||((interp->mods&mods)!=0)); - break; - case XkbSI_AnyOf: - match= ((interp->mods&mods)!=0); - break; - case XkbSI_AllOf: - match= ((interp->mods&mods)==interp->mods); - break; - case XkbSI_Exactly: - match= (interp->mods==mods); - break; - default: - match= 0; - break; - } - if (match) { - if (interp->sym!=NoSymbol) { - return interp; - } - else if (rtrn==NULL) { - rtrn= interp; - } - } - } + register unsigned i; + XkbSymInterpretPtr interp, rtrn; + CARD8 mods; + + rtrn = NULL; + interp = xkb->compat->sym_interpret; + for (i = 0; i < xkb->compat->num_si; i++, interp++) { + if ((interp->sym == NoSymbol) || (sym == interp->sym)) { + int match; + + if ((level == 0) || ((interp->match & XkbSI_LevelOneOnly) == 0)) + mods = real_mods; + else + mods = 0; + switch (interp->match & XkbSI_OpMask) { + case XkbSI_NoneOf: + match = ((interp->mods & mods) == 0); + break; + case XkbSI_AnyOfOrNone: + match = ((mods == 0) || ((interp->mods & mods) != 0)); + break; + case XkbSI_AnyOf: + match = ((interp->mods & mods) != 0); + break; + case XkbSI_AllOf: + match = ((interp->mods & mods) == interp->mods); + break; + case XkbSI_Exactly: + match = (interp->mods == mods); + break; + default: + match = 0; + break; + } + if (match) { + if (interp->sym != NoSymbol) { + return interp; + } + else if (rtrn == NULL) { + rtrn = interp; + } + } + } } return rtrn; } static void -_XkbAddKeyChange(KeyCode *pFirst,unsigned char *pNum,KeyCode newKey) +_XkbAddKeyChange(KeyCode *pFirst, unsigned char *pNum, KeyCode newKey) { -KeyCode last; + KeyCode last; - last= (*pFirst)+(*pNum); - if (newKey<*pFirst) { - *pFirst= newKey; - *pNum= (last-newKey)+1; + last = (*pFirst) + (*pNum); + if (newKey < *pFirst) { + *pFirst = newKey; + *pNum = (last - newKey) + 1; } - else if (newKey>last) { - *pNum= (last-*pFirst)+1; + else if (newKey > last) { + *pNum = (last - *pFirst) + 1; } return; } static void -_XkbSetActionKeyMods(XkbDescPtr xkb,XkbAction *act,unsigned mods) +_XkbSetActionKeyMods(XkbDescPtr xkb, XkbAction *act, unsigned mods) { -unsigned tmp; + unsigned tmp; switch (act->type) { - case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods: - if (act->mods.flags&XkbSA_UseModMapMods) - act->mods.real_mods= act->mods.mask= mods; - if ((tmp= XkbModActionVMods(&act->mods))!=0) { - XkbVirtualModsToReal(xkb,tmp,&tmp); - act->mods.mask|= tmp; - } - break; - case XkbSA_ISOLock: - if (act->iso.flags&XkbSA_UseModMapMods) - act->iso.real_mods= act->iso.mask= mods; - if ((tmp= XkbModActionVMods(&act->iso))!=0) { - XkbVirtualModsToReal(xkb,tmp,&tmp); - act->iso.mask|= tmp; - } - break; + case XkbSA_SetMods: + case XkbSA_LatchMods: + case XkbSA_LockMods: + if (act->mods.flags & XkbSA_UseModMapMods) + act->mods.real_mods = act->mods.mask = mods; + if ((tmp = XkbModActionVMods(&act->mods)) != 0) { + XkbVirtualModsToReal(xkb, tmp, &tmp); + act->mods.mask |= tmp; + } + break; + case XkbSA_ISOLock: + if (act->iso.flags & XkbSA_UseModMapMods) + act->iso.real_mods = act->iso.mask = mods; + if ((tmp = XkbModActionVMods(&act->iso)) != 0) { + XkbVirtualModsToReal(xkb, tmp, &tmp); + act->iso.mask |= tmp; + } + break; } return; } @@ -407,357 +427,374 @@ unsigned tmp; #define IBUF_SIZE 8 Bool -XkbApplyCompatMapToKey(XkbDescPtr xkb,KeyCode key,XkbChangesPtr changes) +XkbApplyCompatMapToKey(XkbDescPtr xkb, KeyCode key, XkbChangesPtr changes) { -KeySym * syms; -unsigned char explicit,mods; -XkbSymInterpretPtr *interps,ibuf[IBUF_SIZE]; -int n,nSyms,found; -unsigned changed,tmp; - - if ((!xkb)||(!xkb->map)||(!xkb->map->key_sym_map)|| - (!xkb->compat)||(!xkb->compat->sym_interpret)|| - (key<xkb->min_key_code)||(key>xkb->max_key_code)) { - return False; - } - if (((!xkb->server)||(!xkb->server->key_acts))&& - (XkbAllocServerMap(xkb,XkbAllServerInfoMask,0)!=Success)) { - return False; - } - changed= 0; /* keeps track of what has changed in _this_ call */ - explicit= xkb->server->explicit[key]; - if (explicit&XkbExplicitInterpretMask) /* nothing to do */ - return True; - mods= (xkb->map->modmap?xkb->map->modmap[key]:0); - nSyms= XkbKeyNumSyms(xkb,key); - syms= XkbKeySymsPtr(xkb,key); - if (nSyms>IBUF_SIZE) { - interps= _XkbTypedCalloc(nSyms,XkbSymInterpretPtr); - if (interps==NULL) { - interps= ibuf; - nSyms= IBUF_SIZE; - } + KeySym *syms; + unsigned char explicit, mods; + XkbSymInterpretPtr *interps, ibuf[IBUF_SIZE]; + int n, nSyms, found; + unsigned changed, tmp; + + if ((!xkb) || (!xkb->map) || (!xkb->map->key_sym_map) || + (!xkb->compat) || (!xkb->compat->sym_interpret) || + (key < xkb->min_key_code) || (key > xkb->max_key_code)) { + return False; + } + if (((!xkb->server) || (!xkb->server->key_acts)) && + (XkbAllocServerMap(xkb, XkbAllServerInfoMask, 0) != Success)) { + return False; + } + changed = 0; /* keeps track of what has changed in _this_ call */ + explicit = xkb->server->explicit[key]; + if (explicit & XkbExplicitInterpretMask) /* nothing to do */ + return True; + mods = (xkb->map->modmap ? xkb->map->modmap[key] : 0); + nSyms = XkbKeyNumSyms(xkb, key); + syms = XkbKeySymsPtr(xkb, key); + if (nSyms > IBUF_SIZE) { + interps = _XkbTypedCalloc(nSyms, XkbSymInterpretPtr); + if (interps == NULL) { + interps = ibuf; + nSyms = IBUF_SIZE; + } } else { - interps= ibuf; - } - found= 0; - for (n=0;n<nSyms;n++) { - unsigned level= (n%XkbKeyGroupsWidth(xkb,key)); - interps[n]= NULL; - if (syms[n]!=NoSymbol) { - interps[n]= _XkbFindMatchingInterp(xkb,syms[n],mods,level); - if (interps[n]&&interps[n]->act.type!=XkbSA_NoAction) - found++; - else interps[n]= NULL; - } + interps = ibuf; + } + found = 0; + for (n = 0; n < nSyms; n++) { + unsigned level = (n % XkbKeyGroupsWidth(xkb, key)); + + interps[n] = NULL; + if (syms[n] != NoSymbol) { + interps[n] = _XkbFindMatchingInterp(xkb, syms[n], mods, level); + if (interps[n] && interps[n]->act.type != XkbSA_NoAction) + found++; + else + interps[n] = NULL; + } } /* 1/28/96 (ef) -- XXX! WORKING HERE */ if (!found) { - if (xkb->server->key_acts[key]!=0) { - xkb->server->key_acts[key]= 0; - changed|= XkbKeyActionsMask; - } + if (xkb->server->key_acts[key] != 0) { + xkb->server->key_acts[key] = 0; + changed |= XkbKeyActionsMask; + } } else { - XkbAction *pActs; - unsigned int new_vmodmask; - changed|= XkbKeyActionsMask; - pActs= XkbResizeKeyActions(xkb,key,nSyms); - if (!pActs) { + XkbAction *pActs; + unsigned int new_vmodmask; + + changed |= XkbKeyActionsMask; + pActs = XkbResizeKeyActions(xkb, key, nSyms); + if (!pActs) { if (nSyms > IBUF_SIZE) Xfree(interps); - return False; - } - new_vmodmask= 0; - for (n=0;n<nSyms;n++) { - if (interps[n]) { - unsigned effMods; - - pActs[n]= *((XkbAction *)&interps[n]->act); - if ((n==0)||((interps[n]->match&XkbSI_LevelOneOnly)==0)) { - effMods= mods; - if (interps[n]->virtual_mod!=XkbNoModifier) - new_vmodmask|= (1<<interps[n]->virtual_mod); - } - else effMods= 0; - _XkbSetActionKeyMods(xkb,&pActs[n],effMods); - } - else pActs[n].type= XkbSA_NoAction; - } - if (((explicit&XkbExplicitVModMapMask)==0)&& - (xkb->server->vmodmap[key]!=new_vmodmask)) { - changed|= XkbVirtualModMapMask; - xkb->server->vmodmap[key]= new_vmodmask; - } - if (interps[0]) { - if ((interps[0]->flags&XkbSI_LockingKey)&& - ((explicit&XkbExplicitBehaviorMask)==0)) { - xkb->server->behaviors[key].type= XkbKB_Lock; - changed|= XkbKeyBehaviorsMask; - } - if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) { - CARD8 old; - old= xkb->ctrls->per_key_repeat[key/8]; - if (interps[0]->flags&XkbSI_AutoRepeat) - xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8)); - else xkb->ctrls->per_key_repeat[key/8]&= ~(1<<(key%8)); - if (changes && (old!=xkb->ctrls->per_key_repeat[key/8])) - changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask; - } - } - } - if ((!found)||(interps[0]==NULL)) { - if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) { - CARD8 old; - old= xkb->ctrls->per_key_repeat[key/8]; + return False; + } + new_vmodmask = 0; + for (n = 0; n < nSyms; n++) { + if (interps[n]) { + unsigned effMods; + + pActs[n] = *((XkbAction *) &interps[n]->act); + if ((n == 0) || ((interps[n]->match & XkbSI_LevelOneOnly) == 0)) { + effMods = mods; + if (interps[n]->virtual_mod != XkbNoModifier) + new_vmodmask |= (1 << interps[n]->virtual_mod); + } + else + effMods = 0; + _XkbSetActionKeyMods(xkb, &pActs[n], effMods); + } + else + pActs[n].type = XkbSA_NoAction; + } + if (((explicit & XkbExplicitVModMapMask) == 0) && + (xkb->server->vmodmap[key] != new_vmodmask)) { + changed |= XkbVirtualModMapMask; + xkb->server->vmodmap[key] = new_vmodmask; + } + if (interps[0]) { + if ((interps[0]->flags & XkbSI_LockingKey) && + ((explicit & XkbExplicitBehaviorMask) == 0)) { + xkb->server->behaviors[key].type = XkbKB_Lock; + changed |= XkbKeyBehaviorsMask; + } + if (((explicit & XkbExplicitAutoRepeatMask) == 0) && (xkb->ctrls)) { + CARD8 old; + + old = xkb->ctrls->per_key_repeat[key / 8]; + if (interps[0]->flags & XkbSI_AutoRepeat) + xkb->ctrls->per_key_repeat[key / 8] |= (1 << (key % 8)); + else + xkb->ctrls->per_key_repeat[key / 8] &= ~(1 << (key % 8)); + if (changes && (old != xkb->ctrls->per_key_repeat[key / 8])) + changes->ctrls.changed_ctrls |= XkbPerKeyRepeatMask; + } + } + } + if ((!found) || (interps[0] == NULL)) { + if (((explicit & XkbExplicitAutoRepeatMask) == 0) && (xkb->ctrls)) { + CARD8 old; + + old = xkb->ctrls->per_key_repeat[key / 8]; #ifdef RETURN_SHOULD_REPEAT - if (*XkbKeySymsPtr(xkb,key) != XK_Return) + if (*XkbKeySymsPtr(xkb, key) != XK_Return) #endif - xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8)); - if (changes && (old!=xkb->ctrls->per_key_repeat[key/8])) - changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask; - } - if (((explicit&XkbExplicitBehaviorMask)==0)&& - (xkb->server->behaviors[key].type==XkbKB_Lock)) { - xkb->server->behaviors[key].type= XkbKB_Default; - changed|= XkbKeyBehaviorsMask; - } + xkb->ctrls->per_key_repeat[key / 8] |= (1 << (key % 8)); + if (changes && (old != xkb->ctrls->per_key_repeat[key / 8])) + changes->ctrls.changed_ctrls |= XkbPerKeyRepeatMask; + } + if (((explicit & XkbExplicitBehaviorMask) == 0) && + (xkb->server->behaviors[key].type == XkbKB_Lock)) { + xkb->server->behaviors[key].type = XkbKB_Default; + changed |= XkbKeyBehaviorsMask; + } } if (changes) { - XkbMapChangesPtr mc; - mc= &changes->map; - tmp= (changed&mc->changed); - if (tmp&XkbKeyActionsMask) - _XkbAddKeyChange(&mc->first_key_act,&mc->num_key_acts,key); - else if (changed&XkbKeyActionsMask) { - mc->changed|= XkbKeyActionsMask; - mc->first_key_act= key; - mc->num_key_acts= 1; - } - if (tmp&XkbKeyBehaviorsMask) { - _XkbAddKeyChange(&mc->first_key_behavior,&mc->num_key_behaviors, - key); - } - else if (changed&XkbKeyBehaviorsMask) { - mc->changed|= XkbKeyBehaviorsMask; - mc->first_key_behavior= key; - mc->num_key_behaviors= 1; - } - if (tmp&XkbVirtualModMapMask) - _XkbAddKeyChange(&mc->first_vmodmap_key,&mc->num_vmodmap_keys,key); - else if (changed&XkbVirtualModMapMask) { - mc->changed|= XkbVirtualModMapMask; - mc->first_vmodmap_key= key; - mc->num_vmodmap_keys= 1; - } - mc->changed|= changed; - } - if (interps!=ibuf) - _XkbFree(interps); + XkbMapChangesPtr mc; + + mc = &changes->map; + tmp = (changed & mc->changed); + if (tmp & XkbKeyActionsMask) + _XkbAddKeyChange(&mc->first_key_act, &mc->num_key_acts, key); + else if (changed & XkbKeyActionsMask) { + mc->changed |= XkbKeyActionsMask; + mc->first_key_act = key; + mc->num_key_acts = 1; + } + if (tmp & XkbKeyBehaviorsMask) { + _XkbAddKeyChange(&mc->first_key_behavior, &mc->num_key_behaviors, + key); + } + else if (changed & XkbKeyBehaviorsMask) { + mc->changed |= XkbKeyBehaviorsMask; + mc->first_key_behavior = key; + mc->num_key_behaviors = 1; + } + if (tmp & XkbVirtualModMapMask) + _XkbAddKeyChange(&mc->first_vmodmap_key, &mc->num_vmodmap_keys, + key); + else if (changed & XkbVirtualModMapMask) { + mc->changed |= XkbVirtualModMapMask; + mc->first_vmodmap_key = key; + mc->num_vmodmap_keys = 1; + } + mc->changed |= changed; + } + if (interps != ibuf) + _XkbFree(interps); return True; } Bool -XkbUpdateMapFromCore( XkbDescPtr xkb, - KeyCode first_key, - int num_keys, - int map_width, - KeySym * core_keysyms, - XkbChangesPtr changes) +XkbUpdateMapFromCore(XkbDescPtr xkb, + KeyCode first_key, + int num_keys, + int map_width, + KeySym *core_keysyms, + XkbChangesPtr changes) { -register int key,last_key; -KeySym * syms; + register int key, last_key; + KeySym *syms; - syms= &core_keysyms[(first_key-xkb->min_key_code)*map_width]; + syms = &core_keysyms[(first_key - xkb->min_key_code) * map_width]; if (changes) { - if (changes->map.changed&XkbKeySymsMask) { - _XkbAddKeyChange(&changes->map.first_key_sym, - &changes->map.num_key_syms,first_key); - if (num_keys>1) { - _XkbAddKeyChange(&changes->map.first_key_sym, - &changes->map.num_key_syms, - first_key+num_keys-1); - } - } - else { - changes->map.changed|= XkbKeySymsMask; - changes->map.first_key_sym= first_key; - changes->map.num_key_syms= num_keys; - } - } - last_key= first_key+num_keys-1; - for (key=first_key;key<=last_key;key++,syms+= map_width) { - XkbMapChangesPtr mc; - unsigned explicit; - KeySym tsyms[XkbMaxSymsPerKey]; - int types[XkbNumKbdGroups]; - int nG; - - explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask; - types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index); - types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index); - types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index); - types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index); - nG= XkbKeyTypesForCoreSymbols(xkb,map_width,syms,explicit,types,tsyms); - if (changes) - mc= &changes->map; - else mc= NULL; - XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc); - memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms, - XkbKeyNumSyms(xkb,key)*sizeof(KeySym)); - XkbApplyCompatMapToKey(xkb,key,changes); - } - - if ((xkb->map->modmap!=NULL)&&(changes)&& - (changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) { - unsigned char newVMods[XkbNumVirtualMods]; - register unsigned bit,i; - unsigned present; - - bzero(newVMods,XkbNumVirtualMods); - present= 0; - for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) { - if (xkb->server->vmodmap[key]==0) - continue; - for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { - if (bit&xkb->server->vmodmap[key]) { - present|= bit; - newVMods[i]|= xkb->map->modmap[key]; - } - } - } - for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { - if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) { - changes->map.changed|= XkbVirtualModsMask; - changes->map.vmods|= bit; - xkb->server->vmods[i]= newVMods[i]; - } - } - } - if (changes && (changes->map.changed&XkbVirtualModsMask)) - XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes); + if (changes->map.changed & XkbKeySymsMask) { + _XkbAddKeyChange(&changes->map.first_key_sym, + &changes->map.num_key_syms, first_key); + if (num_keys > 1) { + _XkbAddKeyChange(&changes->map.first_key_sym, + &changes->map.num_key_syms, + first_key + num_keys - 1); + } + } + else { + changes->map.changed |= XkbKeySymsMask; + changes->map.first_key_sym = first_key; + changes->map.num_key_syms = num_keys; + } + } + last_key = first_key + num_keys - 1; + for (key = first_key; key <= last_key; key++, syms += map_width) { + XkbMapChangesPtr mc; + unsigned explicit; + KeySym tsyms[XkbMaxSymsPerKey]; + int types[XkbNumKbdGroups]; + int nG; + + explicit = xkb->server->explicit[key] & XkbExplicitKeyTypesMask; + types[XkbGroup1Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup1Index); + types[XkbGroup2Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup2Index); + types[XkbGroup3Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup3Index); + types[XkbGroup4Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup4Index); + nG = XkbKeyTypesForCoreSymbols(xkb, map_width, syms, explicit, types, + tsyms); + if (changes) + mc = &changes->map; + else + mc = NULL; + XkbChangeTypesOfKey(xkb, key, nG, XkbAllGroupsMask, types, mc); + memcpy((char *) XkbKeySymsPtr(xkb, key), (char *) tsyms, + XkbKeyNumSyms(xkb, key) * sizeof(KeySym)); + XkbApplyCompatMapToKey(xkb, key, changes); + } + + if ((xkb->map->modmap != NULL) && (changes) && + (changes->map.changed & (XkbVirtualModMapMask | XkbModifierMapMask))) { + unsigned char newVMods[XkbNumVirtualMods]; + register unsigned bit, i; + unsigned present; + + bzero(newVMods, XkbNumVirtualMods); + present = 0; + for (key = xkb->min_key_code; key <= xkb->max_key_code; key++) { + if (xkb->server->vmodmap[key] == 0) + continue; + for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { + if (bit & xkb->server->vmodmap[key]) { + present |= bit; + newVMods[i] |= xkb->map->modmap[key]; + } + } + } + for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { + if ((bit & present) && (newVMods[i] != xkb->server->vmods[i])) { + changes->map.changed |= XkbVirtualModsMask; + changes->map.vmods |= bit; + xkb->server->vmods[i] = newVMods[i]; + } + } + } + if (changes && (changes->map.changed & XkbVirtualModsMask)) + XkbApplyVirtualModChanges(xkb, changes->map.vmods, changes); return True; } Status -XkbChangeTypesOfKey( XkbDescPtr xkb, - int key, - int nGroups, - unsigned groups, - int * newTypesIn, - XkbMapChangesPtr changes) +XkbChangeTypesOfKey(XkbDescPtr xkb, + int key, + int nGroups, + unsigned groups, + int *newTypesIn, + XkbMapChangesPtr changes) { -XkbKeyTypePtr pOldType,pNewType; -register int i; -int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups]; - - if ((!xkb) || (!XkbKeycodeInRange(xkb,key)) || (!xkb->map) || - (!xkb->map->types)||((groups&XkbAllGroupsMask)==0)|| - (nGroups>XkbNumKbdGroups)) { - return BadMatch; - } - if (nGroups==0) { - for (i=0;i<XkbNumKbdGroups;i++) { - xkb->map->key_sym_map[key].kt_index[i]= XkbOneLevelIndex; - } - i= xkb->map->key_sym_map[key].group_info; - i= XkbSetNumGroups(i,0); - xkb->map->key_sym_map[key].group_info= i; - XkbResizeKeySyms(xkb,key,0); - return Success; - } - - nOldGroups= XkbKeyNumGroups(xkb,key); - oldWidth= XkbKeyGroupsWidth(xkb,key); - for (width=i=0;i<nGroups;i++) { - if (groups&(1<<i)) - newTypes[i]= newTypesIn[i]; - else if (i<nOldGroups) - newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,i); - else if (nOldGroups>0) - newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index); - else newTypes[i]= XkbTwoLevelIndex; - if (newTypes[i]>xkb->map->num_types) - return BadMatch; - pNewType= &xkb->map->types[newTypes[i]]; - if (pNewType->num_levels>width) - width= pNewType->num_levels; - } - if ((xkb->ctrls)&&(nGroups>xkb->ctrls->num_groups)) - xkb->ctrls->num_groups= nGroups; - if ((width!=oldWidth)||(nGroups!=nOldGroups)) { - KeySym oldSyms[XkbMaxSymsPerKey],*pSyms; - int nCopy; - - if (nOldGroups==0) { - pSyms= XkbResizeKeySyms(xkb,key,width*nGroups); - if (pSyms!=NULL) { - i= xkb->map->key_sym_map[key].group_info; - i= XkbSetNumGroups(i,nGroups); - xkb->map->key_sym_map[key].group_info= i; - xkb->map->key_sym_map[key].width= width; - for (i=0;i<nGroups;i++) { - xkb->map->key_sym_map[key].kt_index[i]= newTypes[i]; - } - return Success; - } - return BadAlloc; - } - pSyms= XkbKeySymsPtr(xkb,key); - memcpy(oldSyms,pSyms,XkbKeyNumSyms(xkb,key)*sizeof(KeySym)); - pSyms= XkbResizeKeySyms(xkb,key,width*nGroups); - if (pSyms==NULL) - return BadAlloc; - bzero(pSyms,width*nGroups*sizeof(KeySym)); - for (i=0;(i<nGroups)&&(i<nOldGroups);i++) { - pOldType= XkbKeyKeyType(xkb,key,i); - pNewType= &xkb->map->types[newTypes[i]]; - if (pNewType->num_levels>pOldType->num_levels) - nCopy= pOldType->num_levels; - else nCopy= pNewType->num_levels; - memcpy(&pSyms[i*width],&oldSyms[i*oldWidth],nCopy*sizeof(KeySym)); - } - if (XkbKeyHasActions(xkb,key)) { - XkbAction oldActs[XkbMaxSymsPerKey],*pActs; - pActs= XkbKeyActionsPtr(xkb,key); - memcpy(oldActs,pActs,XkbKeyNumSyms(xkb,key)*sizeof(XkbAction)); - pActs= XkbResizeKeyActions(xkb,key,width*nGroups); - if (pActs==NULL) - return BadAlloc; - bzero(pActs,width*nGroups*sizeof(XkbAction)); - for (i=0;(i<nGroups)&&(i<nOldGroups);i++) { - pOldType= XkbKeyKeyType(xkb,key,i); - pNewType= &xkb->map->types[newTypes[i]]; - if (pNewType->num_levels>pOldType->num_levels) - nCopy= pOldType->num_levels; - else nCopy= pNewType->num_levels; - memcpy(&pActs[i*width],&oldActs[i*oldWidth], - nCopy*sizeof(XkbAction)); - } - } - i= xkb->map->key_sym_map[key].group_info; - i= XkbSetNumGroups(i,nGroups); - xkb->map->key_sym_map[key].group_info= i; - xkb->map->key_sym_map[key].width= width; - } - width= 0; - for (i=0;i<nGroups;i++) { - xkb->map->key_sym_map[key].kt_index[i]= newTypes[i]; - if (xkb->map->types[newTypes[i]].num_levels>width) - width= xkb->map->types[newTypes[i]].num_levels; - } - xkb->map->key_sym_map[key].width= width; - if (changes!=NULL) { - if (changes->changed&XkbKeySymsMask) { - _XkbAddKeyChange(&changes->first_key_sym,&changes->num_key_syms, - key); - } - else { - changes->changed|= XkbKeySymsMask; - changes->first_key_sym= key; - changes->num_key_syms= 1; - } + XkbKeyTypePtr pOldType, pNewType; + register int i; + int width, nOldGroups, oldWidth, newTypes[XkbNumKbdGroups]; + + if ((!xkb) || (!XkbKeycodeInRange(xkb, key)) || (!xkb->map) || + (!xkb->map->types) || ((groups & XkbAllGroupsMask) == 0) || + (nGroups > XkbNumKbdGroups)) { + return BadMatch; + } + if (nGroups == 0) { + for (i = 0; i < XkbNumKbdGroups; i++) { + xkb->map->key_sym_map[key].kt_index[i] = XkbOneLevelIndex; + } + i = xkb->map->key_sym_map[key].group_info; + i = XkbSetNumGroups(i, 0); + xkb->map->key_sym_map[key].group_info = i; + XkbResizeKeySyms(xkb, key, 0); + return Success; + } + + nOldGroups = XkbKeyNumGroups(xkb, key); + oldWidth = XkbKeyGroupsWidth(xkb, key); + for (width = i = 0; i < nGroups; i++) { + if (groups & (1 << i)) + newTypes[i] = newTypesIn[i]; + else if (i < nOldGroups) + newTypes[i] = XkbKeyKeyTypeIndex(xkb, key, i); + else if (nOldGroups > 0) + newTypes[i] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup1Index); + else + newTypes[i] = XkbTwoLevelIndex; + if (newTypes[i] > xkb->map->num_types) + return BadMatch; + pNewType = &xkb->map->types[newTypes[i]]; + if (pNewType->num_levels > width) + width = pNewType->num_levels; + } + if ((xkb->ctrls) && (nGroups > xkb->ctrls->num_groups)) + xkb->ctrls->num_groups = nGroups; + if ((width != oldWidth) || (nGroups != nOldGroups)) { + KeySym oldSyms[XkbMaxSymsPerKey], *pSyms; + int nCopy; + + if (nOldGroups == 0) { + pSyms = XkbResizeKeySyms(xkb, key, width * nGroups); + if (pSyms != NULL) { + i = xkb->map->key_sym_map[key].group_info; + i = XkbSetNumGroups(i, nGroups); + xkb->map->key_sym_map[key].group_info = i; + xkb->map->key_sym_map[key].width = width; + for (i = 0; i < nGroups; i++) { + xkb->map->key_sym_map[key].kt_index[i] = newTypes[i]; + } + return Success; + } + return BadAlloc; + } + pSyms = XkbKeySymsPtr(xkb, key); + memcpy(oldSyms, pSyms, XkbKeyNumSyms(xkb, key) * sizeof(KeySym)); + pSyms = XkbResizeKeySyms(xkb, key, width * nGroups); + if (pSyms == NULL) + return BadAlloc; + bzero(pSyms, width * nGroups * sizeof(KeySym)); + for (i = 0; (i < nGroups) && (i < nOldGroups); i++) { + pOldType = XkbKeyKeyType(xkb, key, i); + pNewType = &xkb->map->types[newTypes[i]]; + if (pNewType->num_levels > pOldType->num_levels) + nCopy = pOldType->num_levels; + else + nCopy = pNewType->num_levels; + memcpy(&pSyms[i * width], &oldSyms[i * oldWidth], + nCopy * sizeof(KeySym)); + } + if (XkbKeyHasActions(xkb, key)) { + XkbAction oldActs[XkbMaxSymsPerKey], *pActs; + + pActs = XkbKeyActionsPtr(xkb, key); + memcpy(oldActs, pActs, XkbKeyNumSyms(xkb, key) * sizeof(XkbAction)); + pActs = XkbResizeKeyActions(xkb, key, width * nGroups); + if (pActs == NULL) + return BadAlloc; + bzero(pActs, width * nGroups * sizeof(XkbAction)); + for (i = 0; (i < nGroups) && (i < nOldGroups); i++) { + pOldType = XkbKeyKeyType(xkb, key, i); + pNewType = &xkb->map->types[newTypes[i]]; + if (pNewType->num_levels > pOldType->num_levels) + nCopy = pOldType->num_levels; + else + nCopy = pNewType->num_levels; + memcpy(&pActs[i * width], &oldActs[i * oldWidth], + nCopy * sizeof(XkbAction)); + } + } + i = xkb->map->key_sym_map[key].group_info; + i = XkbSetNumGroups(i, nGroups); + xkb->map->key_sym_map[key].group_info = i; + xkb->map->key_sym_map[key].width = width; + } + width = 0; + for (i = 0; i < nGroups; i++) { + xkb->map->key_sym_map[key].kt_index[i] = newTypes[i]; + if (xkb->map->types[newTypes[i]].num_levels > width) + width = xkb->map->types[newTypes[i]].num_levels; + } + xkb->map->key_sym_map[key].width = width; + if (changes != NULL) { + if (changes->changed & XkbKeySymsMask) { + _XkbAddKeyChange(&changes->first_key_sym, &changes->num_key_syms, + key); + } + else { + changes->changed |= XkbKeySymsMask; + changes->first_key_sym = key; + changes->num_key_syms = 1; + } } return Success; } @@ -765,204 +802,223 @@ int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups]; /***====================================================================***/ Bool -XkbVirtualModsToReal(XkbDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn) +XkbVirtualModsToReal(XkbDescPtr xkb, unsigned virtual_mask, unsigned *mask_rtrn) { -register int i,bit; -register unsigned mask; - - if (xkb==NULL) - return False; - if (virtual_mask==0) { - *mask_rtrn= 0; - return True; - } - if (xkb->server==NULL) - return False; - for (i=mask=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { - if (virtual_mask&bit) - mask|= xkb->server->vmods[i]; - } - *mask_rtrn= mask; + register int i, bit; + register unsigned mask; + + if (xkb == NULL) + return False; + if (virtual_mask == 0) { + *mask_rtrn = 0; + return True; + } + if (xkb->server == NULL) + return False; + for (i = mask = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { + if (virtual_mask & bit) + mask |= xkb->server->vmods[i]; + } + *mask_rtrn = mask; return True; } /***====================================================================***/ Bool -XkbUpdateActionVirtualMods(XkbDescPtr xkb,XkbAction *act,unsigned changed) +XkbUpdateActionVirtualMods(XkbDescPtr xkb, XkbAction *act, unsigned changed) { -unsigned int tmp; + unsigned int tmp; switch (act->type) { - case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods: - if (((tmp= XkbModActionVMods(&act->mods))&changed)!=0) { - XkbVirtualModsToReal(xkb,tmp,&tmp); - act->mods.mask= act->mods.real_mods; - act->mods.mask|= tmp; - return True; - } - break; - case XkbSA_ISOLock: - if ((((tmp= XkbModActionVMods(&act->iso))!=0)&changed)!=0) { - XkbVirtualModsToReal(xkb,tmp,&tmp); - act->iso.mask= act->iso.real_mods; - act->iso.mask|= tmp; - return True; - } - break; + case XkbSA_SetMods: + case XkbSA_LatchMods: + case XkbSA_LockMods: + if (((tmp = XkbModActionVMods(&act->mods)) & changed) != 0) { + XkbVirtualModsToReal(xkb, tmp, &tmp); + act->mods.mask = act->mods.real_mods; + act->mods.mask |= tmp; + return True; + } + break; + case XkbSA_ISOLock: + if ((((tmp = XkbModActionVMods(&act->iso)) != 0) & changed) != 0) { + XkbVirtualModsToReal(xkb, tmp, &tmp); + act->iso.mask = act->iso.real_mods; + act->iso.mask |= tmp; + return True; + } + break; } return False; } void -XkbUpdateKeyTypeVirtualMods( XkbDescPtr xkb, - XkbKeyTypePtr type, - unsigned int changed, - XkbChangesPtr changes) +XkbUpdateKeyTypeVirtualMods(XkbDescPtr xkb, + XkbKeyTypePtr type, + unsigned int changed, + XkbChangesPtr changes) { -register unsigned int i; -unsigned int mask; - - XkbVirtualModsToReal(xkb,type->mods.vmods,&mask); - type->mods.mask= type->mods.real_mods|mask; - if ((type->map_count>0)&&(type->mods.vmods!=0)) { - XkbKTMapEntryPtr entry; - for (i=0,entry=type->map;i<type->map_count;i++,entry++) { - if (entry->mods.vmods!=0) { - XkbVirtualModsToReal(xkb,entry->mods.vmods,&mask); - entry->mods.mask=entry->mods.real_mods|mask; - /* entry is active if vmods are bound*/ - entry->active= (mask!=0); - } - else entry->active= 1; - } + register unsigned int i; + unsigned int mask; + + XkbVirtualModsToReal(xkb, type->mods.vmods, &mask); + type->mods.mask = type->mods.real_mods | mask; + if ((type->map_count > 0) && (type->mods.vmods != 0)) { + XkbKTMapEntryPtr entry; + + for (i = 0, entry = type->map; i < type->map_count; i++, entry++) { + if (entry->mods.vmods != 0) { + XkbVirtualModsToReal(xkb, entry->mods.vmods, &mask); + entry->mods.mask = entry->mods.real_mods | mask; + /* entry is active if vmods are bound */ + entry->active = (mask != 0); + } + else + entry->active = 1; + } } if (changes) { - int type_ndx; - type_ndx= type-xkb->map->types; - if ((type_ndx<0)||(type_ndx>xkb->map->num_types)) - return; - if (changes->map.changed&XkbKeyTypesMask) { - int last; - last= changes->map.first_type+changes->map.num_types-1; - if (type_ndx<changes->map.first_type) { - changes->map.first_type= type_ndx; - changes->map.num_types= (last-type_ndx)+1; - } - else if (type_ndx>last) { - changes->map.num_types= (type_ndx-changes->map.first_type)+1; - } - } - else { - changes->map.changed|= XkbKeyTypesMask; - changes->map.first_type= type_ndx; - changes->map.num_types= 1; - } + int type_ndx; + + type_ndx = type - xkb->map->types; + if ((type_ndx < 0) || (type_ndx > xkb->map->num_types)) + return; + if (changes->map.changed & XkbKeyTypesMask) { + int last; + + last = changes->map.first_type + changes->map.num_types - 1; + if (type_ndx < changes->map.first_type) { + changes->map.first_type = type_ndx; + changes->map.num_types = (last - type_ndx) + 1; + } + else if (type_ndx > last) { + changes->map.num_types = + (type_ndx - changes->map.first_type) + 1; + } + } + else { + changes->map.changed |= XkbKeyTypesMask; + changes->map.first_type = type_ndx; + changes->map.num_types = 1; + } } return; } Bool -XkbApplyVirtualModChanges(XkbDescPtr xkb,unsigned changed,XkbChangesPtr changes) +XkbApplyVirtualModChanges(XkbDescPtr xkb, + unsigned changed, + XkbChangesPtr changes) { -register int i; -unsigned int checkState = 0; - - if ((!xkb) || (!xkb->map) || (changed==0)) - return False; - for (i=0;i<xkb->map->num_types;i++) { - if (xkb->map->types[i].mods.vmods & changed) - XkbUpdateKeyTypeVirtualMods(xkb,&xkb->map->types[i],changed,changes); - } - if (changed&xkb->ctrls->internal.vmods) { - unsigned int newMask; - XkbVirtualModsToReal(xkb,xkb->ctrls->internal.vmods,&newMask); - newMask|= xkb->ctrls->internal.real_mods; - if (xkb->ctrls->internal.mask!=newMask) { - xkb->ctrls->internal.mask= newMask; - if (changes) { - changes->ctrls.changed_ctrls|= XkbInternalModsMask; - checkState= True; - } - } - } - if (changed&xkb->ctrls->ignore_lock.vmods) { - unsigned int newMask; - XkbVirtualModsToReal(xkb,xkb->ctrls->ignore_lock.vmods,&newMask); - newMask|= xkb->ctrls->ignore_lock.real_mods; - if (xkb->ctrls->ignore_lock.mask!=newMask) { - xkb->ctrls->ignore_lock.mask= newMask; - if (changes) { - changes->ctrls.changed_ctrls|= XkbIgnoreLockModsMask; - checkState= True; - } - } - } - if (xkb->indicators!=NULL) { - XkbIndicatorMapPtr map; - map= &xkb->indicators->maps[0]; - for (i=0;i<XkbNumIndicators;i++,map++) { - if (map->mods.vmods&changed) { - unsigned int newMask; - XkbVirtualModsToReal(xkb,map->mods.vmods,&newMask); - newMask|= map->mods.real_mods; - if (newMask!=map->mods.mask) { - map->mods.mask= newMask; - if (changes) { - changes->indicators.map_changes|= (1<<i); - checkState= True; - } - } - } - } - } - if (xkb->compat!=NULL) { - XkbCompatMapPtr compat; - compat= xkb->compat; - for (i=0;i<XkbNumKbdGroups;i++) { - unsigned int newMask; - XkbVirtualModsToReal(xkb,compat->groups[i].vmods,&newMask); - newMask|= compat->groups[i].real_mods; - if (compat->groups[i].mask!=newMask) { - compat->groups[i].mask= newMask; - if (changes) { - changes->compat.changed_groups|= (1<<i); - checkState= True; - } - } - } + register int i; + unsigned int checkState = 0; + + if ((!xkb) || (!xkb->map) || (changed == 0)) + return False; + for (i = 0; i < xkb->map->num_types; i++) { + if (xkb->map->types[i].mods.vmods & changed) + XkbUpdateKeyTypeVirtualMods(xkb, &xkb->map->types[i], changed, + changes); + } + if (changed & xkb->ctrls->internal.vmods) { + unsigned int newMask; + + XkbVirtualModsToReal(xkb, xkb->ctrls->internal.vmods, &newMask); + newMask |= xkb->ctrls->internal.real_mods; + if (xkb->ctrls->internal.mask != newMask) { + xkb->ctrls->internal.mask = newMask; + if (changes) { + changes->ctrls.changed_ctrls |= XkbInternalModsMask; + checkState = True; + } + } + } + if (changed & xkb->ctrls->ignore_lock.vmods) { + unsigned int newMask; + + XkbVirtualModsToReal(xkb, xkb->ctrls->ignore_lock.vmods, &newMask); + newMask |= xkb->ctrls->ignore_lock.real_mods; + if (xkb->ctrls->ignore_lock.mask != newMask) { + xkb->ctrls->ignore_lock.mask = newMask; + if (changes) { + changes->ctrls.changed_ctrls |= XkbIgnoreLockModsMask; + checkState = True; + } + } + } + if (xkb->indicators != NULL) { + XkbIndicatorMapPtr map; + + map = &xkb->indicators->maps[0]; + for (i = 0; i < XkbNumIndicators; i++, map++) { + if (map->mods.vmods & changed) { + unsigned int newMask; + + XkbVirtualModsToReal(xkb, map->mods.vmods, &newMask); + newMask |= map->mods.real_mods; + if (newMask != map->mods.mask) { + map->mods.mask = newMask; + if (changes) { + changes->indicators.map_changes |= (1 << i); + checkState = True; + } + } + } + } + } + if (xkb->compat != NULL) { + XkbCompatMapPtr compat; + + compat = xkb->compat; + for (i = 0; i < XkbNumKbdGroups; i++) { + unsigned int newMask; + + XkbVirtualModsToReal(xkb, compat->groups[i].vmods, &newMask); + newMask |= compat->groups[i].real_mods; + if (compat->groups[i].mask != newMask) { + compat->groups[i].mask = newMask; + if (changes) { + changes->compat.changed_groups |= (1 << i); + checkState = True; + } + } + } } if (xkb->map && xkb->server) { - int highChange = 0, lowChange = -1; - for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) { - if (XkbKeyHasActions(xkb,i)) { - register XkbAction *pAct; - register int n; - - pAct= XkbKeyActionsPtr(xkb,i); - for (n=XkbKeyNumActions(xkb,i);n>0;n--,pAct++) { - if ((pAct->type!=XkbSA_NoAction)&& - XkbUpdateActionVirtualMods(xkb,pAct,changed)) { - if (lowChange<0) - lowChange= i; - highChange= i; - } - } - } - } - if (changes && (lowChange>0)) { /* something changed */ - if (changes->map.changed&XkbKeyActionsMask) { - int last; - if (changes->map.first_key_act<lowChange) - lowChange= changes->map.first_key_act; - last= changes->map.first_key_act+changes->map.num_key_acts-1; - if (last>highChange) - highChange= last; - } - changes->map.changed|= XkbKeyActionsMask; - changes->map.first_key_act= lowChange; - changes->map.num_key_acts= (highChange-lowChange)+1; - } + int highChange = 0, lowChange = -1; + + for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) { + if (XkbKeyHasActions(xkb, i)) { + register XkbAction *pAct; + register int n; + + pAct = XkbKeyActionsPtr(xkb, i); + for (n = XkbKeyNumActions(xkb, i); n > 0; n--, pAct++) { + if ((pAct->type != XkbSA_NoAction) && + XkbUpdateActionVirtualMods(xkb, pAct, changed)) { + if (lowChange < 0) + lowChange = i; + highChange = i; + } + } + } + } + if (changes && (lowChange > 0)) { /* something changed */ + if (changes->map.changed & XkbKeyActionsMask) { + int last; + + if (changes->map.first_key_act < lowChange) + lowChange = changes->map.first_key_act; + last = + changes->map.first_key_act + changes->map.num_key_acts - 1; + if (last > highChange) + highChange = last; + } + changes->map.changed |= XkbKeyActionsMask; + changes->map.first_key_act = lowChange; + changes->map.num_key_acts = (highChange - lowChange) + 1; + } } return checkState; } diff --git a/libX11/src/xkb/XKBNames.c b/libX11/src/xkb/XKBNames.c index 3a8860be7..3f2fd39d7 100644 --- a/libX11/src/xkb/XKBNames.c +++ b/libX11/src/xkb/XKBNames.c @@ -34,234 +34,240 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. static Status -_XkbReadAtoms( XkbReadBufferPtr buf, - Atom * atoms, - int maxAtoms, - CARD32 present) +_XkbReadAtoms(XkbReadBufferPtr buf, + Atom *atoms, + int maxAtoms, + CARD32 present) { -register int i,bit; + register int i, bit; - for (i=0,bit=1;(i<maxAtoms)&&(present);i++,bit<<=1) { - if (present&bit) { - if (!_XkbReadBufferCopy32(buf,(long *)&atoms[i],1)) - return BadLength; - present&= ~bit; - } + for (i = 0, bit = 1; (i < maxAtoms) && (present); i++, bit <<= 1) { + if (present & bit) { + if (!_XkbReadBufferCopy32(buf, (long *) &atoms[i], 1)) + return BadLength; + present &= ~bit; + } } return Success; } Status -_XkbReadGetNamesReply( Display * dpy, - xkbGetNamesReply * rep, - XkbDescPtr xkb, - int * nread_rtrn) +_XkbReadGetNamesReply(Display *dpy, + xkbGetNamesReply *rep, + XkbDescPtr xkb, + int *nread_rtrn) { - int i,len; - XkbReadBufferRec buf; - register XkbNamesPtr names; + int i, len; + XkbReadBufferRec buf; + register XkbNamesPtr names; - if ( xkb->device_spec == XkbUseCoreKbd ) - xkb->device_spec = rep->deviceID; + if (xkb->device_spec == XkbUseCoreKbd) + xkb->device_spec = rep->deviceID; - if ((xkb->names==NULL)&& - (XkbAllocNames(xkb,rep->which, - rep->nRadioGroups,rep->nKeyAliases)!=Success)) { - return BadAlloc; + if ((xkb->names == NULL) && + (XkbAllocNames(xkb, rep->which, + rep->nRadioGroups, rep->nKeyAliases) != Success)) { + return BadAlloc; } - names= xkb->names; - if (rep->length==0) - return Success; + names = xkb->names; + if (rep->length == 0) + return Success; - if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) - return BadAlloc; + if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4)) + return BadAlloc; if (nread_rtrn) - *nread_rtrn= (int)rep->length*4; - - if ((rep->which&XkbKeycodesNameMask)&& - (!_XkbReadBufferCopy32(&buf,(long *)&names->keycodes,1))) - goto BAILOUT; - if ((rep->which&XkbGeometryNameMask)&& - (!_XkbReadBufferCopy32(&buf,(long *)&names->geometry,1))) - goto BAILOUT; - if ((rep->which&XkbSymbolsNameMask)&& - (!_XkbReadBufferCopy32(&buf,(long *)&names->symbols,1))) - goto BAILOUT; - if ((rep->which&XkbPhysSymbolsNameMask)&& - (!_XkbReadBufferCopy32(&buf,(long *)&names->phys_symbols,1))) - goto BAILOUT; - if ((rep->which&XkbTypesNameMask)&& - (!_XkbReadBufferCopy32(&buf,(long *)&names->types,1))) - goto BAILOUT; - if ((rep->which&XkbCompatNameMask)&& - (!_XkbReadBufferCopy32(&buf,(long *)&names->compat,1))) - goto BAILOUT; - - if ( rep->which & XkbKeyTypeNamesMask ) { - XkbClientMapPtr map= xkb->map; - XkbKeyTypePtr type; - - len= rep->nTypes*4; - if (map!=NULL) { - type= map->types; - for (i=0;(i<map->num_types)&&(i<rep->nTypes);i++,type++) { - if (!_XkbReadBufferCopy32(&buf,(long *)&type->name,1)) - goto BAILOUT; - len-= 4; - } - } - if ((len>0)&&(!_XkbSkipReadBufferData(&buf,len))) - goto BAILOUT; - } - if ( rep->which&XkbKTLevelNamesMask ) { - CARD8 *nLevels; - XkbClientMapPtr map= xkb->map; - XkbKeyTypePtr type; - - nLevels=(CARD8*)_XkbGetReadBufferPtr(&buf,XkbPaddedSize(rep->nTypes)); - if (nLevels==NULL) - goto BAILOUT; - if (map!=NULL) { - type= map->types; - for (i=0;i<(int)rep->nTypes;i++,type++) { - if (i>=map->num_types) { - if (!_XkbSkipReadBufferData(&buf,nLevels[i]*4)) - goto BAILOUT; - continue; - } - if ((nLevels[i]>0)&&(nLevels[i]!=type->num_levels)) { - goto BAILOUT; - } - if (type->level_names!=NULL) - Xfree(type->level_names); - if (nLevels[i]==0) { - type->level_names= NULL; - continue; - } - type->level_names= _XkbTypedCalloc(nLevels[i],Atom); - if (type->level_names!=NULL) { - if (!_XkbReadBufferCopy32(&buf,(long *)type->level_names, - nLevels[i])) - goto BAILOUT; - } - else { - _XkbSkipReadBufferData(&buf,nLevels[i]*4); - } - } - } - else { - for (i=0;i<(int)rep->nTypes;i++) { - _XkbSkipReadBufferData(&buf,nLevels[i]*4); - } - } + *nread_rtrn = (int) rep->length * 4; + + if ((rep->which & XkbKeycodesNameMask) && + (!_XkbReadBufferCopy32(&buf, (long *) &names->keycodes, 1))) + goto BAILOUT; + if ((rep->which & XkbGeometryNameMask) && + (!_XkbReadBufferCopy32(&buf, (long *) &names->geometry, 1))) + goto BAILOUT; + if ((rep->which & XkbSymbolsNameMask) && + (!_XkbReadBufferCopy32(&buf, (long *) &names->symbols, 1))) + goto BAILOUT; + if ((rep->which & XkbPhysSymbolsNameMask) && + (!_XkbReadBufferCopy32(&buf, (long *) &names->phys_symbols, 1))) + goto BAILOUT; + if ((rep->which & XkbTypesNameMask) && + (!_XkbReadBufferCopy32(&buf, (long *) &names->types, 1))) + goto BAILOUT; + if ((rep->which & XkbCompatNameMask) && + (!_XkbReadBufferCopy32(&buf, (long *) &names->compat, 1))) + goto BAILOUT; + + if (rep->which & XkbKeyTypeNamesMask) { + XkbClientMapPtr map = xkb->map; + XkbKeyTypePtr type; + + len = rep->nTypes * 4; + if (map != NULL) { + type = map->types; + for (i = 0; (i < map->num_types) && (i < rep->nTypes); i++, type++) { + if (!_XkbReadBufferCopy32(&buf, (long *) &type->name, 1)) + goto BAILOUT; + len -= 4; + } + } + if ((len > 0) && (!_XkbSkipReadBufferData(&buf, len))) + goto BAILOUT; + } + if (rep->which & XkbKTLevelNamesMask) { + CARD8 *nLevels; + XkbClientMapPtr map = xkb->map; + + nLevels = + (CARD8 *) _XkbGetReadBufferPtr(&buf, XkbPaddedSize(rep->nTypes)); + if (nLevels == NULL) + goto BAILOUT; + if (map != NULL) { + XkbKeyTypePtr type = map->types; + + for (i = 0; i < (int) rep->nTypes; i++, type++) { + if (i >= map->num_types) { + if (!_XkbSkipReadBufferData(&buf, nLevels[i] * 4)) + goto BAILOUT; + continue; + } + if ((nLevels[i] > 0) && (nLevels[i] != type->num_levels)) { + goto BAILOUT; + } + if (type->level_names != NULL) + Xfree(type->level_names); + if (nLevels[i] == 0) { + type->level_names = NULL; + continue; + } + type->level_names = _XkbTypedCalloc(nLevels[i], Atom); + if (type->level_names != NULL) { + if (!_XkbReadBufferCopy32(&buf, (long *) type->level_names, + nLevels[i])) + goto BAILOUT; + } + else { + _XkbSkipReadBufferData(&buf, nLevels[i] * 4); + } + } + } + else { + for (i = 0; i < (int) rep->nTypes; i++) { + _XkbSkipReadBufferData(&buf, nLevels[i] * 4); + } + } } if (rep->which & XkbIndicatorNamesMask) { - if (_XkbReadAtoms(&buf,names->indicators,XkbNumIndicators, - rep->indicators)!=Success) - goto BAILOUT; - } - if ( rep->which&XkbVirtualModNamesMask ) { - if (_XkbReadAtoms(&buf,names->vmods,XkbNumVirtualMods, - (CARD32)rep->virtualMods)!=Success) - goto BAILOUT; - } - if ( rep->which&XkbGroupNamesMask ) { - if (_XkbReadAtoms(&buf,names->groups,XkbNumKbdGroups, - (CARD32)rep->groupNames)!=Success) - goto BAILOUT; - } - if ( rep->which&XkbKeyNamesMask ) { - if (names->keys==NULL) { - int nKeys; - if (xkb->max_key_code==0) { - xkb->min_key_code= rep->minKeyCode; - xkb->max_key_code= rep->maxKeyCode; - } - nKeys= xkb->max_key_code+1; - names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec); - } - if ( ((int)rep->firstKey + rep->nKeys) > xkb->max_key_code + 1) - goto BAILOUT; - if (names->keys!=NULL) { - if (!_XkbCopyFromReadBuffer(&buf, - (char *)&names->keys[rep->firstKey], - rep->nKeys*XkbKeyNameLength)) - goto BAILOUT; - } - else _XkbSkipReadBufferData(&buf,rep->nKeys*XkbKeyNameLength); - } - if ( rep->which&XkbKeyAliasesMask && (rep->nKeyAliases>0) ) { - if (XkbAllocNames(xkb,XkbKeyAliasesMask,0,rep->nKeyAliases)!=Success) - goto BAILOUT; - if (!_XkbCopyFromReadBuffer(&buf,(char *)names->key_aliases, - rep->nKeyAliases*XkbKeyNameLength*2)) - goto BAILOUT; - } - if ( rep->which&XkbRGNamesMask ) { - if (rep->nRadioGroups>0) { - Atom *rgNames; - - if (names->radio_groups==NULL) - names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups,Atom); - else if (names->num_rg<rep->nRadioGroups) { - names->radio_groups = _XkbTypedRealloc(names->radio_groups, - rep->nRadioGroups, - Atom); - } - rgNames= names->radio_groups; - if (!rgNames) { - goto BAILOUT; - } - if (!_XkbReadBufferCopy32(&buf,(long *)rgNames,rep->nRadioGroups)) - goto BAILOUT; - names->num_rg= rep->nRadioGroups; - } - else if (names->num_rg>0) { - names->num_rg= 0; - Xfree(names->radio_groups); - } - } - len= _XkbFreeReadBuffer(&buf); - if (len!=0) return BadLength; - else return Success; -BAILOUT: + if (_XkbReadAtoms(&buf, names->indicators, XkbNumIndicators, + rep->indicators) != Success) + goto BAILOUT; + } + if (rep->which & XkbVirtualModNamesMask) { + if (_XkbReadAtoms(&buf, names->vmods, XkbNumVirtualMods, + (CARD32) rep->virtualMods) != Success) + goto BAILOUT; + } + if (rep->which & XkbGroupNamesMask) { + if (_XkbReadAtoms(&buf, names->groups, XkbNumKbdGroups, + (CARD32) rep->groupNames) != Success) + goto BAILOUT; + } + if (rep->which & XkbKeyNamesMask) { + if (names->keys == NULL) { + int nKeys; + + if (xkb->max_key_code == 0) { + xkb->min_key_code = rep->minKeyCode; + xkb->max_key_code = rep->maxKeyCode; + } + nKeys = xkb->max_key_code + 1; + names->keys = _XkbTypedCalloc(nKeys, XkbKeyNameRec); + } + if (((int) rep->firstKey + rep->nKeys) > xkb->max_key_code + 1) + goto BAILOUT; + if (names->keys != NULL) { + if (!_XkbCopyFromReadBuffer(&buf, + (char *) &names->keys[rep->firstKey], + rep->nKeys * XkbKeyNameLength)) + goto BAILOUT; + } + else + _XkbSkipReadBufferData(&buf, rep->nKeys * XkbKeyNameLength); + } + if (rep->which & XkbKeyAliasesMask && (rep->nKeyAliases > 0)) { + if (XkbAllocNames(xkb, XkbKeyAliasesMask, 0, rep->nKeyAliases) != + Success) + goto BAILOUT; + if (!_XkbCopyFromReadBuffer(&buf, (char *) names->key_aliases, + rep->nKeyAliases * XkbKeyNameLength * 2)) + goto BAILOUT; + } + if (rep->which & XkbRGNamesMask) { + if (rep->nRadioGroups > 0) { + Atom *rgNames; + + if (names->radio_groups == NULL) + names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups, Atom); + else if (names->num_rg < rep->nRadioGroups) { + names->radio_groups = _XkbTypedRealloc(names->radio_groups, + rep->nRadioGroups, Atom); + } + rgNames = names->radio_groups; + if (!rgNames) { + goto BAILOUT; + } + if (!_XkbReadBufferCopy32 + (&buf, (long *) rgNames, rep->nRadioGroups)) + goto BAILOUT; + names->num_rg = rep->nRadioGroups; + } + else if (names->num_rg > 0) { + names->num_rg = 0; + Xfree(names->radio_groups); + } + } + len = _XkbFreeReadBuffer(&buf); + if (len != 0) + return BadLength; + else + return Success; + BAILOUT: _XkbFreeReadBuffer(&buf); return BadLength; } Status -XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb) +XkbGetNames(Display *dpy, unsigned which, XkbDescPtr xkb) { register xkbGetNamesReq *req; - xkbGetNamesReply rep; - Status status; + xkbGetNamesReply rep; + Status status; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); xkbi = dpy->xkb_info; if (!xkb->names) { - xkb->names = _XkbTypedCalloc(1,XkbNamesRec); - if (!xkb->names) { - UnlockDisplay(dpy); - SyncHandle(); - return BadAlloc; - } + xkb->names = _XkbTypedCalloc(1, XkbNamesRec); + if (!xkb->names) { + UnlockDisplay(dpy); + SyncHandle(); + return BadAlloc; + } } GetReq(kbGetNames, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetNames; req->deviceSpec = xkb->device_spec; req->which = which; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadImplementation; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadImplementation; } - status = _XkbReadGetNamesReply(dpy,&rep,xkb,NULL); + status = _XkbReadGetNamesReply(dpy, &rep, xkb, NULL); UnlockDisplay(dpy); SyncHandle(); return status; @@ -270,12 +276,12 @@ XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb) /***====================================================================***/ static int -_XkbCountBits(int nBitsMax,unsigned long mask) +_XkbCountBits(int nBitsMax, unsigned long mask) { -register unsigned long y, nBits; + register unsigned long y, nBits; - y = (mask >> 1) &033333333333; - y = mask - y - ((y >>1) & 033333333333); + y = (mask >> 1) & 033333333333; + y = mask - y - ((y >> 1) & 033333333333); nBits = ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077)); /* nBitsMax really means max+1 */ @@ -283,85 +289,87 @@ register unsigned long y, nBits; } static CARD32 -_XkbCountAtoms(Atom *atoms,int maxAtoms,int *count) +_XkbCountAtoms(Atom *atoms, int maxAtoms, int *count) { -register unsigned int i,bit,nAtoms; -register CARD32 atomsPresent; + register unsigned int i, bit, nAtoms; + register CARD32 atomsPresent; - for (i=nAtoms=atomsPresent=0,bit=1;i<maxAtoms;i++,bit<<=1) { - if (atoms[i]!=None) { - atomsPresent|= bit; + for (i = nAtoms = atomsPresent = 0, bit = 1; i < maxAtoms; i++, bit <<= 1) { + if (atoms[i] != None) { + atomsPresent |= bit; nAtoms++; } } if (count) - *count= nAtoms; + *count = nAtoms; return atomsPresent; } static void -_XkbCopyAtoms(Display *dpy,Atom *atoms,CARD32 mask,int maxAtoms) +_XkbCopyAtoms(Display *dpy, Atom *atoms, CARD32 mask, int maxAtoms) { -register unsigned int i,bit; + register unsigned int i, bit; - for (i=0,bit=1;i<maxAtoms;i++,bit<<=1) { - if (mask&bit) - Data32(dpy,&atoms[i],4); + for (i = 0, bit = 1; i < maxAtoms; i++, bit <<= 1) { + if (mask & bit) + Data32(dpy, &atoms[i], 4); } return; } Bool -XkbSetNames( Display * dpy, - unsigned int which, - unsigned int firstType, - unsigned int nTypes, - XkbDescPtr xkb) +XkbSetNames(Display *dpy, + unsigned int which, + unsigned int firstType, + unsigned int nTypes, + XkbDescPtr xkb) { register xkbSetNamesReq *req; - int nLvlNames = 0; + int nLvlNames = 0; XkbInfoPtr xkbi; XkbNamesPtr names; - unsigned firstLvlType,nLvlTypes; - int nVMods,nLEDs,nRG,nKA,nGroups; - int nKeys=0,firstKey=0,nAtoms; - CARD32 leds,vmods,groups; + unsigned firstLvlType, nLvlTypes; + int nVMods, nLEDs, nRG, nKA, nGroups; + int nKeys = 0, firstKey = 0, nAtoms; + CARD32 leds, vmods, groups; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!xkb)||(!xkb->names)) - return False; - firstLvlType= firstType; - nLvlTypes= nTypes; - if (nTypes<1) - which&= ~(XkbKTLevelNamesMask|XkbKeyTypeNamesMask); - else if (firstType<=XkbLastRequiredType) { - int adjust; - adjust= XkbLastRequiredType-firstType+1; - firstType+= adjust; - nTypes-= adjust; - if (nTypes<1) - which&= ~XkbKeyTypeNamesMask; - } - names= xkb->names; - if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) { - register int i; - XkbKeyTypePtr type; - if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)|| - (firstType+nTypes>xkb->map->num_types)|| - (firstLvlType+nLvlTypes>xkb->map->num_types)) - return False; - if (which&XkbKTLevelNamesMask) { - type= &xkb->map->types[firstLvlType]; - for (i=nLvlNames=0;i<nLvlTypes;i++,type++) { - if (type->level_names!=NULL) - nLvlNames+= type->num_levels; - } - } - } - - nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!xkb) || (!xkb->names)) + return False; + firstLvlType = firstType; + nLvlTypes = nTypes; + if (nTypes < 1) + which &= ~(XkbKTLevelNamesMask | XkbKeyTypeNamesMask); + else if (firstType <= XkbLastRequiredType) { + int adjust; + + adjust = XkbLastRequiredType - firstType + 1; + firstType += adjust; + nTypes -= adjust; + if (nTypes < 1) + which &= ~XkbKeyTypeNamesMask; + } + names = xkb->names; + if (which & (XkbKTLevelNamesMask | XkbKeyTypeNamesMask)) { + register int i; + XkbKeyTypePtr type; + + if ((xkb->map == NULL) || (xkb->map->types == NULL) || (nTypes == 0) || + (firstType + nTypes > xkb->map->num_types) || + (firstLvlType + nLvlTypes > xkb->map->num_types)) + return False; + if (which & XkbKTLevelNamesMask) { + type = &xkb->map->types[firstLvlType]; + for (i = nLvlNames = 0; i < nLvlTypes; i++, type++) { + if (type->level_names != NULL) + nLvlNames += type->num_levels; + } + } + } + + nVMods = nLEDs = nRG = nKA = nAtoms = nGroups = 0; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetNames, req); @@ -371,138 +379,149 @@ XkbSetNames( Display * dpy, req->firstType = firstType; req->nTypes = nTypes; req->firstKey = xkb->min_key_code; - req->nKeys = xkb->max_key_code-xkb->min_key_code+1; - - if (which&XkbKeycodesNameMask) - nAtoms++; - if (which&XkbGeometryNameMask) - nAtoms++; - if (which&XkbSymbolsNameMask) - nAtoms++; - if (which&XkbPhysSymbolsNameMask) - nAtoms++; - if (which&XkbTypesNameMask) - nAtoms++; - if (which&XkbCompatNameMask) - nAtoms++; - if (which&XkbKeyTypeNamesMask) - nAtoms+= nTypes; - if (which&XkbKTLevelNamesMask) { - req->firstKTLevel= firstLvlType; - req->nKTLevels= nLvlTypes; - req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */ - nAtoms+= nLvlNames; - } - else req->firstKTLevel= req->nKTLevels= 0; - - if (which&XkbIndicatorNamesMask) { - req->indicators= leds= - _XkbCountAtoms(names->indicators,XkbNumIndicators,&nLEDs); - if (nLEDs>0) - nAtoms+= nLEDs; - else which&= ~XkbIndicatorNamesMask; - } - else req->indicators= leds= 0; - - if (which&XkbVirtualModNamesMask) { - vmods= req->virtualMods= (CARD16) - _XkbCountAtoms(names->vmods,XkbNumVirtualMods,&nVMods); - if (nVMods>0) - nAtoms+= nVMods; - else which&= ~XkbVirtualModNamesMask; - } - else vmods= req->virtualMods= 0; - - if (which&XkbGroupNamesMask) { - groups= req->groupNames= (CARD8) - _XkbCountAtoms(names->groups,XkbNumKbdGroups,&nGroups); - if (nGroups>0) - nAtoms+= nGroups; - else which&= ~XkbGroupNamesMask; - } - else groups= req->groupNames= 0; - - if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { - firstKey= req->firstKey; - nKeys= req->nKeys; - nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */ - } - else which&= ~XkbKeyNamesMask; - - if (which&XkbKeyAliasesMask) { - nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0); - if (nKA>0) { - req->nKeyAliases= nKA; - nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */ - } - else { - which&= ~XkbKeyAliasesMask; - req->nKeyAliases = 0; - } - } - else req->nKeyAliases= 0; - - if (which&XkbRGNamesMask) { - nRG= names->num_rg; - if (nRG>0) - nAtoms+= nRG; - else which&= ~XkbRGNamesMask; - } - - req->which= which; - req->nRadioGroups= nRG; - req->length+= (nAtoms*4)/4; - - if (which&XkbKeycodesNameMask) - Data32(dpy,(long *)&names->keycodes,4); - if (which&XkbGeometryNameMask) - Data32(dpy,(long *)&names->geometry,4); - if (which&XkbSymbolsNameMask) - Data32(dpy,(long *)&names->symbols,4); - if (which&XkbPhysSymbolsNameMask) - Data32(dpy,(long *)&names->phys_symbols,4); - if (which&XkbTypesNameMask) - Data32(dpy,(long *)&names->types,4); - if (which&XkbCompatNameMask) - Data32(dpy,(long *)&names->compat,4); - if (which&XkbKeyTypeNamesMask) { - register int i; - register XkbKeyTypePtr type; - type= &xkb->map->types[firstType]; - for (i=0;i<nTypes;i++,type++) { - Data32(dpy,(long *)&type->name,4); - } - } - if (which&XkbKTLevelNamesMask) { - XkbKeyTypePtr type; - int i; - char *tmp; - - BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes)); - type = &xkb->map->types[firstLvlType]; - for (i=0;i<nLvlTypes;i++,type++) { - *tmp++ = type->num_levels; - } - type = &xkb->map->types[firstLvlType]; - for (i=0;i<nLvlTypes;i++,type++) { - if (type->level_names!=NULL) - Data32(dpy,(long *)type->level_names,type->num_levels*4); - } - } - if (which&XkbIndicatorNamesMask) - _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators); - if (which&XkbVirtualModNamesMask) - _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods); - if (which&XkbGroupNamesMask) - _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups); - if (which&XkbKeyNamesMask) { - Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength); - } - if (which&XkbKeyAliasesMask) { - Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2); - } - if (which&XkbRGNamesMask) { - Data32(dpy,(long *)names->radio_groups,nRG*4); + req->nKeys = xkb->max_key_code - xkb->min_key_code + 1; + + if (which & XkbKeycodesNameMask) + nAtoms++; + if (which & XkbGeometryNameMask) + nAtoms++; + if (which & XkbSymbolsNameMask) + nAtoms++; + if (which & XkbPhysSymbolsNameMask) + nAtoms++; + if (which & XkbTypesNameMask) + nAtoms++; + if (which & XkbCompatNameMask) + nAtoms++; + if (which & XkbKeyTypeNamesMask) + nAtoms += nTypes; + if (which & XkbKTLevelNamesMask) { + req->firstKTLevel = firstLvlType; + req->nKTLevels = nLvlTypes; + req->length += XkbPaddedSize(nLvlTypes) / 4; /* room for group widths */ + nAtoms += nLvlNames; + } + else + req->firstKTLevel = req->nKTLevels = 0; + + if (which & XkbIndicatorNamesMask) { + req->indicators = leds = + _XkbCountAtoms(names->indicators, XkbNumIndicators, &nLEDs); + if (nLEDs > 0) + nAtoms += nLEDs; + else + which &= ~XkbIndicatorNamesMask; + } + else + req->indicators = leds = 0; + + if (which & XkbVirtualModNamesMask) { + vmods = req->virtualMods = (CARD16) + _XkbCountAtoms(names->vmods, XkbNumVirtualMods, &nVMods); + if (nVMods > 0) + nAtoms += nVMods; + else + which &= ~XkbVirtualModNamesMask; + } + else + vmods = req->virtualMods = 0; + + if (which & XkbGroupNamesMask) { + groups = req->groupNames = (CARD8) + _XkbCountAtoms(names->groups, XkbNumKbdGroups, &nGroups); + if (nGroups > 0) + nAtoms += nGroups; + else + which &= ~XkbGroupNamesMask; + } + else + groups = req->groupNames = 0; + + if ((which & XkbKeyNamesMask) && (names->keys != NULL)) { + firstKey = req->firstKey; + nKeys = req->nKeys; + nAtoms += nKeys; /* technically not atoms, but 4 bytes wide */ + } + else + which &= ~XkbKeyNamesMask; + + if (which & XkbKeyAliasesMask) { + nKA = ((names->key_aliases != NULL) ? names->num_key_aliases : 0); + if (nKA > 0) { + req->nKeyAliases = nKA; + nAtoms += nKA * 2; /* not atoms, but 8 bytes on the wire */ + } + else { + which &= ~XkbKeyAliasesMask; + req->nKeyAliases = 0; + } + } + else + req->nKeyAliases = 0; + + if (which & XkbRGNamesMask) { + nRG = names->num_rg; + if (nRG > 0) + nAtoms += nRG; + else + which &= ~XkbRGNamesMask; + } + + req->which = which; + req->nRadioGroups = nRG; + req->length += (nAtoms * 4) / 4; + + if (which & XkbKeycodesNameMask) + Data32(dpy, (long *) &names->keycodes, 4); + if (which & XkbGeometryNameMask) + Data32(dpy, (long *) &names->geometry, 4); + if (which & XkbSymbolsNameMask) + Data32(dpy, (long *) &names->symbols, 4); + if (which & XkbPhysSymbolsNameMask) + Data32(dpy, (long *) &names->phys_symbols, 4); + if (which & XkbTypesNameMask) + Data32(dpy, (long *) &names->types, 4); + if (which & XkbCompatNameMask) + Data32(dpy, (long *) &names->compat, 4); + if (which & XkbKeyTypeNamesMask) { + register int i; + register XkbKeyTypePtr type; + + type = &xkb->map->types[firstType]; + for (i = 0; i < nTypes; i++, type++) { + Data32(dpy, (long *) &type->name, 4); + } + } + if (which & XkbKTLevelNamesMask) { + XkbKeyTypePtr type; + int i; + char *tmp; + + BufAlloc(char *, tmp, XkbPaddedSize(nLvlTypes)); + type = &xkb->map->types[firstLvlType]; + for (i = 0; i < nLvlTypes; i++, type++) { + *tmp++ = type->num_levels; + } + type = &xkb->map->types[firstLvlType]; + for (i = 0; i < nLvlTypes; i++, type++) { + if (type->level_names != NULL) + Data32(dpy, (long *) type->level_names, type->num_levels * 4); + } + } + if (which & XkbIndicatorNamesMask) + _XkbCopyAtoms(dpy, names->indicators, leds, XkbNumIndicators); + if (which & XkbVirtualModNamesMask) + _XkbCopyAtoms(dpy, names->vmods, vmods, XkbNumVirtualMods); + if (which & XkbGroupNamesMask) + _XkbCopyAtoms(dpy, names->groups, groups, XkbNumKbdGroups); + if (which & XkbKeyNamesMask) { + Data(dpy, (char *) &names->keys[firstKey], nKeys * XkbKeyNameLength); + } + if (which & XkbKeyAliasesMask) { + Data(dpy, (char *) names->key_aliases, nKA * XkbKeyNameLength * 2); + } + if (which & XkbRGNamesMask) { + Data32(dpy, (long *) names->radio_groups, nRG * 4); } UnlockDisplay(dpy); SyncHandle(); @@ -510,90 +529,94 @@ XkbSetNames( Display * dpy, } Bool -XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes) +XkbChangeNames(Display *dpy, XkbDescPtr xkb, XkbNameChangesPtr changes) { register xkbSetNamesReq *req; - int nLvlNames = 0; + int nLvlNames = 0; XkbInfoPtr xkbi; XkbNamesPtr names; - unsigned which,firstType,nTypes; - unsigned firstLvlType,nLvlTypes; - int nVMods,nLEDs,nRG,nKA,nGroups; - int nKeys=0,firstKey=0,nAtoms; - CARD32 leds=0,vmods=0,groups=0; + unsigned which, firstType, nTypes; + unsigned firstLvlType, nLvlTypes; + int nVMods, nLEDs, nRG, nKA, nGroups; + int nKeys = 0, firstKey = 0, nAtoms; + CARD32 leds = 0, vmods = 0, groups = 0; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!xkb)||(!xkb->names)||(!changes)) - return False; - which= changes->changed; - firstType= changes->first_type; - nTypes= changes->num_types; - firstLvlType= changes->first_lvl;; - nLvlTypes= changes->num_lvls; - if (which&XkbKeyTypeNamesMask) { - if (nTypes<1) - which&= ~XkbKeyTypeNamesMask; - else if (firstType<=XkbLastRequiredType) { - int adjust; - adjust= XkbLastRequiredType-firstType+1; - firstType+= adjust; - nTypes-= adjust; - if (nTypes<1) - which&= ~XkbKeyTypeNamesMask; - } - } - else firstType= nTypes= 0; - - if (which&XkbKTLevelNamesMask) { - if (nLvlTypes<1) - which&= ~XkbKTLevelNamesMask; - } - else firstLvlType= nLvlTypes= 0; - - names= xkb->names; - if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) { - register int i; - XkbKeyTypePtr type; - if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)|| - (firstType+nTypes>xkb->map->num_types)|| - (firstLvlType+nLvlTypes>xkb->map->num_types)) - return False; - if (which&XkbKTLevelNamesMask) { - type= &xkb->map->types[firstLvlType]; - for (i=nLvlNames=0;i<nLvlTypes;i++,type++) { - if (type->level_names!=NULL) - nLvlNames+= type->num_levels; - } - } - } - - if (changes->num_keys<1) - which&= ~XkbKeyNamesMask; - if ((which&XkbKeyNamesMask)==0) - changes->first_key= changes->num_keys= 0; - else if ((changes->first_key<xkb->min_key_code)|| - (changes->first_key+changes->num_keys>xkb->max_key_code)) { - return False; - } - - if ((which&XkbVirtualModNamesMask)==0) - changes->changed_vmods= 0; - else if (changes->changed_vmods==0) - which&= ~XkbVirtualModNamesMask; - - if ((which&XkbIndicatorNamesMask)==0) - changes->changed_indicators= 0; - else if (changes->changed_indicators==0) - which&= ~XkbIndicatorNamesMask; - - if ((which&XkbGroupNamesMask)==0) - changes->changed_groups= 0; - else if (changes->changed_groups==0) - which&= ~XkbGroupNamesMask; - - nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!xkb) || (!xkb->names) || (!changes)) + return False; + which = changes->changed; + firstType = changes->first_type; + nTypes = changes->num_types; + firstLvlType = changes->first_lvl;; + nLvlTypes = changes->num_lvls; + if (which & XkbKeyTypeNamesMask) { + if (nTypes < 1) + which &= ~XkbKeyTypeNamesMask; + else if (firstType <= XkbLastRequiredType) { + int adjust; + + adjust = XkbLastRequiredType - firstType + 1; + firstType += adjust; + nTypes -= adjust; + if (nTypes < 1) + which &= ~XkbKeyTypeNamesMask; + } + } + else + firstType = nTypes = 0; + + if (which & XkbKTLevelNamesMask) { + if (nLvlTypes < 1) + which &= ~XkbKTLevelNamesMask; + } + else + firstLvlType = nLvlTypes = 0; + + names = xkb->names; + if (which & (XkbKTLevelNamesMask | XkbKeyTypeNamesMask)) { + register int i; + + if ((xkb->map == NULL) || (xkb->map->types == NULL) || (nTypes == 0) || + (firstType + nTypes > xkb->map->num_types) || + (firstLvlType + nLvlTypes > xkb->map->num_types)) + return False; + if (which & XkbKTLevelNamesMask) { + XkbKeyTypePtr type = &xkb->map->types[firstLvlType]; + + for (i = nLvlNames = 0; i < nLvlTypes; i++, type++) { + if (type->level_names != NULL) + nLvlNames += type->num_levels; + } + } + } + + if (changes->num_keys < 1) + which &= ~XkbKeyNamesMask; + if ((which & XkbKeyNamesMask) == 0) + changes->first_key = changes->num_keys = 0; + else if ((changes->first_key < xkb->min_key_code) || + (changes->first_key + changes->num_keys > xkb->max_key_code)) { + return False; + } + + if ((which & XkbVirtualModNamesMask) == 0) + changes->changed_vmods = 0; + else if (changes->changed_vmods == 0) + which &= ~XkbVirtualModNamesMask; + + if ((which & XkbIndicatorNamesMask) == 0) + changes->changed_indicators = 0; + else if (changes->changed_indicators == 0) + which &= ~XkbIndicatorNamesMask; + + if ((which & XkbGroupNamesMask) == 0) + changes->changed_groups = 0; + else if (changes->changed_groups == 0) + which &= ~XkbGroupNamesMask; + + nVMods = nLEDs = nRG = nKA = nAtoms = nGroups = 0; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetNames, req); @@ -605,132 +628,143 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes) req->firstKey = changes->first_key; req->nKeys = changes->num_keys; - if (which&XkbKeycodesNameMask) - nAtoms++; - if (which&XkbGeometryNameMask) - nAtoms++; - if (which&XkbSymbolsNameMask) - nAtoms++; - if (which&XkbPhysSymbolsNameMask) - nAtoms++; - if (which&XkbTypesNameMask) - nAtoms++; - if (which&XkbCompatNameMask) - nAtoms++; - if (which&XkbKeyTypeNamesMask) - nAtoms+= nTypes; - if (which&XkbKTLevelNamesMask) { - req->firstKTLevel= firstLvlType; - req->nKTLevels= nLvlTypes; - req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */ - nAtoms+= nLvlNames; - } - else req->firstKTLevel= req->nKTLevels= 0; - - if (which&XkbIndicatorNamesMask) { - leds= req->indicators= (CARD32)changes->changed_indicators; - nLEDs= _XkbCountBits(XkbNumIndicators,changes->changed_indicators); - if (nLEDs>0) - nAtoms+= nLEDs; - else which&= ~XkbIndicatorNamesMask; - } - else req->indicators= 0; - - if (which&XkbVirtualModNamesMask) { - vmods= req->virtualMods= changes->changed_vmods; - nVMods= _XkbCountBits(XkbNumVirtualMods, - (unsigned long)changes->changed_vmods); - if (nVMods>0) - nAtoms+= nVMods; - else which&= ~XkbVirtualModNamesMask; - } - else req->virtualMods= 0; - - if (which&XkbGroupNamesMask) { - groups= req->groupNames= changes->changed_groups; - nGroups= _XkbCountBits(XkbNumKbdGroups, - (unsigned long)changes->changed_groups); - if (nGroups>0) - nAtoms+= nGroups; - else which&= ~XkbGroupNamesMask; - } - else req->groupNames= 0; - - if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { - firstKey= req->firstKey; - nKeys= req->nKeys; - nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */ - } - else which&= ~XkbKeyNamesMask; - - if (which&XkbKeyAliasesMask) { - nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0); - if (nKA>0) - nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */ - else which&= ~XkbKeyAliasesMask; - } - - if (which&XkbRGNamesMask) { - nRG= names->num_rg; - if (nRG>0) - nAtoms+= nRG; - else which&= ~XkbRGNamesMask; - } - - req->which= which; - req->nRadioGroups= nRG; - req->length+= (nAtoms*4)/4; - - if (which&XkbKeycodesNameMask) - Data32(dpy,(long *)&names->keycodes,4); - if (which&XkbGeometryNameMask) - Data32(dpy,(long *)&names->geometry,4); - if (which&XkbSymbolsNameMask) - Data32(dpy,(long *)&names->symbols,4); - if (which&XkbPhysSymbolsNameMask) - Data32(dpy,(long *)&names->phys_symbols,4); - if (which&XkbTypesNameMask) - Data32(dpy,(long *)&names->types,4); - if (which&XkbCompatNameMask) - Data32(dpy,(long *)&names->compat,4); - if (which&XkbKeyTypeNamesMask) { - register int i; - register XkbKeyTypePtr type; - type= &xkb->map->types[firstType]; - for (i=0;i<nTypes;i++,type++) { - Data32(dpy,(long *)&type->name,4); - } - } - if (which&XkbKTLevelNamesMask) { - XkbKeyTypePtr type; - int i; - char *tmp; - - BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes)); - type = &xkb->map->types[firstLvlType]; - for (i=0;i<nLvlTypes;i++,type++) { - *tmp++ = type->num_levels; - } - type = &xkb->map->types[firstLvlType]; - for (i=0;i<nLvlTypes;i++,type++) { - if (type->level_names!=NULL) - Data32(dpy,(long *)type->level_names,type->num_levels*4); - } - } - if (which&XkbIndicatorNamesMask) - _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators); - if (which&XkbVirtualModNamesMask) - _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods); - if (which&XkbGroupNamesMask) - _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups); - if (which&XkbKeyNamesMask) { - Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength); - } - if (which&XkbKeyAliasesMask) { - Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2); - } - if (which&XkbRGNamesMask) { - Data32(dpy,(long *)names->radio_groups,nRG*4); + if (which & XkbKeycodesNameMask) + nAtoms++; + if (which & XkbGeometryNameMask) + nAtoms++; + if (which & XkbSymbolsNameMask) + nAtoms++; + if (which & XkbPhysSymbolsNameMask) + nAtoms++; + if (which & XkbTypesNameMask) + nAtoms++; + if (which & XkbCompatNameMask) + nAtoms++; + if (which & XkbKeyTypeNamesMask) + nAtoms += nTypes; + if (which & XkbKTLevelNamesMask) { + req->firstKTLevel = firstLvlType; + req->nKTLevels = nLvlTypes; + req->length += XkbPaddedSize(nLvlTypes) / 4; /* room for group widths */ + nAtoms += nLvlNames; + } + else + req->firstKTLevel = req->nKTLevels = 0; + + if (which & XkbIndicatorNamesMask) { + leds = req->indicators = (CARD32) changes->changed_indicators; + nLEDs = _XkbCountBits(XkbNumIndicators, changes->changed_indicators); + if (nLEDs > 0) + nAtoms += nLEDs; + else + which &= ~XkbIndicatorNamesMask; + } + else + req->indicators = 0; + + if (which & XkbVirtualModNamesMask) { + vmods = req->virtualMods = changes->changed_vmods; + nVMods = _XkbCountBits(XkbNumVirtualMods, + (unsigned long) changes->changed_vmods); + if (nVMods > 0) + nAtoms += nVMods; + else + which &= ~XkbVirtualModNamesMask; + } + else + req->virtualMods = 0; + + if (which & XkbGroupNamesMask) { + groups = req->groupNames = changes->changed_groups; + nGroups = _XkbCountBits(XkbNumKbdGroups, + (unsigned long) changes->changed_groups); + if (nGroups > 0) + nAtoms += nGroups; + else + which &= ~XkbGroupNamesMask; + } + else + req->groupNames = 0; + + if ((which & XkbKeyNamesMask) && (names->keys != NULL)) { + firstKey = req->firstKey; + nKeys = req->nKeys; + nAtoms += nKeys; /* technically not atoms, but 4 bytes wide */ + } + else + which &= ~XkbKeyNamesMask; + + if (which & XkbKeyAliasesMask) { + nKA = ((names->key_aliases != NULL) ? names->num_key_aliases : 0); + if (nKA > 0) + nAtoms += nKA * 2; /* not atoms, but 8 bytes on the wire */ + else + which &= ~XkbKeyAliasesMask; + } + + if (which & XkbRGNamesMask) { + nRG = names->num_rg; + if (nRG > 0) + nAtoms += nRG; + else + which &= ~XkbRGNamesMask; + } + + req->which = which; + req->nRadioGroups = nRG; + req->length += (nAtoms * 4) / 4; + + if (which & XkbKeycodesNameMask) + Data32(dpy, (long *) &names->keycodes, 4); + if (which & XkbGeometryNameMask) + Data32(dpy, (long *) &names->geometry, 4); + if (which & XkbSymbolsNameMask) + Data32(dpy, (long *) &names->symbols, 4); + if (which & XkbPhysSymbolsNameMask) + Data32(dpy, (long *) &names->phys_symbols, 4); + if (which & XkbTypesNameMask) + Data32(dpy, (long *) &names->types, 4); + if (which & XkbCompatNameMask) + Data32(dpy, (long *) &names->compat, 4); + if (which & XkbKeyTypeNamesMask) { + register int i; + register XkbKeyTypePtr type; + + type = &xkb->map->types[firstType]; + for (i = 0; i < nTypes; i++, type++) { + Data32(dpy, (long *) &type->name, 4); + } + } + if (which & XkbKTLevelNamesMask) { + XkbKeyTypePtr type; + int i; + char *tmp; + + BufAlloc(char *, tmp, XkbPaddedSize(nLvlTypes)); + type = &xkb->map->types[firstLvlType]; + for (i = 0; i < nLvlTypes; i++, type++) { + *tmp++ = type->num_levels; + } + type = &xkb->map->types[firstLvlType]; + for (i = 0; i < nLvlTypes; i++, type++) { + if (type->level_names != NULL) + Data32(dpy, (long *) type->level_names, type->num_levels * 4); + } + } + if (which & XkbIndicatorNamesMask) + _XkbCopyAtoms(dpy, names->indicators, leds, XkbNumIndicators); + if (which & XkbVirtualModNamesMask) + _XkbCopyAtoms(dpy, names->vmods, vmods, XkbNumVirtualMods); + if (which & XkbGroupNamesMask) + _XkbCopyAtoms(dpy, names->groups, groups, XkbNumKbdGroups); + if (which & XkbKeyNamesMask) { + Data(dpy, (char *) &names->keys[firstKey], nKeys * XkbKeyNameLength); + } + if (which & XkbKeyAliasesMask) { + Data(dpy, (char *) names->key_aliases, nKA * XkbKeyNameLength * 2); + } + if (which & XkbRGNamesMask) { + Data32(dpy, (long *) names->radio_groups, nRG * 4); } UnlockDisplay(dpy); SyncHandle(); @@ -738,96 +772,103 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes) } void -XkbNoteNameChanges( XkbNameChangesPtr old, - XkbNamesNotifyEvent * new, - unsigned int wanted) +XkbNoteNameChanges(XkbNameChangesPtr old, + XkbNamesNotifyEvent *new, + unsigned int wanted) { -int first,last,old_last,new_last; - - wanted&= new->changed; - if ((old==NULL)||(new==NULL)||(wanted==0)) - return; - if (wanted&XkbKeyTypeNamesMask) { - if (old->changed&XkbKeyTypeNamesMask) { - new_last= (new->first_type+new->num_types-1); - old_last= (old->first_type+old->num_types-1); - - if (new->first_type<old->first_type) - first= new->first_type; - else first= old->first_type; - - if (old_last>new_last) - last= old_last; - else last= new_last; - - old->first_type= first; - old->num_types= (last-first)+1; - } - else { - old->first_type= new->first_type; - old->num_types= new->num_types; - } - } - if (wanted&XkbKTLevelNamesMask) { - if (old->changed&XkbKTLevelNamesMask) { - new_last= (new->first_lvl+new->num_lvls-1); - old_last= (old->first_lvl+old->num_lvls-1); - - if (new->first_lvl<old->first_lvl) - first= new->first_lvl; - else first= old->first_lvl; - - if (old_last>new_last) - last= old_last; - else last= new_last; - - old->first_lvl= first; - old->num_lvls= (last-first)+1; - } - else { - old->first_lvl= new->first_lvl; - old->num_lvls= new->num_lvls; - } - } - if (wanted&XkbIndicatorNamesMask) { - if (old->changed&XkbIndicatorNamesMask) - old->changed_indicators|= new->changed_indicators; - else old->changed_indicators= new->changed_indicators; - } - if (wanted&XkbKeyNamesMask) { - if (old->changed&XkbKeyNamesMask) { - new_last= (new->first_key+new->num_keys-1); - old_last= (old->first_key+old->num_keys-1); - - first= old->first_key; - - if (new->first_key<old->first_key) - first= new->first_key; - if (old_last>new_last) - new_last= old_last; - - old->first_key= first; - old->num_keys= (new_last-first)+1; - } - else { - old->first_key= new->first_key; - old->num_keys= new->num_keys; - } - } - if (wanted&XkbVirtualModNamesMask) { - if (old->changed&XkbVirtualModNamesMask) - old->changed_vmods|= new->changed_vmods; - else old->changed_vmods= new->changed_vmods; - } - if (wanted&XkbGroupNamesMask) { - if (old->changed&XkbGroupNamesMask) - old->changed_groups|= new->changed_groups; - else old->changed_groups= new->changed_groups; - } - if (wanted&XkbRGNamesMask) - old->num_rg= new->num_radio_groups; - if (wanted&XkbKeyAliasesMask) - old->num_aliases= new->num_aliases; - old->changed|= wanted; + int first, last, old_last, new_last; + + wanted &= new->changed; + if ((old == NULL) || (new == NULL) || (wanted == 0)) + return; + if (wanted & XkbKeyTypeNamesMask) { + if (old->changed & XkbKeyTypeNamesMask) { + new_last = (new->first_type + new->num_types - 1); + old_last = (old->first_type + old->num_types - 1); + + if (new->first_type < old->first_type) + first = new->first_type; + else + first = old->first_type; + + if (old_last > new_last) + last = old_last; + else + last = new_last; + + old->first_type = first; + old->num_types = (last - first) + 1; + } + else { + old->first_type = new->first_type; + old->num_types = new->num_types; + } + } + if (wanted & XkbKTLevelNamesMask) { + if (old->changed & XkbKTLevelNamesMask) { + new_last = (new->first_lvl + new->num_lvls - 1); + old_last = (old->first_lvl + old->num_lvls - 1); + + if (new->first_lvl < old->first_lvl) + first = new->first_lvl; + else + first = old->first_lvl; + + if (old_last > new_last) + last = old_last; + else + last = new_last; + + old->first_lvl = first; + old->num_lvls = (last - first) + 1; + } + else { + old->first_lvl = new->first_lvl; + old->num_lvls = new->num_lvls; + } + } + if (wanted & XkbIndicatorNamesMask) { + if (old->changed & XkbIndicatorNamesMask) + old->changed_indicators |= new->changed_indicators; + else + old->changed_indicators = new->changed_indicators; + } + if (wanted & XkbKeyNamesMask) { + if (old->changed & XkbKeyNamesMask) { + new_last = (new->first_key + new->num_keys - 1); + old_last = (old->first_key + old->num_keys - 1); + + first = old->first_key; + + if (new->first_key < old->first_key) + first = new->first_key; + if (old_last > new_last) + new_last = old_last; + + old->first_key = first; + old->num_keys = (new_last - first) + 1; + } + else { + old->first_key = new->first_key; + old->num_keys = new->num_keys; + } + } + if (wanted & XkbVirtualModNamesMask) { + if (old->changed & XkbVirtualModNamesMask) + old->changed_vmods |= new->changed_vmods; + else + old->changed_vmods = new->changed_vmods; + } + if (wanted & XkbGroupNamesMask) { + if (old->changed & XkbGroupNamesMask) + old->changed_groups |= new->changed_groups; + else + old->changed_groups = new->changed_groups; + } + if (wanted & XkbRGNamesMask) + old->num_rg = new->num_radio_groups; + if (wanted & XkbKeyAliasesMask) + old->num_aliases = new->num_aliases; + old->changed |= wanted; return; } diff --git a/libX11/src/xkb/XKBRdBuf.c b/libX11/src/xkb/XKBRdBuf.c index bf2883a39..8e9eab238 100644 --- a/libX11/src/xkb/XKBRdBuf.c +++ b/libX11/src/xkb/XKBRdBuf.c @@ -35,16 +35,16 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /***====================================================================***/ int -_XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size) +_XkbInitReadBuffer(Display *dpy, XkbReadBufferPtr buf, int size) { - if ((dpy!=NULL) && (buf!=NULL) && (size>0)) { - buf->error= 0; - buf->size= size; - buf->start= buf->data= _XkbAlloc(size); - if (buf->start) { - _XRead(dpy, buf->start, size); - return 1; - } + if ((dpy != NULL) && (buf != NULL) && (size > 0)) { + buf->error = 0; + buf->size = size; + buf->start = buf->data = _XkbAlloc(size); + if (buf->start) { + _XRead(dpy, buf->start, size); + return 1; + } } return 0; } @@ -52,56 +52,55 @@ _XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size) #define _XkbReadBufferDataLeft(b) (((b)->size)-((b)->data-(b)->start)) int -_XkbSkipReadBufferData(XkbReadBufferPtr from,int size) +_XkbSkipReadBufferData(XkbReadBufferPtr from, int size) { - if (size==0) - return 1; - if ((from==NULL)||(from->error)||(size<1)|| - (_XkbReadBufferDataLeft(from)<size)) - return 0; - from->data+= size; + if (size == 0) + return 1; + if ((from == NULL) || (from->error) || (size < 1) || + (_XkbReadBufferDataLeft(from) < size)) + return 0; + from->data += size; return 1; } int -_XkbCopyFromReadBuffer(XkbReadBufferPtr from,char *to,int size) +_XkbCopyFromReadBuffer(XkbReadBufferPtr from, char *to, int size) { - if (size==0) - return 1; - if ((from==NULL)||(from->error)||(to==NULL)||(size<1)|| - (_XkbReadBufferDataLeft(from)<size)) - return 0; - memcpy(to,from->data,size); - from->data+= size; + if (size == 0) + return 1; + if ((from == NULL) || (from->error) || (to == NULL) || (size < 1) || + (_XkbReadBufferDataLeft(from) < size)) + return 0; + memcpy(to, from->data, size); + from->data += size; return 1; } #ifdef XKB_FORCE_INT_KEYSYM int -_XkbReadCopyKeySyms(int *wire,KeySym *to,int num_words) +_XkbReadCopyKeySyms(int *wire, KeySym * to, int num_words) { - while (num_words-->0) { - *to++= *wire++; + while (num_words-- > 0) { + *to++ = *wire++; } return 1; } int -_XkbReadBufferCopyKeySyms(XkbReadBufferPtr from,KeySym *to,int num_words) +_XkbReadBufferCopyKeySyms(XkbReadBufferPtr from, KeySym * to, int num_words) { - if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from)) + if ((unsigned) (num_words * 4) > _XkbReadBufferDataLeft(from)) return 0; - _XkbReadCopyKeySyms((int *)from->data,to,num_words); - from->data+= (4*num_words); + _XkbReadCopyKeySyms((int *) from->data, to, num_words); + from->data += (4 * num_words); return True; } int -_XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len) +_XkbWriteCopyKeySyms(register KeySym * from, CARD32 *to, int len) { - - while (len-->0) { - *to++= (CARD32)*from++; + while (len-- > 0) { + *to++ = (CARD32) *from++; } return True; } @@ -109,54 +108,54 @@ _XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len) #ifdef LONG64 int -_XkbReadCopyData32(int *wire,long *to,int num_words) +_XkbReadCopyData32(int *wire, long *to, int num_words) { - while (num_words-->0) { - *to++= *wire++; + while (num_words-- > 0) { + *to++ = *wire++; } return 1; } int -_XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words) +_XkbReadBufferCopy32(XkbReadBufferPtr from, long *to, int num_words) { - if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from)) - return 0; - _XkbReadCopyData32((int *)from->data,to,num_words); - from->data+= (4*num_words); + if ((unsigned) (num_words * 4) > _XkbReadBufferDataLeft(from)) + return 0; + _XkbReadCopyData32((int *) from->data, to, num_words); + from->data += (4 * num_words); return True; } int -_XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len) +_XkbWriteCopyData32(register unsigned long *from, CARD32 *to, int len) { - - while (len-->0) { - *to++= (CARD32)*from++; + while (len-- > 0) { + *to++ = (CARD32) *from++; } return True; } -#endif /* LONG64 */ +#endif /* LONG64 */ char * -_XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size) +_XkbPeekAtReadBuffer(XkbReadBufferPtr from, int size) { - if ((from==NULL)||(from->error)||(size<1)|| - (_XkbReadBufferDataLeft(from)<size)) - return NULL; + if ((from == NULL) || (from->error) || (size < 1) || + (_XkbReadBufferDataLeft(from) < size)) + return NULL; return from->data; } char * -_XkbGetReadBufferPtr(XkbReadBufferPtr from,int size) +_XkbGetReadBufferPtr(XkbReadBufferPtr from, int size) { -char *ptr; - if ((from==NULL)||(from->error)||(size<1)|| - (_XkbReadBufferDataLeft(from)<size)) - return NULL; - ptr= from->data; - from->data+= size; + char *ptr; + + if ((from == NULL) || (from->error) || (size < 1) || + (_XkbReadBufferDataLeft(from) < size)) + return NULL; + ptr = from->data; + from->data += size; return ptr; } @@ -164,39 +163,41 @@ char *ptr; int _XkbFreeReadBuffer(XkbReadBufferPtr buf) { - if ((buf!=NULL) && (buf->start!=NULL)) { - int left; - left= (int)_XkbReadBufferDataLeft(buf); - if (buf->start!=NULL) - Xfree(buf->start); - buf->size= 0; - buf->start= buf->data= NULL; - return left; + if ((buf != NULL) && (buf->start != NULL)) { + int left; + + left = (int) _XkbReadBufferDataLeft(buf); + if (buf->start != NULL) + Xfree(buf->start); + buf->size = 0; + buf->start = buf->data = NULL; + return left; } return 0; } Bool -_XkbGetReadBufferCountedString(XkbReadBufferPtr buf,char **rtrn) +_XkbGetReadBufferCountedString(XkbReadBufferPtr buf, char **rtrn) { -CARD16 len,*pLen; -int left; -char * str = NULL; - - if ((buf==NULL)||(buf->error)||((left=(int)_XkbReadBufferDataLeft(buf))<4)) - return False; - pLen= (CARD16 *)buf->data; - len= *pLen; - if (len>0) { - if (XkbPaddedSize(len+2)>left) - return False; - str= _XkbAlloc(len+1); - if (str) { - memcpy(str,&buf->data[2],len); - str[len]= '\0'; - } + CARD16 len, *pLen; + int left; + char *str = NULL; + + if ((buf == NULL) || (buf->error) || + ((left = (int) _XkbReadBufferDataLeft(buf)) < 4)) + return False; + pLen = (CARD16 *) buf->data; + len = *pLen; + if (len > 0) { + if (XkbPaddedSize(len + 2) > left) + return False; + str = _XkbAlloc(len + 1); + if (str) { + memcpy(str, &buf->data[2], len); + str[len] = '\0'; + } } - buf->data+= XkbPaddedSize(len+2); - *rtrn= str; + buf->data += XkbPaddedSize(len + 2); + *rtrn = str; return True; } diff --git a/libX11/src/xkb/XKBSetGeom.c b/libX11/src/xkb/XKBSetGeom.c index 1854fd8bf..7998ad72e 100644 --- a/libX11/src/xkb/XKBSetGeom.c +++ b/libX11/src/xkb/XKBSetGeom.c @@ -44,28 +44,29 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #define _SizeCountedString(s) ((s)?XkbPaddedSize(2+strlen(s)):4) static char * -_WriteCountedString(char *wire,char *str) +_WriteCountedString(char *wire, char *str) { -CARD16 len,*pLen; + CARD16 len, *pLen; - len= (str?strlen(str):0); - pLen= (CARD16 *)wire; - *pLen= len; + len = (str ? strlen(str) : 0); + pLen = (CARD16 *) wire; + *pLen = len; if (len && str) - memcpy(&wire[2],str,len); - wire+= XkbPaddedSize(len+2); + memcpy(&wire[2], str, len); + wire += XkbPaddedSize(len + 2); return wire; } static int _SizeGeomProperties(XkbGeometryPtr geom) { -register int i,size; -XkbPropertyPtr prop; + register int i, size; + XkbPropertyPtr prop; - for (size=i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) { - size+= _SizeCountedString(prop->name); - size+= _SizeCountedString(prop->value); + for (size = i = 0, prop = geom->properties; i < geom->num_properties; + i++, prop++) { + size += _SizeCountedString(prop->name); + size += _SizeCountedString(prop->value); } return size; } @@ -73,11 +74,11 @@ XkbPropertyPtr prop; static int _SizeGeomColors(XkbGeometryPtr geom) { -register int i,size; -register XkbColorPtr color; + register int i, size; + register XkbColorPtr color; - for (i=size=0,color=geom->colors;i<geom->num_colors;i++,color++) { - size+= _SizeCountedString(color->spec); + for (i = size = 0, color = geom->colors; i < geom->num_colors; i++, color++) { + size += _SizeCountedString(color->spec); } return size; } @@ -85,35 +86,36 @@ register XkbColorPtr color; static int _SizeGeomShapes(XkbGeometryPtr geom) { -register int i,size; -register XkbShapePtr shape; - - for (i=size=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) { - register int n; - register XkbOutlinePtr ol; - size+= SIZEOF(xkbShapeWireDesc); - for (n=0,ol=shape->outlines;n<shape->num_outlines;n++,ol++) { - size+= SIZEOF(xkbOutlineWireDesc); - size+= ol->num_points*SIZEOF(xkbPointWireDesc); - } + register int i, size; + register XkbShapePtr shape; + + for (i = size = 0, shape = geom->shapes; i < geom->num_shapes; i++, shape++) { + register int n; + register XkbOutlinePtr ol; + + size += SIZEOF(xkbShapeWireDesc); + for (n = 0, ol = shape->outlines; n < shape->num_outlines; n++, ol++) { + size += SIZEOF(xkbOutlineWireDesc); + size += ol->num_points * SIZEOF(xkbPointWireDesc); + } } return size; } static int -_SizeGeomDoodads(int num_doodads,XkbDoodadPtr doodad) +_SizeGeomDoodads(int num_doodads, XkbDoodadPtr doodad) { -register int i,size; - - for (i=size=0;i<num_doodads;i++,doodad++) { - size+= SIZEOF(xkbAnyDoodadWireDesc); - if (doodad->any.type==XkbTextDoodad) { - size+= _SizeCountedString(doodad->text.text); - size+= _SizeCountedString(doodad->text.font); - } - else if (doodad->any.type==XkbLogoDoodad) { - size+= _SizeCountedString(doodad->logo.logo_name); - } + register int i, size; + + for (i = size = 0; i < num_doodads; i++, doodad++) { + size += SIZEOF(xkbAnyDoodadWireDesc); + if (doodad->any.type == XkbTextDoodad) { + size += _SizeCountedString(doodad->text.text); + size += _SizeCountedString(doodad->text.font); + } + else if (doodad->any.type == XkbLogoDoodad) { + size += _SizeCountedString(doodad->logo.logo_name); + } } return size; } @@ -121,34 +123,39 @@ register int i,size; static int _SizeGeomSections(XkbGeometryPtr geom) { -register int i,size; -XkbSectionPtr section; - - for (i=size=0,section=geom->sections;i<geom->num_sections;i++,section++) { - size+= SIZEOF(xkbSectionWireDesc); - if (section->rows) { - int r; - XkbRowPtr row; - for (r=0,row=section->rows;r<section->num_rows;row++,r++) { - size+= SIZEOF(xkbRowWireDesc); - size+= row->num_keys*SIZEOF(xkbKeyWireDesc); - } - } - if (section->doodads) - size+= _SizeGeomDoodads(section->num_doodads,section->doodads); - if (section->overlays) { - int o; - XkbOverlayPtr ol; - for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) { - int r; - XkbOverlayRowPtr row; - size+= SIZEOF(xkbOverlayWireDesc); - for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) { - size+= SIZEOF(xkbOverlayRowWireDesc); - size+= row->num_keys*SIZEOF(xkbOverlayKeyWireDesc); - } - } - } + register int i, size; + XkbSectionPtr section; + + for (i = size = 0, section = geom->sections; i < geom->num_sections; + i++, section++) { + size += SIZEOF(xkbSectionWireDesc); + if (section->rows) { + int r; + XkbRowPtr row; + + for (r = 0, row = section->rows; r < section->num_rows; row++, r++) { + size += SIZEOF(xkbRowWireDesc); + size += row->num_keys * SIZEOF(xkbKeyWireDesc); + } + } + if (section->doodads) + size += _SizeGeomDoodads(section->num_doodads, section->doodads); + if (section->overlays) { + int o; + XkbOverlayPtr ol; + + for (o = 0, ol = section->overlays; o < section->num_overlays; + o++, ol++) { + int r; + XkbOverlayRowPtr row; + + size += SIZEOF(xkbOverlayWireDesc); + for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) { + size += SIZEOF(xkbOverlayRowWireDesc); + size += row->num_keys * SIZEOF(xkbOverlayKeyWireDesc); + } + } + } } return size; } @@ -156,224 +163,230 @@ XkbSectionPtr section; static int _SizeGeomKeyAliases(XkbGeometryPtr geom) { - return geom->num_key_aliases*(2*XkbKeyNameLength); + return geom->num_key_aliases * (2 * XkbKeyNameLength); } /***====================================================================***/ static char * -_WriteGeomProperties(char *wire,XkbGeometryPtr geom) +_WriteGeomProperties(char *wire, XkbGeometryPtr geom) { -register int i; -register XkbPropertyPtr prop; + register int i; + register XkbPropertyPtr prop; - for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) { - wire= _WriteCountedString(wire,prop->name); - wire= _WriteCountedString(wire,prop->value); + for (i = 0, prop = geom->properties; i < geom->num_properties; i++, prop++) { + wire = _WriteCountedString(wire, prop->name); + wire = _WriteCountedString(wire, prop->value); } return wire; } static char * -_WriteGeomColors(char *wire,XkbGeometryPtr geom) +_WriteGeomColors(char *wire, XkbGeometryPtr geom) { -register int i; -register XkbColorPtr color; + register int i; + register XkbColorPtr color; - for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) { - wire= _WriteCountedString(wire,color->spec); + for (i = 0, color = geom->colors; i < geom->num_colors; i++, color++) { + wire = _WriteCountedString(wire, color->spec); } return wire; } static char * -_WriteGeomShapes(char *wire,XkbGeometryPtr geom) +_WriteGeomShapes(char *wire, XkbGeometryPtr geom) { -int i; -XkbShapePtr shape; -xkbShapeWireDesc * shapeWire; - - for (i=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) { - register int o; - XkbOutlinePtr ol; - xkbOutlineWireDesc * olWire; - shapeWire= (xkbShapeWireDesc *)wire; - shapeWire->name= shape->name; - shapeWire->nOutlines= shape->num_outlines; - if (shape->primary!=NULL) - shapeWire->primaryNdx= XkbOutlineIndex(shape,shape->primary); - else shapeWire->primaryNdx= XkbNoShape; - if (shape->approx!=NULL) - shapeWire->approxNdx= XkbOutlineIndex(shape,shape->approx); - else shapeWire->approxNdx= XkbNoShape; - wire= (char *)&shapeWire[1]; - for (o=0,ol=shape->outlines;o<shape->num_outlines;o++,ol++) { - register int p; - XkbPointPtr pt; - xkbPointWireDesc * ptWire; - olWire= (xkbOutlineWireDesc *)wire; - olWire->nPoints= ol->num_points; - olWire->cornerRadius= ol->corner_radius; - wire= (char *)&olWire[1]; - ptWire= (xkbPointWireDesc *)wire; - for (p=0,pt=ol->points;p<ol->num_points;p++,pt++) { - ptWire[p].x= pt->x; - ptWire[p].y= pt->y; - } - wire= (char *)&ptWire[ol->num_points]; - } + int i; + XkbShapePtr shape; + xkbShapeWireDesc *shapeWire; + + for (i = 0, shape = geom->shapes; i < geom->num_shapes; i++, shape++) { + register int o; + XkbOutlinePtr ol; + xkbOutlineWireDesc *olWire; + + shapeWire = (xkbShapeWireDesc *) wire; + shapeWire->name = shape->name; + shapeWire->nOutlines = shape->num_outlines; + if (shape->primary != NULL) + shapeWire->primaryNdx = XkbOutlineIndex(shape, shape->primary); + else + shapeWire->primaryNdx = XkbNoShape; + if (shape->approx != NULL) + shapeWire->approxNdx = XkbOutlineIndex(shape, shape->approx); + else + shapeWire->approxNdx = XkbNoShape; + wire = (char *) &shapeWire[1]; + for (o = 0, ol = shape->outlines; o < shape->num_outlines; o++, ol++) { + register int p; + XkbPointPtr pt; + xkbPointWireDesc *ptWire; + + olWire = (xkbOutlineWireDesc *) wire; + olWire->nPoints = ol->num_points; + olWire->cornerRadius = ol->corner_radius; + wire = (char *) &olWire[1]; + ptWire = (xkbPointWireDesc *) wire; + for (p = 0, pt = ol->points; p < ol->num_points; p++, pt++) { + ptWire[p].x = pt->x; + ptWire[p].y = pt->y; + } + wire = (char *) &ptWire[ol->num_points]; + } } return wire; } static char * -_WriteGeomDoodads(char *wire,int num_doodads,XkbDoodadPtr doodad) +_WriteGeomDoodads(char *wire, int num_doodads, XkbDoodadPtr doodad) { -register int i; -xkbDoodadWireDesc * doodadWire; - - for (i=0;i<num_doodads;i++,doodad++) { - doodadWire= (xkbDoodadWireDesc *)wire; - wire= (char *)&doodadWire[1]; - bzero(doodadWire,SIZEOF(xkbDoodadWireDesc)); - doodadWire->any.name= doodad->any.name; - doodadWire->any.type= doodad->any.type; - doodadWire->any.priority= doodad->any.priority; - doodadWire->any.top= doodad->any.top; - doodadWire->any.left= doodad->any.left; - doodadWire->any.angle= doodad->any.angle; - switch (doodad->any.type) { - case XkbOutlineDoodad: - case XkbSolidDoodad: - doodadWire->shape.colorNdx= doodad->shape.color_ndx; - doodadWire->shape.shapeNdx= doodad->shape.shape_ndx; - break; - case XkbTextDoodad: - doodadWire->text.width= doodad->text.width; - doodadWire->text.height= doodad->text.height; - doodadWire->text.colorNdx= doodad->text.color_ndx; - wire= _WriteCountedString(wire,doodad->text.text); - wire= _WriteCountedString(wire,doodad->text.font); - break; - case XkbIndicatorDoodad: - doodadWire->indicator.shapeNdx= doodad->indicator.shape_ndx; - doodadWire->indicator.onColorNdx=doodad->indicator.on_color_ndx; - doodadWire->indicator.offColorNdx= - doodad->indicator.off_color_ndx; - break; - case XkbLogoDoodad: - doodadWire->logo.colorNdx= doodad->logo.color_ndx; - doodadWire->logo.shapeNdx= doodad->logo.shape_ndx; - wire= _WriteCountedString(wire,doodad->logo.logo_name); - break; - default: - break; - } + register int i; + + for (i = 0; i < num_doodads; i++, doodad++) { + xkbDoodadWireDesc *doodadWire = (xkbDoodadWireDesc *) wire; + + wire = (char *) &doodadWire[1]; + bzero(doodadWire, SIZEOF(xkbDoodadWireDesc)); + doodadWire->any.name = doodad->any.name; + doodadWire->any.type = doodad->any.type; + doodadWire->any.priority = doodad->any.priority; + doodadWire->any.top = doodad->any.top; + doodadWire->any.left = doodad->any.left; + doodadWire->any.angle = doodad->any.angle; + switch (doodad->any.type) { + case XkbOutlineDoodad: + case XkbSolidDoodad: + doodadWire->shape.colorNdx = doodad->shape.color_ndx; + doodadWire->shape.shapeNdx = doodad->shape.shape_ndx; + break; + case XkbTextDoodad: + doodadWire->text.width = doodad->text.width; + doodadWire->text.height = doodad->text.height; + doodadWire->text.colorNdx = doodad->text.color_ndx; + wire = _WriteCountedString(wire, doodad->text.text); + wire = _WriteCountedString(wire, doodad->text.font); + break; + case XkbIndicatorDoodad: + doodadWire->indicator.shapeNdx = doodad->indicator.shape_ndx; + doodadWire->indicator.onColorNdx = doodad->indicator.on_color_ndx; + doodadWire->indicator.offColorNdx = doodad->indicator.off_color_ndx; + break; + case XkbLogoDoodad: + doodadWire->logo.colorNdx = doodad->logo.color_ndx; + doodadWire->logo.shapeNdx = doodad->logo.shape_ndx; + wire = _WriteCountedString(wire, doodad->logo.logo_name); + break; + default: + break; + } } return wire; } static char * -_WriteGeomOverlay(char *wire,XkbOverlayPtr ol) +_WriteGeomOverlay(char *wire, XkbOverlayPtr ol) { -register int r; -XkbOverlayRowPtr row; -xkbOverlayWireDesc * olWire; - - olWire= (xkbOverlayWireDesc *)wire; - olWire->name= ol->name; - olWire->nRows= ol->num_rows; - wire= (char *)&olWire[1]; - for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) { - unsigned int k; - XkbOverlayKeyPtr key; - xkbOverlayRowWireDesc * rowWire; - rowWire= (xkbOverlayRowWireDesc *)wire; - rowWire->rowUnder= row->row_under; - rowWire->nKeys= row->num_keys; - wire= (char *)&rowWire[1]; - for (k=0,key=row->keys;k<row->num_keys;k++,key++) { - xkbOverlayKeyWireDesc * keyWire; - keyWire= (xkbOverlayKeyWireDesc *)wire; - memcpy(keyWire->over,key->over.name,XkbKeyNameLength); - memcpy(keyWire->under,key->under.name,XkbKeyNameLength); - wire= (char *)&keyWire[1]; - } - } - return wire; + register int r; + XkbOverlayRowPtr row; + xkbOverlayWireDesc *olWire = (xkbOverlayWireDesc *) wire; + + olWire->name = ol->name; + olWire->nRows = ol->num_rows; + wire = (char *) &olWire[1]; + for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) { + unsigned int k; + XkbOverlayKeyPtr key; + xkbOverlayRowWireDesc *rowWire = (xkbOverlayRowWireDesc *) wire; + + rowWire->rowUnder = row->row_under; + rowWire->nKeys = row->num_keys; + wire = (char *) &rowWire[1]; + for (k = 0, key = row->keys; k < row->num_keys; k++, key++) { + xkbOverlayKeyWireDesc *keyWire = (xkbOverlayKeyWireDesc *) wire; + + memcpy(keyWire->over, key->over.name, XkbKeyNameLength); + memcpy(keyWire->under, key->under.name, XkbKeyNameLength); + wire = (char *) &keyWire[1]; + } + } + return wire; } static char * -_WriteGeomSections(char *wire,XkbGeometryPtr geom) +_WriteGeomSections(char *wire, XkbGeometryPtr geom) { -register int i; -XkbSectionPtr section; -xkbSectionWireDesc * sectionWire; - - for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) { - sectionWire= (xkbSectionWireDesc *)wire; - sectionWire->name= section->name; - sectionWire->top= section->top; - sectionWire->left= section->left; - sectionWire->width= section->width; - sectionWire->height= section->height; - sectionWire->angle= section->angle; - sectionWire->priority= section->priority; - sectionWire->nRows= section->num_rows; - sectionWire->nDoodads= section->num_doodads; - sectionWire->nOverlays= section->num_overlays; - sectionWire->pad= 0; - wire= (char *)§ionWire[1]; - if (section->rows) { - int r; - XkbRowPtr row; - xkbRowWireDesc * rowWire; - for (r=0,row=section->rows;r<section->num_rows;r++,row++) { - rowWire= (xkbRowWireDesc *)wire; - rowWire->top= row->top; - rowWire->left= row->left; - rowWire->nKeys= row->num_keys; - rowWire->vertical= row->vertical; - rowWire->pad= 0; - wire= (char *)&rowWire[1]; - if (row->keys) { - int k; - XkbKeyPtr key; - xkbKeyWireDesc * keyWire; - keyWire= (xkbKeyWireDesc *)wire; - for (k=0,key=row->keys;k<row->num_keys;k++,key++) { - memcpy(keyWire[k].name,key->name.name,XkbKeyNameLength); - keyWire[k].gap= key->gap; - keyWire[k].shapeNdx= key->shape_ndx; - keyWire[k].colorNdx= key->color_ndx; - } - wire= (char *)&keyWire[row->num_keys]; - } - } - } - if (section->doodads) { - wire= _WriteGeomDoodads(wire, - section->num_doodads,section->doodads); - } - if (section->overlays) { - register int o; - for (o=0;o<section->num_overlays;o++) { - wire= _WriteGeomOverlay(wire,§ion->overlays[o]); - } - } + register int i; + XkbSectionPtr section; + + for (i = 0, section = geom->sections; i < geom->num_sections; + i++, section++) { + xkbSectionWireDesc *sectionWire = (xkbSectionWireDesc *) wire; + + sectionWire->name = section->name; + sectionWire->top = section->top; + sectionWire->left = section->left; + sectionWire->width = section->width; + sectionWire->height = section->height; + sectionWire->angle = section->angle; + sectionWire->priority = section->priority; + sectionWire->nRows = section->num_rows; + sectionWire->nDoodads = section->num_doodads; + sectionWire->nOverlays = section->num_overlays; + sectionWire->pad = 0; + wire = (char *) §ionWire[1]; + if (section->rows) { + int r; + XkbRowPtr row; + + for (r = 0, row = section->rows; r < section->num_rows; r++, row++) { + xkbRowWireDesc *rowWire = (xkbRowWireDesc *) wire; + + rowWire->top = row->top; + rowWire->left = row->left; + rowWire->nKeys = row->num_keys; + rowWire->vertical = row->vertical; + rowWire->pad = 0; + wire = (char *) &rowWire[1]; + if (row->keys) { + int k; + XkbKeyPtr key; + xkbKeyWireDesc *keyWire = (xkbKeyWireDesc *) wire; + + for (k = 0, key = row->keys; k < row->num_keys; k++, key++) { + memcpy(keyWire[k].name, key->name.name, + XkbKeyNameLength); + keyWire[k].gap = key->gap; + keyWire[k].shapeNdx = key->shape_ndx; + keyWire[k].colorNdx = key->color_ndx; + } + wire = (char *) &keyWire[row->num_keys]; + } + } + } + if (section->doodads) { + wire = _WriteGeomDoodads(wire, + section->num_doodads, section->doodads); + } + if (section->overlays) { + register int o; + + for (o = 0; o < section->num_overlays; o++) { + wire = _WriteGeomOverlay(wire, §ion->overlays[o]); + } + } } return wire; } static char * -_WriteGeomKeyAliases(char *wire,XkbGeometryPtr geom) +_WriteGeomKeyAliases(char *wire, XkbGeometryPtr geom) { -register int sz; + register int sz; - sz= geom->num_key_aliases*(XkbKeyNameLength*2); - if (sz>0) { - memcpy(wire,(char *)geom->key_aliases,sz); - wire+= sz; + sz = geom->num_key_aliases * (XkbKeyNameLength * 2); + if (sz > 0) { + memcpy(wire, (char *) geom->key_aliases, sz); + wire += sz; } return wire; } @@ -381,46 +394,46 @@ register int sz; /***====================================================================***/ static Status -_SendSetGeometry(Display *dpy,XkbGeometryPtr geom,xkbSetGeometryReq *req) +_SendSetGeometry(Display *dpy, XkbGeometryPtr geom, xkbSetGeometryReq *req) { -int sz; -char * wire,*tbuf; - - sz= 0; - sz+= _SizeCountedString(geom->label_font); - sz+= _SizeGeomProperties(geom); - sz+= _SizeGeomColors(geom); - sz+= _SizeGeomShapes(geom); - sz+= _SizeGeomSections(geom); - sz+= _SizeGeomDoodads(geom->num_doodads,geom->doodads); - sz+= _SizeGeomKeyAliases(geom); - req->length+= (sz/4); + int sz; + char *wire, *tbuf; + + sz = 0; + sz += _SizeCountedString(geom->label_font); + sz += _SizeGeomProperties(geom); + sz += _SizeGeomColors(geom); + sz += _SizeGeomShapes(geom); + sz += _SizeGeomSections(geom); + sz += _SizeGeomDoodads(geom->num_doodads, geom->doodads); + sz += _SizeGeomKeyAliases(geom); + req->length += (sz / 4); if (sz < (dpy->bufmax - dpy->buffer)) { - BufAlloc(char *,wire,sz); - tbuf= NULL; + BufAlloc(char *, wire, sz); + tbuf = NULL; } else { - tbuf= _XAllocTemp(dpy,sz); - if (!tbuf) - return BadAlloc; - wire= tbuf; + tbuf = _XAllocTemp(dpy, sz); + if (!tbuf) + return BadAlloc; + wire = tbuf; } - wire= _WriteCountedString(wire,geom->label_font); - if (geom->num_properties>0) - wire= _WriteGeomProperties(wire,geom); - if (geom->num_colors>0) - wire= _WriteGeomColors(wire,geom); - if (geom->num_shapes>0) - wire= _WriteGeomShapes(wire,geom); - if (geom->num_sections>0) - wire= _WriteGeomSections(wire,geom); - if (geom->num_doodads>0) - wire= _WriteGeomDoodads(wire,geom->num_doodads,geom->doodads); - if (geom->num_key_aliases>0) - wire= _WriteGeomKeyAliases(wire,geom); - if (tbuf!=NULL) { - Data(dpy,tbuf,sz); - _XFreeTemp(dpy,tbuf,sz); + wire = _WriteCountedString(wire, geom->label_font); + if (geom->num_properties > 0) + wire = _WriteGeomProperties(wire, geom); + if (geom->num_colors > 0) + wire = _WriteGeomColors(wire, geom); + if (geom->num_shapes > 0) + wire = _WriteGeomShapes(wire, geom); + if (geom->num_sections > 0) + wire = _WriteGeomSections(wire, geom); + if (geom->num_doodads > 0) + wire = _WriteGeomDoodads(wire, geom->num_doodads, geom->doodads); + if (geom->num_key_aliases > 0) + wire = _WriteGeomKeyAliases(wire, geom); + if (tbuf != NULL) { + Data(dpy, tbuf, sz); + _XFreeTemp(dpy, tbuf, sz); } return Success; } @@ -428,35 +441,34 @@ char * wire,*tbuf; /***====================================================================***/ Status -XkbSetGeometry(Display *dpy,unsigned deviceSpec,XkbGeometryPtr geom) +XkbSetGeometry(Display *dpy, unsigned deviceSpec, XkbGeometryPtr geom) { -xkbSetGeometryReq *req; -Status ret; + xkbSetGeometryReq *req; + Status ret; - if ( (!geom) || (dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + if ((!geom) || (dpy->flags & XlibDisplayNoXkb) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); GetReq(kbSetGeometry, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbSetGeometry; req->deviceSpec = deviceSpec; - req->nShapes= geom->num_shapes; - req->nSections= geom->num_sections; - req->name= geom->name; - req->widthMM= geom->width_mm; - req->heightMM= geom->height_mm; - req->nProperties= geom->num_properties; - req->nColors= geom->num_colors; - req->nDoodads= geom->num_doodads; - req->nKeyAliases= geom->num_key_aliases; - req->baseColorNdx= (geom->base_color-geom->colors); - req->labelColorNdx= (geom->label_color-geom->colors); - - ret = _SendSetGeometry(dpy,geom,req); + req->nShapes = geom->num_shapes; + req->nSections = geom->num_sections; + req->name = geom->name; + req->widthMM = geom->width_mm; + req->heightMM = geom->height_mm; + req->nProperties = geom->num_properties; + req->nColors = geom->num_colors; + req->nDoodads = geom->num_doodads; + req->nKeyAliases = geom->num_key_aliases; + req->baseColorNdx = (geom->base_color - geom->colors); + req->labelColorNdx = (geom->label_color - geom->colors); + + ret = _SendSetGeometry(dpy, geom, req); UnlockDisplay(dpy); SyncHandle(); return ret; } - diff --git a/libX11/src/xkb/XKBSetMap.c b/libX11/src/xkb/XKBSetMap.c index cad9364b7..6e1e70710 100644 --- a/libX11/src/xkb/XKBSetMap.c +++ b/libX11/src/xkb/XKBSetMap.c @@ -33,221 +33,222 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "XKBlibint.h" static int -_XkbSizeKeyTypes(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeKeyTypes(XkbDescPtr xkb, xkbSetMapReq *req) { - XkbKeyTypePtr map; - int i,len; + XkbKeyTypePtr map; + int i, len; - if (((req->present&XkbKeyTypesMask)==0)||(req->nTypes==0)) { - req->present&= ~XkbKeyTypesMask; - req->firstType= req->nTypes= 0; - return 0; + if (((req->present & XkbKeyTypesMask) == 0) || (req->nTypes == 0)) { + req->present &= ~XkbKeyTypesMask; + req->firstType = req->nTypes = 0; + return 0; } - len= 0; - map= &xkb->map->types[req->firstType]; - for (i=0;i<req->nTypes;i++,map++){ - len+= SIZEOF(xkbKeyTypeWireDesc); - len+= map->map_count*SIZEOF(xkbKTSetMapEntryWireDesc); - if (map->preserve) - len+= map->map_count*SIZEOF(xkbModsWireDesc); + len = 0; + map = &xkb->map->types[req->firstType]; + for (i = 0; i < req->nTypes; i++, map++) { + len += SIZEOF(xkbKeyTypeWireDesc); + len += map->map_count * SIZEOF(xkbKTSetMapEntryWireDesc); + if (map->preserve) + len += map->map_count * SIZEOF(xkbModsWireDesc); } return len; } static void -_XkbWriteKeyTypes(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteKeyTypes(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { - char * buf; - XkbKeyTypePtr type; - int i,n,sz; + char *buf; + XkbKeyTypePtr type; + int i, n; xkbKeyTypeWireDesc *desc; - if ((req->present&XkbKeyTypesMask)==0) - return; - type= &xkb->map->types[req->firstType]; - for (i=0;i<req->nTypes;i++,type++) { - sz= SIZEOF(xkbKeyTypeWireDesc); - sz+= type->map_count*SIZEOF(xkbKTSetMapEntryWireDesc); - if (type->preserve) - sz+= type->map_count*SIZEOF(xkbModsWireDesc); - BufAlloc(xkbKeyTypeWireDesc *,desc,sz); - desc->mask = type->mods.mask; - desc->realMods = type->mods.real_mods; - desc->virtualMods = type->mods.vmods; - desc->numLevels = type->num_levels; - desc->nMapEntries = type->map_count; - desc->preserve = (type->preserve!=NULL); - buf= (char *)&desc[1]; - if (desc->nMapEntries>0) { - xkbKTSetMapEntryWireDesc *wire; - wire= (xkbKTSetMapEntryWireDesc *)buf; - for (n=0;n<type->map_count;n++,wire++) { - wire->level= type->map[n].level; - wire->realMods= type->map[n].mods.real_mods; - wire->virtualMods= type->map[n].mods.vmods; - } - buf= (char *)wire; - if (type->preserve) { - xkbModsWireDesc *pwire; - pwire= (xkbModsWireDesc *)buf; - for (n=0;n<type->map_count;n++,pwire++) { - pwire->realMods= type->preserve[n].real_mods; - pwire->virtualMods= type->preserve[n].vmods; - } - } - } + if ((req->present & XkbKeyTypesMask) == 0) + return; + type = &xkb->map->types[req->firstType]; + for (i = 0; i < req->nTypes; i++, type++) { + int sz = SIZEOF(xkbKeyTypeWireDesc); + sz += type->map_count * SIZEOF(xkbKTSetMapEntryWireDesc); + if (type->preserve) + sz += type->map_count * SIZEOF(xkbModsWireDesc); + BufAlloc(xkbKeyTypeWireDesc *, desc, sz); + desc->mask = type->mods.mask; + desc->realMods = type->mods.real_mods; + desc->virtualMods = type->mods.vmods; + desc->numLevels = type->num_levels; + desc->nMapEntries = type->map_count; + desc->preserve = (type->preserve != NULL); + buf = (char *) &desc[1]; + if (desc->nMapEntries > 0) { + xkbKTSetMapEntryWireDesc *wire = (xkbKTSetMapEntryWireDesc *) buf; + + for (n = 0; n < type->map_count; n++, wire++) { + wire->level = type->map[n].level; + wire->realMods = type->map[n].mods.real_mods; + wire->virtualMods = type->map[n].mods.vmods; + } + buf = (char *) wire; + if (type->preserve) { + xkbModsWireDesc *pwire = (xkbModsWireDesc *) buf; + + for (n = 0; n < type->map_count; n++, pwire++) { + pwire->realMods = type->preserve[n].real_mods; + pwire->virtualMods = type->preserve[n].vmods; + } + } + } } return; } static int -_XkbSizeKeySyms(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeKeySyms(XkbDescPtr xkb, xkbSetMapReq *req) { - int i,len; - unsigned nSyms; - - if (((req->present&XkbKeySymsMask)==0)||(req->nKeySyms==0)) { - req->present&= ~XkbKeySymsMask; - req->firstKeySym= req->nKeySyms= 0; - req->totalSyms= 0; - return 0; + int i, len; + unsigned nSyms; + + if (((req->present & XkbKeySymsMask) == 0) || (req->nKeySyms == 0)) { + req->present &= ~XkbKeySymsMask; + req->firstKeySym = req->nKeySyms = 0; + req->totalSyms = 0; + return 0; } - len= (int)(req->nKeySyms*sizeof(XkbSymMapRec)); - for (i=nSyms=0;i<req->nKeySyms;i++) { - nSyms+= XkbKeyNumSyms(xkb,i+req->firstKeySym); + len = (int) (req->nKeySyms * sizeof(XkbSymMapRec)); + for (i = nSyms = 0; i < req->nKeySyms; i++) { + nSyms += XkbKeyNumSyms(xkb, i + req->firstKeySym); } - len+= nSyms*sizeof(CARD32); - req->totalSyms= nSyms; + len += nSyms * sizeof(CARD32); + req->totalSyms = nSyms; return len; } static void -_XkbWriteKeySyms(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteKeySyms(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { -register KeySym * pSym; -CARD32 * outSym; -XkbSymMapPtr symMap; -xkbSymMapWireDesc *desc; -register int i; - - if ((req->present&XkbKeySymsMask)==0) - return; + register KeySym *pSym; + CARD32 *outSym; + XkbSymMapPtr symMap; + xkbSymMapWireDesc *desc; + register int i; + + if ((req->present & XkbKeySymsMask) == 0) + return; symMap = &xkb->map->key_sym_map[req->firstKeySym]; - for (i=0;i<req->nKeySyms;i++,symMap++) { - BufAlloc(xkbSymMapWireDesc *,desc, - SIZEOF(xkbSymMapWireDesc)+ - (XkbKeyNumSyms(xkb,i+req->firstKeySym)*sizeof(CARD32))); - desc->ktIndex[0] = symMap->kt_index[0]; - desc->ktIndex[1] = symMap->kt_index[1]; - desc->ktIndex[2] = symMap->kt_index[2]; - desc->ktIndex[3] = symMap->kt_index[3]; - desc->groupInfo = symMap->group_info; - desc->width = symMap->width; - desc->nSyms = XkbKeyNumSyms(xkb,i+req->firstKeySym); - outSym = (CARD32 *)&desc[1]; - if (desc->nSyms>0) { - pSym = XkbKeySymsPtr(xkb,i+req->firstKeySym); - _XkbWriteCopyKeySyms(pSym,outSym,desc->nSyms); - } + for (i = 0; i < req->nKeySyms; i++, symMap++) { + BufAlloc(xkbSymMapWireDesc *, desc, + SIZEOF(xkbSymMapWireDesc) + + (XkbKeyNumSyms(xkb, i + req->firstKeySym) * sizeof(CARD32))); + desc->ktIndex[0] = symMap->kt_index[0]; + desc->ktIndex[1] = symMap->kt_index[1]; + desc->ktIndex[2] = symMap->kt_index[2]; + desc->ktIndex[3] = symMap->kt_index[3]; + desc->groupInfo = symMap->group_info; + desc->width = symMap->width; + desc->nSyms = XkbKeyNumSyms(xkb, i + req->firstKeySym); + outSym = (CARD32 *) &desc[1]; + if (desc->nSyms > 0) { + pSym = XkbKeySymsPtr(xkb, i + req->firstKeySym); + _XkbWriteCopyKeySyms(pSym, outSym, desc->nSyms); + } } return; } static int -_XkbSizeKeyActions(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeKeyActions(XkbDescPtr xkb, xkbSetMapReq *req) { - int i,len,nActs; + int i, len, nActs; - if (((req->present&XkbKeyActionsMask)==0)||(req->nKeyActs==0)) { - req->present&= ~XkbKeyActionsMask; - req->firstKeyAct= req->nKeyActs= 0; - req->totalActs= 0; - return 0; + if (((req->present & XkbKeyActionsMask) == 0) || (req->nKeyActs == 0)) { + req->present &= ~XkbKeyActionsMask; + req->firstKeyAct = req->nKeyActs = 0; + req->totalActs = 0; + return 0; } - for (nActs=i=0;i<req->nKeyActs;i++) { - if (xkb->server->key_acts[i+req->firstKeyAct]!=0) - nActs+= XkbKeyNumActions(xkb,i+req->firstKeyAct); + for (nActs = i = 0; i < req->nKeyActs; i++) { + if (xkb->server->key_acts[i + req->firstKeyAct] != 0) + nActs += XkbKeyNumActions(xkb, i + req->firstKeyAct); } - len= XkbPaddedSize(req->nKeyActs)+(nActs*SIZEOF(xkbActionWireDesc)); - req->totalActs= nActs; + len = XkbPaddedSize(req->nKeyActs) + (nActs * SIZEOF(xkbActionWireDesc)); + req->totalActs = nActs; return len; } static void -_XkbWriteKeyActions(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteKeyActions(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { - register int i; - int n; - CARD8 *numDesc; - XkbAction *actDesc; + register int i; + int n; + CARD8 *numDesc; + XkbAction *actDesc; - if ((req->present&XkbKeyActionsMask)==0) - return; + if ((req->present & XkbKeyActionsMask) == 0) + return; n = XkbPaddedSize(req->nKeyActs); - n+= (req->totalActs*SIZEOF(xkbActionWireDesc)); - - BufAlloc(CARD8 *,numDesc,n); - for (i=0;i<req->nKeyActs;i++) { - if (xkb->server->key_acts[i+req->firstKeyAct]==0) - numDesc[i] = 0; - else numDesc[i] = XkbKeyNumActions(xkb,(i+req->firstKeyAct)); + n += (req->totalActs * SIZEOF(xkbActionWireDesc)); + + BufAlloc(CARD8 *, numDesc, n); + for (i = 0; i < req->nKeyActs; i++) { + if (xkb->server->key_acts[i + req->firstKeyAct] == 0) + numDesc[i] = 0; + else + numDesc[i] = XkbKeyNumActions(xkb, (i + req->firstKeyAct)); } - actDesc = (XkbAction *)&numDesc[XkbPaddedSize(req->nKeyActs)]; - for (i=0;i<req->nKeyActs;i++) { - if (xkb->server->key_acts[i+req->firstKeyAct]!=0) { - n = XkbKeyNumActions(xkb,(i+req->firstKeyAct)); - memcpy(actDesc,XkbKeyActionsPtr(xkb,(i+req->firstKeyAct)), - n*SIZEOF(xkbActionWireDesc)); - actDesc+= n; - } + actDesc = (XkbAction *) &numDesc[XkbPaddedSize(req->nKeyActs)]; + for (i = 0; i < req->nKeyActs; i++) { + if (xkb->server->key_acts[i + req->firstKeyAct] != 0) { + n = XkbKeyNumActions(xkb, (i + req->firstKeyAct)); + memcpy(actDesc, XkbKeyActionsPtr(xkb, (i + req->firstKeyAct)), + n * SIZEOF(xkbActionWireDesc)); + actDesc += n; + } } return; } static int -_XkbSizeKeyBehaviors(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeKeyBehaviors(XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last,nFound; + register int i, first, last, nFound; - if (((req->present&XkbKeyBehaviorsMask)==0)||(req->nKeyBehaviors<1)) { - req->present&= ~XkbKeyBehaviorsMask; - req->firstKeyBehavior= req->nKeyBehaviors= 0; - req->totalKeyBehaviors= 0; - return 0; + if (((req->present & XkbKeyBehaviorsMask) == 0) || (req->nKeyBehaviors < 1)) { + req->present &= ~XkbKeyBehaviorsMask; + req->firstKeyBehavior = req->nKeyBehaviors = 0; + req->totalKeyBehaviors = 0; + return 0; } - first= req->firstKeyBehavior; - last= first+req->nKeyBehaviors-1; - for (i=first,nFound=0;i<=last;i++) { - if (xkb->server->behaviors[i].type!=XkbKB_Default) - nFound++; + first = req->firstKeyBehavior; + last = first + req->nKeyBehaviors - 1; + for (i = first, nFound = 0; i <= last; i++) { + if (xkb->server->behaviors[i].type != XkbKB_Default) + nFound++; } - req->totalKeyBehaviors= nFound; - return (nFound*SIZEOF(xkbBehaviorWireDesc)); + req->totalKeyBehaviors = nFound; + return (nFound * SIZEOF(xkbBehaviorWireDesc)); } static void -_XkbWriteKeyBehaviors(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteKeyBehaviors(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last; -xkbBehaviorWireDesc * wire; -char * buf; - - if ((req->present&XkbKeyBehaviorsMask)==0) - return; - first= req->firstKeyBehavior; - last= first+req->nKeyBehaviors-1; - - i= req->totalKeyBehaviors*SIZEOF(xkbBehaviorWireDesc); - BufAlloc(char *,buf,i); - wire= (xkbBehaviorWireDesc *)buf; - for (i=first;i<=last;i++) { - if (xkb->server->behaviors[i].type!=XkbKB_Default) { - wire->key= i; - wire->type= xkb->server->behaviors[i].type; - wire->data= xkb->server->behaviors[i].data; - buf+= SIZEOF(xkbBehaviorWireDesc); - wire= (xkbBehaviorWireDesc *)buf; - } + register int i, first, last; + xkbBehaviorWireDesc *wire; + char *buf; + + if ((req->present & XkbKeyBehaviorsMask) == 0) + return; + first = req->firstKeyBehavior; + last = first + req->nKeyBehaviors - 1; + + i = req->totalKeyBehaviors * SIZEOF(xkbBehaviorWireDesc); + BufAlloc(char *, buf, i); + wire = (xkbBehaviorWireDesc *) buf; + for (i = first; i <= last; i++) { + if (xkb->server->behaviors[i].type != XkbKB_Default) { + wire->key = i; + wire->type = xkb->server->behaviors[i].type; + wire->data = xkb->server->behaviors[i].data; + buf += SIZEOF(xkbBehaviorWireDesc); + wire = (xkbBehaviorWireDesc *) buf; + } } return; } @@ -255,236 +256,239 @@ char * buf; static unsigned _XkbSizeVirtualMods(xkbSetMapReq *req) { -register int i,bit,nMods; - - if (((req->present&XkbVirtualModsMask)==0)||(req->virtualMods==0)) { - req->present&= ~XkbVirtualModsMask; - req->virtualMods= 0; - return 0; - } - for (i=nMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { - if (req->virtualMods&bit) - nMods++; - } - return XkbPaddedSize(nMods); + register int i, bit, nMods; + + if (((req->present & XkbVirtualModsMask) == 0) || (req->virtualMods == 0)) { + req->present &= ~XkbVirtualModsMask; + req->virtualMods = 0; + return 0; + } + for (i = nMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { + if (req->virtualMods & bit) + nMods++; + } + return XkbPaddedSize(nMods); } static void -_XkbWriteVirtualMods( Display * dpy, - XkbDescPtr xkb, - xkbSetMapReq * req, - unsigned size) +_XkbWriteVirtualMods(Display *dpy, + XkbDescPtr xkb, + xkbSetMapReq *req, + unsigned size) { - register int i,bit; - CARD8 *vmods; + register int i, bit; + CARD8 *vmods; /* This was req->present&XkbVirtualModsMask==0, and '==' beats '&' */ if (((req->present & XkbVirtualModsMask) == 0) || (size < 1)) - return; - BufAlloc(CARD8 *,vmods,size); - for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { - if (req->virtualMods&bit) - *vmods++= xkb->server->vmods[i]; + return; + BufAlloc(CARD8 *, vmods, size); + for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { + if (req->virtualMods & bit) + *vmods++ = xkb->server->vmods[i]; } return; } static int -_XkbSizeKeyExplicit(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeKeyExplicit(XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last,nFound; - - if (((req->present&XkbExplicitComponentsMask)==0)||(req->nKeyExplicit==0)) { - req->present&= ~XkbExplicitComponentsMask; - req->firstKeyExplicit= req->nKeyExplicit= 0; - req->totalKeyExplicit= 0; - return 0; + register int i, first, last, nFound; + + if (((req->present & XkbExplicitComponentsMask) == 0) || + (req->nKeyExplicit == 0)) { + req->present &= ~XkbExplicitComponentsMask; + req->firstKeyExplicit = req->nKeyExplicit = 0; + req->totalKeyExplicit = 0; + return 0; } - first= req->firstKeyExplicit; - last= first+req->nKeyExplicit-1; + first = req->firstKeyExplicit; + last = first + req->nKeyExplicit - 1; - for (i=first,nFound=0;i<=last;i++) { - if (xkb->server->explicit[i]!=0) - nFound++; + for (i = first, nFound = 0; i <= last; i++) { + if (xkb->server->explicit[i] != 0) + nFound++; } - req->totalKeyExplicit= nFound; - return XkbPaddedSize((nFound*2)); + req->totalKeyExplicit = nFound; + return XkbPaddedSize((nFound * 2)); } static void -_XkbWriteKeyExplicit(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteKeyExplicit(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last; -CARD8 * wire; - - if ((req->present&XkbExplicitComponentsMask)==0) - return; - first= req->firstKeyExplicit; - last= first+req->nKeyExplicit - 1; - i= XkbPaddedSize((req->totalKeyExplicit*2)); - BufAlloc(CARD8 *,wire,i); - for (i=first;i<=last;i++) { - if (xkb->server->explicit[i]!=0) { - wire[0]= i; - wire[1]= xkb->server->explicit[i]; - wire+= 2; - } + register int i, first, last; + CARD8 *wire; + + if ((req->present & XkbExplicitComponentsMask) == 0) + return; + first = req->firstKeyExplicit; + last = first + req->nKeyExplicit - 1; + i = XkbPaddedSize((req->totalKeyExplicit * 2)); + BufAlloc(CARD8 *, wire, i); + for (i = first; i <= last; i++) { + if (xkb->server->explicit[i] != 0) { + wire[0] = i; + wire[1] = xkb->server->explicit[i]; + wire += 2; + } } return; } static int -_XkbSizeModifierMap(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeModifierMap(XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last,nFound; + register int i, first, last, nFound; - if (((req->present&XkbModifierMapMask)==0)||(req->nModMapKeys==0)) { - req->present&= ~XkbModifierMapMask; - req->firstModMapKey= req->nModMapKeys= 0; - req->totalModMapKeys= 0; - return 0; + if (((req->present & XkbModifierMapMask) == 0) || (req->nModMapKeys == 0)) { + req->present &= ~XkbModifierMapMask; + req->firstModMapKey = req->nModMapKeys = 0; + req->totalModMapKeys = 0; + return 0; } - first= req->firstModMapKey; - last= first+req->nModMapKeys-1; + first = req->firstModMapKey; + last = first + req->nModMapKeys - 1; - for (i=first,nFound=0;i<=last;i++) { - if (xkb->map->modmap[i]!=0) - nFound++; + for (i = first, nFound = 0; i <= last; i++) { + if (xkb->map->modmap[i] != 0) + nFound++; } - req->totalModMapKeys= nFound; - return XkbPaddedSize((nFound*2)); + req->totalModMapKeys = nFound; + return XkbPaddedSize((nFound * 2)); } static void -_XkbWriteModifierMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteModifierMap(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last; -CARD8 * wire; - - if ((req->present&XkbModifierMapMask)==0) - return; - first= req->firstModMapKey; - last= first+req->nModMapKeys-1; - if (req->totalModMapKeys>0) { - i= XkbPaddedSize((req->totalModMapKeys*2)); - BufAlloc(CARD8 *,wire,i); - for (i=first;i<=last;i++) { - if (xkb->map->modmap[i]!=0) { - wire[0]= i; - wire[1]= xkb->map->modmap[i]; - wire+= 2; - } - } + register int i, first, last; + CARD8 *wire; + + if ((req->present & XkbModifierMapMask) == 0) + return; + first = req->firstModMapKey; + last = first + req->nModMapKeys - 1; + if (req->totalModMapKeys > 0) { + i = XkbPaddedSize((req->totalModMapKeys * 2)); + BufAlloc(CARD8 *, wire, i); + + for (i = first; i <= last; i++) { + if (xkb->map->modmap[i] != 0) { + wire[0] = i; + wire[1] = xkb->map->modmap[i]; + wire += 2; + } + } } return; } static int -_XkbSizeVirtualModMap(XkbDescPtr xkb,xkbSetMapReq *req) +_XkbSizeVirtualModMap(XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last,nFound; - - if (((req->present&XkbVirtualModMapMask)==0)||(req->nVModMapKeys==0)) { - req->present&= ~XkbVirtualModMapMask; - req->firstVModMapKey= req->nVModMapKeys= 0; - req->totalVModMapKeys= 0; - return 0; + register int i, first, last, nFound; + + if (((req->present & XkbVirtualModMapMask) == 0) || + (req->nVModMapKeys == 0)) { + req->present &= ~XkbVirtualModMapMask; + req->firstVModMapKey = req->nVModMapKeys = 0; + req->totalVModMapKeys = 0; + return 0; } - first= req->firstVModMapKey; - last= first+req->nVModMapKeys-1; + first = req->firstVModMapKey; + last = first + req->nVModMapKeys - 1; - for (i=first,nFound=0;i<=last;i++) { - if (xkb->server->vmodmap[i]!=0) - nFound++; + for (i = first, nFound = 0; i <= last; i++) { + if (xkb->server->vmodmap[i] != 0) + nFound++; } - req->totalVModMapKeys= nFound; - return nFound*SIZEOF(xkbVModMapWireDesc); + req->totalVModMapKeys = nFound; + return nFound * SIZEOF(xkbVModMapWireDesc); } static void -_XkbWriteVirtualModMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +_XkbWriteVirtualModMap(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { -register int i,first,last; -xkbVModMapWireDesc * wire; - - if ((req->present&XkbVirtualModMapMask)==0) - return; - first= req->firstVModMapKey; - last= first+req->nVModMapKeys-1; - if (req->totalVModMapKeys>0) { - i= req->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc); - BufAlloc(xkbVModMapWireDesc *,wire,i); - for (i=first;i<=last;i++) { - if (xkb->server->vmodmap[i]!=0) { - wire->key= i; - wire->vmods= xkb->server->vmodmap[i]; - wire++; - } - } + register int i, first, last; + xkbVModMapWireDesc *wire; + + if ((req->present & XkbVirtualModMapMask) == 0) + return; + first = req->firstVModMapKey; + last = first + req->nVModMapKeys - 1; + if (req->totalVModMapKeys > 0) { + i = req->totalVModMapKeys * SIZEOF(xkbVModMapWireDesc); + BufAlloc(xkbVModMapWireDesc *, wire, i); + for (i = first; i <= last; i++) { + if (xkb->server->vmodmap[i] != 0) { + wire->key = i; + wire->vmods = xkb->server->vmodmap[i]; + wire++; + } + } } return; } static void -SendSetMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) +SendSetMap(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { -xkbSetMapReq tmp; -unsigned szMods; - - req->length+= _XkbSizeKeyTypes(xkb,req)/4; - req->length+= _XkbSizeKeySyms(xkb,req)/4; - req->length+= _XkbSizeKeyActions(xkb,req)/4; - req->length+= _XkbSizeKeyBehaviors(xkb,req)/4; - szMods= _XkbSizeVirtualMods(req); - req->length+= szMods/4; - req->length+= _XkbSizeKeyExplicit(xkb,req)/4; - req->length+= _XkbSizeModifierMap(xkb,req)/4; - req->length+= _XkbSizeVirtualModMap(xkb,req)/4; - - tmp= *req; - if ( tmp.nTypes>0 ) - _XkbWriteKeyTypes(dpy,xkb,&tmp); - if ( tmp.nKeySyms>0 ) - _XkbWriteKeySyms(dpy,xkb,&tmp); - if ( tmp.nKeyActs ) - _XkbWriteKeyActions(dpy,xkb,&tmp); - if ( tmp.totalKeyBehaviors>0 ) - _XkbWriteKeyBehaviors(dpy,xkb,&tmp); - if ( tmp.virtualMods ) - _XkbWriteVirtualMods(dpy,xkb,&tmp,szMods); - if ( tmp.totalKeyExplicit>0) - _XkbWriteKeyExplicit(dpy,xkb,&tmp); - if ( tmp.totalModMapKeys>0) - _XkbWriteModifierMap(dpy,xkb,&tmp); - if ( tmp.totalVModMapKeys>0) - _XkbWriteVirtualModMap(dpy,xkb,&tmp); + xkbSetMapReq tmp; + unsigned szMods; + + req->length += _XkbSizeKeyTypes(xkb, req) / 4; + req->length += _XkbSizeKeySyms(xkb, req) / 4; + req->length += _XkbSizeKeyActions(xkb, req) / 4; + req->length += _XkbSizeKeyBehaviors(xkb, req) / 4; + szMods = _XkbSizeVirtualMods(req); + req->length += szMods / 4; + req->length += _XkbSizeKeyExplicit(xkb, req) / 4; + req->length += _XkbSizeModifierMap(xkb, req) / 4; + req->length += _XkbSizeVirtualModMap(xkb, req) / 4; + + tmp = *req; + if (tmp.nTypes > 0) + _XkbWriteKeyTypes(dpy, xkb, &tmp); + if (tmp.nKeySyms > 0) + _XkbWriteKeySyms(dpy, xkb, &tmp); + if (tmp.nKeyActs) + _XkbWriteKeyActions(dpy, xkb, &tmp); + if (tmp.totalKeyBehaviors > 0) + _XkbWriteKeyBehaviors(dpy, xkb, &tmp); + if (tmp.virtualMods) + _XkbWriteVirtualMods(dpy, xkb, &tmp, szMods); + if (tmp.totalKeyExplicit > 0) + _XkbWriteKeyExplicit(dpy, xkb, &tmp); + if (tmp.totalModMapKeys > 0) + _XkbWriteModifierMap(dpy, xkb, &tmp); + if (tmp.totalVModMapKeys > 0) + _XkbWriteVirtualModMap(dpy, xkb, &tmp); return; } Bool -XkbSetMap(Display *dpy,unsigned which,XkbDescPtr xkb) +XkbSetMap(Display *dpy, unsigned which, XkbDescPtr xkb) { -register xkbSetMapReq * req; -XkbInfoPtr xkbi; -XkbServerMapPtr srv; -XkbClientMapPtr map; + register xkbSetMapReq *req; + XkbInfoPtr xkbi; + XkbServerMapPtr srv; + XkbClientMapPtr map; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))|| - (!xkb)) - return False; - map= xkb->map; - srv= xkb->server; - - if (((which&XkbKeyTypesMask)&&((!map)||(!map->types)))|| - ((which&XkbKeySymsMask)&&((!map)||(!map->syms)||(!map->key_sym_map)))|| - ((which&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))|| - ((which&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))|| - ((which&XkbVirtualModsMask)&&(!srv))|| - ((which&XkbExplicitComponentsMask)&&((!srv)||(!srv->explicit)))|| - ((which&XkbModifierMapMask)&&((!map)||(!map->modmap)))|| - ((which&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap)))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || (!xkb)) + return False; + map = xkb->map; + srv = xkb->server; + + if (((which & XkbKeyTypesMask) && ((!map) || (!map->types))) || + ((which & XkbKeySymsMask) && + ((!map) || (!map->syms) || (!map->key_sym_map))) || + ((which & XkbKeyActionsMask) && ((!srv) || (!srv->key_acts))) || + ((which & XkbKeyBehaviorsMask) && ((!srv) || (!srv->behaviors))) || + ((which & XkbVirtualModsMask) && (!srv)) || + ((which & XkbExplicitComponentsMask) && ((!srv) || (!srv->explicit))) || + ((which & XkbModifierMapMask) && ((!map) || (!map->modmap))) || + ((which & XkbVirtualModMapMask) && ((!srv) || (!srv->vmodmap)))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; @@ -494,69 +498,73 @@ XkbClientMapPtr map; req->deviceSpec = xkb->device_spec; req->present = which; req->flags = XkbSetMapAllFlags; - req->minKeyCode= xkb->min_key_code; - req->maxKeyCode= xkb->max_key_code; + req->minKeyCode = xkb->min_key_code; + req->maxKeyCode = xkb->max_key_code; req->firstType = 0; - if (which&XkbKeyTypesMask) req->nTypes = map->num_types; - else req->nTypes = 0; - if (which&XkbKeySymsMask) { - req->firstKeySym = xkb->min_key_code; - req->nKeySyms = XkbNumKeys(xkb); + if (which & XkbKeyTypesMask) + req->nTypes = map->num_types; + else + req->nTypes = 0; + if (which & XkbKeySymsMask) { + req->firstKeySym = xkb->min_key_code; + req->nKeySyms = XkbNumKeys(xkb); } - if (which&XkbKeyActionsMask) { - req->firstKeyAct = xkb->min_key_code; - req->nKeyActs = XkbNumKeys(xkb); + if (which & XkbKeyActionsMask) { + req->firstKeyAct = xkb->min_key_code; + req->nKeyActs = XkbNumKeys(xkb); } - if (which&XkbKeyBehaviorsMask) { - req->firstKeyBehavior = xkb->min_key_code; - req->nKeyBehaviors = XkbNumKeys(xkb); + if (which & XkbKeyBehaviorsMask) { + req->firstKeyBehavior = xkb->min_key_code; + req->nKeyBehaviors = XkbNumKeys(xkb); } - if (which&XkbVirtualModsMask) - req->virtualMods= ~0; - if (which&XkbExplicitComponentsMask) { - req->firstKeyExplicit= xkb->min_key_code; - req->nKeyExplicit = XkbNumKeys(xkb); + if (which & XkbVirtualModsMask) + req->virtualMods = ~0; + if (which & XkbExplicitComponentsMask) { + req->firstKeyExplicit = xkb->min_key_code; + req->nKeyExplicit = XkbNumKeys(xkb); } - if (which&XkbModifierMapMask) { - req->firstModMapKey= xkb->min_key_code; - req->nModMapKeys = XkbNumKeys(xkb); + if (which & XkbModifierMapMask) { + req->firstModMapKey = xkb->min_key_code; + req->nModMapKeys = XkbNumKeys(xkb); } - if (which&XkbVirtualModMapMask) { - req->firstVModMapKey= xkb->min_key_code; - req->nVModMapKeys = XkbNumKeys(xkb); + if (which & XkbVirtualModMapMask) { + req->firstVModMapKey = xkb->min_key_code; + req->nVModMapKeys = XkbNumKeys(xkb); } - SendSetMap(dpy,xkb,req); + SendSetMap(dpy, xkb, req); UnlockDisplay(dpy); SyncHandle(); return True; } Bool -XkbChangeMap(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes) +XkbChangeMap(Display *dpy, XkbDescPtr xkb, XkbMapChangesPtr changes) { -register xkbSetMapReq * req; -XkbInfoPtr xkbi; -XkbServerMapPtr srv; -XkbClientMapPtr map; + register xkbSetMapReq *req; + XkbInfoPtr xkbi; + XkbServerMapPtr srv; + XkbClientMapPtr map; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))|| - (!xkb)||(!changes)) - return False; - srv= xkb->server; - map= xkb->map; - - if (((changes->changed&XkbKeyTypesMask)&&((!map)||(!map->types)))|| - ((changes->changed&XkbKeySymsMask)&&((!map)||(!map->syms)|| - (!map->key_sym_map)))|| - ((changes->changed&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))|| - ((changes->changed&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))|| - ((changes->changed&XkbVirtualModsMask)&&(!srv))|| - ((changes->changed&XkbExplicitComponentsMask)&& - ((!srv)||(!srv->explicit)))|| - ((changes->changed&XkbModifierMapMask)&&((!map)||(!map->modmap)))|| - ((changes->changed&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap)))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || + (!xkb) || (!changes)) + return False; + srv = xkb->server; + map = xkb->map; + + if (((changes->changed & XkbKeyTypesMask) && ((!map) || (!map->types))) || + ((changes->changed & XkbKeySymsMask) && ((!map) || (!map->syms) || + (!map->key_sym_map))) || + ((changes->changed & XkbKeyActionsMask) && ((!srv) || (!srv->key_acts))) + || ((changes->changed & XkbKeyBehaviorsMask) && + ((!srv) || (!srv->behaviors))) || + ((changes->changed & XkbVirtualModsMask) && (!srv)) || + ((changes->changed & XkbExplicitComponentsMask) && + ((!srv) || (!srv->explicit))) || + ((changes->changed & XkbModifierMapMask) && ((!map) || (!map->modmap))) + || ((changes->changed & XkbVirtualModMapMask) && + ((!srv) || (!srv->vmodmap)))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; @@ -566,8 +574,8 @@ XkbClientMapPtr map; req->deviceSpec = xkb->device_spec; req->present = changes->changed; req->flags = XkbSetMapRecomputeActions; - req->minKeyCode= xkb->min_key_code; - req->maxKeyCode= xkb->max_key_code; + req->minKeyCode = xkb->min_key_code; + req->maxKeyCode = xkb->max_key_code; req->firstType = changes->first_type; req->nTypes = changes->num_types; req->firstKeySym = changes->first_key_sym; @@ -583,9 +591,8 @@ XkbClientMapPtr map; req->nModMapKeys = changes->num_modmap_keys; req->firstVModMapKey = changes->first_vmodmap_key; req->nVModMapKeys = changes->num_vmodmap_keys; - SendSetMap(dpy,xkb,req); + SendSetMap(dpy, xkb, req); UnlockDisplay(dpy); SyncHandle(); return True; } - diff --git a/libX11/src/xkb/XKBUse.c b/libX11/src/xkb/XKBUse.c index ec2e08d54..b0a031812 100644 --- a/libX11/src/xkb/XKBUse.c +++ b/libX11/src/xkb/XKBUse.c @@ -61,558 +61,552 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <X11/extensions/XKBproto.h> #include "XKBlibint.h" -static Bool _XkbIgnoreExtension = False; +static Bool _XkbIgnoreExtension = False; void -XkbNoteMapChanges(XkbMapChangesPtr old,XkbMapNotifyEvent *new,unsigned wanted) +XkbNoteMapChanges(XkbMapChangesPtr old, + XkbMapNotifyEvent *new, + unsigned wanted) { - int first,oldLast,newLast; - wanted&= new->changed; - - if (wanted&XkbKeyTypesMask) { - if (old->changed&XkbKeyTypesMask) { - first = old->first_type; - oldLast = old->first_type+old->num_types-1; - newLast = new->first_type+new->num_types-1; - - if (new->first_type<first) - first = new->first_type; - if (oldLast>newLast) - newLast= oldLast; - old->first_type = first; - old->num_types = newLast-first+1; - } - else { - old->first_type= new->first_type; - old->num_types = new->num_types; - } - } - if (wanted&XkbKeySymsMask) { - if (old->changed&XkbKeySymsMask) { - first = old->first_key_sym; - oldLast = old->first_key_sym+old->num_key_syms-1; - newLast = new->first_key_sym+new->num_key_syms-1; - - if (new->first_key_sym<first) - first = new->first_key_sym; - if (oldLast>newLast) - newLast= oldLast; - old->first_key_sym = first; - old->num_key_syms = newLast-first+1; - } - else { - old->first_key_sym = new->first_key_sym; - old->num_key_syms = new->num_key_syms; - } - } - if (wanted&XkbKeyActionsMask) { - if (old->changed&XkbKeyActionsMask) { - first = old->first_key_act; - oldLast = old->first_key_act+old->num_key_acts-1; - newLast = new->first_key_act+new->num_key_acts-1; - - if (new->first_key_act<first) - first = new->first_key_act; - if (oldLast>newLast) - newLast= oldLast; - old->first_key_act = first; - old->num_key_acts = newLast-first+1; - } - else { - old->first_key_act = new->first_key_act; - old->num_key_acts = new->num_key_acts; - } - } - if (wanted&XkbKeyBehaviorsMask) { - if (old->changed&XkbKeyBehaviorsMask) { - first = old->first_key_behavior; - oldLast = old->first_key_behavior+old->num_key_behaviors-1; - newLast = new->first_key_behavior+new->num_key_behaviors-1; - - if (new->first_key_behavior<first) - first = new->first_key_behavior; - if (oldLast>newLast) - newLast= oldLast; - old->first_key_behavior = first; - old->num_key_behaviors = newLast-first+1; - } - else { - old->first_key_behavior = new->first_key_behavior; - old->num_key_behaviors = new->num_key_behaviors; - } - } - if (wanted&XkbVirtualModsMask) { - old->vmods|= new->vmods; - } - if (wanted&XkbExplicitComponentsMask) { - if (old->changed&XkbExplicitComponentsMask) { - first = old->first_key_explicit; - oldLast = old->first_key_explicit+old->num_key_explicit-1; - newLast = new->first_key_explicit+new->num_key_explicit-1; - - if (new->first_key_explicit<first) - first = new->first_key_explicit; - if (oldLast>newLast) - newLast= oldLast; - old->first_key_explicit = first; - old->num_key_explicit = newLast-first+1; - } - else { - old->first_key_explicit = new->first_key_explicit; - old->num_key_explicit = new->num_key_explicit; - } - } - if (wanted&XkbModifierMapMask) { - if (old->changed&XkbModifierMapMask) { - first = old->first_modmap_key; - oldLast = old->first_modmap_key+old->num_modmap_keys-1; - newLast = new->first_modmap_key+new->num_modmap_keys-1; - - if (new->first_modmap_key<first) - first = new->first_modmap_key; - if (oldLast>newLast) - newLast= oldLast; - old->first_modmap_key = first; - old->num_modmap_keys = newLast-first+1; - } - else { - old->first_modmap_key = new->first_modmap_key; - old->num_modmap_keys = new->num_modmap_keys; - } - } - if (wanted&XkbVirtualModMapMask) { - if (old->changed&XkbVirtualModMapMask) { - first = old->first_vmodmap_key; - oldLast = old->first_vmodmap_key+old->num_vmodmap_keys-1; - newLast = new->first_vmodmap_key+new->num_vmodmap_keys-1; - - if (new->first_vmodmap_key<first) - first = new->first_vmodmap_key; - if (oldLast>newLast) - newLast= oldLast; - old->first_vmodmap_key = first; - old->num_vmodmap_keys = newLast-first+1; - } - else { - old->first_vmodmap_key = new->first_vmodmap_key; - old->num_vmodmap_keys = new->num_vmodmap_keys; - } - } - old->changed|= wanted; + int first, oldLast, newLast; + + wanted &= new->changed; + + if (wanted & XkbKeyTypesMask) { + if (old->changed & XkbKeyTypesMask) { + first = old->first_type; + oldLast = old->first_type + old->num_types - 1; + newLast = new->first_type + new->num_types - 1; + + if (new->first_type < first) + first = new->first_type; + if (oldLast > newLast) + newLast = oldLast; + old->first_type = first; + old->num_types = newLast - first + 1; + } + else { + old->first_type = new->first_type; + old->num_types = new->num_types; + } + } + if (wanted & XkbKeySymsMask) { + if (old->changed & XkbKeySymsMask) { + first = old->first_key_sym; + oldLast = old->first_key_sym + old->num_key_syms - 1; + newLast = new->first_key_sym + new->num_key_syms - 1; + + if (new->first_key_sym < first) + first = new->first_key_sym; + if (oldLast > newLast) + newLast = oldLast; + old->first_key_sym = first; + old->num_key_syms = newLast - first + 1; + } + else { + old->first_key_sym = new->first_key_sym; + old->num_key_syms = new->num_key_syms; + } + } + if (wanted & XkbKeyActionsMask) { + if (old->changed & XkbKeyActionsMask) { + first = old->first_key_act; + oldLast = old->first_key_act + old->num_key_acts - 1; + newLast = new->first_key_act + new->num_key_acts - 1; + + if (new->first_key_act < first) + first = new->first_key_act; + if (oldLast > newLast) + newLast = oldLast; + old->first_key_act = first; + old->num_key_acts = newLast - first + 1; + } + else { + old->first_key_act = new->first_key_act; + old->num_key_acts = new->num_key_acts; + } + } + if (wanted & XkbKeyBehaviorsMask) { + if (old->changed & XkbKeyBehaviorsMask) { + first = old->first_key_behavior; + oldLast = old->first_key_behavior + old->num_key_behaviors - 1; + newLast = new->first_key_behavior + new->num_key_behaviors - 1; + + if (new->first_key_behavior < first) + first = new->first_key_behavior; + if (oldLast > newLast) + newLast = oldLast; + old->first_key_behavior = first; + old->num_key_behaviors = newLast - first + 1; + } + else { + old->first_key_behavior = new->first_key_behavior; + old->num_key_behaviors = new->num_key_behaviors; + } + } + if (wanted & XkbVirtualModsMask) { + old->vmods |= new->vmods; + } + if (wanted & XkbExplicitComponentsMask) { + if (old->changed & XkbExplicitComponentsMask) { + first = old->first_key_explicit; + oldLast = old->first_key_explicit + old->num_key_explicit - 1; + newLast = new->first_key_explicit + new->num_key_explicit - 1; + + if (new->first_key_explicit < first) + first = new->first_key_explicit; + if (oldLast > newLast) + newLast = oldLast; + old->first_key_explicit = first; + old->num_key_explicit = newLast - first + 1; + } + else { + old->first_key_explicit = new->first_key_explicit; + old->num_key_explicit = new->num_key_explicit; + } + } + if (wanted & XkbModifierMapMask) { + if (old->changed & XkbModifierMapMask) { + first = old->first_modmap_key; + oldLast = old->first_modmap_key + old->num_modmap_keys - 1; + newLast = new->first_modmap_key + new->num_modmap_keys - 1; + + if (new->first_modmap_key < first) + first = new->first_modmap_key; + if (oldLast > newLast) + newLast = oldLast; + old->first_modmap_key = first; + old->num_modmap_keys = newLast - first + 1; + } + else { + old->first_modmap_key = new->first_modmap_key; + old->num_modmap_keys = new->num_modmap_keys; + } + } + if (wanted & XkbVirtualModMapMask) { + if (old->changed & XkbVirtualModMapMask) { + first = old->first_vmodmap_key; + oldLast = old->first_vmodmap_key + old->num_vmodmap_keys - 1; + newLast = new->first_vmodmap_key + new->num_vmodmap_keys - 1; + + if (new->first_vmodmap_key < first) + first = new->first_vmodmap_key; + if (oldLast > newLast) + newLast = oldLast; + old->first_vmodmap_key = first; + old->num_vmodmap_keys = newLast - first + 1; + } + else { + old->first_vmodmap_key = new->first_vmodmap_key; + old->num_vmodmap_keys = new->num_vmodmap_keys; + } + } + old->changed |= wanted; return; } void -_XkbNoteCoreMapChanges( XkbMapChangesPtr old, - XMappingEvent * new, - unsigned int wanted) +_XkbNoteCoreMapChanges(XkbMapChangesPtr old, + XMappingEvent *new, + unsigned int wanted) { - int first,oldLast,newLast; - - if ((new->request==MappingKeyboard)&&(wanted&XkbKeySymsMask)) { - if (old->changed&XkbKeySymsMask) { - first = old->first_key_sym; - oldLast = old->first_key_sym+old->num_key_syms-1; - newLast = new->first_keycode+new->count-1; - - if (new->first_keycode<first) - first = new->first_keycode; - if (oldLast>newLast) - newLast= oldLast; - old->first_key_sym = first; - old->num_key_syms = newLast-first+1; - } - else { - old->changed|= XkbKeySymsMask; - old->first_key_sym = new->first_keycode; - old->num_key_syms = new->count; - } + int first, oldLast, newLast; + + if ((new->request == MappingKeyboard) && (wanted & XkbKeySymsMask)) { + if (old->changed & XkbKeySymsMask) { + first = old->first_key_sym; + oldLast = old->first_key_sym + old->num_key_syms - 1; + newLast = new->first_keycode + new->count - 1; + + if (new->first_keycode < first) + first = new->first_keycode; + if (oldLast > newLast) + newLast = oldLast; + old->first_key_sym = first; + old->num_key_syms = newLast - first + 1; + } + else { + old->changed |= XkbKeySymsMask; + old->first_key_sym = new->first_keycode; + old->num_key_syms = new->count; + } } return; } static Bool -wire_to_event(Display *dpy,XEvent *re,xEvent *event) +wire_to_event(Display *dpy, XEvent *re, xEvent *event) { - xkbEvent *xkbevent= (xkbEvent *)event; + xkbEvent *xkbevent = (xkbEvent *) event; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; xkbi = dpy->xkb_info; - if (((event->u.u.type&0x7f)-xkbi->codes->first_event)!=XkbEventCode) - return False; + if (((event->u.u.type & 0x7f) - xkbi->codes->first_event) != XkbEventCode) + return False; switch (xkbevent->u.any.xkbType) { - case XkbStateNotify: - { - xkbStateNotify *sn = (xkbStateNotify *)event; - if ( xkbi->selected_events&XkbStateNotifyMask ) { - XkbStateNotifyEvent *sev=(XkbStateNotifyEvent *)re; - sev->type = XkbEventCode+xkbi->codes->first_event; - sev->xkb_type = XkbStateNotify; - sev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - sev->send_event = ((event->u.u.type & 0x80) != 0); - sev->display = dpy; - sev->time = sn->time; - sev->device = sn->deviceID; - sev->keycode = sn->keycode; - sev->event_type = sn->eventType; - sev->req_major = sn->requestMajor; - sev->req_minor = sn->requestMinor; - sev->changed = sn->changed; - sev->group = sn->group; - sev->base_group = sn->baseGroup; - sev->latched_group = sn->latchedGroup; - sev->locked_group = sn->lockedGroup; - sev->mods = sn->mods; - sev->base_mods = sn->baseMods; - sev->latched_mods = sn->latchedMods; - sev->locked_mods = sn->lockedMods; - sev->compat_state = sn->compatState; - sev->grab_mods = sn->grabMods; - sev->compat_grab_mods = sn->compatGrabMods; - sev->lookup_mods = sn->lookupMods; - sev->compat_lookup_mods = sn->compatLookupMods; - sev->ptr_buttons = sn->ptrBtnState; - return True; - } - } - break; - case XkbMapNotify: - { - xkbMapNotify *mn = (xkbMapNotify *)event; - if ((xkbi->selected_events&XkbMapNotifyMask)&& - (xkbi->selected_map_details&mn->changed)) { - XkbMapNotifyEvent *mev; - mev =(XkbMapNotifyEvent *)re; - mev->type = XkbEventCode+xkbi->codes->first_event; - mev->xkb_type = XkbMapNotify; - mev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - mev->send_event = ((event->u.u.type&0x80)!=0); - mev->display = dpy; - mev->time = mn->time; - mev->device = mn->deviceID; - mev->changed = mn->changed; - mev->min_key_code = mn->minKeyCode; - mev->max_key_code = mn->maxKeyCode; - mev->first_type = mn->firstType; - mev->num_types = mn->nTypes; - mev->first_key_sym = mn->firstKeySym; - mev->num_key_syms = mn->nKeySyms; - mev->first_key_act = mn->firstKeyAct; - mev->num_key_acts = mn->nKeyActs; - mev->first_key_behavior = mn->firstKeyBehavior; - mev->num_key_behaviors = mn->nKeyBehaviors; - mev->vmods = mn->virtualMods; - mev->first_key_explicit = mn->firstKeyExplicit; - mev->num_key_explicit = mn->nKeyExplicit; - mev->first_modmap_key = mn->firstModMapKey; - mev->num_modmap_keys = mn->nModMapKeys; - mev->first_vmodmap_key = mn->firstVModMapKey; - mev->num_vmodmap_keys = mn->nVModMapKeys; - XkbNoteMapChanges(&xkbi->changes,mev,XKB_XLIB_MAP_MASK); - if (xkbi->changes.changed) - xkbi->flags|= XkbMapPending; - return True; - } - else if (mn->nKeySyms>0) { - register XMappingEvent *ev = (XMappingEvent *)re; - ev->type = MappingNotify; - ev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - ev->send_event = ((event->u.u.type&0x80)!=0); - ev->display = dpy; - ev->window = 0; - ev->first_keycode = mn->firstKeySym; - ev->request = MappingKeyboard; - ev->count = mn->nKeySyms; - _XkbNoteCoreMapChanges(&xkbi->changes,ev,XKB_XLIB_MAP_MASK); - if (xkbi->changes.changed) - xkbi->flags|= XkbMapPending; - return True; - } - } - break; - case XkbControlsNotify: - { - if (xkbi->selected_events&XkbControlsNotifyMask) { - xkbControlsNotify *cn =(xkbControlsNotify *)event; - XkbControlsNotifyEvent *cev; - cev =(XkbControlsNotifyEvent *)re; - cev->type = XkbEventCode+xkbi->codes->first_event; - cev->xkb_type = XkbControlsNotify; - cev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - cev->send_event = ((event->u.u.type&0x80)!=0); - cev->display = dpy; - cev->time = cn->time; - cev->device = cn->deviceID; - cev->changed_ctrls = cn->changedControls; - cev->enabled_ctrls = cn->enabledControls; - cev->enabled_ctrl_changes = cn->enabledControlChanges; - cev->keycode = cn->keycode; - cev->num_groups = cn->numGroups; - cev->event_type = cn->eventType; - cev->req_major = cn->requestMajor; - cev->req_minor = cn->requestMinor; - return True; - } - } - break; - case XkbIndicatorMapNotify: - { - if (xkbi->selected_events&XkbIndicatorMapNotifyMask) { - xkbIndicatorNotify *in =(xkbIndicatorNotify *)event; - XkbIndicatorNotifyEvent *iev; - iev =(XkbIndicatorNotifyEvent *)re; - iev->type = XkbEventCode+xkbi->codes->first_event; - iev->xkb_type = XkbIndicatorMapNotify; - iev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - iev->send_event = ((event->u.u.type&0x80)!=0); - iev->display = dpy; - iev->time = in->time; - iev->device = in->deviceID; - iev->changed = in->changed; - iev->state= in->state; - return True; - } - } - break; - case XkbIndicatorStateNotify: - { - if (xkbi->selected_events&XkbIndicatorStateNotifyMask) { - xkbIndicatorNotify *in =(xkbIndicatorNotify *)event; - XkbIndicatorNotifyEvent *iev; - iev =(XkbIndicatorNotifyEvent *)re; - iev->type = XkbEventCode+xkbi->codes->first_event; - iev->xkb_type = XkbIndicatorStateNotify; - iev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - iev->send_event = ((event->u.u.type&0x80)!=0); - iev->display = dpy; - iev->time = in->time; - iev->device = in->deviceID; - iev->changed = in->changed; - iev->state= in->state; - return True; - } - } - break; - case XkbBellNotify: - { - if (xkbi->selected_events&XkbBellNotifyMask) { - xkbBellNotify *bn =(xkbBellNotify *)event; - XkbBellNotifyEvent *bev; - bev =(XkbBellNotifyEvent *)re; - bev->type = XkbEventCode+xkbi->codes->first_event; - bev->xkb_type = XkbBellNotify; - bev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - bev->send_event = ((event->u.u.type&0x80)!=0); - bev->display = dpy; - bev->time = bn->time; - bev->device = bn->deviceID; - bev->percent = bn->percent; - bev->pitch = bn->pitch; - bev->duration = bn->duration; - bev->bell_class = bn->bellClass; - bev->bell_id = bn->bellID; - bev->name = bn->name; - bev->window = bn->window; - bev->event_only = bn->eventOnly; - return True; - } - } - break; - case XkbAccessXNotify: - { - if (xkbi->selected_events&XkbAccessXNotifyMask) { - xkbAccessXNotify *axn =(xkbAccessXNotify *)event; - XkbAccessXNotifyEvent *axev; - axev =(XkbAccessXNotifyEvent *)re; - axev->type = XkbEventCode+xkbi->codes->first_event; - axev->xkb_type = XkbAccessXNotify; - axev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - axev->send_event = ((event->u.u.type&0x80)!=0); - axev->display = dpy; - axev->time = axn->time; - axev->device = axn->deviceID; - axev->detail = axn->detail; - axev->keycode = axn->keycode; - axev->sk_delay = axn->slowKeysDelay; - axev->debounce_delay = axn->debounceDelay; - return True; - } - } - break; - case XkbNamesNotify: - { - if (xkbi->selected_events&XkbNamesNotifyMask) { - xkbNamesNotify *nn =(xkbNamesNotify *)event; - XkbNamesNotifyEvent *nev; - nev =(XkbNamesNotifyEvent *)re; - nev->type = XkbEventCode+xkbi->codes->first_event; - nev->xkb_type = XkbNamesNotify; - nev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - nev->send_event = ((event->u.u.type&0x80)!=0); - nev->display = dpy; - nev->time = nn->time; - nev->device = nn->deviceID; - nev->changed = nn->changed; - nev->first_type = nn->firstType; - nev->num_types = nn->nTypes; - nev->first_lvl = nn->firstLevelName; - nev->num_lvls = nn->nLevelNames; - nev->num_aliases = nn->nAliases; - nev->num_radio_groups = nn->nRadioGroups; - nev->changed_vmods = nn->changedVirtualMods; - nev->changed_groups = nn->changedGroupNames; - nev->changed_indicators = nn->changedIndicators; - nev->first_key = nn->firstKey; - nev->num_keys = nn->nKeys; - return True; - } - } - break; - case XkbCompatMapNotify: - { - if (xkbi->selected_events&XkbCompatMapNotifyMask) { - xkbCompatMapNotify *cmn =(xkbCompatMapNotify *)event; - XkbCompatMapNotifyEvent *cmev; - cmev =(XkbCompatMapNotifyEvent *)re; - cmev->type = XkbEventCode+xkbi->codes->first_event; - cmev->xkb_type = XkbCompatMapNotify; - cmev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - cmev->send_event = ((event->u.u.type&0x80)!=0); - cmev->display = dpy; - cmev->time = cmn->time; - cmev->device = cmn->deviceID; - cmev->changed_groups = cmn->changedGroups; - cmev->first_si = cmn->firstSI; - cmev->num_si = cmn->nSI; - cmev->num_total_si = cmn->nTotalSI; - return True; - } - } - break; - case XkbActionMessage: - { - if (xkbi->selected_events&XkbActionMessageMask) { - xkbActionMessage *am= (xkbActionMessage *)event; - XkbActionMessageEvent *amev; - amev= (XkbActionMessageEvent *)re; - amev->type = XkbEventCode+xkbi->codes->first_event; - amev->xkb_type = XkbActionMessage; - amev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - amev->send_event = ((event->u.u.type&0x80)!=0); - amev->display = dpy; - amev->time = am->time; - amev->device = am->deviceID; - amev->keycode = am->keycode; - amev->press = am->press; - amev->key_event_follows = am->keyEventFollows; - amev->group = am->group; - amev->mods = am->mods; - memcpy(amev->message,am->message,XkbActionMessageLength); - amev->message[XkbActionMessageLength]= '\0'; - return True; - } - } - break; - case XkbExtensionDeviceNotify: - { - if (xkbi->selected_events&XkbExtensionDeviceNotifyMask) { - xkbExtensionDeviceNotify *ed= - (xkbExtensionDeviceNotify *)event; - XkbExtensionDeviceNotifyEvent *edev; - edev= (XkbExtensionDeviceNotifyEvent *)re; - edev->type= XkbEventCode+xkbi->codes->first_event; - edev->xkb_type= XkbExtensionDeviceNotify; - edev->serial= _XSetLastRequestRead(dpy, - (xGenericReply *)event); - edev->send_event= ((event->u.u.type&0x80)!=0); - edev->display= dpy; - edev->time= ed->time; - edev->device= ed->deviceID; - edev->led_class= ed->ledClass; - edev->led_id= ed->ledID; - edev->reason= ed->reason; - edev->supported= ed->supported; - edev->leds_defined= ed->ledsDefined; - edev->led_state= ed->ledState; - edev->first_btn= ed->firstBtn; - edev->num_btns= ed->nBtns; - edev->unsupported= ed->unsupported; - return True; - } - } - break; - case XkbNewKeyboardNotify: - { - xkbNewKeyboardNotify *nkn = (xkbNewKeyboardNotify *)event; - if ((xkbi->selected_events&XkbNewKeyboardNotifyMask)&& - (xkbi->selected_nkn_details&nkn->changed)) { - XkbNewKeyboardNotifyEvent *nkev; - nkev =(XkbNewKeyboardNotifyEvent *)re; - nkev->type = XkbEventCode+xkbi->codes->first_event; - nkev->xkb_type = XkbNewKeyboardNotify; - nkev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - nkev->send_event = ((event->u.u.type&0x80)!=0); - nkev->display = dpy; - nkev->time = nkn->time; - nkev->device = nkn->deviceID; - nkev->old_device = nkn->oldDeviceID; - nkev->min_key_code = nkn->minKeyCode; - nkev->max_key_code = nkn->maxKeyCode; - nkev->old_min_key_code = nkn->oldMinKeyCode; - nkev->old_max_key_code = nkn->oldMaxKeyCode; - nkev->req_major = nkn->requestMajor; - nkev->req_minor = nkn->requestMinor; - nkev->changed = nkn->changed; - if ((xkbi->desc)&&(nkev->send_event==0)&& - ((xkbi->desc->device_spec==nkev->old_device)|| - (nkev->device!=nkev->old_device))) { - xkbi->flags= XkbMapPending|XkbXlibNewKeyboard; - } - return True; - } - else if(nkn->changed&(XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask)){ - register XMappingEvent *ev = (XMappingEvent *)re; - ev->type = MappingNotify; - ev->serial = _XSetLastRequestRead(dpy, - (xGenericReply *)event); - ev->send_event = ((event->u.u.type&0x80)!=0); - ev->display = dpy; - ev->window = 0; - ev->first_keycode = dpy->min_keycode; - ev->request = MappingKeyboard; - ev->count = (dpy->max_keycode-dpy->min_keycode)+1; - if ((xkbi->desc)&&(ev->send_event==0)&& - ((xkbi->desc->device_spec==nkn->oldDeviceID)|| - (nkn->deviceID!=nkn->oldDeviceID))) { - xkbi->flags|= XkbMapPending|XkbXlibNewKeyboard; - } - return True; - } - } - break; - default: + case XkbStateNotify: + { + xkbStateNotify *sn = (xkbStateNotify *) event; + + if (xkbi->selected_events & XkbStateNotifyMask) { + XkbStateNotifyEvent *sev = (XkbStateNotifyEvent *) re; + + sev->type = XkbEventCode + xkbi->codes->first_event; + sev->xkb_type = XkbStateNotify; + sev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + sev->send_event = ((event->u.u.type & 0x80) != 0); + sev->display = dpy; + sev->time = sn->time; + sev->device = sn->deviceID; + sev->keycode = sn->keycode; + sev->event_type = sn->eventType; + sev->req_major = sn->requestMajor; + sev->req_minor = sn->requestMinor; + sev->changed = sn->changed; + sev->group = sn->group; + sev->base_group = sn->baseGroup; + sev->latched_group = sn->latchedGroup; + sev->locked_group = sn->lockedGroup; + sev->mods = sn->mods; + sev->base_mods = sn->baseMods; + sev->latched_mods = sn->latchedMods; + sev->locked_mods = sn->lockedMods; + sev->compat_state = sn->compatState; + sev->grab_mods = sn->grabMods; + sev->compat_grab_mods = sn->compatGrabMods; + sev->lookup_mods = sn->lookupMods; + sev->compat_lookup_mods = sn->compatLookupMods; + sev->ptr_buttons = sn->ptrBtnState; + return True; + } + } + break; + case XkbMapNotify: + { + xkbMapNotify *mn = (xkbMapNotify *) event; + + if ((xkbi->selected_events & XkbMapNotifyMask) && + (xkbi->selected_map_details & mn->changed)) { + XkbMapNotifyEvent *mev = (XkbMapNotifyEvent *) re; + + mev->type = XkbEventCode + xkbi->codes->first_event; + mev->xkb_type = XkbMapNotify; + mev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + mev->send_event = ((event->u.u.type & 0x80) != 0); + mev->display = dpy; + mev->time = mn->time; + mev->device = mn->deviceID; + mev->changed = mn->changed; + mev->min_key_code = mn->minKeyCode; + mev->max_key_code = mn->maxKeyCode; + mev->first_type = mn->firstType; + mev->num_types = mn->nTypes; + mev->first_key_sym = mn->firstKeySym; + mev->num_key_syms = mn->nKeySyms; + mev->first_key_act = mn->firstKeyAct; + mev->num_key_acts = mn->nKeyActs; + mev->first_key_behavior = mn->firstKeyBehavior; + mev->num_key_behaviors = mn->nKeyBehaviors; + mev->vmods = mn->virtualMods; + mev->first_key_explicit = mn->firstKeyExplicit; + mev->num_key_explicit = mn->nKeyExplicit; + mev->first_modmap_key = mn->firstModMapKey; + mev->num_modmap_keys = mn->nModMapKeys; + mev->first_vmodmap_key = mn->firstVModMapKey; + mev->num_vmodmap_keys = mn->nVModMapKeys; + XkbNoteMapChanges(&xkbi->changes, mev, XKB_XLIB_MAP_MASK); + if (xkbi->changes.changed) + xkbi->flags |= XkbMapPending; + return True; + } + else if (mn->nKeySyms > 0) { + register XMappingEvent *ev = (XMappingEvent *) re; + + ev->type = MappingNotify; + ev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + ev->send_event = ((event->u.u.type & 0x80) != 0); + ev->display = dpy; + ev->window = 0; + ev->first_keycode = mn->firstKeySym; + ev->request = MappingKeyboard; + ev->count = mn->nKeySyms; + _XkbNoteCoreMapChanges(&xkbi->changes, ev, XKB_XLIB_MAP_MASK); + if (xkbi->changes.changed) + xkbi->flags |= XkbMapPending; + return True; + } + } + break; + case XkbControlsNotify: + { + if (xkbi->selected_events & XkbControlsNotifyMask) { + xkbControlsNotify *cn = (xkbControlsNotify *) event; + XkbControlsNotifyEvent *cev = (XkbControlsNotifyEvent *) re; + + cev->type = XkbEventCode + xkbi->codes->first_event; + cev->xkb_type = XkbControlsNotify; + cev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + cev->send_event = ((event->u.u.type & 0x80) != 0); + cev->display = dpy; + cev->time = cn->time; + cev->device = cn->deviceID; + cev->changed_ctrls = cn->changedControls; + cev->enabled_ctrls = cn->enabledControls; + cev->enabled_ctrl_changes = cn->enabledControlChanges; + cev->keycode = cn->keycode; + cev->num_groups = cn->numGroups; + cev->event_type = cn->eventType; + cev->req_major = cn->requestMajor; + cev->req_minor = cn->requestMinor; + return True; + } + } + break; + case XkbIndicatorMapNotify: + { + if (xkbi->selected_events & XkbIndicatorMapNotifyMask) { + xkbIndicatorNotify *in = (xkbIndicatorNotify *) event; + XkbIndicatorNotifyEvent *iev = (XkbIndicatorNotifyEvent *) re; + + iev->type = XkbEventCode + xkbi->codes->first_event; + iev->xkb_type = XkbIndicatorMapNotify; + iev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + iev->send_event = ((event->u.u.type & 0x80) != 0); + iev->display = dpy; + iev->time = in->time; + iev->device = in->deviceID; + iev->changed = in->changed; + iev->state = in->state; + return True; + } + } + break; + case XkbIndicatorStateNotify: + { + if (xkbi->selected_events & XkbIndicatorStateNotifyMask) { + xkbIndicatorNotify *in = (xkbIndicatorNotify *) event; + XkbIndicatorNotifyEvent *iev = (XkbIndicatorNotifyEvent *) re; + + iev->type = XkbEventCode + xkbi->codes->first_event; + iev->xkb_type = XkbIndicatorStateNotify; + iev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + iev->send_event = ((event->u.u.type & 0x80) != 0); + iev->display = dpy; + iev->time = in->time; + iev->device = in->deviceID; + iev->changed = in->changed; + iev->state = in->state; + return True; + } + } + break; + case XkbBellNotify: + { + if (xkbi->selected_events & XkbBellNotifyMask) { + xkbBellNotify *bn = (xkbBellNotify *) event; + XkbBellNotifyEvent *bev = (XkbBellNotifyEvent *) re; + + bev->type = XkbEventCode + xkbi->codes->first_event; + bev->xkb_type = XkbBellNotify; + bev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + bev->send_event = ((event->u.u.type & 0x80) != 0); + bev->display = dpy; + bev->time = bn->time; + bev->device = bn->deviceID; + bev->percent = bn->percent; + bev->pitch = bn->pitch; + bev->duration = bn->duration; + bev->bell_class = bn->bellClass; + bev->bell_id = bn->bellID; + bev->name = bn->name; + bev->window = bn->window; + bev->event_only = bn->eventOnly; + return True; + } + } + break; + case XkbAccessXNotify: + { + if (xkbi->selected_events & XkbAccessXNotifyMask) { + xkbAccessXNotify *axn = (xkbAccessXNotify *) event; + XkbAccessXNotifyEvent *axev = (XkbAccessXNotifyEvent *) re; + + axev->type = XkbEventCode + xkbi->codes->first_event; + axev->xkb_type = XkbAccessXNotify; + axev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + axev->send_event = ((event->u.u.type & 0x80) != 0); + axev->display = dpy; + axev->time = axn->time; + axev->device = axn->deviceID; + axev->detail = axn->detail; + axev->keycode = axn->keycode; + axev->sk_delay = axn->slowKeysDelay; + axev->debounce_delay = axn->debounceDelay; + return True; + } + } + break; + case XkbNamesNotify: + { + if (xkbi->selected_events & XkbNamesNotifyMask) { + xkbNamesNotify *nn = (xkbNamesNotify *) event; + XkbNamesNotifyEvent *nev = (XkbNamesNotifyEvent *) re; + + nev->type = XkbEventCode + xkbi->codes->first_event; + nev->xkb_type = XkbNamesNotify; + nev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + nev->send_event = ((event->u.u.type & 0x80) != 0); + nev->display = dpy; + nev->time = nn->time; + nev->device = nn->deviceID; + nev->changed = nn->changed; + nev->first_type = nn->firstType; + nev->num_types = nn->nTypes; + nev->first_lvl = nn->firstLevelName; + nev->num_lvls = nn->nLevelNames; + nev->num_aliases = nn->nAliases; + nev->num_radio_groups = nn->nRadioGroups; + nev->changed_vmods = nn->changedVirtualMods; + nev->changed_groups = nn->changedGroupNames; + nev->changed_indicators = nn->changedIndicators; + nev->first_key = nn->firstKey; + nev->num_keys = nn->nKeys; + return True; + } + } + break; + case XkbCompatMapNotify: + { + if (xkbi->selected_events & XkbCompatMapNotifyMask) { + xkbCompatMapNotify *cmn = (xkbCompatMapNotify *) event; + XkbCompatMapNotifyEvent *cmev = (XkbCompatMapNotifyEvent *) re; + + cmev->type = XkbEventCode + xkbi->codes->first_event; + cmev->xkb_type = XkbCompatMapNotify; + cmev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + cmev->send_event = ((event->u.u.type & 0x80) != 0); + cmev->display = dpy; + cmev->time = cmn->time; + cmev->device = cmn->deviceID; + cmev->changed_groups = cmn->changedGroups; + cmev->first_si = cmn->firstSI; + cmev->num_si = cmn->nSI; + cmev->num_total_si = cmn->nTotalSI; + return True; + } + } + break; + case XkbActionMessage: + { + if (xkbi->selected_events & XkbActionMessageMask) { + xkbActionMessage *am = (xkbActionMessage *) event; + XkbActionMessageEvent *amev = (XkbActionMessageEvent *) re; + + amev->type = XkbEventCode + xkbi->codes->first_event; + amev->xkb_type = XkbActionMessage; + amev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + amev->send_event = ((event->u.u.type & 0x80) != 0); + amev->display = dpy; + amev->time = am->time; + amev->device = am->deviceID; + amev->keycode = am->keycode; + amev->press = am->press; + amev->key_event_follows = am->keyEventFollows; + amev->group = am->group; + amev->mods = am->mods; + memcpy(amev->message, am->message, XkbActionMessageLength); + amev->message[XkbActionMessageLength] = '\0'; + return True; + } + } + break; + case XkbExtensionDeviceNotify: + { + if (xkbi->selected_events & XkbExtensionDeviceNotifyMask) { + xkbExtensionDeviceNotify *ed = (xkbExtensionDeviceNotify *) event; + XkbExtensionDeviceNotifyEvent *edev + = (XkbExtensionDeviceNotifyEvent *) re; + + edev->type = XkbEventCode + xkbi->codes->first_event; + edev->xkb_type = XkbExtensionDeviceNotify; + edev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + edev->send_event = ((event->u.u.type & 0x80) != 0); + edev->display = dpy; + edev->time = ed->time; + edev->device = ed->deviceID; + edev->led_class = ed->ledClass; + edev->led_id = ed->ledID; + edev->reason = ed->reason; + edev->supported = ed->supported; + edev->leds_defined = ed->ledsDefined; + edev->led_state = ed->ledState; + edev->first_btn = ed->firstBtn; + edev->num_btns = ed->nBtns; + edev->unsupported = ed->unsupported; + return True; + } + } + break; + case XkbNewKeyboardNotify: + { + xkbNewKeyboardNotify *nkn = (xkbNewKeyboardNotify *) event; + + if ((xkbi->selected_events & XkbNewKeyboardNotifyMask) && + (xkbi->selected_nkn_details & nkn->changed)) { + XkbNewKeyboardNotifyEvent *nkev = (XkbNewKeyboardNotifyEvent *) re; + + nkev->type = XkbEventCode + xkbi->codes->first_event; + nkev->xkb_type = XkbNewKeyboardNotify; + nkev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + nkev->send_event = ((event->u.u.type & 0x80) != 0); + nkev->display = dpy; + nkev->time = nkn->time; + nkev->device = nkn->deviceID; + nkev->old_device = nkn->oldDeviceID; + nkev->min_key_code = nkn->minKeyCode; + nkev->max_key_code = nkn->maxKeyCode; + nkev->old_min_key_code = nkn->oldMinKeyCode; + nkev->old_max_key_code = nkn->oldMaxKeyCode; + nkev->req_major = nkn->requestMajor; + nkev->req_minor = nkn->requestMinor; + nkev->changed = nkn->changed; + if ((xkbi->desc) && (nkev->send_event == 0) && + ((xkbi->desc->device_spec == nkev->old_device) || + (nkev->device != nkev->old_device))) { + xkbi->flags = XkbMapPending | XkbXlibNewKeyboard; + } + return True; + } + else if (nkn->changed & (XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask)) { + register XMappingEvent *ev = (XMappingEvent *) re; + + ev->type = MappingNotify; + ev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); + ev->send_event = ((event->u.u.type & 0x80) != 0); + ev->display = dpy; + ev->window = 0; + ev->first_keycode = dpy->min_keycode; + ev->request = MappingKeyboard; + ev->count = (dpy->max_keycode - dpy->min_keycode) + 1; + if ((xkbi->desc) && (ev->send_event == 0) && + ((xkbi->desc->device_spec == nkn->oldDeviceID) || + (nkn->deviceID != nkn->oldDeviceID))) { + xkbi->flags |= XkbMapPending | XkbXlibNewKeyboard; + } + return True; + } + } + break; + default: #ifdef DEBUG - fprintf(stderr,"Got unknown XKEYBOARD event (%d, base=%d)\n", - re->type, - xkbi->codes->first_event); + fprintf(stderr, "Got unknown XKEYBOARD event (%d, base=%d)\n", + re->type, xkbi->codes->first_event); #endif - break; + break; } return False; } @@ -620,15 +614,17 @@ wire_to_event(Display *dpy,XEvent *re,xEvent *event) Bool XkbIgnoreExtension(Bool ignore) { - if (getenv("XKB_FORCE")!=NULL) { + if (getenv("XKB_FORCE") != NULL) { #ifdef DEBUG - fprintf(stderr,"Forcing use of XKEYBOARD (overriding an IgnoreExtensions)\n"); + fprintf(stderr, + "Forcing use of XKEYBOARD (overriding an IgnoreExtensions)\n"); #endif - return False; + return False; } #ifdef DEBUG - else if (getenv("XKB_DEBUG")!=NULL) { - fprintf(stderr,"Explicitly %signoring XKEYBOARD\n",ignore?"":"not "); + else if (getenv("XKB_DEBUG") != NULL) { + fprintf(stderr, "Explicitly %signoring XKEYBOARD\n", + ignore ? "" : "not "); } #endif _XkbIgnoreExtension = ignore; @@ -639,126 +635,142 @@ static void _XkbFreeInfo(Display *dpy) { XkbInfoPtr xkbi = dpy->xkb_info; + if (xkbi) { - if (xkbi->desc) - XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True); - Xfree(xkbi); - } + if (xkbi->desc) + XkbFreeKeyboard(xkbi->desc, XkbAllComponentsMask, True); + Xfree(xkbi); + } } Bool -XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn) +XkbUseExtension(Display *dpy, int *major_rtrn, int *minor_rtrn) { xkbUseExtensionReply rep; register xkbUseExtensionReq *req; - XExtCodes *codes; - int ev_base,forceIgnore; + XExtCodes *codes; + int ev_base, forceIgnore; XkbInfoPtr xkbi; - char * str; + char *str; static int debugMsg; - static int been_here= 0; - - if ( dpy->xkb_info && !(dpy->flags & XlibDisplayNoXkb)) { - if (major_rtrn) *major_rtrn= dpy->xkb_info->srv_major; - if (minor_rtrn) *minor_rtrn= dpy->xkb_info->srv_minor; - return True; + static int been_here = 0; + + if (dpy->xkb_info && !(dpy->flags & XlibDisplayNoXkb)) { + if (major_rtrn) + *major_rtrn = dpy->xkb_info->srv_major; + if (minor_rtrn) + *minor_rtrn = dpy->xkb_info->srv_minor; + return True; } if (!been_here) { - debugMsg= (getenv("XKB_DEBUG")!=NULL); - been_here= 1; + debugMsg = (getenv("XKB_DEBUG") != NULL); + been_here = 1; } - if (major_rtrn) *major_rtrn= 0; - if (minor_rtrn) *minor_rtrn= 0; + if (major_rtrn) + *major_rtrn = 0; + if (minor_rtrn) + *minor_rtrn = 0; if (!dpy->xkb_info) { xkbi = _XkbTypedCalloc(1, XkbInfoRec); - if ( !xkbi ) - return False; + if (!xkbi) + return False; dpy->xkb_info = xkbi; dpy->free_funcs->xkb = _XkbFreeInfo; - xkbi->xlib_ctrls|= (XkbLC_ControlFallback|XkbLC_ConsumeLookupMods); - if ((str=getenv("_XKB_OPTIONS_ENABLE"))!=NULL) { - if ((str=getenv("_XKB_LATIN1_LOOKUP"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_ForceLatin1Lookup; - else xkbi->xlib_ctrls|= XkbLC_ForceLatin1Lookup; - } - if ((str=getenv("_XKB_CONSUME_LOOKUP_MODS"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_ConsumeLookupMods; - else xkbi->xlib_ctrls|= XkbLC_ConsumeLookupMods; - } - if ((str=getenv("_XKB_CONSUME_SHIFT_AND_LOCK"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_AlwaysConsumeShiftAndLock; - else xkbi->xlib_ctrls|= XkbLC_AlwaysConsumeShiftAndLock; - } - if ((str=getenv("_XKB_IGNORE_NEW_KEYBOARDS"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_IgnoreNewKeyboards; - else xkbi->xlib_ctrls|= XkbLC_IgnoreNewKeyboards; - } - if ((str=getenv("_XKB_CONTROL_FALLBACK"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_ControlFallback; - else xkbi->xlib_ctrls|= XkbLC_ControlFallback; - } - if ((str=getenv("_XKB_COMP_LED"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_ComposeLED; - else { - xkbi->xlib_ctrls|= XkbLC_ComposeLED; - if (strlen(str)>0) - xkbi->composeLED= XInternAtom(dpy,str,False); - } - } - if ((str=getenv("_XKB_COMP_FAIL_BEEP"))!=NULL) { - if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) - xkbi->xlib_ctrls&= ~XkbLC_BeepOnComposeFail; - else xkbi->xlib_ctrls|= XkbLC_BeepOnComposeFail; - } - } - if ((xkbi->composeLED==None)&&((xkbi->xlib_ctrls&XkbLC_ComposeLED)!=0)) - xkbi->composeLED= XInternAtom(dpy,"Compose",False); + xkbi->xlib_ctrls |= (XkbLC_ControlFallback | XkbLC_ConsumeLookupMods); + if ((str = getenv("_XKB_OPTIONS_ENABLE")) != NULL) { + if ((str = getenv("_XKB_LATIN1_LOOKUP")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_ForceLatin1Lookup; + else + xkbi->xlib_ctrls |= XkbLC_ForceLatin1Lookup; + } + if ((str = getenv("_XKB_CONSUME_LOOKUP_MODS")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_ConsumeLookupMods; + else + xkbi->xlib_ctrls |= XkbLC_ConsumeLookupMods; + } + if ((str = getenv("_XKB_CONSUME_SHIFT_AND_LOCK")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_AlwaysConsumeShiftAndLock; + else + xkbi->xlib_ctrls |= XkbLC_AlwaysConsumeShiftAndLock; + } + if ((str = getenv("_XKB_IGNORE_NEW_KEYBOARDS")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_IgnoreNewKeyboards; + else + xkbi->xlib_ctrls |= XkbLC_IgnoreNewKeyboards; + } + if ((str = getenv("_XKB_CONTROL_FALLBACK")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_ControlFallback; + else + xkbi->xlib_ctrls |= XkbLC_ControlFallback; + } + if ((str = getenv("_XKB_COMP_LED")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_ComposeLED; + else { + xkbi->xlib_ctrls |= XkbLC_ComposeLED; + if (strlen(str) > 0) + xkbi->composeLED = XInternAtom(dpy, str, False); + } + } + if ((str = getenv("_XKB_COMP_FAIL_BEEP")) != NULL) { + if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0)) + xkbi->xlib_ctrls &= ~XkbLC_BeepOnComposeFail; + else + xkbi->xlib_ctrls |= XkbLC_BeepOnComposeFail; + } + } + if ((xkbi->composeLED == None) && + ((xkbi->xlib_ctrls & XkbLC_ComposeLED) != 0)) + xkbi->composeLED = XInternAtom(dpy, "Compose", False); #ifdef DEBUG if (debugMsg) { - register unsigned c= xkbi->xlib_ctrls; - fprintf(stderr,"XKEYBOARD compose: beep on failure is %s, LED is %s\n", - ((c&XkbLC_BeepOnComposeFail)?"on":"off"), - ((c&XkbLC_ComposeLED)?"on":"off")); - fprintf(stderr,"XKEYBOARD XLookupString: %slatin-1, %s lookup modifiers\n", - ((c&XkbLC_ForceLatin1Lookup)?"allow non-":"force "), - ((c&XkbLC_ConsumeLookupMods)?"consume":"re-use")); - fprintf(stderr, - "XKEYBOARD XLookupString: %sconsume shift and lock, %scontrol fallback\n", - ((c&XkbLC_AlwaysConsumeShiftAndLock)?"always ":"don't "), - ((c&XkbLC_ControlFallback)?"":"no ")); + register unsigned c = xkbi->xlib_ctrls; + + fprintf(stderr, + "XKEYBOARD compose: beep on failure is %s, LED is %s\n", + ((c & XkbLC_BeepOnComposeFail) ? "on" : "off"), + ((c & XkbLC_ComposeLED) ? "on" : "off")); + fprintf(stderr, + "XKEYBOARD XLookupString: %slatin-1, %s lookup modifiers\n", + ((c & XkbLC_ForceLatin1Lookup) ? "allow non-" : "force "), + ((c & XkbLC_ConsumeLookupMods) ? "consume" : "re-use")); + fprintf(stderr, + "XKEYBOARD XLookupString: %sconsume shift and lock, %scontrol fallback\n", + ((c & XkbLC_AlwaysConsumeShiftAndLock) ? "always " : + "don't "), ((c & XkbLC_ControlFallback) ? "" : "no ")); } #endif - } else + } + else xkbi = dpy->xkb_info; - forceIgnore= (dpy->flags&XlibDisplayNoXkb)||dpy->keysyms; - forceIgnore= forceIgnore&&(major_rtrn==NULL)&&(minor_rtrn==NULL); - if ( forceIgnore || _XkbIgnoreExtension || getenv("XKB_DISABLE")) { - LockDisplay(dpy); - dpy->flags |= XlibDisplayNoXkb; - UnlockDisplay(dpy); - if (debugMsg) - fprintf(stderr,"XKEYBOARD extension disabled or missing\n"); - return False; - } - - if ( (codes=XInitExtension(dpy,XkbName))==NULL ) { - LockDisplay(dpy); - dpy->flags |= XlibDisplayNoXkb; - UnlockDisplay(dpy); - if (debugMsg) - fprintf(stderr,"XKEYBOARD extension not present\n"); - return False; + forceIgnore = (dpy->flags & XlibDisplayNoXkb) || dpy->keysyms; + forceIgnore = forceIgnore && (major_rtrn == NULL) && (minor_rtrn == NULL); + if (forceIgnore || _XkbIgnoreExtension || getenv("XKB_DISABLE")) { + LockDisplay(dpy); + dpy->flags |= XlibDisplayNoXkb; + UnlockDisplay(dpy); + if (debugMsg) + fprintf(stderr, "XKEYBOARD extension disabled or missing\n"); + return False; + } + + if ((codes = XInitExtension(dpy, XkbName)) == NULL) { + LockDisplay(dpy); + dpy->flags |= XlibDisplayNoXkb; + UnlockDisplay(dpy); + if (debugMsg) + fprintf(stderr, "XKEYBOARD extension not present\n"); + return False; } xkbi->codes = codes; LockDisplay(dpy); @@ -768,58 +780,63 @@ XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn) req->xkbReqType = X_kbUseExtension; req->wantedMajor = XkbMajorVersion; req->wantedMinor = XkbMinorVersion; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.supported ) { - Bool fail; - fail= True; - if (debugMsg) - fprintf(stderr, - "XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n", - XkbMajorVersion,XkbMinorVersion, - rep.serverMajor, rep.serverMinor); - - /* pre-release 0.65 is very close to 1.00 */ - if ((rep.serverMajor==0)&&(rep.serverMinor==65)) { - if (debugMsg) - fprintf(stderr,"Trying to fall back to version 0.65..."); - GetReq(kbUseExtension, req); - req->reqType = xkbi->codes->major_opcode; - req->xkbReqType = X_kbUseExtension; - req->wantedMajor = 0; - req->wantedMinor = 65; - if ( _XReply(dpy, (xReply *)&rep, 0, xFalse) && rep.supported ) { - if (debugMsg) - fprintf(stderr,"succeeded\n"); - fail= False; - } - else if (debugMsg) fprintf(stderr,"failed\n"); - } - if (fail) { - dpy->flags |= XlibDisplayNoXkb; - UnlockDisplay(dpy); - SyncHandle(); - if (major_rtrn) *major_rtrn= rep.serverMajor; - if (minor_rtrn) *minor_rtrn= rep.serverMinor; - return False; - } + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.supported) { + Bool fail = True; + + if (debugMsg) + fprintf(stderr, + "XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n", + XkbMajorVersion, XkbMinorVersion, + rep.serverMajor, rep.serverMinor); + + /* pre-release 0.65 is very close to 1.00 */ + if ((rep.serverMajor == 0) && (rep.serverMinor == 65)) { + if (debugMsg) + fprintf(stderr, "Trying to fall back to version 0.65..."); + GetReq(kbUseExtension, req); + req->reqType = xkbi->codes->major_opcode; + req->xkbReqType = X_kbUseExtension; + req->wantedMajor = 0; + req->wantedMinor = 65; + if (_XReply(dpy, (xReply *) &rep, 0, xFalse) && rep.supported) { + if (debugMsg) + fprintf(stderr, "succeeded\n"); + fail = False; + } + else if (debugMsg) + fprintf(stderr, "failed\n"); + } + if (fail) { + dpy->flags |= XlibDisplayNoXkb; + UnlockDisplay(dpy); + SyncHandle(); + if (major_rtrn) + *major_rtrn = rep.serverMajor; + if (minor_rtrn) + *minor_rtrn = rep.serverMinor; + return False; + } } #ifdef DEBUG - else if ( forceIgnore ) { - fprintf(stderr,"Internal Error! XkbUseExtension succeeded with forceIgnore set\n"); + else if (forceIgnore) { + fprintf(stderr, + "Internal Error! XkbUseExtension succeeded with forceIgnore set\n"); } #endif UnlockDisplay(dpy); - xkbi->srv_major= rep.serverMajor; - xkbi->srv_minor= rep.serverMinor; - if (major_rtrn) *major_rtrn= rep.serverMajor; - if (minor_rtrn) *minor_rtrn= rep.serverMinor; + xkbi->srv_major = rep.serverMajor; + xkbi->srv_minor = rep.serverMinor; + if (major_rtrn) + *major_rtrn = rep.serverMajor; + if (minor_rtrn) + *minor_rtrn = rep.serverMinor; if (debugMsg) - fprintf(stderr,"XKEYBOARD (version %d.%02d/%d.%02d) OK!\n", - XkbMajorVersion,XkbMinorVersion, - rep.serverMajor,rep.serverMinor); + fprintf(stderr, "XKEYBOARD (version %d.%02d/%d.%02d) OK!\n", + XkbMajorVersion, XkbMinorVersion, + rep.serverMajor, rep.serverMinor); ev_base = codes->first_event; - XESetWireToEvent(dpy,ev_base+XkbEventCode,wire_to_event); + XESetWireToEvent(dpy, ev_base + XkbEventCode, wire_to_event); SyncHandle(); return True; } - diff --git a/libX11/src/xkb/XKBleds.c b/libX11/src/xkb/XKBleds.c index d9b743c6f..5c51f276a 100644 --- a/libX11/src/xkb/XKBleds.c +++ b/libX11/src/xkb/XKBleds.c @@ -33,159 +33,163 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "XKBlibint.h" Status -XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn) +XkbGetIndicatorState(Display *dpy, unsigned deviceSpec, unsigned *pStateRtrn) { register xkbGetIndicatorStateReq *req; - xkbGetIndicatorStateReply rep; + xkbGetIndicatorStateReply rep; XkbInfoPtr xkbi; Bool ok; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetIndicatorState, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetIndicatorState; req->deviceSpec = deviceSpec; - ok=_XReply(dpy, (xReply *)&rep, 0, xFalse); - if (ok && (pStateRtrn!=NULL)) - *pStateRtrn= rep.state; + ok = _XReply(dpy, (xReply *) &rep, 0, xFalse); + if (ok && (pStateRtrn != NULL)) + *pStateRtrn = rep.state; UnlockDisplay(dpy); SyncHandle(); - return (ok?Success:BadImplementation); + return (ok ? Success : BadImplementation); } Status -_XkbReadGetIndicatorMapReply( Display * dpy, - xkbGetIndicatorMapReply * rep, - XkbDescPtr xkb, - int * nread_rtrn) +_XkbReadGetIndicatorMapReply(Display *dpy, + xkbGetIndicatorMapReply *rep, + XkbDescPtr xkb, + int *nread_rtrn) { -XkbIndicatorPtr leds; -XkbReadBufferRec buf; + XkbIndicatorPtr leds; + XkbReadBufferRec buf; - if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success)) - return BadAlloc; - leds= xkb->indicators; + if ((!xkb->indicators) && (XkbAllocIndicatorMaps(xkb) != Success)) + return BadAlloc; + leds = xkb->indicators; leds->phys_indicators = rep->realIndicators; - if (rep->length>0) { - register int left; - if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) - return BadAlloc; - if (nread_rtrn) - *nread_rtrn= (int)rep->length*4; - if (rep->which) { - register int i,bit; - left= (int)rep->which; - for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) { - if (left&bit) { - xkbIndicatorMapWireDesc *wire; - wire= (xkbIndicatorMapWireDesc *) - _XkbGetReadBufferPtr(&buf, - SIZEOF(xkbIndicatorMapWireDesc)); - if (wire==NULL) { - _XkbFreeReadBuffer(&buf); - return BadAlloc; - } - leds->maps[i].flags= wire->flags; - leds->maps[i].which_groups= wire->whichGroups; - leds->maps[i].groups= wire->groups; - leds->maps[i].which_mods= wire->whichMods; - leds->maps[i].mods.mask= wire->mods; - leds->maps[i].mods.real_mods= wire->realMods; - leds->maps[i].mods.vmods= wire->virtualMods; - leds->maps[i].ctrls= wire->ctrls; - left&= ~bit; - } - } - } - left= _XkbFreeReadBuffer(&buf); + if (rep->length > 0) { + register int left; + + if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4)) + return BadAlloc; + if (nread_rtrn) + *nread_rtrn = (int) rep->length * 4; + if (rep->which) { + register int i, bit; + + left = (int) rep->which; + for (i = 0, bit = 1; (i < XkbNumIndicators) && (left); + i++, bit <<= 1) { + if (left & bit) { + xkbIndicatorMapWireDesc *wire; + + wire = (xkbIndicatorMapWireDesc *) + _XkbGetReadBufferPtr(&buf, + SIZEOF(xkbIndicatorMapWireDesc)); + if (wire == NULL) { + _XkbFreeReadBuffer(&buf); + return BadAlloc; + } + leds->maps[i].flags = wire->flags; + leds->maps[i].which_groups = wire->whichGroups; + leds->maps[i].groups = wire->groups; + leds->maps[i].which_mods = wire->whichMods; + leds->maps[i].mods.mask = wire->mods; + leds->maps[i].mods.real_mods = wire->realMods; + leds->maps[i].mods.vmods = wire->virtualMods; + leds->maps[i].ctrls = wire->ctrls; + left &= ~bit; + } + } + } + left = _XkbFreeReadBuffer(&buf); } return Success; } Bool -XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) +XkbGetIndicatorMap(Display *dpy, unsigned long which, XkbDescPtr xkb) { - register xkbGetIndicatorMapReq * req; - xkbGetIndicatorMapReply rep; - XkbInfoPtr xkbi; - Status status; + register xkbGetIndicatorMapReq *req; + xkbGetIndicatorMapReply rep; + XkbInfoPtr xkbi; + Status status; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return BadAccess; - if ((!which)||(!xkb)) - return BadValue; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return BadAccess; + if ((!which) || (!xkb)) + return BadValue; LockDisplay(dpy); xkbi = dpy->xkb_info; if (!xkb->indicators) { - xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec); - if (!xkb->indicators) { - UnlockDisplay(dpy); - SyncHandle(); - return BadAlloc; - } + xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec); + if (!xkb->indicators) { + UnlockDisplay(dpy); + SyncHandle(); + return BadAlloc; + } } GetReq(kbGetIndicatorMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetIndicatorMap; req->deviceSpec = xkb->device_spec; - req->which = (CARD32)which; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return BadValue; + req->which = (CARD32) which; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return BadValue; } - status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL); + status = _XkbReadGetIndicatorMapReply(dpy, &rep, xkb, NULL); UnlockDisplay(dpy); SyncHandle(); return status; } Bool -XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) +XkbSetIndicatorMap(Display *dpy, unsigned long which, XkbDescPtr xkb) { - register xkbSetIndicatorMapReq *req; - register int i,bit; + register xkbSetIndicatorMapReq *req; + register int i, bit; int nMaps; xkbIndicatorMapWireDesc *wire; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; - if ((!xkb)||(!which)||(!xkb->indicators)) - return False; + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; + if ((!xkb) || (!which) || (!xkb->indicators)) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetIndicatorMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSetIndicatorMap; req->deviceSpec = xkb->device_spec; - req->which = (CARD32)which; - for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) { - if (which&bit) - nMaps++; + req->which = (CARD32) which; + for (i = nMaps = 0, bit = 1; i < 32; i++, bit <<= 1) { + if (which & bit) + nMaps++; } - req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4; - BufAlloc(xkbIndicatorMapWireDesc *,wire, - (nMaps*SIZEOF(xkbIndicatorMapWireDesc))); - for (i=0,bit=1;i<32;i++,bit<<=1) { - if (which&bit) { - wire->flags= xkb->indicators->maps[i].flags; - wire->whichGroups= xkb->indicators->maps[i].which_groups; - wire->groups= xkb->indicators->maps[i].groups; - wire->whichMods= xkb->indicators->maps[i].which_mods; - wire->mods= xkb->indicators->maps[i].mods.real_mods; - wire->virtualMods= xkb->indicators->maps[i].mods.vmods; - wire->ctrls= xkb->indicators->maps[i].ctrls; - wire++; - } + req->length += (nMaps * sizeof(XkbIndicatorMapRec)) / 4; + BufAlloc(xkbIndicatorMapWireDesc *, wire, + (nMaps * SIZEOF(xkbIndicatorMapWireDesc))); + for (i = 0, bit = 1; i < 32; i++, bit <<= 1) { + if (which & bit) { + wire->flags = xkb->indicators->maps[i].flags; + wire->whichGroups = xkb->indicators->maps[i].which_groups; + wire->groups = xkb->indicators->maps[i].groups; + wire->whichMods = xkb->indicators->maps[i].which_mods; + wire->mods = xkb->indicators->maps[i].mods.real_mods; + wire->virtualMods = xkb->indicators->maps[i].mods.vmods; + wire->ctrls = xkb->indicators->maps[i].ctrls; + wire++; + } } UnlockDisplay(dpy); SyncHandle(); @@ -193,23 +197,23 @@ XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) } Bool -XkbGetNamedDeviceIndicator( Display * dpy, - unsigned device, - unsigned class, - unsigned id, - Atom name, - int * pNdxRtrn, - Bool * pStateRtrn, - XkbIndicatorMapPtr pMapRtrn, - Bool * pRealRtrn) +XkbGetNamedDeviceIndicator(Display *dpy, + unsigned device, + unsigned class, + unsigned id, + Atom name, + int *pNdxRtrn, + Bool *pStateRtrn, + XkbIndicatorMapPtr pMapRtrn, + Bool *pRealRtrn) { register xkbGetNamedIndicatorReq *req; - xkbGetNamedIndicatorReply rep; + xkbGetNamedIndicatorReply rep; XkbInfoPtr xkbi; - if ((dpy->flags & XlibDisplayNoXkb) || (name==None) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + if ((dpy->flags & XlibDisplayNoXkb) || (name == None) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetNamedIndicator, req); @@ -218,66 +222,66 @@ XkbGetNamedDeviceIndicator( Display * dpy, req->deviceSpec = device; req->ledClass = class; req->ledID = id; - req->indicator = (CARD32)name; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; + req->indicator = (CARD32) name; + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; } UnlockDisplay(dpy); SyncHandle(); - if ((!rep.found)||(!rep.supported)) - return False; - if (pNdxRtrn!=NULL) - *pNdxRtrn= rep.ndx; - if (pStateRtrn!=NULL) - *pStateRtrn= rep.on; - if (pMapRtrn!=NULL) { - pMapRtrn->flags= rep.flags; - pMapRtrn->which_groups= rep.whichGroups; - pMapRtrn->groups= rep.groups; - pMapRtrn->which_mods= rep.whichMods; - pMapRtrn->mods.mask= rep.mods; - pMapRtrn->mods.real_mods= rep.realMods; - pMapRtrn->mods.vmods= rep.virtualMods; - pMapRtrn->ctrls= rep.ctrls; + if ((!rep.found) || (!rep.supported)) + return False; + if (pNdxRtrn != NULL) + *pNdxRtrn = rep.ndx; + if (pStateRtrn != NULL) + *pStateRtrn = rep.on; + if (pMapRtrn != NULL) { + pMapRtrn->flags = rep.flags; + pMapRtrn->which_groups = rep.whichGroups; + pMapRtrn->groups = rep.groups; + pMapRtrn->which_mods = rep.whichMods; + pMapRtrn->mods.mask = rep.mods; + pMapRtrn->mods.real_mods = rep.realMods; + pMapRtrn->mods.vmods = rep.virtualMods; + pMapRtrn->ctrls = rep.ctrls; } - if (pRealRtrn!=NULL) - *pRealRtrn= rep.realIndicator; + if (pRealRtrn != NULL) + *pRealRtrn = rep.realIndicator; return True; } Bool -XkbGetNamedIndicator( Display * dpy, - Atom name, - int * pNdxRtrn, - Bool * pStateRtrn, - XkbIndicatorMapPtr pMapRtrn, - Bool * pRealRtrn) +XkbGetNamedIndicator(Display *dpy, + Atom name, + int *pNdxRtrn, + Bool *pStateRtrn, + XkbIndicatorMapPtr pMapRtrn, + Bool *pRealRtrn) { - return XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd, - XkbDfltXIClass,XkbDfltXIId, - name,pNdxRtrn,pStateRtrn, - pMapRtrn,pRealRtrn); + return XkbGetNamedDeviceIndicator(dpy, XkbUseCoreKbd, + XkbDfltXIClass, XkbDfltXIId, + name, pNdxRtrn, pStateRtrn, + pMapRtrn, pRealRtrn); } Bool -XkbSetNamedDeviceIndicator( Display * dpy, - unsigned device, - unsigned class, - unsigned id, - Atom name, - Bool changeState, - Bool state, - Bool createNewMap, - XkbIndicatorMapPtr pMap) +XkbSetNamedDeviceIndicator(Display *dpy, + unsigned device, + unsigned class, + unsigned id, + Atom name, + Bool changeState, + Bool state, + Bool createNewMap, + XkbIndicatorMapPtr pMap) { - register xkbSetNamedIndicatorReq *req; + register xkbSetNamedIndicatorReq *req; XkbInfoPtr xkbi; - if ((dpy->flags & XlibDisplayNoXkb) || (name==None) || - (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) - return False; + if ((dpy->flags & XlibDisplayNoXkb) || (name == None) || + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetNamedIndicator, req); @@ -286,32 +290,33 @@ XkbSetNamedDeviceIndicator( Display * dpy, req->deviceSpec = device; req->ledClass = class; req->ledID = id; - req->indicator= (CARD32)name; - req->setState= changeState; + req->indicator = (CARD32) name; + req->setState = changeState; if (req->setState) - req->on= state; - else req->on= False; - if (pMap!=NULL) { - req->setMap= True; - req->createMap= createNewMap; - req->flags= pMap->flags; - req->whichGroups= pMap->which_groups; - req->groups= pMap->groups; - req->whichMods= pMap->which_mods; - req->realMods= pMap->mods.real_mods; - req->virtualMods= pMap->mods.vmods; - req->ctrls= pMap->ctrls; + req->on = state; + else + req->on = False; + if (pMap != NULL) { + req->setMap = True; + req->createMap = createNewMap; + req->flags = pMap->flags; + req->whichGroups = pMap->which_groups; + req->groups = pMap->groups; + req->whichMods = pMap->which_mods; + req->realMods = pMap->mods.real_mods; + req->virtualMods = pMap->mods.vmods; + req->ctrls = pMap->ctrls; } else { - req->setMap= False; - req->createMap= False; - req->flags= 0; - req->whichGroups= 0; - req->groups= 0; - req->whichMods= 0; - req->realMods= 0; - req->virtualMods= 0; - req->ctrls= 0; + req->setMap = False; + req->createMap = False; + req->flags = 0; + req->whichGroups = 0; + req->groups = 0; + req->whichMods = 0; + req->realMods = 0; + req->virtualMods = 0; + req->ctrls = 0; } UnlockDisplay(dpy); SyncHandle(); @@ -319,15 +324,15 @@ XkbSetNamedDeviceIndicator( Display * dpy, } Bool -XkbSetNamedIndicator( Display * dpy, - Atom name, - Bool changeState, - Bool state, - Bool createNewMap, - XkbIndicatorMapPtr pMap) +XkbSetNamedIndicator(Display *dpy, + Atom name, + Bool changeState, + Bool state, + Bool createNewMap, + XkbIndicatorMapPtr pMap) { - return XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd, - XkbDfltXIClass,XkbDfltXIId, - name,changeState,state, - createNewMap,pMap); + return XkbSetNamedDeviceIndicator(dpy, XkbUseCoreKbd, + XkbDfltXIClass, XkbDfltXIId, + name, changeState, state, + createNewMap, pMap); } diff --git a/libX11/src/xkb/XKBlibint.h b/libX11/src/xkb/XKBlibint.h index 7b41c3bbf..ca7dc0b74 100644 --- a/libX11/src/xkb/XKBlibint.h +++ b/libX11/src/xkb/XKBlibint.h @@ -25,216 +25,210 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ #ifndef _XKBLIBINT_H_ -#define _XKBLIBINT_H_ +#define _XKBLIBINT_H_ #include <X11/Xutil.h> #include <X11/XKBlib.h> -#define XkbMapPending (1<<0) -#define XkbXlibNewKeyboard (1<<1) +#define XkbMapPending (1<<0) +#define XkbXlibNewKeyboard (1<<1) -typedef int (*XkbKSToMBFunc)( - XPointer /* priv */, - KeySym /* sym */, - char * /* buf */, - int /* len */, - int * /* extra_rtrn */ +typedef int (*XkbKSToMBFunc)( + XPointer /* priv */, + KeySym /* sym */, + char * /* buf */, + int /* len */, + int * /* extra_rtrn */ ); -typedef KeySym (*XkbMBToKSFunc)( - XPointer /* priv */, - char * /* buf */, - int /* len */, - Status * /* status */ +typedef KeySym (*XkbMBToKSFunc)( + XPointer /* priv */, + char * /* buf */, + int /* len */, + Status * /* status */ ); -typedef KeySym (*XkbToUpperFunc)( - KeySym /* sym */ +typedef KeySym (*XkbToUpperFunc)( + KeySym /* sym */ ); typedef struct _XkbConverters { - XkbKSToMBFunc KSToMB; - XPointer KSToMBPriv; - XkbMBToKSFunc MBToKS; - XPointer MBToKSPriv; - XkbToUpperFunc KSToUpper; + XkbKSToMBFunc KSToMB; + XPointer KSToMBPriv; + XkbMBToKSFunc MBToKS; + XPointer MBToKSPriv; + XkbToUpperFunc KSToUpper; } XkbConverters; -extern XkbInternAtomFunc _XkbInternAtomFunc; -extern XkbGetAtomNameFunc _XkbGetAtomNameFunc; +extern XkbInternAtomFunc _XkbInternAtomFunc; +extern XkbGetAtomNameFunc _XkbGetAtomNameFunc; typedef struct _XkbInfoRec { - unsigned flags; - unsigned xlib_ctrls; - XExtCodes *codes; - int srv_major; - int srv_minor; - unsigned selected_events; - unsigned short selected_nkn_details; - unsigned short selected_map_details; - XkbDescRec *desc; - XkbMapChangesRec changes; - Atom composeLED; - XkbConverters cvt; - XkbConverters latin1cvt; + unsigned flags; + unsigned xlib_ctrls; + XExtCodes *codes; + int srv_major; + int srv_minor; + unsigned selected_events; + unsigned short selected_nkn_details; + unsigned short selected_map_details; + XkbDescRec *desc; + XkbMapChangesRec changes; + Atom composeLED; + XkbConverters cvt; + XkbConverters latin1cvt; } XkbInfoRec, *XkbInfoPtr; -#define _XkbUnavailable(d) \ - (((d)->flags&XlibDisplayNoXkb) ||\ - ((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d))) - -#define _XkbCheckPendingRefresh(d,xi) {\ - if ((xi)->flags&XkbXlibNewKeyboard)\ - _XkbReloadDpy((d));\ - else if ((xi)->flags&XkbMapPending) {\ - if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) {\ - LockDisplay((d));\ - (xi)->changes.changed= 0;\ - UnlockDisplay((d));\ - }\ - }\ +#define _XkbUnavailable(d) \ + (((d)->flags&XlibDisplayNoXkb) || \ + ((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d))) + +#define _XkbCheckPendingRefresh(d,xi) { \ + if ((xi)->flags&XkbXlibNewKeyboard) \ + _XkbReloadDpy((d)); \ + else if ((xi)->flags&XkbMapPending) { \ + if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) { \ + LockDisplay((d)); \ + (xi)->changes.changed= 0; \ + UnlockDisplay((d)); \ + } \ + } \ } -#define _XkbNeedModmap(i) ((!(i)->desc->map)||(!(i)->desc->map->modmap)) +#define _XkbNeedModmap(i) ((!(i)->desc->map)||(!(i)->desc->map->modmap)) - /* - * mask of the events that the "invisible" XKB support in Xlib needs - */ + /* + * mask of the events that the "invisible" XKB support in Xlib needs + */ #define XKB_XLIB_MAP_MASK (XkbAllClientInfoMask) - /* - * Handy helper macros - */ -#define XKB_INSURE_SIZE(f,t,nNum,oNum) {\ - if ((f)==NULL) \ - (f)=(t *)Xmalloc(sizeof(t)*(nNum));\ - else if ((nNum)<(oNum))\ - (f)=(t *)Xrealloc((f),sizeof(t)*(nNum));\ - } + /* + * Handy helper macros + */ typedef struct _XkbReadBuffer { - int error; - int size; - char *start; - char *data; -} XkbReadBufferRec,*XkbReadBufferPtr; - -#define _XkbAlloc(s) Xmalloc((s)) -#define _XkbCalloc(n,s) Xcalloc((n),(s)) -#define _XkbRealloc(o,s) Xrealloc((o),(s)) -#define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t))) -#define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t))) -#define _XkbTypedRealloc(o,n,t) \ - ((o)?(t *)Xrealloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t)) -#define _XkbClearElems(a,f,l,t) bzero(&(a)[f],((l)-(f)+1)*sizeof(t)) -#define _XkbFree(p) Xfree(p) + int error; + int size; + char *start; + char *data; +} XkbReadBufferRec, *XkbReadBufferPtr; + +#define _XkbAlloc(s) Xmalloc((s)) +#define _XkbCalloc(n,s) Xcalloc((n),(s)) +#define _XkbRealloc(o,s) Xrealloc((o),(s)) +#define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t))) +#define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t))) +#define _XkbTypedRealloc(o,n,t) \ + ((o) ? (t *)Xrealloc((o), (n)*sizeof(t)) : _XkbTypedCalloc(n,t)) +#define _XkbClearElems(a,f,l,t) bzero(&(a)[f], ((l)-(f)+1) * sizeof(t)) +#define _XkbFree(p) Xfree(p) _XFUNCPROTOBEGIN -extern void _XkbReloadDpy( - Display * /* dpy */ +extern void _XkbReloadDpy( + Display * /* dpy */ ); extern KeySym _XKeycodeToKeysym( - Display* /* display */, + Display * /* display */, #if NeedWidePrototypes - unsigned int /* keycode */, + unsigned int /* keycode */, #else - KeyCode /* keycode */, + KeyCode /* keycode */, #endif - int /* index */ + int /* index */ ); extern KeyCode _XKeysymToKeycode( - Display* /* display */, - KeySym /* keysym */ + Display * /* display */, + KeySym /* keysym */ ); extern KeySym _XLookupKeysym( - XKeyEvent* /* key_event */, - int /* index */ + XKeyEvent * /* key_event */, + int /* index */ ); extern int _XRefreshKeyboardMapping( - XMappingEvent* /* event_map */ + XMappingEvent * /* event_map */ ); -extern unsigned _XKeysymToModifiers( - Display * /* dpy */, - KeySym /* ks */ +extern unsigned _XKeysymToModifiers( + Display * /* dpy */, + KeySym /* ks */ ); extern int _XTranslateKey( - register Display * /* dpy */, - KeyCode /* keycode */, + register Display * /* dpy */, + KeyCode /* keycode */, register unsigned int /* modifiers */, - unsigned int * /* modifiers_return */, - KeySym * /* keysym_return */ + unsigned int * /* modifiers_return */, + KeySym * /* keysym_return */ ); -extern int _XTranslateKeySym( - Display * /* dpy */, - register KeySym /* symbol */, - unsigned int /* modifiers */, - char * /* buffer */, - int /* nbytes */ +extern int _XTranslateKeySym( + Display * /* dpy */, + register KeySym /* symbol */, + unsigned int /* modifiers */, + char * /* buffer */, + int /* nbytes */ ); -extern int _XLookupString( - register XKeyEvent * /* event */, - char * /* buffer */, - int /* nbytes */, - KeySym * /* keysym */, - XComposeStatus * /* status */ +extern int _XLookupString( + register XKeyEvent * /* event */, + char * /* buffer */, + int /* nbytes */, + KeySym * /* keysym */, + XComposeStatus * /* status */ ); extern void _XkbNoteCoreMapChanges( - XkbMapChangesRec * /* old */, - XMappingEvent * /* new */, - unsigned int /* wanted */ + XkbMapChangesRec * /* old */, + XMappingEvent * /* new */, + unsigned int /* wanted */ ); -extern int _XkbInitReadBuffer( - Display * /* dpy */, - XkbReadBufferPtr /* buf */, - int /* size */ +extern int _XkbInitReadBuffer( + Display * /* dpy */, + XkbReadBufferPtr /* buf */, + int /* size */ ); extern int _XkbSkipReadBufferData( - XkbReadBufferPtr /* from */, - int /* size */ + XkbReadBufferPtr /* from */, + int /* size */ ); extern int _XkbCopyFromReadBuffer( - XkbReadBufferPtr /* from */, - char * /* to */, - int /* size */ + XkbReadBufferPtr /* from */, + char * /* to */, + int /* size */ ); #ifdef LONG64 -extern int _XkbReadCopyData32( - int * /* from */, - long * /* to */, - int /* num_words */ +extern int _XkbReadCopyData32( + int * /* from */, + long * /* to */, + int /* num_words */ ); -extern int _XkbWriteCopyData32( - unsigned long * /* from */, - CARD32 * /* to */, - int /* num_words */ +extern int _XkbWriteCopyData32( + unsigned long * /* from */, + CARD32 * /* to */, + int /* num_words */ ); extern int _XkbReadBufferCopy32( - XkbReadBufferPtr /* from */, - long * /* to */, - int /* size */ + XkbReadBufferPtr /* from */, + long * /* to */, + int /* size */ ); #else -#define _XkbReadCopyData32(f,t,s) memcpy((char *)(t),(char *)(f),(s)*4) -#define _XkbWriteCopyData32(f,t,s) memcpy((char *)(t),(char *)(f),(s)*4) -#define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f,(char *)t,(s)*4) +#define _XkbReadCopyData32(f,t,s) memcpy((char *)(t), (char *)(f), (s)*4) +#define _XkbWriteCopyData32(f,t,s) memcpy((char *)(t), (char *)(f), (s)*4) +#define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f, (char *)t, (s)*4) #endif #ifndef NO_DEC_BINARY_COMPATIBILITY @@ -243,97 +237,97 @@ extern int _XkbReadBufferCopy32( #ifdef XKB_FORCE_INT_KEYSYM extern int _XkbReadCopyKeySyms( - int * /* from */, - KeySym * /* to */, - int /* num_words */ + int * /* from */, + KeySym * /* to */, + int /* num_words */ ); -extern int _XkbWriteCopyKeySyms( - KeySym * /* from */, - CARD32 * /* to */, - int /* num_words */ +extern int _XkbWriteCopyKeySyms( + KeySym * /* from */, + CARD32 * /* to */, + int /* num_words */ ); extern int _XkbReadBufferCopyKeySyms( - XkbReadBufferPtr /* from */, + XkbReadBufferPtr /* from */, #ifndef NO_DEC_BUG_FIX - KeySym * /* to */, + KeySym * /* to */, #else - long * /* to */, + long * /* to */, #endif - int /* size */ + int /* size */ ); #else -#define _XkbReadCopyKeySyms(f,t,n) _XkbReadCopyData32(f,t,n) -#define _XkbWriteCopyKeySyms(f,t,n) _XkbWriteCopyData32(f,t,n) -#define _XkbReadBufferCopyKeySyms(f,t,s) _XkbReadBufferCopy32(f,t,s) +#define _XkbReadCopyKeySyms(f,t,n) _XkbReadCopyData32(f,t,n) +#define _XkbWriteCopyKeySyms(f,t,n) _XkbWriteCopyData32(f,t,n) +#define _XkbReadBufferCopyKeySyms(f,t,s) _XkbReadBufferCopy32(f,t,s) #endif extern char *_XkbPeekAtReadBuffer( - XkbReadBufferPtr /* from */, - int /* size */ + XkbReadBufferPtr /* from */, + int /* size */ ); extern char *_XkbGetReadBufferPtr( - XkbReadBufferPtr /* from */, - int /* size */ + XkbReadBufferPtr /* from */, + int /* size */ ); -#define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t))) +#define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t))) extern int _XkbFreeReadBuffer( - XkbReadBufferPtr /* buf */ + XkbReadBufferPtr /* buf */ ); extern Bool _XkbGetReadBufferCountedString( - XkbReadBufferPtr /* buf */, - char ** /* rtrn */ + XkbReadBufferPtr /* buf */, + char ** /* rtrn */ ); -extern char *_XkbGetCharset( +extern char *_XkbGetCharset( void ); -extern int _XkbGetConverters( +extern int _XkbGetConverters( const char * /* encoding_name */, XkbConverters * /* cvt_rtrn */ ); -#ifdef NEED_MAP_READERS +#ifdef NEED_MAP_READERS -extern Status _XkbReadGetMapReply( - Display * /* dpy */, - xkbGetMapReply * /* rep */, - XkbDescRec * /* xkb */, - int * /* nread_rtrn */ +extern Status _XkbReadGetMapReply( + Display * /* dpy */, + xkbGetMapReply * /* rep */, + XkbDescRec * /* xkb */, + int * /* nread_rtrn */ ); -extern Status _XkbReadGetCompatMapReply( - Display * /* dpy */, - xkbGetCompatMapReply * /* rep */, - XkbDescPtr /* xkb */, - int * /* nread_rtrn */ +extern Status _XkbReadGetCompatMapReply( + Display * /* dpy */, + xkbGetCompatMapReply * /* rep */, + XkbDescPtr /* xkb */, + int * /* nread_rtrn */ ); -extern Status _XkbReadGetIndicatorMapReply( - Display * /* dpy */, - xkbGetIndicatorMapReply * /* rep */, - XkbDescPtr /* xkb */, - int * /* nread_rtrn */ +extern Status _XkbReadGetIndicatorMapReply( + Display * /* dpy */, + xkbGetIndicatorMapReply * /* rep */, + XkbDescPtr /* xkb */, + int * /* nread_rtrn */ ); -extern Status _XkbReadGetNamesReply( - Display * /* dpy */, - xkbGetNamesReply * /* rep */, - XkbDescPtr /* xkb */, - int * /* nread_rtrn */ +extern Status _XkbReadGetNamesReply( + Display * /* dpy */, + xkbGetNamesReply * /* rep */, + XkbDescPtr /* xkb */, + int * /* nread_rtrn */ ); -extern Status _XkbReadGetGeometryReply( - Display * /* dpy */, - xkbGetGeometryReply * /* rep */, - XkbDescPtr /* xkb */, - int * /* nread_rtrn */ +extern Status _XkbReadGetGeometryReply( + Display * /* dpy */, + xkbGetGeometryReply * /* rep */, + XkbDescPtr /* xkb */, + int * /* nread_rtrn */ ); #endif diff --git a/libX11/src/xlibi18n/ICWrap.c b/libX11/src/xlibi18n/ICWrap.c index 1eacfa5f1..2a1d0d670 100644 --- a/libX11/src/xlibi18n/ICWrap.c +++ b/libX11/src/xlibi18n/ICWrap.c @@ -128,7 +128,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return) return; } - args = (XIMArg *)Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg)); + args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg)); *args_return = args; if (!args) return; @@ -186,7 +186,7 @@ XSetIMValues(XIM im, ...) va_end(var); ret = (*im->methods->set_values) (im, args); - if (args) Xfree((char *)args); + if (args) Xfree(args); return ret; } @@ -213,7 +213,7 @@ XGetIMValues(XIM im, ...) va_end(var); ret = (*im->methods->get_values) (im, args); - if (args) Xfree((char *)args); + if (args) Xfree(args); return ret; } @@ -245,7 +245,7 @@ XCreateIC(XIM im, ...) va_end(var); ic = (XIC) (*im->methods->create_ic) (im, args); - if (args) Xfree((char *)args); + if (args) Xfree(args); if (ic) { ic->core.next = im->core.ic_chain; im->core.ic_chain = ic; @@ -271,7 +271,7 @@ XDestroyIC(XIC ic) } } } - Xfree ((char *) ic); + Xfree (ic); } char * @@ -300,7 +300,7 @@ XGetICValues(XIC ic, ...) va_end(var); ret = (*ic->methods->get_values) (ic, args); - if (args) Xfree((char *)args); + if (args) Xfree(args); return ret; } @@ -330,7 +330,7 @@ XSetICValues(XIC ic, ...) va_end(var); ret = (*ic->methods->set_values) (ic, args); - if (args) Xfree((char *)args); + if (args) Xfree(args); return ret; } diff --git a/libX11/src/xlibi18n/IMWrap.c b/libX11/src/xlibi18n/IMWrap.c index 0f6ed5593..a7c1d98c1 100644 --- a/libX11/src/xlibi18n/IMWrap.c +++ b/libX11/src/xlibi18n/IMWrap.c @@ -134,7 +134,7 @@ XCloseIM(XIM im) s = (im->methods->close) (im); for (ic = im->core.ic_chain; ic; ic = ic->core.next) ic->core.im = (XIM)NULL; - Xfree ((char *) im); + Xfree (im); _XCloseLC (lcd); return (s); } diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c index 36a457ea5..f271bded1 100644 --- a/libX11/src/xlibi18n/XDefaultIMIF.c +++ b/libX11/src/xlibi18n/XDefaultIMIF.c @@ -185,10 +185,10 @@ _XDefaultOpenIM( return((XIM)NULL); } - if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) { + if ((im = Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) { return((XIM)NULL); } - if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec))) + if ((local_impart = Xmalloc(sizeof(XIMStaticXIMRec))) == (XIMStaticXIMRec *)NULL) { Xfree(im); return((XIM)NULL); @@ -274,11 +274,11 @@ _GetIMValues( for (p = values; p->name != NULL; p++) { if (strcmp(p->name, XNQueryInputStyle) == 0) { - styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles)); + styles = Xmalloc(sizeof(XIMStyles)); *(XIMStyles **)p->value = styles; styles->count_styles = 1; styles->supported_styles = - (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle)); + Xmalloc(styles->count_styles * sizeof(XIMStyle)); styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone); } else { break; @@ -345,7 +345,7 @@ _CreateIC(XIM im, XIMArg *arg) { XIC ic; - if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) { + if ((ic = Xmalloc(sizeof(XICRec))) == (XIC)NULL) { return ((XIC)NULL); } memset(ic, 0, sizeof(XICRec)); @@ -453,7 +453,7 @@ _WcLookupString( XComposeStatus NotSupportedYet ; int length; /* In single-byte, mb_len = wc_len */ - char *mb_buf = (char *)Xmalloc(wlen); + char *mb_buf = Xmalloc(wlen); length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet); diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c index 953475d37..2ff6c414c 100644 --- a/libX11/src/xlibi18n/XDefaultOMIF.c +++ b/libX11/src/xlibi18n/XDefaultOMIF.c @@ -78,7 +78,7 @@ Sun Microsystems, Inc. or its licensors is granted. #define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen) #define DefineLocalBuf char local_buf[BUFSIZ] -#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf) +#define AllocLocalBuf(length) (length > BUFSIZ ? Xmalloc(length) : local_buf) #define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr) typedef struct _FontDataRec { @@ -334,15 +334,15 @@ init_core_part( if (count == 0) return False; - font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *)); + font_struct_list = Xmalloc(sizeof(XFontStruct *)); if (font_struct_list == NULL) return False; - font_name_list = (char **) Xmalloc(sizeof(char *)); + font_name_list = Xmalloc(sizeof(char *)); if (font_name_list == NULL) goto err; - font_name_buf = (char *) Xmalloc(length); + font_name_buf = Xmalloc(length); if (font_name_buf == NULL) goto err; @@ -580,11 +580,11 @@ set_missing_list( if (count == 0) return True; - charset_list = (char **) Xmalloc(sizeof(char *)); + charset_list = Xmalloc(sizeof(char *)); if (charset_list == NULL) return False; - charset_buf = (char *) Xmalloc(length); + charset_buf = Xmalloc(length); if (charset_buf == NULL) { Xfree(charset_list); return False; @@ -1150,10 +1150,9 @@ init_om( FontData font_data; char **required_list; XOrientation *orientation; - char **value, buf[BUFSIZ], *bufptr; - int count, length = 0; + char *bufptr; + int i, count, length = 0; - value = (char**)supported_charset_list; count = XlcNumber(supported_charset_list); data = add_data(om); @@ -1166,14 +1165,8 @@ init_om( data->font_data = font_data; data->font_data_count = count; - for ( ; count-- > 0; font_data++) { -/* -1266793 -This one is fine. *value points to one of the local strings in -supported_charset_list[]. -*/ - strcpy(buf, *value++); - font_data->name = strdup(buf); + for (i = 0; i < count; i++, font_data++) { + font_data->name = strdup(supported_charset_list[i]); if (font_data->name == NULL) return False; } @@ -1181,11 +1174,11 @@ supported_charset_list[]. length += strlen(data->font_data->name) + 1; /* required charset list */ - required_list = (char **) Xmalloc(sizeof(char *)); + required_list = Xmalloc(sizeof(char *)); if (required_list == NULL) return False; - bufptr = (char *) Xmalloc(length); + bufptr = Xmalloc(length); if (bufptr == NULL) { Xfree(required_list); return False; @@ -1201,7 +1194,7 @@ supported_charset_list[]. bufptr += strlen(bufptr) + 1; /* orientation list */ - orientation = (XOrientation *) Xmalloc(sizeof(XOrientation)); + orientation = Xmalloc(sizeof(XOrientation)); if (orientation == NULL) return False; diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c index 75e193c05..a23603865 100644 --- a/libX11/src/xlibi18n/XlcDL.c +++ b/libX11/src/xlibi18n/XlcDL.c @@ -185,16 +185,10 @@ resolve_object(char *path, const char *lc_name) if (lc_len == 0) { /* True only for the 1st time */ lc_len = OBJECT_INIT_LEN; - xi18n_objects_list = (XI18NObjectsList) - Xmalloc(sizeof(XI18NObjectsListRec) * lc_len); + xi18n_objects_list = 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"); + snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS"); fp = fopen(filename, "r"); if (fp == (FILE *)NULL){ return; @@ -212,11 +206,13 @@ Limit the length of path to prevent stack buffer corruption. } 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; + int new_len = lc_len + OBJECT_INC_LEN; + XI18NObjectsListRec *tmp = Xrealloc(xi18n_objects_list, + sizeof(XI18NObjectsListRec) * new_len); + if (tmp == NULL) + goto done; + xi18n_objects_list = tmp; + lc_len = new_len; } n = parse_line(p, args, 6); @@ -244,6 +240,7 @@ Limit the length of path to prevent stack buffer corruption. lc_count++; } } + done: fclose(fp); } @@ -383,9 +380,9 @@ _XlcDynamicLoad(const char *lc_name) if (lc_name == NULL) return (XLCd)NULL; - if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL) + if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XLCd)NULL; - if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL) + if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, lc_name) == NULL) return (XLCd)NULL; resolve_object(lc_dir, lc_name); @@ -512,7 +509,7 @@ _XDynamicUnRegisterIMInstantiateCallback( XPointer client_data) { char lc_dir[BUFSIZE]; - char *lc_name; + const char *lc_name; dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL; Bool ret_flag = False; int count; diff --git a/libX11/src/xlibi18n/XlcPubI.h b/libX11/src/xlibi18n/XlcPubI.h index 22ac2bdf0..a83d24305 100644 --- a/libX11/src/xlibi18n/XlcPubI.h +++ b/libX11/src/xlibi18n/XlcPubI.h @@ -207,13 +207,13 @@ extern int _XlcResolveI18NPath( extern char *_XlcLocaleLibDirName( char* /* dir_name */, size_t, /* dir_len */ - char* /* lc_name */ + const char* /* lc_name */ ); extern char *_XlcLocaleDirName( char* /* dir_name */, size_t, /* dir_len */ - char* /* lc_name */ + const char* /* lc_name */ ); extern XPointer _XlcCreateLocaleDataBase( diff --git a/libX11/src/xlibi18n/lcCT.c b/libX11/src/xlibi18n/lcCT.c index 2fbe8aa88..b1613007d 100644 --- a/libX11/src/xlibi18n/lcCT.c +++ b/libX11/src/xlibi18n/lcCT.c @@ -478,7 +478,7 @@ _XlcAddCT( /* Allocate a CTinfo record. */ length = strlen(ct_sequence); - ct_info = (CTInfo) Xmalloc(sizeof(CTInfoRec) + length+1); + ct_info = Xmalloc(sizeof(CTInfoRec) + length+1); if (ct_info == NULL) return charset; @@ -514,7 +514,7 @@ _XlcAddCT( Xfree(ct_info); return charset; } - p = (char *) Xmalloc(n+1); + p = Xmalloc(n+1); if (p == NULL) { Xfree(ct_info); return charset; @@ -970,7 +970,7 @@ cstoct( /* The CompoundText specification says that the only control characters allowed are 0x09, 0x0a, 0x1b, 0x9b. Therefore here we eliminate other control characters. */ - unsigned char ch = *((unsigned char *) csptr) & 0x7f; + unsigned char ch = *((const unsigned char *) csptr) & 0x7f; if (!((ch >= min_ch && ch <= max_ch) || (side == XlcGL && (ch == 0x00 || ch == 0x09 || ch == 0x0a)) @@ -1020,7 +1020,7 @@ cstoct( #endif ) { while (csstr_len > 0 && ct_len > 0) { - unsigned char ch = * (unsigned char *) csptr; + unsigned char ch = * (const unsigned char *) csptr; int char_size = (ch < 0xc0 ? 1 : ch < 0xe0 ? 2 : ch < 0xf0 ? 3 : @@ -1093,9 +1093,9 @@ strtocs( dst = (char *) *to; length = min(*from_left, *to_left); - side = *((unsigned char *) src) & 0x80; + side = *((const unsigned char *) src) & 0x80; - while (side == (*((unsigned char *) src) & 0x80) && length-- > 0) + while (side == (*((const unsigned char *) src) & 0x80) && length-- > 0) *dst++ = *src++; *from_left -= src - (const char *) *from; @@ -1140,7 +1140,7 @@ cstostr( str_len = *to_left; while (csstr_len > 0 && str_len > 0) { - ch = *((unsigned char *) csptr++); + ch = *((const unsigned char *) csptr++); csstr_len--; /* Citing ICCCM: "STRING as a type specifies the ISO Latin-1 character set plus the control characters TAB and NEWLINE." */ @@ -1169,7 +1169,7 @@ create_conv( { XlcConv conv; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + sizeof(StateRec)); + conv = Xmalloc(sizeof(XlcConvRec) + sizeof(StateRec)); if (conv == NULL) return (XlcConv) NULL; @@ -1187,7 +1187,7 @@ close_converter( XlcConv conv) { /* conv->state is allocated together with conv, free both at once. */ - Xfree((char *) conv); + Xfree(conv); } diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c index 5d287811c..0adf0adfc 100644 --- a/libX11/src/xlibi18n/lcCharSet.c +++ b/libX11/src/xlibi18n/lcCharSet.c @@ -92,7 +92,7 @@ _XlcAddCharSet( if (_XlcGetCharSet(charset->name)) return False; - list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec)); + list = Xmalloc(sizeof(XlcCharSetListRec)); if (list == NULL) return False; @@ -184,9 +184,9 @@ _XlcCreateDefaultCharSet( ct_sequence_len = strlen(ct_sequence); /* Fill in name and xrm_name. */ - tmp = (char *) Xmalloc(name_len + 1 + ct_sequence_len + 1); + tmp = Xmalloc(name_len + 1 + ct_sequence_len + 1); if (tmp == NULL) { - Xfree((char *) charset); + Xfree(charset); return (XlcCharSet) NULL; } memcpy(tmp, name, name_len+1); @@ -196,10 +196,10 @@ _XlcCreateDefaultCharSet( /* Fill in encoding_name and xrm_encoding_name. */ if ((colon = strchr(charset->name, ':')) != NULL) { unsigned int length = colon - charset->name; - char *encoding_tmp = (char *) Xmalloc(length + 1); + char *encoding_tmp = Xmalloc(length + 1); if (encoding_tmp == NULL) { Xfree((char *) charset->name); - Xfree((char *) charset); + Xfree(charset); return (XlcCharSet) NULL; } memcpy(encoding_tmp, charset->name, length); diff --git a/libX11/src/xlibi18n/lcConv.c b/libX11/src/xlibi18n/lcConv.c index 9797e7ed3..7d9a4738c 100644 --- a/libX11/src/xlibi18n/lcConv.c +++ b/libX11/src/xlibi18n/lcConv.c @@ -101,7 +101,7 @@ _XlcSetConverter( } } - list = (XlcConverterList) Xmalloc(sizeof(XlcConverterListRec)); + list = Xmalloc(sizeof(XlcConverterListRec)); if (list == NULL) return False; @@ -199,10 +199,10 @@ close_indirect_converter( if (conv->to_conv) close_converter(conv->to_conv); - Xfree((char *) conv); + Xfree(conv); } - Xfree((char *) lc_conv); + Xfree(lc_conv); } static void @@ -250,13 +250,13 @@ open_indirect_converter( to_type == QChar) return (XlcConv) NULL; - lc_conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + lc_conv = Xmalloc(sizeof(XlcConvRec)); if (lc_conv == NULL) return (XlcConv) NULL; lc_conv->methods = &conv_methods; - lc_conv->state = (XPointer) Xcalloc(1, sizeof(ConvRec)); + lc_conv->state = Xcalloc(1, sizeof(ConvRec)); if (lc_conv->state == NULL) goto err; diff --git a/libX11/src/xlibi18n/lcDB.c b/libX11/src/xlibi18n/lcDB.c index 7f13cc3e2..fca9758d8 100644 --- a/libX11/src/xlibi18n/lcDB.c +++ b/libX11/src/xlibi18n/lcDB.c @@ -168,7 +168,7 @@ init_parse_info (void) int size; if (!allocated) { bzero(&parse_info, sizeof(DBParseInfo)); - parse_info.buf = (char *)Xmalloc(BUFSIZE); + parse_info.buf = Xmalloc(BUFSIZE); parse_info.bufMaxSize = BUFSIZE; allocated = 1; return; @@ -199,7 +199,7 @@ clear_parse_info (void) if (*parse_info.value) { Xfree(*parse_info.value); } - Xfree((char *)parse_info.value); + Xfree(parse_info.value); } ptr = parse_info.buf; size = parse_info.bufMaxSize; @@ -213,11 +213,12 @@ realloc_parse_info( int len) { char *p; + int newsize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1); - parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1); - p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize); + p = Xrealloc(parse_info.buf, newsize); if (p == NULL) return False; + parse_info.bufMaxSize = newsize; parse_info.buf = p; return True; @@ -250,9 +251,9 @@ realloc_line( char *str = line->str; if (str != NULL) { - str = (char *)Xrealloc(str, size); + str = Xrealloc(str, size); } else { - str = (char *)Xmalloc(size); + str = Xmalloc(size); } if (str == NULL) { /* malloc error */ @@ -488,7 +489,7 @@ append_value_list (void) } if (value_list == (char **)NULL) { - value_list = (char **)Xmalloc(sizeof(char *) * 2); + value_list = Xmalloc(sizeof(char *) * 2); *value_list = NULL; } else { char **prev_list = value_list; @@ -504,11 +505,11 @@ append_value_list (void) value = *value_list; if (value == NULL) { - value = (char *)Xmalloc(value_len + len + 1); + value = Xmalloc(value_len + len + 1); } else { char *prev_value = value; - value = (char *)Xrealloc(value, value_len + len + 1); + value = Xrealloc(value, value_len + len + 1); if (value == NULL) { Xfree(prev_value); } @@ -1035,10 +1036,10 @@ DestroyDatabase( if (*p->value != NULL) { Xfree(*p->value); } - Xfree((char *)p->value); + Xfree(p->value); } db = p->next; - Xfree((char *)p); + Xfree(p); p = db; } } @@ -1251,7 +1252,7 @@ _XlcDestroyLocaleDataBase( if (p->lc_db == lc_db) { if ((-- p->ref_count) < 1) { if (p->lc_db != (XlcDatabase)NULL) { - Xfree((char *)p->lc_db); + Xfree(p->lc_db); } DestroyDatabase(p->database); if (prev == (XlcDatabaseList)NULL) { @@ -1316,7 +1317,7 @@ _XlcCreateLocaleDataBase( lc_db[i].db = p; } - new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec)); + new = Xmalloc(sizeof(XlcDatabaseListRec)); if (new == (XlcDatabaseList)NULL) { goto err; } @@ -1333,7 +1334,7 @@ _XlcCreateLocaleDataBase( err: DestroyDatabase(database); if (lc_db != (XlcDatabase)NULL) { - Xfree((char *)lc_db); + Xfree(lc_db); } Xfree (name); return (XPointer)NULL; diff --git a/libX11/src/xlibi18n/lcDynamic.c b/libX11/src/xlibi18n/lcDynamic.c index 8d022d885..a50aa70fa 100644 --- a/libX11/src/xlibi18n/lcDynamic.c +++ b/libX11/src/xlibi18n/lcDynamic.c @@ -65,8 +65,8 @@ _XlcDynamicLoader( XLCd lcd; void *nlshandler; - sprintf(libpath,"%s/%s/%s", - XLOCALEDIR,name,LCLIBNAME); + snprintf(libpath, sizeof(libpath), "%s/%s/%s", + XLOCALEDIR, name, LCLIBNAME); nlshandler = dlopen(libpath,LAZY); _XlcGenericMethods = (XLCdMethods)dlsym(nlshandler,"genericMethods"); lcd = _XlcCreateLC(name,_XlcGenericMethods); diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c index 51fe8bf1c..c3ea02ead 100644 --- a/libX11/src/xlibi18n/lcFile.c +++ b/libX11/src/xlibi18n/lcFile.c @@ -486,9 +486,11 @@ _XlcFileName( for (i = 0; i < n; ++i) { char buf[PATH_MAX], *name; + if (args[i] == NULL) + continue; + name = NULL; - if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) { - sprintf(buf, "%s/%s.dir", args[i], cat); + if (snprintf(buf, PATH_MAX, "%s/%s.dir", args[i], cat) < PATH_MAX) { name = resolve_name(siname, buf, RtoL); } if (name == NULL) { @@ -498,13 +500,13 @@ _XlcFileName( /* supposed to be absolute path name */ file_name = name; } else { - file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) + - (name ? strlen (name) : 0)); - if (file_name != NULL) - sprintf(file_name, "%s/%s", args[i], name); + if (snprintf(buf, PATH_MAX, "%s/%s", args[i], name) < PATH_MAX) + file_name = strdup(buf); + else + file_name = NULL; Xfree(name); } - if (isreadable(file_name)) { + if (file_name && isreadable(file_name)) { break; } Xfree(file_name); @@ -535,9 +537,11 @@ _XlcResolveLocaleName( xlocaledir (dir, PATH_MAX); n = _XlcParsePath(dir, args, NUM_LOCALEDIR); for (i = 0; i < n; ++i) { - if ((2 + (args[i] ? strlen (args[i]) : 0) + - strlen (locale_alias)) < PATH_MAX) { - sprintf (buf, "%s/%s", args[i], locale_alias); + if (args[i] == NULL) + continue; + + if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias) + < PATH_MAX) { name = resolve_name (lc_name, buf, LtoR); if (!name) { if (!nlc_name) @@ -611,14 +615,14 @@ _XlcResolveI18NPath(char *buf, int buf_len) } char * -_XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) +_XlcLocaleDirName(char *dir_name, size_t dir_len, const char *lc_name) { - char dir[PATH_MAX], buf[PATH_MAX], *name = NULL; + char dir[PATH_MAX], buf[PATH_MAX]; int i, n; char *args[NUM_LOCALEDIR]; static char locale_alias[] = LOCALE_ALIAS; - char *target_name = (char*)0; - char *target_dir = (char*)0; + char *target_name = NULL; + char *target_dir = NULL; char *nlc_name = NULL; static char* last_dir_name = 0; static size_t last_dir_len = 0; @@ -631,12 +635,15 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) } xlocaledir (dir, PATH_MAX); - n = _XlcParsePath(dir, args, 256); + n = _XlcParsePath(dir, args, NUM_LOCALEDIR); for (i = 0; i < n; ++i) { + char *name = NULL; - if ((2 + (args[i] ? strlen(args[i]) : 0) + - strlen(locale_alias)) < PATH_MAX) { - sprintf (buf, "%s/%s", args[i], locale_alias); + if (args[i] == NULL) + continue; + + if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias) + < PATH_MAX) { name = resolve_name(lc_name, buf, LtoR); if (!name) { if (!nlc_name) @@ -646,25 +653,15 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) } } - /* If name is not an alias, use lc_name for locale.dir search */ - if (name == NULL) - name = lc_name; - /* look at locale.dir */ target_dir = args[i]; - if (!target_dir) { - /* something wrong */ - if (name != lc_name) - Xfree(name); - continue; + if (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) { + /* If name is not an alias, use lc_name for locale.dir search */ + target_name = resolve_name(name ? name : lc_name, buf, RtoL); } - if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { - sprintf(buf, "%s/locale.dir", target_dir); - target_name = resolve_name(name, buf, RtoL); - } - if (name != lc_name) - Xfree(name); + Xfree(name); + name = NULL; if (target_name != NULL) { char *p = 0; if ((p = strstr(target_name, "/XLC_LOCALE"))) { @@ -674,27 +671,15 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) Xfree(target_name); target_name = NULL; } - name = NULL; } if (nlc_name) Xfree(nlc_name); - if (target_name == NULL) { + if (target_name == NULL) /* vendor locale name == Xlocale name, no expansion of alias */ - target_dir = args[0]; - target_name = lc_name; - } - /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */ - strncpy(dir_name, target_dir, dir_len - 1); - if (strlen(target_dir) >= dir_len - 1) { - dir_name[dir_len - 1] = '\0'; - } else { - strcat(dir_name, "/"); - strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1); - if (strlen(target_name) >= dir_len - strlen(dir_name) - 1) - dir_name[dir_len - 1] = '\0'; - } - if (target_name != lc_name) - Xfree(target_name); + snprintf(dir_name, dir_len, "%s/%s", args[0], lc_name); + else + snprintf(dir_name, dir_len, "%s/%s", target_dir, target_name); + Xfree(target_name); if (last_dir_name != 0) Xfree (last_dir_name); @@ -709,14 +694,14 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) } char * -_XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) +_XlcLocaleLibDirName(char *dir_name, size_t dir_len, const char *lc_name) { - char dir[PATH_MAX], buf[PATH_MAX], *name = NULL; + char dir[PATH_MAX], buf[PATH_MAX]; int i, n; char *args[NUM_LOCALEDIR]; static char locale_alias[] = LOCALE_ALIAS; - char *target_name = (char*)0; - char *target_dir = (char*)0; + char *target_name = NULL; + char *target_dir = NULL; char *nlc_name = NULL; static char* last_dir_name = 0; static size_t last_dir_len = 0; @@ -729,12 +714,15 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) } xlocalelibdir (dir, PATH_MAX); - n = _XlcParsePath(dir, args, 256); + n = _XlcParsePath(dir, args, NUM_LOCALEDIR); for (i = 0; i < n; ++i) { + char *name = NULL; + + if (args[i] == NULL) + continue; - if ((2 + (args[i] ? strlen(args[i]) : 0) + - strlen(locale_alias)) < PATH_MAX) { - sprintf (buf, "%s/%s", args[i], locale_alias); + if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias) + < PATH_MAX) { name = resolve_name(lc_name, buf, LtoR); if (!name) { if (!nlc_name) @@ -744,25 +732,15 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) } } - /* If name is not an alias, use lc_name for locale.dir search */ - if (name == NULL) - name = lc_name; - /* look at locale.dir */ target_dir = args[i]; - if (!target_dir) { - /* something wrong */ - if (name != lc_name) - Xfree(name); - continue; - } - if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { - sprintf(buf, "%s/locale.dir", target_dir); - target_name = resolve_name(name, buf, RtoL); + if (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) { + /* If name is not an alias, use lc_name for locale.dir search */ + target_name = resolve_name(name ? name : lc_name, buf, RtoL); } - if (name != lc_name) - Xfree(name); + Xfree(name); + name = NULL; if (target_name != NULL) { char *p = 0; if ((p = strstr(target_name, "/XLC_LOCALE"))) { @@ -772,27 +750,15 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) Xfree(target_name); target_name = NULL; } - name = NULL; } if (nlc_name) Xfree(nlc_name); - if (target_name == NULL) { + if (target_name == NULL) /* vendor locale name == Xlocale name, no expansion of alias */ - target_dir = args[0]; - target_name = lc_name; - } - /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */ - strncpy(dir_name, target_dir, dir_len - 1); - if (strlen(target_dir) >= dir_len - 1) { - dir_name[dir_len - 1] = '\0'; - } else { - strcat(dir_name, "/"); - strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1); - if (strlen(target_name) >= dir_len - strlen(dir_name) - 1) - dir_name[dir_len - 1] = '\0'; - } - if (target_name != lc_name) - Xfree(target_name); + snprintf(dir_name, dir_len, "%s/%s", args[0], lc_name); + else + snprintf(dir_name, dir_len, "%s/%s", target_dir, target_name); + Xfree(target_name); if (last_dir_name != 0) Xfree (last_dir_name); diff --git a/libX11/src/xlibi18n/lcGeneric.c b/libX11/src/xlibi18n/lcGeneric.c index bf85bfdbc..13405a65b 100644 --- a/libX11/src/xlibi18n/lcGeneric.c +++ b/libX11/src/xlibi18n/lcGeneric.c @@ -69,7 +69,7 @@ create( if (lcd->core == NULL) goto err; - new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); + new = Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) goto err; memcpy(new,methods,sizeof(XLCdPublicMethodsRec)); @@ -157,10 +157,10 @@ add_charset( int num; if ((num = codeset->num_charsets)) - new_list = (XlcCharSet *) Xrealloc(codeset->charset_list, + new_list = Xrealloc(codeset->charset_list, (num + 1) * sizeof(XlcCharSet)); else - new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet)); + new_list = Xmalloc(sizeof(XlcCharSet)); if (new_list == NULL) return False; @@ -184,10 +184,10 @@ add_codeset( return NULL; if ((num = gen->codeset_num)) - new_list = (CodeSet *) Xrealloc(gen->codeset_list, + new_list = Xrealloc(gen->codeset_list, (num + 1) * sizeof(CodeSet)); else - new_list = (CodeSet *) Xmalloc(sizeof(CodeSet)); + new_list = Xmalloc(sizeof(CodeSet)); if (new_list == NULL) goto err; @@ -231,10 +231,10 @@ add_parse_list( } if ((num = gen->mb_parse_list_num)) - new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list, + new_list = Xrealloc(gen->mb_parse_list, (num + 2) * sizeof(ParseInfo)); else { - new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo)); + new_list = Xmalloc(2 * sizeof(ParseInfo)); } if (new_list == NULL) @@ -352,7 +352,7 @@ _XlcParse_scopemaps( const char *str_sc; num = count_scopemap(str); - scope = (FontScope) Xmalloc(num * sizeof(FontScopeRec)); + scope = Xmalloc(num * sizeof(FontScopeRec)); if (scope == NULL) return NULL; @@ -429,17 +429,17 @@ read_charset_define( for (i=0; ; i++) { /* loop start */ charsetd = 0; - sprintf(csd, "csd%d", i); + snprintf(csd, sizeof(csd), "csd%d", i); /* charset_name */ - sprintf(name, "%s.%s", csd, "charset_name"); + snprintf(name, sizeof(name), "%s.%s", csd, "charset_name"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); _XlcDbg_printValue(name,value,num); if (num > 0) { /* hackers will get truncated -- C'est la vie */ strncpy(cset_name,value[0], sizeof cset_name - 1); cset_name[(sizeof cset_name) - 1] = '\0'; - sprintf(name, "%s.%s", csd , "side"); + snprintf(name, sizeof(name), "%s.%s", csd , "side"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -471,21 +471,21 @@ read_charset_define( /* side */ charsetd->side = side ; /* length */ - sprintf(name, "%s.%s", csd, "length"); + snprintf(name, sizeof(name), "%s.%s", csd, "length"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); charsetd->char_size = atoi(value[0]); } /* gc_number */ - sprintf(name, "%s.%s", csd, "gc_number"); + snprintf(name, sizeof(name), "%s.%s", csd, "gc_number"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); charsetd->set_size = atoi(value[0]); } /* string_encoding */ - sprintf(name, "%s.%s", csd, "string_encoding"); + snprintf(name, sizeof(name), "%s.%s", csd, "string_encoding"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -496,7 +496,7 @@ read_charset_define( } } /* sequence */ - sprintf(name, "%s.%s", csd, "sequence"); + snprintf(name, sizeof(name), "%s.%s", csd, "sequence"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -505,14 +505,14 @@ read_charset_define( Xfree(charsetd->ct_sequence); } */ - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = Xmalloc(strlen(value[0])+1); if (tmp == NULL) return; charsetd->ct_sequence = tmp; string_to_encoding(value[0],tmp); } /* encoding_name */ - sprintf(name, "%s.%s", csd, "encoding_name"); + snprintf(name, sizeof(name), "%s.%s", csd, "encoding_name"); _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -537,10 +537,10 @@ add_conversion( int num; if ((num = gen->segment_conv_num) > 0) { - new_list = (SegConv) Xrealloc(gen->segment_conv, + new_list = Xrealloc(gen->segment_conv, (num + 1) * sizeof(SegConvRec)); } else { - new_list = (SegConv) Xmalloc(sizeof(SegConvRec)); + new_list = Xmalloc(sizeof(SegConvRec)); } if (new_list == NULL) @@ -566,10 +566,10 @@ read_segmentconversion( SegConv conversion; for (i=0 ; ; i++) { /* loop start */ conversion = 0; - sprintf(conv, "conv%d", i); + snprintf(conv, sizeof(conv), "conv%d", i); /* length */ - sprintf(name, "%s.%s", conv, "length"); + snprintf(name, sizeof(name), "%s.%s", conv, "length"); _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); if (num > 0) { if (conversion == NULL && @@ -586,7 +586,7 @@ read_segmentconversion( conversion->length = atoi(value[0]); /* source_encoding */ - sprintf(name, "%s.%s", conv, "source_encoding"); + snprintf(name, sizeof(name), "%s.%s", conv, "source_encoding"); _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); if (num > 0) { char *tmp; @@ -598,7 +598,7 @@ read_segmentconversion( conversion->source = srch_charset_define(tmp,&new); } /* destination_encoding */ - sprintf(name, "%s.%s", conv, "destination_encoding"); + snprintf(name, sizeof(name), "%s.%s", conv, "destination_encoding"); _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); if (num > 0) { char *tmp; @@ -610,7 +610,7 @@ read_segmentconversion( conversion->dest = srch_charset_define(tmp,&new); } /* range */ - sprintf(name, "%s.%s", conv, "range"); + snprintf(name, sizeof(name), "%s.%s", conv, "range"); _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -618,7 +618,7 @@ read_segmentconversion( &(conversion->range.start), &(conversion->range.end)); } /* conversion */ - sprintf(name, "%s.%s", conv, "conversion"); + snprintf(name, sizeof(name), "%s.%s", conv, "conversion"); _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -636,9 +636,10 @@ create_ctextseg( ExtdSegment ret; char* ptr; char* cset_name = NULL; + size_t cset_len; int i,new; FontScope scope; - ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec)); + ret = Xmalloc(sizeof(ExtdSegmentRec)); if (ret == NULL) return NULL; ret->name = strdup(value[0]); @@ -646,7 +647,8 @@ create_ctextseg( Xfree (ret); return NULL; } - cset_name = (char*) Xmalloc (strlen(ret->name) + 1); + cset_len = strlen(ret->name) + 1; + cset_name = Xmalloc (cset_len); if (cset_name == NULL) { Xfree (ret->name); Xfree (ret); @@ -658,16 +660,16 @@ create_ctextseg( ptr++; if (!_XlcNCompareISOLatin1(ptr, "GL", 2)) { ret->side = XlcGL; - sprintf(cset_name,"%s:%s",ret->name,"GL"); + snprintf(cset_name, cset_len, "%s:%s", ret->name, "GL"); } else { ret->side = XlcGR; - sprintf(cset_name,"%s:%s",ret->name,"GR"); + snprintf(cset_name, cset_len, "%s:%s", ret->name, "GR"); } } else { ret->side = XlcGLGR; strcpy(cset_name,ret->name); } - ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec)); + ret->area = Xmalloc((num - 1)*sizeof(FontScopeRec)); if (ret->area == NULL) { Xfree (cset_name); Xfree (ret->name); @@ -732,10 +734,10 @@ load_generic( char cs[16]; char name[BUFSIZ]; - sprintf(cs, "cs%d", i); + snprintf(cs, sizeof(cs), "cs%d", i); /***** codeset.side *****/ - sprintf(name, "%s.%s", cs , "side"); + snprintf(name, sizeof(name), "%s.%s", cs , "side"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { char *tmp; @@ -762,7 +764,7 @@ load_generic( } /***** codeset.length *****/ - sprintf(name, "%s.%s", cs , "length"); + snprintf(name, sizeof(name), "%s.%s", cs , "length"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) @@ -773,7 +775,7 @@ load_generic( } /***** codeset.mb_encoding *****/ - sprintf(name, "%s.%s", cs, "mb_encoding"); + snprintf(name, sizeof(name), "%s.%s", cs, "mb_encoding"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { static struct { @@ -809,7 +811,7 @@ load_generic( } /***** codeset.wc_encoding *****/ - sprintf(name, "%s.%s", cs, "wc_encoding"); + snprintf(name, sizeof(name), "%s.%s", cs, "wc_encoding"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) @@ -820,7 +822,7 @@ load_generic( } /***** codeset.ct_encoding *****/ - sprintf(name, "%s.%s", cs, "ct_encoding"); + snprintf(name, sizeof(name), "%s.%s", cs, "ct_encoding"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { char *encoding; @@ -862,7 +864,7 @@ load_generic( unsigned long start,end; ByteInfo tmpb; - sprintf(name,"%s.%s%d",cs,"byte",M); + snprintf(name, sizeof(name),"%s.%s%d",cs,"byte",M); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (M == 1) { @@ -870,8 +872,7 @@ load_generic( codeset->byteM = NULL; break ; } - codeset->byteM = - (ByteInfoListRec *)Xmalloc( + codeset->byteM = Xmalloc( (codeset->length)*sizeof(ByteInfoListRec)); if (codeset->byteM == NULL) { goto err; @@ -883,7 +884,7 @@ load_generic( (codeset->byteM)[M-1].M = M; (codeset->byteM)[M-1].byteinfo_num = num; (codeset->byteM)[M-1].byteinfo = - (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec)); + Xmalloc(num * sizeof(ByteInfoRec)); for (ii = 0 ; ii < num ; ii++) { tmpb = (codeset->byteM)[M-1].byteinfo ; /* default 0x00 - 0xff */ @@ -897,7 +898,7 @@ load_generic( /***** codeset.mb_conversion *****/ - sprintf(name, "%s.%s", cs, "mb_conversion"); + snprintf(name, sizeof(name), "%s.%s", cs, "mb_conversion"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -909,7 +910,7 @@ load_generic( /* [\x%x,\x%x]->\x%x,... */ } /***** codeset.ct_conversion *****/ - sprintf(name, "%s.%s", cs, "ct_conversion"); + snprintf(name, sizeof(name), "%s.%s", cs, "ct_conversion"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); @@ -921,14 +922,14 @@ load_generic( /* [\x%x,\x%x]->\x%x,... */ } /***** codeset.ct_conversion_file *****/ - sprintf(name, "%s.%s", cs, "ct_conversion_file"); + snprintf(name, sizeof(name), "%s.%s", cs, "ct_conversion_file"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); /* [\x%x,\x%x]->\x%x,... */ } /***** codeset.ct_extended_segment *****/ - sprintf(name, "%s.%s", cs, "ct_extended_segment"); + snprintf(name, sizeof(name), "%s.%s", cs, "ct_extended_segment"); _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); if (num > 0) { _XlcDbg_printValue(name,value,num); diff --git a/libX11/src/xlibi18n/lcPrTxt.c b/libX11/src/xlibi18n/lcPrTxt.c index 1b7627cf8..47d11f096 100644 --- a/libX11/src/xlibi18n/lcPrTxt.c +++ b/libX11/src/xlibi18n/lcPrTxt.c @@ -40,11 +40,11 @@ alloc_list( if (is_wide_char) { wchar_t **wstr_list; - wstr_list = (wchar_t **) Xmalloc(count * sizeof(wchar_t *)); + wstr_list = Xmalloc(count * sizeof(wchar_t *)); if (wstr_list == NULL) return (XPointer *) NULL; - *wstr_list = (wchar_t *) Xmalloc(nitems * sizeof(wchar_t)); + *wstr_list = Xmalloc(nitems * sizeof(wchar_t)); if (*wstr_list == NULL) { Xfree(wstr_list); return (XPointer *) NULL; @@ -54,11 +54,11 @@ alloc_list( } else { char **str_list; - str_list = (char **) Xmalloc(count * sizeof(char *)); + str_list = Xmalloc(count * sizeof(char *)); if (str_list == NULL) return (XPointer *) NULL; - *str_list = (char *) Xmalloc(nitems); + *str_list = Xmalloc(nitems); if (*str_list == NULL) { Xfree(str_list); return (XPointer *) NULL; @@ -156,7 +156,7 @@ _XTextPropertyToTextList( else buf_len = text_prop->nitems * XLC_PUBLIC(lcd, mb_cur_max) + 1; } - buf = (XPointer) Xmalloc(buf_len); + buf = Xmalloc(buf_len); if (buf == NULL) return XNoMemory; to = buf; diff --git a/libX11/src/xlibi18n/lcPubWrap.c b/libX11/src/xlibi18n/lcPubWrap.c index 2a5ac08d8..d1096d570 100644 --- a/libX11/src/xlibi18n/lcPubWrap.c +++ b/libX11/src/xlibi18n/lcPubWrap.c @@ -78,7 +78,7 @@ _XlcCreateLC( return (XLCd) NULL; if (lcd->core->name == NULL) { - lcd->core->name = (char*) Xmalloc(strlen(name) + 1); + lcd->core->name = Xmalloc(strlen(name) + 1); if (lcd->core->name == NULL) goto err; strcpy(lcd->core->name, name); diff --git a/libX11/src/xlibi18n/lcPublic.c b/libX11/src/xlibi18n/lcPublic.c index 12a344272..46c652e2b 100644 --- a/libX11/src/xlibi18n/lcPublic.c +++ b/libX11/src/xlibi18n/lcPublic.c @@ -89,7 +89,7 @@ create( if (lcd->core == NULL) goto err; - new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); + new = Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) goto err; memcpy(new,methods,sizeof(XLCdPublicMethodsRec)); @@ -107,7 +107,8 @@ load_public( XLCd lcd) { XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd); - char **values, *str; + char **values; + const char *str; int num; if(_XlcCreateLocaleDataBase(lcd) == NULL) diff --git a/libX11/src/xlibi18n/lcRM.c b/libX11/src/xlibi18n/lcRM.c index 9f72504ee..bdc20f21d 100644 --- a/libX11/src/xlibi18n/lcRM.c +++ b/libX11/src/xlibi18n/lcRM.c @@ -85,7 +85,7 @@ ub_destroy( XPointer state) { _XCloseLC(((UbState) state)->lcd); - Xfree((char *) state); + Xfree(state); } static const XrmMethodsRec ub_methods = { @@ -177,7 +177,7 @@ mb_destroy( { _XlcCloseConverter(((MbState) state)->conv); _XCloseLC(((MbState) state)->lcd); - Xfree((char *) state); + Xfree(state); } static const XrmMethodsRec mb_methods = { @@ -197,7 +197,7 @@ _XrmDefaultInitParseInfo( { if (XLC_PUBLIC(lcd, mb_cur_max) == 1) { /* Unibyte case. */ - UbState state = (UbState) Xmalloc(sizeof(UbStateRec)); + UbState state = Xmalloc(sizeof(UbStateRec)); if (state == NULL) return (XrmMethods) NULL; @@ -207,14 +207,14 @@ _XrmDefaultInitParseInfo( return &ub_methods; } else { /* Multibyte case. */ - MbState state = (MbState) Xmalloc(sizeof(MbStateRec)); + MbState state = Xmalloc(sizeof(MbStateRec)); if (state == NULL) return (XrmMethods) NULL; state->lcd = lcd; state->conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); if (state->conv == NULL) { - Xfree((char *) state); + Xfree(state); return (XrmMethods) NULL; } diff --git a/libX11/src/xlibi18n/lcTxtPr.c b/libX11/src/xlibi18n/lcTxtPr.c index 4dfafe018..05f6a1ffe 100644 --- a/libX11/src/xlibi18n/lcTxtPr.c +++ b/libX11/src/xlibi18n/lcTxtPr.c @@ -89,7 +89,7 @@ _XTextListToTextProperty( is_wide_char = True; buf_len = get_buf_size(is_wide_char, list, count); - if ((buf = (char *) Xmalloc(buf_len)) == NULL) + if ((buf = Xmalloc(buf_len)) == NULL) return XNoMemory; switch (style) { @@ -194,7 +194,7 @@ retry: done: if (nitems <= 0) nitems = 1; - value = (char *) Xmalloc(nitems); + value = Xmalloc(nitems); if (value == NULL) { Xfree(buf); return XNoMemory; diff --git a/libX11/src/xlibi18n/lcUTF8.c b/libX11/src/xlibi18n/lcUTF8.c index 3e934b713..0f3d0d2ca 100644 --- a/libX11/src/xlibi18n/lcUTF8.c +++ b/libX11/src/xlibi18n/lcUTF8.c @@ -86,7 +86,7 @@ create_conv( { XlcConv conv; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = Xmalloc(sizeof(XlcConvRec)); if (conv == (XlcConv) NULL) return (XlcConv) NULL; @@ -100,7 +100,7 @@ static void close_converter( XlcConv conv) { - Xfree((char *) conv); + Xfree(conv); } /* Replacement character for invalid multibyte sequence or wide character. */ @@ -498,7 +498,7 @@ create_tocs_conv( if (charset_num > all_charsets_count-1) charset_num = all_charsets_count-1; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + conv = Xmalloc(sizeof(XlcConvRec) + (charset_num + 1) * sizeof(Utf8Conv)); if (conv == (XlcConv) NULL) return (XlcConv) NULL; @@ -539,7 +539,7 @@ close_tocs_converter( XlcConv conv) { /* conv->state is allocated together with conv, free both at once. */ - Xfree((char *) conv); + Xfree(conv); } /* @@ -961,7 +961,7 @@ create_ucstocs_conv( lazy_init_all_charsets(); - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + 2 * sizeof(Utf8Conv)); + conv = Xmalloc(sizeof(XlcConvRec) + 2 * sizeof(Utf8Conv)); if (conv == (XlcConv) NULL) return (XlcConv) NULL; preferred = (Utf8Conv *) ((char *) conv + sizeof(XlcConvRec)); @@ -1731,10 +1731,10 @@ create_tofontcs_conv( lazy_init_all_charsets(); for (i = 0, num = 0;; i++) { - sprintf(buf, "fs%d.charset.name", i); + snprintf(buf, sizeof(buf), "fs%d.charset.name", i); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) { - sprintf(buf, "fs%d.charset", i); + snprintf(buf, sizeof(buf), "fs%d.charset", i); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) break; @@ -1742,17 +1742,17 @@ create_tofontcs_conv( num += count; } - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec) + (num + 1) * sizeof(Utf8Conv)); + conv = Xmalloc(sizeof(XlcConvRec) + (num + 1) * sizeof(Utf8Conv)); if (conv == (XlcConv) NULL) return (XlcConv) NULL; preferred = (Utf8Conv *) ((char *) conv + sizeof(XlcConvRec)); /* Loop through all fontsets mentioned in the locale. */ for (i = 0, num = 0;; i++) { - sprintf(buf, "fs%d.charset.name", i); + snprintf(buf, sizeof(buf), "fs%d.charset.name", i); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) { - sprintf(buf, "fs%d.charset", i); + snprintf(buf, sizeof(buf), "fs%d.charset", i); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) break; diff --git a/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c b/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c index 1caa28a21..993979aeb 100644 --- a/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c +++ b/libX11/src/xlibi18n/lcUniConv/8bit_tab_to_h.c @@ -65,7 +65,7 @@ int main (int argc, char *argv[]) if (argc > 3) { filename = argv[3]; } else { - char* s = (char*) malloc(strlen(c_charsetname)+strlen(".h")+1); + char* s = malloc(strlen(c_charsetname)+strlen(".h")+1); strcpy(s,c_charsetname); strcat(s,".h"); filename = s; } @@ -361,11 +361,11 @@ int main (int argc, char *argv[]) if (tables[t].usecount > 1) { char* s; if (p == tables[t].minline >> 5) { - s = (char*) malloc(5+1); + s = malloc(5+1); sprintf(s, "%02x_%d", p, ++i); } else { p = tables[t].minline >> 5; - s = (char*) malloc(2+1); + s = malloc(2+1); sprintf(s, "%02x", p); } tables[t].suffix = s; diff --git a/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c b/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c index 6934789cf..f70fe5e11 100644 --- a/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c +++ b/libX11/src/xlibi18n/lcUniConv/cjk_tab_to_h.c @@ -70,9 +70,9 @@ static void read_table (Encoding* enc) { int row, col, i, i1, i2, c, j; - enc->charset2uni = (int**) malloc(enc->rows*sizeof(int*)); + enc->charset2uni = malloc(enc->rows*sizeof(int*)); for (row = 0; row < enc->rows; row++) - enc->charset2uni[row] = (int*) malloc(enc->cols*sizeof(int)); + enc->charset2uni[row] = malloc(enc->cols*sizeof(int)); for (row = 0; row < enc->rows; row++) for (col = 0; col < enc->cols; col++) @@ -136,7 +136,7 @@ static void find_charset2uni_pages (Encoding* enc) { int row, col; - enc->charsetpage = (int*) malloc((enc->rows+1)*sizeof(int)); + enc->charsetpage = malloc((enc->rows+1)*sizeof(int)); for (row = 0; row <= enc->rows; row++) enc->charsetpage[row] = 0; @@ -157,7 +157,7 @@ static void find_charset2uni_blocks (Encoding* enc) { int n, row, lastrow; - enc->charsetblocks = (Block*) malloc(enc->rows*sizeof(Block)); + enc->charsetblocks = malloc(enc->rows*sizeof(Block)); n = 0; for (row = 0; row < enc->rows; row++) @@ -266,7 +266,7 @@ static void invert (Encoding* enc) { int row, col, j; - enc->uni2charset = (int*) malloc(0x10000*sizeof(int)); + enc->uni2charset = malloc(0x10000*sizeof(int)); for (j = 0; j < 0x10000; j++) enc->uni2charset[j] = 0; @@ -764,9 +764,9 @@ static void read_table_ksc5601 (Encoding* enc) { int row, col, i, i1, i2, c, j; - enc->charset2uni = (int**) malloc(enc->rows*sizeof(int*)); + enc->charset2uni = malloc(enc->rows*sizeof(int*)); for (row = 0; row < enc->rows; row++) - enc->charset2uni[row] = (int*) malloc(enc->cols*sizeof(int)); + enc->charset2uni[row] = malloc(enc->cols*sizeof(int)); for (row = 0; row < enc->rows; row++) for (col = 0; col < enc->cols; col++) diff --git a/libX11/src/xlibi18n/lcWrap.c b/libX11/src/xlibi18n/lcWrap.c index c3f5ca531..034bd3c0d 100644 --- a/libX11/src/xlibi18n/lcWrap.c +++ b/libX11/src/xlibi18n/lcWrap.c @@ -77,20 +77,20 @@ XSetLocaleModifiers( { XLCd lcd = _XlcCurrentLC(); char *user_mods; + char *mapped_mods; if (!lcd) return (char *) NULL; if (!modifiers) return lcd->core->modifiers; user_mods = getenv("XMODIFIERS"); - modifiers = (*lcd->methods->map_modifiers) (lcd, - user_mods, (char *)modifiers); - if (modifiers) { + mapped_mods = (*lcd->methods->map_modifiers) (lcd, user_mods, modifiers); + if (mapped_mods) { if (lcd->core->modifiers) Xfree(lcd->core->modifiers); - lcd->core->modifiers = (char *)modifiers; + lcd->core->modifiers = mapped_mods; } - return (char *)modifiers; + return mapped_mods; } Bool @@ -218,7 +218,7 @@ _XlcAddLoader( _XlcRemoveLoader(proc); /* remove old loader, if exist */ - loader = (XlcLoaderList) Xmalloc(sizeof(XlcLoaderListRec)); + loader = Xmalloc(sizeof(XlcLoaderListRec)); if (loader == NULL) return False; @@ -293,7 +293,7 @@ _XOpenLC( for (loader = loader_list; loader; loader = loader->next) { lcd = (*loader->proc)(name); if (lcd) { - cur = (XLCdList) Xmalloc (sizeof(XLCdListRec)); + cur = Xmalloc (sizeof(XLCdListRec)); if (cur) { cur->lcd = lcd; cur->ref_count = 1; @@ -565,7 +565,7 @@ _XlcVaToArgList( { XlcArgList args; - *args_ret = args = (XlcArgList) Xmalloc(sizeof(XlcArg) * count); + *args_ret = args = Xmalloc(sizeof(XlcArg) * count); if (args == (XlcArgList) NULL) return; diff --git a/libX11/src/xlibi18n/mbWMProps.c b/libX11/src/xlibi18n/mbWMProps.c index bff7aa352..1b3dc970b 100644 --- a/libX11/src/xlibi18n/mbWMProps.c +++ b/libX11/src/xlibi18n/mbWMProps.c @@ -61,9 +61,9 @@ XmbSetWMProperties ( XSetWMProperties(dpy, w, wprop, iprop, argv, argc, sizeHints, wmHints, classHints); if (wprop) - Xfree((char *)wname.value); + Xfree(wname.value); if (iprop) - Xfree((char *)iname.value); + Xfree(iname.value); /* Note: The WM_LOCALE_NAME property is set by XSetWMProperties. */ } diff --git a/libX11/src/xlibi18n/mbWrap.c b/libX11/src/xlibi18n/mbWrap.c index 19f01f656..766b8da01 100644 --- a/libX11/src/xlibi18n/mbWrap.c +++ b/libX11/src/xlibi18n/mbWrap.c @@ -101,7 +101,7 @@ XmbDrawString( int text_len) { (void)(*font_set->methods->mb_draw_string) (dpy, d, font_set, gc, x, y, - (char *)text, text_len); + text, text_len); } @@ -117,7 +117,7 @@ XmbDrawImageString( int text_len) { (*font_set->methods->mb_draw_image_string) (dpy, d, font_set, gc, x, y, - (char *)text, text_len); + text, text_len); } int @@ -126,8 +126,7 @@ XmbTextEscapement( _Xconst char *text, int text_len) { - return (*font_set->methods->mb_escapement) (font_set, - (char *)text, text_len); + return (*font_set->methods->mb_escapement) (font_set, text, text_len); } int @@ -138,8 +137,7 @@ XmbTextExtents( XRectangle *overall_ink_extents, XRectangle *overall_logical_extents) { - return (*font_set->methods->mb_extents) (font_set, - (char *)text, text_len, + return (*font_set->methods->mb_extents) (font_set, text, text_len, overall_ink_extents, overall_logical_extents); } @@ -157,7 +155,7 @@ XmbTextPerCharExtents( XRectangle *max_logical_extents) { return (*font_set->methods->mb_extents_per_char) - (font_set, (char *)text, text_len, + (font_set, text, text_len, ink_extents_buffer, logical_extents_buffer, buffer_size, num_chars, max_ink_extents, max_logical_extents); } diff --git a/libX11/src/xlibi18n/utf8WMProps.c b/libX11/src/xlibi18n/utf8WMProps.c index bbfb7c057..80454e66d 100644 --- a/libX11/src/xlibi18n/utf8WMProps.c +++ b/libX11/src/xlibi18n/utf8WMProps.c @@ -83,9 +83,9 @@ Xutf8SetWMProperties ( XSetWMProperties(dpy, w, wprop, iprop, argv, argc, sizeHints, wmHints, classHints); if (wprop) - Xfree((char *)wname.value); + Xfree(wname.value); if (iprop) - Xfree((char *)iname.value); + Xfree(iname.value); /* Note: The WM_LOCALE_NAME property is set by XSetWMProperties. */ } diff --git a/libX11/src/xlibi18n/utf8Wrap.c b/libX11/src/xlibi18n/utf8Wrap.c index 82967b0b1..24cb4494c 100644 --- a/libX11/src/xlibi18n/utf8Wrap.c +++ b/libX11/src/xlibi18n/utf8Wrap.c @@ -123,7 +123,7 @@ Xutf8DrawString( int text_len) { (void)(*font_set->methods->utf8_draw_string) (dpy, d, font_set, gc, x, y, - (char *)text, text_len); + text, text_len); } @@ -139,7 +139,7 @@ Xutf8DrawImageString( int text_len) { (*font_set->methods->utf8_draw_image_string) (dpy, d, font_set, gc, x, y, - (char *)text, text_len); + text, text_len); } int @@ -148,8 +148,7 @@ Xutf8TextEscapement( _Xconst char *text, int text_len) { - return (*font_set->methods->utf8_escapement) (font_set, - (char *)text, text_len); + return (*font_set->methods->utf8_escapement) (font_set, text, text_len); } int @@ -160,8 +159,7 @@ Xutf8TextExtents( XRectangle *overall_ink_extents, XRectangle *overall_logical_extents) { - return (*font_set->methods->utf8_extents) (font_set, - (char *)text, text_len, + return (*font_set->methods->utf8_extents) (font_set, text, text_len, overall_ink_extents, overall_logical_extents); } @@ -179,7 +177,7 @@ Xutf8TextPerCharExtents( XRectangle *max_logical_extents) { return (*font_set->methods->utf8_extents_per_char) - (font_set, (char *)text, text_len, + (font_set, text, text_len, ink_extents_buffer, logical_extents_buffer, buffer_size, num_chars, max_ink_extents, max_logical_extents); } |