>From 871f109e639b17de21ac3ea2f2e27eb975e439a5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Sep 2026 22:24:28 -0400 Subject: [PATCH 05/18] add include frameworks for building built-in C locale string tables these files take an argument as a M_TABLE macro with 3 comma-delimited fields containing a file to include as the data source, a name for the structure to hold the data, and a lower bound on the key values appearing in the data. mdecl.h includes the named header multiple times to produce declarations for the header, offset table, and string table content structure. mdata.h includes the header again multiple times to produce the actual offset values and string table content as initializers. --- src/internal/mdata.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/internal/mdecl.h | 21 +++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/internal/mdata.h create mode 100644 src/internal/mdecl.h diff --git a/src/internal/mdata.h b/src/internal/mdata.h new file mode 100644 index 00000000..6b2968de --- /dev/null +++ b/src/internal/mdata.h @@ -0,0 +1,40 @@ +#define M_3(a,b,c,...) c +#define M_S(...) M_3(,,__VA_ARGS__) +#define M_N(...) M_3(,__VA_ARGS__) +#define M_B(...) M_3(__VA_ARGS__) + +.header = { + 0xff & (M_B(M_TABLE)>>24), + 0xff & (M_B(M_TABLE)>>16), + 0xff & (M_B(M_TABLE)>>8), + 0xff & (M_B(M_TABLE)), + 0, 1, + (sizeof (unsigned char[]){ +#define M(n, s) [(n)-(M_B(M_TABLE))] = 0, +#include M_S(M_TABLE) +#undef M + } - 1) >> 8, + (sizeof (unsigned char[]){ +#define M(n, s) [(n)-(M_B(M_TABLE))] = 0, +#include M_S(M_TABLE) +#undef M + } - 1) & 0xff, +}, +.offsets = { +#define M(n, s) \ + [2*((n)-(M_B(M_TABLE)))] = \ + (offsetof(struct M_N(M_TABLE), m_##n)+1)/256,\ + (offsetof(struct M_N(M_TABLE), m_##n)+1)%256, +#include M_S(M_TABLE) +#undef M +}, +.data = { +#define M(n, s) .m_##n = s, +#include M_S(M_TABLE) +#undef M +}, + +#undef M_3 +#undef M_S +#undef M_N +#undef M_B diff --git a/src/internal/mdecl.h b/src/internal/mdecl.h new file mode 100644 index 00000000..0c36603d --- /dev/null +++ b/src/internal/mdecl.h @@ -0,0 +1,21 @@ +#define M_3(a,b,c,...) c +#define M_S(...) M_3(,,__VA_ARGS__) +#define M_N(...) M_3(,__VA_ARGS__) +#define M_B(...) M_3(__VA_ARGS__) + +unsigned char header[8]; +unsigned char offsets[sizeof (unsigned char[]){ +#define M(n, s) [2*((n)-(M_B(M_TABLE)))] = 0, 0, +#include M_S(M_TABLE) +#undef M +}]; +struct M_N(M_TABLE) { +#define M(n, s) char m_##n[sizeof(s)]; +#include M_S(M_TABLE) +#undef M +} data; + +#undef M_3 +#undef M_S +#undef M_N +#undef M_B -- 2.21.0