From fe94593d022633514c43c48455451985e71e2a09 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 28 Mar 2009 18:17:34 -0700 Subject: [PATCH] malloc/misc/xkb: Coding style cleanup --- src/malloc.c | 77 +++++++++++++----------- src/misc.c | 191 ++++++++++++++++++++++++++++++++--------------------------- src/xkb.c | 71 +++++++++++----------- 3 files changed, 181 insertions(+), 158 deletions(-) diff --git a/src/malloc.c b/src/malloc.c index 67d8319..ca6bf61 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -230,57 +230,66 @@ XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions) } int -XkbcCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into) +XkbcCopyKeyType(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; + _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)); + + *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->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)); + + 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; } int -XkbcCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types) +XkbcCopyKeyTypes(XkbKeyTypePtr from, XkbKeyTypePtr into, int num_types) { -register int i,rtrn; + int i, rtrn; - if ((!from)||(!into)||(num_types<0)) - return BadMatch; - for (i=0;imap; - if ((which&XkbAllRequiredTypes)==0) - return Success; - rtrn= Success; - from= canonicalTypes; - to= map->types; - if (which&XkbOneLevelMask) - rtrn= XkbcCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]); - if ((which&XkbTwoLevelMask)&&(rtrn==Success)) - rtrn= XkbcCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]); - if ((which&XkbAlphabeticMask)&&(rtrn==Success)) - rtrn= XkbcCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]); - if ((which&XkbKeypadMask)&&(rtrn==Success)) { - XkbKeyTypePtr type; - rtrn= XkbcCopyKeyType(&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; - } + if ((which & XkbAllRequiredTypes) == 0) + return Success; + + rtrn = Success; + from = canonicalTypes; + to = map->types; + + if (which & XkbOneLevelMask) + rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex], &to[XkbOneLevelIndex]); + + if ((which & XkbTwoLevelMask) && (rtrn == Success)) + rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex], &to[XkbTwoLevelIndex]); + + if ((which & XkbAlphabeticMask) && (rtrn == Success)) + rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex], + &to[XkbAlphabeticIndex]); + + if ((which & XkbKeypadMask) && (rtrn == Success)) { + XkbKeyTypePtr type; + + rtrn = XkbcCopyKeyType(&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; } Bool -XkbcVirtualModsToReal(XkbcDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn) +XkbcVirtualModsToReal(XkbcDescPtr 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; + int i, bit; + unsigned mask; + + if (!xkb) + 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]; + if (!xkb->server) + 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; + + *mask_rtrn = mask; return True; } diff --git a/src/xkb.c b/src/xkb.c index 22324fe..de2d0d3 100644 --- a/src/xkb.c +++ b/src/xkb.c @@ -32,47 +32,46 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "XKBcommonint.h" Bool -XkbcComputeEffectiveMap( XkbcDescPtr xkb, - XkbKeyTypePtr type, - unsigned char * map_rtrn) +XkbcComputeEffectiveMap(XkbcDescPtr xkb, XkbKeyTypePtr type, + unsigned char *map_rtrn) { -register int i; -unsigned tmp; -XkbKTMapEntryPtr entry = NULL; + int i; + unsigned tmp; + XkbKTMapEntryPtr entry = NULL; - if ((!xkb)||(!type)||(!xkb->server)) - return False; + if (!xkb || !type || !xkb->server) + return False; - if (type->mods.vmods!=0) { - if (!XkbcVirtualModsToReal(xkb,type->mods.vmods,&tmp)) - return False; + if (type->mods.vmods != 0) { + if (!XkbcVirtualModsToReal(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 (!XkbcVirtualModsToReal(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; - } + 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 (!XkbcVirtualModsToReal(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; - } - if (map_rtrn!=NULL) { - bzero(map_rtrn,type->mods.mask+1); - for (i=0;imap_count;i++) { - if (entry->active) { - map_rtrn[type->map[i].mods.mask]= type->map[i].level; - } - } + else + type->mods.mask = type->mods.real_mods; + + if (map_rtrn) { + bzero(map_rtrn, type->mods.mask + 1); + for (i = 0; i < type->map_count; i++) { + if (entry->active) + map_rtrn[type->map[i].mods.mask] = type->map[i].level; + } } + return True; } -- 2.7.4