From: Ben Harris Date: Thu, 18 Jul 2024 11:59:55 +0000 (+0100) Subject: Put bitmap data and alias target into a union X-Git-Tag: bedstead-002.007~11 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=874a12b047ea5126e9cfe1be083eb36fedf1d37f;p=bedstead.git Put bitmap data and alias target into a union A character can't both be an alias and have its own bitmap data, so we may as well overlap them. Wrapping them in a union doesn't require any changes to the syntax of the glyphs array because C allows for incomplete bracketing of initialisers. Because the union doesn't have a name, its members can be accessed as though they're members of the containing struct, which means that accesses to them don't need to change. There is a new flag to mark a glyph as an alias since "alias_of == NULL" no longer works, and a corresponding change to the ALIAS() macro. This saves about 20K of bedstead's data segment on a 64-bit system, which is kind of silly but it's satisfying nonetheless. --- diff --git a/bedstead.c b/bedstead.c index 1031a32..ebdb1b3 100644 --- a/bedstead.c +++ b/bedstead.c @@ -194,10 +194,13 @@ static void glyph_complement(void); /* U(N) sets the code point and name of a glyph not in AGLFN */ #define U(N) 0x ## N, 0x ## N >= 0x10000 ? "u" #N : "uni" #N -#define ALIAS(alias, canonical) {{},-1,alias,0,canonical} +#define ALIAS(alias, canonical) {{.alias_of=canonical},-1,alias,IS_ALIAS} static struct glyph { - char data[YSIZE]; + union { + char data[YSIZE]; + char const *alias_of; + }; int_least32_t unicode; char const *name; uint_least8_t flags; @@ -206,7 +209,7 @@ static struct glyph { #define MOS4 0x04 /* 4-cell mosaic graphics character */ #define SEP6 (SEP | MOS6) #define SEP4 (SEP | MOS4) - char const *alias_of; +#define IS_ALIAS 0x08 } glyphs[] = { /* * The first batch of glyphs comes from the code tables at the end of @@ -2859,7 +2862,7 @@ main(int argc, char **argv) printf("Flags: HW\n"); printf("LayerCount: 2\n"); dolookups(&glyphs[i]); - if (glyphs[i].alias_of != NULL) + if (glyphs[i].flags & IS_ALIAS) doalias(glyphs[i].alias_of); else if (glyphs[i].flags & MOS6) domosaic(glyphs[i].data[0], @@ -2998,7 +3001,7 @@ dopalt(struct glyph const *g) unsigned char cols = 0; int dx = 0, dh = 0; - while (g->alias_of != NULL) + while (g->flags & IS_ALIAS) g = get_glyph_by_name(g->alias_of); if (g->flags & (MOS6|MOS4)) return; /*