ctype.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "test_helpers.h"
  5. struct test_case {
  6. int c;
  7. int isalnum;
  8. int isalpha;
  9. int isascii;
  10. int isblank;
  11. int iscntrl;
  12. int isdigit;
  13. int isgraph;
  14. int islower;
  15. int isprint;
  16. int ispunct;
  17. int isspace;
  18. int isupper;
  19. int isxdigit;
  20. int toascii;
  21. int tolower;
  22. int toupper;
  23. } test_cases[] = {
  24. // a a a b c d g l p p s u x t t t
  25. // l l s l n i r o r u p p d o o o
  26. // n p c a t g a w i n a p i a l u
  27. // u h i n r i p e n c c e g s o p
  28. // m a i k l t h r t t e r i c w p
  29. { 0x00, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, 0x00 },
  30. { 0x01, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x01, 0x01 },
  31. { 0x02, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x02, 0x02, 0x02 },
  32. { 0x03, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x03, 0x03, 0x03 },
  33. { 0x04, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x04, 0x04 },
  34. { 0x05, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x05, 0x05, 0x05 },
  35. { 0x06, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x06, 0x06, 0x06 },
  36. { 0x07, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x07, 0x07, 0x07 },
  37. { 0x08, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x08, 0x08 },
  38. { 0x09, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0x09, 0x09, 0x09 },
  39. { 0x0A, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0x0A, 0x0A, 0x0A },
  40. { 0x0B, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0x0B, 0x0B, 0x0B },
  41. { 0x0C, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0x0C, 0x0C, 0x0C },
  42. { 0x0D, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0x0D, 0x0D, 0x0D },
  43. { 0x0E, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x0E, 0x0E, 0x0E },
  44. { 0x0F, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x0F, 0x0F, 0x0F },
  45. { 0x10, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0x10, 0x10 },
  46. { 0x11, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x11, 0x11 },
  47. { 0x12, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x12, 0x12, 0x12 },
  48. { 0x13, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x13, 0x13, 0x13 },
  49. { 0x14, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x14, 0x14, 0x14 },
  50. { 0x15, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x15, 0x15, 0x15 },
  51. { 0x16, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x16, 0x16, 0x16 },
  52. { 0x17, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x17, 0x17, 0x17 },
  53. { 0x18, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x18, 0x18, 0x18 },
  54. { 0x19, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x19, 0x19, 0x19 },
  55. { 0x1A, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x1A, 0x1A, 0x1A },
  56. { 0x1B, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x1B, 0x1B, 0x1B },
  57. { 0x1C, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x1C, 0x1C, 0x1C },
  58. { 0x1D, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x1D, 0x1D, 0x1D },
  59. { 0x1E, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x1E, 0x1E, 0x1E },
  60. { 0x1F, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x1F, 0x1F, 0x1F },
  61. { ' ', 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, ' ', ' ', ' ' },
  62. { '!', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '!', '!', '!' },
  63. { '"', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '"', '"', '"' },
  64. { '#', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '#', '#', '#' },
  65. { '$', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '$', '$', '$' },
  66. { '%', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '%', '%', '%' },
  67. { '&', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '&', '&', '&' },
  68. { '\'', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '\'', '\'', '\'' },
  69. { '(', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '(', '(', '(' },
  70. { ')', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, ')', ')', ')' },
  71. { '*', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '*', '*', '*' },
  72. { '+', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '+', '+', '+' },
  73. { ',', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, ',', ',', ',' },
  74. { '-', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '-', '-', '-' },
  75. { '.', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '.', '.', '.' },
  76. { '/', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '/', '/', '/' },
  77. { '0', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '0', '0', '0' },
  78. { '1', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '1', '1', '1' },
  79. { '2', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '2', '2', '2' },
  80. { '3', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '3', '3', '3' },
  81. { '4', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '4', '4', '4' },
  82. { '5', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '5', '5', '5' },
  83. { '6', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '6', '6', '6' },
  84. { '7', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '7', '7', '7' },
  85. { '8', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '8', '8', '8' },
  86. { '9', 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, '9', '9', '9' },
  87. { ':', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, ':', ':', ':' },
  88. { ';', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, ';', ';', ';' },
  89. { '<', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '<', '<', '<' },
  90. { '=', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '=', '=', '=' },
  91. { '>', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '>', '>', '>' },
  92. { '?', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '?', '?', '?' },
  93. { '@', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '@', '@', '@' },
  94. { 'A', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 'A', 'a', 'A' },
  95. { 'B', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 'B', 'b', 'B' },
  96. { 'C', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 'C', 'c', 'C' },
  97. { 'D', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 'D', 'd', 'D' },
  98. { 'E', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 'E', 'e', 'E' },
  99. { 'F', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 'F', 'f', 'F' },
  100. { 'G', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'G', 'g', 'G' },
  101. { 'H', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'H', 'h', 'H' },
  102. { 'I', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'I', 'i', 'I' },
  103. { 'J', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'J', 'j', 'J' },
  104. { 'K', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'K', 'k', 'K' },
  105. { 'L', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'L', 'l', 'L' },
  106. { 'M', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'M', 'm', 'M' },
  107. { 'N', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'N', 'n', 'N' },
  108. { 'O', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'O', 'o', 'O' },
  109. { 'P', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'P', 'p', 'P' },
  110. { 'Q', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'Q', 'q', 'Q' },
  111. { 'R', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'R', 'r', 'R' },
  112. { 'S', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'S', 's', 'S' },
  113. { 'T', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'T', 't', 'T' },
  114. { 'U', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'U', 'u', 'U' },
  115. { 'V', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'V', 'v', 'V' },
  116. { 'W', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'W', 'w', 'W' },
  117. { 'X', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'X', 'x', 'X' },
  118. { 'Y', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'Y', 'y', 'Y' },
  119. { 'Z', 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 'Z', 'z', 'Z' },
  120. { '[', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '[', '[', '[' },
  121. { '\\', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '\\', '\\', '\\' },
  122. { ']', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, ']', ']', ']' },
  123. { '^', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '^', '^', '^' },
  124. { '_', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '_', '_', '_' },
  125. { '`', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '`', '`', '`' },
  126. { 'a', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 'a', 'a', 'A' },
  127. { 'b', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 'b', 'b', 'B' },
  128. { 'c', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 'c', 'c', 'C' },
  129. { 'd', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 'd', 'd', 'D' },
  130. { 'e', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 'e', 'e', 'E' },
  131. { 'f', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 'f', 'f', 'F' },
  132. { 'g', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'g', 'g', 'G' },
  133. { 'h', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'h', 'h', 'H' },
  134. { 'i', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'i', 'i', 'I' },
  135. { 'j', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'j', 'j', 'J' },
  136. { 'k', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'k', 'k', 'K' },
  137. { 'l', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'l', 'l', 'L' },
  138. { 'm', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'm', 'm', 'M' },
  139. { 'n', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'n', 'n', 'N' },
  140. { 'o', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'o', 'o', 'O' },
  141. { 'p', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'p', 'p', 'P' },
  142. { 'q', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'q', 'q', 'Q' },
  143. { 'r', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'r', 'r', 'R' },
  144. { 's', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 's', 's', 'S' },
  145. { 't', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 't', 't', 'T' },
  146. { 'u', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'u', 'u', 'U' },
  147. { 'v', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'v', 'v', 'V' },
  148. { 'w', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'w', 'w', 'W' },
  149. { 'x', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'x', 'x', 'X' },
  150. { 'y', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'y', 'y', 'Y' },
  151. { 'z', 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 'z', 'z', 'Z' },
  152. { '{', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '{', '{', '{' },
  153. { '|', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '|', '|', '|' },
  154. { '}', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '}', '}', '}' },
  155. { '~', 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, '~', '~', '~' },
  156. { 0x7F, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x7F, 0x7F, 0x7F },
  157. { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x80, 0x80 },
  158. { 0x81, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x81, 0x81 },
  159. { 0x82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02, 0x82, 0x82 },
  160. { 0x83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03, 0x83, 0x83 },
  161. { 0x84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x84, 0x84 },
  162. { 0x85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x05, 0x85, 0x85 },
  163. { 0x86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x06, 0x86, 0x86 },
  164. { 0x87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x07, 0x87, 0x87 },
  165. { 0x88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x88, 0x88 },
  166. { 0x89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x09, 0x89, 0x89 },
  167. { 0x8A, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0A, 0x8A, 0x8A },
  168. { 0x8B, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0B, 0x8B, 0x8B },
  169. { 0x8C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0C, 0x8C, 0x8C },
  170. { 0x8D, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0D, 0x8D, 0x8D },
  171. { 0x8E, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0E, 0x8E, 0x8E },
  172. { 0x8F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0F, 0x8F, 0x8F },
  173. { 0x90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0x90, 0x90 },
  174. { 0x91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x91, 0x91 },
  175. { 0x92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x12, 0x92, 0x92 },
  176. { 0x93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x13, 0x93, 0x93 },
  177. { 0x94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x14, 0x94, 0x94 },
  178. { 0x95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x15, 0x95, 0x95 },
  179. { 0x96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x16, 0x96, 0x96 },
  180. { 0x97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x17, 0x97, 0x97 },
  181. { 0x98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x18, 0x98, 0x98 },
  182. { 0x99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x19, 0x99, 0x99 },
  183. { 0x9A, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1A, 0x9A, 0x9A },
  184. { 0x9B, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1B, 0x9B, 0x9B },
  185. { 0x9C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1C, 0x9C, 0x9C },
  186. { 0x9D, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1D, 0x9D, 0x9D },
  187. { 0x9E, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1E, 0x9E, 0x9E },
  188. { 0x9F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1F, 0x9F, 0x9F },
  189. { 0xA0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', 0xA0, 0xA0 },
  190. { 0xA1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '!', 0xA1, 0xA1 },
  191. { 0xA2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '"', 0xA2, 0xA2 },
  192. { 0xA3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '#', 0xA3, 0xA3 },
  193. { 0xA4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '$', 0xA4, 0xA4 },
  194. { 0xA5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%', 0xA5, 0xA5 },
  195. { 0xA6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '&', 0xA6, 0xA6 },
  196. { 0xA7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\'', 0xA7, 0xA7 },
  197. { 0xA8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '(', 0xA8, 0xA8 },
  198. { 0xA9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ')', 0xA9, 0xA9 },
  199. { 0xAA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '*', 0xAA, 0xAA },
  200. { 0xAB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '+', 0xAB, 0xAB },
  201. { 0xAC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ',', 0xAC, 0xAC },
  202. { 0xAD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0xAD, 0xAD },
  203. { 0xAE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '.', 0xAE, 0xAE },
  204. { 0xAF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/', 0xAF, 0xAF },
  205. { 0xB0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', 0xB0, 0xB0 },
  206. { 0xB1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '1', 0xB1, 0xB1 },
  207. { 0xB2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '2', 0xB2, 0xB2 },
  208. { 0xB3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '3', 0xB3, 0xB3 },
  209. { 0xB4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '4', 0xB4, 0xB4 },
  210. { 0xB5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '5', 0xB5, 0xB5 },
  211. { 0xB6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '6', 0xB6, 0xB6 },
  212. { 0xB7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', 0xB7, 0xB7 },
  213. { 0xB8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '8', 0xB8, 0xB8 },
  214. { 0xB9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '9', 0xB9, 0xB9 },
  215. { 0xBA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ':', 0xBA, 0xBA },
  216. { 0xBB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ';', 0xBB, 0xBB },
  217. { 0xBC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '<', 0xBC, 0xBC },
  218. { 0xBD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '=', 0xBD, 0xBD },
  219. { 0xBE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '>', 0xBE, 0xBE },
  220. { 0xBF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '?', 0xBF, 0xBF },
  221. { 0xC0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '@', 0xC0, 0xC0 },
  222. { 0xC1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'A', 0xC1, 0xC1 },
  223. { 0xC2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'B', 0xC2, 0xC2 },
  224. { 0xC3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'C', 0xC3, 0xC3 },
  225. { 0xC4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'D', 0xC4, 0xC4 },
  226. { 0xC5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'E', 0xC5, 0xC5 },
  227. { 0xC6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'F', 0xC6, 0xC6 },
  228. { 0xC7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'G', 0xC7, 0xC7 },
  229. { 0xC8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'H', 0xC8, 0xC8 },
  230. { 0xC9, 0, 0, 0, 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0, 0, 'X', 0xD8, 0xD8 },
  246. { 0xD9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Y', 0xD9, 0xD9 },
  247. { 0xDA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Z', 0xDA, 0xDA },
  248. { 0xDB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[', 0xDB, 0xDB },
  249. { 0xDC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\\', 0xDC, 0xDC },
  250. { 0xDD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ']', 0xDD, 0xDD },
  251. { 0xDE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '^', 0xDE, 0xDE },
  252. { 0xDF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0xDF, 0xDF },
  253. { 0xE0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '`', 0xE0, 0xE0 },
  254. { 0xE1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a', 0xE1, 0xE1 },
  255. { 0xE2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'b', 0xE2, 0xE2 },
  256. { 0xE3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'c', 0xE3, 0xE3 },
  257. { 0xE4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'd', 0xE4, 0xE4 },
  258. { 0xE5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'e', 0xE5, 0xE5 },
  259. { 0xE6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'f', 0xE6, 0xE6 },
  260. { 0xE7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'g', 0xE7, 0xE7 },
  261. { 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0, 0, 0, 0, 0, 'w', 0xF7, 0xF7 },
  277. { 0xF8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'x', 0xF8, 0xF8 },
  278. { 0xF9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'y', 0xF9, 0xF9 },
  279. { 0xFA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'z', 0xFA, 0xFA },
  280. { 0xFB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{', 0xFB, 0xFB },
  281. { 0xFC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0xFC, 0xFC },
  282. { 0xFD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '}', 0xFD, 0xFD },
  283. { 0xFE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '~', 0xFE, 0xFE },
  284. { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x7F, 0xFF, 0xFF },
  285. // SUSv2 states that these functions should also accept EOF.
  286. { EOF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x7F, EOF, EOF }
  287. };
  288. size_t num_test_cases = sizeof(test_cases) / sizeof(struct test_case);
  289. #define CHECK_TEST(tc, fn, retval) \
  290. do { \
  291. if (fn(tc.c) != tc.fn) { \
  292. retval = EXIT_FAILURE; \
  293. printf("Unexpected result: " #fn "('%c') != %d // Char value: %d\n", tc.c, tc.fn, tc.c); \
  294. } \
  295. } while (0)
  296. int main(void) {
  297. int retval = EXIT_SUCCESS;
  298. for(int i = 0; i < num_test_cases; ++i) {
  299. struct test_case tc = test_cases[i];
  300. CHECK_TEST(tc, isalnum, retval);
  301. CHECK_TEST(tc, isalpha, retval);
  302. CHECK_TEST(tc, isascii, retval);
  303. CHECK_TEST(tc, isblank, retval);
  304. CHECK_TEST(tc, iscntrl, retval);
  305. CHECK_TEST(tc, isdigit, retval);
  306. CHECK_TEST(tc, isgraph, retval);
  307. CHECK_TEST(tc, islower, retval);
  308. CHECK_TEST(tc, isprint, retval);
  309. CHECK_TEST(tc, ispunct, retval);
  310. CHECK_TEST(tc, isspace, retval);
  311. CHECK_TEST(tc, isupper, retval);
  312. CHECK_TEST(tc, isxdigit, retval);
  313. CHECK_TEST(tc, toascii, retval);
  314. CHECK_TEST(tc, tolower, retval);
  315. CHECK_TEST(tc, toupper, retval);
  316. }
  317. if (retval == EXIT_SUCCESS) {
  318. printf("Success: %d\n", retval);
  319. } else {
  320. printf("Failure: %d\n", retval);
  321. }
  322. return retval;
  323. }