summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-10 13:26:39 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-11 14:35:34 -0800
commit77b1efa1c83ad64d49d1e9c085d2a496580ce6f9 (patch)
treec121541999a472231178f6d9244266a5e953341d
parent64761ee9424f755b84ab0ce02d13eda32d215a14 (diff)
Use C99 struct initializers
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--action.c24
-rw-r--r--alias.c8
-rw-r--r--expr.c11
-rw-r--r--geometry.c29
-rw-r--r--keytypes.c48
-rw-r--r--parseutils.c280
-rw-r--r--xkbpath.c12
7 files changed, 236 insertions, 176 deletions
diff --git a/action.c b/action.c
index 7d66e54..7aae498 100644
--- a/action.c
+++ b/action.c
@@ -1494,17 +1494,21 @@ ActionsInit(void)
if (!actionsInitialized)
{
bzero((char *) &constTrue, sizeof(constTrue));
+ constTrue = (ExprDef) {
+ .common.stmtType = StmtExpr,
+ .common.next = NULL,
+ .op = ExprIdent,
+ .type = TypeBoolean,
+ .value.str = XkbInternAtom(NULL, "true", False)
+ };
bzero((char *) &constFalse, sizeof(constFalse));
- constTrue.common.stmtType = StmtExpr;
- constTrue.common.next = NULL;
- constTrue.op = ExprIdent;
- constTrue.type = TypeBoolean;
- constTrue.value.str = XkbInternAtom(NULL, "true", False);
- constFalse.common.stmtType = StmtExpr;
- constFalse.common.next = NULL;
- constFalse.op = ExprIdent;
- constFalse.type = TypeBoolean;
- constFalse.value.str = XkbInternAtom(NULL, "false", False);
+ constFalse = (ExprDef) {
+ .common.stmtType = StmtExpr,
+ .common.next = NULL,
+ .op = ExprIdent,
+ .type = TypeBoolean,
+ .value.str = XkbInternAtom(NULL, "false", False)
+ };
actionsInitialized = 1;
}
return;
diff --git a/alias.c b/alias.c
index 8532d1b..d9e2431 100644
--- a/alias.c
+++ b/alias.c
@@ -237,10 +237,10 @@ ApplyAliases(XkbDescPtr xkb, Bool toGeom, AliasInfo ** info_in)
{
if (!xkb->geom)
{
- XkbGeometrySizesRec sizes;
- bzero((char *) &sizes, sizeof(XkbGeometrySizesRec));
- sizes.which = XkbGeomKeyAliasesMask;
- sizes.num_key_aliases = nOld + nNew;
+ XkbGeometrySizesRec sizes = {
+ .which = XkbGeomKeyAliasesMask,
+ .num_key_aliases = nOld + nNew
+ };
status = XkbAllocGeometry(xkb, &sizes);
}
else
diff --git a/expr.c b/expr.c
index 2c9bb06..b3d8957 100644
--- a/expr.c
+++ b/expr.c
@@ -367,12 +367,13 @@ ExprResolveModMask(ExprDef * expr,
ExprResult * val_rtrn,
IdentLookupFunc lookup, XPointer lookupPriv)
{
- LookupPriv priv;
+ LookupPriv priv = {
+ .priv = NULL,
+ .chain = lookup,
+ .chainPriv = lookupPriv
+ };
- priv.priv = NULL;
- priv.chain = lookup;
- priv.chainPriv = lookupPriv;
- return ExprResolveMask(expr, val_rtrn, LookupModMask, (XPointer) & priv);
+ return ExprResolveMask(expr, val_rtrn, LookupModMask, (XPointer) &priv);
}
int
diff --git a/geometry.c b/geometry.c
index 46c84f0..49ed6dd 100644
--- a/geometry.c
+++ b/geometry.c
@@ -315,12 +315,14 @@ InitKeyInfo(KeyInfo * key, RowInfo * row, GeometryInfo * info)
else
{
bzero(key, sizeof(KeyInfo));
+ *key = (KeyInfo) {
+ .defs.defined = _GK_Default,
+ .defs.fileID = info->fileID,
+ .defs.merge = info->merge,
+ .defs.next = NULL,
+ .row = row
+ };
strcpy(key->name, "default");
- key->defs.defined = _GK_Default;
- key->defs.fileID = info->fileID;
- key->defs.merge = info->merge;
- key->defs.next = NULL;
- key->row = row;
}
return;
}
@@ -3660,14 +3662,15 @@ CompileGeometry(XkbFile * file, XkbFileInfo * result, unsigned merge)
if (info.errorCount == 0)
{
XkbGeometryPtr geom;
- XkbGeometrySizesRec sizes;
- bzero(&sizes, sizeof(sizes));
- sizes.which = XkbGeomAllMask;
- sizes.num_properties = info.nProps;
- sizes.num_colors = 8;
- sizes.num_shapes = info.nShapes;
- sizes.num_sections = info.nSections;
- sizes.num_doodads = info.nDoodads;
+ XkbGeometrySizesRec sizes = {
+ .which = XkbGeomAllMask,
+ .num_properties = info.nProps,
+ .num_colors = 8,
+ .num_shapes = info.nShapes,
+ .num_sections = info.nSections,
+ .num_doodads = info.nDoodads
+ };
+
if (XkbAllocGeometry(xkb, &sizes) != Success)
{
WSGO("Couldn't allocate GeometryRec\n");
diff --git a/keytypes.c b/keytypes.c
index 1c11ff8..a1db622 100644
--- a/keytypes.c
+++ b/keytypes.c
@@ -987,26 +987,24 @@ static int
HandleKeyTypeDef(KeyTypeDef * def,
XkbDescPtr xkb, unsigned merge, KeyTypesInfo * info)
{
- KeyTypeInfo type;
-
- if (def->merge != MergeDefault)
- merge = def->merge;
-
- type.defs.defined = 0;
- type.defs.fileID = info->fileID;
- type.defs.merge = merge;
- type.defs.next = NULL;
- type.dpy = info->dpy;
- type.name = def->name;
- type.mask = info->dflt.mask;
- type.vmask = info->dflt.vmask;
- type.groupInfo = info->dflt.groupInfo;
- type.numLevels = 1;
- type.nEntries = type.szEntries = 0;
- type.entries = NULL;
- type.szNames = 0;
- type.lvlNames = NULL;
- type.preserve = NULL;
+ KeyTypeInfo type = {
+ .defs.defined = 0,
+ .defs.fileID = info->fileID,
+ .defs.merge = (def->merge != MergeDefault) ? def->merge : merge,
+ .defs.next = NULL,
+ .dpy = info->dpy,
+ .name = def->name,
+ .mask = info->dflt.mask,
+ .vmask = info->dflt.vmask,
+ .groupInfo = info->dflt.groupInfo,
+ .numLevels = 1,
+ .nEntries = 0,
+ .szEntries = 0,
+ .entries = NULL,
+ .preserve = NULL,
+ .szNames = 0,
+ .lvlNames = NULL
+ };
/* Parse the actual content. */
if (!HandleKeyTypeBody(def->body, xkb, &type, info))
@@ -1132,10 +1130,12 @@ CopyDefToKeyType(XkbDescPtr xkb, XkbKeyTypePtr type, KeyTypeInfo * def)
pre = (PreserveInfo *) pre->defs.next)
{
XkbKTMapEntryPtr match;
- XkbKTMapEntryRec tmp;
- tmp.mods.real_mods = pre->indexMods;
- tmp.mods.vmods = pre->indexVMods;
- tmp.level = 0;
+ XkbKTMapEntryRec tmp = {
+ .mods.real_mods = pre->indexMods,
+ .mods.vmods = pre->indexVMods,
+ .level = 0
+ };
+
AddMapEntry(xkb, def, &tmp, False, False);
match = FindMatchingMapEntry(def, pre->indexMods, pre->indexVMods);
if (!match)
diff --git a/parseutils.c b/parseutils.c
index d779d76..dac463a 100644
--- a/parseutils.c
+++ b/parseutils.c
@@ -60,10 +60,12 @@ ExprCreate(unsigned op, unsigned type)
expr = uTypedAlloc(ExprDef);
if (expr)
{
- expr->common.stmtType = StmtExpr;
- expr->common.next = NULL;
- expr->op = op;
- expr->type = type;
+ *expr = (ExprDef) {
+ .common.stmtType = StmtExpr,
+ .common.next = NULL,
+ .op = op,
+ .type = type
+ };
}
else
{
@@ -80,11 +82,13 @@ ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
expr = uTypedAlloc(ExprDef);
if (expr)
{
- expr->common.stmtType = StmtExpr;
- expr->common.next = NULL;
- expr->op = op;
- expr->type = type;
- expr->value.child = child;
+ *expr = (ExprDef) {
+ .common.stmtType = StmtExpr,
+ .common.next = NULL,
+ .op = op,
+ .type = type,
+ .value.child = child
+ };
}
else
{
@@ -101,17 +105,19 @@ ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
expr = uTypedAlloc(ExprDef);
if (expr)
{
- expr->common.stmtType = StmtExpr;
- expr->common.next = NULL;
- expr->op = op;
+ *expr = (ExprDef) {
+ .common.stmtType = StmtExpr,
+ .common.next = NULL,
+ .op = op,
+ .type = TypeUnknown,
+ .value.binary.left = left,
+ .value.binary.right = right
+ };
+
if ((op == OpAssign) || (left->type == TypeUnknown))
expr->type = right->type;
else if ((left->type == right->type) || (right->type == TypeUnknown))
expr->type = left->type;
- else
- expr->type = TypeUnknown;
- expr->value.binary.left = left;
- expr->value.binary.right = right;
}
else
{
@@ -129,11 +135,13 @@ KeycodeCreate(char *name, ExprDef * value)
def = uTypedAlloc(KeycodeDef);
if (def)
{
- def->common.stmtType = StmtKeycodeDef;
- def->common.next = NULL;
+ *def = (KeycodeDef) {
+ .common.stmtType = StmtKeycodeDef,
+ .common.next = NULL,
+ .value = value
+ };
strncpy(def->name, name, XkbKeyNameLength);
def->name[XkbKeyNameLength] = '\0';
- def->value = value;
}
else
{
@@ -151,8 +159,10 @@ KeyAliasCreate(char *alias, char *real)
def = uTypedAlloc(KeyAliasDef);
if (def)
{
- def->common.stmtType = StmtKeyAliasDef;
- def->common.next = NULL;
+ *def = (KeyAliasDef) {
+ .common.stmtType = StmtKeyAliasDef,
+ .common.next = NULL,
+ };
strncpy(def->alias, alias, XkbKeyNameLength);
def->alias[XkbKeyNameLength] = '\0';
strncpy(def->real, real, XkbKeyNameLength);
@@ -173,10 +183,12 @@ VModCreate(Atom name, ExprDef * value)
def = uTypedAlloc(VModDef);
if (def)
{
- def->common.stmtType = StmtVModDef;
- def->common.next = NULL;
- def->name = name;
- def->value = value;
+ *def = (VModDef) {
+ .common.stmtType = StmtVModDef,
+ .common.next = NULL,
+ .name = name,
+ .value = value
+ };
}
else
{
@@ -193,10 +205,12 @@ VarCreate(ExprDef * name, ExprDef * value)
def = uTypedAlloc(VarDef);
if (def)
{
- def->common.stmtType = StmtVarDef;
- def->common.next = NULL;
- def->name = name;
- def->value = value;
+ *def = (VarDef) {
+ .common.stmtType = StmtVarDef,
+ .common.next = NULL,
+ .name = name,
+ .value = value
+ };
}
else
{
@@ -226,13 +240,15 @@ InterpCreate(const char *sym_str, ExprDef * match)
def = uTypedAlloc(InterpDef);
if (def)
{
- def->common.stmtType = StmtInterpDef;
- def->common.next = NULL;
+ *def = (InterpDef) {
+ .common.stmtType = StmtInterpDef,
+ .common.next = NULL,
+ .match = match
+ };
if (LookupKeysym(sym_str, &def->sym) == 0)
def->ignore = True;
else
def->ignore = False;
- def->match = match;
}
else
{
@@ -250,11 +266,13 @@ KeyTypeCreate(Atom name, VarDef * body)
def = uTypedAlloc(KeyTypeDef);
if (def)
{
- def->common.stmtType = StmtKeyTypeDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->name = name;
- def->body = body;
+ *def = (KeyTypeDef) {
+ .common.stmtType = StmtKeyTypeDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .name = name,
+ .body = body
+ };
}
else
{
@@ -272,12 +290,14 @@ SymbolsCreate(char *keyName, ExprDef * symbols)
def = uTypedAlloc(SymbolsDef);
if (def)
{
- def->common.stmtType = StmtSymbolsDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- bzero(def->keyName, 5);
+ *def = (SymbolsDef) {
+ .common.stmtType = StmtSymbolsDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .symbols = symbols
+ };
strncpy(def->keyName, keyName, 4);
- def->symbols = symbols;
+ def->keyName[4] = 0;
}
else
{
@@ -295,11 +315,13 @@ GroupCompatCreate(int group, ExprDef * val)
def = uTypedAlloc(GroupCompatDef);
if (def)
{
- def->common.stmtType = StmtGroupCompatDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->group = group;
- def->def = val;
+ *def = (GroupCompatDef) {
+ .common.stmtType = StmtGroupCompatDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .group = group,
+ .def = val
+ };
}
else
{
@@ -317,11 +339,13 @@ ModMapCreate(Atom modifier, ExprDef * keys)
def = uTypedAlloc(ModMapDef);
if (def)
{
- def->common.stmtType = StmtModMapDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->modifier = modifier;
- def->keys = keys;
+ *def = (ModMapDef) {
+ .common.stmtType = StmtModMapDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .modifier = modifier,
+ .keys = keys
+ };
}
else
{
@@ -339,11 +363,13 @@ IndicatorMapCreate(Atom name, VarDef * body)
def = uTypedAlloc(IndicatorMapDef);
if (def)
{
- def->common.stmtType = StmtIndicatorMapDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->name = name;
- def->body = body;
+ *def = (IndicatorMapDef) {
+ .common.stmtType = StmtIndicatorMapDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .name = name,
+ .body = body
+ };
}
else
{
@@ -361,12 +387,14 @@ IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
def = uTypedAlloc(IndicatorNameDef);
if (def)
{
- def->common.stmtType = StmtIndicatorNameDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->ndx = ndx;
- def->name = name;
- def->virtual = virtual;
+ *def = (IndicatorNameDef) {
+ .common.stmtType = StmtIndicatorNameDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .ndx = ndx,
+ .name = name,
+ .virtual = virtual
+ };
}
else
{
@@ -384,11 +412,13 @@ ActionCreate(Atom name, ExprDef * args)
act = uTypedAlloc(ExprDef);
if (act)
{
- act->common.stmtType = StmtExpr;
- act->common.next = NULL;
- act->op = ExprActionDecl;
- act->value.action.name = name;
- act->value.action.args = args;
+ *act = (ExprDef) {
+ .common.stmtType = StmtExpr,
+ .common.next = NULL,
+ .op = ExprActionDecl,
+ .value.action.name = name,
+ .value.action.args = args
+ };
return act;
}
FATAL("Couldn't allocate ActionDef in parser\n");
@@ -425,12 +455,14 @@ ShapeDeclCreate(Atom name, OutlineDef * outlines)
if (shape != NULL)
{
bzero(shape, sizeof(ShapeDef));
- shape->common.stmtType = StmtShapeDef;
- shape->common.next = NULL;
- shape->merge = MergeDefault;
- shape->name = name;
- shape->nOutlines = 0;
- shape->outlines = outlines;
+ *shape = (ShapeDef) {
+ .common.stmtType = StmtShapeDef,
+ .common.next = NULL,
+ .merge = MergeDefault,
+ .name = name,
+ .nOutlines = 0,
+ .outlines = outlines
+ };
for (OutlineDef *ol = outlines; ol != NULL;
ol = (OutlineDef *) ol->common.next)
{
@@ -450,10 +482,13 @@ OutlineCreate(Atom field, ExprDef * points)
if (outline != NULL)
{
bzero(outline, sizeof(OutlineDef));
- outline->common.stmtType = StmtOutlineDef;
- outline->common.next = NULL;
- outline->field = field;
- outline->nPoints = 0;
+ *outline = (OutlineDef) {
+ .common.stmtType = StmtOutlineDef,
+ .common.next = NULL,
+ .field = field,
+ .nPoints = 0,
+ .points = points
+ };
if (points->op == ExprCoord)
{
for (ExprDef *pt = points; pt != NULL;
@@ -462,7 +497,6 @@ OutlineCreate(Atom field, ExprDef * points)
outline->nPoints++;
}
}
- outline->points = points;
}
return outline;
}
@@ -476,8 +510,10 @@ KeyDeclCreate(char *name, ExprDef * expr)
if (key != NULL)
{
bzero(key, sizeof(KeyDef));
- key->common.stmtType = StmtKeyDef;
- key->common.next = NULL;
+ *key = (KeyDef) {
+ .common.stmtType = StmtKeyDef,
+ .common.next = NULL,
+ };
if (name)
key->name = name;
else
@@ -505,10 +541,12 @@ RowDeclCreate(KeyDef * keys)
if (row != NULL)
{
bzero(row, sizeof(RowDef));
- row->common.stmtType = StmtRowDef;
- row->common.next = NULL;
- row->nKeys = 0;
- row->keys = keys;
+ *row = (RowDef) {
+ .common.stmtType = StmtRowDef,
+ .common.next = NULL,
+ .nKeys = 0,
+ .keys = keys
+ };
for (KeyDef *key = keys; key != NULL; key = (KeyDef *) key->common.next)
{
if (key->common.stmtType == StmtKeyDef)
@@ -527,11 +565,13 @@ SectionDeclCreate(Atom name, RowDef * rows)
if (section != NULL)
{
bzero(section, sizeof(SectionDef));
- section->common.stmtType = StmtSectionDef;
- section->common.next = NULL;
- section->name = name;
- section->nRows = 0;
- section->rows = rows;
+ *section = (SectionDef) {
+ .common.stmtType = StmtSectionDef,
+ .common.next = NULL,
+ .name = name,
+ .nRows = 0,
+ .rows = rows
+ };
for (RowDef *row = rows; row != NULL; row = (RowDef *) row->common.next)
{
if (row->common.stmtType == StmtRowDef)
@@ -550,7 +590,9 @@ OverlayKeyCreate(char *under, char *over)
if (key != NULL)
{
bzero(key, sizeof(OverlayKeyDef));
- key->common.stmtType = StmtOverlayKeyDef;
+ *key = (OverlayKeyDef) {
+ .common.stmtType = StmtOverlayKeyDef
+ };
strncpy(key->over, over, XkbKeyNameLength);
strncpy(key->under, under, XkbKeyNameLength);
uFree(over);
@@ -568,9 +610,11 @@ OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
if (ol != NULL)
{
bzero(ol, sizeof(OverlayDef));
- ol->common.stmtType = StmtOverlayDef;
- ol->name = name;
- ol->keys = keys;
+ *ol = (OverlayDef) {
+ .common.stmtType = StmtOverlayDef,
+ .name = name,
+ .keys = keys
+ };
for (OverlayKeyDef *key = keys; key != NULL;
key = (OverlayKeyDef *) key->common.next)
{
@@ -589,11 +633,13 @@ DoodadCreate(unsigned type, Atom name, VarDef * body)
if (doodad != NULL)
{
bzero(doodad, sizeof(DoodadDef));
- doodad->common.stmtType = StmtDoodadDef;
- doodad->common.next = NULL;
- doodad->type = type;
- doodad->name = name;
- doodad->body = body;
+ *doodad = (DoodadDef) {
+ .common.stmtType = StmtDoodadDef,
+ .common.next = NULL,
+ .type = type,
+ .name = name,
+ .body = body
+ };
}
return doodad;
}
@@ -685,15 +731,17 @@ IncludeCreate(char *str, unsigned merge)
}
if (incl)
{
- incl->common.stmtType = StmtInclude;
- incl->common.next = NULL;
- incl->merge = merge;
- incl->stmt = NULL;
- incl->file = file;
- incl->map = map;
- incl->modifier = extra_data;
- incl->path = NULL;
- incl->next = NULL;
+ *incl = (IncludeStmt) {
+ .common.stmtType = StmtInclude,
+ .common.next = NULL,
+ .merge = merge,
+ .stmt = NULL,
+ .file = file,
+ .map = map,
+ .modifier = extra_data,
+ .path = NULL,
+ .next = NULL
+ };
}
else
{
@@ -818,13 +866,15 @@ CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
{
XkbEnsureSafeMapName(name);
bzero(file, sizeof(XkbFile));
- file->type = type;
- file->topName = uStringDup(name);
- file->name = name;
- file->defs = defs;
- file->id = fileID++;
- file->compiled = False;
- file->flags = flags;
+ *file = (XkbFile) {
+ .type = type,
+ .topName = uStringDup(name),
+ .name = name,
+ .defs = defs,
+ .id = fileID++,
+ .compiled = False,
+ .flags = flags
+ };
}
return file;
}
diff --git a/xkbpath.c b/xkbpath.c
index ee8a91e..dc9a1df 100644
--- a/xkbpath.c
+++ b/xkbpath.c
@@ -324,11 +324,13 @@ XkbAddFileToCache(char *name, unsigned type, char *path, void *data)
entry = uTypedAlloc(FileCacheEntry);
if (entry != NULL)
{
- entry->name = name;
- entry->type = type;
- entry->path = path;
- entry->data = data;
- entry->next = fileCache;
+ *entry = (FileCacheEntry) {
+ .name = name,
+ .type = type,
+ .path = path,
+ .data = data,
+ .next = fileCache
+ };
fileCache = entry;
}
return NULL;