10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24420Sstevel * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
27*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
29*6812Sraf #include "lint.h"
30*6812Sraf #include <euc.h>
31*6812Sraf #include <ctype.h>
320Sstevel@tonic-gate
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate * euccol(s) returns the screen column width of the EUC char.
350Sstevel@tonic-gate */
360Sstevel@tonic-gate int
euccol(const unsigned char * s)370Sstevel@tonic-gate euccol(const unsigned char *s)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate
400Sstevel@tonic-gate if (ISASCII(*s))
410Sstevel@tonic-gate return (1);
420Sstevel@tonic-gate else
430Sstevel@tonic-gate switch (*s) {
440Sstevel@tonic-gate case SS2:
450Sstevel@tonic-gate return (scrw2);
460Sstevel@tonic-gate case SS3:
470Sstevel@tonic-gate return (scrw3);
480Sstevel@tonic-gate default: /* code set 1 */
490Sstevel@tonic-gate return (scrw1);
500Sstevel@tonic-gate }
510Sstevel@tonic-gate }
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * euclen(s,n) returns the code width of the EUC char.
550Sstevel@tonic-gate * May also be implemented as a macro.
560Sstevel@tonic-gate */
570Sstevel@tonic-gate int
euclen(const unsigned char * s)580Sstevel@tonic-gate euclen(const unsigned char *s)
590Sstevel@tonic-gate {
600Sstevel@tonic-gate
610Sstevel@tonic-gate if (ISASCII(*s))
620Sstevel@tonic-gate return (1);
630Sstevel@tonic-gate else
640Sstevel@tonic-gate switch (*s) {
650Sstevel@tonic-gate case SS2:
660Sstevel@tonic-gate return (eucw2 + 1); /* include SS2 */
670Sstevel@tonic-gate case SS3:
680Sstevel@tonic-gate return (eucw3 + 1); /* include SS3 */
690Sstevel@tonic-gate default: /* code set 1 */
700Sstevel@tonic-gate return (eucw1);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
740Sstevel@tonic-gate /* this function will return the number of display column for a */
750Sstevel@tonic-gate /* given euc string. */
760Sstevel@tonic-gate int
eucscol(const unsigned char * s)770Sstevel@tonic-gate eucscol(const unsigned char *s)
780Sstevel@tonic-gate
790Sstevel@tonic-gate {
800Sstevel@tonic-gate int col = 0;
810Sstevel@tonic-gate
820Sstevel@tonic-gate while (*s) { /* end if euc char is a NULL character */
830Sstevel@tonic-gate if (ISASCII(*s)) {
840Sstevel@tonic-gate col += 1;
850Sstevel@tonic-gate s++;
860Sstevel@tonic-gate }
870Sstevel@tonic-gate else
880Sstevel@tonic-gate switch (*s) {
890Sstevel@tonic-gate case SS2:
900Sstevel@tonic-gate col += scrw2;
910Sstevel@tonic-gate s += (eucw2 +1);
920Sstevel@tonic-gate break;
930Sstevel@tonic-gate case SS3:
940Sstevel@tonic-gate col += scrw3;
950Sstevel@tonic-gate s += (eucw3 +1);
960Sstevel@tonic-gate break;
970Sstevel@tonic-gate default: /* code set 1 */
980Sstevel@tonic-gate col += scrw1;
990Sstevel@tonic-gate s += eucw1;
1000Sstevel@tonic-gate break;
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate return (col);
1050Sstevel@tonic-gate }
106