1*7c478bd9Sstevel@tonic-gate// ident "%Z%%M% %I% %E% SMI" 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 26*7c478bd9Sstevel@tonic-gate// 27*7c478bd9Sstevel@tonic-gate// ISO-2022-JP to eucJP 28*7c478bd9Sstevel@tonic-gate// 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate#include <sys/errno.h> 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gateISO-2022-JP%eucJP { 33*7c478bd9Sstevel@tonic-gate operation init { 34*7c478bd9Sstevel@tonic-gate cs = 0; 35*7c478bd9Sstevel@tonic-gate }; 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate operation reset { 38*7c478bd9Sstevel@tonic-gate if (cs != 0) { 39*7c478bd9Sstevel@tonic-gate // Emit state reset sequence, ESC ( J, for 40*7c478bd9Sstevel@tonic-gate // ISO-2022-JP. 41*7c478bd9Sstevel@tonic-gate output = 0x1b284a; 42*7c478bd9Sstevel@tonic-gate } 43*7c478bd9Sstevel@tonic-gate operation init; 44*7c478bd9Sstevel@tonic-gate }; 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate direction { 47*7c478bd9Sstevel@tonic-gate condition { // JIS X 0201 Latin (ASCII) 48*7c478bd9Sstevel@tonic-gate between 0x00...0x7f; 49*7c478bd9Sstevel@tonic-gate } operation { 50*7c478bd9Sstevel@tonic-gate if (cs != 0) { 51*7c478bd9Sstevel@tonic-gate // We will emit four bytes. 52*7c478bd9Sstevel@tonic-gate if (outputsize <= 3) { 53*7c478bd9Sstevel@tonic-gate error E2BIG; 54*7c478bd9Sstevel@tonic-gate } 55*7c478bd9Sstevel@tonic-gate // Emit state reset sequence, ESC ( J. 56*7c478bd9Sstevel@tonic-gate output = 0x1b284a; 57*7c478bd9Sstevel@tonic-gate cs = 0; 58*7c478bd9Sstevel@tonic-gate } else { 59*7c478bd9Sstevel@tonic-gate if (outputsize <= 0) { 60*7c478bd9Sstevel@tonic-gate error E2BIG; 61*7c478bd9Sstevel@tonic-gate } 62*7c478bd9Sstevel@tonic-gate } 63*7c478bd9Sstevel@tonic-gate output = input[0]; 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate // Move input buffer pointer one byte. 66*7c478bd9Sstevel@tonic-gate discard; 67*7c478bd9Sstevel@tonic-gate }; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate condition { // JIS X 0208 70*7c478bd9Sstevel@tonic-gate between 0xa1a1...0xfefe; 71*7c478bd9Sstevel@tonic-gate } operation { 72*7c478bd9Sstevel@tonic-gate if (cs != 1) { 73*7c478bd9Sstevel@tonic-gate if (outputsize <= 4) { 74*7c478bd9Sstevel@tonic-gate error E2BIG; 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate // Emit JIS X 0208 sequence, ESC $ B. 77*7c478bd9Sstevel@tonic-gate output = 0x1b2442; 78*7c478bd9Sstevel@tonic-gate cs = 1; 79*7c478bd9Sstevel@tonic-gate } else { 80*7c478bd9Sstevel@tonic-gate if (outputsize <= 1) { 81*7c478bd9Sstevel@tonic-gate error E2BIG; 82*7c478bd9Sstevel@tonic-gate } 83*7c478bd9Sstevel@tonic-gate } 84*7c478bd9Sstevel@tonic-gate output = (input[0] & 0x7f); 85*7c478bd9Sstevel@tonic-gate output = (input[1] & 0x7f); 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate // Move input buffer pointer two bytes. 88*7c478bd9Sstevel@tonic-gate discard 2; 89*7c478bd9Sstevel@tonic-gate }; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate condition { // JIS X 0201 Kana 92*7c478bd9Sstevel@tonic-gate between 0x8ea1...0x8edf; 93*7c478bd9Sstevel@tonic-gate } operation { 94*7c478bd9Sstevel@tonic-gate if (cs != 2) { 95*7c478bd9Sstevel@tonic-gate if (outputsize <= 3) { 96*7c478bd9Sstevel@tonic-gate error E2BIG; 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate // Emit JIS X 0201 Kana sequence, 99*7c478bd9Sstevel@tonic-gate // ESC ( I. 100*7c478bd9Sstevel@tonic-gate output = 0x1b2849; 101*7c478bd9Sstevel@tonic-gate cs = 2; 102*7c478bd9Sstevel@tonic-gate } else { 103*7c478bd9Sstevel@tonic-gate if (outputsize <= 0) { 104*7c478bd9Sstevel@tonic-gate error E2BIG; 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate output = (input[1] & 127); 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate // Move input buffer pointer two bytes. 110*7c478bd9Sstevel@tonic-gate discard 2; 111*7c478bd9Sstevel@tonic-gate }; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate condition { // JIS X 0212 114*7c478bd9Sstevel@tonic-gate between 0x8fa1a1...0x8ffefe; 115*7c478bd9Sstevel@tonic-gate } operation { 116*7c478bd9Sstevel@tonic-gate if (cs != 3) { 117*7c478bd9Sstevel@tonic-gate if (outputsize <= 5) { 118*7c478bd9Sstevel@tonic-gate error E2BIG; 119*7c478bd9Sstevel@tonic-gate } 120*7c478bd9Sstevel@tonic-gate // Emit JIS X 0212 sequence, ESC $ ( D. 121*7c478bd9Sstevel@tonic-gate output = 0x1b242844; 122*7c478bd9Sstevel@tonic-gate cs = 3; 123*7c478bd9Sstevel@tonic-gate } else { 124*7c478bd9Sstevel@tonic-gate if (outputsize <= 1) { 125*7c478bd9Sstevel@tonic-gate error E2BIG; 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate } 128*7c478bd9Sstevel@tonic-gate output = (input[1] & 127); 129*7c478bd9Sstevel@tonic-gate output = (input[2] & 127); 130*7c478bd9Sstevel@tonic-gate discard 3; 131*7c478bd9Sstevel@tonic-gate }; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate true operation { // error 134*7c478bd9Sstevel@tonic-gate error EILSEQ; 135*7c478bd9Sstevel@tonic-gate }; 136*7c478bd9Sstevel@tonic-gate }; 137*7c478bd9Sstevel@tonic-gate} 138