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:
parent
d7548d0449
commit
804f32765f
@ -25,36 +25,41 @@ shapetypes[(xh)-SHAPE_FIRST].type : SU) /*))*/
|
|||||||
/* Function declarations used outside bidi.c */
|
/* Function declarations used outside bidi.c */
|
||||||
unsigned char bidi_getType(int ch);
|
unsigned char bidi_getType(int ch);
|
||||||
|
|
||||||
/* character types */
|
/* Bidi character types */
|
||||||
enum {
|
#define BIDI_CHAR_TYPE_LIST(X) \
|
||||||
L,
|
X(L) \
|
||||||
LRE,
|
X(LRE) \
|
||||||
LRO,
|
X(LRO) \
|
||||||
R,
|
X(R) \
|
||||||
AL,
|
X(AL) \
|
||||||
RLE,
|
X(RLE) \
|
||||||
RLO,
|
X(RLO) \
|
||||||
PDF,
|
X(PDF) \
|
||||||
EN,
|
X(EN) \
|
||||||
ES,
|
X(ES) \
|
||||||
ET,
|
X(ET) \
|
||||||
AN,
|
X(AN) \
|
||||||
CS,
|
X(CS) \
|
||||||
NSM,
|
X(NSM) \
|
||||||
BN,
|
X(BN) \
|
||||||
B,
|
X(B) \
|
||||||
S,
|
X(S) \
|
||||||
WS,
|
X(WS) \
|
||||||
ON
|
X(ON) \
|
||||||
};
|
/* end of list */
|
||||||
|
|
||||||
/* Shaping Types */
|
/* Shaping Types */
|
||||||
enum {
|
#define SHAPING_CHAR_TYPE_LIST(X) \
|
||||||
SL, /* Left-Joining, doesn't exist in U+0600 - U+06FF */
|
X(SL) /* Left-Joining, doesn't exist in U+0600 - U+06FF */ \
|
||||||
SR, /* Right-Joining, ie has Isolated, Final */
|
X(SR) /* Right-Joining, ie has Isolated, Final */ \
|
||||||
SD, /* Dual-Joining, ie has Isolated, Final, Initial, Medial */
|
X(SD) /* Dual-Joining, ie has Isolated, Final, Initial, Medial */ \
|
||||||
SU, /* Non-Joining */
|
X(SU) /* Non-Joining */ \
|
||||||
SC /* Join-Causing, like U+0640 (TATWEEL) */
|
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 */
|
#endif /* PUTTY_BIDI_H */
|
||||||
|
@ -15,38 +15,18 @@ void out_of_memory(void)
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TYPETONAME(X) #X,
|
||||||
|
static const char *const typenames[] = { BIDI_CHAR_TYPE_LIST(TYPETONAME) };
|
||||||
|
#undef TYPETONAME
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
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;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
unsigned long chr = strtoul(argv[i], NULL, 0);
|
unsigned long chr = strtoul(argv[i], NULL, 0);
|
||||||
int type = bidi_getType(chr);
|
int type = bidi_getType(chr);
|
||||||
assert(typetoname[type].type == type);
|
printf("U+%04x: %s\n", (unsigned)chr, typenames[type]);
|
||||||
printf("U+%04x: %s\n", (unsigned)chr, typetoname[type].name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user