2 a31db67d 2004-04-21 devnull following astonishing goo courtesy of kogure.
5 a31db67d 2004-04-21 devnull * MicroSoft Kanji Encoding (SJIS) Transformation
10 a31db67d 2004-04-21 devnull * J2S(unsigned char *_h, unsigned char *_l)
11 a31db67d 2004-04-21 devnull * JIS X 208 to MS kanji transformation.
13 a31db67d 2004-04-21 devnull * Calling/Exit State:
14 a31db67d 2004-04-21 devnull * _h and _l should be in their valid range.
15 a31db67d 2004-04-21 devnull * No return value.
17 a31db67d 2004-04-21 devnull #define J2S(_h, _l) { \
18 a31db67d 2004-04-21 devnull /* lower: 21-7e >> 40-9d,9e-fb >> 40-7e,(skip 7f),80-fc */ \
19 a31db67d 2004-04-21 devnull if (((_l) += (((_h)-- % 2) ? 0x1f : 0x7d)) > 0x7e) (_l)++; \
20 a31db67d 2004-04-21 devnull /* upper: 21-7e >> 81-af >> 81-9f,(skip a0-df),e0-ef */ \
21 a31db67d 2004-04-21 devnull if (((_h) = ((_h) / 2 + 0x71)) > 0x9f) (_h) += 0x40; \
26 a31db67d 2004-04-21 devnull * S2J(unsigned char *_h, unsigned char *_l)
27 a31db67d 2004-04-21 devnull * MS kanji to JIS X 208 transformation.
29 a31db67d 2004-04-21 devnull * Calling/Exit State:
30 a31db67d 2004-04-21 devnull * _h and _l should be in valid range.
31 a31db67d 2004-04-21 devnull * No return value.
33 a31db67d 2004-04-21 devnull #define S2J(_h, _l) { \
34 a31db67d 2004-04-21 devnull /* lower: 40-7e,80-fc >> 21-5f,61-dd >> 21-7e,7f-dc */ \
35 a31db67d 2004-04-21 devnull if (((_l) -= 0x1f) > 0x60) (_l)--; \
36 a31db67d 2004-04-21 devnull /* upper: 81-9f,e0-ef >> 00-1e,5f-6e >> 00-2e >> 21-7d */ \
37 a31db67d 2004-04-21 devnull if (((_h) -= 0x81) > 0x5e) (_h) -= 0x40; (_h) *= 2, (_h) += 0x21; \
38 a31db67d 2004-04-21 devnull /* upper: ,21-7d >> ,22-7e ; lower: ,7f-dc >> ,21-7e */ \
39 a31db67d 2004-04-21 devnull if ((_l) > 0x7e) (_h)++, (_l) -= 0x5e; \
44 a31db67d 2004-04-21 devnull * ISJKANA(const unsigned char *_b)
45 a31db67d 2004-04-21 devnull * Tests given byte is in the range of JIS X 0201 katakana.
47 a31db67d 2004-04-21 devnull * Calling/Exit State:
48 a31db67d 2004-04-21 devnull * Returns 1 if it is, or 0 otherwise.
50 a31db67d 2004-04-21 devnull #define ISJKANA(_b) (0xa0 <= (_b) && (_b) < 0xe0)
54 a31db67d 2004-04-21 devnull * CANS2JH(const unsigned char *_h)
55 a31db67d 2004-04-21 devnull * Tests given byte is in the range of valid first byte of MS
56 a31db67d 2004-04-21 devnull * kanji code; either acts as a subroutine of CANS2J() macro
57 a31db67d 2004-04-21 devnull * or can be used to parse MS kanji encoded strings.
59 a31db67d 2004-04-21 devnull * Calling/Exit State:
60 a31db67d 2004-04-21 devnull * Returns 1 if it is, or 0 otherwise.
62 a31db67d 2004-04-21 devnull #define CANS2JH(_h) ((0x81 <= (_h) && (_h) < 0xf0) && !ISJKANA(_h))
66 a31db67d 2004-04-21 devnull * CANS2JL(const unsigned char *_l)
67 a31db67d 2004-04-21 devnull * Tests given byte is in the range of valid second byte of MS
68 a31db67d 2004-04-21 devnull * kanji code; acts as a subroutine of CANS2J() macro.
70 a31db67d 2004-04-21 devnull * Calling/Exit State:
71 a31db67d 2004-04-21 devnull * Returns 1 if it is, or 0 otherwise.
73 a31db67d 2004-04-21 devnull #define CANS2JL(_l) (0x40 <= (_l) && (_l) < 0xfd && (_l) != 0x7f)
77 a31db67d 2004-04-21 devnull * CANS2J(const unsigned char *_h, const unsinged char *_l)
78 a31db67d 2004-04-21 devnull * Tests given bytes form a MS kanji code point which can be
79 a31db67d 2004-04-21 devnull * transformed to a valid JIS X 208 code point.
81 a31db67d 2004-04-21 devnull * Calling/Exit State:
82 a31db67d 2004-04-21 devnull * Returns 1 if they are, or 0 otherwise.
84 a31db67d 2004-04-21 devnull #define CANS2J(_h, _l) (CANS2JH(_h) && CANS2JL(_l))
88 a31db67d 2004-04-21 devnull * CANJ2SB(const unsigned char *_b)
89 a31db67d 2004-04-21 devnull * Tests given bytes is in the range of valid 94 graphic
90 a31db67d 2004-04-21 devnull * character set; acts as a subroutine of CANJ2S() macro.
92 a31db67d 2004-04-21 devnull * Calling/Exit State:
93 a31db67d 2004-04-21 devnull * Returns 1 if it is, or 0 otherwise.
95 a31db67d 2004-04-21 devnull #define CANJ2SB(_b) (0x21 <= (_b) && (_b) < 0x7f)
99 a31db67d 2004-04-21 devnull * CANJ2S(const unsigned char *_h, const unsigned char *_l)
100 a31db67d 2004-04-21 devnull * Tests given bytes form valid JIS X 208 code points
101 a31db67d 2004-04-21 devnull * (which can be transformed to MS kanji).
103 a31db67d 2004-04-21 devnull * Calling/Exit State:
104 a31db67d 2004-04-21 devnull * Returns 1 if they are, or 0 otherwise.
106 a31db67d 2004-04-21 devnull #define CANJ2S(_h, _l) (CANJ2SB(_h) && CANJ2SB(_l))