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