alloc/galloc: Coding style cleanup

Mostly tab-to-space conversion plus a few style nits. Dropped the
register keywords as I'm pretty sure modern compilers can be trusted to
do the right thing.
master
Dan Nicholson 2009-03-25 15:41:21 -07:00
parent 1ff77ecd36
commit 46faf56ded
2 changed files with 798 additions and 753 deletions

View File

@ -40,30 +40,36 @@ XkbSymInterpretRec *prev_interpret;
if (!xkb) if (!xkb)
return BadMatch; return BadMatch;
if (xkb->compat) { if (xkb->compat) {
if (xkb->compat->size_si >= nSI) if (xkb->compat->size_si >= nSI)
return Success; return Success;
compat = xkb->compat; compat = xkb->compat;
compat->size_si = nSI; compat->size_si = nSI;
if (compat->sym_interpret==NULL) if (!compat->sym_interpret)
compat->num_si = 0; compat->num_si = 0;
prev_interpret = compat->sym_interpret; prev_interpret = compat->sym_interpret;
compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret, compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
nSI, XkbSymInterpretRec); nSI, XkbSymInterpretRec);
if (compat->sym_interpret==NULL) { if (!compat->sym_interpret) {
_XkbFree(prev_interpret); _XkbFree(prev_interpret);
compat->size_si = compat->num_si = 0; compat->size_si = compat->num_si = 0;
return BadAlloc; return BadAlloc;
} }
if (compat->num_si!=0) {
if (compat->num_si != 0)
_XkbClearElems(compat->sym_interpret, compat->num_si, _XkbClearElems(compat->sym_interpret, compat->num_si,
compat->size_si - 1, XkbSymInterpretRec); compat->size_si - 1, XkbSymInterpretRec);
}
return Success; return Success;
} }
compat = _XkbTypedCalloc(1, XkbCompatMapRec); compat = _XkbTypedCalloc(1, XkbCompatMapRec);
if (compat==NULL) if (!compat)
return BadAlloc; return BadAlloc;
if (nSI > 0) { if (nSI > 0) {
compat->sym_interpret = _XkbTypedCalloc(nSI, XkbSymInterpretRec); compat->sym_interpret = _XkbTypedCalloc(nSI, XkbSymInterpretRec);
if (!compat->sym_interpret) { if (!compat->sym_interpret) {
@ -73,8 +79,9 @@ XkbSymInterpretRec *prev_interpret;
} }
compat->size_si = nSI; compat->size_si = nSI;
compat->num_si = 0; compat->num_si = 0;
bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec));
xkb->compat = compat; xkb->compat = compat;
return Success; return Success;
} }
@ -82,26 +89,29 @@ XkbSymInterpretRec *prev_interpret;
void void
XkbcFreeCompatMap(XkbcDescPtr xkb, unsigned which, Bool freeMap) XkbcFreeCompatMap(XkbcDescPtr xkb, unsigned which, Bool freeMap)
{ {
register XkbCompatMapPtr compat; XkbCompatMapPtr compat;
if ((xkb==NULL)||(xkb->compat==NULL)) if (!xkb || !xkb->compat)
return; return;
compat = xkb->compat; compat = xkb->compat;
if (freeMap) if (freeMap)
which = XkbAllCompatMask; which = XkbAllCompatMask;
if (which & XkbGroupCompatMask) if (which & XkbGroupCompatMask)
bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec));
if (which & XkbSymInterpMask) { if (which & XkbSymInterpMask) {
if ((compat->sym_interpret)&&(compat->size_si>0)) if (compat->sym_interpret && (compat->size_si > 0))
_XkbFree(compat->sym_interpret); _XkbFree(compat->sym_interpret);
compat->size_si = compat->num_si = 0; compat->size_si = compat->num_si = 0;
compat->sym_interpret = NULL; compat->sym_interpret = NULL;
} }
if (freeMap) { if (freeMap) {
_XkbFree(compat); _XkbFree(compat);
xkb->compat = NULL; xkb->compat = NULL;
} }
return;
} }
int int
@ -109,78 +119,87 @@ XkbcAllocNames(XkbcDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases)
{ {
XkbNamesPtr names; XkbNamesPtr names;
if (xkb==NULL) if (!xkb)
return BadMatch; return BadMatch;
if (xkb->names==NULL) {
if (!xkb->names) {
xkb->names = _XkbTypedCalloc(1, XkbNamesRec); xkb->names = _XkbTypedCalloc(1, XkbNamesRec);
if (xkb->names==NULL) if (!xkb->names)
return BadAlloc; return BadAlloc;
} }
names = xkb->names; names = xkb->names;
if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){
register int i; if ((which & XkbKTLevelNamesMask) && xkb->map && xkb->map->types) {
int i;
XkbKeyTypePtr type; XkbKeyTypePtr type;
type = xkb->map->types; type = xkb->map->types;
for (i = 0; i < xkb->map->num_types; i++, type++) { for (i = 0; i < xkb->map->num_types; i++, type++) {
if (type->level_names==NULL) { if (!type->level_names) {
type->level_names = _XkbTypedCalloc(type->num_levels, Atom); type->level_names = _XkbTypedCalloc(type->num_levels, Atom);
if (type->level_names==NULL) if (!type->level_names)
return BadAlloc; return BadAlloc;
} }
} }
} }
if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) {
if ((which & XkbKeyNamesMask) && names->keys) {
if ((!XkbIsLegalKeycode(xkb->min_key_code)) || if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadValue; return BadValue;
names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec);
if (names->keys==NULL) names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, XkbKeyNameRec);
if (!names->keys)
return BadAlloc; return BadAlloc;
} }
if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) { if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
if (names->key_aliases==NULL) { if (!names->key_aliases)
names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec); names->key_aliases = _XkbTypedCalloc(nTotalAliases,
} XkbKeyAliasRec);
else if (nTotalAliases > names->num_key_aliases) { else if (nTotalAliases > names->num_key_aliases) {
XkbKeyAliasRec *prev_aliases = names->key_aliases; XkbKeyAliasRec *prev_aliases = names->key_aliases;
names->key_aliases = _XkbTypedRealloc(names->key_aliases, names->key_aliases = _XkbTypedRealloc(names->key_aliases,
nTotalAliases,XkbKeyAliasRec); nTotalAliases,
if (names->key_aliases!=NULL) { XkbKeyAliasRec);
if (names->key_aliases)
_XkbClearElems(names->key_aliases, names->num_key_aliases, _XkbClearElems(names->key_aliases, names->num_key_aliases,
nTotalAliases - 1, XkbKeyAliasRec); nTotalAliases - 1, XkbKeyAliasRec);
} else { else
_XkbFree(prev_aliases); _XkbFree(prev_aliases);
} }
}
if (names->key_aliases==NULL) { if (!names->key_aliases) {
names->num_key_aliases = 0; names->num_key_aliases = 0;
return BadAlloc; return BadAlloc;
} }
names->num_key_aliases = nTotalAliases; names->num_key_aliases = nTotalAliases;
} }
if ((which & XkbRGNamesMask) && (nTotalRG > 0)) { if ((which & XkbRGNamesMask) && (nTotalRG > 0)) {
if (names->radio_groups==NULL) { if (!names->radio_groups)
names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom); names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom);
}
else if (nTotalRG > names->num_rg) { else if (nTotalRG > names->num_rg) {
Atom *prev_radio_groups = names->radio_groups; Atom *prev_radio_groups = names->radio_groups;
names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG, names->radio_groups = _XkbTypedRealloc(names->radio_groups,
Atom); nTotalRG, Atom);
if (names->radio_groups!=NULL) { if (names->radio_groups)
_XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1, _XkbClearElems(names->radio_groups, names->num_rg,
Atom); nTotalRG - 1, Atom);
} else { else
_XkbFree(prev_radio_groups); _XkbFree(prev_radio_groups);
} }
}
if (names->radio_groups==NULL) if (!names->radio_groups)
return BadAlloc; return BadAlloc;
names->num_rg = nTotalRG; names->num_rg = nTotalRG;
} }
return Success; return Success;
} }
@ -189,92 +208,99 @@ XkbcFreeNames(XkbcDescPtr xkb,unsigned which,Bool freeMap)
{ {
XkbNamesPtr names; XkbNamesPtr names;
if ((xkb==NULL)||(xkb->names==NULL)) if (!xkb || !xkb->names)
return; return;
names = xkb->names; names = xkb->names;
if (freeMap) if (freeMap)
which = XkbAllNamesMask; which = XkbAllNamesMask;
if (which & XkbKTLevelNamesMask) { if (which & XkbKTLevelNamesMask) {
XkbClientMapPtr map = xkb->map; XkbClientMapPtr map = xkb->map;
if ((map!=NULL)&&(map->types!=NULL)) {
register int i; if (map && map->types) {
register XkbKeyTypePtr type; int i;
type= map->types; XkbKeyTypePtr type = map->types;
for (i = 0; i < map->num_types; i++, type++) { for (i = 0; i < map->num_types; i++, type++) {
if (type->level_names!=NULL) { if (type->level_names) {
_XkbFree(type->level_names); _XkbFree(type->level_names);
type->level_names = NULL; type->level_names = NULL;
} }
} }
} }
} }
if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
if ((which & XkbKeyNamesMask) && names->keys) {
_XkbFree(names->keys); _XkbFree(names->keys);
names->keys = NULL; names->keys = NULL;
names->num_keys = 0; names->num_keys = 0;
} }
if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){
if ((which & XkbKeyAliasesMask) && names->key_aliases) {
_XkbFree(names->key_aliases); _XkbFree(names->key_aliases);
names->key_aliases = NULL; names->key_aliases = NULL;
names->num_key_aliases = 0; names->num_key_aliases = 0;
} }
if ((which&XkbRGNamesMask)&&(names->radio_groups)) {
if ((which & XkbRGNamesMask) && names->radio_groups) {
_XkbFree(names->radio_groups); _XkbFree(names->radio_groups);
names->radio_groups = NULL; names->radio_groups = NULL;
names->num_rg = 0; names->num_rg = 0;
} }
if (freeMap) { if (freeMap) {
_XkbFree(names); _XkbFree(names);
xkb->names = NULL; xkb->names = NULL;
} }
return;
} }
int int
XkbcAllocControls(XkbcDescPtr xkb, unsigned which) XkbcAllocControls(XkbcDescPtr xkb, unsigned which)
{ {
if (xkb==NULL) if (!xkb)
return BadMatch; return BadMatch;
if (xkb->ctrls==NULL) { if (!xkb->ctrls) {
xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec); xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec);
if (!xkb->ctrls) if (!xkb->ctrls)
return BadAlloc; return BadAlloc;
} }
return Success; return Success;
} }
void void
XkbcFreeControls(XkbcDescPtr xkb, unsigned which, Bool freeMap) XkbcFreeControls(XkbcDescPtr xkb, unsigned which, Bool freeMap)
{ {
if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) { if (freeMap && xkb && xkb->ctrls) {
_XkbFree(xkb->ctrls); _XkbFree(xkb->ctrls);
xkb->ctrls = NULL; xkb->ctrls = NULL;
} }
return;
} }
int int
XkbcAllocIndicatorMaps(XkbcDescPtr xkb) XkbcAllocIndicatorMaps(XkbcDescPtr xkb)
{ {
if (xkb==NULL) if (!xkb)
return BadMatch; return BadMatch;
if (xkb->indicators==NULL) {
if (!xkb->indicators) {
xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec); xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec);
if (!xkb->indicators) if (!xkb->indicators)
return BadAlloc; return BadAlloc;
} }
return Success; return Success;
} }
void void
XkbcFreeIndicatorMaps(XkbcDescPtr xkb) XkbcFreeIndicatorMaps(XkbcDescPtr xkb)
{ {
if ((xkb!=NULL)&&(xkb->indicators!=NULL)) { if (xkb && xkb->indicators) {
_XkbFree(xkb->indicators); _XkbFree(xkb->indicators);
xkb->indicators = NULL; xkb->indicators = NULL;
} }
return;
} }
XkbcDescRec * XkbcDescRec *
@ -291,10 +317,12 @@ XkbcDescRec *xkb;
void void
XkbcFreeKeyboard(XkbcDescPtr xkb, unsigned which, Bool freeAll) XkbcFreeKeyboard(XkbcDescPtr xkb, unsigned which, Bool freeAll)
{ {
if (xkb==NULL) if (!xkb)
return; return;
if (freeAll) if (freeAll)
which = XkbAllComponentsMask; which = XkbAllComponentsMask;
if (which & XkbClientMapMask) if (which & XkbClientMapMask)
XkbcFreeClientMap(xkb, XkbAllClientInfoMask, True); XkbcFreeClientMap(xkb, XkbAllClientInfoMask, True);
if (which & XkbServerMapMask) if (which & XkbServerMapMask)
@ -305,23 +333,23 @@ XkbcFreeKeyboard(XkbcDescPtr xkb,unsigned which,Bool freeAll)
XkbcFreeIndicatorMaps(xkb); XkbcFreeIndicatorMaps(xkb);
if (which & XkbNamesMask) if (which & XkbNamesMask)
XkbcFreeNames(xkb, XkbAllNamesMask, True); XkbcFreeNames(xkb, XkbAllNamesMask, True);
if ((which&XkbGeometryMask) && (xkb->geom!=NULL)) if ((which & XkbGeometryMask) && xkb->geom)
XkbcFreeGeometry(xkb->geom, XkbGeomAllMask, True); XkbcFreeGeometry(xkb->geom, XkbGeomAllMask, True);
if (which & XkbControlsMask) if (which & XkbControlsMask)
XkbcFreeControls(xkb, XkbAllControlsMask, True); XkbcFreeControls(xkb, XkbAllControlsMask, True);
if (freeAll) if (freeAll)
_XkbFree(xkb); _XkbFree(xkb);
return;
} }
int int
XkbcAllocClientMap(XkbcDescPtr xkb, unsigned which, unsigned nTotalTypes) XkbcAllocClientMap(XkbcDescPtr xkb, unsigned which, unsigned nTotalTypes)
{ {
register int i; int i;
XkbClientMapPtr map; XkbClientMapPtr map;
if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes))) if (!xkb || ((nTotalTypes > 0) && (nTotalTypes < XkbNumRequiredTypes)))
return BadValue; return BadValue;
if ((which & XkbKeySymsMask) && if ((which & XkbKeySymsMask) &&
((!XkbIsLegalKeycode(xkb->min_key_code)) || ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
@ -333,39 +361,45 @@ fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n",
return BadValue; return BadValue;
} }
if (xkb->map==NULL) { if (!xkb->map) {
map = _XkbTypedCalloc(1, XkbClientMapRec); map = _XkbTypedCalloc(1, XkbClientMapRec);
if (map==NULL) if (!map)
return BadAlloc; return BadAlloc;
xkb->map = map; xkb->map = map;
} }
else map= xkb->map; else
map = xkb->map;
if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) { if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) {
if (map->types==NULL) { if (!map->types) {
map->types = _XkbTypedCalloc(nTotalTypes, XkbKeyTypeRec); map->types = _XkbTypedCalloc(nTotalTypes, XkbKeyTypeRec);
if (map->types==NULL) if (!map->types)
return BadAlloc; return BadAlloc;
map->num_types = 0; map->num_types = 0;
map->size_types = nTotalTypes; map->size_types = nTotalTypes;
} }
else if (map->size_types < nTotalTypes) { else if (map->size_types < nTotalTypes) {
XkbKeyTypeRec *prev_types = map->types; XkbKeyTypeRec *prev_types = map->types;
map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec); map->types = _XkbTypedRealloc(map->types, nTotalTypes,
if (map->types==NULL) { XkbKeyTypeRec);
if (!map->types) {
_XkbFree(prev_types); _XkbFree(prev_types);
map->num_types = map->size_types = 0; map->num_types = map->size_types = 0;
return BadAlloc; return BadAlloc;
} }
map->size_types = nTotalTypes; map->size_types = nTotalTypes;
bzero(&map->types[map->num_types], bzero(&map->types[map->num_types],
((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec))); (map->size_types - map->num_types) * sizeof(XkbKeyTypeRec));
} }
} }
if (which & XkbKeySymsMask) { if (which & XkbKeySymsMask) {
int nKeys = XkbNumKeys(xkb); int nKeys = XkbNumKeys(xkb);
if (map->syms==NULL) {
if (!map->syms) {
map->size_syms = (nKeys * 15) / 10; map->size_syms = (nKeys * 15) / 10;
map->syms = _XkbTypedCalloc(map->size_syms, KeySym); map->syms = _XkbTypedCalloc(map->size_syms, KeySym);
if (!map->syms) { if (!map->syms) {
@ -375,68 +409,80 @@ fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n",
map->num_syms = 1; map->num_syms = 1;
map->syms[0] = NoSymbol; map->syms[0] = NoSymbol;
} }
if (map->key_sym_map==NULL) {
if (!map->key_sym_map) {
i = xkb->max_key_code + 1; i = xkb->max_key_code + 1;
map->key_sym_map = _XkbTypedCalloc(i, XkbSymMapRec); map->key_sym_map = _XkbTypedCalloc(i, XkbSymMapRec);
if (map->key_sym_map==NULL) if (!map->key_sym_map)
return BadAlloc; return BadAlloc;
} }
} }
if (which & XkbModifierMapMask) { if (which & XkbModifierMapMask) {
if ((!XkbIsLegalKeycode(xkb->min_key_code)) || if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadMatch; return BadMatch;
if (map->modmap==NULL) {
if (!map->modmap) {
i = xkb->max_key_code + 1; i = xkb->max_key_code + 1;
map->modmap = _XkbTypedCalloc(i, unsigned char); map->modmap = _XkbTypedCalloc(i, unsigned char);
if (map->modmap==NULL) if (!map->modmap)
return BadAlloc; return BadAlloc;
} }
} }
return Success; return Success;
} }
int int
XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions) XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions)
{ {
register int i; int i;
XkbServerMapPtr map; XkbServerMapPtr map;
if (xkb==NULL) if (!xkb)
return BadMatch; return BadMatch;
if (xkb->server==NULL) {
if (!xkb->server) {
map = _XkbTypedCalloc(1, XkbServerMapRec); map = _XkbTypedCalloc(1, XkbServerMapRec);
if (map==NULL) if (!map)
return BadAlloc; return BadAlloc;
for (i=0;i<XkbNumVirtualMods;i++) {
for (i = 0; i < XkbNumVirtualMods; i++)
map->vmods[i] = XkbNoModifierMask; map->vmods[i] = XkbNoModifierMask;
}
xkb->server = map; xkb->server = map;
} }
else map= xkb->server; else
map = xkb->server;
if (which & XkbExplicitComponentsMask) { if (which & XkbExplicitComponentsMask) {
if ((!XkbIsLegalKeycode(xkb->min_key_code)) || if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadMatch; return BadMatch;
if (map->explicit==NULL) {
if (!map->explicit) {
i = xkb->max_key_code + 1; i = xkb->max_key_code + 1;
map->explicit = _XkbTypedCalloc(i, unsigned char); map->explicit = _XkbTypedCalloc(i, unsigned char);
if (map->explicit==NULL) if (!map->explicit)
return BadAlloc; return BadAlloc;
} }
} }
if (which&XkbKeyActionsMask) { if (which&XkbKeyActionsMask) {
if ((!XkbIsLegalKeycode(xkb->min_key_code)) || if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadMatch; return BadMatch;
if (nNewActions < 1) if (nNewActions < 1)
nNewActions = 1; nNewActions = 1;
if (map->acts==NULL) {
map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction); if (!map->acts) {
if (map->acts==NULL) map->acts = _XkbTypedCalloc(nNewActions + 1, XkbAction);
if (!map->acts)
return BadAlloc; return BadAlloc;
map->num_acts = 1; map->num_acts = 1;
map->size_acts = nNewActions + 1; map->size_acts = nNewActions + 1;
@ -444,48 +490,56 @@ XkbServerMapPtr map;
else if ((map->size_acts - map->num_acts) < nNewActions) { else if ((map->size_acts - map->num_acts) < nNewActions) {
unsigned need; unsigned need;
XkbAction *prev_acts = map->acts; XkbAction *prev_acts = map->acts;
need = map->num_acts + nNewActions; need = map->num_acts + nNewActions;
map->acts = _XkbTypedRealloc(map->acts, need, XkbAction); map->acts = _XkbTypedRealloc(map->acts, need, XkbAction);
if (map->acts==NULL) { if (!map->acts) {
_XkbFree(prev_acts); _XkbFree(prev_acts);
map->num_acts = map->size_acts = 0; map->num_acts = map->size_acts = 0;
return BadAlloc; return BadAlloc;
} }
map->size_acts = need; map->size_acts = need;
bzero(&map->acts[map->num_acts], bzero(&map->acts[map->num_acts],
((map->size_acts-map->num_acts)*sizeof(XkbAction))); (map->size_acts - map->num_acts) * sizeof(XkbAction));
} }
if (map->key_acts==NULL) {
if (!map->key_acts) {
i = xkb->max_key_code + 1; i = xkb->max_key_code + 1;
map->key_acts = _XkbTypedCalloc(i, unsigned short); map->key_acts = _XkbTypedCalloc(i, unsigned short);
if (map->key_acts==NULL) if (!map->key_acts)
return BadAlloc; return BadAlloc;
} }
} }
if (which & XkbKeyBehaviorsMask) { if (which & XkbKeyBehaviorsMask) {
if ((!XkbIsLegalKeycode(xkb->min_key_code)) || if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadMatch; return BadMatch;
if (map->behaviors==NULL) {
if (!map->behaviors) {
i = xkb->max_key_code + 1; i = xkb->max_key_code + 1;
map->behaviors = _XkbTypedCalloc(i, XkbBehavior); map->behaviors = _XkbTypedCalloc(i, XkbBehavior);
if (map->behaviors==NULL) if (!map->behaviors)
return BadAlloc; return BadAlloc;
} }
} }
if (which & XkbVirtualModMapMask) { if (which & XkbVirtualModMapMask) {
if ((!XkbIsLegalKeycode(xkb->min_key_code)) || if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code)) || (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadMatch; return BadMatch;
if (map->vmodmap==NULL) {
if (!map->vmodmap) {
i = xkb->max_key_code + 1; i = xkb->max_key_code + 1;
map->vmodmap = _XkbTypedCalloc(i, unsigned short); map->vmodmap = _XkbTypedCalloc(i, unsigned short);
if (map->vmodmap==NULL) if (!map->vmodmap)
return BadAlloc; return BadAlloc;
} }
} }
return Success; return Success;
} }
@ -494,27 +548,30 @@ XkbcFreeClientMap(XkbcDescPtr xkb,unsigned what,Bool freeMap)
{ {
XkbClientMapPtr map; XkbClientMapPtr map;
if ((xkb==NULL)||(xkb->map==NULL)) if (!xkb || !xkb->map)
return; return;
if (freeMap) if (freeMap)
what = XkbAllClientInfoMask; what = XkbAllClientInfoMask;
map = xkb->map; map = xkb->map;
if (what & XkbKeyTypesMask) { if (what & XkbKeyTypesMask) {
if (map->types!=NULL) { if (map->types) {
if (map->num_types > 0) { if (map->num_types > 0) {
register int i; int i;
XkbKeyTypePtr type; XkbKeyTypePtr type;
for (i = 0, type = map->types; i < map->num_types; i++, type++) { for (i = 0, type = map->types; i < map->num_types; i++, type++) {
if (type->map!=NULL) { if (type->map) {
_XkbFree(type->map); _XkbFree(type->map);
type->map = NULL; type->map = NULL;
} }
if (type->preserve!=NULL) { if (type->preserve) {
_XkbFree(type->preserve); _XkbFree(type->preserve);
type->preserve = NULL; type->preserve = NULL;
} }
type->map_count = 0; type->map_count = 0;
if (type->level_names!=NULL) { if (type->level_names) {
_XkbFree(type->level_names); _XkbFree(type->level_names);
type->level_names = NULL; type->level_names = NULL;
} }
@ -525,26 +582,28 @@ XkbClientMapPtr map;
map->types = NULL; map->types = NULL;
} }
} }
if (what & XkbKeySymsMask) { if (what & XkbKeySymsMask) {
if (map->key_sym_map!=NULL) { if (map->key_sym_map) {
_XkbFree(map->key_sym_map); _XkbFree(map->key_sym_map);
map->key_sym_map = NULL; map->key_sym_map = NULL;
} }
if (map->syms!=NULL) { if (map->syms) {
_XkbFree(map->syms); _XkbFree(map->syms);
map->size_syms = map->num_syms = 0; map->size_syms = map->num_syms = 0;
map->syms = NULL; map->syms = NULL;
} }
} }
if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) {
if ((what & XkbModifierMapMask) && map->modmap) {
_XkbFree(map->modmap); _XkbFree(map->modmap);
map->modmap = NULL; map->modmap = NULL;
} }
if (freeMap) { if (freeMap) {
_XkbFree(xkb->map); _XkbFree(xkb->map);
xkb->map = NULL; xkb->map = NULL;
} }
return;
} }
void void
@ -552,31 +611,36 @@ XkbcFreeServerMap(XkbcDescPtr xkb,unsigned what,Bool freeMap)
{ {
XkbServerMapPtr map; XkbServerMapPtr map;
if ((xkb==NULL)||(xkb->server==NULL)) if (!xkb || !xkb->server)
return; return;
if (freeMap) if (freeMap)
what = XkbAllServerInfoMask; what = XkbAllServerInfoMask;
map = xkb->server; map = xkb->server;
if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) {
if ((what & XkbExplicitComponentsMask) && map->explicit) {
_XkbFree(map->explicit); _XkbFree(map->explicit);
map->explicit = NULL; map->explicit = NULL;
} }
if (what & XkbKeyActionsMask) { if (what & XkbKeyActionsMask) {
if (map->key_acts!=NULL) { if (map->key_acts) {
_XkbFree(map->key_acts); _XkbFree(map->key_acts);
map->key_acts = NULL; map->key_acts = NULL;
} }
if (map->acts!=NULL) { if (map->acts) {
_XkbFree(map->acts); _XkbFree(map->acts);
map->num_acts = map->size_acts = 0; map->num_acts = map->size_acts = 0;
map->acts = NULL; map->acts = NULL;
} }
} }
if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) {
if ((what & XkbKeyBehaviorsMask) && map->behaviors) {
_XkbFree(map->behaviors); _XkbFree(map->behaviors);
map->behaviors = NULL; map->behaviors = NULL;
} }
if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) {
if ((what & XkbVirtualModMapMask) && map->vmodmap) {
_XkbFree(map->vmodmap); _XkbFree(map->vmodmap);
map->vmodmap = NULL; map->vmodmap = NULL;
} }
@ -585,5 +649,4 @@ XkbServerMapPtr map;
_XkbFree(xkb->server); _XkbFree(xkb->server);
xkb->server = NULL; xkb->server = NULL;
} }
return;
} }

View File

@ -33,17 +33,13 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/extensions/XKB.h> #include <X11/extensions/XKB.h>
static void static void
_XkbFreeGeomLeafElems( Bool freeAll, _XkbFreeGeomLeafElems(Bool freeAll, int first, int count,
int first, unsigned short *num_inout, unsigned short *sz_inout,
int count, char **elems, unsigned int elem_sz)
unsigned short * num_inout,
unsigned short * sz_inout,
char ** elems,
unsigned int elem_sz)
{ {
if ((freeAll)||(*elems==NULL)) { if (freeAll || !(*elems)) {
*num_inout = *sz_inout = 0; *num_inout = *sz_inout = 0;
if (*elems!=NULL) { if (*elems) {
_XkbFree(*elems); _XkbFree(*elems);
*elems = NULL; *elems = NULL;
} }
@ -53,48 +49,42 @@ _XkbFreeGeomLeafElems( Bool freeAll,
if ((first >= (*num_inout)) || (first < 0) || (count < 1)) if ((first >= (*num_inout)) || (first < 0) || (count < 1))
return; return;
if (first+count>=(*num_inout)) { if (first + count >= (*num_inout))
/* truncating the array is easy */ /* truncating the array is easy */
(*num_inout) = first; (*num_inout) = first;
}
else { else {
char * ptr; char *ptr = *elems;
int extra; int extra = ((*num_inout) - first + count) * elem_sz;
ptr= *elems;
extra= ((*num_inout)-(first+count))*elem_sz;
if (extra > 0) if (extra > 0)
memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra); memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz],
extra);
(*num_inout) -= count; (*num_inout) -= count;
} }
return;
} }
typedef void (*ContentsClearFunc)( typedef void (*ContentsClearFunc)(char *priv);
char * /* priv */
);
static void static void
_XkbFreeGeomNonLeafElems( Bool freeAll, _XkbFreeGeomNonLeafElems(Bool freeAll, int first, int count,
int first, unsigned short *num_inout, unsigned short *sz_inout,
int count, char **elems, unsigned int elem_sz,
unsigned short * num_inout,
unsigned short * sz_inout,
char ** elems,
unsigned int elem_sz,
ContentsClearFunc freeFunc) ContentsClearFunc freeFunc)
{ {
register int i; int i;
register char *ptr; char *ptr;
if (freeAll) { if (freeAll) {
first = 0; first = 0;
count= (*num_inout); count = *num_inout;
} }
else if ((first >= (*num_inout)) || (first < 0) || (count < 1)) else if ((first >= (*num_inout)) || (first < 0) || (count < 1))
return; return;
else if (first + count > (*num_inout)) else if (first + count > (*num_inout))
count = (*num_inout) - first; count = (*num_inout) - first;
if (*elems==NULL)
if (!(*elems))
return; return;
if (freeFunc) { if (freeFunc) {
@ -105,8 +95,9 @@ register char *ptr;
ptr += elem_sz; ptr += elem_sz;
} }
} }
if (freeAll) { if (freeAll) {
(*num_inout)= (*sz_inout)= 0; *num_inout = *sz_inout = 0;
if (*elems) { if (*elems) {
_XkbFree(*elems); _XkbFree(*elems);
*elems = NULL; *elems = NULL;
@ -115,12 +106,11 @@ register char *ptr;
else if (first + count >= (*num_inout)) else if (first + count >= (*num_inout))
*num_inout = first; *num_inout = first;
else { else {
i= ((*num_inout)-(first+count))*elem_sz; i = ((*num_inout) - first + count) * elem_sz;
ptr = *elems; ptr = *elems;
memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i); memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i);
(*num_inout) -= count; (*num_inout) -= count;
} }
return;
} }
static void static void
@ -136,33 +126,25 @@ XkbPropertyPtr prop= (XkbPropertyPtr)prop_in;
_XkbFree(prop->value); _XkbFree(prop->value);
prop->value = NULL; prop->value = NULL;
} }
return;
} }
void void
XkbcFreeGeomProperties( XkbGeometryPtr geom, XkbcFreeGeomProperties(XkbGeometryPtr geom, int first, int count, Bool freeAll)
int first,
int count,
Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_properties, &geom->sz_properties, &geom->num_properties, &geom->sz_properties,
(char **)&geom->properties, (char **)&geom->properties,
sizeof(XkbPropertyRec),_XkbClearProperty); sizeof(XkbPropertyRec),
return; _XkbClearProperty);
} }
void void
XkbcFreeGeomKeyAliases( XkbGeometryPtr geom, XkbcFreeGeomKeyAliases(XkbGeometryPtr geom, int first, int count, Bool freeAll)
int first,
int count,
Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll, first, count, _XkbFreeGeomLeafElems(freeAll, first, count,
&geom->num_key_aliases, &geom->sz_key_aliases, &geom->num_key_aliases, &geom->sz_key_aliases,
(char **)&geom->key_aliases, (char **)&geom->key_aliases,
sizeof(XkbKeyAliasRec)); sizeof(XkbKeyAliasRec));
return;
} }
static void static void
@ -172,7 +154,6 @@ XkbColorPtr color= (XkbColorPtr)color_in;
if (color->spec) if (color->spec)
_XkbFree(color->spec); _XkbFree(color->spec);
return;
} }
void void
@ -180,9 +161,8 @@ XkbcFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_colors, &geom->sz_colors, &geom->num_colors, &geom->sz_colors,
(char **)&geom->colors, (char **)&geom->colors, sizeof(XkbColorRec),
sizeof(XkbColorRec),_XkbClearColor); _XkbClearColor);
return;
} }
void void
@ -190,9 +170,7 @@ XkbcFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll, first, count, _XkbFreeGeomLeafElems(freeAll, first, count,
&outline->num_points, &outline->sz_points, &outline->num_points, &outline->sz_points,
(char **)&outline->points, (char **)&outline->points, sizeof(XkbPointRec));
sizeof(XkbPointRec));
return;
} }
static void static void
@ -200,9 +178,8 @@ _XkbClearOutline(char *outline_in)
{ {
XkbOutlinePtr outline = (XkbOutlinePtr)outline_in; XkbOutlinePtr outline = (XkbOutlinePtr)outline_in;
if (outline->points!=NULL) if (outline->points)
XkbcFreeGeomPoints(outline, 0, outline->num_points, True); XkbcFreeGeomPoints(outline, 0, outline->num_points, True);
return;
} }
void void
@ -210,10 +187,8 @@ XkbcFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&shape->num_outlines, &shape->sz_outlines, &shape->num_outlines, &shape->sz_outlines,
(char **)&shape->outlines, (char **)&shape->outlines, sizeof(XkbOutlineRec),
sizeof(XkbOutlineRec),_XkbClearOutline); _XkbClearOutline);
return;
} }
static void static void
@ -223,7 +198,6 @@ XkbShapePtr shape= (XkbShapePtr)shape_in;
if (shape->outlines) if (shape->outlines)
XkbcFreeGeomOutlines(shape, 0, shape->num_outlines, True); XkbcFreeGeomOutlines(shape, 0, shape->num_outlines, True);
return;
} }
void void
@ -231,19 +205,17 @@ XkbcFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_shapes, &geom->sz_shapes, &geom->num_shapes, &geom->sz_shapes,
(char **)&geom->shapes, (char **)&geom->shapes, sizeof(XkbShapeRec),
sizeof(XkbShapeRec),_XkbClearShape); _XkbClearShape);
return;
} }
void void
XkbcFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll) XkbcFreeGeomOverlayKeys(XkbOverlayRowPtr row, int first, int count,
Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll, first, count, _XkbFreeGeomLeafElems(freeAll, first, count,
&row->num_keys, &row->sz_keys, &row->num_keys, &row->sz_keys,
(char **)&row->keys, (char **)&row->keys, sizeof(XkbOverlayKeyRec));
sizeof(XkbOverlayKeyRec));
return;
} }
@ -252,19 +224,19 @@ _XkbClearOverlayRow(char *row_in)
{ {
XkbOverlayRowPtr row = (XkbOverlayRowPtr)row_in; XkbOverlayRowPtr row = (XkbOverlayRowPtr)row_in;
if (row->keys!=NULL) if (row->keys)
XkbcFreeGeomOverlayKeys(row, 0, row->num_keys, True); XkbcFreeGeomOverlayKeys(row, 0, row->num_keys, True);
return;
} }
void void
XkbcFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll) XkbcFreeGeomOverlayRows(XkbOverlayPtr overlay, int first, int count,
Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&overlay->num_rows, &overlay->sz_rows, &overlay->num_rows, &overlay->sz_rows,
(char **)&overlay->rows, (char **)&overlay->rows,
sizeof(XkbOverlayRowRec),_XkbClearOverlayRow); sizeof(XkbOverlayRowRec),
return; _XkbClearOverlayRow);
} }
@ -273,9 +245,8 @@ _XkbClearOverlay(char *overlay_in)
{ {
XkbOverlayPtr overlay = (XkbOverlayPtr)overlay_in; XkbOverlayPtr overlay = (XkbOverlayPtr)overlay_in;
if (overlay->rows!=NULL) if (overlay->rows)
XkbcFreeGeomOverlayRows(overlay, 0, overlay->num_rows, True); XkbcFreeGeomOverlayRows(overlay, 0, overlay->num_rows, True);
return;
} }
void void
@ -284,8 +255,8 @@ XkbcFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll)
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&section->num_overlays, &section->sz_overlays, &section->num_overlays, &section->sz_overlays,
(char **)&section->overlays, (char **)&section->overlays,
sizeof(XkbOverlayRec),_XkbClearOverlay); sizeof(XkbOverlayRec),
return; _XkbClearOverlay);
} }
@ -294,9 +265,7 @@ XkbcFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll, first, count, _XkbFreeGeomLeafElems(freeAll, first, count,
&row->num_keys, &row->sz_keys, &row->num_keys, &row->sz_keys,
(char **)&row->keys, (char **)&row->keys, sizeof(XkbKeyRec));
sizeof(XkbKeyRec));
return;
} }
@ -305,9 +274,8 @@ _XkbClearRow(char *row_in)
{ {
XkbRowPtr row = (XkbRowPtr)row_in; XkbRowPtr row = (XkbRowPtr)row_in;
if (row->keys!=NULL) if (row->keys)
XkbcFreeGeomKeys(row, 0, row->num_keys, True); XkbcFreeGeomKeys(row, 0, row->num_keys, True);
return;
} }
void void
@ -315,8 +283,8 @@ XkbcFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&section->num_rows, &section->sz_rows, &section->num_rows, &section->sz_rows,
(char **)&section->rows, (char **)&section->rows, sizeof(XkbRowRec),
sizeof(XkbRowRec),_XkbClearRow); _XkbClearRow);
} }
@ -325,13 +293,12 @@ _XkbClearSection(char *section_in)
{ {
XkbSectionPtr section = (XkbSectionPtr)section_in; XkbSectionPtr section = (XkbSectionPtr)section_in;
if (section->rows!=NULL) if (section->rows)
XkbcFreeGeomRows(section, 0, section->num_rows, True); XkbcFreeGeomRows(section, 0, section->num_rows, True);
if (section->doodads!=NULL) { if (section->doodads) {
XkbcFreeGeomDoodads(section->doodads, section->num_doodads, True); XkbcFreeGeomDoodads(section->doodads, section->num_doodads, True);
section->doodads = NULL; section->doodads = NULL;
} }
return;
} }
void void
@ -339,9 +306,8 @@ XkbcFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll, first, count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_sections, &geom->sz_sections, &geom->num_sections, &geom->sz_sections,
(char **)&geom->sections, (char **)&geom->sections, sizeof(XkbSectionRec),
sizeof(XkbSectionRec),_XkbClearSection); _XkbClearSection);
return;
} }
@ -352,147 +318,162 @@ XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in;
switch (doodad->any.type) { switch (doodad->any.type) {
case XkbTextDoodad: case XkbTextDoodad:
{ if (doodad->text.text) {
if (doodad->text.text!=NULL) {
_XkbFree(doodad->text.text); _XkbFree(doodad->text.text);
doodad->text.text = NULL; doodad->text.text = NULL;
} }
if (doodad->text.font!=NULL) { if (doodad->text.font) {
_XkbFree(doodad->text.font); _XkbFree(doodad->text.font);
doodad->text.font = NULL; doodad->text.font = NULL;
} }
}
break; break;
case XkbLogoDoodad: case XkbLogoDoodad:
{ if (doodad->logo.logo_name) {
if (doodad->logo.logo_name!=NULL) {
_XkbFree(doodad->logo.logo_name); _XkbFree(doodad->logo.logo_name);
doodad->logo.logo_name = NULL; doodad->logo.logo_name = NULL;
} }
}
break; break;
} }
return;
} }
void void
XkbcFreeGeomDoodads(XkbDoodadPtr doodads, int nDoodads, Bool freeAll) XkbcFreeGeomDoodads(XkbDoodadPtr doodads, int nDoodads, Bool freeAll)
{ {
register int i; int i;
register XkbDoodadPtr doodad; XkbDoodadPtr doodad;
if (doodads) { if (doodads) {
for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) { for (i = 0, doodad = doodads; i < nDoodads; i++, doodad++)
_XkbClearDoodad((char *)doodad); _XkbClearDoodad((char *)doodad);
}
if (freeAll) if (freeAll)
_XkbFree(doodads); _XkbFree(doodads);
} }
return;
} }
void void
XkbcFreeGeometry(XkbGeometryPtr geom, unsigned which, Bool freeMap) XkbcFreeGeometry(XkbGeometryPtr geom, unsigned which, Bool freeMap)
{ {
if (geom==NULL) if (!geom)
return; return;
if (freeMap) if (freeMap)
which = XkbGeomAllMask; which = XkbGeomAllMask;
if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL))
if ((which & XkbGeomPropertiesMask) && geom->properties)
XkbcFreeGeomProperties(geom, 0, geom->num_properties, True); XkbcFreeGeomProperties(geom, 0, geom->num_properties, True);
if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL))
if ((which & XkbGeomColorsMask) && geom->colors)
XkbcFreeGeomColors(geom, 0, geom->num_colors, True); XkbcFreeGeomColors(geom, 0, geom->num_colors, True);
if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL))
if ((which & XkbGeomShapesMask) && geom->shapes)
XkbcFreeGeomShapes(geom, 0, geom->num_shapes, True); XkbcFreeGeomShapes(geom, 0, geom->num_shapes, True);
if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL))
if ((which & XkbGeomSectionsMask) && geom->sections)
XkbcFreeGeomSections(geom, 0, geom->num_sections, True); XkbcFreeGeomSections(geom, 0, geom->num_sections, True);
if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) {
if ((which & XkbGeomDoodadsMask) && geom->doodads) {
XkbcFreeGeomDoodads(geom->doodads, geom->num_doodads, True); XkbcFreeGeomDoodads(geom->doodads, geom->num_doodads, True);
geom->doodads = NULL; geom->doodads = NULL;
geom->num_doodads = geom->sz_doodads = 0; geom->num_doodads = geom->sz_doodads = 0;
} }
if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
if ((which & XkbGeomKeyAliasesMask) && geom->key_aliases)
XkbcFreeGeomKeyAliases(geom, 0, geom->num_key_aliases, True); XkbcFreeGeomKeyAliases(geom, 0, geom->num_key_aliases, True);
if (freeMap) { if (freeMap) {
if (geom->label_font!=NULL) { if (geom->label_font) {
_XkbFree(geom->label_font); _XkbFree(geom->label_font);
geom->label_font = NULL; geom->label_font = NULL;
} }
_XkbFree(geom); _XkbFree(geom);
} }
return;
} }
static int static int
_XkbGeomAlloc( char ** old, _XkbGeomAlloc(char **old, unsigned short *num, unsigned short *total,
unsigned short * num, int num_new, size_t sz_elem)
unsigned short * total,
int num_new,
size_t sz_elem)
{ {
if (num_new < 1) if (num_new < 1)
return Success; return Success;
if ((*old)==NULL)
if (!(*old))
*num = *total = 0; *num = *total = 0;
if ((*num) + num_new <= (*total)) if ((*num) + num_new <= (*total))
return Success; return Success;
*total = (*num) + num_new; *total = (*num) + num_new;
if ((*old)!=NULL)
(*old)= (char *)_XkbRealloc((*old),(*total)*sz_elem); if (*old)
else (*old)= (char *)_XkbCalloc((*total),sz_elem); *old = (char *)_XkbRealloc(*old, (*total) * sz_elem);
if ((*old)==NULL) { else
*old = (char *)_XkbCalloc(*total, sz_elem);
if (!(*old)) {
*total = *num = 0; *total = *num = 0;
return BadAlloc; return BadAlloc;
} }
if (*num > 0) { if (*num > 0) {
char *tmp= (char *)(*old); char *tmp = *old;
bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem)); bzero(&tmp[sz_elem * (*num)], num_new * sz_elem);
} }
return Success; return Success;
} }
#define _XkbAllocProps(g, n) _XkbGeomAlloc((char **)&(g)->properties, \ #define _XkbAllocProps(g, n) _XkbGeomAlloc((char **)&(g)->properties, \
&(g)->num_properties,&(g)->sz_properties,\ &(g)->num_properties, \
&(g)->sz_properties, \
(n), sizeof(XkbPropertyRec)) (n), sizeof(XkbPropertyRec))
#define _XkbAllocColors(g, n) _XkbGeomAlloc((char **)&(g)->colors, \ #define _XkbAllocColors(g, n) _XkbGeomAlloc((char **)&(g)->colors, \
&(g)->num_colors,&(g)->sz_colors,\ &(g)->num_colors, \
&(g)->sz_colors, \
(n), sizeof(XkbColorRec)) (n), sizeof(XkbColorRec))
#define _XkbAllocShapes(g, n) _XkbGeomAlloc((char **)&(g)->shapes, \ #define _XkbAllocShapes(g, n) _XkbGeomAlloc((char **)&(g)->shapes, \
&(g)->num_shapes,&(g)->sz_shapes,\ &(g)->num_shapes, \
&(g)->sz_shapes, \
(n), sizeof(XkbShapeRec)) (n), sizeof(XkbShapeRec))
#define _XkbAllocSections(g, n) _XkbGeomAlloc((char **)&(g)->sections, \ #define _XkbAllocSections(g, n) _XkbGeomAlloc((char **)&(g)->sections, \
&(g)->num_sections,&(g)->sz_sections,\ &(g)->num_sections, \
&(g)->sz_sections, \
(n), sizeof(XkbSectionRec)) (n), sizeof(XkbSectionRec))
#define _XkbAllocDoodads(g, n) _XkbGeomAlloc((char **)&(g)->doodads, \ #define _XkbAllocDoodads(g, n) _XkbGeomAlloc((char **)&(g)->doodads, \
&(g)->num_doodads,&(g)->sz_doodads,\ &(g)->num_doodads, \
&(g)->sz_doodads, \
(n), sizeof(XkbDoodadRec)) (n), sizeof(XkbDoodadRec))
#define _XkbAllocKeyAliases(g, n) _XkbGeomAlloc((char **)&(g)->key_aliases, \ #define _XkbAllocKeyAliases(g, n) _XkbGeomAlloc((char **)&(g)->key_aliases, \
&(g)->num_key_aliases,&(g)->sz_key_aliases,\ &(g)->num_key_aliases, \
&(g)->sz_key_aliases, \
(n), sizeof(XkbKeyAliasRec)) (n), sizeof(XkbKeyAliasRec))
#define _XkbAllocOutlines(s, n) _XkbGeomAlloc((char **)&(s)->outlines, \ #define _XkbAllocOutlines(s, n) _XkbGeomAlloc((char **)&(s)->outlines, \
&(s)->num_outlines,&(s)->sz_outlines,\ &(s)->num_outlines, \
&(s)->sz_outlines, \
(n), sizeof(XkbOutlineRec)) (n), sizeof(XkbOutlineRec))
#define _XkbAllocRows(s, n) _XkbGeomAlloc((char **)&(s)->rows, \ #define _XkbAllocRows(s, n) _XkbGeomAlloc((char **)&(s)->rows, \
&(s)->num_rows,&(s)->sz_rows,\ &(s)->num_rows, \
&(s)->sz_rows, \
(n), sizeof(XkbRowRec)) (n), sizeof(XkbRowRec))
#define _XkbAllocPoints(o, n) _XkbGeomAlloc((char **)&(o)->points, \ #define _XkbAllocPoints(o, n) _XkbGeomAlloc((char **)&(o)->points, \
&(o)->num_points,&(o)->sz_points,\ &(o)->num_points, \
&(o)->sz_points, \
(n), sizeof(XkbPointRec)) (n), sizeof(XkbPointRec))
#define _XkbAllocKeys(r, n) _XkbGeomAlloc((char **)&(r)->keys, \ #define _XkbAllocKeys(r, n) _XkbGeomAlloc((char **)&(r)->keys, \
&(r)->num_keys,&(r)->sz_keys,\ &(r)->num_keys, \
&(r)->sz_keys, \
(n), sizeof(XkbKeyRec)) (n), sizeof(XkbKeyRec))
#define _XkbAllocOverlays(s, n) _XkbGeomAlloc((char **)&(s)->overlays, \ #define _XkbAllocOverlays(s, n) _XkbGeomAlloc((char **)&(s)->overlays, \
&(s)->num_overlays,&(s)->sz_overlays,\ &(s)->num_overlays, \
&(s)->sz_overlays, \
(n), sizeof(XkbOverlayRec)) (n), sizeof(XkbOverlayRec))
#define _XkbAllocOverlayRows(o, n) _XkbGeomAlloc((char **)&(o)->rows, \ #define _XkbAllocOverlayRows(o, n) _XkbGeomAlloc((char **)&(o)->rows, \
&(o)->num_rows,&(o)->sz_rows,\ &(o)->num_rows, \
&(o)->sz_rows, \
(n), sizeof(XkbOverlayRowRec)) (n), sizeof(XkbOverlayRowRec))
#define _XkbAllocOverlayKeys(r, n) _XkbGeomAlloc((char **)&(r)->keys, \ #define _XkbAllocOverlayKeys(r, n) _XkbGeomAlloc((char **)&(r)->keys, \
&(r)->num_keys,&(r)->sz_keys,\ &(r)->num_keys, \
&(r)->sz_keys, \
(n), sizeof(XkbOverlayKeyRec)) (n), sizeof(XkbOverlayKeyRec))
int int
@ -501,38 +482,39 @@ XkbcAllocGeometry(XkbcDescPtr xkb,XkbGeometrySizesPtr sizes)
XkbGeometryPtr geom; XkbGeometryPtr geom;
int rtrn; int rtrn;
if (xkb->geom==NULL) { if (!xkb->geom) {
xkb->geom = _XkbTypedCalloc(1, XkbGeometryRec); xkb->geom = _XkbTypedCalloc(1, XkbGeometryRec);
if (!xkb->geom) if (!xkb->geom)
return BadAlloc; return BadAlloc;
} }
geom = xkb->geom; geom = xkb->geom;
if ((sizes->which & XkbGeomPropertiesMask) && if ((sizes->which & XkbGeomPropertiesMask) &&
((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) { ((rtrn = _XkbAllocProps(geom, sizes->num_properties)) != Success))
goto BAIL; goto bail;
}
if ((sizes->which & XkbGeomColorsMask) && if ((sizes->which & XkbGeomColorsMask) &&
((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) { ((rtrn = _XkbAllocColors(geom, sizes->num_colors)) != Success))
goto BAIL; goto bail;
}
if ((sizes->which & XkbGeomShapesMask) && if ((sizes->which & XkbGeomShapesMask) &&
((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) { ((rtrn = _XkbAllocShapes(geom, sizes->num_shapes)) != Success))
goto BAIL; goto bail;
}
if ((sizes->which & XkbGeomSectionsMask) && if ((sizes->which & XkbGeomSectionsMask) &&
((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) { ((rtrn = _XkbAllocSections(geom, sizes->num_sections)) != Success))
goto BAIL; goto bail;
}
if ((sizes->which & XkbGeomDoodadsMask) && if ((sizes->which & XkbGeomDoodadsMask) &&
((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) { ((rtrn = _XkbAllocDoodads(geom, sizes->num_doodads)) != Success))
goto BAIL; goto bail;
}
if ((sizes->which & XkbGeomKeyAliasesMask) && if ((sizes->which & XkbGeomKeyAliasesMask) &&
((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) { ((rtrn = _XkbAllocKeyAliases(geom, sizes->num_key_aliases)) != Success))
goto BAIL; goto bail;
}
return Success; return Success;
BAIL: bail:
XkbcFreeGeometry(geom, XkbGeomAllMask, True); XkbcFreeGeometry(geom, XkbGeomAllMask, True);
xkb->geom = NULL; xkb->geom = NULL;
return rtrn; return rtrn;