����14-3 linux/include/ctype.h
1 #ifndef _CTYPE_H
2 #define _CTYPE_H
3
4 #define _U 0x01 /* upper */ // �ñ���λ���ڴ�д�ַ�[A-Z]��
5 #define _L 0x02 /* lower */ // �ñ���λ����Сд�ַ�[a-z]��
6 #define _D 0x04 /* digit */ // �ñ���λ��������[0-9]��
7 #define _C 0x08 /* cntrl */ // �ñ���λ���ڿ����ַ���
8 #define _P 0x10 /* punct */ // �ñ���λ���ڱ���ַ���
9 #define _S 0x20 /* white space (space/lf/tab) */ // �հ��ַ�����ո�\t��\n�ȡ�
10 #define _X 0x40 /* hex digit */ // �ñ���λ����ʮ���������֡�
11 #define _SP 0x80 /* hard space (0x20) */ // �ñ���λ���ڿո��ַ���0x20����
12
13 extern unsigned char _ctype[]; // �ַ��������飨��������������ַ���Ӧ��������ԡ�
14 extern char _ctmp; // һ����ʱ�ַ��������ڶ���lib/ctype.c�У���
15
// ������һЩȷ���ַ����͵ĺꡣ
16 #define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D)) // ���ַ�������[A-Z]��[a-z]��[0-9]��
17 #define isalpha(c) ((_ctype+1)[c]&(_U|_L)) // ���ַ���
18 #define iscntrl(c) ((_ctype+1)[c]&(_C)) // �ǿ����ַ���
19 #define isdigit(c) ((_ctype+1)[c]&(_D)) // �����֡�
20 #define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D)) // ��ͼ���ַ���
21 #define islower(c) ((_ctype+1)[c]&(_L)) // ��Сд�ַ���
22 #define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP)) // �ǿɴ�ӡ�ַ���
23 #define ispunct(c) ((_ctype+1)[c]&(_P)) // �DZ����š�
24 #define isspace(c) ((_ctype+1)[c]&(_S)) // �ǿհ��ַ���ո�,\f,\n,\r,\t,\v��
25 #define isupper(c) ((_ctype+1)[c]&(_U)) // �Ǵ�д�ַ���
26 #define isxdigit(c) ((_ctype+1)[c]&(_D|_X)) // ��ʮ���������֡�
27
// ���������������У������ǰʹ����ǰ��unsigned�������c Ӧ�ü����ţ�����ʾ�� (c)��
// ��Ϊ�ڳ�����c������һ�����ӵı���ʽ�����磬���������a + b�����������ţ����ں궨
// ���б���ˣ�(unsigned) a + b������Ȼ���ԡ��������ž�����ȷ��ʾ��(unsigned)(a + b)��
28 #define isascii(c) (((unsigned) c)<=0x7f) // ��ASCII�ַ���
29 #define toascii(c) (((unsigned) c)&0x7f) // ת����ASCII�ַ���
30
// ���������궨����ʹ��һ����ʱ����_ctmp��ԭ���ǣ��ں궨���У���IJ���ֻ�ܱ�ʹ��һ�Ρ�
// �����ڶ��߳���˵���Dz���ȫ�ģ���Ϊ���������߳̿�����ͬһʱ��ʹ�����������ʱ������
// ��˴�Linux 2.2.x�汾��ʼ����Ϊʹ������������ȡ���������궨�塣
31 #define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp) // ת����Сд�ַ���
32 #define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp) // ת���ɴ�д�ַ���
33
34 #endif
35