Subversion Repositories Kolibri OS

Rev

Rev 6330 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #ifndef _CTYPE_H_
  2. #define _CTYPE_H_
  3.  
  4. #include "_ansi.h"
  5. #include <sys/cdefs.h>
  6.  
  7. _BEGIN_STD_C
  8.  
  9. int _EXFUN(isalnum, (int __c));
  10. int _EXFUN(isalpha, (int __c));
  11. int _EXFUN(iscntrl, (int __c));
  12. int _EXFUN(isdigit, (int __c));
  13. int _EXFUN(isgraph, (int __c));
  14. int _EXFUN(islower, (int __c));
  15. int _EXFUN(isprint, (int __c));
  16. int _EXFUN(ispunct, (int __c));
  17. int _EXFUN(isspace, (int __c));
  18. int _EXFUN(isupper, (int __c));
  19. int _EXFUN(isxdigit,(int __c));
  20. int _EXFUN(tolower, (int __c));
  21. int _EXFUN(toupper, (int __c));
  22.  
  23. #if __ISO_C_VISIBLE >= 1999
  24. int _EXFUN(isblank, (int __c));
  25. #endif
  26.  
  27. #if __MISC_VISIBLE || __XSI_VISIBLE
  28. int _EXFUN(isascii, (int __c));
  29. int _EXFUN(toascii, (int __c));
  30. #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
  31. #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
  32. #endif
  33.  
  34. #define _U      01
  35. #define _L      02
  36. #define _N      04
  37. #define _S      010
  38. #define _P      020
  39. #define _C      040
  40. #define _X      0100
  41. #define _B      0200
  42.  
  43. #ifndef _MB_CAPABLE
  44. _CONST
  45. #endif
  46. extern __IMPORT char   *__ctype_ptr__;
  47.  
  48. #ifndef __cplusplus
  49. /* These macros are intentionally written in a manner that will trigger
  50.    a gcc -Wall warning if the user mistakenly passes a 'char' instead
  51.    of an int containing an 'unsigned char'.  Note that the sizeof will
  52.    always be 1, which is what we want for mapping EOF to __ctype_ptr__[0];
  53.    the use of a raw index inside the sizeof triggers the gcc warning if
  54.    __c was of type char, and sizeof masks side effects of the extra __c.
  55.    Meanwhile, the real index to __ctype_ptr__+1 must be cast to int,
  56.    since isalpha(0x100000001LL) must equal isalpha(1), rather than being
  57.    an out-of-bounds reference on a 64-bit machine.  */
  58. #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])
  59.  
  60. #define isalpha(__c)    (__ctype_lookup(__c)&(_U|_L))
  61. #define isupper(__c)    ((__ctype_lookup(__c)&(_U|_L))==_U)
  62. #define islower(__c)    ((__ctype_lookup(__c)&(_U|_L))==_L)
  63. #define isdigit(__c)    (__ctype_lookup(__c)&_N)
  64. #define isxdigit(__c)   (__ctype_lookup(__c)&(_X|_N))
  65. #define isspace(__c)    (__ctype_lookup(__c)&_S)
  66. #define ispunct(__c)    (__ctype_lookup(__c)&_P)
  67. #define isalnum(__c)    (__ctype_lookup(__c)&(_U|_L|_N))
  68. #define isprint(__c)    (__ctype_lookup(__c)&(_P|_U|_L|_N|_B))
  69. #define isgraph(__c)    (__ctype_lookup(__c)&(_P|_U|_L|_N))
  70. #define iscntrl(__c)    (__ctype_lookup(__c)&_C)
  71.  
  72. #if defined(__GNUC__) && __ISO_C_VISIBLE >= 1999
  73. #define isblank(__c) \
  74.   __extension__ ({ __typeof__ (__c) __x = (__c);                \
  75.         (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
  76. #endif
  77.  
  78.  
  79. /* Non-gcc versions will get the library versions, and will be
  80.    slightly slower.  These macros are not NLS-aware so they are
  81.    disabled if the system supports the extended character sets. */
  82. # if defined(__GNUC__)
  83. #  if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
  84. #   define toupper(__c) \
  85.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  86.       islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
  87. #   define tolower(__c) \
  88.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  89.       isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
  90. #  else /* _MB_EXTENDED_CHARSETS* */
  91. /* Allow a gcc warning if the user passed 'char', but defer to the
  92.    function.  */
  93. #   define toupper(__c) \
  94.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  95.       (void) __ctype_ptr__[__x]; (toupper) (__x);})
  96. #   define tolower(__c) \
  97.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  98.       (void) __ctype_ptr__[__x]; (tolower) (__x);})
  99. #  endif /* _MB_EXTENDED_CHARSETS* */
  100. # endif /* __GNUC__ */
  101.  
  102. #if __MISC_VISIBLE || __XSI_VISIBLE
  103. #define isascii(__c)    ((unsigned)(__c)<=0177)
  104. #define toascii(__c)    ((__c)&0177)
  105. #endif
  106.  
  107. #endif /* !__cplusplus */
  108.  
  109. /* For C++ backward-compatibility only.  */
  110. extern  __IMPORT _CONST char    _ctype_[];
  111.  
  112. _END_STD_C
  113.  
  114. #endif /* _CTYPE_H_ */
  115.