ctype.h 1.8 KB

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