chiark / gitweb /
Better UALIAS() macro
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 8 Sep 2025 20:49:47 +0000 (21:49 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Mon, 8 Sep 2025 20:49:47 +0000 (21:49 +0100)
Now you _can_ pass an instance of U() as the first two arguments.

bedstead.c

index 4621f4932389a78a862b942dbd999ace385517cb..b7628222c6e4c4581930978a1918fcb4446733a1 100644 (file)
@@ -197,10 +197,20 @@ static struct weight {
 
 static struct weight const *weight = &weights[0];
 
+/*
+ * Slightly evil macro for overloading based on argument count.
+ * See https://jadlevesque.github.io/PPMP-Iceberg/explanations#overloading-macros-based-on-argument-count
+ */
+#define GET_MACRO(_1, _2, _3, x, ...) x
+
 /* 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 UALIAS(alias_unicode, alias_name, canonical)                   \
+/* UALIAS2 is for passing U(N) as the first two arguments. */
+#define UALIAS2(alias_unicode_name, canonical)                         \
+       { { .alias_of = canonical }, alias_unicode_name, IS_ALIAS }
+#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)
 
 static struct glyph {
@@ -916,7 +926,7 @@ static struct glyph {
  {"\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" },
  {"\03\02\17\20\20\20\17\00\00", U(0188) }, /* Hooktop C */
- UALIAS(0x0189, "uni0189", "Eth"), /* African D */
+ UALIAS(U(0189), "Eth"), /* African D */
  ALIAS("uni0189.serif", "Eth.serif"),
  ALIAS("uni0189.c2sc", "Eth.c2sc"),
  ALIAS("uni0189.c2sc.serif", "Eth.c2sc.serif"),
@@ -1136,11 +1146,11 @@ static struct glyph {
  /* Spacing modifier letters */
  {"\20\20\30\24\24\00\00\00\00", U(02B0) }, /* Superscript h */
  {"\10\00\10\10\10\20\00\00\00", U(02B2) }, /* Superscript j */
- UALIAS(0x02b9, "uni02B9", "minute"),
- UALIAS(0x02ba, "uni02BA", "second"),
- UALIAS(0x02bb, "uni02BB", "quoteleft"),
- UALIAS(0x02bc, "uni02BC", "quoteright"),
- UALIAS(0x02bd, "uni02BD", "quotereversed"),
+ UALIAS(U(02B9), "minute"),
+ UALIAS(U(02BA), "second"),
+ UALIAS(U(02BB), "quoteleft"),
+ UALIAS(U(02BC), "quoteright"),
+ UALIAS(U(02BD), "quotereversed"),
  {"\04\12\00\00\00\00\00\00\00", 0x02c6, "circumflex" },
  {"\12\04\00\00\00\00\00\00\00", 0x02c7, "caron" },
  {"\04\04\04\00\00\00\00\00\00", U(02C8) }, /* Vertical stroke (superior) */
@@ -3049,7 +3059,6 @@ static struct gsub_feature {
        ALTSET(c, ALT3(a, b, c))
 #define CV2(base, a) CROSSALT2(base, base a)
 #define CV3(base, a, b) CROSSALT3(base, base a, base b)
-#define GET_MACRO(_1, _2, _3, x, ...) x
 #define CV(...) GET_MACRO(__VA_ARGS__, CV3, CV2)(__VA_ARGS__)
        /*
         * Where possible, Character Variant features have numbers