2011-03-21 17:53:02 +03:00
|
|
|
/* $NetBSD: multibyte.h,v 1.6 2011/03/21 14:53:02 tnozaki Exp $ */
|
2008-05-18 18:29:31 +04:00
|
|
|
|
2008-05-16 22:03:01 +04:00
|
|
|
#ifndef MULTIBYTE_H
|
|
|
|
#define MULTIBYTE_H
|
|
|
|
|
2011-03-21 17:53:02 +03:00
|
|
|
/*
|
|
|
|
* Ex/vi commands are generally separated by whitespace characters. We
|
|
|
|
* can't use the standard isspace(3) macro because it returns true for
|
|
|
|
* characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
|
|
|
|
* macro does exactly what we want, but it's not portable yet.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Note side effect, ch is evaluated multiple times.
|
|
|
|
*/
|
|
|
|
#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
|
|
|
|
|
|
|
#define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
|
|
|
|
#define ISXDIGIT(c) (ISDIGIT(c) || \
|
|
|
|
((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
|
|
|
|
#define ISALPHA(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
|
|
|
|
#define ISALNUM(c) (ISALPHA(c) || ISDIGIT(c))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fundamental character types.
|
|
|
|
*
|
|
|
|
* CHAR_T An integral type that can hold any character.
|
|
|
|
* ARG_CHAR_T The type of a CHAR_T when passed as an argument using
|
|
|
|
* traditional promotion rules. It should also be able
|
|
|
|
* to be compared against any CHAR_T for equality without
|
|
|
|
* problems.
|
|
|
|
*
|
|
|
|
* If no integral type can hold a character, don't even try the port.
|
|
|
|
*/
|
|
|
|
|
2008-05-16 22:03:01 +04:00
|
|
|
#ifdef USE_WIDECHAR
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <wctype.h>
|
|
|
|
|
2009-01-02 03:32:11 +03:00
|
|
|
typedef wchar_t RCHAR_T;
|
|
|
|
typedef wchar_t CHAR_T;
|
2011-03-21 17:53:02 +03:00
|
|
|
typedef wint_t ARG_CHAR_T;
|
|
|
|
typedef wint_t UCHAR_T;
|
2008-05-16 22:03:01 +04:00
|
|
|
|
|
|
|
#define STRLEN wcslen
|
|
|
|
#define STRTOL wcstol
|
|
|
|
#define STRTOUL wcstoul
|
|
|
|
#define SPRINTF swprintf
|
|
|
|
#define STRCMP wcscmp
|
|
|
|
#define STRPBRK wcspbrk
|
2011-03-21 17:53:02 +03:00
|
|
|
#define ISBLANK2 iswblank
|
|
|
|
#define ISCNTRL iswcntrl
|
|
|
|
#define ISGRAPH iswgraph
|
2009-12-23 15:44:21 +03:00
|
|
|
#define ISLOWER iswlower
|
2011-03-21 17:53:02 +03:00
|
|
|
#define ISPUNCT iswpunct
|
|
|
|
#define ISSPACE iswspace
|
|
|
|
#define ISUPPER iswupper
|
|
|
|
#define TOLOWER towlower
|
|
|
|
#define TOUPPER towupper
|
2008-05-16 22:03:01 +04:00
|
|
|
#define STRSET wmemset
|
2009-08-12 01:28:02 +04:00
|
|
|
#define STRCHR wcschr
|
2008-05-16 22:03:01 +04:00
|
|
|
|
|
|
|
#define L(ch) L ## ch
|
2011-03-21 17:53:02 +03:00
|
|
|
#define WS "%ls"
|
|
|
|
#define WVS "%*ls"
|
|
|
|
#define WC "%lc"
|
2008-05-16 22:03:01 +04:00
|
|
|
|
|
|
|
#else
|
|
|
|
typedef char RCHAR_T;
|
2011-03-21 17:53:02 +03:00
|
|
|
typedef char CHAR_T;
|
|
|
|
typedef int ARG_CHAR_T;
|
|
|
|
typedef unsigned char UCHAR_T;
|
2008-05-16 22:03:01 +04:00
|
|
|
|
|
|
|
#define STRLEN strlen
|
|
|
|
#define STRTOL strtol
|
|
|
|
#define STRTOUL strtoul
|
|
|
|
#define SPRINTF snprintf
|
|
|
|
#define STRCMP strcmp
|
|
|
|
#define STRPBRK strpbrk
|
2011-03-21 17:53:02 +03:00
|
|
|
#define ISBLANK2 isblank
|
|
|
|
#define ISCNTRL iscntrl
|
|
|
|
#define ISGRAPH isgraph
|
2009-12-23 15:44:21 +03:00
|
|
|
#define ISLOWER islower
|
2011-03-21 17:53:02 +03:00
|
|
|
#define ISPUNCT ispunct
|
|
|
|
#define ISSPACE isspace
|
|
|
|
#define ISUPPER isupper
|
|
|
|
#define TOLOWER tolower
|
|
|
|
#define TOUPPER toupper
|
2008-05-16 22:03:01 +04:00
|
|
|
#define STRSET memset
|
2009-08-12 01:28:02 +04:00
|
|
|
#define STRCHR strchr
|
2008-05-16 22:03:01 +04:00
|
|
|
|
|
|
|
#define L(ch) ch
|
2011-03-21 17:53:02 +03:00
|
|
|
#define WS "%s"
|
|
|
|
#define WVS "%*s"
|
|
|
|
#define WC "%c"
|
2008-05-16 22:03:01 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MEMCMP(to, from, n) \
|
|
|
|
memcmp(to, from, (n) * sizeof(*(to)))
|
|
|
|
#define MEMMOVE(p, t, len) memmove(p, t, (len) * sizeof(*(p)))
|
|
|
|
#define MEMCPY(p, t, len) memcpy(p, t, (len) * sizeof(*(p)))
|
|
|
|
#define SIZE(w) (sizeof(w)/sizeof(*w))
|
|
|
|
|
|
|
|
#endif
|