xref: /titanic_52/usr/src/cmd/geniconvtbl/samples/ISO-2022-JP_to_eucJP.src (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
1// ident	"%Z%%M%	%I%	%E% SMI"
2// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3// Use is subject to license terms.
4//
5// CDDL HEADER START
6//
7// The contents of this file are subject to the terms of the
8// Common Development and Distribution License, Version 1.0 only
9// (the "License").  You may not use this file except in compliance
10// with the License.
11//
12// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13// or http://www.opensolaris.org/os/licensing.
14// See the License for the specific language governing permissions
15// and limitations under the License.
16//
17// When distributing Covered Code, include this CDDL HEADER in each
18// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19// If applicable, add the following below this CDDL HEADER, with the
20// fields enclosed by brackets "[]" replaced with your own identifying
21// information: Portions Copyright [yyyy] [name of copyright owner]
22//
23// CDDL HEADER END
24//
25
26//
27// ISO-2022-JP to eucJP
28//
29
30#include <sys/errno.h>
31
32ISO-2022-JP%eucJP {
33	operation init {
34		cs = 0;
35	};
36
37	operation reset {
38		if (cs != 0) {
39			// Emit state reset sequence, ESC ( J, for
40			// ISO-2022-JP.
41			output = 0x1b284a;
42		}
43		operation init;
44	};
45
46	direction {
47		condition {		// JIS X 0201 Latin (ASCII)
48			between	0x00...0x7f;
49		} operation {
50			if (cs != 0) {
51				// We will emit four bytes.
52				if (outputsize <= 3) {
53					error E2BIG;
54				}
55				// Emit state reset sequence, ESC ( J.
56				output = 0x1b284a;
57				cs = 0;
58			} else {
59				if (outputsize <= 0) {
60					error E2BIG;
61				}
62			}
63			output = input[0];
64
65			// Move input buffer pointer one byte.
66			discard;
67		};
68
69		condition {		// JIS X 0208
70			between	0xa1a1...0xfefe;
71		} operation {
72			if (cs != 1) {
73				if (outputsize <= 4) {
74					error E2BIG;
75				}
76				// Emit JIS X 0208 sequence, ESC $ B.
77				output = 0x1b2442;
78				cs = 1;
79			} else {
80				if (outputsize <= 1) {
81					error E2BIG;
82				}
83			}
84			output = (input[0] & 0x7f);
85			output = (input[1] & 0x7f);
86
87			// Move input buffer pointer two bytes.
88			discard 2;
89		};
90
91		condition {		// JIS X 0201 Kana
92			between	0x8ea1...0x8edf;
93		} operation {
94			if (cs != 2) {
95				if (outputsize <= 3) {
96					error E2BIG;
97				}
98				// Emit JIS X 0201 Kana sequence,
99				// ESC ( I.
100				output = 0x1b2849;
101				cs = 2;
102			} else {
103				if (outputsize <= 0) {
104					error E2BIG;
105				}
106			}
107			output = (input[1] & 127);
108
109			// Move input buffer pointer two bytes.
110			discard 2;
111		};
112
113		condition {		// JIS X 0212
114			between	0x8fa1a1...0x8ffefe;
115		} operation {
116			if (cs != 3) {
117				if (outputsize <= 5) {
118					error E2BIG;
119				}
120				// Emit JIS X 0212 sequence, ESC $ ( D.
121				output = 0x1b242844;
122				cs = 3;
123			} else {
124				if (outputsize <= 1) {
125					error E2BIG;
126				}
127			}
128			output = (input[1] & 127);
129			output = (input[2] & 127);
130			discard 3;
131		};
132
133		true	operation {	// error
134			error EILSEQ;
135		};
136	};
137}
138