home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / GPTX01AS.ZIP / CTYPE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-25  |  3.7 KB  |  109 lines

  1. /* Character classification and correspondance.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    $Id$
  6. */
  7.  
  8. /*
  9.  
  10. These defines replace what is usually <ctype.h>.  They take into account
  11. local character set and possibly 8-bits characters.  There is also a few
  12. defines for foreigh language processing.
  13.  
  14. These defines accept signed characters, unsigned characters or int's having
  15. positive values.  Also, the `is...' defines accept and understand EOF.
  16.  
  17. PLEASE NOTE, however, that the signed character '\377' is quite dangerous,
  18. because several of the following defines will interpret it as EOF.
  19.  
  20. */
  21.  
  22. #define _U 0x01            /* upper case character */
  23. #define _L 0x02            /* lower case character */
  24. #define _N 0x04            /* numeric character */
  25. #define _S 0x08            /* space character */
  26. #define _P 0x10            /* punctuation character */
  27. #define _C 0x20            /* control character */
  28. #define _B 0x40            /* space character */
  29. #define _X 0x80            /* hexadecimal character */
  30.  
  31. /* Table of set of attribute for each character.  */
  32. extern char _ctype_set[];
  33.  
  34. #ifdef MSDOS
  35. extern char _ctype_lower[];    /* lower case equivalents */
  36. extern char _ctype_upper[];    /* upper case equivalents */
  37. #endif
  38. extern char _ctype_base[];    /* characters without diacritics */
  39. extern char _ctype_diac[];    /* diacritic code for each character */
  40.  
  41. /* Returns non zero if c is alphabetic.  */
  42. #define isalpha(c) \
  43.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & (_U | _L)))
  44.  
  45. /* Returns non zero if c is upper case.  */
  46. #define isupper(c) \
  47.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _U))
  48.  
  49. /* Returns non zero if c is lower case.  */
  50. #define islower(c) \
  51.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _L))
  52.  
  53. /* Returns non zero if c is decimal digit (0-9).  */
  54. #define isdigit(c) \
  55.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _N))
  56.  
  57. /* Returns non zero if c is hexadecimal digit (0-9, a-f, A-F).  */
  58. #define isxdigit(c) \
  59.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _X))
  60.  
  61. /* Returns non zero if c is is white space.  */
  62. #define isspace(c) \
  63.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _S))
  64.  
  65. /* Returns non zero if c is punctuation.  */
  66. #define ispunct(c) \
  67.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _P))
  68.  
  69. /* Returns non zero if c is alphanumeric.  */
  70. #define isalnum(c) \
  71.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & (_U | _L | _N)))
  72.  
  73. /* Returns non zero if c is printable, (space included).  */
  74. #define isprint(c) \
  75.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & (_P | _U | _L | _N | _B)))
  76.  
  77. /* Returns non zero if c is grafical, (space excluded).  */
  78. #define isgraph(c) \
  79.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & (_P | _U | _L | _N)))
  80.  
  81. /* Returns non zero if c is control character.  */
  82. #define iscntrl(c) \
  83.   ((c) == EOF ? 0 : (_ctype_set[(unsigned char) c] & _C))
  84.  
  85. /* Returns non zero if c is ASCII character, that is, 7 bits.  */
  86. #define isascii(c) \
  87.   ((c) == EOF ? 0 : (!((c) & ~0177)))
  88.  
  89. /* Returns the upper case value of c, already known to be alphabetic.  */
  90. #ifdef MSDOS
  91. #define toupper(c)   (_ctype_upper[(unsigned char) c])
  92. #else
  93. #define toupper(c)   (islower(c) ? ((c) & ~040) : (c))
  94. #endif
  95.  
  96. /* Returns the lower case value of c, already known to be alphabetic.  */
  97. #ifdef MSDOS
  98. #define tolower(c)   (_ctype_lower[(unsigned char) c])
  99. #else
  100. #define tolower(c)   (isupper(c) ? ((c) | 040) : (c))
  101. #endif
  102.  
  103. /* Returns c without its diacritic.  c is known to be alphabetic.  */
  104. #define tobase(c)     (_ctype_base[(unsigned char) c])
  105.  
  106. /* Returns a diacritic code for c.  c is known to be alphabetic.  */
  107. #define todiac(c)   (_ctype_diac[(unsigned char) c])
  108.  
  109.