summaryrefslogtreecommitdiff
path: root/misc.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 /misc.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 'misc.c')
-rw-r--r--misc.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/misc.c b/misc.c
index 498ec71..f2e87c7 100644
--- a/misc.c
+++ b/misc.c
@@ -53,7 +53,6 @@ ProcessIncludeFile(IncludeStmt * stmt,
unsigned file_type,
XkbFile ** file_rtrn, unsigned *merge_rtrn)
{
- FILE *file;
XkbFile *rtrn, *mapToUse;
char oldFile[1024] = {0};
int oldLine = lineNum;
@@ -63,7 +62,7 @@ ProcessIncludeFile(IncludeStmt * stmt,
{
/* file not in cache, open it, parse it and store it in cache for next
time. */
- file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
+ FILE *file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
if (file == NULL)
{
ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
@@ -400,30 +399,29 @@ static KeyNameDesc dfltKeys[] = {
Status
ComputeKbdDefaults(XkbDescPtr xkb)
{
- Status rtrn;
- int i, tmp, nUnknown;
- KeyNameDesc *name;
- KeySym *syms;
- char tmpname[XkbKeyNameLength + 1];
+ int nUnknown;
if ((xkb->names == NULL) || (xkb->names->keys == NULL))
{
+ Status rtrn;
if ((rtrn = XkbAllocNames(xkb, XkbKeyNamesMask, 0, 0)) != Success)
return rtrn;
}
- for (name = dfltKeys; (name->name[0] != '\0'); name++)
+ for (KeyNameDesc *name = dfltKeys; (name->name[0] != '\0'); name++)
{
name->used = False;
}
nUnknown = 0;
- for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
+ for (int i = xkb->min_key_code; i <= xkb->max_key_code; i++)
{
- tmp = XkbKeyNumSyms(xkb, i);
+ int tmp = XkbKeyNumSyms(xkb, i);
if ((xkb->names->keys[i].name[0] == '\0') && (tmp > 0))
{
+ KeySym *syms;
+
tmp = XkbKeyGroupsWidth(xkb, i);
syms = XkbKeySymsPtr(xkb, i);
- for (name = dfltKeys; (name->name[0] != '\0'); name++)
+ for (KeyNameDesc *name = dfltKeys; (name->name[0] != '\0'); name++)
{
Bool match = True;
if (((name->level1 != syms[0])
@@ -444,6 +442,8 @@ ComputeKbdDefaults(XkbDescPtr xkb)
}
else
{
+ char tmpname[XkbKeyNameLength + 1];
+
if (warningLevel > 2)
{
WARN
@@ -464,6 +464,8 @@ ComputeKbdDefaults(XkbDescPtr xkb)
{
if (warningLevel > 2)
{
+ char tmpname[XkbKeyNameLength + 1];
+
WARN("Key %d does not match any defaults\n", i);
ACTION("Using name <U%03d>\n", nUnknown);
snprintf(tmpname, sizeof(tmpname), "U%03d", nUnknown++);
@@ -494,8 +496,6 @@ FindNamedKey(XkbDescPtr xkb,
unsigned int *kc_rtrn,
Bool use_aliases, Bool create, int start_from)
{
- unsigned n;
-
if (start_from < xkb->min_key_code)
{
start_from = xkb->min_key_code;
@@ -508,7 +508,7 @@ FindNamedKey(XkbDescPtr xkb,
*kc_rtrn = 0; /* some callers rely on this */
if (xkb && xkb->names && xkb->names->keys)
{
- for (n = start_from; n <= xkb->max_key_code; n++)
+ for (unsigned n = start_from; n <= xkb->max_key_code; n++)
{
unsigned long tmp;
tmp = KeyNameToLong(xkb->names->keys[n].name);
@@ -546,7 +546,7 @@ FindNamedKey(XkbDescPtr xkb,
}
}
/* Find first unused keycode and store our key here */
- for (n = xkb->min_key_code; n <= xkb->max_key_code; n++)
+ for (unsigned n = xkb->min_key_code; n <= xkb->max_key_code; n++)
{
if (xkb->names->keys[n].name[0] == '\0')
{
@@ -565,7 +565,6 @@ Bool
FindKeyNameForAlias(XkbDescPtr xkb, unsigned long lname,
unsigned long *real_name)
{
- int i;
char name[XkbKeyNameLength + 1];
if (xkb && xkb->geom && xkb->geom->key_aliases)
@@ -574,7 +573,7 @@ FindKeyNameForAlias(XkbDescPtr xkb, unsigned long lname,
a = xkb->geom->key_aliases;
LongToKeyName(lname, name);
name[XkbKeyNameLength] = '\0';
- for (i = 0; i < xkb->geom->num_key_aliases; i++, a++)
+ for (int i = 0; i < xkb->geom->num_key_aliases; i++, a++)
{
if (strncmp(name, a->alias, XkbKeyNameLength) == 0)
{
@@ -589,7 +588,7 @@ FindKeyNameForAlias(XkbDescPtr xkb, unsigned long lname,
a = xkb->names->key_aliases;
LongToKeyName(lname, name);
name[XkbKeyNameLength] = '\0';
- for (i = 0; i < xkb->names->num_key_aliases; i++, a++)
+ for (int i = 0; i < xkb->names->num_key_aliases; i++, a++)
{
if (strncmp(name, a->alias, XkbKeyNameLength) == 0)
{