summaryrefslogtreecommitdiff
path: root/com32/include/ctype.h
blob: 6e0645ee636014cd5c12e4c45a838393adb68fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * ctype.h
 *
 * This assumes ISO 8859-1, being a reasonable superset of ASCII.
 */

#ifndef _CTYPE_H
#define _CTYPE_H

#include <klibc/extern.h>

#ifndef __CTYPE_NO_INLINE
# define __ctype_inline static __inline__
#else
# define __ctype_inline
#endif

/*
 * This relies on the following definitions:
 *
 * cntrl = !print
 * alpha = upper|lower
 * graph = punct|alpha|digit
 * blank = '\t' || ' ' (per POSIX requirement)
 */
enum {
    __ctype_upper = (1 << 0),
    __ctype_lower = (1 << 1),
    __ctype_digit = (1 << 2),
    __ctype_xdigit = (1 << 3),
    __ctype_space = (1 << 4),
    __ctype_print = (1 << 5),
    __ctype_punct = (1 << 6),
    __ctype_cntrl = (1 << 7),
};

extern const unsigned char __ctypes[];

__ctype_inline int isalnum(int __c)
{
    return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower | __ctype_digit);
}

__ctype_inline int isalpha(int __c)
{
    return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
}

__ctype_inline int isascii(int __c)
{
    return !(__c & ~0x7f);
}

__ctype_inline int isblank(int __c)
{
    return (__c == '\t') || (__c == ' ');
}

__ctype_inline int iscntrl(int __c)
{
    return __ctypes[__c + 1] & __ctype_cntrl;
}

__ctype_inline int isdigit(int __c)
{
    return ((unsigned)__c - '0') <= 9;
}

__ctype_inline int isgraph(int __c)
{
    return __ctypes[__c + 1] &
	(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
}

__ctype_inline int islower(int __c)
{
    return __ctypes[__c + 1] & __ctype_lower;
}

__ctype_inline int isprint(int __c)
{
    return __ctypes[__c + 1] & __ctype_print;
}

__ctype_inline int ispunct(int __c)
{
    return __ctypes[__c + 1] & __ctype_punct;
}

__ctype_inline int isspace(int __c)
{
    return __ctypes[__c + 1] & __ctype_space;
}

__ctype_inline int isupper(int __c)
{
    return __ctypes[__c + 1] & __ctype_upper;
}

__ctype_inline int isxdigit(int __c)
{
    return __ctypes[__c + 1] & __ctype_xdigit;
}

/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
#define _toupper(__c) ((__c) & ~32)
#define _tolower(__c) ((__c) | 32)

__ctype_inline int toupper(int __c)
{
    return islower(__c) ? _toupper(__c) : __c;
}

__ctype_inline int tolower(int __c)
{
    return isupper(__c) ? _tolower(__c) : __c;
}

__extern char *skipspace(const char *p);
__extern void chrreplace(char *source, char old, char new);

#endif /* _CTYPE_H */