1/*	$NetBSD: multibyte.h,v 1.7 2011/11/23 15:43:39 tnozaki Exp $ */
2
3#ifndef MULTIBYTE_H
4#define MULTIBYTE_H
5
6/*
7 * Ex/vi commands are generally separated by whitespace characters.  We
8 * can't use the standard isspace(3) macro because it returns true for
9 * characters like ^K in the ASCII character set.  The 4.4BSD isblank(3)
10 * macro does exactly what we want, but it's not portable yet.
11 *
12 * XXX
13 * Note side effect, ch is evaluated multiple times.
14 */
15#define ISBLANK(c)	((c) == ' ' || (c) == '\t')
16
17#define ISDIGIT(c)	((c) >= '0' && (c) <= '9')
18#define ISXDIGIT(c)	(ISDIGIT(c) || \
19			 ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
20#define ISALPHA(c)	(((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
21#define ISALNUM(c)	(ISALPHA(c) || ISDIGIT(c))
22
23/*
24 * Fundamental character types.
25 *
26 * CHAR_T       An integral type that can hold any character.
27 * ARG_CHAR_T   The type of a CHAR_T when passed as an argument using
28 *              traditional promotion rules.  It should also be able
29 *              to be compared against any CHAR_T for equality without
30 *              problems.
31 *
32 * If no integral type can hold a character, don't even try the port.
33 */
34
35#ifdef USE_WIDECHAR
36#include <wchar.h>
37#include <wctype.h>
38
39typedef wchar_t		RCHAR_T;
40#define REOF		WEOF
41typedef wchar_t		CHAR_T;
42typedef	wint_t		ARG_CHAR_T;
43typedef wint_t		UCHAR_T;
44
45#define STRLEN		wcslen
46#define STRTOL		wcstol
47#define STRTOUL		wcstoul
48#define SPRINTF		swprintf
49#define STRCMP		wcscmp
50#define STRPBRK		wcspbrk
51#define ISBLANK2	iswblank
52#define ISCNTRL		iswcntrl
53#define ISGRAPH		iswgraph
54#define ISLOWER		iswlower
55#define ISPUNCT		iswpunct
56#define ISSPACE		iswspace
57#define ISUPPER		iswupper
58#define TOLOWER		towlower
59#define TOUPPER		towupper
60#define STRSET		wmemset
61#define STRCHR		wcschr
62
63#define L(ch)		L ## ch
64#define WS		"%ls"
65#define WVS		"%*ls"
66#define WC		"%lc"
67
68#else
69#include <stdio.h>
70
71typedef	char		RCHAR_T;
72#define REOF		EOF
73typedef	char		CHAR_T;
74typedef	int		ARG_CHAR_T;
75typedef	unsigned char	UCHAR_T;
76
77#define STRLEN		strlen
78#define STRTOL		strtol
79#define STRTOUL		strtoul
80#define SPRINTF		snprintf
81#define STRCMP		strcmp
82#define STRPBRK		strpbrk
83#define ISBLANK2	isblank
84#define ISCNTRL		iscntrl
85#define ISGRAPH		isgraph
86#define ISLOWER		islower
87#define ISPUNCT		ispunct
88#define ISSPACE		isspace
89#define ISUPPER		isupper
90#define TOLOWER		tolower
91#define TOUPPER		toupper
92#define STRSET		memset
93#define STRCHR		strchr
94
95#define L(ch)		ch
96#define WS		"%s"
97#define WVS		"%*s"
98#define WC		"%c"
99
100#endif
101
102#define MEMCMP(to, from, n) 						    \
103	memcmp(to, from, (n) * sizeof(*(to)))
104#define	MEMMOVE(p, t, len)	memmove(p, t, (len) * sizeof(*(p)))
105#define	MEMCPY(p, t, len)	memcpy(p, t, (len) * sizeof(*(p)))
106#define SIZE(w)		(sizeof(w)/sizeof(*w))
107
108#endif
109