ctype_runtime.c (2494B)
1 #include <ctype.h> 2 3 static int same_truth(int a, int b) { return (!!a) == (!!b); } 4 5 static int check_class(int c, int alnum, int alpha, int blank, int cntrl, 6 int digit, int graph, int lower, int print, int punct, 7 int space, int upper, int xdigit) { 8 return same_truth(isalnum(c), alnum) && same_truth(isalpha(c), alpha) && 9 same_truth(isblank(c), blank) && same_truth(iscntrl(c), cntrl) && 10 same_truth(isdigit(c), digit) && same_truth(isgraph(c), graph) && 11 same_truth(islower(c), lower) && same_truth(isprint(c), print) && 12 same_truth(ispunct(c), punct) && same_truth(isspace(c), space) && 13 same_truth(isupper(c), upper) && same_truth(isxdigit(c), xdigit); 14 } 15 16 static int classify_ok(void) { 17 if (!check_class('A', 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1)) return 1; 18 if (!check_class('G', 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0)) return 2; 19 if (!check_class('f', 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1)) return 3; 20 if (!check_class('x', 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0)) return 4; 21 if (!check_class('7', 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1)) return 5; 22 if (!check_class(' ', 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0)) return 6; 23 if (!check_class('\t', 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0)) return 7; 24 if (!check_class('\n', 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0)) return 8; 25 if (!check_class('\v', 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0)) return 9; 26 if (!check_class('\f', 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0)) return 10; 27 if (!check_class('\r', 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0)) return 11; 28 if (!check_class(0x7f, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)) return 12; 29 if (!check_class('!', 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0)) return 13; 30 if (!check_class('~', 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0)) return 14; 31 if (!check_class(0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) return 15; 32 if (!check_class(-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) return 16; 33 return 0; 34 } 35 36 static int case_ok(void) { 37 if (tolower('A') != 'a') return 21; 38 if (tolower('Z') != 'z') return 22; 39 if (tolower('a') != 'a') return 23; 40 if (tolower('7') != '7') return 24; 41 if (tolower(-1) != -1) return 25; 42 if (toupper('a') != 'A') return 26; 43 if (toupper('z') != 'Z') return 27; 44 if (toupper('Z') != 'Z') return 28; 45 if (toupper('#') != '#') return 29; 46 if (toupper(-1) != -1) return 30; 47 return 0; 48 } 49 50 int test_main(void) { 51 int rc = classify_ok(); 52 if (rc != 0) return rc; 53 rc = case_ok(); 54 if (rc != 0) return rc; 55 return 42; 56 }