From f0b87f3de6261a4b95e6a68aa0a24b35b5278e56 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 15 Jun 2010 18:47:37 +0100 Subject: XStringToKeysym: Special case for XF86 keysyms Some XFree86 keysyms were in XKeysymDB as XF86_foo, despite really being XF86foo. So, if we get to the bottom of XStringToKeysym and haven't found our XF86_foo, try it again as XF86foo. Signed-off-by: Daniel Stone Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/StrKeysym.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/StrKeysym.c b/nx-X11/lib/X11/StrKeysym.c index 9bdc80d32..98629ed18 100644 --- a/nx-X11/lib/X11/StrKeysym.c +++ b/nx-X11/lib/X11/StrKeysym.c @@ -152,5 +152,18 @@ XStringToKeysym(_Xconst char *s) return val; return val | 0x01000000; } + + /* Stupid inconsistency between the headers and XKeysymDB: the former has + * no separating underscore, while some XF86* syms in the latter did. + * As a last ditch effort, try without. */ + if (strncmp(s, "XF86_", 5) == 0) { + KeySym ret; + char *tmp = strdup(s); + memmove(&tmp[4], &tmp[5], strlen(s) - 5 + 1); + ret = XStringToKeysym(tmp); + free(tmp); + return ret; + } + return NoSymbol; } -- cgit v1.2.3 From c1b175d3d1496fdbbad783e8cc0319ca954829b4 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 15 Jun 2010 18:49:43 +0100 Subject: Delete now-redundant XKeysymDB Since XStringToKeysym now supports all the vendor keysyms, just delete our XKeysymDB, which was incomplete at best, misleading at worst, and always an annoyance. Signed-off-by: Daniel Stone Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Imakefile | 3 - nx-X11/lib/X11/XKeysymDB | 382 ----------------------------------------------- 2 files changed, 385 deletions(-) delete mode 100644 nx-X11/lib/X11/XKeysymDB (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Imakefile b/nx-X11/lib/X11/Imakefile index 5a1fc5ff2..af0bcff41 100644 --- a/nx-X11/lib/X11/Imakefile +++ b/nx-X11/lib/X11/Imakefile @@ -159,7 +159,6 @@ EXTRA_LIBRARIES = /**/ XF86BIGFONT_DEFINES = XF86BigfontExtensionDefines EDB_DEFINES = -DERRORDB=\"$(USRDATADIR)/XErrorDB\" - KDB_DEFINES = -DKEYSYMDB=\"$(USRDATADIR)/XKeysymDB\" CMS_DEFINES = -DXCMSDB=\"$(USRDATADIR)/Xcms.txt\" #if HasSnprintf MISC_DEFINES = -DHAS_SNPRINTF -DLIBX11 @@ -1063,7 +1062,6 @@ EXTRASHAREDOBJS = $(STATICLCOBJS) #include SpecialCLibObjectRule(ErrDes,$(ICONFIGFILES),$(EDB_DEFINES)) -SpecialCLibObjectRule(StrKeysym,$(ICONFIGFILES),$(KDB_DEFINES)) SpecialCLibObjectRule(ConnDis,$(ICONFIGFILES),$(XDMAUTHDEFS) $(RPCDEFS) $(CONN_DEFINES) $(SOCK_DEFINES) $(POLL_DEFINES) $(XTRANS_X_DEFINES) $(K5INCL) $(K5DEFS)) SpecialCLibObjectRule(x11_trans,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES) $(XTRANS_X_DEFINES) $(POLL_DEFINES)) SpecialCLibObjectRule(xim_trans,$(ICONFIGFILES),$(TRANS_INCLUDES) $(CONN_DEFINES) $(SOCK_DEFINES) $(XTRANS_XIM_DEFINES) $(POLL_DEFINES)) @@ -1100,7 +1098,6 @@ SpecialCLibObjectRuleSeparateOpts(PutImage,$(ICONFIGFILES),$(_NOOP_),$(XCURSOR_D InstallNonExecFile(Xcms.txt,$(LIBDIR)) #endif InstallNonExecFile(XErrorDB,$(LIBDIR)) -InstallNonExecFile(XKeysymDB,$(LIBDIR)) InstallLintLibrary(X11,$(LINTLIBDIR)) #ifdef QNX4Architecture diff --git a/nx-X11/lib/X11/XKeysymDB b/nx-X11/lib/X11/XKeysymDB deleted file mode 100644 index cdd639955..000000000 --- a/nx-X11/lib/X11/XKeysymDB +++ /dev/null @@ -1,382 +0,0 @@ -! Copyright 1993 Massachusetts Institute of Technology -! -! 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, and that the name of M.I.T. not be used in advertising or -! publicity pertaining to distribution of the software without specific, -! written prior permission. M.I.T. makes no representations about the -! suitability of this software for any purpose. It is provided "as is" -! without express or implied warranty. -! - -hpmute_acute :100000A8 -hpmute_grave :100000A9 -hpmute_asciicircum :100000AA -hpmute_diaeresis :100000AB -hpmute_asciitilde :100000AC -hplira :100000AF -hpguilder :100000BE -hpYdiaeresis :100000EE -hpIO :100000EE -hplongminus :100000F6 -hpblock :100000FC -apLineDel :1000FF00 -apCharDel :1000FF01 -apCopy :1000FF02 -apCut :1000FF03 -apPaste :1000FF04 -apMove :1000FF05 -apGrow :1000FF06 -apCmd :1000FF07 -apShell :1000FF08 -apLeftBar :1000FF09 -apRightBar :1000FF0A -apLeftBox :1000FF0B -apRightBox :1000FF0C -apUpBox :1000FF0D -apDownBox :1000FF0E -apPop :1000FF0F -apRead :1000FF10 -apEdit :1000FF11 -apSave :1000FF12 -apExit :1000FF13 -apRepeat :1000FF14 -hpModelock1 :1000FF48 -hpModelock2 :1000FF49 -hpReset :1000FF6C -hpSystem :1000FF6D -hpUser :1000FF6E -hpClearLine :1000FF6F -hpInsertLine :1000FF70 -hpDeleteLine :1000FF71 -hpInsertChar :1000FF72 -hpDeleteChar :1000FF73 -hpBackTab :1000FF74 -hpKP_BackTab :1000FF75 -apKP_parenleft :1000FFA8 -apKP_parenright :1000FFA9 - -I2ND_FUNC_L :10004001 -I2ND_FUNC_R :10004002 -IREMOVE :10004003 -IREPEAT :10004004 -IA1 :10004101 -IA2 :10004102 -IA3 :10004103 -IA4 :10004104 -IA5 :10004105 -IA6 :10004106 -IA7 :10004107 -IA8 :10004108 -IA9 :10004109 -IA10 :1000410A -IA11 :1000410B -IA12 :1000410C -IA13 :1000410D -IA14 :1000410E -IA15 :1000410F -IB1 :10004201 -IB2 :10004202 -IB3 :10004203 -IB4 :10004204 -IB5 :10004205 -IB6 :10004206 -IB7 :10004207 -IB8 :10004208 -IB9 :10004209 -IB10 :1000420A -IB11 :1000420B -IB12 :1000420C -IB13 :1000420D -IB14 :1000420E -IB15 :1000420F -IB16 :10004210 - -DRemove :1000FF00 -Dring_accent :1000FEB0 -Dcircumflex_accent :1000FE5E -Dcedilla_accent :1000FE2C -Dacute_accent :1000FE27 -Dgrave_accent :1000FE60 -Dtilde :1000FE7E -Ddiaeresis :1000FE22 - -osfCopy :1004FF02 -osfCut :1004FF03 -osfPaste :1004FF04 -osfBackTab :1004FF07 -osfBackSpace :1004FF08 -osfClear :1004FF0B -osfEscape :1004FF1B -osfAddMode :1004FF31 -osfPrimaryPaste :1004FF32 -osfQuickPaste :1004FF33 -osfPageLeft :1004FF40 -osfPageUp :1004FF41 -osfPageDown :1004FF42 -osfPageRight :1004FF43 -osfActivate :1004FF44 -osfMenuBar :1004FF45 -osfLeft :1004FF51 -osfUp :1004FF52 -osfRight :1004FF53 -osfDown :1004FF54 -osfPrior :1004FF55 -osfNext :1004FF56 -osfEndLine :1004FF57 -osfBeginLine :1004FF58 -osfEndData :1004FF59 -osfBeginData :1004FF5A -osfPrevMenu :1004FF5B -osfNextMenu :1004FF5C -osfPrevField :1004FF5D -osfNextField :1004FF5E -osfSelect :1004FF60 -osfInsert :1004FF63 -osfUndo :1004FF65 -osfMenu :1004FF67 -osfCancel :1004FF69 -osfHelp :1004FF6A -osfSelectAll :1004FF71 -osfDeselectAll :1004FF72 -osfReselect :1004FF73 -osfExtend :1004FF74 -osfRestore :1004FF78 -osfSwitchDirection :1004FF7E -osfPriorMinor :1004FFF5 -osfNextMinor :1004FFF6 -osfRightLine :1004FFF7 -osfLeftLine :1004FFF8 -osfDelete :1004FFFF - -SunFA_Grave :1005FF00 -SunFA_Circum :1005FF01 -SunFA_Tilde :1005FF02 -SunFA_Acute :1005FF03 -SunFA_Diaeresis :1005FF04 -SunFA_Cedilla :1005FF05 -SunF36 :1005FF10 -SunF37 :1005FF11 -SunSys_Req :1005FF60 -SunProps :1005FF70 -SunFront :1005FF71 -SunCopy :1005FF72 -SunOpen :1005FF73 -SunPaste :1005FF74 -SunCut :1005FF75 -SunPowerSwitch :1005FF76 -SunAudioLowerVolume :1005FF77 -SunAudioMute :1005FF78 -SunAudioRaiseVolume :1005FF79 -SunVideoDegauss :1005FF7A -SunVideoLowerBrightness :1005FF7B -SunVideoRaiseBrightness :1005FF7C -SunPowerSwitchShift :1005FF7D - -SunCompose :FF20 -SunPageUp :FF55 -SunPageDown :FF56 -SunPrint_Screen :FF61 -SunUndo :FF65 -SunAgain :FF66 -SunFind :FF68 -SunStop :FF69 -SunAltGraph :FF7E - -WYSetup :1006FF00 - -ncdSetup :1006FF00 - -XeroxPointerButton1 :10070001 -XeroxPointerButton2 :10070002 -XeroxPointerButton3 :10070003 -XeroxPointerButton4 :10070004 -XeroxPointerButton5 :10070005 - -! The definitions here should match -XF86ModeLock :1008FF01 -XF86MonBrightnessUp :1008FF02 -XF86MonBrightnessDown :1008FF03 -XF86KbdLightOnOff :1008FF04 -XF86KbdBrightnessUp :1008FF05 -XF86KbdBrightnessDown :1008FF06 -XF86Standby :1008FF10 -XF86AudioLowerVolume :1008FF11 -XF86AudioMute :1008FF12 -XF86AudioRaiseVolume :1008FF13 -XF86AudioPlay :1008FF14 -XF86AudioStop :1008FF15 -XF86AudioPrev :1008FF16 -XF86AudioNext :1008FF17 -XF86HomePage :1008FF18 -XF86Mail :1008FF19 -XF86Start :1008FF1A -XF86Search :1008FF1B -XF86AudioRecord :1008FF1C -XF86Calculator :1008FF1D -XF86Memo :1008FF1E -XF86ToDoList :1008FF1F -XF86Calendar :1008FF20 -XF86PowerDown :1008FF21 -XF86ContrastAdjust :1008FF22 -XF86RockerUp :1008FF23 -XF86RockerDown :1008FF24 -XF86RockerEnter :1008FF25 -XF86Back :1008FF26 -XF86Forward :1008FF27 -XF86Stop :1008FF28 -XF86Refresh :1008FF29 -XF86PowerOff :1008FF2A -XF86WakeUp :1008FF2B -XF86Eject :1008FF2C -XF86ScreenSaver :1008FF2D -XF86WWW :1008FF2E -XF86Sleep :1008FF2F -XF86Favorites :1008FF30 -XF86AudioPause :1008FF31 -XF86AudioMedia :1008FF32 -XF86MyComputer :1008FF33 -XF86VendorHome :1008FF34 -XF86LightBulb :1008FF35 -XF86Shop :1008FF36 -XF86History :1008FF37 -XF86OpenURL :1008FF38 -XF86AddFavorite :1008FF39 -XF86HotLinks :1008FF3A -XF86BrightnessAdjust :1008FF3B -XF86Finance :1008FF3C -XF86Community :1008FF3D -XF86AudioRewind :1008FF3E -XF86BackForward :1008FF3F -XF86Launch0 :1008FF40 -XF86Launch1 :1008FF41 -XF86Launch2 :1008FF42 -XF86Launch3 :1008FF43 -XF86Launch4 :1008FF44 -XF86Launch5 :1008FF45 -XF86Launch6 :1008FF46 -XF86Launch7 :1008FF47 -XF86Launch8 :1008FF48 -XF86Launch9 :1008FF49 -XF86LaunchA :1008FF4A -XF86LaunchB :1008FF4B -XF86LaunchC :1008FF4C -XF86LaunchD :1008FF4D -XF86LaunchE :1008FF4E -XF86LaunchF :1008FF4F -XF86ApplicationLeft :1008FF50 -XF86ApplicationRight :1008FF51 -XF86Book :1008FF52 -XF86CD :1008FF53 -XF86Calculater :1008FF54 -XF86Clear :1008FF55 -XF86Close :1008FF56 -XF86Copy :1008FF57 -XF86Cut :1008FF58 -XF86Display :1008FF59 -XF86DOS :1008FF5A -XF86Documents :1008FF5B -XF86Excel :1008FF5C -XF86Explorer :1008FF5D -XF86Game :1008FF5E -XF86Go :1008FF5F -XF86iTouch :1008FF60 -XF86LogOff :1008FF61 -XF86Market :1008FF62 -XF86Meeting :1008FF63 -XF86MenuKB :1008FF65 -XF86MenuPB :1008FF66 -XF86MySites :1008FF67 -XF86New :1008FF68 -XF86News :1008FF69 -XF86OfficeHome :1008FF6A -XF86Open :1008FF6B -XF86Option :1008FF6C -XF86Paste :1008FF6D -XF86Phone :1008FF6E -XF86Q :1008FF70 -XF86Reply :1008FF72 -XF86Reload :1008FF73 -XF86RotateWindows :1008FF74 -XF86RotationPB :1008FF75 -XF86RotationKB :1008FF76 -XF86Save :1008FF77 -XF86ScrollUp :1008FF78 -XF86ScrollDown :1008FF79 -XF86ScrollClick :1008FF7A -XF86Send :1008FF7B -XF86Spell :1008FF7C -XF86SplitScreen :1008FF7D -XF86Support :1008FF7E -XF86TaskPane :1008FF7F -XF86Terminal :1008FF80 -XF86Tools :1008FF81 -XF86Travel :1008FF82 -XF86UserPB :1008FF84 -XF86User1KB :1008FF85 -XF86User2KB :1008FF86 -XF86Video :1008FF87 -XF86WheelButton :1008FF88 -XF86Word :1008FF89 -XF86Xfer :1008FF8A -XF86ZoomIn :1008FF8B -XF86ZoomOut :1008FF8C -XF86Away :1008FF8D -XF86Messenger :1008FF8E -XF86WebCam :1008FF8F -XF86MailForward :1008FF90 -XF86Pictures :1008FF91 -XF86Music :1008FF92 -XF86Battery :1008FF93 -XF86Bluetooth :1008FF94 -XF86WLAN :1008FF95 -XF86UWB :1008FF96 -XF86AudioForward :1008FF97 -XF86AudioRepeat :1008FF98 -XF86AudioRandomPlay :1008FF99 -XF86Subtitle :1008FF9A -XF86AudioCycleTrack :1008FF9B -XF86CycleAngle :1008FF9C -XF86FrameBack :1008FF9D -XF86FrameForward :1008FF9E -XF86Time :1008FF9F -XF86Select :1008FFA0 -XF86View :1008FFA1 -XF86TopMenu :1008FFA2 -XF86Red :1008FFA3 -XF86Green :1008FFA4 -XF86Yellow :1008FFA5 -XF86Blue :1008FFA6 -XF86Suspend :1008FFA7 -XF86Hibernate :1008FFA8 -XF86TouchpadToggle :1008FFA9 -XF86TouchpadOn :1008FFB0 -XF86TouchpadOff :1008FFB1 - -! XFree86 special action keys -XF86_Switch_VT_1 :1008FE01 -XF86_Switch_VT_2 :1008FE02 -XF86_Switch_VT_3 :1008FE03 -XF86_Switch_VT_4 :1008FE04 -XF86_Switch_VT_5 :1008FE05 -XF86_Switch_VT_6 :1008FE06 -XF86_Switch_VT_7 :1008FE07 -XF86_Switch_VT_8 :1008FE08 -XF86_Switch_VT_9 :1008FE09 -XF86_Switch_VT_10 :1008FE0A -XF86_Switch_VT_11 :1008FE0B -XF86_Switch_VT_12 :1008FE0C -XF86_Ungrab :1008FE20 -XF86_ClearGrab :1008FE21 -XF86_Next_VMode :1008FE22 -XF86_Prev_VMode :1008FE23 - -usldead_acute :100000A8 -usldead_grave :100000A9 -usldead_diaeresis :100000AB -usldead_asciicircum :100000AA -usldead_asciitilde :100000AC -usldead_cedilla :1000FE2C -usldead_ring :1000FEB0 -- cgit v1.2.3 From b414bc2c6f389224023c1d184d8aa0d18387512c Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Thu, 8 Jul 2010 16:49:51 +0100 Subject: XStringToKeysym: Check strdup() return value Signed-off-by: Daniel Stone Reviewed-by: Keith Packard Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/StrKeysym.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/StrKeysym.c b/nx-X11/lib/X11/StrKeysym.c index 98629ed18..a05e755e9 100644 --- a/nx-X11/lib/X11/StrKeysym.c +++ b/nx-X11/lib/X11/StrKeysym.c @@ -159,6 +159,8 @@ XStringToKeysym(_Xconst char *s) if (strncmp(s, "XF86_", 5) == 0) { KeySym ret; char *tmp = strdup(s); + if (!tmp) + return NoSymbol; memmove(&tmp[4], &tmp[5], strlen(s) - 5 + 1); ret = XStringToKeysym(tmp); free(tmp); -- cgit v1.2.3 From 93b55eeec022007d638c0a3b305765d44d3cd185 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 9 Jul 2010 18:13:13 +0100 Subject: XStringToKeysym: Cope with 0x1234cafe-style input If we get input in the style of 0xdeadbeef, just return that exact keysym. Introduces a dependency on strtoul, which I'm told is OK on all the systems we care about. Signed-off-by: Daniel Stone Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/StrKeysym.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/StrKeysym.c b/nx-X11/lib/X11/StrKeysym.c index a05e755e9..21dec924b 100644 --- a/nx-X11/lib/X11/StrKeysym.c +++ b/nx-X11/lib/X11/StrKeysym.c @@ -27,6 +27,7 @@ in this Software without prior written authorization from The Open Group. #ifdef HAVE_CONFIG_H #include #endif +#include #include "Xlibint.h" #include #include @@ -153,6 +154,15 @@ XStringToKeysym(_Xconst char *s) return val | 0x01000000; } + if (strlen(s) > 2 && s[0] == '0' && s[1] == 'x') { + char *tmp = NULL; + val = strtoul(s, &tmp, 16); + if (val == ULONG_MAX || (tmp && *tmp != '\0')) + return NoSymbol; + else + return val; + } + /* Stupid inconsistency between the headers and XKeysymDB: the former has * no separating underscore, while some XF86* syms in the latter did. * As a last ditch effort, try without. */ -- cgit v1.2.3 From 8ff526111bfc6ca8d2384c4d4962b8e8ff3621f9 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 4 Jun 2010 13:20:17 -0700 Subject: LINEAR_RGB_InitSCCData: When malloc fails, don't try to free unallocated bits One of the malloc failure checks had a goto to the wrong spot in the list of cleanup free() calls to unwind at the end, and was freeing bits that hadn't been initialized/allocated yet, since they would be stored in the struct that just failed to be allocated. Error: Null pointer dereference (CWE 476) Read from pointer that could be constant 'NULL' at line 805 of /export/alanc/X.Org/sx86/lib/libX11/nx-X11/lib/X11/LRGB.c in function 'LINEAR_RGB_InitSCCData'. Pointer checked against constant 'NULL' at line 754 but does not protect the dereference. [ This bug was found by the Parfait bug checking tool. For more information see http://research.sun.com/projects/parfait ] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/LRGB.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index dbdddb457..bc1bfd92b 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -753,7 +753,7 @@ LINEAR_RGB_InitSCCData( /* Blue Intensity Table */ if (!(pScreenData->pBlueTbl = (IntensityTbl *) Xcalloc (1, sizeof(IntensityTbl)))) { - goto FreeBlueTblElements; + goto FreeGreenTblElements; } if (_XcmsGetTableType1(pScreenData->pBlueTbl, format_return, &pChar, &nitems) == XcmsFailure) { -- cgit v1.2.3 From 1a72bc41460aa37b2ae6ce37bc9fb9e3644f5943 Mon Sep 17 00:00:00 2001 From: Pauli Nieminen Date: Mon, 3 Jan 2011 12:25:28 -0500 Subject: Initialize event type If we receive unsupported event closing connection triggers valgrind error. ==12017== Conditional jump or move depends on uninitialised value(s) ==12017== at 0x487D454: _XFreeDisplayStructure (OpenDis.c:607) ==12017== by 0x486857B: XCloseDisplay (ClDisplay.c:72) *snip* ==12017== Uninitialised value was created by a heap allocation ==12017== at 0x4834C48: malloc (vg_replace_malloc.c:236) ==12017== by 0x4894147: _XEnq (XlibInt.c:877) ==12017== by 0x4891BF3: handle_response (xcb_io.c:335) ==12017== by 0x4892263: _XReply (xcb_io.c:626) *snip* Problem is that XFreeDisplaySturture is checking for qelt->event.type == GenericEvent while _XUnknownWireEvent doesn't store the type. Reviewed-by: Adam Jackson Reviewed-by: Peter Hutterer Signed-off-by: Pauli Nieminen Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 7ca1d0d01..e4078ca31 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -2951,6 +2951,8 @@ void _XEnq( type = event->u.u.type & 0177; extension = ((xGenericEvent*)event)->extension; + + qelt->event.type = type; /* If an extension has registerd a generic_event_vec handler, then * it can handle event cookies. Otherwise, proceed with the normal * event handlers. -- cgit v1.2.3 From 8aacb3fab5824e20e07699cef93c5a20daaff368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 10 Jan 2011 16:17:47 +0200 Subject: Using freed pointer "e" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reordered code to first to do the comparison and then to release data Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index e4078ca31..917f503fa 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -2839,10 +2839,10 @@ _XFreeEventCookies(Display *dpy) head = (struct stored_event**)&dpy->cookiejar; DL_FOREACH_SAFE(*head, e, tmp) { - XFree(e->ev.data); - XFree(e); if (dpy->cookiejar == e) dpy->cookiejar = NULL; + XFree(e->ev.data); + XFree(e); } } -- cgit v1.2.3 From e175587865ccd01f1771f61cc05735158c8ba6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Thu, 27 Jan 2011 09:54:00 +0200 Subject: Dereferencing possibly NULL "str" in call to function "memcpy" (Deref assumed on the basis of 'nonnull' parameter attribute.) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If _XkbGetReadBufferPtr returns NULL, goto BAILOUT Reviewed-by: Dirk Wallenstein Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBList.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBList.c b/nx-X11/lib/X11/XKBList.c index 569e732b4..cdbb27063 100644 --- a/nx-X11/lib/X11/XKBList.c +++ b/nx-X11/lib/X11/XKBList.c @@ -79,6 +79,8 @@ char * str; if (!this->name) goto BAILOUT; str= (char *)_XkbGetReadBufferPtr(buf,wlen); + if (!str) + goto BAILOUT; memcpy(this->name,str,slen); } return first; -- cgit v1.2.3 From 3147ddbf47897688b61e95c18f255cbd8ccc0532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Wed, 12 Jan 2011 15:51:11 +0200 Subject: Variable "entry" tracked as NULL was dereferenced. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check entry for non-nullness before dereferencing it Reviewed-by: Dirk Wallenstein Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKB.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKB.c b/nx-X11/lib/X11/XKB.c index 008609608..a62e24282 100644 --- a/nx-X11/lib/X11/XKB.c +++ b/nx-X11/lib/X11/XKB.c @@ -462,7 +462,7 @@ XkbKTMapEntryPtr entry = NULL; if (map_rtrn!=NULL) { bzero(map_rtrn,type->mods.mask+1); for (i=0;imap_count;i++) { - if (entry->active) { + if (entry && entry->active) { map_rtrn[type->map[i].mods.mask]= type->map[i].level; } } -- cgit v1.2.3 From b7694b0b51cdf07f49d89132fbe100b5ebfb086b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Tue, 18 Jan 2011 12:49:48 +0200 Subject: Comparing array against NULL is not useful "&xkb->server->vmods != NULL" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed superfluous comparison. Reviewed-by: Dirk Wallenstein Signed-off-by: Erkki Seppälä Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBMisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBMisc.c b/nx-X11/lib/X11/XKBMisc.c index fbd7e6852..ea6bd4518 100644 --- a/nx-X11/lib/X11/XKBMisc.c +++ b/nx-X11/lib/X11/XKBMisc.c @@ -619,7 +619,7 @@ KeySym * syms; XkbApplyCompatMapToKey(xkb,key,changes); } - if ((xkb->server->vmods!=NULL)&&(xkb->map->modmap!=NULL)&&(changes)&& + if ((xkb->map->modmap!=NULL)&&(changes)&& (changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) { unsigned char newVMods[XkbNumVirtualMods]; register unsigned bit,i; -- cgit v1.2.3 From 54550ebb2a1fc504406b199550b8e023ef2c9517 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 1 Feb 2011 12:30:56 +0200 Subject: XDefaultOMIF.c: Fix memory leaks in get_font_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of copying the value returned by get_prop_name and then releasing it, directly use the return value of get_prop_name, which allocates memory for the name. If get_prop_name returns NULL, continue on to XFreeFont to release the font before returning the NULL via the normal function return. Reviewed-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index dbadd90aa..6975aa806 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -381,7 +381,7 @@ get_font_name( XOC oc, char *pattern) { - char **list, *name, *prop_name; + char **list, *name; int count; XFontStruct *fs; Display *dpy = oc->core.om->core.display; @@ -397,13 +397,7 @@ get_font_name( fs = XLoadQueryFont(dpy, pattern); if (fs == NULL) return NULL; - prop_name = get_prop_name(dpy, fs); - if (prop_name == NULL) return NULL; - - name = (char*) Xmalloc(strlen(prop_name) + 1); - if (name) - strcpy(name, prop_name); - + name = get_prop_name(dpy, fs); XFreeFont(dpy, fs); } return name; -- cgit v1.2.3 From 865043ea08c5f4effae397341b5faae8514f220e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:01:54 +0200 Subject: xcmx/cmxColNm: Removed unused assignments to pBuf (in two functions) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pointer "pBuf" returned from "fgets(buf, 256, stream)" is never used Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/cmsColNm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/cmsColNm.c b/nx-X11/lib/X11/cmsColNm.c index 5f9724822..12f23ce99 100644 --- a/nx-X11/lib/X11/cmsColNm.c +++ b/nx-X11/lib/X11/cmsColNm.c @@ -571,7 +571,7 @@ stringSectionSize( return(XcmsFailure); } - while((pBuf = fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) { + while((fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) { if ((sscanf(buf, "%s", token)) && (strcmp(token, END_TOKEN) == 0)) { break; } @@ -666,7 +666,7 @@ ReadColornameDB( * Process lines between START_TOKEN to END_TOKEN */ - while ((pBuf = fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) { + while ((fgets(buf, XCMSDB_MAXLINELEN, stream)) != NULL) { if ((sscanf(buf, "%s", token)) && (strcmp(token, END_TOKEN) == 0)) { /* * Found END_TOKEN so break out of for loop -- cgit v1.2.3 From 52d2c35580bd29d27ce8b8712a94be1042cabdda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:01:56 +0200 Subject: xlibi18n/lcGeneric: Initialize uninitialized local variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using uninitialized value "new" Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcGeneric.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index 69ea97db8..688a4cfc4 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -428,7 +428,7 @@ read_charset_define( char name[BUFSIZ]; XlcCharSet charsetd; char **value; - int num, new; + int num, new = 0; XlcSide side = XlcUnknown; char *tmp; -- cgit v1.2.3 From 1ac1b691d24af84db4061ca7b3fffb0f588e8f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:03 +0200 Subject: ImUtil: Handle a memory leak in one early return branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed memory leak by adding Xfree for image Variable "image" goes out of scope Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ImUtil.c | 1 + 1 file changed, 1 insertion(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ImUtil.c b/nx-X11/lib/X11/ImUtil.c index 00b6f7db8..d562e3ae0 100644 --- a/nx-X11/lib/X11/ImUtil.c +++ b/nx-X11/lib/X11/ImUtil.c @@ -372,6 +372,7 @@ XImage *XCreateImage ( if (image_bytes_per_line == 0) { image->bytes_per_line = min_bytes_per_line; } else if (image_bytes_per_line < min_bytes_per_line) { + Xfree(image); return NULL; } else { image->bytes_per_line = image_bytes_per_line; -- cgit v1.2.3 From afd1d4eb5378d3c7419021b33e9c55619c364c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:05 +0200 Subject: Xrm: NEWTABLE had a memory leak after a memory allocation error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NEWTABLE macro missed freeing its allocated memory on subsequent memory allocation errors. Added call to Xfree. Variable "table" goes out of scope Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xrm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 818e72906..2900816c1 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -842,8 +842,10 @@ static void PutEntry( nprev = NodeBuckets(table); \ } else { \ table->leaf = 1; \ - if (!(nprev = (NTable *)Xmalloc(sizeof(VEntry *)))) \ + if (!(nprev = (NTable *)Xmalloc(sizeof(VEntry *)))) {\ + Xfree(table); \ return; \ + } \ ((LTable)table)->buckets = (VEntry *)nprev; \ } \ *nprev = (NTable)NULL; \ -- cgit v1.2.3 From 8f5a56474671bf3dd4909aa73fec1062fb5a14d8 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Mon, 31 Jan 2011 14:02:08 +0200 Subject: xcms/LRGB: Fix potential resource leak. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit property_return was not free'd if the allocation of pRedTbl failed. Reviewed-by: Erkki Seppälä Signed-off-by: Ander Conselvan de Oliveira Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/LRGB.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index bc1bfd92b..534a7307e 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -687,6 +687,7 @@ LINEAR_RGB_InitSCCData( /* Red Intensity Table */ if (!(pScreenData->pRedTbl = (IntensityTbl *) Xcalloc (1, sizeof(IntensityTbl)))) { + XFree ((char * ) property_return); goto FreeSCCData; } if (_XcmsGetTableType0(pScreenData->pRedTbl, format_return, &pChar, @@ -724,6 +725,7 @@ LINEAR_RGB_InitSCCData( /* Red Intensity Table */ if (!(pScreenData->pRedTbl = (IntensityTbl *) Xcalloc (1, sizeof(IntensityTbl)))) { + XFree ((char * ) property_return); goto FreeSCCData; } if (_XcmsGetTableType1(pScreenData->pRedTbl, format_return, &pChar, -- cgit v1.2.3 From 7482afcaa71df7ed60909c3c3f995f4723190d4e Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Tue, 1 Feb 2011 11:07:25 +0200 Subject: xcms/LRGB: Add a label for freeing property_return. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rest of the code uses goto's to free memory allocated later and prevent memory leaks, but there were several paths were property_return was free'd just before a goto. Reviewed-by: Alan Coopersmith Signed-off-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/LRGB.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index 534a7307e..f2027ea3f 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -595,8 +595,7 @@ LINEAR_RGB_InitSCCData( * intensity2 */ if (nitems < 9) { - Xfree ((char *)property_return); - goto FreeSCCData; + goto Free_property_return; } count = 3; break; @@ -612,8 +611,7 @@ LINEAR_RGB_InitSCCData( * intensity2 */ if (nitems < 7) { - Xfree ((char *)property_return); - goto FreeSCCData; + goto Free_property_return; } count = 1; break; @@ -628,14 +626,12 @@ LINEAR_RGB_InitSCCData( * intensity2 */ if (nitems < 6) { - Xfree ((char *)property_return); - goto FreeSCCData; + goto Free_property_return; } count = 0; break; default: - Xfree ((char *)property_return); - goto FreeSCCData; + goto Free_property_return; } /* @@ -687,8 +683,7 @@ LINEAR_RGB_InitSCCData( /* Red Intensity Table */ if (!(pScreenData->pRedTbl = (IntensityTbl *) Xcalloc (1, sizeof(IntensityTbl)))) { - XFree ((char * ) property_return); - goto FreeSCCData; + goto Free_property_return; } if (_XcmsGetTableType0(pScreenData->pRedTbl, format_return, &pChar, &nitems) == XcmsFailure) { @@ -725,8 +720,7 @@ LINEAR_RGB_InitSCCData( /* Red Intensity Table */ if (!(pScreenData->pRedTbl = (IntensityTbl *) Xcalloc (1, sizeof(IntensityTbl)))) { - XFree ((char * ) property_return); - goto FreeSCCData; + goto Free_property_return; } if (_XcmsGetTableType1(pScreenData->pRedTbl, format_return, &pChar, &nitems) == XcmsFailure) { @@ -763,8 +757,7 @@ LINEAR_RGB_InitSCCData( } } } else { - Xfree ((char *)property_return); - goto FreeSCCData; + goto Free_property_return; } #ifdef ALLDEBUG @@ -821,6 +814,9 @@ FreeRedTblElements: FreeRedTbl: Xfree((char *)pScreenData->pRedTbl); +Free_property_return: + Xfree ((char *)property_return); + FreeSCCData: Xfree((char *)pScreenData); pPerScrnInfo->state = XcmsInitNone; -- cgit v1.2.3 From 698270c47b3b78e3e746c4767a277c5e1e73ec14 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Mon, 31 Jan 2011 14:02:12 +0200 Subject: XlibInt: info_list->watch_data was reallocated, but result was discarded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit info_list->watch_data was being reallocated, but the return value of the reallocation was stored only into a local variable. This might cause some funky behavior and crashes. Variable "wd_array" goes out of scope Value "wd_array" is overwritten in "wd_array = (XPointer*)realloc((char*)info_list->watch_data, (((dpy->watcher_count + 1) * 4U == 0U) ? 1U : ((dpy->watcher_count + 1) * 4U)))" Reviewed-by: Alan Coopersmith Reviewed-by: Erkki Seppälä Signed-off-by: Ander Conselvan de Oliveira Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 917f503fa..23717fd7f 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -2673,6 +2673,7 @@ XAddConnectionWatch( UnlockDisplay(dpy); return 0; } + info_list->watch_data = wd_array; wd_array[dpy->watcher_count] = NULL; /* for cleanliness */ } -- cgit v1.2.3 From 7576f5f150ee5d6cb32ebc55d2a5b32bd642a32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:16 +0200 Subject: xlibi18n/lcFile: Removed superfluous check for NULL target_dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The situation is already handled before this code. Cannot reach dead expression "0U" inside statement "if (1U + (target_dir ? strl..." Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcFile.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index 8c2e7c062..e657e707f 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -663,8 +663,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) Xfree(name); continue; } - if ((1 + (target_dir ? strlen (target_dir) : 0) + - strlen("locale.dir")) < PATH_MAX) { + if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { sprintf(buf, "%s/locale.dir", target_dir); target_name = resolve_name(name, buf, RtoL); } @@ -763,8 +762,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) Xfree(name); continue; } - if ((1 + (target_dir ? strlen (target_dir) : 0) + - strlen("locale.dir")) < PATH_MAX) { + if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { sprintf(buf, "%s/locale.dir", target_dir); target_name = resolve_name(name, buf, RtoL); } -- cgit v1.2.3 From 20470a83e3a57f936cd90856325b897fa115b9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:01:57 +0200 Subject: XlibInt: Use strncpy+zero termination instead of strcpy to enforce buffer size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Possible overrun of 8192 byte fixed size buffer "buffer" by copying "ext->name" without length checking Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 23717fd7f..151e521bd 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -3528,9 +3528,10 @@ static int _XPrintDefaultError( ext && (ext->codes.major_opcode != event->request_code); ext = ext->next) ; - if (ext) - strcpy(buffer, ext->name); - else + if (ext) { + strncpy(buffer, ext->name, BUFSIZ); + buffer[BUFSIZ - 1] = '\0'; + } else buffer[0] = '\0'; } (void) fprintf(fp, " (%s)\n", buffer); -- cgit v1.2.3 From 563318af91403e1bd732141715e77c8caf6108f7 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 2 Feb 2011 08:56:00 -0800 Subject: Expand GetSizeOfFile() macro at the one place it's called Removes XrmI.h header that only contained this single macro Signed-off-by: Alan Coopersmith Reviewed-by: Julien Cristau Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xrm.c | 10 ++++++++-- nx-X11/lib/X11/XrmI.h | 48 ------------------------------------------------ 2 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 nx-X11/lib/X11/XrmI.h (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 2900816c1..4a47d2d0c 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -60,8 +60,8 @@ from The Open Group. #ifdef XTHREADS #include "locking.h" #endif -#include "XrmI.h" #include +#include #include "Xresinternal.h" #include "Xresource.h" @@ -1597,7 +1597,13 @@ ReadInFile(_Xconst char *filename) * result that the number of bytes actually read with be <= * to the size returned by fstat. */ - GetSizeOfFile(fd, size); + { + struct stat status_buffer; + if ( (fstat(fd, &status_buffer)) == -1 ) + size = -1; + else + size = status_buffer.st_size; + } /* There might have been a problem trying to stat a file */ if (size == -1) { diff --git a/nx-X11/lib/X11/XrmI.h b/nx-X11/lib/X11/XrmI.h deleted file mode 100644 index 63ed257ed..000000000 --- a/nx-X11/lib/X11/XrmI.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - -Copyright 1990, 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. - -*/ - - -/* - * Macros to abstract out reading the file, and getting its size. - * - * You may need to redefine these for various other operating systems. - */ - -#include -#include -#include - -#define GetSizeOfFile(fd,size) \ -{ \ - struct stat status_buffer; \ - if ( ((fstat((fd), &status_buffer)) == -1 ) || \ - (status_buffer.st_size >= INT_MAX) ) \ - size = -1; \ - else \ - size = status_buffer.st_size; \ -} -- cgit v1.2.3 From 26270ab1cf15520043b1d138916fce394780e279 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 2 Feb 2011 08:58:45 -0800 Subject: Xrm.c: ReadInFile: refactor fstat error handling We can simplify the fstat failure case now that the GetFileSize macro has been expanded inline. Signed-off-by: Alan Coopersmith Reviewed-by: Julien Cristau Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xrm.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 4a47d2d0c..81fbfaf35 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -1599,18 +1599,13 @@ ReadInFile(_Xconst char *filename) */ { struct stat status_buffer; - if ( (fstat(fd, &status_buffer)) == -1 ) - size = -1; - else + if ( (fstat(fd, &status_buffer)) == -1 ) { + close (fd); + return (char *)NULL; + } else size = status_buffer.st_size; } - /* There might have been a problem trying to stat a file */ - if (size == -1) { - close (fd); - return (char *)NULL; - } - if (!(filebuf = Xmalloc(size + 1))) { /* leave room for '\0' */ close(fd); return (char *)NULL; -- cgit v1.2.3 From ae4e7538e078aff5db75af7b5fafdbb5658cbbb6 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Mon, 31 Jan 2011 14:02:07 +0200 Subject: xcms/LRGB: don't double-free property_return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit property_return was free'd before and in the case the conditional is true, the call to XcmsGetProperty failed which means that property_return wasn't set so there is no need to free it again. Double free of pointer "property_return" in call to "free" Reviewed-by: Alan Coopersmith Reviewed-by: Erkki Seppälä Signed-off-by: Ander Conselvan de Oliveira Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/LRGB.c | 1 - 1 file changed, 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index f2027ea3f..08c7105ab 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -573,7 +573,6 @@ LINEAR_RGB_InitSCCData( if (CorrectAtom == None || !_XcmsGetProperty (dpy, RootWindow(dpy, screenNumber), CorrectAtom, &format_return, &nitems, &nbytes_return, &property_return)) { - Xfree ((char *)property_return); goto FreeSCCData; } -- cgit v1.2.3 From 07fae919a4474abfb55f41ed3d07bf93e74e9154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Thu, 3 Feb 2011 17:08:57 +0200 Subject: cmsProp: don't deal with uninitialized values, fail instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Properly handle the return value of XGetWindowProperty by considering if after the loop as well. Using freed pointer "prop_ret" There were numerous things wrong in how this function interacted with XGetWindowProperty. None of the local variables were initialized and remained that way if the call to XGetWindowProperty returned 1 (not Succeed). That doesn't result in after_ret being initialized in which case if it happens to be 0, the loop was exited. In that case format_ret and nitems_ret were uninitialized and the function might return with success (but with uninitialized pointer in prop_ret) or XcmsFailure. As the buffer enlarging code was called only when XGetWindowProperty failed (returned not Success), after_ret would not have been initialized. It would have been initialized only if the XGetWindowProperty has returned Success earlier, but in that case the code fragment would not have been reached. This patch alters the function to return XcmsFailure if the call to XGetWindowProperty fails. Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Reviewed-by: Rami Ylimäki Signed-off-by: Erkki Seppälä Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/cmsProp.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/cmsProp.c b/nx-X11/lib/X11/cmsProp.c index 0e8f8a2ba..7e1a70310 100644 --- a/nx-X11/lib/X11/cmsProp.c +++ b/nx-X11/lib/X11/cmsProp.c @@ -125,20 +125,23 @@ _XcmsGetProperty( unsigned long nitems_ret, after_ret; #endif Atom atom_ret; + int xgwp_ret; - while (XGetWindowProperty (pDpy, w, property, 0, len, False, - XA_INTEGER, &atom_ret, &format_ret, - &nitems_ret, &after_ret, - (unsigned char **)&prop_ret)) { - if (after_ret > 0) { + while (True) { + xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, + XA_INTEGER, &atom_ret, &format_ret, + &nitems_ret, &after_ret, + (unsigned char **)&prop_ret); + if (xgwp_ret == Success && after_ret > 0) { len += nitems_ret * (format_ret >> 3); XFree (prop_ret); } else { break; } } - if (format_ret == 0 || nitems_ret == 0) { - /* the property does not exist or is of an unexpected type */ + if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { + /* the property does not exist or is of an unexpected type or + getting window property failed */ return(XcmsFailure); } -- cgit v1.2.3 From 2618bd3fc7274be77d7b2cf87018dc21c779bdfa Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 11 Feb 2011 14:49:17 -0800 Subject: Clean up memory when first XCreateRegion succeeds and second fails Error: Memory leak (CWE 401) Memory leak of pointer 's' allocated with XCreateRegion() at line 387 of /export/alanc/X.Org/sx86-gcc/lib/libX11/nx-X11/lib/X11/Region.c in function 'XShrinkRegion'. 's' allocated at line 387 with XCreateRegion(). s leaks when s != 0 at line 387. Error: Memory leak (CWE 401) Memory leak of pointer 'tra' allocated with XCreateRegion() at line 1452 of /export/alanc/X.Org/sx86-gcc/lib/libX11/nx-X11/lib/X11/Region.c in function 'XXorRegion'. 'tra' allocated at line 1451 with XCreateRegion(). tra leaks when tra != 0 at line 1451. [ This bug was found by the Parfait 0.3.6 bug checking tool. For more information see http://labs.oracle.com/projects/parfait/ ] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Region.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Region.c b/nx-X11/lib/X11/Region.c index 5ce276279..5491dbd0e 100644 --- a/nx-X11/lib/X11/Region.c +++ b/nx-X11/lib/X11/Region.c @@ -384,7 +384,12 @@ XShrinkRegion( int grow; if (!dx && !dy) return 0; - if ((! (s = XCreateRegion())) || (! (t = XCreateRegion()))) return 0; + if (! (s = XCreateRegion()) ) + return 0; + if (! (t = XCreateRegion()) ) { + XDestroyRegion(s); + return 0; + } if ((grow = (dx < 0))) dx = -dx; if (dx) Compress(r, s, t, (unsigned) 2*dx, TRUE, grow); if ((grow = (dy < 0))) dy = -dy; @@ -1448,8 +1453,12 @@ XXorRegion(Region sra, Region srb, Region dr) { Region tra, trb; - if ((! (tra = XCreateRegion())) || (! (trb = XCreateRegion()))) + if (! (tra = XCreateRegion()) ) return 0; + if (! (trb = XCreateRegion()) ) { + XDestroyRegion(tra); + return 0; + } (void) XSubtractRegion(sra,srb,tra); (void) XSubtractRegion(srb,sra,trb); (void) XUnionRegion(tra,trb,dr); -- cgit v1.2.3 From bbeee4fd14a664bdf3b305fb7a959583db52241f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 10 Jan 2011 16:37:22 +0200 Subject: keyBind: Use Xcalloc to initialize allocated _XKeytrans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using uninitialized value "p->modifiers" Small fix by using Xcalloc instead of Xmalloc Signed-off-by: Erkki Seppälä Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/KeyBind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index c7f17c4da..bd29cc782 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/KeyBind.c @@ -996,7 +996,7 @@ XRebindKeysym ( tmp = dpy->key_bindings; nb = sizeof(KeySym) * nm; - if ((! (p = (struct _XKeytrans *) Xmalloc( sizeof(struct _XKeytrans)))) || + if ((! (p = (struct _XKeytrans *) Xcalloc( 1, sizeof(struct _XKeytrans)))) || ((! (p->string = (char *) Xmalloc( (unsigned) nbytes))) && (nbytes > 0)) || ((! (p->modifiers = (KeySym *) Xmalloc( (unsigned) nb))) && -- cgit v1.2.3 From 29ad23b980bd03b0796a8f6cfaace347d9db213a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Tue, 18 Jan 2011 15:58:20 +0200 Subject: xkb: XkbPropertyPtr determined allocation success from wrong variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cannot reach dead statement "return NULL;" Check for the NULLness of prop->name and prop->value instead of name and value, which was checked earlier anyway. Decided against using strdup due to curious memory allocation functions and the rest of the xkb not using it either. Signed-off-by: Erkki Seppälä Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGAlloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index 46b997b7f..489d41b78 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -696,11 +696,11 @@ register XkbPropertyPtr prop; } prop= &geom->properties[geom->num_properties]; prop->name= (char *)_XkbAlloc(strlen(name)+1); - if (!name) + if (!prop->name) return NULL; strcpy(prop->name,name); prop->value= (char *)_XkbAlloc(strlen(value)+1); - if (!value) { + if (!prop->value) { _XkbFree(prop->name); prop->name= NULL; return NULL; -- cgit v1.2.3 From 417e0411133ab2be648648d695fc51d4f1b13f3e Mon Sep 17 00:00:00 2001 From: Harshula Jayasuriya Date: Mon, 21 Mar 2011 14:49:37 +0000 Subject: Add #define XK_SINHALA Add #define XK_SINHALA so that the Sinhala keysyms can be used by the lk xkb keymap. Signed-off-by: Harshula Jayasuriya Reviewed-by: Daniel Stone Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/KeyBind.c | 1 + 1 file changed, 1 insertion(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index bd29cc782..a50a7b2cc 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/KeyBind.c @@ -44,6 +44,7 @@ in this Software without prior written authorization from The Open Group. #define XK_CAUCASUS #define XK_VIETNAMESE #define XK_XKB_KEYS +#define XK_SINHALA #include #include -- cgit v1.2.3 From 0f7148695beddf0a9fd9803547f48d3db1368c86 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Wed, 23 Mar 2011 14:36:22 +0200 Subject: Fix memory leak with broken bitmap files in XReadBitmapFileData Bitmap file data is read looping through the lines in the input file. If there is extra data after the bitmap, these lines will be processed and if this data represents another bitmap it will replace the one read before causing the memory allocated for bits to leak. This changes the code to stop processing the file once a bitmap was read. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/RdBitF.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/RdBitF.c b/nx-X11/lib/X11/RdBitF.c index b3c21bc53..2ec100aa3 100644 --- a/nx-X11/lib/X11/RdBitF.c +++ b/nx-X11/lib/X11/RdBitF.c @@ -216,6 +216,11 @@ XReadBitmapFileData ( *ptr=value; } } + + /* If we got to this point, we read a full bitmap file. Break so we don't + * start reading another one from the same file and leak the memory + * allocated for the previous one. */ + break; } /* end while */ fclose(fstream); -- cgit v1.2.3 From dce81504f91a0db92e0a3cdaa173a5e64cd2c213 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 14:17:44 +0200 Subject: FSWrap: fix potential leak in copy_string_list If list_count is 0, dst would be allocated and leaked. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FSWrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FSWrap.c b/nx-X11/lib/X11/FSWrap.c index 35bf33d2a..df65654a9 100644 --- a/nx-X11/lib/X11/FSWrap.c +++ b/nx-X11/lib/X11/FSWrap.c @@ -131,7 +131,7 @@ copy_string_list( char **string_list_ret, **list_src, **list_dst, *dst; int length, count; - if (string_list == NULL) + if (string_list == NULL || list_count == 0) return (char **) NULL; string_list_ret = (char **) Xmalloc(sizeof(char *) * list_count); -- cgit v1.2.3 From fefb909a07d633986e9850dbe3baa91cd1531920 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Wed, 30 Mar 2011 15:19:28 +0300 Subject: xcms: Fix error on LINEAR_RGB_InitSCCData error path. Due to what looks like a copy & paste error, pScreenData->pBlueTbl would be accessed after being free'd. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/LRGB.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index 08c7105ab..82f5de757 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -802,7 +802,7 @@ FreeBlueTbl: Xfree((char *)pScreenData->pBlueTbl); FreeGreenTblElements: - Xfree((char *)pScreenData->pBlueTbl->pBase); + Xfree((char *)pScreenData->pGreenTbl->pBase); FreeGreenTbl: Xfree((char *)pScreenData->pGreenTbl); -- cgit v1.2.3 From f50e651e8acd28f3798d31038b6b9804b8309a89 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Wed, 30 Mar 2011 15:06:10 +0300 Subject: xcms: Fix memory leaks on LINEAR_RGB_InitSCCData error path. pScreenData is replaced when building per visual intensity tables. If malloc failed the old value of pScreenData (stored also in pScreenDefaultData) was being leaked. Also, property_return wasn't free'd in that case. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/LRGB.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index 82f5de757..ef1d7fb27 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -653,7 +653,7 @@ LINEAR_RGB_InitSCCData( */ if (!(pScreenData = (LINEAR_RGB_SCCData *) Xcalloc (1, sizeof(LINEAR_RGB_SCCData)))) { - return(XcmsFailure); + goto Free_property_return; } /* copy matrices */ memcpy((char *)pScreenData, (char *)pScreenDefaultData, @@ -663,7 +663,7 @@ LINEAR_RGB_InitSCCData( if (!(pNewMap = (XcmsIntensityMap *) Xcalloc (1, sizeof(XcmsIntensityMap)))) { Xfree((char *)pScreenData); - return(XcmsFailure); + goto Free_property_return; } pNewMap->visualID = visualID; pNewMap->screenData = (XPointer)pScreenData; @@ -817,7 +817,7 @@ Free_property_return: Xfree ((char *)property_return); FreeSCCData: - Xfree((char *)pScreenData); + Xfree((char *)pScreenDefaultData); pPerScrnInfo->state = XcmsInitNone; return(XcmsFailure); } -- cgit v1.2.3 From 369c956683108226a30bbdd55355f0d8ae57eeb4 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 19:42:36 +0200 Subject: Fix memory leaks on _XimGetAttributeID error paths. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRmAttr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index b6d1e1293..975a1edcd 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -1430,8 +1430,10 @@ _XimGetAttributeID( bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) + if (!(tmp = (XPointer)Xmalloc(values_len))) { + Xfree(res); return False; + } bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; @@ -1477,8 +1479,10 @@ _XimGetAttributeID( bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) + if (!(tmp = (XPointer)Xmalloc(values_len))) { + Xfree(res); return False; + } bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; -- cgit v1.2.3 From 7d7224d8543e85e3a34a1cddf99f3eac9aa9050b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 12 Apr 2011 21:27:45 -0700 Subject: Replace Xmalloc+bzero pairs with Xcalloc calls Signed-off-by: Alan Coopersmith Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Quarks.c | 3 +-- nx-X11/lib/X11/XDefaultOMIF.c | 16 +++++----------- nx-X11/lib/X11/Xrm.c | 6 ++---- nx-X11/lib/X11/imDefIc.c | 3 +-- nx-X11/lib/X11/imInt.c | 3 +-- nx-X11/lib/X11/imLcIc.c | 3 +-- nx-X11/lib/X11/imRm.c | 18 ++++++------------ nx-X11/lib/X11/imRmAttr.c | 15 ++++----------- nx-X11/lib/X11/imThaiIc.c | 3 +-- nx-X11/lib/X11/imTrX.c | 3 +-- nx-X11/lib/X11/imTrans.c | 4 +--- nx-X11/lib/X11/lcCharSet.c | 3 +-- nx-X11/lib/X11/lcDB.c | 6 ++---- nx-X11/lib/X11/lcGenConv.c | 3 +-- nx-X11/lib/X11/lcGeneric.c | 15 +++++---------- nx-X11/lib/X11/lcJis.c | 3 +-- nx-X11/lib/X11/lcPublic.c | 6 ++---- nx-X11/lib/X11/omGeneric.c | 9 +++------ 18 files changed, 39 insertions(+), 83 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Quarks.c b/nx-X11/lib/X11/Quarks.c index 9a7cb04d5..1bba6da4d 100644 --- a/nx-X11/lib/X11/Quarks.c +++ b/nx-X11/lib/X11/Quarks.c @@ -206,10 +206,9 @@ ExpandQuarkTable(void) #endif newmask = 0x1ff; } - entries = (Entry *)Xmalloc(sizeof(Entry) * (newmask + 1)); + entries = Xcalloc(newmask + 1, sizeof(Entry)); if (!entries) return False; - bzero((char *)entries, sizeof(Entry) * (newmask + 1)); quarkTable = entries; quarkMask = newmask; quarkRehash = quarkMask - 2; diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 6975aa806..b74683aa7 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -128,10 +128,9 @@ init_fontset( data = XOM_GENERIC(oc->core.om)->data; - font_set = (FontSet) Xmalloc(sizeof(FontSetRec)); + font_set = Xcalloc(1, sizeof(FontSetRec)); if (font_set == NULL) return False; - bzero((char *) font_set, sizeof(FontSetRec)); gen = XOC_GENERIC(oc); gen->font_set = font_set; @@ -1005,10 +1004,9 @@ create_oc( { XOC oc; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1126,15 +1124,13 @@ add_data( XOMGenericPart *gen = XOM_GENERIC(om); OMData new; - new = (OMData) Xmalloc(sizeof(OMDataRec)); + new = Xcalloc(1, sizeof(OMDataRec)); if (new == NULL) return NULL; gen->data = new; - bzero((char *) new, sizeof(OMDataRec)); - return new; } @@ -1168,10 +1164,9 @@ init_om( if (data == NULL) return False; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return False; - bzero((char *) font_data, sizeof(FontDataRec) * count); data->font_data = font_data; data->font_data_count = count; @@ -1237,10 +1232,9 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = (XOMMethods)&methods; om->core.lcd = lcd; diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 81fbfaf35..d3668affa 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -581,23 +581,21 @@ static void GrowTable( ltable = (LTable)table; /* cons up a copy to make MoveValues look symmetric */ otable = *ltable; - ltable->buckets = (VEntry *)Xmalloc(i * sizeof(VEntry)); + ltable->buckets = Xcalloc(i, sizeof(VEntry)); if (!ltable->buckets) { ltable->buckets = otable.buckets; return; } ltable->table.mask = i - 1; - bzero((char *)ltable->buckets, i * sizeof(VEntry)); MoveValues(&otable, ltable); } else { register NTable ntable; - ntable = (NTable)Xmalloc(sizeof(NTableRec) + i * sizeof(NTable)); + ntable = Xcalloc(1, sizeof(NTableRec) + (i * sizeof(NTable))); if (!ntable) return; *ntable = *table; ntable->mask = i - 1; - bzero((char *)NodeBuckets(ntable), i * sizeof(NTable)); *prev = ntable; MoveTables(table, ntable); } diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index ba720b56c..85029ad1f 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -1425,10 +1425,9 @@ _XimProtoCreateIC( if (!(_XimGetInputStyle(arg, &input_style))) return (XIC)NULL; - if ((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) + if ((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) return (XIC)NULL; - bzero((char *)ic, sizeof(XicRec)); ic->methods = &ic_methods; ic->core.im = (XIM)im; ic->core.input_style = input_style; diff --git a/nx-X11/lib/X11/imInt.c b/nx-X11/lib/X11/imInt.c index c78ffc68d..bab4b5399 100644 --- a/nx-X11/lib/X11/imInt.c +++ b/nx-X11/lib/X11/imInt.c @@ -204,9 +204,8 @@ _XimOpenIM( Xim im; register int i; - if (!(im = (Xim)Xmalloc(sizeof(XimRec)))) + if (!(im = Xcalloc(1, sizeof(XimRec)))) return (XIM)NULL; - bzero(im, sizeof(XimRec)); im->core.lcd = lcd; im->core.ic_chain = (XIC)NULL; diff --git a/nx-X11/lib/X11/imLcIc.c b/nx-X11/lib/X11/imLcIc.c index 66ff3e913..4a452269a 100644 --- a/nx-X11/lib/X11/imLcIc.c +++ b/nx-X11/lib/X11/imLcIc.c @@ -143,10 +143,9 @@ _XimLocalCreateIC( unsigned int num; int len; - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { + if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); } - bzero((char *)ic, sizeof(XicRec)); ic->methods = &Local_ic_methods; ic->core.im = im; diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index 7f79765e1..448cf41e6 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -360,10 +360,9 @@ _XimDefaultStyles( n = XIMNumber(supported_local_styles) - 1; len = sizeof(XIMStyles) + sizeof(XIMStyle) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); styles = (XIMStyles *)tmp; if (n > 0) { @@ -396,10 +395,9 @@ _XimDefaultIMValues( n = XIMNumber(supported_local_im_values_list); len = sizeof(XIMValuesList) + sizeof(char **) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); values_list = (XIMValuesList *)tmp; if (n > 0) { @@ -433,10 +431,9 @@ _XimDefaultICValues( n = XIMNumber(supported_local_ic_values_list); len = sizeof(XIMValuesList) + sizeof(char **) * n; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); values_list = (XIMValuesList *)tmp; if (n > 0) { @@ -1085,10 +1082,9 @@ _XimDecodeStyles( num = styles->count_styles; len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); out = (XIMStyles *)tmp; if(num >0) { @@ -1124,10 +1120,9 @@ _XimDecodeValues( num = values_list->count_values; len = sizeof(XIMValuesList) + sizeof(char **) * num; - if(!(tmp = (char *)Xmalloc(len))) { + if(!(tmp = Xcalloc(1, len))) { return False; } - bzero(tmp, len); out = (XIMValuesList *)tmp; if(num) { @@ -2143,10 +2138,9 @@ _XimSetResourceList( XIMResourceList res; len = sizeof(XIMResource) * num_resource; - if(!(res = (XIMResourceList)Xmalloc(len))) { + if(!(res = Xcalloc(1, len))) { return False; } - bzero((char *)res, len); for(i = 0; i < num_resource; i++, id++) { res[i] = resource[i]; diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index 975a1edcd..56a55a13f 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -1405,7 +1405,6 @@ _XimGetAttributeID( { unsigned int n; XIMResourceList res; - int res_len; char *names; int names_len; XPointer tmp; @@ -1423,18 +1422,15 @@ _XimGetAttributeID( if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len))) return False; - res_len = sizeof(XIMResource) * n; - if (!(res = (XIMResourceList)Xmalloc(res_len))) + if (!(res = Xcalloc(n, sizeof(XIMResource)))) return False; - bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) { + if (!(tmp = Xcalloc(1, values_len))) { Xfree(res); return False; } - bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; values = (char **)((char *)tmp + sizeof(XIMValuesList)); @@ -1472,18 +1468,15 @@ _XimGetAttributeID( if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len))) return False; - res_len = sizeof(XIMResource) * n; - if (!(res = (XIMResourceList)Xmalloc(res_len))) + if (!(res = Xcalloc(n, sizeof(XIMResource)))) return False; - bzero((char *)res, res_len); values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len; - if (!(tmp = (XPointer)Xmalloc(values_len))) { + if (!(tmp = Xcalloc(1, values_len))) { Xfree(res); return False; } - bzero(tmp, values_len); values_list = (XIMValuesList *)tmp; values = (char **)((char *)tmp + sizeof(XIMValuesList)); diff --git a/nx-X11/lib/X11/imThaiIc.c b/nx-X11/lib/X11/imThaiIc.c index 72e99ba75..ded78e38f 100644 --- a/nx-X11/lib/X11/imThaiIc.c +++ b/nx-X11/lib/X11/imThaiIc.c @@ -157,10 +157,9 @@ _XimThaiCreateIC( int len; DefTree *tree; - if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { + if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); } - bzero((char *)ic, sizeof(XicRec)); ic->methods = &Thai_ic_methods; ic->core.im = im; diff --git a/nx-X11/lib/X11/imTrX.c b/nx-X11/lib/X11/imTrX.c index 2b5455f1b..6b757cee5 100644 --- a/nx-X11/lib/X11/imTrX.c +++ b/nx-X11/lib/X11/imTrX.c @@ -487,9 +487,8 @@ _XimXConf(Xim im, char *address) { XSpecRec *spec; - if (!(spec = (XSpecRec *)Xmalloc(sizeof(XSpecRec)))) + if (!(spec = Xcalloc(1, sizeof(XSpecRec)))) return False; - bzero(spec, sizeof(XSpecRec)); spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False); spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False); diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index 0fdc8cd9a..a974c0ca3 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -293,13 +293,11 @@ _XimTransConf( if (!(paddr = (char *)Xmalloc(strlen(address) + 1))) return False; - if (!(spec = (TransSpecRec *) Xmalloc(sizeof(TransSpecRec)))) { + if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) { Xfree(paddr); return False; } - bzero(spec, sizeof(TransSpecRec)); - (void)strcpy(paddr, address); spec->address = paddr; diff --git a/nx-X11/lib/X11/lcCharSet.c b/nx-X11/lib/X11/lcCharSet.c index 0fa39d869..5d287811c 100644 --- a/nx-X11/lib/X11/lcCharSet.c +++ b/nx-X11/lib/X11/lcCharSet.c @@ -176,10 +176,9 @@ _XlcCreateDefaultCharSet( const char *colon; char *tmp; - charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec)); + charset = Xcalloc(1, sizeof(XlcCharSetRec)); if (charset == NULL) return (XlcCharSet) NULL; - bzero((char *) charset, sizeof(XlcCharSetRec)); name_len = strlen(name); ct_sequence_len = strlen(ct_sequence); diff --git a/nx-X11/lib/X11/lcDB.c b/nx-X11/lib/X11/lcDB.c index 1353acfe3..c11a79a6b 100644 --- a/nx-X11/lib/X11/lcDB.c +++ b/nx-X11/lib/X11/lcDB.c @@ -591,11 +591,10 @@ store_to_database( goto err; } - new = (Database)Xmalloc(sizeof(DatabaseRec)); + new = Xcalloc(1, sizeof(DatabaseRec)); if (new == (Database)NULL) { goto err; } - bzero(new, sizeof(DatabaseRec)); new->category = (char *)Xmalloc(strlen(parse_info.category) + 1); if (new->category == NULL) { @@ -1309,10 +1308,9 @@ _XlcCreateLocaleDataBase( return (XPointer)NULL; } n = CountDatabase(database); - lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1)); + lc_db = Xcalloc(n + 1, sizeof(XlcDatabaseRec)); if (lc_db == (XlcDatabase)NULL) goto err; - bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1)); for (p = database, i = 0; p && i < n; p = p->next, ++i) { lc_db[i].category_q = XrmStringToQuark(p->category); lc_db[i].name_q = XrmStringToQuark(p->name); diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 074a8d726..d5f5a9083 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -2660,10 +2660,9 @@ create_conv( *conv->methods = *methods; conv->methods->reset = init_state; - conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + conv->state = Xcalloc(1, sizeof(StateRec)); if (conv->state == NULL) goto err; - bzero((char *) conv->state, sizeof(StateRec)); state = (State) conv->state; state->lcd = lcd; diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index 688a4cfc4..df392e9af 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -60,15 +60,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec)); + lcd->core = Xcalloc(1, sizeof(XLCdGenericRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdGenericRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) @@ -180,10 +178,9 @@ add_codeset( CodeSet new, *new_list; int num; - new = (CodeSet) Xmalloc(sizeof(CodeSetRec)); + new = Xcalloc(1, sizeof(CodeSetRec)); if (new == NULL) return NULL; - bzero((char *) new, sizeof(CodeSetRec)); if ((num = gen->codeset_num)) new_list = (CodeSet *) Xrealloc(gen->codeset_list, @@ -223,16 +220,14 @@ add_parse_list( return False; strcpy(str, encoding); - new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec)); + new = Xcalloc(1, sizeof(ParseInfoRec)); if (new == NULL) goto err; - bzero((char *) new, sizeof(ParseInfoRec)); if (gen->mb_parse_table == NULL) { - gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */ + gen->mb_parse_table = Xcalloc(1, 256); /* 2^8 */ if (gen->mb_parse_table == NULL) goto err; - bzero((char *) gen->mb_parse_table, 256); } if ((num = gen->mb_parse_list_num)) diff --git a/nx-X11/lib/X11/lcJis.c b/nx-X11/lib/X11/lcJis.c index 594e6363c..551862d9b 100644 --- a/nx-X11/lib/X11/lcJis.c +++ b/nx-X11/lib/X11/lcJis.c @@ -545,10 +545,9 @@ create_conv( if (XLC_PUBLIC(lcd, is_state_depend)) conv->methods->reset = init_state; - conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + conv->state = Xcalloc(1, sizeof(StateRec)); if (conv->state == NULL) goto err; - bzero((char *) conv->state, sizeof(StateRec)); state = (State) conv->state; state->lcd = lcd; diff --git a/nx-X11/lib/X11/lcPublic.c b/nx-X11/lib/X11/lcPublic.c index 2c02f5fba..43b9286e7 100644 --- a/nx-X11/lib/X11/lcPublic.c +++ b/nx-X11/lib/X11/lcPublic.c @@ -80,15 +80,13 @@ create( XLCd lcd; XLCdPublicMethods new; - lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + lcd = Xcalloc(1, sizeof(XLCdRec)); if (lcd == NULL) return (XLCd) NULL; - bzero((char *) lcd, sizeof(XLCdRec)); - lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec)); + lcd->core = Xcalloc(1, sizeof(XLCdPublicRec)); if (lcd->core == NULL) goto err; - bzero((char *) lcd->core, sizeof(XLCdPublicRec)); new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); if (new == NULL) diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 32a066a75..fd8742436 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -1656,10 +1656,9 @@ create_oc( XOCMethodsList methods_list = oc_methods_list; int count; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1844,10 +1843,9 @@ create_om( { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = &methods; om->core.lcd = lcd; @@ -1915,10 +1913,9 @@ read_EncodingInfo( FontData font_data,ret; char *buf, *bufptr,*scp; int len; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return NULL; - bzero((char *) font_data, sizeof(FontDataRec) * count); ret = font_data; for ( ; count-- > 0; font_data++) { -- cgit v1.2.3 From dde00b2f6848a38e9fdbe1e4c85373c8b12944b4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 12 Apr 2011 22:30:45 -0700 Subject: Convert malloc(strlen()); strcpy() sets to strdup Signed-off-by: Alan Coopersmith Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FSWrap.c | 3 +-- nx-X11/lib/X11/InitExt.c | 3 +-- nx-X11/lib/X11/PrOfId.c | 11 ++-------- nx-X11/lib/X11/SetLocale.c | 3 +-- nx-X11/lib/X11/XDefaultIMIF.c | 6 ++---- nx-X11/lib/X11/XDefaultOMIF.c | 25 +++++++--------------- nx-X11/lib/X11/XKBGAlloc.c | 13 ++++------- nx-X11/lib/X11/imInt.c | 6 ++---- nx-X11/lib/X11/imRm.c | 19 ++++++---------- nx-X11/lib/X11/imTrans.c | 3 +-- nx-X11/lib/X11/lcDB.c | 12 ++++------- nx-X11/lib/X11/lcFile.c | 14 ++++-------- nx-X11/lib/X11/lcGeneric.c | 18 ++++++---------- nx-X11/lib/X11/lcPublic.c | 3 +-- nx-X11/lib/X11/omGeneric.c | 50 ++++++++++++++----------------------------- 15 files changed, 59 insertions(+), 130 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FSWrap.c b/nx-X11/lib/X11/FSWrap.c index df65654a9..043e5dc3a 100644 --- a/nx-X11/lib/X11/FSWrap.c +++ b/nx-X11/lib/X11/FSWrap.c @@ -85,10 +85,9 @@ _XParseBaseFontNameList( if (!*str) return (char **)NULL; - if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) { + if (!(ptr = strdup(str))) { return (char **)NULL; } - strcpy(ptr, str); psave = ptr; /* somebody who specifies more than XMAXLIST basefontnames will lose */ diff --git a/nx-X11/lib/X11/InitExt.c b/nx-X11/lib/X11/InitExt.c index 21c392c0e..fdadd9ef7 100644 --- a/nx-X11/lib/X11/InitExt.c +++ b/nx-X11/lib/X11/InitExt.c @@ -50,14 +50,13 @@ XExtCodes *XInitExtension ( LockDisplay (dpy); if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) || - ! (ext->name = Xmalloc((unsigned) strlen(name) + 1))) { + ! (ext->name = strdup(name))) { if (ext) Xfree((char *) ext); UnlockDisplay(dpy); return (XExtCodes *) NULL; } codes.extension = dpy->ext_number++; ext->codes = codes; - (void) strcpy(ext->name, name); /* chain it onto the display list */ ext->next = dpy->ext_procs; diff --git a/nx-X11/lib/X11/PrOfId.c b/nx-X11/lib/X11/PrOfId.c index 831f17ab9..a96d28cec 100644 --- a/nx-X11/lib/X11/PrOfId.c +++ b/nx-X11/lib/X11/PrOfId.c @@ -66,7 +66,6 @@ XcmsPrefixOfFormat( */ { XcmsColorSpace **papColorSpaces; - char *prefix; /* * First try Device-Independent color spaces @@ -75,10 +74,7 @@ XcmsPrefixOfFormat( if (papColorSpaces != NULL) { while (*papColorSpaces != NULL) { if ((*papColorSpaces)->id == id) { - prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) + - 1) * sizeof(char)); - strcpy(prefix, (*papColorSpaces)->prefix); - return(prefix); + return strdup((*papColorSpaces)->prefix); } papColorSpaces++; } @@ -91,10 +87,7 @@ XcmsPrefixOfFormat( if (papColorSpaces != NULL) { while (*papColorSpaces != NULL) { if ((*papColorSpaces)->id == id) { - prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) + - 1) * sizeof(char)); - strcpy(prefix, (*papColorSpaces)->prefix); - return(prefix); + return strdup((*papColorSpaces)->prefix); } papColorSpaces++; } diff --git a/nx-X11/lib/X11/SetLocale.c b/nx-X11/lib/X11/SetLocale.c index cf068403b..9ada0fb90 100644 --- a/nx-X11/lib/X11/SetLocale.c +++ b/nx-X11/lib/X11/SetLocale.c @@ -103,13 +103,12 @@ _Xsetlocale( if (!methods) return NULL; name = (*methods->lcname)(state); - xsl_name = Xmalloc(strlen(name) + 1); + xsl_name = strdup(name); if (!xsl_name) { xsl_name = old_name; (*methods->destroy)(state); return NULL; } - strcpy(xsl_name, name); if (old_name) Xfree(old_name); (*methods->destroy)(state); diff --git a/nx-X11/lib/X11/XDefaultIMIF.c b/nx-X11/lib/X11/XDefaultIMIF.c index d36962f05..135c5a259 100644 --- a/nx-X11/lib/X11/XDefaultIMIF.c +++ b/nx-X11/lib/X11/XDefaultIMIF.c @@ -226,12 +226,10 @@ _XDefaultOpenIM( local_impart->ctow_conv = ctow_conv; if ((res_name != NULL) && (*res_name != '\0')){ - im->core.res_name = (char *)Xmalloc(strlen(res_name)+1); - strcpy(im->core.res_name,res_name); + im->core.res_name = strdup(res_name); } if ((res_class != NULL) && (*res_class != '\0')){ - im->core.res_class = (char *)Xmalloc(strlen(res_class)+1); - strcpy(im->core.res_class,res_class); + im->core.res_class = strdup(res_class); } return (XIM)im; diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index b74683aa7..26c6c3a98 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -216,9 +216,8 @@ check_fontname( fname = prop_fname; } if (data) { - font_set->font_name = (char *) Xmalloc(strlen(fname) + 1); + font_set->font_name = strdup(fname); if (font_set->font_name) { - strcpy(font_set->font_name, fname); found_num++; } } @@ -387,9 +386,7 @@ get_font_name( list = XListFonts(dpy, pattern, 1, &count); if (list != NULL) { - name = (char *) Xmalloc(strlen(*list) + 1); - if (name) - strcpy(name, *list); + name = strdup(*list); XFreeFontNames(list); } else { @@ -459,13 +456,11 @@ parse_fontname( if (font_data == NULL) continue; - font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1); + font_set->font_name = strdup(font_name); + Xfree(font_name); if (font_set->font_name == NULL) { - Xfree(font_name); goto err; } - strcpy(font_set->font_name, font_name); - Xfree(font_name); found_num++; goto found; } @@ -548,11 +543,10 @@ Limit the length of the string copy to prevent stack corruption. } } found: - base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + base_name = strdup(oc->core.base_name_list); if (base_name == NULL) goto err; - strcpy(base_name, oc->core.base_name_list); oc->core.base_name_list = base_name; XFreeStringList(name_list); @@ -1177,10 +1171,9 @@ This one is fine. *value points to one of the local strings in supported_charset_list[]. */ strcpy(buf, *value++); - font_data->name = (char *) Xmalloc(strlen(buf) + 1); + font_data->name = strdup(buf); if (font_data->name == NULL) return False; - strcpy(font_data->name, buf); } length += strlen(data->font_data->name) + 1; @@ -1241,16 +1234,14 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, om->core.display = dpy; om->core.rdb = rdb; if (res_name) { - om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1); + om->core.res_name = strdup(res_name); if (om->core.res_name == NULL) goto err; - strcpy(om->core.res_name, res_name); } if (res_class) { - om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1); + om->core.res_class = strdup(res_class); if (om->core.res_class == NULL) goto err; - strcpy(om->core.res_class, res_class); } if (om_resources[0].xrm_name == NULLQUARK) diff --git a/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index 489d41b78..fa405fb9c 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -684,9 +684,7 @@ register XkbPropertyPtr prop; if ((prop->name)&&(strcmp(name,prop->name)==0)) { if (prop->value) _XkbFree(prop->value); - prop->value= (char *)_XkbAlloc(strlen(value)+1); - if (prop->value) - strcpy(prop->value,value); + prop->value= strdup(value); return prop; } } @@ -695,17 +693,15 @@ register XkbPropertyPtr prop; return NULL; } prop= &geom->properties[geom->num_properties]; - prop->name= (char *)_XkbAlloc(strlen(name)+1); + prop->name= strdup(name); if (!prop->name) return NULL; - strcpy(prop->name,name); - prop->value= (char *)_XkbAlloc(strlen(value)+1); + prop->value= strdup(value); if (!prop->value) { _XkbFree(prop->name); prop->name= NULL; return NULL; } - strcpy(prop->value,value); geom->num_properties++; return prop; } @@ -757,10 +753,9 @@ register XkbColorPtr color; } color= &geom->colors[geom->num_colors]; color->pixel= pixel; - color->spec= (char *)_XkbAlloc(strlen(spec)+1); + color->spec= strdup(spec); if (!color->spec) return NULL; - strcpy(color->spec,spec); geom->num_colors++; return color; } diff --git a/nx-X11/lib/X11/imInt.c b/nx-X11/lib/X11/imInt.c index bab4b5399..0c7cc6f1a 100644 --- a/nx-X11/lib/X11/imInt.c +++ b/nx-X11/lib/X11/imInt.c @@ -214,14 +214,12 @@ _XimOpenIM( im->core.res_name = NULL; im->core.res_class = NULL; if((res_name != NULL) && (*res_name != '\0')){ - if(!(im->core.res_name = (char *)Xmalloc(strlen(res_name)+1))) + if(!(im->core.res_name = strdup(res_name))) goto Error1; - strcpy(im->core.res_name,res_name); } if((res_class != NULL) && (*res_class != '\0')){ - if(!(im->core.res_class = (char *)Xmalloc(strlen(res_class)+1))) + if(!(im->core.res_class = strdup(res_class))) goto Error2; - strcpy(im->core.res_class,res_class); } if(!(im->core.im_name = _XimMakeImName(lcd))) goto Error3; diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index 448cf41e6..3c28b1e29 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -793,19 +793,15 @@ _XimEncodeString( XPointer top, XPointer val) { - int len; char *string; char **out; if(val == (XPointer)NULL) { return False; } - len = strlen((char *)val); - if(!(string = (char *)Xmalloc(len + 1))) { + if (!(string = strdup((char *)val))) { return False; } - (void)strcpy(string, (char *)val); - string[len] = '\0'; out = (char **)((char *)top + info->offset); if(*out) { @@ -1163,21 +1159,18 @@ _XimDecodeString( XPointer top, XPointer val) { - int len = 0; char *in; char *string; in = *((char **)((char *)top + info->offset)); - if(in != (char *)NULL) { - len = strlen(in); + if (in != NULL) { + string = strdup(in); + } else { + string = Xcalloc(1, 1); /* strdup("") */ } - if(!(string = (char *)Xmalloc(len + 1))) { + if (string == NULL) { return False; } - if(in != (char *)NULL) { - (void)strcpy(string, in); - } - string[len] = '\0'; *((char **)val) = string; return True; } diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index a974c0ca3..4c4651599 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -290,7 +290,7 @@ _XimTransConf( char *paddr; TransSpecRec *spec; - if (!(paddr = (char *)Xmalloc(strlen(address) + 1))) + if (!(paddr = strdup(address))) return False; if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) { @@ -298,7 +298,6 @@ _XimTransConf( return False; } - (void)strcpy(paddr, address); spec->address = paddr; im->private.proto.spec = (XPointer)spec; diff --git a/nx-X11/lib/X11/lcDB.c b/nx-X11/lib/X11/lcDB.c index c11a79a6b..027d7747b 100644 --- a/nx-X11/lib/X11/lcDB.c +++ b/nx-X11/lib/X11/lcDB.c @@ -596,20 +596,18 @@ store_to_database( goto err; } - new->category = (char *)Xmalloc(strlen(parse_info.category) + 1); + new->category = strdup(parse_info.category); if (new->category == NULL) { goto err; } - strcpy(new->category, parse_info.category); if (! construct_name(name, sizeof(name))) { goto err; } - new->name = (char *)Xmalloc(strlen(name) + 1); + new->name = strdup(name); if (new->name == NULL) { goto err; } - strcpy(new->name, name); new->next = *db; new->value = parse_info.value; new->value_num = parse_info.value_num; @@ -943,10 +941,9 @@ f_default( case S_NULL: if (parse_info.category != NULL) goto err; - p = (char *)Xmalloc(strlen(wordp) + 1); + p = strdup(wordp); if (p == NULL) goto err; - strcpy(p, wordp); parse_info.category = p; parse_info.pre_state = S_CATEGORY; break; @@ -960,10 +957,9 @@ f_default( break; } } - p = (char *)Xmalloc(strlen(wordp) + 1); + p = strdup(wordp); if (p == NULL) goto err; - strcpy(p, wordp); if (parse_info.name[parse_info.nest_depth] != NULL) { Xfree(parse_info.name[parse_info.nest_depth]); } diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index e657e707f..36f0ddf5a 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -401,10 +401,7 @@ resolve_name( from = args[1], to = args[0]; /* right to left */ } if (! strcmp(from, lc_name)) { - name = Xmalloc(strlen(to) + 1); - if (name != NULL) { - strcpy(name, to); - } + name = strdup(to); break; } } @@ -557,8 +554,7 @@ _XlcResolveLocaleName( if (name == NULL) { /* vendor locale name == Xlocale name, no expansion of alias */ - pub->siname = Xmalloc (strlen (lc_name) + 1); - strcpy (pub->siname, lc_name); + pub->siname = strdup (lc_name); } else { pub->siname = name; } @@ -707,8 +703,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); - last_lc_name = Xmalloc (strlen (lc_name) + 1); - strcpy (last_lc_name, lc_name); + last_lc_name = strdup (lc_name); return dir_name; } @@ -806,8 +801,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); - last_lc_name = Xmalloc (strlen (lc_name) + 1); - strcpy (last_lc_name, lc_name); + last_lc_name = strdup (lc_name); return dir_name; } diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index df392e9af..619cb47f9 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -215,10 +215,9 @@ add_parse_list( unsigned char ch; int num; - str = (char *) Xmalloc(strlen(encoding) + 1); + str = strdup(encoding); if (str == NULL) return False; - strcpy(str, encoding); new = Xcalloc(1, sizeof(ParseInfoRec)); if (new == NULL) @@ -463,10 +462,9 @@ read_charset_define( break; } if (new) { - tmp = (char *)Xmalloc(strlen(cset_name)+1); + tmp = strdup(cset_name); if (tmp == NULL) return; - strcpy(tmp,cset_name); charsetd->name = tmp; } /* side */ @@ -522,8 +520,7 @@ read_charset_define( Xfree(charsetd->encoding_name); } */ - tmp = (char *)Xmalloc(strlen(value[0])+1); - strcpy(tmp,value[0]); + tmp = strdup(value[0]); charsetd->encoding_name = tmp; charsetd->xrm_encoding_name = XrmStringToQuark(tmp); } @@ -593,10 +590,9 @@ read_segmentconversion( if (num > 0) { char *tmp; _XlcDbg_printValue(name,value,num); - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = strdup(value[0]); if (tmp == NULL) return; - strcpy(tmp,value[0]); conversion->source_encoding = tmp; conversion->source = srch_charset_define(tmp,&new); } @@ -606,10 +602,9 @@ read_segmentconversion( if (num > 0) { char *tmp; _XlcDbg_printValue(name,value,num); - tmp = (char *)Xmalloc(strlen(value[0])+1); + tmp = strdup(value[0]); if (tmp == NULL) return; - strcpy(tmp,value[0]); conversion->destination_encoding = tmp; conversion->dest = srch_charset_define(tmp,&new); } @@ -645,12 +640,11 @@ create_ctextseg( ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec)); if (ret == NULL) return NULL; - ret->name = (char *)Xmalloc(strlen(value[0]) + 1); + ret->name = strdup(value[0]); if (ret->name == NULL) { Xfree (ret); return NULL; } - strcpy(ret->name,value[0]); cset_name = (char*) Xmalloc (strlen(ret->name) + 1); if (cset_name == NULL) { Xfree (ret->name); diff --git a/nx-X11/lib/X11/lcPublic.c b/nx-X11/lib/X11/lcPublic.c index 43b9286e7..1b1fb548a 100644 --- a/nx-X11/lib/X11/lcPublic.c +++ b/nx-X11/lib/X11/lcPublic.c @@ -128,10 +128,9 @@ load_public( _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num); str = (num > 0) ? values[0] : "STRING"; - pub->encoding_name = (char*) Xmalloc(strlen(str) + 1); + pub->encoding_name = strdup(str); if (pub->encoding_name == NULL) return False; - strcpy(pub->encoding_name, str); return True; } diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index fd8742436..6b5e30a69 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -523,9 +523,7 @@ get_font_name( if (list == NULL) return NULL; - name = (char *) Xmalloc(strlen(*list) + 1); - if (name) - strcpy(name, *list); + name = strdup(*list); XFreeFontNames(list); @@ -549,10 +547,9 @@ get_rotate_fontname( || len > XLFD_MAX_LEN) return NULL; - pattern = (char *)Xmalloc(len + 1); + pattern = strdup(font_name); if(!pattern) return NULL; - strcpy(pattern, font_name); memset(fields, 0, sizeof(char *) * 14); ptr = pattern; @@ -663,10 +660,8 @@ get_font_name_from_list( for (i = 0; i < count; i++) { fname = list[i]; if(is_match_charset(font_data, fname) == True) { - name = (char *) Xmalloc(strlen(fname) + 1); - if (name) - strcpy(name, fname); - break; + name = strdup(fname); + break; } } @@ -687,11 +682,10 @@ parse_all_name( if(is_match_charset(font_data, pattern) != True) return False; - font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1); + font_data->xlfd_name = strdup(pattern); if(font_data->xlfd_name == NULL) return (-1); - strcpy(font_data->xlfd_name, pattern); return True; #else /* OLDCODE */ Display *dpy = oc->core.om->core.display; @@ -725,11 +719,10 @@ parse_all_name( } } - font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1); + font_data->xlfd_name = strdup(pattern); if(font_data->xlfd_name == NULL) return (-1); - strcpy(font_data->xlfd_name, pattern); return True; #endif /* OLDCODE */ } @@ -948,12 +941,9 @@ parse_fontdata( * -- jjw/pma (HP) */ if (font_data_return) { - font_data_return->xlfd_name = (char *)Xmalloc - (strlen(font_data->xlfd_name) + 1); + font_data_return->xlfd_name = strdup(font_data->xlfd_name); if (!font_data_return->xlfd_name) return -1; - strcpy (font_data_return->xlfd_name, font_data->xlfd_name); - font_data_return->side = font_data->side; } #ifdef FONTDEBUG @@ -998,11 +988,9 @@ parse_fontdata( #ifdef FONTDEBUG fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name); #endif - font_data_return->xlfd_name = (char *)Xmalloc - (strlen(font_data->xlfd_name) + 1); + font_data_return->xlfd_name = strdup(font_data->xlfd_name); if (!font_data_return->xlfd_name) return -1; - strcpy (font_data_return->xlfd_name, font_data->xlfd_name); font_data_return->side = font_data->side; } @@ -1194,11 +1182,10 @@ parse_fontname( * be matched. It returns the required information in * font_data_return. */ - font_set->font_name = (char *)Xmalloc - (strlen(font_data_return.xlfd_name) + 1); + font_set->font_name = strdup(font_data_return.xlfd_name); if(font_set->font_name == (char *) NULL) goto err; - strcpy(font_set->font_name, font_data_return.xlfd_name); + font_set->side = font_data_return.side; Xfree (font_data_return.xlfd_name); @@ -1225,11 +1212,10 @@ parse_fontname( break; } } - font_set->font_name = (char *)Xmalloc - (strlen(font_set->substitute[i].xlfd_name) + 1); + font_set->font_name = strdup(font_set->substitute[i].xlfd_name); if(font_set->font_name == (char *) NULL) goto err; - strcpy(font_set->font_name,font_set->substitute[i].xlfd_name); + font_set->side = font_set->substitute[i].side; if(parse_vw(oc, font_set, name_list, count) == -1) goto err; @@ -1239,11 +1225,10 @@ parse_fontname( } } - base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + base_name = strdup(oc->core.base_name_list); if (base_name == NULL) goto err; - strcpy(base_name, oc->core.base_name_list); oc->core.base_name_list = base_name; XFreeStringList(name_list); @@ -1852,16 +1837,14 @@ create_om( om->core.display = dpy; om->core.rdb = rdb; if (res_name) { - om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1); + om->core.res_name = strdup(res_name); if (om->core.res_name == NULL) goto err; - strcpy(om->core.res_name, res_name); } if (res_class) { - om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1); + om->core.res_class = strdup(res_class); if (om->core.res_class == NULL) goto err; - strcpy(om->core.res_class, res_class); } if (om_resources[0].xrm_name == NULLQUARK) @@ -2014,10 +1997,9 @@ init_om( _XlcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count); if (count > 0) { - gen->object_name = (char *) Xmalloc(strlen(*value) + 1); + gen->object_name = strdup(*value); if (gen->object_name == NULL) return False; - strcpy(gen->object_name, *value); } for (num = 0; ; num++) { -- cgit v1.2.3 From 8127b17dc289831a559944a51d0ea10028016df5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 21 Apr 2011 16:21:04 -0700 Subject: Delete special case code to append "/sparcv9" to i18n module path Was triggered by defined(__sparcv9) so only built on Solaris SPARC 64-bit. Inconsistent with all other platforms, and a bit overcomplicated. Should anyone need to continue using that path, simply build with a #define POSTLOCALELIBDIR "sparcv9" to get the same result. Fixes Solaris bug 7038737: sparcv9 Xlib looking in wrong path for i18n loadable modules Signed-off-by: Alan Coopersmith Reviewed-by: Daniel Stone Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 879bc51eb..7a6e0485c 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -86,16 +86,6 @@ Sun Microsystems, Inc. or its licensors is granted. #include "XlcPublic.h" #include "XlcPubI.h" -#if defined(_LP64) && defined(__sparcv9) -# define _MACH64_NAME "sparcv9" -#else -# undef _MACH64_NAME -#endif /* defined(_LP64) && defined(__sparcv9) */ - -#ifdef _MACH64_NAME -# define _MACH64_NAME_LEN (sizeof (_MACH64_NAME) - 1) -#endif - #define XI18N_DLREL 2 #define iscomment(ch) ((ch) == '\0' || (ch) == '#') @@ -269,35 +259,6 @@ __lc_path(const char *dl_name, const char *lc_dir) if (strstr (dl_name, "../")) return NULL; -#if defined (_LP64) && defined (_MACH64_NAME) - len = (lc_dir ? strlen(lc_dir) : 0 ) + - (dl_name ? strlen(dl_name) : 0) + _MACH64_NAME_LEN + 10; - path = Xmalloc(len + 1); - - if (strchr(dl_name, '/') != NULL) { - char *tmp = strdup(dl_name); - char *dl_dir, *dl_file; - char *slash_p; - slash_p = strchr(tmp, '/'); - *slash_p = '\0'; - dl_dir = tmp; - dl_file = ++slash_p; - - slash_p = strrchr(lc_dir, '/'); - *slash_p = '\0'; - strcpy(path, lc_dir); strcat(path, "/"); - strcat(path, dl_dir); strcat(path, "/"); - strcat(path, _MACH64_NAME); strcat(path, "/"); - strcat(path, dl_file); strcat(path, ".so.2"); - - *slash_p = '/'; - Xfree(tmp); - } else { - strcpy(path, lc_dir); strcat(path, "/"); - strcat(path, _MACH64_NAME); strcat(path, "/"); - strcat(path, dl_name); strcat(path, ".so.2"); - } -#else len = (lc_dir ? strlen(lc_dir) : 0 ) + (dl_name ? strlen(dl_name) : 0) + 10; #if defined POSTLOCALELIBDIR @@ -322,7 +283,6 @@ __lc_path(const char *dl_name, const char *lc_dir) #endif strcat(path, dl_name); strcat(path, ".so.2"); } -#endif return path; } -- cgit v1.2.3 From 1d806a5550490ab2d97ddd3daf3b1e1eb2a779b8 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Wed, 4 May 2011 11:35:31 -0700 Subject: Dead code removal XKBGeom.c:118:27: warning: Assigned value is always the same as the existing value for (key=row->keys,pos=k=0;knum_keys;k++,key++) { ~~~^~~~ XKBGeom.c:115:5: warning: Value stored to 'pos' is never read pos= 0; ^ ~ Found-by: clang static analyzer Signed-off-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGeom.c | 1 - 1 file changed, 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGeom.c b/nx-X11/lib/X11/XKBGeom.c index 1f9628bea..39ed4bed7 100644 --- a/nx-X11/lib/X11/XKBGeom.c +++ b/nx-X11/lib/X11/XKBGeom.c @@ -112,7 +112,6 @@ XkbBoundsPtr bounds,sbounds; if ((!geom)||(!section)||(!row)) return False; - pos= 0; bounds= &row->bounds; bzero(bounds,sizeof(XkbBoundsRec)); for (key=row->keys,pos=k=0;knum_keys;k++,key++) { -- cgit v1.2.3 From 7efa7da59e27ad72e7f1b554f85804b82977cbef Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Wed, 4 May 2011 15:34:31 -0700 Subject: XKB: XkbComputeSectionBounds: Check correct bounds in default switch-case XKBGeom.c:191:25: warning: Access to field 'x1' results in a dereference of a null pointer (loaded from variable 'rbounds') _XkbCheckBounds(bounds,rbounds->x1,rbounds->y1); ^~~~~~~ Found-by: clang static analyzer Signed-off-by: Jeremy Huddleston Reviewed-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGeom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGeom.c b/nx-X11/lib/X11/XKBGeom.c index 39ed4bed7..2f34bea80 100644 --- a/nx-X11/lib/X11/XKBGeom.c +++ b/nx-X11/lib/X11/XKBGeom.c @@ -146,7 +146,7 @@ register int i; XkbShapePtr shape; XkbRowPtr row; XkbDoodadPtr doodad; -XkbBoundsPtr bounds,rbounds=NULL; +XkbBoundsPtr bounds,rbounds; if ((!geom)||(!section)) return False; @@ -185,6 +185,7 @@ XkbBoundsPtr bounds,rbounds=NULL; default: tbounds.x1= tbounds.x2= doodad->any.left; tbounds.y1= tbounds.y2= doodad->any.top; + rbounds= &tbounds; break; } _XkbCheckBounds(bounds,rbounds->x1,rbounds->y1); -- cgit v1.2.3 From 1871ff031211a842601821735cae7a6d7600ca05 Mon Sep 17 00:00:00 2001 From: Choe Hwanjin Date: Thu, 13 Oct 2011 07:58:02 +0900 Subject: XIM: Make Xim handle NEED_SYNC_REPLY flag NEED_SYNC_REPLY flag should be in Xim not in Xic. Because the focused Xic can be changed before sending sync reply. After focused Xic changed, the new Xic doesn't have NEED_SYNC_REPLY flag enabled, so libX11 doesn't send XIM_SYNC_REPLY packet. This patch adds sync reply flag to Xim and removes sync reply from Xic. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=7869 Signed-off-by: Choe Hwanjin Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XimintP.h | 40 ++++++++++++++++------------------------ nx-X11/lib/X11/imDefFlt.c | 16 ++++++---------- nx-X11/lib/X11/imDefIc.c | 4 ---- nx-X11/lib/X11/imDefLkup.c | 12 ++++-------- nx-X11/lib/X11/imExten.c | 2 +- 5 files changed, 27 insertions(+), 47 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XimintP.h b/nx-X11/lib/X11/XimintP.h index 89b7c214f..55257545e 100644 --- a/nx-X11/lib/X11/XimintP.h +++ b/nx-X11/lib/X11/XimintP.h @@ -161,6 +161,8 @@ typedef struct _XimProtoPrivateRec { #define DELAYBINDABLE (1L << 3) #define RECONNECTABLE (1L << 4) #endif /* XIM_CONNECTABLE */ +#define FABRICATED (1L << 5) +#define NEED_SYNC_REPLY (1L << 6) /* * macro for the flag of XIMPrivateRec @@ -199,6 +201,20 @@ typedef struct _XimProtoPrivateRec { (((Xim)im)->private.proto.flag &= ~(DELAYBINDABLE|RECONNECTABLE)) #endif /* XIM_CONNECTABLE */ +#define IS_FABRICATED(im) \ + (((Xim)im)->private.proto.flag & FABRICATED) +#define MARK_FABRICATED(im) \ + (((Xim)im)->private.proto.flag |= FABRICATED) +#define UNMARK_FABRICATED(im) \ + (((Xim)im)->private.proto.flag &= ~FABRICATED) + +#define IS_NEED_SYNC_REPLY(im) \ + (((Xim)im)->private.proto.flag & NEED_SYNC_REPLY) +#define MARK_NEED_SYNC_REPLY(im) \ + (((Xim)im)->private.proto.flag |= NEED_SYNC_REPLY) +#define UNMARK_NEED_SYNC_REPLY(im) \ + (((Xim)im)->private.proto.flag &= ~NEED_SYNC_REPLY) + /* * bit mask for the register_filter_event of XIMPrivateRec/XICPrivateRec */ @@ -259,9 +275,6 @@ typedef struct _XicProtoPrivateRec { * bit mask for the flag of XICPrivateRec */ #define IC_CONNECTED (1L) -#define FABLICATED (1L << 1) -#define NEED_SYNC_REPLY (1L << 2) -#define FOCUSED (1L << 3) /* * macro for the flag of XICPrivateRec @@ -273,27 +286,6 @@ typedef struct _XicProtoPrivateRec { #define UNMARK_IC_CONNECTED(ic) \ (((Xic)ic)->private.proto.flag &= ~IC_CONNECTED) -#define IS_FABLICATED(ic) \ - (((Xic)ic)->private.proto.flag & FABLICATED) -#define MARK_FABLICATED(ic) \ - (((Xic)ic)->private.proto.flag |= FABLICATED) -#define UNMARK_FABLICATED(ic) \ - (((Xic)ic)->private.proto.flag &= ~FABLICATED) - -#define IS_NEED_SYNC_REPLY(ic) \ - (((Xic)ic)->private.proto.flag & NEED_SYNC_REPLY) -#define MARK_NEED_SYNC_REPLY(ic) \ - (((Xic)ic)->private.proto.flag |= NEED_SYNC_REPLY) -#define UNMARK_NEED_SYNC_REPLY(ic) \ - (((Xic)ic)->private.proto.flag &= ~NEED_SYNC_REPLY) - -#define IS_FOCUSED(ic) \ - (((Xic)ic)->private.proto.flag & FOCUSED) -#define MARK_FOCUSED(ic) \ - (((Xic)ic)->private.proto.flag |= FOCUSED) -#define UNMARK_FOCUSED(ic) \ - (((Xic)ic)->private.proto.flag &= ~FOCUSED) - /* * macro for the filter_event_mask of XICPrivateRec */ diff --git a/nx-X11/lib/X11/imDefFlt.c b/nx-X11/lib/X11/imDefFlt.c index 9717aa2c3..6259fb7f7 100644 --- a/nx-X11/lib/X11/imDefFlt.c +++ b/nx-X11/lib/X11/imDefFlt.c @@ -128,9 +128,9 @@ _XimPendingFilter( { Xim im = (Xim)ic->core.im; - if (IS_NEED_SYNC_REPLY(ic)) { + if (IS_NEED_SYNC_REPLY(im)) { (void)_XimProcSyncReply(im, ic); - UNMARK_NEED_SYNC_REPLY(ic); + UNMARK_NEED_SYNC_REPLY(im); } return; } @@ -140,13 +140,11 @@ _XimProtoKeypressFilter( Xic ic, XKeyEvent *ev) { -#ifdef XIM_CONNECTABLE Xim im = (Xim)ic->core.im; -#endif - if (IS_FABLICATED(ic)) { + if (IS_FABRICATED(im)) { _XimPendingFilter(ic); - UNMARK_FABLICATED(ic); + UNMARK_FABRICATED(im); return NOTFILTERD; } @@ -203,13 +201,11 @@ _XimProtoKeyreleaseFilter( Xic ic, XKeyEvent *ev) { -#ifdef XIM_CONNECTABLE Xim im = (Xim)ic->core.im; -#endif - if (IS_FABLICATED(ic)) { + if (IS_FABRICATED(im)) { _XimPendingFilter(ic); - UNMARK_FABLICATED(ic); + UNMARK_FABRICATED(im); return NOTFILTERD; } diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index 85029ad1f..dab0e3c75 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -968,8 +968,6 @@ _XimProtoSetFocus( (void)_XimWrite(im, len, (XPointer)buf); _XimFlush(im); - MARK_FOCUSED(ic); - _XimRegisterFilter(ic); return; } @@ -1015,8 +1013,6 @@ _XimProtoUnsetFocus( (void)_XimWrite(im, len, (XPointer)buf); _XimFlush(im); - UNMARK_FOCUSED(ic); - _XimUnregisterFilter(ic); return; } diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index d1c3a6567..e2b1e05bc 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -213,12 +213,8 @@ _XimRespSyncReply( Xic ic, BITMASK16 mode) { - if (mode & XimSYNCHRONUS) /* SYNC Request */ { - if (IS_FOCUSED(ic)) - MARK_NEED_SYNC_REPLY(ic); - else - _XimProcSyncReply((Xim)ic->core.im, ic); - } + if (mode & XimSYNCHRONUS) /* SYNC Request */ + MARK_NEED_SYNC_REPLY(ic->core.im); return True; } @@ -356,7 +352,7 @@ _XimProcEvent( ev->xany.serial |= serial << 16; ev->xany.send_event = False; ev->xany.display = d; - MARK_FABLICATED(ic); + MARK_FABRICATED(ic->core.im); return; } @@ -706,7 +702,7 @@ _XimCommitRecv( (void)_XimRespSyncReply(ic, flag); - MARK_FABLICATED(ic); + MARK_FABRICATED(im); ev.type = KeyPress; ev.send_event = False; diff --git a/nx-X11/lib/X11/imExten.c b/nx-X11/lib/X11/imExten.c index 3ffe7f891..c7b9ed11e 100644 --- a/nx-X11/lib/X11/imExten.c +++ b/nx-X11/lib/X11/imExten.c @@ -159,7 +159,7 @@ _XimProcExtForwardKeyEvent( XPutBackEvent(im->core.display, &ev); _XimRespSyncReply(ic, buf_s[0]); - MARK_FABLICATED(ic); + MARK_FABRICATED(im); return True; } -- cgit v1.2.3 From 02dad70a8dc920d25aa1c9b61a343310fe112e5b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 17 Oct 2011 09:45:15 +1000 Subject: Add _XGetRequest as substitute for GetReq/GetReqExtra Signed-off-by: Peter Hutterer Reviewed-by: Jamey Sharp Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index 69561f401..5adde76ed 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -437,6 +437,19 @@ extern LockInfoPtr _Xglobal_lock; * X Protocol packetizing macros. */ +/** + * Return a len-sized request buffer for the request type. This function may + * flush the output queue. + * + * @param dpy The display connection + * @param type The request type + * @param len Length of the request in bytes + * + * @returns A pointer to the request buffer with a few default values + * initialized. + */ +extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); + /* * GetReq - Get the next available X request packet in the buffer and * return it. @@ -448,23 +461,10 @@ extern LockInfoPtr _Xglobal_lock; #if !defined(UNIXCPP) || defined(ANSICPP) #define GetReq(name, req) \ - if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ - req->reqType = X_##name;\ - req->length = (SIZEOF(x##name##Req))>>2;\ - dpy->bufptr += SIZEOF(x##name##Req);\ - dpy->request++ - + req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req)) #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ #define GetReq(name, req) \ - if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ - req->reqType = X_/**/name;\ - req->length = (SIZEOF(x/**/name/**/Req))>>2;\ - dpy->bufptr += SIZEOF(x/**/name/**/Req);\ - dpy->request++ + req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req)) #endif /* GetReqExtra is the same as GetReq, but allocates "n" additional @@ -472,22 +472,10 @@ extern LockInfoPtr _Xglobal_lock; #if !defined(UNIXCPP) || defined(ANSICPP) #define GetReqExtra(name, n, req) \ - if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ - req->reqType = X_##name;\ - req->length = (SIZEOF(x##name##Req) + n)>>2;\ - dpy->bufptr += SIZEOF(x##name##Req) + n;\ - dpy->request++ + req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req) + n) #else #define GetReqExtra(name, n, req) \ - if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ - req->reqType = X_/**/name;\ - req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\ - dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\ - dpy->request++ + req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req) + n) #endif -- cgit v1.2.3 From 0f089824eedf91df21d1786abc2961247ba8efb7 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 9 Nov 2011 21:00:36 -0800 Subject: XlcSL.c: convert old-style function definitions to ANSI C89 style Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcSL.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcSL.c b/nx-X11/lib/X11/XlcSL.c index 526f677fb..f059bb34d 100644 --- a/nx-X11/lib/X11/XlcSL.c +++ b/nx-X11/lib/X11/XlcSL.c @@ -71,8 +71,7 @@ extern XIM _XDefaultOpenIM( ); Bool -_XInitDefaultIM(lcd) -XLCd lcd; +_XInitDefaultIM(XLCd lcd) { if(lcd == (XLCd)NULL) return False; @@ -88,8 +87,7 @@ extern XOM _XDefaultOpenOM( ); Bool -_XInitDefaultOM(lcd) - XLCd lcd; +_XInitDefaultOM(XLCd lcd) { lcd->methods->open_om = _XDefaultOpenOM; return True; -- cgit v1.2.3 From 30d4454e350ac7c5558d79fd09dfd49ffd415dd5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 29 Nov 2011 23:56:57 -0800 Subject: Reject negative string counts in copy_string_list Silences parfait warning of a potential memory leak: Memory leak of pointer 'dst' allocated with malloc(length) at line 160 of FSWrap.c in function 'copy_string_list'. 'dst' allocated at line 145 with malloc(length). dst leaks when count <= 0 at line 154. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FSWrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FSWrap.c b/nx-X11/lib/X11/FSWrap.c index 043e5dc3a..40a892f20 100644 --- a/nx-X11/lib/X11/FSWrap.c +++ b/nx-X11/lib/X11/FSWrap.c @@ -130,7 +130,7 @@ copy_string_list( char **string_list_ret, **list_src, **list_dst, *dst; int length, count; - if (string_list == NULL || list_count == 0) + if (string_list == NULL || list_count <= 0) return (char **) NULL; string_list_ret = (char **) Xmalloc(sizeof(char *) * list_count); -- cgit v1.2.3 From 5eb1147cc32d59c2f3490d38918e386676eac94b Mon Sep 17 00:00:00 2001 From: Kusanagi Kouichi Date: Wed, 14 Dec 2011 02:17:55 -0500 Subject: XQueryColors: Split a request into multiple requests if necessary https://bugs.freedesktop.org/show_bug.cgi?id=9160 Signed-off-by: Kusanagi Kouichi Signed-off-by: James Cloos Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/QuColors.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/QuColors.c b/nx-X11/lib/X11/QuColors.c index a8bc8837b..7937f5e5a 100644 --- a/nx-X11/lib/X11/QuColors.c +++ b/nx-X11/lib/X11/QuColors.c @@ -29,8 +29,8 @@ in this Software without prior written authorization from The Open Group. #endif #include "Xlibint.h" -int -XQueryColors( +static void +_XQueryColors( register Display *dpy, Colormap cmap, XColor *defs, /* RETURN */ @@ -40,11 +40,10 @@ XQueryColors( xQueryColorsReply rep; register xQueryColorsReq *req; - LockDisplay(dpy); GetReq(QueryColors, req); req->cmap = cmap; - req->length += ncolors; /* each pixel is a CARD32 */ + SetReqLen(req, ncolors, ncolors); /* each pixel is a CARD32 */ for (i = 0; i < ncolors; i++) Data32 (dpy, (long *)&defs[i].pixel, 4L); @@ -70,6 +69,30 @@ XQueryColors( else _XEatDataWords(dpy, rep.length); } +} + +int +XQueryColors( + register Display * const dpy, + const Colormap cmap, + XColor *defs, /* RETURN */ + int ncolors) +{ + int n; + + if (dpy->bigreq_size > 0) + n = dpy->bigreq_size - (sizeof (xQueryColorsReq) >> 2) - 1; + else + n = dpy->max_request_size - (sizeof (xQueryColorsReq) >> 2); + + LockDisplay(dpy); + while (ncolors >= n) { + _XQueryColors(dpy, cmap, defs, n); + defs += n; + ncolors -= n; + } + if (ncolors > 0) + _XQueryColors(dpy, cmap, defs, ncolors); UnlockDisplay(dpy); SyncHandle(); return 1; -- cgit v1.2.3 From fd71577231e93e9c886a08e8d707778664c1cfa4 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Sun, 1 Jan 2012 21:04:52 +0000 Subject: Use pthreads on MinGW also Use pthreads (provided by the pthreads-win32 compatability library which implements them using native Win32 threading) on MinGW Reviewed-by: Jon TURNEY Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/UIThrStubs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/UIThrStubs.c b/nx-X11/lib/X11/UIThrStubs.c index a3bcdfc41..8f4ea076b 100644 --- a/nx-X11/lib/X11/UIThrStubs.c +++ b/nx-X11/lib/X11/UIThrStubs.c @@ -81,9 +81,7 @@ typedef thread_t xthread_t; #pragma weak cond_broadcast = _Xthr_zero_stub_ #else /* !SVR4 */ #ifdef WIN32 - /* - * Don't know what to do here. Is there something do be done at all? - */ +#include #else /* !WIN32 */ #ifdef USE_TIS_SUPPORT #include -- cgit v1.2.3 From e8e91b69e83da81b3d8d71139a99c13d7a62ba00 Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Sun, 20 Feb 2011 17:09:43 +0200 Subject: Provide translation from XK_permille (ad5) to Unicode (U2030) https://bugs.freedesktop.org/show_bug.cgi?id=19687 Signed-off-by: Marko Myllynen Reviewed-by: Matt Dew Signed-off-by: James Cloos Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imKStoUCS.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imKStoUCS.c b/nx-X11/lib/X11/imKStoUCS.c index 5cfce420d..640b3516a 100644 --- a/nx-X11/lib/X11/imKStoUCS.c +++ b/nx-X11/lib/X11/imKStoUCS.c @@ -143,7 +143,7 @@ static unsigned short const keysym_to_unicode_aa1_afe[] = { 0x2105, 0x0000, 0x0000, 0x2012, 0x2039, 0x2024, 0x203a, 0x0000, /* 0x0ab8-0x0abf */ 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000, /* 0x0ac0-0x0ac7 */ 0x0000, 0x2122, 0x2120, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25ad, /* 0x0ac8-0x0acf */ - 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000, 0x2032, 0x2033, /* 0x0ad0-0x0ad7 */ + 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x2030, 0x2032, 0x2033, /* 0x0ad0-0x0ad7 */ 0x0000, 0x271d, 0x0000, 0x220e, 0x25c2, 0x2023, 0x25cf, 0x25ac, /* 0x0ad8-0x0adf */ 0x25e6, 0x25ab, 0x25ae, 0x25b5, 0x25bf, 0x2606, 0x2022, 0x25aa, /* 0x0ae0-0x0ae7 */ 0x25b4, 0x25be, 0x261a, 0x261b, 0x2663, 0x2666, 0x2665, 0x0000, /* 0x0ae8-0x0aef */ -- cgit v1.2.3 From 3d37513eb81325cef80eada39dbdb812c9c627d5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 4 Mar 2012 02:00:13 -0800 Subject: Block for other threads in _XUserLockDisplay Wait for all other threads to release the user-level lock when acquiring it. This ensures that only one thread at a time holds the user-level lock, necessary as it is a nesting lock and a single variable is used to determine when the lock is nesting and when it is contended. Signed-off-by: Keith Packard Reviewed-by: Jamey Sharp Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/locking.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/locking.c b/nx-X11/lib/X11/locking.c index 4f9a40fbd..b3dfb3b01 100644 --- a/nx-X11/lib/X11/locking.c +++ b/nx-X11/lib/X11/locking.c @@ -486,6 +486,8 @@ static void _XInternalLockDisplay( static void _XUserLockDisplay( register Display* dpy) { + _XDisplayLockWait(dpy); + if (++dpy->lock->locking_level == 1) { dpy->lock->lock_wait = _XDisplayLockWait; dpy->lock->locking_thread = xthread_self(); -- cgit v1.2.3 From 4c7f0af734a99b2d44adc70931ee27454ee687f1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 15 Mar 2012 22:03:21 -0700 Subject: Remove "register" qualifier that annoys Solaris Studio compiler Fixes warning: "Xrm.c", line 1094: warning: storage class after type is obsolescent Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index d3668affa..2a3f4889b 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -1092,7 +1092,7 @@ static void GetIncludeFile( static void GetDatabase( XrmDatabase db, - _Xconst register char *str, + _Xconst char *str, _Xconst char *filename, Bool doall, int depth) -- cgit v1.2.3 From 79a5330db17102dd62506b6d748244acb2074369 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Apr 2012 16:36:47 +1000 Subject: Typo fix Signed-off-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 151e521bd..8dc07ad1b 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -2954,7 +2954,7 @@ void _XEnq( extension = ((xGenericEvent*)event)->extension; qelt->event.type = type; - /* If an extension has registerd a generic_event_vec handler, then + /* If an extension has registered a generic_event_vec handler, then * it can handle event cookies. Otherwise, proceed with the normal * event handlers. * -- cgit v1.2.3 From b8b885daf7b6b368c8ad7a31dfc89b44f993d21b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 21 Feb 2011 17:27:38 +0100 Subject: Match braille patterns with compose tree Braille patterns should also be usable in Compose. This combines the implementation of braille chords and compose tree: only emit the braille pattern if it can not be found in the compose tree, if any. Signed-off-by: Samuel Thibault Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcFlt.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcFlt.c b/nx-X11/lib/X11/imLcFlt.c index e812fdd0d..e4ab3815c 100644 --- a/nx-X11/lib/X11/imLcFlt.c +++ b/nx-X11/lib/X11/imLcFlt.c @@ -45,6 +45,7 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) static char buf[256]; DefTree *b = ic->private.local.base.tree; DTIndex t; + Bool braille = False; if(ev->xkey.keycode == 0) return (False); @@ -58,6 +59,7 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) if(ev->type == KeyPress) { ic->private.local.brl_pressed |= 1<<(keysym-XK_braille_dot_1); + return(True); } else { if(!ic->private.local.brl_committing || ev->xkey.time - ic->private.local.brl_release_start > 300) { @@ -65,23 +67,20 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) ic->private.local.brl_release_start = ev->xkey.time; } ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1)); - if(!ic->private.local.brl_pressed) { - if(ic->private.local.brl_committing) { - ic->private.local.brl_committed = - ic->private.local.brl_committing; - ic->private.local.composed = 0; - ev->type = KeyPress; - ev->xkey.keycode = 0; - _XPutBackEvent(d, ev); - } + if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) { + /* Commited a braille pattern, let it go through compose tree */ + keysym = XK_braille_blank | ic->private.local.brl_committing; + ev->type = KeyPress; + braille = True; + } else { + return(True); } } - return(True); } if( (ev->type != KeyPress) || (((Xim)ic->core.im)->private.local.top == 0 ) ) - return(False); + goto emit_braille; for(t = ic->private.local.context; t; t = b[t].next) { if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) && @@ -105,11 +104,22 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) } } else { /* Unmatched */ if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) { - return(False); + goto emit_braille; } /* Error (Sequence Unmatch occured) */ /* initialize internal state for next key sequence */ ic->private.local.context = ((Xim)ic->core.im)->private.local.top; return(True); } + +emit_braille: + if(braille) { + /* Braille pattern is not in compose tree, emit alone */ + ic->private.local.brl_committed = ic->private.local.brl_committing; + ic->private.local.composed = 0; + ev->xkey.keycode = 0; + _XPutBackEvent(d, ev); + return(True); + } + return(False); } -- cgit v1.2.3 From 4ef27790b18d697aaa4b5cd38d9f896eaeffd469 Mon Sep 17 00:00:00 2001 From: Andreas Wettstein Date: Tue, 8 Nov 2011 20:18:09 +0000 Subject: XIM: Allow modifier releases in compose sequences (#26705) Currently, only non-modifier keys (actually, keysyms) can be part of a compose sequence, and they are matched against the defined compose sequences at the time the key is pressed. The patch allows to use modifier keys an well, but matches them on key release, and only if no other key has been pressed after the modifier. Releasing a non-matched modifier during an ongoing compose sequence only aborts the sequence if any modifier release would have matched. In particular, if no compose sequences with modifiers are specified, the compose mechanism works exactly as without this patch. Even if modifiers are part of a compose sequence, they are not filtered. This is because modifiers affect the keyboard state no matter what we do here and, therefore, filtering them only could confuse clients. The purpose is this extension to the compose mechanism is to allow to make better use of keys in convenient reach for touch typing. Signed-off-by: Andreas Wettstein Signed-off-by: James Cloos Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcFlt.c | 52 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcFlt.c b/nx-X11/lib/X11/imLcFlt.c index e4ab3815c..50f4c252a 100644 --- a/nx-X11/lib/X11/imLcFlt.c +++ b/nx-X11/lib/X11/imLcFlt.c @@ -43,18 +43,17 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) Xic ic = (Xic)client_data; KeySym keysym; static char buf[256]; + static unsigned prevcode = 0, prevstate = 0; + unsigned currstate; DefTree *b = ic->private.local.base.tree; DTIndex t; - Bool braille = False; + Bool braille = False, anymodifier = False; if(ev->xkey.keycode == 0) return (False); XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL); - if(IsModifierKey(keysym)) - return (False); - if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) { if(ev->type == KeyPress) { ic->private.local.brl_pressed |= @@ -78,38 +77,71 @@ _XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data) } } - if( (ev->type != KeyPress) - || (((Xim)ic->core.im)->private.local.top == 0 ) ) + if(((Xim)ic->core.im)->private.local.top == 0 ) goto emit_braille; + currstate = ev->xkey.state; + if(ev->type == KeyPress) { + prevcode = ev->xkey.keycode; + prevstate = currstate; + + if(IsModifierKey(keysym)) + return(False); + prevcode = 0; + } else { + if(prevcode != ev->xkey.keycode) + return False; + + /* For lookup, we use the state at the time when the key was pressed, */ + /* because this state was not affected by the modifier that is mapped */ + /* to the key. */ + ev->xkey.state = prevstate; + XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL); + } + for(t = ic->private.local.context; t; t = b[t].next) { + if(IsModifierKey(b[t].keysym)) + anymodifier = True; if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) && (keysym == b[t].keysym)) break; } + /* Restore the state */ + ev->xkey.state = currstate; + if(t) { /* Matched */ if(b[t].succession) { /* Intermediate */ ic->private.local.context = b[t].succession; - return(True); + return (ev->type == KeyPress); } else { /* Terminate (reached to leaf) */ ic->private.local.composed = t; ic->private.local.brl_committed = 0; /* return back to client KeyPressEvent keycode == 0 */ ev->xkey.keycode = 0; + ev->xkey.type = KeyPress; XPutBackEvent(d, ev); + if(prevcode){ + /* For modifier key releases, restore the event, as we do not */ + /* filter it. */ + ev->xkey.type = KeyRelease; + ev->xkey.keycode = prevcode; + } /* initialize internal state for next key sequence */ ic->private.local.context = ((Xim)ic->core.im)->private.local.top; - return(True); + return (ev->type == KeyPress); } } else { /* Unmatched */ - if(ic->private.local.context == ((Xim)ic->core.im)->private.local.top) { + /* Unmatched modifier key releases abort matching only in the case that */ + /* there was any modifier that would have matched */ + if((ic->private.local.context == ((Xim)ic->core.im)->private.local.top) || + (ev->type == KeyRelease && !anymodifier)) { goto emit_braille; } /* Error (Sequence Unmatch occured) */ /* initialize internal state for next key sequence */ ic->private.local.context = ((Xim)ic->core.im)->private.local.top; - return(True); + return (ev->type == KeyPress); } emit_braille: -- cgit v1.2.3 From 2f49f62a81c51582509bd6abab27b72eb0a29b1f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 14 Oct 2011 17:53:00 -0700 Subject: Fix "nomal" -> "normal" typo in several comments Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcGenConv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index d5f5a9083..9dd7e7104 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -1872,7 +1872,7 @@ output: return -1; } - /* nomal end */ + /* normal end */ *from = (XPointer) inbufptr; *to = (XPointer) outbufptr; @@ -2171,7 +2171,7 @@ end: return -1; } - /* nomal end */ + /* normal end */ *from = (XPointer) inbufptr; *to = (XPointer) outbufptr; @@ -2225,7 +2225,7 @@ end: return -1; } - /* nomal end */ + /* normal end */ *from = (XPointer) src; *from_left = src_left; -- cgit v1.2.3 From 8d1e059403555e7feafdaff788c9e716fcb68ce3 Mon Sep 17 00:00:00 2001 From: Xue Wei Date: Fri, 14 Oct 2011 17:39:21 -0700 Subject: mbtocs should not truncate input Fixes pasting more than 1024 bytes into xterm, as described in https://bugs.freedesktop.org/show_bug.cgi?id=25209 Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcGenConv.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 9dd7e7104..37aca0c25 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -1784,9 +1784,6 @@ mbtocs( return( 0 ); } - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { ch = *inbufptr++; -- cgit v1.2.3 From cded3305d3c10f1b3918ea07120fb527f85b7802 Mon Sep 17 00:00:00 2001 From: Yann Droneaud Date: Tue, 11 Oct 2011 17:27:59 +0200 Subject: Return name instead of False in XSetICValues() In case of error, XSetICValues() must return the first argument that failed to be set. But in some error paths, it returns False, which is converted to NULL, so the function returns OK in case of error. Signed-off-by: Yann Droneaud Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index 3c28b1e29..6761bd351 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -2881,13 +2881,13 @@ _XimSetICValueData( if(mode & XIM_PREEDIT_ATTR) { if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p)) - return False; + return p->name; } else if(mode & XIM_STATUS_ATTR) { if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p)) - return False; + return p->name; } else { if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag)) - return False; + return p->name; } if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) { return p->name; -- cgit v1.2.3 From bec22fe978b41f36e7d9f47480f1fd24d5a23973 Mon Sep 17 00:00:00 2001 From: Yann Droneaud Date: Sun, 9 Oct 2011 17:56:45 +0200 Subject: Return name instead of value in XGetIMValues() and XSetIMValues() As stated in man page (XOpenIM) and Xlib documentation (chapter 13.5.3), XGetIMValues() and XSetImValues() "returns the name of the first argument that could not be obtained." But currently, err = XGetIMValues(im, "invalid", &arg, NULL); returns &arg instead of "invalid". This patch fixes https://bugs.freedesktop.org/show_bug.cgi?id=12897 Signed-off-by: Yann Droneaud Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index 6761bd351..b66bc1421 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -2250,17 +2250,17 @@ _XimSetIMValueData( for(p = values; p->name != NULL; p++) { if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { - return p->value; + return p->name; } check = _XimCheckIMMode(res, XIM_SETIMVALUES); if(check == XIM_CHECK_INVALID) { continue; } else if (check == XIM_CHECK_ERROR) { - return p->value; + return p->name; } if(!_XimEncodeLocalIMAttr(res, top, p->value)) { - return p->value; + return p->name; } } return NULL; @@ -2280,17 +2280,17 @@ _XimGetIMValueData( for(p = values; p->name != NULL; p++) { if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { - return p->value; + return p->name; } check = _XimCheckIMMode(res, XIM_GETIMVALUES); if(check == XIM_CHECK_INVALID) { continue; } else if (check == XIM_CHECK_ERROR) { - return p->value; + return p->name; } if(!_XimDecodeLocalIMAttr(res, top, p->value)) { - return p->value; + return p->name; } } return NULL; -- cgit v1.2.3 From 73a2898af337ea96772dfd1036d7c36e61ac5fd0 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Sun, 9 Oct 2011 02:26:45 -0700 Subject: Fix potential uninitialized variable access in _XimMakeICAttrIDList Found by clang static analysis Signed-off-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRmAttr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index 56a55a13f..52f860553 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -177,6 +177,8 @@ _XimMakeICAttrIDList( else *len += new_len; return name; } + *len += new_len; + buf = (CARD16 *)((char *)buf + new_len); } else if (res->xrm_name == sts_quark) { if ((name = _XimMakeICAttrIDList(ic, res_list, res_num, (XIMArg *)p->value, buf, &new_len, @@ -185,9 +187,10 @@ _XimMakeICAttrIDList( else *len += new_len; return name; } + *len += new_len; + buf = (CARD16 *)((char *)buf + new_len); } - *len += new_len; - buf = (CARD16 *)((char *)buf + new_len); + if (!(res = _XimGetNestedListSeparator(res_list, res_num))) { p++; if (p) { -- cgit v1.2.3 From 6fe8d44ca01c56b5d639c258ad73a5d0b74fc6b8 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Fri, 25 Mar 2011 14:47:35 +0200 Subject: om: Fix memory leaks on get_font_name error paths. While at it, remove unneeded check for NULL before Xfree. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 6b5e30a69..e54b27c29 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -572,7 +572,7 @@ get_rotate_fontname( } if(field_num < CHARSET_ENCODING_FIELD) - return NULL; + goto free_pattern; /* Pixel Size field : fields[6] */ for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) { @@ -581,9 +581,7 @@ get_rotate_fontname( strcpy(pattern, font_name); return(pattern); } - if(pattern) - Xfree(pattern); - return NULL; + goto free_pattern; } } pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]); @@ -602,11 +600,11 @@ get_rotate_fontname( /* Max XLFD length is 255 */ if (len > XLFD_MAX_LEN) - return NULL; + goto free_pattern; rotate_font_ptr = (char *)Xmalloc(len + 1); if(!rotate_font_ptr) - return NULL; + goto free_pattern; rotate_font_ptr[0] = '\0'; @@ -616,8 +614,8 @@ get_rotate_fontname( strcat(rotate_font_ptr, fields[field_num]); } - if(pattern) - Xfree(pattern); +free_pattern: + Xfree(pattern); return rotate_font_ptr; } -- cgit v1.2.3 From 748cf8946537e0c199cbf2f19cdc582001ea8232 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Fri, 25 Mar 2011 16:06:15 +0200 Subject: om: Fix potential memory leak in init_om. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index e54b27c29..dbddc8415 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -2094,22 +2094,24 @@ init_om( if (required_list == NULL) return False; - bufptr = (char *) Xmalloc(length); - if (bufptr == NULL) { - Xfree(required_list); - return False; - } - om->core.required_charset.charset_list = required_list; om->core.required_charset.charset_count = gen->data_num; count = gen->data_num; data = gen->data; - for ( ; count-- > 0; data++) { - strcpy(bufptr, data->font_data->name); - *required_list++ = bufptr; - bufptr += strlen(bufptr) + 1; + if (count > 0) { + bufptr = (char *) Xmalloc(length); + if (bufptr == NULL) { + Xfree(required_list); + return False; + } + + for ( ; count-- > 0; data++) { + strcpy(bufptr, data->font_data->name); + *required_list++ = bufptr; + bufptr += strlen(bufptr) + 1; + } } /* orientation list */ -- cgit v1.2.3 From 9fa1e98dd7c3481f8e1a0d31037c01c5b02440fc Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 20:40:41 +0200 Subject: om: Fix memory leak on read_EncodingInfo error path. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index dbddc8415..1b017cb21 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -1910,8 +1910,10 @@ read_EncodingInfo( } else len = strlen(buf); font_data->name = (char *) Xmalloc(len + 1); - if (font_data->name == NULL) + if (font_data->name == NULL) { + Xfree(font_data); return NULL; + } strncpy(font_data->name, buf,len); font_data->name[len] = 0; if (bufptr && _XlcCompareISOLatin1(bufptr, "GL") == 0) -- cgit v1.2.3 From 60840dc318efb680611ccfeae365b38f370de0bc Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 19:55:33 +0200 Subject: Fix memory leaks on _XimCbDispatch error path. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imCallbk.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imCallbk.c b/nx-X11/lib/X11/imCallbk.c index 866b27c64..6275bbf00 100644 --- a/nx-X11/lib/X11/imCallbk.c +++ b/nx-X11/lib/X11/imCallbk.c @@ -247,6 +247,8 @@ _XimCbDispatch(Xim xim, /* status = XimCbQueued; */ } else { /* status = XimCbError; */ + Xfree(pcb); + Xfree(proto_buf); } } else { -- cgit v1.2.3 From 7024f3d909b8637038d332940ae59b8679092279 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 19:52:05 +0200 Subject: Fix memory leak on _XimCommitRecv error path. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imDefLkup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index e2b1e05bc..53ab78d10 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -687,8 +687,10 @@ _XimCommitRecv( return False; if (!(_XimProcCommit(ic, (BYTE *)&buf_s[5], - (int)buf_s[4], &string, &string_len))) + (int)buf_s[4], &string, &string_len))) { + Xfree(keysym); return False; + } } if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) { -- cgit v1.2.3 From b7cc762ba5b2b724d9181bdf81870bac0e469554 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 19:48:44 +0200 Subject: Fix memory leaks on _XimWriteCachedDefaultTree error paths. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcIm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcIm.c b/nx-X11/lib/X11/imLcIm.c index 81645e5bd..d0ce12d4d 100644 --- a/nx-X11/lib/X11/imLcIm.c +++ b/nx-X11/lib/X11/imLcIm.c @@ -491,10 +491,13 @@ _XimWriteCachedDefaultTree( /* This STILL might be racy on NFS */ if ( (fd = _XOpenFileMode (cachename, O_WRONLY | O_CREAT | O_EXCL, - 0600)) < 0) + 0600)) < 0) { + Xfree(m); return; + } if (! (fp = fdopen (fd, "wb")) ) { close (fd); + Xfree(m); return; } fwrite (m, msize, 1, fp); -- cgit v1.2.3 From 3720ed7bf1528a51c426fd9892a23a1204bbc461 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 19:36:56 +0200 Subject: Fix memory leaks on _XimProtoCreateIC error paths. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imDefIc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index dab0e3c75..6db54bcc2 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -1431,7 +1431,7 @@ _XimProtoCreateIC( num = im->core.ic_num_resources; len = sizeof(XIMResource) * num; if (!(res = (XIMResourceList)Xmalloc(len))) - return (XIC)NULL; + goto ErrorOnCreatingIC; (void)memcpy((char *)res, (char *)im->core.ic_resources, len); ic->private.proto.ic_resources = res; ic->private.proto.ic_num_resources = num; @@ -1459,7 +1459,7 @@ _XimProtoCreateIC( num = im->private.proto.ic_num_inner_resources; len = sizeof(XIMResource) * num; if (!(res = (XIMResourceList)Xmalloc(len))) - return (XIC)NULL; + goto ErrorOnCreatingIC; (void)memcpy((char *)res, (char *)im->private.proto.ic_inner_resources, len); ic->private.proto.ic_inner_resources = res; -- cgit v1.2.3 From 4aa79f1f1f0d2e53b989268747e96f40aca2d538 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Thu, 24 Mar 2011 16:24:29 +0200 Subject: Fix leaks in _XimEncodingNegotiation error paths. name_ptr and detail_ptr weren't free'd in some cases before returning False. Signed-off-by: Ander Conselvan de Oliveira Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imDefIm.c | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imDefIm.c b/nx-X11/lib/X11/imDefIm.c index f29f44436..94e745792 100644 --- a/nx-X11/lib/X11/imDefIm.c +++ b/nx-X11/lib/X11/imDefIm.c @@ -1713,11 +1713,8 @@ _XimEncodingNegotiation( if (!(_XimSetEncodingByName(im, &name_ptr, &name_len))) return False; - if (!(_XimSetEncodingByDetail(im, &detail_ptr, &detail_len))) { - if (name_ptr) - Xfree(name_ptr); - return False; - } + if (!(_XimSetEncodingByDetail(im, &detail_ptr, &detail_len))) + goto free_name_ptr; len = sizeof(CARD16) + sizeof(INT16) @@ -1727,13 +1724,9 @@ _XimEncodingNegotiation( + sizeof(CARD16) + detail_len; - if (!(buf = (CARD8 *)Xmalloc(XIM_HEADER_SIZE + len))) { - if (name_ptr) - Xfree(name_ptr); - if (detail_ptr) - Xfree(detail_ptr); - return False; - } + if (!(buf = (CARD8 *)Xmalloc(XIM_HEADER_SIZE + len))) + goto free_detail_ptr; + buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; buf_s[0] = im->private.proto.imid; @@ -1750,7 +1743,7 @@ _XimEncodingNegotiation( _XimSetHeader((XPointer)buf, XIM_ENCODING_NEGOTIATION, 0, &len); if (!(_XimWrite(im, len, (XPointer)buf))) { Xfree(buf); - return False; + goto free_detail_ptr; } _XimFlush(im); Xfree(buf); @@ -1767,27 +1760,21 @@ _XimEncodingNegotiation( preply = (XPointer)Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimEncodingNegoCheck, 0); - if(ret_code != XIM_TRUE) { - Xfree(preply); - return False; - } + if(ret_code != XIM_TRUE) + goto free_preply; } } else - return False; + goto free_detail_ptr; buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE); if (*((CARD8 *)preply) == XIM_ERROR) { _XimProcError(im, 0, (XPointer)&buf_s[3]); - if(reply != preply) - Xfree(preply); - return False; + goto free_preply; } if (!(_XimGetEncoding(im, &buf_s[1], name_ptr, name_len, - detail_ptr, detail_len))) { - if(reply != preply) - Xfree(preply); - return False; - } + detail_ptr, detail_len))) + goto free_preply; + if (name_ptr) Xfree(name_ptr); if (detail_ptr) @@ -1797,6 +1784,18 @@ _XimEncodingNegotiation( Xfree(preply); return True; + +free_preply: + if (reply != preply) + Xfree(preply); + +free_detail_ptr: + Xfree(detail_ptr); + +free_name_ptr: + Xfree(name_ptr); + + return False; } #ifdef XIM_CONNECTABLE -- cgit v1.2.3 From 018d938aa3aea8bd30bd07736bd4107aa6fda996 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 12 Apr 2011 20:50:42 -0700 Subject: Fix "attrinute" typo in comments in ximcp Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRmAttr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index 52f860553..09521653d 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -1384,7 +1384,7 @@ _XimCountNumberOfAttr( { unsigned int n; INT16 len; - INT16 min_len = sizeof(CARD16) /* sizeof attrinute ID */ + INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */ + sizeof(CARD16) /* sizeof type of value */ + sizeof(INT16); /* sizeof length of attribute */ @@ -1416,7 +1416,7 @@ _XimGetAttributeID( int values_len; register int i; INT16 len; - INT16 min_len = sizeof(CARD16) /* sizeof attrinute ID */ + INT16 min_len = sizeof(CARD16) /* sizeof attribute ID */ + sizeof(CARD16) /* sizeof type of value */ + sizeof(INT16); /* sizeof length of attr */ /* -- cgit v1.2.3 From e4815126b5f0befca091fe7c9ce40477ef1d5f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 10 Jan 2011 16:22:45 +0200 Subject: im/ximcp: release modifiermap before returning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Variable "map" goes out of scope Release modifiermap before returning. Reordered code to call XGetModifierMapping after the first return from the function. Signed-off-by: Erkki Seppälä Reviewed-by: Dirk Wallenstein Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imThaiFlt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imThaiFlt.c b/nx-X11/lib/X11/imThaiFlt.c index 5f67373d1..72f6f2e7a 100644 --- a/nx-X11/lib/X11/imThaiFlt.c +++ b/nx-X11/lib/X11/imThaiFlt.c @@ -1262,15 +1262,22 @@ Private unsigned NumLockMask(Display *d) { int i; - XModifierKeymap *map = XGetModifierMapping (d); + XModifierKeymap *map; KeyCode numlock_keycode = XKeysymToKeycode (d, XK_Num_Lock); if (numlock_keycode == NoSymbol) return 0; + map = XGetModifierMapping (d); + if (!map) + return 0; + for (i = 0; i < 8; i++) { - if (map->modifiermap[map->max_keypermod * i] == numlock_keycode) + if (map->modifiermap[map->max_keypermod * i] == numlock_keycode) { + XFreeModifiermap(map); return 1 << i; + } } + XFreeModifiermap(map); return 0; } -- cgit v1.2.3 From 2cca621e3996246d46a43bb6a4a6df335bf33466 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 21 Feb 2011 21:54:17 +0100 Subject: Make the Local XIM request key releases for braille Braille chords management needs key release events. We need to explicitly request then, else GTK would not pass them throught XFilterEvent and braille wouldn't work. Signed-off-by: Samuel Thibault Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcIc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcIc.c b/nx-X11/lib/X11/imLcIc.c index 4a452269a..60bda4dcb 100644 --- a/nx-X11/lib/X11/imLcIc.c +++ b/nx-X11/lib/X11/imLcIc.c @@ -179,7 +179,7 @@ _XimLocalCreateIC( values, XIM_CREATEIC, True)) { goto Set_Error; } - ic_values.filter_events = KeyPressMask; + ic_values.filter_events = KeyPressMask | KeyReleaseMask; _XimSetCurrentICValues(ic, &ic_values); if(_XimSetICDefaults(ic, (XPointer)&ic_values, XIM_SETICDEFAULTS, res, num) == False) { -- cgit v1.2.3 From 93a4f5c4758f68717c4e8fa8cb346719b265319c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 21 Feb 2011 15:56:54 +0100 Subject: Fix status reporting for braille patterns _XimLocalMbLookupString can return a braille keysym even if _Xlcwctomb can't convert to the current MB charset. _XimLocalUtf8LookupString needs to set the braille keysym and status too. Signed-off-by: Samuel Thibault Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcLkup.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcLkup.c b/nx-X11/lib/X11/imLcLkup.c index fa65ed077..9449b9f43 100644 --- a/nx-X11/lib/X11/imLcLkup.c +++ b/nx-X11/lib/X11/imLcLkup.c @@ -67,12 +67,21 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, if(status) *status = XBufferOverflow; return(ret); } - if(keysym) { - *keysym = XK_braille_blank | pattern; - if(status) *status = XLookupBoth; - } else - if(status) *status = XLookupChars; - memcpy(buffer, mb, ret); + if(keysym) *keysym = XK_braille_blank | pattern; + if(ret > 0) { + if (keysym) { + if(status) *status = XLookupBoth; + } else { + if(status) *status = XLookupChars; + } + memcpy(buffer, mb, ret); + } else { + if(keysym) { + if(status) *status = XLookupKeySym; + } else { + if(status) *status = XLookupNone; + } + } } else { /* Composed Event */ ret = strlen(&mb[b[ic->private.local.composed].mb]); if(ret > bytes) { @@ -213,6 +222,11 @@ _XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f); buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6); buffer[2] = 0x80 | (pattern & 0x3f); + if(keysym) { + *keysym = XK_braille_blank | pattern; + if(status) *status = XLookupBoth; + } else + if(status) *status = XLookupChars; } else { /* Composed Event */ ret = strlen(&utf8[b[ic->private.local.composed].utf8]); if(ret > bytes) { -- cgit v1.2.3 From a8598e06240df4423aea79e659846409be6a75e9 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Mon, 31 Jan 2011 14:02:13 +0200 Subject: lc/def/lcDefConv: Use Xcalloc to avoid use of uninitialized memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed by zero'ing conv on allocation with Xcalloc. Then close_converter works properly. Using uninitialized value "conv->state" in call to function "close_converter" Reviewed-by: Alan Coopersmith Reviewed-by: Erkki Seppälä Signed-off-by: Ander Conselvan de Oliveira Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 2 +- nx-X11/lib/X11/lcGenConv.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index 5860a79a5..12a48615e 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -577,7 +577,7 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 37aca0c25..42d63c529 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -2647,7 +2647,7 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; -- cgit v1.2.3 From 81422098f57f568499de2fba55a606c74575aba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:15 +0200 Subject: ximcp/imLckup: Handle negative return value from _Xlcwctomb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed by negative value to memcpy by checking for the negative return value of _Xlcwctomb and returning 0/XLookupNone in that case. a negative value was passed to memcpy Unfortunately the other return values for *status don't fit into the error (which appears to indicate some internal error or running out of memory). The other valid status codes are XBufferOverflow, XLookupNone, XLookupChars, XLookupKeySym, and XLookupBoth. Each of these has a specific meaning attached. Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcLkup.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcLkup.c b/nx-X11/lib/X11/imLcLkup.c index 9449b9f43..f2f96e280 100644 --- a/nx-X11/lib/X11/imLcLkup.c +++ b/nx-X11/lib/X11/imLcLkup.c @@ -63,6 +63,10 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, unsigned char pattern = ic->private.local.brl_committed; char mb[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)]; ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern); + if(ret < 0) { + if(status) *status = XLookupNone; + return(0); + } if(ret > bytes) { if(status) *status = XBufferOverflow; return(ret); -- cgit v1.2.3 From 89dc7ccfbcaf45db6ca8d5fa548568b7fb7529de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:14 +0200 Subject: ximcp/imTrX: Handle failing XGetWindowProperty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checked return value of XGetWindowProperty and return false if it fails. Return value of "XGetWindowProperty(im->core.display, spec->lib_connect_wid, prop, 0L, (length + bytes_after_ret + 3UL) / 4UL, 1, 0UL, &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret)" is not checked Reviewed-by: Alan Coopersmith Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imTrX.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imTrX.c b/nx-X11/lib/X11/imTrX.c index 6b757cee5..b81c173c5 100644 --- a/nx-X11/lib/X11/imTrX.c +++ b/nx-X11/lib/X11/imTrX.c @@ -377,14 +377,19 @@ _XimXGetReadData( *ret_len = (int)nitems; if (bytes_after_ret > 0) { XFree(prop_ret); - XGetWindowProperty(im->core.display, - spec->lib_connect_wid, prop, 0L, - ((length + bytes_after_ret + 3)/ 4), True, AnyPropertyType, - &type_ret, &format_ret, &nitems, &bytes_after_ret, - &prop_ret); - XChangeProperty(im->core.display, spec->lib_connect_wid, prop, - XA_STRING, 8, PropModePrepend, &prop_ret[length], - (nitems - length)); + if (XGetWindowProperty(im->core.display, + spec->lib_connect_wid, prop, 0L, + ((length + bytes_after_ret + 3)/ 4), + True, AnyPropertyType, + &type_ret, &format_ret, &nitems, + &bytes_after_ret, + &prop_ret) == Success) { + XChangeProperty(im->core.display, spec->lib_connect_wid, prop, + XA_STRING, 8, PropModePrepend, &prop_ret[length], + (nitems - length)); + } else { + return False; + } } } else { (void)memcpy(buf, prop_ret, buf_len); @@ -393,10 +398,14 @@ _XimXGetReadData( if (bytes_after_ret > 0) { XFree(prop_ret); - XGetWindowProperty(im->core.display, - spec->lib_connect_wid, prop, 0L, - ((length + bytes_after_ret + 3)/ 4), True, AnyPropertyType, - &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret); + if (XGetWindowProperty(im->core.display, + spec->lib_connect_wid, prop, 0L, + ((length + bytes_after_ret + 3)/ 4), + True, AnyPropertyType, + &type_ret, &format_ret, &nitems, + &bytes_after_ret, &prop_ret) != Success) { + return False; + } } XChangeProperty(im->core.display, spec->lib_connect_wid, prop, XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len); -- cgit v1.2.3 From 44e472068b163b7be001b74fec1ed98bcdde85e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:01 +0200 Subject: ximcp/imRm: Handle leaking colormap_ret MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed memory leak by adding Xfree for colormap_ret Variable "colormap_ret" goes out of scope Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRm.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index b66bc1421..c0c6d8eb8 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -2808,6 +2808,8 @@ _XimEncodeLocalPreeditValue( ic->core.focus_window, &colormap_ret, &count, (Atom)p->value))) return False; + + Xfree(colormap_ret); } return True; } @@ -2828,6 +2830,8 @@ _XimEncodeLocalStatusValue( ic->core.focus_window, &colormap_ret, &count, (Atom)p->value))) return False; + + Xfree(colormap_ret); } return True; } -- cgit v1.2.3 From 79cb50e4c4e88921b7f97da5431641cc842c19f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:01:59 +0200 Subject: ximcp/imRmAttr: Handle leaking missing_list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed memory leak by adding Xfree and initializing missing_list with NULL Variable "missing_list" goes out of scope Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRmAttr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index 09521653d..fcb347caa 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -316,7 +316,7 @@ _XimAttributeToValue( INT16 len = data[0]; char *base_name; XFontSet rep = (XFontSet)NULL; - char **missing_list; + char **missing_list = NULL; int missing_count; char *def_string; @@ -350,6 +350,7 @@ _XimAttributeToValue( } Xfree(base_name); + Xfree(missing_list); *((XFontSet *)value) = rep; break; } -- cgit v1.2.3 From 3155b9bb225656eb1d3871b65110210a342e8c70 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 27 Oct 2011 13:53:22 +1000 Subject: Use GetReqSized for GetReq and GetReqExtra GetEmptyReq and GetResReq cannot do this due to the final typecast - typically requests that need either of those do not have their own typedef in the protocol headers. Signed-off-by: Peter Hutterer Reviewed-by: Jamey Sharp Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index 5adde76ed..8d7291d01 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -461,10 +461,10 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); #if !defined(UNIXCPP) || defined(ANSICPP) #define GetReq(name, req) \ - req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req)) + GetReqSized(name, SIZEOF(x##name##Req), req) #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ #define GetReq(name, req) \ - req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req)) + GetReqSized(name, SIZEOF(x/**/name/**/Req), req) #endif /* GetReqExtra is the same as GetReq, but allocates "n" additional @@ -472,10 +472,10 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); #if !defined(UNIXCPP) || defined(ANSICPP) #define GetReqExtra(name, n, req) \ - req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req) + n) + GetReqSized(name, SIZEOF(x##name##Req) + n, req) #else #define GetReqExtra(name, n, req) \ - req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req) + n) + GetReqSized(name, SIZEOF(x/**/name/**/Req) + n, req) #endif -- cgit v1.2.3 From 3597915f64c44552c16ce6e0acff9165e6009f9a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 14 Oct 2011 14:51:06 +1000 Subject: include: Add GetReqSized() for request buffers of specific size Some XI2 requests change in size over different versions and libXi would need to hack around GetReq and GetReqExtra. Add a new GetReqSized so the library can explicitly specify the size of the request in 4-byte units. Signed-off-by: Peter Hutterer Reviewed-by: Jamey Sharp Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index 8d7291d01..f4c648634 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -450,6 +450,18 @@ extern LockInfoPtr _Xglobal_lock; */ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); +/* GetReqSized is the same as GetReq but allows the caller to specify the + * size in bytes. 'sz' must be a multiple of 4! */ + +#if !defined(UNIXCPP) || defined(ANSICPP) +#define GetReqSized(name, sz, req) \ + req = (x##name##Req *) _XGetRequest(dpy, X_##name, sz) +#else +#define GetReqSized(name, sz, req) \ + req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, sz) +#endif + + /* * GetReq - Get the next available X request packet in the buffer and * return it. -- cgit v1.2.3 From 3bf350742fe2c828d4e348a797050743ed55a4ac Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 27 Oct 2011 13:24:10 +1000 Subject: Switch GetEmptyReq and GetResReq to call _XGetRequest Signed-off-by: Peter Hutterer Reviewed-by: Jamey Sharp Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index f4c648634..ae5d8c182 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -499,24 +499,12 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); #if !defined(UNIXCPP) || defined(ANSICPP) #define GetResReq(name, rid, req) \ - if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\ - req->reqType = X_##name;\ - req->length = 2;\ - req->id = (rid);\ - dpy->bufptr += SIZEOF(xResourceReq);\ - dpy->request++ + req = (xResourceReq *) _XGetRequest(dpy, X_##name, SIZEOF(xResourceReq)); \ + req->id = (rid) #else #define GetResReq(name, rid, req) \ - if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\ - req->reqType = X_/**/name;\ - req->length = 2;\ - req->id = (rid);\ - dpy->bufptr += SIZEOF(xResourceReq);\ - dpy->request++ + req = (xResourceReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xResourceReq)); \ + req->id = (rid) #endif /* @@ -525,22 +513,10 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); */ #if !defined(UNIXCPP) || defined(ANSICPP) #define GetEmptyReq(name, req) \ - if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (xReq *) (dpy->last_req = dpy->bufptr);\ - req->reqType = X_##name;\ - req->length = 1;\ - dpy->bufptr += SIZEOF(xReq);\ - dpy->request++ + req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq)) #else #define GetEmptyReq(name, req) \ - if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (xReq *) (dpy->last_req = dpy->bufptr);\ - req->reqType = X_/**/name;\ - req->length = 1;\ - dpy->bufptr += SIZEOF(xReq);\ - dpy->request++ + req = (xReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xReq)) #endif /* -- cgit v1.2.3 From cc4d5260e86bfb2c3813081f37d9b694f93bfbba Mon Sep 17 00:00:00 2001 From: Bodo Graumann Date: Mon, 10 Oct 2011 16:40:52 +0200 Subject: libX11: Fixing modifier key range in Xutil.h (Bug #21910) IsModifierKey, defined in include/X11/Xutil.h, is a macro determining, which keys are regarded as modifiers. The constants ISO_Level5_Shift, ISO_Level5_Latch and ISO_Level5_Lock where excluded previously, leaving some Neo2 modifiers functionless in combination with compose. This patch adjusts the range to include the correct, full range of modifier constants. Neo2 Bug 277 X.Org Bug 21910 Signed-off-by: Bodo Graumann Reviewed-by: Daniel Stone Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xutil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xutil.h b/nx-X11/lib/X11/Xutil.h index 2b90005d7..311a66c9d 100644 --- a/nx-X11/lib/X11/Xutil.h +++ b/nx-X11/lib/X11/Xutil.h @@ -251,7 +251,7 @@ typedef struct _XComposeStatus { #define IsModifierKey(keysym) \ ((((KeySym)(keysym) >= XK_Shift_L) && ((KeySym)(keysym) <= XK_Hyper_R)) \ || (((KeySym)(keysym) >= XK_ISO_Lock) && \ - ((KeySym)(keysym) <= XK_ISO_Last_Group_Lock)) \ + ((KeySym)(keysym) <= XK_ISO_Level5_Lock)) \ || ((KeySym)(keysym) == XK_Mode_switch) \ || ((KeySym)(keysym) == XK_Num_Lock)) #else -- cgit v1.2.3 From f3bbb81c4a4b402521bd8d82115d4b178774287d Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Mon, 10 Oct 2011 14:09:17 -0700 Subject: Mark XKeycodeToKeysym as _X_DEPRECATED Signed-off-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlib.h | 1 + 1 file changed, 1 insertion(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlib.h b/nx-X11/lib/X11/Xlib.h index e537c7522..2d688d022 100644 --- a/nx-X11/lib/X11/Xlib.h +++ b/nx-X11/lib/X11/Xlib.h @@ -1688,6 +1688,7 @@ extern XHostAddress *XListHosts( int* /* nhosts_return */, Bool* /* state_return */ ); +_X_DEPRECATED extern KeySym XKeycodeToKeysym( Display* /* display */, #if NeedWidePrototypes -- cgit v1.2.3 From c300a430d36e1f35335896bb7a8a47f3ca8ba863 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 17 May 2011 20:49:59 -0700 Subject: Fix man page and comment references to use XFreeModifiermap (lowercase map) Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index ae5d8c182..8a7144959 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -760,7 +760,7 @@ typedef int (*FreeModmapType) ( */ typedef struct _XFreeFuncs { FreeFuncType atoms; /* _XFreeAtomTable */ - FreeModmapType modifiermap; /* XFreeModifierMap */ + FreeModmapType modifiermap; /* XFreeModifiermap */ FreeFuncType key_bindings; /* _XFreeKeyBindings */ FreeFuncType context_db; /* _XFreeContextDB */ FreeFuncType defaultCCCs; /* _XcmsFreeDefaultCCCs */ -- cgit v1.2.3 From c19cda6d6c63d1889b0d7fd97794ac45cd4e5fca Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Sun, 8 May 2011 09:08:07 -0700 Subject: Silence clang static analysis warnings for SetReqLen This provides a simplified version of the SetReqLen macro when using clang for static analysis. Prior to this change, we would see many Idempotent operation warnings inside this macro due to the common case of calling with arg2 and arg3 being the same variable. This has no effect on code produced during compilation, but it silences a number of false positives in static analysis. XIPassiveGrab.c:170:5: warning: Assigned value is always the same as the existing value SetReqLen(req, num_modifiers, num_modifiers); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from XIPassiveGrab.c:26: .../nx-X11/lib/X11/Xlibint.h:580:8: note: instantiated from: n = badlen; \ ^ Signed-off-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index 8a7144959..cd42913f0 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -558,6 +558,7 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); * Do not use SetReqLen if "req" does not already have data after the * xReq header. req->length must already be >= 2. */ +#ifndef __clang_analyzer__ #define SetReqLen(req,n,badlen) \ if ((req->length + n) > (unsigned)65535) { \ if (dpy->bigreq_size) { \ @@ -568,6 +569,10 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); } \ } else \ req->length += n +#else +#define SetReqLen(req,n,badlen) \ + req->length += n +#endif #define SyncHandle() \ if (dpy->synchandler) (*dpy->synchandler)(dpy) -- cgit v1.2.3 From 5062342d464eecc35cd39df7dd303dcda86d57cc Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Tue, 3 May 2011 09:32:53 -0700 Subject: clang analyzer: Don't warn about Xmalloc(0) This will prevent a number of false positives in where clang's static analysis reports about calls to malloc(0). Signed-off-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index cd42913f0..603139fd6 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -367,7 +367,7 @@ extern LockInfoPtr _Xglobal_lock; * define MALLOC_0_RETURNS_NULL. This is necessary because some * Xlib code expects malloc(0) to return a valid pointer to storage. */ -#ifdef MALLOC_0_RETURNS_NULL +#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__) # define Xmalloc(size) malloc(((size) == 0 ? 1 : (size))) # define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size))) -- cgit v1.2.3 From c868061482102f68353a1eea7fdf275f0cd2600b Mon Sep 17 00:00:00 2001 From: Philipp Reh Date: Wed, 22 Dec 2010 15:14:05 +0000 Subject: Events: Store event cookie when dequeuing event When we dequeue an event in XCheckTypedEvent or XCheckTypedWindowEvent, make sure to store the corresponding cookie too. Signed-off-by: Philipp Reh Reviewed-by: Daniel Stone Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ChkTypEv.c | 1 + nx-X11/lib/X11/ChkTypWEv.c | 1 + 2 files changed, 2 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ChkTypEv.c b/nx-X11/lib/X11/ChkTypEv.c index 8ca1c8048..2e9bcdd0a 100644 --- a/nx-X11/lib/X11/ChkTypEv.c +++ b/nx-X11/lib/X11/ChkTypEv.c @@ -57,6 +57,7 @@ Bool XCheckTypedEvent ( if (qelt->event.type == type) { *event = qelt->event; _XDeq(dpy, prev, qelt); + _XStoreEventCookie(dpy, event); UnlockDisplay(dpy); return True; } diff --git a/nx-X11/lib/X11/ChkTypWEv.c b/nx-X11/lib/X11/ChkTypWEv.c index 92b3f5d94..2f247be26 100644 --- a/nx-X11/lib/X11/ChkTypWEv.c +++ b/nx-X11/lib/X11/ChkTypWEv.c @@ -59,6 +59,7 @@ Bool XCheckTypedWindowEvent ( (qelt->event.type == type)) { *event = qelt->event; _XDeq(dpy, prev, qelt); + _XStoreEventCookie(dpy, event); UnlockDisplay(dpy); return True; } -- cgit v1.2.3 From 7a8721b8a7c6d8b11f1223a8a06ccbfe97ad7352 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 29 Jun 2012 22:57:13 -0700 Subject: XCreate{Pix,Bit}map...Data: Free pixmap in error path if XCreateGC fails Fixes leaks in error paths found by Parfait 1.0.0: Error: X Resource Leak Leaked X Resource pix at line 62 of CrBFData.c in function 'XCreateBitmapFromData'. pix initialized at line 60 with XCreatePixmap Error: X Resource Leak Leaked X Resource pix at line 70 of CrPFBData.c in function 'XCreatePixmapFromBitmapData'. pix initialized at line 66 with XCreatePixmap Signed-off-by: Alan Coopersmith Reviewed-by: Aaron Plattner Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/CrBFData.c | 7 +++++-- nx-X11/lib/X11/CrPFBData.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/CrBFData.c b/nx-X11/lib/X11/CrBFData.c index 449095690..95158755f 100644 --- a/nx-X11/lib/X11/CrBFData.c +++ b/nx-X11/lib/X11/CrBFData.c @@ -58,8 +58,11 @@ Pixmap XCreateBitmapFromData( Pixmap pix; pix = XCreatePixmap(display, d, width, height, 1); - if (! (gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0))) - return (Pixmap) None; + gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0); + if (gc == NULL) { + XFreePixmap(display, pix); + return (Pixmap) None; + } ximage.height = height; ximage.width = width; ximage.depth = 1; diff --git a/nx-X11/lib/X11/CrPFBData.c b/nx-X11/lib/X11/CrPFBData.c index 57cd15303..d343420aa 100644 --- a/nx-X11/lib/X11/CrPFBData.c +++ b/nx-X11/lib/X11/CrPFBData.c @@ -66,8 +66,11 @@ Pixmap XCreatePixmapFromBitmapData( pix = XCreatePixmap(display, d, width, height, depth); gcv.foreground = fg; gcv.background = bg; - if (! (gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv))) - return (Pixmap) NULL; + gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv); + if (gc == NULL) { + XFreePixmap(display, pix); + return (Pixmap) None; + } ximage.height = height; ximage.width = width; ximage.depth = 1; -- cgit v1.2.3 From 97b9864eabf7930e6d72c11a4d35182ef3bd3828 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 29 Jun 2012 23:08:04 -0700 Subject: Convert XCreate{Pix,Bit}map...Data to use C99 designated initializers Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/CrBFData.c | 42 +++++++++++++++++++-------------------- nx-X11/lib/X11/CrPFBData.c | 49 +++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 47 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/CrBFData.c b/nx-X11/lib/X11/CrBFData.c index 95158755f..6708a9b91 100644 --- a/nx-X11/lib/X11/CrBFData.c +++ b/nx-X11/lib/X11/CrBFData.c @@ -53,30 +53,28 @@ Pixmap XCreateBitmapFromData( unsigned int width, unsigned int height) { - XImage ximage; - GC gc; - Pixmap pix; - - pix = XCreatePixmap(display, d, width, height, 1); - gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0); + Pixmap pix = XCreatePixmap(display, d, width, height, 1); + GC gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0); if (gc == NULL) { XFreePixmap(display, pix); return (Pixmap) None; + } else { + XImage ximage = { + .height = height, + .width = width, + .depth = 1, + .bits_per_pixel = 1, + .xoffset = 0, + .format = XYPixmap, + .data = (char *) data, + .byte_order = LSBFirst, + .bitmap_unit = 8, + .bitmap_bit_order = LSBFirst, + .bitmap_pad = 8, + .bytes_per_line = (width + 7) / 8, + }; + XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); + XFreeGC(display, gc); + return(pix); } - ximage.height = height; - ximage.width = width; - ximage.depth = 1; - ximage.bits_per_pixel = 1; - ximage.xoffset = 0; - ximage.format = XYPixmap; - ximage.data = (char *)data; - ximage.byte_order = LSBFirst; - ximage.bitmap_unit = 8; - ximage.bitmap_bit_order = LSBFirst; - ximage.bitmap_pad = 8; - ximage.bytes_per_line = (width+7)/8; - - XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); - XFreeGC(display, gc); - return(pix); } diff --git a/nx-X11/lib/X11/CrPFBData.c b/nx-X11/lib/X11/CrPFBData.c index d343420aa..17d551bb7 100644 --- a/nx-X11/lib/X11/CrPFBData.c +++ b/nx-X11/lib/X11/CrPFBData.c @@ -58,33 +58,32 @@ Pixmap XCreatePixmapFromBitmapData( unsigned long bg, unsigned int depth) { - XImage ximage; - GC gc; - XGCValues gcv; - Pixmap pix; - - pix = XCreatePixmap(display, d, width, height, depth); - gcv.foreground = fg; - gcv.background = bg; - gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv); + Pixmap pix = XCreatePixmap(display, d, width, height, depth); + XGCValues gcv = { + .foreground = fg, + .background = bg + }; + GC gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv); if (gc == NULL) { XFreePixmap(display, pix); return (Pixmap) None; + } else { + XImage ximage = { + .height = height, + .width = width, + .depth = 1, + .bits_per_pixel = 1, + .xoffset = 0, + .format = XYBitmap, + .data = data, + .byte_order = LSBFirst, + .bitmap_unit = 8, + .bitmap_bit_order = LSBFirst, + .bitmap_pad = 8, + .bytes_per_line = (width + 7) / 8 + }; + XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); + XFreeGC(display, gc); + return(pix); } - ximage.height = height; - ximage.width = width; - ximage.depth = 1; - ximage.bits_per_pixel = 1; - ximage.xoffset = 0; - ximage.format = XYBitmap; - ximage.data = data; - ximage.byte_order = LSBFirst; - ximage.bitmap_unit = 8; - ximage.bitmap_bit_order = LSBFirst; - ximage.bitmap_pad = 8; - ximage.bytes_per_line = (width+7)/8; - - XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); - XFreeGC(display, gc); - return(pix); } -- cgit v1.2.3 From 11d6dac92b6c3c3f62d49817809ce8c6a61c9293 Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Mon, 22 Oct 2012 13:54:11 -0500 Subject: XIM: remove Private and Public macros Private is a struct member name in mingw-w64 , causing this useless define in a private header to break the build. Signed-off-by: Yaakov Selkowitz Reviewed-by: Jon TURNEY Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Ximint.h | 7 +- nx-X11/lib/X11/imCallbk.c | 54 +++++------ nx-X11/lib/X11/imDefFlt.c | 40 ++++----- nx-X11/lib/X11/imDefIc.c | 60 ++++++------- nx-X11/lib/X11/imDefIm.c | 96 ++++++++++---------- nx-X11/lib/X11/imDefLkup.c | 74 +++++++-------- nx-X11/lib/X11/imDispch.c | 8 +- nx-X11/lib/X11/imExten.c | 34 +++---- nx-X11/lib/X11/imImSw.c | 2 +- nx-X11/lib/X11/imInsClbk.c | 14 +-- nx-X11/lib/X11/imInt.c | 20 ++--- nx-X11/lib/X11/imLcGIc.c | 2 +- nx-X11/lib/X11/imLcIc.c | 16 ++-- nx-X11/lib/X11/imLcIm.c | 34 +++---- nx-X11/lib/X11/imLcLkup.c | 14 +-- nx-X11/lib/X11/imLcSIc.c | 2 +- nx-X11/lib/X11/imRm.c | 220 ++++++++++++++++++++++----------------------- nx-X11/lib/X11/imRmAttr.c | 48 +++++----- nx-X11/lib/X11/imThaiFlt.c | 98 ++++++++++---------- nx-X11/lib/X11/imThaiIc.c | 14 +-- nx-X11/lib/X11/imThaiIm.c | 8 +- nx-X11/lib/X11/imTrX.c | 28 +++--- nx-X11/lib/X11/imTrans.c | 22 ++--- nx-X11/lib/X11/imTransR.c | 22 ++--- 24 files changed, 467 insertions(+), 470 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Ximint.h b/nx-X11/lib/X11/Ximint.h index f39053f84..9550c6851 100644 --- a/nx-X11/lib/X11/Ximint.h +++ b/nx-X11/lib/X11/Ximint.h @@ -36,9 +36,6 @@ PERFORMANCE OF THIS SOFTWARE. #include #include -#define Public /**/ -#define Private static - typedef struct _Xim *Xim; typedef struct _Xic *Xic; @@ -982,7 +979,7 @@ extern Bool _XimEncodeSavedICATTRIBUTE( ); #endif -extern Public Bool +extern Bool _XimRegisterDispatcher( Xim im, Bool (*callback)( @@ -990,7 +987,7 @@ _XimRegisterDispatcher( ), XPointer call_data); -extern Public Bool +extern Bool _XimRespSyncReply( Xic ic, BITMASK16 mode); diff --git a/nx-X11/lib/X11/imCallbk.c b/nx-X11/lib/X11/imCallbk.c index 6275bbf00..f57a8de31 100644 --- a/nx-X11/lib/X11/imCallbk.c +++ b/nx-X11/lib/X11/imCallbk.c @@ -92,17 +92,17 @@ typedef XimCbStatus (*XimCb)( (im->private.proto.read((im),(XPointer)(buf),(buf_len),&(len))) #define _XimFlushData(im) im->private.proto.flush((im)) -Private XimCbStatus _XimGeometryCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimStrConversionCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimPreeditStartCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimPreeditDoneCallback(Xim, Xic, char*, int); -Private void _free_memory_for_text(XIMText*); -Private XimCbStatus _XimPreeditDrawCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimPreeditCaretCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimStatusStartCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimStatusDoneCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimStatusDrawCallback(Xim, Xic, char*, int); -Private XimCbStatus _XimPreeditStateNotifyCallback(Xim, Xic, char *, int); +static XimCbStatus _XimGeometryCallback(Xim, Xic, char*, int); +static XimCbStatus _XimStrConversionCallback(Xim, Xic, char*, int); +static XimCbStatus _XimPreeditStartCallback(Xim, Xic, char*, int); +static XimCbStatus _XimPreeditDoneCallback(Xim, Xic, char*, int); +static void _free_memory_for_text(XIMText*); +static XimCbStatus _XimPreeditDrawCallback(Xim, Xic, char*, int); +static XimCbStatus _XimPreeditCaretCallback(Xim, Xic, char*, int); +static XimCbStatus _XimStatusStartCallback(Xim, Xic, char*, int); +static XimCbStatus _XimStatusDoneCallback(Xim, Xic, char*, int); +static XimCbStatus _XimStatusDrawCallback(Xim, Xic, char*, int); +static XimCbStatus _XimPreeditStateNotifyCallback(Xim, Xic, char *, int); #if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32)) #define RConst /**/ @@ -138,13 +138,13 @@ static RConst XimCb callback_table[] = { }; -Private Bool +static Bool _XimIsReadyForProcess(Xic ic) { return(!ic->private.proto.waitCallback); /* check HM */ } -Private void +static void _XimProcessPendingCallbacks(Xic ic) { XimPendingCallback pcbq; @@ -161,7 +161,7 @@ _XimProcessPendingCallbacks(Xic ic) } } -Private void +static void _XimPutCbIntoQueue(Xic ic, XimPendingCallback call_data) { XimPendingCallback pcbq = ic->private.proto.pend_cb_que; @@ -182,7 +182,7 @@ _XimPutCbIntoQueue(Xic ic, XimPendingCallback call_data) } } -Public Bool +Bool _XimCbDispatch(Xim xim, INT16 len, XPointer data, @@ -261,7 +261,7 @@ _XimCbDispatch(Xim xim, return True; } -Private XimCbStatus +static XimCbStatus _XimGeometryCallback(Xim im, Xic ic, char* proto, @@ -284,7 +284,7 @@ _XimGeometryCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimStrConversionCallback(Xim im, Xic ic, char* proto, @@ -367,7 +367,7 @@ _XimStrConversionCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimPreeditStartCallback(Xim im, Xic ic, char* proto, @@ -416,7 +416,7 @@ _XimPreeditStartCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimPreeditDoneCallback(Xim im, Xic ic, char* proto, @@ -439,7 +439,7 @@ _XimPreeditDoneCallback(Xim im, return XimCbSuccess; } -Private void +static void _read_text_from_packet(Xim im, char* buf, XIMText** text_ptr) @@ -554,7 +554,7 @@ _read_text_from_packet(Xim im, } } -Private void +static void _free_memory_for_text(XIMText* text) { if (text) { @@ -566,7 +566,7 @@ _free_memory_for_text(XIMText* text) } } -Private XimCbStatus +static XimCbStatus _XimPreeditDrawCallback(Xim im, Xic ic, char* proto, @@ -597,7 +597,7 @@ _XimPreeditDrawCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimPreeditCaretCallback(Xim im, Xic ic, char* proto, @@ -649,7 +649,7 @@ _XimPreeditCaretCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimStatusStartCallback(Xim im, Xic ic, char* proto, @@ -672,7 +672,7 @@ _XimStatusStartCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimStatusDoneCallback(Xim im, Xic ic, char* proto, @@ -695,7 +695,7 @@ _XimStatusDoneCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimStatusDrawCallback(Xim im, Xic ic, char* proto, @@ -730,7 +730,7 @@ _XimStatusDrawCallback(Xim im, return XimCbSuccess; } -Private XimCbStatus +static XimCbStatus _XimPreeditStateNotifyCallback( Xim im, Xic ic, char* proto, int len ) { XICCallback *cb = &ic->core.preedit_attr.state_notify_callback; diff --git a/nx-X11/lib/X11/imDefFlt.c b/nx-X11/lib/X11/imDefFlt.c index 6259fb7f7..b6473e176 100644 --- a/nx-X11/lib/X11/imDefFlt.c +++ b/nx-X11/lib/X11/imDefFlt.c @@ -35,7 +35,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Private long +static long _XimTriggerCheck( Xim im, XKeyEvent *ev, @@ -66,7 +66,7 @@ _XimTriggerCheck( return -1; } -Private long +static long _XimTriggerOnCheck( Xim im, XKeyEvent *ev) @@ -75,7 +75,7 @@ _XimTriggerOnCheck( &im->private.proto.im_onkeylist[1]); } -Private long +static long _XimTriggerOffCheck( Xim im, XKeyEvent *ev) @@ -84,7 +84,7 @@ _XimTriggerOffCheck( &im->private.proto.im_offkeylist[1]); } -Private Bool +static Bool _XimOnKeysCheck( Xic ic, XKeyEvent *ev) @@ -103,7 +103,7 @@ _XimOnKeysCheck( return False; } -Private Bool +static Bool _XimOffKeysCheck( Xic ic, XKeyEvent *ev) @@ -122,7 +122,7 @@ _XimOffKeysCheck( return False; } -Private void +static void _XimPendingFilter( Xic ic) { @@ -135,7 +135,7 @@ _XimPendingFilter( return; } -Private Bool +static Bool _XimProtoKeypressFilter( Xic ic, XKeyEvent *ev) @@ -186,7 +186,7 @@ _XimProtoKeypressFilter( return NOTFILTERD; } -Private Bool +static Bool _XimFilterKeypress( Display *d, Window w, @@ -196,7 +196,7 @@ _XimFilterKeypress( return _XimProtoKeypressFilter((Xic)client_data, (XKeyEvent *)ev ); } -Private Bool +static Bool _XimProtoKeyreleaseFilter( Xic ic, XKeyEvent *ev) @@ -247,7 +247,7 @@ _XimProtoKeyreleaseFilter( return NOTFILTERD; } -Private Bool +static Bool _XimFilterKeyrelease( Display *d, Window w, @@ -257,7 +257,7 @@ _XimFilterKeyrelease( return _XimProtoKeyreleaseFilter((Xic)client_data, (XKeyEvent *)ev); } -Private void +static void _XimRegisterKeyPressFilter( Xic ic) { @@ -274,7 +274,7 @@ _XimRegisterKeyPressFilter( return; } -Private void +static void _XimRegisterKeyReleaseFilter( Xic ic) { @@ -291,7 +291,7 @@ _XimRegisterKeyReleaseFilter( return; } -Private void +static void _XimUnregisterKeyPressFilter( Xic ic) { @@ -307,7 +307,7 @@ _XimUnregisterKeyPressFilter( return; } -Private void +static void _XimUnregisterKeyReleaseFilter( Xic ic) { @@ -323,7 +323,7 @@ _XimUnregisterKeyReleaseFilter( return; } -Public void +void _XimRegisterFilter( Xic ic) { @@ -333,7 +333,7 @@ _XimRegisterFilter( return; } -Public void +void _XimUnregisterFilter( Xic ic) { @@ -342,7 +342,7 @@ _XimUnregisterFilter( return; } -Public void +void _XimReregisterFilter( Xic ic) { @@ -354,7 +354,7 @@ _XimReregisterFilter( return; } -Private Bool +static Bool _XimFilterServerDestroy( Display *d, Window w, @@ -376,7 +376,7 @@ _XimFilterServerDestroy( return True; } -Public void +void _XimRegisterServerFilter( Xim im) { @@ -395,7 +395,7 @@ _XimRegisterServerFilter( return; } -Public void +void _XimUnregisterServerFilter( Xim im) { diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index 6db54bcc2..4aae8e006 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -56,7 +56,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Private Bool +static Bool _XimCreateICCheck( Xim im, INT16 len, @@ -81,7 +81,7 @@ _XimCreateICCheck( } #ifdef XIM_CONNECTABLE -Public Bool +Bool _XimReCreateIC(ic) Xic ic; { @@ -244,7 +244,7 @@ ErrorOnReCreateIC: return False; } -Private char * +static char * _XimDelayModeGetICValues(ic, arg) Xic ic; XIMArg *arg; @@ -259,7 +259,7 @@ _XimDelayModeGetICValues(ic, arg) } #endif /* XIM_CONNECTABLE */ -Private Bool +static Bool _XimGetICValuesCheck( Xim im, INT16 len, @@ -288,7 +288,7 @@ _XimGetICValuesCheck( return False; } -Private char * +static char * _XimProtoGetICValues( XIC xic, XIMArg *arg) @@ -424,7 +424,7 @@ _XimProtoGetICValues( } #ifdef XIM_CONNECTABLE -Private Bool +static Bool _XimCheckNestQuarkList(quark_list, num_quark, quark, separator) XrmQuark *quark_list; int num_quark; @@ -444,7 +444,7 @@ _XimCheckNestQuarkList(quark_list, num_quark, quark, separator) return False; } -Private Bool +static Bool _XimCheckNestedQuarkList(quark_list, idx, num_quark, arg, separator) XrmQuark **quark_list; int idx; @@ -485,7 +485,7 @@ _XimCheckNestedQuarkList(quark_list, idx, num_quark, arg, separator) return True; } -Private Bool +static Bool _XimCheckICQuarkList(quark_list, num_quark, quark, idx) XrmQuark *quark_list; int num_quark; @@ -503,7 +503,7 @@ _XimCheckICQuarkList(quark_list, num_quark, quark, idx) return False; } -Private Bool +static Bool _XimSaveICValues(ic, arg) Xic ic; XIMArg *arg; @@ -610,7 +610,7 @@ _XimSaveICValues(ic, arg) return True; } -Private char * +static char * _XimDelayModeSetICValues(ic, arg) Xic ic; XIMArg *arg; @@ -628,7 +628,7 @@ _XimDelayModeSetICValues(ic, arg) } #endif /* XIM_CONNECTABLE */ -Private Bool +static Bool _XimSetICValuesCheck( Xim im, INT16 len, @@ -657,7 +657,7 @@ _XimSetICValuesCheck( return False; } -Private char * +static char * _XimProtoSetICValues( XIC xic, XIMArg *arg) @@ -807,7 +807,7 @@ _XimProtoSetICValues( return name; } -Private Bool +static Bool _XimDestroyICCheck( Xim im, INT16 len, @@ -837,7 +837,7 @@ _XimDestroyICCheck( return ret; } -Private void +static void _XimProtoICFree( Xic ic) { @@ -884,7 +884,7 @@ _XimProtoICFree( return; } -Private void +static void _XimProtoDestroyIC( XIC xic) { @@ -927,7 +927,7 @@ _XimProtoDestroyIC( return; } -Private void +static void _XimProtoSetFocus( XIC xic) { @@ -972,7 +972,7 @@ _XimProtoSetFocus( return; } -Private void +static void _XimProtoUnsetFocus( XIC xic) { @@ -1017,7 +1017,7 @@ _XimProtoUnsetFocus( return; } -Private Bool +static Bool _XimResetICCheck( Xim im, INT16 len, @@ -1046,7 +1046,7 @@ _XimResetICCheck( return False; } -Private char * +static char * _XimProtoReset( XIC xic, char * (*retfunc) (Xim im, Xic ic, XPointer buf) ) @@ -1117,7 +1117,7 @@ _XimProtoReset( return commit; } -Private char * +static char * _XimCommitedMbString( Xim im, Xic ic, @@ -1167,14 +1167,14 @@ Error_On_Reset: return new_commit; } -Private char * +static char * _XimProtoMbReset( XIC xic) { return _XimProtoReset(xic, _XimCommitedMbString); } -Private wchar_t * +static wchar_t * _XimCommitedWcString( Xim im, Xic ic, @@ -1225,7 +1225,7 @@ Error_On_Reset: return new_commit; } -Private wchar_t * +static wchar_t * _XimProtoWcReset( XIC xic) { @@ -1233,7 +1233,7 @@ _XimProtoWcReset( (char * (*) (Xim, Xic, XPointer)) _XimCommitedWcString); } -Private char * +static char * _XimCommitedUtf8String( Xim im, Xic ic, @@ -1283,14 +1283,14 @@ Error_On_Reset: return new_commit; } -Private char * +static char * _XimProtoUtf8Reset( XIC xic) { return _XimProtoReset(xic, _XimCommitedUtf8String); } -Private XICMethodsRec ic_methods = { +static XICMethodsRec ic_methods = { _XimProtoDestroyIC, /* destroy */ _XimProtoSetFocus, /* set_focus */ _XimProtoUnsetFocus, /* unset_focus */ @@ -1304,7 +1304,7 @@ Private XICMethodsRec ic_methods = { _XimProtoUtf8LookupString /* utf8_lookup_string */ }; -Private Bool +static Bool _XimGetInputStyle( XIMArg *arg, XIMStyle *input_style) @@ -1321,7 +1321,7 @@ _XimGetInputStyle( } #ifdef XIM_CONNECTABLE -Private Bool +static Bool _XimDelayModeCreateIC( Xic ic, XIMArg *values, @@ -1356,7 +1356,7 @@ _XimDelayModeCreateIC( return True; } -Public Bool +Bool _XimReconnectModeCreateIC(ic) Xic ic; { @@ -1382,7 +1382,7 @@ _XimReconnectModeCreateIC(ic) } #endif /* XIM_CONNECTABLE */ -Public XIC +XIC _XimProtoCreateIC( XIM xim, XIMArg *arg) diff --git a/nx-X11/lib/X11/imDefIm.c b/nx-X11/lib/X11/imDefIm.c index 94e745792..34c0345b8 100644 --- a/nx-X11/lib/X11/imDefIm.c +++ b/nx-X11/lib/X11/imDefIm.c @@ -63,7 +63,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Ximint.h" -Public int +int _XimCheckDataSize( XPointer buf, int len) @@ -75,7 +75,7 @@ _XimCheckDataSize( return buf_s[1]; } -Public void +void _XimSetHeader( XPointer buf, CARD8 major_opcode, @@ -93,7 +93,7 @@ _XimSetHeader( return; } -Public char +char _XimGetMyEndian(void) { CARD16 test_card = 1; @@ -104,7 +104,7 @@ _XimGetMyEndian(void) return BIGENDIAN; } -Private Bool +static Bool _XimCheckServerName( Xim im, char *str) @@ -142,7 +142,7 @@ _XimCheckServerName( return True; } -Private char * +static char * _XimCheckLocaleName( Xim im, char *address, @@ -182,7 +182,7 @@ _XimCheckLocaleName( return (char *)NULL; } -Private Bool +static Bool _XimCheckTransport( char *address, int address_len, @@ -226,7 +226,7 @@ _XimCheckTransport( return True; } -Private Bool +static Bool _CheckSNEvent( Display *display, XEvent *xevent, @@ -240,7 +240,7 @@ _CheckSNEvent( return False; } -Private Bool +static Bool _XimGetSelectionNotify( Display *display, Window window, @@ -269,7 +269,7 @@ _XimGetSelectionNotify( return True; } -Private Bool +static Bool _XimPreConnectionIM( Xim im, Atom selection) @@ -387,7 +387,7 @@ Error: return False; } -Private Bool +static Bool _XimPreConnect( Xim im) { @@ -434,7 +434,7 @@ _XimPreConnect( return True; } -Private Bool +static Bool _XimGetAuthProtocolNames( Xim im, CARD16 *buf, @@ -452,7 +452,7 @@ _XimGetAuthProtocolNames( return True; } -Private Bool +static Bool _XimSetAuthReplyData( Xim im, XPointer buf, @@ -465,7 +465,7 @@ _XimSetAuthReplyData( return True; } -Private Bool +static Bool _XimSetAuthNextData( Xim im, XPointer buf, @@ -478,7 +478,7 @@ _XimSetAuthNextData( return True; } -Private Bool +static Bool _XimSetAuthRequiredData( Xim im, XPointer buf, @@ -491,7 +491,7 @@ _XimSetAuthRequiredData( return True; } -Private Bool +static Bool _XimCheckAuthSetupData( Xim im, XPointer buf) @@ -502,7 +502,7 @@ _XimCheckAuthSetupData( return True; } -Private Bool +static Bool _XimCheckAuthNextData( Xim im, XPointer buf) @@ -517,7 +517,7 @@ _XimCheckAuthNextData( #define GOOD_AUTH 1 #define BAD_AUTH 0 -Private int +static int _XimClientAuthCheck( Xim im, XPointer buf) @@ -528,7 +528,7 @@ _XimClientAuthCheck( return NO_MORE_AUTH; } -Private void +static void _XimAuthNG( Xim im) { @@ -542,7 +542,7 @@ _XimAuthNG( return; } -Private Bool +static Bool _XimAllRecv( Xim im, INT16 len, @@ -555,7 +555,7 @@ _XimAllRecv( #define CLIENT_WAIT1 1 #define CLIENT_WAIT2 2 -Private Bool +static Bool _XimConnection( Xim im) { @@ -716,7 +716,7 @@ _XimConnection( return True; } -Private Bool +static Bool _XimDisconnectCheck( Xim im, INT16 len, @@ -735,7 +735,7 @@ _XimDisconnectCheck( return False; } -Private Bool +static Bool _XimDisconnect( Xim im) { @@ -775,7 +775,7 @@ _XimDisconnect( return True; } -Private Bool +static Bool _XimOpenCheck( Xim im, INT16 len, @@ -794,7 +794,7 @@ _XimOpenCheck( return False; } -Private Bool +static Bool _XimOpen( Xim im) { @@ -890,7 +890,7 @@ _XimOpen( return True; } -Private Bool +static Bool _XimCloseCheck( Xim im, INT16 len, @@ -914,7 +914,7 @@ _XimCloseCheck( return False; } -Private Bool +static Bool _XimClose( Xim im) { @@ -972,7 +972,7 @@ _XimClose( return True; } -Public void +void _XimProtoIMFree( Xim im) { @@ -1090,7 +1090,7 @@ _XimProtoIMFree( return; } -Private Status +static Status _XimProtoCloseIM( XIM xim) { @@ -1138,7 +1138,7 @@ _XimProtoCloseIM( } #ifdef XIM_CONNECTABLE -Private Bool +static Bool _XimCheckIMQuarkList( XrmQuark *quark_list, int num_quark, @@ -1154,7 +1154,7 @@ _XimCheckIMQuarkList( return False; } -Private Bool +static Bool _XimSaveIMValues( Xim im, XIMArg *arg) @@ -1203,7 +1203,7 @@ _XimSaveIMValues( return True; } -Private char * +static char * _XimDelayModeSetIMValues( Xim im, XIMArg *arg) @@ -1221,7 +1221,7 @@ _XimDelayModeSetIMValues( } #endif /* XIM_CONNECTABLE */ -Private Bool +static Bool _XimSetIMValuesCheck( Xim im, INT16 len, @@ -1245,7 +1245,7 @@ _XimSetIMValuesCheck( return False; } -Private char * +static char * _XimProtoSetIMValues( XIM xim, XIMArg *arg) @@ -1377,7 +1377,7 @@ _XimProtoSetIMValues( } #ifdef XIM_CONNECTABLE -Private char * +static char * _XimDelayModeGetIMValues( Xim im, XIMArg *arg) @@ -1390,7 +1390,7 @@ _XimDelayModeGetIMValues( } #endif /* XIM_CONNECTABLE */ -Private Bool +static Bool _XimGetIMValuesCheck( Xim im, INT16 len, @@ -1414,7 +1414,7 @@ _XimGetIMValuesCheck( return False; } -Private char * +static char * _XimProtoGetIMValues( XIM xim, XIMArg *arg) @@ -1526,7 +1526,7 @@ _XimProtoGetIMValues( return makeid_name; } -Private XIMMethodsRec im_methods = { +static XIMMethodsRec im_methods = { _XimProtoCloseIM, /* close */ _XimProtoSetIMValues, /* set_values */ _XimProtoGetIMValues, /* get_values */ @@ -1536,7 +1536,7 @@ Private XIMMethodsRec im_methods = { _Ximctstoutf8 /* ctstoutf8 */ }; -Private Bool +static Bool _XimSetEncodingByName( Xim im, char **buf, @@ -1569,7 +1569,7 @@ _XimSetEncodingByName( return True; } -Private Bool +static Bool _XimSetEncodingByDetail( Xim im, char **buf, @@ -1580,7 +1580,7 @@ _XimSetEncodingByDetail( return True; } -Private Bool +static Bool _XimGetEncoding( Xim im, CARD16 *buf, @@ -1669,7 +1669,7 @@ _XimGetEncoding( return True; } -Private Bool +static Bool _XimEncodingNegoCheck( Xim im, INT16 len, @@ -1693,7 +1693,7 @@ _XimEncodingNegoCheck( return False; } -Private Bool +static Bool _XimEncodingNegotiation( Xim im) { @@ -1799,7 +1799,7 @@ free_name_ptr: } #ifdef XIM_CONNECTABLE -Private Bool +static Bool _XimSendSavedIMValues( Xim im) { @@ -1909,7 +1909,7 @@ _XimSendSavedIMValues( return True; } -Private void +static void _XimDelayModeIMFree( Xim im) { @@ -1932,7 +1932,7 @@ _XimDelayModeIMFree( return; } -Public Bool +Bool _XimConnectServer( Xim im) { @@ -1956,7 +1956,7 @@ _XimConnectServer( return False; } -Public Bool +Bool _XimDelayModeSetAttr( Xim im) { @@ -1988,7 +1988,7 @@ _XimDelayModeSetAttr( return True; } -Private Bool +static Bool _XimReconnectModeSetAttr( Xim im) { @@ -2015,7 +2015,7 @@ _XimReconnectModeSetAttr( } #endif /* XIM_CONNECTABLE */ -Public Bool +Bool _XimProtoOpenIM( Xim im) { diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index 53ab78d10..0ce3f787a 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -34,7 +34,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Public Xic +Xic _XimICOfXICID( Xim im, XICID icid) @@ -48,7 +48,7 @@ _XimICOfXICID( return (Xic)0; } -Private void +static void _XimProcIMSetEventMask( Xim im, XPointer buf) @@ -60,7 +60,7 @@ _XimProcIMSetEventMask( return; } -Private void +static void _XimProcICSetEventMask( Xic ic, XPointer buf) @@ -73,7 +73,7 @@ _XimProcICSetEventMask( return; } -Public Bool +Bool _XimSetEventMaskCallback( Xim xim, INT16 len, @@ -98,7 +98,7 @@ _XimSetEventMaskCallback( return False; } -Private Bool +static Bool _XimSyncCheck( Xim im, INT16 len, @@ -127,7 +127,7 @@ _XimSyncCheck( return False; } -Public Bool +Bool _XimSync( Xim im, Xic ic) @@ -185,7 +185,7 @@ _XimSync( return True; } -Public Bool +Bool _XimProcSyncReply( Xim im, Xic ic) @@ -208,7 +208,7 @@ _XimProcSyncReply( return True; } -Public Bool +Bool _XimRespSyncReply( Xic ic, BITMASK16 mode) @@ -219,7 +219,7 @@ _XimRespSyncReply( return True; } -Public Bool +Bool _XimSyncCallback( Xim xim, INT16 len, @@ -240,7 +240,7 @@ _XimSyncCallback( return False; } -Private INT16 +static INT16 _XimSetEventToWire( XEvent *ev, xEvent *event) @@ -252,7 +252,7 @@ _XimSetEventToWire( return sz_xEvent; } -Private Bool +static Bool _XimForwardEventCore( Xic ic, XEvent *ev, @@ -324,7 +324,7 @@ _XimForwardEventCore( return True; } -Public Bool +Bool _XimForwardEvent( Xic ic, XEvent *ev, @@ -338,7 +338,7 @@ _XimForwardEvent( return _XimForwardEventCore(ic, ev, sync); } -Private void +static void _XimProcEvent( Display *d, Xic ic, @@ -356,7 +356,7 @@ _XimProcEvent( return; } -Private Bool +static Bool _XimForwardEventRecv( Xim im, Xic ic, @@ -375,7 +375,7 @@ _XimForwardEventRecv( return True; } -Public Bool +Bool _XimForwardEventCallback( Xim xim, INT16 len, @@ -396,7 +396,7 @@ _XimForwardEventCallback( return False; } -Private Bool +static Bool _XimRegisterTriggerkey( Xim im, XPointer buf) @@ -443,7 +443,7 @@ _XimRegisterTriggerkey( return True; } -Public Bool +Bool _XimRegisterTriggerKeysCallback( Xim xim, INT16 len, @@ -457,7 +457,7 @@ _XimRegisterTriggerKeysCallback( return True; } -Public EVENTMASK +EVENTMASK _XimGetWindowEventmask( Xic ic) { @@ -470,7 +470,7 @@ _XimGetWindowEventmask( } -Private Bool +static Bool _XimTriggerNotifyCheck( Xim im, INT16 len, @@ -499,7 +499,7 @@ _XimTriggerNotifyCheck( return False; } -Public Bool +Bool _XimTriggerNotify( Xim im, Xic ic, @@ -567,7 +567,7 @@ _XimTriggerNotify( return True; } -Private Bool +static Bool _XimRegCommitInfo( Xic ic, char *string, @@ -588,7 +588,7 @@ _XimRegCommitInfo( return True; } -Private void +static void _XimUnregCommitInfo( Xic ic) { @@ -606,7 +606,7 @@ _XimUnregCommitInfo( return; } -Public void +void _XimFreeCommitInfo( Xic ic) { @@ -615,7 +615,7 @@ _XimFreeCommitInfo( return; } -Private Bool +static Bool _XimProcKeySym( Xic ic, CARD32 sym, @@ -635,7 +635,7 @@ _XimProcKeySym( return True; } -Private Bool +static Bool _XimProcCommit( Xic ic, BYTE *buf, @@ -659,7 +659,7 @@ _XimProcCommit( return True; } -Private Bool +static Bool _XimCommitRecv( Xim im, Xic ic, @@ -718,7 +718,7 @@ _XimCommitRecv( return True; } -Public Bool +Bool _XimCommitCallback( Xim xim, INT16 len, @@ -739,7 +739,7 @@ _XimCommitCallback( return False; } -Public void +void _XimProcError( Xim im, Xic ic, @@ -748,7 +748,7 @@ _XimProcError( return; } -Public Bool +Bool _XimErrorCallback( Xim xim, INT16 len, @@ -777,7 +777,7 @@ _XimErrorCallback( return True; } -Public Bool +Bool _XimError( Xim im, Xic ic, @@ -821,7 +821,7 @@ _XimError( return True; } -Private int +static int _Ximctsconvert( XlcConv conv, char *from, @@ -887,7 +887,7 @@ _Ximctsconvert( return to_cnvlen; } -Public int +int _Ximctstombs(XIM xim, char *from, int from_len, char *to, int to_len, Status *state) { @@ -895,7 +895,7 @@ _Ximctstombs(XIM xim, char *from, int from_len, from, from_len, to, to_len, state); } -Public int +int _Ximctstowcs( XIM xim, char *from, @@ -963,7 +963,7 @@ _Ximctstowcs( return to_cnvlen; } -Public int +int _Ximctstoutf8( XIM xim, char *from, @@ -976,7 +976,7 @@ _Ximctstoutf8( from, from_len, to, to_len, state); } -Public int +int _XimProtoMbLookupString( XIC xic, XKeyEvent *ev, @@ -1039,7 +1039,7 @@ _XimProtoMbLookupString( return ret; } -Public int +int _XimProtoWcLookupString( XIC xic, XKeyEvent *ev, @@ -1102,7 +1102,7 @@ _XimProtoWcLookupString( return ret; } -Public int +int _XimProtoUtf8LookupString( XIC xic, XKeyEvent *ev, diff --git a/nx-X11/lib/X11/imDispch.c b/nx-X11/lib/X11/imDispch.c index cd4870671..888e2fd4b 100644 --- a/nx-X11/lib/X11/imDispch.c +++ b/nx-X11/lib/X11/imDispch.c @@ -36,7 +36,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Ximint.h" -Public Bool +Bool _XimRegProtoIntrCallback( Xim im, CARD16 major_code, @@ -60,7 +60,7 @@ _XimRegProtoIntrCallback( return True; } -Public void +void _XimFreeProtoIntrCallback(Xim im) { register XimProtoIntrRec *rec, *next; @@ -74,7 +74,7 @@ _XimFreeProtoIntrCallback(Xim im) return; } -Private Bool +static Bool _XimTransportIntr( Xim im, INT16 len, @@ -95,7 +95,7 @@ _XimTransportIntr( return False; } -Public Bool +Bool _XimDispatchInit(Xim im) { if (_XimRegisterDispatcher(im, _XimTransportIntr, (XPointer)im)) diff --git a/nx-X11/lib/X11/imExten.c b/nx-X11/lib/X11/imExten.c index c7b9ed11e..779cead0b 100644 --- a/nx-X11/lib/X11/imExten.c +++ b/nx-X11/lib/X11/imExten.c @@ -55,7 +55,7 @@ typedef struct _XIM_QueryExtRec { int idx; } XIM_QueryExtRec; -Private XIM_QueryExtRec extensions[] = { +static XIM_QueryExtRec extensions[] = { {False, "XIM_EXT_SET_EVENT_MASK", 0, 0, 0, XIM_EXT_SET_EVENT_MASK_IDX}, #ifdef EXT_FORWARD @@ -68,7 +68,7 @@ Private XIM_QueryExtRec extensions[] = { {False, NULL, 0, 0, 0, 0} /* dummy */ }; -Private int +static int _XimIsSupportExt( int idx) { @@ -86,7 +86,7 @@ _XimIsSupportExt( return -1; } -Private Bool +static Bool _XimProcExtSetEventMask( Xim im, Xic ic, @@ -113,7 +113,7 @@ _XimProcExtSetEventMask( return True; } -Private Bool +static Bool _XimExtSetEventMaskCallback( Xim xim, INT16 len, @@ -135,7 +135,7 @@ _XimExtSetEventMaskCallback( } #ifdef EXT_FORWARD -Private Bool +static Bool _XimProcExtForwardKeyEvent( Xim im, Xic ic, @@ -164,7 +164,7 @@ _XimProcExtForwardKeyEvent( return True; } -Private Bool +static Bool _XimExtForwardKeyEventCallback( Xim xim, INT16 len, @@ -185,7 +185,7 @@ _XimExtForwardKeyEventCallback( return False; } -Private Bool +static Bool _XimExtForwardKeyEventCheck( Xim im, INT16 len, @@ -213,7 +213,7 @@ _XimExtForwardKeyEventCheck( return False; } -Public Bool +Bool _XimExtForwardKeyEvent( Xic ic, XKeyEvent *ev, @@ -295,7 +295,7 @@ _XimExtForwardKeyEvent( } #endif /* EXT_FORWARD */ -Private int +static int _XimCheckExtensionListSize(void) { register int i; @@ -312,7 +312,7 @@ _XimCheckExtensionListSize(void) return total; } -Private void +static void _XimSetExtensionList( CARD8 *buf) { @@ -330,7 +330,7 @@ _XimSetExtensionList( return; } -Private unsigned int +static unsigned int _XimCountNumberOfExtension( INT16 total, CARD8 *ext) @@ -352,7 +352,7 @@ _XimCountNumberOfExtension( return n; } -Private Bool +static Bool _XimParseExtensionList( Xim im, CARD16 *data) @@ -388,7 +388,7 @@ _XimParseExtensionList( return True; } -Private Bool +static Bool _XimQueryExtensionCheck( Xim im, INT16 len, @@ -412,7 +412,7 @@ _XimQueryExtensionCheck( return False; } -Public Bool +Bool _XimExtension( Xim im) { @@ -518,7 +518,7 @@ _XimExtension( /* length of XPoint attribute */ #define XIM_Xpoint_length 12 -Private Bool +static Bool _XimExtMove( Xim im, Xic ic, @@ -551,7 +551,7 @@ _XimExtMove( return True; } -Public BITMASK32 +BITMASK32 _XimExtenArgCheck( XIMArg *arg) { @@ -561,7 +561,7 @@ _XimExtenArgCheck( return flag; } -Public Bool +Bool _XimExtenMove( Xim im, Xic ic, diff --git a/nx-X11/lib/X11/imImSw.c b/nx-X11/lib/X11/imImSw.c index acad4b8af..28b1725a6 100644 --- a/nx-X11/lib/X11/imImSw.c +++ b/nx-X11/lib/X11/imImSw.c @@ -40,7 +40,7 @@ THIS SOFTWARE. #include "Ximint.h" #include "XimImSw.h" -Private Bool +static Bool _XimCheckIfDefault( Xim im) { diff --git a/nx-X11/lib/X11/imInsClbk.c b/nx-X11/lib/X11/imInsClbk.c index cb1905c01..47a56c508 100644 --- a/nx-X11/lib/X11/imInsClbk.c +++ b/nx-X11/lib/X11/imInsClbk.c @@ -52,11 +52,11 @@ typedef struct _XimInstCallback { } XimInstCallbackRec, *XimInstCallback; -Private XimInstCallback callback_list = NULL; -Private Bool lock = False; +static XimInstCallback callback_list = NULL; +static Bool lock = False; -Private void +static void MakeLocale( XLCd lcd, char locale[] ) { char *language, *territory, *codeset; @@ -76,7 +76,7 @@ MakeLocale( XLCd lcd, char locale[] ) } -Private Bool +static Bool _XimFilterPropertyNotify( Display *display, Window window, @@ -150,7 +150,7 @@ _XimFilterPropertyNotify( } -Public Bool +Bool _XimRegisterIMInstantiateCallback( XLCd lcd, Display *display, @@ -213,7 +213,7 @@ _XimRegisterIMInstantiateCallback( } -Public Bool +Bool _XimUnRegisterIMInstantiateCallback( XLCd lcd, Display *display, @@ -267,7 +267,7 @@ _XimUnRegisterIMInstantiateCallback( } -Public void +void _XimResetIMInstantiateCallback(Xim xim) { char locale[XIM_MAXLCNAMELEN]; diff --git a/nx-X11/lib/X11/imInt.c b/nx-X11/lib/X11/imInt.c index 0c7cc6f1a..e6929207a 100644 --- a/nx-X11/lib/X11/imInt.c +++ b/nx-X11/lib/X11/imInt.c @@ -37,10 +37,10 @@ PERFORMANCE OF THIS SOFTWARE. #include "Ximint.h" #include "XimImSw.h" -Private Xim *_XimCurrentIMlist = (Xim *)NULL; -Private int _XimCurrentIMcount = 0; +static Xim *_XimCurrentIMlist = (Xim *)NULL; +static int _XimCurrentIMcount = 0; -Private Bool +static Bool _XimSetIMStructureList( Xim im) { @@ -72,7 +72,7 @@ _XimSetIMStructureList( return True; } -Public void +void _XimDestroyIMStructureList(Xim im) { register int i; @@ -86,7 +86,7 @@ _XimDestroyIMStructureList(Xim im) return; } -Public void +void _XimServerDestroy(Xim im_2_destroy) { register int i; @@ -120,7 +120,7 @@ _XimServerDestroy(Xim im_2_destroy) } #ifdef XIM_CONNECTABLE -Public void +void _XimServerReconectableDestroy(void) { register int i; @@ -147,7 +147,7 @@ _XimServerReconectableDestroy(void) } #endif /* XIM_CONNECTABLE */ -Private const char * +static const char * _XimStrstr( register const char *src, register const char *dest) @@ -163,7 +163,7 @@ _XimStrstr( return NULL; } -Private char * +static char * _XimMakeImName( XLCd lcd) { @@ -193,7 +193,7 @@ _XimMakeImName( return ret; } -Public XIM +XIM _XimOpenIM( XLCd lcd, Display *dpy, @@ -251,7 +251,7 @@ Error1: return NULL; } -Public Bool +Bool _XInitIM(XLCd lcd) { if(lcd == (XLCd)NULL) diff --git a/nx-X11/lib/X11/imLcGIc.c b/nx-X11/lib/X11/imLcGIc.c index 26930c426..003b3897a 100644 --- a/nx-X11/lib/X11/imLcGIc.c +++ b/nx-X11/lib/X11/imLcGIc.c @@ -33,7 +33,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Public char * +char * _XimLocalGetICValues(XIC xic, XIMArg *values) { Xic ic = (Xic)xic; diff --git a/nx-X11/lib/X11/imLcIc.c b/nx-X11/lib/X11/imLcIc.c index 60bda4dcb..46323061e 100644 --- a/nx-X11/lib/X11/imLcIc.c +++ b/nx-X11/lib/X11/imLcIc.c @@ -36,7 +36,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Private void +static void _XimLocalUnSetFocus( XIC xic) { @@ -49,7 +49,7 @@ _XimLocalUnSetFocus( return; } -Private void +static void _XimLocalDestroyIC( XIC xic) { @@ -68,7 +68,7 @@ _XimLocalDestroyIC( return; } -Private void +static void _XimLocalSetFocus( XIC xic) { @@ -90,7 +90,7 @@ _XimLocalSetFocus( return; } -Private void +static void _XimLocalReset( XIC xic) { @@ -102,7 +102,7 @@ _XimLocalReset( ic->private.local.brl_committed = 0; } -Private char * +static char * _XimLocalMbReset( XIC xic) { @@ -110,7 +110,7 @@ _XimLocalMbReset( return (char *)NULL; } -Private wchar_t * +static wchar_t * _XimLocalWcReset( XIC xic) { @@ -118,7 +118,7 @@ _XimLocalWcReset( return (wchar_t *)NULL; } -Private XICMethodsRec Local_ic_methods = { +static XICMethodsRec Local_ic_methods = { _XimLocalDestroyIC, /* destroy */ _XimLocalSetFocus, /* set_focus */ _XimLocalUnSetFocus, /* unset_focus */ @@ -132,7 +132,7 @@ Private XICMethodsRec Local_ic_methods = { _XimLocalUtf8LookupString /* utf8_lookup_string */ }; -Public XIC +XIC _XimLocalCreateIC( XIM im, XIMArg *values) diff --git a/nx-X11/lib/X11/imLcIm.c b/nx-X11/lib/X11/imLcIm.c index d0ce12d4d..70a71591c 100644 --- a/nx-X11/lib/X11/imLcIm.c +++ b/nx-X11/lib/X11/imLcIm.c @@ -88,14 +88,14 @@ struct _XimCacheStruct { /* char encoding[1] */ }; -Private struct _XimCacheStruct* _XimCache_mmap = NULL; -Private DefTreeBase _XimCachedDefaultTreeBase; -Private int _XimCachedDefaultTreeRefcount = 0; +static struct _XimCacheStruct* _XimCache_mmap = NULL; +static DefTreeBase _XimCachedDefaultTreeBase; +static int _XimCachedDefaultTreeRefcount = 0; #endif -Public Bool +Bool _XimCheckIfLocalProcessing(Xim im) { FILE *fp; @@ -119,7 +119,7 @@ _XimCheckIfLocalProcessing(Xim im) return(False); } -Private void +static void XimFreeDefaultTree( DefTreeBase *b) { @@ -146,7 +146,7 @@ XimFreeDefaultTree( b->utf8used = b->utf8size = 0; } -Public void +void _XimLocalIMFree( Xim im) { @@ -220,7 +220,7 @@ _XimLocalIMFree( return; } -Private Status +static Status _XimLocalCloseIM( XIM xim) { @@ -241,7 +241,7 @@ _XimLocalCloseIM( return(True); } -Public char * +char * _XimLocalGetIMValues( XIM xim, XIMArg *values) @@ -254,7 +254,7 @@ _XimLocalGetIMValues( im->core.im_resources, im->core.im_num_resources)); } -Public char * +char * _XimLocalSetIMValues( XIM xim, XIMArg *values) @@ -273,7 +273,7 @@ _XimLocalSetIMValues( #ifdef COMPOSECACHE -Private Bool +static Bool _XimReadCachedDefaultTree( int fd_cache, const char *name, @@ -324,7 +324,7 @@ _XimReadCachedDefaultTree( return True; } -Private unsigned int strToHash ( +static unsigned int strToHash ( const char *name) { unsigned int hash = 0; @@ -336,7 +336,7 @@ Private unsigned int strToHash ( /* Returns read-only fd of cache file, -1 if none. * Sets *res to cache filename if safe. Sets *size to file size of cache. */ -Private int _XimCachedFileName ( +static int _XimCachedFileName ( const char *dir, const char *name, const char *intname, const char *encoding, uid_t uid, int isglobal, char **res, off_t *size) @@ -421,7 +421,7 @@ Private int _XimCachedFileName ( } -Private Bool _XimLoadCache ( +static Bool _XimLoadCache ( int fd, const char *name, const char *encoding, @@ -441,7 +441,7 @@ Private Bool _XimLoadCache ( } -Private void +static void _XimWriteCachedDefaultTree( const char *name, const char *encoding, @@ -516,7 +516,7 @@ _XimWriteCachedDefaultTree( #endif -Private void +static void _XimCreateDefaultTree( Xim im) { @@ -646,7 +646,7 @@ _XimCreateDefaultTree( Xfree (cachename); } -Private XIMMethodsRec Xim_im_local_methods = { +static XIMMethodsRec Xim_im_local_methods = { _XimLocalCloseIM, /* close */ _XimLocalSetIMValues, /* set_values */ _XimLocalGetIMValues, /* get_values */ @@ -656,7 +656,7 @@ Private XIMMethodsRec Xim_im_local_methods = { _XimLcctstoutf8 /* ctstoutf8 */ }; -Public Bool +Bool _XimLocalOpenIM( Xim im) { diff --git a/nx-X11/lib/X11/imLcLkup.c b/nx-X11/lib/X11/imLcLkup.c index f2f96e280..51c1f2ed8 100644 --- a/nx-X11/lib/X11/imLcLkup.c +++ b/nx-X11/lib/X11/imLcLkup.c @@ -43,7 +43,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "XlcPubI.h" #include "Ximint.h" -Public int +int _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, KeySym *keysym, Status *status) { @@ -130,7 +130,7 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, return (ret); } -Public int +int _XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen, KeySym *keysym, Status *status) { @@ -202,7 +202,7 @@ _XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen, return (ret); } -Public int +int _XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, KeySym *keysym, Status *status) { @@ -275,7 +275,7 @@ _XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, return (ret); } -Private int +static int _XimLcctsconvert( XlcConv conv, char *from, @@ -341,7 +341,7 @@ _XimLcctsconvert( return to_cnvlen; } -Public int +int _XimLcctstombs(XIM xim, char *from, int from_len, char *to, int to_len, Status *state) { @@ -349,7 +349,7 @@ _XimLcctstombs(XIM xim, char *from, int from_len, from, from_len, to, to_len, state); } -Public int +int _XimLcctstowcs(XIM xim, char *from, int from_len, wchar_t *to, int to_len, Status *state) { @@ -412,7 +412,7 @@ _XimLcctstowcs(XIM xim, char *from, int from_len, return to_cnvlen; } -Public int +int _XimLcctstoutf8(XIM xim, char *from, int from_len, char *to, int to_len, Status *state) { diff --git a/nx-X11/lib/X11/imLcSIc.c b/nx-X11/lib/X11/imLcSIc.c index 8f656f670..944bd8abd 100644 --- a/nx-X11/lib/X11/imLcSIc.c +++ b/nx-X11/lib/X11/imLcSIc.c @@ -37,7 +37,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Public char * +char * _XimLocalSetICValues(XIC xic, XIMArg *values) { XimDefICValues ic_values; diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index c0c6d8eb8..34c9bfa35 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -58,7 +58,7 @@ typedef struct _XimValueOffsetInfo { } XimValueOffsetInfoRec, *XimValueOffsetInfo; #ifdef XIM_CONNECTABLE -Private Bool +static Bool _XimCheckBool(str) char *str; { @@ -69,7 +69,7 @@ _XimCheckBool(str) return False; } -Public void +void _XimSetProtoResource(im) Xim im; { @@ -344,7 +344,7 @@ static XIMStyle const supported_local_styles[] = { 0 /* dummy */ }; -Private Bool +static Bool _XimDefaultStyles( XimValueOffsetInfo info, XPointer top, @@ -379,7 +379,7 @@ _XimDefaultStyles( return True; } -Private Bool +static Bool _XimDefaultIMValues( XimValueOffsetInfo info, XPointer top, @@ -415,7 +415,7 @@ _XimDefaultIMValues( return True; } -Private Bool +static Bool _XimDefaultICValues( XimValueOffsetInfo info, XPointer top, @@ -451,7 +451,7 @@ _XimDefaultICValues( return True; } -Private Bool +static Bool _XimDefaultVisiblePos( XimValueOffsetInfo info, XPointer top, @@ -465,7 +465,7 @@ _XimDefaultVisiblePos( return True; } -Private Bool +static Bool _XimDefaultFocusWindow( XimValueOffsetInfo info, XPointer top, @@ -484,7 +484,7 @@ _XimDefaultFocusWindow( return True; } -Private Bool +static Bool _XimDefaultResName( XimValueOffsetInfo info, XPointer top, @@ -504,7 +504,7 @@ _XimDefaultResName( return True; } -Private Bool +static Bool _XimDefaultResClass( XimValueOffsetInfo info, XPointer top, @@ -524,7 +524,7 @@ _XimDefaultResClass( return True; } -Private Bool +static Bool _XimDefaultDestroyCB( XimValueOffsetInfo info, XPointer top, @@ -540,7 +540,7 @@ _XimDefaultDestroyCB( return True; } -Private Bool +static Bool _XimDefaultResetState( XimValueOffsetInfo info, XPointer top, @@ -554,7 +554,7 @@ _XimDefaultResetState( return True; } -Private Bool +static Bool _XimDefaultHotKeyState( XimValueOffsetInfo info, XPointer top, @@ -568,7 +568,7 @@ _XimDefaultHotKeyState( return True; } -Private Bool +static Bool _XimDefaultArea( XimValueOffsetInfo info, XPointer top, @@ -604,7 +604,7 @@ _XimDefaultArea( return True; } -Private Bool +static Bool _XimDefaultColormap( XimValueOffsetInfo info, XPointer top, @@ -629,7 +629,7 @@ _XimDefaultColormap( return True; } -Private Bool +static Bool _XimDefaultStdColormap( XimValueOffsetInfo info, XPointer top, @@ -643,7 +643,7 @@ _XimDefaultStdColormap( return True; } -Private Bool +static Bool _XimDefaultFg( XimValueOffsetInfo info, XPointer top, @@ -661,7 +661,7 @@ _XimDefaultFg( return True; } -Private Bool +static Bool _XimDefaultBg( XimValueOffsetInfo info, XPointer top, @@ -679,7 +679,7 @@ _XimDefaultBg( return True; } -Private Bool +static Bool _XimDefaultBgPixmap( XimValueOffsetInfo info, XPointer top, @@ -693,7 +693,7 @@ _XimDefaultBgPixmap( return True; } -Private Bool +static Bool _XimDefaultFontSet( XimValueOffsetInfo info, XPointer top, @@ -707,7 +707,7 @@ _XimDefaultFontSet( return True; } -Private Bool +static Bool _XimDefaultLineSpace( XimValueOffsetInfo info, XPointer top, @@ -736,7 +736,7 @@ _XimDefaultLineSpace( return True; } -Private Bool +static Bool _XimDefaultCursor( XimValueOffsetInfo info, XPointer top, @@ -750,7 +750,7 @@ _XimDefaultCursor( return True; } -Private Bool +static Bool _XimDefaultPreeditState( XimValueOffsetInfo info, XPointer top, @@ -764,7 +764,7 @@ _XimDefaultPreeditState( return True; } -Private Bool +static Bool _XimDefaultNest( XimValueOffsetInfo info, XPointer top, @@ -774,7 +774,7 @@ _XimDefaultNest( return True; } -Private Bool +static Bool _XimEncodeCallback( XimValueOffsetInfo info, XPointer top, @@ -787,7 +787,7 @@ _XimEncodeCallback( return True; } -Private Bool +static Bool _XimEncodeString( XimValueOffsetInfo info, XPointer top, @@ -811,7 +811,7 @@ _XimEncodeString( return True; } -Private Bool +static Bool _XimEncodeStyle( XimValueOffsetInfo info, XPointer top, @@ -824,7 +824,7 @@ _XimEncodeStyle( return True; } -Private Bool +static Bool _XimEncodeWindow( XimValueOffsetInfo info, XPointer top, @@ -837,7 +837,7 @@ _XimEncodeWindow( return True; } -Private Bool +static Bool _XimEncodeStringConv( XimValueOffsetInfo info, XPointer top, @@ -849,7 +849,7 @@ _XimEncodeStringConv( return True; } -Private Bool +static Bool _XimEncodeResetState( XimValueOffsetInfo info, XPointer top, @@ -862,7 +862,7 @@ _XimEncodeResetState( return True; } -Private Bool +static Bool _XimEncodeHotKey( XimValueOffsetInfo info, XPointer top, @@ -905,7 +905,7 @@ _XimEncodeHotKey( return True; } -Private Bool +static Bool _XimEncodeHotKetState( XimValueOffsetInfo info, XPointer top, @@ -918,7 +918,7 @@ _XimEncodeHotKetState( return True; } -Private Bool +static Bool _XimEncodeRectangle( XimValueOffsetInfo info, XPointer top, @@ -931,7 +931,7 @@ _XimEncodeRectangle( return True; } -Private Bool +static Bool _XimEncodeSpot( XimValueOffsetInfo info, XPointer top, @@ -944,7 +944,7 @@ _XimEncodeSpot( return True; } -Private Bool +static Bool _XimEncodeColormap( XimValueOffsetInfo info, XPointer top, @@ -957,7 +957,7 @@ _XimEncodeColormap( return True; } -Private Bool +static Bool _XimEncodeStdColormap( XimValueOffsetInfo info, XPointer top, @@ -970,7 +970,7 @@ _XimEncodeStdColormap( return True; } -Private Bool +static Bool _XimEncodeLong( XimValueOffsetInfo info, XPointer top, @@ -983,7 +983,7 @@ _XimEncodeLong( return True; } -Private Bool +static Bool _XimEncodeBgPixmap( XimValueOffsetInfo info, XPointer top, @@ -996,7 +996,7 @@ _XimEncodeBgPixmap( return True; } -Private Bool +static Bool _XimEncodeFontSet( XimValueOffsetInfo info, XPointer top, @@ -1009,7 +1009,7 @@ _XimEncodeFontSet( return True; } -Private Bool +static Bool _XimEncodeLineSpace( XimValueOffsetInfo info, XPointer top, @@ -1022,7 +1022,7 @@ _XimEncodeLineSpace( return True; } -Private Bool +static Bool _XimEncodeCursor( XimValueOffsetInfo info, XPointer top, @@ -1035,7 +1035,7 @@ _XimEncodeCursor( return True; } -Private Bool +static Bool _XimEncodePreeditState( XimValueOffsetInfo info, XPointer top, @@ -1048,7 +1048,7 @@ _XimEncodePreeditState( return True; } -Private Bool +static Bool _XimEncodeNest( XimValueOffsetInfo info, XPointer top, @@ -1057,7 +1057,7 @@ _XimEncodeNest( return True; } -Private Bool +static Bool _XimDecodeStyles( XimValueOffsetInfo info, XPointer top, @@ -1095,7 +1095,7 @@ _XimDecodeStyles( return True; } -Private Bool +static Bool _XimDecodeValues( XimValueOffsetInfo info, XPointer top, @@ -1133,7 +1133,7 @@ _XimDecodeValues( return True; } -Private Bool +static Bool _XimDecodeCallback( XimValueOffsetInfo info, XPointer top, @@ -1153,7 +1153,7 @@ _XimDecodeCallback( return True; } -Private Bool +static Bool _XimDecodeString( XimValueOffsetInfo info, XPointer top, @@ -1175,7 +1175,7 @@ _XimDecodeString( return True; } -Private Bool +static Bool _XimDecodeBool( XimValueOffsetInfo info, XPointer top, @@ -1188,7 +1188,7 @@ _XimDecodeBool( return True; } -Private Bool +static Bool _XimDecodeStyle( XimValueOffsetInfo info, XPointer top, @@ -1201,7 +1201,7 @@ _XimDecodeStyle( return True; } -Private Bool +static Bool _XimDecodeWindow( XimValueOffsetInfo info, XPointer top, @@ -1214,7 +1214,7 @@ _XimDecodeWindow( return True; } -Private Bool +static Bool _XimDecodeStringConv( XimValueOffsetInfo info, XPointer top, @@ -1226,7 +1226,7 @@ _XimDecodeStringConv( return True; } -Private Bool +static Bool _XimDecodeResetState( XimValueOffsetInfo info, XPointer top, @@ -1239,7 +1239,7 @@ _XimDecodeResetState( return True; } -Private Bool +static Bool _XimDecodeHotKey( XimValueOffsetInfo info, XPointer top, @@ -1273,7 +1273,7 @@ _XimDecodeHotKey( return True; } -Private Bool +static Bool _XimDecodeHotKetState( XimValueOffsetInfo info, XPointer top, @@ -1286,7 +1286,7 @@ _XimDecodeHotKetState( return True; } -Private Bool +static Bool _XimDecodeRectangle( XimValueOffsetInfo info, XPointer top, @@ -1304,7 +1304,7 @@ _XimDecodeRectangle( return True; } -Private Bool +static Bool _XimDecodeSpot( XimValueOffsetInfo info, XPointer top, @@ -1322,7 +1322,7 @@ _XimDecodeSpot( return True; } -Private Bool +static Bool _XimDecodeColormap( XimValueOffsetInfo info, XPointer top, @@ -1335,7 +1335,7 @@ _XimDecodeColormap( return True; } -Private Bool +static Bool _XimDecodeStdColormap( XimValueOffsetInfo info, XPointer top, @@ -1348,7 +1348,7 @@ _XimDecodeStdColormap( return True; } -Private Bool +static Bool _XimDecodeLong( XimValueOffsetInfo info, XPointer top, @@ -1361,7 +1361,7 @@ _XimDecodeLong( return True; } -Private Bool +static Bool _XimDecodeBgPixmap( XimValueOffsetInfo info, XPointer top, @@ -1374,7 +1374,7 @@ _XimDecodeBgPixmap( return True; } -Private Bool +static Bool _XimDecodeFontSet( XimValueOffsetInfo info, XPointer top, @@ -1387,7 +1387,7 @@ _XimDecodeFontSet( return True; } -Private Bool +static Bool _XimDecodeLineSpace( XimValueOffsetInfo info, XPointer top, @@ -1400,7 +1400,7 @@ _XimDecodeLineSpace( return True; } -Private Bool +static Bool _XimDecodeCursor( XimValueOffsetInfo info, XPointer top, @@ -1413,7 +1413,7 @@ _XimDecodeCursor( return True; } -Private Bool +static Bool _XimDecodePreeditState( XimValueOffsetInfo info, XPointer top, @@ -1426,7 +1426,7 @@ _XimDecodePreeditState( return True; } -Private Bool +static Bool _XimDecodeNest( XimValueOffsetInfo info, XPointer top, @@ -2118,7 +2118,7 @@ static const XimICMode ic_mode[] = { static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])]; static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])]; -Private Bool +static Bool _XimSetResourceList( XIMResourceList *res_list, unsigned int *list_num, @@ -2146,7 +2146,7 @@ _XimSetResourceList( return True; } -Public Bool +Bool _XimSetIMResourceList( XIMResourceList *res_list, unsigned int *list_num) @@ -2155,7 +2155,7 @@ _XimSetIMResourceList( im_resources, XIMNumber(im_resources), 100); } -Public Bool +Bool _XimSetICResourceList( XIMResourceList *res_list, unsigned int *list_num) @@ -2164,7 +2164,7 @@ _XimSetICResourceList( ic_resources, XIMNumber(ic_resources), 200); } -Public Bool +Bool _XimSetInnerIMResourceList( XIMResourceList *res_list, unsigned int *list_num) @@ -2173,7 +2173,7 @@ _XimSetInnerIMResourceList( im_inner_resources, XIMNumber(im_inner_resources), 100); } -Public Bool +Bool _XimSetInnerICResourceList( XIMResourceList *res_list, unsigned int *list_num) @@ -2182,7 +2182,7 @@ _XimSetInnerICResourceList( ic_inner_resources, XIMNumber(ic_inner_resources), 200); } -Private XIMResourceList +static XIMResourceList _XimGetResourceListRecByMode( XIMResourceList res_list, unsigned int list_num, @@ -2198,7 +2198,7 @@ _XimGetResourceListRecByMode( return (XIMResourceList)NULL; } -Public Bool +Bool _XimCheckCreateICValues( XIMResourceList res_list, unsigned int list_num) @@ -2209,7 +2209,7 @@ _XimCheckCreateICValues( return False; } -Public XIMResourceList +XIMResourceList _XimGetResourceListRecByQuark( XIMResourceList res_list, unsigned int list_num, @@ -2225,7 +2225,7 @@ _XimGetResourceListRecByQuark( return (XIMResourceList)NULL; } -Public XIMResourceList +XIMResourceList _XimGetResourceListRec( XIMResourceList res_list, unsigned int list_num, @@ -2236,7 +2236,7 @@ _XimGetResourceListRec( return _XimGetResourceListRecByQuark(res_list, list_num, quark); } -Public char * +char * _XimSetIMValueData( Xim im, XPointer top, @@ -2266,7 +2266,7 @@ _XimSetIMValueData( return NULL; } -Public char * +char * _XimGetIMValueData( Xim im, XPointer top, @@ -2296,7 +2296,7 @@ _XimGetIMValueData( return NULL; } -Public void +void _XimSetIMMode( XIMResourceList res_list, unsigned int list_num) @@ -2315,7 +2315,7 @@ _XimSetIMMode( return; } -Private int +static int _XimCheckSetIMDefaultsMode( XIMResourceList res) { @@ -2325,7 +2325,7 @@ _XimCheckSetIMDefaultsMode( return XIM_CHECK_INVALID; } -Private int +static int _XimCheckSetIMValuesMode( XIMResourceList res) { @@ -2335,7 +2335,7 @@ _XimCheckSetIMValuesMode( return XIM_CHECK_INVALID; } -Private int +static int _XimCheckGetIMValuesMode( XIMResourceList res) { @@ -2345,7 +2345,7 @@ Private int return XIM_CHECK_INVALID; } -Public int +int _XimCheckIMMode( XIMResourceList res, unsigned long mode) @@ -2364,7 +2364,7 @@ Public int } } -Public void +void _XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style) { XIMResourceList res; @@ -2406,7 +2406,7 @@ _XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style) return; } -Private int +static int _XimCheckSetICDefaultsMode( XIMResourceList res, unsigned long mode) @@ -2449,7 +2449,7 @@ _XimCheckSetICDefaultsMode( return XIM_CHECK_VALID; } -Private int +static int _XimCheckCreateICMode( XIMResourceList res, unsigned long mode) @@ -2502,7 +2502,7 @@ _XimCheckCreateICMode( return XIM_CHECK_VALID; } -Private int +static int _XimCheckSetICValuesMode( XIMResourceList res, unsigned long mode) @@ -2543,7 +2543,7 @@ _XimCheckSetICValuesMode( return XIM_CHECK_VALID; } -Private int +static int _XimCheckGetICValuesMode( XIMResourceList res, unsigned long mode) @@ -2578,7 +2578,7 @@ _XimCheckGetICValuesMode( return XIM_CHECK_VALID; } -Public int +int _XimCheckICMode( XIMResourceList res, unsigned long mode) @@ -2596,7 +2596,7 @@ Public int } } -Public Bool +Bool _XimSetLocalIMDefaults( Xim im, XPointer top, @@ -2635,7 +2635,7 @@ _XimSetLocalIMDefaults( return True; } -Public Bool +Bool _XimSetICDefaults( Xic ic, XPointer top, @@ -2700,7 +2700,7 @@ _XimSetICDefaults( return True; } -Private Bool +static Bool _XimEncodeAttr( XimValueOffsetInfo info, unsigned int num, @@ -2721,7 +2721,7 @@ _XimEncodeAttr( return False; } -Public Bool +Bool _XimEncodeLocalIMAttr( XIMResourceList res, XPointer top, @@ -2731,7 +2731,7 @@ _XimEncodeLocalIMAttr( res, top, val); } -Public Bool +Bool _XimEncodeLocalICAttr( Xic ic, XIMResourceList res, @@ -2756,7 +2756,7 @@ _XimEncodeLocalICAttr( return _XimEncodeAttr(info, num, res, top, arg->value); } -Private Bool +static Bool _XimEncodeLocalTopValue( Xic ic, XIMResourceList res, @@ -2792,7 +2792,7 @@ _XimEncodeLocalTopValue( return True; } -Private Bool +static Bool _XimEncodeLocalPreeditValue( Xic ic, XIMResourceList res, @@ -2814,7 +2814,7 @@ _XimEncodeLocalPreeditValue( return True; } -Private Bool +static Bool _XimEncodeLocalStatusValue( Xic ic, XIMResourceList res, @@ -2836,7 +2836,7 @@ _XimEncodeLocalStatusValue( return True; } -Public char * +char * _XimSetICValueData( Xic ic, XPointer top, @@ -2901,7 +2901,7 @@ _XimSetICValueData( return NULL; } -Private Bool +static Bool _XimCheckInputStyle( XIMStyles *styles, XIMStyle style) @@ -2917,7 +2917,7 @@ _XimCheckInputStyle( return False; } -Public Bool +Bool _XimCheckLocalInputStyle( Xic ic, XPointer top, @@ -2948,7 +2948,7 @@ _XimCheckLocalInputStyle( return False; } -Private Bool +static Bool _XimDecodeAttr( XimValueOffsetInfo info, unsigned int num, @@ -2969,7 +2969,7 @@ _XimDecodeAttr( return False; } -Public Bool +Bool _XimDecodeLocalIMAttr( XIMResourceList res, XPointer top, @@ -2979,7 +2979,7 @@ _XimDecodeLocalIMAttr( res, top, val); } -Public Bool +Bool _XimDecodeLocalICAttr( XIMResourceList res, XPointer top, @@ -3003,7 +3003,7 @@ _XimDecodeLocalICAttr( return _XimDecodeAttr(info, num, res, top, val); } -Public char * +char * _XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list, unsigned int list_num, XIMArg *values, unsigned long mode) { @@ -3052,7 +3052,7 @@ _XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list, return NULL; } -Public void +void _XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values) { bzero((char *)im_values, sizeof(XimDefIMValues)); @@ -3066,7 +3066,7 @@ _XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values) im_values->visible_position = im->core.visible_position; } -Public void +void _XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values) { im->core.styles = im_values->styles; @@ -3078,7 +3078,7 @@ _XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values) im->core.visible_position = im_values->visible_position; } -Public void +void _XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values) { bzero((char *)ic_values, sizeof(XimDefICValues)); @@ -3101,7 +3101,7 @@ _XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values) ic_values->status_attr = ic->core.status_attr; } -Public void +void _XimSetCurrentICValues( Xic ic, XimDefICValues *ic_values) @@ -3125,7 +3125,7 @@ _XimSetCurrentICValues( ic->core.status_attr = ic_values->status_attr; } -Private void +static void _XimInitialIMOffsetInfo(void) { unsigned int n = XIMNumber(im_attr_info); @@ -3136,7 +3136,7 @@ _XimInitialIMOffsetInfo(void) } } -Private void +static void _XimInitialICOffsetInfo(void) { unsigned int n; @@ -3158,7 +3158,7 @@ _XimInitialICOffsetInfo(void) } } -Private void +static void _XimInitialIMMode(void) { unsigned int n = XIMNumber(im_mode); @@ -3169,7 +3169,7 @@ _XimInitialIMMode(void) } } -Private void +static void _XimInitialICMode(void) { unsigned int n = XIMNumber(ic_mode); @@ -3180,7 +3180,7 @@ _XimInitialICMode(void) } } -Public void +void _XimInitialResourceInfo(void) { static Bool init_flag = False; diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index fcb347caa..b5abcdd75 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -34,7 +34,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "Ximint.h" -Private XIMResourceList +static XIMResourceList _XimGetNestedListSeparator( XIMResourceList res_list, /* LISTofIMATTR or IMATTR */ unsigned int res_num) @@ -42,7 +42,7 @@ _XimGetNestedListSeparator( return _XimGetResourceListRec(res_list, res_num, XNSeparatorofNestedList); } -Private Bool +static Bool _XimCheckInnerIMAttributes( Xim im, XIMArg *arg, @@ -64,7 +64,7 @@ _XimCheckInnerIMAttributes( return True; } -Public char * +char * _XimMakeIMAttrIDList( Xim im, XIMResourceList res_list, @@ -102,7 +102,7 @@ _XimMakeIMAttrIDList( return (char *)NULL; } -Private Bool +static Bool _XimCheckInnerICAttributes( Xic ic, XIMArg *arg, @@ -124,7 +124,7 @@ _XimCheckInnerICAttributes( return True; } -Public char * +char * _XimMakeICAttrIDList( Xic ic, XIMResourceList res_list, @@ -209,7 +209,7 @@ _XimMakeICAttrIDList( return (char *)NULL; } -Private Bool +static Bool _XimAttributeToValue( Xic ic, XIMResourceList res, @@ -399,7 +399,7 @@ _XimAttributeToValue( return True; } -Private Bool +static Bool _XimDecodeInnerIMATTRIBUTE( Xim im, XIMArg *arg) @@ -415,7 +415,7 @@ _XimDecodeInnerIMATTRIBUTE( return _XimDecodeLocalIMAttr(res, (XPointer)&im_values, arg->value); } -Public char * +char * _XimDecodeIMATTRIBUTE( Xim im, XIMResourceList res_list, @@ -468,7 +468,7 @@ _XimDecodeIMATTRIBUTE( return (char *)NULL; } -Private Bool +static Bool _XimDecodeInnerICATTRIBUTE( Xic ic, XIMArg *arg, @@ -488,7 +488,7 @@ _XimDecodeInnerICATTRIBUTE( return True; } -Public char * +char * _XimDecodeICATTRIBUTE( Xic ic, XIMResourceList res_list, @@ -564,7 +564,7 @@ _XimDecodeICATTRIBUTE( return (char *)NULL; } -Private Bool +static Bool _XimValueToAttribute( XIMResourceList res, XPointer buf, @@ -772,7 +772,7 @@ _XimValueToAttribute( return True; } -Private Bool +static Bool _XimSetInnerIMAttributes( Xim im, XPointer top, @@ -795,7 +795,7 @@ _XimSetInnerIMAttributes( return _XimEncodeLocalIMAttr(res, top, arg->value); } -Public char * +char * _XimEncodeIMATTRIBUTE( Xim im, XIMResourceList res_list, @@ -859,7 +859,7 @@ _XimEncodeIMATTRIBUTE( } #ifdef XIM_CONNECTABLE -Public Bool +Bool _XimEncodeSavedIMATTRIBUTE( Xim im, XIMResourceList res_list, @@ -922,7 +922,7 @@ _XimEncodeSavedIMATTRIBUTE( } #endif /* XIM_CONNECTABLE */ -Private Bool +static Bool _XimEncodeTopValue( Xic ic, XIMResourceList res, @@ -945,7 +945,7 @@ _XimEncodeTopValue( return True; } -Private Bool +static Bool _XimEncodePreeditValue( Xic ic, XIMResourceList res, @@ -996,7 +996,7 @@ _XimEncodePreeditValue( return True; } -Private Bool +static Bool _XimEncodeStatusValue( Xic ic, XIMResourceList res, @@ -1047,7 +1047,7 @@ _XimEncodeStatusValue( return True; } -Private Bool +static Bool _XimSetInnerICAttributes( Xic ic, XPointer top, @@ -1070,7 +1070,7 @@ _XimSetInnerICAttributes( return _XimEncodeLocalICAttr(ic, res, top, arg, mode); } -Public char * +char * _XimEncodeICATTRIBUTE( Xic ic, XIMResourceList res_list, @@ -1182,7 +1182,7 @@ _XimEncodeICATTRIBUTE( } #ifdef XIM_CONNECTABLE -Private Bool +static Bool _XimEncodeSavedPreeditValue( Xic ic, XIMResourceList res, @@ -1224,7 +1224,7 @@ _XimEncodeSavedPreeditValue( return True; } -Private Bool +static Bool _XimEncodeSavedStatusValue( Xic ic, XIMResourceList res, @@ -1266,7 +1266,7 @@ _XimEncodeSavedStatusValue( return True; } -Public Bool +Bool _XimEncodeSavedICATTRIBUTE( Xic ic, XIMResourceList res_list, @@ -1377,7 +1377,7 @@ _XimEncodeSavedICATTRIBUTE( } #endif /* XIM_CONNECTABLE */ -Private unsigned int +static unsigned int _XimCountNumberOfAttr( INT16 total, CARD16 *attr, @@ -1402,7 +1402,7 @@ _XimCountNumberOfAttr( return n; } -Public Bool +Bool _XimGetAttributeID( Xim im, CARD16 *buf) diff --git a/nx-X11/lib/X11/imThaiFlt.c b/nx-X11/lib/X11/imThaiFlt.c index 72f6f2e7a..401bd9a08 100644 --- a/nx-X11/lib/X11/imThaiFlt.c +++ b/nx-X11/lib/X11/imThaiFlt.c @@ -81,7 +81,7 @@ SOFTWARE. /* character classification table */ #define TACTIS_CHARS 256 -Private +static char const tactis_chtype[TACTIS_CHARS] = { CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, /* 0 - 7 */ CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, CTRL, /* 8 - 15 */ @@ -127,7 +127,7 @@ char const tactis_chtype[TACTIS_CHARS] = { #define CH_CLASSES 17 /* 17 classes of chars */ -Private +static char const write_rules_lookup[CH_CLASSES][CH_CLASSES] = { /* Table 0: writing/outputing rules */ /* row: leading char, column: following char */ @@ -151,7 +151,7 @@ char const write_rules_lookup[CH_CLASSES][CH_CLASSES] = { ,{XC, NC, NC, NC, NC, NC, NC, NC, NC, NC, CP, NC, CP, NC, NC, NC, NC}/*AV3*/ }; -Private +static char const wtt_isc1_lookup[CH_CLASSES][CH_CLASSES] = { /* Table 1: WTT default input sequence check rules */ /* row: leading char, column: following char */ @@ -175,7 +175,7 @@ char const wtt_isc1_lookup[CH_CLASSES][CH_CLASSES] = { ,{XC, AC, AC, AC, AC, AC, AC, RJ, RJ, RJ, CP, RJ, CP, RJ, RJ, RJ, RJ}/*AV3*/ }; -Private +static char const wtt_isc2_lookup[CH_CLASSES][CH_CLASSES] = { /* Table 2: WTT strict input sequence check rules */ /* row: leading char, column: following char */ @@ -199,7 +199,7 @@ char const wtt_isc2_lookup[CH_CLASSES][CH_CLASSES] = { ,{XC, AC, AC, AC, RJ, RJ, AC, RJ, RJ, RJ, CP, RJ, CP, RJ, RJ, RJ, RJ}/*AV3*/ }; -Private +static char const thaicat_isc_lookup[CH_CLASSES][CH_CLASSES] = { /* Table 3: Thaicat input sequence check rules */ /* row: leading char, column: following char */ @@ -225,7 +225,7 @@ char const thaicat_isc_lookup[CH_CLASSES][CH_CLASSES] = { /* returns classification of a char */ -Private int +static int THAI_chtype (unsigned char ch) { return tactis_chtype[ch]; @@ -233,7 +233,7 @@ THAI_chtype (unsigned char ch) #ifdef UNUSED /* returns the display level */ -Private int +static int THAI_chlevel (unsigned char ch) { int chlevel; @@ -274,7 +274,7 @@ THAI_chlevel (unsigned char ch) /* return True if char is non-spacing */ -Private Bool +static Bool THAI_isdead (unsigned char ch) { return ((tactis_chtype[ch] == CTRL) || (tactis_chtype[ch] == BV1) || @@ -287,7 +287,7 @@ THAI_isdead (unsigned char ch) /* return True if char is consonant */ -Private Bool +static Bool THAI_iscons (unsigned char ch) { return (tactis_chtype[ch] == CONS); @@ -295,7 +295,7 @@ THAI_iscons (unsigned char ch) /* return True if char is vowel */ -Private Bool +static Bool THAI_isvowel (unsigned char ch) { return ((tactis_chtype[ch] == LV) || (tactis_chtype[ch] == FV1) || @@ -307,14 +307,14 @@ THAI_isvowel (unsigned char ch) /* return True if char is tonemark */ -Private Bool +static Bool THAI_istone (unsigned char ch) { return (tactis_chtype[ch] == TONE); } #endif -Private Bool +static Bool THAI_iscomposible ( unsigned char follow_ch, unsigned char lead_ch) @@ -324,7 +324,7 @@ THAI_iscomposible ( == CP); } -Private Bool +static Bool THAI_isaccepted ( unsigned char follow_ch, unsigned char lead_ch, @@ -355,7 +355,7 @@ THAI_isaccepted ( } #ifdef UNUSED -Private void +static void THAI_apply_write_rules( unsigned char *instr, unsigned char *outstr, @@ -401,7 +401,7 @@ Output parameters: } } -Private int +static int THAI_find_chtype ( unsigned char *instr, int chtype) @@ -430,7 +430,7 @@ Output parameters: } -Private int +static int THAI_apply_scm( unsigned char *instr, unsigned char *outstr, @@ -466,33 +466,33 @@ THAI_apply_scm( /* The following functions are copied from XKeyBind.c */ -Private void ComputeMaskFromKeytrans(); -Private int IsCancelComposeKey(KeySym *symbol, XKeyEvent *event); -Private void SetLed(Display *dpy, int num, int state); -Private CARD8 FindKeyCode(); +static void ComputeMaskFromKeytrans(); +static int IsCancelComposeKey(KeySym *symbol, XKeyEvent *event); +static void SetLed(Display *dpy, int num, int state); +static CARD8 FindKeyCode(); /* The following functions are specific to this module */ -Private int XThaiTranslateKey(); -Private int XThaiTranslateKeySym(); +static int XThaiTranslateKey(); +static int XThaiTranslateKeySym(); -Private KeySym HexIMNormalKey( +static KeySym HexIMNormalKey( XicThaiPart *thai_part, KeySym symbol, XKeyEvent *event); -Private KeySym HexIMFirstComposeKey( +static KeySym HexIMFirstComposeKey( XicThaiPart *thai_part, KeySym symbol, XKeyEvent *event); -Private KeySym HexIMSecondComposeKey( +static KeySym HexIMSecondComposeKey( XicThaiPart *thai_part, KeySym symbol XKeyEvent *event); -Private KeySym HexIMComposeSequence(KeySym ks1, KeySym ks2); -Private void InitIscMode(Xic ic); -Private Bool ThaiComposeConvert( +static KeySym HexIMComposeSequence(KeySym ks1, KeySym ks2); +static void InitIscMode(Xic ic); +static Bool ThaiComposeConvert( Display *dpy, KeySym insym, KeySym *outsym, KeySym *lower, KeySym *upper); @@ -530,7 +530,7 @@ Private Bool ThaiComposeConvert( #define IC_DeletePreviousChar(ic) \ (IC_RealDeletePreviousChar(ic)) -Private unsigned char +static unsigned char IC_RealGetPreviousChar(Xic ic, unsigned short pos) { XICCallback* cb = &ic->core.string_conversion_callback; @@ -597,7 +597,7 @@ IC_RealGetPreviousChar(Xic ic, unsigned short pos) } } -Private unsigned char +static unsigned char IC_RealDeletePreviousChar(Xic ic) { XICCallback* cb = &ic->core.string_conversion_callback; @@ -701,8 +701,8 @@ typedef KeySym (*StateProc)( * State handler to implement the Thai hex input method. */ -Private int const nstate_handlers = 3; -Private StateProc state_handler[] = { +static int const nstate_handlers = 3; +static StateProc state_handler[] = { HexIMNormalKey, HexIMFirstComposeKey, HexIMSecondComposeKey @@ -718,7 +718,7 @@ struct _XMapThaiKey { KeySym to; }; -Private struct _XMapThaiKey const ThaiComposeTable[] = { +static struct _XMapThaiKey const ThaiComposeTable[] = { { /* 0xa4 */ XK_currency, /* 0xa5 */ XK_yen }, { /* 0xa2 */ XK_cent, /* 0xa3 */ XK_sterling }, { /* 0xe6 */ XK_ae, /* 0xef */ XK_idiaeresis }, @@ -742,7 +742,7 @@ struct _XKeytrans { /* Convert keysym to 'Thai Compose' keysym */ /* The current implementation use latin-1 keysyms */ -Private Bool +static Bool ThaiComposeConvert( Display *dpy, KeySym insym, @@ -762,7 +762,7 @@ ThaiComposeConvert( return False; } -Private int +static int XThaiTranslateKey( register Display *dpy, KeyCode keycode, @@ -847,7 +847,7 @@ XThaiTranslateKey( * Should be changed to TACTIS keysyms when they are defined by the * standard. */ -Private int +static int XThaiTranslateKeySym( Display *dpy, register KeySym symbol, @@ -956,7 +956,7 @@ XThaiTranslateKeySym( /* * given a KeySym, returns the first keycode containing it, if any. */ -Private CARD8 +static CARD8 FindKeyCode( register Display *dpy, register KeySym code) @@ -980,7 +980,7 @@ FindKeyCode( * what modifier it is bound to, if any. Sets the AnyModifier bit if it * can't map some keysym to a modifier. */ -Private void +static void ComputeMaskFromKeytrans( Display *dpy, register struct _XKeytrans *p) @@ -1020,7 +1020,7 @@ ComputeMaskFromKeytrans( #define FIRST_COMPOSE_KEY_STATE 1 #define SECOND_COMPOSE_KEY_STATE 2 -Private +static KeySym HexIMNormalKey( XicThaiPart *thai_part, KeySym symbol, @@ -1036,7 +1036,7 @@ KeySym HexIMNormalKey( } -Private +static KeySym HexIMFirstComposeKey( XicThaiPart *thai_part, KeySym symbol, @@ -1059,7 +1059,7 @@ KeySym HexIMFirstComposeKey( return NoSymbol; } -Private +static KeySym HexIMSecondComposeKey( XicThaiPart *thai_part, KeySym symbol, @@ -1094,7 +1094,7 @@ KeySym HexIMSecondComposeKey( * The current implementation of this routine returns ISO Latin Keysyms. */ -Private +static KeySym HexIMComposeSequence(KeySym ks1, KeySym ks2) { int hi_digit; @@ -1131,7 +1131,7 @@ int tactis_code; * 2) whether cancelling key event should be processed or ignored */ -Private +static int IsCancelComposeKey( KeySym *symbol, XKeyEvent *event) @@ -1163,7 +1163,7 @@ int IsCancelComposeKey( * set specified keyboard LED on or off */ -Private +static void SetLed( Display *dpy, int num, @@ -1180,7 +1180,7 @@ void SetLed( /* * Initialize ISC mode from im modifier */ -Private void InitIscMode(Xic ic) +static void InitIscMode(Xic ic) { Xim im; char *im_modifier_name; @@ -1213,7 +1213,7 @@ Private void InitIscMode(Xic ic) /* * Helper functions for _XimThaiFilter() */ -Private Bool +static Bool ThaiFltAcceptInput(Xic ic, unsigned char new_char, KeySym symbol) { DefTreeBase *b = &ic->private.local.base; @@ -1228,7 +1228,7 @@ ThaiFltAcceptInput(Xic ic, unsigned char new_char, KeySym symbol) return True; } -Private Bool +static Bool ThaiFltReorderInput(Xic ic, unsigned char previous_char, unsigned char new_char) { DefTreeBase *b = &ic->private.local.base; @@ -1242,7 +1242,7 @@ ThaiFltReorderInput(Xic ic, unsigned char previous_char, unsigned char new_char) return True; } -Private Bool +static Bool ThaiFltReplaceInput(Xic ic, unsigned char new_char, KeySym symbol) { DefTreeBase *b = &ic->private.local.base; @@ -1258,7 +1258,7 @@ ThaiFltReplaceInput(Xic ic, unsigned char new_char, KeySym symbol) return True; } -Private unsigned +static unsigned NumLockMask(Display *d) { int i; diff --git a/nx-X11/lib/X11/imThaiIc.c b/nx-X11/lib/X11/imThaiIc.c index ded78e38f..4211038e3 100644 --- a/nx-X11/lib/X11/imThaiIc.c +++ b/nx-X11/lib/X11/imThaiIc.c @@ -42,7 +42,7 @@ THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" -Private void +static void _XimThaiUnSetFocus( XIC xic) { @@ -55,7 +55,7 @@ _XimThaiUnSetFocus( return; } -Private void +static void _XimThaiDestroyIC( XIC xic) { @@ -81,7 +81,7 @@ _XimThaiDestroyIC( return; } -Private void +static void _XimThaiSetFocus( XIC xic) { @@ -102,7 +102,7 @@ _XimThaiSetFocus( return; } -Private void +static void _XimThaiReset( XIC xic) { @@ -115,7 +115,7 @@ _XimThaiReset( b->utf8[b->tree[ic->private.local.composed].utf8] = '\0'; } -Private char * +static char * _XimThaiMbReset( XIC xic) { @@ -123,7 +123,7 @@ _XimThaiMbReset( return (char *)NULL; } -Private wchar_t * +static wchar_t * _XimThaiWcReset( XIC xic) { @@ -131,7 +131,7 @@ _XimThaiWcReset( return (wchar_t *)NULL; } -Private XICMethodsRec Thai_ic_methods = { +static XICMethodsRec Thai_ic_methods = { _XimThaiDestroyIC, /* destroy */ _XimThaiSetFocus, /* set_focus */ _XimThaiUnSetFocus, /* unset_focus */ diff --git a/nx-X11/lib/X11/imThaiIm.c b/nx-X11/lib/X11/imThaiIm.c index 73de70748..d360d0890 100644 --- a/nx-X11/lib/X11/imThaiIm.c +++ b/nx-X11/lib/X11/imThaiIm.c @@ -46,7 +46,7 @@ THIS SOFTWARE. #include "XlcPubI.h" #include "Ximint.h" -Private XIMMethodsRec Xim_im_thai_methods = { +static XIMMethodsRec Xim_im_thai_methods = { _XimThaiCloseIM, /* close */ _XimLocalSetIMValues, /* set_values */ _XimLocalGetIMValues, /* get_values */ @@ -76,7 +76,7 @@ _XimCheckIfThaiProcessing(Xim im) return(False); } -Public Bool +Bool _XimThaiOpenIM(Xim im) { XLCd lcd = im->core.lcd; @@ -145,7 +145,7 @@ Open_Error : return(False); } -Public void +void _XimThaiIMFree(Xim im) { if(im->core.im_resources) { @@ -215,7 +215,7 @@ _XimThaiIMFree(Xim im) return; } -Public Status +Status _XimThaiCloseIM(XIM xim) { Xim im = (Xim)xim; diff --git a/nx-X11/lib/X11/imTrX.c b/nx-X11/lib/X11/imTrX.c index b81c173c5..dfe915f9d 100644 --- a/nx-X11/lib/X11/imTrX.c +++ b/nx-X11/lib/X11/imTrX.c @@ -60,7 +60,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "XimTrInt.h" #include "XimTrX.h" -Private Bool +static Bool _XimXRegisterDispatcher( Xim im, Bool (*callback)( @@ -81,7 +81,7 @@ _XimXRegisterDispatcher( return True; } -Private void +static void _XimXFreeIntrCallback( Xim im) { @@ -96,7 +96,7 @@ _XimXFreeIntrCallback( return; } -Private Bool +static Bool _XimXCallDispatcher(Xim im, INT16 len, XPointer data) { register XIntrCallbackRec *rec; @@ -109,7 +109,7 @@ _XimXCallDispatcher(Xim im, INT16 len, XPointer data) return False; } -Private Bool +static Bool _XimXFilterWaitEvent( Display *d, Window w, @@ -137,7 +137,7 @@ _XimXFilterWaitEvent( return ret; } -Private Bool +static Bool _CheckConnect( Display *display, XEvent *event, @@ -153,7 +153,7 @@ _CheckConnect( return False; } -Private Bool +static Bool _XimXConnect(Xim im) { XEvent event; @@ -224,7 +224,7 @@ _XimXConnect(Xim im) return True; } -Private Bool +static Bool _XimXShutdown(Xim im) { XSpecRec *spec = (XSpecRec *)im->private.proto.spec; @@ -244,7 +244,7 @@ _XimXShutdown(Xim im) return True; } -Private char * +static char * _NewAtom( char *atomName) { @@ -255,7 +255,7 @@ _NewAtom( return atomName; } -Private Bool +static Bool _XimXWrite(Xim im, INT16 len, XPointer data) { Atom atom; @@ -316,7 +316,7 @@ _XimXWrite(Xim im, INT16 len, XPointer data) return True; } -Private Bool +static Bool _XimXGetReadData( Xim im, char *buf, @@ -440,7 +440,7 @@ _XimXGetReadData( return True; } -Private Bool +static Bool _CheckCMEvent( Display *display, XEvent *event, @@ -461,7 +461,7 @@ _CheckCMEvent( return False; } -Private Bool +static Bool _XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len) { XEvent *ev; @@ -484,14 +484,14 @@ _XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len) return True; } -Private void +static void _XimXFlush(Xim im) { XFlush(im->core.display); return; } -Public Bool +Bool _XimXConf(Xim im, char *address) { XSpecRec *spec; diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index 4c4651599..adfa044f5 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -72,7 +72,7 @@ PERFORMANCE OF THIS SOFTWARE. #endif -Private Bool +static Bool _XimTransConnect( Xim im) { @@ -122,7 +122,7 @@ _XimTransConnect( } -Private Bool +static Bool _XimTransShutdown( Xim im) { @@ -142,7 +142,7 @@ _XimTransShutdown( -Public Bool +Bool _XimTransRegisterDispatcher( Xim im, Bool (*callback)( @@ -164,7 +164,7 @@ _XimTransRegisterDispatcher( } -Public void +void _XimFreeTransIntrCallback( Xim im) { @@ -180,7 +180,7 @@ _XimFreeTransIntrCallback( } -Public Bool +Bool _XimTransCallDispatcher(Xim im, INT16 len, XPointer data) { TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; @@ -194,7 +194,7 @@ _XimTransCallDispatcher(Xim im, INT16 len, XPointer data) } -Public Bool +Bool _XimTransFilterWaitEvent( Display *d, Window w, @@ -209,7 +209,7 @@ _XimTransFilterWaitEvent( } -Public void +void _XimTransInternalConnection( Display *d, int fd, @@ -235,7 +235,7 @@ _XimTransInternalConnection( } -Public Bool +Bool _XimTransWrite(Xim im, INT16 len, XPointer data) { TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; @@ -252,7 +252,7 @@ _XimTransWrite(Xim im, INT16 len, XPointer data) } -Public Bool +Bool _XimTransRead( Xim im, XPointer recv_buf, @@ -273,7 +273,7 @@ _XimTransRead( } -Public void +void _XimTransFlush( Xim im) { @@ -282,7 +282,7 @@ _XimTransFlush( -Public Bool +Bool _XimTransConf( Xim im, char *address) diff --git a/nx-X11/lib/X11/imTransR.c b/nx-X11/lib/X11/imTransR.c index e536bbc9b..5f51722da 100644 --- a/nx-X11/lib/X11/imTransR.c +++ b/nx-X11/lib/X11/imTransR.c @@ -57,7 +57,7 @@ PERFORMANCE OF THIS SOFTWARE. #include "XimTrInt.h" #include "Ximint.h" -Public TransportSW _XimTransportRec[] = { +TransportSW _XimTransportRec[] = { { "X", _XimXConf }, /* 1st entry must be X. This will be a fallback */ #ifdef TCPCONN @@ -75,25 +75,25 @@ Public TransportSW _XimTransportRec[] = { { (char *)NULL, (Bool (*)(Xim, char *))NULL }, }; -Public Bool +Bool _XimConnect(Xim im) { return im->private.proto.connect(im); } -Public Bool +Bool _XimShutdown(Xim im) { return im->private.proto.shutdown(im); } -Public Bool +Bool _XimWrite(Xim im, INT16 len, XPointer data) { return im->private.proto.write(im, len, data); } -Private int +static int _CheckProtocolData( Xim im, char *recv_buf) @@ -104,7 +104,7 @@ _CheckProtocolData( return data_len; } -Private int +static int _XimReadData( Xim im, INT16 *len, @@ -221,7 +221,7 @@ _XimReadData( return XIM_TRUE; } -Private Bool +static Bool _XimCallDispatcher( Xim im, INT16 len, @@ -230,7 +230,7 @@ _XimCallDispatcher( return im->private.proto.call_dispatcher(im, len, data); } -Public int +int _XimRead(Xim im, INT16 *len, XPointer buf, int buf_size, Bool (*predicate)(Xim, INT16, XPointer, XPointer), XPointer arg) { @@ -252,7 +252,7 @@ _XimRead(Xim im, INT16 *len, XPointer buf, int buf_size, return True; } -Public Bool +Bool _XimRegisterDispatcher( Xim im, Bool (*callback)( @@ -263,14 +263,14 @@ _XimRegisterDispatcher( return im->private.proto.register_dispatcher(im, callback, call_data); } -Public void +void _XimFlush(Xim im) { im->private.proto.flush(im); return; } -Public Bool +Bool _XimFilterWaitEvent(Xim im) { INT16 read_len; -- cgit v1.2.3 From 53e2e92e30138f92f04dc5cd25020ee757560d63 Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Fri, 20 May 2011 18:25:24 +0200 Subject: Don't hard code path to Xcms.txt file. The path to this file is configurable at build time. The source however contains a hard coded path. Signed-off-by: Egbert Eich Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Imakefile | 2 +- nx-X11/lib/X11/cmsColNm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Imakefile b/nx-X11/lib/X11/Imakefile index af0bcff41..28dcdc1db 100644 --- a/nx-X11/lib/X11/Imakefile +++ b/nx-X11/lib/X11/Imakefile @@ -159,7 +159,7 @@ EXTRA_LIBRARIES = /**/ XF86BIGFONT_DEFINES = XF86BigfontExtensionDefines EDB_DEFINES = -DERRORDB=\"$(USRDATADIR)/XErrorDB\" - CMS_DEFINES = -DXCMSDB=\"$(USRDATADIR)/Xcms.txt\" + CMS_DEFINES = -DXCMSDB=\"$(USRDATADIR)/Xcms.txt\" -DXCMSDIR=\"$(USRDATADIR)\" #if HasSnprintf MISC_DEFINES = -DHAS_SNPRINTF -DLIBX11 #endif diff --git a/nx-X11/lib/X11/cmsColNm.c b/nx-X11/lib/X11/cmsColNm.c index 12f23ce99..4b6739adf 100644 --- a/nx-X11/lib/X11/cmsColNm.c +++ b/nx-X11/lib/X11/cmsColNm.c @@ -54,7 +54,7 @@ static Status LoadColornameDB(void); * #define declarations local to this package. */ #ifndef XCMSDB -#define XCMSDB "/usr/lib/X11/Xcms.txt" +#define XCMSDB XCMSDIR "/Xcms.txt" #endif #ifndef isgraph -- cgit v1.2.3 From acceb2cf62a9c732703717eb5b54c5d56af281d2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 26 Dec 2012 22:56:38 -0800 Subject: Remove unused TLI ("STREAMSCONN") code from Xlib Has never been converted to build in modular builds, so has been unusable since X11R7.0 release in 2005. All known platforms with TLI/XTI support that X11R7 & later releases run on also have (and mostly prefer) BSD socket support for their networking API. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XimTrInt.h | 2 +- nx-X11/lib/X11/globals.c | 121 ---------------------------------------------- nx-X11/lib/X11/imTransR.c | 3 -- 3 files changed, 1 insertion(+), 125 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XimTrInt.h b/nx-X11/lib/X11/XimTrInt.h index b7e4439d2..58134cdd9 100644 --- a/nx-X11/lib/X11/XimTrInt.h +++ b/nx-X11/lib/X11/XimTrInt.h @@ -73,7 +73,7 @@ extern Bool _XimXConf( char *address ); -#if defined(TCPCONN) || defined(UNIXCONN) || defined(DNETCONN) || defined(STREAMSCONN) +#if defined(TCPCONN) || defined(UNIXCONN) || defined(DNETCONN) extern Bool _XimTransConf( Xim im, diff --git a/nx-X11/lib/X11/globals.c b/nx-X11/lib/X11/globals.c index d1cab6ba5..bcc49486e 100644 --- a/nx-X11/lib/X11/globals.c +++ b/nx-X11/lib/X11/globals.c @@ -87,127 +87,6 @@ ZEROINIT (int, _Xdebug, 0); ZEROINIT (Display *, _XHeadOfDisplayList, NULL); - -#if 0 -#ifdef STREAMSCONN - - -/* The following are how the Xstream connections are used: */ -/* 1) Local connections over pseudo-tty ports. */ -/* 2) SVR4 local connections using named streams or SVR3.2 */ -/* local connections using streams. */ -/* 3) SVR4 stream pipe code. This code is proprietary and */ -/* the actual code is not included in the XC distribution. */ -/* 4) remote connections using tcp */ -/* 5) remote connections using StarLan */ - -/* - * descriptor block for streams connections - */ - -#include "Xstreams.h" - -char _XsTypeOfStream[100] = { 0 }; - -extern int write(); -extern int close(); -#ifdef SVR4 -extern int _XsSetupSpStream(); -extern int _XsSetupNamedStream(); -#endif -extern int _XsSetupLocalStream(); -extern int _XsConnectLocalClient(); -extern int _XsCallLocalServer(); -extern int _XsReadLocalStream(); -extern int _XsErrorCall(); -extern int _XsWriteLocalStream(); -extern int _XsCloseLocalStream(); -extern int _XsSetupTliStream(); -extern int _XsConnectTliClient(); -extern int _XsCallTliServer(); -extern int _XsReadTliStream(); -extern int _XsWriteTliStream(); -extern int _XsCloseTliStream(); - - -Xstream _XsStream[] = { - - { - /* local connections using pseudo-ttys */ - - _XsSetupLocalStream, - _XsConnectLocalClient, - _XsCallLocalServer, - _XsReadLocalStream, - _XsErrorCall, - write, - close, - NULL - }, - { -#ifdef SVR4 - /* local connections using named streams */ - - _XsSetupNamedStream, -#else - /* local connections using streams */ - _XsSetupLocalStream, -#endif - _XsConnectLocalClient, - _XsCallLocalServer, - _XsReadLocalStream, - _XsErrorCall, - write, - close, - NULL - }, - /* Enhanced Application Compatibility Support */ - { -#ifdef SVR4 - /* SVR4 stream pipe code */ - _XsSetupSpStream, -#else - _XsSetupLocalStream, -#endif - _XsConnectLocalClient, - _XsCallLocalServer, - _XsReadLocalStream, - _XsErrorCall, - write, - close, - NULL - }, - /* End Enhanced Application Compatibility Support */ - - { - /* remote connections using tcp */ - _XsSetupTliStream, - _XsConnectTliClient, - _XsCallTliServer, - _XsReadLocalStream, - _XsErrorCall, - write, - close, - NULL - }, - { - /* remote connections using StarLan */ - _XsSetupTliStream, - _XsConnectTliClient, - _XsCallTliServer, - _XsReadLocalStream, - _XsErrorCall, - write, - close, - NULL - } -}; - - -#endif /* STREAMSCONN */ -#endif - - #ifdef XTEST1 /* * Stuff for input synthesis extension: diff --git a/nx-X11/lib/X11/imTransR.c b/nx-X11/lib/X11/imTransR.c index 5f51722da..6dc335876 100644 --- a/nx-X11/lib/X11/imTransR.c +++ b/nx-X11/lib/X11/imTransR.c @@ -69,9 +69,6 @@ TransportSW _XimTransportRec[] = { #ifdef DNETCONN { "dnet", _XimTransConf }, /* use X transport lib */ #endif /* DNETCONN */ -#ifdef STREAMSCONN - { "streams", _XimTransConf }, /* use X transport lib */ -#endif /* STREAMSCONN */ { (char *)NULL, (Bool (*)(Xim, char *))NULL }, }; -- cgit v1.2.3 From 19275f9e196c13e5ebab807da34b69f0defef1b6 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 26 Dec 2012 22:57:39 -0800 Subject: Remove unused DECnet ("DNETCONN") code from Xlib Has never been converted to build in modular builds, so has been unusable since X11R7.0 release in 2005. DNETCONN support was removed from xtrans back in 2008. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XimTrInt.h | 2 +- nx-X11/lib/X11/imTransR.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XimTrInt.h b/nx-X11/lib/X11/XimTrInt.h index 58134cdd9..541df2eb9 100644 --- a/nx-X11/lib/X11/XimTrInt.h +++ b/nx-X11/lib/X11/XimTrInt.h @@ -73,7 +73,7 @@ extern Bool _XimXConf( char *address ); -#if defined(TCPCONN) || defined(UNIXCONN) || defined(DNETCONN) +#if defined(TCPCONN) || defined(UNIXCONN) extern Bool _XimTransConf( Xim im, diff --git a/nx-X11/lib/X11/imTransR.c b/nx-X11/lib/X11/imTransR.c index 6dc335876..2226c950d 100644 --- a/nx-X11/lib/X11/imTransR.c +++ b/nx-X11/lib/X11/imTransR.c @@ -66,9 +66,6 @@ TransportSW _XimTransportRec[] = { #if defined(UNIXCONN) || defined(LOCALCONN) { "local", _XimTransConf }, /* use X transport lib */ #endif /* UNIXCONN */ -#ifdef DNETCONN - { "dnet", _XimTransConf }, /* use X transport lib */ -#endif /* DNETCONN */ { (char *)NULL, (Bool (*)(Xim, char *))NULL }, }; -- cgit v1.2.3 From 5608b67f2bfafcee9ac82434aa4fa7e532ffb472 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 15 Feb 2013 22:45:19 -0800 Subject: cmsColNm.c: maintain constness of arguments to qsort helper function Fixes gcc warning: cmsColNm.c: In function 'FirstCmp': cmsColNm.c:257:20: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] cmsColNm.c:257:45: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/cmsColNm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/cmsColNm.c b/nx-X11/lib/X11/cmsColNm.c index 4b6739adf..a56141021 100644 --- a/nx-X11/lib/X11/cmsColNm.c +++ b/nx-X11/lib/X11/cmsColNm.c @@ -255,7 +255,7 @@ FirstCmp(const void *p1, const void *p2) * */ { - return(strcmp(((XcmsPair *)p1)->first, ((XcmsPair *)p2)->first)); + return(strcmp(((const XcmsPair *)p1)->first, ((const XcmsPair *)p2)->first)); } -- cgit v1.2.3 From 6417045168d4ea833c3d340c885932befd25adad Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 15 Feb 2013 23:14:40 -0800 Subject: XRebindKeysym: Drop unnecessary const-removing cast C89 defines memcpy as taking a const void *, so casting from const unsigned char * to char * simply angers gcc for no benefit: KeyBind.c:1017:24: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/KeyBind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index a50a7b2cc..d473f907c 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/KeyBind.c @@ -1014,7 +1014,7 @@ XRebindKeysym ( dpy->key_bindings = p; dpy->free_funcs->key_bindings = _XFreeKeyBindings; p->next = tmp; /* chain onto list */ - memcpy (p->string, (char *) str, nbytes); + memcpy (p->string, str, nbytes); p->len = nbytes; memcpy ((char *) p->modifiers, (char *) mlist, nb); p->key = keysym; -- cgit v1.2.3 From d91c145a46bcece11623121f5e468d24d5031cab Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 15 Feb 2013 23:25:38 -0800 Subject: XStringToKeysym: preserve constness when casting off unsignedness for strcmp Fixes gcc warning: StrKeysym.c:97:17: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/StrKeysym.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/StrKeysym.c b/nx-X11/lib/X11/StrKeysym.c index 21dec924b..125aceca3 100644 --- a/nx-X11/lib/X11/StrKeysym.c +++ b/nx-X11/lib/X11/StrKeysym.c @@ -94,7 +94,7 @@ XStringToKeysym(_Xconst char *s) { entry = &_XkeyTable[idx]; if ((entry[0] == sig1) && (entry[1] == sig2) && - !strcmp(s, (char *)entry + 6)) + !strcmp(s, (const char *)entry + 6)) { val = (entry[2] << 24) | (entry[3] << 16) | (entry[4] << 8) | entry[5]; -- cgit v1.2.3 From 5e0584c43d3511a5544246a0f82c759ce860a0c2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 15 Feb 2013 23:34:40 -0800 Subject: Preserve constness in casting arguments through the Data*() routines Casts were annoying gcc by dropping constness when changing types, when routines simply either copy data into the request buffer or send it directly to the X server, and never modify the input. Fixes gcc warnings including: ChProp.c: In function 'XChangeProperty': ChProp.c:65:6: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] ChProp.c:65:6: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] ChProp.c:74:6: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] ChProp.c:74:6: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] ChProp.c:83:6: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] SetHints.c: In function 'XSetStandardProperties': SetHints.c:262:20: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] SetPntMap.c: In function 'XSetPointerMapping': SetPntMap.c:46:5: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] SetPntMap.c:46:5: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] StBytes.c: In function 'XStoreBuffer': StBytes.c:97:33: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] StName.c: In function 'XStoreName': StName.c:40:27: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] StName.c: In function 'XSetIconName': StName.c:51:27: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ChProp.c | 6 +++--- nx-X11/lib/X11/SetHints.c | 4 +++- nx-X11/lib/X11/SetPntMap.c | 2 +- nx-X11/lib/X11/StBytes.c | 2 +- nx-X11/lib/X11/StName.c | 6 +++--- nx-X11/lib/X11/XlibInt.c | 4 ++-- nx-X11/lib/X11/Xlibint.h | 8 ++++---- 7 files changed, 17 insertions(+), 15 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ChProp.c b/nx-X11/lib/X11/ChProp.c index 347c3d7a1..1721168b4 100644 --- a/nx-X11/lib/X11/ChProp.c +++ b/nx-X11/lib/X11/ChProp.c @@ -62,7 +62,7 @@ XChangeProperty ( len = ((long)nelements + 3)>>2; if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { SetReqLen(req, len, len); - Data (dpy, (char *)data, nelements); + Data (dpy, (_Xconst char *)data, nelements); } /* else force BadLength */ break; @@ -71,7 +71,7 @@ XChangeProperty ( if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { SetReqLen(req, len, len); len = (long)nelements << 1; - Data16 (dpy, (short *) data, len); + Data16 (dpy, (_Xconst short *) data, len); } /* else force BadLength */ break; @@ -80,7 +80,7 @@ XChangeProperty ( if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { SetReqLen(req, len, len); len = (long)nelements << 2; - Data32 (dpy, (long *) data, len); + Data32 (dpy, (_Xconst long *) data, len); } /* else force BadLength */ break; diff --git a/nx-X11/lib/X11/SetHints.c b/nx-X11/lib/X11/SetHints.c index 7301ce42a..102619622 100644 --- a/nx-X11/lib/X11/SetHints.c +++ b/nx-X11/lib/X11/SetHints.c @@ -259,7 +259,9 @@ XSetStandardProperties ( if (icon_string != NULL) { XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8, - PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string)); + PropModeReplace, + (_Xconst unsigned char *)icon_string, + safestrlen(icon_string)); } if (icon_pixmap != None) { diff --git a/nx-X11/lib/X11/SetPntMap.c b/nx-X11/lib/X11/SetPntMap.c index 45571ada0..5dd9beef8 100644 --- a/nx-X11/lib/X11/SetPntMap.c +++ b/nx-X11/lib/X11/SetPntMap.c @@ -43,7 +43,7 @@ XSetPointerMapping ( GetReq (SetPointerMapping, req); req->nElts = nmaps; req->length += (nmaps + 3)>>2; - Data (dpy, (char *)map, (long) nmaps); + Data (dpy, (_Xconst char *)map, (long) nmaps); if (_XReply (dpy, (xReply *)&rep, 0, xFalse) == 0) rep.success = MappingSuccess; UnlockDisplay(dpy); diff --git a/nx-X11/lib/X11/StBytes.c b/nx-X11/lib/X11/StBytes.c index 0cbbb25f6..390f66832 100644 --- a/nx-X11/lib/X11/StBytes.c +++ b/nx-X11/lib/X11/StBytes.c @@ -94,7 +94,7 @@ XStoreBuffer ( { if ((buffer < 0) || (buffer > 7)) return 0; return XChangeProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer], - XA_STRING, 8, PropModeReplace, (unsigned char *) bytes, nbytes); + XA_STRING, 8, PropModeReplace, (_Xconst unsigned char *) bytes, nbytes); } int diff --git a/nx-X11/lib/X11/StName.c b/nx-X11/lib/X11/StName.c index 3f33472d3..a003a109e 100644 --- a/nx-X11/lib/X11/StName.c +++ b/nx-X11/lib/X11/StName.c @@ -37,7 +37,7 @@ XStoreName ( _Xconst char *name) { return XChangeProperty(dpy, w, XA_WM_NAME, XA_STRING, - 8, PropModeReplace, (unsigned char *)name, + 8, PropModeReplace, (_Xconst unsigned char *)name, name ? strlen(name) : 0); } @@ -47,7 +47,7 @@ XSetIconName ( Window w, _Xconst char *icon_name) { - return XChangeProperty(dpy, w, XA_WM_ICON_NAME, XA_STRING, - 8, PropModeReplace, (unsigned char *)icon_name, + return XChangeProperty(dpy, w, XA_WM_ICON_NAME, XA_STRING, 8, + PropModeReplace, (_Xconst unsigned char *)icon_name, icon_name ? strlen(icon_name) : 0); } diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 8dc07ad1b..2d84c626d 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -3852,7 +3852,7 @@ void _Xbcopy(b1, b2, length) #ifdef DataRoutineIsProcedure void Data( Display *dpy, - char *data, + _Xconst char *data, long len) { if (dpy->bufptr + (len) <= dpy->bufmax) { @@ -3869,7 +3869,7 @@ void Data( int _XData32( Display *dpy, - register long *data, + register _Xconst long *data, unsigned len) { register int *buf; diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index 603139fd6..e3d63f29a 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -620,14 +620,14 @@ extern void _XFlushGCCache(Display *dpy, GC gc); (void)ptr; \ dpy->bufptr += (n); -#define Data16(dpy, data, len) Data((dpy), (char *)(data), (len)) +#define Data16(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len)) #define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len)) #define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len)) #ifdef LONG64 -#define Data32(dpy, data, len) _XData32(dpy, (long *)data, len) +#define Data32(dpy, data, len) _XData32(dpy, (_Xconst long *)data, len) extern int _XData32( Display *dpy, - register long *data, + register _Xconst long *data, unsigned len ); extern void _XRead32( @@ -636,7 +636,7 @@ extern void _XRead32( long len ); #else -#define Data32(dpy, data, len) Data((dpy), (char *)(data), (len)) +#define Data32(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len)) #define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len)) #endif -- cgit v1.2.3 From d43f4c3980cb76f39167e18b20ccec23182ed582 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 15 Feb 2013 23:43:12 -0800 Subject: XKeysymToString: move variable declarations to the scope of their usage Makes it easier for readers to understand scope of variable usage, and clears up gcc warning: KeysymStr.c: In function 'XKeysymToString': KeysymStr.c:128:13: warning: declaration of 'i' shadows a previous local [-Wshadow] KeysymStr.c:73:18: warning: shadowed declaration is here [-Wshadow] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/KeysymStr.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/KeysymStr.c b/nx-X11/lib/X11/KeysymStr.c index 96c49227a..797cf53bd 100644 --- a/nx-X11/lib/X11/KeysymStr.c +++ b/nx-X11/lib/X11/KeysymStr.c @@ -70,11 +70,6 @@ SameValue( char *XKeysymToString(KeySym ks) { - register int i, n; - int h; - register int idx; - const unsigned char *entry; - unsigned char val1, val2, val3, val4; XrmDatabase keysymdb; if (!ks || (ks & ((unsigned long) ~0x1fffffff)) != 0) @@ -83,16 +78,17 @@ char *XKeysymToString(KeySym ks) ks = 0; if (ks <= 0x1fffffff) { - val1 = ks >> 24; - val2 = (ks >> 16) & 0xff; - val3 = (ks >> 8) & 0xff; - val4 = ks & 0xff; - i = ks % VTABLESIZE; - h = i + 1; - n = VMAXHASH; + unsigned char val1 = ks >> 24; + unsigned char val2 = (ks >> 16) & 0xff; + unsigned char val3 = (ks >> 8) & 0xff; + unsigned char val4 = ks & 0xff; + int i = ks % VTABLESIZE; + int h = i + 1; + int n = VMAXHASH; + int idx; while ((idx = hashKeysym[i])) { - entry = &_XkeyTable[idx]; + const unsigned char *entry = &_XkeyTable[idx]; if ((entry[0] == val1) && (entry[1] == val2) && (entry[2] == val3) && (entry[3] == val4)) return ((char *)entry + 4); @@ -136,7 +132,7 @@ char *XKeysymToString(KeySym ks) i--; s[i--] = '\0'; for (; i; i--){ - val1 = val & 0xf; + unsigned char val1 = val & 0xf; val >>= 4; if (val1 < 10) s[i] = '0'+ val1; -- cgit v1.2.3 From d31b81c1010b4259bb0caafdbd82483fabda787d Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 16 Feb 2013 10:42:23 -0800 Subject: Convert more sprintf calls to snprintf You could analyze most of these and quickly recognize that there was no chance of buffer overflow already, but why make everyone spend time doing that when we can just make it obviously safe? Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ErrDes.c | 9 +++++---- nx-X11/lib/X11/GetDflt.c | 2 +- nx-X11/lib/X11/KeysymStr.c | 2 +- nx-X11/lib/X11/XlibInt.c | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ErrDes.c b/nx-X11/lib/X11/ErrDes.c index ac13b480b..f13e3dce4 100644 --- a/nx-X11/lib/X11/ErrDes.c +++ b/nx-X11/lib/X11/ErrDes.c @@ -109,7 +109,7 @@ XGetErrorText( if (nbytes == 0) return 0; if (code <= BadImplementation && code > 0) { - sprintf(buf, "%d", code); + snprintf(buf, sizeof(buf), "%d", code); (void) XGetErrorDatabaseText(dpy, "XProtoError", buf, _XErrorList + _XErrorOffsets[code], buffer, nbytes); @@ -125,11 +125,12 @@ XGetErrorText( bext = ext; } if (!buffer[0] && bext) { - sprintf(buf, "%s.%d", bext->name, code - bext->codes.first_error); + snprintf(buf, sizeof(buf), "%s.%d", + bext->name, code - bext->codes.first_error); (void) XGetErrorDatabaseText(dpy, "XProtoError", buf, "", buffer, nbytes); } if (!buffer[0]) - sprintf(buffer, "%d", code); + snprintf(buffer, nbytes, "%d", code); return 0; } @@ -190,7 +191,7 @@ XGetErrorDatabaseText( else tptr = Xmalloc (tlen); if (tptr) { - sprintf(tptr, "%s.%s", name, type); + snprintf(tptr, tlen, "%s.%s", name, type); XrmGetResource(db, tptr, "ErrorType.ErrorNumber", &type_str, &result); if (tptr != temp) diff --git a/nx-X11/lib/X11/GetDflt.c b/nx-X11/lib/X11/GetDflt.c index 749893c7e..f2098dff3 100644 --- a/nx-X11/lib/X11/GetDflt.c +++ b/nx-X11/lib/X11/GetDflt.c @@ -87,7 +87,7 @@ GetHomeDir( len2 = strlen (ptr2); } if ((len1 + len2 + 1) < len) - sprintf (dest, "%s%s", ptr1, (ptr2) ? ptr2 : ""); + snprintf (dest, len, "%s%s", ptr1, (ptr2) ? ptr2 : ""); else *dest = '\0'; #else diff --git a/nx-X11/lib/X11/KeysymStr.c b/nx-X11/lib/X11/KeysymStr.c index 797cf53bd..ba6c8450a 100644 --- a/nx-X11/lib/X11/KeysymStr.c +++ b/nx-X11/lib/X11/KeysymStr.c @@ -107,7 +107,7 @@ char *XKeysymToString(KeySym ks) XrmQuark empty = NULLQUARK; GRNData data; - sprintf(buf, "%lX", ks); + snprintf(buf, sizeof(buf), "%lX", ks); resval.addr = (XPointer)buf; resval.size = strlen(buf) + 1; data.name = (char *)NULL; diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 2d84c626d..1ecbaaa4f 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -3521,7 +3521,7 @@ static int _XPrintDefaultError( mesg, BUFSIZ); (void) fprintf(fp, mesg, event->request_code); if (event->request_code < 128) { - sprintf(number, "%d", event->request_code); + snprintf(number, sizeof(number), "%d", event->request_code); XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); } else { for (ext = dpy->ext_procs; @@ -3541,7 +3541,7 @@ static int _XPrintDefaultError( fputs(" ", fp); (void) fprintf(fp, mesg, event->minor_code); if (ext) { - sprintf(mesg, "%s.%d", ext->name, event->minor_code); + snprintf(mesg, sizeof(mesg), "%s.%d", ext->name, event->minor_code); XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); (void) fprintf(fp, " (%s)", buffer); } @@ -3564,8 +3564,8 @@ static int _XPrintDefaultError( bext = ext; } if (bext) - sprintf(buffer, "%s.%d", bext->name, - event->error_code - bext->codes.first_error); + snprintf(buffer, sizeof(buffer), "%s.%d", bext->name, + event->error_code - bext->codes.first_error); else strcpy(buffer, "Value"); XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ); -- cgit v1.2.3 From 2393e1acdbf709c5797a37ffca6bfa9093876c0b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 1 Mar 2013 18:09:07 -0800 Subject: unifdef XKB_IN_SERVER Leftovers from XKB files that were previously shared between the client and server code, but aren't any more. Signed-off-by: Alan Coopersmith Reviewed-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBAlloc.c | 12 ------------ nx-X11/lib/X11/XKBGAlloc.c | 12 ------------ nx-X11/lib/X11/XKBMAlloc.c | 13 ------------- nx-X11/lib/X11/XKBMisc.c | 13 ------------- 4 files changed, 50 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBAlloc.c b/nx-X11/lib/X11/XKBAlloc.c index 995c955cc..937e02fae 100644 --- a/nx-X11/lib/X11/XKBAlloc.c +++ b/nx-X11/lib/X11/XKBAlloc.c @@ -30,7 +30,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -#ifndef XKB_IN_SERVER #include #include "Xlibint.h" @@ -39,17 +38,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "XKBlibint.h" -#else - -#include -#include -#include -#include "misc.h" -#include "inputstr.h" -#include -#include - -#endif /* XKB_IN_SERVER */ /***===================================================================***/ diff --git a/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index fa405fb9c..d9682f588 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -30,7 +30,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -#ifndef XKB_IN_SERVER #include #include "Xlibint.h" @@ -38,17 +37,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#else - -#include -#include -#include -#include "misc.h" -#include "inputstr.h" -#include -#include - -#endif /* XKB_IN_SERVER */ #ifdef X_NOT_POSIX #define Size_t unsigned int diff --git a/nx-X11/lib/X11/XKBMAlloc.c b/nx-X11/lib/X11/XKBMAlloc.c index 594ef7f71..c81540aae 100644 --- a/nx-X11/lib/X11/XKBMAlloc.c +++ b/nx-X11/lib/X11/XKBMAlloc.c @@ -30,7 +30,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -#ifndef XKB_IN_SERVER #include #include "Xlibint.h" @@ -38,18 +37,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "XKBlibint.h" -#else - -#include -#include -#include -#include "misc.h" -#include "inputstr.h" -#include -#define XKBSRV_NEED_FILE_FUNCS -#include - -#endif /* XKB_IN_SERVER */ /***====================================================================***/ diff --git a/nx-X11/lib/X11/XKBMisc.c b/nx-X11/lib/X11/XKBMisc.c index ea6bd4518..4a12946e0 100644 --- a/nx-X11/lib/X11/XKBMisc.c +++ b/nx-X11/lib/X11/XKBMisc.c @@ -30,7 +30,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -#ifndef XKB_IN_SERVER #include #include "Xlibint.h" @@ -38,18 +37,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "XKBlibint.h" -#else - -#include -#include -#include -#include "misc.h" -#include "inputstr.h" -#include -#define XKBSRV_NEED_FILE_FUNCS -#include - -#endif /* XKB_IN_SERVER */ /***====================================================================***/ -- cgit v1.2.3 From e18ccaaae7fdf039114eb10e92d8339031530816 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 1 Mar 2013 18:10:27 -0800 Subject: Assume size_t is always available, since it was defined in C89 Don't provide a fallback definition #ifdef X_NOT_POSIX anymore. We already use size_t throughout the rest of Xlib, just had this one instance left in XKBGAlloc.c of a fallback definition. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGAlloc.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index d9682f588..74cadaee0 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -37,13 +37,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include - -#ifdef X_NOT_POSIX -#define Size_t unsigned int -#else -#define Size_t size_t -#endif - /***====================================================================***/ static void @@ -464,7 +457,7 @@ _XkbGeomAlloc( XPointer * old, unsigned short * num, unsigned short * total, int num_new, - Size_t sz_elem) + size_t sz_elem) { if (num_new<1) return Success; -- cgit v1.2.3 From 7ddc5b90f200d3df70ca744d35507799334a8d9e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 8 Mar 2013 17:13:09 -0800 Subject: _xudc_code_to_glyph: check for NULL pointer *before* writing to it, not after Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/udcInf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/udcInf.c b/nx-X11/lib/X11/udcInf.c index afe398cc7..eeb847657 100644 --- a/nx-X11/lib/X11/udcInf.c +++ b/nx-X11/lib/X11/udcInf.c @@ -702,14 +702,14 @@ int *num_gi; _XlcCloseConverter(conv); _XlcDestroyLC(lcd); - *gi = (_XUDCGIInf *)Xmalloc(sizeof(_XUDCGIInf)); - (*gi)->charset_str = (char *)Xmalloc(strlen(charsetname)+1); - strcpy((*gi)->charset_str,charsetname); - (*gi)->glyph_index = glyph; + *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); } -- cgit v1.2.3 From 001aeb55b16633ced88eec1fa3d1a5bf516c83f0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 8 Mar 2013 15:37:33 -0800 Subject: XAllocClassHint: Assume calloc sets pointers in allocated memory to NULL While the C standard technically allows for the compiler to translate pointer = 0 or pointer = NULL into something other than filling the pointer address with 0 bytes, the rest of the Xlib code already assumes that calloc initializes any pointers in the struct to NULL, and there are no known systems supported by X.Org where this is not true. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/PropAlloc.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/PropAlloc.c b/nx-X11/lib/X11/PropAlloc.c index bad768153..516283080 100644 --- a/nx-X11/lib/X11/PropAlloc.c +++ b/nx-X11/lib/X11/PropAlloc.c @@ -58,12 +58,7 @@ XWMHints *XAllocWMHints (void) XClassHint *XAllocClassHint (void) { - register XClassHint *h; - - if ((h = (XClassHint *) Xcalloc (1, (unsigned) sizeof (XClassHint)))) - h->res_name = h->res_class = NULL; - - return h; + return Xcalloc (1, sizeof (XClassHint)); } -- cgit v1.2.3 From 4988e9bd927165af0914c3a598751e1bd775f9b1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 8 Mar 2013 22:33:28 -0800 Subject: Fix very weird indenting in nx-X11/lib/X11/GetFProp.c Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/GetFProp.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/GetFProp.c b/nx-X11/lib/X11/GetFProp.c index 78e69c941..1e0cd3285 100644 --- a/nx-X11/lib/X11/GetFProp.c +++ b/nx-X11/lib/X11/GetFProp.c @@ -29,24 +29,24 @@ in this Software without prior written authorization from The Open Group. #endif #include "Xlibint.h" -Bool XGetFontProperty ( +Bool +XGetFontProperty( XFontStruct *fs, register Atom name, unsigned long *valuePtr) { /* XXX this is a simple linear search for now. If the - protocol is changed to sort the property list, this should - become a binary search. */ + protocol is changed to sort the property list, this should + become a binary search. */ register XFontProp *prop = fs->properties; register XFontProp *last = prop + fs->n_properties; + while (prop != last) { - if (prop->name == name) { - *valuePtr = prop->card32; - return (1); - } - prop++; - } - return (0); + if (prop->name == name) { + *valuePtr = prop->card32; + return (1); + } + prop++; } - - + return (0); +} -- cgit v1.2.3 From 47d0ea1ba5bdd53d5df2cd06ffb637c889cf5e03 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 16 Mar 2013 18:30:56 -0700 Subject: Move big request comment in XOpenDisplay to the right place Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/OpenDis.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/OpenDis.c b/nx-X11/lib/X11/OpenDis.c index 4036572a8..dca8ae580 100644 --- a/nx-X11/lib/X11/OpenDis.c +++ b/nx-X11/lib/X11/OpenDis.c @@ -713,6 +713,9 @@ fallback_success: #endif /* !USE_XCB */ #if USE_XCB +/* + * get availability of large requests + */ dpy->bigreq_size = xcb_get_maximum_request_length(dpy->xcb->connection); if(dpy->bigreq_size <= dpy->max_request_size) dpy->bigreq_size = 0; @@ -740,7 +743,6 @@ fallback_success: (void) XSynchronize(dpy, _Xdebug); /* - * get availability of large requests, and * get the resource manager database off the root window. */ LockDisplay(dpy); -- cgit v1.2.3 From e15023b2ad2a5ca8742cbb93fe10cb38ab079831 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 7 Mar 2013 23:46:05 -0800 Subject: Remove more unnecessary casts from Xmalloc/calloc calls Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Context.c | 8 ++++---- nx-X11/lib/X11/CrGC.c | 2 +- nx-X11/lib/X11/Depths.c | 2 +- nx-X11/lib/X11/FSWrap.c | 6 +++--- nx-X11/lib/X11/Font.c | 12 ++++++------ nx-X11/lib/X11/GetAtomNm.c | 8 ++++---- nx-X11/lib/X11/GetHints.c | 9 ++++----- nx-X11/lib/X11/GetRGBCMap.c | 3 +-- nx-X11/lib/X11/ImUtil.c | 6 +++--- nx-X11/lib/X11/InitExt.c | 4 ++-- nx-X11/lib/X11/IntAtom.c | 6 +++--- nx-X11/lib/X11/KeyBind.c | 8 +++----- nx-X11/lib/X11/ModMap.c | 4 ++-- nx-X11/lib/X11/OpenDis.c | 8 +++----- nx-X11/lib/X11/PixFormats.c | 4 ++-- nx-X11/lib/X11/PolyReg.c | 13 +++++-------- nx-X11/lib/X11/PropAlloc.c | 9 ++++----- nx-X11/lib/X11/PutBEvent.c | 2 +- nx-X11/lib/X11/PutImage.c | 13 ++++++------- nx-X11/lib/X11/Quarks.c | 9 ++++----- nx-X11/lib/X11/RdBitF.c | 2 +- nx-X11/lib/X11/Region.c | 19 +++++++++---------- nx-X11/lib/X11/RegstFlt.c | 4 ++-- nx-X11/lib/X11/SetFPath.c | 2 +- nx-X11/lib/X11/SetHints.c | 6 +++--- nx-X11/lib/X11/StrToText.c | 2 +- nx-X11/lib/X11/TextToStr.c | 4 ++-- nx-X11/lib/X11/VisUtil.c | 8 +++----- nx-X11/lib/X11/WrBitF.c | 2 +- nx-X11/lib/X11/XlibInt.c | 22 ++++++++++------------ nx-X11/lib/X11/Xrm.c | 20 +++++++++----------- nx-X11/lib/X11/locking.c | 8 ++++---- nx-X11/lib/X11/udcInf.c | 9 ++++----- 33 files changed, 112 insertions(+), 132 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Context.c b/nx-X11/lib/X11/Context.c index 79ae7d66c..4bb465b1a 100644 --- a/nx-X11/lib/X11/Context.c +++ b/nx-X11/lib/X11/Context.c @@ -111,7 +111,7 @@ static void ResizeTable(DB db) otable = db->table; for (i = INITHASHMASK+1; (i + i) < db->numentries; ) i += i; - db->table = (TableEntry *) Xcalloc((unsigned)i, sizeof(TableEntry)); + db->table = Xcalloc(i, sizeof(TableEntry)); if (!db->table) { db->table = otable; return; @@ -180,11 +180,11 @@ int XSaveContext( UnlockDisplay(display); } if (!db) { - db = (DB) Xmalloc(sizeof(DBRec)); + db = Xmalloc(sizeof(DBRec)); if (!db) return XCNOMEM; db->mask = INITHASHMASK; - db->table = (TableEntry *)Xcalloc(db->mask + 1, sizeof(TableEntry)); + db->table = Xcalloc(db->mask + 1, sizeof(TableEntry)); if (!db->table) { Xfree((char *)db); return XCNOMEM; @@ -210,7 +210,7 @@ int XSaveContext( return 0; } } - entry = (TableEntry) Xmalloc(sizeof(TableEntryRec)); + entry = Xmalloc(sizeof(TableEntryRec)); if (!entry) return XCNOMEM; entry->rid = rid; diff --git a/nx-X11/lib/X11/CrGC.c b/nx-X11/lib/X11/CrGC.c index 11de94c1f..2d5f17c00 100644 --- a/nx-X11/lib/X11/CrGC.c +++ b/nx-X11/lib/X11/CrGC.c @@ -72,7 +72,7 @@ GC XCreateGC ( register _XExtension *ext; LockDisplay(dpy); - if ((gc = (GC)Xmalloc (sizeof(struct _XGC))) == NULL) { + if ((gc = Xmalloc (sizeof(struct _XGC))) == NULL) { UnlockDisplay(dpy); SyncHandle(); return (NULL); diff --git a/nx-X11/lib/X11/Depths.c b/nx-X11/lib/X11/Depths.c index f49655cb2..a8b719d00 100644 --- a/nx-X11/lib/X11/Depths.c +++ b/nx-X11/lib/X11/Depths.c @@ -49,7 +49,7 @@ int *XListDepths ( register Depth *dp; register int i; - depths = (int *) Xmalloc (count * sizeof(int)); + depths = Xmalloc (count * sizeof(int)); if (!depths) return NULL; for (i = 0, dp = scr->depths; i < count; i++, dp++) depths[i] = dp->depth; diff --git a/nx-X11/lib/X11/FSWrap.c b/nx-X11/lib/X11/FSWrap.c index 40a892f20..015965779 100644 --- a/nx-X11/lib/X11/FSWrap.c +++ b/nx-X11/lib/X11/FSWrap.c @@ -112,7 +112,7 @@ _XParseBaseFontNameList( if (!*ptr) break; } - if (!(list = (char **) Xmalloc((unsigned)sizeof(char *) * (*num + 1)))) { + if (!(list = Xmalloc(sizeof(char *) * (*num + 1)))) { Xfree(psave); return (char **)NULL; } @@ -133,7 +133,7 @@ copy_string_list( if (string_list == NULL || list_count <= 0) return (char **) NULL; - string_list_ret = (char **) Xmalloc(sizeof(char *) * list_count); + string_list_ret = Xmalloc(sizeof(char *) * list_count); if (string_list_ret == NULL) return (char **) NULL; @@ -142,7 +142,7 @@ copy_string_list( for (length = 0; count-- > 0; list_src++) length += strlen(*list_src) + 1; - dst = (char *) Xmalloc(length); + dst = Xmalloc(length); if (dst == NULL) { Xfree(string_list_ret); return (char **) NULL; diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index d311cd0f7..cc08fda27 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -215,7 +215,7 @@ _XQueryFont ( DeqAsyncHandler(dpy, &async); reply_left = reply.length - ((SIZEOF(xQueryFontReply) - SIZEOF(xReply)) >> 2); - if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) { + if (! (fs = Xmalloc (sizeof (XFontStruct)))) { _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -324,7 +324,7 @@ _XF86BigfontCodes ( if (pData) return (XF86BigfontCodes *) pData->private_data; - pData = (XExtData *) Xmalloc(sizeof(XExtData) + sizeof(XF86BigfontCodes)); + pData = Xmalloc(sizeof(XExtData) + sizeof(XF86BigfontCodes)); if (!pData) { /* Out of luck. */ return (XF86BigfontCodes *) NULL; @@ -460,7 +460,7 @@ _XF86BigfontQueryFont ( DeqAsyncHandler(dpy, &async1); reply_left = reply.length - ((SIZEOF(xXF86BigfontQueryFontReply) - SIZEOF(xReply)) >> 2); - if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) { + if (! (fs = Xmalloc (sizeof (XFontStruct)))) { _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } @@ -523,14 +523,14 @@ _XF86BigfontQueryFont ( nbytes = reply.nUniqCharInfos * SIZEOF(xCharInfo) + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16); - pUniqCI = (xCharInfo *) Xmalloc (nbytes); + pUniqCI = Xmalloc (nbytes); if (!pUniqCI) { if (fs->properties) Xfree((char *) fs->properties); Xfree((char *) fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } - if (! (fs->per_char = (XCharStruct *) Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) { + if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) { Xfree((char *) pUniqCI); if (fs->properties) Xfree((char *) fs->properties); Xfree((char *) fs); @@ -557,7 +557,7 @@ _XF86BigfontQueryFont ( XEDataObject fs_union; char *addr; - pData = (XExtData *) Xmalloc(sizeof(XExtData)); + pData = Xmalloc(sizeof(XExtData)); if (!pData) { if (fs->properties) Xfree((char *) fs->properties); Xfree((char *) fs); diff --git a/nx-X11/lib/X11/GetAtomNm.c b/nx-X11/lib/X11/GetAtomNm.c index 996f7ebf9..32de50d23 100644 --- a/nx-X11/lib/X11/GetAtomNm.c +++ b/nx-X11/lib/X11/GetAtomNm.c @@ -46,7 +46,7 @@ char *_XGetAtomName( for (idx = TABLESIZE; --idx >= 0; ) { if ((e = *table++) && (e->atom == atom)) { idx = strlen(EntryName(e)) + 1; - if ((name = (char *)Xmalloc(idx))) + if ((name = Xmalloc(idx))) strcpy(name, EntryName(e)); return name; } @@ -73,7 +73,7 @@ char *XGetAtomName( SyncHandle(); return(NULL); } - if ((name = (char *) Xmalloc(rep.nameLength+1))) { + if ((name = Xmalloc(rep.nameLength + 1))) { _XReadPad(dpy, name, (long)rep.nameLength); name[rep.nameLength] = '\0'; _XUpdateAtomCache(dpy, name, atom, 0, -1, 0); @@ -124,7 +124,7 @@ Bool _XGetAtomNameHandler( _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len, (SIZEOF(xGetAtomNameReply) - SIZEOF(xReply)) >> 2, False); - state->names[state->idx] = (char *) Xmalloc(repl->nameLength+1); + state->names[state->idx] = Xmalloc(repl->nameLength + 1); _XGetAsyncData(dpy, state->names[state->idx], buf, len, SIZEOF(xGetAtomNameReply), repl->nameLength, repl->length << 2); @@ -170,7 +170,7 @@ XGetAtomNames ( } if (missed >= 0) { if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - if ((names_return[missed] = (char *) Xmalloc(rep.nameLength+1))) { + if ((names_return[missed] = Xmalloc(rep.nameLength + 1))) { _XReadPad(dpy, names_return[missed], (long)rep.nameLength); names_return[missed][rep.nameLength] = '\0'; _XUpdateAtomCache(dpy, names_return[missed], atoms[missed], diff --git a/nx-X11/lib/X11/GetHints.c b/nx-X11/lib/X11/GetHints.c index 1b522c8ef..80f93b427 100644 --- a/nx-X11/lib/X11/GetHints.c +++ b/nx-X11/lib/X11/GetHints.c @@ -128,7 +128,7 @@ XWMHints *XGetWMHints ( return(NULL); } /* static copies not allowed in library, due to reentrancy constraint*/ - if ((hints = (XWMHints *) Xcalloc (1, (unsigned) sizeof(XWMHints)))) { + if ((hints = Xcalloc (1, sizeof(XWMHints)))) { hints->flags = prop->flags; hints->input = (prop->input ? True : False); hints->initial_state = cvtINT32toInt (prop->initialState); @@ -203,8 +203,7 @@ Status XGetIconSizes ( /* static copies not allowed in library, due to reentrancy constraint*/ nitems /= NumPropIconSizeElements; - if (! (hp = hints = (XIconSize *) - Xcalloc ((unsigned) nitems, (unsigned) sizeof(XIconSize)))) { + if (! (hp = hints = Xcalloc (nitems, sizeof(XIconSize)))) { if (prop) Xfree ((char *) prop); return 0; } @@ -317,14 +316,14 @@ XGetClassHint( if ( (actual_type == XA_STRING) && (actual_format == 8) ) { len_name = strlen((char *) data); - if (! (classhint->res_name = Xmalloc((unsigned) (len_name+1)))) { + if (! (classhint->res_name = Xmalloc(len_name + 1))) { Xfree((char *) data); return (0); } strcpy(classhint->res_name, (char *) data); if (len_name == nitems) len_name--; len_class = strlen((char *) (data+len_name+1)); - if (! (classhint->res_class = Xmalloc((unsigned) (len_class+1)))) { + if (! (classhint->res_class = Xmalloc(len_class + 1))) { Xfree(classhint->res_name); classhint->res_name = (char *) NULL; Xfree((char *) data); diff --git a/nx-X11/lib/X11/GetRGBCMap.c b/nx-X11/lib/X11/GetRGBCMap.c index b58468bab..c4eff5602 100644 --- a/nx-X11/lib/X11/GetRGBCMap.c +++ b/nx-X11/lib/X11/GetRGBCMap.c @@ -99,8 +99,7 @@ Status XGetRGBColormaps ( /* * allocate array */ - cmaps = (XStandardColormap *) Xmalloc (ncmaps * - sizeof (XStandardColormap)); + cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap)); if (!cmaps) { if (data) Xfree ((char *) data); return False; diff --git a/nx-X11/lib/X11/ImUtil.c b/nx-X11/lib/X11/ImUtil.c index d562e3ae0..f9a21f839 100644 --- a/nx-X11/lib/X11/ImUtil.c +++ b/nx-X11/lib/X11/ImUtil.c @@ -332,7 +332,7 @@ XImage *XCreateImage ( (xpad != 8 && xpad != 16 && xpad != 32) || offset < 0) return (XImage *) NULL; - if ((image = (XImage *) Xcalloc(1, (unsigned) sizeof(XImage))) == NULL) + if ((image = Xcalloc(1, sizeof(XImage))) == NULL) return (XImage *) NULL; image->width = width; @@ -844,7 +844,7 @@ static XImage *_XSubImage ( register unsigned long pixel; char *data; - if ((subimage = (XImage *) Xcalloc (1, sizeof (XImage))) == NULL) + if ((subimage = Xcalloc (1, sizeof (XImage))) == NULL) return (XImage *) NULL; subimage->width = width; subimage->height = height; @@ -870,7 +870,7 @@ static XImage *_XSubImage ( _XInitImageFuncPtrs (subimage); dsize = subimage->bytes_per_line * height; if (subimage->format == XYPixmap) dsize = dsize * subimage->depth; - if (((data = Xcalloc (1, (unsigned) dsize)) == NULL) && (dsize > 0)) { + if (((data = Xcalloc (1, dsize)) == NULL) && (dsize > 0)) { Xfree((char *) subimage); return (XImage *) NULL; } diff --git a/nx-X11/lib/X11/InitExt.c b/nx-X11/lib/X11/InitExt.c index fdadd9ef7..9e63a9ec2 100644 --- a/nx-X11/lib/X11/InitExt.c +++ b/nx-X11/lib/X11/InitExt.c @@ -49,7 +49,7 @@ XExtCodes *XInitExtension ( &codes.first_error)) return (NULL); LockDisplay (dpy); - if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) || + if (! (ext = Xcalloc (1, sizeof (_XExtension))) || ! (ext->name = strdup(name))) { if (ext) Xfree((char *) ext); UnlockDisplay(dpy); @@ -71,7 +71,7 @@ XExtCodes *XAddExtension (Display *dpy) register _XExtension *ext; LockDisplay (dpy); - if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension)))) { + if (! (ext = Xcalloc (1, sizeof (_XExtension)))) { UnlockDisplay(dpy); return (XExtCodes *) NULL; } diff --git a/nx-X11/lib/X11/IntAtom.c b/nx-X11/lib/X11/IntAtom.c index 7a5625840..25466ca20 100644 --- a/nx-X11/lib/X11/IntAtom.c +++ b/nx-X11/lib/X11/IntAtom.c @@ -72,7 +72,7 @@ Atom _XInternAtom( /* look in the cache first */ if (!(atoms = dpy->atoms)) { - dpy->atoms = atoms = (AtomTable *)Xcalloc(1, sizeof(AtomTable)); + dpy->atoms = atoms = Xcalloc(1, sizeof(AtomTable)); dpy->free_funcs->atoms = _XFreeAtomTable; } sig = 0; @@ -127,7 +127,7 @@ _XUpdateAtomCache( if (!dpy->atoms) { if (idx < 0) { - dpy->atoms = (AtomTable *)Xcalloc(1, sizeof(AtomTable)); + dpy->atoms = Xcalloc(1, sizeof(AtomTable)); dpy->free_funcs->atoms = _XFreeAtomTable; } if (!dpy->atoms) @@ -147,7 +147,7 @@ _XUpdateAtomCache( } } } - e = (Entry)Xmalloc(sizeof(EntryRec) + n + 1); + e = Xmalloc(sizeof(EntryRec) + n + 1); if (e) { e->sig = sig; e->atom = atom; diff --git a/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index d473f907c..e29aeddc0 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/KeyBind.c @@ -997,11 +997,9 @@ XRebindKeysym ( tmp = dpy->key_bindings; nb = sizeof(KeySym) * nm; - if ((! (p = (struct _XKeytrans *) Xcalloc( 1, sizeof(struct _XKeytrans)))) || - ((! (p->string = (char *) Xmalloc( (unsigned) nbytes))) && - (nbytes > 0)) || - ((! (p->modifiers = (KeySym *) Xmalloc( (unsigned) nb))) && - (nb > 0))) { + if ((! (p = Xcalloc( 1, sizeof(struct _XKeytrans)))) || + ((! (p->string = Xmalloc(nbytes))) && (nbytes > 0)) || + ((! (p->modifiers = Xmalloc(nb))) && (nb > 0))) { if (p) { if (p->string) Xfree(p->string); if (p->modifiers) Xfree((char *) p->modifiers); diff --git a/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index 122ca80db..5c5b42612 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/ModMap.c @@ -97,11 +97,11 @@ XSetModifierMapping( XModifierKeymap * XNewModifiermap(int keyspermodifier) { - XModifierKeymap *res = (XModifierKeymap *) Xmalloc((sizeof (XModifierKeymap))); + XModifierKeymap *res = Xmalloc((sizeof (XModifierKeymap))); if (res) { res->max_keypermod = keyspermodifier; res->modifiermap = (keyspermodifier > 0 ? - (KeyCode *) Xmalloc((unsigned) (8 * keyspermodifier)) + Xmalloc(8 * keyspermodifier) : (KeyCode *) NULL); if (keyspermodifier && (res->modifiermap == NULL)) { Xfree((char *) res); diff --git a/nx-X11/lib/X11/OpenDis.c b/nx-X11/lib/X11/OpenDis.c index dca8ae580..bb87a2285 100644 --- a/nx-X11/lib/X11/OpenDis.c +++ b/nx-X11/lib/X11/OpenDis.c @@ -182,7 +182,7 @@ XOpenDisplay ( /* * Attempt to allocate a display structure. Return NULL if allocation fails. */ - if ((dpy = (Display *)Xcalloc(1, sizeof(Display))) == NULL) { + if ((dpy = Xcalloc(1, sizeof(Display))) == NULL) { return(NULL); } @@ -356,9 +356,7 @@ fallback_success: dpy->qlen = 0; /* Set up free-function record */ - if ((dpy->free_funcs = (_XFreeFuncRec *)Xcalloc(1, - sizeof(_XFreeFuncRec))) - == NULL) { + if ((dpy->free_funcs = Xcalloc(1, sizeof(_XFreeFuncRec))) == NULL) { OutOfMemory (dpy, setup); return(NULL); } @@ -523,7 +521,7 @@ fallback_success: return (NULL); } - dpy->vendor = (char *) Xmalloc((unsigned) (u.setup->nbytesVendor + 1)); + dpy->vendor = Xmalloc(u.setup->nbytesVendor + 1); if (dpy->vendor == NULL) { OutOfMemory(dpy, setup); return (NULL); diff --git a/nx-X11/lib/X11/PixFormats.c b/nx-X11/lib/X11/PixFormats.c index 8e4a10027..6d9f64d2c 100644 --- a/nx-X11/lib/X11/PixFormats.c +++ b/nx-X11/lib/X11/PixFormats.c @@ -38,8 +38,8 @@ XPixmapFormatValues *XListPixmapFormats ( Display *dpy, int *count) /* RETURN */ { - XPixmapFormatValues *formats = (XPixmapFormatValues *) - Xmalloc((unsigned) (dpy->nformats * sizeof (XPixmapFormatValues))); + XPixmapFormatValues *formats = + Xmalloc(dpy->nformats * sizeof (XPixmapFormatValues)); if (formats) { register int i; diff --git a/nx-X11/lib/X11/PolyReg.c b/nx-X11/lib/X11/PolyReg.c index 6ac2e2897..f56a872ca 100644 --- a/nx-X11/lib/X11/PolyReg.c +++ b/nx-X11/lib/X11/PolyReg.c @@ -95,8 +95,7 @@ InsertEdgeInET( { if (*iSLLBlock > SLLSPERBLOCK-1) { - tmpSLLBlock = - (ScanLineListBlock *)Xmalloc(sizeof(ScanLineListBlock)); + tmpSLLBlock = Xmalloc(sizeof(ScanLineListBlock)); (*SLLBlock)->next = tmpSLLBlock; tmpSLLBlock->next = (ScanLineListBlock *)NULL; *SLLBlock = tmpSLLBlock; @@ -410,8 +409,7 @@ static int PtsToRegion( numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1; - if (!(reg->rects = (BOX *)Xrealloc((char *)reg->rects, - (unsigned) (sizeof(BOX) * numRects)))) { + if (!(reg->rects = Xrealloc(reg->rects, sizeof(BOX) * numRects))) { Xfree(prevRects); return(0); } @@ -521,8 +519,7 @@ XPolygonRegion( if (Count < 2) return region; - if (! (pETEs = (EdgeTableEntry *) - Xmalloc((unsigned) (sizeof(EdgeTableEntry) * Count)))) { + if (! (pETEs = Xmalloc(sizeof(EdgeTableEntry) * Count))) { XDestroyRegion(region); return (Region) NULL; } @@ -559,7 +556,7 @@ XPolygonRegion( * send out the buffer */ if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)Xmalloc(sizeof(POINTBLOCK)); + tmpPtBlock = Xmalloc(sizeof(POINTBLOCK)); curPtBlock->next = tmpPtBlock; curPtBlock = tmpPtBlock; pts = curPtBlock->pts; @@ -605,7 +602,7 @@ XPolygonRegion( * send out the buffer */ if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)Xmalloc(sizeof(POINTBLOCK)); + tmpPtBlock = Xmalloc(sizeof(POINTBLOCK)); curPtBlock->next = tmpPtBlock; curPtBlock = tmpPtBlock; pts = curPtBlock->pts; diff --git a/nx-X11/lib/X11/PropAlloc.c b/nx-X11/lib/X11/PropAlloc.c index 516283080..87817d88a 100644 --- a/nx-X11/lib/X11/PropAlloc.c +++ b/nx-X11/lib/X11/PropAlloc.c @@ -39,20 +39,19 @@ in this Software without prior written authorization from The Open Group. XSizeHints *XAllocSizeHints (void) { - return ((XSizeHints *) Xcalloc (1, (unsigned) sizeof (XSizeHints))); + return Xcalloc (1, sizeof (XSizeHints)); } XStandardColormap *XAllocStandardColormap (void) { - return ((XStandardColormap *) - Xcalloc (1, (unsigned) sizeof (XStandardColormap))); + return Xcalloc (1, sizeof (XStandardColormap)); } XWMHints *XAllocWMHints (void) { - return ((XWMHints *) Xcalloc (1, (unsigned) sizeof (XWMHints))); + return Xcalloc (1, sizeof (XWMHints)); } @@ -64,7 +63,7 @@ XClassHint *XAllocClassHint (void) XIconSize *XAllocIconSize (void) { - return ((XIconSize *) Xcalloc (1, (unsigned) sizeof (XIconSize))); + return Xcalloc (1, sizeof (XIconSize)); } diff --git a/nx-X11/lib/X11/PutBEvent.c b/nx-X11/lib/X11/PutBEvent.c index f9d4c29bd..1768e032c 100644 --- a/nx-X11/lib/X11/PutBEvent.c +++ b/nx-X11/lib/X11/PutBEvent.c @@ -41,7 +41,7 @@ _XPutBackEvent ( XEvent store = *event; if (!dpy->qfree) { - if ((dpy->qfree = (_XQEvent *) Xmalloc (sizeof (_XQEvent))) == NULL) { + if ((dpy->qfree = Xmalloc (sizeof (_XQEvent))) == NULL) { return 0; } dpy->qfree->next = NULL; diff --git a/nx-X11/lib/X11/PutImage.c b/nx-X11/lib/X11/PutImage.c index 6dad4f13a..2a694f099 100644 --- a/nx-X11/lib/X11/PutImage.c +++ b/nx-X11/lib/X11/PutImage.c @@ -680,7 +680,7 @@ SendXYImage( length = ROUNDUP(length, 4); if ((dpy->bufptr + length) > dpy->bufmax) { - if ((buf = _XAllocScratch(dpy, (unsigned long) (length))) == NULL) { + if ((buf = _XAllocScratch(dpy, length)) == NULL) { UnGetReq(PutImage); return; } @@ -703,13 +703,13 @@ SendXYImage( bytes_per_temp_plane = bytes_per_line * req->height; temp_length = ROUNDUP(bytes_per_temp_plane * image->depth, 4); if (buf == dpy->bufptr) { - if (! (temp = _XAllocScratch(dpy, (unsigned long) temp_length))) { + if (! (temp = _XAllocScratch(dpy, temp_length))) { UnGetReq(PutImage); return; } } else - if ((extra = temp = Xmalloc((unsigned) temp_length)) == NULL) { + if ((extra = temp = Xmalloc(temp_length)) == NULL) { UnGetReq(PutImage); return; } @@ -778,8 +778,7 @@ SendZImage( (req_yoffset * image->bytes_per_line) + ((req_xoffset * image->bits_per_pixel) >> 3); if ((image->bits_per_pixel == 4) && ((unsigned int) req_xoffset & 0x01)) { - if (! (shifted_src = (unsigned char *) - Xmalloc((unsigned) (req->height * image->bytes_per_line)))) { + if (! (shifted_src = Xmalloc(req->height * image->bytes_per_line))) { UnGetReq(PutImage); return; } @@ -810,7 +809,7 @@ SendZImage( dest = (unsigned char *)dpy->bufptr; else if ((dest = (unsigned char *) - _XAllocScratch(dpy, (unsigned long)(length))) == NULL) { + _XAllocScratch(dpy, length)) == NULL) { if (shifted_src) Xfree((char *) shifted_src); UnGetReq(PutImage); return; @@ -1001,7 +1000,7 @@ XPutImage ( img.bits_per_pixel = dest_bits_per_pixel; img.bytes_per_line = ROUNDUP((dest_bits_per_pixel * width), dest_scanline_pad) >> 3; - img.data = Xmalloc((unsigned) (img.bytes_per_line * height)); + img.data = Xmalloc(img.bytes_per_line * height); if (img.data == NULL) return 0; _XInitImageFuncPtrs(&img); diff --git a/nx-X11/lib/X11/Quarks.c b/nx-X11/lib/X11/Quarks.c index 1bba6da4d..c3e9906f7 100644 --- a/nx-X11/lib/X11/Quarks.c +++ b/nx-X11/lib/X11/Quarks.c @@ -186,15 +186,14 @@ ExpandQuarkTable(void) newmask = (oldmask << 1) + 1; else { if (!stringTable) { - stringTable = (XrmString **)Xmalloc(sizeof(XrmString *) * - CHUNKPER); + stringTable = Xmalloc(sizeof(XrmString *) * CHUNKPER); if (!stringTable) return False; stringTable[0] = (XrmString *)NULL; } #ifdef PERMQ if (!permTable) - permTable = (Bits **)Xmalloc(sizeof(Bits *) * CHUNKPER); + permTable = Xmalloc(sizeof(Bits *) * CHUNKPER); if (!permTable) return False; #endif @@ -289,13 +288,13 @@ nomatch: if (!rehash) q = nextQuark; if (!(q & QUANTUMMASK)) { if (!(q & CHUNKMASK)) { - if (!(new = Xrealloc((char *)stringTable, + if (!(new = Xrealloc(stringTable, sizeof(XrmString *) * ((q >> QUANTUMSHIFT) + CHUNKPER)))) goto fail; stringTable = (XrmString **)new; #ifdef PERMQ - if (!(new = Xrealloc((char *)permTable, + if (!(new = Xrealloc(permTable, sizeof(Bits *) * ((q >> QUANTUMSHIFT) + CHUNKPER)))) goto fail; diff --git a/nx-X11/lib/X11/RdBitF.c b/nx-X11/lib/X11/RdBitF.c index 2ec100aa3..cc3623394 100644 --- a/nx-X11/lib/X11/RdBitF.c +++ b/nx-X11/lib/X11/RdBitF.c @@ -191,7 +191,7 @@ XReadBitmapFileData ( bytes_per_line = (ww+7)/8 + padding; size = bytes_per_line * hh; - bits = (unsigned char *) Xmalloc ((unsigned int) size); + bits = Xmalloc (size); if (!bits) RETURN (BitmapNoMemory); diff --git a/nx-X11/lib/X11/Region.c b/nx-X11/lib/X11/Region.c index 5491dbd0e..998639c25 100644 --- a/nx-X11/lib/X11/Region.c +++ b/nx-X11/lib/X11/Region.c @@ -139,9 +139,9 @@ XCreateRegion(void) { Region temp; - if (! (temp = ( Region )Xmalloc( (unsigned) sizeof( REGION )))) + if (! (temp = Xmalloc(sizeof( REGION )))) return (Region) NULL; - if (! (temp->rects = ( BOX * )Xmalloc( (unsigned) sizeof( BOX )))) { + if (! (temp->rects = Xmalloc(sizeof( BOX )))) { Xfree((char *) temp); return (Region) NULL; } @@ -521,9 +521,9 @@ miRegionCopy( { BOX *prevRects = dstrgn->rects; - if (! (dstrgn->rects = (BOX *) - Xrealloc((char *) dstrgn->rects, - (unsigned) rgn->numRects * (sizeof(BOX))))) { + dstrgn->rects = Xrealloc(dstrgn->rects, + rgn->numRects * (sizeof(BOX))); + if (! dstrgn->rects) { Xfree(prevRects); return; } @@ -788,8 +788,7 @@ miRegionOp( */ newReg->size = max(reg1->numRects,reg2->numRects) * 2; - if (! (newReg->rects = (BoxPtr) - Xmalloc ((unsigned) (sizeof(BoxRec) * newReg->size)))) { + if (! (newReg->rects = Xmalloc (sizeof(BoxRec) * newReg->size))) { newReg->size = 0; return; } @@ -980,8 +979,8 @@ miRegionOp( { BoxPtr prev_rects = newReg->rects; newReg->size = newReg->numRects; - newReg->rects = (BoxPtr) Xrealloc ((char *) newReg->rects, - (unsigned) (sizeof(BoxRec) * newReg->size)); + newReg->rects = Xrealloc (newReg->rects, + sizeof(BoxRec) * newReg->size); if (! newReg->rects) newReg->rects = prev_rects; } @@ -993,7 +992,7 @@ miRegionOp( */ newReg->size = 1; Xfree((char *) newReg->rects); - newReg->rects = (BoxPtr) Xmalloc(sizeof(BoxRec)); + newReg->rects = Xmalloc(sizeof(BoxRec)); } } Xfree ((char *) oldRects); diff --git a/nx-X11/lib/X11/RegstFlt.c b/nx-X11/lib/X11/RegstFlt.c index 1dba7e4a0..cbc93ba43 100644 --- a/nx-X11/lib/X11/RegstFlt.c +++ b/nx-X11/lib/X11/RegstFlt.c @@ -85,7 +85,7 @@ _XRegisterFilterByMask( { XFilterEventRec *rec; - rec = (XFilterEventList)Xmalloc(sizeof(XFilterEventRec)); + rec = Xmalloc(sizeof(XFilterEventRec)); if (!rec) return; rec->window = window; @@ -117,7 +117,7 @@ _XRegisterFilterByType( { XFilterEventRec *rec; - rec = (XFilterEventList)Xmalloc(sizeof(XFilterEventRec)); + rec = Xmalloc(sizeof(XFilterEventRec)); if (!rec) return; rec->window = window; diff --git a/nx-X11/lib/X11/SetFPath.c b/nx-X11/lib/X11/SetFPath.c index 89955c23e..b1afd8201 100644 --- a/nx-X11/lib/X11/SetFPath.c +++ b/nx-X11/lib/X11/SetFPath.c @@ -52,7 +52,7 @@ XSetFontPath ( } nbytes = (n + 3) & ~3; req->length += nbytes >> 2; - if ((p = (char *) Xmalloc ((unsigned) nbytes))) { + if ((p = Xmalloc (nbytes))) { /* * pack into counted strings. */ diff --git a/nx-X11/lib/X11/SetHints.c b/nx-X11/lib/X11/SetHints.c index 102619622..8e8413069 100644 --- a/nx-X11/lib/X11/SetHints.c +++ b/nx-X11/lib/X11/SetHints.c @@ -184,7 +184,7 @@ XSetIconSizes ( #define size_of_the_real_thing sizeof /* avoid grepping screwups */ unsigned nbytes = count * size_of_the_real_thing(xPropIconSize); #undef size_of_the_real_thing - if ((prop = pp = (xPropIconSize *) Xmalloc (nbytes))) { + if ((prop = pp = Xmalloc (nbytes))) { for (i = 0; i < count; i++) { pp->minWidth = list->min_width; pp->minHeight = list->min_height; @@ -216,7 +216,7 @@ XSetCommand ( for (i = 0, nbytes = 0; i < argc; i++) { nbytes += safestrlen(argv[i]) + 1; } - if ((bp = buf = Xmalloc((unsigned) nbytes))) { + if ((bp = buf = Xmalloc(nbytes))) { /* copy arguments into single buffer */ for (i = 0; i < argc; i++) { if (argv[i]) { @@ -299,7 +299,7 @@ XSetClassHint( len_nm = safestrlen(classhint->res_name); len_cl = safestrlen(classhint->res_class); - if ((class_string = s = Xmalloc((unsigned) (len_nm + len_cl + 2)))) { + if ((class_string = s = Xmalloc(len_nm + len_cl + 2))) { if (len_nm) { strcpy(s, classhint->res_name); s += len_nm + 1; diff --git a/nx-X11/lib/X11/StrToText.c b/nx-X11/lib/X11/StrToText.c index 64ed5fd24..ff33492f2 100644 --- a/nx-X11/lib/X11/StrToText.c +++ b/nx-X11/lib/X11/StrToText.c @@ -78,7 +78,7 @@ Status XStringListToTextProperty ( } } } else { - proto.value = (unsigned char *) Xmalloc (1); /* easier for client */ + proto.value = Xmalloc (1); /* easier for client */ if (!proto.value) return False; proto.value[0] = '\0'; diff --git a/nx-X11/lib/X11/TextToStr.c b/nx-X11/lib/X11/TextToStr.c index e75b7fcea..9252b62a8 100644 --- a/nx-X11/lib/X11/TextToStr.c +++ b/nx-X11/lib/X11/TextToStr.c @@ -72,10 +72,10 @@ Status XTextPropertyToStringList ( /* * allocate list and duplicate */ - list = (char **) Xmalloc (nelements * sizeof (char *)); + list = Xmalloc (nelements * sizeof (char *)); if (!list) return False; - start = (char *) Xmalloc ((datalen + 1) * sizeof (char)); /* for */ + start = Xmalloc ((datalen + 1) * sizeof (char)); /* for */ if (!start) { Xfree ((char *) list); return False; diff --git a/nx-X11/lib/X11/VisUtil.c b/nx-X11/lib/X11/VisUtil.c index 3434c0161..aa679928a 100644 --- a/nx-X11/lib/X11/VisUtil.c +++ b/nx-X11/lib/X11/VisUtil.c @@ -75,8 +75,7 @@ XVisualInfo *XGetVisualInfo( count = 0; total = 10; - if (! (vip_base = vip = (XVisualInfo *) - Xmalloc((unsigned) (sizeof(XVisualInfo) * total)))) { + if (! (vip_base = vip = Xmalloc(sizeof(XVisualInfo) * total))) { UnlockDisplay(dpy); return (XVisualInfo *) NULL; } @@ -132,9 +131,8 @@ XVisualInfo *XGetVisualInfo( { XVisualInfo *old_vip_base = vip_base; total += 10; - if (! (vip_base = (XVisualInfo *) - Xrealloc((char *) vip_base, - (unsigned) (sizeof(XVisualInfo) * total)))) { + if (! (vip_base = Xrealloc(vip_base, + sizeof(XVisualInfo) * total))) { Xfree((char *) old_vip_base); UnlockDisplay(dpy); return (XVisualInfo *) NULL; diff --git a/nx-X11/lib/X11/WrBitF.c b/nx-X11/lib/X11/WrBitF.c index c9ed6b47e..0b27d5adf 100644 --- a/nx-X11/lib/X11/WrBitF.c +++ b/nx-X11/lib/X11/WrBitF.c @@ -53,7 +53,7 @@ static char *Format_Image( bytes_per_line = (width+7)/8; *resultsize = bytes_per_line * height; /* Calculate size of data */ - data = (char *) Xmalloc( *resultsize ); /* Get space for data */ + data = Xmalloc( *resultsize ); /* Get space for data */ if (!data) return(ERR_RETURN); diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 1ecbaaa4f..4c4e80e6a 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -608,7 +608,7 @@ Bool _XPollfdCacheInit( #ifdef USE_POLL struct pollfd *pfp; - pfp = (struct pollfd *)Xmalloc(POLLFD_CACHE_SIZE * sizeof(struct pollfd)); + pfp = Xmalloc(POLLFD_CACHE_SIZE * sizeof(struct pollfd)); if (!pfp) return False; pfp[0].fd = dpy->fd; @@ -2477,10 +2477,10 @@ _XRegisterInternalConnection( #if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) fprintf(stderr, "_XRegisterInternalConnection: Got called.\n"); #endif - new_conni = (struct _XConnectionInfo*)Xmalloc(sizeof(struct _XConnectionInfo)); + new_conni = Xmalloc(sizeof(struct _XConnectionInfo)); if (!new_conni) return 0; - new_conni->watch_data = (XPointer *)Xmalloc(dpy->watcher_count * sizeof(XPointer)); + new_conni->watch_data = Xmalloc(dpy->watcher_count * sizeof(XPointer)); if (!new_conni->watch_data) { Xfree(new_conni); return 0; @@ -2573,7 +2573,7 @@ XInternalConnectionNumbers( count = 0; for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next) count++; - fd_list = (int*) Xmalloc (count * sizeof(int)); + fd_list = Xmalloc (count * sizeof(int)); if (!fd_list) { UnlockDisplay(dpy); return 0; @@ -2666,9 +2666,8 @@ XAddConnectionWatch( /* allocate new watch data */ for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next) { - wd_array = (XPointer *)Xrealloc((char *)info_list->watch_data, - (dpy->watcher_count + 1) * - sizeof(XPointer)); + wd_array = Xrealloc(info_list->watch_data, + (dpy->watcher_count + 1) * sizeof(XPointer)); if (!wd_array) { UnlockDisplay(dpy); return 0; @@ -2677,7 +2676,7 @@ XAddConnectionWatch( wd_array[dpy->watcher_count] = NULL; /* for cleanliness */ } - new_watcher = (struct _XConnWatchInfo*)Xmalloc(sizeof(struct _XConnWatchInfo)); + new_watcher = Xmalloc(sizeof(struct _XConnWatchInfo)); if (!new_watcher) { UnlockDisplay(dpy); return 0; @@ -2936,8 +2935,7 @@ void _XEnq( /* If dpy->qfree is non-NULL do this, else malloc a new one. */ dpy->qfree = qelt->next; } - else if ((qelt = - (_XQEvent *) Xmalloc((unsigned)sizeof(_XQEvent))) == NULL) { + else if ((qelt = Xmalloc(sizeof(_XQEvent))) == NULL) { /* Malloc call failed! */ ESET(ENOMEM); #ifdef NX_TRANS_SOCKET @@ -3766,8 +3764,8 @@ char *_XAllocScratch( { if (nbytes > dpy->scratch_length) { if (dpy->scratch_buffer) Xfree (dpy->scratch_buffer); - if ((dpy->scratch_buffer = Xmalloc((unsigned) nbytes))) - dpy->scratch_length = nbytes; + if ((dpy->scratch_buffer = Xmalloc(nbytes))) + dpy->scratch_length = nbytes; else dpy->scratch_length = 0; } return (dpy->scratch_buffer); diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 2a3f4889b..e498e4e5a 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -494,7 +494,7 @@ static XrmDatabase NewDatabase(void) { register XrmDatabase db; - db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec)); + db = Xmalloc(sizeof(XrmHashBucketRec)); if (db) { _XCreateMutex(&db->linfo); db->table = (NTable)NULL; @@ -827,7 +827,7 @@ static void PutEntry( NTable *nprev, *firstpprev; #define NEWTABLE(q,i) \ - table = (NTable)Xmalloc(sizeof(LTableRec)); \ + table = Xmalloc(sizeof(LTableRec)); \ if (!table) \ return; \ table->name = q; \ @@ -840,7 +840,7 @@ static void PutEntry( nprev = NodeBuckets(table); \ } else { \ table->leaf = 1; \ - if (!(nprev = (NTable *)Xmalloc(sizeof(VEntry *)))) {\ + if (!(nprev = Xmalloc(sizeof(VEntry *)))) {\ Xfree(table); \ return; \ } \ @@ -954,9 +954,8 @@ static void PutEntry( prev = nprev; } /* now allocate the value entry */ - entry = (VEntry)Xmalloc(((type == XrmQString) ? - sizeof(VEntryRec) : sizeof(DEntryRec)) + - value->size); + entry = Xmalloc(((type == XrmQString) ? + sizeof(VEntryRec) : sizeof(DEntryRec)) + value->size); if (!entry) return; entry->name = q = *quarks; @@ -986,13 +985,12 @@ static void PutEntry( if (resourceQuarks) { unsigned char *prevQuarks = resourceQuarks; - resourceQuarks = (unsigned char *)Xrealloc((char *)resourceQuarks, - size); + resourceQuarks = Xrealloc(resourceQuarks, size); if (!resourceQuarks) { Xfree(prevQuarks); } } else - resourceQuarks = (unsigned char *)Xmalloc(size); + resourceQuarks = Xmalloc(size); if (resourceQuarks) { bzero((char *)&resourceQuarks[oldsize], size - oldsize); maxResourceQuark = (size << 3) - 1; @@ -1137,11 +1135,11 @@ static void GetDatabase( str_len = strlen (str); if (DEF_BUFF_SIZE > str_len) lhs = lhs_s; - else if ((lhs = (char*) Xmalloc (str_len)) == NULL) + else if ((lhs = Xmalloc (str_len)) == NULL) return; alloc_chars = DEF_BUFF_SIZE < str_len ? str_len : DEF_BUFF_SIZE; - if ((rhs = (char*) Xmalloc (alloc_chars)) == NULL) { + if ((rhs = Xmalloc (alloc_chars)) == NULL) { if (lhs != lhs_s) Xfree (lhs); return; } diff --git a/nx-X11/lib/X11/locking.c b/nx-X11/lib/X11/locking.c index b3dfb3b01..7c09c44d2 100644 --- a/nx-X11/lib/X11/locking.c +++ b/nx-X11/lib/X11/locking.c @@ -82,7 +82,7 @@ _Xthread_waiter(void) struct _xthread_waiter *me; if (!(me = TlsGetValue(_X_TlsIndex))) { - me = (struct _xthread_waiter *)xmalloc(sizeof(struct _xthread_waiter)); + me = xmalloc(sizeof(struct _xthread_waiter)); me->sem = CreateSemaphore(NULL, 0, 1, NULL); me->next = NULL; TlsSetValue(_X_TlsIndex, me); @@ -249,7 +249,7 @@ static struct _XCVList *_XCreateCVL( dpy->lock->free_cvls = cvl->next; dpy->lock->num_free_cvls--; } else { - cvl = (struct _XCVList *)Xmalloc(sizeof(struct _XCVList)); + cvl = Xmalloc(sizeof(struct _XCVList)); if (!cvl) return NULL; cvl->cv = xcondition_malloc(); @@ -512,10 +512,10 @@ void _XUserUnlockDisplay( static int _XInitDisplayLock( Display *dpy) { - dpy->lock_fns = (struct _XLockPtrs*)Xmalloc(sizeof(struct _XLockPtrs)); + dpy->lock_fns = Xmalloc(sizeof(struct _XLockPtrs)); if (dpy->lock_fns == NULL) return -1; - dpy->lock = (struct _XLockInfo *)Xmalloc(sizeof(struct _XLockInfo)); + dpy->lock = Xmalloc(sizeof(struct _XLockInfo)); if (dpy->lock == NULL) { _XFreeDisplayLock(dpy); return -1; diff --git a/nx-X11/lib/X11/udcInf.c b/nx-X11/lib/X11/udcInf.c index eeb847657..9acf0fb3f 100644 --- a/nx-X11/lib/X11/udcInf.c +++ b/nx-X11/lib/X11/udcInf.c @@ -145,12 +145,11 @@ int *num_codeset; if(!_XlcCompareISOLatin1(charset_str,buf)){ num_ret += 1; if(num_ret == 1){ - ret = (int *)Xmalloc(sizeof(int)); + ret = Xmalloc(sizeof(int)); } else { int *prev_ret = ret; - ret = - (int *)Xrealloc(ret,num_ret*sizeof(int)); + ret = Xrealloc(ret, num_ret * sizeof(int)); if (ret == NULL){ Xfree(prev_ret); } @@ -272,7 +271,7 @@ int *num_gr; sprintf(buf, "fs%d.charset.udc_area", codeset-1); _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); if(count > 0){ - udc = (_XUDCGlyphRegion *)Xmalloc(count * sizeof(_XUDCGlyphRegion)); + udc = Xmalloc(count * sizeof(_XUDCGlyphRegion)); if(udc == NULL){ _xudc_utyerrno = 0x03 ; _xudc_utyerrno |= (0x0b<<8) ; @@ -524,7 +523,7 @@ int *num_cr; return(ret); } - crr = (_XUDCCodeRegion *)Xmalloc(num_gr*sizeof(_XUDCCodeRegion)); + crr = Xmalloc(num_gr * sizeof(_XUDCCodeRegion)); if(crr == NULL){ Xfree(gr); _xudc_utyerrno = 0x03 ; -- cgit v1.2.3 From 082e831303bb8c8c63ce40d79bee10855112c014 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 6 Oct 2016 23:34:06 +0200 Subject: Revert "Add a couple fixups for the security patches" This reverts commit b092864a39bbcd4f34c5c26a7cd0df90e235815d. We will use the proper libX11 upstream patches now. --- nx-X11/lib/X11/Font.c | 1 - nx-X11/lib/X11/XKBGetMap.c | 2 +- nx-X11/lib/X11/XKBNames.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index cc08fda27..c0efb3f45 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -508,7 +508,6 @@ _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(fs->properties); Xfree((char *) fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; diff --git a/nx-X11/lib/X11/XKBGetMap.c b/nx-X11/lib/X11/XKBGetMap.c index 391d7aa89..5eb1d41bf 100644 --- a/nx-X11/lib/X11/XKBGetMap.c +++ b/nx-X11/lib/X11/XKBGetMap.c @@ -427,7 +427,7 @@ XkbServerMapPtr srv; if ( rep->totalVModMapKeys>0 ) { if (((int) rep->firstVModMapKey + rep->nVModMapKeys) - > xkb->max_key_code + 1) + > xkb->max_key_code) return BadLength; if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&& (XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) { diff --git a/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index c82b59e30..1f5207493 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/XKBNames.c @@ -180,7 +180,7 @@ _XkbReadGetNamesReply( Display * dpy, nKeys= xkb->max_key_code+1; names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec); } - else if ( ((int)rep->firstKey + rep->nKeys) > xkb->max_key_code + 1) + else if ( ((int)rep->firstKey + rep->nKeys) > xkb->max_key_code) goto BAILOUT; if (names->keys!=NULL) { if (!_XkbCopyFromReadBuffer(&buf, -- cgit v1.2.3 From 78ed233308babdeb428d9292f7e40e438e9b2efd Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 23 May 2013 20:39:46 +0200 Subject: xkb: fix off-by-one in _XkbReadGetNamesReply and _XkbReadVirtualModMap The size of the arrays is max_key_code + 1. This makes these functions consistent with the other checks added for CVE-2013-1997. Also check the XkbGetNames reply when names->keys was just allocated. Signed-off-by: Julien Cristau Tested-by: Colin Walters Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGetMap.c | 2 +- nx-X11/lib/X11/XKBNames.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGetMap.c b/nx-X11/lib/X11/XKBGetMap.c index 5eb1d41bf..391d7aa89 100644 --- a/nx-X11/lib/X11/XKBGetMap.c +++ b/nx-X11/lib/X11/XKBGetMap.c @@ -427,7 +427,7 @@ XkbServerMapPtr srv; if ( rep->totalVModMapKeys>0 ) { if (((int) rep->firstVModMapKey + rep->nVModMapKeys) - > xkb->max_key_code) + > xkb->max_key_code + 1) return BadLength; if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&& (XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) { diff --git a/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index 1f5207493..dc5ef90d7 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/XKBNames.c @@ -180,7 +180,7 @@ _XkbReadGetNamesReply( Display * dpy, nKeys= xkb->max_key_code+1; names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec); } - else if ( ((int)rep->firstKey + rep->nKeys) > xkb->max_key_code) + if ( ((int)rep->firstKey + rep->nKeys) > xkb->max_key_code + 1) goto BAILOUT; if (names->keys!=NULL) { if (!_XkbCopyFromReadBuffer(&buf, -- cgit v1.2.3 From 71fb99cb433d657bd9f4898a93a6ba4733c7093e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 16 May 2013 23:05:36 -0700 Subject: Free fs->properties in XF86BigfontQueryFont overflow error path Fixes small memory leak introduced in commit 5669a22081 Reported-by: Julien Cristau Signed-off-by: Alan Coopersmith Hint: Upstream commit 5669a22081 is "integer overflow in _XF86BigfontQueryFont() [CVE-2013-1981 2/13]" Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Font.c | 1 + 1 file changed, 1 insertion(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index c0efb3f45..7943ba7a1 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -508,6 +508,7 @@ _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); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; -- cgit v1.2.3 From 26f7239a0111a0915ba121c292ced276e3942900 Mon Sep 17 00:00:00 2001 From: Niveditha Rau Date: Fri, 17 May 2013 15:26:21 -0700 Subject: Make sure internal headers include required headers Fixes builds with Solaris Studio 12.3 when lint is enabled, since it no longer ignores *.h files, but complains when they reference undefined typedefs or macros. Signed-off-by: Niveditha Rau Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Cmap.h | 2 ++ nx-X11/lib/X11/Cr.h | 2 ++ nx-X11/lib/X11/Key.h | 3 +++ nx-X11/lib/X11/Xintatom.h | 1 + nx-X11/lib/X11/Xintconn.h | 1 + nx-X11/lib/X11/Xprivate.h | 2 ++ nx-X11/lib/X11/Xresinternal.h | 2 ++ nx-X11/lib/X11/locking.h | 2 ++ 8 files changed, 15 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Cmap.h b/nx-X11/lib/X11/Cmap.h index 062b5383b..db2de5697 100644 --- a/nx-X11/lib/X11/Cmap.h +++ b/nx-X11/lib/X11/Cmap.h @@ -2,6 +2,8 @@ #ifndef _CMAP_H_ #define _CMAP_H_ +#include + extern void _XcmsDeleteCmapRec( Display *dpy, diff --git a/nx-X11/lib/X11/Cr.h b/nx-X11/lib/X11/Cr.h index 800c9ab1c..e71d86d1c 100644 --- a/nx-X11/lib/X11/Cr.h +++ b/nx-X11/lib/X11/Cr.h @@ -2,6 +2,8 @@ #ifndef _CR_H_ #define _CR_H_ +#include + extern int _XUpdateGCCache( register GC gc, register unsigned long mask, diff --git a/nx-X11/lib/X11/Key.h b/nx-X11/lib/X11/Key.h index 0fe89ba37..3a1639c5c 100644 --- a/nx-X11/lib/X11/Key.h +++ b/nx-X11/lib/X11/Key.h @@ -2,6 +2,9 @@ #ifndef _KEY_H_ #define _KEY_H_ +#include +#include + #ifndef NEEDKTABLE extern const unsigned char _XkeyTable[]; #endif diff --git a/nx-X11/lib/X11/Xintatom.h b/nx-X11/lib/X11/Xintatom.h index f4057798d..b2d307bab 100644 --- a/nx-X11/lib/X11/Xintatom.h +++ b/nx-X11/lib/X11/Xintatom.h @@ -2,6 +2,7 @@ #ifndef _XINTATOM_H_ #define _XINTATOM_H_ 1 +#include #include /* IntAtom.c */ diff --git a/nx-X11/lib/X11/Xintconn.h b/nx-X11/lib/X11/Xintconn.h index 54200ed9f..675f684ac 100644 --- a/nx-X11/lib/X11/Xintconn.h +++ b/nx-X11/lib/X11/Xintconn.h @@ -3,6 +3,7 @@ #define _XINTCONN_H_ 1 #include +#include _XFUNCPROTOBEGIN diff --git a/nx-X11/lib/X11/Xprivate.h b/nx-X11/lib/X11/Xprivate.h index ebe51c1ed..bc8dbf4d9 100644 --- a/nx-X11/lib/X11/Xprivate.h +++ b/nx-X11/lib/X11/Xprivate.h @@ -8,6 +8,8 @@ #ifndef XPRIVATE_H #define XPRIVATE_H +#include + extern void _XIDHandler(Display *dpy); extern void _XSeqSyncFunction(Display *dpy); extern void _XSetPrivSyncFunction(Display *dpy); diff --git a/nx-X11/lib/X11/Xresinternal.h b/nx-X11/lib/X11/Xresinternal.h index c2f355fe6..c740102b6 100644 --- a/nx-X11/lib/X11/Xresinternal.h +++ b/nx-X11/lib/X11/Xresinternal.h @@ -2,6 +2,8 @@ #ifndef _XRESINTERNAL_H_ #define _XRESINTERNAL_H_ +#include +#include #include /* type defines */ diff --git a/nx-X11/lib/X11/locking.h b/nx-X11/lib/X11/locking.h index 7126e61d8..0942b95aa 100644 --- a/nx-X11/lib/X11/locking.h +++ b/nx-X11/lib/X11/locking.h @@ -36,6 +36,8 @@ in this Software without prior written authorization from The Open Group. #define xmalloc(s) Xmalloc(s) #define xfree(s) Xfree(s) +#include +#include #include struct _XCVList { -- cgit v1.2.3 From e03d8c215ea51164b4c53a821e0a77660b60ffbd Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Sun, 2 Jun 2013 11:49:54 -0700 Subject: cmsMath.c: Add missing stdio header for printf(3) in DEBUG build. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/cmsMath.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/cmsMath.c b/nx-X11/lib/X11/cmsMath.c index 70b067587..487eb3f9c 100644 --- a/nx-X11/lib/X11/cmsMath.c +++ b/nx-X11/lib/X11/cmsMath.c @@ -35,6 +35,10 @@ in this Software without prior written authorization from The Open Group. #include "Xlibint.h" #include "Xcmsint.h" +#ifdef DEBUG +#include +#endif + #include #ifndef DBL_EPSILON #define DBL_EPSILON 1e-6 -- cgit v1.2.3 From 1078f97706b77ab93fb30204acf270cfb652c900 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 7 Oct 2016 21:00:20 +0200 Subject: rename xf86bigfstr.h to xf86bigfproto.h --- nx-X11/lib/X11/Font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index 7943ba7a1..298d96c63 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -45,7 +45,7 @@ authorization from the X Consortium and the XFree86 Project. #include #include -#include +#include #endif #include "Xlcint.h" -- cgit v1.2.3 From 5dbcf198726838267dadd98f447973a8fb2d6505 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 7 Oct 2016 21:16:39 +0200 Subject: Assume size_t is always available, since it was defined in C89 We have the same commit for XKBGAlloc.c but it was missing here since upstream has dropped OpenDis.c when they switched to XCB. Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/OpenDis.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/OpenDis.c b/nx-X11/lib/X11/OpenDis.c index bb87a2285..89f1edab3 100644 --- a/nx-X11/lib/X11/OpenDis.c +++ b/nx-X11/lib/X11/OpenDis.c @@ -73,12 +73,6 @@ extern void *_X11TransSocketProxyConnInfo(XtransConnInfo); #endif #if !USE_XCB -#ifdef X_NOT_POSIX -#define Size_t unsigned int -#else -#define Size_t size_t -#endif - #define bignamelen (sizeof(XBigReqExtensionName) - 1) typedef struct { @@ -457,8 +451,8 @@ fallback_success: if (prefix.lengthReason > setuplength) { fprintf (stderr, "Xlib: Broken initial reply: length of reason > length of packet\r\n"); }else{ - (void) fwrite (u.failure, (Size_t)sizeof(char), - (Size_t)prefix.lengthReason, stderr); + (void) fwrite (u.failure, (size_t)sizeof(char), + (size_t)prefix.lengthReason, stderr); (void) fwrite ("\r\n", sizeof(char), 2, stderr); } -- cgit v1.2.3 From bd43a06402b7499a74de0d4fb5ef8330b490b38f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 3 Sep 2010 23:11:53 -0700 Subject: Sun's copyrights are now owned by Oracle Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Host.c | 2 +- nx-X11/lib/X11/LiHosts.c | 2 +- nx-X11/lib/X11/XDefaultIMIF.c | 2 +- nx-X11/lib/X11/XDefaultOMIF.c | 2 +- nx-X11/lib/X11/XimTrInt.h | 2 +- nx-X11/lib/X11/XimTrX.h | 2 +- nx-X11/lib/X11/XimTrans.h | 2 +- nx-X11/lib/X11/XimintP.h | 2 +- nx-X11/lib/X11/XlcDL.c | 2 +- nx-X11/lib/X11/XlcSL.c | 2 +- nx-X11/lib/X11/imDefIc.c | 2 +- nx-X11/lib/X11/imDefIm.c | 2 +- nx-X11/lib/X11/imTrX.c | 2 +- nx-X11/lib/X11/imTrans.c | 2 +- nx-X11/lib/X11/imTransR.c | 2 +- nx-X11/lib/X11/lcInit.c | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Host.c b/nx-X11/lib/X11/Host.c index bfa87507d..b07c9c312 100644 --- a/nx-X11/lib/X11/Host.c +++ b/nx-X11/lib/X11/Host.c @@ -34,7 +34,7 @@ X Window System is a trademark of The Open Group. */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2004 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/LiHosts.c b/nx-X11/lib/X11/LiHosts.c index 6ec956e72..202deee02 100644 --- a/nx-X11/lib/X11/LiHosts.c +++ b/nx-X11/lib/X11/LiHosts.c @@ -34,7 +34,7 @@ X Window System is a trademark of The Open Group. */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2004 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XDefaultIMIF.c b/nx-X11/lib/X11/XDefaultIMIF.c index 135c5a259..e97d2f444 100644 --- a/nx-X11/lib/X11/XDefaultIMIF.c +++ b/nx-X11/lib/X11/XDefaultIMIF.c @@ -37,7 +37,7 @@ Sun Microsystems, Inc. or its licensors is granted. */ /* - * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 26c6c3a98..9e6feb76b 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -37,7 +37,7 @@ Sun Microsystems, Inc. or its licensors is granted. */ /* - * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XimTrInt.h b/nx-X11/lib/X11/XimTrInt.h index 541df2eb9..bceab9886 100644 --- a/nx-X11/lib/X11/XimTrInt.h +++ b/nx-X11/lib/X11/XimTrInt.h @@ -1,5 +1,5 @@ /* - * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XimTrX.h b/nx-X11/lib/X11/XimTrX.h index 1c24fe368..198d5fa5f 100644 --- a/nx-X11/lib/X11/XimTrX.h +++ b/nx-X11/lib/X11/XimTrX.h @@ -1,5 +1,5 @@ /* - * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XimTrans.h b/nx-X11/lib/X11/XimTrans.h index 987b5ee33..8c3aa829a 100644 --- a/nx-X11/lib/X11/XimTrans.h +++ b/nx-X11/lib/X11/XimTrans.h @@ -1,5 +1,5 @@ /* - * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XimintP.h b/nx-X11/lib/X11/XimintP.h index 55257545e..14a7e6d5a 100644 --- a/nx-X11/lib/X11/XimintP.h +++ b/nx-X11/lib/X11/XimintP.h @@ -1,5 +1,5 @@ /* - * Copyright 1991, 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1991, 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 7a6e0485c..75e193c05 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -37,7 +37,7 @@ Sun Microsystems, Inc. or its licensors is granted. */ /* - * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/XlcSL.c b/nx-X11/lib/X11/XlcSL.c index f059bb34d..b8b3967d9 100644 --- a/nx-X11/lib/X11/XlcSL.c +++ b/nx-X11/lib/X11/XlcSL.c @@ -37,7 +37,7 @@ Sun Microsystems, Inc. or its licensors is granted. */ /* - * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index 4aae8e006..3b5fa4147 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -1,5 +1,5 @@ /* - * Copyright 1991, 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1991, 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/imDefIm.c b/nx-X11/lib/X11/imDefIm.c index 34c0345b8..5f65b5312 100644 --- a/nx-X11/lib/X11/imDefIm.c +++ b/nx-X11/lib/X11/imDefIm.c @@ -1,5 +1,5 @@ /* - * Copyright 1990, 1991, 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1990, 1991, 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/imTrX.c b/nx-X11/lib/X11/imTrX.c index dfe915f9d..6b1d61f2d 100644 --- a/nx-X11/lib/X11/imTrX.c +++ b/nx-X11/lib/X11/imTrX.c @@ -1,5 +1,5 @@ /* - * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index adfa044f5..f06759f88 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -1,5 +1,5 @@ /* - * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/imTransR.c b/nx-X11/lib/X11/imTransR.c index 2226c950d..caa530904 100644 --- a/nx-X11/lib/X11/imTransR.c +++ b/nx-X11/lib/X11/imTransR.c @@ -1,5 +1,5 @@ /* - * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Copyright 1992 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/nx-X11/lib/X11/lcInit.c b/nx-X11/lib/X11/lcInit.c index ee66b8c92..5aaf1832b 100644 --- a/nx-X11/lib/X11/lcInit.c +++ b/nx-X11/lib/X11/lcInit.c @@ -37,7 +37,7 @@ Sun Microsystems, Inc. or its licensors is granted. */ /* - * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), -- cgit v1.2.3 From a2fded2e334eb2f68b5ee6b44463daf58bd8b32c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 7 Oct 2016 22:16:24 +0200 Subject: Revert incomplete "Fix status reporting for braille patterns" This reverts commit 8866f80d9f42e02093058cab027edbf127118105. That commit had been edited and was incomplete, by reverting and re-applying we get it right. --- nx-X11/lib/X11/imLcLkup.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcLkup.c b/nx-X11/lib/X11/imLcLkup.c index 51c1f2ed8..50e09d2e7 100644 --- a/nx-X11/lib/X11/imLcLkup.c +++ b/nx-X11/lib/X11/imLcLkup.c @@ -71,21 +71,12 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, if(status) *status = XBufferOverflow; return(ret); } - if(keysym) *keysym = XK_braille_blank | pattern; - if(ret > 0) { - if (keysym) { - if(status) *status = XLookupBoth; - } else { - if(status) *status = XLookupChars; - } - memcpy(buffer, mb, ret); - } else { - if(keysym) { - if(status) *status = XLookupKeySym; - } else { - if(status) *status = XLookupNone; - } - } + if(keysym) { + *keysym = XK_braille_blank | pattern; + if(status) *status = XLookupBoth; + } else + if(status) *status = XLookupChars; + memcpy(buffer, mb, ret); } else { /* Composed Event */ ret = strlen(&mb[b[ic->private.local.composed].mb]); if(ret > bytes) { @@ -226,11 +217,6 @@ _XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f); buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6); buffer[2] = 0x80 | (pattern & 0x3f); - if(keysym) { - *keysym = XK_braille_blank | pattern; - if(status) *status = XLookupBoth; - } else - if(status) *status = XLookupChars; } else { /* Composed Event */ ret = strlen(&utf8[b[ic->private.local.composed].utf8]); if(ret > bytes) { -- cgit v1.2.3 From b00312f5d4e09ade3e91e5d6c5f7c847c474fb58 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 21 Feb 2011 15:56:54 +0100 Subject: Fix status reporting for braille patterns _XimLocalMbLookupString can return a braille keysym even if _Xlcwctomb can't convert to the current MB charset. _XimLocalUtf8LookupString needs to set the braille keysym and status too. Signed-off-by: Samuel Thibault Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcLkup.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcLkup.c b/nx-X11/lib/X11/imLcLkup.c index 50e09d2e7..878b8e350 100644 --- a/nx-X11/lib/X11/imLcLkup.c +++ b/nx-X11/lib/X11/imLcLkup.c @@ -63,20 +63,25 @@ _XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, unsigned char pattern = ic->private.local.brl_committed; char mb[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)]; ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern); - if(ret < 0) { - if(status) *status = XLookupNone; - return(0); - } if(ret > bytes) { if(status) *status = XBufferOverflow; return(ret); } - if(keysym) { - *keysym = XK_braille_blank | pattern; - if(status) *status = XLookupBoth; - } else - if(status) *status = XLookupChars; - memcpy(buffer, mb, ret); + if(keysym) *keysym = XK_braille_blank | pattern; + if(ret > 0) { + if (keysym) { + if(status) *status = XLookupBoth; + } else { + if(status) *status = XLookupChars; + } + memcpy(buffer, mb, ret); + } else { + if(keysym) { + if(status) *status = XLookupKeySym; + } else { + if(status) *status = XLookupNone; + } + } } else { /* Composed Event */ ret = strlen(&mb[b[ic->private.local.composed].mb]); if(ret > bytes) { @@ -217,6 +222,11 @@ _XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes, buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f); buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6); buffer[2] = 0x80 | (pattern & 0x3f); + if(keysym) { + *keysym = XK_braille_blank | pattern; + if(status) *status = XLookupBoth; + } else + if(status) *status = XLookupChars; } else { /* Composed Event */ ret = strlen(&utf8[b[ic->private.local.composed].utf8]); if(ret > bytes) { -- cgit v1.2.3 From 78b0ca2fe42ca998708490854d5f5f38ca90d0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:01:58 +0200 Subject: ximcp/imRmAttr: Handle leaking colormap_ret MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit XFree colormap_ret and initialize it when appropriate. Variable "colormap_ret" goes out of scope Reviewed-by: Alan Coopersmith Signed-off-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRmAttr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index b5abcdd75..ef3ac2ca7 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -960,6 +960,7 @@ _XimEncodePreeditValue( &count, (Atom)p->value))) return False; + XFree(colormap_ret); } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) { int list_ret; XFontStruct **struct_list; @@ -1003,7 +1004,7 @@ _XimEncodeStatusValue( XIMArg *p) { if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { - XStandardColormap *colormap_ret; + XStandardColormap *colormap_ret = NULL; int count; if (!(XGetRGBColormaps(ic->core.im->core.display, @@ -1011,6 +1012,7 @@ _XimEncodeStatusValue( &count, (Atom)p->value))) return False; + XFree(colormap_ret); } else if (res->xrm_name == XrmStringToQuark(XNFontSet)) { int list_ret; XFontStruct **struct_list; -- cgit v1.2.3 From 7992a98737cfc8a61b996951cb126820c87277dd Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 1 Mar 2013 18:37:37 -0800 Subject: integer overflow in ReadInFile() in Xrm.c [CVE-2013-1981 7/13] Called from XrmGetFileDatabase() which gets called from InitDefaults() which gets the filename from getenv ("XENVIRONMENT") If file is exactly 0xffffffff bytes long (or longer and truncates to 0xffffffff, on implementations where off_t is larger than an int), then size may be set to a value which overflows causing less memory to be allocated than is written to by the following read() call. size is left limited to an int, because if your Xresources file is larger than 2gb, you're very definitely doing it wrong. Reported-by: Ilja Van Sprundel Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xrm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index e498e4e5a..6adbc0dda 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -62,6 +62,7 @@ from The Open Group. #endif #include #include +#include #include "Xresinternal.h" #include "Xresource.h" @@ -1595,11 +1596,12 @@ ReadInFile(_Xconst char *filename) */ { struct stat status_buffer; - if ( (fstat(fd, &status_buffer)) == -1 ) { + if ( ((fstat(fd, &status_buffer)) == -1 ) || + (status_buffer.st_size >= INT_MAX) ) { close (fd); return (char *)NULL; } else - size = status_buffer.st_size; + size = (int) status_buffer.st_size; } if (!(filebuf = Xmalloc(size + 1))) { /* leave room for '\0' */ -- cgit v1.2.3 From 13fe4d4758c111a659c97356c7faf8bddeef336c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Mon, 31 Jan 2011 14:02:10 +0200 Subject: GetProp: Zero-initialized error so its resourceID field is initialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using uninitialized value "error.resourceID" in call to function "_XError" Reviewed-by: Alan Coopersmith Reviewed-by: Erkki Seppälä Signed-off-by: Ander Conselvan de Oliveira Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/GetProp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/GetProp.c b/nx-X11/lib/X11/GetProp.c index 4149199f5..9eb422ee3 100644 --- a/nx-X11/lib/X11/GetProp.c +++ b/nx-X11/lib/X11/GetProp.c @@ -47,7 +47,7 @@ XGetWindowProperty( { xGetPropertyReply reply; register xGetPropertyReq *req; - xError error; + xError error = {0}; /* Always initialize return values, in case callers fail to initialize them and fail to check the return code for an error. */ -- cgit v1.2.3 From 9b5f99c37b4c48406eda5af2e58eb57b9a33c164 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 8 Sep 2010 10:44:23 -0400 Subject: Zero buffer data in BufAlloc() Inspired by a pattern in NoMachine's NX. Consistently zeroed buffers compress better with ssh and friends. Note that you'll need to rebuild all your protocol libraries to take advantage of this. Signed-off-by: Adam Jackson Reviewed-by: Jeremy Huddleston Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index e3d63f29a..ead343eae 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -617,7 +617,7 @@ extern void _XFlushGCCache(Display *dpy, GC gc); if (dpy->bufptr + (n) > dpy->bufmax) \ _XFlush (dpy); \ ptr = (type) dpy->bufptr; \ - (void)ptr; \ + memset(ptr, '\0', n); \ dpy->bufptr += (n); #define Data16(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len)) -- cgit v1.2.3 From 878040bf0bdb5d791cbe2ac6e07899c149517a79 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 16 Dec 2012 17:44:42 -0800 Subject: Tell clang not to report -Wpadded warnings on public headers we can't fix Better to silence the compiler warning than break ABI. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xcms.h | 12 ++++++++++++ nx-X11/lib/X11/Xlib.h | 12 ++++++++++++ nx-X11/lib/X11/Xlibint.h | 12 ++++++++++++ nx-X11/lib/X11/Xutil.h | 12 ++++++++++++ 4 files changed, 48 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xcms.h b/nx-X11/lib/X11/Xcms.h index 7f7c1553a..3b0410533 100644 --- a/nx-X11/lib/X11/Xcms.h +++ b/nx-X11/lib/X11/Xcms.h @@ -32,6 +32,14 @@ #include +/* The Xcms structs are full of implicit padding to properly align members. + We can't clean that up without breaking ABI, so tell clang not to bother + complaining about it. */ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + /* * XCMS Status Values */ @@ -799,6 +807,10 @@ extern Visual *XcmsVisualOfCCC ( XcmsCCC /* ccc */ ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + _XFUNCPROTOEND #endif /* !defined(_X11_XCMS_H_) && !defined(_XCMS_H_) */ diff --git a/nx-X11/lib/X11/Xlib.h b/nx-X11/lib/X11/Xlib.h index 2d688d022..9ef4e00b0 100644 --- a/nx-X11/lib/X11/Xlib.h +++ b/nx-X11/lib/X11/Xlib.h @@ -82,6 +82,14 @@ _Xmblen( November 2000. Its presence is indicated through the following macro. */ #define X_HAVE_UTF8_STRING 1 +/* The Xlib structs are full of implicit padding to properly align members. + We can't clean that up without breaking ABI, so tell clang not to bother + complaining about it. */ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + typedef char *XPointer; #define Bool int @@ -4037,6 +4045,10 @@ extern void XFreeEventData( XGenericEventCookie* /* cookie*/ ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + _XFUNCPROTOEND #endif /* #if !defined(_X11_XLIB_H_) && !defined(_XLIB_H_) */ diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index ead343eae..ee39c7cf0 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -67,6 +67,14 @@ from The Open Group. #include /* to declare xEvent */ #include /* for configured options like XTHREADS */ +/* The Xlib structs are full of implicit padding to properly align members. + We can't clean that up without breaking ABI, so tell clang not to bother + complaining about it. */ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + #ifdef NX_TRANS_SOCKET #include @@ -1386,6 +1394,10 @@ extern void xlocaledir( int buf_len ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + _XFUNCPROTOEND #endif /* !defined(_X11_XLIBINT_H_) && !defined(_XLIBINT_H_) */ diff --git a/nx-X11/lib/X11/Xutil.h b/nx-X11/lib/X11/Xutil.h index 311a66c9d..55bedc96d 100644 --- a/nx-X11/lib/X11/Xutil.h +++ b/nx-X11/lib/X11/Xutil.h @@ -54,6 +54,14 @@ SOFTWARE. #include #include +/* The Xlib structs are full of implicit padding to properly align members. + We can't clean that up without breaking ABI, so tell clang not to bother + complaining about it. */ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + /* * Bitmask returned by XParseGeometry(). Each bit tells if the corresponding * value (x, y, width, height) was found in the parsed string. @@ -822,6 +830,10 @@ extern int XXorRegion( Region /* dr_return */ ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + _XFUNCPROTOEND #endif /* !defined(_X11_XUTIL_H_) && !defined(_XUTIL_H_) */ -- cgit v1.2.3 From e2e45b2b3abf46e4e5c27d7c655769f2b693446e Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 7 Oct 2016 23:46:05 +0200 Subject: Align files with upstream libX11-1.6.0 This commit looks a bit crazy at first glance. It (re-)introduces lots of whitespaces and bad formatting. Explanation: Backporting upstream changes lead to commits being applied out of order. This meant a lot of manual intervention which in turn lead to slight differences between upstream and NX. With this commit these slight differences are minimized which will be of great help when adding further upstream patches. --- nx-X11/lib/X11/AllCells.c | 1 - nx-X11/lib/X11/ChProp.c | 2 +- nx-X11/lib/X11/DrArc.c | 1 + nx-X11/lib/X11/ErrHndlr.c | 10 ++--- nx-X11/lib/X11/FillRcts.c | 1 + nx-X11/lib/X11/Font.c | 11 +++--- nx-X11/lib/X11/FreeGC.c | 1 + nx-X11/lib/X11/GetWAttrs.c | 4 +- nx-X11/lib/X11/ImUtil.c | 6 +-- nx-X11/lib/X11/LiHosts.c | 1 + nx-X11/lib/X11/LoadFont.c | 2 +- nx-X11/lib/X11/PolyTxt.c | 14 +++---- nx-X11/lib/X11/PolyTxt16.c | 17 +++++---- nx-X11/lib/X11/QuColors.c | 15 ++++---- nx-X11/lib/X11/RegstFlt.c | 4 +- nx-X11/lib/X11/RestackWs.c | 2 + nx-X11/lib/X11/SetCRects.c | 1 + nx-X11/lib/X11/SetDashes.c | 2 +- nx-X11/lib/X11/SetPntMap.c | 1 + nx-X11/lib/X11/StColor.c | 1 + nx-X11/lib/X11/Text.c | 22 +++++------ nx-X11/lib/X11/TextExt.c | 8 ++-- nx-X11/lib/X11/TextExt16.c | 8 ++-- nx-X11/lib/X11/WMGeom.c | 14 +++---- nx-X11/lib/X11/XErrorDB | 12 +++--- nx-X11/lib/X11/XKBGetMap.c | 1 - nx-X11/lib/X11/XKBRdBuf.c | 5 +-- nx-X11/lib/X11/XKBlibint.h | 2 +- nx-X11/lib/X11/Xlibint.h | 12 +++--- nx-X11/lib/X11/Xprivate.h | 8 ++-- nx-X11/lib/X11/Xrm.c | 12 +++--- nx-X11/lib/X11/Xutil.h | 2 +- nx-X11/lib/X11/cmsProp.c | 12 +++--- nx-X11/lib/X11/imLcIm.c | 4 +- nx-X11/lib/X11/lcFile.c | 72 ++++++++++++++++++------------------ nx-X11/lib/X11/lcUniConv/big5hkscs.h | 1 + nx-X11/lib/X11/locking.h | 2 +- nx-X11/lib/X11/omXChar.c | 24 ++++++------ nx-X11/lib/X11/os2Stubs.c | 42 ++++++++++----------- nx-X11/lib/X11/pathmax.h | 1 - nx-X11/lib/X11/udcInf.c | 22 +++++------ nx-X11/lib/X11/utlist.h | 1 + 42 files changed, 190 insertions(+), 194 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/AllCells.c b/nx-X11/lib/X11/AllCells.c index 6d9548f0d..6e97e1181 100644 --- a/nx-X11/lib/X11/AllCells.c +++ b/nx-X11/lib/X11/AllCells.c @@ -24,7 +24,6 @@ in this Software without prior written authorization from The Open Group. */ - #ifdef HAVE_CONFIG_H #include #endif diff --git a/nx-X11/lib/X11/ChProp.c b/nx-X11/lib/X11/ChProp.c index 1721168b4..190a224f8 100644 --- a/nx-X11/lib/X11/ChProp.c +++ b/nx-X11/lib/X11/ChProp.c @@ -65,7 +65,7 @@ XChangeProperty ( Data (dpy, (_Xconst char *)data, nelements); } /* else force BadLength */ break; - + case 16: len = ((long)nelements + 1)>>1; if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { diff --git a/nx-X11/lib/X11/DrArc.c b/nx-X11/lib/X11/DrArc.c index 61102e9b2..d72fac9d7 100644 --- a/nx-X11/lib/X11/DrArc.c +++ b/nx-X11/lib/X11/DrArc.c @@ -66,6 +66,7 @@ XDrawArc( arc->angle1 = angle1; arc->angle2 = angle2; + UnlockDisplay(dpy); SyncHandle(); return 1; diff --git a/nx-X11/lib/X11/ErrHndlr.c b/nx-X11/lib/X11/ErrHndlr.c index 4785ca157..167a68b1e 100644 --- a/nx-X11/lib/X11/ErrHndlr.c +++ b/nx-X11/lib/X11/ErrHndlr.c @@ -29,12 +29,12 @@ in this Software without prior written authorization from The Open Group. #endif #include "Xlibint.h" -/* +/* * XErrorHandler - This procedure sets the X non-fatal error handler * (_XErrorFunction) to be the specified routine. If NULL is passed in * the original error handler is restored. */ - + XErrorHandler XSetErrorHandler(XErrorHandler handler) { @@ -57,12 +57,12 @@ XSetErrorHandler(XErrorHandler handler) return (XErrorHandler) oldhandler; } -/* +/* * XIOErrorHandler - This procedure sets the X fatal I/O error handler - * (_XIOErrorFunction) to be the specified routine. If NULL is passed in + * (_XIOErrorFunction) to be the specified routine. If NULL is passed in * the original error handler is restored. */ - + XIOErrorHandler XSetIOErrorHandler(XIOErrorHandler handler) { diff --git a/nx-X11/lib/X11/FillRcts.c b/nx-X11/lib/X11/FillRcts.c index 7d9569124..ad334244f 100644 --- a/nx-X11/lib/X11/FillRcts.c +++ b/nx-X11/lib/X11/FillRcts.c @@ -63,3 +63,4 @@ XFillRectangles( SyncHandle(); return 1; } + diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index 298d96c63..d48b7d0ff 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -260,7 +260,6 @@ _XQueryFont ( * If no characters in font, then it is a bad font, but * shouldn't try to read nothing. */ - /* have to unpack charinfos on some machines (CRAY) */ fs->per_char = NULL; if (reply.nCharInfos > 0){ /* nCharInfos is a CARD32 */ @@ -507,11 +506,11 @@ _XF86BigfontQueryFont ( /* compares each part to half the maximum, which should be far more than 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); - _XEatDataWords(dpy, reply_left); - return (XFontStruct *)NULL; + reply.nCharInfos > ((ULONG_MAX / 2) / sizeof(CARD16))) { + Xfree((char *) fs->properties); + Xfree((char *) fs); + _XEatDataWords(dpy, reply_left); + return (XFontStruct *)NULL; } #endif if (reply.nCharInfos > 0) { diff --git a/nx-X11/lib/X11/FreeGC.c b/nx-X11/lib/X11/FreeGC.c index cc9765551..ab994bc64 100644 --- a/nx-X11/lib/X11/FreeGC.c +++ b/nx-X11/lib/X11/FreeGC.c @@ -47,3 +47,4 @@ XFreeGC ( Xfree ((char *) gc); return 1; } + diff --git a/nx-X11/lib/X11/GetWAttrs.c b/nx-X11/lib/X11/GetWAttrs.c index 4d51893d6..c10824cf4 100644 --- a/nx-X11/lib/X11/GetWAttrs.c +++ b/nx-X11/lib/X11/GetWAttrs.c @@ -89,14 +89,14 @@ _XGetWindowAttributes( register Display *dpy, Window w, XWindowAttributes *attr) -{ +{ xGetGeometryReply rep; register xResourceReq *req; register int i; register Screen *sp; _XAsyncHandler async; _XWAttrsState async_state; - + GetResReq(GetWindowAttributes, w, req); async_state.attr_seq = dpy->request; diff --git a/nx-X11/lib/X11/ImUtil.c b/nx-X11/lib/X11/ImUtil.c index f9a21f839..16dd0fa79 100644 --- a/nx-X11/lib/X11/ImUtil.c +++ b/nx-X11/lib/X11/ImUtil.c @@ -543,8 +543,7 @@ static unsigned long _XGetPixel32 ( [y * ximage->bytes_per_line + (x << 2)]; if (*((const char *)&byteorderpixel) == ximage->byte_order) pixel = *((CARD32 *)addr); - else - if (ximage->byte_order == MSBFirst) + else if (ximage->byte_order == MSBFirst) pixel = ((unsigned long)addr[0] << 24 | (unsigned long)addr[1] << 16 | (unsigned long)addr[2] << 8 | @@ -732,8 +731,7 @@ static int _XPutPixel32 ( [y * ximage->bytes_per_line + (x << 2)]; if (*((const char *)&byteorderpixel) == ximage->byte_order) *((CARD32 *)addr) = pixel; - else - if (ximage->byte_order == MSBFirst) { + else if (ximage->byte_order == MSBFirst) { addr[0] = pixel >> 24; addr[1] = pixel >> 16; addr[2] = pixel >> 8; diff --git a/nx-X11/lib/X11/LiHosts.c b/nx-X11/lib/X11/LiHosts.c index 202deee02..83cf3c791 100644 --- a/nx-X11/lib/X11/LiHosts.c +++ b/nx-X11/lib/X11/LiHosts.c @@ -154,3 +154,4 @@ XHostAddress *XListHosts ( + diff --git a/nx-X11/lib/X11/LoadFont.c b/nx-X11/lib/X11/LoadFont.c index 88171a633..f547976ba 100644 --- a/nx-X11/lib/X11/LoadFont.c +++ b/nx-X11/lib/X11/LoadFont.c @@ -49,7 +49,7 @@ XLoadFont ( Data (dpy, name, nbytes); UnlockDisplay(dpy); SyncHandle(); - return (fid); + return (fid); /* can't return (req->fid) since request may have already been sent */ } diff --git a/nx-X11/lib/X11/PolyTxt.c b/nx-X11/lib/X11/PolyTxt.c index 2f43c43d3..471383b57 100644 --- a/nx-X11/lib/X11/PolyTxt.c +++ b/nx-X11/lib/X11/PolyTxt.c @@ -121,9 +121,9 @@ XDrawText( { int nb = SIZEOF(xTextElt); - BufAlloc (char *, tbuf, nb); + BufAlloc (char *, tbuf, nb); *tbuf = 0; /* elt->len */ - if (PartialDelta > 0 ) + if (PartialDelta > 0 ) { *(tbuf+1) = 127; /* elt->delta */ PartialDelta = PartialDelta - 127; @@ -148,9 +148,9 @@ XDrawText( { FirstTimeThrough = False; if (!item->delta) - { + { nbytes += SIZEOF(xTextElt); - BufAlloc (char *, tbuf, nbytes); + BufAlloc (char *, tbuf, nbytes); *(tbuf+1) = 0; /* elt->delta */ } else @@ -179,9 +179,9 @@ XDrawText( { FirstTimeThrough = False; if (!item->delta) - { + { nbytes += SIZEOF(xTextElt); - BufAlloc (char *, tbuf, nbytes); + BufAlloc (char *, tbuf, nbytes); *(tbuf+1) = 0; /* elt->delta */ } else @@ -193,7 +193,7 @@ XDrawText( else { nbytes += SIZEOF(xTextElt); - BufAlloc (char *, tbuf, nbytes); + BufAlloc (char *, tbuf, nbytes); *(tbuf+1) = 0; /* elt->delta */ } *tbuf = PartialNChars; /* elt->len */ diff --git a/nx-X11/lib/X11/PolyTxt16.c b/nx-X11/lib/X11/PolyTxt16.c index 6c7cc49ec..2e4be1673 100644 --- a/nx-X11/lib/X11/PolyTxt16.c +++ b/nx-X11/lib/X11/PolyTxt16.c @@ -120,9 +120,9 @@ XDrawText16( { int nb = SIZEOF(xTextElt); - BufAlloc (xTextElt *, elt, nb); + BufAlloc (xTextElt *, elt, nb); elt->len = 0; - if (PartialDelta > 0 ) + if (PartialDelta > 0 ) { elt->delta = 127; PartialDelta = PartialDelta - 127; @@ -146,9 +146,9 @@ XDrawText16( { FirstTimeThrough = False; if (!item->delta) - { + { nbytes += SIZEOF(xTextElt); - BufAlloc (xTextElt *, elt, nbytes); + BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } else @@ -180,9 +180,9 @@ XDrawText16( { FirstTimeThrough = False; if (!item->delta) - { + { nbytes += SIZEOF(xTextElt); - BufAlloc (xTextElt *, elt, nbytes); + BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } else @@ -197,13 +197,14 @@ XDrawText16( else { nbytes += SIZEOF(xTextElt); - BufAlloc (xTextElt *, elt, nbytes); + BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } elt->len = PartialNChars; memcpy ((char *) (elt + 1), (char *)CharacterOffset, - PartialNChars * 2); + PartialNChars * +2); } } item++; diff --git a/nx-X11/lib/X11/QuColors.c b/nx-X11/lib/X11/QuColors.c index 7937f5e5a..13a63eb25 100644 --- a/nx-X11/lib/X11/QuColors.c +++ b/nx-X11/lib/X11/QuColors.c @@ -75,26 +75,25 @@ int XQueryColors( register Display * const dpy, const Colormap cmap, - XColor *defs, /* RETURN */ + XColor *defs, /* RETURN */ int ncolors) { int n; if (dpy->bigreq_size > 0) - n = dpy->bigreq_size - (sizeof (xQueryColorsReq) >> 2) - 1; + n = dpy->bigreq_size - (sizeof (xQueryColorsReq) >> 2) - 1; else - n = dpy->max_request_size - (sizeof (xQueryColorsReq) >> 2); + n = dpy->max_request_size - (sizeof (xQueryColorsReq) >> 2); LockDisplay(dpy); while (ncolors >= n) { - _XQueryColors(dpy, cmap, defs, n); - defs += n; - ncolors -= n; + _XQueryColors(dpy, cmap, defs, n); + defs += n; + ncolors -= n; } if (ncolors > 0) - _XQueryColors(dpy, cmap, defs, ncolors); + _XQueryColors(dpy, cmap, defs, ncolors); UnlockDisplay(dpy); SyncHandle(); return 1; } - diff --git a/nx-X11/lib/X11/RegstFlt.c b/nx-X11/lib/X11/RegstFlt.c index cbc93ba43..5a1faa7e9 100644 --- a/nx-X11/lib/X11/RegstFlt.c +++ b/nx-X11/lib/X11/RegstFlt.c @@ -18,12 +18,12 @@ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * PERFORMANCE OF THIS SOFTWARE. * * Author: Seiji Kuwari OMRON Corporation * kuwa@omron.co.jp * kuwa%omron.co.jp@uunet.uu.net - */ + */ /* Copyright 1990, 1991, 1998 The Open Group diff --git a/nx-X11/lib/X11/RestackWs.c b/nx-X11/lib/X11/RestackWs.c index b2a77fcdf..52391ecd2 100644 --- a/nx-X11/lib/X11/RestackWs.c +++ b/nx-X11/lib/X11/RestackWs.c @@ -57,3 +57,5 @@ XRestackWindows ( } + + diff --git a/nx-X11/lib/X11/SetCRects.c b/nx-X11/lib/X11/SetCRects.c index 21b68f8a2..c7ad3fcf2 100644 --- a/nx-X11/lib/X11/SetCRects.c +++ b/nx-X11/lib/X11/SetCRects.c @@ -78,3 +78,4 @@ XSetClipRectangles ( SyncHandle(); return 1; } + diff --git a/nx-X11/lib/X11/SetDashes.c b/nx-X11/lib/X11/SetDashes.c index a2d537bc5..ffe4a95ff 100644 --- a/nx-X11/lib/X11/SetDashes.c +++ b/nx-X11/lib/X11/SetDashes.c @@ -52,4 +52,4 @@ XSetDashes ( SyncHandle(); return 1; } - + diff --git a/nx-X11/lib/X11/SetPntMap.c b/nx-X11/lib/X11/SetPntMap.c index 5dd9beef8..14e104d6d 100644 --- a/nx-X11/lib/X11/SetPntMap.c +++ b/nx-X11/lib/X11/SetPntMap.c @@ -74,3 +74,4 @@ XChangeKeyboardMapping ( SyncHandle(); return 0; } + diff --git a/nx-X11/lib/X11/StColor.c b/nx-X11/lib/X11/StColor.c index b19f0a5dc..d5a217fb0 100644 --- a/nx-X11/lib/X11/StColor.c +++ b/nx-X11/lib/X11/StColor.c @@ -51,6 +51,7 @@ XStoreColor( citem->blue = def->blue; citem->flags = def->flags; /* do_red, do_green, do_blue */ + UnlockDisplay(dpy); SyncHandle(); return 1; diff --git a/nx-X11/lib/X11/Text.c b/nx-X11/lib/X11/Text.c index 645aa283f..223b1cf8b 100644 --- a/nx-X11/lib/X11/Text.c +++ b/nx-X11/lib/X11/Text.c @@ -38,7 +38,7 @@ XDrawString( int y, _Xconst char *string, int length) -{ +{ int Datalength = 0; register xPolyText8Req *req; @@ -60,11 +60,11 @@ XDrawString( req->length += (Datalength + 3)>>2; /* convert to number of 32-bit words */ - /* + /* * If the entire request does not fit into the remaining space in the * buffer, flush the buffer first. If the request does fit into the * empty buffer, then we won't have to flush it at the end to keep - * the buffer 32-bit aligned. + * the buffer 32-bit aligned. */ if (dpy->bufptr + Datalength > dpy->bufmax) @@ -92,11 +92,11 @@ XDrawString( PartialNChars = PartialNChars - 254; CharacterOffset += 254; } - + if (PartialNChars) { nbytes = PartialNChars + SIZEOF(xTextElt); - BufAlloc (unsigned char *, tbuf, nbytes); + BufAlloc (unsigned char *, tbuf, nbytes); /* elt->delta = 0; * elt->len = PartialNChars; */ @@ -112,23 +112,23 @@ XDrawString( if (Datalength &= 3) { char *pad; - /* + /* * BufAlloc is a macro that uses its last argument more than - * once, otherwise I'd write "BufAlloc (char *, pad, 4-length)" + * once, otherwise I'd write "BufAlloc (char *, pad, 4-length)" */ length = 4 - Datalength; BufAlloc (char *, pad, length); - /* + /* * if there are 3 bytes of padding, the first byte MUST be 0 - * so the pad bytes aren't mistaken for a final xTextElt + * so the pad bytes aren't mistaken for a final xTextElt */ *pad = 0; } - /* + /* * If the buffer pointer is not now pointing to a 32-bit boundary, * we must flush the buffer so that it does point to a 32-bit boundary - * at the end of this routine. + * at the end of this routine. */ if ((dpy->bufptr - dpy->buffer) & 3) diff --git a/nx-X11/lib/X11/TextExt.c b/nx-X11/lib/X11/TextExt.c index 910bb3d7b..b883b01b4 100644 --- a/nx-X11/lib/X11/TextExt.c +++ b/nx-X11/lib/X11/TextExt.c @@ -41,7 +41,7 @@ from The Open Group. #define max_byte2 max_char_or_byte2 -/* +/* * CI_GET_ROWZERO_CHAR_INFO_2D - do the same thing as CI_GET_CHAR_INFO_1D, * except that the font has more than one row. This is special case of more * general version used in XTextExt16.c since row == 0. This is used when @@ -119,7 +119,7 @@ XTextExtents ( } else { overall->ascent = max (overall->ascent, cs->ascent); overall->descent = max (overall->descent, cs->descent); - overall->lbearing = min (overall->lbearing, + overall->lbearing = min (overall->lbearing, overall->width + cs->lbearing); overall->rbearing = max (overall->rbearing, overall->width + cs->rbearing); @@ -132,7 +132,7 @@ XTextExtents ( * if there were no characters, then set everything to 0 */ if (nfound == 0) { - overall->width = overall->ascent = overall->descent = + overall->width = overall->ascent = overall->descent = overall->lbearing = overall->rbearing = 0; } @@ -141,7 +141,7 @@ XTextExtents ( /* - * XTextWidth - compute the width of a string of eightbit bytes. This is a + * XTextWidth - compute the width of a string of eightbit bytes. This is a * subset of XTextExtents. */ int diff --git a/nx-X11/lib/X11/TextExt16.c b/nx-X11/lib/X11/TextExt16.c index 643aa5e30..01a0f32e4 100644 --- a/nx-X11/lib/X11/TextExt16.c +++ b/nx-X11/lib/X11/TextExt16.c @@ -41,7 +41,7 @@ from The Open Group. #define max_byte2 max_char_or_byte2 /* - * XTextExtents16 - compute the extents of string given as a sequence of + * XTextExtents16 - compute the extents of string given as a sequence of * XChar2bs. */ int @@ -94,7 +94,7 @@ XTextExtents16 ( } else { overall->ascent = max (overall->ascent, cs->ascent); overall->descent = max (overall->descent, cs->descent); - overall->lbearing = min (overall->lbearing, + overall->lbearing = min (overall->lbearing, overall->width + cs->lbearing); overall->rbearing = max (overall->rbearing, overall->width + cs->rbearing); @@ -107,7 +107,7 @@ XTextExtents16 ( * if there were no characters, then set everything to 0 */ if (nfound == 0) { - overall->width = overall->ascent = overall->descent = + overall->width = overall->ascent = overall->descent = overall->lbearing = overall->rbearing = 0; } @@ -116,7 +116,7 @@ XTextExtents16 ( /* - * XTextWidth16 - compute the width of sequence of XChar2bs. This is a + * XTextWidth16 - compute the width of sequence of XChar2bs. This is a * subset of XTextExtents16. */ int diff --git a/nx-X11/lib/X11/WMGeom.c b/nx-X11/lib/X11/WMGeom.c index 68187b583..7947536f5 100644 --- a/nx-X11/lib/X11/WMGeom.c +++ b/nx-X11/lib/X11/WMGeom.c @@ -72,13 +72,13 @@ XWMGeometry ( * Get the base sizes and increments. Section 4.1.2.3 of the ICCCM * states that the base and minimum sizes are defaults for each other. * If neither is given, then the base sizes should be 0. These parameters - * control the sets of sizes that window managers should allow for the + * control the sets of sizes that window managers should allow for the * window according to the following formulae: * * width = base_width + (i * width_inc) * height = base_height + (j * height_inc) */ - base_width = ((hints->flags & PBaseSize) ? hints->base_width : + base_width = ((hints->flags & PBaseSize) ? hints->base_width : ((hints->flags & PMinSize) ? hints->min_width : 0)); base_height = ((hints->flags & PBaseSize) ? hints->base_height : ((hints->flags & PMinSize) ? hints->min_height : 0)); @@ -103,11 +103,11 @@ XWMGeometry ( * 4. multiply by the size increment * 5. and add to the base size */ - rwidth = ((((umask & WidthValue) ? uwidth : + rwidth = ((((umask & WidthValue) ? uwidth : ((dmask & WidthValue) ? dwidth : 1)) * width_inc) + base_width); - rheight = ((((umask & HeightValue) ? uheight : - ((dmask & HeightValue) ? dheight : 1)) * height_inc) + + rheight = ((((umask & HeightValue) ? uheight : + ((dmask & HeightValue) ? dheight : 1)) * height_inc) + base_height); /* @@ -135,7 +135,7 @@ XWMGeometry ( if (dmask & XNegative) { rx = (DisplayWidth (dpy, screen) + dx - rwidth - 2 * bwidth); rmask |= XNegative; - } else + } else rx = dx; } else { rx = 0; /* gotta choose something... */ @@ -148,7 +148,7 @@ XWMGeometry ( if (dmask & YNegative) { ry = (DisplayHeight(dpy, screen) + dy - rheight - 2 * bwidth); rmask |= YNegative; - } else + } else ry = dy; } else { ry = 0; /* gotta choose something... */ diff --git a/nx-X11/lib/X11/XErrorDB b/nx-X11/lib/X11/XErrorDB index c2efa1044..7b6d46513 100644 --- a/nx-X11/lib/X11/XErrorDB +++ b/nx-X11/lib/X11/XErrorDB @@ -1014,9 +1014,9 @@ XRequest.DRI2.3: DRI2CreateDrawable XRequest.DRI2.4: DRI2DestroyDrawable XRequest.DRI2.5: DRI2GetBuffers XRequest.DRI2.6: DRI2CopyRegion -XRequest.DRI2.7: DRI2GetBuffersWithFormat -XRequest.DRI2.8: DRI2SwapBuffers -XRequest.DRI2.9: DRI2GetMSC -XRequest.DRI2.10: DRI2WaitMSC -XRequest.DRI2.11: DRI2WaitSBC -XRequest.DRI2.12: DRI2SwapInterval +XRequest.DRI2.7: DRI2GetBuffersWithFormat +XRequest.DRI2.8: DRI2SwapBuffers +XRequest.DRI2.9: DRI2GetMSC +XRequest.DRI2.10: DRI2WaitMSC +XRequest.DRI2.11: DRI2WaitSBC +XRequest.DRI2.12: DRI2SwapInterval diff --git a/nx-X11/lib/X11/XKBGetMap.c b/nx-X11/lib/X11/XKBGetMap.c index 391d7aa89..bfba747aa 100644 --- a/nx-X11/lib/X11/XKBGetMap.c +++ b/nx-X11/lib/X11/XKBGetMap.c @@ -24,7 +24,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ - #define NEED_MAP_READERS #ifdef HAVE_CONFIG_H #include diff --git a/nx-X11/lib/X11/XKBRdBuf.c b/nx-X11/lib/X11/XKBRdBuf.c index ca8f8e722..694d579f7 100644 --- a/nx-X11/lib/X11/XKBRdBuf.c +++ b/nx-X11/lib/X11/XKBRdBuf.c @@ -116,9 +116,7 @@ _XkbReadCopyData32(int *wire,long *to,int num_words) } return 1; } -#endif -#if defined(LONG64) int _XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words) { @@ -128,9 +126,7 @@ _XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words) from->data+= (4*num_words); return True; } -#endif -#ifdef LONG64 int _XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len) { @@ -142,6 +138,7 @@ _XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len) } #endif /* LONG64 */ + char * _XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size) { diff --git a/nx-X11/lib/X11/XKBlibint.h b/nx-X11/lib/X11/XKBlibint.h index 34cdf9aaf..94b8ac077 100644 --- a/nx-X11/lib/X11/XKBlibint.h +++ b/nx-X11/lib/X11/XKBlibint.h @@ -213,7 +213,7 @@ extern int _XkbCopyFromReadBuffer( ); -#if defined(LONG64) +#ifdef LONG64 extern int _XkbReadCopyData32( int * /* from */, long * /* to */, diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index ee39c7cf0..31bec58f9 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -243,10 +243,6 @@ struct _XDisplay #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n) -/* - * define the following if you want the Data macro to be a procedure instead - */ - #ifndef _XEVENT_ /* * _QEvent datatype for use in input queueing. @@ -445,6 +441,9 @@ extern LockInfoPtr _Xglobal_lock; * X Protocol packetizing macros. */ +/* Leftover from CRAY support - was defined empty on all non-Cray systems */ +#define WORD64ALIGN + /** * Return a len-sized request buffer for the request type. This function may * flush the output queue. @@ -593,7 +592,7 @@ extern void _XFlushGCCache(Display *dpy, GC gc); * 32 bit word alignment. Transmit if the buffer fills. * * "dpy" is a pointer to a Display. - * "data" is a pinter to a data buffer. + * "data" is a pointer to a data buffer. * "len" is the length of the data buffer. */ #ifndef DataRoutineIsProcedure @@ -715,7 +714,6 @@ extern void _XRead32( } - /* srcvar must be a variable for large architecture version */ #define OneDataCard32(dpy,dstaddr,srcvar) \ { *(CARD32 *)(dstaddr) = (srcvar); } @@ -894,7 +892,7 @@ extern int _XError( ); extern int _XIOError( Display* /* dpy */ -); +) _X_NORETURN; extern int (*_XIOErrorFunction)( Display* /* dpy */ ); diff --git a/nx-X11/lib/X11/Xprivate.h b/nx-X11/lib/X11/Xprivate.h index bc8dbf4d9..2dd62ce7d 100644 --- a/nx-X11/lib/X11/Xprivate.h +++ b/nx-X11/lib/X11/Xprivate.h @@ -10,10 +10,10 @@ #include -extern void _XIDHandler(Display *dpy); -extern void _XSeqSyncFunction(Display *dpy); -extern void _XSetPrivSyncFunction(Display *dpy); -extern void _XSetSeqSyncFunction(Display *dpy); +extern _X_HIDDEN void _XIDHandler(Display *dpy); +extern _X_HIDDEN void _XSeqSyncFunction(Display *dpy); +extern _X_HIDDEN void _XSetPrivSyncFunction(Display *dpy); +extern _X_HIDDEN void _XSetSeqSyncFunction(Display *dpy); #ifdef XTHREADS #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 6adbc0dda..e83b28428 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -1595,13 +1595,13 @@ ReadInFile(_Xconst char *filename) * to the size returned by fstat. */ { - struct stat status_buffer; - if ( ((fstat(fd, &status_buffer)) == -1 ) || + struct stat status_buffer; + if ( ((fstat(fd, &status_buffer)) == -1 ) || (status_buffer.st_size >= INT_MAX) ) { - close (fd); - return (char *)NULL; - } else - size = (int) status_buffer.st_size; + close (fd); + return (char *)NULL; + } else + size = (int) status_buffer.st_size; } if (!(filebuf = Xmalloc(size + 1))) { /* leave room for '\0' */ diff --git a/nx-X11/lib/X11/Xutil.h b/nx-X11/lib/X11/Xutil.h index 55bedc96d..48fa23cf5 100644 --- a/nx-X11/lib/X11/Xutil.h +++ b/nx-X11/lib/X11/Xutil.h @@ -50,7 +50,7 @@ SOFTWARE. #define _X11_XUTIL_H_ #define _XUTIL_H_ -/* You must include before including this file */ +/* You must include before including this file */ #include #include diff --git a/nx-X11/lib/X11/cmsProp.c b/nx-X11/lib/X11/cmsProp.c index 7e1a70310..a7aa5b5c5 100644 --- a/nx-X11/lib/X11/cmsProp.c +++ b/nx-X11/lib/X11/cmsProp.c @@ -128,11 +128,11 @@ _XcmsGetProperty( int xgwp_ret; while (True) { - xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, - XA_INTEGER, &atom_ret, &format_ret, - &nitems_ret, &after_ret, - (unsigned char **)&prop_ret); - if (xgwp_ret == Success && after_ret > 0) { + xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, + XA_INTEGER, &atom_ret, &format_ret, + &nitems_ret, &after_ret, + (unsigned char **)&prop_ret); + if (xgwp_ret == Success && after_ret > 0) { len += nitems_ret * (format_ret >> 3); XFree (prop_ret); } else { @@ -140,7 +140,7 @@ _XcmsGetProperty( } } if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { - /* the property does not exist or is of an unexpected type or + /* the property does not exist or is of an unexpected type or getting window property failed */ return(XcmsFailure); } diff --git a/nx-X11/lib/X11/imLcIm.c b/nx-X11/lib/X11/imLcIm.c index 70a71591c..15e5bee4d 100644 --- a/nx-X11/lib/X11/imLcIm.c +++ b/nx-X11/lib/X11/imLcIm.c @@ -36,9 +36,7 @@ THIS SOFTWARE. #include #endif #include -/* -#include -*/ + #include #include #include diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index 36f0ddf5a..aeaae245d 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -635,53 +635,53 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) 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); - name = resolve_name(lc_name, buf, LtoR); + strlen(locale_alias)) < PATH_MAX) { + sprintf (buf, "%s/%s", args[i], locale_alias); + name = resolve_name(lc_name, buf, LtoR); if (!name) { if (!nlc_name) nlc_name = normalize_lcname(lc_name); if (nlc_name) name = resolve_name (nlc_name, buf, LtoR); } - } + } - /* If name is not an alias, use lc_name for locale.dir search */ - if (name == NULL) - name = 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 */ + /* 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 (name != lc_name) - Xfree(name); - if (target_name != NULL) { - char *p = 0; - if ((p = strstr(target_name, "/XLC_LOCALE"))) { - *p = '\0'; - break; - } - Xfree(target_name); - target_name = NULL; - } - name = NULL; + 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 (name != lc_name) + Xfree(name); + if (target_name != NULL) { + char *p = 0; + if ((p = strstr(target_name, "/XLC_LOCALE"))) { + *p = '\0'; + break; + } + Xfree(target_name); + target_name = NULL; + } + name = NULL; } if (nlc_name) Xfree(nlc_name); if (target_name == NULL) { - /* vendor locale name == Xlocale name, no expansion of alias */ - target_dir = args[0]; - target_name = lc_name; + /* 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); @@ -694,7 +694,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) dir_name[dir_len - 1] = '\0'; } if (target_name != lc_name) - Xfree(target_name); + Xfree(target_name); if (last_dir_name != 0) Xfree (last_dir_name); @@ -757,7 +757,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) Xfree(name); continue; } - if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { + if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { sprintf(buf, "%s/locale.dir", target_dir); target_name = resolve_name(name, buf, RtoL); } diff --git a/nx-X11/lib/X11/lcUniConv/big5hkscs.h b/nx-X11/lib/X11/lcUniConv/big5hkscs.h index 29eab938f..721d1228e 100644 --- a/nx-X11/lib/X11/lcUniConv/big5hkscs.h +++ b/nx-X11/lib/X11/lcUniConv/big5hkscs.h @@ -6249,3 +6249,4 @@ big5hkscs_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n) } return RET_TOOSMALL; } + diff --git a/nx-X11/lib/X11/locking.h b/nx-X11/lib/X11/locking.h index 0942b95aa..277c9afc8 100644 --- a/nx-X11/lib/X11/locking.h +++ b/nx-X11/lib/X11/locking.h @@ -1,4 +1,4 @@ -/* +/* Copyright 1992, 1998 The Open Group diff --git a/nx-X11/lib/X11/omXChar.c b/nx-X11/lib/X11/omXChar.c index 85d2f15b7..c9bbb8e88 100644 --- a/nx-X11/lib/X11/omXChar.c +++ b/nx-X11/lib/X11/omXChar.c @@ -317,7 +317,7 @@ _XomConvert( XlcCharSet charset; int length, cs_left, ret; FontSet font_set; - + cs = *to; cs_left = *to_left; lc_args[0] = (XPointer) &charset; @@ -335,20 +335,18 @@ _XomConvert( length = *to_left - cs_left; - { - if (font_set->side != charset->side) { - if (font_set->side == XlcGL) - shift_to_gl(*to, length); - else if (font_set->side == XlcGR) - shift_to_gr(*to, length); - } - - if (font_set->is_xchar2b) - length >>= 1; - *to = cs; - *to_left -= length; + if (font_set->side != charset->side) { + if (font_set->side == XlcGL) + shift_to_gl(*to, length); + else if (font_set->side == XlcGR) + shift_to_gr(*to, length); } + if (font_set->is_xchar2b) + length >>= 1; + *to = cs; + *to_left -= length; + *((XFontStruct **) args[0]) = font_set->font; *((Bool *) args[1]) = font_set->is_xchar2b; if(num_args >= 3){ diff --git a/nx-X11/lib/X11/os2Stubs.c b/nx-X11/lib/X11/os2Stubs.c index d01b85b46..5ffc4824c 100644 --- a/nx-X11/lib/X11/os2Stubs.c +++ b/nx-X11/lib/X11/os2Stubs.c @@ -3,26 +3,26 @@ * * * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * HOLGER VEIT 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * HOLGER VEIT 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 Sebastien Marineau or Holger Veit - * shall not be used in advertising or otherwise to promote the sale, use or other + * + * Except as contained in this notice, the name of Sebastien Marineau or Holger Veit + * shall not be used in advertising or otherwise to promote the sale, use or other * dealings in this Software without prior written authorization from Holger Veit or * Sebastien Marineau. * @@ -66,7 +66,7 @@ char *__XOS2RedirRoot(char *fname) return fname; root = (char*)getenv("X11ROOT"); - if (root==0 || + if (root==0 || (fname[1]==':' && isalpha(fname[0])) || (strlen(fname)+strlen(root)+2) > 300) return fname; @@ -131,7 +131,7 @@ BOOL any_ready; int np,ns, i,ready_handles,n; APIRET rc; -sd.have_read=FALSE; sd.have_write=FALSE; +sd.have_read=FALSE; sd.have_write=FALSE; sd.socket_nread=0; sd.socket_nwrite=0; sd.socket_ntotal=0; sd.max_fds=31; ready_handles=0; any_ready=FALSE; sd.pipe_ntotal=0; sd.pipe_have_write=FALSE; @@ -149,7 +149,7 @@ if(FirstTime){ } /* Call these a first time to set the semaphore */ rc = DosCreateEventSem(NULL, &hPipeSem, DC_SEM_SHARED, FALSE); - if(rc) { + if(rc) { fprintf(stderr, "Could not create event semaphore, rc=%d\n",rc); return(-1); } @@ -238,7 +238,7 @@ if(FirstTime){ ready_handles+=np; any_ready = TRUE; } - else if (np == -1) { + else if (np == -1) { return(-1); } } @@ -249,7 +249,7 @@ if(FirstTime){ } else if (ns == -1) {return(-1);} - if (i%8 == 0) { + if (i%8 == 0) { now_millis = os2_get_sys_millis(); if((now_millis-start_millis) > timeout_ms) timeout_ms = 0; } @@ -349,7 +349,7 @@ fd_set *readfds,*writefds; int j,n; memcpy(sd->tcp_select_copy,sd->tcp_select_mask, sd->socket_ntotal*sizeof(int)); - + e = os2_tcp_select(sd->tcp_select_copy,sd->socket_nread, sd->socket_nwrite, 0, 0); @@ -370,7 +370,7 @@ fd_set *readfds,*writefds; n ++; } errno = 0; - + return n; } if(e<0){ @@ -393,7 +393,7 @@ PIPESEMSTATE pipeSemState[128]; APIRET rc; e = 0; rc = DosResetEventSem(hPipeSem,&ulPostCount); - rc = DosQueryNPipeSemState((HSEM) hPipeSem, (PPIPESEMSTATE)&pipeSemState, + rc = DosQueryNPipeSemState((HSEM) hPipeSem, (PPIPESEMSTATE)&pipeSemState, sizeof(pipeSemState)); if(rc) fprintf(stderr,"SELECT: rc from QueryNPipeSem: %d\n",rc); i=0; diff --git a/nx-X11/lib/X11/pathmax.h b/nx-X11/lib/X11/pathmax.h index ffec295e0..86e65fadf 100644 --- a/nx-X11/lib/X11/pathmax.h +++ b/nx-X11/lib/X11/pathmax.h @@ -79,4 +79,3 @@ SOFTWARE. #endif #endif #endif - diff --git a/nx-X11/lib/X11/udcInf.c b/nx-X11/lib/X11/udcInf.c index 9acf0fb3f..9ecf1566e 100644 --- a/nx-X11/lib/X11/udcInf.c +++ b/nx-X11/lib/X11/udcInf.c @@ -46,7 +46,7 @@ from The Open Group. #include /* - external symbols + external symbols */ extern FontData read_EncodingInfo(); extern int _xudc_get_codeset(); @@ -145,11 +145,11 @@ int *num_codeset; if(!_XlcCompareISOLatin1(charset_str,buf)){ num_ret += 1; if(num_ret == 1){ - ret = Xmalloc(sizeof(int)); + ret = Xmalloc(sizeof(int)); } else { int *prev_ret = ret; - ret = Xrealloc(ret, num_ret * sizeof(int)); + ret = Xrealloc(ret, num_ret * sizeof(int)); if (ret == NULL){ Xfree(prev_ret); } @@ -306,9 +306,9 @@ int *num_gr; return 0; } -/* +/* * Code convert wo tomonau UDC area no kakutoku - * GetUDCCPArea() / glyph_to_code() + * GetUDCCPArea() / glyph_to_code() * */ @@ -372,7 +372,7 @@ XlcCharSet charset; sprintf(buf, "csd%d.charset_name", i); _XlcGetLocaleDataBase(lcd, "XLC_CHARSET_DEFINE", buf, &value, &count); if(count > 0){ - if(!_XlcNCompareISOLatin1(value[0], + if(!_XlcNCompareISOLatin1(value[0], charset->name,strlen(value[0])) ){ return(True); } @@ -403,7 +403,7 @@ int size; strcpy(&from[seq_len + name_len],src); return True; } -int +int _xudc_glyph_to_code(locale,charset_str,codeset,glyph_index,codepoint) char *locale; char *charset_str; @@ -429,7 +429,7 @@ unsigned long *codepoint; dst = (unsigned char *)to32; memset(dst,0,25); - + lcd = (XLCd)_XlcGenericLoader(locale); if (!_xudc_gi_to_vgi(lcd,locale,charset_str,codeset, @@ -557,7 +557,7 @@ int *num_cr; /* * code_to_glyph() - * + * */ typedef struct __XUDCGIInf { char *charset_str; @@ -586,7 +586,7 @@ FontScope scope; * * */ -static Bool +static Bool _xudc_vgi_to_gi(lcd,locale,vglyph,glyph,charset,charsetname,size) XLCd lcd; char *locale; @@ -602,7 +602,7 @@ int size; FontData font_data; CodeSet cs; - + for(i=0;;i++){ sprintf(buf, "fs%d.charset.name",i); _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); diff --git a/nx-X11/lib/X11/utlist.h b/nx-X11/lib/X11/utlist.h index 0ce06f2b5..215c2c62e 100644 --- a/nx-X11/lib/X11/utlist.h +++ b/nx-X11/lib/X11/utlist.h @@ -113,3 +113,4 @@ do { for(el=head,tmp=el->next;el;el=tmp,tmp=(el) ? (el->next) : NULL) #endif /* UTLIST_H */ + -- cgit v1.2.3 From 88edf80838c182ec5a533e2ffec429747b128355 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 24 Jun 2013 23:02:05 -0700 Subject: Require ANSI C89 pre-processor, drop pre-C89 token pasting support Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/PutImage.c | 6 ------ nx-X11/lib/X11/Xlibint.h | 28 ---------------------------- nx-X11/lib/X11/globals.c | 6 ------ 3 files changed, 40 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/PutImage.c b/nx-X11/lib/X11/PutImage.c index 2a694f099..934fabe0f 100644 --- a/nx-X11/lib/X11/PutImage.c +++ b/nx-X11/lib/X11/PutImage.c @@ -600,15 +600,9 @@ static int const HalfOrderWord[12] = { /* Cancel a GetReq operation, before doing _XSend or Data */ -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) #define UnGetReq(name)\ dpy->bufptr -= SIZEOF(x##name##Req);\ dpy->request-- -#else -#define UnGetReq(name)\ - dpy->bufptr -= SIZEOF(x/**/name/**/Req);\ - dpy->request-- -#endif static void SendXYImage( diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index 31bec58f9..d4767ecfc 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -460,14 +460,8 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); /* GetReqSized is the same as GetReq but allows the caller to specify the * size in bytes. 'sz' must be a multiple of 4! */ -#if !defined(UNIXCPP) || defined(ANSICPP) #define GetReqSized(name, sz, req) \ req = (x##name##Req *) _XGetRequest(dpy, X_##name, sz) -#else -#define GetReqSized(name, sz, req) \ - req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, sz) -#endif - /* * GetReq - Get the next available X request packet in the buffer and @@ -478,25 +472,14 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); * */ -#if !defined(UNIXCPP) || defined(ANSICPP) #define GetReq(name, req) \ GetReqSized(name, SIZEOF(x##name##Req), req) -#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ -#define GetReq(name, req) \ - GetReqSized(name, SIZEOF(x/**/name/**/Req), req) -#endif /* GetReqExtra is the same as GetReq, but allocates "n" additional bytes after the request. "n" must be a multiple of 4! */ -#if !defined(UNIXCPP) || defined(ANSICPP) #define GetReqExtra(name, n, req) \ GetReqSized(name, SIZEOF(x##name##Req) + n, req) -#else -#define GetReqExtra(name, n, req) \ - GetReqSized(name, SIZEOF(x/**/name/**/Req) + n, req) -#endif - /* * GetResReq is for those requests that have a resource ID @@ -504,27 +487,16 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len); * "rid" is the name of the resource. */ -#if !defined(UNIXCPP) || defined(ANSICPP) #define GetResReq(name, rid, req) \ req = (xResourceReq *) _XGetRequest(dpy, X_##name, SIZEOF(xResourceReq)); \ req->id = (rid) -#else -#define GetResReq(name, rid, req) \ - req = (xResourceReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xResourceReq)); \ - req->id = (rid) -#endif /* * GetEmptyReq is for those requests that have no arguments * at all. */ -#if !defined(UNIXCPP) || defined(ANSICPP) #define GetEmptyReq(name, req) \ req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq)) -#else -#define GetEmptyReq(name, req) \ - req = (xReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xReq)) -#endif /* * MakeBigReq sets the CARD16 "req->length" to 0 and inserts a new CARD32 diff --git a/nx-X11/lib/X11/globals.c b/nx-X11/lib/X11/globals.c index bcc49486e..efae2f8bb 100644 --- a/nx-X11/lib/X11/globals.c +++ b/nx-X11/lib/X11/globals.c @@ -53,15 +53,9 @@ from The Open Group. /* * If we need to define extra variables for each global */ -#if !defined(UNIXCPP) || defined(ANSICPP) #define ZEROINIT(t,var,val) SetZero(t,var,val); \ SetZero (long, _libX_##var##Flag, 0); \ SetZero (void *, _libX_##var##Ptr, NULL) -#else /* else pcc concatenation */ -#define ZEROINIT(t,var,val) SetZero(t,var,val); \ - SetZero (long, _libX_/**/var/**/Flag, 0); \ - SetZero (void *, _libX_/**/var/**/Ptr, NULL) -#endif /* concat ANSI C vs. pcc */ #else /* else not USL_SHAREDLIB */ /* -- cgit v1.2.3 From d122d75454c9e9dbd0f2c51c259387e9182d70ec Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 25 Jun 2013 18:31:32 +0200 Subject: Stop truncating source to destination length if it is larger. It seems useless to do that since the code tests for both source length and destination to be non-zero. This fixes a cut'n'paste problem in xterm where the paste length was limited to 1024 (BUFSIZ) in button.c. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcGenConv.c | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 42d63c529..1041dc709 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -764,9 +764,6 @@ mbstowcs_org( return( 0 ); } - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { ch = *inbufptr++; @@ -921,9 +918,6 @@ wcstombs_org( int defstr_len = strlen(default_string); - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { wc = *inbufptr++; @@ -1080,9 +1074,6 @@ wcstocts( int from_size = *from_left; char *ext_seg_len = NULL; - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { wc = *inbufptr++; @@ -1272,9 +1263,6 @@ ctstowcs( return( 0 ); } - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { ch = *inbufptr++; @@ -1666,9 +1654,6 @@ mbstostr( return( 0 ); } - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { ch = *inbufptr++; @@ -1956,10 +1941,6 @@ wcstostr( const char *default_string = XLC_PUBLIC(lcd, default_string); int defstr_len = strlen(default_string); - - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { wc = *inbufptr++; @@ -2114,9 +2095,6 @@ wctocs( char *outbufptr = *to; int from_size = *from_left; - if (*from_left > *to_left) - *from_left = *to_left; - if (*from_left && *to_left) { wc = *inbufptr++; @@ -2427,9 +2405,6 @@ strtombs( char *outbufptr = *to; int from_size = *from_left; - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { ch = *inbufptr++; @@ -2537,9 +2512,6 @@ strtowcs( wchar_t *outbufptr = (wchar_t *)*to; int from_size = *from_left; - if (*from_left > *to_left) - *from_left = *to_left; - while (*from_left && *to_left) { ch = *inbufptr++; -- cgit v1.2.3 From 61fdf93ef56818c081fb775a17fdc513315957c3 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 25 Jun 2013 18:33:56 +0200 Subject: Check for symbol existence with #ifdef, not #if Reviewed-by: Jamey Sharp Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 4c4e80e6a..564d318fc 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -901,7 +901,7 @@ void _XSeqSyncFunction( static int _XPrivSyncFunction (Display *dpy) { -#if XTHREADS +#ifdef XTHREADS assert(!dpy->lock_fns); #endif assert(dpy->synchandler == _XPrivSyncFunction); -- cgit v1.2.3 From ac3d26251f8de17839dbdada457ffcd670338d0a Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 25 Jun 2013 18:34:32 +0200 Subject: Fix out-of-range comparison in _XF86BigfontQueryFont clang complained (correctly): warning: comparison of constant 768614336404564650 with expression of type 'CARD32' (aka 'unsigned int') is always true [-Wtautological-constant-out-of-range-compare] [While LONG_MAX is correct, since it's used in size_t math, the numbers have to be limited to 32-bit range to be usable by 32-bit clients, and values beyond that range are far more likely to be bugs in the data from the server than valid numbers of characters in a font. -alan- ] Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index d48b7d0ff..26f29d301 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -588,7 +588,7 @@ _XF86BigfontQueryFont ( if (!(extcodes->serverCapabilities & CAP_VerifiedLocal)) { struct shmid_ds buf; if (!(shmctl(reply.shmid, IPC_STAT, &buf) >= 0 - && reply.nCharInfos < (LONG_MAX / sizeof(XCharStruct)) + && reply.nCharInfos < (INT_MAX / sizeof(XCharStruct)) && buf.shm_segsz >= reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct) + sizeof(CARD32) && *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) { shmdt(addr); -- cgit v1.2.3 From 39c6e5aa859c633fcb48e299643bb0189f333a0d Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 25 Jun 2013 22:35:29 +0200 Subject: Tighten out-of-range comparisons. [For all of these, LONG_MAX was the correct value to prevent overflows for the recent CVEs. Lowering to INT_MAX catches buggy replies from the server that 32-bit clients would reject but 64-bit would accept, so we catch bugs sooner, and really, no sane & working server should ever report more than 2gb of extension names, font path entries, key modifier maps, etc. -alan- ] Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FontNames.c | 2 +- nx-X11/lib/X11/GetFPath.c | 2 +- nx-X11/lib/X11/ListExt.c | 2 +- nx-X11/lib/X11/ModMap.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FontNames.c b/nx-X11/lib/X11/FontNames.c index b5bc7b4ba..764711559 100644 --- a/nx-X11/lib/X11/FontNames.c +++ b/nx-X11/lib/X11/FontNames.c @@ -66,7 +66,7 @@ int *actualCount) /* RETURN */ if (rep.nFonts) { flist = Xmalloc (rep.nFonts * sizeof(char *)); - if (rep.length < (LONG_MAX >> 2)) { + if (rep.length < (INT_MAX >> 2)) { rlen = rep.length << 2; ch = Xmalloc(rlen + 1); /* +1 to leave room for last null-terminator */ diff --git a/nx-X11/lib/X11/GetFPath.c b/nx-X11/lib/X11/GetFPath.c index abd4a5dbd..8f8c6144a 100644 --- a/nx-X11/lib/X11/GetFPath.c +++ b/nx-X11/lib/X11/GetFPath.c @@ -50,7 +50,7 @@ char **XGetFontPath( if (rep.nPaths) { flist = Xmalloc(rep.nPaths * sizeof (char *)); - if (rep.length < (LONG_MAX >> 2)) { + if (rep.length < (INT_MAX >> 2)) { nbytes = (unsigned long) rep.length << 2; ch = Xmalloc (nbytes + 1); /* +1 to leave room for last null-terminator */ diff --git a/nx-X11/lib/X11/ListExt.c b/nx-X11/lib/X11/ListExt.c index e925c4773..59599d1a6 100644 --- a/nx-X11/lib/X11/ListExt.c +++ b/nx-X11/lib/X11/ListExt.c @@ -55,7 +55,7 @@ char **XListExtensions( if (rep.nExtensions) { list = Xmalloc (rep.nExtensions * sizeof (char *)); - if (rep.length < (LONG_MAX >> 2)) { + if (rep.length < (INT_MAX >> 2)) { rlen = rep.length << 2; ch = Xmalloc (rlen + 1); /* +1 to leave room for last null-terminator */ diff --git a/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index 5c5b42612..04cd676eb 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/ModMap.c @@ -42,7 +42,7 @@ XGetModifierMapping(register Display *dpy) GetEmptyReq(GetModifierMapping, req); (void) _XReply (dpy, (xReply *)&rep, 0, xFalse); - if (rep.length < (LONG_MAX >> 2)) { + if (rep.length < (INT_MAX >> 2)) { nbytes = (unsigned long)rep.length << 2; res = Xmalloc(sizeof (XModifierKeymap)); if (res) -- cgit v1.2.3 From ea8239650656846d810a93e7659e182e412f07b3 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Sun, 9 Jun 2013 11:13:42 -0700 Subject: libX11: check size of GetReqExtra after XFlush Two users of GetReqExtra pass arbitrarily sized allocations from the caller (ModMap and Host). Adjust _XGetRequest() (called by the GetReqExtra macro) to double-check the requested length and invalidate "req" when this happens. Users of GetReqExtra passing lengths greater than the Xlib buffer size (normally 16K) must check "req" and fail gracefully instead of crashing. Any callers of GetReqExtra that do not check "req" for NULL will experience this change, in the pathological case, as a NULL dereference instead of a buffer overflow. This is an improvement, but the documentation for GetReqExtra has been updated to reflect the need to check the value of "req" after the call. Bug that manifested the problem: https://bugs.launchpad.net/ubuntu/+source/x11-xserver-utils/+bug/792628 Signed-off-by: Kees Cook Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ModMap.c | 10 +++++++--- nx-X11/lib/X11/XlibInt.c | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index 04cd676eb..3c6971c77 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/ModMap.c @@ -65,9 +65,9 @@ XGetModifierMapping(register Display *dpy) /* * Returns: - * 0 Success - * 1 Busy - one or more old or new modifiers are down - * 2 Failed - one or more new modifiers unacceptable + * MappingSuccess (0) Success + * MappingBusy (1) Busy - one or more old or new modifiers are down + * MappingFailed (2) Failed - one or more new modifiers unacceptable */ int XSetModifierMapping( @@ -80,6 +80,10 @@ XSetModifierMapping( LockDisplay(dpy); GetReqExtra(SetModifierMapping, mapSize, req); + if (!req) { + UnlockDisplay(dpy); + return MappingFailed; + } req->numKeyPerModifier = modifier_map->max_keypermod; diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 564d318fc..deab8b3ad 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -3980,6 +3980,14 @@ void *_XGetRequest(Display *dpy, CARD8 type, size_t len) if (dpy->bufptr + len > dpy->bufmax) _XFlush(dpy); + /* Request still too large, so do not allow it to overflow. */ + if (dpy->bufptr + len > dpy->bufmax) { + fprintf(stderr, + "Xlib: request %d length %zd would exceed buffer size.\n", + type, len); + /* Changes failure condition from overflow to NULL dereference. */ + return NULL; + } if (len % 4) fprintf(stderr, -- cgit v1.2.3 From 6d64c4164c0c2269b1b5a998f1869a6419c3471d Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 23 Jul 2013 22:11:34 -0700 Subject: XSetModifierMapping: Use Data instead of GetReqExtra Handle arbitrary length data in the same fashion as other calls, avoiding need to ensure it fits all in the request buffer. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ModMap.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index 3c6971c77..2fabc560c 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/ModMap.c @@ -79,17 +79,11 @@ XSetModifierMapping( int mapSize = modifier_map->max_keypermod << 3; /* 8 modifiers */ LockDisplay(dpy); - GetReqExtra(SetModifierMapping, mapSize, req); - if (!req) { - UnlockDisplay(dpy); - return MappingFailed; - } - + GetReq(SetModifierMapping, req); + req->length += mapSize >> 2; req->numKeyPerModifier = modifier_map->max_keypermod; - memcpy((char *) NEXTPTR(req,xSetModifierMappingReq), - (char *) modifier_map->modifiermap, - mapSize); + Data(dpy, modifier_map->modifiermap, mapSize); (void) _XReply(dpy, (xReply *) & rep, (SIZEOF(xSetModifierMappingReply) - SIZEOF(xReply)) >> 2, xTrue); -- cgit v1.2.3 From adcf3894aa3663b1debba412a85104a5c17fc3bb Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 27 Jul 2013 01:03:18 -0700 Subject: omGeneric: remove space between struct name & member name Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 1b017cb21..758d24ab4 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -1163,7 +1163,7 @@ parse_fontname( * a "missing_charset" will be reported to the client * for this CharSet. */ - font_data_return. xlfd_name = NULL; + font_data_return.xlfd_name = NULL; font_data_return.side = XlcUnknown; ret = parse_fontdata(oc, font_set, font_set->font_data, -- cgit v1.2.3 From ed53aca1d68a5d7511b1304f11a43ba80885fbe2 Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Thu, 16 Jun 2011 17:28:39 +0200 Subject: XIM: Fix race on focus change: set 'FABRICATED' only when keyev filters in place. When synthesized key events are sent on commit XIM sets the 'fabricated' flag so that the keypress handler knows that these were not real events. This also happens when committing due to the loss of focus. However in this case the keypress/release filters which consume and unset this flag are no longer in the filter chain. So the flag is erronously set when a real keyboard event is received after focus has been regained. So the first event is wrongly treated as a fabricated key in the keypress handler which will at the same time reset the flag so the second key event is treated correctly. This fix only sets the flag when at least one of the keyboard filters is in place. How to reproduce this bug: run scim, choose a Japanese input method start two instances of xterm: start typing in one xterm (this should pop up an IM window). Without comitting (hitting 'enter') move focus to the other xterm, then move focus back. Start typing again. The first character will be committed immediately without popping up an input window. With this fix this behavior is gone. See also: https://bugzilla.novell.com/show_bug.cgi?id=239698 Signed-off-by: Egbert Eich Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imDefLkup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index 0ce3f787a..8a6b7e5a9 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -704,7 +704,9 @@ _XimCommitRecv( (void)_XimRespSyncReply(ic, flag); - MARK_FABRICATED(im); + if (ic->private.proto.registed_filter_event + & (KEYPRESS_MASK | KEYRELEASE_MASK)) + MARK_FABRICATED(im); ev.type = KeyPress; ev.send_event = False; -- cgit v1.2.3 From ce482d4fd8fe565810391b0ac89e4b1ac8fd7212 Mon Sep 17 00:00:00 2001 From: "ISHIKAWA,chiaki" Date: Tue, 18 Dec 2012 15:28:05 +0000 Subject: Fix bogus timestamp generated by XIM Fix bogus timestamp generted by XIM due to uninitialized data field. Also set appropriate serial, too. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=39367 Signed-off-by: Chiaki ISHIKAWA Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imDefLkup.c | 13 +++++++++++++ nx-X11/lib/X11/imTrans.c | 8 ++++++++ 2 files changed, 21 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index 8a6b7e5a9..3317831e6 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -269,6 +269,8 @@ _XimForwardEventCore( int ret_code; INT16 len; + bzero(buf32, sizeof(buf32)); /* valgrind noticed uninitialized memory use! */ + if (!(len = _XimSetEventToWire(ev, (xEvent *)&buf_s[4]))) return False; /* X event */ @@ -708,6 +710,8 @@ _XimCommitRecv( & (KEYPRESS_MASK | KEYRELEASE_MASK)) MARK_FABRICATED(im); + bzero(&ev, sizeof(ev)); /* uninitialized : found when running kterm under valgrind */ + ev.type = KeyPress; ev.send_event = False; ev.display = im->core.display; @@ -715,6 +719,15 @@ _XimCommitRecv( ev.keycode = 0; ev.state = 0; + ev.time = 0L; + ev.serial = LastKnownRequestProcessed(im->core.display); + /* FIXME : + I wish there were COMMENTs (!) about the data passed around. + */ +#if 0 + fprintf(stderr,"%s,%d: putback k press FIXED ev.time=0 ev.serial=%lu\n", __FILE__, __LINE__, ev.serial); +#endif + XPutBackEvent(im->core.display, (XEvent *)&ev); return True; diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index f06759f88..3cea659f9 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -222,12 +222,20 @@ _XimTransInternalConnection( if (spec->is_putback) return; + + bzero(&ev, sizeof(ev)); /* FIXME: other fields may be accessed, too. */ kev = (XKeyEvent *)&ev; kev->type = KeyPress; kev->send_event = False; kev->display = im->core.display; kev->window = spec->window; kev->keycode = 0; + kev->time = 0L; + kev->serial = LastKnownRequestProcessed(im->core.display); +#if 0 + fprintf(stderr,"%s,%d: putback FIXED kev->time=0 kev->serial=%lu\n", __FILE__, __LINE__, kev->serial); +#endif + XPutBackEvent(im->core.display, &ev); XFlush(im->core.display); spec->is_putback = True; -- cgit v1.2.3 From 7bca34528c6e693ce086cd8ddc92ede467448767 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 9 Aug 2013 22:00:09 -0700 Subject: Fix file leak on malloc error in XlcDL.c:resolve_object() File Leak: Leaked File fp at line 219 of lib/libX11/nx-X11/lib/X11/XlcDL.c in function 'resolve_object'. fp initialized at line 198 with fopen [ This bug was found by the Parfait 1.2.0 bug checking tool. http://labs.oracle.com/pls/apex/f?p=labs:49:::::P49_PROJECT_ID:13 ] Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 75e193c05..79e8a2f8d 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -216,7 +216,8 @@ Limit the length of path to prevent stack buffer corruption. xi18n_objects_list = (XI18NObjectsList) Xrealloc(xi18n_objects_list, sizeof(XI18NObjectsListRec) * lc_len); - if (!xi18n_objects_list) return; + if (!xi18n_objects_list) + goto done; } n = parse_line(p, args, 6); @@ -244,6 +245,7 @@ Limit the length of path to prevent stack buffer corruption. lc_count++; } } + done: fclose(fp); } -- cgit v1.2.3 From bde3d8b141ff42c1f6828e5ed1467b691e54b253 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 9 Aug 2013 23:02:12 -0700 Subject: lcfile: skip over any null entries in args list Previous code seemed to assume that printf("%s", NULL) would result in a 0-length string, not "(null)" or similar, but since there's no point looking for files in "(null)/filepath...", instead we just skip over NULL entries in search paths when generating file names. In the *DirName() functions, this effectively just moves the "bail on NULL in arg[i]" check up from the later code that assigned it to targetdir and then bailed if that was NULL. Not sure how there ever could be a NULL in arg[i], given the current implementation of XlcParsePath, but it's easy enough to check once and reject up front instead of on every reference. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcFile.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index aeaae245d..3b239ff2f 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -486,8 +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) { + if ((5 + strlen(args[i]) + strlen(cat)) < PATH_MAX) { sprintf(buf, "%s/%s.dir", args[i], cat); name = resolve_name(siname, buf, RtoL); } @@ -498,7 +501,7 @@ _XlcFileName( /* supposed to be absolute path name */ file_name = name; } else { - file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) + + file_name = Xmalloc(2 + strlen(args[i]) + (name ? strlen (name) : 0)); if (file_name != NULL) sprintf(file_name, "%s/%s", args[i], name); @@ -535,8 +538,10 @@ _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) { + if (args[i] == NULL) + continue; + + if ((2 + strlen (args[i]) + strlen (locale_alias)) < PATH_MAX) { sprintf (buf, "%s/%s", args[i], locale_alias); name = resolve_name (lc_name, buf, LtoR); if (!name) { @@ -633,9 +638,10 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) xlocaledir (dir, PATH_MAX); n = _XlcParsePath(dir, args, 256); for (i = 0; i < n; ++i) { + if (args[i] == NULL) + continue; - if ((2 + (args[i] ? strlen(args[i]) : 0) + - strlen(locale_alias)) < PATH_MAX) { + if ((2 + strlen(args[i]) + strlen(locale_alias)) < PATH_MAX) { sprintf (buf, "%s/%s", args[i], locale_alias); name = resolve_name(lc_name, buf, LtoR); if (!name) { @@ -653,12 +659,6 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *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); @@ -731,9 +731,10 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) xlocalelibdir (dir, PATH_MAX); n = _XlcParsePath(dir, args, 256); for (i = 0; i < n; ++i) { + if (args[i] == NULL) + continue; - if ((2 + (args[i] ? strlen(args[i]) : 0) + - strlen(locale_alias)) < PATH_MAX) { + if ((2 + strlen(args[i]) + strlen(locale_alias)) < PATH_MAX) { sprintf (buf, "%s/%s", args[i], locale_alias); name = resolve_name(lc_name, buf, LtoR); if (!name) { @@ -751,12 +752,6 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *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); -- cgit v1.2.3 From a1b0fdb2c9852c48ede8e3bc2a7049d707188fd1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 9 Aug 2013 23:02:12 -0700 Subject: xlibi18n: convert sprintf calls to snprintf Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 7 +----- nx-X11/lib/X11/lcDynamic.c | 4 ++-- nx-X11/lib/X11/lcFile.c | 31 +++++++++++-------------- nx-X11/lib/X11/lcGeneric.c | 58 ++++++++++++++++++++++++---------------------- nx-X11/lib/X11/lcUTF8.c | 8 +++---- 5 files changed, 51 insertions(+), 57 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 79e8a2f8d..02860a028 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -189,12 +189,7 @@ resolve_object(char *path, const char *lc_name) 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; diff --git a/nx-X11/lib/X11/lcDynamic.c b/nx-X11/lib/X11/lcDynamic.c index f6df94cbb..3821bfff1 100644 --- a/nx-X11/lib/X11/lcDynamic.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index 3b239ff2f..65ea652d0 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -490,8 +490,7 @@ _XlcFileName( continue; name = NULL; - if ((5 + strlen(args[i]) + 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) { @@ -501,13 +500,13 @@ _XlcFileName( /* supposed to be absolute path name */ file_name = name; } else { - file_name = Xmalloc(2 + strlen(args[i]) + - (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); @@ -541,8 +540,8 @@ _XlcResolveLocaleName( if (args[i] == NULL) continue; - if ((2 + strlen (args[i]) + 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) @@ -641,8 +640,8 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) if (args[i] == NULL) continue; - if ((2 + strlen(args[i]) + 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) @@ -659,8 +658,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) /* look at locale.dir */ target_dir = args[i]; - if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { - sprintf(buf, "%s/locale.dir", target_dir); + if (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) { target_name = resolve_name(name, buf, RtoL); } if (name != lc_name) @@ -734,8 +732,8 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) if (args[i] == NULL) continue; - if ((2 + strlen(args[i]) + 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) @@ -752,8 +750,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) /* look at locale.dir */ target_dir = args[i]; - if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { - sprintf(buf, "%s/locale.dir", target_dir); + if (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) { target_name = resolve_name(name, buf, RtoL); } if (name != lc_name) diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index 619cb47f9..f604fe23d 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -428,17 +428,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); @@ -470,21 +470,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); @@ -495,7 +495,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); @@ -511,7 +511,7 @@ read_charset_define( 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); @@ -565,10 +565,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 && @@ -585,7 +585,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; @@ -597,7 +597,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; @@ -609,7 +609,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); @@ -617,7 +617,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); @@ -635,6 +635,7 @@ create_ctextseg( ExtdSegment ret; char* ptr; char* cset_name = NULL; + size_t cset_len; int i,new; FontScope scope; ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec)); @@ -645,7 +646,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); @@ -657,10 +659,10 @@ 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; @@ -731,10 +733,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; @@ -761,7 +763,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) @@ -772,7 +774,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 { @@ -808,7 +810,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) @@ -819,7 +821,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; @@ -861,7 +863,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) { @@ -896,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); @@ -908,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); @@ -920,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/nx-X11/lib/X11/lcUTF8.c b/nx-X11/lib/X11/lcUTF8.c index 3e934b713..84d87772f 100644 --- a/nx-X11/lib/X11/lcUTF8.c +++ b/nx-X11/lib/X11/lcUTF8.c @@ -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; @@ -1749,10 +1749,10 @@ create_tofontcs_conv( /* 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; -- cgit v1.2.3 From d03ab1de0b68290291e2b74834b0c7dbe8b6df21 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 9 Aug 2013 23:30:30 -0700 Subject: ximcp/imRm.c: convert sprintf calls to snprintf Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRm.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index 34c9bfa35..a7565d94b 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -75,8 +75,10 @@ _XimSetProtoResource(im) { char res_name_buf[256]; char* res_name; + size_t res_name_len; char res_class_buf[256]; char* res_class; + size_t res_class_len; char* str_type; XrmValue value; XIMStyle preedit_style = 0; @@ -90,17 +92,31 @@ _XimSetProtoResource(im) if (!im->core.rdb) return; - if (strlen (im->core.res_name) < 200) res_name = res_name_buf; - else res_name = Xmalloc (strlen (im->core.res_name) + 50); - if (strlen (im->core.res_class) < 200) res_class = res_class_buf; - else res_class = Xmalloc (strlen (im->core.res_class) + 50); + res_name_len = strlen (im->core.res_name); + if (res_name_len < 200) { + res_name = res_name_buf; + res_name_len = sizeof(res_name_buf); + } + else { + res_name_len += 50; + res_name = Xmalloc (res_name_len); + } + res_class_len = strlen (im->core.res_class); + if (res_class_len < 200) { + res_class = res_class_buf; + res_class_len = sizeof(res_class_buf); + } + else { + res_class_len += 50; + res_class = Xmalloc (res_class_len); + } /* pretend malloc always works */ - (void) sprintf (res_name, "%s%s%s", + (void) snprintf (res_name, res_name_len, "%s%s%s", im->core.res_name != NULL ? im->core.res_name : "*", im->core.res_name != NULL ? dotximdot : ximdot, "useAuth"); - (void) sprintf (res_class, "%s%s%s", + (void) snprintf (res_class, res_class_len, "%s%s%s", im->core.res_class != NULL ? im->core.res_class : "*", im->core.res_class != NULL ? dotXimdot : Ximdot, "UseAuth"); @@ -111,11 +127,11 @@ _XimSetProtoResource(im) } } - (void) sprintf (res_name, "%s%s%s", + (void) snprintf (res_name, res_name_len, "%s%s%s", im->core.res_name != NULL ? im->core.res_name : "*", im->core.res_name != NULL ? dotximdot : ximdot, "delaybinding"); - (void) sprintf (res_class, "%s%s%s", + (void) snprintf (res_class, res_class_len, "%s%s%s", im->core.res_class != NULL ? im->core.res_class : "*", im->core.res_class != NULL ? dotXimdot : Ximdot, "Delaybinding"); @@ -126,11 +142,11 @@ _XimSetProtoResource(im) } } - (void) sprintf (res_name, "%s%s%s", + (void) snprintf (res_name, res_name_len, "%s%s%s", im->core.res_name != NULL ? im->core.res_name : "*", im->core.res_name != NULL ? dotximdot : ximdot, "reconnect"); - (void) sprintf (res_class, "%s%s%s", + (void) snprintf (res_class, res_class_len, "%s%s%s", im->core.res_class != NULL ? im->core.res_class : "*", im->core.res_class != NULL ? dotXimdot : Ximdot, "Reconnect"); @@ -147,11 +163,11 @@ _XimSetProtoResource(im) return; } - (void) sprintf (res_name, "%s%s%s", + (void) snprintf (res_name, res_name_len, "%s%s%s", im->core.res_name != NULL ? im->core.res_name : "*", im->core.res_name != NULL ? dotximdot : ximdot, "preeditDefaultStyle"); - (void) sprintf (res_class, "%s%s%s", + (void) snprintf (res_class, res_class_len, "%s%s%s", im->core.res_class != NULL ? im->core.res_class : "*", im->core.res_class != NULL ? dotXimdot : Ximdot, "PreeditDefaultStyle"); @@ -170,11 +186,11 @@ _XimSetProtoResource(im) if(!preedit_style) preedit_style = XIMPreeditNothing; - (void) sprintf (res_name, "%s%s%s", + (void) snprintf (res_name, res_name_len, "%s%s%s", im->core.res_name != NULL ? im->core.res_name : "*", im->core.res_name != NULL ? dotximdot : ximdot, "statusDefaultStyle"); - (void) sprintf (res_class, "%s%s%s", + (void) snprintf (res_class, res_class_len, "%s%s%s", im->core.res_class != NULL ? im->core.res_class : "*", im->core.res_class != NULL ? dotXimdot : Ximdot, "StatusDefaultStyle"); -- cgit v1.2.3 From a6d9409b060a23ad709a03a14518091cab55ee3e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 9 Aug 2013 23:33:03 -0700 Subject: omGeneric.c: convert sprintf calls to snprintf Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 758d24ab4..2c5e8dd06 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -585,7 +585,8 @@ get_rotate_fontname( } } pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]); - sprintf(str_pixel, "[ 0 ~%d %d 0 ]", pixel_size, pixel_size); + snprintf(str_pixel, sizeof(str_pixel), + "[ 0 ~%d %d 0 ]", pixel_size, pixel_size); fields[6] = str_pixel; /* Point Size field : fields[7] */ @@ -1960,7 +1961,7 @@ static void read_vw( char **value, buf[BUFSIZ]; int count; - sprintf(buf, "fs%d.font.vertical_map", num); + snprintf(buf, sizeof(buf), "fs%d.font.vertical_map", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count > 0){ _XlcDbg_printValue(buf,value,count); @@ -1968,7 +1969,7 @@ static void read_vw( font_set->vmap = read_EncodingInfo(count,value); } - sprintf(buf, "fs%d.font.vertical_rotate", num); + snprintf(buf, sizeof(buf), "fs%d.font.vertical_rotate", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count > 0){ _XlcDbg_printValue(buf,value,count); @@ -2004,11 +2005,11 @@ init_om( for (num = 0; ; num++) { - sprintf(buf, "fs%d.charset.name", num); + snprintf(buf, sizeof(buf), "fs%d.charset.name", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if( count < 1){ - sprintf(buf, "fs%d.charset", num); + snprintf(buf, sizeof(buf), "fs%d.charset", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) break; @@ -2027,7 +2028,7 @@ init_om( while (count-- > 0){ *charset_list++ = _XlcGetCharSet(*value++); } - sprintf(buf, "fs%d.charset.udc_area", num); + snprintf(buf, sizeof(buf), "fs%d.charset.udc_area", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if( count > 0){ UDCArea udc; @@ -2051,10 +2052,10 @@ init_om( } } - sprintf(buf, "fs%d.font.primary", num); + snprintf(buf, sizeof(buf), "fs%d.font.primary", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1){ - sprintf(buf, "fs%d.font", num); + snprintf(buf, sizeof(buf), "fs%d.font", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) return False; @@ -2067,7 +2068,7 @@ init_om( data->font_data = font_data; data->font_data_count = count; - sprintf(buf, "fs%d.font.substitute", num); + snprintf(buf, sizeof(buf), "fs%d.font.substitute", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count > 0){ font_data = read_EncodingInfo(count,value); @@ -2076,7 +2077,7 @@ init_om( data->substitute = font_data; data->substitute_num = count; } else { - sprintf(buf, "fs%d.font", num); + snprintf(buf, sizeof(buf), "fs%d.font", num); _XlcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); if (count < 1) { data->substitute = NULL; -- cgit v1.2.3 From 0574a55ebd9243cd8d0a5d0ee6161c598f99aef4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 11:07:47 -0700 Subject: Avoid memory leak/corruption if realloc fails in XlcDL.c:resolve_object() Previously, if realloc failed to increase the size, we'd still record that we had allocated the larger size, but the pointer to it would be NULL, causing future calls to be broken, and the previous allocation to be lost/leaked. Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 02860a028..2bef4ac12 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -207,12 +207,13 @@ resolve_object(char *path, const char *lc_name) } 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) + 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); -- cgit v1.2.3 From 7156a20bc9c211becd299a264cce5db350147362 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 12:30:39 -0700 Subject: lcDB.c: ensure buffer size is updated correctly if realloc fails Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDB.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcDB.c b/nx-X11/lib/X11/lcDB.c index 027d7747b..cb509d273 100644 --- a/nx-X11/lib/X11/lcDB.c +++ b/nx-X11/lib/X11/lcDB.c @@ -210,11 +210,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; -- cgit v1.2.3 From 180991ce21c79c9a2816a5cbddc5232555fc954c Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 12:07:51 -0700 Subject: Avoid memory leak/corruption if realloc fails in imLcPrs.c:parseline() Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcPrs.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcPrs.c b/nx-X11/lib/X11/imLcPrs.c index ad65da694..7745c53d2 100644 --- a/nx-X11/lib/X11/imLcPrs.c +++ b/nx-X11/lib/X11/imLcPrs.c @@ -574,9 +574,12 @@ parseline( if (token == STRING) { l = strlen(tokenbuf) + 1; while (b->mbused + l > b->mbsize) { - b->mbsize = b->mbsize ? b->mbsize * 1.5 : 1024; - if (! (b->mb = Xrealloc (b->mb, b->mbsize)) ) + DTCharIndex newsize = b->mbsize ? b->mbsize * 1.5 : 1024; + char *newmb = Xrealloc (b->mb, newsize); + if (newmb == NULL) goto error; + b->mb = newmb; + b->mbsize = newsize; } rhs_string_mb = &b->mb[b->mbused]; b->mbused += l; @@ -604,9 +607,12 @@ parseline( l = get_mb_string(im, local_mb_buf, rhs_keysym); while (b->mbused + l + 1 > b->mbsize) { - b->mbsize = b->mbsize ? b->mbsize * 1.5 : 1024; - if (! (b->mb = Xrealloc (b->mb, b->mbsize)) ) + DTCharIndex newsize = b->mbsize ? b->mbsize * 1.5 : 1024; + char *newmb = Xrealloc (b->mb, newsize); + if (newmb == NULL) goto error; + b->mb = newmb; + b->mbsize = newsize; } rhs_string_mb = &b->mb[b->mbused]; b->mbused += l + 1; @@ -621,9 +627,12 @@ parseline( local_wc_buf[l] = (wchar_t)'\0'; } while (b->wcused + l + 1 > b->wcsize) { - b->wcsize = b->wcsize ? b->wcsize * 1.5 : 512; - if (! (b->wc = Xrealloc (b->wc, sizeof(wchar_t) * b->wcsize)) ) + DTCharIndex newsize = b->wcsize ? b->wcsize * 1.5 : 512; + wchar_t *newwc = Xrealloc (b->wc, sizeof(wchar_t) * newsize); + if (newwc == NULL) goto error; + b->wc = newwc; + b->wcsize = newsize; } rhs_string_wc = &b->wc[b->wcused]; b->wcused += l + 1; @@ -634,9 +643,12 @@ parseline( local_utf8_buf[l] = '\0'; } while (b->utf8used + l + 1 > b->utf8size) { - b->utf8size = b->utf8size ? b->utf8size * 1.5 : 1024; - if (! (b->utf8 = Xrealloc (b->utf8, b->utf8size)) ) + DTCharIndex newsize = b->utf8size ? b->utf8size * 1.5 : 1024; + char *newutf8 = Xrealloc (b->utf8, b->utf8size); + if (newutf8 == NULL) goto error; + b->utf8 = newutf8; + b->utf8size = newsize; } rhs_string_utf8 = &b->utf8[b->utf8used]; b->utf8used += l + 1; @@ -657,9 +669,12 @@ parseline( while (b->treeused >= b->treesize) { DefTree *old = b->tree; int oldsize = b->treesize; - b->treesize = b->treesize ? b->treesize * 1.5 : 256; - if (! (b->tree = Xrealloc (b->tree, sizeof(DefTree) * b->treesize)) ) + int newsize = b->treesize ? b->treesize * 1.5 : 256; + DefTree *new = Xrealloc (b->tree, sizeof(DefTree) * newsize); + if (new == NULL) goto error; + b->tree = new; + b->treesize = newsize; if (top >= (DTIndex *) old && top < (DTIndex *) &old[oldsize]) top = (DTIndex *) (((char *) top) + (((char *)b->tree)-(char *)old)); } -- cgit v1.2.3 From 105cd4711219e8f47e21fde03ab2accffbd5d451 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 11:27:22 -0700 Subject: Avoid memory leak/corruption if realloc fails in Xregion.h:MEMCHECK macro Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xregion.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xregion.h b/nx-X11/lib/X11/Xregion.h index 1c36db144..4f55af82f 100644 --- a/nx-X11/lib/X11/Xregion.h +++ b/nx-X11/lib/X11/Xregion.h @@ -113,10 +113,11 @@ typedef struct _XRegion { */ #define MEMCHECK(reg, rect, firstrect){\ if ((reg)->numRects >= ((reg)->size - 1)){\ - (firstrect) = (BOX *) Xrealloc \ - ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\ - if ((firstrect) == 0)\ + BoxPtr tmpRect = Xrealloc ((firstrect), \ + (2 * (sizeof(BOX)) * ((reg)->size))); \ + if (tmpRect == NULL) \ return(0);\ + (firstrect) = tmpRect; \ (reg)->size *= 2;\ (rect) = &(firstrect)[(reg)->numRects];\ }\ -- cgit v1.2.3 From ad51fbdb41f8f6bb898ca60b5e547a24aa4ef700 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 12:19:17 -0700 Subject: miRegionCopy(): handle realloc failure better Zero out the region size when freeing the region so callers don't think there's anything there. (Pointer is already set to NULL from the realloc result itself.) Return 0 to the callers, and have them cascade that back to their callers to indicate failure, instead of their usual return value of 1 on success. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Region.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Region.c b/nx-X11/lib/X11/Region.c index 998639c25..77e3aed76 100644 --- a/nx-X11/lib/X11/Region.c +++ b/nx-X11/lib/X11/Region.c @@ -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; } /*====================================================================== @@ -1150,7 +1152,7 @@ XUnionRegion( if ( (reg1 == reg2) || (!(reg1->numRects)) ) { if (newReg != reg2) - miRegionCopy(newReg, reg2); + return miRegionCopy(newReg, reg2); return 1; } @@ -1160,7 +1162,7 @@ XUnionRegion( if (!(reg2->numRects)) { if (newReg != reg1) - miRegionCopy(newReg, reg1); + return miRegionCopy(newReg, reg1); return 1; } @@ -1174,7 +1176,7 @@ XUnionRegion( (reg1->extents.y2 >= reg2->extents.y2)) { if (newReg != reg1) - miRegionCopy(newReg, reg1); + return miRegionCopy(newReg, reg1); return 1; } @@ -1188,7 +1190,7 @@ XUnionRegion( (reg2->extents.y2 >= reg1->extents.y2)) { if (newReg != reg2) - miRegionCopy(newReg, reg2); + return miRegionCopy(newReg, reg2); return 1; } @@ -1429,8 +1431,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, -- cgit v1.2.3 From be32fbb31b1cf65986b46ed8e837d556546c5e45 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 12:19:17 -0700 Subject: miRegionOp(): ensure region size is not updated if realloc fails This function performs operations on a region, and when finished, checks to see if it should compact the rectangle list. If the number of rectangles for which memory is allocated in the list is more than twice the number used, it tries to shrink. realloc() should not fail in this case, but if it does, might as well keep the correct value for the number of allocated rectangles, so we don't try to grow it unnecessarily later if adding to the region. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Region.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Region.c b/nx-X11/lib/X11/Region.c index 77e3aed76..3c4263760 100644 --- a/nx-X11/lib/X11/Region.c +++ b/nx-X11/lib/X11/Region.c @@ -980,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 { -- cgit v1.2.3 From 92591316d2698f48e9021d0c2c0e4f5ec3b29880 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 12:34:53 -0700 Subject: Delete unused XKB_INSURE_SIZE macro from XKBlibint.h Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBlibint.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBlibint.h b/nx-X11/lib/X11/XKBlibint.h index 94b8ac077..d14c7df10 100644 --- a/nx-X11/lib/X11/XKBlibint.h +++ b/nx-X11/lib/X11/XKBlibint.h @@ -106,12 +106,6 @@ typedef struct _XkbInfoRec { /* * 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));\ - } typedef struct _XkbReadBuffer { int error; -- cgit v1.2.3 From 22377a799a141ba6b1e43b83de4a506b36a842a4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 13:37:53 -0700 Subject: init_om: remove unneeded extra copy of string to local buffer Strings from the supported_charset_list[] were being copied one by one to a stack buffer, and then strdup called on that buffer. Instead, just strdup the original string, without the local copy, and use a more traditional for loop, so it's easier to figure out what the code is doing (cleaning up a gcc const-cast warning in the process). Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 9e6feb76b..a8faa2af1 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -1148,10 +1148,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); @@ -1164,14 +1163,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; } -- cgit v1.2.3 From d2671c285e1923acae674ef9390a3f8bf23c11b3 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 21:46:37 -0700 Subject: Constify lc_name argument to _XlcLocaleDirName() & _XlcLocaleLibDirName() Makes code considerably less crufty and clears gcc warnings: XlcDL.c: In function '_XlcDynamicLoad': XlcDL.c:384:44: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] XlcDL.c:386:51: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 6 ++-- nx-X11/lib/X11/XlcPubI.h | 4 +-- nx-X11/lib/X11/lcFile.c | 86 +++++++++++++++++------------------------------- 3 files changed, 35 insertions(+), 61 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 2bef4ac12..18fb3e3b1 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -381,9 +381,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); @@ -510,7 +510,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/nx-X11/lib/X11/XlcPubI.h b/nx-X11/lib/X11/XlcPubI.h index f41e3442a..44d0d086c 100644 --- a/nx-X11/lib/X11/XlcPubI.h +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index 65ea652d0..91773a0a8 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -615,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; @@ -637,6 +637,8 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) xlocaledir (dir, PATH_MAX); n = _XlcParsePath(dir, args, 256); for (i = 0; i < n; ++i) { + char *name = NULL; + if (args[i] == NULL) continue; @@ -651,18 +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 (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) { - target_name = resolve_name(name, buf, RtoL); + /* 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"))) { @@ -672,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); @@ -707,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,6 +716,8 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) xlocalelibdir (dir, PATH_MAX); n = _XlcParsePath(dir, args, 256); for (i = 0; i < n; ++i) { + char *name = NULL; + if (args[i] == NULL) continue; @@ -743,18 +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 (snprintf(buf, PATH_MAX, "%s/locale.dir", target_dir) < PATH_MAX) { - target_name = resolve_name(name, buf, RtoL); + /* 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"))) { @@ -764,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); -- cgit v1.2.3 From e667b9054308dd2033d3771a0656dd485286e855 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 22:18:00 -0700 Subject: Fix const handling in XSetLocaleModifiers Instead of reusing the input parameter to store the output, make a result variable instead, so that there's less const confusion. Fixes gcc warnings: lcWrap.c: In function 'XSetLocaleModifiers': lcWrap.c:87:18: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] lcWrap.c:91:25: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] lcWrap.c:93:12: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcWrap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcWrap.c b/nx-X11/lib/X11/lcWrap.c index 47581f8f8..358748fdc 100644 --- a/nx-X11/lib/X11/lcWrap.c +++ b/nx-X11/lib/X11/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 -- cgit v1.2.3 From d8358c6ef0c05dad211ad273dc669fae94884441 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 22:21:54 -0700 Subject: xlibi18n: Fix a bunch of const cast warnings Add const qualifiers to casts where needed, remove other casts that are no longer needed. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcCT.c | 10 +++++----- nx-X11/lib/X11/lcPublic.c | 3 ++- nx-X11/lib/X11/mbWrap.c | 12 +++++------- nx-X11/lib/X11/utf8Wrap.c | 12 +++++------- 4 files changed, 17 insertions(+), 20 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcCT.c b/nx-X11/lib/X11/lcCT.c index d7fbb74cb..317e3999f 100644 --- a/nx-X11/lib/X11/lcCT.c +++ b/nx-X11/lib/X11/lcCT.c @@ -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." */ diff --git a/nx-X11/lib/X11/lcPublic.c b/nx-X11/lib/X11/lcPublic.c index 1b1fb548a..4b26710b2 100644 --- a/nx-X11/lib/X11/lcPublic.c +++ b/nx-X11/lib/X11/lcPublic.c @@ -106,7 +106,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/nx-X11/lib/X11/mbWrap.c b/nx-X11/lib/X11/mbWrap.c index 19f01f656..766b8da01 100644 --- a/nx-X11/lib/X11/mbWrap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/utf8Wrap.c b/nx-X11/lib/X11/utf8Wrap.c index 82967b0b1..24cb4494c 100644 --- a/nx-X11/lib/X11/utf8Wrap.c +++ b/nx-X11/lib/X11/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); } -- cgit v1.2.3 From 069c1f4d52243d17fd8c23008e1b4fe1486477f7 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 22:32:42 -0700 Subject: i18n modules: Fix some const cast warnings imRm.c: In function '_XimSetICMode': imRm.c:2419:37: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] imRm.c:2420:30: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] lcGenConv.c: In function 'byteM_parse_codeset': lcGenConv.c:345:13: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imRm.c | 4 ++-- nx-X11/lib/X11/lcGenConv.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index a7565d94b..d46500ac7 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -2416,8 +2416,8 @@ _XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style) list_num, ic_mode_quark[i]))) { continue; } - res->mode = ( (*(unsigned short *)((char *)&ic_mode[i] + pre_offset)) - | (*(unsigned short *)((char *)&ic_mode[i] + sts_offset))); + res->mode = ( (*(const unsigned short *)((const char *)&ic_mode[i] + pre_offset)) + | (*(const unsigned short *)((const char *)&ic_mode[i] + sts_offset))); } return; } diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 1041dc709..96904afa3 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -342,7 +342,7 @@ byteM_parse_codeset( continue; for (j = 0; j < codeset->length; j++) { - ch = *((unsigned char *)(inbufptr + j)); + ch = *((const unsigned char *)(inbufptr + j)); byteM_rec = byteM[j]; byteinfo = byteM_rec.byteinfo; -- cgit v1.2.3 From 5d6cda4f6442c524db3c52b272f7ff5f7225bec6 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 23:05:13 -0700 Subject: xlibi18n: fix argsize argument to _XlcParsePath The array is defined as having NUM_LOCALEDIR entries, so use that instead of hardcoded 256 value (the other two calls already did this). Reported by parfait: Buffer overflow (CWE 120): In pointer dereference of argv[argc] with index argc Pointer size is 64 elements (of 8 bytes each), index is 255 at line 82 of nx-X11/lib/X11/lcFile.c in function 'parse_line'. called at line 178 in function '_XlcParsePath' with argv = argv. called at line 722 in function '_XlcLocaleLibDirName' with argv = args, argsize = 256. at line 82 of nx-X11/lib/X11/lcFile.c in function 'parse_line'. called at line 178 in function '_XlcParsePath' with argv = argv. called at line 638 in function '_XlcLocaleDirName' with argv = args, argsize = 256. [ This bug was found by the Parfait 1.2.0 bug checking tool. http://labs.oracle.com/pls/apex/f?p=labs:49:::::P49_PROJECT_ID:13 ] Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcFile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index 91773a0a8..7b0e5a824 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -635,7 +635,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, const 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; @@ -714,7 +714,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, const 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; -- cgit v1.2.3 From c161df4fee61819a28089682963cc2e721ca22c8 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 23:51:08 -0700 Subject: Remove even more casts of return values from Xmalloc/Xrealloc Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/CCC.c | 4 +-- nx-X11/lib/X11/CvCols.c | 2 +- nx-X11/lib/X11/ICWrap.c | 2 +- nx-X11/lib/X11/IdOfPr.c | 2 +- nx-X11/lib/X11/SetGetCols.c | 2 +- nx-X11/lib/X11/StCols.c | 2 +- nx-X11/lib/X11/XDefaultIMIF.c | 12 ++++---- nx-X11/lib/X11/XDefaultOMIF.c | 18 +++++------ nx-X11/lib/X11/XlcDL.c | 3 +- nx-X11/lib/X11/cmsCmap.c | 4 +-- nx-X11/lib/X11/cmsColNm.c | 8 ++--- nx-X11/lib/X11/cmsInt.c | 9 +++--- nx-X11/lib/X11/imCallbk.c | 17 +++++------ nx-X11/lib/X11/imDefIc.c | 52 ++++++++++++++++---------------- nx-X11/lib/X11/imDefIm.c | 36 +++++++++++----------- nx-X11/lib/X11/imDefLkup.c | 16 +++++----- nx-X11/lib/X11/imDispch.c | 2 +- nx-X11/lib/X11/imExten.c | 6 ++-- nx-X11/lib/X11/imInsClbk.c | 2 +- nx-X11/lib/X11/imInt.c | 4 +-- nx-X11/lib/X11/imLcIc.c | 2 +- nx-X11/lib/X11/imRm.c | 12 ++++---- nx-X11/lib/X11/imRmAttr.c | 12 ++++---- nx-X11/lib/X11/imThaiIc.c | 10 +++--- nx-X11/lib/X11/imTrX.c | 2 +- nx-X11/lib/X11/imTrans.c | 2 +- nx-X11/lib/X11/imTransR.c | 8 ++--- nx-X11/lib/X11/lcCT.c | 6 ++-- nx-X11/lib/X11/lcCharSet.c | 6 ++-- nx-X11/lib/X11/lcConv.c | 6 ++-- nx-X11/lib/X11/lcDB.c | 14 ++++----- nx-X11/lib/X11/lcDefConv.c | 4 +-- nx-X11/lib/X11/lcEuc.c | 2 +- nx-X11/lib/X11/lcGenConv.c | 4 +-- nx-X11/lib/X11/lcGeneric.c | 31 +++++++++---------- nx-X11/lib/X11/lcJis.c | 4 +-- nx-X11/lib/X11/lcPrTxt.c | 10 +++--- nx-X11/lib/X11/lcPubWrap.c | 2 +- nx-X11/lib/X11/lcPublic.c | 2 +- nx-X11/lib/X11/lcRM.c | 4 +-- nx-X11/lib/X11/lcSjis.c | 2 +- nx-X11/lib/X11/lcTxtPr.c | 4 +-- nx-X11/lib/X11/lcUTF8.c | 8 ++--- nx-X11/lib/X11/lcUniConv/8bit_tab_to_h.c | 6 ++-- nx-X11/lib/X11/lcUniConv/cjk_tab_to_h.c | 14 ++++----- nx-X11/lib/X11/lcWrap.c | 6 ++-- nx-X11/lib/X11/omGeneric.c | 36 +++++++++++----------- 47 files changed, 209 insertions(+), 213 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/CCC.c b/nx-X11/lib/X11/CCC.c index 090b1078c..da8b661dc 100644 --- a/nx-X11/lib/X11/CCC.c +++ b/nx-X11/lib/X11/CCC.c @@ -111,7 +111,7 @@ XcmsCreateCCC( XcmsPerScrnInfo *pNewScrnInfo; if (pDefaultCCC == NULL || - !(newccc = (XcmsCCC) Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) { + !(newccc = Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) { return(NULL); } @@ -144,7 +144,7 @@ XcmsCreateCCC( * If one exists replace the pPerScrnInfo. */ if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) { - if (!(pNewScrnInfo = (XcmsPerScrnInfo *) + if (!(pNewScrnInfo = Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { Xfree(newccc); return(NULL); diff --git a/nx-X11/lib/X11/CvCols.c b/nx-X11/lib/X11/CvCols.c index ed3582663..f543f277b 100644 --- a/nx-X11/lib/X11/CvCols.c +++ b/nx-X11/lib/X11/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; } diff --git a/nx-X11/lib/X11/ICWrap.c b/nx-X11/lib/X11/ICWrap.c index 1eacfa5f1..8584e36a7 100644 --- a/nx-X11/lib/X11/ICWrap.c +++ b/nx-X11/lib/X11/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; diff --git a/nx-X11/lib/X11/IdOfPr.c b/nx-X11/lib/X11/IdOfPr.c index 3a92e0a11..e15f34fec 100644 --- a/nx-X11/lib/X11/IdOfPr.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/SetGetCols.c b/nx-X11/lib/X11/SetGetCols.c index 9b548dbb2..fc3708585 100644 --- a/nx-X11/lib/X11/SetGetCols.c +++ b/nx-X11/lib/X11/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); } diff --git a/nx-X11/lib/X11/StCols.c b/nx-X11/lib/X11/StCols.c index 24ccd386f..95fd6eeba 100644 --- a/nx-X11/lib/X11/StCols.c +++ b/nx-X11/lib/X11/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; } diff --git a/nx-X11/lib/X11/XDefaultIMIF.c b/nx-X11/lib/X11/XDefaultIMIF.c index e97d2f444..db0f5d1fa 100644 --- a/nx-X11/lib/X11/XDefaultIMIF.c +++ b/nx-X11/lib/X11/XDefaultIMIF.c @@ -184,10 +184,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); @@ -273,11 +273,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; @@ -344,7 +344,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)); @@ -452,7 +452,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/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index a8faa2af1..71dc810eb 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -76,7 +76,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 { @@ -332,15 +332,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; @@ -578,11 +578,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; @@ -1172,11 +1172,11 @@ init_om( 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; @@ -1192,7 +1192,7 @@ init_om( bufptr += strlen(bufptr) + 1; /* orientation list */ - orientation = (XOrientation *) Xmalloc(sizeof(XOrientation)); + orientation = Xmalloc(sizeof(XOrientation)); if (orientation == NULL) return False; diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 18fb3e3b1..a23603865 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -185,8 +185,7 @@ 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; } snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS"); diff --git a/nx-X11/lib/X11/cmsCmap.c b/nx-X11/lib/X11/cmsCmap.c index 00816ce03..45843e3b8 100644 --- a/nx-X11/lib/X11/cmsCmap.c +++ b/nx-X11/lib/X11/cmsCmap.c @@ -250,7 +250,7 @@ _XcmsAddCmapRec( { XcmsCmapRec *pNew; - if ((pNew = (XcmsCmapRec *) Xcalloc(1, (unsigned) sizeof(XcmsCmapRec))) + if ((pNew = Xcalloc(1, (unsigned) sizeof(XcmsCmapRec))) == NULL) { return((XcmsCmapRec *)NULL); } @@ -301,7 +301,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, (unsigned) sizeof(XcmsCCCRec)); memcpy((char *)pRec_copy->ccc, (char *)pRec_src->ccc, sizeof(XcmsCCCRec)); } diff --git a/nx-X11/lib/X11/cmsColNm.c b/nx-X11/lib/X11/cmsColNm.c index a56141021..bd5c253fe 100644 --- a/nx-X11/lib/X11/cmsColNm.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/cmsInt.c b/nx-X11/lib/X11/cmsInt.c index b7c321472..cefa1e680 100644 --- a/nx-X11/lib/X11/cmsInt.c +++ b/nx-X11/lib/X11/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, (unsigned) sizeof(XcmsCCCRec)))) { return(0); } dpy->cms.defaultCCCs = (XPointer)ccc; @@ -322,7 +321,7 @@ _XcmsInitScrnInfo( * for the latter (see XcmsCreateCCC). The ones created * here are referenced by the default CCC. */ - if (!(defaultccc->pPerScrnInfo = (XcmsPerScrnInfo *) + if (!(defaultccc->pPerScrnInfo = Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { return(0); } diff --git a/nx-X11/lib/X11/imCallbk.c b/nx-X11/lib/X11/imCallbk.c index f57a8de31..edffac173 100644 --- a/nx-X11/lib/X11/imCallbk.c +++ b/nx-X11/lib/X11/imCallbk.c @@ -230,9 +230,9 @@ _XimCbDispatch(Xim xim, /* queue the protocol */ XimPendingCallback pcb; - char *proto_buf = (proto_len > 0) ? (char*)Xmalloc(proto_len) : NULL; + char *proto_buf = (proto_len > 0) ? Xmalloc(proto_len) : NULL; - pcb = (XimPendingCallback)Xmalloc(sizeof(XimPendingCallbackRec)); + pcb = Xmalloc(sizeof(XimPendingCallbackRec)); if (pcb && (proto_len <= 0 || proto_buf)) { if (proto_len > 0) memcpy(proto_buf, proto, proto_len); @@ -339,7 +339,7 @@ _XimStrConversionCallback(Xim im, 2 + length_in_bytes + XIM_PAD(2 + length_in_bytes) + 2 + 2 + sz_CARD32 * cbrec.text->length; - buf = (CARD8*)Xmalloc(buf_len); + buf = Xmalloc(buf_len); } _XimSetHeader((XPointer)buf, XIM_STR_CONVERSION_REPLY, 0, &buf_len); buf_len -= XIM_HEADER_SIZE; /* added by _XimSetHeader (HACK) */ @@ -461,12 +461,12 @@ _read_text_from_packet(Xim im, return; } - *text_ptr = text = (XIMText*)Xmalloc(sizeof(XIMText)); + *text_ptr = text = Xmalloc(sizeof(XIMText)); if (text == (XIMText*)NULL) return; tmp_len = (int)*(CARD16*)buf; buf += sz_CARD16; - if ((tmp_buf = (char*)Xmalloc(tmp_len + 1))) { + if ((tmp_buf = Xmalloc(tmp_len + 1))) { memcpy(tmp_buf, buf, tmp_len); tmp_buf[tmp_len] = '\0'; @@ -477,11 +477,10 @@ _read_text_from_packet(Xim im, if (s != XLookupNone) { #ifndef NO_DEC_I18N_FIX /* Allow for NULL-terminated */ - if ((text->string.multi_byte = - (char*)Xmalloc(text->length * + if ((text->string.multi_byte = Xmalloc(text->length * XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1))) { #else - if (text->string.multi_byte = (char*)Xmalloc(text->length+1)) { + if (text->string.multi_byte = Xmalloc(text->length+1)) { #endif int tmp; #ifndef NO_DEC_I18N_FIX @@ -530,7 +529,7 @@ _read_text_from_packet(Xim im, i = (int)*(CARD16*)buf; buf += sz_CARD16; buf += sz_CARD16; /* skip `unused' */ - text->feedback = (XIMFeedback*)Xmalloc(i*(sizeof(XIMFeedback)/sizeof(CARD32))); + text->feedback = Xmalloc(i*(sizeof(XIMFeedback)/sizeof(CARD32))); j = 0; while (i > 0) { text->feedback[j] = (XIMFeedback)*(CARD32*)buf; diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index 3b5fa4147..a5b14ec9a 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -108,7 +108,7 @@ _XimReCreateIC(ic) XPointer preply; int ret_code; - if (!(save_ic = (Xic)Xmalloc(sizeof(XicRec)))) + if (!(save_ic = Xmalloc(sizeof(XicRec)))) return False; memcpy((char *)save_ic, (char *)ic, sizeof(XicRec)); @@ -120,7 +120,7 @@ _XimReCreateIC(ic) num = im->core.ic_num_resources; buf_size = sizeof(XIMResource) * num; - if (!(res = (XIMResourceList)Xmalloc(buf_size))) + if (!(res = Xmalloc(buf_size))) goto ErrorOnReCreateIC; (void)memcpy((char *)res, (char *)im->core.ic_resources, buf_size); ic->private.proto.ic_resources = res; @@ -128,7 +128,7 @@ _XimReCreateIC(ic) num = im->private.proto.ic_num_inner_resources; buf_size = sizeof(XIMResource) * num; - if (!(res = (XIMResourceList)Xmalloc(buf_size))) + if (!(res = Xmalloc(buf_size))) goto ErrorOnReCreateIC; (void)memcpy((char *)res, (char *)im->private.proto.ic_inner_resources, buf_size); @@ -164,13 +164,13 @@ _XimReCreateIC(ic) buf_size += ret_len; if (buf == tmp_buf) { - if (!(tmp = (char *)Xmalloc(buf_size + data_len))) { + if (!(tmp = Xmalloc(buf_size + data_len))) { goto ErrorOnReCreateIC; } memcpy(tmp, buf, buf_size); buf = tmp; } else { - if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) { + if (!(tmp = Xrealloc(buf, (buf_size + data_len)))) { Xfree(buf); goto ErrorOnReCreateIC; } @@ -203,7 +203,7 @@ _XimReCreateIC(ic) preply = reply; } else { buf_size = (int)len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimCreateICCheck, 0); if (ret_code != XIM_TRUE) { @@ -351,7 +351,7 @@ _XimProtoGetICValues( + sizeof(INT16) + XIM_PAD(2 + buf_size); - if (!(buf = (CARD8 *)Xmalloc(buf_size))) + if (!(buf = Xmalloc(buf_size))) return arg->name; buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; @@ -385,7 +385,7 @@ _XimProtoGetICValues( preply = reply; } else { buf_size = (int)len; - preply = (XPointer)Xmalloc(len); + preply = Xmalloc(len); ret_code = _XimRead(im, &len, preply, buf_size, _XimGetICValuesCheck, (XPointer)ic); if (ret_code != XIM_TRUE) { @@ -465,7 +465,7 @@ _XimCheckNestedQuarkList(quark_list, idx, num_quark, arg, separator) quark, separator)) { continue; } - if (!(tmp = (XrmQuark *)Xmalloc((sizeof(XrmQuark) * (n_quark + 1))))) { + if (!(tmp = Xmalloc((sizeof(XrmQuark) * (n_quark + 1))))) { *quark_list = q_list; *num_quark = n_quark; return False; @@ -535,7 +535,7 @@ _XimSaveICValues(ic, arg) for (pp = (XIMArg *)p->value, nn = 0; pp && pp->name; pp++, nn++); - if (!(tmp = (XrmQuark *)Xrealloc(quark_list, + if (!(tmp = Xrealloc(quark_list, (sizeof(XrmQuark) * (num_quark + nn + 2))))) { ic->private.proto.saved_icvalues = quark_list; ic->private.proto.num_saved_icvalues = num_quark; @@ -562,7 +562,7 @@ _XimSaveICValues(ic, arg) if (_XimCheckICQuarkList(quark_list, num_quark, quark, &idx)) { continue; } - if (!(tmp = (XrmQuark *)Xrealloc(quark_list, + if (!(tmp = Xrealloc(quark_list, (sizeof(XrmQuark) * (num_quark + 1))))) { ic->private.proto.saved_icvalues = quark_list; ic->private.proto.num_saved_icvalues = num_quark; @@ -589,7 +589,7 @@ _XimSaveICValues(ic, arg) } } - if (!(quark_list = (XrmQuark *)Xmalloc(sizeof(XrmQuark) * n))) { + if (!(quark_list = Xmalloc(sizeof(XrmQuark) * n))) { return False; } @@ -731,13 +731,13 @@ _XimProtoSetICValues( buf_size += ret_len; if (buf == tmp_buf) { - if (!(tmp = (char *)Xmalloc(buf_size + data_len))) { + if (!(tmp = Xmalloc(buf_size + data_len))) { return tmp_name; } memcpy(tmp, buf, buf_size); buf = tmp; } else { - if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) { + if (!(tmp = Xrealloc(buf, (buf_size + data_len)))) { Xfree(buf); return tmp_name; } @@ -781,7 +781,7 @@ _XimProtoSetICValues( preply = reply; } else if (ret_code == XIM_OVERFLOW) { buf_size = (int)len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimSetICValuesCheck, (XPointer)ic); if (ret_code != XIM_TRUE) { @@ -915,7 +915,7 @@ _XimProtoDestroyIC( _XimDestroyICCheck, (XPointer)ic); if (ret_code == XIM_OVERFLOW) { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); (void)_XimRead(im, &len, preply, buf_size, _XimDestroyICCheck, (XPointer)ic); Xfree(preply); @@ -1088,7 +1088,7 @@ _XimProtoReset( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimResetICCheck, (XPointer)ic); if (ret_code != XIM_TRUE) { @@ -1139,7 +1139,7 @@ _XimCommitedMbString( if ( len == 0 ) return( NULL ); - if (!(commit = (char *)Xmalloc(len + 1))) + if (!(commit = Xmalloc(len + 1))) goto Error_On_Reset; str = commit; @@ -1196,7 +1196,7 @@ _XimCommitedWcString( if ( len == 0 ) return( (wchar_t *)NULL ); - if (!(commit = (char *)Xmalloc(len + 1))) + if (!(commit = Xmalloc(len + 1))) goto Error_On_Reset; str = commit; @@ -1255,7 +1255,7 @@ _XimCommitedUtf8String( if ( len == 0 ) return( NULL ); - if (!(commit = (char *)Xmalloc(len + 1))) + if (!(commit = Xmalloc(len + 1))) goto Error_On_Reset; str = commit; @@ -1368,7 +1368,7 @@ _XimReconnectModeCreateIC(ic) num = im->core.ic_num_resources; len = sizeof(XIMResource) * num; - if (!(res = (XIMResourceList)Xmalloc(len))) + if (!(res = Xmalloc(len))) return False; (void)memcpy((char *)res, (char *)im->core.ic_resources, len); ic->private.proto.ic_resources = res; @@ -1430,7 +1430,7 @@ _XimProtoCreateIC( num = im->core.ic_num_resources; len = sizeof(XIMResource) * num; - if (!(res = (XIMResourceList)Xmalloc(len))) + if (!(res = Xmalloc(len))) goto ErrorOnCreatingIC; (void)memcpy((char *)res, (char *)im->core.ic_resources, len); ic->private.proto.ic_resources = res; @@ -1458,7 +1458,7 @@ _XimProtoCreateIC( num = im->private.proto.ic_num_inner_resources; len = sizeof(XIMResource) * num; - if (!(res = (XIMResourceList)Xmalloc(len))) + if (!(res = Xmalloc(len))) goto ErrorOnCreatingIC; (void)memcpy((char *)res, (char *)im->private.proto.ic_inner_resources, len); @@ -1492,13 +1492,13 @@ _XimProtoCreateIC( buf_size += ret_len; if (buf == tmp_buf) { - if (!(tmp = (char *)Xmalloc(buf_size + data_len))) { + if (!(tmp = Xmalloc(buf_size + data_len))) { goto ErrorOnCreatingIC; } memcpy(tmp, buf, buf_size); buf = tmp; } else { - if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) { + if (!(tmp = Xrealloc(buf, (buf_size + data_len)))) { Xfree(buf); goto ErrorOnCreatingIC; } @@ -1538,7 +1538,7 @@ _XimProtoCreateIC( preply = reply; } else { buf_size = (int)len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimCreateICCheck, 0); if (ret_code != XIM_TRUE) { diff --git a/nx-X11/lib/X11/imDefIm.c b/nx-X11/lib/X11/imDefIm.c index 5f65b5312..ce2856bb2 100644 --- a/nx-X11/lib/X11/imDefIm.c +++ b/nx-X11/lib/X11/imDefIm.c @@ -616,7 +616,7 @@ _XimConnection( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimAllRecv, 0); if(ret_code != XIM_TRUE) { Xfree(preply); @@ -759,7 +759,7 @@ _XimDisconnect( if(ret_code == XIM_OVERFLOW) { if(len > 0) { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimDisconnectCheck, 0); Xfree(preply); @@ -831,7 +831,7 @@ _XimOpen( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimOpenCheck, 0); if(ret_code != XIM_TRUE) { @@ -950,7 +950,7 @@ _XimClose( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimCloseCheck, 0); if(ret_code != XIM_TRUE) { Xfree(preply); @@ -1173,7 +1173,7 @@ _XimSaveIMValues( if (_XimCheckIMQuarkList(quark_list, num_quark, quark)) { continue; } - if (!(tmp = (XrmQuark *)Xrealloc(quark_list, + if (!(tmp = Xrealloc(quark_list, (sizeof(XrmQuark) * (num_quark + 1))))) { im->private.proto.saved_imvalues = quark_list; im->private.proto.num_saved_imvalues = num_quark; @@ -1190,7 +1190,7 @@ _XimSaveIMValues( for (p = arg, n = 0; p && p->name; p++, n++); - if (!(quark_list = (XrmQuark *)Xmalloc(sizeof(XrmQuark) * n))) { + if (!(quark_list = Xmalloc(sizeof(XrmQuark) * n))) { return False; } @@ -1311,13 +1311,13 @@ _XimProtoSetIMValues( buf_size += ret_len; if (buf == tmp_buf) { - if (!(tmp = (char *)Xmalloc(buf_size + data_len))) { + if (!(tmp = Xmalloc(buf_size + data_len))) { return arg->name; } memcpy(tmp, buf, buf_size); buf = tmp; } else { - if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) { + if (!(tmp = Xrealloc(buf, (buf_size + data_len)))) { Xfree(buf); return arg->name; } @@ -1353,7 +1353,7 @@ _XimProtoSetIMValues( preply = reply; } else { buf_size = (int)len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, reply, buf_size, _XimSetIMValuesCheck, 0); if(ret_code != XIM_TRUE) { @@ -1462,7 +1462,7 @@ _XimProtoGetIMValues( + sizeof(INT16) + XIM_PAD(buf_size); - if (!(buf = (CARD8 *)Xmalloc(buf_size))) + if (!(buf = Xmalloc(buf_size))) return arg->name; buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; @@ -1494,7 +1494,7 @@ _XimProtoGetIMValues( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimGetIMValuesCheck, 0); if(ret_code != XIM_TRUE) { @@ -1556,7 +1556,7 @@ _XimSetEncodingByName( encoding_len = strlen(encoding); compound_len = strlen("COMPOUND_TEXT"); *len = encoding_len + sizeof(BYTE) + compound_len + sizeof(BYTE); - if (!(ret = (BYTE *)Xmalloc(*len))) { + if (!(ret = Xmalloc(*len))) { return False; } *buf = (char *)ret; @@ -1724,7 +1724,7 @@ _XimEncodingNegotiation( + sizeof(CARD16) + detail_len; - if (!(buf = (CARD8 *)Xmalloc(XIM_HEADER_SIZE + len))) + if (!(buf = Xmalloc(XIM_HEADER_SIZE + len))) goto free_detail_ptr; buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; @@ -1757,7 +1757,7 @@ _XimEncodingNegotiation( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimEncodingNegoCheck, 0); if(ret_code != XIM_TRUE) @@ -1844,13 +1844,13 @@ _XimSendSavedIMValues( buf_size += ret_len; if (buf == tmp_buf) { - if (!(tmp = (char *)Xmalloc(buf_size + data_len))) { + if (!(tmp = Xmalloc(buf_size + data_len))) { return False; } memcpy(tmp, buf, buf_size); buf = tmp; } else { - if (!(tmp = (char *)Xrealloc(buf, (buf_size + data_len)))) { + if (!(tmp = Xrealloc(buf, (buf_size + data_len)))) { Xfree(buf); return False; } @@ -1885,7 +1885,7 @@ _XimSendSavedIMValues( preply = reply; } else { buf_size = (int)len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, reply, buf_size, _XimSetIMValuesCheck, 0); if(ret_code != XIM_TRUE) { @@ -1938,7 +1938,7 @@ _XimConnectServer( { Xim save_im; - if (!(save_im = (Xim)Xmalloc(sizeof(XimRec)))) + if (!(save_im = Xmalloc(sizeof(XimRec)))) return False; memcpy((char *)save_im, (char *)im, sizeof(XimRec)); diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index 3317831e6..1cbd15b54 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -162,7 +162,7 @@ _XimSync( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(len); + preply = Xmalloc(len); ret_code = _XimRead(im, &len, preply, buf_size, _XimSyncCheck, (XPointer)ic); if(ret_code != XIM_TRUE) { @@ -302,7 +302,7 @@ _XimForwardEventCore( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(len); + preply = Xmalloc(len); ret_code = _XimRead(im, &len, preply, buf_size, _XimSyncCheck, (XPointer)ic); if(ret_code != XIM_TRUE) { @@ -417,7 +417,7 @@ _XimRegisterTriggerkey( len = buf_l[0]; /* length of on-keys */ len += sizeof(INT32); /* sizeof length of on-keys */ - if (!(key = (CARD32 *)Xmalloc(len))) { + if (!(key = Xmalloc(len))) { _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); return False; } @@ -434,7 +434,7 @@ _XimRegisterTriggerkey( len = buf_l[0]; /* length of off-keys */ len += sizeof(INT32); /* sizeof length of off-keys */ - if (!(key = (CARD32 *)Xmalloc(len))) { + if (!(key = Xmalloc(len))) { _XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); return False; } @@ -546,7 +546,7 @@ _XimTriggerNotify( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(len); + preply = Xmalloc(len); ret_code = _XimRead(im, &len, (XPointer)reply, buf_size, _XimTriggerNotifyCheck, (XPointer)ic); if(ret_code != XIM_TRUE) { @@ -579,7 +579,7 @@ _XimRegCommitInfo( { XimCommitInfo info; - if (!(info = (XimCommitInfo)Xmalloc(sizeof(XimCommitInfoRec)))) + if (!(info = Xmalloc(sizeof(XimCommitInfoRec)))) return False; info->string = string; info->string_len = string_len; @@ -626,7 +626,7 @@ _XimProcKeySym( { Xim im = (Xim)ic->core.im; - if (!(*xim_keysym = (KeySym *)Xmalloc(sizeof(KeySym)))) { + if (!(*xim_keysym = Xmalloc(sizeof(KeySym)))) { _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); return False; } @@ -648,7 +648,7 @@ _XimProcCommit( Xim im = (Xim)ic->core.im; char *string; - if (!(string = (char *)Xmalloc(len + 1))) { + if (!(string = Xmalloc(len + 1))) { _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); return False; } diff --git a/nx-X11/lib/X11/imDispch.c b/nx-X11/lib/X11/imDispch.c index 888e2fd4b..862a9b651 100644 --- a/nx-X11/lib/X11/imDispch.c +++ b/nx-X11/lib/X11/imDispch.c @@ -49,7 +49,7 @@ _XimRegProtoIntrCallback( { XimProtoIntrRec *rec; - if (!(rec = (XimProtoIntrRec *)Xmalloc(sizeof(XimProtoIntrRec)))) + if (!(rec = Xmalloc(sizeof(XimProtoIntrRec)))) return False; rec->func = proc; rec->major_code = major_code; diff --git a/nx-X11/lib/X11/imExten.c b/nx-X11/lib/X11/imExten.c index 779cead0b..7ed4c6be9 100644 --- a/nx-X11/lib/X11/imExten.c +++ b/nx-X11/lib/X11/imExten.c @@ -271,7 +271,7 @@ _XimExtForwardKeyEvent( preply = reply; } else { buf_sizex = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, preply, buf_size, _XimExtForwardKeyEventCheck, (XPointer)ic); if(ret_code != XIM_TRUE) { @@ -436,7 +436,7 @@ _XimExtension( + len + XIM_PAD(len); - if (!(buf = (CARD8 *)Xmalloc(buf_len))) + if (!(buf = Xmalloc(buf_len))) return False; buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE]; @@ -465,7 +465,7 @@ _XimExtension( preply = reply; } else { buf_size = len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimRead(im, &len, reply, buf_size, _XimQueryExtensionCheck, 0); if(ret_code != XIM_TRUE) { diff --git a/nx-X11/lib/X11/imInsClbk.c b/nx-X11/lib/X11/imInsClbk.c index 47a56c508..3ae6b1bd7 100644 --- a/nx-X11/lib/X11/imInsClbk.c +++ b/nx-X11/lib/X11/imInsClbk.c @@ -168,7 +168,7 @@ _XimRegisterIMInstantiateCallback( if( lock ) return( False ); - icb = (XimInstCallback)Xmalloc(sizeof(XimInstCallbackRec)); + icb = Xmalloc(sizeof(XimInstCallbackRec)); if( !icb ) return( False ); icb->call = icb->destroy = False; diff --git a/nx-X11/lib/X11/imInt.c b/nx-X11/lib/X11/imInt.c index e6929207a..dcfb476d9 100644 --- a/nx-X11/lib/X11/imInt.c +++ b/nx-X11/lib/X11/imInt.c @@ -48,7 +48,7 @@ _XimSetIMStructureList( Xim *xim; if(!(_XimCurrentIMlist)) { - if(!(_XimCurrentIMlist = (Xim *)Xmalloc(sizeof(Xim)))) + if(!(_XimCurrentIMlist = Xmalloc(sizeof(Xim)))) return False; _XimCurrentIMlist[0] = im; _XimCurrentIMcount = 1; @@ -61,7 +61,7 @@ _XimSetIMStructureList( } } if(i >= _XimCurrentIMcount) { - if(!(xim = (Xim *)Xrealloc(_XimCurrentIMlist, + if(!(xim = Xrealloc(_XimCurrentIMlist, ((i + 1) * sizeof(Xim))))) return False; _XimCurrentIMlist = xim; diff --git a/nx-X11/lib/X11/imLcIc.c b/nx-X11/lib/X11/imLcIc.c index 46323061e..7ab9050c1 100644 --- a/nx-X11/lib/X11/imLcIc.c +++ b/nx-X11/lib/X11/imLcIc.c @@ -158,7 +158,7 @@ _XimLocalCreateIC( num = im->core.ic_num_resources; len = sizeof(XIMResource) * num; - if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) { + if((res = Xmalloc(len)) == (XIMResourceList)NULL) { goto Set_Error; } (void)memcpy((char *)res, (char *)im->core.ic_resources, len); diff --git a/nx-X11/lib/X11/imRm.c b/nx-X11/lib/X11/imRm.c index d46500ac7..373217173 100644 --- a/nx-X11/lib/X11/imRm.c +++ b/nx-X11/lib/X11/imRm.c @@ -207,7 +207,7 @@ _XimSetProtoResource(im) if(!status_style) status_style = XIMStatusNothing; - if(!(imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){ + if(!(imstyles = Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){ if (res_name != res_name_buf) Xfree (res_name); if (res_class != res_class_buf) Xfree (res_class); return; @@ -902,7 +902,7 @@ _XimEncodeHotKey( } len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xmalloc(len))) { return False; } @@ -1159,7 +1159,7 @@ _XimDecodeCallback( XIMCallback *callback; in = (XIMCallback *)((char *)top + info->offset); - if(!(callback = (XIMCallback *)Xmalloc(sizeof(XIMCallback)))) { + if(!(callback = Xmalloc(sizeof(XIMCallback)))) { return False; } callback->client_data = in->client_data; @@ -1272,7 +1272,7 @@ _XimDecodeHotKey( in = *((XIMHotKeyTriggers **)((char *)top + info->offset)); num = in->num_hot_key; len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; - if(!(tmp = (XPointer)Xmalloc(len))) { + if(!(tmp = Xmalloc(len))) { return False; } @@ -1312,7 +1312,7 @@ _XimDecodeRectangle( XRectangle *rect; in = (XRectangle *)((char *)top + info->offset); - if(!(rect = (XRectangle *)Xmalloc(sizeof(XRectangle)))) { + if(!(rect = Xmalloc(sizeof(XRectangle)))) { return False; } *rect = *in; @@ -1330,7 +1330,7 @@ _XimDecodeSpot( XPoint *spot; in = (XPoint *)((char *)top + info->offset); - if(!(spot = (XPoint *)Xmalloc(sizeof(XPoint)))) { + if(!(spot = Xmalloc(sizeof(XPoint)))) { return False; } *spot = *in; diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index ef3ac2ca7..ad5290ee5 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -238,7 +238,7 @@ _XimAttributeToValue( if (!(value)) return False; - if (!(str = (char *)Xmalloc(data_len + 1))) + if (!(str = Xmalloc(data_len + 1))) return False; (void)memcpy(str, (char *)data, data_len); @@ -262,7 +262,7 @@ _XimAttributeToValue( return False; alloc_len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; - if (!(p = (char *)Xmalloc(alloc_len))) + if (!(p = Xmalloc(alloc_len))) return False; rep = (XIMStyles *)p; @@ -284,7 +284,7 @@ _XimAttributeToValue( if (!(value)) return False; - if (!(rep = (XRectangle *)Xmalloc(sizeof(XRectangle)))) + if (!(rep = Xmalloc(sizeof(XRectangle)))) return False; rep->x = data[0]; @@ -302,7 +302,7 @@ _XimAttributeToValue( if (!(value)) return False; - if (!(rep = (XPoint *)Xmalloc(sizeof(XPoint)))) + if (!(rep = Xmalloc(sizeof(XPoint)))) return False; rep->x = data[0]; @@ -325,7 +325,7 @@ _XimAttributeToValue( if (!ic) return False; - if (!(base_name = (char *)Xmalloc(len + 1))) + if (!(base_name = Xmalloc(len + 1))) return False; (void)strncpy(base_name, (char *)&data[1], (int)len); @@ -370,7 +370,7 @@ _XimAttributeToValue( alloc_len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; - if (!(p = (char *)Xmalloc(alloc_len))) + if (!(p = Xmalloc(alloc_len))) return False; rep = (XIMHotKeyTriggers *)p; diff --git a/nx-X11/lib/X11/imThaiIc.c b/nx-X11/lib/X11/imThaiIc.c index 4211038e3..002219920 100644 --- a/nx-X11/lib/X11/imThaiIc.c +++ b/nx-X11/lib/X11/imThaiIc.c @@ -165,13 +165,13 @@ _XimThaiCreateIC( ic->core.im = im; ic->core.filter_events = KeyPressMask; - if (! (ic->private.local.base.tree = tree = (DefTree *)Xmalloc(sizeof(DefTree)*3)) ) + if (! (ic->private.local.base.tree = tree = Xmalloc(sizeof(DefTree)*3)) ) goto Set_Error; - if (! (ic->private.local.base.mb = (char *)Xmalloc(21)) ) + if (! (ic->private.local.base.mb = Xmalloc(21)) ) goto Set_Error; - if (! (ic->private.local.base.wc = (wchar_t*)Xmalloc(sizeof(wchar_t)*21)) ) + if (! (ic->private.local.base.wc = Xmalloc(sizeof(wchar_t)*21)) ) goto Set_Error; - if (! (ic->private.local.base.utf8 = (char *)Xmalloc(21)) ) + if (! (ic->private.local.base.utf8 = Xmalloc(21)) ) goto Set_Error; ic->private.local.context = 1; tree[1].mb = 1; @@ -188,7 +188,7 @@ _XimThaiCreateIC( num = im->core.ic_num_resources; len = sizeof(XIMResource) * num; - if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) { + if((res = Xmalloc(len)) == (XIMResourceList)NULL) { goto Set_Error; } (void)memcpy((char *)res, (char *)im->core.ic_resources, len); diff --git a/nx-X11/lib/X11/imTrX.c b/nx-X11/lib/X11/imTrX.c index 6b1d61f2d..148b7fc90 100644 --- a/nx-X11/lib/X11/imTrX.c +++ b/nx-X11/lib/X11/imTrX.c @@ -71,7 +71,7 @@ _XimXRegisterDispatcher( XIntrCallbackPtr rec; XSpecRec *spec = (XSpecRec *)im->private.proto.spec; - if (!(rec = (XIntrCallbackPtr)Xmalloc(sizeof(XIntrCallbackRec)))) + if (!(rec = Xmalloc(sizeof(XIntrCallbackRec)))) return False; rec->func = callback; diff --git a/nx-X11/lib/X11/imTrans.c b/nx-X11/lib/X11/imTrans.c index 3cea659f9..7f936cff6 100644 --- a/nx-X11/lib/X11/imTrans.c +++ b/nx-X11/lib/X11/imTrans.c @@ -153,7 +153,7 @@ _XimTransRegisterDispatcher( TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec; TransIntrCallbackPtr rec; - if (!(rec = (TransIntrCallbackPtr)Xmalloc(sizeof(TransIntrCallbackRec)))) + if (!(rec = Xmalloc(sizeof(TransIntrCallbackRec)))) return False; rec->func = callback; diff --git a/nx-X11/lib/X11/imTransR.c b/nx-X11/lib/X11/imTransR.c index caa530904..50b549e71 100644 --- a/nx-X11/lib/X11/imTransR.c +++ b/nx-X11/lib/X11/imTransR.c @@ -138,7 +138,7 @@ _XimReadData( data_len -= i; if (data_len) { - if (!(tmp = (char *)Xmalloc(data_len))) { + if (!(tmp = Xmalloc(data_len))) { return XIM_FALSE; } memcpy(tmp, &hold_buf[i], data_len); @@ -173,7 +173,7 @@ _XimReadData( } if (packet_size > buf_size) { - if (!(tmp = (char *)Xmalloc(data_len))) { + if (!(tmp = Xmalloc(data_len))) { return XIM_FALSE; } memcpy(tmp, buf, data_len); @@ -200,7 +200,7 @@ _XimReadData( data_len -= i; if (data_len) { - if (!(tmp = (char *)Xmalloc(data_len))) { + if (!(tmp = Xmalloc(data_len))) { return XIM_FALSE; } memcpy(tmp, &buf[i], data_len); @@ -283,7 +283,7 @@ _XimFilterWaitEvent(Xim im) preply = reply; } else { buf_size = (int)read_len; - preply = (XPointer)Xmalloc(buf_size); + preply = Xmalloc(buf_size); ret_code = _XimReadData(im, &read_len, preply, buf_size); if(ret_code != XIM_TRUE) { if (preply != reply) diff --git a/nx-X11/lib/X11/lcCT.c b/nx-X11/lib/X11/lcCT.c index 317e3999f..ee3c76878 100644 --- a/nx-X11/lib/X11/lcCT.c +++ b/nx-X11/lib/X11/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; @@ -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; diff --git a/nx-X11/lib/X11/lcCharSet.c b/nx-X11/lib/X11/lcCharSet.c index 5d287811c..57f13d501 100644 --- a/nx-X11/lib/X11/lcCharSet.c +++ b/nx-X11/lib/X11/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,7 +184,7 @@ _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); return (XlcCharSet) NULL; @@ -196,7 +196,7 @@ _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); diff --git a/nx-X11/lib/X11/lcConv.c b/nx-X11/lib/X11/lcConv.c index 9797e7ed3..0a8a67752 100644 --- a/nx-X11/lib/X11/lcConv.c +++ b/nx-X11/lib/X11/lcConv.c @@ -101,7 +101,7 @@ _XlcSetConverter( } } - list = (XlcConverterList) Xmalloc(sizeof(XlcConverterListRec)); + list = Xmalloc(sizeof(XlcConverterListRec)); if (list == NULL) return False; @@ -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/nx-X11/lib/X11/lcDB.c b/nx-X11/lib/X11/lcDB.c index cb509d273..66250a023 100644 --- a/nx-X11/lib/X11/lcDB.c +++ b/nx-X11/lib/X11/lcDB.c @@ -165,7 +165,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; @@ -248,9 +248,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 */ @@ -486,7 +486,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; @@ -502,11 +502,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); } @@ -1314,7 +1314,7 @@ _XlcCreateLocaleDataBase( lc_db[i].db = p; } - new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec)); + new = Xmalloc(sizeof(XlcDatabaseListRec)); if (new == (XlcDatabaseList)NULL) { goto err; } diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index 12a48615e..a17d358a6 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -577,11 +577,11 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec)); + conv = Xcalloc(1, sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; - state = (State) Xmalloc(sizeof(StateRec)); + state = Xmalloc(sizeof(StateRec)); if (state == NULL) { close_converter(conv); return (XlcConv) NULL; diff --git a/nx-X11/lib/X11/lcEuc.c b/nx-X11/lib/X11/lcEuc.c index 442e3090f..6917a0443 100644 --- a/nx-X11/lib/X11/lcEuc.c +++ b/nx-X11/lib/X11/lcEuc.c @@ -671,7 +671,7 @@ create_conv( { XlcConv conv; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = Xmalloc(sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 96904afa3..4edc1250d 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -2619,11 +2619,11 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec)); + conv = Xcalloc(1, sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; - conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec)); + conv->methods = Xmalloc(sizeof(XlcConvMethodsRec)); if (conv->methods == NULL) goto err; *conv->methods = *methods; diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index f604fe23d..20c455c13 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -68,7 +68,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)); @@ -156,10 +156,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; @@ -183,10 +183,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; @@ -230,10 +230,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) @@ -351,7 +351,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; @@ -504,7 +504,7 @@ 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; @@ -536,10 +536,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) @@ -638,7 +638,7 @@ create_ctextseg( 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]); @@ -668,7 +668,7 @@ create_ctextseg( 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); @@ -871,8 +871,7 @@ load_generic( codeset->byteM = NULL; break ; } - codeset->byteM = - (ByteInfoListRec *)Xmalloc( + codeset->byteM = Xmalloc( (codeset->length)*sizeof(ByteInfoListRec)); if (codeset->byteM == NULL) { goto err; @@ -884,7 +883,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 */ diff --git a/nx-X11/lib/X11/lcJis.c b/nx-X11/lib/X11/lcJis.c index 551862d9b..dc2822ed9 100644 --- a/nx-X11/lib/X11/lcJis.c +++ b/nx-X11/lib/X11/lcJis.c @@ -534,11 +534,11 @@ create_conv( XlcConv conv; State state; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = Xmalloc(sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; - conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec)); + conv->methods = Xmalloc(sizeof(XlcConvMethodsRec)); if (conv->methods == NULL) goto err; *conv->methods = *methods; diff --git a/nx-X11/lib/X11/lcPrTxt.c b/nx-X11/lib/X11/lcPrTxt.c index b86fb7f5e..2ed7d8515 100644 --- a/nx-X11/lib/X11/lcPrTxt.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcPubWrap.c b/nx-X11/lib/X11/lcPubWrap.c index 2a5ac08d8..d1096d570 100644 --- a/nx-X11/lib/X11/lcPubWrap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcPublic.c b/nx-X11/lib/X11/lcPublic.c index 4b26710b2..39ec0829b 100644 --- a/nx-X11/lib/X11/lcPublic.c +++ b/nx-X11/lib/X11/lcPublic.c @@ -88,7 +88,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)); diff --git a/nx-X11/lib/X11/lcRM.c b/nx-X11/lib/X11/lcRM.c index 9f72504ee..aec93a2a3 100644 --- a/nx-X11/lib/X11/lcRM.c +++ b/nx-X11/lib/X11/lcRM.c @@ -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,7 +207,7 @@ _XrmDefaultInitParseInfo( return &ub_methods; } else { /* Multibyte case. */ - MbState state = (MbState) Xmalloc(sizeof(MbStateRec)); + MbState state = Xmalloc(sizeof(MbStateRec)); if (state == NULL) return (XrmMethods) NULL; diff --git a/nx-X11/lib/X11/lcSjis.c b/nx-X11/lib/X11/lcSjis.c index 74dd033ec..eb5e4cad1 100644 --- a/nx-X11/lib/X11/lcSjis.c +++ b/nx-X11/lib/X11/lcSjis.c @@ -1431,7 +1431,7 @@ create_conv( { XlcConv conv; - conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + conv = Xmalloc(sizeof(XlcConvRec)); if (conv == NULL) return (XlcConv) NULL; diff --git a/nx-X11/lib/X11/lcTxtPr.c b/nx-X11/lib/X11/lcTxtPr.c index e980f0168..cf25e3d0e 100644 --- a/nx-X11/lib/X11/lcTxtPr.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcUTF8.c b/nx-X11/lib/X11/lcUTF8.c index 84d87772f..f9739c10a 100644 --- a/nx-X11/lib/X11/lcUTF8.c +++ b/nx-X11/lib/X11/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; @@ -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; @@ -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)); @@ -1742,7 +1742,7 @@ 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)); diff --git a/nx-X11/lib/X11/lcUniConv/8bit_tab_to_h.c b/nx-X11/lib/X11/lcUniConv/8bit_tab_to_h.c index 1caa28a21..993979aeb 100644 --- a/nx-X11/lib/X11/lcUniConv/8bit_tab_to_h.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcUniConv/cjk_tab_to_h.c b/nx-X11/lib/X11/lcUniConv/cjk_tab_to_h.c index 6934789cf..f70fe5e11 100644 --- a/nx-X11/lib/X11/lcUniConv/cjk_tab_to_h.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/lcWrap.c b/nx-X11/lib/X11/lcWrap.c index 358748fdc..b71de7abb 100644 --- a/nx-X11/lib/X11/lcWrap.c +++ b/nx-X11/lib/X11/lcWrap.c @@ -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/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 2c5e8dd06..24d5a902e 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -101,7 +101,7 @@ init_fontdata( FontData fd; int i; - fd = (FontData)Xmalloc(sizeof(FontDataRec) * font_data_count); + fd = Xmalloc(sizeof(FontDataRec) * font_data_count); if(fd == (FontData) NULL) return False; @@ -126,7 +126,7 @@ init_vrotate( if(type == VROTATE_NONE) return (VRotate)NULL; - vrotate = (VRotate)Xmalloc(sizeof(VRotateRec) * font_data_count); + vrotate = Xmalloc(sizeof(VRotateRec) * font_data_count); if(vrotate == (VRotate) NULL) return False; @@ -155,7 +155,7 @@ init_fontset( count = XOM_GENERIC(oc->core.om)->data_num; data = XOM_GENERIC(oc->core.om)->data; - font_set = (FontSet) Xmalloc(sizeof(FontSetRec) * count); + font_set = Xmalloc(sizeof(FontSetRec) * count); if (font_set == NULL) return False; memset((char *) font_set, 0x00, sizeof(FontSetRec) * count); @@ -463,15 +463,15 @@ init_core_part( if (count == 0) return False; - font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *) * count); + font_struct_list = Xmalloc(sizeof(XFontStruct *) * count); if (font_struct_list == NULL) return False; - font_name_list = (char **) Xmalloc(sizeof(char *) * count); + font_name_list = Xmalloc(sizeof(char *) * count); 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; @@ -603,7 +603,7 @@ get_rotate_fontname( if (len > XLFD_MAX_LEN) goto free_pattern; - rotate_font_ptr = (char *)Xmalloc(len + 1); + rotate_font_ptr = Xmalloc(len + 1); if(!rotate_font_ptr) goto free_pattern; @@ -1098,7 +1098,7 @@ parse_vw( Xfree(vrotate); if(sub_num > 0) { - vrotate = font_set->vrotate = (VRotate)Xmalloc + vrotate = font_set->vrotate = Xmalloc (sizeof(VRotateRec) * sub_num); if(font_set->vrotate == (VRotate)NULL) return (-1); @@ -1288,12 +1288,12 @@ set_missing_list( return True; } - charset_list = (char **) Xmalloc(sizeof(char *) * count); + charset_list = Xmalloc(sizeof(char *) * count); if (charset_list == NULL) { return False; } - charset_buf = (char *) Xmalloc(length); + charset_buf = Xmalloc(length); if (charset_buf == NULL) { Xfree(charset_list); return False; @@ -1869,9 +1869,9 @@ add_data( int num; if ((num = gen->data_num)) - new = (OMData) Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec)); + new = Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec)); else - new = (OMData) Xmalloc(sizeof(OMDataRec)); + new = Xmalloc(sizeof(OMDataRec)); if (new == NULL) return NULL; @@ -1910,7 +1910,7 @@ read_EncodingInfo( bufptr++ ; } else len = strlen(buf); - font_data->name = (char *) Xmalloc(len + 1); + font_data->name = Xmalloc(len + 1); if (font_data->name == NULL) { Xfree(font_data); return NULL; @@ -2019,7 +2019,7 @@ init_om( if (data == NULL) return False; - charset_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet) * count); + charset_list = Xmalloc(sizeof(XlcCharSet) * count); if (charset_list == NULL) return False; data->charset_list = charset_list; @@ -2033,7 +2033,7 @@ init_om( if( count > 0){ UDCArea udc; int i,flag = 0; - udc = (UDCArea)Xmalloc(count * sizeof(UDCAreaRec)); + udc = Xmalloc(count * sizeof(UDCAreaRec)); if (udc == NULL) return False; for(i=0;idata_num); + required_list = Xmalloc(sizeof(char *) * gen->data_num); if (required_list == NULL) return False; @@ -2104,7 +2104,7 @@ init_om( data = gen->data; if (count > 0) { - bufptr = (char *) Xmalloc(length); + bufptr = Xmalloc(length); if (bufptr == NULL) { Xfree(required_list); return False; @@ -2118,7 +2118,7 @@ init_om( } /* orientation list */ - orientation = (XOrientation *) Xmalloc(sizeof(XOrientation) * 2); + orientation = Xmalloc(sizeof(XOrientation) * 2); if (orientation == NULL) return False; -- cgit v1.2.3 From d33cf0446fa6bd838f0020da2fd4a0884c2bc5ef Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 23:57:55 -0700 Subject: Don't cast sizeof() results to unsigned when passing to Xmalloc/Xcalloc sizeof() returns size_t, malloc() & calloc() expect sizes in size_t, don't strip down to unsigned int and re-expand unnecessarily. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/CCC.c | 5 ++--- nx-X11/lib/X11/ICWrap.c | 2 +- nx-X11/lib/X11/cmsCmap.c | 5 ++--- nx-X11/lib/X11/cmsInt.c | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/CCC.c b/nx-X11/lib/X11/CCC.c index da8b661dc..de6d6318a 100644 --- a/nx-X11/lib/X11/CCC.c +++ b/nx-X11/lib/X11/CCC.c @@ -111,7 +111,7 @@ XcmsCreateCCC( XcmsPerScrnInfo *pNewScrnInfo; if (pDefaultCCC == NULL || - !(newccc = 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 = - Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { + if (!(pNewScrnInfo = Xcalloc(1, sizeof(XcmsPerScrnInfo)))) { Xfree(newccc); return(NULL); } diff --git a/nx-X11/lib/X11/ICWrap.c b/nx-X11/lib/X11/ICWrap.c index 8584e36a7..dadc8f541 100644 --- a/nx-X11/lib/X11/ICWrap.c +++ b/nx-X11/lib/X11/ICWrap.c @@ -128,7 +128,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return) return; } - args = Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg)); + args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg)); *args_return = args; if (!args) return; diff --git a/nx-X11/lib/X11/cmsCmap.c b/nx-X11/lib/X11/cmsCmap.c index 45843e3b8..8db6ffe30 100644 --- a/nx-X11/lib/X11/cmsCmap.c +++ b/nx-X11/lib/X11/cmsCmap.c @@ -250,8 +250,7 @@ _XcmsAddCmapRec( { XcmsCmapRec *pNew; - if ((pNew = 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 = Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)); + pRec_copy->ccc = Xcalloc(1, sizeof(XcmsCCCRec)); memcpy((char *)pRec_copy->ccc, (char *)pRec_src->ccc, sizeof(XcmsCCCRec)); } diff --git a/nx-X11/lib/X11/cmsInt.c b/nx-X11/lib/X11/cmsInt.c index cefa1e680..f4aef04ff 100644 --- a/nx-X11/lib/X11/cmsInt.c +++ b/nx-X11/lib/X11/cmsInt.c @@ -183,7 +183,7 @@ _XcmsInitDefaultCCCs( * Create an array of XcmsCCC structures, one for each screen. * They serve as the screen's default CCC. */ - if (!(ccc = Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) { + if (!(ccc = Xcalloc((unsigned)nScrn, sizeof(XcmsCCCRec)))) { return(0); } dpy->cms.defaultCCCs = (XPointer)ccc; @@ -322,7 +322,7 @@ _XcmsInitScrnInfo( * here are referenced by the default CCC. */ if (!(defaultccc->pPerScrnInfo = - Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { + Xcalloc(1, sizeof(XcmsPerScrnInfo)))) { return(0); } defaultccc->pPerScrnInfo->state = XcmsInitNone; -- cgit v1.2.3 From 26256188b498e122e21ce0e05521dfc58f8b60a5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Aug 2013 00:07:33 -0700 Subject: Remove unnecessary casts of pointers to (char *) in calls to Xfree() Left one cast behind that is necessary to change from const char * to char * in nx-X11/lib/X11/lcCharSet.c. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Context.c | 12 ++++---- nx-X11/lib/X11/CvCols.c | 4 +-- nx-X11/lib/X11/FetchName.c | 4 +-- nx-X11/lib/X11/Font.c | 66 ++++++++++++++++++++++---------------------- nx-X11/lib/X11/FontInfo.c | 18 ++++++------ nx-X11/lib/X11/FontNames.c | 4 +-- nx-X11/lib/X11/FreeEData.c | 4 +-- nx-X11/lib/X11/FreeGC.c | 2 +- nx-X11/lib/X11/GetFPath.c | 4 +-- nx-X11/lib/X11/GetHints.c | 24 ++++++++-------- nx-X11/lib/X11/GetNrmHint.c | 4 +-- nx-X11/lib/X11/GetRGBCMap.c | 10 +++---- nx-X11/lib/X11/GetStCmap.c | 6 ++-- nx-X11/lib/X11/GetWMCMapW.c | 2 +- nx-X11/lib/X11/GetWMProto.c | 2 +- nx-X11/lib/X11/ICWrap.c | 12 ++++---- nx-X11/lib/X11/IMWrap.c | 2 +- nx-X11/lib/X11/ImUtil.c | 8 +++--- nx-X11/lib/X11/InitExt.c | 2 +- nx-X11/lib/X11/IntAtom.c | 6 ++-- nx-X11/lib/X11/KeyBind.c | 12 ++++---- nx-X11/lib/X11/LRGB.c | 36 ++++++++++++------------ nx-X11/lib/X11/ListExt.c | 6 ++-- nx-X11/lib/X11/ModMap.c | 8 +++--- nx-X11/lib/X11/OpenDis.c | 20 +++++++------- nx-X11/lib/X11/PolyReg.c | 6 ++-- nx-X11/lib/X11/PutImage.c | 6 ++-- nx-X11/lib/X11/QuColors.c | 2 +- nx-X11/lib/X11/Quarks.c | 2 +- nx-X11/lib/X11/RdBitF.c | 4 +-- nx-X11/lib/X11/Region.c | 6 ++-- nx-X11/lib/X11/RegstFlt.c | 4 +-- nx-X11/lib/X11/SetFPath.c | 2 +- nx-X11/lib/X11/SetGetCols.c | 8 +++--- nx-X11/lib/X11/SetHints.c | 2 +- nx-X11/lib/X11/SetRGBCMap.c | 2 +- nx-X11/lib/X11/StBytes.c | 2 +- nx-X11/lib/X11/StCols.c | 2 +- nx-X11/lib/X11/TextToStr.c | 4 +-- nx-X11/lib/X11/VisUtil.c | 4 +-- nx-X11/lib/X11/Xrm.c | 28 +++++++++---------- nx-X11/lib/X11/cmsCmap.c | 6 ++-- nx-X11/lib/X11/imDefIm.c | 4 +-- nx-X11/lib/X11/imLcIm.c | 2 +- nx-X11/lib/X11/imThaiIm.c | 2 +- nx-X11/lib/X11/lcCT.c | 2 +- nx-X11/lib/X11/lcCharSet.c | 4 +-- nx-X11/lib/X11/lcConv.c | 4 +-- nx-X11/lib/X11/lcDB.c | 10 +++---- nx-X11/lib/X11/lcDefConv.c | 4 +-- nx-X11/lib/X11/lcEuc.c | 2 +- nx-X11/lib/X11/lcGenConv.c | 22 +++++++-------- nx-X11/lib/X11/lcJis.c | 4 +-- nx-X11/lib/X11/lcRM.c | 6 ++-- nx-X11/lib/X11/lcSjis.c | 2 +- nx-X11/lib/X11/lcUTF8.c | 4 +-- nx-X11/lib/X11/locking.c | 12 ++++---- nx-X11/lib/X11/mbWMProps.c | 4 +-- nx-X11/lib/X11/utf8WMProps.c | 4 +-- 59 files changed, 230 insertions(+), 230 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Context.c b/nx-X11/lib/X11/Context.c index 4bb465b1a..8a078713a 100644 --- a/nx-X11/lib/X11/Context.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/CvCols.c b/nx-X11/lib/X11/CvCols.c index f543f277b..87d49311c 100644 --- a/nx-X11/lib/X11/CvCols.c +++ b/nx-X11/lib/X11/CvCols.c @@ -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/nx-X11/lib/X11/FetchName.c b/nx-X11/lib/X11/FetchName.c index 7503482fa..060c4b183 100644 --- a/nx-X11/lib/X11/FetchName.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index 26f29d301..041ac58e7 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/FontInfo.c b/nx-X11/lib/X11/FontInfo.c index 0cb5b1910..763aafb3d 100644 --- a/nx-X11/lib/X11/FontInfo.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/FontNames.c b/nx-X11/lib/X11/FontNames.c index 764711559..c50de2eeb 100644 --- a/nx-X11/lib/X11/FontNames.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/FreeEData.c b/nx-X11/lib/X11/FreeEData.c index 3a7abca74..ce78467d3 100644 --- a/nx-X11/lib/X11/FreeEData.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/FreeGC.c b/nx-X11/lib/X11/FreeGC.c index ab994bc64..926d50745 100644 --- a/nx-X11/lib/X11/FreeGC.c +++ b/nx-X11/lib/X11/FreeGC.c @@ -44,7 +44,7 @@ XFreeGC ( UnlockDisplay(dpy); SyncHandle(); _XFreeExtData(gc->ext_data); - Xfree ((char *) gc); + Xfree (gc); return 1; } diff --git a/nx-X11/lib/X11/GetFPath.c b/nx-X11/lib/X11/GetFPath.c index 8f8c6144a..76ff7327b 100644 --- a/nx-X11/lib/X11/GetFPath.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/GetHints.c b/nx-X11/lib/X11/GetHints.c index 80f93b427..589ee9ae2 100644 --- a/nx-X11/lib/X11/GetHints.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/GetNrmHint.c b/nx-X11/lib/X11/GetNrmHint.c index 939d353b9..7871d99de 100644 --- a/nx-X11/lib/X11/GetNrmHint.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/GetRGBCMap.c b/nx-X11/lib/X11/GetRGBCMap.c index c4eff5602..08dc1deaf 100644 --- a/nx-X11/lib/X11/GetRGBCMap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/GetStCmap.c b/nx-X11/lib/X11/GetStCmap.c index 1ca6a0c70..cea20e0f8 100644 --- a/nx-X11/lib/X11/GetStCmap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/GetWMCMapW.c b/nx-X11/lib/X11/GetWMCMapW.c index 04f98a8a8..a28e27ea1 100644 --- a/nx-X11/lib/X11/GetWMCMapW.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/GetWMProto.c b/nx-X11/lib/X11/GetWMProto.c index 1303382fe..32466218d 100644 --- a/nx-X11/lib/X11/GetWMProto.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/ICWrap.c b/nx-X11/lib/X11/ICWrap.c index dadc8f541..2a1d0d670 100644 --- a/nx-X11/lib/X11/ICWrap.c +++ b/nx-X11/lib/X11/ICWrap.c @@ -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/nx-X11/lib/X11/IMWrap.c b/nx-X11/lib/X11/IMWrap.c index 0f6ed5593..a7c1d98c1 100644 --- a/nx-X11/lib/X11/IMWrap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/ImUtil.c b/nx-X11/lib/X11/ImUtil.c index 16dd0fa79..523b2a718 100644 --- a/nx-X11/lib/X11/ImUtil.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/InitExt.c b/nx-X11/lib/X11/InitExt.c index 9e63a9ec2..968f0bb8d 100644 --- a/nx-X11/lib/X11/InitExt.c +++ b/nx-X11/lib/X11/InitExt.c @@ -51,7 +51,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/nx-X11/lib/X11/IntAtom.c b/nx-X11/lib/X11/IntAtom.c index 25466ca20..3042b65dd 100644 --- a/nx-X11/lib/X11/IntAtom.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index e29aeddc0..01f015c65 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index ef1d7fb27..f8e0d66fb 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/ListExt.c b/nx-X11/lib/X11/ListExt.c index 59599d1a6..f40924df7 100644 --- a/nx-X11/lib/X11/ListExt.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index 2fabc560c..78d635bf5 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/OpenDis.c b/nx-X11/lib/X11/OpenDis.c index 89f1edab3..3c56aa580 100644 --- a/nx-X11/lib/X11/OpenDis.c +++ b/nx-X11/lib/X11/OpenDis.c @@ -866,7 +866,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); @@ -908,17 +908,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) { @@ -926,7 +926,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); } if (dpy->display_name) @@ -937,15 +937,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); @@ -955,7 +955,7 @@ void _XFreeDisplayStructure(Display *dpy) while (qelt) { register _XQEvent *qnxt = qelt->next; - Xfree ((char *) qelt); + Xfree (qelt); qelt = qnxt; } } @@ -978,7 +978,7 @@ void _XFreeDisplayStructure(Display *dpy) _XFreeX11XCBStructure(dpy); #endif /* USE_XCB */ - Xfree ((char *)dpy); + Xfree (dpy); } /* OutOfMemory is called if malloc fails. XOpenDisplay returns NULL diff --git a/nx-X11/lib/X11/PolyReg.c b/nx-X11/lib/X11/PolyReg.c index f56a872ca..cb30f8422 100644 --- a/nx-X11/lib/X11/PolyReg.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/PutImage.c b/nx-X11/lib/X11/PutImage.c index 934fabe0f..e6ac9a23f 100644 --- a/nx-X11/lib/X11/PutImage.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/QuColors.c b/nx-X11/lib/X11/QuColors.c index 13a63eb25..0b9bc508f 100644 --- a/nx-X11/lib/X11/QuColors.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/Quarks.c b/nx-X11/lib/X11/Quarks.c index c3e9906f7..132ec6f67 100644 --- a/nx-X11/lib/X11/Quarks.c +++ b/nx-X11/lib/X11/Quarks.c @@ -230,7 +230,7 @@ ExpandQuarkTable(void) } } if (oldmask) - Xfree((char *)oldentries); + Xfree(oldentries); return True; } diff --git a/nx-X11/lib/X11/RdBitF.c b/nx-X11/lib/X11/RdBitF.c index cc3623394..f1e913819 100644 --- a/nx-X11/lib/X11/RdBitF.c +++ b/nx-X11/lib/X11/RdBitF.c @@ -137,7 +137,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) @@ -254,7 +254,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/nx-X11/lib/X11/Region.c b/nx-X11/lib/X11/Region.c index 3c4263760..28fa3e416 100644 --- a/nx-X11/lib/X11/Region.c +++ b/nx-X11/lib/X11/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; @@ -994,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; } diff --git a/nx-X11/lib/X11/RegstFlt.c b/nx-X11/lib/X11/RegstFlt.c index 5a1faa7e9..077ea424c 100644 --- a/nx-X11/lib/X11/RegstFlt.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/SetFPath.c b/nx-X11/lib/X11/SetFPath.c index b1afd8201..60aaef01e 100644 --- a/nx-X11/lib/X11/SetFPath.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/SetGetCols.c b/nx-X11/lib/X11/SetGetCols.c index fc3708585..83fa4c200 100644 --- a/nx-X11/lib/X11/SetGetCols.c +++ b/nx-X11/lib/X11/SetGetCols.c @@ -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/nx-X11/lib/X11/SetHints.c b/nx-X11/lib/X11/SetHints.c index 8e8413069..eed360f46 100644 --- a/nx-X11/lib/X11/SetHints.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/SetRGBCMap.c b/nx-X11/lib/X11/SetRGBCMap.c index def7a22ca..f413c0d69 100644 --- a/nx-X11/lib/X11/SetRGBCMap.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/StBytes.c b/nx-X11/lib/X11/StBytes.c index 390f66832..df533c95d 100644 --- a/nx-X11/lib/X11/StBytes.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/StCols.c b/nx-X11/lib/X11/StCols.c index 95fd6eeba..42a29cd7f 100644 --- a/nx-X11/lib/X11/StCols.c +++ b/nx-X11/lib/X11/StCols.c @@ -102,7 +102,7 @@ XcmsStoreColors( * Free copies as needed. */ if (nColors > 1) { - Xfree((char *)pColors_tmp); + Xfree(pColors_tmp); } /* diff --git a/nx-X11/lib/X11/TextToStr.c b/nx-X11/lib/X11/TextToStr.c index 9252b62a8..03f71558b 100644 --- a/nx-X11/lib/X11/TextToStr.c +++ b/nx-X11/lib/X11/TextToStr.c @@ -77,7 +77,7 @@ Status XTextPropertyToStringList ( start = Xmalloc ((datalen + 1) * sizeof (char)); /* for */ 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/nx-X11/lib/X11/VisUtil.c b/nx-X11/lib/X11/VisUtil.c index aa679928a..17ca3631f 100644 --- a/nx-X11/lib/X11/VisUtil.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index e83b28428..4cba0d5a3 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/cmsCmap.c b/nx-X11/lib/X11/cmsCmap.c index 8db6ffe30..c5401c05d 100644 --- a/nx-X11/lib/X11/cmsCmap.c +++ b/nx-X11/lib/X11/cmsCmap.c @@ -191,7 +191,7 @@ CmapRecForColormap( SyncHandle(); } while (async_state.error_count > 0 && ++j < nVisualsMatched); - Xfree((char *)visualList); + Xfree(visualList); /* * if successful @@ -352,7 +352,7 @@ _XcmsDeleteCmapRec( XcmsFreeCCC(pRec->ccc); } *pPrevPtr = pRec->pNext; - Xfree((char *)pRec); + Xfree(pRec); } } @@ -387,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/nx-X11/lib/X11/imDefIm.c b/nx-X11/lib/X11/imDefIm.c index ce2856bb2..4ccab53ae 100644 --- a/nx-X11/lib/X11/imDefIm.c +++ b/nx-X11/lib/X11/imDefIm.c @@ -1105,10 +1105,10 @@ _XimProtoCloseIM( next = ic->core.next; #ifdef XIM_CONNECTABLE if (!(!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im))) { - Xfree ((char *) ic); + Xfree (ic); } #else - Xfree ((char *) ic); + Xfree (ic); #endif /* XIM_CONNECTABLE */ ic = next; } diff --git a/nx-X11/lib/X11/imLcIm.c b/nx-X11/lib/X11/imLcIm.c index 15e5bee4d..25872e8ab 100644 --- a/nx-X11/lib/X11/imLcIm.c +++ b/nx-X11/lib/X11/imLcIm.c @@ -231,7 +231,7 @@ _XimLocalCloseIM( while (ic) { (*ic->methods->destroy) (ic); next = ic->core.next; - Xfree ((char *) ic); + Xfree (ic); ic = next; } _XimLocalIMFree(im); diff --git a/nx-X11/lib/X11/imThaiIm.c b/nx-X11/lib/X11/imThaiIm.c index d360d0890..c17723aca 100644 --- a/nx-X11/lib/X11/imThaiIm.c +++ b/nx-X11/lib/X11/imThaiIm.c @@ -227,7 +227,7 @@ _XimThaiCloseIM(XIM xim) while (ic) { (*ic->methods->destroy) (ic); next = ic->core.next; - Xfree ((char *) ic); + Xfree (ic); ic = next; } _XimThaiIMFree(im); diff --git a/nx-X11/lib/X11/lcCT.c b/nx-X11/lib/X11/lcCT.c index ee3c76878..6e3f21e92 100644 --- a/nx-X11/lib/X11/lcCT.c +++ b/nx-X11/lib/X11/lcCT.c @@ -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/nx-X11/lib/X11/lcCharSet.c b/nx-X11/lib/X11/lcCharSet.c index 57f13d501..0adf0adfc 100644 --- a/nx-X11/lib/X11/lcCharSet.c +++ b/nx-X11/lib/X11/lcCharSet.c @@ -186,7 +186,7 @@ _XlcCreateDefaultCharSet( /* Fill in name and xrm_name. */ 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); @@ -199,7 +199,7 @@ _XlcCreateDefaultCharSet( 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/nx-X11/lib/X11/lcConv.c b/nx-X11/lib/X11/lcConv.c index 0a8a67752..7d9a4738c 100644 --- a/nx-X11/lib/X11/lcConv.c +++ b/nx-X11/lib/X11/lcConv.c @@ -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 diff --git a/nx-X11/lib/X11/lcDB.c b/nx-X11/lib/X11/lcDB.c index 66250a023..1111ec955 100644 --- a/nx-X11/lib/X11/lcDB.c +++ b/nx-X11/lib/X11/lcDB.c @@ -196,7 +196,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; @@ -1033,10 +1033,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; } } @@ -1249,7 +1249,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) { @@ -1331,7 +1331,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/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index a17d358a6..3cd5c22c9 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -564,9 +564,9 @@ close_converter( XlcConv conv) { if (conv->state) - Xfree((char *) conv->state); + Xfree(conv->state); - Xfree((char *) conv); + Xfree(conv); } static XlcConv diff --git a/nx-X11/lib/X11/lcEuc.c b/nx-X11/lib/X11/lcEuc.c index 6917a0443..5b171a9f3 100644 --- a/nx-X11/lib/X11/lcEuc.c +++ b/nx-X11/lib/X11/lcEuc.c @@ -1363,7 +1363,7 @@ static void close_converter( XlcConv conv) { - Xfree((char *) conv); + Xfree(conv); } enum { MBSTOCS, WCSTOCS, MBTOCS, CSTOMBS, CSTOWCS, MBSTOWCS, WCSTOMBS, diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 4edc1250d..1f7c301f5 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -1224,7 +1224,7 @@ stdc_wcstocts( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -1544,7 +1544,7 @@ stdc_ctstowcs( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -1580,7 +1580,7 @@ stdc_cstowcs( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -1616,7 +1616,7 @@ mbstocts( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2063,7 +2063,7 @@ stdc_wcstostr( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2338,7 +2338,7 @@ ctstombs( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2374,7 +2374,7 @@ cstombs( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2583,7 +2583,7 @@ stdc_strtowcs( ret: if (buf) - Xfree((char *)buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2597,14 +2597,14 @@ close_converter( XlcConv conv) { if (conv->state) { - Xfree((char *) conv->state); + Xfree(conv->state); } if (conv->methods) { - Xfree((char *) conv->methods); + Xfree(conv->methods); } - Xfree((char *) conv); + Xfree(conv); } /* -------------------------------------------------------------------------- */ diff --git a/nx-X11/lib/X11/lcJis.c b/nx-X11/lib/X11/lcJis.c index dc2822ed9..a6917cf9f 100644 --- a/nx-X11/lib/X11/lcJis.c +++ b/nx-X11/lib/X11/lcJis.c @@ -520,10 +520,10 @@ close_converter( XlcConv conv) { if (conv->state) { - Xfree((char *) conv->state); + Xfree(conv->state); } - Xfree((char *) conv); + Xfree(conv); } static XlcConv diff --git a/nx-X11/lib/X11/lcRM.c b/nx-X11/lib/X11/lcRM.c index aec93a2a3..bdc20f21d 100644 --- a/nx-X11/lib/X11/lcRM.c +++ b/nx-X11/lib/X11/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 = { @@ -214,7 +214,7 @@ _XrmDefaultInitParseInfo( 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/nx-X11/lib/X11/lcSjis.c b/nx-X11/lib/X11/lcSjis.c index eb5e4cad1..ac945570a 100644 --- a/nx-X11/lib/X11/lcSjis.c +++ b/nx-X11/lib/X11/lcSjis.c @@ -1420,7 +1420,7 @@ static void close_converter( XlcConv conv) { - Xfree((char *) conv); + Xfree(conv); } diff --git a/nx-X11/lib/X11/lcUTF8.c b/nx-X11/lib/X11/lcUTF8.c index f9739c10a..0f3d0d2ca 100644 --- a/nx-X11/lib/X11/lcUTF8.c +++ b/nx-X11/lib/X11/lcUTF8.c @@ -100,7 +100,7 @@ static void close_converter( XlcConv conv) { - Xfree((char *) conv); + Xfree(conv); } /* Replacement character for invalid multibyte sequence or wide character. */ @@ -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); } /* diff --git a/nx-X11/lib/X11/locking.c b/nx-X11/lib/X11/locking.c index 7c09c44d2..9f4fe0677 100644 --- a/nx-X11/lib/X11/locking.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/mbWMProps.c b/nx-X11/lib/X11/mbWMProps.c index 123d379fc..9fb57faca 100644 --- a/nx-X11/lib/X11/mbWMProps.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/utf8WMProps.c b/nx-X11/lib/X11/utf8WMProps.c index 2ac3e390b..09d643377 100644 --- a/nx-X11/lib/X11/utf8WMProps.c +++ b/nx-X11/lib/X11/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. */ } -- cgit v1.2.3 From c22524d30e773048fad4c14e4636bb045e20439f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Aug 2013 17:02:21 -0700 Subject: Remove long unused udcInf.c I can find no record of what this file was for. Neither the X11R6.8.2 monolith Imakefile nor any modular release Makefile.am have ever built it and nothing else references it. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/udcInf.c | 715 ------------------------------------------------ 1 file changed, 715 deletions(-) delete mode 100644 nx-X11/lib/X11/udcInf.c (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/udcInf.c b/nx-X11/lib/X11/udcInf.c deleted file mode 100644 index 9ecf1566e..000000000 --- a/nx-X11/lib/X11/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 -#endif -#include -#include -#include -#include -#include -#include -#include -#include - -/* - 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= 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 0){ - font_data = read_EncodingInfo(count,value); - for(i=0;i 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;ict_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= 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= 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); -} - -- cgit v1.2.3 From 3cd82252610ac02483f776de95c9c771e71d8864 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 16 Aug 2013 18:14:14 -0700 Subject: Fix overflow checks in _XkbReadKeySyms when key_sym_map is already created We were checking to make sure that the largest keysym value was within the range of the allocated buffer, but checking against different limits in the not-yet-allocated vs. the already-allocated branches. The check should be the same in both, and reflect the size used for the allocation, which is based on the maximum key code value, so we move it to be a common check, before we branch, instead of duplicating in each branch. map->key_sym_map is an array of XkbSymMapRec structs, [0..max_key_code] map->syms is the array for which num_syms is recorded, hence is not the right value to check for ensuring our key_sym_map accesses are in range. Signed-off-by: Alan Coopersmith Reported-by: Barry Kauler Tested-by: Barry Kauler Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGetMap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGetMap.c b/nx-X11/lib/X11/XKBGetMap.c index bfba747aa..529177858 100644 --- a/nx-X11/lib/X11/XKBGetMap.c +++ b/nx-X11/lib/X11/XKBGetMap.c @@ -147,15 +147,16 @@ _XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) { 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; - 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; @@ -212,8 +213,6 @@ XkbClientMapPtr map; 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 *) -- cgit v1.2.3 From 3c5880e7254dcd04ea8e54d53ec99880e2dfdc27 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Aug 2013 13:29:33 -0700 Subject: Reindent XKB code to X.Org standard style Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKB.c | 766 +++++++++---------- nx-X11/lib/X11/XKBAlloc.c | 639 ++++++++-------- nx-X11/lib/X11/XKBBell.c | 123 +-- nx-X11/lib/X11/XKBBind.c | 1080 +++++++++++++------------- nx-X11/lib/X11/XKBCompat.c | 296 ++++---- nx-X11/lib/X11/XKBCtrls.c | 347 +++++---- nx-X11/lib/X11/XKBCvt.c | 294 ++++---- nx-X11/lib/X11/XKBExtDev.c | 1186 +++++++++++++++-------------- nx-X11/lib/X11/XKBGAlloc.c | 1202 ++++++++++++++--------------- nx-X11/lib/X11/XKBGeom.c | 1043 +++++++++++++------------- nx-X11/lib/X11/XKBGetByName.c | 286 +++---- nx-X11/lib/X11/XKBGetMap.c | 1099 ++++++++++++++------------- nx-X11/lib/X11/XKBList.c | 334 +++++---- nx-X11/lib/X11/XKBMAlloc.c | 1666 +++++++++++++++++++++-------------------- nx-X11/lib/X11/XKBMisc.c | 1636 +++++++++++++++++++++------------------- nx-X11/lib/X11/XKBNames.c | 1397 +++++++++++++++++----------------- nx-X11/lib/X11/XKBRdBuf.c | 173 ++--- nx-X11/lib/X11/XKBSetGeom.c | 610 +++++++-------- nx-X11/lib/X11/XKBSetMap.c | 771 +++++++++---------- nx-X11/lib/X11/XKBUse.c | 1374 ++++++++++++++++----------------- nx-X11/lib/X11/XKBleds.c | 377 +++++----- nx-X11/lib/X11/XKBlibint.h | 356 ++++----- 22 files changed, 8714 insertions(+), 8341 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKB.c b/nx-X11/lib/X11/XKB.c index a62e24282..cd0a448ad 100644 --- a/nx-X11/lib/X11/XKB.c +++ b/nx-X11/lib/X11/XKB.c @@ -32,45 +32,47 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #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; @@ -79,49 +81,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(); @@ -129,91 +134,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<selected_events&= ~(1<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<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(); @@ -221,24 +229,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; @@ -252,17 +260,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); @@ -270,7 +278,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; @@ -285,21 +293,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; @@ -313,14 +321,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); @@ -328,7 +336,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; @@ -343,15 +351,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; } @@ -359,9 +367,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; } @@ -371,155 +379,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;imap_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;imap_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); @@ -528,31 +538,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); @@ -561,32 +572,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); @@ -595,33 +606,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); @@ -630,35 +641,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); @@ -667,30 +678,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); @@ -699,69 +711,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/nx-X11/lib/X11/XKBAlloc.c b/nx-X11/lib/X11/XKBAlloc.c index 937e02fae..343c2fcdd 100644 --- a/nx-X11/lib/X11/XKBAlloc.c +++ b/nx-X11/lib/X11/XKBAlloc.c @@ -43,73 +43,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 +117,133 @@ 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;imap->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; + + 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_codemin_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;inum_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 +252,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 +281,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 +294,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;inum_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];isz_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;inum_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/nx-X11/lib/X11/XKBBell.c b/nx-X11/lib/X11/XKBBell.c index ff2d5543a..d3e3a57ff 100644 --- a/nx-X11/lib/X11/XKBBell.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/XKBBind.c b/nx-X11/lib/X11/XKBBind.c index 2d67e9e1e..1952422bd 100644 --- a/nx-X11/lib/X11/XKBBind.c +++ b/nx-X11/lib/X11/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 @@ -42,112 +42,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 ((kcmin_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 ((kcmin_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 @@ -156,21 +160,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; } @@ -178,50 +182,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); } @@ -231,159 +236,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;imap_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+, 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+, 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; @@ -392,99 +403,106 @@ 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_codedesc->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 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); + } #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; } @@ -493,35 +511,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; } @@ -531,166 +550,175 @@ _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;icvt.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; + 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; + } } - 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; } } @@ -698,96 +726,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 @@ -795,54 +826,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/nx-X11/lib/X11/XKBCompat.c b/nx-X11/lib/X11/XKBCompat.c index 35359522c..d5658ce09 100644 --- a/nx-X11/lib/X11/XKBCompat.c +++ b/nx-X11/lib/X11/XKBCompat.c @@ -34,191 +34,197 @@ 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;inSI;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;igroups&bit) - nGroups++; - } - wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf, - nGroups*SIZEOF(xkbModsWireDesc)); - if (wire==NULL) - goto BAILOUT; - for (i=0,bit=1;igroups&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;igroups; + 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;isym= (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;imask= 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; + + 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 +232,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/nx-X11/lib/X11/XKBCtrls.c b/nx-X11/lib/X11/XKBCtrls.c index 198953d79..2e8546d92 100644 --- a/nx-X11/lib/X11/XKBCtrls.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/XKBCvt.c b/nx-X11/lib/X11/XKBCvt.c index d8ceddbdc..f4df3fcfc 100644 --- a/nx-X11/lib/X11/XKBCvt.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/XKBExtDev.c b/nx-X11/lib/X11/XKBExtDev.c index 47b94a3aa..37847dcfd 100644 --- a/nx-X11/lib/X11/XKBExtDev.c +++ b/nx-X11/lib/X11/XKBExtDev.c @@ -37,68 +37,73 @@ 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_btnfirst_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; + + 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 +111,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;inamesPresent&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;imapsPresent&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;inDeviceLedFBs;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 +280,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 +342,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 +428,303 @@ 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;inum_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;inames_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];inum_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;inames[i]; - awire++; - } - } - wire= (char *)awire; + 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; } if (mapsNeeded) { - xkbIndicatorMapWireDesc *mwire; - - mwire= (xkbIndicatorMapWireDesc *)wire; - for (i=0,bit=1;imaps[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; + + 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; } 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; + + 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; } - if (changes->changed&XkbXI_IndicatorsMask) { - register int i; - register LedInfoStuff *linfo; - - for (i=0,linfo=&stuff->info[0];inum_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 +734,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 +784,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/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index 74cadaee0..f52a0e70e 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -40,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=(*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; } @@ -135,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; } @@ -181,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; } @@ -215,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; } @@ -238,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; } @@ -272,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; } @@ -294,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; } @@ -328,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); } /***====================================================================***/ @@ -349,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; } @@ -375,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;iproperties!=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; } @@ -453,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;inum_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;inum_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;inum_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;inum_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; } @@ -790,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;inum_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;iany.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;inum_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;inum_rows;i++) { - if (overlay->rows[i].row_under==row_under) { - row= &overlay->rows[i]; - if ((row->sz_keysrows[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;inum_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/nx-X11/lib/X11/XKBGeom.c b/nx-X11/lib/X11/XKBGeom.c index 2f34bea80..3666d16fa 100644 --- a/nx-X11/lib/X11/XKBGeom.c +++ b/nx-X11/lib/X11/XKBGeom.c @@ -47,149 +47,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 (xx1) bounds->x1= x; - if (x>bounds->x2) bounds->x2= x; - if (yy1) 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;onum_outlines;o++,outline++) { - for (pt=outline->points,p=0;pnum_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;pnum_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;knum_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;inum_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;inum_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; } @@ -197,39 +208,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;snum_sections;s++,section++) { - XkbOverlayPtr ol; - int o; - - if (section->num_overlays<1) - continue; - for (o=0,ol=section->overlays;onum_overlays;o++,ol++) { - XkbOverlayRowPtr row; - int r; - - for (r=0,row=ol->rows;rnum_rows;r++,row++) { - XkbOverlayKeyPtr key; - int k; - for (k=0,key=row->keys;knum_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; } @@ -237,463 +251,476 @@ 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;(inProperties)&&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; + 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; } 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;inColors;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; + 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; } 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;inShapes;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;onOutlines;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;pnPoints;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;rnRows;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;knKeys;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;snSections;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;rnRows;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;knKeys;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;dnDoodads;d++) { - if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success) - return rtrn; - } - } - if (sectionWire->nOverlays>0) { - register int o; - for (o=0;onOverlays;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; + 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; + } + } } 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;dnDoodads;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/nx-X11/lib/X11/XKBGetByName.c b/nx-X11/lib/X11/XKBGetByName.c index 5c6eca0e2..4a6ca9392 100644 --- a/nx-X11/lib/X11/XKBGetByName.c +++ b/nx-X11/lib/X11/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/nx-X11/lib/X11/XKBGetMap.c b/nx-X11/lib/X11/XKBGetMap.c index 529177858..db761611a 100644 --- a/nx-X11/lib/X11/XKBGetMap.c +++ b/nx-X11/lib/X11/XKBGetMap.c @@ -33,428 +33,444 @@ 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;nmap_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;nnMapEntries;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; -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; + 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; - - 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; - } + xkbSymMapWireDesc *newMap; + XkbSymMapPtr oldMap; + KeySym *newSyms; + int tmp; + + 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; + } } 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;itotalKeyBehaviors;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; + 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; + } } 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;ivirtualMods&bit) - nVMods++; - } - data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods)); - if (data==NULL) - return BadLength; - for (i=0,bit=1;(i0);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;itotalKeyExplicit;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;itotalModMapKeys;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;itotalVModMapKeys;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; @@ -473,142 +489,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(); @@ -616,24 +637,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(); @@ -641,24 +662,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(); @@ -667,24 +688,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(); @@ -692,20 +713,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(); @@ -713,32 +734,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; @@ -748,29 +771,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; @@ -780,30 +807,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; @@ -813,40 +842,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/nx-X11/lib/X11/XKBList.c b/nx-X11/lib/X11/XKBList.c index cdbb27063..d8086a305 100644 --- a/nx-X11/lib/X11/XKBList.c +++ b/nx-X11/lib/X11/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;iname) { - _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,180 @@ 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;iflags= 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; + + 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 +238,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/nx-X11/lib/X11/XKBMAlloc.c b/nx-X11/lib/X11/XKBMAlloc.c index c81540aae..8586ae966 100644 --- a/nx-X11/lib/X11/XKBMAlloc.c +++ b/nx-X11/lib/X11/XKBMAlloc.c @@ -41,176 +41,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)&&(nTotalTypesmin_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_codemin_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_typestypes; - - 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_codemin_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;ivmods[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_codemin_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_codemin_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)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_codemin_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_codemin_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 +224,220 @@ 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;imap; - if ((map)&&(map->types)) { - for (i=0;inum_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_typesmap; + 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; 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;inum_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 +460,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 (widthnum_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_lvlsnum_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 (widthnum_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=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,404 +627,410 @@ 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)||(minKCXkbMaxLegalKeyCode)) - return BadValue; - if (minKC>maxKC) - return BadMatch; - if (minKCmin_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; - } + 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; + } #ifdef NXAGENT_SERVER - bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code+1], - tmp*sizeof(XkbSymMapRec)); + bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code + 1], + tmp * sizeof(XkbSymMapRec)); #else - bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code], - tmp*sizeof(XkbSymMapRec)); + bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code], + tmp * sizeof(XkbSymMapRec)); #endif - 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; - } + 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; + } #ifdef NXAGENT_SERVER - bzero((char *)&xkb->map->modmap[xkb->max_key_code+1],tmp); + bzero((char *) &xkb->map->modmap[xkb->max_key_code + 1], tmp); #else - bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp); + bzero((char *) &xkb->map->modmap[xkb->max_key_code], tmp); #endif - 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; - } + 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; + } #ifdef NXAGENT_SERVER - bzero((char *)&xkb->server->behaviors[xkb->max_key_code+1], - tmp*sizeof(XkbBehavior)); + bzero((char *) &xkb->server->behaviors[xkb->max_key_code + 1], + tmp * sizeof(XkbBehavior)); #else - bzero((char *)&xkb->server->behaviors[xkb->max_key_code], - tmp*sizeof(XkbBehavior)); + bzero((char *) &xkb->server->behaviors[xkb->max_key_code], + tmp * sizeof(XkbBehavior)); #endif - 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; - } + 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; + } #ifdef NXAGENT_SERVER - bzero((char *)&xkb->server->key_acts[xkb->max_key_code+1], - tmp*sizeof(unsigned short)); + bzero((char *) &xkb->server->key_acts[xkb->max_key_code + 1], + tmp * sizeof(unsigned short)); #else - bzero((char *)&xkb->server->key_acts[xkb->max_key_code], - tmp*sizeof(unsigned short)); + bzero((char *) &xkb->server->key_acts[xkb->max_key_code], + tmp * sizeof(unsigned short)); #endif - 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; - } + 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; + } #ifdef NXAGENT_SERVER - bzero((char *)&xkb->server->vmodmap[xkb->max_key_code+1], - tmp*sizeof(unsigned short)); + bzero((char *) &xkb->server->vmodmap[xkb->max_key_code + 1], + tmp * sizeof(unsigned short)); #else - bzero((char *)&xkb->server->vmodmap[xkb->max_key_code], - tmp*sizeof(unsigned short)); + bzero((char *) &xkb->server->vmodmap[xkb->max_key_code], + tmp * sizeof(unsigned short)); #endif - 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; - } + 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; + } #ifdef NXAGENT_SERVER - bzero((char *)&xkb->names->keys[xkb->max_key_code+1], - tmp*sizeof(XkbKeyNameRec)); + bzero((char *) &xkb->names->keys[xkb->max_key_code + 1], + tmp * sizeof(XkbKeyNameRec)); #else - bzero((char *)&xkb->names->keys[xkb->max_key_code], - tmp*sizeof(XkbKeyNameRec)); + bzero((char *) &xkb->names->keys[xkb->max_key_code], + tmp * sizeof(XkbKeyNameRec)); #endif - if (changes) { - changes->names.changed= _ExtendRange(changes->names.changed, - XkbKeyNamesMask,maxKC, - &changes->names.first_key, - &changes->names.num_keys); - } - } - xkb->max_key_code= maxKC; + 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 (needed0) - memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i), - nCopy*sizeof(XkbAction)); - if (nCopyserver->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;inum_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/nx-X11/lib/X11/XKBMisc.c b/nx-X11/lib/X11/XKBMisc.c index 4a12946e0..4267b214f 100644 --- a/nx-X11/lib/X11/XKBMisc.c +++ b/nx-X11/lib/X11/XKBMisc.c @@ -41,94 +41,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)&&(keypadVModmods.vmods= (1<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<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; } @@ -139,264 +142,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;imap->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=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;i1)&&(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< 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<= 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)&&(imap->types[types_inout[i]].num_levels==1); - } - if ((sameType)&& - (!(protected&(XkbExplicitKeyTypesMask&~XkbExplicitKeyType1Mask)))){ - register int s; - Bool identical; - for (i=1,identical=True;identical&&(i1)) { - KeySym *syms; - syms= &xkb_syms_rtrn[nSyms[XkbGroup1Index]]; - nSyms[XkbGroup1Index]= 1; - for (i=1;i 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;icompat->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; } @@ -404,357 +426,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)|| - (keymin_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;nact.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;nact); - if ((n==0)||((interps[n]->match&XkbSI_LevelOneOnly)==0)) { - effMods= mods; - if (interps[n]->virtual_mod!=XkbNoModifier) - new_vmodmask|= (1<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;iserver->vmodmap[key]) { - present|= bit; - newVMods[i]|= xkb->map->modmap[key]; - } - } - } - for (i=0,bit=1;iserver->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;imap->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;i0) - 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;imap->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;(imap->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;(imap->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;imap->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; } @@ -762,204 +801,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;iserver->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 = 0; - - 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;imap_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 = 0; + + 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_ndxmap.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;imap->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 = 0; - 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 = 0; - 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;imods.vmods&changed) { - unsigned int newMask = 0; - 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<compat!=NULL) { - XkbCompatMapPtr compat; - compat= xkb->compat; - for (i=0;igroups[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<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 = 0; + + 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 = 0; + + 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 = 0; + + 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 = 0; + + 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_actmap.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/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index dc5ef90d7..7eaf92335 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/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;(idevice_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;(inum_types)&&(inTypes);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; + 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); + } + } } 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_rgnRadioGroups) { - 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;iflags & 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;ilevel_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;iname,4); - } - } - if (which&XkbKTLevelNamesMask) { - XkbKeyTypePtr type; - int i; - char *tmp; - - BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes)); - type = &xkb->map->types[firstLvlType]; - for (i=0;inum_levels; - } - type = &xkb->map->types[firstLvlType]; - for (i=0;ilevel_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;ilevel_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_keymin_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; + 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; 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;iname,4); - } - } - if (which&XkbKTLevelNamesMask) { - XkbKeyTypePtr type; - int i; - char *tmp; - - BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes)); - type = &xkb->map->types[firstLvlType]; - for (i=0;inum_levels; - } - type = &xkb->map->types[firstLvlType]; - for (i=0;ilevel_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_typefirst_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_lvlfirst_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_keyfirst_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/nx-X11/lib/X11/XKBRdBuf.c b/nx-X11/lib/X11/XKBRdBuf.c index 694d579f7..60d7c7364 100644 --- a/nx-X11/lib/X11/XKBRdBuf.c +++ b/nx-X11/lib/X11/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)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)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)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)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/nx-X11/lib/X11/XKBSetGeom.c b/nx-X11/lib/X11/XKBSetGeom.c index e951afaeb..e5e524fa4 100644 --- a/nx-X11/lib/X11/XKBSetGeom.c +++ b/nx-X11/lib/X11/XKBSetGeom.c @@ -48,28 +48,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;inum_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; } @@ -77,11 +78,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;inum_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; } @@ -89,35 +90,36 @@ register XkbColorPtr color; static int _SizeGeomShapes(XkbGeometryPtr geom) { -register int i,size; -register XkbShapePtr shape; - - for (i=size=0,shape=geom->shapes;inum_shapes;i++,shape++) { - register int n; - register XkbOutlinePtr ol; - size+= SIZEOF(xkbShapeWireDesc); - for (n=0,ol=shape->outlines;nnum_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;iany.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; } @@ -125,34 +127,39 @@ register int i,size; static int _SizeGeomSections(XkbGeometryPtr geom) { -register int i,size; -XkbSectionPtr section; - - for (i=size=0,section=geom->sections;inum_sections;i++,section++) { - size+= SIZEOF(xkbSectionWireDesc); - if (section->rows) { - int r; - XkbRowPtr row; - for (r=0,row=section->rows;rnum_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;onum_overlays;o++,ol++) { - int r; - XkbOverlayRowPtr row; - size+= SIZEOF(xkbOverlayWireDesc); - for (r=0,row=ol->rows;rnum_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; } @@ -160,224 +167,234 @@ 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;inum_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;inum_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;inum_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;onum_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;pnum_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;iany.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; + 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; + } } 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;rnum_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;knum_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; + + 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; } 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;inum_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;rnum_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;knum_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;onum_overlays;o++) { - wire= _WriteGeomOverlay(wire,§ion->overlays[o]); - } - } + 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]); + } + } } 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; } @@ -385,46 +402,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; } @@ -432,35 +449,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/nx-X11/lib/X11/XKBSetMap.c b/nx-X11/lib/X11/XKBSetMap.c index 994e401d2..dbf1a8a96 100644 --- a/nx-X11/lib/X11/XKBSetMap.c +++ b/nx-X11/lib/X11/XKBSetMap.c @@ -33,221 +33,224 @@ 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;inTypes;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, sz; xkbKeyTypeWireDesc *desc; - if ((req->present&XkbKeyTypesMask)==0) - return; - type= &xkb->map->types[req->firstType]; - for (i=0;inTypes;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;nmap_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;nmap_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++) { + 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; + } + } + } } 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;inKeySyms;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;inKeySyms;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;inKeyActs;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;inKeyActs;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;inKeyActs;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 +258,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;ivirtualMods&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;ivirtualMods&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 +500,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 +576,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 +593,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/nx-X11/lib/X11/XKBUse.c b/nx-X11/lib/X11/XKBUse.c index 9ce60f12c..0af4679d3 100644 --- a/nx-X11/lib/X11/XKBUse.c +++ b/nx-X11/lib/X11/XKBUse.c @@ -33,558 +33,562 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #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_typefirst_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_symfirst_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_actfirst_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_behaviorfirst_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_explicitfirst_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_keyfirst_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_keyfirst_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_keycodefirst_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; + + 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: #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; } @@ -592,15 +596,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; @@ -611,126 +617,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); @@ -740,58 +762,64 @@ 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; + + 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/nx-X11/lib/X11/XKBleds.c b/nx-X11/lib/X11/XKBleds.c index 6c1b46140..c098ee948 100644 --- a/nx-X11/lib/X11/XKBleds.c +++ b/nx-X11/lib/X11/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;(imaps[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/nx-X11/lib/X11/XKBlibint.h b/nx-X11/lib/X11/XKBlibint.h index d14c7df10..dad48b703 100644 --- a/nx-X11/lib/X11/XKBlibint.h +++ b/nx-X11/lib/X11/XKBlibint.h @@ -25,210 +25,210 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ #ifndef _XKBLIBINT_H_ -#define _XKBLIBINT_H_ +#define _XKBLIBINT_H_ #include #include -#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 - */ + /* + * 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 @@ -237,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 -- cgit v1.2.3 From 2824899d280f2b169b3e745b222f9a981c1ce5f7 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 16 Aug 2013 18:27:28 -0700 Subject: Rearrange some variable declarations & initializations in XKB Little things noticed during XKB restyling that seemed to make the code easier to read. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBAlloc.c | 3 +-- nx-X11/lib/X11/XKBBind.c | 16 ++++++++-------- nx-X11/lib/X11/XKBCompat.c | 3 +-- nx-X11/lib/X11/XKBExtDev.c | 18 ++++++------------ nx-X11/lib/X11/XKBGeom.c | 21 ++++++++++----------- nx-X11/lib/X11/XKBGetMap.c | 13 +++++++------ nx-X11/lib/X11/XKBList.c | 3 +-- nx-X11/lib/X11/XKBMAlloc.c | 4 +--- nx-X11/lib/X11/XKBNames.c | 8 ++++---- nx-X11/lib/X11/XKBSetGeom.c | 24 ++++++++++-------------- nx-X11/lib/X11/XKBSetMap.c | 10 ++++------ nx-X11/lib/X11/XKBUse.c | 37 +++++++++++++------------------------ 12 files changed, 66 insertions(+), 94 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBAlloc.c b/nx-X11/lib/X11/XKBAlloc.c index 343c2fcdd..ed00f7ff2 100644 --- a/nx-X11/lib/X11/XKBAlloc.c +++ b/nx-X11/lib/X11/XKBAlloc.c @@ -132,9 +132,8 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases) if ((which & XkbKTLevelNamesMask) && (xkb->map != NULL) && (xkb->map->types != NULL)) { register int i; - XkbKeyTypePtr type; + XkbKeyTypePtr type = xkb->map->types; - 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); diff --git a/nx-X11/lib/X11/XKBBind.c b/nx-X11/lib/X11/XKBBind.c index 1952422bd..37f1b8ad6 100644 --- a/nx-X11/lib/X11/XKBBind.c +++ b/nx-X11/lib/X11/XKBBind.c @@ -450,23 +450,24 @@ XRefreshKeyboardMapping(register XMappingEvent * event) fprintf(stderr, " symbols: %d..%d\n", first, last); } if (changes.changed & XkbKeyActionsMask) { - int last, first = changes.first_key_act; + int first = changes.first_key_act; + int last = changes.first_key_act + changes.num_key_acts - 1; - 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; + 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 last, first = changes.first_key_explicit; + int first = changes.first_key_explicit; + int last = first + changes.num_key_explicit - 1; - last = first + changes.num_key_explicit - 1; fprintf(stderr, " explicit: %d..%d\n", first, last); } #endif @@ -643,10 +644,9 @@ XkbTranslateKeySym(register Display *dpy, if ((!xkb->cvt.KSToUpper) && (mods & LockMask)) { register int i; int change; - char ch; for (i = change = 0; i < n; i++) { - ch = toupper(buffer[i]); + char ch = toupper(buffer[i]); change = (change || (buffer[i] != ch)); buffer[i] = ch; } diff --git a/nx-X11/lib/X11/XKBCompat.c b/nx-X11/lib/X11/XKBCompat.c index d5658ce09..a5222b56e 100644 --- a/nx-X11/lib/X11/XKBCompat.c +++ b/nx-X11/lib/X11/XKBCompat.c @@ -195,9 +195,8 @@ _XkbWriteSetCompatMap(Display *dpy, xkbSetCompatMapReq *req, XkbDescPtr xkb) buf += nSI * SIZEOF(xkbSymInterpretWireDesc); } if (groups & XkbAllGroupsMask) { - xkbModsWireDesc *out; + xkbModsWireDesc *out = (xkbModsWireDesc *) buf; - out = (xkbModsWireDesc *) buf; for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) { if ((groups & bit) != 0) { out->mask = xkb->compat->groups[i].mask; diff --git a/nx-X11/lib/X11/XKBExtDev.c b/nx-X11/lib/X11/XKBExtDev.c index 37847dcfd..25c76ab11 100644 --- a/nx-X11/lib/X11/XKBExtDev.c +++ b/nx-X11/lib/X11/XKBExtDev.c @@ -68,9 +68,8 @@ XkbNoteDeviceChanges(XkbDeviceChangesPtr old, XkbDeviceLedChangesPtr this; if (old->changed & XkbXI_IndicatorsMask) { - XkbDeviceLedChangesPtr found; + XkbDeviceLedChangesPtr found = NULL; - found = NULL; for (this = &old->leds; this && (!found); this = this->next) { if ((this->led_class == new->led_class) && (this->led_id == new->led_id)) { @@ -607,9 +606,8 @@ _XkbWriteLedInfo(char *wire, unsigned changed, XkbDeviceLedInfoPtr devli) lwire->state = devli->state; wire = (char *) &lwire[1]; if (namesNeeded) { - CARD32 *awire; + CARD32 *awire = (CARD32 *) wire; - awire = (CARD32 *) wire; for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { if (namesNeeded & bit) { *awire = (CARD32) devli->names[i]; @@ -619,14 +617,12 @@ _XkbWriteLedInfo(char *wire, unsigned changed, XkbDeviceLedInfoPtr devli) wire = (char *) awire; } if (mapsNeeded) { - xkbIndicatorMapWireDesc *mwire; + xkbIndicatorMapWireDesc *mwire = (xkbIndicatorMapWireDesc *) wire; - mwire = (xkbIndicatorMapWireDesc *) wire; for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { if (mapsNeeded & bit) { - XkbIndicatorMapPtr map; + XkbIndicatorMapPtr map = &devli->maps[i]; - map = &devli->maps[i]; mwire->flags = map->flags; mwire->whichGroups = map->which_groups; mwire->groups = map->groups; @@ -650,13 +646,11 @@ _XkbWriteSetDeviceInfo(char *wire, SetLedStuff *stuff, XkbDeviceInfoPtr devi) { - char *start; + char *start = wire; - start = wire; if (changes->changed & XkbXI_ButtonActionsMask) { - int size; + int size = changes->num_btns * SIZEOF(xkbActionWireDesc); - size = changes->num_btns * SIZEOF(xkbActionWireDesc); memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], size); wire += size; } diff --git a/nx-X11/lib/X11/XKBGeom.c b/nx-X11/lib/X11/XKBGeom.c index 3666d16fa..1014c9adb 100644 --- a/nx-X11/lib/X11/XKBGeom.c +++ b/nx-X11/lib/X11/XKBGeom.c @@ -261,13 +261,11 @@ _XkbReadGeomProperties(XkbReadBufferPtr buf, return Success; if ((rtrn = XkbAllocGeomProps(geom, rep->nProperties)) == Success) { register int i; - register Bool ok; - char *name, *value; + register Bool ok = True; - ok = True; for (i = 0; (i < rep->nProperties) && ok; i++) { - name = NULL; - value = NULL; + char *name = NULL; + char *value = NULL; ok = _XkbGetReadBufferCountedString(buf, &name) && ok; ok = _XkbGetReadBufferCountedString(buf, &value) && ok; ok = ok && (XkbAddGeomProperty(geom, name, value) != NULL); @@ -317,10 +315,9 @@ _XkbReadGeomColors(XkbReadBufferPtr buf, return Success; if ((rtrn = XkbAllocGeomColors(geom, rep->nColors)) == Success) { register int i; - char *spec; for (i = 0; i < rep->nColors; i++) { - spec = NULL; + char *spec = NULL; if (!_XkbGetReadBufferCountedString(buf, &spec)) rtrn = BadLength; else if (XkbAddGeomColor(geom, spec, geom->num_colors) == NULL) @@ -531,10 +528,11 @@ _XkbReadGeomSections(XkbReadBufferPtr buf, section->priority = sectionWire->priority; if (sectionWire->nRows > 0) { register int r; - XkbRowPtr row; - xkbRowWireDesc *rowWire; for (r = 0; r < sectionWire->nRows; r++) { + XkbRowPtr row; + xkbRowWireDesc *rowWire; + rowWire = (xkbRowWireDesc *) _XkbGetReadBufferPtr(buf, SIZEOF(xkbRowWireDesc)); if (!rowWire) @@ -547,10 +545,11 @@ _XkbReadGeomSections(XkbReadBufferPtr buf, row->vertical = rowWire->vertical; if (rowWire->nKeys > 0) { register int k; - XkbKeyPtr key; - xkbKeyWireDesc *keyWire; for (k = 0; k < rowWire->nKeys; k++) { + XkbKeyPtr key; + xkbKeyWireDesc *keyWire; + keyWire = (xkbKeyWireDesc *) _XkbGetReadBufferPtr(buf, SIZEOF(xkbKeyWireDesc)); if (!keyWire) diff --git a/nx-X11/lib/X11/XKBGetMap.c b/nx-X11/lib/X11/XKBGetMap.c index db761611a..6e3c74343 100644 --- a/nx-X11/lib/X11/XKBGetMap.c +++ b/nx-X11/lib/X11/XKBGetMap.c @@ -211,13 +211,13 @@ _XkbReadKeySyms(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) map->num_syms = offset; } else { - xkbSymMapWireDesc *newMap; - XkbSymMapPtr oldMap; - KeySym *newSyms; - int tmp; + XkbSymMapPtr oldMap = &map->key_sym_map[rep->firstKeySym]; - 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) @@ -310,7 +310,6 @@ static Status _XkbReadKeyBehaviors(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) { register int i; - xkbBehaviorWireDesc *wire; if (rep->totalKeyBehaviors > 0) { int size = xkb->max_key_code + 1; @@ -327,6 +326,8 @@ _XkbReadKeyBehaviors(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) (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) diff --git a/nx-X11/lib/X11/XKBList.c b/nx-X11/lib/X11/XKBList.c index d8086a305..d3d29e2a6 100644 --- a/nx-X11/lib/X11/XKBList.c +++ b/nx-X11/lib/X11/XKBList.c @@ -193,9 +193,8 @@ XkbListComponents(Display *dpy, return list; } if (_XkbInitReadBuffer(dpy, &buf, extraLen)) { - Status status; + Status status = Success; - status = Success; list = _XkbTypedCalloc(1, XkbComponentListRec); if (!list) { _XkbFreeReadBuffer(&buf); diff --git a/nx-X11/lib/X11/XKBMAlloc.c b/nx-X11/lib/X11/XKBMAlloc.c index 8586ae966..c7c138e4d 100644 --- a/nx-X11/lib/X11/XKBMAlloc.c +++ b/nx-X11/lib/X11/XKBMAlloc.c @@ -297,9 +297,7 @@ XkbAddKeyType(XkbDescPtr xkb, if ((map) && (map->types)) { for (i = 0; i < map->num_types; i++) { if (map->types[i].name == name) { - Status status; - - status = + Status status = XkbResizeKeyType(xkb, i, map_count, want_preserve, num_lvls); return (status == Success ? &map->types[i] : NULL); diff --git a/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index 7eaf92335..3cfd02f96 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/XKBNames.c @@ -116,14 +116,14 @@ _XkbReadGetNamesReply(Display *dpy, 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; + XkbKeyTypePtr type = map->types; + for (i = 0; i < (int) rep->nTypes; i++, type++) { if (i >= map->num_types) { if (!_XkbSkipReadBufferData(&buf, nLevels[i] * 4)) @@ -577,14 +577,14 @@ XkbChangeNames(Display *dpy, XkbDescPtr xkb, XkbNameChangesPtr changes) 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]; + XkbKeyTypePtr type = &xkb->map->types[firstLvlType]; + for (i = nLvlNames = 0; i < nLvlTypes; i++, type++) { if (type->level_names != NULL) nLvlNames += type->num_levels; diff --git a/nx-X11/lib/X11/XKBSetGeom.c b/nx-X11/lib/X11/XKBSetGeom.c index e5e524fa4..ee254e0dc 100644 --- a/nx-X11/lib/X11/XKBSetGeom.c +++ b/nx-X11/lib/X11/XKBSetGeom.c @@ -245,10 +245,10 @@ static char * _WriteGeomDoodads(char *wire, int num_doodads, XkbDoodadPtr doodad) { register int i; - xkbDoodadWireDesc *doodadWire; for (i = 0; i < num_doodads; i++, doodad++) { - doodadWire = (xkbDoodadWireDesc *) wire; + xkbDoodadWireDesc *doodadWire = (xkbDoodadWireDesc *) wire; + wire = (char *) &doodadWire[1]; bzero(doodadWire, SIZEOF(xkbDoodadWireDesc)); doodadWire->any.name = doodad->any.name; @@ -292,25 +292,22 @@ _WriteGeomOverlay(char *wire, XkbOverlayPtr ol) { register int r; XkbOverlayRowPtr row; - xkbOverlayWireDesc *olWire; + xkbOverlayWireDesc *olWire = (xkbOverlayWireDesc *) wire; - 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 *rowWire = (xkbOverlayRowWireDesc *) wire; - 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 *keyWire = (xkbOverlayKeyWireDesc *) wire; - keyWire = (xkbOverlayKeyWireDesc *) wire; memcpy(keyWire->over, key->over.name, XkbKeyNameLength); memcpy(keyWire->under, key->under.name, XkbKeyNameLength); wire = (char *) &keyWire[1]; @@ -324,11 +321,11 @@ _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; + xkbSectionWireDesc *sectionWire = (xkbSectionWireDesc *) wire; + sectionWire->name = section->name; sectionWire->top = section->top; sectionWire->left = section->left; @@ -344,10 +341,10 @@ _WriteGeomSections(char *wire, XkbGeometryPtr geom) if (section->rows) { int r; XkbRowPtr row; - xkbRowWireDesc *rowWire; for (r = 0, row = section->rows; r < section->num_rows; r++, row++) { - rowWire = (xkbRowWireDesc *) wire; + xkbRowWireDesc *rowWire = (xkbRowWireDesc *) wire; + rowWire->top = row->top; rowWire->left = row->left; rowWire->nKeys = row->num_keys; @@ -357,9 +354,8 @@ _WriteGeomSections(char *wire, XkbGeometryPtr geom) if (row->keys) { int k; XkbKeyPtr key; - xkbKeyWireDesc *keyWire; + xkbKeyWireDesc *keyWire = (xkbKeyWireDesc *) wire; - keyWire = (xkbKeyWireDesc *) wire; for (k = 0, key = row->keys; k < row->num_keys; k++, key++) { memcpy(keyWire[k].name, key->name.name, XkbKeyNameLength); diff --git a/nx-X11/lib/X11/XKBSetMap.c b/nx-X11/lib/X11/XKBSetMap.c index dbf1a8a96..cb696105c 100644 --- a/nx-X11/lib/X11/XKBSetMap.c +++ b/nx-X11/lib/X11/XKBSetMap.c @@ -59,14 +59,14 @@ _XkbWriteKeyTypes(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) { char *buf; XkbKeyTypePtr type; - int i, n, sz; + 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); + int sz = SIZEOF(xkbKeyTypeWireDesc); sz += type->map_count * SIZEOF(xkbKTSetMapEntryWireDesc); if (type->preserve) sz += type->map_count * SIZEOF(xkbModsWireDesc); @@ -79,9 +79,8 @@ _XkbWriteKeyTypes(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) desc->preserve = (type->preserve != NULL); buf = (char *) &desc[1]; if (desc->nMapEntries > 0) { - xkbKTSetMapEntryWireDesc *wire; + xkbKTSetMapEntryWireDesc *wire = (xkbKTSetMapEntryWireDesc *) buf; - 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; @@ -89,9 +88,8 @@ _XkbWriteKeyTypes(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req) } buf = (char *) wire; if (type->preserve) { - xkbModsWireDesc *pwire; + xkbModsWireDesc *pwire = (xkbModsWireDesc *) buf; - 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; diff --git a/nx-X11/lib/X11/XKBUse.c b/nx-X11/lib/X11/XKBUse.c index 0af4679d3..cf6497551 100644 --- a/nx-X11/lib/X11/XKBUse.c +++ b/nx-X11/lib/X11/XKBUse.c @@ -263,9 +263,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) if ((xkbi->selected_events & XkbMapNotifyMask) && (xkbi->selected_map_details & mn->changed)) { - XkbMapNotifyEvent *mev; + XkbMapNotifyEvent *mev = (XkbMapNotifyEvent *) re; - mev = (XkbMapNotifyEvent *) re; mev->type = XkbEventCode + xkbi->codes->first_event; mev->xkb_type = XkbMapNotify; mev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -318,9 +317,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbControlsNotifyMask) { xkbControlsNotify *cn = (xkbControlsNotify *) event; - XkbControlsNotifyEvent *cev; + XkbControlsNotifyEvent *cev = (XkbControlsNotifyEvent *) re; - cev = (XkbControlsNotifyEvent *) re; cev->type = XkbEventCode + xkbi->codes->first_event; cev->xkb_type = XkbControlsNotify; cev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -344,9 +342,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbIndicatorMapNotifyMask) { xkbIndicatorNotify *in = (xkbIndicatorNotify *) event; - XkbIndicatorNotifyEvent *iev; + XkbIndicatorNotifyEvent *iev = (XkbIndicatorNotifyEvent *) re; - iev = (XkbIndicatorNotifyEvent *) re; iev->type = XkbEventCode + xkbi->codes->first_event; iev->xkb_type = XkbIndicatorMapNotify; iev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -364,9 +361,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbIndicatorStateNotifyMask) { xkbIndicatorNotify *in = (xkbIndicatorNotify *) event; - XkbIndicatorNotifyEvent *iev; + XkbIndicatorNotifyEvent *iev = (XkbIndicatorNotifyEvent *) re; - iev = (XkbIndicatorNotifyEvent *) re; iev->type = XkbEventCode + xkbi->codes->first_event; iev->xkb_type = XkbIndicatorStateNotify; iev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -384,9 +380,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbBellNotifyMask) { xkbBellNotify *bn = (xkbBellNotify *) event; - XkbBellNotifyEvent *bev; + XkbBellNotifyEvent *bev = (XkbBellNotifyEvent *) re; - bev = (XkbBellNotifyEvent *) re; bev->type = XkbEventCode + xkbi->codes->first_event; bev->xkb_type = XkbBellNotify; bev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -410,9 +405,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbAccessXNotifyMask) { xkbAccessXNotify *axn = (xkbAccessXNotify *) event; - XkbAccessXNotifyEvent *axev; + XkbAccessXNotifyEvent *axev = (XkbAccessXNotifyEvent *) re; - axev = (XkbAccessXNotifyEvent *) re; axev->type = XkbEventCode + xkbi->codes->first_event; axev->xkb_type = XkbAccessXNotify; axev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -432,9 +426,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbNamesNotifyMask) { xkbNamesNotify *nn = (xkbNamesNotify *) event; - XkbNamesNotifyEvent *nev; + XkbNamesNotifyEvent *nev = (XkbNamesNotifyEvent *) re; - nev = (XkbNamesNotifyEvent *) re; nev->type = XkbEventCode + xkbi->codes->first_event; nev->xkb_type = XkbNamesNotify; nev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -462,9 +455,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbCompatMapNotifyMask) { xkbCompatMapNotify *cmn = (xkbCompatMapNotify *) event; - XkbCompatMapNotifyEvent *cmev; + XkbCompatMapNotifyEvent *cmev = (XkbCompatMapNotifyEvent *) re; - cmev = (XkbCompatMapNotifyEvent *) re; cmev->type = XkbEventCode + xkbi->codes->first_event; cmev->xkb_type = XkbCompatMapNotify; cmev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -484,9 +476,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbActionMessageMask) { xkbActionMessage *am = (xkbActionMessage *) event; - XkbActionMessageEvent *amev; + XkbActionMessageEvent *amev = (XkbActionMessageEvent *) re; - amev = (XkbActionMessageEvent *) re; amev->type = XkbEventCode + xkbi->codes->first_event; amev->xkb_type = XkbActionMessage; amev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -509,9 +500,9 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) { if (xkbi->selected_events & XkbExtensionDeviceNotifyMask) { xkbExtensionDeviceNotify *ed = (xkbExtensionDeviceNotify *) event; - XkbExtensionDeviceNotifyEvent *edev; + XkbExtensionDeviceNotifyEvent *edev + = (XkbExtensionDeviceNotifyEvent *) re; - edev = (XkbExtensionDeviceNotifyEvent *) re; edev->type = XkbEventCode + xkbi->codes->first_event; edev->xkb_type = XkbExtensionDeviceNotify; edev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -538,9 +529,8 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) if ((xkbi->selected_events & XkbNewKeyboardNotifyMask) && (xkbi->selected_nkn_details & nkn->changed)) { - XkbNewKeyboardNotifyEvent *nkev; + XkbNewKeyboardNotifyEvent *nkev = (XkbNewKeyboardNotifyEvent *) re; - nkev = (XkbNewKeyboardNotifyEvent *) re; nkev->type = XkbEventCode + xkbi->codes->first_event; nkev->xkb_type = XkbNewKeyboardNotify; nkev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); @@ -763,9 +753,8 @@ XkbUseExtension(Display *dpy, int *major_rtrn, int *minor_rtrn) req->wantedMajor = XkbMajorVersion; req->wantedMinor = XkbMinorVersion; if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.supported) { - Bool fail; + Bool fail = True; - fail = True; if (debugMsg) fprintf(stderr, "XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n", -- cgit v1.2.3 From ba86b7a2eb0370ef1275382122274f514d361778 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 16 Aug 2013 21:04:02 -0700 Subject: Stop checking for HAVE_DIX_CONFIG_H on the client side Leftover from when these XKB files were shared with the server sources and could be compiled in either the client or server, with the different autoconf config files in each. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBAlloc.c | 4 +--- nx-X11/lib/X11/XKBGAlloc.c | 4 +--- nx-X11/lib/X11/XKBMAlloc.c | 4 +--- nx-X11/lib/X11/XKBMisc.c | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBAlloc.c b/nx-X11/lib/X11/XKBAlloc.c index ed00f7ff2..a089ff46d 100644 --- a/nx-X11/lib/X11/XKBAlloc.c +++ b/nx-X11/lib/X11/XKBAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include #endif diff --git a/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index f52a0e70e..28d1fae43 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include #endif diff --git a/nx-X11/lib/X11/XKBMAlloc.c b/nx-X11/lib/X11/XKBMAlloc.c index c7c138e4d..d1f232619 100644 --- a/nx-X11/lib/X11/XKBMAlloc.c +++ b/nx-X11/lib/X11/XKBMAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include #endif diff --git a/nx-X11/lib/X11/XKBMisc.c b/nx-X11/lib/X11/XKBMisc.c index 4267b214f..ab48b6124 100644 --- a/nx-X11/lib/X11/XKBMisc.c +++ b/nx-X11/lib/X11/XKBMisc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include #endif -- cgit v1.2.3 From f04e1a6d1f3cecc041a2495430a960a931bd1d5b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 24 Aug 2013 17:27:43 -0700 Subject: Bug 68413 - [Bisected]Error in `xterm': realloc(): invalid next size Pass *new* size to realloc, not old size. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcPrs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcPrs.c b/nx-X11/lib/X11/imLcPrs.c index 7745c53d2..afc947468 100644 --- a/nx-X11/lib/X11/imLcPrs.c +++ b/nx-X11/lib/X11/imLcPrs.c @@ -644,7 +644,7 @@ parseline( } while (b->utf8used + l + 1 > b->utf8size) { DTCharIndex newsize = b->utf8size ? b->utf8size * 1.5 : 1024; - char *newutf8 = Xrealloc (b->utf8, b->utf8size); + char *newutf8 = Xrealloc (b->utf8, newsize); if (newutf8 == NULL) goto error; b->utf8 = newutf8; -- cgit v1.2.3 From 35dc4784bcee7a42a83cc1dbab13fb82cfcc5803 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 16 Nov 2013 20:21:54 -0800 Subject: Drop X_LOCALE fallback for OS'es without setlocale() C89 or bust! This was documented as being needed for "only Lynx, Linux-libc5, OS/2" and has never been enabled in modular builds, since none of those platforms have had anyone step up to add support since the X11R7 conversion to autotools. Mostly performed with unifdef -UX_LOCALE, followed by removal of files left without any purpose, and manual cleanup of remaining references. Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Imakefile | 6 - nx-X11/lib/X11/SetLocale.c | 51 - nx-X11/lib/X11/XlcPubI.h | 7 - nx-X11/lib/X11/Xlcint.h | 15 - nx-X11/lib/X11/Xlocale.h | 22 - nx-X11/lib/X11/imCallbk.c | 4 - nx-X11/lib/X11/lcEuc.c | 1537 ------------------------ nx-X11/lib/X11/lcInit.c | 29 - nx-X11/lib/X11/lcJis.c | 944 --------------- nx-X11/lib/X11/lcSjis.c | 1612 -------------------------- nx-X11/lib/X11/xlibi18n/lc/Imakefile | 2 +- nx-X11/lib/X11/xlibi18n/lc/xlocale/Imakefile | 14 - 12 files changed, 1 insertion(+), 4242 deletions(-) delete mode 100644 nx-X11/lib/X11/lcEuc.c delete mode 100644 nx-X11/lib/X11/lcJis.c delete mode 100644 nx-X11/lib/X11/lcSjis.c delete mode 100644 nx-X11/lib/X11/xlibi18n/lc/xlocale/Imakefile (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Imakefile b/nx-X11/lib/X11/Imakefile index 28dcdc1db..8549f69cd 100644 --- a/nx-X11/lib/X11/Imakefile +++ b/nx-X11/lib/X11/Imakefile @@ -924,10 +924,7 @@ STATICI18NSTATICSRCS = \ imTrX.c \ imTransR.c \ imTrans.c \ - lcEuc.c \ lcGenConv.c \ - lcJis.c \ - lcSjis.c \ lcUTF8Load.c \ omDefault.c \ omGeneric.c \ @@ -998,10 +995,7 @@ STATICI18NSTATICOBJS = \ imTrX.o \ imTransR.o \ imTrans.o \ - lcEuc.o \ lcGenConv.o \ - lcJis.o \ - lcSjis.o \ lcUTF8Load.o \ omDefault.o \ omGeneric.o \ diff --git a/nx-X11/lib/X11/SetLocale.c b/nx-X11/lib/X11/SetLocale.c index 9ada0fb90..f4d2aca21 100644 --- a/nx-X11/lib/X11/SetLocale.c +++ b/nx-X11/lib/X11/SetLocale.c @@ -66,56 +66,6 @@ from The Open Group. #define MAXLOCALE 64 /* buffer size of locale name */ -#ifdef X_LOCALE - -/* alternative setlocale() for when the OS does not provide one */ - -char * -_Xsetlocale( - int category, - _Xconst char *name -) -{ - static char *xsl_name; - char *old_name; - XrmMethods methods; - XPointer state; - - if (category != LC_CTYPE && category != LC_ALL) - return NULL; - if (!name) { - if (xsl_name) - return xsl_name; - return "C"; - } - if (!*name) - name = getenv("LC_CTYPE"); - if (!name || !*name) - name = getenv("LANG"); - if (name && strlen(name) >= MAXLOCALE) - name = NULL; - if (!name || !*name || !_XOpenLC((char *) name)) - name = "C"; - old_name = xsl_name; - xsl_name = (char *)name; - methods = _XrmInitParseInfo(&state); - xsl_name = old_name; - if (!methods) - return NULL; - name = (*methods->lcname)(state); - xsl_name = strdup(name); - if (!xsl_name) { - xsl_name = old_name; - (*methods->destroy)(state); - return NULL; - } - if (old_name) - Xfree(old_name); - (*methods->destroy)(state); - return xsl_name; -} - -#else /* X_LOCALE */ #if defined(__DARWIN__) || defined(__APPLE__) || defined(__CYGWIN__) char * @@ -250,4 +200,3 @@ _XlcMapOSLocaleName( return osname; } -#endif /* X_LOCALE */ diff --git a/nx-X11/lib/X11/XlcPubI.h b/nx-X11/lib/X11/XlcPubI.h index 44d0d086c..c454c7ddd 100644 --- a/nx-X11/lib/X11/XlcPubI.h +++ b/nx-X11/lib/X11/XlcPubI.h @@ -232,12 +232,6 @@ extern void _XlcGetLocaleDataBase( int* /* count */ ); -#ifdef X_LOCALE -extern char * -_Xsetlocale( - int category, - _Xconst char *name); -#else #if defined(__APPLE__) || defined(__DARWIN__) extern char * _Xsetlocale( @@ -247,7 +241,6 @@ _Xsetlocale( extern char *_XlcMapOSLocaleName( char *osname, char *siname); -#endif extern int _Xmbstoutf8( diff --git a/nx-X11/lib/X11/Xlcint.h b/nx-X11/lib/X11/Xlcint.h index 7b10d8fd7..5a6205a1f 100644 --- a/nx-X11/lib/X11/Xlcint.h +++ b/nx-X11/lib/X11/Xlcint.h @@ -932,21 +932,6 @@ extern XLCd _XlcUtf8Loader( const char* name ); -/* The old EUC locale loader. */ -extern XLCd _XlcEucLoader( - const char* name -); - -/* The old SJIS locale loader. */ -extern XLCd _XlcSjisLoader( - const char* name -); - -/* The old ISO-2022-JP locale loader. */ -extern XLCd _XlcJisLoader( - const char* name -); - extern XLCd _XlcDynamicLoad( const char* name ); diff --git a/nx-X11/lib/X11/Xlocale.h b/nx-X11/lib/X11/Xlocale.h index da5746d28..4ac9bac30 100644 --- a/nx-X11/lib/X11/Xlocale.h +++ b/nx-X11/lib/X11/Xlocale.h @@ -33,28 +33,6 @@ from The Open Group. #include #include -#ifndef X_LOCALE #include -#else - -#define LC_ALL 0 -#define LC_COLLATE 1 -#define LC_CTYPE 2 -#define LC_MONETARY 3 -#define LC_NUMERIC 4 -#define LC_TIME 5 - -_XFUNCPROTOBEGIN -extern char *_Xsetlocale( - int /* category */, - _Xconst char* /* name */ -); -_XFUNCPROTOEND - -#define setlocale _Xsetlocale - -#include - -#endif /* X_LOCALE */ #endif /* !defined(_X11_XLOCALE_H_) && !defined(_XLOCALE_H_) */ diff --git a/nx-X11/lib/X11/imCallbk.c b/nx-X11/lib/X11/imCallbk.c index edffac173..07921f8a1 100644 --- a/nx-X11/lib/X11/imCallbk.c +++ b/nx-X11/lib/X11/imCallbk.c @@ -39,10 +39,6 @@ PERFORMANCE OF THIS SOFTWARE. #include "Xlcint.h" #include "Ximint.h" #include "XlcPubI.h" -#ifdef X_LOCALE -#define mblen(a,b) _Xmblen(a,b) -extern int _Xmblen (); -#endif #define sz_CARD8 1 #define sz_INT8 1 diff --git a/nx-X11/lib/X11/lcEuc.c b/nx-X11/lib/X11/lcEuc.c deleted file mode 100644 index 5b171a9f3..000000000 --- a/nx-X11/lib/X11/lcEuc.c +++ /dev/null @@ -1,1537 +0,0 @@ -/****************************************************************** - - Copyright 1992, 1993 by FUJITSU LIMITED - Copyright 1993 by Fujitsu Open Systems Solutions, Inc. - -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, and that the name of FUJITSU LIMITED and -Fujitsu Open Systems Solutions, Inc. not be used in advertising or -publicity pertaining to distribution of the software without specific, -written prior permission. -FUJITSU LIMITED and Fujitsu Open Systems Solutions, Inc. makes no -representations about the suitability of this software for any purpose. -It is provided "as is" without express or implied warranty. - -FUJITSU LIMITED AND FUJITSU OPEN SYSTEMS SOLUTIONS, INC. DISCLAIMS ALL -WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU OPEN SYSTEMS -SOLUTIONS, INC. AND FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT -OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. - - Authors: Shigeru Yamada (yamada@ossi.com) - Jeffrey Bloomfield (jeffb@ossi.com) - Yoshiyuki Segawa (segawa@ossi.com) - -*****************************************************************/ - -/* - * An EUC locale. - * Supports: all locales with codeset eucJP, eucKR, eucCN, eucTW. - * How: Provides converters for euc*. - * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2). - */ - -#ifdef X_LOCALE - -#ifdef HAVE_CONFIG_H -#include -#endif -#include "Xlibint.h" -#include "XlcGeneric.h" - -#include -#ifdef WIN32 -#define isascii __isascii -#endif - -#define CS0 codesets[0] /* Codeset 0 - 7-bit ASCII */ -#define CS1 codesets[1] /* Codeset 1 - Kanji */ -#define CS2 codesets[2] /* Codeset 2 - Half-Kana */ -#define CS3 codesets[3] /* Codeset 3 - User defined */ - -#define SS2 0x8e /* Single-shift char: CS2 */ -#define SS3 0x8f /* Single-shift char: CS3 */ - -#define ASCII_CODESET 0 -#define KANJI_CODESET 1 -#define KANA_CODESET 2 -#define USERDEF_CODESET 3 -#define MAX_CODESETS - -#define GR 0x80 /* begins right-side (non-ascii) region */ -#define GL 0x7f /* ends left-side (ascii) region */ - -#define isleftside(c) (((c) & GR) ? 0 : 1) -#define isrightside(c) (!isleftside(c)) - -#define BIT8OFF(c) ((c) & GL) -#define BIT8ON(c) ((c) | GR) - -typedef unsigned char Uchar; -typedef unsigned long Ulong; -typedef unsigned int Uint; - -static CodeSet GetCodeSetFromCharSet (XLCd lcd, XlcCharSet charset); -static CodeSet wc_codeset (XLCd lcd, wchar_t wch); - -#define BADCHAR(min_ch, c) (BIT8OFF(c) < (char)min_ch && BIT8OFF(c) != 0x0 && \ - BIT8OFF(c) != '\t' && BIT8OFF(c) != '\n' && \ - BIT8OFF(c) != 0x1b) - -/* - * Notes: - * 1. Defining FORCE_INDIRECT_CONVERTER (see _XlcEucLoader()) - * forces indirect (charset) conversions (e.g. wcstocs()<->cstombs()). - * 2. Using direct converters (e.g. mbstowcs()) decreases conversion - * times by 20-40% (depends on specific converter used). - */ - -static int -euc_mbstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - - Uchar ch; - int chr_len = 0; - int sshift = False; - int shift_mult = 0; - Uint chrcode; - - Uint wc_encode = 0; - Uint wc_tmp = 0; - - int cs0flg = False; - int cs1flg = False; - int length = 0; - int unconv_num = 0; - - Bool new_char; - - const char *inbufptr = *from; - wchar_t *outbufptr = (wchar_t *) *to; - - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - int codeset_num = XLC_GENERIC(lcd, codeset_num); - Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - for (new_char = True; *from_left > 0 && *to_left > 0;) { - - ch = *inbufptr++; - - if (isleftside(ch)) { /* CS0 */ - if (ASCII_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - if( cs0flg == True) { - new_char = True; - cs0flg = False; - } - length = CS0->length; - *outbufptr++ = (wchar_t)ch; - (*from_left)--; - (*to_left)--; - continue; - } - else if (ch == SS2) { /* CS2 */ - if (KANA_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - if (sshift == True || cs1flg == True) { - cs1flg = False; - unconv_num++; - continue; - } - length = CS2->length; - wc_encode = CS2->wc_encoding; - chrcode = 0; - sshift = True; - cs0flg = True; - (*from_left)--; - continue; - } - else if (ch == SS3) { /* CS3 */ - if (USERDEF_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - if (sshift == True || cs1flg == True) { - cs1flg = False; - unconv_num++; - continue; - } - length = CS3->length; - if (*from_left < 1 ) - unconv_num++; - wc_encode = CS3->wc_encoding; - chrcode = 0; - sshift = True; - cs0flg = True; - (*from_left)--; - continue; - - } else { /* CS1 */ - if (KANJI_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - if (sshift == False) { - length = CS1->length; - if (*from_left < 1) - unconv_num++; - wc_encode = CS1->wc_encoding; - } - chrcode = BIT8OFF(ch); - cs0flg = True; - cs1flg = True; - (*from_left)--; - } - - if (new_char) { /* begin new character */ - chr_len = length; - shift_mult = length - 1; - new_char = False; - } - - chrcode <<= (wc_shift * shift_mult); - shift_mult--; - wc_tmp |= chrcode; - - if (--chr_len == 0) { - wc_tmp |= wc_encode; - *outbufptr++ = wc_tmp; - (*to_left)--; - - new_char = True; - sshift = False; - cs0flg = False; - cs1flg = False; - wc_tmp = (Uint)0; - } - - } /* end for */ - - *to = (XPointer)outbufptr; - - if (cs0flg == True || cs1flg == True) /* error check on last char */ - unconv_num++; - - return unconv_num; -} - - -static int -euc_wcstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const wchar_t *inbufptr = (const wchar_t *) *from; - XPointer outbufptr = *to; - wchar_t wch; - int length; - Uchar tmp; - int unconv_num = 0; - - XLCd lcd = (XLCd)conv->state; - CodeSet codeset; - Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - for (; *from_left > 0 && *to_left > 0; (*from_left)-- ) { - - wch = *inbufptr++; - - if (!(codeset = wc_codeset(lcd, wch))) { - unconv_num++; - (*from_left)--; - continue; - } - - length = codeset->length; - wch ^= (wchar_t)codeset->wc_encoding; - - if (codeset->parse_info) { /* put out SS2 or SS3 */ - if (*to_left < length + 1) { - unconv_num++; - break; - } - *outbufptr++ = *codeset->parse_info->encoding; - (*to_left)--; - } else { - if (*to_left < length) { - unconv_num++; - break; - } - } - - do { - length--; - tmp = (wch>>(wchar_t)(length * wc_shift)); - - if (codeset->side == XlcGR) - tmp = BIT8ON(tmp); - - *outbufptr++ = (Uchar)tmp; - (*to_left)--; - } while (length); - } - - *to = (XPointer)outbufptr; - - return unconv_num; -} - - -static int -euc_mbtocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - XlcCharSet charset; - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - int codeset_num = XLC_GENERIC(lcd, codeset_num); - int length; - int unconv_num = 0; - int min_ch = 0; - const char *src = *from; - char *dst = *to; - - if (isleftside(*src)) { /* 7-bit (CS0) */ - if (ASCII_CODESET >= codeset_num) - return -1; - charset = *CS0->charset_list; - } - else if ((Uchar)*src == SS2) { /* half-kana (CS2) */ - if (KANA_CODESET >= codeset_num) - return -1; - charset = *CS2->charset_list; - src++; - (*from_left)--; - } - else if ((Uchar)*src == SS3) { /* user-def */ - if (USERDEF_CODESET >= codeset_num) - return -1; - charset = *CS3->charset_list; - src++; - (*from_left)--; - } - else { /* Kanji (CS1) */ - if (KANJI_CODESET >= codeset_num) - return -1; - charset = *CS1->charset_list; - } - - if(*from_left < charset->char_size || *to_left < charset->char_size) - return -1; - - min_ch = 0x20; - if (charset->set_size == 94) - if (charset->char_size > 1 || charset->side == XlcGR) - min_ch = 0x21; - - length = charset->char_size; - do { - if(BADCHAR(min_ch, *src)) { - unconv_num++; - src++; - break; - } - switch (charset->side) { - case XlcGL: - *dst++ = BIT8OFF(*src++); - break; - case XlcGR: - *dst++ = BIT8ON(*src++); - break; - default: - *dst++ = *src++; - break; - } - } while (--length); - - *to = dst; - *from = (XPointer) src; - *from_left -= charset->char_size; - *to_left -= charset->char_size - length; - - if (num_args > 0) - *((XlcCharSet *) args[0]) = charset; - - return unconv_num; -} - - -static int -euc_mbstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const char *tmp_from; - char *tmp_to; - int tmp_from_left, tmp_to_left; - XlcCharSet charset, tmp_charset; - XPointer tmp_args[1]; - int unconv_num = 0, ret; - -/* Determine the charset of the segment and convert one characater: */ - - tmp_args[0] = (XPointer) &charset; /* charset from euc_mbtocs() */ - while - ((ret = euc_mbtocs(conv, from, from_left, to, to_left, tmp_args, 1)) > 0) - unconv_num += ret; - if ( ret < 0 ) - return ret; - - tmp_from = *from; - tmp_from_left = *from_left; - tmp_to_left = *to_left; - tmp_to = *to; - -/* Convert remainder of the segment: */ - - tmp_args[0] = (XPointer) &tmp_charset; - while( (ret = euc_mbtocs(conv, (XPointer *) &tmp_from, &tmp_from_left, - (XPointer *) &tmp_to, &tmp_to_left, tmp_args, 1)) >= 0 ) { - - if (ret > 0) { - unconv_num += ret; - continue; - } - - if (tmp_charset != charset) /* quit on end of segment */ - break; - - *from = (XPointer) tmp_from; - *from_left = tmp_from_left; - *to = (XPointer) tmp_to; - *to_left = tmp_to_left; - } - - if (num_args > 0) - *((XlcCharSet *) args[0]) = charset; - - return unconv_num; -} - - -static int -euc_wcstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - const wchar_t *wcptr = (const wchar_t *) *from; - char *bufptr = (char *) *to; - wchar_t wch; - char *tmpptr; - int length; - CodeSet codeset; - Ulong wc_encoding; - int wcstr_len = *from_left, buf_len = *to_left; - - if (!(codeset = wc_codeset(lcd, *wcptr))) - return -1; - - wc_encoding = codeset->wc_encoding; - - if (wcstr_len < buf_len / codeset->length) - buf_len = wcstr_len * codeset->length; - - for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) { - wch = *wcptr; - - if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding) - break; - - length = codeset->length; - - buf_len -= length; - bufptr += length; - tmpptr = bufptr - 1; - - while (length--) { - *tmpptr-- = codeset->length == 1 && codeset->side == XlcGR ? - BIT8ON(wch) : BIT8OFF(wch); - wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); - } - } - - if (num_args > 0) - *((XlcCharSet *) args[0]) = *codeset->charset_list; - - *from_left -= wcptr - (wchar_t *) *from; - *from = (XPointer) wcptr; - - *to_left -= bufptr - *to; - *to = bufptr; - - return 0; -} - - -static int -euc_cstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - const char *csptr = *from; - char *bufptr = *to; - int csstr_len = *from_left; - int buf_len = *to_left; - int length; - CodeSet codeset; - int cvt_length; - - if (num_args < 1) - return -1; - - if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) - return -1; - - cvt_length = 0; - csstr_len /= codeset->length; - buf_len /= codeset->length; - - if (codeset->parse_info) - csstr_len *= 2; - - if (csstr_len < buf_len) - buf_len = csstr_len; - - cvt_length += buf_len * codeset->length; - - if (bufptr) { - while (buf_len--) { - if (codeset->parse_info) /* put out SS2 or SS3 */ - *bufptr++ = *codeset->parse_info->encoding; - - length = codeset->length; - while (length--) - *bufptr++ = codeset->side == XlcGR ? - BIT8ON(*csptr++) : BIT8OFF(*csptr++); - } - } - - *from_left -= csptr - *from; - *from = (XPointer) csptr; - if (bufptr) - *to += cvt_length; - *to_left -= cvt_length; - - return 0; -} - - -static int -euc_cstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - const char *csptr = *from; - wchar_t *bufptr = (wchar_t *) *to; - wchar_t *toptr = (wchar_t *) *to; - int csstr_len = *from_left; - int buf_len = *to_left; - wchar_t wch; - int length; - Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); - CodeSet codeset; - - if (num_args < 1) - return -1; - - if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) - return -1; - - csstr_len /= codeset->length; - if (csstr_len < buf_len) - buf_len = csstr_len; - *to_left -= buf_len; - - if (bufptr) { - - toptr += buf_len; - *to = (XPointer) toptr; - - while (buf_len--) { - - wch = (wchar_t) BIT8OFF(*csptr); - csptr++; - - length = codeset->length - 1; - while (length--) { - wch = (wch << wc_shift_bits) | BIT8OFF(*csptr); - csptr++; - } - *bufptr++ = wch | codeset->wc_encoding; - } - } - *from_left -= csptr - *from; - *from = (XPointer) csptr; - - return 0; -} - - -static CodeSet -wc_codeset( - XLCd lcd, - wchar_t wch) -{ - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - int end = XLC_GENERIC(lcd, codeset_num); - Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); - - for (; --end >= 0; codesets++) - if ( widech == (*codesets)->wc_encoding ) - return *codesets; - - return NULL; -} - - -static CodeSet -GetCodeSetFromCharSet( - XLCd lcd, - XlcCharSet charset) -{ - CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); - XlcCharSet *charset_list; - int codeset_num, num_charsets; - - codeset_num = XLC_GENERIC(lcd, codeset_num); - - for ( ; codeset_num-- > 0; codeset++) { - num_charsets = (*codeset)->num_charsets; - charset_list = (*codeset)->charset_list; - - for ( ; num_charsets-- > 0; charset_list++) - if (*charset_list == charset) - return *codeset; - } - - return (CodeSet) NULL; -} - - -static XlcConv -create_conv( - XLCd lcd, - XlcConvMethods methods) -{ - XlcConv conv; - - conv = Xmalloc(sizeof(XlcConvRec)); - if (conv == NULL) - return (XlcConv) NULL; - - conv->methods = methods; - conv->state = (XPointer) lcd; - return conv; -} - - -/* - * Stripped down Direct CT converters for EUC - * - */ - -typedef struct _CTDataRec { - int side; - int length; - char *name; - Ulong wc_encoding; - char sshift; - char *ct_encoding; - int ct_encoding_len; - int set_size; - Uchar min_ch; - Uchar ct_type; -} CTDataRec, *CTData; - -typedef struct _StateRec { - CTData GL_charset; - CTData GR_charset; - CTData charset; -} StateRec, *State; - -#define CT_STD 0 -#define CT_NSTD 1 -#define CT_DIR 2 -#define CT_EXT0 3 -#define CT_EXT1 4 -#define CT_EXT2 5 -#define CT_VER 6 - -static CTDataRec ctdata[] = -{ - { XlcGL, 1, "ISO8859-1:GL", 0, 0, "\033(B" , 3, 0, 0, CT_STD }, - { XlcGR, 1, "ISO8859-1:GR", 0, 0, "\033-A" , 3, 0, 0, CT_STD }, - { XlcGL, 1, "JISX0201.1976-0:GL", 0, 0, "\033(J" , 3, 0, 0, CT_STD }, - { XlcGR, 1, "JISX0201.1976-0:GR", 0, 0, "\033)I" , 3, 0, 0, CT_STD }, - { XlcGL, 2, "JISX0208.1983-0:GL", 0, 0, "\033$(B" , 4, 0, 0, CT_STD }, - { XlcGR, 2, "JISX0208.1983-0:GR", 0, 0, "\033$)B" , 4, 0, 0, CT_STD }, - { XlcGL, 2, "JISX0212.1990-0:GL", 0, 0, "\033$(D" , 4, 0, 0, CT_STD }, - { XlcGR, 2, "JISX0212.1990-0:GR", 0, 0, "\033$)D" , 4, 0, 0, CT_STD }, - { XlcUnknown, 0, "Ignore-Ext-Status?", 0, 0, "\033#" , 2, 0, 0, CT_VER }, - { XlcUnknown, 0, "NonStd-?-OctetChar", 0, 0, "\033%/0" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 1, "NonStd-1-OctetChar", 0, 0, "\033%/1" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 2, "NonStd-2-OctetChar", 0, 0, "\033%/2" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 3, "NonStd-3-OctetChar", 0, 0, "\033%/3" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 4, "NonStd-4-OctetChar", 0, 0, "\033%/4" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 0, "Extension-2" , 0, 0, "\033%/" , 3, 0, 0, CT_EXT2 }, - { XlcUnknown, 0, "Extension-0" , 0, 0, "\033" , 1, 0, 0, CT_EXT0 }, - { XlcUnknown, 0, "Begin-L-to-R-Text", 0, 0, "\2331]" , 3, 0, 0, CT_DIR }, - { XlcUnknown, 0, "Begin-R-to-L-Text", 0, 0, "\2332]" , 3, 0, 0, CT_DIR }, - { XlcUnknown, 0, "End-Of-String", 0, 0, "\233]" , 2, 0, 0, CT_DIR }, - { XlcUnknown, 0, "Extension-1" , 0, 0, "\233" , 1, 0, 0, CT_EXT1 }, -}; - -/* Note on above table: euc_ctstombs() and euc_ctstowcs() parser depends on - * certain table entries occuring in decreasing string length-- - * 1. CT_EXT2 and CT_EXT0 entries must occur after CT_NSTD entries. - * 2. CT_DIR and CT_EXT1 entries must occur after CT_DIR entries. - */ - -static CTData ctd_endp = ctdata + ((sizeof(ctdata) / sizeof(CTDataRec))) - 1; -static CTData ctdptr[sizeof(ctdata) / sizeof(CTDataRec)]; - -#define Ascii 0 -#define Kanji 1 -#define Kana 2 -#define Userdef 3 - -/* - * initCTptr(): Set ctdptr[] to point at ctdata[], indexed by codeset_num. - */ -static void -initCTptr( - XLCd lcd) -{ - int num_codesets = XLC_GENERIC(lcd, codeset_num); - int num_charsets; - int i, j; - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - CodeSet codeset; - XlcCharSet charset; - CTData ctdp = ctdata; - - ctdptr[Ascii] = &ctdata[0]; /* failsafe */ - - for (i = 0; i < num_codesets; i++) { - - codeset = codesets[i]; - num_charsets = codeset->num_charsets; - - for (j = 0; j < num_charsets; j++) { - - charset = codeset->charset_list[j]; - - for (ctdp = ctdata; ctdp <= ctd_endp; ctdp++) - - if (! strcmp(ctdp->name, charset->name)) { - - ctdptr[codeset->cs_num] = ctdp; - - ctdptr[codeset->cs_num]->wc_encoding = codeset->wc_encoding; - - ctdptr[codeset->cs_num]->set_size = - charset->set_size; - - ctdptr[codeset->cs_num]->min_ch = - charset->set_size == 94 && - (ctdptr[codeset->cs_num]->length > 1 || - ctdptr[codeset->cs_num]->side == XlcGR) ? 0x21 : 0x20; - - if (codeset->parse_info) { - ctdptr[codeset->cs_num]->sshift = - *codeset->parse_info->encoding; - } - - break; - } - } - } -} - - -#define SKIP_I(str) while (*(str) >= 0x20 && *(str) <= 0x2f) (str)++; -#define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; - -static int -euc_ctstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); - const char *inbufptr = *from; - const char *inbuf_base; - wchar_t *outbufptr = (wchar_t *) *to; - wchar_t *outbuf_base = outbufptr; - int clen, length; - int unconv_num = 0; - unsigned int ct_seglen = 0; - Uchar ct_type = 0; - int shift_mult; - wchar_t wc_tmp; - wchar_t wch; - Ulong wc_encoding; - CTData ctdp = ctdata; - CTData GL_ctdp = ctdp; /* GL ctdp save */ - CTData GR_ctdp = ctdp; /* GR ctdp save */ - Bool save_outbuf = True; - /* If outbufptr is NULL, doen't save output, but just counts - a length to hold the output */ - if (outbufptr == NULL) save_outbuf = False; - - for (length = ctdata[Ascii].length; *from_left > 0; (*from_left) -= length) - { - ct_type = CT_STD; - /* change GL/GR charset */ - if(ctdp->side == XlcGR && isleftside(*inbufptr)){ - /* select GL side */ - ctdp = GL_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - }else if(ctdp->side == XlcGL && isrightside(*inbufptr)){ - /* select GR side */ - ctdp = GR_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - } - if (*inbufptr == '\033' || *inbufptr == (char)'\233') { - for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { - - if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) - { - inbufptr += ctdp->ct_encoding_len; - (*from_left) -= ctdp->ct_encoding_len; - if (ctdp->length) { - length = ctdp->length; - if( *from_left < length ) { - *to = (XPointer)outbufptr; - *to_left -= outbufptr - outbuf_base; - return( unconv_num + *from_left ); - } - } - ct_type = ctdp->ct_type; - if(ctdp->side == XlcGL){ - GL_ctdp = ctdp; /* save GL ctdp */ - }else{ - GR_ctdp = ctdp; /* save GR ctdp */ - } - break; - } - } - if (ctdp > ctd_endp) /* failed to match CT sequence */ - unconv_num++; - } - -/* The following code insures that non-standard encodings, direction, extension, - * and version strings are ignored; subject to change in future. - */ - switch (ct_type) { - case CT_STD: - break; - case CT_EXT2: - inbufptr++; - (*from_left)--; - case CT_NSTD: - ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; - inbufptr += ct_seglen; - (*from_left) -= ct_seglen; - continue; - case CT_EXT0: - inbuf_base = inbufptr; - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - *(from_left) -= ct_seglen; - continue; - case CT_EXT1: - inbuf_base = inbufptr; - SKIP_P(inbufptr); - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - *(from_left) -= ct_seglen; - continue; - case CT_DIR: - continue; - case CT_VER: - inbufptr += 2; - *(from_left) -= 2; - continue; - } - - wc_encoding = (ctdp == ctdptr[Kana] && isleftside(*inbufptr)) ? - ctdptr[Ascii]->wc_encoding: ctdp->wc_encoding; - - shift_mult = length - 1; - wch = (wchar_t)0; - clen = length; - - do { - wc_tmp = BIT8OFF(*inbufptr++) << (wc_shift_bits * shift_mult); - wch |= wc_tmp; - shift_mult--; - } while (--clen); - - if (save_outbuf == True) - *outbufptr++ = wch | wc_encoding; - if (--*to_left == 0 && *from_left != length) { - *to = (XPointer)outbufptr; - unconv_num = *from_left; - return unconv_num; - } - } - - *to = (XPointer)outbufptr; - - return unconv_num; - -} - - -#define byte1 (length == codeset->length - 1) -#define byte2 (byte1 == 0) -#define kanji (codeset->cs_num == 1) -#define kana (codeset->cs_num == 2) -#define userdef (codeset->cs_num == 3) - -static int -euc_wcstocts( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - int ct_len = *to_left; - const wchar_t *inbufptr = (const wchar_t *) *from; - char *ctptr = *to; - XPointer ct_base = ctptr; - wchar_t wch; - int length; - int unconv_num = 0; - Uchar tmp; - Uchar t1 = 0; - int num_conv; - - StateRec ct_state; - XLCd lcd = (XLCd)conv->state; - CTData charset; - CodeSet codeset; - Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - -/* Initial State: */ - ct_state.GL_charset = ctdptr[0]; /* Codeset 0 */ - ct_state.GR_charset = NULL; - - if (*from_left > *to_left) - *from_left = *to_left; - - for (; *from_left > 0 ; (*from_left)-- ) { - - wch = *inbufptr++; - - if (!(codeset = wc_codeset(lcd, wch))) { - unconv_num++; - (*from_left)--; - continue; - } - - charset = ctdptr[codeset->cs_num]; - - length = codeset->length; - wch ^= (wchar_t)codeset->wc_encoding; - - if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || - (charset->side == XlcGL && charset != ct_state.GL_charset) ) { - - ct_len -= ctdptr[codeset->cs_num]->ct_encoding_len; - - if (ct_len < 0) { - unconv_num++; - break; - } - - if (ctptr) { - strcpy(ctptr, ctdptr[codeset->cs_num]->ct_encoding); - ctptr += ctdptr[codeset->cs_num]->ct_encoding_len; - } - } - - if (charset->side == XlcGR) { - ct_state.GR_charset = charset; - ct_state.GL_charset = NULL; - } else if (charset->side == XlcGL) { - ct_state.GL_charset = charset; - ct_state.GR_charset = NULL; - } - - do { - - length--; - tmp = wch>>(wchar_t)( (Ulong)length * wc_shift); - - if (kana) { - if (BADCHAR(charset->min_ch, (char)tmp)) { - unconv_num++; - break; - } - *ctptr++ = (char)BIT8ON(tmp); - } - - else if (byte1 && (kanji || userdef)) - t1 = tmp; - - else if (byte2 && (kanji || userdef)) { - if (BADCHAR(charset->min_ch, (char)t1) || - BADCHAR(charset->min_ch, (char)tmp)) { - unconv_num++; - break; - } - if (charset->side == XlcGR) { - *ctptr++ = (char)BIT8ON(t1); - *ctptr++ = (char)BIT8ON(tmp); - } else { - *ctptr++ = (char)BIT8OFF(t1); - *ctptr++ = (char)BIT8OFF(tmp); - } - } - - else { - if (BADCHAR(charset->min_ch, (char)tmp)) { - unconv_num++; - break; - } - *ctptr++ = (char)tmp; - } - - - } while (length); - - } /* end for */ - - *to = (XPointer)ctptr; - - if ((num_conv = (int)(ctptr - ct_base)) > 0) - (*to_left) -= num_conv; - - return unconv_num; -} -#undef byte1 -#undef byte2 -#undef kana -#undef kanji -#undef userdef - - -#define byte1 (ctdp->length == clen) -#define kana (ctdp == ctdptr[Kana] && isrightside(*inbufptr)) -/* #define kanji (ctdp == ctdptr[Kanji]) */ -#define kanji (strstr(ctdp->name, "JISX0208")) -#define userdef (ctdp == ctdptr[Userdef]) - -static int -euc_ctstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - char *inbufptr = *from; - XPointer outbufptr = *to; - const char *inbuf_base; - XPointer outbuf_base = outbufptr; - int clen, length; - int unconv_num = 0; - unsigned int ct_seglen = 0; - Uchar ct_type = 0; - CTData ctdp = &ctdata[0]; /* default */ - CTData GL_ctdp = ctdp; /* GL ctdp save */ - CTData GR_ctdp = ctdp; /* GR ctdp save */ - Bool save_outbuf = True; - /* If outbufptr is NULL, doen't save output, but just counts - a length to hold the output */ - if (outbufptr == NULL) save_outbuf = False; - - for (length = ctdata[Ascii].length; *from_left > 0; (*from_left) -= length) - { - ct_type = CT_STD; - /* change GL/GR charset */ - if(ctdp->side == XlcGR && isleftside(*inbufptr)){ - /* select GL side */ - ctdp = GL_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - }else if(ctdp->side == XlcGL && isrightside(*inbufptr)){ - /* select GR side */ - ctdp = GR_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - } - if (*inbufptr == '\033' || *inbufptr == (char)'\233') { - - for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { - - if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) - { - inbufptr += ctdp->ct_encoding_len; - (*from_left) -= ctdp->ct_encoding_len; - if (ctdp->length) { - length = ctdp->length; - if( *from_left < length ) { - *to = (XPointer)outbufptr; - *to_left -= outbufptr - outbuf_base; - return( unconv_num + *from_left ); - } - } - ct_type = ctdp->ct_type; - if(ctdp->side == XlcGL){ - GL_ctdp = ctdp; /* save GL ctdp */ - }else{ - GR_ctdp = ctdp; /* save GR ctdp */ - } - break; - } - } - if (ctdp > ctd_endp) /* failed to match CT sequence */ - unconv_num++; - } - -/* The following code insures that non-standard encodings, direction, extension, - * and version strings are ignored; subject to change in future. - */ - switch (ct_type) { - case CT_STD: - break; - case CT_EXT2: - inbufptr++; - (*from_left)--; - case CT_NSTD: - ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; - inbufptr += ct_seglen; - (*from_left) -= ct_seglen; - continue; - case CT_EXT0: - inbuf_base = inbufptr; - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - *(from_left) -= ct_seglen; - continue; - case CT_EXT1: - inbuf_base = inbufptr; - SKIP_P(inbufptr); - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - *(from_left) -= ct_seglen; - continue; - case CT_DIR: - continue; - case CT_VER: - inbufptr += 2; - *(from_left) -= 2; - continue; - } - - clen = length; - do { - - if (byte1) { - if (kanji) { - /* FIXME: assignment of read-only location */ - *inbufptr = BIT8ON(*inbufptr); - *(inbufptr+1) = BIT8ON(*(inbufptr+1)); - } - else if (kana || userdef) { - if (save_outbuf == True) { - *outbufptr++ = ctdp->sshift; - } - (*to_left)--; - } - } - if (save_outbuf == True) { - *outbufptr++ = *inbufptr; - } - (*to_left)--; - inbufptr++; - - if (*to_left == 0 && *from_left != length) { - *to = (XPointer)outbufptr; - unconv_num = *from_left; - return unconv_num; - } - } while (--clen); - } - - *to = outbufptr; - - return unconv_num; - -} -#undef byte1 -#undef kana -#undef kanji -#undef userdef - - -static int -euc_mbstocts( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - int ct_len = *to_left; - int cs_num; - int clen, length = 0; - int unconv_num = 0; - int num_conv; - const char *inbufptr = *from; - char *ctptr = *to; - XPointer ct_base = ctptr; - - StateRec ct_state; - CTData charset; - XLCd lcd = (XLCd) conv->state; - int codeset_num = XLC_GENERIC(lcd, codeset_num); - -/* Initial State: */ - ct_state.GL_charset = NULL; - ct_state.GR_charset = NULL; - - if (*from_left > *to_left) - *from_left = *to_left; - - for (;*from_left > 0; (*from_left) -= length) { - - if (isleftside(*inbufptr)) { /* 7-bit (CS0) */ - if (ASCII_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Ascii; - charset = ctdptr[Ascii]; - } - else if ((Uchar)*inbufptr == SS2) { /* Kana */ - if (KANA_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Kana; - charset = ctdptr[Kana]; - inbufptr++; - (*from_left)--; - } - else if ((Uchar)*inbufptr == SS3) { /* Userdef */ - if (USERDEF_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Userdef; - charset = ctdptr[Userdef]; - inbufptr++; - (*from_left)--; - } - else { - if (KANJI_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Kanji; - charset = ctdptr[Kanji]; - } - - length = charset->length; - - if (BADCHAR(charset->min_ch, *inbufptr)) - continue; - - if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || - (charset->side == XlcGL && charset != ct_state.GL_charset) ) { - - ct_len -= ctdptr[cs_num]->ct_encoding_len; - if (ct_len < 0) { - unconv_num++; - break; - } - - if (ctptr) { - strcpy(ctptr, ctdptr[cs_num]->ct_encoding); - ctptr += ctdptr[cs_num]->ct_encoding_len; - } - } - - if (charset->side == XlcGR) { - ct_state.GR_charset = charset; - ct_state.GL_charset = NULL; - } else if (charset->side == XlcGL) { - ct_state.GL_charset = charset; - ct_state.GR_charset = NULL; - } - - clen = length; - - do { - *ctptr++ = charset == ct_state.GR_charset ? - BIT8ON(*inbufptr++) : BIT8OFF(*inbufptr++); - } while (--clen); - } - - *to = (XPointer)ctptr; - - if ((num_conv = (int)(ctptr - ct_base)) > 0) - (*to_left) -= num_conv; - return unconv_num; - -} - - -static void -close_converter( - XlcConv conv) -{ - Xfree(conv); -} - -enum { MBSTOCS, WCSTOCS, MBTOCS, CSTOMBS, CSTOWCS, MBSTOWCS, WCSTOMBS, - CTSTOWCS, CTSTOMBS, WCSTOCTS, MBSTOCTS }; - -static XlcConvMethodsRec conv_methods[] = { - {close_converter, euc_mbstocs, NULL }, - {close_converter, euc_wcstocs, NULL }, - {close_converter, euc_mbtocs, NULL }, - {close_converter, euc_cstombs, NULL }, - {close_converter, euc_cstowcs, NULL }, - {close_converter, euc_mbstowcs, NULL }, - {close_converter, euc_wcstombs, NULL }, - {close_converter, euc_ctstowcs, NULL }, - {close_converter, euc_ctstombs, NULL }, - {close_converter, euc_wcstocts, NULL }, - {close_converter, euc_mbstocts, NULL }, -}; - - -static XlcConv -open_mbstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBSTOCS]); -} - -static XlcConv -open_wcstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[WCSTOCS]); -} - -static XlcConv -open_mbtocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBTOCS]); -} - -static XlcConv -open_cstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CSTOMBS]); -} - -static XlcConv -open_cstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CSTOWCS]); -} - -static XlcConv -open_mbstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBSTOWCS]); -} - -static XlcConv -open_wcstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[WCSTOMBS]); -} - -static XlcConv -open_ctstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CTSTOWCS]); -} - -static XlcConv -open_ctstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CTSTOMBS]); -} - -static XlcConv -open_wcstocts( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[WCSTOCTS]); -} - -static XlcConv -open_mbstocts( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBSTOCTS]); -} - -XLCd -_XlcEucLoader( - const char *name) -{ - XLCd lcd; - - lcd = _XlcCreateLC(name, _XlcGenericMethods); - if (lcd == NULL) - return lcd; - - if (!XLC_PUBLIC_PART(lcd)->codeset || - (_XlcNCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "euc", 3))) { - _XlcDestroyLC(lcd); - return (XLCd) NULL; - } - - initCTptr(lcd); - - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); - -#ifndef FORCE_INDIRECT_CONVERTER - _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs); - _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs); - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts); - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); -#endif - - _XlcAddUtf8Converters(lcd); - - return lcd; -} - -#else -typedef int dummy; -#endif /* X_LOCALE */ diff --git a/nx-X11/lib/X11/lcInit.c b/nx-X11/lib/X11/lcInit.c index 5aaf1832b..e3092f77d 100644 --- a/nx-X11/lib/X11/lcInit.c +++ b/nx-X11/lib/X11/lcInit.c @@ -106,11 +106,6 @@ Sun Microsystems, Inc. or its licensors is granted. #define USE_GENERIC_LOADER #define USE_DEFAULT_LOADER #define USE_UTF8_LOADER -#ifdef X_LOCALE -# define USE_EUC_LOADER -# define USE_SJIS_LOADER -# define USE_JIS_LOADER -#endif #endif /* @@ -138,18 +133,6 @@ _XlcInitLoader(void) _XlcAddLoader(_XlcUtf8Loader, XlcHead); #endif -#ifdef USE_EUC_LOADER - _XlcAddLoader(_XlcEucLoader, XlcHead); -#endif - -#ifdef USE_SJIS_LOADER - _XlcAddLoader(_XlcSjisLoader, XlcHead); -#endif - -#ifdef USE_JIS_LOADER - _XlcAddLoader(_XlcJisLoader, XlcHead); -#endif - #ifdef USE_DYNAMIC_LOADER _XlcAddLoader(_XlcDynamicLoader, XlcHead); #endif @@ -177,18 +160,6 @@ _XlcDeInitLoader(void) _XlcRemoveLoader(_XlcUtf8Loader); #endif -#ifdef USE_EUC_LOADER - _XlcRemoveLoader(_XlcEucLoader); -#endif - -#ifdef USE_SJIS_LOADER - _XlcRemoveLoader(_XlcSjisLoader); -#endif - -#ifdef USE_JIS_LOADER - _XlcRemoveLoader(_XlcJisLoader); -#endif - #ifdef USE_DYNAMIC_LOADER _XlcRemoveLoader(_XlcDynamicLoader); #endif diff --git a/nx-X11/lib/X11/lcJis.c b/nx-X11/lib/X11/lcJis.c deleted file mode 100644 index a6917cf9f..000000000 --- a/nx-X11/lib/X11/lcJis.c +++ /dev/null @@ -1,944 +0,0 @@ -/* - * Copyright 1992, 1993 by TOSHIBA Corp. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of TOSHIBA not be used in advertising - * or publicity pertaining to distribution of the software without specific, - * written prior permission. TOSHIBA make no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING - * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL - * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR - * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * Author: Katsuhisa Yano TOSHIBA Corp. - * mopi@osa.ilab.toshiba.co.jp - */ - -/* - * A Japanese JIS locale. - * Supports: all locales with codeset JIS7. - * How: Provides converters for JIS. - * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2). - */ - -#ifdef X_LOCALE - -#ifdef HAVE_CONFIG_H -#include -#endif -#include "Xlibint.h" -#include "XlcGeneric.h" -#include - -#if !defined(X_LOCALE) -#define STDCVT -#endif - -typedef struct _StateRec { - XLCd lcd; - XlcCharSet charset; - XlcCharSet GL_charset; - XlcCharSet GR_charset; -} StateRec, *State; - -static void -init_state( - XlcConv conv) -{ - State state = (State) conv->state; - XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd); - CodeSet codeset; - - codeset = gen->initial_state_GL; - if (codeset && codeset->charset_list) - state->GL_charset = *codeset->charset_list; - codeset = gen->initial_state_GR; - if (codeset && codeset->charset_list) - state->GR_charset = *codeset->charset_list; - - if (state->GL_charset == NULL) - if ((codeset = *gen->codeset_list) != NULL) - state->GL_charset = *codeset->charset_list; -} - -static int -compare( - const char *src, - const char *encoding, - int length) -{ - const char *start = src; - - while (length-- > 0) { - if (*src++ != *encoding++) - return 0; - if (*encoding == '\0') - return src - start; - } - - return 0; -} - -static int -mbtocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - State state = (State) conv->state; - XLCd lcd = state->lcd; - const char *src; - char *dst; - unsigned char *mb_parse_table; - ParseInfo *parse_list, parse_info; - XlcCharSet charset; - int length, number, encoding_len = 0; - int i; - - src = *((const char **) from); - dst = *((char **) to); - - mb_parse_table = XLC_GENERIC(lcd, mb_parse_table); - if (mb_parse_table != NULL) { - number = mb_parse_table[(unsigned char) *src]; - if (number > 0) { - parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1; - for ( ; (parse_info = *parse_list) != NULL; parse_list++) { - encoding_len = compare(src, parse_info->encoding, *from_left); - if (encoding_len > 0) { - switch (parse_info->type) { - case E_SS: - src += encoding_len; - charset = *parse_info->codeset->charset_list; - goto found; - case E_LSL: - case E_LSR: - src += encoding_len; - charset = *parse_info->codeset->charset_list; - if (parse_info->type == E_LSL) - state->GL_charset = charset; - else - state->GR_charset = charset; - length = 0; - goto end; - case E_GL: - charset = state->GL_charset; - goto found; - case E_GR: - charset = state->GR_charset; - goto found; - default: - break; - } - } - } - } - } - - if ((*src & 0x80) && state->GR_charset) - charset = state->GR_charset; - else - charset = state->GL_charset; - -found: - if (charset == NULL || - (num_args == 2 && (XlcCharSet) args[1] != charset)) - return -1; - - length = charset->char_size; - if (length > *from_left - encoding_len) - return -1; - - if (dst) { - if (length > *to_left) - return -1; - if (charset->side == XlcGL) { - for (i = 0; i < length; i++) - *dst++ = *src++ & 0x7f; - } else if (charset->side == XlcGR) { - for (i = 0; i < length; i++) - *dst++ = *src++ | 0x80; - } else { - for (i = 0; i < length; i++) - *dst++ = *src++; - } - *to = (XPointer) dst; - *to_left -= length; - } -end: - *from = (XPointer) src; - *from_left -= encoding_len + length; - state->charset = charset; - if (num_args == 1) - *((XlcCharSet *) args[0]) = charset; - - return 0; -} - -static int -mbstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XlcCharSet charset = NULL; - XPointer tmp_args[2], save_from = *from; - int ret, unconv_num = 0, tmp_num = 1; - - tmp_args[0] = (XPointer) &charset; - - while (*from_left > 0 && *to_left > 0) { - ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, tmp_num); - if (ret < 0) - break; - unconv_num += ret; - if (tmp_num == 1 && charset) { - tmp_args[1] = (XPointer) charset; - tmp_num = 2; - } - } - - if (save_from == *from) - return -1; - - if (num_args > 0) - *((XlcCharSet *) args[0]) = charset; - - return unconv_num; -} - -static CodeSet -wc_parse_codeset( - XLCd lcd, - const wchar_t *wcstr) -{ - CodeSet *codeset; - unsigned long wc_encoding; - int num; - - wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask); - num = XLC_GENERIC(lcd, codeset_num); - codeset = XLC_GENERIC(lcd, codeset_list); - while (num-- > 0) { - if (wc_encoding == (*codeset)->wc_encoding) - return *codeset; - codeset++; - } - - return NULL; -} - -static int -wcstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - State state = (State) conv->state; - XLCd lcd = state->lcd; - const wchar_t *wcptr; - char *bufptr; - wchar_t wch; - char *tmpptr; - int length; - CodeSet codeset; - unsigned long wc_encoding; - int wcstr_len, buf_len; - - if (from == NULL || *from == NULL) - return 0; - - wcptr = *((const wchar_t **) from); - bufptr = *((char **) to); - wcstr_len = *from_left; - buf_len = *to_left; - - codeset = wc_parse_codeset(lcd, wcptr); - if (codeset == NULL) - return -1; - wc_encoding = codeset->wc_encoding; - - if (wcstr_len < buf_len / codeset->length) - buf_len = wcstr_len * codeset->length; - - for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) { - wch = *wcptr; - if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding) - break; - length = codeset->length; - buf_len -= length; - bufptr += length; - - tmpptr = bufptr - 1; - if ((*codeset->charset_list)->side == XlcGL) { - while (length--) { - *tmpptr-- = (unsigned char) (wch & 0x7f); - wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); - } - } else if ((*codeset->charset_list)->side == XlcGR) { - while (length--) { - *tmpptr-- = (unsigned char) (wch | 0x80); - wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); - } - } else { - while (length--) { - *tmpptr-- = (unsigned char) wch; - wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); - } - } - } - - if (num_args > 0) - *((XlcCharSet *) args[0]) = *codeset->charset_list; - - *from_left -= wcptr - *((wchar_t **) from); - *from = (XPointer) wcptr; - - *to_left -= bufptr - *((char **) to); - *to = bufptr; - - return 0; -} - -static CodeSet -GetCodeSetFromCharSet( - XLCd lcd, - XlcCharSet charset) -{ - CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); - XlcCharSet *charset_list; - int codeset_num, num_charsets; - - codeset_num = XLC_GENERIC(lcd, codeset_num); - - for ( ; codeset_num-- > 0; codeset++) { - num_charsets = (*codeset)->num_charsets; - charset_list = (*codeset)->charset_list; - - for ( ; num_charsets-- > 0; charset_list++) - if (*charset_list == charset) - return *codeset; - } - - return (CodeSet) NULL; -} - -static int -cstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - State state = (State) conv->state; - const char *csptr; - char *bufptr; - int csstr_len; - int buf_len; - int num, encoding_len = 0; - CodeSet codeset; - XlcCharSet charset; - EncodingType type; - int cvt_length; - - csptr = *((const char **) from); - bufptr = *((char **) to); - csstr_len = *from_left; - buf_len = *to_left; - - if (num_args < 1) - return -1; - - charset = (XlcCharSet) args[0]; - - codeset = GetCodeSetFromCharSet(state->lcd, charset); - if (codeset == NULL) - return -1; - - cvt_length = 0; - if (codeset->parse_info) { - switch (type = codeset->parse_info->type) { - case E_SS: - encoding_len = strlen(codeset->parse_info->encoding); - break; - case E_LSL: - case E_LSR: - if (type == E_LSL) { - if (charset == state->GL_charset) - break; - } else { - if (charset == state->GR_charset) - break; - } - encoding_len = strlen(codeset->parse_info->encoding); - if (encoding_len > buf_len) - return -1; - cvt_length += encoding_len; - if (bufptr) { - strcpy(bufptr, codeset->parse_info->encoding); - bufptr += encoding_len; - } - buf_len -= encoding_len; - encoding_len = 0; - if (type == E_LSL) - state->GL_charset = charset; - else - state->GR_charset = charset; - break; - default: - break; - } - } - - csstr_len /= codeset->length; - buf_len /= codeset->length + encoding_len; - if (csstr_len < buf_len) - buf_len = csstr_len; - - cvt_length += buf_len * (encoding_len + codeset->length); - if (bufptr) { - while (buf_len--) { - if (encoding_len) { - strcpy(bufptr, codeset->parse_info->encoding); - bufptr += encoding_len; - } - num = codeset->length; - if (codeset->side == XlcGL) { - while (num--) - *bufptr++ = *csptr++ & 0x7f; - } else if (codeset->side == XlcGR) { - while (num--) - *bufptr++ = *csptr++ | 0x80; - } else { - while (num--) - *bufptr++ = *csptr++; - } - } - } - - *from_left -= csptr - *((char **) from); - *from = (XPointer) csptr; - - if (bufptr) - *to = (XPointer) bufptr; - *to_left -= cvt_length; - - return 0; -} - -static int -cstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - State state = (State) conv->state; - XLCd lcd = state->lcd; - const char *csptr; - wchar_t *bufptr; - int csstr_len; - int buf_len; - wchar_t wch; - unsigned long code_mask, wc_encoding; - int num, length, wc_shift_bits; - CodeSet codeset; - - csptr = *((const char **) from); - bufptr = *((wchar_t **) to); - csstr_len = *from_left; - buf_len = *to_left; - - if (num_args < 1) - return -1; - - codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]); - if (codeset == NULL) - return -1; - - length = codeset->length; - csstr_len /= length; - if (csstr_len < buf_len) - buf_len = csstr_len; - - code_mask = ~XLC_GENERIC(lcd, wc_encode_mask); - wc_encoding = codeset->wc_encoding; - wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); - - *to_left -= buf_len; - - if (bufptr) { - while (buf_len--) { - wch = (wchar_t) (*csptr++ & 0x7f); - num = length - 1; - while (num--) - wch = (wch << wc_shift_bits) | (*csptr++ & 0x7f); - - *bufptr++ = (wch & code_mask) | wc_encoding; - } - } - - *from_left -= csptr - *((char **) from); - *from = (XPointer) csptr; - - if (bufptr) - *to = (XPointer) bufptr; - - return 0; -} - - -static void -close_converter( - XlcConv conv) -{ - if (conv->state) { - Xfree(conv->state); - } - - Xfree(conv); -} - -static XlcConv -create_conv( - XLCd lcd, - XlcConvMethods methods) -{ - XlcConv conv; - State state; - - conv = Xmalloc(sizeof(XlcConvRec)); - if (conv == NULL) - return (XlcConv) NULL; - - conv->methods = Xmalloc(sizeof(XlcConvMethodsRec)); - if (conv->methods == NULL) - goto err; - *conv->methods = *methods; - if (XLC_PUBLIC(lcd, is_state_depend)) - conv->methods->reset = init_state; - - conv->state = Xcalloc(1, sizeof(StateRec)); - if (conv->state == NULL) - goto err; - - state = (State) conv->state; - state->lcd = lcd; - init_state(conv); - - return conv; - -err: - close_converter(conv); - - return (XlcConv) NULL; -} - -static XlcConvMethodsRec mbstocs_methods = { - close_converter, - mbstocs, - NULL -}; - -static XlcConv -open_mbstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &mbstocs_methods); -} - -static XlcConvMethodsRec wcstocs_methods = { - close_converter, - wcstocs, - NULL -}; - -static XlcConv -open_wcstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &wcstocs_methods); -} - -static XlcConvMethodsRec mbtocs_methods = { - close_converter, - mbtocs, - NULL -}; - -static XlcConv -open_mbtocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &mbtocs_methods); -} - -static XlcConvMethodsRec cstombs_methods = { - close_converter, - cstombs, - NULL -}; - -static XlcConv -open_cstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &cstombs_methods); -} - -static XlcConvMethodsRec cstowcs_methods = { - close_converter, - cstowcs, - NULL -}; - -static XlcConv -open_cstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &cstowcs_methods); -} - -#ifdef STDCVT -static int -stdc_mbstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const char *src = *((const char **) from); - wchar_t *dst = *((wchar_t **) to); - int src_left = *from_left; - int dst_left = *to_left; - int length; - - while (src_left > 0 && dst_left > 0) { - length = mbtowc(dst, src, src_left); - if (length < 0) - break; - - src += length; - src_left -= length; - if (dst) - dst++; - dst_left--; - - if (length == 0) { - src++; - src_left--; - break; - } - } - - if (*from_left == src_left) - return -1; - - *from = (XPointer) src; - if (dst) - *to = (XPointer) dst; - *from_left = src_left; - *to_left = dst_left; - - return 0; -} - -static int -stdc_wcstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const wchar_t *src = *((const wchar_t **) from); - char *dst = *((char **) to); - int src_left = *from_left; - int dst_left = *to_left; - int length; - - while (src_left > 0 && dst_left > 0) { - length = wctomb(dst, *src); /* XXX */ - if (length < 0 || dst_left < length) - break; - - src++; - src_left--; - dst += length; - dst_left -= length; - - if (length == 0) { - dst++; - dst_left--; - break; - } - } - - if (*from_left == src_left) - return -1; - - *from = (XPointer) src; - *to = (XPointer) dst; - *from_left = src_left; - *to_left = dst_left; - - return 0; -} - -static int -stdc_wcstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const wchar_t *src = *((const wchar_t **) from); - wchar_t wch; - XlcCharSet charset = NULL; - XPointer tmp_args[2], tmp_from, save_from = *from; - char tmp[32]; - int length, ret, src_left = *from_left; - int unconv_num = 0, tmp_num = 1; - - tmp_args[0] = (XPointer) &charset; - - while (src_left > 0 && *to_left > 0) { - if (wch = *src) { - length = wctomb(tmp, wch); - } else { - length = 1; - *tmp = '\0'; - } - - if (length < 0) - break; - - tmp_from = (XPointer) tmp; - ret = mbtocs(conv, &tmp_from, &length, to, to_left, tmp_args, tmp_num); - if (ret < 0) - break; - unconv_num += ret; - if (tmp_num == 1 && charset) { - tmp_args[1] = (XPointer) charset; - tmp_num = 2; - } - - src++; - src_left--; - } - - if (save_from == (XPointer) src) - return -1; - - *from = (XPointer) src; - *from_left = src_left; - - if (num_args > 0) - *((XlcCharSet *) args[0]) = charset; - - return unconv_num; -} - -#define DefineLocalBuf char local_buf[BUFSIZ] -#define AllocLocalBuf(length) (length > BUFSIZ ? (char*) Xmalloc(length) : local_buf) -#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr) - -static int -stdc_cstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = ((State) conv->state)->lcd; - DefineLocalBuf; - XPointer buf, save_buf; - int length, left, ret; - - left = length = *to_left * XLC_PUBLIC(lcd, mb_cur_max); - buf = save_buf = (XPointer) AllocLocalBuf(length); - if (buf == NULL) - return -1; - - ret = cstombs(conv, from, from_left, &buf, &left, args, num_args); - if (ret < 0) - goto err; - - buf = save_buf; - length -= left; - if (stdc_mbstowcs(conv, &buf, &length, to, to_left, args, num_args) < 0) - ret = -1; - -err: - FreeLocalBuf(save_buf); - - return ret; -} - -static XlcConvMethodsRec stdc_mbstowcs_methods = { - close_converter, - stdc_mbstowcs, - NULL -}; - -static XlcConv -open_stdc_mbstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &stdc_mbstowcs_methods); -} - -static XlcConvMethodsRec stdc_wcstombs_methods = { - close_converter, - stdc_wcstombs, - NULL -}; - -static XlcConv -open_stdc_wcstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &stdc_wcstombs_methods); -} - -static XlcConvMethodsRec stdc_wcstocs_methods = { - close_converter, - stdc_wcstocs, - NULL -}; - -static XlcConv -open_stdc_wcstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &stdc_wcstocs_methods); -} - -static XlcConvMethodsRec stdc_cstowcs_methods = { - close_converter, - stdc_cstowcs, - NULL -}; - -static XlcConv -open_stdc_cstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &stdc_cstowcs_methods); -} -#endif /* STDCVT */ - -XLCd -_XlcJisLoader( - const char *name) -{ - XLCd lcd; -#ifdef STDCVT - XLCdGenericPart *gen; -#endif - - lcd = _XlcCreateLC(name, _XlcGenericMethods); - if (lcd == NULL) - return lcd; - - if (!XLC_PUBLIC_PART(lcd)->codeset || - (_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "JIS7"))) { - _XlcDestroyLC(lcd); - return (XLCd) NULL; - } - - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs); - -#ifdef STDCVT - gen = XLC_GENERIC_PART(lcd); - - if (gen->use_stdc_env == True) { - _XlcSetConverter(lcd,XlcNMultiByte,lcd,XlcNWideChar,open_stdc_mbstowcs); - _XlcSetConverter(lcd,XlcNWideChar,lcd,XlcNMultiByte,open_stdc_wcstombs); - } - if (gen->force_convert_to_mb == True) { - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet,open_stdc_wcstocs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar,open_stdc_cstowcs); - } else { -#endif - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs); -#ifdef STDCVT - } -#endif - - _XlcAddUtf8Converters(lcd); - - return lcd; -} - -#else -typedef int dummy; -#endif /* X_LOCALE */ diff --git a/nx-X11/lib/X11/lcSjis.c b/nx-X11/lib/X11/lcSjis.c deleted file mode 100644 index ac945570a..000000000 --- a/nx-X11/lib/X11/lcSjis.c +++ /dev/null @@ -1,1612 +0,0 @@ -/**************************************************************** - - Copyright 1992, 1993 by FUJITSU LIMITED - Copyright 1993 by Fujitsu Open Systems Solutions, Inc. - Copyright 1994 by Sony Corporation - -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, and that the name of FUJITSU LIMITED, -Fujitsu Open Systems Solutions, Inc. and Sony Corporation not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. -FUJITSU LIMITED, Fujitsu Open Systems Solutions, Inc. and -Sony Corporation make no representations about the suitability of -this software for any purpose. It is provided "as is" without -express or implied warranty. - -FUJITSU LIMITED, FUJITSU OPEN SYSTEMS SOLUTIONS, INC. AND SONY -CORPORATION DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, -IN NO EVENT SHALL FUJITSU OPEN SYSTEMS SOLUTIONS, INC., FUJITSU LIMITED -AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE. - - Authors: Jeffrey Bloomfield (jeffb@ossi.com) - Shigeru Yamada (yamada@ossi.com) - Yoshiyuki Segawa (segawa@ossi.com) - Modifier:Makoto Wakamatsu Sony Corporation - makoto@sm.sony.co.jp - -*****************************************************************/ - -/* - * A Japanese SJIS locale. - * Supports: all locales with codeset SJIS. - * How: Provides converters for SJIS. - * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2). - */ - -#ifdef X_LOCALE - -#ifdef HAVE_CONFIG_H -#include -#endif -#include "Xlibint.h" -#include "XlcGeneric.h" - -#include -#ifdef WIN32 -#define isascii __isascii -#endif - -#define CS0 codesets[0] /* Codeset 0 - 7-bit ASCII */ -#define CS1 codesets[1] /* Codeset 1 - Kanji */ -#define CS2 codesets[2] /* Codeset 2 - Half-Kana */ -#define CS3 codesets[3] /* Codeset 3 - User defined */ - -#define ascii (codeset->cs_num == 0) -#define kanji (codeset->cs_num == 1) -#define kana (codeset->cs_num == 2) -#define userdef (codeset->cs_num == 3) - -#define ASCII_CODESET 0 -#define KANJI_CODESET 1 -#define KANA_CODESET 2 -#define USERDEF_CODESET 3 -#define MAX_CODESETS 4 - -#define GR 0x80 /* begins right-side (non-ascii) region */ -#define GL 0x7f /* ends left-side (ascii) region */ - -#define isleftside(c) (((c) & GR) ? 0 : 1) -#define isrightside(c) (!isleftside(c)) - -typedef unsigned char Uchar; -typedef unsigned long Ulong; -typedef unsigned int Uint; - -/* Acceptable range for 2nd byte of SJIS multibyte char */ -#define VALID_MULTIBYTE(c) \ - ((0x40<=((Uchar)c) && ((Uchar)c)<=0x7e) \ - || (0x80<=((Uchar)c) && ((Uchar)c)<=0xfc)) - -#ifndef iskanji -#define iskanji(c) ((0x81<=((Uchar)c) && ((Uchar)c)<=0x9f) \ - || (0xe0<=((Uchar)c) && ((Uchar)c)<=0xef)) -#endif /* !iskanji */ - -#ifndef iskana -#define iskana(c) (0xa1<=((Uchar)c) && ((Uchar)c)<=0xdf) -#endif /* !iskana */ - -#define isuserdef(c) (0xf0<=((Uchar)c) && ((Uchar)c)<=0xfc) - -#define BIT8OFF(c) ((c) & GL) -#define BIT8ON(c) ((c) | GR) - - -static void jis_to_sjis (Uchar *p1, Uchar *p2); -static void sjis_to_jis (Uchar *p1, Uchar *p2); -static CodeSet wc_codeset (XLCd lcd, wchar_t wch); - - -/* - * Notes: - * 1. 16-bit widechar format is limited to 14 data bits. Since the 2nd byte - * of SJIS multibyte chars are in the ranges of 0x40 - 7E and 0x80 - 0xFC, - * SJIS cannot map directly into 16 bit widechar format within the confines - * of a single codeset. Therefore, for SJIS widechar conversion, SJIS Kanji - * is mapped into the JIS codeset. (The algorithms used in jis_to_sjis() - * and sjis_to_jis() are from Ken Lunde (lunde@mv.us.adobe.com) and are in - * the public domain.) - * 2. Defining FORCE_INDIRECT_CONVERTER (see _XlcEucLoader()) - * forces indirect (charset) conversions (e.g. wcstocs()<->cstombs()). - * 3. Using direct converters (e.g. mbstowcs()) decreases conversion - * times by 20-40% (depends on specific converter used). - */ - - -static int -sjis_mbstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - - XLCd lcd = (XLCd)conv->state; - - int chr_len = 0; - int shift_mult = 0; - Uint chrcode = 0; - - Uchar ch, ch2; - Uint wc_encode = 0; - Uint wc_tmp = 0; - - Bool new_char; - - int firstbyte; - int length = 0; - int num_conv; - int unconv_num = 0; - - const char *inbufptr = *from; - wchar_t *outbufptr = (wchar_t *) *to; - wchar_t *outbuf_base = outbufptr; - - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - int codeset_num = XLC_GENERIC(lcd, codeset_num); - Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - if (*from_left > *to_left) - *from_left = *to_left; - - for (new_char = True, firstbyte = True; *from_left > 0; (*from_left)--) { - - ch = *inbufptr++; - - if (firstbyte) { - if (ASCII_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - if (isascii(ch)) { - length = CS0->length; - *outbufptr++ = (wchar_t)ch; - continue; - } - else if (iskanji(ch)) { - if (KANJI_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - firstbyte = False; - length = CS1->length; - if (*from_left < length || *to_left < length) - return -1; - wc_encode = CS1->wc_encoding; - ch2 = *inbufptr; - sjis_to_jis(&ch, &ch2); - chrcode = ch; - } - else if (iskana(ch)) { - if (KANA_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - length = CS2->length; - wc_encode = CS2->wc_encoding; - chrcode = BIT8OFF(ch); - } - else if (isuserdef(ch)) { - if (USERDEF_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - firstbyte = False; - length = CS3->length; - if (*from_left < length || *to_left < length) - return -1; - wc_encode = CS3->wc_encoding; - ch2 = *inbufptr; - sjis_to_jis(&ch, &ch2); - chrcode = ch; - } - else /* unknown */ { - unconv_num++; - (*from_left)--; - continue; - } - } else { /* 2nd byte of multibyte char */ - if (!VALID_MULTIBYTE((Uchar) *(inbufptr-1))) { - unconv_num++; - firstbyte = True; - } - chrcode = ch2; - } - - if (new_char) { - chr_len = length; - shift_mult = length - 1; - new_char = False; - } - - chrcode <<= (wc_shift * shift_mult); - shift_mult--; - wc_tmp |= chrcode; - if (--chr_len == 0) { - wc_tmp |= wc_encode; - *outbufptr++ = wc_tmp; - - firstbyte = True; - new_char = True; - wc_tmp = (Uint)0; - } - - } /* end for */ - - *to = (XPointer)outbufptr; - - if ((num_conv = outbufptr - outbuf_base) > 0) - (*to_left) -= num_conv; - - return unconv_num; -} - - -#define byte1 (length == codeset->length - 1) -#define byte2 (byte1 == 0) - -static int -sjis_wcstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const wchar_t *inbufptr = (const wchar_t *) *from; - XPointer outbufptr = *to; - XPointer outbuf_base = outbufptr; - wchar_t wch; - int length; - Uchar tmp; - Uchar t1, t2; - int num_conv; - int unconv_num = 0; - - XLCd lcd = (XLCd)conv->state; - CodeSet codeset; - Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - if (*from_left > *to_left) - *from_left = *to_left; - - for (; *from_left > 0 ; (*from_left)-- ) { - - wch = *inbufptr++; - - if (!(codeset = wc_codeset(lcd, wch))) { - unconv_num++; - (*from_left)--; - continue; - } - - length = codeset->length; - wch ^= (wchar_t)codeset->wc_encoding; - - do { - length--; - tmp = wch>>(wchar_t)( (Ulong)length * wc_shift); - - if (kana) - tmp = BIT8ON(tmp); - - else if (byte1 && (kanji || userdef)) { - t1 = BIT8OFF(tmp); - continue; - } - - else if (byte2 && (kanji || userdef)) { - t2 = BIT8OFF(tmp); - jis_to_sjis(&t1, &t2); - *outbufptr++ = (char)t1; - tmp = t2; - } - - *outbufptr++ = (char)tmp; - } while (length); - - } /* end for */ - - *to = (XPointer)outbufptr; - - if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) - (*to_left) -= num_conv; - - return unconv_num; -} -#undef byte1 -#undef byte2 - -/* - * sjis<->jis conversion for widechar kanji (See Note at top of file) - */ -static void -sjis_to_jis( - Uchar *p1, - Uchar *p2) -{ - Uchar c1 = *p1; - Uchar c2 = *p2; - Uchar adjust = c2 < 0x9f; - Uchar rowOffset = c1 < 0xa0 ? 0x70 : 0xb0; - Uchar cellOffset = adjust ? (0x1f + (c2 > 0x7f)) : 0x7e; - - *p1 = ((c1 - rowOffset) << 1) - adjust; - *p2 -= cellOffset; -} - -static void -jis_to_sjis( - Uchar *p1, - Uchar *p2) -{ - Uchar c1 = *p1; - Uchar c2 = *p2; - Uchar rowOffset = c1 < 0x5f ? 0x70 : 0xb0; - Uchar cellOffset = c1 % 2 ? 0x1f + (c2 > 0x5f) : 0x7e; - - *p1 = ((Uchar)(c1 + 1) >> 1) + rowOffset; - *p2 = c2 + cellOffset; -} - -static CodeSet -wc_codeset( - XLCd lcd, - wchar_t wch) -{ - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); -#if !defined(__sony_news) || defined(SVR4) - int end = XLC_GENERIC(lcd, codeset_num); - Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); - - for (; --end >= 0; codesets++) - if ( widech == (*codesets)->wc_encoding ) - return *codesets; - - return NULL; -#else - if( iskanji(wch >> 8) ) - return( codesets[1] ); - if( iskana(wch & 0xff) ) - return( codesets[2] ); - return( codesets[0] ); -#endif -} - - -static int -sjis_mbtocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - XlcCharSet charset = NULL; - int char_size = 0; - int unconv_num = 0; - const char *src = *from; - char *dst = *to; - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - int codeset_num = XLC_GENERIC(lcd, codeset_num); - - if (iskanji(*src)) { - if (KANJI_CODESET >= codeset_num) - return -1; - charset = *CS1->charset_list; - char_size = charset->char_size; - - if (*from_left >= char_size && *to_left >= char_size) { - *dst++ = *src++; - *dst++ = *src++; - if (!VALID_MULTIBYTE((Uchar) *(src-1))) /* check 2nd byte */ - unconv_num++; - sjis_to_jis((Uchar *)(dst-2), (Uchar *)(dst-1)); - } else - return -1; - } - else if (isuserdef(*src)) { - if (USERDEF_CODESET >= codeset_num) - return -1; - charset = *CS3->charset_list; - char_size = charset->char_size; - - if (*from_left >= char_size && *to_left >= char_size) { - *dst++ = *src++; - *dst++ = *src++; - if (!VALID_MULTIBYTE((Uchar) *(src-1))) /* check 2nd byte */ - unconv_num++; - sjis_to_jis((Uchar *)(dst-2), (Uchar *)(dst-1)); - } else - return -1; - } - else if (isascii(*src)) { - if (ASCII_CODESET >= codeset_num) - return -1; - charset = *CS0->charset_list; - char_size = charset->char_size; - - if (*from_left >= char_size && *to_left >= char_size) - *dst++ = *src++; - else - return -1; - } - else if (iskana(*src)) { - if (KANA_CODESET >= codeset_num) - return -1; - charset = *CS2->charset_list; - char_size = charset->char_size; - - if (*from_left >= char_size && *to_left >= char_size) - *dst++ = *src++; - else - return -1; - } - else /* unknown */ - return -1; - - *from_left -= char_size; - *to_left -= char_size; - - *to = (XPointer) dst; - *from = (XPointer) src; - - if (num_args > 0) - *((XlcCharSet *) args[0]) = charset; - - return unconv_num; -} - - -static int -sjis_mbstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const char *tmp_from; - char *tmp_to; - int tmp_from_left, tmp_to_left; - XlcCharSet charset, tmp_charset; - XPointer tmp_args[1]; - int unconv_num = 0, ret; - -/* Determine the charset of the segment and convert one character: */ - - tmp_args[0] = (XPointer) &charset; /* charset from sjis_mbtocs() */ - while - ((ret = sjis_mbtocs(conv, from, from_left, to, to_left, tmp_args, 1)) > 0) - unconv_num += ret; - if ( ret < 0 ) - return ret; - - tmp_from = *from; - tmp_from_left = *from_left; - tmp_to_left = *to_left; - tmp_to = *to; - -/* Convert remainder of the segment: */ - - tmp_args[0] = (XPointer) &tmp_charset; - while( (ret = sjis_mbtocs(conv, (XPointer *) &tmp_from, &tmp_from_left, - (XPointer *) &tmp_to, &tmp_to_left, tmp_args, 1)) >= 0 ) { - - if (ret > 0) { - unconv_num += ret; - continue; - } - - if (tmp_charset != charset) /* quit on end of segment */ - break; - - *from = (XPointer) tmp_from; - *from_left = tmp_from_left; - *to = (XPointer) tmp_to; - *to_left = tmp_to_left; - } - - if (num_args > 0) - *((XlcCharSet *) args[0]) = charset; - - return unconv_num; -} - -static int -sjis_wcstocs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd) conv->state; - const wchar_t *wcptr = *((const wchar_t **)from); - char *bufptr = *((char **) to); - wchar_t wch; - char *tmpptr; - int length; - CodeSet codeset; - Ulong wc_encoding; - int buf_len = *to_left; - int wcstr_len = *from_left; - - if (!(codeset = wc_codeset(lcd, *wcptr))) - return -1; - - if (wcstr_len < buf_len / codeset->length) - buf_len = wcstr_len * codeset->length; - -#if !defined(__sony_news) || defined(SVR4) - wc_encoding = codeset->wc_encoding; - - for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) { - wch = *wcptr; - - if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding) - break; - - length = codeset->length; - - buf_len -= length; - bufptr += length; - tmpptr = bufptr - 1; - - while (length--) { - *tmpptr-- = kana ? BIT8ON(wch) : BIT8OFF(wch); - wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); - } - } -#else - length = codeset->length; - for( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len-- ) { - wch = *wcptr; - if( codeset != wc_codeset( lcd, wch ) ) - break; - - buf_len -= length; - if( length == 2 ) { - unsigned short code; - - code = sjis2jis( wch & 0xffff ); - *bufptr++ = code >> 8; - *bufptr++ = code & 0xff; - } - else - *bufptr++ = wch & 0xff; - } -#endif - - if (num_args > 0) - *((XlcCharSet *) args[0]) = *codeset->charset_list; - - *from_left -= wcptr - (wchar_t *) *from; - *from = (XPointer) wcptr; - - *to_left -= bufptr - *to; - *to = bufptr; - - return 0; -} - -static CodeSet -GetCodeSetFromCharSet( - XLCd lcd, - XlcCharSet charset) -{ - CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); - XlcCharSet *charset_list; - int codeset_num, num_charsets; - - codeset_num = XLC_GENERIC(lcd, codeset_num); - - for ( ; codeset_num-- > 0; codeset++) { - num_charsets = (*codeset)->num_charsets; - charset_list = (*codeset)->charset_list; - - for ( ; num_charsets-- > 0; charset_list++) - if (*charset_list == charset) - return *codeset; - } - - return (CodeSet) NULL; -} - - -static int -sjis_cstombs( - XlcConv conv, - char **from, - int *from_left, - char **to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd) conv->state; - const char *csptr = *from; - char *bufptr = *to; - int csstr_len = *from_left; - int buf_len = *to_left; - int length; - CodeSet codeset; - int cvt_length = 0; - - if (num_args < 1) - return -1; - - if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) - return -1; - - csstr_len /= codeset->length; - buf_len /= codeset->length; - if (csstr_len < buf_len) - buf_len = csstr_len; - - cvt_length += buf_len * codeset->length; - - if (bufptr) { - while (buf_len--) { - length = codeset->length; - while (length--) - *bufptr++ = codeset->length == 1 && codeset->side == XlcGR ? - BIT8ON(*csptr++) : BIT8OFF(*csptr++); - - if (codeset->length == 2) - jis_to_sjis((Uchar *)(bufptr-2), (Uchar *)(bufptr-1)); - } - } - - *from_left -= csptr - *from; - *from = (XPointer) csptr; - - if (bufptr) - *to += cvt_length; - *to_left -= cvt_length; - - - return 0; -} - -static int -sjis_cstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd) conv->state; - const char *csptr = (const char *) *from; - wchar_t *bufptr = (wchar_t *) *to; - wchar_t *toptr = (wchar_t *) *to; - int csstr_len = *from_left; - int buf_len = *to_left; - wchar_t wch; - int length; - Ulong wc_shift_bits = (int)XLC_GENERIC(lcd, wc_shift_bits); - CodeSet codeset; - - if (num_args < 1) - return -1; - - if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) - return -1; - - csstr_len /= codeset->length; - if (csstr_len < buf_len) - buf_len = csstr_len; - - *to_left -= buf_len; - - if (bufptr) { - - toptr += buf_len; - *to = (XPointer) toptr; - - while (buf_len--) { - wch = (wchar_t) BIT8OFF(*csptr); - csptr++; - - length = codeset->length - 1; - while (length--) { - wch = (wch << wc_shift_bits) | BIT8OFF(*csptr); - csptr++; - } - *bufptr++ = wch | codeset->wc_encoding; - } - } - - *from_left -= csptr - *from; - *from = (XPointer) csptr; - - return 0; -} - - -/* - * Stripped down Direct CT converters for SJIS - * - */ - -#define BADCHAR(min_ch, c) (BIT8OFF(c) < (char)min_ch && BIT8OFF(c) != 0x0 && \ - BIT8OFF(c) != '\t' && BIT8OFF(c) != '\n' && \ - BIT8OFF(c) != 0x1b) - -typedef struct _CTDataRec { - int side; - int length; - char *name; - Ulong wc_encoding; - char *ct_encoding; - int ct_encoding_len; - int set_size; - Uchar min_ch; - Uchar ct_type; -} CTDataRec, *CTData; - -typedef struct _StateRec { - CTData GL_charset; - CTData GR_charset; - CTData charset; -} StateRec, *State; - -#define CT_STD 0 -#define CT_NSTD 1 -#define CT_DIR 2 -#define CT_EXT0 3 -#define CT_EXT1 4 -#define CT_EXT2 5 -#define CT_VER 6 - -static CTDataRec ctdata[] = -{ - { XlcGL, 1, "ISO8859-1:GL", 0, "\033(B" , 3, 0, 0, CT_STD }, - { XlcGR, 1, "ISO8859-1:GR", 0, "\033-A" , 3, 0, 0, CT_STD }, - { XlcGL, 1, "JISX0201.1976-0:GL", 0, "\033(J" , 3, 0, 0, CT_STD }, - { XlcGR, 1, "JISX0201.1976-0:GR", 0, "\033)I" , 3, 0, 0, CT_STD }, - { XlcGL, 2, "JISX0208.1983-0:GL", 0, "\033$(B" , 4, 0, 0, CT_STD }, - { XlcGR, 2, "JISX0208.1983-0:GR", 0, "\033$)B" , 4, 0, 0, CT_STD }, - { XlcGL, 2, "JISX0212.1990-0:GL", 0, "\033$(D" , 4, 0, 0, CT_STD }, - { XlcGR, 2, "JISX0212.1990-0:GR", 0, "\033$)D" , 4, 0, 0, CT_STD }, - { XlcUnknown, 0, "Ignore-Ext-Status?", 0, "\033#" , 2, 0, 0, CT_VER }, - { XlcUnknown, 0, "NonStd-?-OctetChar", 0, "\033%/0" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 1, "NonStd-1-OctetChar", 0, "\033%/1" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 2, "NonStd-2-OctetChar", 0, "\033%/2" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 3, "NonStd-3-OctetChar", 0, "\033%/3" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 4, "NonStd-4-OctetChar", 0, "\033%/4" , 4, 0, 0, CT_NSTD }, - { XlcUnknown, 0, "Extension-2" , 0, "\033%/" , 3, 0, 0, CT_EXT2 }, - { XlcUnknown, 0, "Extension-0" , 0, "\033" , 1, 0, 0, CT_EXT0 }, - { XlcUnknown, 0, "Begin-L-to-R-Text", 0, "\2331]" , 3, 0, 0, CT_DIR }, - { XlcUnknown, 0, "Begin-R-to-L-Text", 0, "\2332]" , 3, 0, 0, CT_DIR }, - { XlcUnknown, 0, "End-Of-String", 0, "\233]" , 2, 0, 0, CT_DIR }, - { XlcUnknown, 0, "Extension-1" , 0, "\233" , 1, 0, 0, CT_EXT1 }, -}; - -/* Note on above table: sjis_ctstombs() and sjis_ctstowcs() parser depends on - * certain table entries occuring in decreasing string length-- - * 1. CT_EXT2 and CT_EXT0 entries must occur after CT_NSTD entries. - * 2. CT_DIR and CT_EXT1 entries must occur after CT_DIR entries. - */ - -static CTData ctdptr[sizeof(ctdata) / sizeof(CTDataRec)]; -static CTData ctd_endp = ctdata + ((sizeof(ctdata) / sizeof(CTDataRec))) - 1; - -#define Ascii 0 -#define Kanji 1 -#define Kana 2 -#define Userdef 3 - -/* - * initCTptr(): Set ctptr[] to point at ctdata[], indexed by codeset_num. - */ -static void -initCTptr( - XLCd lcd) -{ - int num_codesets = XLC_GENERIC(lcd, codeset_num); - int num_charsets; - int i, j; - CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - CodeSet codeset; - XlcCharSet charset; - CTData ctdp = ctdata; - - ctdptr[Ascii] = &ctdata[0]; /* failsafe */ - - for (i = 0; i < num_codesets; i++) { - - codeset = codesets[i]; - num_charsets = codeset->num_charsets; - - for (j = 0; j < num_charsets; j++) { - - charset = codeset->charset_list[j]; - - for (ctdp = ctdata; ctdp <= ctd_endp; ctdp++) - - if (! strcmp(ctdp->name, charset->name)) { - - ctdptr[codeset->cs_num] = ctdp; - - ctdptr[codeset->cs_num]->wc_encoding = codeset->wc_encoding; - - ctdptr[codeset->cs_num]->set_size = - charset->set_size; - - ctdptr[codeset->cs_num]->min_ch = - charset->set_size == 94 && - (ctdptr[codeset->cs_num]->length > 1 || - ctdptr[codeset->cs_num]->side == XlcGR) ? 0x21 : 0x20; - - break; - } - } - } -} - - -static int -sjis_mbstocts( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - int ct_len = *to_left; - int cs_num; - int clen; - int unconv_num = 0; - int num_conv; - const char *inbufptr = *from; - char *ctptr = *to; - XPointer ct_base = ctptr; - - StateRec ct_state; - CTData charset = NULL; - XLCd lcd = (XLCd) conv->state; - int codeset_num = XLC_GENERIC(lcd, codeset_num); - -/* Initial State: */ - - ct_state.GL_charset = ctdptr[Ascii]; - ct_state.GR_charset = NULL; - - if (*from_left > *to_left) - *from_left = *to_left; - - for (;*from_left > 0; (*from_left) -= charset->length) { - - if (iskanji(*inbufptr)) { - if (KANJI_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Kanji; - charset = ctdptr[Kanji]; - if (!VALID_MULTIBYTE((Uchar) *(inbufptr+1))) - unconv_num++; - } - else if (isuserdef(*inbufptr)) { - if (USERDEF_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Userdef; - charset = ctdptr[Userdef]; - if (!VALID_MULTIBYTE((Uchar) *(inbufptr+1))) - unconv_num++; - } - else if (isascii(*inbufptr)) { - if (ASCII_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Ascii; - charset = ctdptr[Ascii]; - } - else if (iskana(*inbufptr)) { - if (KANA_CODESET >= codeset_num) { - unconv_num++; - (*from_left)--; - continue; - } - cs_num = Kana; - charset = ctdptr[Kana]; - } - else { /* unknown */ - unconv_num++; - (*from_left)--; - continue; - } - - if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || - (charset->side == XlcGL && charset != ct_state.GL_charset) ) { - - ct_len -= ctdptr[cs_num]->ct_encoding_len; - if (ct_len < 0) { - unconv_num++; - break; - } - - if (ctptr) { - strcpy(ctptr, ctdptr[cs_num]->ct_encoding); - ctptr += ctdptr[cs_num]->ct_encoding_len; - } - } - - clen = charset->length; - do { - *ctptr++ = *inbufptr++; - } while (--clen); - - if (charset->length >= 2) { - sjis_to_jis((Uchar *)(ctptr-2), (Uchar *)(ctptr-1)); - if (BADCHAR(charset->min_ch, *(ctptr-2)) || - BADCHAR(charset->min_ch, *(ctptr-1))) { - unconv_num++; - continue; - } - } - else - if (BADCHAR(charset->min_ch, *(ctptr-1))) { - unconv_num++; - continue; - } - - if (charset->side == XlcGR) - ct_state.GR_charset = charset; - else if (charset->side == XlcGL) - ct_state.GL_charset = charset; - - if (charset->side == XlcGR) { - clen = charset->length; - do { - (*(Uchar *)(ctptr-clen)) = BIT8ON(*(Uchar *)(ctptr-clen)); - } while (--clen); - } - } - - *to = (XPointer)ctptr; - - if ((num_conv = (int)(ctptr - ct_base)) > 0) - (*to_left) -= num_conv; - - return unconv_num; - -} - - -#define byte1 (length == codeset->length - 1) -#define byte2 (byte1 == 0) - -static int -sjis_wcstocts( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - int ct_len = *to_left; - const wchar_t *inbufptr = (const wchar_t *) *from; - char *ctptr = *to; - XPointer ct_base = ctptr; - wchar_t wch; - int length; - Uchar tmp; - Uchar t1 = 0; - int num_conv; - - StateRec ct_state; - XLCd lcd = (XLCd)conv->state; - CTData charset; - CodeSet codeset; - int unconv_num = 0; - Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - -/* Initial State: */ - ct_state.GL_charset = ctdptr[0]; /* Codeset 0 */ - ct_state.GR_charset = NULL; - - if (*from_left > *to_left) - *from_left = *to_left; - - for (; *from_left > 0 ; (*from_left)-- ) { - - wch = *inbufptr++; - - if (!(codeset = wc_codeset(lcd, wch))) { - unconv_num++; - (*from_left)--; - continue; - } - - charset = ctdptr[codeset->cs_num]; - - length = codeset->length; - wch ^= (wchar_t)codeset->wc_encoding; - - if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || - (charset->side == XlcGL && charset != ct_state.GL_charset) ) { - - ct_len -= ctdptr[codeset->cs_num]->ct_encoding_len; - if (ct_len < 0) { - unconv_num++; - break; - } - - if (ctptr) { - strcpy(ctptr, ctdptr[codeset->cs_num]->ct_encoding); - ctptr += ctdptr[codeset->cs_num]->ct_encoding_len; - } - - } - - if (charset->side == XlcGR) - ct_state.GR_charset = charset; - else if (charset->side == XlcGL) - ct_state.GL_charset = charset; - - do { - length--; - tmp = wch>>(wchar_t)( (Ulong)length * wc_shift); - - if (kana) { - if (BADCHAR(charset->min_ch, (char)tmp)) { - unconv_num++; - break; - } - *ctptr++ = (char)BIT8ON(tmp); - } - - else if (byte1 && (kanji || userdef)) { - t1 = tmp; - } - - else if (byte2 && (kanji || userdef)) { - if (BADCHAR(charset->min_ch, (char)t1) || - BADCHAR(charset->min_ch, (char)tmp)) { - unconv_num++; - break; - } - - *ctptr++ = (char)BIT8OFF(t1); - *ctptr++ = (char)BIT8OFF(tmp); - } - - else { - if (BADCHAR(charset->min_ch, (char)tmp)) { - unconv_num++; - break; - } - *ctptr++ = (char)tmp; - } - } while (length); - - } /* end for */ - - *to = (XPointer)ctptr; - - if ((num_conv = (int)(ctptr - ct_base)) > 0) - (*to_left) -= num_conv; - - return unconv_num; -} -#undef byte1 -#undef byte2 - -#define SKIP_I(str) while (*(str) >= 0x20 && *(str) <= 0x2f) (str)++; -#define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; - -static int -sjis_ctstombs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - const char *inbufptr = *from; - XPointer outbufptr = *to; - const char *inbuf_base; - XPointer outbuf_base = outbufptr; - int clen, length; - int unconv_num = 0; - int num_conv; - unsigned int ct_seglen = 0; - Uchar ct_type; - CTData ctdp = ctdata; /* default */ - CTData GL_ctdp = ctdp; /* GL ctdp save */ - CTData GR_ctdp = ctdp; /* GR ctdp save */ - - if (*from_left > *to_left) - *from_left = *to_left; - - for (length = ctdata[Ascii].length; *from_left > 0 ; (*from_left) -= length) - { - ct_type = CT_STD; - /* change GL/GR charset */ - if(ctdp->side == XlcGR && isleftside(*inbufptr)){ - /* select GL side */ - ctdp = GL_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - }else if(ctdp->side == XlcGL && isrightside(*inbufptr)){ - /* select GR side */ - ctdp = GR_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - } - if (*inbufptr == '\033' || *inbufptr == (char)'\233') { - - for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { - - if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) - { - inbufptr += ctdp->ct_encoding_len; - (*from_left) -= ctdp->ct_encoding_len; - if( ctdp->length ) { - length = ctdp->length; - if( *from_left < length ) { - *to = (XPointer)outbufptr; - *to_left -= outbufptr - outbuf_base; - return( unconv_num + *from_left ); - } - } - ct_type = ctdp->ct_type; - if(ctdp->side == XlcGL){ - GL_ctdp = ctdp; /* save GL ctdp */ - }else{ - GR_ctdp = ctdp; /* save GR ctdp */ - } - break; - } - } - if (ctdp > ctd_endp) /* failed to match CT sequence */ - unconv_num++; - } - -/* The following code insures that non-standard encodings, direction, extension, - * and version strings are ignored; subject to change in future. - */ - switch (ct_type) { - case CT_STD: - break; - case CT_EXT2: - inbufptr++; - (*from_left)--; - case CT_NSTD: - ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; - inbufptr += ct_seglen; - (*from_left) -= ct_seglen; - continue; - case CT_EXT0: - inbuf_base = inbufptr; - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - (*from_left) -= ct_seglen; - continue; - case CT_EXT1: - inbuf_base = inbufptr; - SKIP_P(inbufptr); - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - (*from_left) -= ct_seglen; - continue; - case CT_DIR: - continue; - case CT_VER: - inbufptr += 2; - (*from_left) -= 2; - continue; - } - - if (ctdp->side == XlcGL || isrightside (*inbufptr)) { - clen = length; - } else { - clen = 1; - *from_left += length - clen; - } - do { - Uchar mask = (length == 2) ? GL : -1; - *outbufptr++ = *inbufptr++ & mask; - } while (--clen); - - if (length >= 2) - jis_to_sjis((Uchar *)(outbufptr-2), (Uchar *)(outbufptr-1)); - } - - *to = (XPointer)outbufptr; - - if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) - (*to_left) -= num_conv; - - return unconv_num; -} - - -static int -sjis_ctstowcs( - XlcConv conv, - XPointer *from, - int *from_left, - XPointer *to, - int *to_left, - XPointer *args, - int num_args) -{ - XLCd lcd = (XLCd)conv->state; - Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); - const char *inbufptr = *from; - const char *inbuf_base; - wchar_t *outbufptr = (wchar_t *) *to; - wchar_t *outbuf_base = outbufptr; - int clen, length; - int num_conv; - int unconv_num = 0; - unsigned int ct_seglen = 0; - Uchar ct_type = 0; - int shift_mult; - wchar_t wc_tmp; - wchar_t wch; - Ulong wc_encoding; - CTData ctdp = ctdata; - CTData GL_ctdp = ctdp; /* GL ctdp save */ - CTData GR_ctdp = ctdp; /* GR ctdp save */ - - if (*from_left > *to_left) - *from_left = *to_left; - - for (length = ctdata[Ascii].length; *from_left > 0; (*from_left) -= length ) - { - ct_type = CT_STD; - /* change GL/GR charset */ - if(ctdp->side == XlcGR && isleftside(*inbufptr)){ - /* select GL side */ - ctdp = GL_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - }else if(ctdp->side == XlcGL && isrightside(*inbufptr)){ - /* select GR side */ - ctdp = GR_ctdp; - length = ctdp->length; - ct_type = ctdp->ct_type; - } - if (*inbufptr == '\033' || *inbufptr == (char)'\233') { - for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { - - if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) - { - inbufptr += ctdp->ct_encoding_len; - (*from_left) -= ctdp->ct_encoding_len; - if( ctdp->length ) { - length = ctdp->length; - if( *from_left < length ) { - *to = (XPointer)outbufptr; - *to_left -= outbufptr - outbuf_base; - return( unconv_num + *from_left ); - } - } - ct_type = ctdp->ct_type; - if(ctdp->side == XlcGL){ - GL_ctdp = ctdp; /* save GL ctdp */ - }else{ - GR_ctdp = ctdp; /* save GR ctdp */ - } - break; - } - } - if (ctdp > ctd_endp) /* failed to match CT sequence */ - unconv_num++; - } - -/* The following block of code insures that non-standard encodings, direction, - * extension, and version strings are ignored; subject to change in future. - */ - switch (ct_type) { - case CT_STD: - break; - case CT_EXT2: - inbufptr++; - (*from_left)--; - case CT_NSTD: - ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; - inbufptr += ct_seglen; - (*from_left) -= ct_seglen; - continue; - case CT_EXT0: - inbuf_base = inbufptr; - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - (*from_left) -= ct_seglen; - continue; - case CT_EXT1: - inbuf_base = inbufptr; - SKIP_P(inbufptr); - SKIP_I(inbufptr); - inbufptr++; - ct_seglen = (unsigned)(inbufptr - inbuf_base); - (*from_left) -= ct_seglen; - continue; - case CT_DIR: - continue; - case CT_VER: - inbufptr += 2; - (*from_left) -= 2; - continue; - } -#if !defined(__sony_news) || defined(SVR4) - if (ctdp->side == XlcGL || isrightside (*inbufptr)) { - clen = length; - wc_encoding = ctdp->wc_encoding; - } else { - clen = 1; - *from_left += length - clen; - wc_encoding = ctdptr[Ascii]->wc_encoding; - } - shift_mult = clen - 1; - wch = (wchar_t)0; - - do { - wc_tmp = BIT8OFF(*inbufptr++) << (wc_shift_bits * shift_mult); - wch |= wc_tmp; - shift_mult--; - } while (--clen); - *outbufptr++ = wch | wc_encoding; -#else - if( length == 1 ) - *outbufptr++ = (unsigned char)*inbufptr++; - else if( length == 2 ) { - unsigned short code; - code = (*inbufptr << 8) | *(inbufptr+1); - *outbufptr++ = jis2sjis( code ); - inbufptr += 2; - } -#endif - } - *to = (XPointer)outbufptr; - - if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) - (*to_left) -= num_conv ; - - return unconv_num; - -} -#undef BADCHAR - -static void -close_converter( - XlcConv conv) -{ - Xfree(conv); -} - - -static XlcConv -create_conv( - XLCd lcd, - XlcConvMethods methods) -{ - XlcConv conv; - - conv = Xmalloc(sizeof(XlcConvRec)); - if (conv == NULL) - return (XlcConv) NULL; - - conv->methods = methods; - conv->state = (XPointer) lcd; - return conv; -} - - -enum { MBSTOCS, WCSTOCS, MBTOCS, CSTOMBS, CSTOWCS, MBSTOWCS, WCSTOMBS, - WCSTOCTS, MBSTOCTS, CTSTOMBS, CTSTOWCS }; - -static XlcConvMethodsRec conv_methods[] = { - {close_converter, sjis_mbstocs, NULL }, - {close_converter, sjis_wcstocs, NULL }, - {close_converter, sjis_mbtocs, NULL }, - {close_converter, sjis_cstombs, NULL }, - {close_converter, sjis_cstowcs, NULL }, - {close_converter, sjis_mbstowcs, NULL }, - {close_converter, sjis_wcstombs, NULL }, - {close_converter, sjis_wcstocts, NULL }, - {close_converter, sjis_mbstocts, NULL }, - {close_converter, sjis_ctstombs, NULL }, - {close_converter, sjis_ctstowcs, NULL }, -}; - - -static XlcConv -open_mbstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBSTOCS]); -} - -static XlcConv -open_wcstocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[WCSTOCS]); -} - -static XlcConv -open_mbtocs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBTOCS]); -} - -static XlcConv -open_cstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CSTOMBS]); -} - -static XlcConv -open_cstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CSTOWCS]); -} - -static XlcConv -open_mbstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBSTOWCS]); -} - -static XlcConv -open_wcstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[WCSTOMBS]); -} - -static XlcConv -open_wcstocts( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[WCSTOCTS]); -} - -static XlcConv -open_mbstocts( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[MBSTOCTS]); -} - -static XlcConv -open_ctstombs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CTSTOMBS]); -} - -static XlcConv -open_ctstowcs( - XLCd from_lcd, - const char *from_type, - XLCd to_lcd, - const char *to_type) -{ - return create_conv(from_lcd, &conv_methods[CTSTOWCS]); -} - -XLCd -_XlcSjisLoader( - const char *name) -{ - XLCd lcd; - - lcd = _XlcCreateLC(name, _XlcGenericMethods); - if (lcd == NULL) - return lcd; - - if (!XLC_PUBLIC_PART(lcd)->codeset || - (_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "SJIS"))) { - _XlcDestroyLC(lcd); - return (XLCd) NULL; - } - - initCTptr(lcd); - - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs); - _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); - -#ifndef FORCE_INDIRECT_CONVERTER - _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs); - _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts); - _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs); - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts); - _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); -#endif - - _XlcAddUtf8Converters(lcd); - - return lcd; -} - -#else -typedef int dummy; -#endif /* X_LOCALE */ diff --git a/nx-X11/lib/X11/xlibi18n/lc/Imakefile b/nx-X11/lib/X11/xlibi18n/lc/Imakefile index a4eaeeb6f..16f7aceb3 100644 --- a/nx-X11/lib/X11/xlibi18n/lc/Imakefile +++ b/nx-X11/lib/X11/xlibi18n/lc/Imakefile @@ -2,7 +2,7 @@ XCOMM $XConsortium: Imakefile,v 1.27 94/04/07 15:01:48 rws Exp $ #define IHaveSubdirs #define PassCDebugFlags CDEBUGFLAGS="$(CDEBUGFLAGS)" -SUBDIRS = gen def Utf8 xlocale +SUBDIRS = gen def Utf8 MakeSubdirs($(SUBDIRS)) DependSubdirs($(SUBDIRS)) diff --git a/nx-X11/lib/X11/xlibi18n/lc/xlocale/Imakefile b/nx-X11/lib/X11/xlibi18n/lc/xlocale/Imakefile deleted file mode 100644 index 5ead4b763..000000000 --- a/nx-X11/lib/X11/xlibi18n/lc/xlocale/Imakefile +++ /dev/null @@ -1,14 +0,0 @@ - -#include "../../Xi18nLib.conf" - - EXTRA_INCLUDES = -I../../.. - XI18NLIBNAME = xlocale - SRCS = lcEuc.c lcSjis.c lcJis.c - OBJS = ${SRCS:.c=.o} - REQUIREDLIBS = SharedXlibi18nReqs - -LinkSourceFile(lcEuc.c, ../../..) -LinkSourceFile(lcSjis.c, ../../..) -LinkSourceFile(lcJis.c, ../../..) - -Xi18nLibraryTarget(xlocale) -- cgit v1.2.3 From f45ac4ae31017c15ce8634be387be53b5ab8ebf3 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 2 Dec 2013 21:51:27 -0800 Subject: unifdef -UISC Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlib.h | 17 ----------------- nx-X11/lib/X11/lcStd.c | 10 ---------- 2 files changed, 27 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlib.h b/nx-X11/lib/X11/Xlib.h index 9ef4e00b0..5f2368800 100644 --- a/nx-X11/lib/X11/Xlib.h +++ b/nx-X11/lib/X11/Xlib.h @@ -59,23 +59,11 @@ typedef unsigned long wchar_t; #endif #endif -#if defined(ISC) && defined(USE_XMBTOWC) -#define wctomb(a,b) _Xwctomb(a,b) -#define mblen(a,b) _Xmblen(a,b) -#ifndef USE_XWCHAR_STRING -#define mbtowc(a,b,c) _Xmbtowc(a,b,c) -#endif -#endif extern int _Xmblen( -#ifdef ISC - char const *str, - size_t len -#else char *str, int len -#endif ); /* API mentioning "UTF8" or "utf8" is an XFree86 extension, introduced in @@ -4021,13 +4009,8 @@ extern void XSetAuthorization( extern int _Xmbtowc( wchar_t * /* wstr */, -#ifdef ISC - char const * /* str */, - size_t /* len */ -#else char * /* str */, int /* len */ -#endif ); extern int _Xwctomb( diff --git a/nx-X11/lib/X11/lcStd.c b/nx-X11/lib/X11/lcStd.c index 87f6b60b3..9d452bcae 100644 --- a/nx-X11/lib/X11/lcStd.c +++ b/nx-X11/lib/X11/lcStd.c @@ -199,13 +199,8 @@ _Xlcwcstombs( int _Xmbtowc( wchar_t *wstr, -#ifdef ISC - char const *str, - size_t len -#else char *str, int len -#endif ) { return _Xlcmbtowc((XLCd) NULL, wstr, str, len); @@ -213,13 +208,8 @@ _Xmbtowc( int _Xmblen( -#ifdef ISC - char const *str, - size_t len -#else char *str, int len -#endif ) { return _Xmbtowc((wchar_t *) NULL, str, len); -- cgit v1.2.3 From 4fad46e9cbc7f6a29a113bf064cf210743544caf Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Thu, 7 Oct 2010 18:46:08 +0100 Subject: Don't try so hard to find a matching font with the given encoding See http://sourceware.org/bugzilla/show_bug.cgi?id=10948 Currently, if the locale is UTF-8, no CJK fonts are installed, and someone does XCreateFontSet() with a font name of "*", we end up asking the server to list the (non-existent) fonts 11 times for each CJK encoding, which can take a while. A * wildcard can match multiple components in a XLFD name in XListFonts(), so there's no need to try adding more than one to get a match. We do try once with a leading '*-' in case the fontname isn't a full well-formed XLFD name, maybe even that isn't needed? (See also http://invisible-island.net/xterm/xterm.faq.html#slow_menus) Signed-off-by: Jon TURNEY Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 24d5a902e..89d1b2ffd 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -833,7 +833,7 @@ parse_omit_name( return True; /* This may mot be needed anymore as XListFonts() takes care of this */ - while (num_fields < 12) { + if (num_fields < 12) { if ((last - buf) > (XLFD_MAX_LEN - 2)) return -1; *last = '*'; -- cgit v1.2.3 From 1b0df5da6d70f306db248907bdf65fe2e3ba4005 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 26 Dec 2013 09:22:49 -0800 Subject: XkbSelectEventDetails: remove unnecessary assignments clear & selectAll are set to 0 already a few lines earlier, affectWhich is set to XkbMapNotifyMask a few lines later. None are used between the other assignments and the removed ones. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKB.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKB.c b/nx-X11/lib/X11/XKB.c index cd0a448ad..7f1b233aa 100644 --- a/nx-X11/lib/X11/XKB.c +++ b/nx-X11/lib/X11/XKB.c @@ -169,9 +169,6 @@ XkbSelectEventDetails(Display *dpy, /* 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; -- cgit v1.2.3 From 101419b10ea0fcaf9b3e48d733a510f27f827919 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 26 Dec 2013 09:26:13 -0800 Subject: _XkbReadGeomOverlay: check for NULL first, then use pointer Flagged by cppcheck 1.62: [lib/libX11/nx-X11/lib/X11/XKBGeom.c:479] -> [lib/libX11/nx-X11/lib/X11/XKBGeom.c:480]: (warning) Possible null pointer dereference: row - otherwise it is redundant to check it against null. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGeom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGeom.c b/nx-X11/lib/X11/XKBGeom.c index 1014c9adb..0145da8c1 100644 --- a/nx-X11/lib/X11/XKBGeom.c +++ b/nx-X11/lib/X11/XKBGeom.c @@ -476,9 +476,9 @@ _XkbReadGeomOverlay(XkbReadBufferPtr buf, if (rowWire == NULL) return BadLength; row = XkbAddGeomOverlayRow(ol, rowWire->rowUnder, rowWire->nKeys); - row->row_under = rowWire->rowUnder; if (!row) return BadAlloc; + row->row_under = rowWire->rowUnder; if (rowWire->nKeys < 1) continue; keyWire = (xkbOverlayKeyWireDesc *) -- cgit v1.2.3 From 3e8df1a2e7f07907b4ce4524a4e79100d762ce70 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 6 Feb 2014 13:48:08 -0800 Subject: Fix typos in Xrm.c comments Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xrm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xrm.c b/nx-X11/lib/X11/Xrm.c index 4cba0d5a3..3b90346d8 100644 --- a/nx-X11/lib/X11/Xrm.c +++ b/nx-X11/lib/X11/Xrm.c @@ -349,7 +349,7 @@ void XrmSetDatabase( XrmDatabase database) { LockDisplay(display); - /* destroy database if set up imlicitely by XGetDefault() */ + /* destroy database if set up implicitly by XGetDefault() */ if (display->db && (display->flags & XlibDisplayDfltRMDB)) { XrmDestroyDatabase(display->db); display->flags &= ~XlibDisplayDfltRMDB; @@ -508,7 +508,7 @@ static XrmDatabase NewDatabase(void) } /* move all values from ftable to ttable, and free ftable's buckets. - * ttable is quaranteed empty to start with. + * ttable is guaranteed empty to start with. */ static void MoveValues( LTable ftable, -- cgit v1.2.3 From 88d496598fbf36724c1a825875a4becdfc29d600 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 11 Feb 2014 13:26:16 +0200 Subject: Remove dead USE_OWN_COMPOSE-protected code The build doesn't provide any way to define this option. It also refers to files (imComp.h) and functions (e.g. XimCompInitTables(), XimCompProcessSym()) which are not found anywhere, and the ordinary Compose implementation in xim doesn't use any of it. Signed-off-by: Ran Benita Reviewed-by: Julien Cristau Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/KeyBind.c | 72 --------------------------------- nx-X11/lib/X11/XKBBind.c | 102 ----------------------------------------------- 2 files changed, 174 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index 01f015c65..deb200786 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/KeyBind.c @@ -48,11 +48,6 @@ in this Software without prior written authorization from The Open Group. #include #include -#ifdef USE_OWN_COMPOSE -#include "imComp.h" - -#endif - #include "Xresource.h" #include "Key.h" @@ -891,73 +886,6 @@ XLookupString ( &modifiers, &symbol)) return 0; -#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(symbol,event->keycode,status) ) { - XimCompRtrn rtrn; - switch (XimCompProcessSym(status,symbol,&rtrn)) { - case XIM_COMP_IGNORE: - break; - case XIM_COMP_IN_PROGRESS: - if ( keysym!=NULL ) - *keysym = NoSymbol; - return 0; - case XIM_COMP_FAIL: - { - int n = 0, len= 0; - for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) { - if ( nbytes-len > 0 ) { - len+= _XTranslateKeySym(event->display,rtrn.sym[n], - event->state, - buffer+len,nbytes-len); - } - } - if ( keysym!=NULL ) { - if ( n==1 ) *keysym = rtrn.sym[0]; - else *keysym = NoSymbol; - } - return len; - } - case XIM_COMP_SUCCEED: - { - int len,n = 0; - - symbol = rtrn.matchSym; - if ( keysym!=NULL ) *keysym = symbol; - if ( rtrn.str[0]!='\0' ) { - strncpy(buffer,rtrn.str,nbytes-1); - buffer[nbytes-1]= '\0'; - len = strlen(buffer); - } - else { - len = _XTranslateKeySym(event->display,symbol, - event->state, - buffer,nbytes); - } - for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) { - if ( nbytes-len > 0 ) { - len+= _XTranslateKeySym(event->display,rtrn.sym[n], - event->state, - buffer+len,nbytes-len); - } - } - return len; - } - } - } - } -#endif - if (keysym) *keysym = symbol; /* arguable whether to use (event->state & ~modifiers) here */ diff --git a/nx-X11/lib/X11/XKBBind.c b/nx-X11/lib/X11/XKBBind.c index 37f1b8ad6..c679dc552 100644 --- a/nx-X11/lib/X11/XKBBind.c +++ b/nx-X11/lib/X11/XKBBind.c @@ -41,11 +41,6 @@ from The Open Group. #include #include "XKBlibint.h" -#ifdef USE_OWN_COMPOSE -#define COMPOSE_NO_CONST_MEMBERS -#include "imComp.h" -#endif - #define AllMods (ShiftMask|LockMask|ControlMask| \ Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask) @@ -725,103 +720,6 @@ 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; -#ifndef NO_COMPOSE_LED - 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; - -#ifndef NO_COMPOSE_LED - 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); - } -#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; - -#ifndef NO_COMPOSE_LED - 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; - } - } - } - } -#endif - /* We *should* use the new_mods (which does not contain any modifiers */ /* that were used to compute the symbol here, but pre-XKB XLookupString */ /* did not and we have to remain compatible. Sigh. */ -- cgit v1.2.3 From afc7138f952ff28a27a43452d6ea8e1ae82ae8cd Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Fri, 9 May 2014 18:21:05 -0400 Subject: Fix XNextRequest() after direct usage of XCB When XCB owns the X socket, dpy->request is not updated, so NextRequest() and XNextRequest() return the wrong value. There's nothing we can do to fix NextRequest() while retaining ABI compat, but change XNextRequest() to grab the socket back from XCB, updating dpy->request. Signed-off-by: Owen W. Taylor Reviewed-by: Uli Schlachter Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller : Added #ifdefs to be aware of changes regarding XCB in case we later switch to XCB. --- nx-X11/lib/X11/Macros.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Macros.c b/nx-X11/lib/X11/Macros.c index cfc083a01..d5a3a0485 100644 --- a/nx-X11/lib/X11/Macros.c +++ b/nx-X11/lib/X11/Macros.c @@ -30,6 +30,9 @@ in this Software without prior written authorization from The Open Group. #include "Xlibint.h" #define XUTIL_DEFINE_FUNCTIONS #include "Xutil.h" +#if USE_XCB +#include "Xxcbint.h" +#endif /* * This file makes full definitions of routines for each macro. @@ -135,10 +138,28 @@ int XBitmapPad(Display *dpy) { return (BitmapPad(dpy)); } int XImageByteOrder(Display *dpy) { return (ImageByteOrder(dpy)); } +#if !USE_XCB unsigned long XNextRequest(Display *dpy) { return (NextRequest(dpy)); } +#else +/* XNextRequest() differs from the rest of the functions here because it is + * no longer a macro wrapper - when libX11 is being used mixed together + * with direct use of xcb, the next request field of the Display structure will + * not be updated. We can't fix the NextRequest() macro in any easy way, + * but we can at least make XNextRequest() do the right thing. + */ +unsigned long XNextRequest(Display *dpy) +{ + unsigned long next_request; + LockDisplay(dpy); + next_request = _XNextRequest(dpy); + UnlockDisplay(dpy); + + return next_request; +} +#endif unsigned long XLastKnownRequestProcessed(Display *dpy) { -- cgit v1.2.3 From e7528f5816a3196c9869c6028f012ae0a6b3d650 Mon Sep 17 00:00:00 2001 From: walter harms Date: Wed, 4 Jun 2014 17:08:12 +0200 Subject: libX11/lcGenConv.c fix: dereferenced before check * Do not use variables before checked for NULL. Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcGenConv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index 1f7c301f5..c816c25d4 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -753,7 +753,7 @@ mbstowcs_org( CodeSet codeset = NULL; - const char *inbufptr = *from; + const char *inbufptr; wchar_t *outbufptr = (wchar_t *) *to; int from_size = *from_left; @@ -764,6 +764,8 @@ mbstowcs_org( return( 0 ); } + inbufptr = *from; + while (*from_left && *to_left) { ch = *inbufptr++; @@ -1252,7 +1254,7 @@ ctstowcs( CodeSet codeset = NULL; XlcCharSet charset_tmp; - const char *inbufptr = *from; + const char *inbufptr; wchar_t *outbufptr = (wchar_t *) *to; int from_size = *from_left; @@ -1262,6 +1264,7 @@ ctstowcs( _XlcResetConverter(conv); return( 0 ); } + inbufptr = *from; while (*from_left && *to_left) { @@ -1437,7 +1440,7 @@ cstowcs( CodeSet codeset = NULL; XlcCharSet charset, charset_tmp; - const char *inbufptr = *from; + const char *inbufptr; wchar_t *outbufptr = (wchar_t *) *to; int from_size = *from_left; @@ -1445,6 +1448,8 @@ cstowcs( return( 0 ); } + inbufptr = *from; + charset = (XlcCharSet) args[0]; while (*from_left && *to_left) { @@ -1643,7 +1648,7 @@ mbstostr( CodeSet codeset = NULL; - const char *inbufptr = *from; + const char *inbufptr; char *outbufptr = *to; int from_size = *from_left; @@ -1654,6 +1659,8 @@ mbstostr( return( 0 ); } + inbufptr = *from; + while (*from_left && *to_left) { ch = *inbufptr++; @@ -1758,7 +1765,7 @@ mbtocs( CodeSet codeset = NULL; XlcCharSet charset = NULL; - const char *inbufptr = *from; + const char *inbufptr; char *outbufptr = *to; int from_size = *from_left; @@ -1769,6 +1776,8 @@ mbtocs( return( 0 ); } + inbufptr = *from; + while (*from_left && *to_left) { ch = *inbufptr++; -- cgit v1.2.3 From 861fe5aee1519244e4af04007076dbd814ed2b0b Mon Sep 17 00:00:00 2001 From: walter harms Date: Wed, 4 Jun 2014 17:10:20 +0200 Subject: libX11/XKBNames.c fix: dereferenced before check * Do not use variables before checked for NULL. Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBNames.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index 3cfd02f96..f5a6ed1fa 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/XKBNames.c @@ -778,9 +778,14 @@ XkbNoteNameChanges(XkbNameChangesPtr old, { int first, last, old_last, new_last; - wanted &= new->changed; - if ((old == NULL) || (new == NULL) || (wanted == 0)) + if ((old == NULL) || (new == NULL)) return; + + wanted &= new->changed; + + if (wanted == 0) + return; + if (wanted & XkbKeyTypeNamesMask) { if (old->changed & XkbKeyTypeNamesMask) { new_last = (new->first_type + new->num_types - 1); -- cgit v1.2.3 From 191d1575f42affc0d86170132bef5a1535f7bdfa Mon Sep 17 00:00:00 2001 From: walter harms Date: Wed, 4 Jun 2014 17:12:31 +0200 Subject: libX11/lcUTF8.c fix: dereferenced before check * Do not use variables before checked for NULL. Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcUTF8.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcUTF8.c b/nx-X11/lib/X11/lcUTF8.c index 0f3d0d2ca..38201573e 100644 --- a/nx-X11/lib/X11/lcUTF8.c +++ b/nx-X11/lib/X11/lcUTF8.c @@ -1015,7 +1015,7 @@ ucstocs1( XPointer *args, int num_args) { - ucs4_t const *src = (ucs4_t const *) *from; + ucs4_t const *src; unsigned char *dst = (unsigned char *) *to; int unconv_num = 0; Utf8Conv *preferred_charsets = (Utf8Conv *) conv->state; @@ -1027,6 +1027,8 @@ ucstocs1( if (from == NULL || *from == NULL) return 0; + src = (ucs4_t const *) *from; + count = charset_wctocs_exactly(preferred_charsets, &chosen_charset, &chosen_side, conv, dst, *src, *to_left); if (count < 1) { -- cgit v1.2.3 From fc26b97ea9053a2aba54824243282e27bc4a1e15 Mon Sep 17 00:00:00 2001 From: walter harms Date: Thu, 5 Jun 2014 18:37:40 +0200 Subject: Remove redundant null checks before free This patch removes some redundant null checks before free. It should not change the code otherwise. Be aware that this is only the first series. Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FetchName.c | 4 ++-- nx-X11/lib/X11/Font.c | 22 +++++++++++----------- nx-X11/lib/X11/FontInfo.c | 4 ++-- nx-X11/lib/X11/FontNames.c | 4 ++-- nx-X11/lib/X11/GetFPath.c | 4 ++-- nx-X11/lib/X11/GetHints.c | 16 ++++++++-------- nx-X11/lib/X11/GetNrmHint.c | 2 +- nx-X11/lib/X11/GetRGBCMap.c | 8 ++++---- nx-X11/lib/X11/GetStCmap.c | 2 +- nx-X11/lib/X11/GetWMCMapW.c | 2 +- nx-X11/lib/X11/ImUtil.c | 4 ++-- nx-X11/lib/X11/InitExt.c | 2 +- nx-X11/lib/X11/KeyBind.c | 9 +++++---- nx-X11/lib/X11/ListExt.c | 4 ++-- nx-X11/lib/X11/ModMap.c | 5 ++--- nx-X11/lib/X11/OpenDis.c | 35 +++++++++++++---------------------- nx-X11/lib/X11/PutImage.c | 11 ++++------- nx-X11/lib/X11/RdBitF.c | 2 +- nx-X11/lib/X11/ScrResStr.c | 3 +-- nx-X11/lib/X11/StBytes.c | 2 +- nx-X11/lib/X11/XlibInt.c | 14 +++++++------- 21 files changed, 73 insertions(+), 86 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FetchName.c b/nx-X11/lib/X11/FetchName.c index 060c4b183..52c65c52c 100644 --- a/nx-X11/lib/X11/FetchName.c +++ b/nx-X11/lib/X11/FetchName.c @@ -58,7 +58,7 @@ Status XFetchName ( *name = (char *)data; return(1); } - if (data) Xfree (data); + Xfree (data); *name = NULL; return(0); } @@ -89,7 +89,7 @@ Status XGetIconName ( *icon_name = (char*)data; return(1); } - if (data) Xfree (data); + Xfree (data); *icon_name = NULL; return(0); } diff --git a/nx-X11/lib/X11/Font.c b/nx-X11/lib/X11/Font.c index 041ac58e7..6bbab3f19 100644 --- a/nx-X11/lib/X11/Font.c +++ b/nx-X11/lib/X11/Font.c @@ -170,8 +170,8 @@ XFreeFont( #endif } _XFreeExtData(fs->ext_data); - if (fs->properties) - Xfree (fs->properties); + + Xfree (fs->properties); Xfree (fs); return 1; } @@ -271,7 +271,7 @@ _XQueryFont ( } } if (! fs->per_char) { - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; @@ -524,14 +524,14 @@ _XF86BigfontQueryFont ( + (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16); pUniqCI = Xmalloc (nbytes); if (!pUniqCI) { - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; } if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) { Xfree(pUniqCI); - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); return (XFontStruct *)NULL; @@ -542,7 +542,7 @@ _XF86BigfontQueryFont ( if (pIndex2UniqIndex[i] >= reply.nUniqCharInfos) { fprintf(stderr, "_XF86BigfontQueryFont: server returned wrong data\n"); Xfree(pUniqCI); - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); return (XFontStruct *)NULL; } @@ -558,7 +558,7 @@ _XF86BigfontQueryFont ( pData = Xmalloc(sizeof(XExtData)); if (!pData) { - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); return (XFontStruct *)NULL; } @@ -578,7 +578,7 @@ _XF86BigfontQueryFont ( if (extcodes->serverCapabilities & CAP_VerifiedLocal) fprintf(stderr, "_XF86BigfontQueryFont: could not attach shm segment\n"); Xfree(pData); - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; @@ -593,7 +593,7 @@ _XF86BigfontQueryFont ( && *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) { shmdt(addr); Xfree(pData); - if (fs->properties) Xfree(fs->properties); + Xfree(fs->properties); Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; @@ -697,8 +697,8 @@ int _XF86LoadQueryLocaleFont( #endif } _XFreeExtData(fs->ext_data); - if (fs->properties) - Xfree (fs->properties); + + Xfree (fs->properties); *fidp = fs->fid; Xfree (fs); } else { diff --git a/nx-X11/lib/X11/FontInfo.c b/nx-X11/lib/X11/FontInfo.c index 763aafb3d..a2d12c2ec 100644 --- a/nx-X11/lib/X11/FontInfo.c +++ b/nx-X11/lib/X11/FontInfo.c @@ -179,8 +179,8 @@ XFontStruct **info) /* RETURN */ Xfree(flist[j]); if (finfo[j].properties) Xfree(finfo[j].properties); } - if (flist) Xfree(flist); - if (finfo) Xfree(finfo); + Xfree(flist); + Xfree(finfo); clearwire: /* Clear the wire. */ diff --git a/nx-X11/lib/X11/FontNames.c b/nx-X11/lib/X11/FontNames.c index c50de2eeb..6fc6b1272 100644 --- a/nx-X11/lib/X11/FontNames.c +++ b/nx-X11/lib/X11/FontNames.c @@ -73,8 +73,8 @@ int *actualCount) /* RETURN */ } if ((! flist) || (! ch)) { - if (flist) Xfree(flist); - if (ch) Xfree(ch); + Xfree(flist); + Xfree(ch); _XEatDataWords(dpy, rep.length); *actualCount = 0; UnlockDisplay(dpy); diff --git a/nx-X11/lib/X11/GetFPath.c b/nx-X11/lib/X11/GetFPath.c index 76ff7327b..62ba01436 100644 --- a/nx-X11/lib/X11/GetFPath.c +++ b/nx-X11/lib/X11/GetFPath.c @@ -57,8 +57,8 @@ char **XGetFontPath( } if ((! flist) || (! ch)) { - if (flist) Xfree(flist); - if (ch) Xfree(ch); + Xfree(flist); + Xfree(ch); _XEatDataWords(dpy, rep.length); UnlockDisplay(dpy); SyncHandle(); diff --git a/nx-X11/lib/X11/GetHints.c b/nx-X11/lib/X11/GetHints.c index 589ee9ae2..fae61e912 100644 --- a/nx-X11/lib/X11/GetHints.c +++ b/nx-X11/lib/X11/GetHints.c @@ -75,7 +75,7 @@ Status XGetSizeHints ( if ((actual_type != XA_WM_SIZE_HINTS) || (nitems < OldNumPropSizeElements) || (actual_format != 32)) { - if (prop != NULL) Xfree (prop); + Xfree (prop); return(0); } hints->flags = (prop->flags & (USPosition|USSize|PAllHints)); @@ -124,7 +124,7 @@ XWMHints *XGetWMHints ( if ((actual_type != XA_WM_HINTS) || (nitems < (NumPropWMHintsElements - 1)) || (actual_format != 32)) { - if (prop != NULL) Xfree (prop); + Xfree (prop); return(NULL); } /* static copies not allowed in library, due to reentrancy constraint*/ @@ -196,7 +196,7 @@ Status XGetIconSizes ( (nitems < NumPropIconSizeElements) || (nitems % NumPropIconSizeElements != 0) || (actual_format != 32)) { - if (prop != NULL) Xfree (prop); + Xfree (prop); return(0); } @@ -204,7 +204,7 @@ Status XGetIconSizes ( nitems /= NumPropIconSizeElements; if (! (hp = hints = Xcalloc (nitems, sizeof(XIconSize)))) { - if (prop) Xfree (prop); + Xfree (prop); return 0; } @@ -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 (tp.value); + Xfree (tp.value); return 0; } @@ -254,7 +254,7 @@ Status XGetCommand ( * create a string list and return if successful */ if (!XTextPropertyToStringList (&tp, &argv, &argc)) { - if (tp.value) Xfree (tp.value); + Xfree (tp.value); return (0); } @@ -291,7 +291,7 @@ XGetTransientForHint( return (1); } *propWindow = None; - if (data) Xfree( (char *) data); + Xfree( (char *) data); return(0); } @@ -333,6 +333,6 @@ XGetClassHint( Xfree( (char *) data); return(1); } - if (data) Xfree( (char *) data); + Xfree( (char *) data); return(0); } diff --git a/nx-X11/lib/X11/GetNrmHint.c b/nx-X11/lib/X11/GetNrmHint.c index 7871d99de..cc8fd235e 100644 --- a/nx-X11/lib/X11/GetNrmHint.c +++ b/nx-X11/lib/X11/GetNrmHint.c @@ -83,7 +83,7 @@ Status XGetWMSizeHints ( if ((actual_type != XA_WM_SIZE_HINTS) || (nitems < OldNumPropSizeElements) || (actual_format != 32)) { - if (prop != NULL) Xfree (prop); + Xfree (prop); return False; } diff --git a/nx-X11/lib/X11/GetRGBCMap.c b/nx-X11/lib/X11/GetRGBCMap.c index 08dc1deaf..746b53fbf 100644 --- a/nx-X11/lib/X11/GetRGBCMap.c +++ b/nx-X11/lib/X11/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 (data); + Xfree (data); return False; } @@ -78,7 +78,7 @@ Status XGetRGBColormaps ( Screen *sp = _XScreenOfWindow (dpy, w); if (!sp) { - if (data) Xfree (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 (data); + Xfree (data); return False; } } @@ -101,7 +101,7 @@ Status XGetRGBColormaps ( */ cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap)); if (!cmaps) { - if (data) Xfree (data); + Xfree (data); return False; } diff --git a/nx-X11/lib/X11/GetStCmap.c b/nx-X11/lib/X11/GetStCmap.c index cea20e0f8..560de67ba 100644 --- a/nx-X11/lib/X11/GetStCmap.c +++ b/nx-X11/lib/X11/GetStCmap.c @@ -81,7 +81,7 @@ Status XGetStandardColormap ( int i; if (!sp) { - if (stdcmaps) Xfree (stdcmaps); + Xfree (stdcmaps); return False; } vid = sp->root_visual->visualid; diff --git a/nx-X11/lib/X11/GetWMCMapW.c b/nx-X11/lib/X11/GetWMCMapW.c index a28e27ea1..722ec60f8 100644 --- a/nx-X11/lib/X11/GetWMCMapW.c +++ b/nx-X11/lib/X11/GetWMCMapW.c @@ -77,7 +77,7 @@ Status XGetWMColormapWindows ( return False; if (actual_type != XA_WINDOW || actual_format != 32) { - if (data) Xfree (data); + Xfree (data); return False; } diff --git a/nx-X11/lib/X11/ImUtil.c b/nx-X11/lib/X11/ImUtil.c index 523b2a718..b0d421680 100644 --- a/nx-X11/lib/X11/ImUtil.c +++ b/nx-X11/lib/X11/ImUtil.c @@ -434,8 +434,8 @@ Status XInitImage (XImage *image) static int _XDestroyImage (XImage *ximage) { - if (ximage->data != NULL) Xfree(ximage->data); - if (ximage->obdata != NULL) Xfree(ximage->obdata); + Xfree(ximage->data); + Xfree(ximage->obdata); Xfree(ximage); return 1; } diff --git a/nx-X11/lib/X11/InitExt.c b/nx-X11/lib/X11/InitExt.c index 968f0bb8d..d02527d5c 100644 --- a/nx-X11/lib/X11/InitExt.c +++ b/nx-X11/lib/X11/InitExt.c @@ -51,7 +51,7 @@ XExtCodes *XInitExtension ( LockDisplay (dpy); if (! (ext = Xcalloc (1, sizeof (_XExtension))) || ! (ext->name = strdup(name))) { - if (ext) Xfree(ext); + Xfree(ext); UnlockDisplay(dpy); return (XExtCodes *) NULL; } diff --git a/nx-X11/lib/X11/KeyBind.c b/nx-X11/lib/X11/KeyBind.c index deb200786..acaf7fd8f 100644 --- a/nx-X11/lib/X11/KeyBind.c +++ b/nx-X11/lib/X11/KeyBind.c @@ -271,12 +271,13 @@ _XKeyInitialize( if (! keysyms) return 0; LockDisplay(dpy); - if (dpy->keysyms) - Xfree (dpy->keysyms); + + Xfree (dpy->keysyms); dpy->keysyms = keysyms; dpy->keysyms_per_keycode = per; if (dpy->modifiermap) ResetModMap(dpy); + UnlockDisplay(dpy); } if (!dpy->modifiermap) @@ -929,8 +930,8 @@ XRebindKeysym ( ((! (p->string = Xmalloc(nbytes))) && (nbytes > 0)) || ((! (p->modifiers = Xmalloc(nb))) && (nb > 0))) { if (p) { - if (p->string) Xfree(p->string); - if (p->modifiers) Xfree(p->modifiers); + Xfree(p->string); + Xfree(p->modifiers); Xfree(p); } UnlockDisplay(dpy); diff --git a/nx-X11/lib/X11/ListExt.c b/nx-X11/lib/X11/ListExt.c index f40924df7..431ae6784 100644 --- a/nx-X11/lib/X11/ListExt.c +++ b/nx-X11/lib/X11/ListExt.c @@ -62,8 +62,8 @@ char **XListExtensions( } if ((!list) || (!ch)) { - if (list) Xfree(list); - if (ch) Xfree(ch); + Xfree(list); + Xfree(ch); _XEatDataWords(dpy, rep.length); UnlockDisplay(dpy); SyncHandle(); diff --git a/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index 78d635bf5..a809aa291 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/ModMap.c @@ -50,7 +50,7 @@ XGetModifierMapping(register Display *dpy) } else res = NULL; if ((! res) || (! res->modifiermap)) { - if (res) Xfree(res); + Xfree(res); res = (XModifierKeymap *) NULL; _XEatDataWords(dpy, rep.length); } else { @@ -114,8 +114,7 @@ int XFreeModifiermap(XModifierKeymap *map) { if (map) { - if (map->modifiermap) - Xfree(map->modifiermap); + Xfree(map->modifiermap); Xfree(map); } return 1; diff --git a/nx-X11/lib/X11/OpenDis.c b/nx-X11/lib/X11/OpenDis.c index 3c56aa580..965924650 100644 --- a/nx-X11/lib/X11/OpenDis.c +++ b/nx-X11/lib/X11/OpenDis.c @@ -864,8 +864,7 @@ void _XFreeDisplayStructure(Display *dpy) while (dpy->ext_procs) { _XExtension *ext = dpy->ext_procs; dpy->ext_procs = ext->next; - if (ext->name) - Xfree (ext->name); + Xfree (ext->name); Xfree (ext); } if (dpy->im_filters) @@ -929,25 +928,18 @@ void _XFreeDisplayStructure(Display *dpy) Xfree (dpy->pixmap_format); } - if (dpy->display_name) - Xfree (dpy->display_name); - if (dpy->vendor) - Xfree (dpy->vendor); + free(dpy->display_name); - if (dpy->buffer) - Xfree (dpy->buffer); - if (dpy->keysyms) - Xfree (dpy->keysyms); - if (dpy->xdefaults) - Xfree (dpy->xdefaults); - if (dpy->error_vec) - Xfree (dpy->error_vec); + Xfree (dpy->vendor); + Xfree (dpy->buffer); + Xfree (dpy->keysyms); + Xfree (dpy->xdefaults); + Xfree (dpy->error_vec); _XFreeExtData (dpy->ext_data); - if (dpy->free_funcs) - Xfree (dpy->free_funcs); - if (dpy->scratch_buffer) - Xfree (dpy->scratch_buffer); + + Xfree (dpy->free_funcs); + Xfree (dpy->scratch_buffer); FreeDisplayLock(dpy); if (dpy->qfree) { @@ -962,8 +954,7 @@ void _XFreeDisplayStructure(Display *dpy) while (dpy->im_fd_info) { struct _XConnectionInfo *conni = dpy->im_fd_info; dpy->im_fd_info = conni->next; - if (conni->watch_data) - Xfree (conni->watch_data); + Xfree (conni->watch_data); Xfree (conni); } if (dpy->conn_watchers) { @@ -971,8 +962,8 @@ void _XFreeDisplayStructure(Display *dpy) dpy->conn_watchers = watcher->next; Xfree (watcher); } - if (dpy->filedes) - Xfree (dpy->filedes); + + Xfree (dpy->filedes); #if USE_XCB _XFreeX11XCBStructure(dpy); diff --git a/nx-X11/lib/X11/PutImage.c b/nx-X11/lib/X11/PutImage.c index e6ac9a23f..de085bcde 100644 --- a/nx-X11/lib/X11/PutImage.c +++ b/nx-X11/lib/X11/PutImage.c @@ -740,8 +740,7 @@ SendXYImage( bytes_per_src, bytes_per_line, bytes_per_dest, req->height, half_order); - if (extra) - Xfree(extra); + Xfree(extra); if (buf == dpy->bufptr) dpy->bufptr += length; @@ -793,8 +792,7 @@ SendZImage( ((req_xoffset == 0) || ((req_yoffset + req->height) < (unsigned)image->height))) { Data(dpy, (char *)src, length); - if (shifted_src) - Xfree(shifted_src); + Xfree(shifted_src); return; } @@ -804,7 +802,7 @@ SendZImage( else if ((dest = (unsigned char *) _XAllocScratch(dpy, length)) == NULL) { - if (shifted_src) Xfree(shifted_src); + Xfree(shifted_src); UnGetReq(PutImage); return; } @@ -831,8 +829,7 @@ SendZImage( else _XSend(dpy, (char *)dest, length); - if (shifted_src) - Xfree(shifted_src); + Xfree(shifted_src); } static void diff --git a/nx-X11/lib/X11/RdBitF.c b/nx-X11/lib/X11/RdBitF.c index f1e913819..c2316ae0c 100644 --- a/nx-X11/lib/X11/RdBitF.c +++ b/nx-X11/lib/X11/RdBitF.c @@ -137,7 +137,7 @@ XReadBitmapFileData ( /* error cleanup and return macro */ #define RETURN(code) \ -{ if (bits) Xfree (bits); fclose (fstream); return code; } +{ Xfree (bits); fclose (fstream); return code; } while (fgets(line, MAX_SIZE, fstream)) { if (strlen(line) == MAX_SIZE-1) diff --git a/nx-X11/lib/X11/ScrResStr.c b/nx-X11/lib/X11/ScrResStr.c index 3e8d39071..1dd04a383 100644 --- a/nx-X11/lib/X11/ScrResStr.c +++ b/nx-X11/lib/X11/ScrResStr.c @@ -48,8 +48,7 @@ char *XScreenResourceString(Screen *screen) (unsigned char **) &val) == Success) { if ((actual_type == XA_STRING) && (actual_format == 8)) return val; - if (val) - Xfree(val); + Xfree(val); } return (char *)NULL; } diff --git a/nx-X11/lib/X11/StBytes.c b/nx-X11/lib/X11/StBytes.c index df533c95d..f058d354b 100644 --- a/nx-X11/lib/X11/StBytes.c +++ b/nx-X11/lib/X11/StBytes.c @@ -74,7 +74,7 @@ char *XFetchBuffer ( *nbytes = nitems; return((char *)data); } - if ((char *) data != NULL) Xfree (data); + Xfree (data); return(NULL); } diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index deab8b3ad..418853391 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -2537,8 +2537,7 @@ _XUnregisterInternalConnection( watch=watch->next, wd++) { (*watch->fn) (dpy, watch->client_data, fd, False, wd); } - if (info_list->watch_data) - Xfree (info_list->watch_data); + Xfree (info_list->watch_data); Xfree (info_list); break; } @@ -3763,9 +3762,10 @@ char *_XAllocScratch( unsigned long nbytes) { if (nbytes > dpy->scratch_length) { - if (dpy->scratch_buffer) Xfree (dpy->scratch_buffer); - if ((dpy->scratch_buffer = Xmalloc(nbytes))) - dpy->scratch_length = nbytes; + Xfree (dpy->scratch_buffer); + dpy->scratch_buffer = Xmalloc(nbytes); + if (dpy->scratch_buffer) + dpy->scratch_length = nbytes; else dpy->scratch_length = 0; } return (dpy->scratch_buffer); @@ -3792,8 +3792,8 @@ void _XFreeTemp( char *buf, unsigned long nbytes) { - if (dpy->scratch_buffer) - Xfree(dpy->scratch_buffer); + + Xfree(dpy->scratch_buffer); dpy->scratch_buffer = buf; dpy->scratch_length = nbytes; } -- cgit v1.2.3 From 1ff6961231eda8929406b93fe3d70071cbba2469 Mon Sep 17 00:00:00 2001 From: walter harms Date: Fri, 6 Jun 2014 22:53:05 +0200 Subject: Remove more redundant null checks before Xfree() Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imCallbk.c | 6 +-- nx-X11/lib/X11/imDefIc.c | 7 ++-- nx-X11/lib/X11/imDefIm.c | 6 +-- nx-X11/lib/X11/imDefLkup.c | 13 +++--- nx-X11/lib/X11/imInt.c | 9 ++-- nx-X11/lib/X11/imLcIm.c | 102 ++++++++++++++++++--------------------------- nx-X11/lib/X11/imRmAttr.c | 24 +++++------ nx-X11/lib/X11/imThaiIc.c | 18 ++++---- nx-X11/lib/X11/lcDefConv.c | 3 +- nx-X11/lib/X11/lcGenConv.c | 34 +++++---------- nx-X11/lib/X11/omGeneric.c | 43 +++++++------------ 11 files changed, 102 insertions(+), 163 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imCallbk.c b/nx-X11/lib/X11/imCallbk.c index 07921f8a1..4e091d8ef 100644 --- a/nx-X11/lib/X11/imCallbk.c +++ b/nx-X11/lib/X11/imCallbk.c @@ -553,10 +553,8 @@ static void _free_memory_for_text(XIMText* text) { if (text) { - if (text->string.multi_byte) - Xfree(text->string.multi_byte); - if (text->feedback) - Xfree(text->feedback); + Xfree(text->string.multi_byte); + Xfree(text->feedback); Xfree(text); } } diff --git a/nx-X11/lib/X11/imDefIc.c b/nx-X11/lib/X11/imDefIc.c index a5b14ec9a..3cf46827a 100644 --- a/nx-X11/lib/X11/imDefIc.c +++ b/nx-X11/lib/X11/imDefIc.c @@ -1568,10 +1568,9 @@ _XimProtoCreateIC( ErrorOnCreatingIC: _XimUnregisterFilter(ic); - if (ic->private.proto.ic_resources) - Xfree(ic->private.proto.ic_resources); - if (ic->private.proto.ic_inner_resources) - Xfree(ic->private.proto.ic_inner_resources); + + Xfree(ic->private.proto.ic_resources); + Xfree(ic->private.proto.ic_inner_resources); Xfree(ic); return (XIC)NULL; } diff --git a/nx-X11/lib/X11/imDefIm.c b/nx-X11/lib/X11/imDefIm.c index 4ccab53ae..2a1ccb4ec 100644 --- a/nx-X11/lib/X11/imDefIm.c +++ b/nx-X11/lib/X11/imDefIm.c @@ -1775,10 +1775,8 @@ _XimEncodingNegotiation( detail_ptr, detail_len))) goto free_preply; - if (name_ptr) - Xfree(name_ptr); - if (detail_ptr) - Xfree(detail_ptr); + Xfree(name_ptr); + Xfree(detail_ptr); if(reply != preply) Xfree(preply); diff --git a/nx-X11/lib/X11/imDefLkup.c b/nx-X11/lib/X11/imDefLkup.c index 1cbd15b54..af39008bc 100644 --- a/nx-X11/lib/X11/imDefLkup.c +++ b/nx-X11/lib/X11/imDefLkup.c @@ -599,10 +599,9 @@ _XimUnregCommitInfo( if (!(info = ic->private.proto.commit_info)) return; - if (info->string) - Xfree(info->string); - if (info->keysym) - Xfree(info->keysym); + + Xfree(info->string); + Xfree(info->keysym); ic->private.proto.commit_info = info->next; Xfree(info); return; @@ -696,10 +695,8 @@ _XimCommitRecv( } if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) { - if (string) - Xfree(string); - if (keysym) - Xfree(keysym); + Xfree(string); + Xfree(keysym); _XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL); return False; } diff --git a/nx-X11/lib/X11/imInt.c b/nx-X11/lib/X11/imInt.c index dcfb476d9..05e04dac8 100644 --- a/nx-X11/lib/X11/imInt.c +++ b/nx-X11/lib/X11/imInt.c @@ -239,14 +239,11 @@ Error4 : Xfree(im); return NULL; Error3 : - if(im->core.im_name) - Xfree(im->core.im_name); + Xfree(im->core.im_name); Error2: - if(im->core.res_class) - Xfree(im->core.res_class); + Xfree(im->core.res_class); Error1: - if(im->core.res_name) - Xfree(im->core.res_name); + Xfree(im->core.res_name); Xfree(im); return NULL; } diff --git a/nx-X11/lib/X11/imLcIm.c b/nx-X11/lib/X11/imLcIm.c index 25872e8ab..95d81f6ee 100644 --- a/nx-X11/lib/X11/imLcIm.c +++ b/nx-X11/lib/X11/imLcIm.c @@ -131,13 +131,14 @@ XimFreeDefaultTree( } #endif Xfree (b->tree); - if (b->mb) Xfree (b->mb); - if (b->wc) Xfree (b->wc); - if (b->utf8) Xfree (b->utf8); b->tree = NULL; + Xfree (b->mb); b->mb = NULL; + Xfree (b->wc); b->wc = NULL; + Xfree (b->utf8); b->utf8 = NULL; + b->treeused = b->treesize = 0; b->mbused = b->mbsize = 0; b->wcused = b->wcsize = 0; @@ -151,38 +152,30 @@ _XimLocalIMFree( XimFreeDefaultTree(&im->private.local.base); im->private.local.top = 0; - if(im->core.im_resources) { - Xfree(im->core.im_resources); - im->core.im_resources = NULL; - } - if(im->core.ic_resources) { - Xfree(im->core.ic_resources); - im->core.ic_resources = NULL; - } - if(im->core.im_values_list) { - Xfree(im->core.im_values_list); - im->core.im_values_list = NULL; - } - if(im->core.ic_values_list) { - Xfree(im->core.ic_values_list); - im->core.ic_values_list = NULL; - } - if(im->core.styles) { - Xfree(im->core.styles); - im->core.styles = NULL; - } - if(im->core.res_name) { - Xfree(im->core.res_name); - im->core.res_name = NULL; - } - if(im->core.res_class) { - Xfree(im->core.res_class); - im->core.res_class = NULL; - } - if(im->core.im_name) { - Xfree(im->core.im_name); - im->core.im_name = NULL; - } + Xfree(im->core.im_resources); + im->core.im_resources = NULL; + + Xfree(im->core.ic_resources); + im->core.ic_resources = NULL; + + Xfree(im->core.im_values_list); + im->core.im_values_list = NULL; + + Xfree(im->core.ic_values_list); + im->core.ic_values_list = NULL; + + Xfree(im->core.styles); + im->core.styles = NULL; + + Xfree(im->core.res_name); + im->core.res_name = NULL; + + Xfree(im->core.res_class); + im->core.res_class = NULL; + + Xfree(im->core.im_name); + im->core.im_name = NULL; + if (im->private.local.ctom_conv) { _XlcCloseConverter(im->private.local.ctom_conv); im->private.local.ctom_conv = NULL; @@ -576,19 +569,15 @@ _XimCreateDefaultTree( encoding, 0, 1, &cachename, &size); if (cachefd != -1) { if (_XimLoadCache (cachefd, intname, encoding, size, im)) { - if (tmpcachedir) - Xfree (tmpcachedir); - if (tmpname) - Xfree (tmpname); - if (cachename) - Xfree (cachename); + Xfree (tmpcachedir); + Xfree (tmpname); + Xfree (cachename); close (cachefd); return; } close (cachefd); } - if (cachename) - Xfree (cachename); + Xfree (cachename); cachename = NULL; } @@ -603,12 +592,9 @@ _XimCreateDefaultTree( euid, 0, &cachename, &size); if (cachefd != -1) { if (_XimLoadCache (cachefd, intname, encoding, size, im)) { - if (tmpcachedir) - Xfree (tmpcachedir); - if (tmpname) - Xfree (tmpname); - if (cachename) - Xfree (cachename); + Xfree (tmpcachedir); + Xfree (tmpname); + Xfree (cachename); close (cachefd); return; } @@ -618,12 +604,9 @@ _XimCreateDefaultTree( #endif if (! (fp = _XFopenFile (name, "r"))) { - if (tmpcachedir) - Xfree (tmpcachedir); - if (tmpname) - Xfree (tmpname); - if (cachename) - Xfree (cachename); + Xfree (tmpcachedir); + Xfree (tmpname); + Xfree (cachename); return; } _XimParseStringFile(fp, im); @@ -636,12 +619,9 @@ _XimCreateDefaultTree( } #endif - if (tmpcachedir) - Xfree (tmpcachedir); - if (tmpname) - Xfree (tmpname); - if (cachename) - Xfree (cachename); + Xfree (tmpcachedir); + Xfree (tmpname); + Xfree (cachename); } static XIMMethodsRec Xim_im_local_methods = { diff --git a/nx-X11/lib/X11/imRmAttr.c b/nx-X11/lib/X11/imRmAttr.c index ad5290ee5..9d4e46258 100644 --- a/nx-X11/lib/X11/imRmAttr.c +++ b/nx-X11/lib/X11/imRmAttr.c @@ -972,8 +972,7 @@ _XimEncodePreeditValue( if (!p->value) return False; - if (ic->private.proto.preedit_font) - Xfree(ic->private.proto.preedit_font); + Xfree(ic->private.proto.preedit_font); list_ret = XFontsOfFontSet((XFontSet)p->value, &struct_list, &name_list); @@ -1024,8 +1023,7 @@ _XimEncodeStatusValue( if (!p->value) return False; - if (ic->private.proto.status_font) - Xfree(ic->private.proto.status_font); + Xfree(ic->private.proto.status_font); list_ret = XFontsOfFontSet((XFontSet)p->value, &struct_list, &name_list); @@ -1243,8 +1241,7 @@ _XimEncodeSavedStatusValue( if (!value) return False; - if (ic->private.proto.status_font) - Xfree(ic->private.proto.status_font); + Xfree(ic->private.proto.status_font); list_ret = XFontsOfFontSet((XFontSet)value, &struct_list, &name_list); @@ -1460,10 +1457,9 @@ _XimGetAttributeID( } _XIMCompileResourceList(res, n); - if (im->core.im_resources) - Xfree(im->core.im_resources); - if (im->core.im_values_list) - Xfree(im->core.im_values_list); + Xfree(im->core.im_resources); + Xfree(im->core.im_values_list); + im->core.im_resources = res; im->core.im_num_resources = n; im->core.im_values_list = values_list; @@ -1506,10 +1502,10 @@ _XimGetAttributeID( } _XIMCompileResourceList(res, n); - if (im->core.ic_resources) - Xfree(im->core.ic_resources); - if (im->core.ic_values_list) - Xfree(im->core.ic_values_list); + + Xfree(im->core.ic_resources); + Xfree(im->core.ic_values_list); + im->core.ic_resources = res; im->core.ic_num_resources = n; im->core.ic_values_list = values_list; diff --git a/nx-X11/lib/X11/imThaiIc.c b/nx-X11/lib/X11/imThaiIc.c index 002219920..b559145d0 100644 --- a/nx-X11/lib/X11/imThaiIc.c +++ b/nx-X11/lib/X11/imThaiIc.c @@ -65,18 +65,20 @@ _XimThaiDestroyIC( if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) { _XimThaiUnSetFocus(xic); } - if(ic->private.local.ic_resources) { - Xfree(ic->private.local.ic_resources); - ic->private.local.ic_resources = NULL; - } - if (b->tree) Xfree (b->tree); - if (b->mb) Xfree (b->mb); - if (b->wc) Xfree (b->wc); - if (b->utf8) Xfree (b->utf8); + Xfree(ic->private.local.ic_resources); + ic->private.local.ic_resources = NULL; + + Xfree (b->tree); b->tree = NULL; + + Xfree (b->mb); b->mb = NULL; + + Xfree (b->wc); b->wc = NULL; + + Xfree (b->utf8); b->utf8 = NULL; return; } diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index 3cd5c22c9..e1f02289b 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -563,9 +563,8 @@ static void close_converter( XlcConv conv) { - if (conv->state) - Xfree(conv->state); + Xfree(conv->state); Xfree(conv); } diff --git a/nx-X11/lib/X11/lcGenConv.c b/nx-X11/lib/X11/lcGenConv.c index c816c25d4..eede76807 100644 --- a/nx-X11/lib/X11/lcGenConv.c +++ b/nx-X11/lib/X11/lcGenConv.c @@ -1225,8 +1225,7 @@ stdc_wcstocts( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -1548,8 +1547,7 @@ stdc_ctstowcs( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -1584,8 +1582,7 @@ stdc_cstowcs( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -1620,8 +1617,7 @@ mbstocts( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2071,8 +2067,7 @@ stdc_wcstostr( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2346,8 +2341,7 @@ ctstombs( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2382,8 +2376,7 @@ cstombs( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2591,8 +2584,7 @@ stdc_strtowcs( goto ret; ret: - if (buf) - Xfree(buf); + Xfree(buf); return (unconv_num1 + unconv_num2); } @@ -2605,14 +2597,8 @@ static void close_converter( XlcConv conv) { - if (conv->state) { - Xfree(conv->state); - } - - if (conv->methods) { - Xfree(conv->methods); - } - + Xfree(conv->state); + Xfree(conv->methods); Xfree(conv); } diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 89d1b2ffd..91f4280d0 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -196,16 +196,12 @@ init_fontset( return True; err: - if(font_set->font_data) - Xfree(font_set->font_data); - if(font_set->substitute) - Xfree(font_set->substitute); - if(font_set->vmap) - Xfree(font_set->vmap); - if(font_set->vrotate) - Xfree(font_set->vrotate); - if(font_set) - Xfree(font_set); + + Xfree(font_set->font_data); + Xfree(font_set->substitute); + Xfree(font_set->vmap); + Xfree(font_set->vrotate); + Xfree(font_set); gen->font_set = (FontSet) NULL; gen->font_set_num = 0; return False; @@ -504,8 +500,8 @@ init_core_part( return True; err: - if (font_name_list) - Xfree(font_name_list); + + Xfree(font_name_list); Xfree(font_struct_list); return False; @@ -1486,24 +1482,15 @@ destroy_oc( */ /* For VW/UDC end */ - if (oc->core.base_name_list) - Xfree(oc->core.base_name_list); - - if (oc->core.font_info.font_name_list) - XFreeStringList(oc->core.font_info.font_name_list); - - if (oc->core.font_info.font_struct_list) { - Xfree(oc->core.font_info.font_struct_list); - } - - if (oc->core.missing_list.charset_list) - XFreeStringList(oc->core.missing_list.charset_list); + Xfree(oc->core.base_name_list); + XFreeStringList(oc->core.font_info.font_name_list); + Xfree(oc->core.font_info.font_struct_list); + XFreeStringList(oc->core.missing_list.charset_list); #ifdef notdef - if (oc->core.res_name) - Xfree(oc->core.res_name); - if (oc->core.res_class) - Xfree(oc->core.res_class); + + Xfree(oc->core.res_name); + Xfree(oc->core.res_class); #endif Xfree(oc); -- cgit v1.2.3 From a98260726b8f878e72223899e21ad87882389e2d Mon Sep 17 00:00:00 2001 From: walter harms Date: Sat, 7 Jun 2014 15:17:27 +0200 Subject: libX11: rm redundante NULL checks This patch removes the last remaining NULL checks for Xfree() Signed-off-by: Harms Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/GetWMProto.c | 2 +- nx-X11/lib/X11/ICWrap.c | 10 +++++----- nx-X11/lib/X11/XDefaultOMIF.c | 36 ++++++++++++++---------------------- nx-X11/lib/X11/XKBGAlloc.c | 6 ++---- nx-X11/lib/X11/lcFile.c | 19 ++++++++----------- nx-X11/lib/X11/lcGeneric.c | 10 ++++------ nx-X11/lib/X11/lcPrTxt.c | 3 +-- nx-X11/lib/X11/lcPublic.c | 20 ++++++++------------ nx-X11/lib/X11/lcWrap.c | 3 +-- 9 files changed, 44 insertions(+), 65 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/GetWMProto.c b/nx-X11/lib/X11/GetWMProto.c index 32466218d..1ea4f55d5 100644 --- a/nx-X11/lib/X11/GetWMProto.c +++ b/nx-X11/lib/X11/GetWMProto.c @@ -77,7 +77,7 @@ Status XGetWMProtocols ( return False; if (actual_type != XA_ATOM || actual_format != 32) { - if (data) Xfree (data); + Xfree (data); return False; } diff --git a/nx-X11/lib/X11/ICWrap.c b/nx-X11/lib/X11/ICWrap.c index 2a1d0d670..8c1b4a01c 100644 --- a/nx-X11/lib/X11/ICWrap.c +++ b/nx-X11/lib/X11/ICWrap.c @@ -186,7 +186,7 @@ XSetIMValues(XIM im, ...) va_end(var); ret = (*im->methods->set_values) (im, args); - if (args) Xfree(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(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(args); + Xfree(args); if (ic) { ic->core.next = im->core.ic_chain; im->core.ic_chain = ic; @@ -300,7 +300,7 @@ XGetICValues(XIC ic, ...) va_end(var); ret = (*ic->methods->get_values) (ic, args); - if (args) Xfree(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(args); + Xfree(args); return ret; } diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 71dc810eb..6af1c8015 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -367,8 +367,8 @@ init_core_part( return True; err: - if (font_name_list) - Xfree(font_name_list); + + Xfree(font_name_list); Xfree(font_struct_list); return False; @@ -636,14 +636,10 @@ destroy_oc( XOCGenericPart *gen = XOC_GENERIC(oc); XFontStruct **font_list, *font; - if (gen->font_set) - Xfree(gen->font_set); - - if (oc->core.base_name_list) - Xfree(oc->core.base_name_list); - if (oc->core.font_info.font_name_list) - XFreeStringList(oc->core.font_info.font_name_list); + Xfree(gen->font_set); + Xfree(oc->core.base_name_list); + XFreeStringList(oc->core.font_info.font_name_list); if ((font_list = oc->core.font_info.font_struct_list)) { if ((font = *font_list)) { @@ -655,14 +651,12 @@ destroy_oc( Xfree(oc->core.font_info.font_struct_list); } - if (oc->core.missing_list.charset_list) - XFreeStringList(oc->core.missing_list.charset_list); + + XFreeStringList(oc->core.missing_list.charset_list); #ifdef notdef - if (oc->core.res_name) - Xfree(oc->core.res_name); - if (oc->core.res_class) - Xfree(oc->core.res_class); + Xfree(oc->core.res_name); + Xfree(oc->core.res_class); #endif Xfree(oc); @@ -1043,7 +1037,6 @@ close_om( if (data->font_data) { for (font_data = data->font_data, count = data->font_data_count; count-- > 0 ; font_data++) { - if (font_data->name) Xfree(font_data->name); } Xfree(data->font_data); @@ -1051,17 +1044,16 @@ close_om( Xfree(gen->data); } - if (om->core.res_name) - Xfree(om->core.res_name); - if (om->core.res_class) - Xfree(om->core.res_class); + + Xfree(om->core.res_name); + Xfree(om->core.res_class); + if (om->core.required_charset.charset_list) XFreeStringList(om->core.required_charset.charset_list); else Xfree((char*)om->core.required_charset.charset_list); - if (om->core.orientation_list.orientation) - Xfree(om->core.orientation_list.orientation); + Xfree(om->core.orientation_list.orientation); Xfree(om); return 1; diff --git a/nx-X11/lib/X11/XKBGAlloc.c b/nx-X11/lib/X11/XKBGAlloc.c index 28d1fae43..ab05f8d88 100644 --- a/nx-X11/lib/X11/XKBGAlloc.c +++ b/nx-X11/lib/X11/XKBGAlloc.c @@ -177,8 +177,7 @@ _XkbClearColor(char *color_in) { XkbColorPtr color = (XkbColorPtr) color_in; - if (color->spec) - _XkbFree(color->spec); + _XkbFree(color->spec); return; } @@ -660,8 +659,7 @@ XkbAddGeomProperty(XkbGeometryPtr geom, char *name, char *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); + _XkbFree(prop->value); prop->value = strdup(value); return prop; } diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index 7b0e5a824..eeb6ce312 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -554,7 +554,7 @@ _XlcResolveLocaleName( break; } } - if (nlc_name) Xfree(nlc_name); + Xfree(nlc_name); if (name == NULL) { /* vendor locale name == Xlocale name, no expansion of alias */ @@ -672,19 +672,18 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, const char *lc_name) target_name = NULL; } } - if (nlc_name) Xfree(nlc_name); + Xfree(nlc_name); if (target_name == NULL) /* vendor locale name == Xlocale name, no expansion of alias */ 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); + Xfree (last_dir_name); + Xfree (last_lc_name); - if (last_dir_name != 0) - Xfree (last_dir_name); - if (last_lc_name != 0) - Xfree (last_lc_name); last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); @@ -751,7 +750,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, const char *lc_name) target_name = NULL; } } - if (nlc_name) Xfree(nlc_name); + Xfree(nlc_name); if (target_name == NULL) /* vendor locale name == Xlocale name, no expansion of alias */ @@ -759,11 +758,9 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, const char *lc_name) else snprintf(dir_name, dir_len, "%s/%s", target_dir, target_name); Xfree(target_name); + Xfree (last_dir_name); + Xfree (last_lc_name); - if (last_dir_name != 0) - Xfree (last_dir_name); - if (last_lc_name != 0) - Xfree (last_lc_name); last_dir_len = strlen (dir_name) + 1; last_dir_name = Xmalloc (last_dir_len); strcpy (last_dir_name, dir_name); diff --git a/nx-X11/lib/X11/lcGeneric.c b/nx-X11/lib/X11/lcGeneric.c index 20c455c13..1c78a95c6 100644 --- a/nx-X11/lib/X11/lcGeneric.c +++ b/nx-X11/lib/X11/lcGeneric.c @@ -259,8 +259,8 @@ add_parse_list( err: Xfree(str); - if (new) - Xfree(new); + + Xfree(new); return False; } @@ -273,12 +273,10 @@ free_charset( ParseInfo *parse_info; int num; - if (gen->mb_parse_table) - Xfree(gen->mb_parse_table); + Xfree(gen->mb_parse_table); if ((num = gen->mb_parse_list_num) > 0) { for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) { - if ((*parse_info)->encoding) - Xfree((*parse_info)->encoding); + Xfree((*parse_info)->encoding); Xfree(*parse_info); } Xfree(gen->mb_parse_list); diff --git a/nx-X11/lib/X11/lcPrTxt.c b/nx-X11/lib/X11/lcPrTxt.c index 2ed7d8515..f038bd70b 100644 --- a/nx-X11/lib/X11/lcPrTxt.c +++ b/nx-X11/lib/X11/lcPrTxt.c @@ -283,8 +283,7 @@ _XwcFreeStringList( wchar_t **list) { if (list) { - if (*list) - Xfree(*list); + Xfree(*list); Xfree(list); } } diff --git a/nx-X11/lib/X11/lcPublic.c b/nx-X11/lib/X11/lcPublic.c index 39ec0829b..98a7435fd 100644 --- a/nx-X11/lib/X11/lcPublic.c +++ b/nx-X11/lib/X11/lcPublic.c @@ -254,16 +254,14 @@ static void destroy_core( XLCd lcd) { - if (lcd->core) { - if (lcd->core->name) + if (lcd) { + if (lcd->core) { Xfree(lcd->core->name); - Xfree(lcd->core); + Xfree(lcd->core); + } + Xfree(lcd->methods); + Xfree(lcd); } - - if (lcd->methods) - Xfree(lcd->methods); - - Xfree(lcd); } static void @@ -274,10 +272,8 @@ destroy( _XlcDestroyLocaleDataBase(lcd); - if (pub->siname) - Xfree(pub->siname); - if (pub->encoding_name) - Xfree(pub->encoding_name); + Xfree(pub->siname); + Xfree(pub->encoding_name); destroy_core(lcd); } diff --git a/nx-X11/lib/X11/lcWrap.c b/nx-X11/lib/X11/lcWrap.c index b71de7abb..067c501ba 100644 --- a/nx-X11/lib/X11/lcWrap.c +++ b/nx-X11/lib/X11/lcWrap.c @@ -86,8 +86,7 @@ XSetLocaleModifiers( user_mods = getenv("XMODIFIERS"); mapped_mods = (*lcd->methods->map_modifiers) (lcd, user_mods, modifiers); if (mapped_mods) { - if (lcd->core->modifiers) - Xfree(lcd->core->modifiers); + Xfree(lcd->core->modifiers); lcd->core->modifiers = mapped_mods; } return mapped_mods; -- cgit v1.2.3 From dd6dc2ddfa8b0cb671711acb9d157de29a48c032 Mon Sep 17 00:00:00 2001 From: walter harms Date: Sat, 7 Jun 2014 11:54:34 +0200 Subject: rm redundant null checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove more redundant NULL checks note that _XkbFree() is really Xfree() Signed-off-by: Harms Reviewed-by: Rémi Cardona Signed-off-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/GetHints.c | 2 +- nx-X11/lib/X11/XKBAlloc.c | 3 +- nx-X11/lib/X11/XKBExtDev.c | 6 +-- nx-X11/lib/X11/XKBGeom.c | 11 +++--- nx-X11/lib/X11/XKBMAlloc.c | 92 +++++++++++++++++++--------------------------- nx-X11/lib/X11/XKBNames.c | 4 +- nx-X11/lib/X11/XKBRdBuf.c | 4 +- 7 files changed, 52 insertions(+), 70 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/GetHints.c b/nx-X11/lib/X11/GetHints.c index fae61e912..7bfd35358 100644 --- a/nx-X11/lib/X11/GetHints.c +++ b/nx-X11/lib/X11/GetHints.c @@ -258,7 +258,7 @@ Status XGetCommand ( return (0); } - if (tp.value) Xfree (tp.value); + Xfree (tp.value); *argvp = argv; *argcp = argc; return 1; diff --git a/nx-X11/lib/X11/XKBAlloc.c b/nx-X11/lib/X11/XKBAlloc.c index a089ff46d..9c3430c1a 100644 --- a/nx-X11/lib/X11/XKBAlloc.c +++ b/nx-X11/lib/X11/XKBAlloc.c @@ -442,8 +442,7 @@ XkbAllocDeviceInfo(unsigned deviceSpec, unsigned nButtons, unsigned szLeds) devi->sz_leds = szLeds; devi->leds = _XkbTypedCalloc(szLeds, XkbDeviceLedInfoRec); if (!devi->leds) { - if (devi->btn_acts) - _XkbFree(devi->btn_acts); + _XkbFree(devi->btn_acts); _XkbFree(devi); return NULL; } diff --git a/nx-X11/lib/X11/XKBExtDev.c b/nx-X11/lib/X11/XKBExtDev.c index 25c76ab11..183647fc6 100644 --- a/nx-X11/lib/X11/XKBExtDev.c +++ b/nx-X11/lib/X11/XKBExtDev.c @@ -194,8 +194,8 @@ _XkbReadGetDeviceInfoReply(Display *dpy, act = &devi->btn_acts[rep->firstBtnWanted]; bzero((char *) act, (rep->nBtnsWanted * sizeof(XkbAction))); } - if (devi->name != NULL) - _XkbFree(devi->name); + + _XkbFree(devi->name); if (!_XkbGetReadBufferCountedString(&buf, &devi->name)) goto BAILOUT; if (rep->nBtnsRtrn > 0) { @@ -475,7 +475,7 @@ _InitLedStuff(SetLedStuff *stuff, unsigned wanted, XkbDeviceInfoPtr devi) static void _FreeLedStuff(SetLedStuff * stuff) { - if ((stuff->num_info > 0) && (stuff->info != NULL)) + if (stuff->num_info > 0) _XkbFree(stuff->info); bzero(stuff, sizeof(SetLedStuff)); return; diff --git a/nx-X11/lib/X11/XKBGeom.c b/nx-X11/lib/X11/XKBGeom.c index 0145da8c1..f57fe7cf6 100644 --- a/nx-X11/lib/X11/XKBGeom.c +++ b/nx-X11/lib/X11/XKBGeom.c @@ -269,10 +269,9 @@ _XkbReadGeomProperties(XkbReadBufferPtr buf, 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); + + _XkbFree(name); + _XkbFree(value); } if (ok) rtrn = Success; @@ -322,8 +321,8 @@ _XkbReadGeomColors(XkbReadBufferPtr buf, rtrn = BadLength; else if (XkbAddGeomColor(geom, spec, geom->num_colors) == NULL) rtrn = BadAlloc; - if (spec) - _XkbFree(spec); + + _XkbFree(spec); if (rtrn != Success) return rtrn; } diff --git a/nx-X11/lib/X11/XKBMAlloc.c b/nx-X11/lib/X11/XKBMAlloc.c index d1f232619..5e77670af 100644 --- a/nx-X11/lib/X11/XKBMAlloc.c +++ b/nx-X11/lib/X11/XKBMAlloc.c @@ -226,18 +226,16 @@ XkbCopyKeyType(XkbKeyTypePtr from, XkbKeyTypePtr into) { if ((!from) || (!into)) return BadMatch; - if (into->map) { - _XkbFree(into->map); - into->map = NULL; - } - if (into->preserve) { - _XkbFree(into->preserve); - into->preserve = NULL; - } - if (into->level_names) { - _XkbFree(into->level_names); - into->level_names = NULL; - } + + _XkbFree(into->map); + into->map = NULL; + + _XkbFree(into->preserve); + into->preserve = NULL; + + _XkbFree(into->level_names); + into->level_names = NULL; + *into = *from; if ((from->map) && (into->map_count > 0)) { into->map = _XkbTypedCalloc(into->map_count, XkbKTMapEntryRec); @@ -385,11 +383,9 @@ XkbResizeKeyType(XkbDescPtr xkb, } type = &xkb->map->types[type_ndx]; if (map_count == 0) { - if (type->map != NULL) - _XkbFree(type->map); + _XkbFree(type->map); type->map = NULL; - if (type->preserve != NULL) - _XkbFree(type->preserve); + _XkbFree(type->preserve); type->preserve = NULL; type->map_count = 0; } @@ -400,8 +396,7 @@ XkbResizeKeyType(XkbDescPtr xkb, type->map = _XkbTypedRealloc(type->map, map_count, XkbKTMapEntryRec); if (!type->map) { - if (prev_map) - _XkbFree(prev_map); + _XkbFree(prev_map); return BadAlloc; } if (want_preserve) { @@ -412,12 +407,11 @@ XkbResizeKeyType(XkbDescPtr xkb, XkbModsRec); } if (!type->preserve) { - if (prev_preserve) - _XkbFree(prev_preserve); + _XkbFree(prev_preserve); return BadAlloc; } } - else if (type->preserve != NULL) { + else { _XkbFree(type->preserve); type->preserve = NULL; } @@ -430,8 +424,7 @@ XkbResizeKeyType(XkbDescPtr xkb, type->level_names = _XkbTypedRealloc(type->level_names, new_num_lvls, Atom); if (!type->level_names) { - if (prev_level_names) - _XkbFree(prev_level_names); + _XkbFree(prev_level_names); return BadAlloc; } } @@ -948,19 +941,16 @@ XkbFreeClientMap(XkbDescPtr xkb, unsigned what, Bool freeMap) 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; - } + _XkbFree(type->map); + type->map = 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(type->level_names); + type->level_names = NULL; } } _XkbFree(map->types); @@ -969,17 +959,14 @@ XkbFreeClientMap(XkbDescPtr xkb, unsigned what, Bool freeMap) } } 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; - } + _XkbFree(map->key_sym_map); + map->key_sym_map = NULL; + + _XkbFree(map->syms); + map->size_syms = map->num_syms = 0; + map->syms = NULL; } - if ((what & XkbModifierMapMask) && (map->modmap != NULL)) { + if (what & XkbModifierMapMask) { _XkbFree(map->modmap); map->modmap = NULL; } @@ -1000,26 +987,23 @@ XkbFreeServerMap(XkbDescPtr xkb, unsigned what, Bool freeMap) if (freeMap) what = XkbAllServerInfoMask; map = xkb->server; - if ((what & XkbExplicitComponentsMask) && (map->explicit != NULL)) { + if (what & XkbExplicitComponentsMask) { _XkbFree(map->explicit); map->explicit = NULL; } if (what & XkbKeyActionsMask) { - if (map->key_acts != NULL) { - _XkbFree(map->key_acts); + _XkbFree(map->key_acts); map->key_acts = NULL; - } - if (map->acts != NULL) { - _XkbFree(map->acts); + + _XkbFree(map->acts); map->num_acts = map->size_acts = 0; map->acts = NULL; - } } - if ((what & XkbKeyBehaviorsMask) && (map->behaviors != NULL)) { + if (what & XkbKeyBehaviorsMask) { _XkbFree(map->behaviors); map->behaviors = NULL; } - if ((what & XkbVirtualModMapMask) && (map->vmodmap != NULL)) { + if (what & XkbVirtualModMapMask) { _XkbFree(map->vmodmap); map->vmodmap = NULL; } diff --git a/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index f5a6ed1fa..44f71cedf 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/XKBNames.c @@ -133,8 +133,8 @@ _XkbReadGetNamesReply(Display *dpy, if ((nLevels[i] > 0) && (nLevels[i] != type->num_levels)) { goto BAILOUT; } - if (type->level_names != NULL) - Xfree(type->level_names); + + Xfree(type->level_names); if (nLevels[i] == 0) { type->level_names = NULL; continue; diff --git a/nx-X11/lib/X11/XKBRdBuf.c b/nx-X11/lib/X11/XKBRdBuf.c index 60d7c7364..381f4c900 100644 --- a/nx-X11/lib/X11/XKBRdBuf.c +++ b/nx-X11/lib/X11/XKBRdBuf.c @@ -167,8 +167,8 @@ _XkbFreeReadBuffer(XkbReadBufferPtr buf) int left; left = (int) _XkbReadBufferDataLeft(buf); - if (buf->start != NULL) - Xfree(buf->start); + + Xfree(buf->start); buf->size = 0; buf->start = buf->data = NULL; return left; -- cgit v1.2.3 From aa7053b3eea7c98e155caf6ff6fd652f55b0547e Mon Sep 17 00:00:00 2001 From: walter harms Date: Sat, 7 Jun 2014 12:03:17 +0200 Subject: lcDefConv.c: fix use before check * Do not use variables before checked for NULL. * remove some superfluid spaces (Mark Kettenis) Signed-off-by: Harms Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcDefConv.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcDefConv.c b/nx-X11/lib/X11/lcDefConv.c index e1f02289b..51ad2f8e7 100644 --- a/nx-X11/lib/X11/lcDefConv.c +++ b/nx-X11/lib/X11/lcDefConv.c @@ -149,14 +149,16 @@ def_mbstowcs( XPointer *args, int num_args) { - const char *src = (const char *) *from; - wchar_t *dst = (wchar_t *) * to; + const char *src; + wchar_t *dst = (wchar_t *) *to; State state = (State) conv->state; int unconv = 0; if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + while (*from_left && *to_left) { (*from_left)--; if (state->MBtoWC (state, src++, dst)) { @@ -181,7 +183,7 @@ def_wcstombs( XPointer *args, int num_args) { - const wchar_t *src = (const wchar_t *) * from; + const wchar_t *src; char *dst = (char *) *to; State state = (State) conv->state; char ch[MB_LEN_MAX]; @@ -190,6 +192,8 @@ def_wcstombs( if (from == NULL || *from == NULL) return 0; + src = (const wchar_t *) *from; + while (*from_left && *to_left) { (*from_left)--; if (state->WCtoMB (state, *src++, ch)) { @@ -214,7 +218,7 @@ mbstostr( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; CodeSet codeset; State state = (State) conv->state; @@ -224,6 +228,8 @@ mbstostr( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + while (*from_left && *to_left) { ch = *src++; (*from_left)--; @@ -251,7 +257,7 @@ wcstostr( XPointer *args, int num_args) { - const wchar_t *src = (const wchar_t *) *from; + const wchar_t *src; char *dst = (char *) *to; CodeSet codeset; State state = (State) conv->state; @@ -261,6 +267,8 @@ wcstostr( if (from == NULL || *from == NULL) return 0; + src = (const wchar_t *) *from; + while (*from_left && *to_left) { (*from_left)--; if (state->WCtoMB (state, *src++, ch)) { @@ -290,7 +298,7 @@ mbstocs( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; int length; State state = (State) conv->state; @@ -300,6 +308,7 @@ mbstocs( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; length = min(*from_left, *to_left); cur_side = *src & GR; @@ -336,7 +345,7 @@ wcstocs( XPointer *args, int num_args) { - const wchar_t *src = (const wchar_t *) * from; + const wchar_t *src; char *dst = (char *) *to; State state = (State) conv->state; char cur_side = 0, ch[MB_LEN_MAX]; @@ -346,6 +355,8 @@ wcstocs( if (from == NULL || *from == NULL) return 0; + src = (const wchar_t *) *from; + while (*from_left) { if ((found = state->WCtoMB (state, *src, ch))) break; @@ -398,7 +409,7 @@ cstombs( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; CodeSet codeset; XlcCharSet charset; @@ -410,6 +421,8 @@ cstombs( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + if (num_args > 0) { charset = (XlcCharSet) args[0]; if (charset == NULL) @@ -467,8 +480,8 @@ cstowcs( XPointer *args, int num_args) { - const char *src = (const char *) *from; - wchar_t *dst = (wchar_t *) * to; + const char *src; + wchar_t *dst = (wchar_t *) *to; CodeSet codeset; XlcCharSet charset; State state = (State) conv->state; @@ -479,6 +492,8 @@ cstowcs( if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; + if (num_args > 0) { charset = (XlcCharSet) args[0]; if (charset == NULL) @@ -539,13 +554,14 @@ strtombs( XPointer *args, int num_args) { - const char *src = (const char *) *from; + const char *src; char *dst = (char *) *to; int length; if (from == NULL || *from == NULL) return 0; + src = (const char *) *from; length = min(*from_left, *to_left); while (length) { *dst++ = *src++; -- cgit v1.2.3 From 37b8d68832cfd6f20b321d9d7e757027c75677f2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 6 Jul 2014 10:54:57 -0700 Subject: Fix map->num_types check in XkbAddKeyType() Check is intended to ensure we allocate at least XkbNumRequiredTypes in map, but was accidentally marked with a ! causing the wrong check. Reported-by: Harms Reviewed-by: Matthieu Herrb Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBMAlloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBMAlloc.c b/nx-X11/lib/X11/XKBMAlloc.c index 5e77670af..2467a2024 100644 --- a/nx-X11/lib/X11/XKBMAlloc.c +++ b/nx-X11/lib/X11/XKBMAlloc.c @@ -300,7 +300,7 @@ XkbAddKeyType(XkbDescPtr xkb, } } } - if ((!map) || (!map->types) || (!map->num_types < XkbNumRequiredTypes)) { + if ((!map) || (!map->types) || (map->num_types < XkbNumRequiredTypes)) { tmp = XkbNumRequiredTypes + 1; if (XkbAllocClientMap(xkb, XkbKeyTypesMask, tmp) != Success) return NULL; -- cgit v1.2.3 From f20f91ee89607537dfc6bfaec05d18e9830bea13 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 6 Jul 2014 11:13:49 -0700 Subject: Fix validation of ctrls parameter to XkbGetPerClientControls() Nothing in the XKB spec states that the memory pointed to by ctrls has to be initialized to any given value when passed to the function, only that it is set by the function to the values returned by the X server: http://www.x.org/releases/X11R7.7/doc/libX11/XKB/xkblib.html#The_Miscellaneous_Per_client_Controls The check for the incoming value seems to be copied from XkbSetPerClientControls without explanation. Instead change it to checking if ctrls is non-NULL, since there's no point asking the X server to return a value the caller won't even see. Found while investigating report from cppcheck-1.65: [nx-X11/lib/X11/XKB.c:699] -> [nx-X11/lib/X11/XKB.c:719]: (warning) Possible null pointer dereference: ctrls - otherwise it is redundant to check it against null. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKB.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKB.c b/nx-X11/lib/X11/XKB.c index 7f1b233aa..7ecd39706 100644 --- a/nx-X11/lib/X11/XKB.c +++ b/nx-X11/lib/X11/XKB.c @@ -696,9 +696,7 @@ XkbGetPerClientControls(Display *dpy, unsigned *ctrls) if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || - (*ctrls & ~(XkbPCF_GrabsUseXKBStateMask | - XkbPCF_LookupStateWhenGrabbed | - XkbPCF_SendEventUsesXKBState))) + (ctrls == NULL)) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; @@ -716,10 +714,9 @@ XkbGetPerClientControls(Display *dpy, unsigned *ctrls) } 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); } -- cgit v1.2.3 From 0f1fa85fe03a268c2b3b04978f3a533df1bf3414 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 11 Jul 2014 10:34:08 -0700 Subject: Use C99 named initializers to fill in events passed to XSendEvent Forces compiler to zero-fill unset fields in the struct (fixing bug 81236) and allows optimizer to order field initialization to best fit cache layout or other considerations. Before & after output of gcc -S on AMD64 shows insertion of "rep stosq" instructions to rapidly zero-fill structs. Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Iconify.c | 26 +++++++++++++++----------- nx-X11/lib/X11/ReconfWM.c | 37 ++++++++++++++++++++----------------- nx-X11/lib/X11/Withdraw.c | 22 ++++++++++++---------- 3 files changed, 47 insertions(+), 38 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Iconify.c b/nx-X11/lib/X11/Iconify.c index 9e24c6b86..542f5885c 100644 --- a/nx-X11/lib/X11/Iconify.c +++ b/nx-X11/lib/X11/Iconify.c @@ -67,19 +67,23 @@ Status XIconifyWindow ( Window w, int screen) { - XClientMessageEvent ev; - Window root = RootWindow (dpy, screen); Atom prop; prop = XInternAtom (dpy, "WM_CHANGE_STATE", False); - if (prop == None) return False; + if (prop == None) + return False; + else { + XClientMessageEvent ev = { + .type = ClientMessage, + .window = w, + .message_type = prop, + .format = 32, + .data.l[0] = IconicState + }; + Window root = RootWindow (dpy, screen); - ev.type = ClientMessage; - ev.window = w; - ev.message_type = prop; - ev.format = 32; - ev.data.l[0] = IconicState; - return (XSendEvent (dpy, root, False, - SubstructureRedirectMask|SubstructureNotifyMask, - (XEvent *)&ev)); + return (XSendEvent (dpy, root, False, + SubstructureRedirectMask|SubstructureNotifyMask, + (XEvent *)&ev)); + } } diff --git a/nx-X11/lib/X11/ReconfWM.c b/nx-X11/lib/X11/ReconfWM.c index 1776f2e15..8dc3534e0 100644 --- a/nx-X11/lib/X11/ReconfWM.c +++ b/nx-X11/lib/X11/ReconfWM.c @@ -41,7 +41,6 @@ Status XReconfigureWMWindow ( unsigned int mask, XWindowChanges *changes) { - XConfigureRequestEvent ev; Window root = RootWindow (dpy, screen); _XAsyncHandler async; _XAsyncErrorState async_state; @@ -120,20 +119,24 @@ Status XReconfigureWMWindow ( /* * If the request succeeded, then everything is okay; otherwise, send event */ - if (!async_state.error_count) return True; - - ev.type = ConfigureRequest; - ev.window = w; - ev.parent = root; - ev.value_mask = (mask & AllMaskBits); - ev.x = changes->x; - ev.y = changes->y; - ev.width = changes->width; - ev.height = changes->height; - ev.border_width = changes->border_width; - ev.above = changes->sibling; - ev.detail = changes->stack_mode; - return (XSendEvent (dpy, root, False, - SubstructureRedirectMask|SubstructureNotifyMask, - (XEvent *)&ev)); + if (!async_state.error_count) + return True; + else { + XConfigureRequestEvent ev = { + .type = ConfigureRequest, + .window = w, + .parent = root, + .value_mask = (mask & AllMaskBits), + .x = changes->x, + .y = changes->y, + .width = changes->width, + .height = changes->height, + .border_width = changes->border_width, + .above = changes->sibling, + .detail = changes->stack_mode, + }; + return (XSendEvent (dpy, root, False, + SubstructureRedirectMask|SubstructureNotifyMask, + (XEvent *)&ev)); + } } diff --git a/nx-X11/lib/X11/Withdraw.c b/nx-X11/lib/X11/Withdraw.c index bca1f8d9b..9c2280234 100644 --- a/nx-X11/lib/X11/Withdraw.c +++ b/nx-X11/lib/X11/Withdraw.c @@ -67,16 +67,18 @@ Status XWithdrawWindow ( Window w, int screen) { - XUnmapEvent ev; - Window root = RootWindow (dpy, screen); - XUnmapWindow (dpy, w); - ev.type = UnmapNotify; - ev.event = root; - ev.window = w; - ev.from_configure = False; - return (XSendEvent (dpy, root, False, - SubstructureRedirectMask|SubstructureNotifyMask, - (XEvent *)&ev)); + { + Window root = RootWindow (dpy, screen); + XUnmapEvent ev = { + .type = UnmapNotify, + .event = root, + .window = w, + .from_configure = False + }; + return (XSendEvent (dpy, root, False, + SubstructureRedirectMask|SubstructureNotifyMask, + (XEvent *)&ev)); + } } -- cgit v1.2.3 From 8e3e7bb774beac484c3c74b9f46597a5debad219 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 3 Feb 2015 13:23:50 -0500 Subject: compose: fix the description of modifiers in compose sequences The Compose format has a feature which allows specifying certain modifiers must (or must not) be present with a given keysym in the sequence. The grammar in imLcPrs.c and the Compose man page both do not match what the code actually does (see the handling of the variables `modifier_mask` and `modifier` in parseline() in imLcPrs.c, which are eventually matched as `ev->state & modifier_mask == modifier`). Also explicitly list the accepted modifier names, since they are not standard (e.g. "Ctrl" instead of "Control"). Signed-off-by: Ran Benita Signed-off-by: James Cloos Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcPrs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcPrs.c b/nx-X11/lib/X11/imLcPrs.c index afc947468..7528d838f 100644 --- a/nx-X11/lib/X11/imLcPrs.c +++ b/nx-X11/lib/X11/imLcPrs.c @@ -68,8 +68,9 @@ static void parsestringfile(FILE *fp, Xim im, int depth); * COMMENT ::= "#" {} * LHS ::= EVENT { EVENT } * EVENT ::= [MODIFIER_LIST] "<" keysym ">" - * MODIFIER_LIST ::= ("!" {MODIFIER} ) | "None" - * MODIFIER ::= ["~"] modifier_name + * MODIFIER_LIST ::= (["!"] {MODIFIER} ) | "None" + * MODIFIER ::= ["~"] MODIFIER_NAME + * MODIFIER_NAME ::= ("Ctrl"|"Lock"|"Caps"|"Shift"|"Alt"|"Meta") * RHS ::= ( STRING | keysym | STRING keysym ) * STRING ::= '"' { CHAR } '"' * CHAR ::= GRAPHIC_CHAR | ESCAPED_CHAR -- cgit v1.2.3 From e14489988338c648897b23197efaceffbfaa20d2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 18 May 2015 07:55:17 +1000 Subject: Fix potential memory leak If we hit the depth limit, filename leaks. Move the depth check up before we allocate filename. Introduced in 226622349a4b1e16064649d4444a34fb4be4f464. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/imLcPrs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/imLcPrs.c b/nx-X11/lib/X11/imLcPrs.c index 7528d838f..fa992e5d3 100644 --- a/nx-X11/lib/X11/imLcPrs.c +++ b/nx-X11/lib/X11/imLcPrs.c @@ -496,10 +496,10 @@ parseline( token = nexttoken(fp, tokenbuf, &lastch); if (token != KEY && token != STRING) goto error; - if ((filename = TransFileName(im, tokenbuf)) == NULL) - goto error; if (++depth > 100) goto error; + if ((filename = TransFileName(im, tokenbuf)) == NULL) + goto error; infp = _XFopenFile(filename, "r"); Xfree(filename); if (infp == NULL) -- cgit v1.2.3 From 73f2d66e0ec90ac5140e5015ca511f914016786e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 19 May 2015 12:30:22 +1000 Subject: Fix three "use of uninitialized variable" coverity warnings False positive, if rlen/nbytes are unset we quit early before using it. Still, initialize it so we don't have to deal with these warnings again. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FontNames.c | 2 +- nx-X11/lib/X11/GetFPath.c | 2 +- nx-X11/lib/X11/ListExt.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FontNames.c b/nx-X11/lib/X11/FontNames.c index 6fc6b1272..21dcafea1 100644 --- a/nx-X11/lib/X11/FontNames.c +++ b/nx-X11/lib/X11/FontNames.c @@ -47,7 +47,7 @@ int *actualCount) /* RETURN */ int count = 0; xListFontsReply rep; register xListFontsReq *req; - unsigned long rlen; + unsigned long rlen = 0; LockDisplay(dpy); GetReq(ListFonts, req); diff --git a/nx-X11/lib/X11/GetFPath.c b/nx-X11/lib/X11/GetFPath.c index 62ba01436..8c3f49c95 100644 --- a/nx-X11/lib/X11/GetFPath.c +++ b/nx-X11/lib/X11/GetFPath.c @@ -35,7 +35,7 @@ char **XGetFontPath( int *npaths) /* RETURN */ { xGetFontPathReply rep; - unsigned long nbytes; + unsigned long nbytes = 0; char **flist = NULL; char *ch = NULL; char *chend; diff --git a/nx-X11/lib/X11/ListExt.c b/nx-X11/lib/X11/ListExt.c index 431ae6784..be6b989a3 100644 --- a/nx-X11/lib/X11/ListExt.c +++ b/nx-X11/lib/X11/ListExt.c @@ -42,7 +42,7 @@ char **XListExtensions( register unsigned i; register int length; register xReq *req; - unsigned long rlen; + unsigned long rlen = 0; LockDisplay(dpy); GetEmptyReq (ListExtensions, req); -- cgit v1.2.3 From a402ed0162562b43a945d9a90b406c54c87c72b6 Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Thu, 4 Jun 2015 19:07:12 -0700 Subject: omGeneric.c: Correct the parameter usage of sizeof Incorrect parameter usage with sizeof. Earlier passed argument FontData will be 4 bytes always as its a pointer hence the change is needed and FontDataRec should be used for memset. Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 91f4280d0..c790bbc44 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -105,7 +105,7 @@ init_fontdata( if(fd == (FontData) NULL) return False; - memset(fd, 0x00, sizeof(FontData) * font_data_count); + memset(fd, 0x00, sizeof(FontDataRec) * font_data_count); for(i = 0 ; i < font_data_count ; i++) fd[i] = font_data[i]; -- cgit v1.2.3 From 39dd37d57b7bab3e44304562d1bbf9722bf3e03e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 4 Jun 2015 20:51:17 -0700 Subject: Replace Xmalloc+memset pairs with Xcalloc calls Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultIMIF.c | 9 +++------ nx-X11/lib/X11/imLcIm.c | 6 ++---- nx-X11/lib/X11/omGeneric.c | 14 +++++--------- 3 files changed, 10 insertions(+), 19 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultIMIF.c b/nx-X11/lib/X11/XDefaultIMIF.c index db0f5d1fa..2eb52ae4a 100644 --- a/nx-X11/lib/X11/XDefaultIMIF.c +++ b/nx-X11/lib/X11/XDefaultIMIF.c @@ -184,16 +184,14 @@ _XDefaultOpenIM( return((XIM)NULL); } - if ((im = Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) { + if ((im = Xcalloc(1, sizeof(StaticXIMRec))) == (StaticXIM)NULL) { return((XIM)NULL); } - if ((local_impart = Xmalloc(sizeof(XIMStaticXIMRec))) + if ((local_impart = Xcalloc(1, sizeof(XIMStaticXIMRec))) == (XIMStaticXIMRec *)NULL) { Xfree(im); return((XIM)NULL); } - memset(im, 0, sizeof(StaticXIMRec)); - memset(local_impart, 0, sizeof(XIMStaticXIMRec)); buf[0] = '\0'; i = 0; @@ -344,10 +342,9 @@ _CreateIC(XIM im, XIMArg *arg) { XIC ic; - if ((ic = Xmalloc(sizeof(XICRec))) == (XIC)NULL) { + if ((ic = Xcalloc(1, sizeof(XICRec))) == (XIC)NULL) { return ((XIC)NULL); } - memset(ic, 0, sizeof(XICRec)); ic->methods = (XICMethods)&local_ic_methods; ic->core.im = im; diff --git a/nx-X11/lib/X11/imLcIm.c b/nx-X11/lib/X11/imLcIm.c index 95d81f6ee..817fb2147 100644 --- a/nx-X11/lib/X11/imLcIm.c +++ b/nx-X11/lib/X11/imLcIm.c @@ -447,7 +447,7 @@ _XimWriteCachedDefaultTree( + XIM_CACHE_TREE_ALIGNMENT-1) & -XIM_CACHE_TREE_ALIGNMENT; DefTreeBase *b = &im->private.local.base; - if (! b->tree && ! (b->tree = Xmalloc (sizeof(DefTree))) ) + if (! b->tree && ! (b->tree = Xcalloc (1, sizeof(DefTree))) ) return; if (! b->mb && ! (b->mb = Xmalloc (1)) ) return; @@ -457,13 +457,11 @@ _XimWriteCachedDefaultTree( return; /* First entry is always unused */ - memset (b->tree, 0, sizeof(DefTree)); b->mb[0] = 0; b->wc[0] = 0; b->utf8[0] = 0; - m = Xmalloc (msize); - memset (m, 0, msize); + m = Xcalloc (1, msize); m->id = XIM_CACHE_MAGIC; m->version = XIM_CACHE_VERSION; m->top = im->private.local.top; diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index c790bbc44..143ec00eb 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -101,11 +101,10 @@ init_fontdata( FontData fd; int i; - fd = Xmalloc(sizeof(FontDataRec) * font_data_count); + fd = Xcalloc(font_data_count, sizeof(FontDataRec)); if(fd == (FontData) NULL) return False; - memset(fd, 0x00, sizeof(FontDataRec) * font_data_count); for(i = 0 ; i < font_data_count ; i++) fd[i] = font_data[i]; @@ -126,11 +125,10 @@ init_vrotate( if(type == VROTATE_NONE) return (VRotate)NULL; - vrotate = Xmalloc(sizeof(VRotateRec) * font_data_count); + vrotate = Xcalloc(font_data_count, sizeof(VRotateRec)); if(vrotate == (VRotate) NULL) return False; - memset(vrotate, 0x00, sizeof(VRotateRec) * font_data_count); for(i = 0 ; i < font_data_count ; i++) { vrotate[i].charset_name = font_data[i].name; vrotate[i].side = font_data[i].side; @@ -155,10 +153,9 @@ init_fontset( count = XOM_GENERIC(oc->core.om)->data_num; data = XOM_GENERIC(oc->core.om)->data; - font_set = Xmalloc(sizeof(FontSetRec) * count); + font_set = Xcalloc(count, sizeof(FontSetRec)); if (font_set == NULL) return False; - memset((char *) font_set, 0x00, sizeof(FontSetRec) * count); gen = XOC_GENERIC(oc); gen->font_set_num = count; @@ -1094,11 +1091,10 @@ parse_vw( Xfree(vrotate); if(sub_num > 0) { - vrotate = font_set->vrotate = Xmalloc - (sizeof(VRotateRec) * sub_num); + vrotate = font_set->vrotate = Xcalloc(sub_num, + sizeof(VRotateRec)); if(font_set->vrotate == (VRotate)NULL) return (-1); - memset(font_set->vrotate, 0x00, sizeof(VRotateRec) * sub_num); for(i = 0 ; i < sub_num ; i++) { vrotate[i].charset_name = font_set->substitute[i].name; -- cgit v1.2.3 From 1445735ef8fb669de0b96f01939c77ce285b5f4c Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Mon, 18 May 2015 14:49:01 +0100 Subject: Add missing NULL checks to ICWrap ICWrap.c dereferences the xim parameter passed in from client code without a NULL check. I have seen mplayer trigger this resulting in a segfault. In this case mplayer had called XOpenIM and NULL was returned which was later passed into XCreateIC. Patch originally by Drew Moseley . Signed-off-by: Ross Burton Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/ICWrap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/ICWrap.c b/nx-X11/lib/X11/ICWrap.c index 8c1b4a01c..69f080d87 100644 --- a/nx-X11/lib/X11/ICWrap.c +++ b/nx-X11/lib/X11/ICWrap.c @@ -169,7 +169,7 @@ XSetIMValues(XIM im, ...) va_list var; int total_count; XIMArg *args; - char *ret; + char *ret = NULL; /* * so count the stuff dangling here @@ -185,7 +185,8 @@ XSetIMValues(XIM im, ...) _XIMVaToNestedList(var, total_count, &args); va_end(var); - ret = (*im->methods->set_values) (im, args); + if (im && im->methods) + ret = (*im->methods->set_values) (im, args); Xfree(args); return ret; } @@ -196,7 +197,7 @@ XGetIMValues(XIM im, ...) va_list var; int total_count; XIMArg *args; - char *ret; + char *ret = NULL; /* * so count the stuff dangling here @@ -212,7 +213,8 @@ XGetIMValues(XIM im, ...) _XIMVaToNestedList(var, total_count, &args); va_end(var); - ret = (*im->methods->get_values) (im, args); + if (im && im->methods) + ret = (*im->methods->get_values) (im, args); Xfree(args); return ret; } @@ -228,7 +230,7 @@ XCreateIC(XIM im, ...) va_list var; int total_count; XIMArg *args; - XIC ic; + XIC ic = NULL; /* * so count the stuff dangling here @@ -244,7 +246,8 @@ XCreateIC(XIM im, ...) _XIMVaToNestedList(var, total_count, &args); va_end(var); - ic = (XIC) (*im->methods->create_ic) (im, args); + if (im && im->methods) + ic = (XIC) (*im->methods->create_ic) (im, args); Xfree(args); if (ic) { ic->core.next = im->core.ic_chain; -- cgit v1.2.3 From fc524ddbba875a5f091f13aaf5d851c7afb299f4 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Sun, 19 Jul 2015 10:22:45 +0200 Subject: Do not return() after exit(). Signed-off-by: Thomas Klausner Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlibInt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlibInt.c b/nx-X11/lib/X11/XlibInt.c index 418853391..d3c85a343 100644 --- a/nx-X11/lib/X11/XlibInt.c +++ b/nx-X11/lib/X11/XlibInt.c @@ -3496,7 +3496,7 @@ int _XDefaultIOError( #else exit(1); #endif /* #ifdef NX_TRANS_SOCKET */ - return(0); /* dummy - function should never return */ + /*NOTREACHED*/ } @@ -3746,7 +3746,7 @@ _XIOError ( #else exit (1); #endif - return 0; + /*NOTREACHED*/ } -- cgit v1.2.3 From f857c70f822c8e1147d74a2994acb765742e72e0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 27 Sep 2015 18:38:32 -0700 Subject: Get rid of some extraneous ; at the end of C source lines Signed-off-by: Alan Coopersmith Reviewed-by: Thomas Klausner Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBNames.c | 2 +- nx-X11/lib/X11/imExten.c | 2 +- nx-X11/lib/X11/lcPrTxt.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBNames.c b/nx-X11/lib/X11/XKBNames.c index 44f71cedf..951fd1da8 100644 --- a/nx-X11/lib/X11/XKBNames.c +++ b/nx-X11/lib/X11/XKBNames.c @@ -549,7 +549,7 @@ XkbChangeNames(Display *dpy, XkbDescPtr xkb, XkbNameChangesPtr changes) which = changes->changed; firstType = changes->first_type; nTypes = changes->num_types; - firstLvlType = changes->first_lvl;; + firstLvlType = changes->first_lvl; nLvlTypes = changes->num_lvls; if (which & XkbKeyTypeNamesMask) { if (nTypes < 1) diff --git a/nx-X11/lib/X11/imExten.c b/nx-X11/lib/X11/imExten.c index 7ed4c6be9..532b18d3b 100644 --- a/nx-X11/lib/X11/imExten.c +++ b/nx-X11/lib/X11/imExten.c @@ -367,7 +367,7 @@ _XimParseExtensionList( if (!(n = _XimCountNumberOfExtension(data[0], (CARD8 *)&data[1]))) return True; - buf = (CARD8 *)&data[1];; + buf = (CARD8 *)&data[1]; for (i = 0; i < n; i++) { len = *((INT16 *)(&buf[2])); for (j = 0; j < num; j++) { diff --git a/nx-X11/lib/X11/lcPrTxt.c b/nx-X11/lib/X11/lcPrTxt.c index f038bd70b..e62e94e80 100644 --- a/nx-X11/lib/X11/lcPrTxt.c +++ b/nx-X11/lib/X11/lcPrTxt.c @@ -149,7 +149,7 @@ _XTextPropertyToTextList( return XConverterNotFound; if (is_wide_char) { - buf_len = (text_prop->nitems + 1) * sizeof(wchar_t);; + buf_len = (text_prop->nitems + 1) * sizeof(wchar_t); } else { if (strcmp(to_type, XlcNUtf8String) == 0) buf_len = text_prop->nitems * 6 + 1; -- cgit v1.2.3 From 8339e680375bec533005bc5a2e8e01d3ec5a3fe6 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 28 Nov 2015 13:18:11 -0800 Subject: Remove unused definition of XCONN_CHECK_FREQ The only use of XCONN_CHECK_FREQ was removed in commit 15e5eaf62897b3179 when we dropped the old Xlib connection handling in favor of xcb's. Signed-off-by: Alan Coopersmith Reviewed-by: Mark Kettenis Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlibint.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlibint.h b/nx-X11/lib/X11/Xlibint.h index d4767ecfc..056b4d8f9 100644 --- a/nx-X11/lib/X11/Xlibint.h +++ b/nx-X11/lib/X11/Xlibint.h @@ -88,14 +88,6 @@ from The Open Group. #define _XFlush _XFlushIt #endif -/* - * If your BytesReadable correctly detects broken connections, then - * you should NOT define XCONN_CHECK_FREQ. - */ -#ifndef XCONN_CHECK_FREQ -#define XCONN_CHECK_FREQ 256 -#endif - struct _XGC { XExtData *ext_data; /* hook for extension to hang data */ -- cgit v1.2.3 From 8d6d95d74c0e0e6fcd3523c78ad7b9607288f578 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 3 Dec 2015 23:19:48 -0800 Subject: Bug 93184: read_EncodingInfo invalid free Free the correct bits of memory if we run out and need to unwind Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93184 Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/omGeneric.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 143ec00eb..31575d85d 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -1877,13 +1877,13 @@ read_EncodingInfo( { FontData font_data,ret; char *buf, *bufptr,*scp; - int len; + int len, i; font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return NULL; ret = font_data; - for ( ; count-- > 0; font_data++) { + for (i = 0; i < count; i++, font_data++) { /* strcpy(buf, *value++); */ @@ -1895,7 +1895,8 @@ read_EncodingInfo( len = strlen(buf); font_data->name = Xmalloc(len + 1); if (font_data->name == NULL) { - Xfree(font_data); + free_fontdataOM(ret, i + 1); + Xfree(ret); return NULL; } strncpy(font_data->name, buf,len); -- cgit v1.2.3 From 9dec6c18bc5289d86a1a25c71c86e82e8ad37332 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 3 Dec 2015 23:38:07 -0800 Subject: Bug 93183: _XDefaultOpenIM memory leaks in out-of-memory error paths Rework code to store allocations directly into XIM struct instead of temporary local variables, so we can use _XCloseIM to unwind instead of duplicating it, and consistently jump to error handler on failure, instead of sometimes leaking and sometimes freeing. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93183 Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultIMIF.c | 58 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultIMIF.c b/nx-X11/lib/X11/XDefaultIMIF.c index 2eb52ae4a..4e75fa0b4 100644 --- a/nx-X11/lib/X11/XDefaultIMIF.c +++ b/nx-X11/lib/X11/XDefaultIMIF.c @@ -168,30 +168,25 @@ _XDefaultOpenIM( char *res_class) { StaticXIM im; - XIMStaticXIMRec *local_impart; - XlcConv ctom_conv, ctow_conv; int i; char *mod; char buf[BUFSIZ]; - if (!(ctom_conv = _XlcOpenConverter(lcd, - XlcNCompoundText, lcd, XlcNMultiByte))) { - return((XIM)NULL); - } + if ((im = Xcalloc(1, sizeof(StaticXIMRec))) == NULL) + return NULL; - if (!(ctow_conv = _XlcOpenConverter(lcd, - XlcNCompoundText, lcd, XlcNWideChar))) { - return((XIM)NULL); - } + if ((im->private = Xcalloc(1, sizeof(XIMStaticXIMRec))) == NULL) + goto Error; - if ((im = Xcalloc(1, sizeof(StaticXIMRec))) == (StaticXIM)NULL) { - return((XIM)NULL); - } - if ((local_impart = Xcalloc(1, sizeof(XIMStaticXIMRec))) - == (XIMStaticXIMRec *)NULL) { - Xfree(im); - return((XIM)NULL); - } + if ((im->private->ctom_conv = _XlcOpenConverter(lcd, XlcNCompoundText, + lcd, XlcNMultiByte)) + == NULL) + goto Error; + + if ((im->private->ctow_conv = _XlcOpenConverter(lcd, XlcNCompoundText, + lcd, XlcNWideChar)) + == NULL) + goto Error; buf[0] = '\0'; i = 0; @@ -208,10 +203,9 @@ _XDefaultOpenIM( } #undef MODIFIER if ((im->core.im_name = Xmalloc(i+1)) == NULL) - goto Error2; + goto Error; strcpy(im->core.im_name, buf); - im->private = local_impart; im->methods = (XIMMethods)&local_im_methods; im->core.lcd = lcd; im->core.ic_chain = (XIC)NULL; @@ -220,9 +214,6 @@ _XDefaultOpenIM( im->core.res_name = NULL; im->core.res_class = NULL; - local_impart->ctom_conv = ctom_conv; - local_impart->ctow_conv = ctow_conv; - if ((res_name != NULL) && (*res_name != '\0')){ im->core.res_name = strdup(res_name); } @@ -231,12 +222,10 @@ _XDefaultOpenIM( } return (XIM)im; -Error2 : - Xfree(im->private); - Xfree(im->core.im_name); + + Error: + _CloseIM((XIM)im); Xfree(im); - _XlcCloseConverter(ctom_conv); - _XlcCloseConverter(ctow_conv); return(NULL); } @@ -244,13 +233,16 @@ static Status _CloseIM(XIM xim) { StaticXIM im = (StaticXIM)xim; - _XlcCloseConverter(im->private->ctom_conv); - _XlcCloseConverter(im->private->ctow_conv); + + if (im->private->ctom_conv != NULL) + _XlcCloseConverter(im->private->ctom_conv); + if (im->private->ctow_conv != NULL) + _XlcCloseConverter(im->private->ctow_conv); XFree(im->private); XFree(im->core.im_name); - if (im->core.res_name) XFree(im->core.res_name); - if (im->core.res_class) XFree(im->core.res_class); - return 1; /*bugID 4163122*/ + XFree(im->core.res_name); + XFree(im->core.res_class); + return 1; } static char * -- cgit v1.2.3 From b912a4042d884ccc2f226ab80ddc7272967d58b2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 4 Dec 2015 22:20:53 -0800 Subject: Delete #if 0 hunks of code Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 83 ------------------------------------------- nx-X11/lib/X11/cmsTrig.c | 11 ------ nx-X11/lib/X11/omGeneric.c | 54 ---------------------------- nx-X11/lib/X11/omImText.c | 4 --- 4 files changed, 152 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 6af1c8015..f9469feca 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -182,61 +182,6 @@ check_charset( return (FontData) NULL; } -#if 0 /* Unused */ -static int -check_fontname( - XOC oc, - char *name) -{ - Display *dpy = oc->core.om->core.display; - XOCGenericPart *gen = XOC_GENERIC(oc); - FontData data; - FontSet font_set; - XFontStruct *fs_list; - char **fn_list, *fname, *prop_fname = NULL; - int list_num, i; - int list2_num; - char **fn2_list = NULL; - int found_num = 0; - - fn_list = XListFonts(dpy, name, MAXFONTS, &list_num); - if (fn_list == NULL) - return found_num; - - for (i = 0; i < list_num; i++) { - fname = fn_list[i]; - - font_set = gen->font_set; - - if ((data = check_charset(font_set, fname)) == NULL) { - if ((fn2_list = XListFontsWithInfo(dpy, name, MAXFONTS, - &list2_num, &fs_list)) - && (prop_fname = get_prop_name(dpy, fs_list)) - && (data = check_charset(font_set, prop_fname))) - fname = prop_fname; - } - if (data) { - font_set->font_name = strdup(fname); - if (font_set->font_name) { - found_num++; - } - } - if (fn2_list) { - XFreeFontInfo(fn2_list, fs_list, list2_num); - fn2_list = NULL; - if (prop_fname) { - Xfree(prop_fname); - prop_fname = NULL; - } - } - if (found_num == 1) - break; - } - XFreeFontNames(fn_list); - return found_num; -} -#endif - static Bool load_font( XOC oc) @@ -256,34 +201,6 @@ load_font( return True; } -#if 0 -static Bool -load_font_info( - XOC oc) -{ - Display *dpy = oc->core.om->core.display; - XOCGenericPart *gen = XOC_GENERIC(oc); - FontSet font_set = gen->font_set; - char **fn_list; - int fn_num; - - if (font_set->font_name == NULL) - return False; - - if (font_set->info == NULL) { - fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num, - &font_set->info); - if (font_set->info == NULL) - return False; - if (fn_num > 0) - font_set->info->fid = XLoadFont(dpy, font_set->font_name); - - if (fn_list) XFreeFontNames(fn_list); - } - return True; -} -#endif - static void set_fontset_extents( XOC oc) diff --git a/nx-X11/lib/X11/cmsTrig.c b/nx-X11/lib/X11/cmsTrig.c index a917b78db..b23033aa8 100644 --- a/nx-X11/lib/X11/cmsTrig.c +++ b/nx-X11/lib/X11/cmsTrig.c @@ -375,21 +375,10 @@ static double _XcmsPolynomial( { auto double rtn_value; -#if 0 - auto double curr_coeff; - if (order <= 0) { - rtn_value = *coeffs; - } else { - curr_coeff = *coeffs; /* Bug in Unisoft's compiler. Does not */ - coeffs++; /* generate good code for *coeffs++ */ - rtn_value = curr_coeff + x * _XcmsPolynomial (--order, coeffs, x); - } -#else /* ++jrb -- removed tail recursion */ coeffs += order; rtn_value = *coeffs--; while(order-- > 0) rtn_value = *coeffs-- + (x * rtn_value); -#endif return(rtn_value); } diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c index 31575d85d..68eec01c0 100644 --- a/nx-X11/lib/X11/omGeneric.c +++ b/nx-X11/lib/X11/omGeneric.c @@ -65,32 +65,6 @@ #define CHARSET_ENCODING_FIELD 14 #define XLFD_MAX_LEN 255 -#if 0 -extern int _XmbDefaultTextEscapement(), _XwcDefaultTextEscapement(), - _Xutf8DefaultTextEscapement(); -extern int _XmbDefaultTextExtents(), _XwcDefaultTextExtents(), - _Xutf8DefaultTextExtents(); -extern Status _XmbDefaultTextPerCharExtents(), _XwcDefaultTextPerCharExtents(), - _Xutf8DefaultTextPerCharExtents(); -extern int _XmbDefaultDrawString(), _XwcDefaultDrawString(), - _Xutf8DefaultDrawString(); -extern void _XmbDefaultDrawImageString(), _XwcDefaultDrawImageString(), - _Xutf8DefaultDrawImageString(); - -extern int _XmbGenericTextEscapement(), _XwcGenericTextEscapement(), - _Xutf8GenericTextEscapement(); -extern int _XmbGenericTextExtents(), _XwcGenericTextExtents(), - _Xutf8GenericTextExtents(); -extern Status _XmbGenericTextPerCharExtents(), _XwcGenericTextPerCharExtents(), - _Xutf8GenericTextPerCharExtents(); -extern int _XmbGenericDrawString(), _XwcGenericDrawString(), - _Xutf8GenericDrawString(); -extern void _XmbGenericDrawImageString(), _XwcGenericDrawImageString(), - _Xutf8GenericDrawImageString(); - -extern void _XlcDbg_printValue (const char *str, char **value, int num); -#endif - /* For VW/UDC start */ static FontData @@ -635,34 +609,6 @@ is_match_charset( return False; } -#if 0 -static char * -get_font_name_from_list( - XOC oc, - char *pattern, - FontData font_data) -{ - char **list, *name = (char *)NULL, *fname; - int count = 0, i; - - list = XListFonts(oc->core.om->core.display, pattern, MAXFONTS, &count); - if (list == NULL) - return NULL; - - for (i = 0; i < count; i++) { - fname = list[i]; - if(is_match_charset(font_data, fname) == True) { - name = strdup(fname); - break; - } - } - - XFreeFontNames(list); - - return name; -} -#endif - static int parse_all_name( XOC oc, diff --git a/nx-X11/lib/X11/omImText.c b/nx-X11/lib/X11/omImText.c index 1bc08bc25..9cfb5497d 100644 --- a/nx-X11/lib/X11/omImText.c +++ b/nx-X11/lib/X11/omImText.c @@ -29,10 +29,6 @@ #include "Xlibint.h" #include "XomGeneric.h" -#if 0 -extern int _XomGenericTextExtents(), _XomGenericDrawString(); -#endif - #define GET_VALUE_MASK (GCFunction | GCForeground | GCBackground | GCFillStyle) #define SET_VALUE_MASK (GCFunction | GCForeground | GCFillStyle) -- cgit v1.2.3 From f7254c69f00eb41fd3b8a78c6ae5d09fcfe1c01a Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 09:20:55 -0800 Subject: Use strdup instead of Xmalloc+strcpy in _XDefaultOpenIM Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultIMIF.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultIMIF.c b/nx-X11/lib/X11/XDefaultIMIF.c index 4e75fa0b4..7c32ce296 100644 --- a/nx-X11/lib/X11/XDefaultIMIF.c +++ b/nx-X11/lib/X11/XDefaultIMIF.c @@ -202,9 +202,8 @@ _XDefaultOpenIM( } } #undef MODIFIER - if ((im->core.im_name = Xmalloc(i+1)) == NULL) + if ((im->core.im_name = strdup(buf)) == NULL) goto Error; - strcpy(im->core.im_name, buf); im->methods = (XIMMethods)&local_im_methods; im->core.lcd = lcd; -- cgit v1.2.3 From c00196d2d178b4ed1866c18ccab76cbb941df6f0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 09:46:31 -0800 Subject: XDefaultOMIF: replace strlen+Xmalloc+strcpy with strdup Code seems to have been originally written to handle appending multiple strings, but only ever operates on a single string. Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index f9469feca..f7b1b1d8c 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -237,13 +237,12 @@ init_core_part( FontSet font_set; XFontStruct **font_struct_list; char **font_name_list, *font_name_buf; - int count, length; + int count; font_set = gen->font_set; - count = length = 0; + count = 0; if (font_set->font_name != NULL) { - length += strlen(font_set->font_name) + 1; count++; } if (count == 0) @@ -257,7 +256,7 @@ init_core_part( if (font_name_list == NULL) goto err; - font_name_buf = Xmalloc(length); + font_name_buf = strdup(font_set->font_name); if (font_name_buf == NULL) goto err; @@ -273,7 +272,6 @@ init_core_part( *font_struct_list++ = font_set->font; else *font_struct_list++ = font_set->info; - strcpy(font_name_buf, font_set->font_name); Xfree(font_set->font_name); *font_name_list++ = font_set->font_name = font_name_buf; font_name_buf += strlen(font_name_buf) + 1; @@ -482,13 +480,12 @@ set_missing_list( XOCGenericPart *gen = XOC_GENERIC(oc); FontSet font_set; char **charset_list, *charset_buf; - int count, length; + int count; font_set = gen->font_set; - count = length = 0; + count = 0; if (!font_set->info && !font_set->font) { - length += strlen(font_set->font_data->name) + 1; count++; } @@ -499,7 +496,7 @@ set_missing_list( if (charset_list == NULL) return False; - charset_buf = Xmalloc(length); + charset_buf = strdup(font_set->font_data->name); if (charset_buf == NULL) { Xfree(charset_list); return False; @@ -510,7 +507,6 @@ set_missing_list( font_set = gen->font_set; if (!font_set->info && !font_set->font) { - strcpy(charset_buf, font_set->font_data->name); *charset_list++ = charset_buf; charset_buf += strlen(charset_buf) + 1; } @@ -1058,7 +1054,7 @@ init_om( char **required_list; XOrientation *orientation; char *bufptr; - int i, count, length = 0; + int i, count; count = XlcNumber(supported_charset_list); @@ -1078,14 +1074,12 @@ init_om( return False; } - length += strlen(data->font_data->name) + 1; - /* required charset list */ required_list = Xmalloc(sizeof(char *)); if (required_list == NULL) return False; - bufptr = Xmalloc(length); + bufptr = strdup(data->font_data->name); if (bufptr == NULL) { Xfree(required_list); return False; @@ -1096,7 +1090,6 @@ init_om( data = gen->data; - strcpy(bufptr, data->font_data->name); *required_list++ = bufptr; bufptr += strlen(bufptr) + 1; -- cgit v1.2.3 From d980be3c2c3c39bc4db64388b992d4535cbffcd6 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 10:00:22 -0800 Subject: XDefaultOMIF: additional code simplification Don't need to test for a case that we already returned for, don't need to store a count that will only ever be 1 if we didn't return, don't need to increment pointers to allow storing more than one item when we can only ever possibly do one. Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index f7b1b1d8c..e38739a0a 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -237,15 +237,10 @@ init_core_part( FontSet font_set; XFontStruct **font_struct_list; char **font_name_list, *font_name_buf; - int count; font_set = gen->font_set; - count = 0; - if (font_set->font_name != NULL) { - count++; - } - if (count == 0) + if (font_set->font_name == NULL) return False; font_struct_list = Xmalloc(sizeof(XFontStruct *)); @@ -264,18 +259,13 @@ init_core_part( oc->core.font_info.font_name_list = font_name_list; oc->core.font_info.font_struct_list = font_struct_list; - font_set = gen->font_set; - - if (font_set->font_name != NULL) { - font_set->id = 1; - if (font_set->font) - *font_struct_list++ = font_set->font; - else - *font_struct_list++ = font_set->info; - Xfree(font_set->font_name); - *font_name_list++ = font_set->font_name = font_name_buf; - font_name_buf += strlen(font_name_buf) + 1; - } + font_set->id = 1; + if (font_set->font) + *font_struct_list = font_set->font; + else + *font_struct_list = font_set->info; + Xfree(font_set->font_name); + *font_name_list = font_set->font_name = font_name_buf; set_fontset_extents(oc); @@ -480,16 +470,10 @@ set_missing_list( XOCGenericPart *gen = XOC_GENERIC(oc); FontSet font_set; char **charset_list, *charset_buf; - int count; font_set = gen->font_set; - count = 0; - - if (!font_set->info && !font_set->font) { - count++; - } - if (count == 0) + if (font_set->info == NULL || font_set->font == NULL) return True; charset_list = Xmalloc(sizeof(char *)); @@ -504,12 +488,8 @@ set_missing_list( oc->core.missing_list.charset_list = charset_list; - font_set = gen->font_set; + *charset_list = charset_buf; - if (!font_set->info && !font_set->font) { - *charset_list++ = charset_buf; - charset_buf += strlen(charset_buf) + 1; - } return True; } @@ -1090,8 +1070,7 @@ init_om( data = gen->data; - *required_list++ = bufptr; - bufptr += strlen(bufptr) + 1; + *required_list = bufptr; /* orientation list */ orientation = Xmalloc(sizeof(XOrientation)); -- cgit v1.2.3 From 2874fd14b84994762f41f1f13dac5c1b09bed095 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 10:05:42 -0800 Subject: XDefaultOMIF: Remove comments referring to ancient Sun bug ids Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index e38739a0a..e61344d31 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -369,11 +369,7 @@ parse_fontname( found_num++; goto found; } -/* -1266793 -Limit the length of the string copy to prevent stack corruption. - strcpy(buf, pattern); -*/ + strncpy(buf, pattern, BUFSIZ); buf[BUFSIZ-1] = '\0'; length = strlen(buf); @@ -425,11 +421,6 @@ Limit the length of the string copy to prevent stack corruption. for ( ; font_data_count-- > 0; font_data++) { if (append_charset) { -/* -1266793 -Limit the length of the string copy to prevent stack corruption. - strcpy(last, font_data->name); -*/ strncpy(last, font_data->name, BUFSIZ - length); buf[BUFSIZ-1] = '\0'; } @@ -1015,11 +1006,7 @@ add_data( static _Xconst char *supported_charset_list[] = { "ISO8859-1", -/* fix for bug4332979 */ "adobe-fontspecific", -/* fix for bug4237353: "JISX0201.1976-0" entry should be removed from - supported_charset_list because it is not a supported_charset for C locale - "JISX0201.1976-0", */ "SUNOLCURSOR-1", "SUNOLGLYPH-1" }; -- cgit v1.2.3 From c9ebd122fb9b7c28abac21b83ade9fee365a882f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 10:19:25 -0800 Subject: XlcDL.c: replace strcpy+strcat sequences with snprintf Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index a23603865..519103b86 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -267,18 +267,20 @@ __lc_path(const char *dl_name, const char *lc_dir) char *slash_p; slash_p = strrchr(lc_dir, '/'); *slash_p = '\0'; - strcpy(path, lc_dir); strcat(path, "/"); #if defined POSTLOCALELIBDIR - strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); + snprintf(path, len + 1, "%s/%s/%s.so.2", + lc_dir, POSTLOCALELIBDIR, dl_name); +#else + snprintf(path, len + 1, "%s/%s.so.2", lc_dir, dl_name); #endif - strcat(path, dl_name); strcat(path, ".so.2"); *slash_p = '/'; } else { - strcpy(path, lc_dir); strcat(path, "/"); #if defined POSTLOCALELIBDIR - strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); + snprintf(path, len + 1, "%s/%s/%s.so.2", + lc_dir, POSTLOCALELIBDIR, dl_name); +#else + snprintf(path, len + 1, "%s/%s.so.2", lc_dir, dl_name); #endif - strcat(path, dl_name); strcat(path, ".so.2"); } return path; } -- cgit v1.2.3 From 7a1fc175980837ccc25cdd8582846a3b44838505 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 10:21:04 -0800 Subject: XlcDL.c: reduce code duplication Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XlcDL.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XlcDL.c b/nx-X11/lib/X11/XlcDL.c index 519103b86..bc71900a0 100644 --- a/nx-X11/lib/X11/XlcDL.c +++ b/nx-X11/lib/X11/XlcDL.c @@ -249,6 +249,7 @@ __lc_path(const char *dl_name, const char *lc_dir) { char *path; size_t len; + char *slash_p; /* * reject this for possible security issue @@ -264,24 +265,21 @@ __lc_path(const char *dl_name, const char *lc_dir) path = Xmalloc(len + 1); if (strchr(dl_name, '/') != NULL) { - char *slash_p; slash_p = strrchr(lc_dir, '/'); *slash_p = '\0'; + } else + slash_p = NULL; + #if defined POSTLOCALELIBDIR - snprintf(path, len + 1, "%s/%s/%s.so.2", - lc_dir, POSTLOCALELIBDIR, dl_name); + snprintf(path, len + 1, "%s/%s/%s.so.2", + lc_dir, POSTLOCALELIBDIR, dl_name); #else - snprintf(path, len + 1, "%s/%s.so.2", lc_dir, dl_name); + snprintf(path, len + 1, "%s/%s.so.2", lc_dir, dl_name); #endif + + if (slash_p != NULL) *slash_p = '/'; - } else { -#if defined POSTLOCALELIBDIR - snprintf(path, len + 1, "%s/%s/%s.so.2", - lc_dir, POSTLOCALELIBDIR, dl_name); -#else - snprintf(path, len + 1, "%s/%s.so.2", lc_dir, dl_name); -#endif - } + return path; } -- cgit v1.2.3 From 50192b720a1f0ae6c4dd97d44e3c54d43ab7358b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 18:03:41 -0800 Subject: lcPubWrap: replace malloc(strlen) + strcpy with strdup Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcPubWrap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/lcPubWrap.c b/nx-X11/lib/X11/lcPubWrap.c index d1096d570..3119918c6 100644 --- a/nx-X11/lib/X11/lcPubWrap.c +++ b/nx-X11/lib/X11/lcPubWrap.c @@ -78,10 +78,9 @@ _XlcCreateLC( return (XLCd) NULL; if (lcd->core->name == NULL) { - lcd->core->name = Xmalloc(strlen(name) + 1); + lcd->core->name = strdup(name); if (lcd->core->name == NULL) goto err; - strcpy(lcd->core->name, name); } if (lcd->methods == NULL) -- cgit v1.2.3 From a3759f323a476deee8347ac3b88df1b426d7cc1a Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Thu, 21 Jan 2016 11:54:19 +0100 Subject: XKB: fix XkbGetKeyboardByName with Xming server XkbGetKeyboardByName relies on flags to read the data from the server. If the X server sends us the wrong flags or if a subreply is smaller than it should be, XkbGetKeyboardByName will not read all the available data and leave data in the buffer, which will cause the next _XReply() to fail with: [xcb] Extra reply data still left in queue [xcb] This is most likely caused by a broken X extension library [xcb] Aborting, sorry about that. xcb_io.c:576: _XReply: Assertion `!xcb_xlib_extra_reply_data_left' failed. Aborted Check if there is some extra data left at the end of XkbGetKeyboardByName() and discard that data if any is found. Many thanks to Peter Hutterer for finding the root cause of the issue and Adam Jackson for helping with the analysis! Signed-off-by: Olivier Fourdan Reviewed-by: Daniel Stone Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XKBGetByName.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/XKBGetByName.c b/nx-X11/lib/X11/XKBGetByName.c index 4a6ca9392..c673781ed 100644 --- a/nx-X11/lib/X11/XKBGetByName.c +++ b/nx-X11/lib/X11/XKBGetByName.c @@ -44,7 +44,7 @@ XkbGetKeyboardByName(Display *dpy, { register xkbGetKbdByNameReq *req; xkbGetKbdByNameReply rep; - int len, extraLen; + int len, extraLen = 0; char *str; XkbDescPtr xkb; int mapLen, codesLen, typesLen, compatLen; @@ -204,12 +204,16 @@ XkbGetKeyboardByName(Display *dpy, if (status != Success) goto BAILOUT; } + if (extraLen > 0) + goto BAILOUT; UnlockDisplay(dpy); SyncHandle(); return xkb; BAILOUT: if (xkb != NULL) XkbFreeKeyboard(xkb, XkbAllComponentsMask, xTrue); + if (extraLen > 0) + _XEatData(dpy, extraLen); UnlockDisplay(dpy); SyncHandle(); return NULL; -- cgit v1.2.3 From de4047722a243f1be2212d1af6002247c5c3c733 Mon Sep 17 00:00:00 2001 From: Dominik Muth Date: Thu, 26 Mar 2015 07:52:58 +0100 Subject: Xlib.h: Fix macros imitating C functions. The basic rule "put parantheses around macro parameters" should be observed where possible. Otherwise code like ConnectionNumber(foo = bar); fails to compile. (It obviously passes if ConnectionNumber is a C function.) There are several other macros amended for the same reason. This bug appeared while building http://ioccc.org/1993/cmills.c, so historically it was not present. Signed-off-by: Dominik Muth Reviewed-by: Alan Coopersmith Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/Xlib.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/Xlib.h b/nx-X11/lib/X11/Xlib.h index 5f2368800..1ac1ef181 100644 --- a/nx-X11/lib/X11/Xlib.h +++ b/nx-X11/lib/X11/Xlib.h @@ -89,39 +89,39 @@ typedef char *XPointer; #define QueuedAfterReading 1 #define QueuedAfterFlush 2 -#define ConnectionNumber(dpy) (((_XPrivDisplay)dpy)->fd) +#define ConnectionNumber(dpy) (((_XPrivDisplay)(dpy))->fd) #define RootWindow(dpy, scr) (ScreenOfDisplay(dpy,scr)->root) -#define DefaultScreen(dpy) (((_XPrivDisplay)dpy)->default_screen) +#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) #define DefaultRootWindow(dpy) (ScreenOfDisplay(dpy,DefaultScreen(dpy))->root) #define DefaultVisual(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_visual) #define DefaultGC(dpy, scr) (ScreenOfDisplay(dpy,scr)->default_gc) #define BlackPixel(dpy, scr) (ScreenOfDisplay(dpy,scr)->black_pixel) #define WhitePixel(dpy, scr) (ScreenOfDisplay(dpy,scr)->white_pixel) #define AllPlanes ((unsigned long)~0L) -#define QLength(dpy) (((_XPrivDisplay)dpy)->qlen) +#define QLength(dpy) (((_XPrivDisplay)(dpy))->qlen) #define DisplayWidth(dpy, scr) (ScreenOfDisplay(dpy,scr)->width) #define DisplayHeight(dpy, scr) (ScreenOfDisplay(dpy,scr)->height) #define DisplayWidthMM(dpy, scr)(ScreenOfDisplay(dpy,scr)->mwidth) #define DisplayHeightMM(dpy, scr)(ScreenOfDisplay(dpy,scr)->mheight) #define DisplayPlanes(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_depth) #define DisplayCells(dpy, scr) (DefaultVisual(dpy,scr)->map_entries) -#define ScreenCount(dpy) (((_XPrivDisplay)dpy)->nscreens) -#define ServerVendor(dpy) (((_XPrivDisplay)dpy)->vendor) -#define ProtocolVersion(dpy) (((_XPrivDisplay)dpy)->proto_major_version) -#define ProtocolRevision(dpy) (((_XPrivDisplay)dpy)->proto_minor_version) -#define VendorRelease(dpy) (((_XPrivDisplay)dpy)->release) -#define DisplayString(dpy) (((_XPrivDisplay)dpy)->display_name) +#define ScreenCount(dpy) (((_XPrivDisplay)(dpy))->nscreens) +#define ServerVendor(dpy) (((_XPrivDisplay)(dpy))->vendor) +#define ProtocolVersion(dpy) (((_XPrivDisplay)(dpy))->proto_major_version) +#define ProtocolRevision(dpy) (((_XPrivDisplay)(dpy))->proto_minor_version) +#define VendorRelease(dpy) (((_XPrivDisplay)(dpy))->release) +#define DisplayString(dpy) (((_XPrivDisplay)(dpy))->display_name) #define DefaultDepth(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_depth) #define DefaultColormap(dpy, scr)(ScreenOfDisplay(dpy,scr)->cmap) -#define BitmapUnit(dpy) (((_XPrivDisplay)dpy)->bitmap_unit) -#define BitmapBitOrder(dpy) (((_XPrivDisplay)dpy)->bitmap_bit_order) -#define BitmapPad(dpy) (((_XPrivDisplay)dpy)->bitmap_pad) -#define ImageByteOrder(dpy) (((_XPrivDisplay)dpy)->byte_order) -#define NextRequest(dpy) (((_XPrivDisplay)dpy)->request + 1) -#define LastKnownRequestProcessed(dpy) (((_XPrivDisplay)dpy)->last_request_read) +#define BitmapUnit(dpy) (((_XPrivDisplay)(dpy))->bitmap_unit) +#define BitmapBitOrder(dpy) (((_XPrivDisplay)(dpy))->bitmap_bit_order) +#define BitmapPad(dpy) (((_XPrivDisplay)(dpy))->bitmap_pad) +#define ImageByteOrder(dpy) (((_XPrivDisplay)(dpy))->byte_order) +#define NextRequest(dpy) (((_XPrivDisplay)(dpy))->request + 1) +#define LastKnownRequestProcessed(dpy) (((_XPrivDisplay)(dpy))->last_request_read) /* macros for screen oriented applications (toolkit) */ -#define ScreenOfDisplay(dpy, scr)(&((_XPrivDisplay)dpy)->screens[scr]) +#define ScreenOfDisplay(dpy, scr)(&((_XPrivDisplay)(dpy))->screens[scr]) #define DefaultScreenOfDisplay(dpy) ScreenOfDisplay(dpy,DefaultScreen(dpy)) #define DisplayOfScreen(s) ((s)->display) #define RootWindowOfScreen(s) ((s)->root) @@ -1010,7 +1010,7 @@ typedef union _XEvent { } XEvent; #endif -#define XAllocID(dpy) ((*((_XPrivDisplay)dpy)->resource_alloc)((dpy))) +#define XAllocID(dpy) ((*((_XPrivDisplay)(dpy))->resource_alloc)((dpy))) /* * per character font metric information. -- cgit v1.2.3 From 327d2cc6047683abb36cab25a90633c7b8d9b036 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 6 Feb 2016 13:01:25 -0800 Subject: xcms: use size_t for strlen/sizeof values instead of converting to int & back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes gcc warnings of the form: IdOfPr.c: In function ‘XcmsFormatOfPrefix’: IdOfPr.c:69:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if ((len = strlen(prefix)) >= sizeof(string_buf)) { ^ IdOfPr.c:83:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (len >= sizeof(string_buf)) Xfree(string_lowered); ^ IdOfPr.c:97:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (len >= sizeof(string_buf)) Xfree(string_lowered); ^ IdOfPr.c:104:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (len >= sizeof(string_buf)) Xfree(string_lowered); ^ Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/IdOfPr.c | 2 +- nx-X11/lib/X11/cmsColNm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/IdOfPr.c b/nx-X11/lib/X11/IdOfPr.c index e15f34fec..9f43dd387 100644 --- a/nx-X11/lib/X11/IdOfPr.c +++ b/nx-X11/lib/X11/IdOfPr.c @@ -61,7 +61,7 @@ XcmsFormatOfPrefix(char *prefix) XcmsColorSpace **papColorSpaces; char string_buf[64]; char *string_lowered; - int len; + size_t len; /* * While copying prefix to string_lowered, convert to lowercase diff --git a/nx-X11/lib/X11/cmsColNm.c b/nx-X11/lib/X11/cmsColNm.c index bd5c253fe..0e96e13a3 100644 --- a/nx-X11/lib/X11/cmsColNm.c +++ b/nx-X11/lib/X11/cmsColNm.c @@ -198,7 +198,7 @@ _XcmsParseColorString( XcmsColorSpace *pColorSpace; char string_buf[64]; char *string_lowered; - int len; + size_t len; int res; if (ccc == NULL) { -- cgit v1.2.3 From 8d8d5cfd8c4f3d25c85d6ed60298f3aa917651eb Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 6 Feb 2016 13:32:44 -0800 Subject: xcms: use unsigned indexes when looping through unsigned values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clears many gcc warnings of the form: uvY.c: In function ‘XcmsCIEuvYToCIEXYZ’: uvY.c:263:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (i = 0; i < nColors; i++, pColor++) { ^ Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/HVC.c | 4 ++-- nx-X11/lib/X11/LRGB.c | 2 +- nx-X11/lib/X11/Lab.c | 4 ++-- nx-X11/lib/X11/Luv.c | 4 ++-- nx-X11/lib/X11/uvY.c | 4 ++-- nx-X11/lib/X11/xyY.c | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/HVC.c b/nx-X11/lib/X11/HVC.c index f790b1335..c6bf2cda4 100644 --- a/nx-X11/lib/X11/HVC.c +++ b/nx-X11/lib/X11/HVC.c @@ -349,7 +349,7 @@ XcmsTekHVCToCIEuvY( XcmsCIEuvY uvY_return; XcmsFloat tempHue, u, v; XcmsFloat tmpVal; - register int i; + unsigned int i; /* * Check arguments @@ -468,7 +468,7 @@ XcmsCIEuvYToTekHVC( XcmsColor *pColor = pColors_in_out; XcmsColor whitePt; XcmsTekHVC HVC_return; - register int i; + unsigned int i; /* * Check arguments diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index f8e0d66fb..55e3aaade 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -966,7 +966,7 @@ _XcmsGetTableType1( * */ { - int count; + unsigned int count; unsigned int max_index; IntensityRec *pIRec; diff --git a/nx-X11/lib/X11/Lab.c b/nx-X11/lib/X11/Lab.c index 642886ec2..6f7075643 100644 --- a/nx-X11/lib/X11/Lab.c +++ b/nx-X11/lib/X11/Lab.c @@ -251,7 +251,7 @@ XcmsCIELabToCIEXYZ( XcmsCIEXYZ XYZ_return; XcmsFloat tmpFloat, tmpL; XcmsColor whitePt; - int i; + unsigned int i; XcmsColor *pColor = pColors_in_out; /* @@ -354,7 +354,7 @@ XcmsCIEXYZToCIELab( XcmsCIELab Lab_return; XcmsFloat fX_Xn, fY_Yn, fZ_Zn; XcmsColor whitePt; - int i; + unsigned int i; XcmsColor *pColor = pColors_in_out; /* diff --git a/nx-X11/lib/X11/Luv.c b/nx-X11/lib/X11/Luv.c index 8af5ee98b..2bce977ea 100644 --- a/nx-X11/lib/X11/Luv.c +++ b/nx-X11/lib/X11/Luv.c @@ -251,7 +251,7 @@ XcmsCIELuvToCIEuvY( XcmsColor whitePt; XcmsCIEuvY uvY_return; XcmsFloat tmpVal; - register int i; + unsigned int i; /* * Check arguments @@ -343,7 +343,7 @@ XcmsCIEuvYToCIELuv( XcmsColor whitePt; XcmsCIELuv Luv_return; XcmsFloat tmpVal; - register int i; + unsigned int i; /* * Check arguments diff --git a/nx-X11/lib/X11/uvY.c b/nx-X11/lib/X11/uvY.c index 60603a950..0788b7542 100644 --- a/nx-X11/lib/X11/uvY.c +++ b/nx-X11/lib/X11/uvY.c @@ -243,7 +243,7 @@ XcmsCIEuvYToCIEXYZ( { XcmsCIEXYZ XYZ_return; XcmsColor whitePt; - int i; + unsigned int i; XcmsColor *pColor = pColors_in_out; XcmsFloat div, x, y, z, Y; @@ -358,7 +358,7 @@ XcmsCIEXYZToCIEuvY( { XcmsCIEuvY uvY_return; XcmsColor whitePt; - int i; + unsigned int i; XcmsColor *pColor = pColors_in_out; XcmsFloat div; diff --git a/nx-X11/lib/X11/xyY.c b/nx-X11/lib/X11/xyY.c index 67959b048..e85b8d249 100644 --- a/nx-X11/lib/X11/xyY.c +++ b/nx-X11/lib/X11/xyY.c @@ -253,7 +253,7 @@ XcmsCIExyYToCIEXYZ( XcmsCIEXYZ XYZ_return; XcmsFloat div; /* temporary storage in case divisor is zero */ XcmsFloat u, v, x, y, z; /* temporary storage */ - register int i; + unsigned int i; /* * Check arguments @@ -359,7 +359,7 @@ XcmsCIEXYZToCIExyY( XcmsColor *pColor = pColors_in_out; XcmsCIExyY xyY_return; XcmsFloat div; /* temporary storage in case divisor is zero */ - register int i; + unsigned int i; /* * Check arguments -- cgit v1.2.3 From 68e3ee67c07282c11cd144fbdb767b41a6dacc4e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 6 Feb 2016 14:18:32 -0800 Subject: xcms: use size_t for pointer offsets passed to strncmp instead of converting to int and back Fixes clang warnings of the form: HVC.c:190:43: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion] if (strncmp(spec, _XcmsTekHVC_prefix, n) != 0) { ~~~~~~~ Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/HVC.c | 4 ++-- nx-X11/lib/X11/LRGB.c | 4 ++-- nx-X11/lib/X11/XYZ.c | 4 ++-- nx-X11/lib/X11/cmsColNm.c | 4 ++-- nx-X11/lib/X11/uvY.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/HVC.c b/nx-X11/lib/X11/HVC.c index c6bf2cda4..98d7142c3 100644 --- a/nx-X11/lib/X11/HVC.c +++ b/nx-X11/lib/X11/HVC.c @@ -176,13 +176,13 @@ TekHVC_ParseString( * XcmsSuccess if valid. */ { - int n; + size_t n; char *pchar; if ((pchar = strchr(spec, ':')) == NULL) { return(XcmsFailure); } - n = (int)(pchar - spec); + n = (size_t)(pchar - spec); /* * Check for proper prefix. diff --git a/nx-X11/lib/X11/LRGB.c b/nx-X11/lib/X11/LRGB.c index 55e3aaade..4bfa3cfb1 100644 --- a/nx-X11/lib/X11/LRGB.c +++ b/nx-X11/lib/X11/LRGB.c @@ -1405,13 +1405,13 @@ XcmsLRGB_RGBi_ParseString( * 0 if failed, non-zero otherwise. */ { - int n; + size_t n; char *pchar; if ((pchar = strchr(spec, ':')) == NULL) { return(XcmsFailure); } - n = (int)(pchar - spec); + n = (size_t)(pchar - spec); /* * Check for proper prefix. diff --git a/nx-X11/lib/X11/XYZ.c b/nx-X11/lib/X11/XYZ.c index 1245622b7..826565773 100644 --- a/nx-X11/lib/X11/XYZ.c +++ b/nx-X11/lib/X11/XYZ.c @@ -120,13 +120,13 @@ CIEXYZ_ParseString( * RETURNS */ { - int n; + size_t n; char *pchar; if ((pchar = strchr(spec, ':')) == NULL) { return(XcmsFailure); } - n = (int)(pchar - spec); + n = (size_t)(pchar - spec); /* * Check for proper prefix. diff --git a/nx-X11/lib/X11/cmsColNm.c b/nx-X11/lib/X11/cmsColNm.c index 0e96e13a3..e43a829f2 100644 --- a/nx-X11/lib/X11/cmsColNm.c +++ b/nx-X11/lib/X11/cmsColNm.c @@ -126,13 +126,13 @@ _XcmsColorSpaceOfString( */ { XcmsColorSpace **papColorSpaces; - int n; + size_t n; char *pchar; if ((pchar = strchr(color_string, ':')) == NULL) { return(XcmsFailure); } - n = (int)(pchar - color_string); + n = (size_t)(pchar - color_string); if (ccc == NULL) { return(NULL); diff --git a/nx-X11/lib/X11/uvY.c b/nx-X11/lib/X11/uvY.c index 0788b7542..19e6c5232 100644 --- a/nx-X11/lib/X11/uvY.c +++ b/nx-X11/lib/X11/uvY.c @@ -135,13 +135,13 @@ CIEuvY_ParseString( * 0 if failed, non-zero otherwise. */ { - int n; + size_t n; char *pchar; if ((pchar = strchr(spec, ':')) == NULL) { return(XcmsFailure); } - n = (int)(pchar - spec); + n = (size_t)(pchar - spec); /* * Check for proper prefix. -- cgit v1.2.3 From b17557f9f0cd0ba992415411040e20390fa881f0 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 25 Sep 2016 21:22:57 +0200 Subject: The validation of server responses avoids out of boundary accesses. v2: FontNames.c return a NULL list whenever a single length field from the server is incohent. Signed-off-by: Tobias Stoeckmann Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/FontNames.c | 23 +++++++++++++++++------ nx-X11/lib/X11/ListExt.c | 12 ++++++++---- nx-X11/lib/X11/ModMap.c | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/FontNames.c b/nx-X11/lib/X11/FontNames.c index 21dcafea1..e55f338ca 100644 --- a/nx-X11/lib/X11/FontNames.c +++ b/nx-X11/lib/X11/FontNames.c @@ -66,7 +66,7 @@ int *actualCount) /* RETURN */ if (rep.nFonts) { flist = Xmalloc (rep.nFonts * sizeof(char *)); - if (rep.length < (INT_MAX >> 2)) { + if (rep.length > 0 && rep.length < (INT_MAX >> 2)) { rlen = rep.length << 2; ch = Xmalloc(rlen + 1); /* +1 to leave room for last null-terminator */ @@ -93,11 +93,22 @@ int *actualCount) /* RETURN */ if (ch + length < chend) { flist[i] = ch + 1; /* skip over length */ ch += length + 1; /* find next length ... */ - length = *(unsigned char *)ch; - *ch = '\0'; /* and replace with null-termination */ - count++; - } else - flist[i] = NULL; + if (ch <= chend) { + length = *(unsigned char *)ch; + *ch = '\0'; /* and replace with null-termination */ + count++; + } else { + Xfree(flist); + flist = NULL; + count = 0; + break; + } + } else { + Xfree(flist); + flist = NULL; + count = 0; + break; + } } } *actualCount = count; diff --git a/nx-X11/lib/X11/ListExt.c b/nx-X11/lib/X11/ListExt.c index be6b989a3..0516e4596 100644 --- a/nx-X11/lib/X11/ListExt.c +++ b/nx-X11/lib/X11/ListExt.c @@ -55,7 +55,7 @@ char **XListExtensions( if (rep.nExtensions) { list = Xmalloc (rep.nExtensions * sizeof (char *)); - if (rep.length < (INT_MAX >> 2)) { + if (rep.length > 0 && rep.length < (INT_MAX >> 2)) { rlen = rep.length << 2; ch = Xmalloc (rlen + 1); /* +1 to leave room for last null-terminator */ @@ -80,9 +80,13 @@ char **XListExtensions( if (ch + length < chend) { list[i] = ch+1; /* skip over length */ ch += length + 1; /* find next length ... */ - length = *ch; - *ch = '\0'; /* and replace with null-termination */ - count++; + if (ch <= chend) { + length = *ch; + *ch = '\0'; /* and replace with null-termination */ + count++; + } else { + list[i] = NULL; + } } else list[i] = NULL; } diff --git a/nx-X11/lib/X11/ModMap.c b/nx-X11/lib/X11/ModMap.c index a809aa291..49a5d08e8 100644 --- a/nx-X11/lib/X11/ModMap.c +++ b/nx-X11/lib/X11/ModMap.c @@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy) GetEmptyReq(GetModifierMapping, req); (void) _XReply (dpy, (xReply *)&rep, 0, xFalse); - if (rep.length < (INT_MAX >> 2)) { + if (rep.length < (INT_MAX >> 2) && + (rep.length >> 1) == rep.numKeyPerModifier) { nbytes = (unsigned long)rep.length << 2; res = Xmalloc(sizeof (XModifierKeymap)); if (res) -- cgit v1.2.3 From 70e9d346fe34af127d2c827c3678e53d0f4312ae Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 25 Sep 2016 21:25:25 +0200 Subject: Validation of server responses in XGetImage() Check if enough bytes were received for specified image type and geometry. Otherwise GetPixel and other functions could trigger an out of boundary read later on. Signed-off-by: Tobias Stoeckmann Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/GetImage.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/X11/GetImage.c b/nx-X11/lib/X11/GetImage.c index 59fb45eb1..d80f6715f 100644 --- a/nx-X11/lib/X11/GetImage.c +++ b/nx-X11/lib/X11/GetImage.c @@ -59,6 +59,7 @@ XImage *XGetImage ( char *data; unsigned long nbytes; XImage *image; + int planes; LockDisplay(dpy); GetReq (GetImage, req); /* @@ -91,18 +92,28 @@ XImage *XGetImage ( return (XImage *) NULL; } _XReadPad (dpy, data, nbytes); - if (format == XYPixmap) - image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual), - Ones (plane_mask & - (((unsigned long)0xFFFFFFFF) >> (32 - rep.depth))), - format, 0, data, width, height, dpy->bitmap_pad, 0); - else /* format == ZPixmap */ - image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual), - rep.depth, ZPixmap, 0, data, width, height, - _XGetScanlinePad(dpy, (int) rep.depth), 0); + if (format == XYPixmap) { + image = XCreateImage(dpy, _XVIDtoVisual(dpy, rep.visual), + Ones (plane_mask & + (((unsigned long)0xFFFFFFFF) >> (32 - rep.depth))), + format, 0, data, width, height, dpy->bitmap_pad, 0); + planes = image->depth; + } else { /* format == ZPixmap */ + image = XCreateImage (dpy, _XVIDtoVisual(dpy, rep.visual), + rep.depth, ZPixmap, 0, data, width, height, + _XGetScanlinePad(dpy, (int) rep.depth), 0); + planes = 1; + } if (!image) Xfree(data); + if (planes < 1 || image->height < 1 || image->bytes_per_line < 1 || + INT_MAX / image->height <= image->bytes_per_line || + INT_MAX / planes <= image->height * image->bytes_per_line || + nbytes < planes * image->height * image->bytes_per_line) { + XDestroyImage(image); + image = NULL; + } UnlockDisplay(dpy); SyncHandle(); return (image); -- cgit v1.2.3