1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

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.
This commit is contained in:
Simon Tatham 2021-10-10 14:32:03 +01:00
parent d7548d0449
commit 804f32765f
2 changed files with 39 additions and 54 deletions

View File

@ -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 */

View File

@ -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;