home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / Q0 < prev    next >
Encoding:
Text File  |  1992-01-07  |  5.1 KB  |  197 lines

  1. /*
  2.  *   ctype.h -- ANSI 
  3.  *
  4.  *   Functions for handling characters.
  5.  *
  6.  *           Copyright (c) 1990, MetaWare Incorporated
  7.  */
  8.  
  9. #ifndef _CTYPE_H
  10. #define _CTYPE_H
  11.  
  12. #define _UPPER 1
  13. #define _LOWER 2
  14. #define _NUMBER 4
  15. #define _SPACE    8
  16. #define _PUNCT    16
  17. #define _CNTRL    32
  18. #define _HEX    64
  19. #define _BLANK    128
  20.  
  21. extern unsigned char _ctype[256];
  22. #if 0    /* Here are the contents of this external array: */
  23. = {
  24.    _CNTRL, /* \0 */
  25.    _CNTRL, /* \001 */
  26.    _CNTRL, /* \002 */
  27.    _CNTRL, /* \003 */
  28.    _CNTRL, /* \004 */
  29.    _CNTRL, /* \005 */
  30.    _CNTRL, /* \006 */
  31.    _CNTRL, /* \007 - bell */
  32.    _CNTRL, /* \b - backspace */
  33.    _CNTRL | _SPACE, /* \t - horizontal tab */
  34.    _CNTRL | _SPACE, /* \n - newline (linefeed) */
  35.    _CNTRL | _SPACE, /* \v - vertical tab */
  36.    _CNTRL | _SPACE, /* \f - form feed */
  37.    _CNTRL | _SPACE, /* \r - carriage return */
  38.    _CNTRL, /* \016 */
  39.    _CNTRL, /* \017 */
  40.    _CNTRL, /* \020 */
  41.    _CNTRL, /* \021 */
  42.    _CNTRL, /* \022 */
  43.    _CNTRL, /* \023 */
  44.    _CNTRL, /* \024 */
  45.    _CNTRL, /* \025 */
  46.    _CNTRL, /* \026 */
  47.    _CNTRL, /* \027 */
  48.    _CNTRL, /* \030 */
  49.    _CNTRL, /* \031 */
  50.    _CNTRL, /* \032 */
  51.    _CNTRL, /* \033 */
  52.    _CNTRL, /* \034 */
  53.    _CNTRL, /* \035 */
  54.    _CNTRL, /* \036 */
  55.    _CNTRL, /* \037 */
  56.    _SPACE | _BLANK, /* ' ' (space) */
  57.    _PUNCT, /* '!' */
  58.    _PUNCT, /* '"' */
  59.    _PUNCT, /* '#' */
  60.    _PUNCT, /* '$' */
  61.    _PUNCT, /* '%' */
  62.    _PUNCT, /* '&' */
  63.    _PUNCT, /* ''' a single quote */
  64.    _PUNCT, /* '(' */
  65.    _PUNCT, /* ')' */
  66.    _PUNCT, /* '*' */
  67.    _PUNCT, /* '+' */
  68.    _PUNCT, /* ',' */
  69.    _PUNCT, /* '-' */
  70.    _PUNCT, /* '.' */
  71.    _PUNCT, /* '/' */
  72.    _NUMBER, /* '0' */
  73.    _NUMBER, /* '1' */
  74.    _NUMBER, /* '2' */
  75.    _NUMBER, /* '3' */
  76.    _NUMBER, /* '4' */
  77.    _NUMBER, /* '5' */
  78.    _NUMBER, /* '6' */
  79.    _NUMBER, /* '7' */
  80.    _NUMBER,/* '8' */
  81.    _NUMBER,/* '9' */
  82.    _PUNCT, /* ':' */
  83.    _PUNCT, /* ';' */
  84.    _PUNCT, /* '<' */
  85.    _PUNCT, /* '=' */
  86.    _PUNCT, /* '>' */
  87.    _PUNCT, /* '?' */
  88.    _PUNCT, /* '@' */
  89.    _UPPER | _HEX, /* 'A' */
  90.    _UPPER | _HEX, /* 'B' */
  91.    _UPPER | _HEX, /* 'C' */
  92.    _UPPER | _HEX, /* 'D' */
  93.    _UPPER | _HEX, /* 'E' */
  94.    _UPPER | _HEX, /* 'F' */
  95.    _UPPER, /* 'G' */
  96.    _UPPER, /* 'H' */
  97.    _UPPER, /* 'I' */
  98.    _UPPER, /* 'J' */
  99.    _UPPER, /* 'K' */
  100.    _UPPER, /* 'L' */
  101.    _UPPER, /* 'M' */
  102.    _UPPER, /* 'N' */
  103.    _UPPER, /* 'O' */
  104.    _UPPER, /* 'P' */
  105.    _UPPER, /* 'Q' */
  106.    _UPPER, /* 'R' */
  107.    _UPPER, /* 'S' */
  108.    _UPPER, /* 'T' */
  109.    _UPPER, /* 'U' */
  110.    _UPPER, /* 'V' */
  111.    _UPPER, /* 'W' */
  112.    _UPPER, /* 'X' */
  113.    _UPPER, /* 'Y' */
  114.    _UPPER, /* 'Z' */
  115.    _PUNCT, /* '[' */
  116.    _PUNCT, /* '\' */
  117.    _PUNCT, /* ']' */
  118.    _PUNCT, /* '^' */
  119.    _PUNCT, /* '_' */
  120.    _PUNCT, /* '`' */
  121.    _LOWER | _HEX, /* 'a' */
  122.    _LOWER | _HEX, /* 'b' */
  123.    _LOWER | _HEX, /* 'c' */
  124.    _LOWER | _HEX, /* 'd' */
  125.    _LOWER | _HEX, /* 'e' */
  126.    _LOWER | _HEX, /* 'f' */
  127.    _LOWER, /* 'g' */
  128.    _LOWER, /* 'h' */
  129.    _LOWER, /* 'i' */
  130.    _LOWER, /* 'j' */
  131.    _LOWER, /* 'k' */
  132.    _LOWER, /* 'l' */
  133.    _LOWER, /* 'm' */
  134.    _LOWER, /* 'n' */
  135.    _LOWER, /* 'o' */
  136.    _LOWER, /* 'p' */
  137.    _LOWER, /* 'q' */
  138.    _LOWER, /* 'r' */
  139.    _LOWER, /* 's' */
  140.    _LOWER, /* 't' */
  141.    _LOWER, /* 'u' */
  142.    _LOWER, /* 'v' */
  143.    _LOWER, /* 'w' */
  144.    _LOWER, /* 'x' */
  145.    _LOWER, /* 'y' */
  146.    _LOWER, /* 'z' */
  147.    _PUNCT, /* '{' */
  148.    _PUNCT, /* '|' */
  149.    _PUNCT, /* '}' */
  150.    _PUNCT, /* '~' */
  151.    _CNTRL /* \177 */
  152.    };
  153. #endif
  154.  
  155. extern  int    isupper(int __c);
  156. extern  int    islower(int __c);
  157. extern  int    isalpha(int __c);
  158. extern  int    isdigit(int __c);
  159. extern  int     isxdigit(int __c);
  160. extern  int    isspace(int __c);
  161. extern  int     ispunct(int __c);
  162. extern  int     isalnum(int __c);
  163. extern  int    isgraph(int __c);
  164. extern  int    isprint(int __c);
  165. extern     int     iscntrl(int __c);
  166. extern    int    toupper(int __c);
  167. extern    int    tolower(int __c);
  168. extern  int    _isascii(int __c);
  169. extern  int    _toupper(int __c);
  170. extern  int    _tolower(int __c);
  171.  
  172. #define isupper(c)    (_ctype[(c) & 0XFF] & _UPPER)
  173. #define islower(c)    (_ctype[(c) & 0XFF] & _LOWER)
  174. #define isalpha(c)    (_ctype[(c) & 0XFF] & (_UPPER | _LOWER))
  175. #define isdigit(c)    (_ctype[(c) & 0XFF] & _NUMBER)
  176. #define isxdigit(c)    (_ctype[(c) & 0XFF] & (_NUMBER | _HEX))
  177. #define isspace(c)    (_ctype[(c) & 0XFF] & _SPACE)
  178. #define ispunct(c)    (_ctype[(c) & 0XFF] & _PUNCT)
  179. #define isalnum(c)    (_ctype[(c) & 0XFF] & (_UPPER | _LOWER | _NUMBER))
  180. #define isgraph(c)    (_ctype[(c) & 0XFF] & (_UPPER | _LOWER | _NUMBER | _PUNCT))
  181. #define isprint(c)    (_ctype[(c) & 0XFF] & (_UPPER | _LOWER | _NUMBER | _PUNCT | _BLANK))
  182. #define iscntrl(c)    (_ctype[(c) & 0XFF] & _CNTRL)
  183. #define _toupper(c)    ((c) - 'a' + 'A')
  184. #define _tolower(c)    ((c) - 'A' + 'a')
  185. /* Warning:  THE ARGUMENT IS EVALUATED TWICE here. */
  186. #define toupper(c)    (islower(c) ? _toupper(c) : (c))
  187. #define tolower(c)    (isupper(c) ? _tolower(c) : (c))
  188.  
  189. /* _isodigit is not ANSI Standard.  */
  190. #define _isodigit(c) ((unsigned int)(((c)&0xFF) - '0') <= 7)
  191. #define _isascii(c)    ((unsigned) (c) <= 0177)
  192. #ifdef __HIGHC__
  193. #define isascii(c)    ((unsigned) (c) <= 0177)
  194. #endif
  195.  
  196. #endif /* _CTYPE_H */
  197.