home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / ctype.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  10KB  |  313 lines

  1. /***
  2. *ctype.h - character conversion macros and ctype macros
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines macros for character classification/conversion.
  8. *       [ANSI/System V]
  9. *
  10. *       [Public]
  11. *
  12. ****/
  13.  
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif  /* _MSC_VER > 1000 */
  17.  
  18. #ifndef _INC_CTYPE
  19. #define _INC_CTYPE
  20.  
  21. #if !defined (_WIN32) && !defined (_MAC)
  22. #error ERROR: Only Mac or Win32 targets supported!
  23. #endif  /* !defined (_WIN32) && !defined (_MAC) */
  24.  
  25. #ifndef _CRTBLD
  26. /* This version of the header files is NOT for user programs.
  27.  * It is intended for use when building the C runtimes ONLY.
  28.  * The version intended for public use will not have this message.
  29.  */
  30. #error ERROR: Use of C runtime library internal header file.
  31. #endif  /* _CRTBLD */
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif  /* __cplusplus */
  36.  
  37. #ifndef _INTERNAL_IFSTRIP_
  38. #include <cruntime.h>
  39. #endif  /* _INTERNAL_IFSTRIP_ */
  40.  
  41.  
  42. /* Define _CRTIMP */
  43.  
  44. #ifndef _CRTIMP
  45. #ifdef CRTDLL
  46. #define _CRTIMP __declspec(dllexport)
  47. #else  /* CRTDLL */
  48. #ifdef _DLL
  49. #define _CRTIMP __declspec(dllimport)
  50. #else  /* _DLL */
  51. #define _CRTIMP
  52. #endif  /* _DLL */
  53. #endif  /* CRTDLL */
  54. #endif  /* _CRTIMP */
  55.  
  56.  
  57. /* Define __cdecl for non-Microsoft compilers */
  58.  
  59. #if (!defined (_MSC_VER) && !defined (__cdecl))
  60. #define __cdecl
  61. #endif  /* (!defined (_MSC_VER) && !defined (__cdecl)) */
  62.  
  63. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  64.  
  65. #ifndef _CRTAPI1
  66. #if _MSC_VER >= 800 && _M_IX86 >= 300
  67. #define _CRTAPI1 __cdecl
  68. #else  /* _MSC_VER >= 800 && _M_IX86 >= 300 */
  69. #define _CRTAPI1
  70. #endif  /* _MSC_VER >= 800 && _M_IX86 >= 300 */
  71. #endif  /* _CRTAPI1 */
  72.  
  73. #ifndef _WCHAR_T_DEFINED
  74. typedef unsigned short wchar_t;
  75. #define _WCHAR_T_DEFINED
  76. #endif  /* _WCHAR_T_DEFINED */
  77.  
  78. #ifndef _MAC
  79. #ifndef _WCTYPE_T_DEFINED
  80. typedef wchar_t wint_t;
  81. typedef wchar_t wctype_t;
  82. #define _WCTYPE_T_DEFINED
  83. #endif  /* _WCTYPE_T_DEFINED */
  84.  
  85. #ifndef WEOF
  86. #define WEOF (wint_t)(0xFFFF)
  87. #endif  /* WEOF */
  88. #endif  /* _MAC */
  89.  
  90.  
  91. #ifndef _CTYPE_DISABLE_MACROS
  92. _CRTIMP extern unsigned short _ctype[];
  93. #ifndef _INTERNAL_IFSTRIP_
  94. #if defined (_DLL) && defined (_M_IX86)
  95. /* Retained for compatibility with VC++ 5.0 and earlier versions */
  96. _CRTIMP unsigned short ** __cdecl __p__pctype(void);
  97. _CRTIMP wctype_t ** __cdecl __p__pwctype(void);
  98. #endif  /* defined (_DLL) && defined (_M_IX86) */
  99. #endif  /* _INTERNAL_IFSTRIP_ */
  100. _CRTIMP extern unsigned short *_pctype;
  101. #ifndef _MAC
  102. _CRTIMP extern wctype_t *_pwctype;
  103. #endif  /* _MAC */
  104. #endif  /* _CTYPE_DISABLE_MACROS */
  105.  
  106.  
  107. /* set bit masks for the possible character types */
  108.  
  109. #define _UPPER          0x1     /* upper case letter */
  110. #define _LOWER          0x2     /* lower case letter */
  111. #define _DIGIT          0x4     /* digit[0-9] */
  112. #define _SPACE          0x8     /* tab, carriage return, newline, */
  113.                                 /* vertical tab or form feed */
  114. #define _PUNCT          0x10    /* punctuation character */
  115. #define _CONTROL        0x20    /* control character */
  116. #define _BLANK          0x40    /* space char */
  117. #define _HEX            0x80    /* hexadecimal digit */
  118.  
  119. #define _LEADBYTE       0x8000                  /* multibyte leadbyte */
  120. #define _ALPHA          (0x0100|_UPPER|_LOWER)  /* alphabetic character */
  121.  
  122.  
  123. /* character classification function prototypes */
  124.  
  125. #ifndef _CTYPE_DEFINED
  126.  
  127. _CRTIMP int __cdecl _isctype(int, int);
  128. _CRTIMP int __cdecl isalpha(int);
  129. _CRTIMP int __cdecl isupper(int);
  130. _CRTIMP int __cdecl islower(int);
  131. _CRTIMP int __cdecl isdigit(int);
  132. _CRTIMP int __cdecl isxdigit(int);
  133. _CRTIMP int __cdecl isspace(int);
  134. _CRTIMP int __cdecl ispunct(int);
  135. _CRTIMP int __cdecl isalnum(int);
  136. _CRTIMP int __cdecl isprint(int);
  137. _CRTIMP int __cdecl isgraph(int);
  138. _CRTIMP int __cdecl iscntrl(int);
  139. _CRTIMP int __cdecl toupper(int);
  140. _CRTIMP int __cdecl tolower(int);
  141. _CRTIMP int __cdecl _tolower(int);
  142. _CRTIMP int __cdecl _toupper(int);
  143. _CRTIMP int __cdecl __isascii(int);
  144. _CRTIMP int __cdecl __toascii(int);
  145. _CRTIMP int __cdecl __iscsymf(int);
  146. _CRTIMP int __cdecl __iscsym(int);
  147. #define _CTYPE_DEFINED
  148. #endif  /* _CTYPE_DEFINED */
  149.  
  150.  
  151. #ifndef _MAC
  152. #ifndef _WCTYPE_DEFINED
  153.  
  154. /* wide function prototypes, also declared in wchar.h  */
  155.  
  156. /* character classification function prototypes */
  157.  
  158. _CRTIMP int __cdecl iswalpha(wint_t);
  159. _CRTIMP int __cdecl iswupper(wint_t);
  160. _CRTIMP int __cdecl iswlower(wint_t);
  161. _CRTIMP int __cdecl iswdigit(wint_t);
  162. _CRTIMP int __cdecl iswxdigit(wint_t);
  163. _CRTIMP int __cdecl iswspace(wint_t);
  164. _CRTIMP int __cdecl iswpunct(wint_t);
  165. _CRTIMP int __cdecl iswalnum(wint_t);
  166. _CRTIMP int __cdecl iswprint(wint_t);
  167. _CRTIMP int __cdecl iswgraph(wint_t);
  168. _CRTIMP int __cdecl iswcntrl(wint_t);
  169. _CRTIMP int __cdecl iswascii(wint_t);
  170. _CRTIMP int __cdecl isleadbyte(int);
  171.  
  172. _CRTIMP wchar_t __cdecl towupper(wchar_t);
  173. _CRTIMP wchar_t __cdecl towlower(wchar_t);
  174.  
  175. _CRTIMP int __cdecl iswctype(wint_t, wctype_t);
  176.  
  177. /* --------- The following functions are OBSOLETE --------- */
  178. _CRTIMP int __cdecl is_wctype(wint_t, wctype_t);
  179. /*  --------- The preceding functions are OBSOLETE --------- */
  180.  
  181. #define _WCTYPE_DEFINED
  182. #endif  /* _WCTYPE_DEFINED */
  183. #endif  /* _MAC */
  184.  
  185.  
  186. /* the character classification macro definitions */
  187.  
  188. #ifndef _CTYPE_DISABLE_MACROS
  189.  
  190. /*
  191.  * Maximum number of bytes in multi-byte character in the current locale
  192.  * (also defined in stdlib.h).
  193.  */
  194. #ifndef MB_CUR_MAX
  195. #ifndef _INTERNAL_IFSTRIP_
  196. #if defined (_DLL) && defined (_M_IX86)
  197. /* Retained for compatibility with VC++ 5.0 and earlier versions */
  198. _CRTIMP int * __cdecl __p___mb_cur_max(void);
  199. #endif  /* defined (_DLL) && defined (_M_IX86) */
  200. #endif  /* _INTERNAL_IFSTRIP_ */
  201.  
  202. #define MB_CUR_MAX __mb_cur_max
  203. _CRTIMP extern int __mb_cur_max;
  204.  
  205. #endif  /* MB_CUR_MAX */
  206.  
  207. #ifdef _MAC
  208.  
  209. #ifndef __cplusplus
  210. #define isalpha(_c)     ( _pctype[_c] & (_UPPER|_LOWER) )
  211. #define isupper(_c)     ( _pctype[_c] & _UPPER )
  212. #define islower(_c)     ( _pctype[_c] & _LOWER )
  213. #define isdigit(_c)     ( _pctype[_c] & _DIGIT )
  214. #define isxdigit(_c)    ( _pctype[_c] & _HEX )
  215. #define isspace(_c)     ( _pctype[_c] & _SPACE )
  216. #define ispunct(_c)     ( _pctype[_c] & _PUNCT )
  217. #define isalnum(_c)     ( _pctype[_c] & (_UPPER|_LOWER|_DIGIT) )
  218. #define isprint(_c)     ( _pctype[_c] & (_BLANK|_PUNCT|_UPPER|_LOWER|_DIGIT) )
  219. #define isgraph(_c)     ( _pctype[_c] & (_PUNCT|_UPPER|_LOWER|_DIGIT) )
  220. #define iscntrl(_c)     ( _pctype[_c] & _CONTROL )
  221. #endif  /* __cplusplus */
  222.  
  223. #else  /* _MAC */
  224.  
  225. #ifndef __cplusplus
  226. #define isalpha(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_ALPHA) : _pctype[_c] & _ALPHA)
  227. #define isupper(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_UPPER) : _pctype[_c] & _UPPER)
  228. #define islower(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_LOWER) : _pctype[_c] & _LOWER)
  229. #define isdigit(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_DIGIT) : _pctype[_c] & _DIGIT)
  230. #define isxdigit(_c)    (MB_CUR_MAX > 1 ? _isctype(_c,_HEX)   : _pctype[_c] & _HEX)
  231. #define isspace(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_SPACE) : _pctype[_c] & _SPACE)
  232. #define ispunct(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_PUNCT) : _pctype[_c] & _PUNCT)
  233. #define isalnum(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_ALPHA|_DIGIT) : _pctype[_c] & (_ALPHA|_DIGIT))
  234. #define isprint(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT) : _pctype[_c] & (_BLANK|_PUNCT|_ALPHA|_DIGIT))
  235. #define isgraph(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_PUNCT|_ALPHA|_DIGIT) : _pctype[_c] & (_PUNCT|_ALPHA|_DIGIT))
  236. #define iscntrl(_c)     (MB_CUR_MAX > 1 ? _isctype(_c,_CONTROL) : _pctype[_c] & _CONTROL)
  237. #endif  /* __cplusplus */
  238.  
  239. #endif  /* _MAC */
  240.  
  241. #define _tolower(_c)    ( (_c)-'A'+'a' )
  242. #define _toupper(_c)    ( (_c)-'a'+'A' )
  243.  
  244. #define __isascii(_c)   ( (unsigned)(_c) < 0x80 )
  245. #define __toascii(_c)   ( (_c) & 0x7f )
  246.  
  247. #ifndef _WCTYPE_INLINE_DEFINED
  248. #ifndef __cplusplus
  249. #define iswalpha(_c)    ( iswctype(_c,_ALPHA) )
  250. #define iswupper(_c)    ( iswctype(_c,_UPPER) )
  251. #define iswlower(_c)    ( iswctype(_c,_LOWER) )
  252. #define iswdigit(_c)    ( iswctype(_c,_DIGIT) )
  253. #define iswxdigit(_c)   ( iswctype(_c,_HEX) )
  254. #define iswspace(_c)    ( iswctype(_c,_SPACE) )
  255. #define iswpunct(_c)    ( iswctype(_c,_PUNCT) )
  256. #define iswalnum(_c)    ( iswctype(_c,_ALPHA|_DIGIT) )
  257. #define iswprint(_c)    ( iswctype(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT) )
  258. #define iswgraph(_c)    ( iswctype(_c,_PUNCT|_ALPHA|_DIGIT) )
  259. #define iswcntrl(_c)    ( iswctype(_c,_CONTROL) )
  260. #define iswascii(_c)    ( (unsigned)(_c) < 0x80 )
  261. #define isleadbyte(_c)  (_pctype[(unsigned char)(_c)] & _LEADBYTE)
  262. #endif  /* __cplusplus */
  263. #define _WCTYPE_INLINE_DEFINED
  264. #endif  /* _WCTYPE_INLINE_DEFINED */
  265.  
  266. /* MS C version 2.0 extended ctype macros */
  267.  
  268. #define __iscsymf(_c)   (isalpha(_c) || ((_c) == '_'))
  269. #define __iscsym(_c)    (isalnum(_c) || ((_c) == '_'))
  270.  
  271. #endif  /* _CTYPE_DISABLE_MACROS */
  272.  
  273. #ifdef _MT
  274. int __cdecl _tolower_lk(int);                                   /* _MTHREAD_ONLY */
  275. int __cdecl _toupper_lk(int);                                   /* _MTHREAD_ONLY */
  276. #ifndef _MAC
  277. wchar_t __cdecl _towlower_lk(wchar_t);                          /* _MTHREAD_ONLY */
  278. wchar_t __cdecl _towupper_lk(wchar_t);                          /* _MTHREAD_ONLY */
  279. #endif  /* _MAC */
  280. #else  /* _MT */
  281. #define _tolower_lk(c)      tolower(c)                          /* _MTHREAD_ONLY */
  282. #define _toupper_lk(c)      toupper(c)                          /* _MTHREAD_ONLY */
  283. #ifndef _MAC
  284. #define _towlower_lk(c)     towlower(c)                         /* _MTHREAD_ONLY */
  285. #define _towupper_lk(c)     towupper(c)                         /* _MTHREAD_ONLY */
  286. #endif  /* _MAC */
  287. #endif  /* _MT */
  288.  
  289. #if !__STDC__
  290.  
  291. /* Non-ANSI names for compatibility */
  292.  
  293. #ifndef _CTYPE_DEFINED
  294. _CRTIMP int __cdecl isascii(int);
  295. _CRTIMP int __cdecl toascii(int);
  296. _CRTIMP int __cdecl iscsymf(int);
  297. _CRTIMP int __cdecl iscsym(int);
  298. #else  /* _CTYPE_DEFINED */
  299. #define isascii __isascii
  300. #define toascii __toascii
  301. #define iscsymf __iscsymf
  302. #define iscsym  __iscsym
  303. #endif  /* _CTYPE_DEFINED */
  304.  
  305. #endif  /* !__STDC__ */
  306.  
  307. #ifdef __cplusplus
  308. }
  309. #endif  /* __cplusplus */
  310.  
  311.  
  312. #endif  /* _INC_CTYPE */
  313.