You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.8KB

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