1 7c478bd9Sstevel@tonic-gate /* 2 7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3 7c478bd9Sstevel@tonic-gate * 4 7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5 *7257d1b4Sraf * Common Development and Distribution License (the "License"). 6 *7257d1b4Sraf * You may not use this file except in compliance with the License. 7 7c478bd9Sstevel@tonic-gate * 8 7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 10 7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 11 7c478bd9Sstevel@tonic-gate * and limitations under the License. 12 7c478bd9Sstevel@tonic-gate * 13 7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 14 7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 16 7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 17 7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 18 7c478bd9Sstevel@tonic-gate * 19 7c478bd9Sstevel@tonic-gate * CDDL HEADER END 20 7c478bd9Sstevel@tonic-gate */ 21 *7257d1b4Sraf 22 7c478bd9Sstevel@tonic-gate /* 23 *7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 a0b85df4Sstevel * Use is subject to license terms. 25 7c478bd9Sstevel@tonic-gate */ 26 7c478bd9Sstevel@tonic-gate 27 *7257d1b4Sraf #pragma ident "%Z%%M% %I% %E% SMI" 28 7c478bd9Sstevel@tonic-gate 29 *7257d1b4Sraf #include "lint.h" 30 7c478bd9Sstevel@tonic-gate #include <euc.h> 31 7c478bd9Sstevel@tonic-gate #include <ctype.h> 32 7c478bd9Sstevel@tonic-gate 33 7c478bd9Sstevel@tonic-gate /* 34 7c478bd9Sstevel@tonic-gate * euccol(s) returns the screen column width of the EUC char. 35 7c478bd9Sstevel@tonic-gate */ 36 7c478bd9Sstevel@tonic-gate int euccol(const unsigned char * s)37 7c478bd9Sstevel@tonic-gateeuccol(const unsigned char *s) 38 7c478bd9Sstevel@tonic-gate { 39 7c478bd9Sstevel@tonic-gate 40 7c478bd9Sstevel@tonic-gate if (ISASCII(*s)) 41 7c478bd9Sstevel@tonic-gate return (1); 42 7c478bd9Sstevel@tonic-gate else 43 7c478bd9Sstevel@tonic-gate switch (*s) { 44 7c478bd9Sstevel@tonic-gate case SS2: 45 7c478bd9Sstevel@tonic-gate return (scrw2); 46 7c478bd9Sstevel@tonic-gate case SS3: 47 7c478bd9Sstevel@tonic-gate return (scrw3); 48 7c478bd9Sstevel@tonic-gate default: /* code set 1 */ 49 7c478bd9Sstevel@tonic-gate return (scrw1); 50 7c478bd9Sstevel@tonic-gate } 51 7c478bd9Sstevel@tonic-gate } 52 7c478bd9Sstevel@tonic-gate 53 7c478bd9Sstevel@tonic-gate /* 54 7c478bd9Sstevel@tonic-gate * euclen(s,n) returns the code width of the EUC char. 55 7c478bd9Sstevel@tonic-gate * May also be implemented as a macro. 56 7c478bd9Sstevel@tonic-gate */ 57 7c478bd9Sstevel@tonic-gate int euclen(const unsigned char * s)58 7c478bd9Sstevel@tonic-gateeuclen(const unsigned char *s) 59 7c478bd9Sstevel@tonic-gate { 60 7c478bd9Sstevel@tonic-gate 61 7c478bd9Sstevel@tonic-gate if (ISASCII(*s)) 62 7c478bd9Sstevel@tonic-gate return (1); 63 7c478bd9Sstevel@tonic-gate else 64 7c478bd9Sstevel@tonic-gate switch (*s) { 65 7c478bd9Sstevel@tonic-gate case SS2: 66 7c478bd9Sstevel@tonic-gate return (eucw2 + 1); /* include SS2 */ 67 7c478bd9Sstevel@tonic-gate case SS3: 68 7c478bd9Sstevel@tonic-gate return (eucw3 + 1); /* include SS3 */ 69 7c478bd9Sstevel@tonic-gate default: /* code set 1 */ 70 7c478bd9Sstevel@tonic-gate return (eucw1); 71 7c478bd9Sstevel@tonic-gate } 72 7c478bd9Sstevel@tonic-gate } 73 7c478bd9Sstevel@tonic-gate 74 7c478bd9Sstevel@tonic-gate /* this function will return the number of display column for a */ 75 7c478bd9Sstevel@tonic-gate /* given euc string. */ 76 7c478bd9Sstevel@tonic-gate int eucscol(const unsigned char * s)77 7c478bd9Sstevel@tonic-gateeucscol(const unsigned char *s) 78 7c478bd9Sstevel@tonic-gate 79 7c478bd9Sstevel@tonic-gate { 80 7c478bd9Sstevel@tonic-gate int col = 0; 81 7c478bd9Sstevel@tonic-gate 82 7c478bd9Sstevel@tonic-gate while (*s) { /* end if euc char is a NULL character */ 83 7c478bd9Sstevel@tonic-gate if (ISASCII(*s)) { 84 7c478bd9Sstevel@tonic-gate col += 1; 85 7c478bd9Sstevel@tonic-gate s++; 86 7c478bd9Sstevel@tonic-gate } 87 7c478bd9Sstevel@tonic-gate else 88 7c478bd9Sstevel@tonic-gate switch (*s) { 89 7c478bd9Sstevel@tonic-gate case SS2: 90 7c478bd9Sstevel@tonic-gate col += scrw2; 91 7c478bd9Sstevel@tonic-gate s += (eucw2 +1); 92 7c478bd9Sstevel@tonic-gate break; 93 7c478bd9Sstevel@tonic-gate case SS3: 94 7c478bd9Sstevel@tonic-gate col += scrw3; 95 7c478bd9Sstevel@tonic-gate s += (eucw3 +1); 96 7c478bd9Sstevel@tonic-gate break; 97 7c478bd9Sstevel@tonic-gate default: /* code set 1 */ 98 7c478bd9Sstevel@tonic-gate col += scrw1; 99 7c478bd9Sstevel@tonic-gate s += eucw1; 100 7c478bd9Sstevel@tonic-gate break; 101 7c478bd9Sstevel@tonic-gate } 102 7c478bd9Sstevel@tonic-gate 103 7c478bd9Sstevel@tonic-gate } 104 7c478bd9Sstevel@tonic-gate return (col); 105 7c478bd9Sstevel@tonic-gate } 106