Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1408 serge 1
/* The  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
 
11
extern char	__ctype[];	/* property array defined in chartab.c */
12
 
13
#define _U		0x01	/* this bit is for upper-case letters [A-Z] */
14
#define _L		0x02	/* this bit is for lower-case letters [a-z] */
15
#define _N		0x04	/* this bit is for numbers [0-9] */
16
#define _S		0x08	/* this bit is for white space \t \n \f etc */
17
#define _P		0x10	/* this bit is for punctuation characters */
18
#define _C		0x20	/* this bit is for control characters */
19
#define _X		0x40	/* this bit is for hex digits [a-f] and [A-F]*/
20
 
21
 
22
/* Macros for identifying character classes. */
23
#define isalnum(c)	((__ctype+1)[c]&(_U|_L|_N))
24
#define isalpha(c)	((__ctype+1)[c]&(_U|_L))
25
#define iscntrl(c)	((__ctype+1)[c]&_C)
26
#define isgraph(c)	((__ctype+1)[c]&(_P|_U|_L|_N))
27
#define ispunct(c)	((__ctype+1)[c]&_P)
28
#define isspace(c)	((__ctype+1)[c]&_S)
29
#define isxdigit(c)	((__ctype+1)[c]&(_N|_X))
30
 
31
#define isdigit(c)	((unsigned) ((c)-'0') < 10)
32
#define islower(c)	((unsigned) ((c)-'a') < 26)
33
#define isupper(c)	((unsigned) ((c)-'A') < 26)
34
#define isprint(c)	((unsigned) ((c)-' ') < 95)
35
#define isascii(c)	((unsigned) (c) < 128)
36
 
37
#define toascii(c)	((c) & 0x7f)
38
 
39
static inline int toupper(int c)
40
{
41
    return islower(c) ? c - 'a' + 'A' : c ;
42
}
43
 
44
#endif /* _CTYPE_H */