summaryrefslogtreecommitdiff
path: root/symbols.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-10 11:38:04 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-11 14:35:34 -0800
commit64761ee9424f755b84ab0ce02d13eda32d215a14 (patch)
tree0d5369ba1460fb9c4be686511de659ed653362ba /symbols.c
parent9737af15196380a1687d18a17d297ee17b45a83f (diff)
Variable scope reductions
Some found by cppcheck, some found by manual code inspection Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'symbols.c')
-rw-r--r--symbols.c89
1 files changed, 39 insertions, 50 deletions
diff --git a/symbols.c b/symbols.c
index 1b59475..18e9a2b 100644
--- a/symbols.c
+++ b/symbols.c
@@ -81,7 +81,6 @@ typedef struct _KeyInfo
static void
InitKeyInfo(KeyInfo * info)
{
- int i;
static char dflt[4] = "*";
info->defs.defined = 0;
@@ -91,7 +90,7 @@ InitKeyInfo(KeyInfo * info)
info->name = KeyNameToLong(dflt);
info->groupInfo = 0;
info->typesDefined = info->symsDefined = info->actsDefined = 0;
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
info->numLevels[i] = 0;
info->types[i] = None;
@@ -114,15 +113,13 @@ InitKeyInfo(KeyInfo * info)
static void
FreeKeyInfo(KeyInfo * info)
{
- int i;
-
info->defs.defined = 0;
info->defs.fileID = 0;
info->defs.merge = MergeOverride;
info->defs.next = NULL;
info->groupInfo = 0;
info->typesDefined = info->symsDefined = info->actsDefined = 0;
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
info->numLevels[i] = 0;
info->types[i] = None;
@@ -151,13 +148,11 @@ FreeKeyInfo(KeyInfo * info)
static Bool
CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
{
- int i;
-
*new = *old;
new->defs.next = NULL;
if (clearOld)
{
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
old->numLevels[i] = 0;
old->syms[i] = NULL;
@@ -166,10 +161,9 @@ CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
}
else
{
- int width;
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
- width = new->numLevels[i];
+ int width = new->numLevels[i];
if (old->syms[i] != NULL)
{
new->syms[i] = uTypedCalloc(width, KeySym);
@@ -237,8 +231,6 @@ typedef struct _SymbolsInfo
static void
InitSymbolsInfo(SymbolsInfo * info, XkbDescPtr xkb)
{
- int i;
-
tok_ONE_LEVEL = XkbInternAtom(NULL, "ONE_LEVEL", False);
tok_TWO_LEVEL = XkbInternAtom(NULL, "TWO_LEVEL", False);
tok_KEYPAD = XkbInternAtom(NULL, "KEYPAD", False);
@@ -252,7 +244,7 @@ InitSymbolsInfo(SymbolsInfo * info, XkbDescPtr xkb)
info->nKeys = 0;
info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
info->modMap = NULL;
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
info->groupNames[i] = None;
InitKeyInfo(&info->dflt);
InitVModInfo(&info->vmods, xkb);
@@ -264,14 +256,12 @@ InitSymbolsInfo(SymbolsInfo * info, XkbDescPtr xkb)
static void
FreeSymbolsInfo(SymbolsInfo * info)
{
- int i;
-
if (info->name)
uFree(info->name);
info->name = NULL;
if (info->keys)
{
- for (i = 0; i < info->nKeys; i++)
+ for (int i = 0; i < info->nKeys; i++)
{
FreeKeyInfo(&info->keys[i]);
}
@@ -333,7 +323,6 @@ MergeKeyGroups(SymbolsInfo * info,
KeySym *resultSyms;
XkbAction *resultActs;
int resultWidth;
- int i;
Bool report, clobber;
clobber = (from->defs.merge != MergeAugment);
@@ -374,7 +363,7 @@ MergeKeyGroups(SymbolsInfo * info,
return False;
}
}
- for (i = 0; i < resultWidth; i++)
+ for (int i = 0; i < resultWidth; i++)
{
KeySym fromSym, toSym;
if (from->syms[group] && (i < from->numLevels[group]))
@@ -477,13 +466,12 @@ MergeKeyGroups(SymbolsInfo * info,
static Bool
MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
{
- int i;
unsigned collide = 0;
Bool report;
if (from->defs.merge == MergeReplace)
{
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
if (into->numLevels[i] != 0)
{
@@ -500,7 +488,7 @@ MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
report = ((warningLevel > 9) ||
((into->defs.fileID == from->defs.fileID)
&& (warningLevel > 0)));
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
if (from->numLevels[i] > 0)
{
@@ -601,17 +589,16 @@ MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
static Bool
AddKeySymbols(SymbolsInfo * info, KeyInfo * key, XkbDescPtr xkb)
{
- int i;
unsigned long real_name;
- for (i = 0; i < info->nKeys; i++)
+ for (int i = 0; i < info->nKeys; i++)
{
if (info->keys[i].name == key->name)
return MergeKeys(info, &info->keys[i], key);
}
if (FindKeyNameForAlias(xkb, key->name, &real_name))
{
- for (i = 0; i < info->nKeys; i++)
+ for (int i = 0; i < info->nKeys; i++)
{
if (info->keys[i].name == real_name)
return MergeKeys(info, &info->keys[i], key);
@@ -644,9 +631,10 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
if (new->haveSymbol && mm->haveSymbol
&& (new->u.keySym == mm->u.keySym))
{
- unsigned use, ignore;
if (mm->modifier != new->modifier)
{
+ unsigned use, ignore;
+
if (clobber)
{
use = new->modifier;
@@ -670,9 +658,10 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
if ((!new->haveSymbol) && (!mm->haveSymbol) &&
(new->u.keyName == mm->u.keyName))
{
- unsigned use, ignore;
if (mm->modifier != new->modifier)
{
+ unsigned use, ignore;
+
if (clobber)
{
use = new->modifier;
@@ -887,14 +876,13 @@ GetGroupIndex(KeyInfo * key,
if (arrayNdx == NULL)
{
- int i;
unsigned defined;
if (what == SYMBOLS)
defined = key->symsDefined;
else
defined = key->actsDefined;
- for (i = 0; i < XkbNumKbdGroups; i++)
+ for (int i = 0; i < XkbNumKbdGroups; i++)
{
if ((defined & (1 << i)) == 0)
{
@@ -933,7 +921,6 @@ AddSymbolsToKey(KeyInfo * key,
ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
{
unsigned ndx, nSyms;
- int i;
if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
return False;
@@ -966,7 +953,7 @@ AddSymbolsToKey(KeyInfo * key,
return False;
}
key->symsDefined |= (1 << ndx);
- for (i = 0; i < nSyms; i++) {
+ for (int i = 0; i < nSyms; i++) {
if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
if (warningLevel > 0)
{
@@ -976,7 +963,7 @@ AddSymbolsToKey(KeyInfo * key,
key->syms[ndx][i] = NoSymbol;
}
}
- for (i = key->numLevels[ndx] - 1;
+ for (int i = key->numLevels[ndx] - 1;
(i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
{
key->numLevels[ndx]--;
@@ -990,7 +977,6 @@ AddActionsToKey(KeyInfo * key,
const char *field,
ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
{
- int i;
unsigned ndx, nActs;
ExprDef *act;
XkbAnyAction *toAct;
@@ -1037,7 +1023,7 @@ AddActionsToKey(KeyInfo * key,
toAct = (XkbAnyAction *) key->acts[ndx];
act = value->value.child;
- for (i = 0; i < nActs; i++, toAct++)
+ for (int i = 0; i < nActs; i++, toAct++)
{
if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
{
@@ -1493,8 +1479,6 @@ HandleSymbolsBody(VarDef * def,
XkbDescPtr xkb, KeyInfo * key, SymbolsInfo * info)
{
Bool ok = True;
- ExprResult tmp, field;
- ExprDef *arrayNdx;
for (; def != NULL; def = (VarDef *) def->common.next)
{
@@ -1505,6 +1489,9 @@ HandleSymbolsBody(VarDef * def,
}
else
{
+ ExprResult tmp, field;
+ ExprDef *arrayNdx;
+
if (def->name == NULL)
{
if ((def->value == NULL)
@@ -1536,7 +1523,6 @@ SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
{
- int i;
if (warningLevel > 0)
{
WARN("For map %s an explicit group is specified\n", info->name);
@@ -1544,7 +1530,7 @@ SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
longText(key->name, XkbMessage));
ACTION("All groups except first one will be ignored\n");
}
- for (i = 1; i < XkbNumKbdGroups; i++)
+ for (int i = 1; i < XkbNumKbdGroups; i++)
{
key->numLevels[i] = 0;
if (key->syms[i] != NULL)
@@ -1603,7 +1589,6 @@ static Bool
HandleModMapDef(ModMapDef * def,
XkbDescPtr xkb, unsigned merge, SymbolsInfo * info)
{
- ExprDef *key;
ModMapEntry tmp;
ExprResult rtrn;
Bool ok;
@@ -1617,7 +1602,8 @@ HandleModMapDef(ModMapDef * def,
}
ok = True;
tmp.modifier = rtrn.uval;
- for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
+ for (ExprDef *key = def->keys; key != NULL;
+ key = (ExprDef *) key->common.next)
{
if ((key->op == ExprValue) && (key->type == TypeKeyName))
{
@@ -1706,14 +1692,14 @@ HandleSymbolsFile(XkbFile * file,
static Bool
FindKeyForSymbol(XkbDescPtr xkb, KeySym sym, unsigned int *kc_rtrn)
{
- int i, j;
+ int j;
Bool gotOne;
j = 0;
do
{
gotOne = False;
- for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
+ for (int i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
{
if (j < (int) XkbKeyNumSyms(xkb, i))
{
@@ -1742,11 +1728,9 @@ FindKeyForSymbol(XkbDescPtr xkb, KeySym sym, unsigned int *kc_rtrn)
static Bool
FindNamedType(XkbDescPtr xkb, Atom name, unsigned *type_rtrn)
{
- unsigned n;
-
if (xkb && xkb->map && xkb->map->types)
{
- for (n = 0; n < xkb->map->num_types; n++)
+ for (unsigned n = 0; n < xkb->map->num_types; n++)
{
if (xkb->map->types[n].name == (Atom) name)
{
@@ -1850,7 +1834,7 @@ FindAutomaticType(int width, KeySym * syms, Atom * typeNameRtrn,
static void
PrepareKeyDef(KeyInfo * key)
{
- int i, j, width, defined, lastGroup;
+ int i, defined, lastGroup;
Bool identical;
defined = key->symsDefined | key->actsDefined | key->typesDefined;
@@ -1870,12 +1854,14 @@ PrepareKeyDef(KeyInfo * key)
/* We can make a wrong assumption here. But leaving gaps is worse. */
for (i = lastGroup; i > 0; i--)
{
+ int width;
+
if (defined & (1 << i))
continue;
width = key->numLevels[0];
if (key->typesDefined & 1)
{
- for (j = 0; j < width; j++)
+ for (int j = 0; j < width; j++)
{
key->types[i] = key->types[0];
}
@@ -1961,7 +1947,7 @@ static Bool
CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from)
{
int i;
- unsigned okc, kc, width, tmp, nGroups;
+ unsigned kc, width, nGroups;
XkbKeyTypePtr type;
Bool haveActions, autoType, useAlias;
KeySym *outSyms;
@@ -2100,7 +2086,7 @@ CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from)
if (key->syms[i] != NULL)
{
/* fill key to "width" symbols*/
- for (tmp = 0; tmp < width; tmp++)
+ for (unsigned tmp = 0; tmp < width; tmp++)
{
if (tmp < key->numLevels[i])
outSyms[tmp] = key->syms[i][tmp];
@@ -2125,6 +2111,8 @@ CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from)
break;
case XkbKB_Overlay1:
case XkbKB_Overlay2:
+ {
+ unsigned okc;
/* find key by name! */
if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
CreateKeyNames(xkb), 0))
@@ -2140,6 +2128,7 @@ CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from)
break;
}
key->behavior.data = okc;
+ }
default:
xkb->server->behaviors[kc] = key->behavior;
xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
@@ -2213,7 +2202,6 @@ CopyModMapDef(XkbFileInfo * result, ModMapEntry * entry)
Bool
CompileSymbols(XkbFile * file, XkbFileInfo * result, unsigned merge)
{
- int i;
SymbolsInfo info;
XkbDescPtr xkb;
@@ -2227,6 +2215,7 @@ CompileSymbols(XkbFile * file, XkbFileInfo * result, unsigned merge)
return True;
if (info.errorCount == 0)
{
+ int i;
KeyInfo *key;
/* alloc memory in the xkb struct */