ctype.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. #ifndef _CTYPE_H
  7. #define _CTYPE_H
  8. /* File : ctypes.h
  9. Author : Richard A. O'Keefe.
  10. Updated: 26 April 1984
  11. Purpose: Reimplement the UNIX ctype(3) library.
  12. isaneol(c) means that c is a line terminating character.
  13. isalnum, ispunct, isspace, and isaneol are defined on the
  14. range -1..127, i.e. on ASCII U {EOF}, while all the other
  15. macros are defined for any integer.
  16. isodigit(c) checks for Octal digits.
  17. isxdigit(c) checkx for heXadecimal digits.
  18. */
  19. #define isdigit(c) ((unsigned)((c)-'0') < 10)
  20. #define islower(c) ((unsigned)((c)-'a') < 26)
  21. #define isupper(c) ((unsigned)((c)-'A') < 26)
  22. #define isprint(c) ((unsigned)((c)-' ') < 95)
  23. #define iscntrl(c) ((unsigned)((c)-' ') >= 95)
  24. #define isascii(c) ((unsigned)(c) < 128)
  25. #define isalpha(c) ((unsigned)(((c)|32)-'a') < 26)
  26. extern char _c2type[];
  27. #define isalnum(c) (_c2type[(c)+1] < 36)
  28. #define ispunct(c) (_c2type[(c)+1] == 36)
  29. #define isspace(c) (_c2type[(c)+1] > 37)
  30. #define isaneol(c) (_c2type[(c)+1] > 38)
  31. #define isxdigit(c) (_c2type[(c)+1] < 16)
  32. #define isodigit(c) ((unsigned)((c)-'0') < 8)
  33. /* The following "conversion" macros have been in some versions of UNIX
  34. but are not in all. tocntrl is new. The original motivation for ^?
  35. being a name for DEL was that (x)^64 mapped A..Z to ^A..^Z and also
  36. ? to DEL. The trouble is that this trick doesn't work for lower case
  37. letters. The version given here is not mine. I wish it was. It has
  38. the nice property that DEL is mapped to itself (so does EOF).
  39. tolower(c) and toupper(c) are only defined when isalpha(c).
  40. */
  41. #define tolower(c) ((c)|32)
  42. #define toupper(c) ((c)&~32)
  43. #define tocntrl(c) (((((c)+1)&~96)-1)&127)
  44. #define toascii(c) ((c)&127)
  45. #endif /* _CTYPE_H */