ยปCore Development>Code coverage>Modules/cjkcodecs/_codecs_jp.c

Python code coverage for Modules/cjkcodecs/_codecs_jp.c

#countcontent
1n/a/*
2n/a * _codecs_jp.c: Codecs collection for Japanese encodings
3n/a *
4n/a * Written by Hye-Shik Chang <perky@FreeBSD.org>
5n/a */
6n/a
7n/a#define USING_BINARY_PAIR_SEARCH
8n/a#define EMPBASE 0x20000
9n/a
10n/a#include "cjkcodecs.h"
11n/a#include "mappings_jp.h"
12n/a#include "mappings_jisx0213_pair.h"
13n/a#include "alg_jisx0201.h"
14n/a#include "emu_jisx0213_2000.h"
15n/a
16n/a/*
17n/a * CP932 codec
18n/a */
19n/a
20n/aENCODER(cp932)
21n/a{
22n/a while (*inpos < inlen) {
23n/a Py_UCS4 c = INCHAR1;
24n/a DBCHAR code;
25n/a unsigned char c1, c2;
26n/a
27n/a if (c <= 0x80) {
28n/a WRITEBYTE1((unsigned char)c);
29n/a NEXT(1, 1);
30n/a continue;
31n/a }
32n/a else if (c >= 0xff61 && c <= 0xff9f) {
33n/a WRITEBYTE1(c - 0xfec0);
34n/a NEXT(1, 1);
35n/a continue;
36n/a }
37n/a else if (c >= 0xf8f0 && c <= 0xf8f3) {
38n/a /* Windows compatibility */
39n/a REQUIRE_OUTBUF(1);
40n/a if (c == 0xf8f0)
41n/a OUTBYTE1(0xa0);
42n/a else
43n/a OUTBYTE1(c - 0xfef1 + 0xfd);
44n/a NEXT(1, 1);
45n/a continue;
46n/a }
47n/a
48n/a if (c > 0xFFFF)
49n/a return 1;
50n/a REQUIRE_OUTBUF(2);
51n/a
52n/a if (TRYMAP_ENC(cp932ext, code, c)) {
53n/a OUTBYTE1(code >> 8);
54n/a OUTBYTE2(code & 0xff);
55n/a }
56n/a else if (TRYMAP_ENC(jisxcommon, code, c)) {
57n/a if (code & 0x8000) /* MSB set: JIS X 0212 */
58n/a return 1;
59n/a
60n/a /* JIS X 0208 */
61n/a c1 = code >> 8;
62n/a c2 = code & 0xff;
63n/a c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21);
64n/a c1 = (c1 - 0x21) >> 1;
65n/a OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1);
66n/a OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41);
67n/a }
68n/a else if (c >= 0xe000 && c < 0xe758) {
69n/a /* User-defined area */
70n/a c1 = (Py_UCS4)(c - 0xe000) / 188;
71n/a c2 = (Py_UCS4)(c - 0xe000) % 188;
72n/a OUTBYTE1(c1 + 0xf0);
73n/a OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41);
74n/a }
75n/a else
76n/a return 1;
77n/a
78n/a NEXT(1, 2);
79n/a }
80n/a
81n/a return 0;
82n/a}
83n/a
84n/aDECODER(cp932)
85n/a{
86n/a while (inleft > 0) {
87n/a unsigned char c = INBYTE1, c2;
88n/a Py_UCS4 decoded;
89n/a
90n/a if (c <= 0x80) {
91n/a OUTCHAR(c);
92n/a NEXT_IN(1);
93n/a continue;
94n/a }
95n/a else if (c >= 0xa0 && c <= 0xdf) {
96n/a if (c == 0xa0)
97n/a OUTCHAR(0xf8f0); /* half-width katakana */
98n/a else
99n/a OUTCHAR(0xfec0 + c);
100n/a NEXT_IN(1);
101n/a continue;
102n/a }
103n/a else if (c >= 0xfd/* && c <= 0xff*/) {
104n/a /* Windows compatibility */
105n/a OUTCHAR(0xf8f1 - 0xfd + c);
106n/a NEXT_IN(1);
107n/a continue;
108n/a }
109n/a
110n/a REQUIRE_INBUF(2);
111n/a c2 = INBYTE2;
112n/a
113n/a if (TRYMAP_DEC(cp932ext, decoded, c, c2))
114n/a OUTCHAR(decoded);
115n/a else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)){
116n/a if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc)
117n/a return 1;
118n/a
119n/a c = (c < 0xe0 ? c - 0x81 : c - 0xc1);
120n/a c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41);
121n/a c = (2 * c + (c2 < 0x5e ? 0 : 1) + 0x21);
122n/a c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21;
123n/a
124n/a if (TRYMAP_DEC(jisx0208, decoded, c, c2))
125n/a OUTCHAR(decoded);
126n/a else
127n/a return 1;
128n/a }
129n/a else if (c >= 0xf0 && c <= 0xf9) {
130n/a if ((c2 >= 0x40 && c2 <= 0x7e) ||
131n/a (c2 >= 0x80 && c2 <= 0xfc))
132n/a OUTCHAR(0xe000 + 188 * (c - 0xf0) +
133n/a (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41));
134n/a else
135n/a return 1;
136n/a }
137n/a else
138n/a return 1;
139n/a
140n/a NEXT_IN(2);
141n/a }
142n/a
143n/a return 0;
144n/a}
145n/a
146n/a
147n/a/*
148n/a * EUC-JIS-2004 codec
149n/a */
150n/a
151n/aENCODER(euc_jis_2004)
152n/a{
153n/a while (*inpos < inlen) {
154n/a Py_UCS4 c = INCHAR1;
155n/a DBCHAR code;
156n/a Py_ssize_t insize;
157n/a
158n/a if (c < 0x80) {
159n/a WRITEBYTE1(c);
160n/a NEXT(1, 1);
161n/a continue;
162n/a }
163n/a
164n/a insize = 1;
165n/a
166n/a if (c <= 0xFFFF) {
167n/a EMULATE_JISX0213_2000_ENCODE_BMP(code, c)
168n/a else if (TRYMAP_ENC(jisx0213_bmp, code, c)) {
169n/a if (code == MULTIC) {
170n/a if (inlen - *inpos < 2) {
171n/a if (flags & MBENC_FLUSH) {
172n/a code = find_pairencmap(
173n/a (ucs2_t)c, 0,
174n/a jisx0213_pair_encmap,
175n/a JISX0213_ENCPAIRS);
176n/a if (code == DBCINV)
177n/a return 1;
178n/a }
179n/a else
180n/a return MBERR_TOOFEW;
181n/a }
182n/a else {
183n/a Py_UCS4 c2 = INCHAR2;
184n/a code = find_pairencmap(
185n/a (ucs2_t)c, c2,
186n/a jisx0213_pair_encmap,
187n/a JISX0213_ENCPAIRS);
188n/a if (code == DBCINV) {
189n/a code = find_pairencmap(
190n/a (ucs2_t)c, 0,
191n/a jisx0213_pair_encmap,
192n/a JISX0213_ENCPAIRS);
193n/a if (code == DBCINV)
194n/a return 1;
195n/a } else
196n/a insize = 2;
197n/a }
198n/a }
199n/a }
200n/a else if (TRYMAP_ENC(jisxcommon, code, c))
201n/a ;
202n/a else if (c >= 0xff61 && c <= 0xff9f) {
203n/a /* JIS X 0201 half-width katakana */
204n/a WRITEBYTE2(0x8e, c - 0xfec0);
205n/a NEXT(1, 2);
206n/a continue;
207n/a }
208n/a else if (c == 0xff3c)
209n/a /* F/W REVERSE SOLIDUS (see NOTES) */
210n/a code = 0x2140;
211n/a else if (c == 0xff5e)
212n/a /* F/W TILDE (see NOTES) */
213n/a code = 0x2232;
214n/a else
215n/a return 1;
216n/a }
217n/a else if (c >> 16 == EMPBASE >> 16) {
218n/a EMULATE_JISX0213_2000_ENCODE_EMP(code, c)
219n/a else if (TRYMAP_ENC(jisx0213_emp, code, c & 0xffff))
220n/a ;
221n/a else
222n/a return insize;
223n/a }
224n/a else
225n/a return insize;
226n/a
227n/a if (code & 0x8000) {
228n/a /* Codeset 2 */
229n/a WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80);
230n/a NEXT(insize, 3);
231n/a } else {
232n/a /* Codeset 1 */
233n/a WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80);
234n/a NEXT(insize, 2);
235n/a }
236n/a }
237n/a
238n/a return 0;
239n/a}
240n/a
241n/aDECODER(euc_jis_2004)
242n/a{
243n/a while (inleft > 0) {
244n/a unsigned char c = INBYTE1;
245n/a Py_UCS4 code, decoded;
246n/a
247n/a if (c < 0x80) {
248n/a OUTCHAR(c);
249n/a NEXT_IN(1);
250n/a continue;
251n/a }
252n/a
253n/a if (c == 0x8e) {
254n/a /* JIS X 0201 half-width katakana */
255n/a unsigned char c2;
256n/a
257n/a REQUIRE_INBUF(2);
258n/a c2 = INBYTE2;
259n/a if (c2 >= 0xa1 && c2 <= 0xdf) {
260n/a OUTCHAR(0xfec0 + c2);
261n/a NEXT_IN(2);
262n/a }
263n/a else
264n/a return 1;
265n/a }
266n/a else if (c == 0x8f) {
267n/a unsigned char c2, c3;
268n/a
269n/a REQUIRE_INBUF(3);
270n/a c2 = INBYTE2 ^ 0x80;
271n/a c3 = INBYTE3 ^ 0x80;
272n/a
273n/a /* JIS X 0213 Plane 2 or JIS X 0212 (see NOTES) */
274n/a EMULATE_JISX0213_2000_DECODE_PLANE2(writer, c2, c3)
275n/a else if (TRYMAP_DEC(jisx0213_2_bmp, decoded, c2, c3))
276n/a OUTCHAR(decoded);
277n/a else if (TRYMAP_DEC(jisx0213_2_emp, code, c2, c3)) {
278n/a OUTCHAR(EMPBASE | code);
279n/a NEXT_IN(3);
280n/a continue;
281n/a }
282n/a else if (TRYMAP_DEC(jisx0212, decoded, c2, c3))
283n/a OUTCHAR(decoded);
284n/a else
285n/a return 1;
286n/a NEXT_IN(3);
287n/a }
288n/a else {
289n/a unsigned char c2;
290n/a
291n/a REQUIRE_INBUF(2);
292n/a c ^= 0x80;
293n/a c2 = INBYTE2 ^ 0x80;
294n/a
295n/a /* JIS X 0213 Plane 1 */
296n/a EMULATE_JISX0213_2000_DECODE_PLANE1(writer, c, c2)
297n/a else if (c == 0x21 && c2 == 0x40)
298n/a OUTCHAR(0xff3c);
299n/a else if (c == 0x22 && c2 == 0x32)
300n/a OUTCHAR(0xff5e);
301n/a else if (TRYMAP_DEC(jisx0208, decoded, c, c2))
302n/a OUTCHAR(decoded);
303n/a else if (TRYMAP_DEC(jisx0213_1_bmp, decoded, c, c2))
304n/a OUTCHAR(decoded);
305n/a else if (TRYMAP_DEC(jisx0213_1_emp, code, c, c2)) {
306n/a OUTCHAR(EMPBASE | code);
307n/a NEXT_IN(2);
308n/a continue;
309n/a }
310n/a else if (TRYMAP_DEC(jisx0213_pair, code, c, c2)) {
311n/a OUTCHAR2(code >> 16, code & 0xffff);
312n/a NEXT_IN(2);
313n/a continue;
314n/a }
315n/a else
316n/a return 1;
317n/a NEXT_IN(2);
318n/a }
319n/a }
320n/a
321n/a return 0;
322n/a}
323n/a
324n/a
325n/a/*
326n/a * EUC-JP codec
327n/a */
328n/a
329n/aENCODER(euc_jp)
330n/a{
331n/a while (*inpos < inlen) {
332n/a Py_UCS4 c = INCHAR1;
333n/a DBCHAR code;
334n/a
335n/a if (c < 0x80) {
336n/a WRITEBYTE1((unsigned char)c);
337n/a NEXT(1, 1);
338n/a continue;
339n/a }
340n/a
341n/a if (c > 0xFFFF)
342n/a return 1;
343n/a
344n/a if (TRYMAP_ENC(jisxcommon, code, c))
345n/a ;
346n/a else if (c >= 0xff61 && c <= 0xff9f) {
347n/a /* JIS X 0201 half-width katakana */
348n/a WRITEBYTE2(0x8e, c - 0xfec0);
349n/a NEXT(1, 2);
350n/a continue;
351n/a }
352n/a#ifndef STRICT_BUILD
353n/a else if (c == 0xff3c) /* FULL-WIDTH REVERSE SOLIDUS */
354n/a code = 0x2140;
355n/a else if (c == 0xa5) { /* YEN SIGN */
356n/a WRITEBYTE1(0x5c);
357n/a NEXT(1, 1);
358n/a continue;
359n/a } else if (c == 0x203e) { /* OVERLINE */
360n/a WRITEBYTE1(0x7e);
361n/a NEXT(1, 1);
362n/a continue;
363n/a }
364n/a#endif
365n/a else
366n/a return 1;
367n/a
368n/a if (code & 0x8000) {
369n/a /* JIS X 0212 */
370n/a WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80);
371n/a NEXT(1, 3);
372n/a } else {
373n/a /* JIS X 0208 */
374n/a WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80);
375n/a NEXT(1, 2);
376n/a }
377n/a }
378n/a
379n/a return 0;
380n/a}
381n/a
382n/aDECODER(euc_jp)
383n/a{
384n/a while (inleft > 0) {
385n/a unsigned char c = INBYTE1;
386n/a Py_UCS4 decoded;
387n/a
388n/a if (c < 0x80) {
389n/a OUTCHAR(c);
390n/a NEXT_IN(1);
391n/a continue;
392n/a }
393n/a
394n/a if (c == 0x8e) {
395n/a /* JIS X 0201 half-width katakana */
396n/a unsigned char c2;
397n/a
398n/a REQUIRE_INBUF(2);
399n/a c2 = INBYTE2;
400n/a if (c2 >= 0xa1 && c2 <= 0xdf) {
401n/a OUTCHAR(0xfec0 + c2);
402n/a NEXT_IN(2);
403n/a }
404n/a else
405n/a return 1;
406n/a }
407n/a else if (c == 0x8f) {
408n/a unsigned char c2, c3;
409n/a
410n/a REQUIRE_INBUF(3);
411n/a c2 = INBYTE2;
412n/a c3 = INBYTE3;
413n/a /* JIS X 0212 */
414n/a if (TRYMAP_DEC(jisx0212, decoded, c2 ^ 0x80, c3 ^ 0x80)) {
415n/a OUTCHAR(decoded);
416n/a NEXT_IN(3);
417n/a }
418n/a else
419n/a return 1;
420n/a }
421n/a else {
422n/a unsigned char c2;
423n/a
424n/a REQUIRE_INBUF(2);
425n/a c2 = INBYTE2;
426n/a /* JIS X 0208 */
427n/a#ifndef STRICT_BUILD
428n/a if (c == 0xa1 && c2 == 0xc0)
429n/a /* FULL-WIDTH REVERSE SOLIDUS */
430n/a OUTCHAR(0xff3c);
431n/a else
432n/a#endif
433n/a if (TRYMAP_DEC(jisx0208, decoded, c ^ 0x80, c2 ^ 0x80))
434n/a OUTCHAR(decoded);
435n/a else
436n/a return 1;
437n/a NEXT_IN(2);
438n/a }
439n/a }
440n/a
441n/a return 0;
442n/a}
443n/a
444n/a
445n/a/*
446n/a * SHIFT_JIS codec
447n/a */
448n/a
449n/aENCODER(shift_jis)
450n/a{
451n/a while (*inpos < inlen) {
452n/a Py_UCS4 c = INCHAR1;
453n/a DBCHAR code;
454n/a unsigned char c1, c2;
455n/a
456n/a#ifdef STRICT_BUILD
457n/a JISX0201_R_ENCODE(c, code)
458n/a#else
459n/a if (c < 0x80)
460n/a code = c;
461n/a else if (c == 0x00a5)
462n/a code = 0x5c; /* YEN SIGN */
463n/a else if (c == 0x203e)
464n/a code = 0x7e; /* OVERLINE */
465n/a#endif
466n/a else JISX0201_K_ENCODE(c, code)
467n/a else if (c > 0xFFFF)
468n/a return 1;
469n/a else
470n/a code = NOCHAR;
471n/a
472n/a if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) {
473n/a REQUIRE_OUTBUF(1);
474n/a
475n/a OUTBYTE1((unsigned char)code);
476n/a NEXT(1, 1);
477n/a continue;
478n/a }
479n/a
480n/a REQUIRE_OUTBUF(2);
481n/a
482n/a if (code == NOCHAR) {
483n/a if (TRYMAP_ENC(jisxcommon, code, c))
484n/a ;
485n/a#ifndef STRICT_BUILD
486n/a else if (c == 0xff3c)
487n/a code = 0x2140; /* FULL-WIDTH REVERSE SOLIDUS */
488n/a#endif
489n/a else
490n/a return 1;
491n/a
492n/a if (code & 0x8000) /* MSB set: JIS X 0212 */
493n/a return 1;
494n/a }
495n/a
496n/a c1 = code >> 8;
497n/a c2 = code & 0xff;
498n/a c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21);
499n/a c1 = (c1 - 0x21) >> 1;
500n/a OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1);
501n/a OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41);
502n/a NEXT(1, 2);
503n/a }
504n/a
505n/a return 0;
506n/a}
507n/a
508n/aDECODER(shift_jis)
509n/a{
510n/a while (inleft > 0) {
511n/a unsigned char c = INBYTE1;
512n/a Py_UCS4 decoded;
513n/a
514n/a#ifdef STRICT_BUILD
515n/a JISX0201_R_DECODE(c, writer)
516n/a#else
517n/a if (c < 0x80)
518n/a OUTCHAR(c);
519n/a#endif
520n/a else JISX0201_K_DECODE(c, writer)
521n/a else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)){
522n/a unsigned char c1, c2;
523n/a
524n/a REQUIRE_INBUF(2);
525n/a c2 = INBYTE2;
526n/a if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc)
527n/a return 1;
528n/a
529n/a c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1);
530n/a c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41);
531n/a c1 = (2 * c1 + (c2 < 0x5e ? 0 : 1) + 0x21);
532n/a c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21;
533n/a
534n/a#ifndef STRICT_BUILD
535n/a if (c1 == 0x21 && c2 == 0x40) {
536n/a /* FULL-WIDTH REVERSE SOLIDUS */
537n/a OUTCHAR(0xff3c);
538n/a NEXT_IN(2);
539n/a continue;
540n/a }
541n/a#endif
542n/a if (TRYMAP_DEC(jisx0208, decoded, c1, c2)) {
543n/a OUTCHAR(decoded);
544n/a NEXT_IN(2);
545n/a continue;
546n/a }
547n/a else
548n/a return 1;
549n/a }
550n/a else
551n/a return 1;
552n/a
553n/a NEXT_IN(1); /* JIS X 0201 */
554n/a }
555n/a
556n/a return 0;
557n/a}
558n/a
559n/a
560n/a/*
561n/a * SHIFT_JIS-2004 codec
562n/a */
563n/a
564n/aENCODER(shift_jis_2004)
565n/a{
566n/a while (*inpos < inlen) {
567n/a Py_UCS4 c = INCHAR1;
568n/a DBCHAR code = NOCHAR;
569n/a int c1, c2;
570n/a Py_ssize_t insize;
571n/a
572n/a JISX0201_ENCODE(c, code)
573n/a
574n/a if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) {
575n/a WRITEBYTE1((unsigned char)code);
576n/a NEXT(1, 1);
577n/a continue;
578n/a }
579n/a
580n/a REQUIRE_OUTBUF(2);
581n/a insize = 1;
582n/a
583n/a if (code == NOCHAR) {
584n/a if (c <= 0xffff) {
585n/a EMULATE_JISX0213_2000_ENCODE_BMP(code, c)
586n/a else if (TRYMAP_ENC(jisx0213_bmp, code, c)) {
587n/a if (code == MULTIC) {
588n/a if (inlen - *inpos < 2) {
589n/a if (flags & MBENC_FLUSH) {
590n/a code = find_pairencmap
591n/a ((ucs2_t)c, 0,
592n/a jisx0213_pair_encmap,
593n/a JISX0213_ENCPAIRS);
594n/a if (code == DBCINV)
595n/a return 1;
596n/a }
597n/a else
598n/a return MBERR_TOOFEW;
599n/a }
600n/a else {
601n/a Py_UCS4 ch2 = INCHAR2;
602n/a code = find_pairencmap(
603n/a (ucs2_t)c, ch2,
604n/a jisx0213_pair_encmap,
605n/a JISX0213_ENCPAIRS);
606n/a if (code == DBCINV) {
607n/a code = find_pairencmap(
608n/a (ucs2_t)c, 0,
609n/a jisx0213_pair_encmap,
610n/a JISX0213_ENCPAIRS);
611n/a if (code == DBCINV)
612n/a return 1;
613n/a }
614n/a else
615n/a insize = 2;
616n/a }
617n/a }
618n/a }
619n/a else if (TRYMAP_ENC(jisxcommon, code, c)) {
620n/a /* abandon JIS X 0212 codes */
621n/a if (code & 0x8000)
622n/a return 1;
623n/a }
624n/a else
625n/a return 1;
626n/a }
627n/a else if (c >> 16 == EMPBASE >> 16) {
628n/a EMULATE_JISX0213_2000_ENCODE_EMP(code, c)
629n/a else if (TRYMAP_ENC(jisx0213_emp, code, c&0xffff))
630n/a ;
631n/a else
632n/a return insize;
633n/a }
634n/a else
635n/a return insize;
636n/a }
637n/a
638n/a c1 = code >> 8;
639n/a c2 = (code & 0xff) - 0x21;
640n/a
641n/a if (c1 & 0x80) {
642n/a /* Plane 2 */
643n/a if (c1 >= 0xee)
644n/a c1 -= 0x87;
645n/a else if (c1 >= 0xac || c1 == 0xa8)
646n/a c1 -= 0x49;
647n/a else
648n/a c1 -= 0x43;
649n/a }
650n/a else {
651n/a /* Plane 1 */
652n/a c1 -= 0x21;
653n/a }
654n/a
655n/a if (c1 & 1)
656n/a c2 += 0x5e;
657n/a c1 >>= 1;
658n/a OUTBYTE1(c1 + (c1 < 0x1f ? 0x81 : 0xc1));
659n/a OUTBYTE2(c2 + (c2 < 0x3f ? 0x40 : 0x41));
660n/a
661n/a NEXT(insize, 2);
662n/a }
663n/a
664n/a return 0;
665n/a}
666n/a
667n/aDECODER(shift_jis_2004)
668n/a{
669n/a while (inleft > 0) {
670n/a unsigned char c = INBYTE1;
671n/a
672n/a JISX0201_DECODE(c, writer)
673n/a else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)){
674n/a unsigned char c1, c2;
675n/a Py_UCS4 code, decoded;
676n/a
677n/a REQUIRE_INBUF(2);
678n/a c2 = INBYTE2;
679n/a if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc)
680n/a return 1;
681n/a
682n/a c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1);
683n/a c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41);
684n/a c1 = (2 * c1 + (c2 < 0x5e ? 0 : 1));
685n/a c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21;
686n/a
687n/a if (c1 < 0x5e) { /* Plane 1 */
688n/a c1 += 0x21;
689n/a EMULATE_JISX0213_2000_DECODE_PLANE1(writer,
690n/a c1, c2)
691n/a else if (TRYMAP_DEC(jisx0208, decoded, c1, c2))
692n/a OUTCHAR(decoded);
693n/a else if (TRYMAP_DEC(jisx0213_1_bmp, decoded, c1, c2))
694n/a OUTCHAR(decoded);
695n/a else if (TRYMAP_DEC(jisx0213_1_emp, code, c1, c2))
696n/a OUTCHAR(EMPBASE | code);
697n/a else if (TRYMAP_DEC(jisx0213_pair, code, c1, c2))
698n/a OUTCHAR2(code >> 16, code & 0xffff);
699n/a else
700n/a return 1;
701n/a NEXT_IN(2);
702n/a }
703n/a else { /* Plane 2 */
704n/a if (c1 >= 0x67)
705n/a c1 += 0x07;
706n/a else if (c1 >= 0x63 || c1 == 0x5f)
707n/a c1 -= 0x37;
708n/a else
709n/a c1 -= 0x3d;
710n/a
711n/a EMULATE_JISX0213_2000_DECODE_PLANE2(writer,
712n/a c1, c2)
713n/a else if (TRYMAP_DEC(jisx0213_2_bmp, decoded, c1, c2))
714n/a OUTCHAR(decoded);
715n/a else if (TRYMAP_DEC(jisx0213_2_emp, code, c1, c2)) {
716n/a OUTCHAR(EMPBASE | code);
717n/a NEXT_IN(2);
718n/a continue;
719n/a }
720n/a else
721n/a return 1;
722n/a NEXT_IN(2);
723n/a }
724n/a continue;
725n/a }
726n/a else
727n/a return 1;
728n/a
729n/a NEXT_IN(1); /* JIS X 0201 */
730n/a }
731n/a
732n/a return 0;
733n/a}
734n/a
735n/a
736n/aBEGIN_MAPPINGS_LIST
737n/a MAPPING_DECONLY(jisx0208)
738n/a MAPPING_DECONLY(jisx0212)
739n/a MAPPING_ENCONLY(jisxcommon)
740n/a MAPPING_DECONLY(jisx0213_1_bmp)
741n/a MAPPING_DECONLY(jisx0213_2_bmp)
742n/a MAPPING_ENCONLY(jisx0213_bmp)
743n/a MAPPING_DECONLY(jisx0213_1_emp)
744n/a MAPPING_DECONLY(jisx0213_2_emp)
745n/a MAPPING_ENCONLY(jisx0213_emp)
746n/a MAPPING_ENCDEC(jisx0213_pair)
747n/a MAPPING_ENCDEC(cp932ext)
748n/aEND_MAPPINGS_LIST
749n/a
750n/aBEGIN_CODECS_LIST
751n/a CODEC_STATELESS(shift_jis)
752n/a CODEC_STATELESS(cp932)
753n/a CODEC_STATELESS(euc_jp)
754n/a CODEC_STATELESS(shift_jis_2004)
755n/a CODEC_STATELESS(euc_jis_2004)
756n/a { "euc_jisx0213", (void *)2000, NULL, _STATELESS_METHODS(euc_jis_2004) },
757n/a { "shift_jisx0213", (void *)2000, NULL, _STATELESS_METHODS(shift_jis_2004) },
758n/aEND_CODECS_LIST
759n/a
760n/aI_AM_A_MODULE_FOR(jp)