summaryrefslogtreecommitdiff
path: root/parseutils.c
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 /parseutils.c
parent64761ee9424f755b84ab0ce02d13eda32d215a14 (diff)
Use C99 struct initializers
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'parseutils.c')
-rw-r--r--parseutils.c280
1 files changed, 165 insertions, 115 deletions
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;
}