1*7c478bd9Sstevel@tonic-gate
2*7c478bd9Sstevel@tonic-gate// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate// Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate//
5*7c478bd9Sstevel@tonic-gate// CDDL HEADER START
6*7c478bd9Sstevel@tonic-gate//
7*7c478bd9Sstevel@tonic-gate// The contents of this file are subject to the terms of the
8*7c478bd9Sstevel@tonic-gate// Common Development and Distribution License, Version 1.0 only
9*7c478bd9Sstevel@tonic-gate// (the "License").  You may not use this file except in compliance
10*7c478bd9Sstevel@tonic-gate// with the License.
11*7c478bd9Sstevel@tonic-gate//
12*7c478bd9Sstevel@tonic-gate// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13*7c478bd9Sstevel@tonic-gate// or http://www.opensolaris.org/os/licensing.
14*7c478bd9Sstevel@tonic-gate// See the License for the specific language governing permissions
15*7c478bd9Sstevel@tonic-gate// and limitations under the License.
16*7c478bd9Sstevel@tonic-gate//
17*7c478bd9Sstevel@tonic-gate// When distributing Covered Code, include this CDDL HEADER in each
18*7c478bd9Sstevel@tonic-gate// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19*7c478bd9Sstevel@tonic-gate// If applicable, add the following below this CDDL HEADER, with the
20*7c478bd9Sstevel@tonic-gate// fields enclosed by brackets "[]" replaced with your own identifying
21*7c478bd9Sstevel@tonic-gate// information: Portions Copyright [yyyy] [name of copyright owner]
22*7c478bd9Sstevel@tonic-gate//
23*7c478bd9Sstevel@tonic-gate// CDDL HEADER END
24*7c478bd9Sstevel@tonic-gate//
25*7c478bd9Sstevel@tonic-gate// ident	"%Z%%M%	%I%	%E% SMI"
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate//
28*7c478bd9Sstevel@tonic-gate// eucJP to SJIS
29*7c478bd9Sstevel@tonic-gate//
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate#include <sys/errno.h>
33*7c478bd9Sstevel@tonic-gate#define	SS2	0x008e
34*7c478bd9Sstevel@tonic-gate#define	SS3	0x008f
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gateeucJP%SJIS {
37*7c478bd9Sstevel@tonic-gate	operation init {
38*7c478bd9Sstevel@tonic-gate		cs = 0;
39*7c478bd9Sstevel@tonic-gate		offset = 0;
40*7c478bd9Sstevel@tonic-gate	};
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate	direction {
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate		condition {
45*7c478bd9Sstevel@tonic-gate			cs == 2;
46*7c478bd9Sstevel@tonic-gate		} operation {
47*7c478bd9Sstevel@tonic-gate			output = input[0];
48*7c478bd9Sstevel@tonic-gate			cs = 0;
49*7c478bd9Sstevel@tonic-gate			discard;
50*7c478bd9Sstevel@tonic-gate		};
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate		condition {
53*7c478bd9Sstevel@tonic-gate			cs == 1;
54*7c478bd9Sstevel@tonic-gate		} operation {
55*7c478bd9Sstevel@tonic-gate			var_input = input[0] & 0x7f;
56*7c478bd9Sstevel@tonic-gate			var_input = var_input + offset;
57*7c478bd9Sstevel@tonic-gate			if (var_input >= 0x7f) {
58*7c478bd9Sstevel@tonic-gate				var_input = var_input + 0x01;
59*7c478bd9Sstevel@tonic-gate			}
60*7c478bd9Sstevel@tonic-gate			output = var_input;
61*7c478bd9Sstevel@tonic-gate			cs = 0;
62*7c478bd9Sstevel@tonic-gate			discard;
63*7c478bd9Sstevel@tonic-gate		};
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate		condition {
66*7c478bd9Sstevel@tonic-gate			between 0x00 ... 0x7f ;
67*7c478bd9Sstevel@tonic-gate		} operation {
68*7c478bd9Sstevel@tonic-gate			if ( outputsize < 1 ) {
69*7c478bd9Sstevel@tonic-gate				error E2BIG;
70*7c478bd9Sstevel@tonic-gate			}
71*7c478bd9Sstevel@tonic-gate			output = input[0];
72*7c478bd9Sstevel@tonic-gate			discard;
73*7c478bd9Sstevel@tonic-gate		};
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate		condition {
76*7c478bd9Sstevel@tonic-gate			between SS2 ... SS2 ;
77*7c478bd9Sstevel@tonic-gate		} operation {
78*7c478bd9Sstevel@tonic-gate			// Note this, in the .c file check is made
79*7c478bd9Sstevel@tonic-gate			// against ileft > 0 ,  but it's since the
80*7c478bd9Sstevel@tonic-gate			// ileft is already decremented.
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate			if ( inputsize > 1 ) {
83*7c478bd9Sstevel@tonic-gate				if ( ( input[1] >= 0xa1 ) && ( input[1] <= 0xfe )) {
84*7c478bd9Sstevel@tonic-gate					if (outputsize < 1 ) {
85*7c478bd9Sstevel@tonic-gate						error E2BIG;
86*7c478bd9Sstevel@tonic-gate					}
87*7c478bd9Sstevel@tonic-gate					cs = 2;
88*7c478bd9Sstevel@tonic-gate				} else {
89*7c478bd9Sstevel@tonic-gate					error EILSEQ;
90*7c478bd9Sstevel@tonic-gate				}
91*7c478bd9Sstevel@tonic-gate			} else {
92*7c478bd9Sstevel@tonic-gate				error EINVAL;
93*7c478bd9Sstevel@tonic-gate			}
94*7c478bd9Sstevel@tonic-gate		};
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate		condition {
97*7c478bd9Sstevel@tonic-gate			between 0xa1 ... 0xfe;
98*7c478bd9Sstevel@tonic-gate		} operation {
99*7c478bd9Sstevel@tonic-gate			if ( inputsize > 1 ) {
100*7c478bd9Sstevel@tonic-gate				if ( ( input[1]   >= 0xa1 ) && (  input[1]  <= 0xfe)) {
101*7c478bd9Sstevel@tonic-gate					if ( outputsize < 2 ) {
102*7c478bd9Sstevel@tonic-gate						error E2BIG;
103*7c478bd9Sstevel@tonic-gate					}
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate					cs = 1;
106*7c478bd9Sstevel@tonic-gate					var_input = input[0] & 0x7f;
107*7c478bd9Sstevel@tonic-gate					if ( var_input & 0x01) {
108*7c478bd9Sstevel@tonic-gate						offset = 0x1f;
109*7c478bd9Sstevel@tonic-gate					} else {
110*7c478bd9Sstevel@tonic-gate						offset = 0x7d;
111*7c478bd9Sstevel@tonic-gate					}
112*7c478bd9Sstevel@tonic-gate					var_input = ((var_input - 0x21 ) >> 1) + 0x81;
113*7c478bd9Sstevel@tonic-gate					if ( var_input > 0x9f ) {
114*7c478bd9Sstevel@tonic-gate						var_input = var_input + 0x40;
115*7c478bd9Sstevel@tonic-gate					}
116*7c478bd9Sstevel@tonic-gate					output = var_input;
117*7c478bd9Sstevel@tonic-gate					discard;
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate				} else {
120*7c478bd9Sstevel@tonic-gate					error EINVAL;
121*7c478bd9Sstevel@tonic-gate				}
122*7c478bd9Sstevel@tonic-gate			} else {
123*7c478bd9Sstevel@tonic-gate				error EILSEQ;
124*7c478bd9Sstevel@tonic-gate			}
125*7c478bd9Sstevel@tonic-gate		};
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate		true operation {
128*7c478bd9Sstevel@tonic-gate			error EILSEQ;
129*7c478bd9Sstevel@tonic-gate		};
130*7c478bd9Sstevel@tonic-gate	};
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate}
133