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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include <sys/types.h>
44 #include "_loc_path.h"
46 static int wdchkind_C(wchar_t);
47 static int (*wdchknd
)(wchar_t) = wdchkind_C
;
48 static int wdbindf_C(wchar_t, wchar_t, int);
49 static int (*wdbdg
)(wchar_t, wchar_t, int) = wdbindf_C
;
50 static wchar_t *wddelim_C(wchar_t, wchar_t, int);
51 static wchar_t *(*wddlm
)(wchar_t, wchar_t, int) = wddelim_C
;
52 static wchar_t (*mcfllr
)(void) = NULL
;
53 static int (*mcwrp
)(void) = NULL
;
54 static void *modhandle
= NULL
;
55 static int initialized
= 0;
60 #define _DFLTLOCPATH_LEN (sizeof (_DFLT_LOC_PATH) - 1)
61 #define _WDMODPATH_LEN (sizeof (_WDMOD_PATH) - 1)
62 char wdmodpath
[PATH_MAX
];
70 (void) dlclose(modhandle
);
72 curloc
= uselocale(NULL
);
73 loc
= current_locale(curloc
, LC_CTYPE
);
75 if (_DFLTLOCPATH_LEN
+ loclen
+ _WDMODPATH_LEN
>= sizeof (wdmodpath
)) {
76 /* pathname too long */
81 (void) strcpy(wdmodpath
, _DFLT_LOC_PATH
);
82 (void) strcpy(wdmodpath
+ _DFLTLOCPATH_LEN
, loc
);
83 (void) strcpy(wdmodpath
+ _DFLTLOCPATH_LEN
+ loclen
, _WDMOD_PATH
);
85 if ((modhandle
= dlopen(wdmodpath
, RTLD_LAZY
)) != NULL
) {
86 wdchknd
= (int(*)(wchar_t))dlsym(modhandle
, "_wdchkind_");
89 wdbdg
= (int(*)(wchar_t, wchar_t, int))dlsym(modhandle
,
93 wddlm
= (wchar_t *(*)(wchar_t, wchar_t, int))
94 dlsym(modhandle
, "_wddelim_");
97 mcfllr
= (wchar_t(*)(void))dlsym(modhandle
, "_mcfiller_");
98 mcwrp
= (int(*)(void))dlsym(modhandle
, "_mcwrap_");
99 return ((mcfllr
&& mcwrp
) ? 0 : -1);
103 wdchknd
= wdchkind_C
;
112 * wdinit() initializes other word-analyzing routines according to the
113 * current locale. Programmers are supposed to call this routine every
114 * time the locale for the LC_CTYPE category is changed. It returns 0
115 * when every initialization completes successfully, or -1 otherwise.
117 /* XXX: wdinit() is not exported from libc. Should it be? */
123 callout_lock_enter();
124 res
= _wdinitialize();
130 * wdchkind() returns a non-negative integral value unique to the kind
131 * of the character represented by given argument.
138 callout_lock_enter();
140 (void) _wdinitialize();
146 wdchkind_C(wchar_t wc
)
148 switch (wcsetno(wc
)) {
156 return (isascii(wc
) &&
157 (isalpha(wc
) || isdigit(wc
) || wc
== ' '));
163 * wdbindf() returns an integral value (0 - 7) indicating binding
164 * strength of two characters represented by the first two arguments.
165 * It returns -1 when either of the two character is not printable.
169 wdbindf(wchar_t wc1
, wchar_t wc2
, int type
)
173 callout_lock_enter();
175 (void) _wdinitialize();
176 if (!iswprint(wc1
) || !iswprint(wc2
)) {
180 i
= (*wdbdg
)(wc1
, wc2
, type
);
186 wdbindf_C(wchar_t wc1
, wchar_t wc2
, int type
)
188 if (csetlen(wc1
) > 1 && csetlen(wc2
) > 1)
194 * wddelim() returns a pointer to a null-terminated word delimiter
195 * string in wchar_t type that is thought most appropriate to join
196 * a text line ending with the first argument and a line beginning
197 * with the second argument, with. When either of the two character
198 * is not printable it returns a pointer to a null wide character.
202 wddelim(wchar_t wc1
, wchar_t wc2
, int type
)
206 callout_lock_enter();
208 (void) _wdinitialize();
209 if (!iswprint(wc1
) || !iswprint(wc2
)) {
211 return ((wchar_t *)L
"");
213 i
= (*wddlm
)(wc1
, wc2
, type
);
219 wddelim_C(wchar_t wc1
, wchar_t wc2
, int type
)
221 return ((wchar_t *)L
" ");
225 * mcfiller returns a printable ASCII character suggested for use in
226 * filling space resulted by a multicolumn character at the right margin.
233 callout_lock_enter();
235 (void) _wdinitialize();
237 fillerchar
= (*mcfllr
)();
239 fillerchar
= (wchar_t)'~';
240 if (iswprint(fillerchar
)) {
246 return ((wchar_t)'~');
250 * mcwrap returns an integral value indicating if a multicolumn character
251 * on the right margin should be wrapped around on a terminal screen.
253 /* XXX: mcwrap() is not exported from libc. Should it be? */
257 callout_lock_enter();
259 (void) _wdinitialize();
261 if ((*mcwrp
)() == 0) {