xref: /titanic_52/usr/src/lib/libxcurses/h/m_wchar.h (revision c7158ae983f5a04c4a998f468ecefba6d23ba721)
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) 1996, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * ISO/IEC 9899: 1990/Add.3: 1993 (E): Wide character header file
31  *
32  * Copyright 1992, 1993 by Mortice Kern Systems Inc.  All rights reserved.
33  *
34  * $Header: /rd/h/rcs/m_wchar.h 1.51 1995/09/20 19:17:54 ant Exp $
35  *
36  */
37 
38 #ifndef __M_M_WCHAR_H__
39 #define __M_M_WCHAR_H__ 1
40 
41 /*
42  * m_wchar.h:
43  *   configuration file for multi-byte vs. single byte enablement
44  */
45 
46 #include <wchar.h>
47 #include <wctype.h>
48 #include <limits.h>		/* Fetch MB_LEN_MAX */
49 
50 #ifdef M_I18N_LOCKING_SHIFT
51 extern char *m_strsanitize (char *);
52 #else
53 #define m_strsanitize(str)	(str)
54 #endif /* M_I18N_LOCKING_SHIFT */
55 
56 #ifdef	M_I18N_MB
57 
58 # ifndef MB_LEN_MAX
59 #  error M_I18N_MB defined; but the local system does not support multibyte
60 # endif /* MB_LEN_MAX */
61 
62 #define	MB_BEGIN	if (MB_CUR_MAX > 1) {
63 #define	MB_ELSE		} else {
64 #define	MB_END		}
65 
66 #define	M_MB_L(s)	L##s
67 
68 #ifndef _WUCHAR_T
69 #define _WUCHAR_T
70 /* a typedef to allow single byte distinction between char and uchar
71  * in MKS environment
72  */
73 typedef	wchar_t	wuchar_t;
74 #endif /*_WUCHAR_T*/
75 
76 extern wint_t	m_escapewc(wchar_t **);
77 extern int	m_fputmbs(FILE* fp, char *mbs, int wid, int prec, int ljust);
78 extern int	m_fgetws (wchar_t *, size_t, FILE *);
79 extern FILE	*m_fwopen (wchar_t *, char *);
80 extern	wchar_t	*m_wcsdup (const wchar_t *);
81 extern wchar_t	*m_mbstowcsdup (const char *s);
82 extern char	*m_wcstombsdup (const wchar_t *w);
83 extern char	*m_mbschr (const char *, int);
84 extern char	*m_mbsrchr (const char *, int);
85 extern char	*m_mbspbrk (const char *, const char *);
86 extern wchar_t	*m_wcsset (wchar_t *, wchar_t, size_t);
87 extern int	iswabsname (wchar_t *);
88 
89 #define m_smalls(s) (s)
90 #define wctomb_init() wctomb(NULL,0)
91 
92 #else	/* !M_I18N_MB */
93 
94 /* include <stdlib.h> here,
95  * We must include the multibyte function prototypes (in <stdlib.h>) before
96  * redefining the prototype function names below.
97  *
98  * AND including <stdlib.h> DOES NOT cause a problem with wchar_t.
99  *
100  * ANSI says that the typedef of wchar_t should be defined in stdlib.h.
101  * Thus, the prototypes in stdlib.h are declared using stdlib's definition
102  * of wchar_t.
103  */
104 
105 #include <stdlib.h> 	/* DO NOT MOVE THIS include - THIS must be first */
106 #undef	m_escapewc
107 #undef	m_fgetws
108 #undef	m_fwopen
109 #undef	m_wcsdup
110 #undef	m_mbstowcsdup
111 #undef	m_wcstombsdup
112 #undef	m_mbschr
113 #undef	m_mbsrchr
114 #undef	m_mbspbrk
115 #undef	m_wcsset
116 #undef	iswabsname
117 #undef	m_fputmbs
118 
119 #define	m_escapewc	m_escapec
120 #define	m_fgetws	m_fgets
121 #define	m_fwopen	fopen
122 #define	m_wcsdup	strdup
123 #define	m_mbstowcsdup	strdup
124 #define	m_wcstombsdup	strdup
125 #define	m_mbschr	strchr
126 #define	m_mbsrchr	strrchr
127 #define	m_mbspbrk	strpbrk
128 #define	m_wcsset	memset
129 #define	iswabsname(s)	isabsname(s)
130 
131 #define	m_fputmbs(fp, str, wid, prec, ljust) \
132 	fprintf((fp), (ljust) ? "%-*.*s" : "%*.*s", wid, prec, str)
133 
134 
135 #define	MB_BEGIN	if (0) {
136 #define	MB_ELSE		} else {
137 #define	MB_END		}
138 
139 #define	M_MB_L(s)	s
140 
141 /*
142  * Types and Macros
143  */
144 #undef WEOF
145 #undef wint_t
146 #undef wuchar_t
147 #undef wchar_t
148 
149 #define	WEOF	EOF
150 #define	wchar_t	char		/* ensures we never use the wchar_t typedef */
151 #define	wint_t	int		/* type as large as either wchar_t or WEOF */
152 #define	wuchar_t unsigned char 		/* Force override of typedef */
153 
154 /*
155  * Must define _WCHAR_T, _WINT_T and _WUCHAR_T to avoid typedefs collisions
156  * in other system headers.
157  * Most systems do something like this:
158  *    #ifndef _WCHAR_T
159  *      #define _WCHAR_T
160  *      typedef unsigned short wchar_t
161  *    #endif
162  * in their system headers to avoid multiple declarations of wchar_t
163  */
164 #undef _WCHAR_T
165 #undef _WINT_T
166 #undef _WUCHAR_T
167 #define _WCHAR_T
168 #define _WINT_T
169 #define _WUCHAR_T
170 
171 /*
172  * Input/Output
173  */
174 #undef	fgetwc
175 #undef	getwc
176 #undef	getwchar
177 #undef	fputwc
178 #undef	putwc
179 #undef	putwchar
180 #undef	fputws
181 #undef	puts
182 #undef	fgetwx
183 #undef	getws
184 #undef	ungetwc
185 #undef	fwprintf
186 #undef	fwscanf
187 #undef	wprintf
188 #undef	wscanf
189 #undef	swscanf
190 #undef	vfwprintf
191 #undef	vwprintf
192 #undef	vswprintf
193 
194 #define	fgetwc		fgetc
195 #define	getwc		getc
196 #define	getwchar	getchar
197 #define	fputwc		fputc
198 #define	putwc		putc
199 #define	putwchar	putchar
200 #define	fputws		fputs
201 #define	fgetws		fgets
202 #define	getws		gets
203 #define	ungetwc		ungetc
204 #define	fwprintf	fprintf
205 #define	fwscanf		fscanf
206 #define	wprintf		printf
207 #define	wscanf		scanf
208 #define	swscanf		sscanf
209 #define	vfwprintf	vfprintf
210 #define	vwprintf	vprintf
211 /* NOTE:
212  *  In single byte mode, both swprintf() and vswprintf() are converted to
213  *  similar, but NOT IDENTICAL, functions that have slightly different
214  *  semantics.
215  *  The 2nd argument to both these routines (e.g the size_t arg)
216  *  is not used in the singlebyte environment since sprintf() and vsprintf()
217  *  do not support this argument.
218  *  One has to be careful when using this routine to not depend on
219  *  the enforcement/safety of this 2nd argument.
220  *
221  *  swprintf() is converted to m_swprintf(), which is a C function
222  *  (because it can use  a variable number of args),
223  *  which is implemented as a call to vsprint()
224  *  vswprintf() is converted to vsprintf()
225  *
226  */
227 #define	swprintf		m_swprintf
228 #define	vswprintf(w,n,f,v)	vsprintf((char*)w,(const char*)f, v)
229 
230 #ifndef m_smalls
231 extern wchar_t *m_smalls (const wchar_t *);
232 #endif /*m_smalls*/
233 
234 /*
235  * General Utilities
236  */
237 #undef wcstod
238 #undef wcstol
239 #undef wcstoul
240 #undef wctomb_init
241 
242 #define	wcstod		strtod
243 #define	wcstol		strtol
244 #define	wcstoul		strtoul
245 #define wctomb_init()   (0)	 /* No state dependency for nonmultibyte. */
246 
247 /*
248  * Wide string handling
249  */
250 #undef	wcscpy
251 #undef	wcsncpy
252 #undef	wcscat
253 #undef	wcsncat
254 #undef	wcscoll
255 #undef	wcscmp
256 #undef	wcsncmp
257 #undef	wcsxfrm
258 #undef	wcschr
259 #undef	wcscspn
260 #undef	wcspbrk
261 #undef	wcsrchr
262 #undef	wcsspn
263 #undef	wcsstr
264 #undef	wcstok
265 #undef	wcslen
266 #undef	wcswidth
267 #undef	wcwidth
268 
269 #define	wcscpy		strcpy
270 #define	wcsncpy		strncpy
271 #define	wcscat		strcat
272 #define	wcsncat		strncat
273 #define	wcscoll		strcoll
274 #define	wcscmp		strcmp
275 #define	wcsncmp		strncmp
276 #define	wcsxfrm		strxfrm
277 #define	wcschr		strchr
278 #define	wcscspn		strcspn
279 #define	wcspbrk		strpbrk
280 #define	wcsrchr		strrchr
281 #define	wcsspn		strspn
282 #define	wcsstr		strstr
283 #define	wcstok(x, y, z)	strtok(x, y)
284 #define	wcslen		strlen
285 #define	wcswidth(s1, n)		strlen(s1)	/* Need a strnlen? */
286 #define	wcwidth(c)		1
287 
288 /*
289  * Date and time
290  */
291 #undef wcsftime
292 #define	wcsftime	strftime
293 
294 /*
295  * Extended Multibyte functions
296  */
297 
298 #undef wctob
299 #undef sisinit
300 
301 #define	wctob(c)		((int) (wint_t) (c))
302 #define	sisinit(p)		(1)	/* Always in initial state */
303 
304 /*
305  * Define prototypes for singlebyte equivalents of multibyte functions.
306  * We have to use macros to map them to other function names, so that
307  * they do not conflict with the prototypes from <stdlib.h> that may have
308  * used a different definition of wchar_t.  The restartable functions are
309  * mapped to their non-restartable counterparts, since there is no state
310  * information to be preserved.
311  */
312 
313 #undef mblen
314 #undef mbrlen
315 #undef mbtowc
316 #undef mbrtowc
317 #undef wctomb
318 #undef wcrtomb
319 #undef mbstowcs
320 #undef mbsrtowcs
321 #undef wcstombs
322 #undef wcsrtombs
323 
324 #define mblen(s, n)			m_sb_mblen(s, n)
325 #define mbrlen(s, n, ps)		m_sb_mblen(s, n)
326 #define mbtowc(pwc, s, n)		m_sb_mbtowc(pwc, s, n)
327 #define	mbrtowc(pwc, s, n, ps)		m_sb_mbtowc(pwc, s, n)
328 #define wctomb(s, wc)			m_sb_wctomb(s, wc)
329 #define	wcrtomb(s, wc, ps)		m_sb_wctomb(s, wc)
330 #define mbstowcs(pwcs, s, n)		m_sb_mbstowcs(pwcs, s, n)
331 #define mbsrtowcs(pwcs, s, n, ps)	m_sb_mbstowcs(pwcs, s, n)
332 #define wcstombs(s, pwcs, n)		m_sb_wcstombs(s, pwcs, n)
333 #define wcsrtombs(s, pwcs, n, ps)	m_sb_wcstombs(s, pwcs, n)
334 
335 extern int m_sb_mblen(const char *s, size_t n);
336 extern int m_sb_mbtowc(wchar_t *pwc, const char *s, size_t n);
337 extern int m_sb_wctomb(char *s, wchar_t wc);
338 extern size_t m_sb_mbstowcs(wchar_t *pwcs, const char *s, size_t n);
339 extern size_t m_sb_wcstombs(char *s, const wchar_t *pwcs, size_t n);
340 
341 /*
342  * convert definitions from <wctype.h>
343  */
344 #undef	iswalnum
345 #undef	iswalpha
346 #undef	iswcntrl
347 #undef	iswdigit
348 #undef	iswgraph
349 #undef	iswlower
350 #undef	iswprint
351 #undef	iswpunct
352 #undef	iswspace
353 #undef	iswupper
354 #undef	iswxdigit
355 #undef	iswblank
356 #undef	towlower
357 #undef	towupper
358 
359 #define	iswalnum(c)	isalnum(c)
360 #define	iswalpha(c)	isalpha(c)
361 #define	iswcntrl(c)	iscntrl(c)
362 #define	iswdigit(c)	isdigit(c)
363 #define	iswgraph(c)	isgraph(c)
364 #define	iswlower(c)	islower(c)
365 #define	iswprint(c)	isprint(c)
366 #define	iswpunct(c)	ispunct(c)
367 #define	iswspace(c)	isspace(c)
368 #define	iswupper(c)	isupper(c)
369 #define	iswxdigit(c)	isxdigit(c)
370 #define	iswblank(c)	isblank(c)
371 #define	towlower(c)	tolower(c)
372 #define	towupper(c)	toupper(c)
373 
374 /*
375  * Note: MKS libc/gen/iswctype.c contains the system independent version
376  *       of wctype() and iswctype().
377  *
378  * In single byte mode, we can't use the names wctype() and iswctype().
379  * These may have been defined in the system's headers (e.g <wctype.h>)
380  * using the system definition of wint_t and wctype_t.
381  * BUT we have just changed the meaning of wint_t above, to an 'int'
382  * which may not be the same size as wint_t.
383  * Thus, we rename them so that we don't get any prototype conflicts
384  */
385 #undef wctype
386 #undef iswctype
387 #define wctype _m_wctype
388 #define iswctype _m_iswctype
389 
390 extern wctype_t wctype(const char *property);
391 extern int iswctype(wint_t wc, wctype_t desc);
392 
393 
394 /*
395  * .2 Functions
396  */
397 #include <fnmatch.h>
398 #undef fnwwmatch
399 #undef fnwnmatch
400 #define	fnwwmatch	fnmatch
401 #define	fnwnmatch	fnmatch
402 
403 #include <regex.h>
404 #undef regwcomp
405 #undef regwexec
406 #undef regwdosub
407 #undef regwdosuba
408 #undef regwmatch_t
409 
410 #define regwcomp	regcomp
411 #define regwexec	regexec
412 #define regwdosub	regdosub
413 #define regwdosuba	regdosuba
414 #define regwmatch_t	regmatch_t
415 
416 #endif	/* M_I18N_MB */
417 
418 /*
419  * prototypes that are common to both SingleByte and MultiByte
420  */
421 extern int	m_mbswidth (const char *, size_t);
422 extern int	m_mbsrwidth (const char *, size_t, mbstate_t *);
423 
424 
425 #endif /*__M_M_WCHAR_H__*/
426