Subversion Repositories Kolibri OS

Rev

Rev 4874 | Rev 6099 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #ifndef _CTYPE_H_
  2. #define _CTYPE_H_
  3.  
  4. #include "_ansi.h"
  5.  
  6. _BEGIN_STD_C
  7.  
  8. int _EXFUN(isalnum, (int __c));
  9. int _EXFUN(isalpha, (int __c));
  10. int _EXFUN(iscntrl, (int __c));
  11. int _EXFUN(isdigit, (int __c));
  12. int _EXFUN(isgraph, (int __c));
  13. int _EXFUN(islower, (int __c));
  14. int _EXFUN(isprint, (int __c));
  15. int _EXFUN(ispunct, (int __c));
  16. int _EXFUN(isspace, (int __c));
  17. int _EXFUN(isupper, (int __c));
  18. int _EXFUN(isxdigit,(int __c));
  19. int _EXFUN(tolower, (int __c));
  20. int _EXFUN(toupper, (int __c));
  21.  
  22. #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
  23. int _EXFUN(isblank, (int __c));
  24. #endif
  25.  
  26. #ifndef __STRICT_ANSI__
  27. int _EXFUN(isascii, (int __c));
  28. int _EXFUN(toascii, (int __c));
  29. #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
  30. #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
  31. #endif
  32.  
  33. #define _U      01
  34. #define _L      02
  35. #define _N      04
  36. #define _S      010
  37. #define _P      020
  38. #define _C      040
  39. #define _X      0100
  40. #define _B      0200
  41.  
  42. extern
  43. #ifndef _MB_CAPABLE
  44. _CONST
  45. #endif
  46. __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__) && \
  73.     (!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
  74. #define isblank(__c) \
  75.   __extension__ ({ __typeof__ (__c) __x = (__c);                \
  76.         (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
  77. #endif
  78.  
  79.  
  80. /* Non-gcc versions will get the library versions, and will be
  81.    slightly slower.  These macros are not NLS-aware so they are
  82.    disabled if the system supports the extended character sets. */
  83. # if defined(__GNUC__)
  84. #  if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
  85. #   define toupper(__c) \
  86.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  87.       islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
  88. #   define tolower(__c) \
  89.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  90.       isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
  91. #  else /* _MB_EXTENDED_CHARSETS* */
  92. /* Allow a gcc warning if the user passed 'char', but defer to the
  93.    function.  */
  94. #   define toupper(__c) \
  95.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  96.       (void) __ctype_ptr__[__x]; (toupper) (__x);})
  97. #   define tolower(__c) \
  98.   __extension__ ({ __typeof__ (__c) __x = (__c);        \
  99.       (void) __ctype_ptr__[__x]; (tolower) (__x);})
  100. #  endif /* _MB_EXTENDED_CHARSETS* */
  101. # endif /* __GNUC__ */
  102. #endif /* !__cplusplus */
  103.  
  104. #ifndef __STRICT_ANSI__
  105. #define isascii(__c)    ((unsigned)(__c)<=0177)
  106. #define toascii(__c)    ((__c)&0177)
  107. #endif
  108.  
  109. /* For C++ backward-compatibility only.  */
  110. extern  __IMPORT _CONST char    _ctype_[];
  111.  
  112. _END_STD_C
  113.  
  114. #endif /* _CTYPE_H_ */
  115.