Remove alloc.{c,h}
These functions are more appropriate elsewhere now. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
13eb9c357d
commit
74be17627e
|
@ -61,8 +61,6 @@ libxkbcommon_la_SOURCES = \
|
|||
src/xkbcomp/xkbcomp.c \
|
||||
src/xkbcomp/xkbcomp.h \
|
||||
src/xkbcomp/xkbcomp-priv.h \
|
||||
src/alloc.c \
|
||||
src/alloc.h \
|
||||
src/atom.c \
|
||||
src/atom.h \
|
||||
src/context.c \
|
||||
|
|
167
src/alloc.c
167
src/alloc.c
|
@ -1,167 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* 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 Silicon Graphics not be
|
||||
* used in advertising or publicity pertaining to distribution
|
||||
* of the software without specific prior written permission.
|
||||
* Silicon Graphics makes no representation about the suitability
|
||||
* of this software for any purpose. It is provided "as is"
|
||||
* without any express or implied warranty.
|
||||
*
|
||||
* SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
||||
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
||||
* GRAPHICS 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.
|
||||
*/
|
||||
|
||||
#include "xkb-priv.h"
|
||||
#include "alloc.h"
|
||||
|
||||
int
|
||||
XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!from || !into)
|
||||
return BadMatch;
|
||||
|
||||
darray_free(into->map);
|
||||
free(into->preserve);
|
||||
free(into->level_names);
|
||||
|
||||
*into = *from;
|
||||
darray_init(into->map);
|
||||
|
||||
darray_copy(into->map, from->map);
|
||||
|
||||
if (from->preserve && !darray_empty(into->map)) {
|
||||
into->preserve = calloc(darray_size(into->map),
|
||||
sizeof(*into->preserve));
|
||||
if (!into->preserve)
|
||||
return BadAlloc;
|
||||
memcpy(into->preserve, from->preserve,
|
||||
darray_size(into->map) * sizeof(*into->preserve));
|
||||
}
|
||||
|
||||
if (from->level_names && into->num_levels > 0) {
|
||||
into->level_names = calloc(into->num_levels,
|
||||
sizeof(*into->level_names));
|
||||
if (!into->level_names)
|
||||
return BadAlloc;
|
||||
|
||||
for (i = 0; i < into->num_levels; i++)
|
||||
into->level_names[i] = strdup(from->level_names[i]);
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
union xkb_action *
|
||||
XkbcResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
uint32_t needed)
|
||||
{
|
||||
size_t old_ndx, old_num_acts, new_ndx;
|
||||
|
||||
if (needed == 0) {
|
||||
key->acts_index = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (XkbKeyHasActions(key) && key->width >= needed)
|
||||
return XkbKeyActionsPtr(keymap, key);
|
||||
|
||||
/*
|
||||
* The key may already be in the array, but without enough space.
|
||||
* This should not happen often, so in order to avoid moving and
|
||||
* copying stuff from acts and key_acts, we just allocate new
|
||||
* space for the key at the end, and leave the old space alone.
|
||||
*/
|
||||
|
||||
old_ndx = key->acts_index;
|
||||
old_num_acts = XkbKeyNumActions(key);
|
||||
new_ndx = darray_size(keymap->acts);
|
||||
|
||||
darray_resize0(keymap->acts, new_ndx + needed);
|
||||
key->acts_index = new_ndx;
|
||||
|
||||
/*
|
||||
* The key was already in the array, copy the old actions to the
|
||||
* new space.
|
||||
*/
|
||||
if (old_ndx != 0)
|
||||
memcpy(darray_mem(keymap->acts, new_ndx),
|
||||
darray_mem(keymap->acts, old_ndx),
|
||||
old_num_acts * sizeof(union xkb_action));
|
||||
|
||||
return XkbKeyActionsPtr(keymap, key);
|
||||
}
|
||||
|
||||
static void
|
||||
free_types(struct xkb_keymap *keymap)
|
||||
{
|
||||
struct xkb_key_type *type;
|
||||
|
||||
darray_foreach(type, keymap->types) {
|
||||
darray_free(type->map);
|
||||
free(type->preserve);
|
||||
free(type->level_names);
|
||||
}
|
||||
darray_free(keymap->types);
|
||||
}
|
||||
|
||||
static void
|
||||
free_keys(struct xkb_keymap *keymap)
|
||||
{
|
||||
struct xkb_key *key;
|
||||
|
||||
darray_foreach(key, keymap->keys) {
|
||||
free(key->sym_index);
|
||||
free(key->num_syms);
|
||||
darray_free(key->syms);
|
||||
}
|
||||
|
||||
darray_free(keymap->keys);
|
||||
}
|
||||
|
||||
struct xkb_keymap *
|
||||
XkbcAllocKeyboard(struct xkb_context *ctx)
|
||||
{
|
||||
struct xkb_keymap *keymap;
|
||||
|
||||
keymap = calloc(1, sizeof(*keymap));
|
||||
if (!keymap)
|
||||
return NULL;
|
||||
|
||||
keymap->refcnt = 1;
|
||||
keymap->ctx = xkb_context_ref(ctx);
|
||||
|
||||
return keymap;
|
||||
}
|
||||
|
||||
void
|
||||
XkbcFreeKeyboard(struct xkb_keymap *keymap)
|
||||
{
|
||||
if (!keymap)
|
||||
return;
|
||||
|
||||
free_types(keymap);
|
||||
darray_free(keymap->acts);
|
||||
darray_free(keymap->sym_interpret);
|
||||
darray_free(keymap->key_aliases);
|
||||
free(keymap->keycodes_section_name);
|
||||
free(keymap->symbols_section_name);
|
||||
free(keymap->types_section_name);
|
||||
free(keymap->compat_section_name);
|
||||
free_keys(keymap);
|
||||
xkb_context_unref(keymap->ctx);
|
||||
free(keymap);
|
||||
}
|
45
src/alloc.h
45
src/alloc.h
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009 Dan Nicholson
|
||||
*
|
||||
* 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 THE
|
||||
* AUTHORS 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 names of the authors or their
|
||||
* institutions 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 authors.
|
||||
*/
|
||||
|
||||
#ifndef ALLOC_H
|
||||
#define ALLOC_H
|
||||
|
||||
#include "xkb-priv.h"
|
||||
|
||||
extern struct xkb_keymap *
|
||||
XkbcAllocKeyboard(struct xkb_context *ctx);
|
||||
|
||||
extern void
|
||||
XkbcFreeKeyboard(struct xkb_keymap *keymap);
|
||||
|
||||
extern int
|
||||
XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into);
|
||||
|
||||
extern union xkb_action *
|
||||
XkbcResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
uint32_t needed);
|
||||
|
||||
#endif /* ALLOC_H */
|
|
@ -1216,3 +1216,43 @@ ActionsInit(struct xkb_context *ctx)
|
|||
actionsInitialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
union xkb_action *
|
||||
ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
uint32_t needed)
|
||||
{
|
||||
size_t old_ndx, old_num_acts, new_ndx;
|
||||
|
||||
if (needed == 0) {
|
||||
key->acts_index = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (XkbKeyHasActions(key) && key->width >= needed)
|
||||
return XkbKeyActionsPtr(keymap, key);
|
||||
|
||||
/*
|
||||
* The key may already be in the array, but without enough space.
|
||||
* This should not happen often, so in order to avoid moving and
|
||||
* copying stuff from acts and key_acts, we just allocate new
|
||||
* space for the key at the end, and leave the old space alone.
|
||||
*/
|
||||
|
||||
old_ndx = key->acts_index;
|
||||
old_num_acts = XkbKeyNumActions(key);
|
||||
new_ndx = darray_size(keymap->acts);
|
||||
|
||||
darray_resize0(keymap->acts, new_ndx + needed);
|
||||
key->acts_index = new_ndx;
|
||||
|
||||
/*
|
||||
* The key was already in the array, copy the old actions to the
|
||||
* new space.
|
||||
*/
|
||||
if (old_ndx != 0)
|
||||
memcpy(darray_mem(keymap->acts, new_ndx),
|
||||
darray_mem(keymap->acts, old_ndx),
|
||||
old_num_acts * sizeof(union xkb_action));
|
||||
|
||||
return XkbKeyActionsPtr(keymap, key);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
|
|||
ExprDef *index, ExprDef *value,
|
||||
ActionInfo **info_rtrn);
|
||||
|
||||
union xkb_action *
|
||||
ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
uint32_t needed);
|
||||
|
||||
extern const LookupEntry ctrlNames[];
|
||||
|
||||
#endif /* ACTION_H */
|
||||
|
|
|
@ -1410,7 +1410,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
|
|||
|
||||
if (num_acts)
|
||||
num_acts = key->num_groups * key->width;
|
||||
acts = XkbcResizeKeyActions(keymap, key, num_acts);
|
||||
acts = ResizeKeyActions(keymap, key, num_acts);
|
||||
if (num_acts && !acts)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -1090,6 +1090,42 @@ static const struct xkb_key_type canonicalTypes[XkbNumRequiredTypes] = {
|
|||
}
|
||||
};
|
||||
|
||||
static int
|
||||
CopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into)
|
||||
{
|
||||
int i;
|
||||
|
||||
darray_free(into->map);
|
||||
free(into->preserve);
|
||||
free(into->level_names);
|
||||
|
||||
*into = *from;
|
||||
darray_init(into->map);
|
||||
|
||||
darray_copy(into->map, from->map);
|
||||
|
||||
if (from->preserve && !darray_empty(into->map)) {
|
||||
into->preserve = calloc(darray_size(into->map),
|
||||
sizeof(*into->preserve));
|
||||
if (!into->preserve)
|
||||
return BadAlloc;
|
||||
memcpy(into->preserve, from->preserve,
|
||||
darray_size(into->map) * sizeof(*into->preserve));
|
||||
}
|
||||
|
||||
if (from->level_names && into->num_levels > 0) {
|
||||
into->level_names = calloc(into->num_levels,
|
||||
sizeof(*into->level_names));
|
||||
if (!into->level_names)
|
||||
return BadAlloc;
|
||||
|
||||
for (i = 0; i < into->num_levels; i++)
|
||||
into->level_names[i] = strdup(from->level_names[i]);
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
static int
|
||||
InitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
|
||||
int keypadVMod)
|
||||
|
@ -1106,22 +1142,22 @@ InitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
|
|||
from = canonicalTypes;
|
||||
|
||||
if (which & XkbOneLevelMask)
|
||||
rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex],
|
||||
&darray_item(keymap->types, XkbOneLevelIndex));
|
||||
rtrn = CopyKeyType(&from[XkbOneLevelIndex],
|
||||
&darray_item(keymap->types, XkbOneLevelIndex));
|
||||
|
||||
if ((which & XkbTwoLevelMask) && rtrn == Success)
|
||||
rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex],
|
||||
&darray_item(keymap->types, XkbTwoLevelIndex));
|
||||
rtrn = CopyKeyType(&from[XkbTwoLevelIndex],
|
||||
&darray_item(keymap->types, XkbTwoLevelIndex));
|
||||
|
||||
if ((which & XkbAlphabeticMask) && rtrn == Success)
|
||||
rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
|
||||
&darray_item(keymap->types, XkbAlphabeticIndex));
|
||||
rtrn = CopyKeyType(&from[XkbAlphabeticIndex],
|
||||
&darray_item(keymap->types, XkbAlphabeticIndex));
|
||||
|
||||
if ((which & XkbKeypadMask) && rtrn == Success) {
|
||||
struct xkb_key_type *type;
|
||||
|
||||
rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex],
|
||||
&darray_item(keymap->types, XkbKeypadIndex));
|
||||
rtrn = CopyKeyType(&from[XkbKeypadIndex],
|
||||
&darray_item(keymap->types, XkbKeypadIndex));
|
||||
type = &darray_item(keymap->types, XkbKeypadIndex);
|
||||
|
||||
if (keypadVMod >= 0 && keypadVMod < XkbNumVirtualMods &&
|
||||
|
|
|
@ -1792,7 +1792,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
|
|||
darray_resize0(key->syms, sizeSyms);
|
||||
|
||||
if (haveActions) {
|
||||
outActs = XkbcResizeKeyActions(keymap, key, width * nGroups);
|
||||
outActs = ResizeKeyActions(keymap, key, width * nGroups);
|
||||
if (outActs == NULL) {
|
||||
log_wsgo(info->keymap->ctx,
|
||||
"Could not enlarge actions for %s (key %d)\n",
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#define XKBCOMP_PRIV_H
|
||||
|
||||
#include "xkbcomp.h"
|
||||
#include "alloc.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
|
|
@ -60,6 +60,21 @@ keymap_file_from_components(struct xkb_context *ctx,
|
|||
&keycodes->common, 0);
|
||||
}
|
||||
|
||||
static struct xkb_keymap *
|
||||
new_keymap(struct xkb_context *ctx)
|
||||
{
|
||||
struct xkb_keymap *keymap;
|
||||
|
||||
keymap = calloc(1, sizeof(*keymap));
|
||||
if (!keymap)
|
||||
return NULL;
|
||||
|
||||
keymap->refcnt = 1;
|
||||
keymap->ctx = xkb_context_ref(ctx);
|
||||
|
||||
return keymap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the given file and store the output in keymap.
|
||||
* @param file A list of XkbFiles, each denoting one type (e.g.
|
||||
|
@ -77,7 +92,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
|
|||
XkbFile *compat = NULL;
|
||||
XkbFile *symbols = NULL;
|
||||
|
||||
keymap = XkbcAllocKeyboard(ctx);
|
||||
keymap = new_keymap(ctx);
|
||||
if (!keymap)
|
||||
goto err;
|
||||
|
||||
|
@ -332,8 +347,38 @@ xkb_map_ref(struct xkb_keymap *keymap)
|
|||
XKB_EXPORT void
|
||||
xkb_map_unref(struct xkb_keymap *keymap)
|
||||
{
|
||||
struct xkb_key_type *type;
|
||||
struct xkb_key *key;
|
||||
|
||||
if (!keymap || --keymap->refcnt > 0)
|
||||
return;
|
||||
|
||||
XkbcFreeKeyboard(keymap);
|
||||
darray_foreach(type, keymap->types) {
|
||||
darray_free(type->map);
|
||||
free(type->preserve);
|
||||
free(type->level_names);
|
||||
}
|
||||
darray_free(keymap->types);
|
||||
|
||||
darray_foreach(key, keymap->keys) {
|
||||
free(key->sym_index);
|
||||
free(key->num_syms);
|
||||
darray_free(key->syms);
|
||||
}
|
||||
darray_free(keymap->keys);
|
||||
|
||||
darray_free(keymap->acts);
|
||||
|
||||
darray_free(keymap->sym_interpret);
|
||||
|
||||
darray_free(keymap->key_aliases);
|
||||
|
||||
free(keymap->keycodes_section_name);
|
||||
free(keymap->symbols_section_name);
|
||||
free(keymap->types_section_name);
|
||||
free(keymap->compat_section_name);
|
||||
|
||||
xkb_context_unref(keymap->ctx);
|
||||
|
||||
free(keymap);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue