source: trunk/minix/include/ctype.h@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 2.5 KB
Line 
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.
5 */
6
7#ifndef _CTYPE_H
8#define _CTYPE_H
9
10#ifndef _ANSI_H
11#include <ansi.h>
12#endif
13
14extern char __ctype[]; /* property array defined in chartab.c */
15
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]*/
23
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 iscntrl, (int _c) ); /* control characters */
28_PROTOTYPE( int isdigit, (int _c) ); /* digit [0-9] */
29_PROTOTYPE( int isgraph, (int _c) ); /* graphic character */
30_PROTOTYPE( int islower, (int _c) ); /* lower-case letter [a-z] */
31_PROTOTYPE( int isprint, (int _c) ); /* printable character */
32_PROTOTYPE( int ispunct, (int _c) ); /* punctuation mark */
33_PROTOTYPE( int isspace, (int _c) ); /* white space sp, \f, \n, \r, \t, \v*/
34_PROTOTYPE( int isupper, (int _c) ); /* upper-case letter [A-Z] */
35_PROTOTYPE( int isxdigit,(int _c) ); /* hex digit [0-9], [a-f], [A-F] */
36_PROTOTYPE( int tolower, (int _c) ); /* convert to lower-case */
37_PROTOTYPE( int toupper, (int _c) ); /* convert to upper-case */
38_PROTOTYPE( int toascii, (int _c) ); /* convert to 7-bit ASCII */
39
40/* Macros for identifying character classes. */
41#define isalnum(c) ((__ctype+1)[c]&(_U|_L|_N))
42#define isalpha(c) ((__ctype+1)[c]&(_U|_L))
43#define iscntrl(c) ((__ctype+1)[c]&_C)
44#define isgraph(c) ((__ctype+1)[c]&(_P|_U|_L|_N))
45#define ispunct(c) ((__ctype+1)[c]&_P)
46#define isspace(c) ((__ctype+1)[c]&_S)
47#define isxdigit(c) ((__ctype+1)[c]&(_N|_X))
48
49#define isdigit(c) ((unsigned) ((c)-'0') < 10)
50#define islower(c) ((unsigned) ((c)-'a') < 26)
51#define isupper(c) ((unsigned) ((c)-'A') < 26)
52#define isprint(c) ((unsigned) ((c)-' ') < 95)
53#define isascii(c) ((unsigned) (c) < 128)
54
55#define toascii(c) ((c) & 0x7f)
56
57#endif /* _CTYPE_H */
Note: See TracBrowser for help on using the repository browser.