libgrapheme

unicode string library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | README | LICENSE

commit 2dbe3f7dedbd805ecb3a381abcc7a8564aeba181
parent 860e81dd634e47beaa4b9bc2a97e9a165f6df4ff
Author: Laslo Hunhold <dev@frign.de>
Date:   Fri,  7 Jan 2022 18:30:31 +0100

Refactor derived-properties-table-generation

Use a callback-function that gives us the desired single element in
the properties array rather than hacking around with pointers. This also
makes it a more general interface.

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
Mgen/properties.c | 25++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/gen/properties.c b/gen/properties.c @@ -312,20 +312,22 @@ print_lookup_table(char *name, size_t *data, size_t datalen) printf("};\n"); } -/* - * this function is for the special case where struct property - * only contains a single enum value. - */ +static uint_least8_t +get_value(const void *payload, size_t offset) +{ + return ((const struct properties *)payload)[offset].char_break_property; +} + static void -print_enum_lookup_table(char *name, size_t *offset, size_t offsetlen, - const struct properties *prop) +print_derived_lookup_table(char *name, size_t *offset, size_t offsetlen, + uint_least8_t (*get_value)(const void *, size_t), + const void *payload) { size_t i; - printf("static const uint8_t %s[] = {\n\t", name); + printf("static const uint_least8_t %s[] = {\n\t", name); for (i = 0; i < offsetlen; i++) { - printf("%"PRIuLEAST8, - *((const uint_least8_t *)&(prop[offset[i]]))); + printf("%"PRIuLEAST8, get_value(payload, offset[i])); if (i + 1 == offsetlen) { printf("\n"); } else if ((i + 1) % 8 != 0) { @@ -369,9 +371,9 @@ main(int argc, char *argv[]) /* extract properties */ payload.prop = prop; - payload.spec = char_break_property; payload.speclen = LEN(char_break_property); + parse_file_with_callback(FILE_EMOJI, break_property_callback, &payload); parse_file_with_callback(FILE_GRAPHEME, break_property_callback, &payload); @@ -391,7 +393,8 @@ main(int argc, char *argv[]) print_lookup_table("major", mm.major, 0x1100); printf("\n"); - print_enum_lookup_table("minor", mm.minor, mm.minorlen, comp.data); + print_derived_lookup_table("minor", mm.minor, mm.minorlen, get_value, + comp.data); /* free data */ free(prop);