diff options
author | marha <marha@users.sourceforge.net> | 2013-08-26 09:04:58 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-08-26 09:04:58 +0200 |
commit | 5ee5b91b019005aa27273dff01388a68c12be293 (patch) | |
tree | d2db8b0d1533d2eea8bfe77f8a6b3d52fa3f633e /libX11/src/xkb/XKBAlloc.c | |
parent | 854ec4da20ddff9b830be0a7d5b81d8cb4774132 (diff) | |
download | vcxsrv-5ee5b91b019005aa27273dff01388a68c12be293.tar.gz vcxsrv-5ee5b91b019005aa27273dff01388a68c12be293.tar.bz2 vcxsrv-5ee5b91b019005aa27273dff01388a68c12be293.zip |
xserver mesa fontconfig libX11 libxcb libxcb/xcb-proto xkeyboard-config git update 26 Aug 2013
xserver commit e01a3f65d3e6d92f92ef2992b338cc9625bde082
libxcb commit c52f2891b43ae77008f63700982f800371458f4d
libxcb/xcb-proto commit bd7708ac1037e647b094fa7440ebb6171b9bc75f
xkeyboard-config commit 77026e8c59cc64856180452c5f89be86928fea7c
libX11 commit e9b14d10d0258bfcc273ff8bc84cd349dccda62c
libXdmcp commit 66514a4af7eaa47e8718434356d7efce95e570cf
libXext commit 7378d4bdbd33ed49ed6cfa5c4f73d7527982aab4
libfontenc commit 3acba630d8b57084f7e92c15732408711ed5137a
libXinerama commit 6e1d1dc328ba8162bba2f4694e7f3c706a1491ff
libXau commit 899790011304c4029e15abf410e49ce7cec17e0a
xkbcomp commit 0ebdf47fd4bc434ac3d2339544c022a869510738
pixman commit 3518a0dafa63098d41e466f73d105b7e3e4b12de
xextproto commit f27fcc99d1cf935cc289933326f7d3baacd5107a
randrproto commit ca7cc541c2e43e6c784df19b4583ac35829d2f72
glproto commit 8e3407e02980d088e20041e79bdcdd3737e7827e
mkfontscale commit f48de13423c7300f4da9f61993b624426b38ddc0
xwininfo commit ba0d1b0da21d2dbdd81098ed5778f3792b472e13
libXft commit c5e760a239afc62a1c75e0509868e35957c8df52
libXmu commit d5dac08d65c4865f311cb62c161dbb1300eecd11
libxtrans commit f6a161f2a003f4da0a2e414b4faa0ee0de0c01f0
fontconfig commit fba9efecd2ef3aca84e0a4806899c09ba95f4c19
mesa commit 7fa18774bd9d0e97a82ee9b7dfce8fc5a1041c3a
Diffstat (limited to 'libX11/src/xkb/XKBAlloc.c')
-rw-r--r-- | libX11/src/xkb/XKBAlloc.c | 642 |
1 files changed, 326 insertions, 316 deletions
diff --git a/libX11/src/xkb/XKBAlloc.c b/libX11/src/xkb/XKBAlloc.c index 034539b67..5cfef0fb8 100644 --- a/libX11/src/xkb/XKBAlloc.c +++ b/libX11/src/xkb/XKBAlloc.c @@ -24,9 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#elif defined(HAVE_CONFIG_H) +#ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -43,73 +41,73 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. /*ARGSUSED*/ Status -XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI) +XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI) { -XkbCompatMapPtr compat; -XkbSymInterpretRec *prev_interpret; + XkbCompatMapPtr compat; + XkbSymInterpretRec *prev_interpret; if (!xkb) - return BadMatch; + return BadMatch; if (xkb->compat) { - if (xkb->compat->size_si>=nSI) - return Success; - compat= xkb->compat; - compat->size_si= nSI; - if (compat->sym_interpret==NULL) - compat->num_si= 0; - prev_interpret = compat->sym_interpret; - compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret, - nSI,XkbSymInterpretRec); - if (compat->sym_interpret==NULL) { - _XkbFree(prev_interpret); - compat->size_si= compat->num_si= 0; - return BadAlloc; - } - if (compat->num_si!=0) { - _XkbClearElems(compat->sym_interpret,compat->num_si, - compat->size_si-1,XkbSymInterpretRec); - } - return Success; + if (xkb->compat->size_si >= nSI) + return Success; + compat = xkb->compat; + compat->size_si = nSI; + if (compat->sym_interpret == NULL) + compat->num_si = 0; + prev_interpret = compat->sym_interpret; + compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret, + nSI, XkbSymInterpretRec); + if (compat->sym_interpret == NULL) { + _XkbFree(prev_interpret); + compat->size_si = compat->num_si = 0; + return BadAlloc; + } + if (compat->num_si != 0) { + _XkbClearElems(compat->sym_interpret, compat->num_si, + compat->size_si - 1, XkbSymInterpretRec); + } + return Success; } - compat= _XkbTypedCalloc(1,XkbCompatMapRec); - if (compat==NULL) - return BadAlloc; - if (nSI>0) { - compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec); - if (!compat->sym_interpret) { - _XkbFree(compat); - return BadAlloc; - } + compat = _XkbTypedCalloc(1, XkbCompatMapRec); + if (compat == NULL) + return BadAlloc; + if (nSI > 0) { + compat->sym_interpret = _XkbTypedCalloc(nSI, XkbSymInterpretRec); + if (!compat->sym_interpret) { + _XkbFree(compat); + return BadAlloc; + } } - compat->size_si= nSI; - compat->num_si= 0; - bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); - xkb->compat= compat; + compat->size_si = nSI; + compat->num_si = 0; + bzero((char *) &compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec)); + xkb->compat = compat; return Success; } void -XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap) +XkbFreeCompatMap(XkbDescPtr xkb, unsigned which, Bool freeMap) { -register XkbCompatMapPtr compat; + register XkbCompatMapPtr compat; - if ((xkb==NULL)||(xkb->compat==NULL)) - return; - compat= xkb->compat; + if ((xkb == NULL) || (xkb->compat == NULL)) + return; + compat = xkb->compat; if (freeMap) - which= XkbAllCompatMask; - if (which&XkbGroupCompatMask) - bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); - if (which&XkbSymInterpMask) { - if ((compat->sym_interpret)&&(compat->size_si>0)) - _XkbFree(compat->sym_interpret); - compat->size_si= compat->num_si= 0; - compat->sym_interpret= NULL; + which = XkbAllCompatMask; + if (which & XkbGroupCompatMask) + bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec)); + if (which & XkbSymInterpMask) { + if ((compat->sym_interpret) && (compat->size_si > 0)) + _XkbFree(compat->sym_interpret); + compat->size_si = compat->num_si = 0; + compat->sym_interpret = NULL; } if (freeMap) { - _XkbFree(compat); - xkb->compat= NULL; + _XkbFree(compat); + xkb->compat = NULL; } return; } @@ -117,127 +115,132 @@ register XkbCompatMapPtr compat; /***===================================================================***/ Status -XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases) +XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases) { -XkbNamesPtr names; - - if (xkb==NULL) - return BadMatch; - if (xkb->names==NULL) { - xkb->names = _XkbTypedCalloc(1,XkbNamesRec); - if (xkb->names==NULL) - return BadAlloc; + XkbNamesPtr names; + + if (xkb == NULL) + return BadMatch; + if (xkb->names == NULL) { + xkb->names = _XkbTypedCalloc(1, XkbNamesRec); + if (xkb->names == NULL) + return BadAlloc; } - names= xkb->names; - if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){ - register int i; - XkbKeyTypePtr type; - - type= xkb->map->types; - for (i=0;i<xkb->map->num_types;i++,type++) { - if (type->level_names==NULL) { - type->level_names= _XkbTypedCalloc(type->num_levels,Atom); - if (type->level_names==NULL) - return BadAlloc; - } - } + names = xkb->names; + if ((which & XkbKTLevelNamesMask) && (xkb->map != NULL) && + (xkb->map->types != NULL)) { + register int i; + XkbKeyTypePtr type = xkb->map->types; + + for (i = 0; i < xkb->map->num_types; i++, type++) { + if (type->level_names == NULL) { + type->level_names = _XkbTypedCalloc(type->num_levels, Atom); + if (type->level_names == NULL) + return BadAlloc; + } + } } - if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) { - if ((!XkbIsLegalKeycode(xkb->min_key_code))|| - (!XkbIsLegalKeycode(xkb->max_key_code))|| - (xkb->max_key_code<xkb->min_key_code)) - return BadValue; - names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec); - if (names->keys==NULL) - return BadAlloc; + if ((which & XkbKeyNamesMask) && (names->keys == NULL)) { + if ((!XkbIsLegalKeycode(xkb->min_key_code)) || + (!XkbIsLegalKeycode(xkb->max_key_code)) || + (xkb->max_key_code < xkb->min_key_code)) + return BadValue; + names->keys = _XkbTypedCalloc((xkb->max_key_code + 1), XkbKeyNameRec); + if (names->keys == NULL) + return BadAlloc; } - if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) { - if (names->key_aliases==NULL) { - names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec); - } - else if (nTotalAliases>names->num_key_aliases) { - XkbKeyAliasRec *prev_aliases = names->key_aliases; - - names->key_aliases= _XkbTypedRealloc(names->key_aliases, - nTotalAliases,XkbKeyAliasRec); - if (names->key_aliases!=NULL) { - _XkbClearElems(names->key_aliases,names->num_key_aliases, - nTotalAliases-1,XkbKeyAliasRec); - } else { - _XkbFree(prev_aliases); - } - } - if (names->key_aliases==NULL) { - names->num_key_aliases= 0; - return BadAlloc; - } - names->num_key_aliases= nTotalAliases; + if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) { + if (names->key_aliases == NULL) { + names->key_aliases = _XkbTypedCalloc(nTotalAliases, XkbKeyAliasRec); + } + else if (nTotalAliases > names->num_key_aliases) { + XkbKeyAliasRec *prev_aliases = names->key_aliases; + + names->key_aliases = _XkbTypedRealloc(names->key_aliases, + nTotalAliases, + XkbKeyAliasRec); + if (names->key_aliases != NULL) { + _XkbClearElems(names->key_aliases, names->num_key_aliases, + nTotalAliases - 1, XkbKeyAliasRec); + } + else { + _XkbFree(prev_aliases); + } + } + if (names->key_aliases == NULL) { + names->num_key_aliases = 0; + return BadAlloc; + } + names->num_key_aliases = nTotalAliases; } - if ((which&XkbRGNamesMask)&&(nTotalRG>0)) { - if (names->radio_groups==NULL) { - names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom); - } - else if (nTotalRG>names->num_rg) { - Atom *prev_radio_groups = names->radio_groups; - - names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG, - Atom); - if (names->radio_groups!=NULL) { - _XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1, - Atom); - } else { - _XkbFree(prev_radio_groups); - } - } - if (names->radio_groups==NULL) - return BadAlloc; - names->num_rg= nTotalRG; + if ((which & XkbRGNamesMask) && (nTotalRG > 0)) { + if (names->radio_groups == NULL) { + names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom); + } + else if (nTotalRG > names->num_rg) { + Atom *prev_radio_groups = names->radio_groups; + + names->radio_groups = + _XkbTypedRealloc(names->radio_groups, nTotalRG, Atom); + if (names->radio_groups != NULL) { + _XkbClearElems(names->radio_groups, names->num_rg, nTotalRG - 1, + Atom); + } + else { + _XkbFree(prev_radio_groups); + } + } + if (names->radio_groups == NULL) + return BadAlloc; + names->num_rg = nTotalRG; } return Success; } void -XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap) +XkbFreeNames(XkbDescPtr xkb, unsigned which, Bool freeMap) { -XkbNamesPtr names; + XkbNamesPtr names; - if ((xkb==NULL)||(xkb->names==NULL)) - return; - names= xkb->names; + if ((xkb == NULL) || (xkb->names == NULL)) + return; + names = xkb->names; if (freeMap) - which= XkbAllNamesMask; - if (which&XkbKTLevelNamesMask) { - XkbClientMapPtr map= xkb->map; - if ((map!=NULL)&&(map->types!=NULL)) { - register int i; - register XkbKeyTypePtr type; - type= map->types; - for (i=0;i<map->num_types;i++,type++) { - if (type->level_names!=NULL) { - _XkbFree(type->level_names); - type->level_names= NULL; - } - } - } + which = XkbAllNamesMask; + if (which & XkbKTLevelNamesMask) { + XkbClientMapPtr map = xkb->map; + + if ((map != NULL) && (map->types != NULL)) { + register int i; + register XkbKeyTypePtr type; + + type = map->types; + for (i = 0; i < map->num_types; i++, type++) { + if (type->level_names != NULL) { + _XkbFree(type->level_names); + type->level_names = NULL; + } + } + } } - if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { - _XkbFree(names->keys); - names->keys= NULL; - names->num_keys= 0; + if ((which & XkbKeyNamesMask) && (names->keys != NULL)) { + _XkbFree(names->keys); + names->keys = NULL; + names->num_keys = 0; } - if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){ - _XkbFree(names->key_aliases); - names->key_aliases=NULL; - names->num_key_aliases=0; + if ((which & XkbKeyAliasesMask) && (names->key_aliases)) { + _XkbFree(names->key_aliases); + names->key_aliases = NULL; + names->num_key_aliases = 0; } - if ((which&XkbRGNamesMask)&&(names->radio_groups)) { - _XkbFree(names->radio_groups); - names->radio_groups= NULL; - names->num_rg= 0; + if ((which & XkbRGNamesMask) && (names->radio_groups)) { + _XkbFree(names->radio_groups); + names->radio_groups = NULL; + names->num_rg = 0; } if (freeMap) { - _XkbFree(names); - xkb->names= NULL; + _XkbFree(names); + xkb->names = NULL; } return; } @@ -246,26 +249,26 @@ XkbNamesPtr names; /*ARGSUSED*/ Status -XkbAllocControls(XkbDescPtr xkb,unsigned which) +XkbAllocControls(XkbDescPtr xkb, unsigned which) { - if (xkb==NULL) - return BadMatch; + if (xkb == NULL) + return BadMatch; - if (xkb->ctrls==NULL) { - xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec); - if (!xkb->ctrls) - return BadAlloc; + if (xkb->ctrls == NULL) { + xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec); + if (!xkb->ctrls) + return BadAlloc; } return Success; } /*ARGSUSED*/ void -XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap) +XkbFreeControls(XkbDescPtr xkb, unsigned which, Bool freeMap) { - if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) { - _XkbFree(xkb->ctrls); - xkb->ctrls= NULL; + if (freeMap && (xkb != NULL) && (xkb->ctrls != NULL)) { + _XkbFree(xkb->ctrls); + xkb->ctrls = NULL; } return; } @@ -275,12 +278,12 @@ XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap) Status XkbAllocIndicatorMaps(XkbDescPtr xkb) { - if (xkb==NULL) - return BadMatch; - if (xkb->indicators==NULL) { - xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec); - if (!xkb->indicators) - return BadAlloc; + if (xkb == NULL) + return BadMatch; + if (xkb->indicators == NULL) { + xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec); + if (!xkb->indicators) + return BadAlloc; } return Success; } @@ -288,199 +291,206 @@ XkbAllocIndicatorMaps(XkbDescPtr xkb) void XkbFreeIndicatorMaps(XkbDescPtr xkb) { - if ((xkb!=NULL)&&(xkb->indicators!=NULL)) { - _XkbFree(xkb->indicators); - xkb->indicators= NULL; + if ((xkb != NULL) && (xkb->indicators != NULL)) { + _XkbFree(xkb->indicators); + xkb->indicators = NULL; } return; } /***====================================================================***/ -XkbDescRec * +XkbDescRec * XkbAllocKeyboard(void) { -XkbDescRec *xkb; + XkbDescRec *xkb; - xkb = _XkbTypedCalloc(1,XkbDescRec); + xkb = _XkbTypedCalloc(1, XkbDescRec); if (xkb) - xkb->device_spec= XkbUseCoreKbd; + xkb->device_spec = XkbUseCoreKbd; return xkb; } void -XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll) +XkbFreeKeyboard(XkbDescPtr xkb, unsigned which, Bool freeAll) { - if (xkb==NULL) - return; + if (xkb == NULL) + return; if (freeAll) - which= XkbAllComponentsMask; - if (which&XkbClientMapMask) - XkbFreeClientMap(xkb,XkbAllClientInfoMask,True); - if (which&XkbServerMapMask) - XkbFreeServerMap(xkb,XkbAllServerInfoMask,True); - if (which&XkbCompatMapMask) - XkbFreeCompatMap(xkb,XkbAllCompatMask,True); - if (which&XkbIndicatorMapMask) - XkbFreeIndicatorMaps(xkb); - if (which&XkbNamesMask) - XkbFreeNames(xkb,XkbAllNamesMask,True); - if ((which&XkbGeometryMask) && (xkb->geom!=NULL)) - XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True); - if (which&XkbControlsMask) - XkbFreeControls(xkb,XkbAllControlsMask,True); + which = XkbAllComponentsMask; + if (which & XkbClientMapMask) + XkbFreeClientMap(xkb, XkbAllClientInfoMask, True); + if (which & XkbServerMapMask) + XkbFreeServerMap(xkb, XkbAllServerInfoMask, True); + if (which & XkbCompatMapMask) + XkbFreeCompatMap(xkb, XkbAllCompatMask, True); + if (which & XkbIndicatorMapMask) + XkbFreeIndicatorMaps(xkb); + if (which & XkbNamesMask) + XkbFreeNames(xkb, XkbAllNamesMask, True); + if ((which & XkbGeometryMask) && (xkb->geom != NULL)) + XkbFreeGeometry(xkb->geom, XkbGeomAllMask, True); + if (which & XkbControlsMask) + XkbFreeControls(xkb, XkbAllControlsMask, True); if (freeAll) - _XkbFree(xkb); + _XkbFree(xkb); return; } /***====================================================================***/ XkbDeviceLedInfoPtr -XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId) +XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId) { -XkbDeviceLedInfoPtr devli; -register int i; - - if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId))) - return NULL; - for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) { - if ((devli->led_class==ledClass)&&(devli->led_id==ledId)) - return devli; + XkbDeviceLedInfoPtr devli; + register int i; + + if ((!devi) || (!XkbSingleXIClass(ledClass)) || (!XkbSingleXIId(ledId))) + return NULL; + for (i = 0, devli = devi->leds; i < devi->num_leds; i++, devli++) { + if ((devli->led_class == ledClass) && (devli->led_id == ledId)) + return devli; } - if (devi->num_leds>=devi->sz_leds) { - XkbDeviceLedInfoRec *prev_leds = devi->leds; - - if (devi->sz_leds>0) devi->sz_leds*= 2; - else devi->sz_leds= 1; - devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds, - XkbDeviceLedInfoRec); - if (!devi->leds) { - _XkbFree(prev_leds); - devi->sz_leds= devi->num_leds= 0; - return NULL; - } - i= devi->num_leds; - for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) { - bzero(devli,sizeof(XkbDeviceLedInfoRec)); - devli->led_class= XkbXINone; - devli->led_id= XkbXINone; - } + if (devi->num_leds >= devi->sz_leds) { + XkbDeviceLedInfoRec *prev_leds = devi->leds; + + if (devi->sz_leds > 0) + devi->sz_leds *= 2; + else + devi->sz_leds = 1; + devi->leds = _XkbTypedRealloc(devi->leds, devi->sz_leds, + XkbDeviceLedInfoRec); + if (!devi->leds) { + _XkbFree(prev_leds); + devi->sz_leds = devi->num_leds = 0; + return NULL; + } + i = devi->num_leds; + for (devli = &devi->leds[i]; i < devi->sz_leds; i++, devli++) { + bzero(devli, sizeof(XkbDeviceLedInfoRec)); + devli->led_class = XkbXINone; + devli->led_id = XkbXINone; + } } - devli= &devi->leds[devi->num_leds++]; - bzero(devli,sizeof(XkbDeviceLedInfoRec)); - devli->led_class= ledClass; - devli->led_id= ledId; + devli = &devi->leds[devi->num_leds++]; + bzero(devli, sizeof(XkbDeviceLedInfoRec)); + devli->led_class = ledClass; + devli->led_id = ledId; return devli; } Status -XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal) +XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal) { XkbAction *prev_btn_acts; - if ((!devi)||(newTotal>255)) - return BadValue; - if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns)) - return Success; - if (newTotal==0) { - if (devi->btn_acts!=NULL) { - _XkbFree(devi->btn_acts); - devi->btn_acts= NULL; - } - devi->num_btns= 0; - return Success; + if ((!devi) || (newTotal > 255)) + return BadValue; + if ((devi->btn_acts != NULL) && (newTotal == devi->num_btns)) + return Success; + if (newTotal == 0) { + if (devi->btn_acts != NULL) { + _XkbFree(devi->btn_acts); + devi->btn_acts = NULL; + } + devi->num_btns = 0; + return Success; } prev_btn_acts = devi->btn_acts; - devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction); - if (devi->btn_acts==NULL) { - _XkbFree(prev_btn_acts); - devi->num_btns= 0; - return BadAlloc; + devi->btn_acts = _XkbTypedRealloc(devi->btn_acts, newTotal, XkbAction); + if (devi->btn_acts == NULL) { + _XkbFree(prev_btn_acts); + devi->num_btns = 0; + return BadAlloc; } - if (newTotal>devi->num_btns) { - XkbAction *act; - act= &devi->btn_acts[devi->num_btns]; - bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction)); + if (newTotal > devi->num_btns) { + XkbAction *act; + + act = &devi->btn_acts[devi->num_btns]; + bzero((char *) act, (newTotal - devi->num_btns) * sizeof(XkbAction)); } - devi->num_btns= newTotal; + devi->num_btns = newTotal; return Success; } /*ARGSUSED*/ XkbDeviceInfoPtr -XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds) +XkbAllocDeviceInfo(unsigned deviceSpec, unsigned nButtons, unsigned szLeds) { -XkbDeviceInfoPtr devi; - - devi= _XkbTypedCalloc(1,XkbDeviceInfoRec); - if (devi!=NULL) { - devi->device_spec= deviceSpec; - devi->has_own_state= False; - devi->num_btns= 0; - devi->btn_acts= NULL; - if (nButtons>0) { - devi->num_btns= nButtons; - devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction); - if (!devi->btn_acts) { - _XkbFree(devi); - return NULL; - } - } - devi->dflt_kbd_fb= XkbXINone; - devi->dflt_led_fb= XkbXINone; - devi->num_leds= 0; - devi->sz_leds= 0; - devi->leds= NULL; - if (szLeds>0) { - devi->sz_leds= szLeds; - devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec); - if (!devi->leds) { - if (devi->btn_acts) - _XkbFree(devi->btn_acts); - _XkbFree(devi); - return NULL; - } - } + XkbDeviceInfoPtr devi; + + devi = _XkbTypedCalloc(1, XkbDeviceInfoRec); + if (devi != NULL) { + devi->device_spec = deviceSpec; + devi->has_own_state = False; + devi->num_btns = 0; + devi->btn_acts = NULL; + if (nButtons > 0) { + devi->num_btns = nButtons; + devi->btn_acts = _XkbTypedCalloc(nButtons, XkbAction); + if (!devi->btn_acts) { + _XkbFree(devi); + return NULL; + } + } + devi->dflt_kbd_fb = XkbXINone; + devi->dflt_led_fb = XkbXINone; + devi->num_leds = 0; + devi->sz_leds = 0; + devi->leds = NULL; + if (szLeds > 0) { + devi->sz_leds = szLeds; + devi->leds = _XkbTypedCalloc(szLeds, XkbDeviceLedInfoRec); + if (!devi->leds) { + if (devi->btn_acts) + _XkbFree(devi->btn_acts); + _XkbFree(devi); + return NULL; + } + } } return devi; } void -XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI) +XkbFreeDeviceInfo(XkbDeviceInfoPtr devi, unsigned which, Bool freeDevI) { if (devi) { - if (freeDevI) { - which= XkbXI_AllDeviceFeaturesMask; - if (devi->name) { - _XkbFree(devi->name); - devi->name= NULL; - } - } - if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) { - _XkbFree(devi->btn_acts); - devi->num_btns= 0; - devi->btn_acts= NULL; - } - if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) { - register int i; - if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) { - _XkbFree(devi->leds); - devi->sz_leds= devi->num_leds= 0; - devi->leds= NULL; - } - else { - XkbDeviceLedInfoPtr devli; - for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) { - if (which&XkbXI_IndicatorMapsMask) - bzero((char *)&devli->maps[0],sizeof(devli->maps)); - else bzero((char *)&devli->names[0],sizeof(devli->names)); - } - } - } - if (freeDevI) - _XkbFree(devi); + if (freeDevI) { + which = XkbXI_AllDeviceFeaturesMask; + if (devi->name) { + _XkbFree(devi->name); + devi->name = NULL; + } + } + if ((which & XkbXI_ButtonActionsMask) && (devi->btn_acts)) { + _XkbFree(devi->btn_acts); + devi->num_btns = 0; + devi->btn_acts = NULL; + } + if ((which & XkbXI_IndicatorsMask) && (devi->leds)) { + register int i; + + if ((which & XkbXI_IndicatorsMask) == XkbXI_IndicatorsMask) { + _XkbFree(devi->leds); + devi->sz_leds = devi->num_leds = 0; + devi->leds = NULL; + } + else { + XkbDeviceLedInfoPtr devli; + + for (i = 0, devli = devi->leds; i < devi->num_leds; + i++, devli++) { + if (which & XkbXI_IndicatorMapsMask) + bzero((char *) &devli->maps[0], sizeof(devli->maps)); + else + bzero((char *) &devli->names[0], sizeof(devli->names)); + } + } + } + if (freeDevI) + _XkbFree(devi); } return; } |