xref: /titanic_52/usr/src/lib/libc/port/gen/euclen.c (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "lint.h"
30 #include <euc.h>
31 #include <ctype.h>
32 
33 /*
34  * euccol(s) returns the screen column width of the EUC char.
35  */
36 int
37 euccol(const unsigned char *s)
38 {
39 
40 	if (ISASCII(*s))
41 		return (1);
42 	else
43 		switch (*s) {
44 		case SS2:
45 			return (scrw2);
46 		case SS3:
47 			return (scrw3);
48 		default: /* code set 1 */
49 			return (scrw1);
50 		}
51 }
52 
53 /*
54  * euclen(s,n) returns the code width of the  EUC char.
55  * May also be implemented as a macro.
56  */
57 int
58 euclen(const unsigned char *s)
59 {
60 
61 	if (ISASCII(*s))
62 		return (1);
63 	else
64 		switch (*s) {
65 		case SS2:
66 			return (eucw2 + 1); /* include SS2 */
67 		case SS3:
68 			return (eucw3 + 1); /* include SS3 */
69 		default: /* code set 1 */
70 			return (eucw1);
71 		}
72 }
73 
74 /* this function will return the number of display column for a */
75 /* given euc string.						*/
76 int
77 eucscol(const unsigned char *s)
78 
79 {
80 	int	col = 0;
81 
82 	while (*s) { /* end if euc char is a NULL character */
83 		if (ISASCII(*s)) {
84 			col += 1;
85 			s++;
86 		}
87 		else
88 			switch (*s) {
89 			case SS2:
90 				col += scrw2;
91 				s += (eucw2 +1);
92 				break;
93 			case SS3:
94 				col += scrw3;
95 				s += (eucw3 +1);
96 				break;
97 			default:	/* code set 1 */
98 				col += scrw1;
99 				s += eucw1;
100 				break;
101 			}
102 
103 	}
104 	return (col);
105 }
106