xref: /titanic_44/usr/src/lib/libc/port/gen/euclen.c (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
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 1996 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"   /* Nihon Sun Micro JLE */
28 
29 #include	"synonyms.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