From 383a376372a27dbd1f905c8d08f936f13521d355 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 18 Nov 2025 21:04:16 +0000 Subject: [PATCH] Use a defined constant instead of -1 for "no Unicode mapping" Partly on the principle that magic numbers should be avoided, but mostly because I want to change it. --- bedstead.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/bedstead.c b/bedstead.c index e333594..b8a08c0 100644 --- a/bedstead.c +++ b/bedstead.c @@ -211,7 +211,7 @@ static struct weight const *weight = &weights[0]; #define UALIAS3(alias_unicode, alias_name, canonical) \ { { .alias_of = canonical }, alias_unicode, alias_name, IS_ALIAS } #define UALIAS(...) GET_MACRO(__VA_ARGS__, UALIAS3, UALIAS2)(__VA_ARGS__) -#define ALIAS(alias, canonical) UALIAS(-1, alias, canonical) +#define ALIAS(alias, canonical) UALIAS(NU, alias, canonical) static struct glyph { union { @@ -227,6 +227,7 @@ static struct glyph { int subr_idx; }; int_least32_t unicode; +#define NU (-1) char const *name; uint_least16_t flags; #define SEP 0x01 /* Separated graphics */ @@ -542,14 +543,14 @@ static struct glyph { /* Basic Latin */ ALIAS("quotesingle.curly", "quoteright"), - {"\00\00\04\12\21\12\04\00\00", -1, "zero.onum" }, - {"\00\00\04\14\04\04\16\00\00", -1, "one.onum" }, - {"\00\00\36\01\16\20\37\00\00", -1, "two.onum" }, - {"\00\00\37\01\02\06\01\21\16", -1, "three.onum" }, - {"\00\00\02\06\12\22\37\02\02", -1, "four.onum" }, - {"\00\00\37\20\36\01\01\21\16", -1, "five.onum" }, - {"\00\00\37\01\02\04\10\10\10", -1, "seven.onum" }, - {"\00\00\16\21\21\17\01\02\14", -1, "nine.onum" }, + {"\00\00\04\12\21\12\04\00\00", NU, "zero.onum" }, + {"\00\00\04\14\04\04\16\00\00", NU, "one.onum" }, + {"\00\00\36\01\16\20\37\00\00", NU, "two.onum" }, + {"\00\00\37\01\02\06\01\21\16", NU, "three.onum" }, + {"\00\00\02\06\12\22\37\02\02", NU, "four.onum" }, + {"\00\00\37\20\36\01\01\21\16", NU, "five.onum" }, + {"\00\00\37\01\02\04\10\10\10", NU, "seven.onum" }, + {"\00\00\16\21\21\17\01\02\14", NU, "nine.onum" }, ALIAS("A.c2sc", "uni1D00"), ALIAS("B.c2sc", "uni0299"), ALIAS("C.c2sc", "uni1D04"), @@ -943,7 +944,7 @@ static struct glyph { {"\37\20\36\21\21\21\36\00\00", U(0183) }, /* b with topbar */ ALIAS("uni0183.sc", "uni0182.c2sc"), {"\16\21\01\01\01\21\16\00\00", U(0186) }, /* open O */ - {"\00\00\16\21\01\21\16\00\00", -1, "uni0186.c2sc" }, + {"\00\00\16\21\01\21\16\00\00", NU, "uni0186.c2sc" }, {"\03\02\17\20\20\20\17\00\00", U(0188) }, /* Hooktop C */ UALIAS(U(0189), "Eth"), /* African D */ ALIAS("uni0189.serif", "Eth.serif"), @@ -954,18 +955,18 @@ static struct glyph { {"\16\21\01\37\21\21\16\00\00", U(018F) }, /* Schwa */ ALIAS("uni018F.c2sc", "uni0259"), {"\16\21\20\14\20\21\16\00\00", U(0190) }, /* Open E */ - {"\00\00\16\21\14\21\16\00\00", -1, "uni0190.c2sc" }, + {"\00\00\16\21\14\21\16\00\00", NU, "uni0190.c2sc" }, {"\02\04\04\16\04\04\04\04\10", 0x0192, "florin" }, {"\21\21\21\12\12\04\12\12\04", U(0194) }, /* Latin Gamma */ - {"\00\00\21\21\12\04\12\12\04", -1, "uni0194.c2sc" }, + {"\00\00\21\21\12\04\12\12\04", NU, "uni0194.c2sc" }, {"\16\04\04\04\04\04\02\00\00", U(0196) }, /* Latin Iota */ - {"\00\00\16\04\04\04\02\00\00", -1, "uni0196.c2sc" }, + {"\00\00\16\04\04\04\02\00\00", NU, "uni0196.c2sc" }, {"\16\04\04\16\04\04\16\00\00", U(0197) }, /* I with stroke */ ALIAS("uni0197.c2sc", "uni1D7B"), {"\06\10\11\12\14\12\11\00\00", U(0199) }, /* Hooktop K */ {"\30\04\16\04\12\12\21\00\00", U(019B) }, /* Barred lambda */ {"\11\11\15\13\11\11\11\10\20", U(019D) }, /* N with left hook */ - {"\00\00\11\15\13\11\11\10\20", -1, "uni019D.c2sc" }, + {"\00\00\11\15\13\11\11\10\20", NU, "uni019D.c2sc" }, {"\00\00\36\21\21\21\21\01\01", U(019E) }, /* N, right leg */ {"\14\20\36\21\21\21\36\20\20", U(01A5) }, /* Hooktop P */ {"\16\21\01\16\20\21\16\00\00", U(01A7) }, /* Tone 2 (reversed S) */ @@ -1641,7 +1642,7 @@ static struct glyph { {"\12\00\21\21\25\25\12\00\00", 0x1e85, "wdieresis", }, ALIAS("wdieresis.sc", "Wdieresis"), {"\21\21\21\25\25\25\12\00\04", U(1E88) }, /* Wdotbelow */ - {"\00\00\21\25\25\25\12\00\04", -1, "uni1E88.c2sc" }, + {"\00\00\21\25\25\25\12\00\04", NU, "uni1E88.c2sc" }, {"\00\00\21\21\25\25\12\00\04", U(1E89) }, /* wdotbelow */ ALIAS("uni1E89.sc", "uni1E88.c2sc"), {"\25\21\12\04\12\21\21\00\00", U(1E8A) }, /* Xdotaccent */ @@ -2938,7 +2939,7 @@ static struct glyph { * the old name working. The first group were added in Bedstead 002.002. */ #define COMPAT_ALIAS(alias, canonical) \ - {{.alias_of=canonical},-1,alias,IS_ALIAS|COMPAT} + {{.alias_of=canonical},NU,alias,IS_ALIAS|COMPAT} COMPAT_ALIAS("uni2126", "Omega"), COMPAT_ALIAS("uni2295", "circleplus"), #define UA(u) COMPAT_ALIAS("uni" #u, "u" #u) @@ -2978,7 +2979,7 @@ static struct glyph { * gave proper code points for separated 6-cell mosaic graphics. */ #define A(f,t) \ - { .alias_of = "u1CE" #t, -1, "u1FB" #f ".sep6", IS_ALIAS | COMPAT } + { .alias_of = "u1CE" #t, NU, "u1FB" #f ".sep6", IS_ALIAS | COMPAT } /* */ A(00,51),A(01,52),A(02,53),A(03,54),A(04,55),A(05,56),A(06,57), A(07,58),A(08,59),A(09,5A),A(0A,5B),A(0B,5C),A(0C,5D),A(0D,5E),A(0E,5F), A(0F,60),A(10,61),A(11,62),A(12,63),A(13,64), A(14,66),A(15,67), @@ -5225,7 +5226,7 @@ glyph_complement() for (i = 0; i < lenof(sorted); i++) { g = sorted[i]; if (g->unicode / nrow != unicol || - (g->unicode == -1 && row == nrow)) { + (g->unicode == NU && row == nrow)) { if (++col == ncol) { printf("grestore showpage\n"); col = -1; @@ -5241,16 +5242,16 @@ glyph_complement() col = 0; newcol = true; } - if (newcol && g->unicode != -1) { + if (newcol && g->unicode != NU) { printf("gsave %d 0 translate (%03lX) colnum grestore\n", col * 40, unicol); newcol = false; } printf("gsave %d %d translate ", (col * 40), - (int)-((g->unicode == -1 ? + (int)-((g->unicode == NU ? row++ : g->unicode % nrow) * 40)); - if (g->unicode != -1) + if (g->unicode != NU) printf("(U+%04lX)", (unsigned long)g->unicode); else printf("()"); @@ -5260,7 +5261,7 @@ glyph_complement() struct glyph const *target = g; while (target->flags & COMPAT) target = get_glyph_by_name(target->alias_of); - if (target->unicode != -1) + if (target->unicode != NU) printf("(USE U+%04lX) sash ", (unsigned long)target->unicode); else @@ -5331,7 +5332,10 @@ bdf_gen(int px_height) for (i = 0; i < lenof(glyphs); i++) { struct glyph *g = &glyphs[i]; printf("STARTCHAR %s\n", g->name); - printf("ENCODING %d\n", g->unicode); + if (g->unicode == NU) + printf("ENCODING -1\n"); + else + printf("ENCODING %lu\n", (unsigned long)g->unicode); printf("SWIDTH %d 0\n", (int)(XPIX * XSIZE)); printf("DWIDTH %d 0\n", px_width); printf("BBX %d %d 0 %d\n", px_width, px_height, -base); -- 2.30.2