xref: /titanic_50/usr/src/cmd/geniconvtbl/samples/eucJP_to_ISO-2022-JP.src (revision 936b7af69172dce89b577831f79c0e18d15e854b)
1
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// ident	"%Z%%M%	%I%	%E% SMI"
26
27//
28// eucJP to SJIS
29//
30
31
32#include <sys/errno.h>
33#define	SS2	0x008e
34#define	SS3	0x008f
35
36eucJP%SJIS {
37	operation init {
38		cs = 0;
39		offset = 0;
40	};
41
42	direction {
43
44		condition {
45			cs == 2;
46		} operation {
47			output = input[0];
48			cs = 0;
49			discard;
50		};
51
52		condition {
53			cs == 1;
54		} operation {
55			var_input = input[0] & 0x7f;
56			var_input = var_input + offset;
57			if (var_input >= 0x7f) {
58				var_input = var_input + 0x01;
59			}
60			output = var_input;
61			cs = 0;
62			discard;
63		};
64
65		condition {
66			between 0x00 ... 0x7f ;
67		} operation {
68			if ( outputsize < 1 ) {
69				error E2BIG;
70			}
71			output = input[0];
72			discard;
73		};
74
75		condition {
76			between SS2 ... SS2 ;
77		} operation {
78			// Note this, in the .c file check is made
79			// against ileft > 0 ,  but it's since the
80			// ileft is already decremented.
81
82			if ( inputsize > 1 ) {
83				if ( ( input[1] >= 0xa1 ) && ( input[1] <= 0xfe )) {
84					if (outputsize < 1 ) {
85						error E2BIG;
86					}
87					cs = 2;
88				} else {
89					error EILSEQ;
90				}
91			} else {
92				error EINVAL;
93			}
94		};
95
96		condition {
97			between 0xa1 ... 0xfe;
98		} operation {
99			if ( inputsize > 1 ) {
100				if ( ( input[1]   >= 0xa1 ) && (  input[1]  <= 0xfe)) {
101					if ( outputsize < 2 ) {
102						error E2BIG;
103					}
104
105					cs = 1;
106					var_input = input[0] & 0x7f;
107					if ( var_input & 0x01) {
108						offset = 0x1f;
109					} else {
110						offset = 0x7d;
111					}
112					var_input = ((var_input - 0x21 ) >> 1) + 0x81;
113					if ( var_input > 0x9f ) {
114						var_input = var_input + 0x40;
115					}
116					output = var_input;
117					discard;
118
119				} else {
120					error EINVAL;
121				}
122			} else {
123				error EILSEQ;
124			}
125		};
126
127		true operation {
128			error EILSEQ;
129		};
130	};
131
132}
133