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