🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
7.8 KiB

  1. #!/usr/bin/perl -w
  2. use warnings;
  3. use strict;
  4. my $HASHBUCKETS1_16 = 256;
  5. my $HASHBUCKETS1_32 = 16;
  6. my $HASHBUCKETS2_16 = 16;
  7. my $HASHBUCKETS3_16 = 4;
  8. print <<__EOF__;
  9. /*
  10. * This file is part of PhysicsFS (https://icculus.org/physfs/)
  11. *
  12. * This data generated by physfs/extras/makecasefoldhashtable.pl ...
  13. * Do not manually edit this file!
  14. *
  15. * Please see the file LICENSE.txt in the source's root directory.
  16. */
  17. #ifndef _INCLUDE_PHYSFS_CASEFOLDING_H_
  18. #define _INCLUDE_PHYSFS_CASEFOLDING_H_
  19. #ifndef __PHYSICSFS_INTERNAL__
  20. #error Do not include this header from your applications.
  21. #endif
  22. /* We build three simple hashmaps here: one that maps Unicode codepoints to
  23. a one, two, or three lowercase codepoints. To retrieve this info: look at
  24. case_fold_hashX, where X is 1, 2, or 3. Most foldable codepoints fold to one,
  25. a few dozen fold to two, and a handful fold to three. If the codepoint isn't
  26. in any of these hashes, it doesn't fold (no separate upper and lowercase).
  27. Almost all these codepoints fit into 16 bits, so we hash them as such to save
  28. memory. If a codepoint is > 0xFFFF, we have separate hashes for them,
  29. since there are (currently) only about 120 of them and (currently) all of them
  30. map to a single lowercase codepoint. */
  31. typedef struct CaseFoldMapping1_32
  32. {
  33. PHYSFS_uint32 from;
  34. PHYSFS_uint32 to0;
  35. } CaseFoldMapping1_32;
  36. typedef struct CaseFoldMapping1_16
  37. {
  38. PHYSFS_uint16 from;
  39. PHYSFS_uint16 to0;
  40. } CaseFoldMapping1_16;
  41. typedef struct CaseFoldMapping2_16
  42. {
  43. PHYSFS_uint16 from;
  44. PHYSFS_uint16 to0;
  45. PHYSFS_uint16 to1;
  46. } CaseFoldMapping2_16;
  47. typedef struct CaseFoldMapping3_16
  48. {
  49. PHYSFS_uint16 from;
  50. PHYSFS_uint16 to0;
  51. PHYSFS_uint16 to1;
  52. PHYSFS_uint16 to2;
  53. } CaseFoldMapping3_16;
  54. typedef struct CaseFoldHashBucket1_16
  55. {
  56. const CaseFoldMapping1_16 *list;
  57. const PHYSFS_uint8 count;
  58. } CaseFoldHashBucket1_16;
  59. typedef struct CaseFoldHashBucket1_32
  60. {
  61. const CaseFoldMapping1_32 *list;
  62. const PHYSFS_uint8 count;
  63. } CaseFoldHashBucket1_32;
  64. typedef struct CaseFoldHashBucket2_16
  65. {
  66. const CaseFoldMapping2_16 *list;
  67. const PHYSFS_uint8 count;
  68. } CaseFoldHashBucket2_16;
  69. typedef struct CaseFoldHashBucket3_16
  70. {
  71. const CaseFoldMapping3_16 *list;
  72. const PHYSFS_uint8 count;
  73. } CaseFoldHashBucket3_16;
  74. __EOF__
  75. my @foldPairs1_16;
  76. my @foldPairs2_16;
  77. my @foldPairs3_16;
  78. my @foldPairs1_32;
  79. for (my $i = 0; $i < $HASHBUCKETS1_16; $i++) {
  80. $foldPairs1_16[$i] = '';
  81. }
  82. for (my $i = 0; $i < $HASHBUCKETS1_32; $i++) {
  83. $foldPairs1_32[$i] = '';
  84. }
  85. for (my $i = 0; $i < $HASHBUCKETS2_16; $i++) {
  86. $foldPairs2_16[$i] = '';
  87. }
  88. for (my $i = 0; $i < $HASHBUCKETS3_16; $i++) {
  89. $foldPairs3_16[$i] = '';
  90. }
  91. open(FH,'<','casefolding.txt') or die("failed to open casefolding.txt: $!\n");
  92. while (<FH>) {
  93. chomp;
  94. # strip comments from textfile...
  95. s/\#.*\Z//;
  96. # strip whitespace...
  97. s/\A\s+//;
  98. s/\s+\Z//;
  99. next if not /\A([a-fA-F0-9]+)\;\s*(.)\;\s*(.+)\;/;
  100. my ($code, $status, $mapping) = ($1, $2, $3);
  101. my $hexxed = hex($code);
  102. #print("// code '$code' status '$status' mapping '$mapping'\n");
  103. if (($status eq 'C') or ($status eq 'F')) {
  104. my ($map1, $map2, $map3) = (undef, undef, undef);
  105. $map1 = $1 if $mapping =~ s/\A([a-fA-F0-9]+)(\s*|\Z)//;
  106. $map2 = $1 if $mapping =~ s/\A([a-fA-F0-9]+)(\s*|\Z)//;
  107. $map3 = $1 if $mapping =~ s/\A([a-fA-F0-9]+)(\s*|\Z)//;
  108. die("mapping space too small for '$code'\n") if ($mapping ne '');
  109. die("problem parsing mapping for '$code'\n") if (not defined($map1));
  110. if ($hexxed < 128) {
  111. # Just ignore these, we'll handle the low-ASCII ones ourselves.
  112. } elsif ($hexxed > 0xFFFF) {
  113. # We just need to add the 32-bit 2 and/or 3 codepoint maps if this die()'s here.
  114. die("Uhoh, a codepoint > 0xFFFF that folds to multiple codepoints! Fixme.") if defined($map2);
  115. my $hashed = (($hexxed ^ ($hexxed >> 8)) & ($HASHBUCKETS1_32-1));
  116. #print("// hexxed '$hexxed' hashed1 '$hashed'\n");
  117. $foldPairs1_32[$hashed] .= " { 0x$code, 0x$map1 },\n";
  118. } elsif (not defined($map2)) {
  119. my $hashed = (($hexxed ^ ($hexxed >> 8)) & ($HASHBUCKETS1_16-1));
  120. #print("// hexxed '$hexxed' hashed1 '$hashed'\n");
  121. $foldPairs1_16[$hashed] .= " { 0x$code, 0x$map1 },\n";
  122. } elsif (not defined($map3)) {
  123. my $hashed = (($hexxed ^ ($hexxed >> 8)) & ($HASHBUCKETS2_16-1));
  124. #print("// hexxed '$hexxed' hashed2 '$hashed'\n");
  125. $foldPairs2_16[$hashed] .= " { 0x$code, 0x$map1, 0x$map2 },\n";
  126. } else {
  127. my $hashed = (($hexxed ^ ($hexxed >> 8)) & ($HASHBUCKETS3_16-1));
  128. #print("// hexxed '$hexxed' hashed3 '$hashed'\n");
  129. $foldPairs3_16[$hashed] .= " { 0x$code, 0x$map1, 0x$map2, 0x$map3 },\n";
  130. }
  131. }
  132. }
  133. close(FH);
  134. for (my $i = 0; $i < $HASHBUCKETS1_16; $i++) {
  135. $foldPairs1_16[$i] =~ s/,\n\Z//;
  136. my $str = $foldPairs1_16[$i];
  137. next if $str eq '';
  138. my $num = '000' . $i;
  139. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  140. my $sym = "case_fold1_16_${num}";
  141. print("static const CaseFoldMapping1_16 ${sym}[] = {\n$str\n};\n\n");
  142. }
  143. for (my $i = 0; $i < $HASHBUCKETS1_32; $i++) {
  144. $foldPairs1_32[$i] =~ s/,\n\Z//;
  145. my $str = $foldPairs1_32[$i];
  146. next if $str eq '';
  147. my $num = '000' . $i;
  148. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  149. my $sym = "case_fold1_32_${num}";
  150. print("static const CaseFoldMapping1_32 ${sym}[] = {\n$str\n};\n\n");
  151. }
  152. for (my $i = 0; $i < $HASHBUCKETS2_16; $i++) {
  153. $foldPairs2_16[$i] =~ s/,\n\Z//;
  154. my $str = $foldPairs2_16[$i];
  155. next if $str eq '';
  156. my $num = '000' . $i;
  157. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  158. my $sym = "case_fold2_16_${num}";
  159. print("static const CaseFoldMapping2_16 ${sym}[] = {\n$str\n};\n\n");
  160. }
  161. for (my $i = 0; $i < $HASHBUCKETS3_16; $i++) {
  162. $foldPairs3_16[$i] =~ s/,\n\Z//;
  163. my $str = $foldPairs3_16[$i];
  164. next if $str eq '';
  165. my $num = '000' . $i;
  166. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  167. my $sym = "case_fold3_16_${num}";
  168. print("static const CaseFoldMapping3_16 ${sym}[] = {\n$str\n};\n\n");
  169. }
  170. print("static const CaseFoldHashBucket1_16 case_fold_hash1_16[] = {\n");
  171. for (my $i = 0; $i < $HASHBUCKETS1_16; $i++) {
  172. my $str = $foldPairs1_16[$i];
  173. if ($str eq '') {
  174. print(" { NULL, 0 },\n");
  175. } else {
  176. my $num = '000' . $i;
  177. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  178. my $sym = "case_fold1_16_${num}";
  179. print(" { $sym, __PHYSFS_ARRAYLEN($sym) },\n");
  180. }
  181. }
  182. print("};\n\n");
  183. print("static const CaseFoldHashBucket1_32 case_fold_hash1_32[] = {\n");
  184. for (my $i = 0; $i < $HASHBUCKETS1_32; $i++) {
  185. my $str = $foldPairs1_32[$i];
  186. if ($str eq '') {
  187. print(" { NULL, 0 },\n");
  188. } else {
  189. my $num = '000' . $i;
  190. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  191. my $sym = "case_fold1_32_${num}";
  192. print(" { $sym, __PHYSFS_ARRAYLEN($sym) },\n");
  193. }
  194. }
  195. print("};\n\n");
  196. print("static const CaseFoldHashBucket2_16 case_fold_hash2_16[] = {\n");
  197. for (my $i = 0; $i < $HASHBUCKETS2_16; $i++) {
  198. my $str = $foldPairs2_16[$i];
  199. if ($str eq '') {
  200. print(" { NULL, 0 },\n");
  201. } else {
  202. my $num = '000' . $i;
  203. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  204. my $sym = "case_fold2_16_${num}";
  205. print(" { $sym, __PHYSFS_ARRAYLEN($sym) },\n");
  206. }
  207. }
  208. print("};\n\n");
  209. print("static const CaseFoldHashBucket3_16 case_fold_hash3_16[] = {\n");
  210. for (my $i = 0; $i < $HASHBUCKETS3_16; $i++) {
  211. my $str = $foldPairs3_16[$i];
  212. if ($str eq '') {
  213. print(" { NULL, 0 },\n");
  214. } else {
  215. my $num = '000' . $i;
  216. $num =~ s/\A.*?(\d\d\d)\Z/$1/;
  217. my $sym = "case_fold3_16_${num}";
  218. print(" { $sym, __PHYSFS_ARRAYLEN($sym) },\n");
  219. }
  220. }
  221. print("};\n\n");
  222. print <<__EOF__;
  223. #endif /* _INCLUDE_PHYSFS_CASEFOLDING_H_ */
  224. /* end of physfs_casefolding.h ... */
  225. __EOF__
  226. exit 0;
  227. # end of makecashfoldhashtable.pl ...