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