It's more tidy and less error prone, since we use strcasecmp == 0 a lot.
We replace strcmp == 0 by streq, strcasecmp == 0 by istreq,
uStrCasePrefix by istreq_prefix and uDupString by strdup_safe.
Signed-off-by: Ran Benita <ran234@gmail.com>
22 files changed:
char *
atom_strdup(struct atom_table *table, xkb_atom_t atom)
{
char *
atom_strdup(struct atom_table *table, xkb_atom_t atom)
{
- const char *ret = atom_text(table, atom);
- return ret ? strdup(ret) : NULL;
+ return strdup_safe(atom_text(table, atom));
entry = &_XkeyTable[idx];
if ((entry[0] == sig1) && (entry[1] == sig2) &&
entry = &_XkeyTable[idx];
if ((entry[0] == sig1) && (entry[1] == sig2) &&
- !strcmp(s, (const char *) entry + 6)) {
+ streq(s, (const char *) entry + 6)) {
val = (entry[2] << 24) | (entry[3] << 16) |
(entry[4] << 8) | entry[5];
if (!val)
val = (entry[2] << 24) | (entry[3] << 16) |
(entry[4] << 8) | entry[5];
if (!val)
- if (strcasecmp(name, "Shift") == 0)
+ if (istreq(name, "Shift"))
- if (strcasecmp(name, "Control") == 0)
+ if (istreq(name, "Control"))
- if (strcasecmp(name, "Caps Lock") == 0)
+ if (istreq(name, "Caps Lock"))
- if (strcasecmp(name, "Mod1") == 0)
+ if (istreq(name, "Mod1"))
- if (strcasecmp(name, "Mod2") == 0)
+ if (istreq(name, "Mod2"))
- if (strcasecmp(name, "Mod3") == 0)
+ if (istreq(name, "Mod3"))
- if (strcasecmp(name, "Mod4") == 0)
+ if (istreq(name, "Mod4"))
- if (strcasecmp(name, "Mod5") == 0)
+ if (istreq(name, "Mod5"))
return Mod5MapIndex;
for (i = 0; i < XkbNumVirtualMods && keymap->vmod_names[i]; i++) {
return Mod5MapIndex;
for (i = 0; i < XkbNumVirtualMods && keymap->vmod_names[i]; i++) {
- if (strcasecmp(name, keymap->vmod_names[i]) == 0)
+ if (istreq(name, keymap->vmod_names[i]))
return i + Mod5MapIndex;
}
return i + Mod5MapIndex;
}
xkb_group_index_t num_groups = xkb_map_num_groups(keymap);
xkb_group_index_t i;
xkb_group_index_t num_groups = xkb_map_num_groups(keymap);
xkb_group_index_t i;
- for (i = 0; i < num_groups; i++) {
- if (strcasecmp(keymap->group_names[i], name) == 0)
+ for (i = 0; i < num_groups; i++)
+ if (istreq(keymap->group_names[i], name))
return XKB_GROUP_INVALID;
}
return XKB_GROUP_INVALID;
}
xkb_led_index_t num_leds = xkb_map_num_leds(keymap);
xkb_led_index_t i;
xkb_led_index_t num_leds = xkb_map_num_leds(keymap);
xkb_led_index_t i;
- for (i = 0; i < num_leds; i++) {
- if (strcasecmp(keymap->indicator_names[i], name) == 0)
+ for (i = 0; i < num_leds; i++)
+ if (istreq(keymap->indicator_names[i], name))
return XKB_LED_INVALID;
}
return XKB_LED_INVALID;
}
* software without specific, written prior permission.
\*/
* software without specific, written prior permission.
\*/
-/***====================================================================***/
+#include <stdbool.h>
+#include <string.h>
/*
* We sometimes malloc strings and then expose them as const char*'s. This
/*
* We sometimes malloc strings and then expose them as const char*'s. This
*/
#define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr))
*/
#define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr))
-#define uDupString(s) ((s) ? strdup(s) : NULL)
-#define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
+static inline bool
+streq(const char *s1, const char *s2)
+{
+ return strcmp(s1, s2) == 0;
+}
+
+static inline bool
+istreq(const char *s1, const char *s2)
+{
+ return strcasecmp(s1, s2) == 0;
+}
+
+static inline bool
+istreq_prefix(const char *s1, const char *s2)
+{
+ return strncasecmp(s1, s2, strlen(s1)) == 0;
+}
+
+static inline char *
+strdup_safe(const char *s)
+{
+ return s ? strdup(s) : NULL;
+}
/* Compiler Attributes */
/* Compiler Attributes */
return false;
for (entry = tab; entry->name != NULL; entry++) {
return false;
for (entry = tab; entry->name != NULL; entry++) {
- if (strcasecmp(entry->name, string) == 0) {
+ if (istreq(entry->name, string)) {
*value_rtrn = entry->result;
return true;
}
*value_rtrn = entry->result;
return true;
}
if (value->op == ExprIdent) {
const char *valStr;
valStr = xkb_atom_text(keymap->ctx, value->value.str);
if (value->op == ExprIdent) {
const char *valStr;
valStr = xkb_atom_text(keymap->ctx, value->value.str);
- if (valStr && ((strcasecmp(valStr, "usemodmapmods") == 0) ||
- (strcasecmp(valStr, "modmapmods") == 0))) {
+ if (valStr && (istreq(valStr, "usemodmapmods") ||
+ istreq(valStr, "modmapmods"))) {
*mods_rtrn = 0;
*flags_inout |= XkbSA_UseModMapMods;
*mods_rtrn = 0;
*flags_inout |= XkbSA_UseModMapMods;
- if (strcasecmp(elem, "action") == 0)
+ if (istreq(elem, "action"))
new->action = XkbSA_NoAction;
else {
if (!stringToAction(elem, &new->action)) {
new->action = XkbSA_NoAction;
else {
if (!stringToAction(elem, &new->action)) {
if (expr->op == ExprActionDecl) {
const char *pred_txt = xkb_atom_text(info->keymap->ctx,
expr->value.action.name);
if (expr->op == ExprActionDecl) {
const char *pred_txt = xkb_atom_text(info->keymap->ctx,
expr->value.action.name);
- if (strcasecmp(pred_txt, "noneof") == 0)
+ if (istreq(pred_txt, "noneof"))
*pred_rtrn = XkbSI_NoneOf;
*pred_rtrn = XkbSI_NoneOf;
- else if (strcasecmp(pred_txt, "anyofornone") == 0)
+ else if (istreq(pred_txt, "anyofornone"))
*pred_rtrn = XkbSI_AnyOfOrNone;
*pred_rtrn = XkbSI_AnyOfOrNone;
- else if (strcasecmp(pred_txt, "anyof") == 0)
+ else if (istreq(pred_txt, "anyof"))
*pred_rtrn = XkbSI_AnyOf;
*pred_rtrn = XkbSI_AnyOf;
- else if (strcasecmp(pred_txt, "allof") == 0)
+ else if (istreq(pred_txt, "allof"))
*pred_rtrn = XkbSI_AllOf;
*pred_rtrn = XkbSI_AllOf;
- else if (strcasecmp(pred_txt, "exactly") == 0)
+ else if (istreq(pred_txt, "exactly"))
*pred_rtrn = XkbSI_Exactly;
else {
log_err(info->keymap->ctx,
*pred_rtrn = XkbSI_Exactly;
else {
log_err(info->keymap->ctx,
else if (expr->op == ExprIdent) {
const char *pred_txt = xkb_atom_text(info->keymap->ctx,
expr->value.str);
else if (expr->op == ExprIdent) {
const char *pred_txt = xkb_atom_text(info->keymap->ctx,
expr->value.str);
- if ((pred_txt) && (strcasecmp(pred_txt, "any") == 0)) {
+ if (pred_txt && istreq(pred_txt, "any")) {
*pred_rtrn = XkbSI_AnyOf;
*mods_rtrn = 0xff;
return true;
*pred_rtrn = XkbSI_AnyOf;
*mods_rtrn = 0xff;
return true;
ExprResult tmp;
struct xkb_keymap *keymap = info->keymap;
ExprResult tmp;
struct xkb_keymap *keymap = info->keymap;
- if (strcasecmp(field, "action") == 0) {
+ if (istreq(field, "action")) {
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = HandleActionDef(value, keymap, &si->interp.act.any,
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = HandleActionDef(value, keymap, &si->interp.act.any,
if (ok)
si->defined |= _SI_Action;
}
if (ok)
si->defined |= _SI_Action;
}
- else if ((strcasecmp(field, "virtualmodifier") == 0) ||
- (strcasecmp(field, "virtualmod") == 0)) {
+ else if (istreq(field, "virtualmodifier") ||
+ istreq(field, "virtualmod")) {
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ResolveVirtualModifier(value, keymap, &tmp, &info->vmods);
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ResolveVirtualModifier(value, keymap, &tmp, &info->vmods);
else
return ReportSIBadType(info, si, field, "virtual modifier");
}
else
return ReportSIBadType(info, si, field, "virtual modifier");
}
- else if (strcasecmp(field, "repeat") == 0) {
+ else if (istreq(field, "repeat")) {
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
else
return ReportSIBadType(info, si, field, "boolean");
}
else
return ReportSIBadType(info, si, field, "boolean");
}
- else if (strcasecmp(field, "locking") == 0) {
+ else if (istreq(field, "locking")) {
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
else
return ReportSIBadType(info, si, field, "boolean");
}
else
return ReportSIBadType(info, si, field, "boolean");
}
- else if ((strcasecmp(field, "usemodmap") == 0) ||
- (strcasecmp(field, "usemodmapmods") == 0)) {
+ else if (istreq(field, "usemodmap") ||
+ istreq(field, "usemodmapmods")) {
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ExprResolveEnum(keymap->ctx, value, &tmp, useModMapValues);
if (arrayNdx != NULL)
return ReportSINotArray(info, si, field);
ok = ExprResolveEnum(keymap->ctx, value, &tmp, useModMapValues);
bool ok = true;
struct xkb_keymap *keymap = info->keymap;
bool ok = true;
struct xkb_keymap *keymap = info->keymap;
- if (strcasecmp(field, "modifiers") == 0 || strcasecmp(field, "mods") == 0) {
+ if (istreq(field, "modifiers") || istreq(field, "mods")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->vmods = (rtrn.uval >> 8) & 0xff;
led->defined |= _LED_Mods;
}
led->vmods = (rtrn.uval >> 8) & 0xff;
led->defined |= _LED_Mods;
}
- else if (strcasecmp(field, "groups") == 0) {
+ else if (istreq(field, "groups")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->groups = rtrn.uval;
led->defined |= _LED_Groups;
}
led->groups = rtrn.uval;
led->defined |= _LED_Groups;
}
- else if (strcasecmp(field, "controls") == 0 ||
- strcasecmp(field, "ctrls") == 0) {
+ else if (istreq(field, "controls") || istreq(field, "ctrls")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->ctrls = rtrn.uval;
led->defined |= _LED_Ctrls;
}
led->ctrls = rtrn.uval;
led->defined |= _LED_Ctrls;
}
- else if (strcasecmp(field, "allowexplicit") == 0) {
+ else if (istreq(field, "allowexplicit")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->flags |= XkbIM_NoExplicit;
led->defined |= _LED_Explicit;
}
led->flags |= XkbIM_NoExplicit;
led->defined |= _LED_Explicit;
}
- else if (strcasecmp(field, "whichmodstate") == 0 ||
- strcasecmp(field, "whichmodifierstate") == 0) {
+ else if (istreq(field, "whichmodstate") ||
+ istreq(field, "whichmodifierstate")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->which_mods = rtrn.uval;
}
led->which_mods = rtrn.uval;
}
- else if (strcasecmp(field, "whichgroupstate") == 0) {
+ else if (istreq(field, "whichgroupstate")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->which_groups = rtrn.uval;
}
led->which_groups = rtrn.uval;
}
- else if (strcasecmp(field, "driveskbd") == 0 ||
- strcasecmp(field, "driveskeyboard") == 0 ||
- strcasecmp(field, "leddriveskbd") == 0 ||
- strcasecmp(field, "leddriveskeyboard") == 0 ||
- strcasecmp(field, "indicatordriveskbd") == 0 ||
- strcasecmp(field, "indicatordriveskeyboard") == 0) {
+ else if (istreq(field, "driveskbd") ||
+ istreq(field, "driveskeyboard") ||
+ istreq(field, "leddriveskbd") ||
+ istreq(field, "leddriveskeyboard") ||
+ istreq(field, "indicatordriveskbd") ||
+ istreq(field, "indicatordriveskeyboard")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
led->flags &= ~XkbIM_LEDDrivesKB;
led->defined |= _LED_DrivesKbd;
}
led->flags &= ~XkbIM_LEDDrivesKB;
led->defined |= _LED_DrivesKbd;
}
- else if (strcasecmp(field, "index") == 0) {
+ else if (istreq(field, "index")) {
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (arrayNdx != NULL)
return ReportIndicatorNotArray(info, led, field);
if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &ndx) == 0)
ret = 0; /* internal error, already reported */
if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &ndx) == 0)
ret = 0; /* internal error, already reported */
- else if (elem.str && (strcasecmp(elem.str, "interpret") == 0))
+ else if (elem.str && istreq(elem.str, "interpret"))
ret = SetInterpField(info, &info->dflt, field.str, ndx, stmt->value);
ret = SetInterpField(info, &info->dflt, field.str, ndx, stmt->value);
- else if (elem.str && (strcasecmp(elem.str, "indicator") == 0))
+ else if (elem.str && istreq(elem.str, "indicator"))
ret = SetIndicatorMapField(info, &info->ledDflt, field.str, ndx,
stmt->value);
else
ret = SetIndicatorMapField(info, &info->ledDflt, field.str, ndx,
stmt->value);
else
if (merge == MERGE_DEFAULT)
merge = MERGE_AUGMENT;
free(info->name);
if (merge == MERGE_DEFAULT)
merge = MERGE_AUGMENT;
free(info->name);
- info->name = uDupString(file->name);
+ info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt)
{
stmt = file->defs;
while (stmt)
{
if (led->indicator == _LED_NotBound) {
for (i = 0; i < XkbNumIndicators; i++) {
if (keymap->indicator_names[i] &&
if (led->indicator == _LED_NotBound) {
for (i = 0; i < XkbNumIndicators; i++) {
if (keymap->indicator_names[i] &&
- strcmp(keymap->indicator_names[i],
- xkb_atom_text(keymap->ctx, led->name)) == 0) {
+ streq(keymap->indicator_names[i],
+ xkb_atom_text(keymap->ctx, led->name))) {
led->indicator = i + 1;
break;
}
led->indicator = i + 1;
break;
}
- if (strcmp(keymap->indicator_names[led->indicator - 1],
- xkb_atom_text(keymap->ctx, led->name)) != 0) {
+ if (!streq(keymap->indicator_names[led->indicator - 1],
+ xkb_atom_text(keymap->ctx, led->name))) {
const char *old = keymap->indicator_names[led->indicator - 1];
log_err(info->keymap->ctx,
"Multiple names bound to indicator %d; "
const char *old = keymap->indicator_names[led->indicator - 1];
log_err(info->keymap->ctx,
"Multiple names bound to indicator %d; "
str = xkb_atom_text(ctx, field);
for (entry = priv; (entry != NULL) && (entry->name != NULL); entry++) {
str = xkb_atom_text(ctx, field);
for (entry = priv; (entry != NULL) && (entry->name != NULL); entry++) {
- if (strcasecmp(str, entry->name) == 0) {
+ if (istreq(str, entry->name)) {
val_rtrn->uval = entry->result;
return true;
}
val_rtrn->uval = entry->result;
return true;
}
str = xkb_atom_text(ctx, field);
if (str == NULL)
return false;
str = xkb_atom_text(ctx, field);
if (str == NULL)
return false;
- if (strcasecmp(str, "all") == 0)
+ if (istreq(str, "all"))
- else if (strcasecmp(str, "none") == 0)
+ else if (istreq(str, "none"))
val_rtrn->uval = 0;
else if (LookupModIndex(ctx, priv, field, type, val_rtrn))
val_rtrn->uval = (1 << val_rtrn->uval);
val_rtrn->uval = 0;
else if (LookupModIndex(ctx, priv, field, type, val_rtrn))
val_rtrn->uval = (1 << val_rtrn->uval);
ExprResult *val_rtrn)
{
int ok = 0;
ExprResult *val_rtrn)
{
int ok = 0;
- const char *bogus = NULL;
switch (expr->op) {
case ExprValue:
switch (expr->op) {
case ExprValue:
return true;
case ExprIdent:
return true;
case ExprIdent:
- bogus = xkb_atom_text(ctx, expr->value.str);
- if (bogus) {
- if ((strcasecmp(bogus, "true") == 0) ||
- (strcasecmp(bogus, "yes") == 0) ||
- (strcasecmp(bogus, "on") == 0)) {
+ ident = xkb_atom_text(ctx, expr->value.str);
+ if (ident) {
+ if (istreq(ident, "true") ||
+ istreq(ident, "yes") ||
+ istreq(ident, "on")) {
val_rtrn->uval = 1;
return true;
}
val_rtrn->uval = 1;
return true;
}
- else if ((strcasecmp(bogus, "false") == 0) ||
- (strcasecmp(bogus, "no") == 0) ||
- (strcasecmp(bogus, "off") == 0)) {
+ else if (istreq(ident, "false") ||
+ istreq(ident, "no") ||
+ istreq(ident, "off")) {
val_rtrn->uval = 0;
return true;
}
}
val_rtrn->uval = 0;
return true;
}
}
- log_err(ctx, "Identifier \"%s\" of type int is unknown\n",
+ log_err(ctx, "Identifier \"%s\" of type boolean is unknown\n",
xkb_atom_text(ctx, expr->value.str));
return false;
xkb_atom_text(ctx, expr->value.str));
return false;
KeyNamesInfo included, next_incl;
/* XXX: What's that? */
KeyNamesInfo included, next_incl;
/* XXX: What's that? */
- if (stmt->file && strcmp(stmt->file, "computed") == 0) {
+ if (stmt->file && streq(stmt->file, "computed")) {
info->keymap->flags |= AutoKeyNames;
info->explicitMin = 0;
info->explicitMax = XKB_KEYCODE_MAX;
info->keymap->flags |= AutoKeyNames;
info->explicitMin = 0;
info->explicitMax = XKB_KEYCODE_MAX;
- if (strcasecmp(field.str, "minimum") == 0)
+ if (istreq(field.str, "minimum"))
- else if (strcasecmp(field.str, "maximum") == 0)
+ else if (istreq(field.str, "maximum"))
which = MAX_KEYCODE_DEF;
else {
log_err(info->keymap->ctx,
which = MAX_KEYCODE_DEF;
else {
log_err(info->keymap->ctx,
ParseCommon *stmt;
free(info->name);
ParseCommon *stmt;
free(info->name);
- info->name = uDupString(file->name);
+ info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt)
{
stmt = file->defs;
while (stmt)
{
- if (strcasecmp(field, "modifiers") == 0) {
+ if (istreq(field, "modifiers")) {
unsigned mods, vmods;
if (arrayNdx != NULL)
log_warn(info->keymap->ctx,
unsigned mods, vmods;
if (arrayNdx != NULL)
log_warn(info->keymap->ctx,
type->defined |= _KT_Mask;
return true;
}
type->defined |= _KT_Mask;
return true;
}
- else if (strcasecmp(field, "map") == 0) {
+ else if (istreq(field, "map")) {
type->defined |= _KT_Map;
return SetMapEntry(info, type, arrayNdx, value);
}
type->defined |= _KT_Map;
return SetMapEntry(info, type, arrayNdx, value);
}
- else if (strcasecmp(field, "preserve") == 0) {
+ else if (istreq(field, "preserve")) {
type->defined |= _KT_Preserve;
return SetPreserve(info, type, arrayNdx, value);
}
type->defined |= _KT_Preserve;
return SetPreserve(info, type, arrayNdx, value);
}
- else if ((strcasecmp(field, "levelname") == 0) ||
- (strcasecmp(field, "level_name") == 0)) {
+ else if (istreq(field, "levelname") || istreq(field, "level_name")) {
type->defined |= _KT_LevelNames;
return SetLevelName(info, type, arrayNdx, value);
}
type->defined |= _KT_LevelNames;
return SetLevelName(info, type, arrayNdx, value);
}
if (!ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &arrayNdx))
return false; /* internal error, already reported */
if (!ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &arrayNdx))
return false; /* internal error, already reported */
- if (elem.str && (strcasecmp(elem.str, "type") == 0))
+ if (elem.str && istreq(elem.str, "type"))
return SetKeyTypeField(info, &info->dflt, field.str, arrayNdx,
stmt->value);
if (elem.str != NULL) {
return SetKeyTypeField(info, &info->dflt, field.str, arrayNdx,
stmt->value);
if (elem.str != NULL) {
ParseCommon *stmt;
free(info->name);
ParseCommon *stmt;
free(info->name);
- info->name = uDupString(file->name);
+ info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt)
{
stmt = file->defs;
while (stmt)
{
{
next = (XkbFile *) mapToUse->common.next;
mapToUse->common.next = NULL;
{
next = (XkbFile *) mapToUse->common.next;
mapToUse->common.next = NULL;
- if (strcmp(mapToUse->name, stmt->map) == 0 &&
+ if (streq(mapToUse->name, stmt->map) &&
mapToUse->type == file_type) {
FreeXKBFile(next);
break;
mapToUse->type == file_type) {
FreeXKBFile(next);
break;
LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
{
xkb_keysym_t sym;
LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
{
xkb_keysym_t sym;
- if ((!str) || (strcasecmp(str, "any") == 0) ||
- (strcasecmp(str, "nosymbol") == 0)) {
+ if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
*sym_rtrn = XKB_KEY_NoSymbol;
return 1;
}
*sym_rtrn = XKB_KEY_NoSymbol;
return 1;
}
- else if ((strcasecmp(str, "none") == 0) ||
- (strcasecmp(str, "voidsymbol") == 0)) {
+
+ if (istreq(str, "none") || istreq(str, "voidsymbol")) {
*sym_rtrn = XKB_KEY_VoidSymbol;
return 1;
}
*sym_rtrn = XKB_KEY_VoidSymbol;
return 1;
}
sym = xkb_keysym_from_name(str);
if (sym != XKB_KEY_NoSymbol) {
*sym_rtrn = sym;
return 1;
}
sym = xkb_keysym_from_name(str);
if (sym != XKB_KEY_NoSymbol) {
*sym_rtrn = sym;
return 1;
}
incl = first = NULL;
file = map = NULL;
tmp = str;
incl = first = NULL;
file = map = NULL;
tmp = str;
- stmt = uDupString(str);
+ stmt = strdup_safe(str);
while (tmp && *tmp)
{
if (!XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
while (tmp && *tmp)
{
if (!XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
EnsureSafeMapName(name);
file->type = type;
EnsureSafeMapName(name);
file->type = type;
- file->topName = name ? strdup(name) : NULL;
+ file->topName = strdup_safe(name);
file->name = name;
file->defs = defs;
file->id = xkb_context_take_file_id(ctx);
file->name = name;
file->defs = defs;
file->id = xkb_context_take_file_id(ctx);
extern ExprDef *
AppendKeysymList(ExprDef *list, char *sym);
extern ExprDef *
AppendKeysymList(ExprDef *list, char *sym);
LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn);
extern IncludeStmt *
LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn);
extern IncludeStmt *
tmp = strchr(str, ':');
if (tmp != NULL) {
*tmp++ = '\0';
tmp = strchr(str, ':');
if (tmp != NULL) {
*tmp++ = '\0';
- *extra_data = uDupString(tmp);
+ *extra_data = strdup(tmp);
}
else {
*extra_data = NULL;
}
else {
*extra_data = NULL;
tmp = strchr(str, '(');
if (tmp == NULL) {
tmp = strchr(str, '(');
if (tmp == NULL) {
- *file_rtrn = uDupString(str);
+ *file_rtrn = strdup(str);
*map_rtrn = NULL;
}
else if (str[0] == '(') {
*map_rtrn = NULL;
}
else if (str[0] == '(') {
- *file_rtrn = uDupString(str);
+ *file_rtrn = strdup(str);
str = tmp;
tmp = strchr(str, ')');
if ((tmp == NULL) || (tmp[1] != '\0')) {
str = tmp;
tmp = strchr(str, ')');
if ((tmp == NULL) || (tmp[1] != '\0')) {
return false;
}
*tmp++ = '\0';
return false;
}
*tmp++ = '\0';
- *map_rtrn = uDupString(str);
+ *map_rtrn = strdup(str);
}
if (*nextop_rtrn == '\0')
}
if (*nextop_rtrn == '\0')
found = false;
str = NULL;
found = false;
str = NULL;
- if (strcmp(tok, "=") == 0)
continue;
for (i = 0; i < MAX_WORDS; i++) {
continue;
for (i = 0; i < MAX_WORDS; i++) {
- if (strcmp(tok, "=") == 0) {
else
rule->flags |= RULE_FLAG_NORMAL;
else
rule->flags |= RULE_FLAG_NORMAL;
- rule->model = uDupString(names[MODEL]);
- rule->layout = uDupString(names[LAYOUT]);
- rule->variant = uDupString(names[VARIANT]);
- rule->option = uDupString(names[OPTION]);
+ rule->model = strdup_safe(names[MODEL]);
+ rule->layout = strdup_safe(names[LAYOUT]);
+ rule->variant = strdup_safe(names[VARIANT]);
+ rule->option = strdup_safe(names[OPTION]);
- rule->keycodes = uDupString(names[KEYCODES]);
- rule->symbols = uDupString(names[SYMBOLS]);
- rule->types = uDupString(names[TYPES]);
- rule->compat = uDupString(names[COMPAT]);
+ rule->keycodes = strdup_safe(names[KEYCODES]);
+ rule->symbols = strdup_safe(names[SYMBOLS]);
+ rule->types = strdup_safe(names[TYPES]);
+ rule->compat = strdup_safe(names[COMPAT]);
rule->layout_num = rule->variant_num = 0;
for (i = 0; i < nread; i++) {
rule->layout_num = rule->variant_num = 0;
for (i = 0; i < nread; i++) {
struct group *iter, *group = NULL;
darray_foreach(iter, rules->groups) {
struct group *iter, *group = NULL;
darray_foreach(iter, rules->groups) {
- if (strcmp(iter->name, group_name) == 0) {
+ if (streq(iter->name, group_name)) {
word = group->words;
for (i = 0; i < group->number; i++, word += strlen(word) + 1)
word = group->words;
for (i = 0; i < group->number; i++, word += strlen(word) + 1)
- if (strcmp(word, name) == 0)
return true;
return false;
return true;
return false;
if (mdefs->model == NULL)
return 0;
if (mdefs->model == NULL)
return 0;
- if (strcmp(rule->model, "*") == 0) {
+ if (streq(rule->model, "*")) {
pending = true;
}
else if (rule->model[0] == '$') {
if (!match_group_member(rules, rule->model, mdefs->model))
return 0;
}
pending = true;
}
else if (rule->model[0] == '$') {
if (!match_group_member(rules, rule->model, mdefs->model))
return 0;
}
- else if (strcmp(rule->model, mdefs->model) != 0) {
+ else if (!streq(rule->model, mdefs->model)) {
if (mdefs->layout[rule->layout_num] == NULL)
return 0;
if (mdefs->layout[rule->layout_num] == NULL)
return 0;
- if (strcmp(rule->layout, "*") == 0) {
+ if (streq(rule->layout, "*")) {
pending = true;
}
else if (rule->layout[0] == '$') {
pending = true;
}
else if (rule->layout[0] == '$') {
mdefs->layout[rule->layout_num]))
return 0;
}
mdefs->layout[rule->layout_num]))
return 0;
}
- else if (strcmp(rule->layout,
- mdefs->layout[rule->layout_num]) != 0) {
+ else if (!streq(rule->layout, mdefs->layout[rule->layout_num])) {
if (mdefs->variant[rule->variant_num] == NULL)
return 0;
if (mdefs->variant[rule->variant_num] == NULL)
return 0;
- if (strcmp(rule->variant, "*") == 0) {
+ if (streq(rule->variant, "*")) {
pending = true;
}
else if (rule->variant[0] == '$') {
pending = true;
}
else if (rule->variant[0] == '$') {
mdefs->variant[rule->variant_num]))
return 0;
}
mdefs->variant[rule->variant_num]))
return 0;
}
- else if (strcmp(rule->variant,
- mdefs->variant[rule->variant_num]) != 0) {
+ else if (!streq(rule->variant, mdefs->variant[rule->variant_num])) {
ExprResult tmp;
struct xkb_context *ctx = info->keymap->ctx;
ExprResult tmp;
struct xkb_context *ctx = info->keymap->ctx;
- if (strcasecmp(field, "type") == 0) {
+ if (istreq(field, "type")) {
ExprResult ndx;
if (!ExprResolveString(ctx, value, &tmp))
log_lvl(info->keymap->ctx, 1,
ExprResult ndx;
if (!ExprResolveString(ctx, value, &tmp))
log_lvl(info->keymap->ctx, 1,
keyi->typesDefined |= (1 << (ndx.uval - 1));
}
}
keyi->typesDefined |= (1 << (ndx.uval - 1));
}
}
- else if (strcasecmp(field, "symbols") == 0)
+ else if (istreq(field, "symbols"))
return AddSymbolsToKey(info, keyi, arrayNdx, value);
return AddSymbolsToKey(info, keyi, arrayNdx, value);
- else if (strcasecmp(field, "actions") == 0)
+ else if (istreq(field, "actions"))
return AddActionsToKey(info, keyi, arrayNdx, value);
return AddActionsToKey(info, keyi, arrayNdx, value);
- else if ((strcasecmp(field, "vmods") == 0) ||
- (strcasecmp(field, "virtualmods") == 0) ||
- (strcasecmp(field, "virtualmodifiers") == 0)) {
+ else if (istreq(field, "vmods") ||
+ istreq(field, "virtualmods") ||
+ istreq(field, "virtualmodifiers")) {
ok = ExprResolveVModMask(info->keymap, value, &tmp);
if (ok) {
keyi->vmodmap = (tmp.uval >> 8);
ok = ExprResolveVModMask(info->keymap, value, &tmp);
if (ok) {
keyi->vmodmap = (tmp.uval >> 8);
exprOpText(value->op), longText(keyi->name));
}
}
exprOpText(value->op), longText(keyi->name));
}
}
- else if ((strcasecmp(field, "locking") == 0) ||
- (strcasecmp(field, "lock") == 0) ||
- (strcasecmp(field, "locks") == 0)) {
+ else if (istreq(field, "locking") ||
+ istreq(field, "lock") ||
+ istreq(field, "locks")) {
ok = ExprResolveEnum(ctx, value, &tmp, lockingEntries);
if (ok)
keyi->behavior.type = tmp.uval;
keyi->defined |= _Key_Behavior;
}
ok = ExprResolveEnum(ctx, value, &tmp, lockingEntries);
if (ok)
keyi->behavior.type = tmp.uval;
keyi->defined |= _Key_Behavior;
}
- else if ((strcasecmp(field, "radiogroup") == 0) ||
- (strcasecmp(field, "permanentradiogroup") == 0) ||
- (strcasecmp(field, "allownone") == 0)) {
+ else if (istreq(field, "radiogroup") ||
+ istreq(field, "permanentradiogroup") ||
+ istreq(field, "allownone")) {
log_err(info->keymap->ctx,
"Radio groups not supported; "
"Ignoring radio group specification for key %s\n",
longText(keyi->name));
return false;
}
log_err(info->keymap->ctx,
"Radio groups not supported; "
"Ignoring radio group specification for key %s\n",
longText(keyi->name));
return false;
}
- else if (uStrCasePrefix("overlay", field) ||
- uStrCasePrefix("permanentoverlay", field)) {
+ else if (istreq_prefix("overlay", field) ||
+ istreq_prefix("permanentoverlay", field)) {
log_err(info->keymap->ctx,
"Overlays not supported; "
"Ignoring overlay specification for key %s\n",
longText(keyi->name));
}
log_err(info->keymap->ctx,
"Overlays not supported; "
"Ignoring overlay specification for key %s\n",
longText(keyi->name));
}
- else if ((strcasecmp(field, "repeating") == 0) ||
- (strcasecmp(field, "repeats") == 0) ||
- (strcasecmp(field, "repeat") == 0)) {
+ else if (istreq(field, "repeating") ||
+ istreq(field, "repeats") ||
+ istreq(field, "repeat")) {
ok = ExprResolveEnum(ctx, value, &tmp, repeatEntries);
if (!ok) {
log_err(info->keymap->ctx,
ok = ExprResolveEnum(ctx, value, &tmp, repeatEntries);
if (!ok) {
log_err(info->keymap->ctx,
keyi->repeat = tmp.uval;
keyi->defined |= _Key_Repeat;
}
keyi->repeat = tmp.uval;
keyi->defined |= _Key_Repeat;
}
- else if ((strcasecmp(field, "groupswrap") == 0) ||
- (strcasecmp(field, "wrapgroups") == 0)) {
- ok = ExprResolveBoolean(ctx, value, &tmp);
- if (!ok) {
+ else if (istreq(field, "groupswrap") ||
+ istreq(field, "wrapgroups")) {
+ if (!ExprResolveBoolean(ctx, value, &tmp)) {
log_err(info->keymap->ctx,
"Illegal groupsWrap setting for %s; "
"Non-boolean value ignored\n",
log_err(info->keymap->ctx,
"Illegal groupsWrap setting for %s; "
"Non-boolean value ignored\n",
keyi->out_of_range_group_action = XkbClampIntoRange;
keyi->defined |= _Key_GroupInfo;
}
keyi->out_of_range_group_action = XkbClampIntoRange;
keyi->defined |= _Key_GroupInfo;
}
- else if ((strcasecmp(field, "groupsclamp") == 0) ||
- (strcasecmp(field, "clampgroups") == 0)) {
- ok = ExprResolveBoolean(ctx, value, &tmp);
- if (!ok) {
+ else if (istreq(field, "groupsclamp") ||
+ istreq(field, "clampgroups")) {
+ if (!ExprResolveBoolean(ctx, value, &tmp)) {
log_err(info->keymap->ctx,
"Illegal groupsClamp setting for %s; "
"Non-boolean value ignored\n",
log_err(info->keymap->ctx,
"Illegal groupsClamp setting for %s; "
"Non-boolean value ignored\n",
keyi->out_of_range_group_action = XkbWrapIntoRange;
keyi->defined |= _Key_GroupInfo;
}
keyi->out_of_range_group_action = XkbWrapIntoRange;
keyi->defined |= _Key_GroupInfo;
}
- else if ((strcasecmp(field, "groupsredirect") == 0) ||
- (strcasecmp(field, "redirectgroups") == 0)) {
+ else if (istreq(field, "groupsredirect") ||
+ istreq(field, "redirectgroups")) {
if (!ExprResolveGroup(ctx, value, &tmp)) {
log_err(info->keymap->ctx,
"Illegal group index for redirect of key %s; "
if (!ExprResolveGroup(ctx, value, &tmp)) {
log_err(info->keymap->ctx,
"Illegal group index for redirect of key %s; "
if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field,
&arrayNdx) == 0)
return 0; /* internal error, already reported */
if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field,
&arrayNdx) == 0)
return 0; /* internal error, already reported */
- if (elem.str && (strcasecmp(elem.str, "key") == 0)) {
+ if (elem.str && istreq(elem.str, "key")) {
ret = SetSymbolsField(info, &info->dflt, field.str, arrayNdx,
stmt->value);
}
ret = SetSymbolsField(info, &info->dflt, field.str, arrayNdx,
stmt->value);
}
- else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
- (strcasecmp(field.str, "groupname") ==
- 0))) {
+ else if (!elem.str && (istreq(field.str, "name") ||
+ istreq(field.str, "groupname"))) {
ret = SetGroupName(info, arrayNdx, stmt->value);
}
ret = SetGroupName(info, arrayNdx, stmt->value);
}
- else if ((elem.str == NULL)
- && ((strcasecmp(field.str, "groupswrap") == 0) ||
- (strcasecmp(field.str, "wrapgroups") == 0))) {
+ else if (!elem.str && (istreq(field.str, "groupswrap") ||
+ istreq(field.str, "wrapgroups"))) {
log_err(info->keymap->ctx,
"Global \"groupswrap\" not supported; Ignored\n");
ret = true;
}
log_err(info->keymap->ctx,
"Global \"groupswrap\" not supported; Ignored\n");
ret = true;
}
- else if ((elem.str == NULL)
- && ((strcasecmp(field.str, "groupsclamp") == 0) ||
- (strcasecmp(field.str, "clampgroups") == 0))) {
+ else if (!elem.str && (istreq(field.str, "groupsclamp") ||
+ istreq(field.str, "clampgroups"))) {
log_err(info->keymap->ctx,
"Global \"groupsclamp\" not supported; Ignored\n");
ret = true;
}
log_err(info->keymap->ctx,
"Global \"groupsclamp\" not supported; Ignored\n");
ret = true;
}
- else if ((elem.str == NULL)
- && ((strcasecmp(field.str, "groupsredirect") == 0) ||
- (strcasecmp(field.str, "redirectgroups") == 0))) {
+ else if (!elem.str && (istreq(field.str, "groupsredirect") ||
+ istreq(field.str, "redirectgroups"))) {
log_err(info->keymap->ctx,
"Global \"groupsredirect\" not supported; Ignored\n");
ret = true;
}
log_err(info->keymap->ctx,
"Global \"groupsredirect\" not supported; Ignored\n");
ret = true;
}
- else if ((elem.str == NULL) &&
- (strcasecmp(field.str, "allownone") == 0)) {
+ else if (!elem.str && istreq(field.str, "allownone")) {
log_err(info->keymap->ctx,
"Radio groups not supported; "
"Ignoring \"allownone\" specification\n");
log_err(info->keymap->ctx,
"Radio groups not supported; "
"Ignoring \"allownone\" specification\n");
ParseCommon *stmt;
free(info->name);
ParseCommon *stmt;
free(info->name);
- info->name = uDupString(file->name);
+ info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt)
{
stmt = file->defs;
while (stmt)
{
if (keymap) {
darray_foreach(type, keymap->types) {
if (keymap) {
darray_foreach(type, keymap->types) {
- if (strcmp(type->name, name) == 0) {
+ if (streq(type->name, name)) {
*type_rtrn = n;
return true;
}
*type_rtrn = n;
return true;
}
if (!keymap->vmod_names[i])
continue;
if (!keymap->vmod_names[i])
continue;
- if (strcmp(keymap->vmod_names[i],
- xkb_atom_text(keymap->ctx, stmt->name)) != 0)
+ if (!streq(keymap->vmod_names[i],
+ xkb_atom_text(keymap->ctx, stmt->name)))
info->available |= bit;
if (!stmt->value)
info->available |= bit;
if (!stmt->value)
* The order of modifiers is the same as in the virtual_modifiers line in
* the xkb_types section.
*/
* The order of modifiers is the same as in the virtual_modifiers line in
* the xkb_types section.
*/
- for (i = 0; i < XkbNumVirtualMods; i++)
- if (keymap->vmod_names[i] &&
- strcmp(keymap->vmod_names[i], name) == 0) {
+ for (i = 0; i < XkbNumVirtualMods; i++) {
+ if (keymap->vmod_names[i] && streq(keymap->vmod_names[i], name)) {
val_rtrn->uval = i;
return true;
}
val_rtrn->uval = i;
return true;
}
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if ((info->available & bit) && keymap->vmod_names[i] &&
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if ((info->available & bit) && keymap->vmod_names[i] &&
- strcmp(keymap->vmod_names[i], name) == 0) {
+ streq(keymap->vmod_names[i], name)) {
val_rtrn->uval = i;
return true;
}
val_rtrn->uval = i;
return true;
}
expected = test_read_file("keymaps/dump.data");
assert(expected);
expected = test_read_file("keymaps/dump.data");
assert(expected);
- if (strcmp(as_string, expected) != 0) {
+ if (!streq(as_string, expected)) {
fprintf(stderr, "dumped map differs from expected!\n\n");
fprintf(stderr, "length: got %zu, expected %zu\n",
strlen(as_string), strlen(expected));
fprintf(stderr, "dumped map differs from expected!\n\n");
fprintf(stderr, "length: got %zu, expected %zu\n",
strlen(as_string), strlen(expected));
printf("%s", log_string.item);
printf("%s", log_string.item);
- assert(strcmp(log_string.item,
- "warning: first warning: 87\n"
- "error: first error: 115415\n"
- "warning: first verbose 5\n"
- "warning: second warning: 87\n"
- "debug: second debug: hello world\n"
- "info: second info\n"
- "error: second error: 115415\n") == 0);
+ assert(streq(log_string.item,
+ "warning: first warning: 87\n"
+ "error: first error: 115415\n"
+ "warning: first verbose 5\n"
+ "warning: second warning: 87\n"
+ "debug: second debug: hello world\n"
+ "info: second info\n"
+ "error: second error: 115415\n"));
xkb_context_unref(ctx);
darray_free(log_string);
xkb_context_unref(ctx);
darray_free(log_string);
-static inline bool
-streq(const char *s1, const char *s2)
-{
- if (s1 == NULL || s2 == NULL)
- return s1 == s2;
- return strcmp(s1, s2) == 0;
-}
-
static bool
test_rules(struct xkb_context *ctx, struct test_data *data)
{
static bool
test_rules(struct xkb_context *ctx, struct test_data *data)
{
assert(!test_rmlvo(ctx, "base", "pc105", "", "", ""));
assert(!test_rmlvo(ctx, "badrules", "", "us", "", ""));
assert(!test_rmlvo(ctx, "base", "pc105", "", "", ""));
assert(!test_rmlvo(ctx, "badrules", "", "us", "", ""));
- if (argc > 1 && strcmp(argv[1], "bench") == 0)
+ if (argc > 1 && streq(argv[1], "bench"))
benchmark(ctx);
xkb_context_unref(ctx);
benchmark(ctx);
xkb_context_unref(ctx);
*/
#include "xkbcommon/xkbcommon.h"
*/
#include "xkbcommon/xkbcommon.h"
const char *
test_get_path(const char *path_rel);
const char *
test_get_path(const char *path_rel);
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
-#include "xkbcommon/xkbcommon.h"
static int
test_string(const char *string, xkb_keysym_t expected)
static int
test_string(const char *string, xkb_keysym_t expected)
fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
- return strcmp(s, expected) == 0;
+ return streq(s, expected);
fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
- return strcmp(s, expected) == 0;
+ return streq(s, expected);