static void
-XkbcFreeCompatMap(struct xkb_desc * xkb, unsigned which, Bool freeMap)
+XkbcFreeCompatMap(struct xkb_desc * xkb)
{
struct xkb_compat_map * compat;
return;
compat = xkb->compat;
- if (freeMap)
- which = XkbAllCompatMask;
- if (which & XkbGroupCompatMask)
- memset(&compat->groups[0], 0,
- XkbNumKbdGroups * sizeof(struct xkb_mods));
-
- if (which & XkbSymInterpMask) {
- free(compat->sym_interpret);
- compat->size_si = compat->num_si = 0;
- compat->sym_interpret = NULL;
- }
-
- if (freeMap) {
- free(compat);
- xkb->compat = NULL;
- }
+ free(compat->sym_interpret);
+ free(compat);
+ xkb->compat = NULL;
}
int
}
static void
-XkbcFreeNames(struct xkb_desc * xkb, unsigned which, Bool freeMap)
+XkbcFreeNames(struct xkb_desc * xkb)
{
struct xkb_names * names;
+ struct xkb_client_map * map;
if (!xkb || !xkb->names)
return;
names = xkb->names;
- if (freeMap)
- which = XkbAllNamesMask;
+ map = xkb->map;
- if (which & XkbKTLevelNamesMask) {
- struct xkb_client_map * map = xkb->map;
-
- if (map && map->types) {
- int i;
- struct xkb_key_type * type = map->types;
+ if (map && map->types) {
+ int i;
+ struct xkb_key_type * type = map->types;
- for (i = 0; i < map->num_types; i++, type++) {
- free(type->level_names);
- type->level_names = NULL;
- }
+ for (i = 0; i < map->num_types; i++, type++) {
+ free(type->level_names);
+ type->level_names = NULL;
}
}
- if (which & XkbKeyNamesMask) {
- free(names->keys);
- names->keys = NULL;
- names->num_keys = 0;
- }
-
- if (which & XkbKeyAliasesMask) {
- free(names->key_aliases);
- names->key_aliases = NULL;
- names->num_key_aliases = 0;
- }
-
- if (which & XkbRGNamesMask) {
- free(names->radio_groups);
- names->radio_groups = NULL;
- names->num_rg = 0;
- }
-
- if (freeMap) {
- free(names);
- xkb->names = NULL;
- }
+ free(names->keys);
+ free(names->key_aliases);
+ free(names->radio_groups);
+ free(names);
+ xkb->names = NULL;
}
int
}
static void
-XkbcFreeControls(struct xkb_desc * xkb, unsigned which, Bool freeMap)
+XkbcFreeControls(struct xkb_desc * xkb)
{
- if (freeMap && xkb && xkb->ctrls) {
+ if (xkb && xkb->ctrls) {
free(xkb->ctrls->per_key_repeat);
free(xkb->ctrls);
xkb->ctrls = NULL;
}
void
-XkbcFreeKeyboard(struct xkb_desc * xkb, unsigned which, Bool freeAll)
+XkbcFreeKeyboard(struct xkb_desc * xkb)
{
if (!xkb)
return;
- if (freeAll)
- which = XkbAllComponentsMask;
-
- if (which & XkbClientMapMask)
- XkbcFreeClientMap(xkb, XkbAllClientInfoMask, True);
- if (which & XkbServerMapMask)
- XkbcFreeServerMap(xkb, XkbAllServerInfoMask, True);
- if (which & XkbCompatMapMask)
- XkbcFreeCompatMap(xkb, XkbAllCompatMask, True);
- if (which & XkbIndicatorMapMask)
- XkbcFreeIndicatorMaps(xkb);
- if (which & XkbNamesMask)
- XkbcFreeNames(xkb, XkbAllNamesMask, True);
- if ((which & XkbGeometryMask) && xkb->geom)
- XkbcFreeGeometry(xkb->geom, XkbGeomAllMask, True);
- if (which & XkbControlsMask)
- XkbcFreeControls(xkb, XkbAllControlsMask, True);
- if (freeAll)
- free(xkb);
+ XkbcFreeClientMap(xkb);
+ XkbcFreeServerMap(xkb);
+ XkbcFreeCompatMap(xkb);
+ XkbcFreeIndicatorMaps(xkb);
+ XkbcFreeNames(xkb);
+ XkbcFreeGeometry(xkb);
+ XkbcFreeControls(xkb);
+ free(xkb);
}
#include "XKBcommonint.h"
#include <X11/extensions/XKB.h>
-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)) {
- *num_inout = *sz_inout = 0;
- free(*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 = *elems;
- int extra = ((*num_inout) - first + count) * elem_sz;
-
- if (extra > 0)
- memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz],
- extra);
-
- (*num_inout) -= count;
- }
-}
-
-typedef void (*ContentsClearFunc)(char *priv);
+typedef void (*ContentsClearFunc)(void *priv);
static void
-_XkbFreeGeomNonLeafElems(Bool freeAll, int first, int count,
- unsigned short *num_inout, unsigned short *sz_inout,
- char **elems, unsigned int elem_sz,
+_XkbFreeGeomNonLeafElems(unsigned short *num_inout, unsigned short *sz_inout,
+ void *elems, size_t elem_sz,
ContentsClearFunc freeFunc)
{
int i;
- char *ptr;
+ char *start, *ptr;
- if (freeAll) {
- first = 0;
- count = *num_inout;
- }
- else if ((first >= (*num_inout)) || (first < 0) || (count < 1))
+ if (!elems)
return;
- else if (first + count > (*num_inout))
- count = (*num_inout) - first;
- if (!(*elems))
+ start = *(char **)elems;
+ if (!start)
return;
- if (freeFunc) {
- ptr = *elems;
- ptr += first * elem_sz;
- for (i = 0; i < count; i++) {
- (*freeFunc)(ptr);
- ptr += elem_sz;
- }
+ ptr = start;
+ for (i = 0; i < *num_inout; i++) {
+ freeFunc(ptr);
+ ptr += elem_sz;
}
- if (freeAll) {
- *num_inout = *sz_inout = 0;
- free(*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;
- }
+ *num_inout = *sz_inout = 0;
+ free(start);
}
static void
-_XkbClearProperty(char *prop_in)
+_XkbClearProperty(void *prop_in)
{
- struct xkb_property * prop = (struct xkb_property *)prop_in;
+ struct xkb_property * prop = prop_in;
free(prop->name);
prop->name = NULL;
}
static void
-XkbcFreeGeomProperties(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomProperties(struct xkb_geometry * geom)
{
- _XkbFreeGeomNonLeafElems(freeAll, first, count,
- &geom->num_properties, &geom->sz_properties,
- (char **)&geom->properties,
- sizeof(struct xkb_property),
+ _XkbFreeGeomNonLeafElems(&geom->num_properties, &geom->sz_properties,
+ &geom->properties, sizeof(struct xkb_property),
_XkbClearProperty);
}
static void
-XkbcFreeGeomKeyAliases(struct xkb_geometry * geom, int first, int count, Bool freeAll)
-{
- _XkbFreeGeomLeafElems(freeAll, first, count,
- &geom->num_key_aliases, &geom->sz_key_aliases,
- (char **)&geom->key_aliases,
- sizeof(struct xkb_key_alias));
-}
-
-static void
-_XkbClearColor(char *color_in)
+_XkbClearColor(void *color_in)
{
- struct xkb_color * color = (struct xkb_color *)color_in;
+ struct xkb_color * color = color_in;
free(color->spec);
}
static void
-XkbcFreeGeomColors(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomColors(struct xkb_geometry * geom)
{
- _XkbFreeGeomNonLeafElems(freeAll, first, count,
- &geom->num_colors, &geom->sz_colors,
- (char **)&geom->colors, sizeof(struct xkb_color),
+ _XkbFreeGeomNonLeafElems(&geom->num_colors, &geom->sz_colors,
+ &geom->colors, sizeof(struct xkb_color),
_XkbClearColor);
}
static void
-XkbcFreeGeomPoints(struct xkb_outline * outline, int first, int count, Bool freeAll)
+_XkbClearOutline(void *outline_in)
{
- _XkbFreeGeomLeafElems(freeAll, first, count,
- &outline->num_points, &outline->sz_points,
- (char **)&outline->points, sizeof(struct xkb_point));
-}
-
-static void
-_XkbClearOutline(char *outline_in)
-{
- struct xkb_outline * outline = (struct xkb_outline *)outline_in;
+ struct xkb_outline * outline = outline_in;
- if (outline->points)
- XkbcFreeGeomPoints(outline, 0, outline->num_points, True);
+ free(outline->points);
}
static void
-XkbcFreeGeomOutlines(struct xkb_shape * shape, int first, int count, Bool freeAll)
+XkbcFreeGeomOutlines(struct xkb_shape * shape)
{
- _XkbFreeGeomNonLeafElems(freeAll, first, count,
- &shape->num_outlines, &shape->sz_outlines,
- (char **)&shape->outlines, sizeof(struct xkb_outline),
+ _XkbFreeGeomNonLeafElems(&shape->num_outlines, &shape->sz_outlines,
+ &shape->outlines, sizeof(struct xkb_outline),
_XkbClearOutline);
}
static void
-_XkbClearShape(char *shape_in)
+_XkbClearShape(void *shape_in)
{
- struct xkb_shape * shape = (struct xkb_shape *)shape_in;
+ struct xkb_shape * shape = shape_in;
- if (shape->outlines)
- XkbcFreeGeomOutlines(shape, 0, shape->num_outlines, True);
+ XkbcFreeGeomOutlines(shape);
}
static void
-XkbcFreeGeomShapes(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomShapes(struct xkb_geometry * geom)
{
- _XkbFreeGeomNonLeafElems(freeAll, first, count,
- &geom->num_shapes, &geom->sz_shapes,
- (char **)&geom->shapes, sizeof(struct xkb_shape),
+ _XkbFreeGeomNonLeafElems(&geom->num_shapes, &geom->sz_shapes,
+ &geom->shapes, sizeof(struct xkb_shape),
_XkbClearShape);
}
static void
-XkbcFreeGeomKeys(struct xkb_row * row, int first, int count, Bool freeAll)
+_XkbClearRow(void *row_in)
{
- _XkbFreeGeomLeafElems(freeAll, first, count,
- &row->num_keys, &row->sz_keys,
- (char **)&row->keys, sizeof(struct xkb_key));
-}
+ struct xkb_row * row = row_in;
-static void
-_XkbClearRow(char *row_in)
-{
- struct xkb_row * row = (struct xkb_row *)row_in;
-
- if (row->keys)
- XkbcFreeGeomKeys(row, 0, row->num_keys, True);
+ free(row->keys);
}
static void
-XkbcFreeGeomRows(struct xkb_section * section, int first, int count, Bool freeAll)
+XkbcFreeGeomRows(struct xkb_section * section)
{
- _XkbFreeGeomNonLeafElems(freeAll, first, count,
- §ion->num_rows, §ion->sz_rows,
- (char **)§ion->rows, sizeof(struct xkb_row),
+ _XkbFreeGeomNonLeafElems(§ion->num_rows, §ion->sz_rows,
+ §ion->rows, sizeof(struct xkb_row),
_XkbClearRow);
}
-
-
static void
-_XkbClearDoodad(char *doodad_in)
+_XkbClearDoodad(union xkb_doodad *doodad)
{
- union xkb_doodad * doodad = (union xkb_doodad *)doodad_in;
-
switch (doodad->any.type) {
case XkbTextDoodad:
free(doodad->text.text);
}
static void
-XkbcFreeGeomDoodads(union xkb_doodad * doodads, int nDoodads, Bool freeAll)
+XkbcFreeGeomDoodads(union xkb_doodad * doodads, int nDoodads)
{
int i;
union xkb_doodad * doodad;
for (i = 0, doodad = doodads; i < nDoodads && doodad; i++, doodad++)
- _XkbClearDoodad((char *)doodad);
- if (freeAll)
- free(doodads);
+ _XkbClearDoodad(doodad);
+ free(doodads);
}
static void
-_XkbClearSection(char *section_in)
+_XkbClearSection(void *section_in)
{
- struct xkb_section * section = (struct xkb_section *)section_in;
+ struct xkb_section * section = section_in;
- if (section->rows)
- XkbcFreeGeomRows(section, 0, section->num_rows, True);
- XkbcFreeGeomDoodads(section->doodads, section->num_doodads, True);
+ XkbcFreeGeomRows(section);
+ XkbcFreeGeomDoodads(section->doodads, section->num_doodads);
section->doodads = NULL;
}
static void
-XkbcFreeGeomSections(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomSections(struct xkb_geometry * geom)
{
- _XkbFreeGeomNonLeafElems(freeAll, first, count,
- &geom->num_sections, &geom->sz_sections,
- (char **)&geom->sections, sizeof(struct xkb_section),
+ _XkbFreeGeomNonLeafElems(&geom->num_sections, &geom->sz_sections,
+ &geom->sections, sizeof(struct xkb_section),
_XkbClearSection);
}
void
-XkbcFreeGeometry(struct xkb_geometry * geom, unsigned which, Bool freeMap)
+XkbcFreeGeometry(struct xkb_desc * xkb)
{
- if (!geom)
- return;
-
- if (freeMap)
- which = XkbGeomAllMask;
-
- if ((which & XkbGeomPropertiesMask) && geom->properties)
- XkbcFreeGeomProperties(geom, 0, geom->num_properties, True);
-
- if ((which & XkbGeomColorsMask) && geom->colors)
- XkbcFreeGeomColors(geom, 0, geom->num_colors, True);
-
- if ((which & XkbGeomShapesMask) && geom->shapes)
- XkbcFreeGeomShapes(geom, 0, geom->num_shapes, True);
+ struct xkb_geometry *geom;
- if ((which & XkbGeomSectionsMask) && geom->sections)
- XkbcFreeGeomSections(geom, 0, geom->num_sections, True);
-
- if ((which & XkbGeomDoodadsMask) && geom->doodads) {
- XkbcFreeGeomDoodads(geom->doodads, geom->num_doodads, True);
- geom->doodads = NULL;
- geom->num_doodads = geom->sz_doodads = 0;
- }
+ if (!xkb || !xkb->geom)
+ return;
- if ((which & XkbGeomKeyAliasesMask) && geom->key_aliases)
- XkbcFreeGeomKeyAliases(geom, 0, geom->num_key_aliases, True);
+ geom = xkb->geom;
- if (freeMap) {
- free(geom->label_font);
- geom->label_font = NULL;
- free(geom);
- }
+ XkbcFreeGeomProperties(geom);
+ XkbcFreeGeomColors(geom);
+ XkbcFreeGeomShapes(geom);
+ XkbcFreeGeomSections(geom);
+ XkbcFreeGeomDoodads(geom->doodads, geom->num_doodads);
+ free(geom->key_aliases);
+ free(geom->label_font);
+ free(geom);
}
static int
return Success;
bail:
- XkbcFreeGeometry(geom, XkbGeomAllMask, True);
+ XkbcFreeGeometry(xkb);
xkb->geom = NULL;
return rtrn;
}