2013-12-06 12:04:52 +01:00
|
|
|
/* $NetBSD: multibyte.h,v 1.2 2013/11/22 15:52:05 christos Exp $ */
|
2013-01-22 12:03:53 +01:00
|
|
|
#ifndef MULTIBYTE_H
|
|
|
|
#define MULTIBYTE_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_WIDECHAR
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <wctype.h>
|
|
|
|
|
|
|
|
typedef wchar_t RCHAR_T;
|
|
|
|
#define REOF WEOF
|
|
|
|
typedef wchar_t CHAR_T;
|
|
|
|
typedef wint_t ARG_CHAR_T;
|
|
|
|
typedef wint_t UCHAR_T;
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
#define ISUPPER iswupper
|
2013-01-22 12:03:53 +01:00
|
|
|
#define STRLEN wcslen
|
|
|
|
#define STRTOL wcstol
|
|
|
|
#define STRTOUL wcstoul
|
|
|
|
#define SPRINTF swprintf
|
2013-12-06 12:04:52 +01:00
|
|
|
#define STRCHR wcschr
|
2013-01-22 12:03:53 +01:00
|
|
|
#define STRCMP wcscmp
|
|
|
|
#define STRPBRK wcspbrk
|
|
|
|
#define ISBLANK2 iswblank
|
|
|
|
#define ISCNTRL iswcntrl
|
|
|
|
#define ISGRAPH iswgraph
|
|
|
|
#define ISLOWER iswlower
|
|
|
|
#define ISPUNCT iswpunct
|
|
|
|
#define ISSPACE iswspace
|
|
|
|
#define ISUPPER iswupper
|
|
|
|
#define TOLOWER towlower
|
|
|
|
#define TOUPPER towupper
|
|
|
|
#define STRSET wmemset
|
|
|
|
#define STRCHR wcschr
|
|
|
|
|
|
|
|
#define L(ch) L ## ch
|
|
|
|
#define WS "%ls"
|
|
|
|
#define WVS "%*ls"
|
|
|
|
#define WC "%lc"
|
|
|
|
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define REOF EOF
|
|
|
|
typedef char CHAR_T;
|
|
|
|
typedef int ARG_CHAR_T;
|
|
|
|
typedef unsigned char UCHAR_T;
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
#define ISUPPER isupper
|
2013-01-22 12:03:53 +01:00
|
|
|
#define STRLEN strlen
|
|
|
|
#define STRTOL strtol
|
|
|
|
#define STRTOUL strtoul
|
|
|
|
#define SPRINTF snprintf
|
2013-12-06 12:04:52 +01:00
|
|
|
#define STRCHR strchr
|
2013-01-22 12:03:53 +01:00
|
|
|
#define STRCMP strcmp
|
|
|
|
#define STRPBRK strpbrk
|
|
|
|
#define ISBLANK2 isblank
|
|
|
|
#define ISCNTRL iscntrl
|
|
|
|
#define ISGRAPH isgraph
|
|
|
|
#define ISLOWER islower
|
|
|
|
#define ISPUNCT ispunct
|
|
|
|
#define ISSPACE isspace
|
|
|
|
#define ISUPPER isupper
|
|
|
|
#define TOLOWER tolower
|
|
|
|
#define TOUPPER toupper
|
|
|
|
#define STRSET memset
|
|
|
|
#define STRCHR strchr
|
|
|
|
|
|
|
|
#define L(ch) ch
|
|
|
|
#define WS "%s"
|
|
|
|
#define WVS "%*s"
|
|
|
|
#define WC "%c"
|
|
|
|
|
|
|
|
#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)))
|
2013-12-06 12:04:52 +01:00
|
|
|
/*
|
|
|
|
* Like MEMCPY but return a pointer to the end of the copied bytes.
|
|
|
|
* Glibc has a function mempcpy with the same purpose.
|
|
|
|
*/
|
|
|
|
#define MEMPCPY(p, t, len) \
|
|
|
|
((void *)((char *)MEMCPY(p, t, len) + (len) * sizeof(*(p))))
|
2013-01-22 12:03:53 +01:00
|
|
|
#define SIZE(w) (sizeof(w)/sizeof(*w))
|
|
|
|
|
|
|
|
#endif
|