source: branches/minix3-book/include/ctype.h@ 9

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

Importazione sorgenti libro

File size: 2.4 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
39/* Macros for identifying character classes. */
40#define isalnum(c) ((__ctype+1)[c]&(_U|_L|_N))
41#define isalpha(c) ((__ctype+1)[c]&(_U|_L))
42#define iscntrl(c) ((__ctype+1)[c]&_C)
43#define isgraph(c) ((__ctype+1)[c]&(_P|_U|_L|_N))
44#define ispunct(c) ((__ctype+1)[c]&_P)
45#define isspace(c) ((__ctype+1)[c]&_S)
46#define isxdigit(c) ((__ctype+1)[c]&(_N|_X))
47
48#define isdigit(c) ((unsigned) ((c)-'0') < 10)
49#define islower(c) ((unsigned) ((c)-'a') < 26)
50#define isupper(c) ((unsigned) ((c)-'A') < 26)
51#define isprint(c) ((unsigned) ((c)-' ') < 95)
52#define isascii(c) ((unsigned) (c) < 128)
53
54#endif /* _CTYPE_H */
Note: See TracBrowser for help on using the repository browser.