From cc8b06826b74feb31f02d6862d875255d3ba605c Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 16 Jul 2012 17:53:46 +0300 Subject: [PATCH] Move alias.c functions into keycodes.c They are only used in this file. Signed-off-by: Ran Benita --- Makefile.am | 2 - src/xkbcomp/alias.c | 220 ------------------------------------------------- src/xkbcomp/alias.h | 51 ------------ src/xkbcomp/keycodes.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 214 insertions(+), 274 deletions(-) delete mode 100644 src/xkbcomp/alias.c delete mode 100644 src/xkbcomp/alias.h diff --git a/Makefile.am b/Makefile.am index 9b43aab..db17832 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,8 +42,6 @@ libxkbcommon_la_LDFLAGS = -no-undefined libxkbcommon_la_SOURCES = \ src/xkbcomp/action.c \ src/xkbcomp/action.h \ - src/xkbcomp/alias.c \ - src/xkbcomp/alias.h \ src/xkbcomp/compat.c \ src/xkbcomp/expr.c \ src/xkbcomp/expr.h \ diff --git a/src/xkbcomp/alias.c b/src/xkbcomp/alias.c deleted file mode 100644 index 6d57511..0000000 --- a/src/xkbcomp/alias.c +++ /dev/null @@ -1,220 +0,0 @@ -/************************************************************ - * Copyright (c) 1995 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 "alias.h" -#include "keycodes.h" - -static void -HandleCollision(AliasInfo * old, AliasInfo * new) -{ - if (strncmp(new->real, old->real, XkbKeyNameLength) == 0) { - if (((new->def.file_id == old->def.file_id) && (warningLevel > 0)) || - (warningLevel > 9)) { - WARN("Alias of %s for %s declared more than once\n", - XkbcKeyNameText(new->alias), XkbcKeyNameText(new->real)); - ACTION("First definition ignored\n"); - } - } - else { - char *use, *ignore; - if (new->def.merge == MERGE_AUGMENT) { - use = old->real; - ignore = new->real; - } - else { - use = new->real; - ignore = old->real; - } - if (((old->def.file_id == new->def.file_id) && (warningLevel > 0)) || - (warningLevel > 9)) { - WARN("Multiple definitions for alias %s\n", - XkbcKeyNameText(old->alias)); - ACTION("Using %s, ignoring %s\n", - XkbcKeyNameText(use), XkbcKeyNameText(ignore)); - } - if (use != old->real) - memcpy(old->real, use, XkbKeyNameLength); - } - old->def.file_id = new->def.file_id; - old->def.merge = new->def.merge; -} - -static void -InitAliasInfo(AliasInfo * info, - enum merge_mode merge, unsigned file_id, char *alias, - char *real) -{ - memset(info, 0, sizeof(AliasInfo)); - info->def.merge = merge; - info->def.file_id = file_id; - strncpy(info->alias, alias, XkbKeyNameLength); - strncpy(info->real, real, XkbKeyNameLength); -} - -int -HandleAliasDef(KeyAliasDef * def, - enum merge_mode merge, unsigned file_id, AliasInfo ** info_in) -{ - AliasInfo *info; - - for (info = *info_in; info != NULL; info = - (AliasInfo *) info->def.next) { - if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0) { - AliasInfo new; - InitAliasInfo(&new, merge, file_id, def->alias, def->real); - HandleCollision(info, &new); - return true; - } - } - info = uTypedCalloc(1, AliasInfo); - if (info == NULL) { - WSGO("Allocation failure in HandleAliasDef\n"); - return false; - } - info->def.file_id = file_id; - info->def.merge = merge; - info->def.next = (CommonInfo *) *info_in; - memcpy(info->alias, def->alias, XkbKeyNameLength); - memcpy(info->real, def->real, XkbKeyNameLength); - *info_in = AddCommonInfo(&(*info_in)->def, &info->def); - return true; -} - -void -ClearAliases(AliasInfo ** info_in) -{ - if ((info_in) && (*info_in)) - ClearCommonInfo(&(*info_in)->def); -} - -bool -MergeAliases(AliasInfo ** into, AliasInfo ** merge, - enum merge_mode how_merge) -{ - AliasInfo *tmp; - KeyAliasDef def; - - if ((*merge) == NULL) - return true; - if ((*into) == NULL) { - *into = *merge; - *merge = NULL; - return true; - } - memset(&def, 0, sizeof(KeyAliasDef)); - for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next) { - if (how_merge == MERGE_DEFAULT) - def.merge = tmp->def.merge; - else - def.merge = how_merge; - memcpy(def.alias, tmp->alias, XkbKeyNameLength); - memcpy(def.real, tmp->real, XkbKeyNameLength); - if (!HandleAliasDef(&def, def.merge, tmp->def.file_id, into)) - return false; - } - return true; -} - -int -ApplyAliases(struct xkb_keymap *keymap, AliasInfo ** info_in) -{ - int i; - struct xkb_key *key; - struct xkb_key_alias *old, *a; - AliasInfo *info; - int nNew, nOld; - - nOld = darray_size(keymap->key_aliases); - old = &darray_item(keymap->key_aliases, 0); - - for (nNew = 0, info = *info_in; info; - info = (AliasInfo *)info->def.next) { - unsigned long lname; - - lname = KeyNameToLong(info->real); - key = FindNamedKey(keymap, lname, false, CreateKeyNames(keymap), 0); - if (!key) { - if (warningLevel > 4) { - WARN("Attempt to alias %s to non-existent key %s\n", - XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real)); - ACTION("Ignored\n"); - } - info->alias[0] = '\0'; - continue; - } - - lname = KeyNameToLong(info->alias); - key = FindNamedKey(keymap, lname, false, false, 0); - if (key) { - if (warningLevel > 4) { - WARN("Attempt to create alias with the name of a real key\n"); - ACTION("Alias \"%s = %s\" ignored\n", - XkbcKeyNameText(info->alias), - XkbcKeyNameText(info->real)); - } - info->alias[0] = '\0'; - continue; - } - - nNew++; - - if (!old) - continue; - - for (i = 0, a = old; i < nOld; i++, a++) { - AliasInfo old_info; - - if (strncmp(a->alias, info->alias, XkbKeyNameLength) != 0) - continue; - - InitAliasInfo(&old_info, MERGE_AUGMENT, 0, a->alias, a->real); - HandleCollision(&old_info, info); - memcpy(old_info.real, a->real, XkbKeyNameLength); - info->alias[0] = '\0'; - nNew--; - break; - } - } - - if (nNew == 0) - goto out; - - darray_resize0(keymap->key_aliases, nOld + nNew); - - a = &darray_item(keymap->key_aliases, nOld); - for (info = *info_in; info; info = (AliasInfo *)info->def.next) { - if (info->alias[0] != '\0') { - strncpy(a->alias, info->alias, XkbKeyNameLength); - strncpy(a->real, info->real, XkbKeyNameLength); - a++; - } - } - -out: - ClearCommonInfo(&(*info_in)->def); - *info_in = NULL; - return true; -} diff --git a/src/xkbcomp/alias.h b/src/xkbcomp/alias.h deleted file mode 100644 index bd59847..0000000 --- a/src/xkbcomp/alias.h +++ /dev/null @@ -1,51 +0,0 @@ -/************************************************************ - * Copyright (c) 1995 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. - * - ********************************************************/ - -#ifndef ALIAS_H -#define ALIAS_H 1 - -#include "xkbcomp-priv.h" - -typedef struct _AliasInfo { - CommonInfo def; - char alias[XkbKeyNameLength + 1]; - char real[XkbKeyNameLength + 1]; -} AliasInfo; - -extern int -HandleAliasDef(KeyAliasDef *def, enum merge_mode merge, unsigned file_id, - AliasInfo **info); - -extern void -ClearAliases(AliasInfo **info); - -extern bool -MergeAliases(AliasInfo **into, AliasInfo **merge, enum merge_mode how_merge); - -extern int -ApplyAliases(struct xkb_keymap *keymap, AliasInfo **info); - -#endif /* ALIAS_H */ diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index e77e047..f06856a 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -27,7 +27,6 @@ #include "keycodes.h" #include "expr.h" #include "parseutils.h" -#include "alias.h" const char * longText(unsigned long val) @@ -51,6 +50,12 @@ LongToKeyName(unsigned long val, char *name) /***====================================================================***/ +typedef struct _AliasInfo { + CommonInfo def; + char alias[XkbKeyNameLength + 1]; + char real[XkbKeyNameLength + 1]; +} AliasInfo; + typedef struct _IndicatorNameInfo { CommonInfo defs; int ndx; @@ -89,6 +94,17 @@ ResizeKeyNameArrays(KeyNamesInfo *info, int newMax) } static void +InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id, + char *alias, char *real) +{ + memset(info, 0, sizeof(*info)); + info->def.merge = merge; + info->def.file_id = file_id; + strncpy(info->alias, alias, XkbKeyNameLength); + strncpy(info->real, real, XkbKeyNameLength); +} + +static void InitIndicatorNameInfo(IndicatorNameInfo * ii, KeyNamesInfo * info) { ii->defs.defined = 0; @@ -251,6 +267,13 @@ AddIndicatorName(KeyNamesInfo *info, struct xkb_keymap *keymap, } static void +ClearAliases(AliasInfo **info_in) +{ + if (info_in && *info_in) + ClearCommonInfo(&(*info_in)->def); +} + +static void ClearKeyNamesInfo(KeyNamesInfo * info) { free(info->name); @@ -369,6 +392,44 @@ AddKeyName(KeyNamesInfo * info, /***====================================================================***/ +static int +HandleAliasDef(KeyAliasDef *def, enum merge_mode merge, unsigned file_id, + AliasInfo **info_in); + +static bool +MergeAliases(AliasInfo **into, AliasInfo **merge, + enum merge_mode how_merge) +{ + AliasInfo *tmp; + KeyAliasDef def; + + if (*merge == NULL) + return true; + + if (*into == NULL) { + *into = *merge; + *merge = NULL; + return true; + } + + memset(&def, 0, sizeof(def)); + + for (tmp = *merge; tmp; tmp = (AliasInfo *) tmp->def.next) { + if (how_merge == MERGE_DEFAULT) + def.merge = tmp->def.merge; + else + def.merge = how_merge; + + memcpy(def.alias, tmp->alias, XkbKeyNameLength); + memcpy(def.real, tmp->real, XkbKeyNameLength); + + if (!HandleAliasDef(&def, def.merge, tmp->def.file_id, into)) + return false; + } + + return true; +} + static void MergeIncludedKeycodes(KeyNamesInfo *into, struct xkb_keymap *keymap, KeyNamesInfo *from, enum merge_mode merge) @@ -525,6 +586,76 @@ HandleKeycodeDef(KeycodeDef *stmt, enum merge_mode merge, KeyNamesInfo *info) true); } +static void +HandleAliasCollision(AliasInfo *old, AliasInfo *new) +{ + if (strncmp(new->real, old->real, XkbKeyNameLength) == 0) { + if ((new->def.file_id == old->def.file_id && warningLevel > 0) || + warningLevel > 9) { + WARN("Alias of %s for %s declared more than once\n", + XkbcKeyNameText(new->alias), XkbcKeyNameText(new->real)); + ACTION("First definition ignored\n"); + } + } + else { + char *use, *ignore; + + if (new->def.merge == MERGE_AUGMENT) { + use = old->real; + ignore = new->real; + } + else { + use = new->real; + ignore = old->real; + } + + if ((old->def.file_id == new->def.file_id && warningLevel > 0) || + warningLevel > 9) { + WARN("Multiple definitions for alias %s\n", + XkbcKeyNameText(old->alias)); + ACTION("Using %s, ignoring %s\n", + XkbcKeyNameText(use), XkbcKeyNameText(ignore)); + } + + if (use != old->real) + memcpy(old->real, use, XkbKeyNameLength); + } + + old->def.file_id = new->def.file_id; + old->def.merge = new->def.merge; +} + +static int +HandleAliasDef(KeyAliasDef *def, enum merge_mode merge, unsigned file_id, + AliasInfo **info_in) +{ + AliasInfo *info; + + for (info = *info_in; info; info = (AliasInfo *) info->def.next) { + if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0) { + AliasInfo new; + InitAliasInfo(&new, merge, file_id, def->alias, def->real); + HandleAliasCollision(info, &new); + return true; + } + } + + info = calloc(1, sizeof(*info)); + if (!info) { + WSGO("Allocation failure in HandleAliasDef\n"); + return false; + } + + info->def.file_id = file_id; + info->def.merge = merge; + info->def.next = (CommonInfo *) *info_in; + memcpy(info->alias, def->alias, XkbKeyNameLength); + memcpy(info->real, def->real, XkbKeyNameLength); + *info_in = AddCommonInfo(&(*info_in)->def, &info->def); + + return true; +} + #define MIN_KEYCODE_DEF 0 #define MAX_KEYCODE_DEF 1 @@ -718,6 +849,88 @@ HandleKeycodesFile(XkbFile *file, struct xkb_keymap *keymap, } } +static int +ApplyAliases(struct xkb_keymap *keymap, AliasInfo **info_in) +{ + int i; + struct xkb_key *key; + struct xkb_key_alias *old, *a; + AliasInfo *info; + int nNew, nOld; + + nOld = darray_size(keymap->key_aliases); + old = &darray_item(keymap->key_aliases, 0); + + for (nNew = 0, info = *info_in; info; + info = (AliasInfo *) info->def.next) { + unsigned long lname; + + lname = KeyNameToLong(info->real); + key = FindNamedKey(keymap, lname, false, CreateKeyNames(keymap), 0); + if (!key) { + if (warningLevel > 4) { + WARN("Attempt to alias %s to non-existent key %s\n", + XkbcKeyNameText(info->alias), + XkbcKeyNameText(info->real)); + ACTION("Ignored\n"); + } + info->alias[0] = '\0'; + continue; + } + + lname = KeyNameToLong(info->alias); + key = FindNamedKey(keymap, lname, false, false, 0); + if (key) { + if (warningLevel > 4) { + WARN("Attempt to create alias with the name of a real key\n"); + ACTION("Alias \"%s = %s\" ignored\n", + XkbcKeyNameText(info->alias), + XkbcKeyNameText(info->real)); + } + info->alias[0] = '\0'; + continue; + } + + nNew++; + + if (!old) + continue; + + for (i = 0, a = old; i < nOld; i++, a++) { + AliasInfo old_info; + + if (strncmp(a->alias, info->alias, XkbKeyNameLength) != 0) + continue; + + InitAliasInfo(&old_info, MERGE_AUGMENT, 0, a->alias, a->real); + HandleAliasCollision(&old_info, info); + memcpy(old_info.real, a->real, XkbKeyNameLength); + info->alias[0] = '\0'; + nNew--; + break; + } + } + + if (nNew == 0) + goto out; + + darray_resize0(keymap->key_aliases, nOld + nNew); + + a = &darray_item(keymap->key_aliases, nOld); + for (info = *info_in; info; info = (AliasInfo *)info->def.next) { + if (info->alias[0] != '\0') { + strncpy(a->alias, info->alias, XkbKeyNameLength); + strncpy(a->real, info->real, XkbKeyNameLength); + a++; + } + } + +out: + ClearCommonInfo(&(*info_in)->def); + *info_in = NULL; + return true; +} + /** * Compile the xkb_keycodes section, parse it's output, return the results. * -- 2.7.4