Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
3d689ed6 ACM |
2 | #ifndef _PERF_SANE_CTYPE_H |
3 | #define _PERF_SANE_CTYPE_H | |
4 | ||
5 | extern const char *graph_line; | |
6 | extern const char *graph_dotted_line; | |
7 | extern const char *spaces; | |
8 | extern const char *dots; | |
9 | ||
10 | /* Sane ctype - no locale, and works with signed chars */ | |
11 | #undef isascii | |
12 | #undef isspace | |
13 | #undef isdigit | |
14 | #undef isxdigit | |
15 | #undef isalpha | |
16 | #undef isprint | |
17 | #undef isalnum | |
18 | #undef islower | |
19 | #undef isupper | |
20 | #undef tolower | |
21 | #undef toupper | |
22 | ||
23 | extern unsigned char sane_ctype[256]; | |
24 | #define GIT_SPACE 0x01 | |
25 | #define GIT_DIGIT 0x02 | |
26 | #define GIT_ALPHA 0x04 | |
27 | #define GIT_GLOB_SPECIAL 0x08 | |
28 | #define GIT_REGEX_SPECIAL 0x10 | |
29 | #define GIT_PRINT_EXTRA 0x20 | |
30 | #define GIT_PRINT 0x3E | |
31 | #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) | |
32 | #define isascii(x) (((x) & ~0x7f) == 0) | |
33 | #define isspace(x) sane_istest(x,GIT_SPACE) | |
34 | #define isdigit(x) sane_istest(x,GIT_DIGIT) | |
35 | #define isxdigit(x) \ | |
36 | (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G') | |
37 | #define isalpha(x) sane_istest(x,GIT_ALPHA) | |
38 | #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) | |
39 | #define isprint(x) sane_istest(x,GIT_PRINT) | |
40 | #define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20)) | |
41 | #define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20)) | |
42 | #define tolower(x) sane_case((unsigned char)(x), 0x20) | |
43 | #define toupper(x) sane_case((unsigned char)(x), 0) | |
44 | ||
45 | static inline int sane_case(int x, int high) | |
46 | { | |
47 | if (sane_istest(x, GIT_ALPHA)) | |
48 | x = (x & ~0x20) | high; | |
49 | return x; | |
50 | } | |
51 | ||
52 | #endif /* _PERF_SANE_CTYPE_H */ |