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