diff options
author | Simon Tatham <anakin@pobox.com> | 2021-10-10 16:32:03 +0300 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2021-10-10 16:55:15 +0300 |
commit | 804f32765fd909018ec22b27d5e3d7bffe802d72 (patch) | |
tree | ba57ef1ce1b48a2387a1b15d346bd2d2fdf7fe34 /terminal | |
parent | d7548d044923a991914486432439612f0ddb982a (diff) |
Make bidi type enums into list macros.
This makes it easier to create the matching array of type names in
bidi_gettype.c, and eliminates the need for an assertion to check the
array matched the enum. And I'm about to need to add more types, so
let's start by making that trivially easy.
Diffstat (limited to 'terminal')
-rw-r--r-- | terminal/bidi.h | 63 | ||||
-rw-r--r-- | terminal/bidi_gettype.c | 30 |
2 files changed, 39 insertions, 54 deletions
diff --git a/terminal/bidi.h b/terminal/bidi.h index eca80c21..53ffbcd3 100644 --- a/terminal/bidi.h +++ b/terminal/bidi.h @@ -25,36 +25,41 @@ shapetypes[(xh)-SHAPE_FIRST].type : SU) /*))*/ /* Function declarations used outside bidi.c */ unsigned char bidi_getType(int ch); -/* character types */ -enum { - L, - LRE, - LRO, - R, - AL, - RLE, - RLO, - PDF, - EN, - ES, - ET, - AN, - CS, - NSM, - BN, - B, - S, - WS, - ON -}; +/* Bidi character types */ +#define BIDI_CHAR_TYPE_LIST(X) \ + X(L) \ + X(LRE) \ + X(LRO) \ + X(R) \ + X(AL) \ + X(RLE) \ + X(RLO) \ + X(PDF) \ + X(EN) \ + X(ES) \ + X(ET) \ + X(AN) \ + X(CS) \ + X(NSM) \ + X(BN) \ + X(B) \ + X(S) \ + X(WS) \ + X(ON) \ + /* end of list */ /* Shaping Types */ -enum { - SL, /* Left-Joining, doesn't exist in U+0600 - U+06FF */ - SR, /* Right-Joining, ie has Isolated, Final */ - SD, /* Dual-Joining, ie has Isolated, Final, Initial, Medial */ - SU, /* Non-Joining */ - SC /* Join-Causing, like U+0640 (TATWEEL) */ -}; +#define SHAPING_CHAR_TYPE_LIST(X) \ + X(SL) /* Left-Joining, doesn't exist in U+0600 - U+06FF */ \ + X(SR) /* Right-Joining, ie has Isolated, Final */ \ + X(SD) /* Dual-Joining, ie has Isolated, Final, Initial, Medial */ \ + X(SU) /* Non-Joining */ \ + X(SC) /* Join-Causing, like U+0640 (TATWEEL) */ \ + /* end of list */ + +#define ENUM_DECL(name) name, +typedef enum { BIDI_CHAR_TYPE_LIST(ENUM_DECL) N_BIDI_TYPES } BidiType; +typedef enum { SHAPING_CHAR_TYPE_LIST(ENUM_DECL) N_SHAPING_TYPES } ShapingType; +#undef ENUM_DECL #endif /* PUTTY_BIDI_H */ diff --git a/terminal/bidi_gettype.c b/terminal/bidi_gettype.c index a3b765ae..f3f5338e 100644 --- a/terminal/bidi_gettype.c +++ b/terminal/bidi_gettype.c @@ -15,38 +15,18 @@ void out_of_memory(void) exit(2); } +#define TYPETONAME(X) #X, +static const char *const typenames[] = { BIDI_CHAR_TYPE_LIST(TYPETONAME) }; +#undef TYPETONAME + int main(int argc, char **argv) { - static const struct { int type; char *name; } typetoname[] = { -#define TYPETONAME(X) { X , #X } - TYPETONAME(L), - TYPETONAME(LRE), - TYPETONAME(LRO), - TYPETONAME(R), - TYPETONAME(AL), - TYPETONAME(RLE), - TYPETONAME(RLO), - TYPETONAME(PDF), - TYPETONAME(EN), - TYPETONAME(ES), - TYPETONAME(ET), - TYPETONAME(AN), - TYPETONAME(CS), - TYPETONAME(NSM), - TYPETONAME(BN), - TYPETONAME(B), - TYPETONAME(S), - TYPETONAME(WS), - TYPETONAME(ON), -#undef TYPETONAME - }; int i; for (i = 1; i < argc; i++) { unsigned long chr = strtoul(argv[i], NULL, 0); int type = bidi_getType(chr); - assert(typetoname[type].type == type); - printf("U+%04x: %s\n", (unsigned)chr, typetoname[type].name); + printf("U+%04x: %s\n", (unsigned)chr, typenames[type]); } return 0; |