ctype.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* ctype.h
  2. * Character classification and conversion */
  3. #ifndef __CTYPE_H
  4. #define __CTYPE_H
  5. /* For now, just always use the functions instead of the macros...*/
  6. #define USE_CTYPE_C_FUNCTIONS
  7. #ifdef USE_CTYPE_C_FUNCTIONS
  8. /* function prototpes */
  9. extern int isalnum(int c);
  10. extern int isalpha(int c);
  11. extern int isascii(int c);
  12. extern int iscntrl(int c);
  13. extern int isdigit(int c);
  14. extern int isgraph(int c);
  15. extern int islower(int c);
  16. extern int isprint(int c);
  17. extern int ispunct(int c);
  18. extern int isspace(int c);
  19. extern int isupper(int c);
  20. extern int isxdigit(int c);
  21. extern int isxlower(int c);
  22. extern int isxupper(int c);
  23. extern int toascii(int c);
  24. extern int tolower(int c);
  25. extern int toupper(int c);
  26. #else
  27. /* macro definitions */
  28. #define isalnum(c) (isalpha(c) || isdigit(c))
  29. #define isalpha(c) (isupper(c) || islower(c))
  30. #define isascii(c) (c > 0 && c <= 0x7f)
  31. #define iscntrl(c) ((c > 0) && ((c <= 0x1F) || (c == 0x7f)))
  32. #define isdigit(c) (c >= '0' && c <= '9')
  33. #define isgraph(c) (c != ' ' && isprint(c))
  34. #define islower(c) (c >= 'a' && c <= 'z')
  35. #define isprint(c) (c >= ' ' && c <= '~')
  36. #define ispunct(c) ((c > ' ' && c <= '~') && !isalnum(c))
  37. #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||\
  38. c == '\t' || c == '\v')
  39. #define isupper(c) (c >= 'A' && c <= 'Z')
  40. #define isxdigit(c) (isxupper(c) || isxlower(c))
  41. #define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
  42. #define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
  43. #define toascii(c) (c & 0x7f)
  44. #define tolower(c) (isupper(c) ? ( c - 'A' + 'a') : (c))
  45. #define toupper(c) (islower(c) ? (c - 'a' + 'A') : (c))
  46. #endif
  47. #endif /* __CTYPE_H */