home *** CD-ROM | disk | FTP | other *** search
/ Beginning C++ Through Gam…rogramming (2nd Edition) / BCGP2E.ISO / bloodshed / devcpp-4.9.9.2_setup.exe / ctype.h < prev    next >
C/C++ Source or Header  |  2005-01-29  |  8KB  |  245 lines

  1. /* 
  2.  * ctype.h
  3.  * This file has no copyright assigned and is placed in the Public Domain.
  4.  * This file is a part of the mingw-runtime package.
  5.  * No warranty is given; refer to the file DISCLAIMER within the package.
  6.  *
  7.  * Functions for testing character types and converting characters.
  8.  *
  9.  */
  10.  
  11. #ifndef _CTYPE_H_
  12. #define _CTYPE_H_
  13.  
  14. /* All the headers include this file. */
  15. #include <_mingw.h>
  16.  
  17. #define    __need_wchar_t
  18. #define    __need_wint_t
  19. #ifndef RC_INVOKED
  20. #include <stddef.h>
  21. #endif    /* Not RC_INVOKED */
  22.  
  23.  
  24. /*
  25.  * The following flags are used to tell iswctype and _isctype what character
  26.  * types you are looking for.
  27.  */
  28. #define    _UPPER        0x0001
  29. #define    _LOWER        0x0002
  30. #define    _DIGIT        0x0004
  31. #define    _SPACE        0x0008 /* HT  LF  VT  FF  CR  SP */
  32. #define    _PUNCT        0x0010
  33. #define    _CONTROL    0x0020
  34. #define    _BLANK        0x0040 /* this is SP only, not SP and HT as in C99  */
  35. #define    _HEX        0x0080
  36. #define    _LEADBYTE    0x8000
  37.  
  38. #define    _ALPHA        0x0103
  39.  
  40. #ifndef RC_INVOKED
  41.  
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45.  
  46. _CRTIMP int __cdecl isalnum(int);
  47. _CRTIMP int __cdecl isalpha(int);
  48. _CRTIMP int __cdecl iscntrl(int);
  49. _CRTIMP int __cdecl isdigit(int);
  50. _CRTIMP int __cdecl isgraph(int);
  51. _CRTIMP int __cdecl islower(int);
  52. _CRTIMP int __cdecl isprint(int);
  53. _CRTIMP int __cdecl ispunct(int);
  54. _CRTIMP int __cdecl isspace(int);
  55. _CRTIMP int __cdecl isupper(int);
  56. _CRTIMP int __cdecl isxdigit(int);
  57.  
  58. #ifndef __STRICT_ANSI__
  59. _CRTIMP int __cdecl _isctype (int, int);
  60. #endif
  61.  
  62. /* These are the ANSI versions, with correct checking of argument */
  63. _CRTIMP int __cdecl tolower(int);
  64. _CRTIMP int __cdecl toupper(int);
  65.  
  66. /*
  67.  * NOTE: The above are not old name type wrappers, but functions exported
  68.  * explicitly by MSVCRT/CRTDLL. However, underscored versions are also
  69.  * exported.
  70.  */
  71. #ifndef    __STRICT_ANSI__
  72. /*
  73.  *  These are the cheap non-std versions: The return values are undefined
  74.  *  if the argument is not ASCII char or is not of appropriate case
  75.  */ 
  76. _CRTIMP int __cdecl _tolower(int);
  77. _CRTIMP int __cdecl _toupper(int);
  78. #endif
  79.  
  80. /* Also defined in stdlib.h */
  81. #ifndef MB_CUR_MAX
  82. #ifdef __DECLSPEC_SUPPORTED
  83. # ifdef __MSVCRT__
  84. #  define MB_CUR_MAX __mb_cur_max
  85.    __MINGW_IMPORT int __mb_cur_max;
  86. # else    /* not __MSVCRT */
  87. #  define MB_CUR_MAX __mb_cur_max_dll
  88.    __MINGW_IMPORT int __mb_cur_max_dll;
  89. # endif    /* not __MSVCRT */
  90.  
  91. #else        /* ! __DECLSPEC_SUPPORTED */
  92. # ifdef __MSVCRT__
  93.    extern int* _imp____mbcur_max;
  94. #  define MB_CUR_MAX (*_imp____mb_cur_max)
  95. # else        /* not __MSVCRT */
  96.    extern int*  _imp____mbcur_max_dll;
  97. #  define MB_CUR_MAX (*_imp____mb_cur_max_dll)
  98. # endif     /* not __MSVCRT */
  99. #endif      /*  __DECLSPEC_SUPPORTED */
  100. #endif  /* MB_CUR_MAX */
  101.  
  102.  
  103. #ifdef __DECLSPEC_SUPPORTED
  104. __MINGW_IMPORT unsigned short _ctype[];
  105. # ifdef __MSVCRT__
  106.   __MINGW_IMPORT unsigned short* _pctype;
  107. # else /* CRTDLL */
  108.   __MINGW_IMPORT unsigned short* _pctype_dll;
  109. # define  _pctype _pctype_dll
  110. # endif 
  111.  
  112. #else        /*  __DECLSPEC_SUPPORTED */
  113. extern unsigned short** _imp___ctype;
  114. #define _ctype (*_imp___ctype)
  115. # ifdef __MSVCRT__
  116.   extern unsigned short** _imp___pctype;
  117. # define _pctype (*_imp___pctype)
  118. # else /* CRTDLL */
  119.   extern unsigned short** _imp___pctype_dll;
  120. # define _pctype (*_imp___pctype_dll)
  121. # endif /* CRTDLL */
  122. #endif        /*  __DECLSPEC_SUPPORTED */
  123.  
  124. /*
  125.  * Use inlines here rather than macros, because macros will upset 
  126.  * C++ usage (eg, ::isalnum), and so usually get undefined
  127.  *
  128.  * According to standard for SB chars, these function are defined only
  129.  * for input values representable by unsigned char or EOF.
  130.  * Thus, there is no range test.
  131.  * This reproduces behaviour of MSVCRT.dll lib implemention for SB chars.
  132.  *
  133.  * If no MB char support is needed, these can be simplified even
  134.  * more by command line define -DMB_CUR_MAX=1.  The compiler will then
  135.  * optimise away the constant condition.            
  136.  */
  137.  
  138.  
  139. #if ! (defined (__NO_INLINE__)  || defined (__NO_CTYPE_INLINES) \
  140.       || defined (__STRICT_ANSI__ ))
  141. /* use  simple lookup if SB locale, else  _isctype()  */
  142. #define __ISCTYPE(c, mask)  (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype(c, mask))
  143. __CRT_INLINE int __cdecl isalnum(int c) {return __ISCTYPE(c, (_ALPHA|_DIGIT));}
  144. __CRT_INLINE int __cdecl isalpha(int c) {return __ISCTYPE(c, _ALPHA);}
  145. __CRT_INLINE int __cdecl iscntrl(int c) {return __ISCTYPE(c, _CONTROL);}
  146. __CRT_INLINE int __cdecl isdigit(int c) {return __ISCTYPE(c, _DIGIT);}
  147. __CRT_INLINE int __cdecl isgraph(int c) {return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT));}
  148. __CRT_INLINE int __cdecl islower(int c) {return __ISCTYPE(c, _LOWER);}
  149. __CRT_INLINE int __cdecl isprint(int c) {return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT));}
  150. __CRT_INLINE int __cdecl ispunct(int c) {return __ISCTYPE(c, _PUNCT);}
  151. __CRT_INLINE int __cdecl isspace(int c) {return __ISCTYPE(c, _SPACE);}
  152. __CRT_INLINE int __cdecl isupper(int c) {return __ISCTYPE(c, _UPPER);}
  153. __CRT_INLINE int __cdecl isxdigit(int c) {return __ISCTYPE(c, _HEX);}
  154.  
  155. /* these reproduce behaviour of lib underscored versions  */
  156. __CRT_INLINE int __cdecl _tolower(int c) {return ( c -'A'+'a');}
  157. __CRT_INLINE int __cdecl _toupper(int c) {return ( c -'a'+'A');}
  158.  
  159. /* TODO? Is it worth inlining ANSI tolower, toupper? Probably only
  160.    if we only want C-locale. */
  161.  
  162. #endif /* _NO_CTYPE_INLINES */
  163.  
  164. /* Wide character equivalents */
  165.  
  166. #ifndef WEOF
  167. #define    WEOF    (wchar_t)(0xFFFF)
  168. #endif
  169.  
  170. #ifndef _WCTYPE_T_DEFINED
  171. typedef wchar_t wctype_t;
  172. #define _WCTYPE_T_DEFINED
  173. #endif
  174.  
  175. _CRTIMP int __cdecl iswalnum(wint_t);
  176. _CRTIMP int __cdecl iswalpha(wint_t);
  177. _CRTIMP int __cdecl iswascii(wint_t);
  178. _CRTIMP int __cdecl iswcntrl(wint_t);
  179. _CRTIMP int __cdecl iswctype(wint_t, wctype_t);
  180. _CRTIMP int __cdecl is_wctype(wint_t, wctype_t);    /* Obsolete! */
  181. _CRTIMP int __cdecl iswdigit(wint_t);
  182. _CRTIMP int __cdecl iswgraph(wint_t);
  183. _CRTIMP int __cdecl iswlower(wint_t);
  184. _CRTIMP int __cdecl iswprint(wint_t);
  185. _CRTIMP int __cdecl iswpunct(wint_t);
  186. _CRTIMP int __cdecl iswspace(wint_t);
  187. _CRTIMP int __cdecl iswupper(wint_t);
  188. _CRTIMP int __cdecl iswxdigit(wint_t);
  189.  
  190. _CRTIMP wchar_t __cdecl towlower(wchar_t);
  191. _CRTIMP wchar_t __cdecl towupper(wchar_t);
  192.  
  193. _CRTIMP int __cdecl isleadbyte (int);
  194.  
  195. /* Also in wctype.h */
  196. #if ! (defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \
  197.        || defined(__WCTYPE_INLINES_DEFINED))
  198. #define __WCTYPE_INLINES_DEFINED
  199. __CRT_INLINE int __cdecl iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));}
  200. __CRT_INLINE int __cdecl iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));}
  201. __CRT_INLINE int __cdecl iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);}
  202. __CRT_INLINE int __cdecl iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));}
  203. __CRT_INLINE int __cdecl iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
  204. __CRT_INLINE int __cdecl iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));}
  205. __CRT_INLINE int __cdecl iswlower(wint_t wc) {return (iswctype(wc,_LOWER));}
  206. __CRT_INLINE int __cdecl iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));}
  207. __CRT_INLINE int __cdecl iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));}
  208. __CRT_INLINE int __cdecl iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
  209. __CRT_INLINE int __cdecl iswupper(wint_t wc) {return (iswctype(wc,_UPPER));}
  210. __CRT_INLINE int __cdecl iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
  211. __CRT_INLINE int __cdecl isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);}
  212. #endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */
  213.  
  214. #ifndef    __STRICT_ANSI__
  215. int __cdecl __isascii (int);
  216. int __cdecl __toascii (int);
  217. int __cdecl __iscsymf (int);        /* Valid first character in C symbol */
  218. int __cdecl __iscsym (int);        /* Valid character in C symbol (after first) */
  219.  
  220. #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES))
  221. __CRT_INLINE int __cdecl __isascii(int c) {return ((c & ~0x7F) == 0);} 
  222. __CRT_INLINE int __cdecl __toascii(int c) {return (c & 0x7F);}
  223. __CRT_INLINE int __cdecl __iscsymf(int c) {return (isalpha(c) || (c == '_'));}
  224. __CRT_INLINE int __cdecl __iscsym(int c)  {return  (isalnum(c) || (c == '_'));}
  225. #endif /* __NO_CTYPE_INLINES */
  226.  
  227. #ifndef    _NO_OLDNAMES
  228. /* Not _CRTIMP */ 
  229. int __cdecl isascii (int);
  230. int __cdecl toascii (int);
  231. int __cdecl iscsymf (int);
  232. int __cdecl iscsym (int);
  233. #endif    /* Not _NO_OLDNAMES */
  234.  
  235. #endif    /* Not __STRICT_ANSI__ */
  236.  
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240.  
  241. #endif    /* Not RC_INVOKED */
  242.  
  243. #endif    /* Not _CTYPE_H_ */
  244.  
  245.