X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/charset/blobdiff_plain/01081d4e1448c952c0967e71448b504e26360923..1f6db6557bd76e444df6bc1a142c65979ebc1564:/iso2022s.c diff --git a/iso2022s.c b/iso2022s.c index fd75ab4..53b5d44 100644 --- a/iso2022s.c +++ b/iso2022s.c @@ -562,7 +562,8 @@ enum { CTEXT_ISO8859_9, CTEXT_GB2312, CTEXT_KSC5601, - CTEXT_JISX0208 + CTEXT_JISX0208, + CTEXT_JISX0212 }; static long int ctext_to_ucs(int subcharset, unsigned long bytes) { @@ -599,6 +600,9 @@ static long int ctext_to_ucs(int subcharset, unsigned long bytes) case CTEXT_JISX0208: return jisx0208_to_unicode(((bytes >> 8) & 0xFF) - 0x21, ((bytes ) & 0xFF) - 0x21); + case CTEXT_JISX0212: + return jisx0212_to_unicode(((bytes >> 8) & 0xFF) - 0x21, + ((bytes ) & 0xFF) - 0x21); default: return ERROR; } } @@ -666,12 +670,16 @@ static int ctext_from_ucs(long int ucs, int *subcharset, unsigned long *bytes) *subcharset = CTEXT_JISX0208; *bytes = ((r+0x21) << 8) | (c+0x21); return 1; + } else if (unicode_to_jisx0212(ucs, &r, &c)) { + *subcharset = CTEXT_JISX0212; + *bytes = ((r+0x21) << 8) | (c+0x21); + return 1; } else { return 0; } } #define SEQ(str,cont,cs) \ - {str,~(63<<(6*((cont&~RO)))),(cs)<<(6*((cont&~RO))),(cont),(cs)} + {str,~(63<<(6*(((cont)&~RO)))),(cs)<<(6*(((cont)&~RO))),(cont),(cs)} /* * Compound text defines restrictions on which container can take * which character sets. Things labelled `left half of' can only go @@ -688,11 +696,14 @@ static struct iso2022_escape ctext_escapes[] = { SEQ("\033$(A", 0|RO, CTEXT_GB2312), SEQ("\033$(B", 0|RO, CTEXT_JISX0208), SEQ("\033$(C", 0|RO, CTEXT_KSC5601), + SEQ("\033$(D", 0|RO, CTEXT_JISX0212), SEQ("\033$)A", 1, CTEXT_GB2312), SEQ("\033$)B", 1, CTEXT_JISX0208), SEQ("\033$)C", 1, CTEXT_KSC5601), + SEQ("\033$)D", 1, CTEXT_JISX0212), SEQ("\033(B", 0, CTEXT_ASCII), SEQ("\033(J", 0, CTEXT_JISX0201_LEFT), + SEQ("\033)I", 1, CTEXT_JISX0201_RIGHT), SEQ("\033-A", 1, CTEXT_ISO8859_1), SEQ("\033-B", 1, CTEXT_ISO8859_2), SEQ("\033-C", 1, CTEXT_ISO8859_3), @@ -700,14 +711,13 @@ static struct iso2022_escape ctext_escapes[] = { SEQ("\033-F", 1, CTEXT_ISO8859_7), SEQ("\033-G", 1, CTEXT_ISO8859_6), SEQ("\033-H", 1, CTEXT_ISO8859_8), - SEQ("\033)I", 1, CTEXT_JISX0201_RIGHT), SEQ("\033-L", 1, CTEXT_ISO8859_5), SEQ("\033-M", 1, CTEXT_ISO8859_9), }; static struct iso2022 ctext = { ctext_escapes, lenof(ctext_escapes), - "\1\1\1\1\1\1\1\1\1\1\1\1\2\2\2", /* must match the enum above */ - "", 0x80000000 | (CTEXT_ASCII<<0) | (CTEXT_ASCII<<6), "", TRUE, + "\1\1\1\1\1\1\1\1\1\1\1\1\2\2\2\2", /* must match the enum above */ + "", 0x80000000 | (CTEXT_ASCII<<0) | (CTEXT_ISO8859_1<<6), "", TRUE, ctext_to_ucs, ctext_from_ucs }; const charset_spec charset_CS_CTEXT = {