/*
* ctype.h
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is a part of the mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER within the package.
*
- * Functions for testing character types and converting characters.
+ * Functions for character classification and conversion.
+ *
+ * $Id$
+ *
+ * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
+ * Copyright (C) 1997-2008, 2016, MinGW.org Project
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice, this permission notice, and the following
+ * disclaimer shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*
*/
+#ifndef _CTYPE_H
+#pragma GCC system_header
+#define _CTYPE_H
-#ifndef _CTYPE_H_
-#define _CTYPE_H_
-
-/* All the headers include this file. */
+/* All MinGW headers must include <_mingw.h>
+ */
#include <_mingw.h>
-#define __need_wchar_t
-#define __need_wint_t
-#ifndef RC_INVOKED
-#include <stddef.h>
-#endif /* Not RC_INVOKED */
-
+/* Although conflicting with both ISO-C and POSIX, Microsoft say that,
+ * in addition to the single byte character classification API which is
+ * properly declared here, this file should also declare elements of the
+ * wide classification API, which is properly declared in <wctype.h>
+ *
+ * To avoid the burden of maintaining duplicate declarations, in two
+ * locations, we keep the wide character declarations where ISO-C and
+ * POSIX say they belong, in <wctype.h>, while accommodating Microsoft
+ * compatibility by providing for selective inclusion of the relevant
+ * elements of it here. (Note that we must do this early, because to
+ * avoid duplication, we delegate the definition of common character
+ * classification macros, with the exception of _LEADBYTE, which is
+ * not required in both headers, to <wctype.h>).
+ */
+#define __CTYPE_H_SOURCED__
+#include <wctype.h>
-/*
- * The following flags are used to tell iswctype and _isctype what character
- * types you are looking for.
+/* This is the one character classification macro, for which definition
+ * is NOT delegated to <wctype.h>
*/
-#define _UPPER 0x0001
-#define _LOWER 0x0002
-#define _DIGIT 0x0004
-#define _SPACE 0x0008 /* HT LF VT FF CR SP */
-#define _PUNCT 0x0010
-#define _CONTROL 0x0020
-/* _BLANK is set for SP and non-ASCII horizontal space chars (eg,
- "no-break space", 0xA0, in CP1250) but not for HT. */
-#define _BLANK 0x0040
-#define _HEX 0x0080
-#define _LEADBYTE 0x8000
-
-#define _ALPHA 0x0103
+#define _LEADBYTE 0x8000
#ifndef RC_INVOKED
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-_CRTIMP int __cdecl __MINGW_NOTHROW isalnum(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isalpha(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW iscntrl(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isdigit(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isgraph(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW islower(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isprint(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW ispunct(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isspace(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isupper(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW isxdigit(int);
-
-#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
- || !defined __STRICT_ANSI__
-int __cdecl __MINGW_NOTHROW isblank (int);
+_BEGIN_C_DECLS
+
+_CRTIMP __cdecl __MINGW_NOTHROW int isalnum(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isalpha(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int iscntrl(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isdigit(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isgraph(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int islower(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isleadbyte (int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isprint(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int ispunct(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isspace(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isupper(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int isxdigit(int);
+
+#if __STDC_VERSION__ >= 199901L || !defined __STRICT_ANSI__
+__cdecl __MINGW_NOTHROW int isblank (int);
#endif
#ifndef __STRICT_ANSI__
-_CRTIMP int __cdecl __MINGW_NOTHROW _isctype (int, int);
+_CRTIMP __cdecl __MINGW_NOTHROW int _isctype (int, int);
#endif
-/* These are the ANSI versions, with correct checking of argument */
-_CRTIMP int __cdecl __MINGW_NOTHROW tolower(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW toupper(int);
-
-/*
- * NOTE: The above are not old name type wrappers, but functions exported
- * explicitly by MSVCRT/CRTDLL. However, underscored versions are also
- * exported.
+/* These are ISO-C conforming functions, with correct checking of
+ * argument; they are exported by MSVCRT.DLL, and by CRTDLL.DLL as
+ * such, and are NOT simply old-name mapped variants; however...
*/
+_CRTIMP __cdecl __MINGW_NOTHROW int tolower (int);
+_CRTIMP __cdecl __MINGW_NOTHROW int toupper (int);
+
#ifndef __STRICT_ANSI__
-/*
- * These are the cheap non-std versions: The return values are undefined
- * if the argument is not ASCII char or is not of appropriate case
+/* ...Microsoft's beloved underscore decorated variants are also
+ * exported. These are cheap non-standard versions: their return
+ * values are undefined if the argument is not an ASCII character,
+ * or is not of appropriate case for the requested conversion.
+ *
+ * Note that these appear to be approximately equivalent to POSIX
+ * macros of the same names, (declared obsolescent in POSIX.1-2008),
+ * but are implemented as DLL functions, rather than macros.
*/
-_CRTIMP int __cdecl __MINGW_NOTHROW _tolower(int);
-_CRTIMP int __cdecl __MINGW_NOTHROW _toupper(int);
+_CRTIMP __cdecl __MINGW_NOTHROW int _tolower (int);
+_CRTIMP __cdecl __MINGW_NOTHROW int _toupper (int);
#endif
-/* Also defined in stdlib.h */
#ifndef MB_CUR_MAX
-#ifdef __DECLSPEC_SUPPORTED
-# ifdef __MSVCRT__
-# define MB_CUR_MAX __mb_cur_max
- __MINGW_IMPORT int __mb_cur_max;
-# else /* not __MSVCRT */
-# define MB_CUR_MAX __mb_cur_max_dll
- __MINGW_IMPORT int __mb_cur_max_dll;
-# endif /* not __MSVCRT */
-
-#else /* ! __DECLSPEC_SUPPORTED */
-# ifdef __MSVCRT__
- extern int* _imp____mb_cur_max;
-# define MB_CUR_MAX (*_imp____mb_cur_max)
-# else /* not __MSVCRT */
- extern int* _imp____mb_cur_max_dll;
-# define MB_CUR_MAX (*_imp____mb_cur_max_dll)
-# endif /* not __MSVCRT */
-#endif /* __DECLSPEC_SUPPORTED */
-#endif /* MB_CUR_MAX */
-
+/* FIXME: also defined in stdlib.h; should be factored into ONE
+ * location ONLY, and included into the other.
+ */
+# ifdef __DECLSPEC_SUPPORTED
+# ifdef __MSVCRT__
+# define MB_CUR_MAX __mb_cur_max
+ __MINGW_IMPORT int __mb_cur_max;
+
+# else /* !__MSVCRT__ */
+# define MB_CUR_MAX __mb_cur_max_dll
+ __MINGW_IMPORT int __mb_cur_max_dll;
+# endif /* !__MSVCRT__ */
+
+# else /* !__DECLSPEC_SUPPORTED */
+# ifdef __MSVCRT__
+# define MB_CUR_MAX (*_imp____mb_cur_max)
+ extern int *_imp____mb_cur_max;
+
+# else /* !__MSVCRT__ */
+# define MB_CUR_MAX (*_imp____mb_cur_max_dll)
+ extern int *_imp____mb_cur_max_dll;
+# endif /* !__MSVCRT__ */
+# endif /* __DECLSPEC_SUPPORTED */
+#endif /* ! MB_CUR_MAX */
#ifdef __DECLSPEC_SUPPORTED
-# if __MSVCRT_VERSION__ <= 0x0700
- __MINGW_IMPORT unsigned short _ctype[];
+# if __MSVCRT_VERSION__ <= __MSVCR70_DLL
+ __MINGW_IMPORT unsigned short _ctype[];
# endif
+
# ifdef __MSVCRT__
- __MINGW_IMPORT unsigned short* _pctype;
-# else /* CRTDLL */
- __MINGW_IMPORT unsigned short* _pctype_dll;
+ __MINGW_IMPORT unsigned short *_pctype;
+
+# else /* !__MSVCRT__ (implies CRTDLL) */
# define _pctype _pctype_dll
+ __MINGW_IMPORT unsigned short *_pctype_dll;
# endif
-#else /* __DECLSPEC_SUPPORTED */
-# if __MSVCRT_VERSION__ <= 0x0700
- extern unsigned short** _imp___ctype;
-# define _ctype (*_imp___ctype)
+#else /* !__DECLSPEC_SUPPORTED */
+# if __MSVCRT_VERSION__ <= __MSVCR70_DLL
+# define _ctype (*_imp___ctype)
+ extern unsigned short **_imp___ctype;
# endif
+
# ifdef __MSVCRT__
- extern unsigned short** _imp___pctype;
-# define _pctype (*_imp___pctype)
-# else /* CRTDLL */
- extern unsigned short** _imp___pctype_dll;
-# define _pctype (*_imp___pctype_dll)
+# define _pctype (*_imp___pctype)
+ extern unsigned short **_imp___pctype;
+
+# else /* !__MSVCRT__ (implies CRTDLL) */
+# define _pctype (*_imp___pctype_dll)
+ extern unsigned short **_imp___pctype_dll;
# endif /* CRTDLL */
-#endif /* __DECLSPEC_SUPPORTED */
+#endif /* !__DECLSPEC_SUPPORTED */
-/*
- * Use inlines here rather than macros, because macros will upset
+/* Use inlines here rather than macros, because macros will upset
* C++ usage (eg, ::isalnum), and so usually get undefined
*
* According to standard for SB chars, these function are defined only
#if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES) \
|| defined (__STRICT_ANSI__))
-/* use simple lookup if SB locale, else _isctype() */
-#define __ISCTYPE(c, mask) (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype(c, mask))
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isalnum(int c) {return __ISCTYPE(c, (_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isalpha(int c) {return __ISCTYPE(c, _ALPHA);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iscntrl(int c) {return __ISCTYPE(c, _CONTROL);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isdigit(int c) {return __ISCTYPE(c, _DIGIT);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isgraph(int c) {return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW islower(int c) {return __ISCTYPE(c, _LOWER);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isprint(int c) {return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW ispunct(int c) {return __ISCTYPE(c, _PUNCT);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isspace(int c) {return __ISCTYPE(c, _SPACE);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isupper(int c) {return __ISCTYPE(c, _UPPER);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isxdigit(int c) {return __ISCTYPE(c, _HEX);}
-
-#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
- || !defined __STRICT_ANSI__
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isblank (int c)
- {return (__ISCTYPE(c, _BLANK) || c == '\t');}
-#endif
+/* Use simple lookup in single byte locales, else _isctype()
+ */
+#define __ISCTYPE(c, mask) (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype (c, mask))
-/* these reproduce behaviour of lib underscored versions */
-__CRT_INLINE int __cdecl __MINGW_NOTHROW _tolower(int c) {return ( c -'A'+'a');}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW _toupper(int c) {return ( c -'a'+'A');}
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isalnum (int c)
+{ return __ISCTYPE(c, (_ALPHA|_DIGIT)); }
-/* TODO? Is it worth inlining ANSI tolower, toupper? Probably only
- if we only want C-locale. */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isalpha (int c)
+{ return __ISCTYPE(c, _ALPHA); }
-#endif /* _NO_CTYPE_INLINES */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iscntrl (int c)
+{ return __ISCTYPE(c, _CONTROL); }
-/* Wide character equivalents */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isdigit (int c)
+{ return __ISCTYPE(c, _DIGIT); }
-#ifndef WEOF
-#define WEOF (wchar_t)(0xFFFF)
-#endif
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isgraph (int c)
+{ return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT)); }
-#ifndef _WCTYPE_T_DEFINED
-typedef wchar_t wctype_t;
-#define _WCTYPE_T_DEFINED
-#endif
+__CRT_INLINE __cdecl __MINGW_NOTHROW int islower (int c)
+{ return __ISCTYPE(c, _LOWER); }
-_CRTIMP int __cdecl __MINGW_NOTHROW iswalnum(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswalpha(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswascii(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswcntrl(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswctype(wint_t, wctype_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW is_wctype(wint_t, wctype_t); /* Obsolete! */
-_CRTIMP int __cdecl __MINGW_NOTHROW iswdigit(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswgraph(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswlower(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswprint(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswpunct(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswspace(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswupper(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswxdigit(wint_t);
-
-#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
- || !defined __STRICT_ANSI__ || defined __cplusplus
-int __cdecl __MINGW_NOTHROW iswblank (wint_t);
-#endif
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isprint (int c)
+{ return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT)); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int ispunct (int c)
+{ return __ISCTYPE(c, _PUNCT); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isspace (int c)
+{ return __ISCTYPE(c, _SPACE); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isupper (int c)
+{ return __ISCTYPE(c, _UPPER); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isxdigit (int c)
+{ return __ISCTYPE(c, _HEX); }
-/* Older MS docs uses wchar_t for arg and return type, while newer
- online MS docs say arg is wint_t and return is int.
- ISO C uses wint_t for both. */
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW towlower (wint_t);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW towupper (wint_t);
-
-_CRTIMP int __cdecl __MINGW_NOTHROW isleadbyte (int);
-
-/* Also in wctype.h */
-#if ! (defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \
- || defined(__WCTYPE_INLINES_DEFINED))
-#define __WCTYPE_INLINES_DEFINED
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswlower(wint_t wc) {return (iswctype(wc,_LOWER));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswupper(wint_t wc) {return (iswctype(wc,_UPPER));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);}
-#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
- || !defined __STRICT_ANSI__ || defined __cplusplus
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswblank (wint_t wc)
- {return (iswctype(wc,_BLANK) || wc == L'\t');}
+#if __STDC_VERSION__ >= 199901L || !defined __STRICT_ANSI__
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isblank (int c)
+{ return (__ISCTYPE(c, _BLANK) || c == '\t'); }
#endif
-#endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */
+/* These reproduce the behaviour of their DLL exported namesakes,
+ * and thus ARE the effective equivalents of the similarly named,
+ * and now-obsolescent, POSIX macros.
+ */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int _tolower (int c)
+{ return (c - 'A' + 'a'); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int _toupper (int c)
+{ return (c - 'a' + 'A'); }
+
+/* TODO: is it worth inlining ANSI tolower(), and toupper()?
+ * Probably only if we only want C-locale.
+ */
+#endif /* _NO_CTYPE_INLINES */
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int isleadbyte (int c)
+{ return (_pctype[(unsigned char)(c)] & _LEADBYTE); }
#ifndef __STRICT_ANSI__
-int __cdecl __MINGW_NOTHROW __isascii (int);
-int __cdecl __MINGW_NOTHROW __toascii (int);
-int __cdecl __MINGW_NOTHROW __iscsymf (int); /* Valid first character in C symbol */
-int __cdecl __MINGW_NOTHROW __iscsym (int); /* Valid character in C symbol (after first) */
+__cdecl __MINGW_NOTHROW int __isascii (int);
+__cdecl __MINGW_NOTHROW int __toascii (int);
+__cdecl __MINGW_NOTHROW int __iscsymf (int); /* Valid as first character in a C symbol */
+__cdecl __MINGW_NOTHROW int __iscsym (int); /* Valid character in C symbol (after first) */
#if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES))
-__CRT_INLINE int __cdecl __MINGW_NOTHROW __isascii(int c) {return ((c & ~0x7F) == 0);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW __toascii(int c) {return (c & 0x7F);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW __iscsymf(int c) {return (isalpha(c) || (c == '_'));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW __iscsym(int c) {return (isalnum(c) || (c == '_'));}
-#endif /* __NO_CTYPE_INLINES */
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int __isascii (int c)
+{ return ((c & ~0x7F) == 0); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int __toascii (int c)
+{ return (c & 0x7F); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int __iscsymf (int c)
+{ return (isalpha(c) || (c == '_')); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int __iscsym (int c)
+{ return (isalnum(c) || (c == '_')); }
+
+#endif /* !__NO_CTYPE_INLINES */
#ifndef _NO_OLDNAMES
/* Not _CRTIMP */
-int __cdecl __MINGW_NOTHROW isascii (int);
-int __cdecl __MINGW_NOTHROW toascii (int);
-int __cdecl __MINGW_NOTHROW iscsymf (int);
-int __cdecl __MINGW_NOTHROW iscsym (int);
-#endif /* Not _NO_OLDNAMES */
-
-#endif /* Not __STRICT_ANSI__ */
+__cdecl __MINGW_NOTHROW int isascii (int);
+__cdecl __MINGW_NOTHROW int toascii (int);
+__cdecl __MINGW_NOTHROW int iscsymf (int);
+__cdecl __MINGW_NOTHROW int iscsym (int);
+#endif /* !_NO_OLDNAMES */
-#ifdef __cplusplus
-}
-#endif
+#endif /* !__STRICT_ANSI__ */
-#endif /* Not RC_INVOKED */
+_END_C_DECLS
-#endif /* Not _CTYPE_H_ */
+#endif /* ! RC_INVOKED */
+#undef __CTYPE_H_SOURCED__
+#endif /* !_CTYPE_H: $RCSfile$: end of file */
/*
* wctype.h
*
- * Functions for testing wide character types and converting characters.
+ * Functions for wide character classification and conversion.
*
- * This file is part of the Mingw32 package.
+ * $Id$
*
- * Contributors:
- * Created by Mumit Khan <khan@xraylith.wisc.edu>
+ * Written by Mumit Khan <khan@xraylith.wisc.edu>
+ * Copyright (C) 1999-2003, 2005-2007, 2016, MinGW.org Project
*
- * THIS SOFTWARE IS NOT COPYRIGHTED
*
- * This source code is offered for use in the public domain. You may
- * use, modify or distribute it freely.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
*
- * This code is distributed in the hope that it will be useful but
- * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
- * DISCLAIMED. This includes but is not limited to warranties of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * The above copyright notice, this permission notice, and the following
+ * disclaimer shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*
*/
+#ifndef _WCTYPE_H
+#pragma GCC system_header
+
+#ifndef __CTYPE_H_SOURCED__
+/* Perversely, (since they provide <wctype.h> themselves), Microsoft
+ * say that most of the definitions and declarations which follow are
+ * provided by <ctype.h>, rather than here; (this conflicts with both
+ * ISO-C and POSIX). We prefer to provide them here, for ISO-C/POSIX
+ * conformance, while also exposing them for selective inclusion by
+ * <ctype.h>, to maintain Microsoft compatibility.
+ *
+ * We define the <wctype.h> multiple inclusion guard macro only when
+ * <wctype.h> is included directly, NOT when included via <ctype.h>
+ */
+#define _WCTYPE_H
-#ifndef _WCTYPE_H_
-#define _WCTYPE_H_
-
-/* All the headers include this file. */
+/* All MinGW headers must include <_mingw.h>; when sourced by <ctype.h>,
+ * we may delegate that responsibility to it, but in the case of direct
+ * inclusion, we must address it ourselves.
+ */
#include <_mingw.h>
+#endif
+
+/* The following flags are used to tell iswctype() and _isctype() what
+ * character classes are to be matched; (note that _BLANK will match for
+ * SP and non-ASCII horizontal space chars -- e.g. for "no-break space",
+ * 0xA0, in CP1250 -- but NOT for HT).
+ *
+ * These are defined such that they will be made visible by inclusion
+ * of either <wctype.h> (this file), or <ctype.h>:
+ */
+#define _ALPHA 0x0103
+#define _LOWER 0x0002
+#define _UPPER 0x0001
+#define _DIGIT 0x0004
+#define _SPACE 0x0008 /* HT LF VT FF CR SP */
+#define _PUNCT 0x0010
+#define _CONTROL 0x0020
+#define _BLANK 0x0040
+#define _HEX 0x0080
-#define __need_wchar_t
-#define __need_wint_t
#ifndef RC_INVOKED
-#include <stddef.h>
-#endif /* Not RC_INVOKED */
-/*
- * The following flags are used to tell iswctype and _isctype what character
- * types you are looking for.
+/* ISO-C and POSIX specify that <wctype.h> must define wint_t, wctype_t,
+ * and the WEOF macro, (which also requires wchar_t), as they are defined
+ * in <wchar.h>; since <wchar.h> gets wint_t, (and wchar_t), from <stddef.h>,
+ * we do likewise here. Furthermore, to maintain Microsoft compatibility,
+ * we must also do this on behalf of <ctype.h>; however...
*/
-#define _UPPER 0x0001
-#define _LOWER 0x0002
-#define _DIGIT 0x0004
-#define _SPACE 0x0008
-#define _PUNCT 0x0010
-#define _CONTROL 0x0020
-#define _BLANK 0x0040
-#define _HEX 0x0080
-#define _LEADBYTE 0x8000
-
-#define _ALPHA 0x0103
+#if !(defined _WCTYPE_H && defined _CTYPE_H)
+/* ...we need not incur the overhead of doing it twice, when both <ctype.h>
+ * and <wctype.h> have been included.
+ */
+#define __need_wint_t
+#define __need_wchar_t
+#include <stddef.h>
-#ifndef RC_INVOKED
+typedef wchar_t wctype_t;
+#define WEOF (wchar_t)(0xffff)
-#ifdef __cplusplus
-extern "C" {
-#endif
+_BEGIN_C_DECLS
-#ifndef WEOF
-#define WEOF (wchar_t)(0xFFFF)
-#endif
+/* Wide character classification functions. In typically perverse
+ * fashion, and contrary to both ISO-C and POSIX, Microsoft specify
+ * that these should be declared in <ctype.h>; thus, to accommodate
+ * this persersity, we make them visible here, irrespective of any
+ * selective inclusion filter macro.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW int iswalnum (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswalpha (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswascii (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswcntrl (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswctype (wint_t, wctype_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswdigit (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswgraph (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswlower (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswprint (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswpunct (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswspace (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswupper (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW int iswxdigit (wint_t);
+
+__MINGW_ATTRIB_DEPRECATED
+/* This function is exported by all versions of MSVCRT.DLL, (up to and
+ * including that in Windows-7), and in all non-free counterparts up to
+ * and including MSVCR120.DLL, but as of MSVC-2013, Microsoft declare
+ * it to be obsolete. DO NOT USE IT! Use iswctype() instead.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW int is_wctype (wint_t, wctype_t);
-#ifndef _WCTYPE_T_DEFINED
-typedef wchar_t wctype_t;
-#define _WCTYPE_T_DEFINED
+#if __STDC_VERSION__>=199901L || !defined __STRICT_ANSI__ || defined __cplusplus
+__cdecl __MINGW_NOTHROW int iswblank (wint_t);
#endif
-/* Wide character equivalents - also in ctype.h */
-_CRTIMP int __cdecl __MINGW_NOTHROW iswalnum(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswalpha(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswascii(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswcntrl(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswctype(wint_t, wctype_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW is_wctype(wint_t, wctype_t); /* Obsolete! */
-_CRTIMP int __cdecl __MINGW_NOTHROW iswdigit(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswgraph(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswlower(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswprint(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswpunct(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswspace(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswupper(wint_t);
-_CRTIMP int __cdecl __MINGW_NOTHROW iswxdigit(wint_t);
-
-#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
- || !defined __STRICT_ANSI__ || defined __cplusplus
-int __cdecl __MINGW_NOTHROW iswblank (wint_t);
-#endif
+/* Wide character case transliteration functions; the following conform
+ * to the ISO-C and POSIX standard declarations; Microsoft, at one time,
+ * specified both as taking a wchar_t argument, and returning a wchar_t
+ * result, but now take a wint_t argument, and return int.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW wint_t towlower (wint_t);
+_CRTIMP __cdecl __MINGW_NOTHROW wint_t towupper (wint_t);
+
+#if !(defined __NO_INLINE__ || defined __NO_CTYPE_INLINES)
+/* Provide inline alternatives to the DLL-exported isw*() functions.
+ * Note that POSIX stipulates that these alternatives should be macros;
+ * we prefer __CRT_INLINEs, (which GCC effectively treats as macros),
+ * because they do not interfere with C++ namespace qualification.
+ */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswalnum (wint_t wc)
+{ return (iswctype (wc, _ALPHA | _DIGIT)); }
-/* Older MS docs uses wchar_t for arg and return type, while newer
- online MS docs say arg is wint_t and return is int.
- ISO C uses wint_t for both. */
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW towlower (wint_t);
-_CRTIMP wint_t __cdecl __MINGW_NOTHROW towupper (wint_t);
-
-_CRTIMP int __cdecl __MINGW_NOTHROW isleadbyte (int);
-
-/* Also in ctype.h */
-
-#ifdef __DECLSPEC_SUPPORTED
-# if __MSVCRT_VERSION__ <= 0x0700
- __MINGW_IMPORT unsigned short _ctype[];
-# endif
-# ifdef __MSVCRT__
- __MINGW_IMPORT unsigned short* _pctype;
-# else /* CRTDLL */
- __MINGW_IMPORT unsigned short* _pctype_dll;
-# define _pctype _pctype_dll
-# endif
-
-#else /* ! __DECLSPEC_SUPPORTED */
-# if __MSVCRT_VERSION__ <= 0x0700
- extern unsigned short** _imp___ctype;
-# define _ctype (*_imp___ctype)
-# endif
-# ifdef __MSVCRT__
- extern unsigned short** _imp___pctype;
-# define _pctype (*_imp___pctype)
-# else /* CRTDLL */
- extern unsigned short** _imp___pctype_dll;
-# define _pctype (*_imp___pctype_dll)
-# endif /* CRTDLL */
-#endif /* __DECLSPEC_SUPPORTED */
-
-
-#if !(defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \
- || defined(__WCTYPE_INLINES_DEFINED))
-#define __WCTYPE_INLINES_DEFINED
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswlower(wint_t wc) {return (iswctype(wc,_LOWER));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswupper(wint_t wc) {return (iswctype(wc,_UPPER));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
-__CRT_INLINE int __cdecl __MINGW_NOTHROW isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);}
-
-#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
- || !defined __STRICT_ANSI__ || defined __cplusplus
-__CRT_INLINE int __cdecl __MINGW_NOTHROW iswblank (wint_t wc)
- {return (iswctype(wc, _BLANK) || wc == L'\t');}
-#endif
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswalpha (wint_t wc)
+{ return (iswctype (wc, _ALPHA )); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswascii (wint_t wc)
+{ return ((wc & ~0x7F) == 0); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswcntrl (wint_t wc)
+{ return (iswctype (wc, _CONTROL)); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswdigit (wint_t wc)
+{ return (iswctype (wc, _DIGIT)); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswgraph (wint_t wc)
+{ return (iswctype (wc, _PUNCT | _ALPHA | _DIGIT)); }
-#endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswlower (wint_t wc)
+{ return (iswctype (wc, _LOWER)); }
-typedef wchar_t wctrans_t;
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswprint (wint_t wc)
+{ return (iswctype (wc, _BLANK | _PUNCT | _ALPHA | _DIGIT)); }
-/* These are resolved by libmingwex.a. Note, that they are also exported
- by the MS C++ runtime lib (msvcp60.dll). The msvcp60.dll implementations
- of wctrans and towctrans are not C99 compliant in that wctrans("tolower")
- returns 0, while std specifies that a non-zero value should be returned
- for a valid string descriptor. If you want the MS behaviour (and you have
- msvcp60.dll in your path) add -lmsvcp60 to your command line. */
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswpunct (wint_t wc)
+{ return (iswctype (wc, _PUNCT)); }
-wint_t __cdecl __MINGW_NOTHROW towctrans(wint_t, wctrans_t);
-wctrans_t __cdecl __MINGW_NOTHROW wctrans(const char*);
-wctype_t __cdecl __MINGW_NOTHROW wctype(const char*);
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswspace (wint_t wc)
+{ return (iswctype (wc, _SPACE)); }
-#ifdef __cplusplus
-}
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswupper (wint_t wc)
+{ return (iswctype (wc, _UPPER)); }
+
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswxdigit (wint_t wc)
+{ return (iswctype (wc, _HEX)); }
+
+#if __STDC_VERSION__>=199901L || !defined __STRICT_ANSI__ || defined __cplusplus
+__CRT_INLINE __cdecl __MINGW_NOTHROW int iswblank (wint_t wc)
+{ return (iswctype (wc, _BLANK) || wc == L'\t'); }
#endif
+#endif /* !__NO_CTYPE_INLINES */
+
+_END_C_DECLS
+
+#endif /* !(_WCTYPE_H && _CTYPE_H) */
-#endif /* Not RC_INVOKED */
+#ifdef _WCTYPE_H
+/* Although Microsoft make most of the content, which ISO-C and POSIX say
+ * should be in <wctype.h>, available through <ctype.h>, the declarations
+ * in this section are exclusive to <wctype.h>
+ */
+typedef wchar_t wctrans_t;
+
+_BEGIN_C_DECLS
+
+/* These are provided in libmingwex.a. Note, that they are also exported
+ * by the MS C++ runtime lib (MSVCP60.DLL). The MSVCP60.DLL implementations
+ * of wctrans and towctrans are not C99 compliant in that wctrans("tolower")
+ * returns 0, while C99 specifies that a non-zero value should be returned
+ * for a valid string descriptor. If you want the MS behaviour (and you
+ * have MSVCP60.DLL in your path) add -lmsvcp60 to your command line.
+ */
+__cdecl __MINGW_NOTHROW wint_t towctrans (wint_t, wctrans_t);
+__cdecl __MINGW_NOTHROW wctrans_t wctrans (const char*);
+__cdecl __MINGW_NOTHROW wctype_t wctype (const char*);
-#endif /* Not _WCTYPE_H_ */
+_END_C_DECLS
+#endif /* _WCTYPE_H */
+#endif /* ! RC_INVOKED */
+#endif /* !_WCTYPE_H: $RCSfile$: end of file */