1 /* The <ctype.h> header file defines some macros used to identify characters.
2 * It works by using a table stored in chartab.c. When a character is presented
3 * to one of these macros, the character is used as an index into the table
4 * (__ctype) to retrieve a byte. The relevant bit is then extracted.
14 extern char __ctype
[]; /* property array defined in chartab.c */
16 #define _U 0x01 /* this bit is for upper-case letters [A-Z] */
17 #define _L 0x02 /* this bit is for lower-case letters [a-z] */
18 #define _N 0x04 /* this bit is for numbers [0-9] */
19 #define _S 0x08 /* this bit is for white space \t \n \f etc */
20 #define _P 0x10 /* this bit is for punctuation characters */
21 #define _C 0x20 /* this bit is for control characters */
22 #define _X 0x40 /* this bit is for hex digits [a-f] and [A-F]*/
24 /* Function Prototypes (have to go before the macros). */
25 _PROTOTYPE( int isalnum
, (int _c
) ); /* alphanumeric [a-z], [A-Z], [0-9] */
26 _PROTOTYPE( int isalpha
, (int _c
) ); /* alphabetic */
27 _PROTOTYPE( int isblank
, (int _c
) ); /* blank space */
28 _PROTOTYPE( int iscntrl
, (int _c
) ); /* control characters */
29 _PROTOTYPE( int isdigit
, (int _c
) ); /* digit [0-9] */
30 _PROTOTYPE( int isgraph
, (int _c
) ); /* graphic character */
31 _PROTOTYPE( int islower
, (int _c
) ); /* lower-case letter [a-z] */
32 _PROTOTYPE( int isprint
, (int _c
) ); /* printable character */
33 _PROTOTYPE( int ispunct
, (int _c
) ); /* punctuation mark */
34 _PROTOTYPE( int isspace
, (int _c
) ); /* white space sp, \f, \n, \r, \t, \v*/
35 _PROTOTYPE( int isupper
, (int _c
) ); /* upper-case letter [A-Z] */
36 _PROTOTYPE( int isxdigit
,(int _c
) ); /* hex digit [0-9], [a-f], [A-F] */
37 _PROTOTYPE( int tolower
, (int _c
) ); /* convert to lower-case */
38 _PROTOTYPE( int toupper
, (int _c
) ); /* convert to upper-case */
39 _PROTOTYPE( int toascii
, (int _c
) ); /* convert to 7-bit ASCII */
41 /* Macros for identifying character classes. */
42 #define isalnum(c) ((__ctype+1)[c]&(_U|_L|_N))
43 #define isalpha(c) ((__ctype+1)[c]&(_U|_L))
44 #define iscntrl(c) ((__ctype+1)[c]&_C)
45 #define isgraph(c) ((__ctype+1)[c]&(_P|_U|_L|_N))
46 #define ispunct(c) ((__ctype+1)[c]&_P)
47 #define isspace(c) ((__ctype+1)[c]&_S)
48 #define isxdigit(c) ((__ctype+1)[c]&(_N|_X))
50 #define isdigit(c) ((unsigned) ((c)-'0') < 10)
51 #define islower(c) ((unsigned) ((c)-'a') < 26)
52 #define isupper(c) ((unsigned) ((c)-'A') < 26)
53 #define isprint(c) ((unsigned) ((c)-' ') < 95)
54 #define isascii(c) ((unsigned) (c) < 128)
55 #define isblank(c) ((c) == ' ' || (c) == '\t')
57 #define toascii(c) ((c) & 0x7f)