xref: /dragonfly/contrib/nvi2/common/multibyte.h (revision e98bdfd3)
1 /*-
2  * Copyright (c) 1992, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *	Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  *
9  *	$Id: multibyte.h,v 1.32 2012/10/07 01:35:58 zy Exp $
10  */
11 
12 #ifndef MULTIBYTE_H
13 #define MULTIBYTE_H
14 
15 /*
16  * Fundamental character types.
17  *
18  * CHAR_T	An integral type that can hold any character.
19  * ARG_CHAR_T	The type of a CHAR_T when passed as an argument using
20  *		traditional promotion rules.  It should also be able
21  *		to be compared against any CHAR_T for equality without
22  *		problems.
23  * UCHAR_T	The shortest unified character type (8-bit clean).
24  * RCHAR_T	The character type used by the internal regex engine.
25  *
26  * If no integral type can hold a character, don't even try the port.
27  */
28 typedef	int		ARG_CHAR_T;
29 
30 #ifdef USE_WIDECHAR
31 #include <wchar.h>
32 #include <wctype.h>
33 
34 typedef	wchar_t		CHAR_T;
35 typedef	wint_t		UCHAR_T;
36 typedef wchar_t 	RCHAR_T;
37 #define REOF		WEOF
38 
39 #define STRLEN		wcslen
40 #define STRTOL		wcstol
41 #define STRTOUL		wcstoul
42 #define SPRINTF		swprintf
43 #define STRCMP		wcscmp
44 #define STRPBRK		wcspbrk
45 #define ISBLANK		iswblank
46 #define ISCNTRL		iswcntrl
47 #define ISDIGIT		iswdigit
48 #define ISXDIGIT	iswxdigit
49 #define ISGRAPH		iswgraph
50 #define ISLOWER		iswlower
51 #define ISPRINT		iswprint
52 #define ISPUNCT		iswpunct
53 #define ISSPACE		iswspace
54 #define ISUPPER		iswupper
55 #define TOLOWER		towlower
56 #define TOUPPER		towupper
57 #define STRSET		wmemset
58 #define STRCHR		wcschr
59 #define STRRCHR		wcsrchr
60 #define GETC		getwc
61 
62 #define L(ch)		L ## ch
63 #define WS		"%ls"
64 #define WVS		"%*ls"
65 #define WC		"%lc"
66 
67 #else
68 typedef	u_char		CHAR_T;
69 typedef	u_char		UCHAR_T;
70 typedef	char		RCHAR_T;
71 #define REOF		EOF
72 
73 #define STRLEN		strlen
74 #define STRTOL(a,b,c)	(strtol(a,(char**)b,c))
75 #define STRTOUL(a,b,c)	(strtoul(a,(char**)b,c))
76 #define SPRINTF		snprintf
77 #define STRCMP		strcmp
78 #define STRPBRK		strpbrk
79 #define ISBLANK		isblank
80 #define ISCNTRL		iscntrl
81 #define ISDIGIT		isdigit
82 #define ISXDIGIT	isxdigit
83 #define ISGRAPH		isgraph
84 #define ISLOWER		islower
85 #define ISPRINT		isprint
86 #define ISPUNCT		ispunct
87 #define ISSPACE		isspace
88 #define ISUPPER		isupper
89 #define TOLOWER		tolower
90 #define TOUPPER		toupper
91 #define STRSET		memset
92 #define STRCHR		strchr
93 #define STRRCHR		strrchr
94 #define GETC		getc
95 
96 #define L(ch)		ch
97 #define WS		"%s"
98 #define WVS		"%*s"
99 #define WC		"%c"
100 
101 #endif
102 
103 #if defined(USE_WIDECHAR) && defined(DEBUG)
104 #define MEMCPY			wmemcpy
105 #define MEMMOVE			wmemmove
106 #define MEMCMP			wmemcmp
107 #else
108 #define MEMCPY(p, t, len)	memcpy(p, t, (len) * sizeof(CHAR_T))
109 #define MEMMOVE(p, t, len)	memmove(p, t, (len) * sizeof(CHAR_T))
110 #define MEMCMP(p, t, len)	memcmp(p, t, (len) * sizeof(CHAR_T))
111 #endif
112 
113 #define SIZE(w)			(sizeof(w) / sizeof(*w))
114 
115 #endif
116