And merge all the similar ones into the same name.
The u* prefix is chosen over the _Xkb prefix because it has more uses
throughout the codebase. But It should now be simple to choose a nice
prefix and stay consistent.
Signed-off-by: Ran Benita <ran234@gmail.com>
[daniels: fixed for the case where we have strcasecmp]
#define False 0
#endif
-#define _XkbTypedAlloc(t) ((t *)malloc(sizeof(t)))
-#define _XkbTypedCalloc(n,t) ((t *)calloc((n),sizeof(t)))
-#define _XkbTypedRealloc(o,n,t) \
- ((o)?(t *)realloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t))
-#define _XkbClearElems(a,f,l,t) memset(&(a)[f], 0, ((l) - (f) + 1) * sizeof(t))
-
-#define _XkbDupString(s) ((s) ? strdup(s) : NULL)
-#define _XkbStrCaseCmp strcasecmp
-
/* From XKM.h */
#define XkmFileVersion 15
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "utils.h"
#include "xkballoc.h"
#include "xkbcommon/xkbcommon.h"
#include "XKBcommonint.h"
compat->num_si = 0;
prev_interpret = compat->sym_interpret;
- compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
- nSI, struct xkb_sym_interpret);
+ compat->sym_interpret = uTypedRecalloc(compat->sym_interpret,
+ compat->num_si, nSI,
+ struct xkb_sym_interpret);
if (!compat->sym_interpret) {
free(prev_interpret);
compat->size_si = compat->num_si = 0;
return BadAlloc;
}
- if (compat->num_si != 0)
- _XkbClearElems(compat->sym_interpret, compat->num_si,
- compat->size_si - 1, struct xkb_sym_interpret);
-
return Success;
}
- compat = _XkbTypedCalloc(1, struct xkb_compat_map);
+ compat = uTypedCalloc(1, struct xkb_compat_map);
if (!compat)
return BadAlloc;
if (nSI > 0) {
- compat->sym_interpret = _XkbTypedCalloc(nSI, struct xkb_sym_interpret);
+ compat->sym_interpret = uTypedCalloc(nSI, struct xkb_sym_interpret);
if (!compat->sym_interpret) {
free(compat);
return BadAlloc;
return BadMatch;
if (!xkb->names) {
- xkb->names = _XkbTypedCalloc(1, struct xkb_names);
+ xkb->names = uTypedCalloc(1, struct xkb_names);
if (!xkb->names)
return BadAlloc;
}
type = xkb->map->types;
for (i = 0; i < xkb->map->num_types; i++, type++) {
if (!type->level_names) {
- type->level_names = _XkbTypedCalloc(type->num_levels, const char *);
+ type->level_names = uTypedCalloc(type->num_levels, const char *);
if (!type->level_names)
return BadAlloc;
}
if (!xkb_keymap_keycode_range_is_legal(xkb))
return BadMatch;
- names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
+ names->keys = uTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
if (!names->keys)
return BadAlloc;
}
if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
if (!names->key_aliases)
- names->key_aliases = _XkbTypedCalloc(nTotalAliases,
+ names->key_aliases = uTypedCalloc(nTotalAliases,
struct xkb_key_alias);
else if (nTotalAliases > names->num_key_aliases) {
struct xkb_key_alias *prev_aliases = names->key_aliases;
- names->key_aliases = _XkbTypedRealloc(names->key_aliases,
- nTotalAliases,
- struct xkb_key_alias);
- if (names->key_aliases)
- _XkbClearElems(names->key_aliases, names->num_key_aliases,
- nTotalAliases - 1, struct xkb_key_alias);
- else
+ names->key_aliases = uTypedRecalloc(names->key_aliases,
+ names->num_key_aliases,
+ nTotalAliases,
+ struct xkb_key_alias);
+ if (!names->key_aliases)
free(prev_aliases);
}
return BadMatch;
if (!xkb->ctrls) {
- xkb->ctrls = _XkbTypedCalloc(1, struct xkb_controls);
+ xkb->ctrls = uTypedCalloc(1, struct xkb_controls);
if (!xkb->ctrls)
return BadAlloc;
}
if (!xkb->ctrls->per_key_repeat) {
- xkb->ctrls->per_key_repeat = _XkbTypedCalloc(xkb->max_key_code << 3,
- unsigned char);
+ xkb->ctrls->per_key_repeat = uTypedCalloc(xkb->max_key_code << 3,
+ unsigned char);
if (!xkb->ctrls->per_key_repeat)
return BadAlloc;
}
return BadMatch;
if (!xkb->indicators) {
- xkb->indicators = _XkbTypedCalloc(1, struct xkb_indicator);
+ xkb->indicators = uTypedCalloc(1, struct xkb_indicator);
if (!xkb->indicators)
return BadAlloc;
}
{
struct xkb_desc *xkb;
- xkb = _XkbTypedCalloc(1, struct xkb_desc);
+ xkb = uTypedCalloc(1, struct xkb_desc);
if (xkb) {
xkb->device_spec = XkbUseCoreKbd;
xkb->refcnt = 1;
********************************************************/
+#include "utils.h"
#include "xkballoc.h"
#include "xkbcommon/xkbcommon.h"
#include "XKBcommonint.h"
}
if (!xkb->map) {
- map = _XkbTypedCalloc(1, struct xkb_client_map);
+ map = uTypedCalloc(1, struct xkb_client_map);
if (!map)
return BadAlloc;
xkb->map = map;
if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) {
if (!map->types) {
- map->types = _XkbTypedCalloc(nTotalTypes, struct xkb_key_type);
+ map->types = uTypedCalloc(nTotalTypes, struct xkb_key_type);
if (!map->types)
return BadAlloc;
else if (map->size_types < nTotalTypes) {
struct xkb_key_type *prev_types = map->types;
- map->types = _XkbTypedRealloc(map->types, nTotalTypes,
+ map->types = uTypedRealloc(map->types, nTotalTypes,
struct xkb_key_type);
if (!map->types) {
free(prev_types);
if (!map->syms) {
map->size_syms = (nKeys * 15) / 10;
- map->syms = _XkbTypedCalloc(map->size_syms, xkb_keysym_t);
+ map->syms = uTypedCalloc(map->size_syms, xkb_keysym_t);
if (!map->syms) {
map->size_syms = 0;
return BadAlloc;
if (!map->key_sym_map) {
i = xkb->max_key_code + 1;
- map->key_sym_map = _XkbTypedCalloc(i, struct xkb_sym_map);
+ map->key_sym_map = uTypedCalloc(i, struct xkb_sym_map);
if (!map->key_sym_map)
return BadAlloc;
}
if (!map->modmap) {
i = xkb->max_key_code + 1;
- map->modmap = _XkbTypedCalloc(i, unsigned char);
+ map->modmap = uTypedCalloc(i, unsigned char);
if (!map->modmap)
return BadAlloc;
}
return BadMatch;
if (!xkb->server) {
- map = _XkbTypedCalloc(1, struct xkb_server_map);
+ map = uTypedCalloc(1, struct xkb_server_map);
if (!map)
return BadAlloc;
if (which & XkbExplicitComponentsMask) {
if (!map->explicit) {
i = xkb->max_key_code + 1;
- map->explicit = _XkbTypedCalloc(i, unsigned char);
+ map->explicit = uTypedCalloc(i, unsigned char);
if (!map->explicit)
return BadAlloc;
}
nNewActions = 1;
if (!map->acts) {
- map->acts = _XkbTypedCalloc(nNewActions + 1, union xkb_action);
+ map->acts = uTypedCalloc(nNewActions + 1, union xkb_action);
if (!map->acts)
return BadAlloc;
map->num_acts = 1;
union xkb_action *prev_acts = map->acts;
need = map->num_acts + nNewActions;
- map->acts = _XkbTypedRealloc(map->acts, need, union xkb_action);
+ map->acts = uTypedRealloc(map->acts, need, union xkb_action);
if (!map->acts) {
free(prev_acts);
map->num_acts = map->size_acts = 0;
if (!map->key_acts) {
i = xkb->max_key_code + 1;
- map->key_acts = _XkbTypedCalloc(i, unsigned short);
+ map->key_acts = uTypedCalloc(i, unsigned short);
if (!map->key_acts)
return BadAlloc;
}
if (which & XkbKeyBehaviorsMask) {
if (!map->behaviors) {
i = xkb->max_key_code + 1;
- map->behaviors = _XkbTypedCalloc(i, struct xkb_behavior);
+ map->behaviors = uTypedCalloc(i, struct xkb_behavior);
if (!map->behaviors)
return BadAlloc;
}
if (which & XkbVirtualModMapMask) {
if (!map->vmodmap) {
i = xkb->max_key_code + 1;
- map->vmodmap = _XkbTypedCalloc(i, uint32_t);
+ map->vmodmap = uTypedCalloc(i, uint32_t);
if (!map->vmodmap)
return BadAlloc;
}
*into = *from;
if (from->map && (into->map_count > 0)) {
- into->map = _XkbTypedCalloc(into->map_count, struct xkb_kt_map_entry);
+ into->map = uTypedCalloc(into->map_count, struct xkb_kt_map_entry);
if (!into->map)
return BadAlloc;
memcpy(into->map, from->map,
}
if (from->preserve && (into->map_count > 0)) {
- into->preserve = _XkbTypedCalloc(into->map_count, struct xkb_mods);
+ into->preserve = uTypedCalloc(into->map_count, struct xkb_mods);
if (!into->preserve)
return BadAlloc;
memcpy(into->preserve, from->preserve,
}
if (from->level_names && (into->num_levels > 0)) {
- into->level_names = _XkbTypedCalloc(into->num_levels, const char *);
+ into->level_names = uTypedCalloc(into->num_levels, const char *);
if (!into->level_names)
return BadAlloc;
for (i = 0; i < into->num_levels; i++)
}
xkb->map->size_syms += (needed > 32 ? needed : 32);
- newSyms = _XkbTypedCalloc(xkb->map->size_syms, xkb_keysym_t);
+ newSyms = uTypedCalloc(xkb->map->size_syms, xkb_keysym_t);
if (!newSyms)
return NULL;
}
xkb->server->size_acts = xkb->server->num_acts + needed + 8;
- newActs = _XkbTypedCalloc(xkb->server->size_acts, union xkb_action);
+ newActs = uTypedCalloc(xkb->server->size_acts, union xkb_action);
if (!newActs)
return NULL;
newActs[0].type = XkbSA_NoAction;
#include <config.h>
#endif
+#include "utils.h"
#include "xkbcommon/xkbcommon.h"
#include "XKBcommonint.h"
#include "xkballoc.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "utils.h"
#include "xkbrules.h"
#include "xkbcommon/xkbcommon.h"
#include "XKBcommonint.h"
}
if (*words == '\0')
return False;
- group->name = _XkbDupString(gname);
- group->words = _XkbDupString(words);
+ group->name = uDupString(gname);
+ group->words = uDupString(words);
for (i = 1, words = group->words; *words; words++) {
if ( *words == ' ') {
*words++ = '\0';
rule->flags|= XkbRF_Append;
else
rule->flags|= XkbRF_Normal;
- rule->model= _XkbDupString(tmp.name[MODEL]);
- rule->layout= _XkbDupString(tmp.name[LAYOUT]);
- rule->variant= _XkbDupString(tmp.name[VARIANT]);
- rule->option= _XkbDupString(tmp.name[OPTION]);
+ rule->model= uDupString(tmp.name[MODEL]);
+ rule->layout= uDupString(tmp.name[LAYOUT]);
+ rule->variant= uDupString(tmp.name[VARIANT]);
+ rule->option= uDupString(tmp.name[OPTION]);
- rule->keycodes= _XkbDupString(tmp.name[KEYCODES]);
- rule->symbols= _XkbDupString(tmp.name[SYMBOLS]);
- rule->types= _XkbDupString(tmp.name[TYPES]);
- rule->compat= _XkbDupString(tmp.name[COMPAT]);
- rule->keymap= _XkbDupString(tmp.name[KEYMAP]);
+ rule->keycodes= uDupString(tmp.name[KEYCODES]);
+ rule->symbols= uDupString(tmp.name[SYMBOLS]);
+ rule->types= uDupString(tmp.name[TYPES]);
+ rule->compat= uDupString(tmp.name[COMPAT]);
+ rule->keymap= uDupString(tmp.name[KEYMAP]);
rule->layout_num = rule->variant_num = 0;
for (i = 0; i < nread; i++) {
if ((!str1)||(!str2))
return str1;
len= strlen(str1)+strlen(str2)+1;
- str1= _XkbTypedRealloc(str1,len,char);
+ str1 = uTypedRealloc(str1, len, char);
if (str1)
strcat(str1,str2);
return str1;
{
memset(mdefs, 0, sizeof(XkbRF_MultiDefsRec));
mdefs->model = defs->model;
- mdefs->options = _XkbDupString(defs->options);
+ mdefs->options = uDupString(defs->options);
if (mdefs->options) squeeze_spaces(mdefs->options);
if (defs->layout) {
} else {
char *p;
int i;
- p = _XkbDupString(defs->layout);
+ p = uDupString(defs->layout);
if (p == NULL)
return False;
squeeze_spaces(p);
} else {
char *p;
int i;
- p = _XkbDupString(defs->variant);
+ p = uDupString(defs->variant);
if (p == NULL)
return False;
squeeze_spaces(p);
*dst= _Concat(*dst, src);
} else {
if (*dst == NULL)
- *dst= _XkbDupString(src);
+ *dst= uDupString(src);
}
}
}
if (rules->sz_rules<1) {
rules->sz_rules= 16;
rules->num_rules= 0;
- rules->rules= _XkbTypedCalloc(rules->sz_rules,XkbRF_RuleRec);
+ rules->rules= uTypedCalloc(rules->sz_rules,XkbRF_RuleRec);
}
else if (rules->num_rules>=rules->sz_rules) {
rules->sz_rules*= 2;
- rules->rules= _XkbTypedRealloc(rules->rules,rules->sz_rules,
+ rules->rules= uTypedRealloc(rules->rules,rules->sz_rules,
XkbRF_RuleRec);
}
if (!rules->rules) {
if (rules->sz_groups<1) {
rules->sz_groups= 16;
rules->num_groups= 0;
- rules->groups= _XkbTypedCalloc(rules->sz_groups,XkbRF_GroupRec);
+ rules->groups= uTypedCalloc(rules->sz_groups,XkbRF_GroupRec);
}
else if (rules->num_groups >= rules->sz_groups) {
rules->sz_groups *= 2;
- rules->groups= _XkbTypedRealloc(rules->groups,rules->sz_groups,
- XkbRF_GroupRec);
+ rules->groups= uTypedRealloc(rules->groups,rules->sz_groups,
+ XkbRF_GroupRec);
}
if (!rules->groups) {
rules->sz_groups= rules->num_groups= 0;
extern void *
recalloc(void *ptr, size_t old_size, size_t new_size);
-#define uTypedAlloc(t) ((t *)malloc((unsigned)sizeof(t)))
-#define uTypedCalloc(n,t) ((t *)calloc((unsigned)n,(unsigned)sizeof(t)))
-#define uTypedRealloc(pO,n,t) ((t *)realloc(pO,((unsigned)n)*sizeof(t)))
-#define uTypedRecalloc(pO, o, n, t) recalloc(pO, (o) * sizeof(t), (n) * sizeof(t))
+#define uTypedAlloc(t) malloc(sizeof(t))
+#define uTypedCalloc(n, t) calloc((n), sizeof(t))
+#define uTypedRealloc(pO, n, t) realloc((pO), (n) * sizeof(t))
+#define uTypedRecalloc(pO, o, n, t) recalloc((pO), (o) * sizeof(t), (n) * sizeof(t))
+
+#define uDupString(s) ((s) ? strdup(s) : NULL)
+#define uStringText(s) ((s) == NULL ? "<NullString>" : (s))
+#define uStrCaseCmp(s1, s2) strcasecmp(s1, s2)
+#define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
/***====================================================================***/
extern Bool
uSetErrorFile(char *name);
-
#define INFO uInformation
extern _X_ATTRIBUTE_PRINTF(1, 2) void
extern _X_ATTRIBUTE_PRINTF(1, 2) void
uInternalError(const char *s, ...);
-/***====================================================================***/
-
-#define uStringText(s) ((s) == NULL ? "<NullString>" : (s))
-#define uStringEqual(s1,s2) (strcmp(s1,s2) == 0)
-#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0)
-#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2))
-#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0)
-
#endif /* UTILS_H */
if (merge == MergeDefault)
merge = MergeAugment;
free(info->name);
- info->name = _XkbDupString(file->name);
+ info->name = uDupString(file->name);
stmt = file->defs;
while (stmt)
{
#include "vmod.h"
#include "indicators.h"
#include "action.h"
+#include "utils.h"
/***====================================================================***/
void *tmp;
int i;
- tmp = _XkbTypedRealloc(info->names, newMax + 1, unsigned long);
+ tmp = uTypedRealloc(info->names, newMax + 1, unsigned long);
if (!tmp) {
ERROR
("Couldn't reallocate for larger maximum keycode (%d)\n",
for (i = info->arraySize + 1; i <= newMax; i++)
info->names[i] = 0;
- tmp = _XkbTypedRealloc(info->files, newMax + 1, unsigned);
+ tmp = uTypedRealloc(info->files, newMax + 1, unsigned);
if (!tmp) {
ERROR
("Couldn't reallocate for larger maximum keycode (%d)\n",
for (i = info->arraySize + 1; i <= newMax; i++)
info->files[i] = 0;
- tmp = _XkbTypedRealloc(info->has_alt_forms, newMax + 1, unsigned char);
+ tmp = uTypedRealloc(info->has_alt_forms, newMax + 1, unsigned char);
if (!tmp) {
ERROR
("Couldn't reallocate for larger maximum keycode (%d)\n",
ParseCommon *stmt;
free(info->name);
- info->name = _XkbDupString(file->name);
+ info->name = uDupString(file->name);
stmt = file->defs;
while (stmt)
{
ParseCommon *stmt;
free(info->name);
- info->name = _XkbDupString(file->name);
+ info->name = uDupString(file->name);
stmt = file->defs;
while (stmt)
{
incl = first = NULL;
file = map = NULL;
tmp = str;
- stmt = _XkbDupString(str);
+ stmt = uDupString(str);
while ((tmp) && (*tmp))
{
if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
XkbcEnsureSafeMapName(name);
memset(file, 0, sizeof(XkbFile));
file->type = type;
- file->topName = _XkbDupString(name);
+ file->topName = uDupString(name);
file->name = name;
file->defs = defs;
file->id = fileID++;
ParseCommon *stmt;
free(info->name);
- info->name = _XkbDupString(file->name);
+ info->name = uDupString(file->name);
stmt = file->defs;
while (stmt)
{
return NULL;
}
- if (!(loaded = _XkbTypedCalloc(1, XkbRF_RulesRec))) {
+ if (!(loaded = uTypedCalloc(1, XkbRF_RulesRec))) {
ERROR("failed to allocate XKB rules\n");
goto unwind_file;
}
goto unwind_file;
}
- if (!(names = _XkbTypedCalloc(1, struct xkb_component_names))) {
+ if (!(names = uTypedCalloc(1, struct xkb_component_names))) {
ERROR("failed to allocate XKB components\n");
goto unwind_file;
}
if (tmp != NULL)
{
*tmp++ = '\0';
- *extra_data = _XkbDupString(tmp);
+ *extra_data = uDupString(tmp);
}
else
{
tmp = strchr(str, '(');
if (tmp == NULL)
{
- *file_rtrn = _XkbDupString(str);
+ *file_rtrn = uDupString(str);
*map_rtrn = NULL;
}
else if (str[0] == '(')
else
{
*tmp++ = '\0';
- *file_rtrn = _XkbDupString(str);
+ *file_rtrn = uDupString(str);
str = tmp;
tmp = strchr(str, ')');
if ((tmp == NULL) || (tmp[1] != '\0'))
return False;
}
*tmp++ = '\0';
- *map_rtrn = _XkbDupString(str);
+ *map_rtrn = uDupString(str);
}
}
if (*nextop_rtrn == '\0')