make_unicode 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820
  1. #!/usr/bin/perl -w
  2. #
  3. # Generate code page .c files from ftp.unicode.org descriptions
  4. #
  5. # Copyright 2000 Alexandre Julliard
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  20. #
  21. use strict;
  22. # base URLs for www.unicode.org files
  23. my $UNIVERSION = "13.0.0";
  24. my $UNIDATA = "https://www.unicode.org/Public/$UNIVERSION/ucd/UCD.zip";
  25. my $IDNADATA = "https://www.unicode.org/Public/idna/$UNIVERSION";
  26. my $JISDATA = "https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS";
  27. my $REPORTS = "http://www.unicode.org/reports";
  28. my $MSDATA = "https://download.microsoft.com/download/C/F/7/CF713A5E-9FBC-4FD6-9246-275F65C0E498";
  29. my $MSCODEPAGES = "$MSDATA/Windows Supported Code Page Data Files.zip";
  30. # Sort keys file
  31. my $SORTKEYS = "tr10/allkeys.txt";
  32. # Default char for undefined mappings
  33. my $DEF_CHAR = ord '?';
  34. # Last valid Unicode character
  35. my $MAX_CHAR = 0x10ffff;
  36. my @allfiles =
  37. (
  38. "CodpageFiles/037.txt",
  39. "CodpageFiles/437.txt",
  40. "CodpageFiles/500.txt",
  41. "CodpageFiles/737.txt",
  42. "CodpageFiles/775.txt",
  43. "CodpageFiles/850.txt",
  44. "CodpageFiles/852.txt",
  45. "CodpageFiles/855.txt",
  46. "CodpageFiles/857.txt",
  47. "CodpageFiles/860.txt",
  48. "CodpageFiles/861.txt",
  49. "CodpageFiles/862.txt",
  50. "CodpageFiles/863.txt",
  51. "CodpageFiles/864.txt",
  52. "CodpageFiles/865.txt",
  53. "CodpageFiles/866.txt",
  54. "CodpageFiles/869.txt",
  55. "CodpageFiles/874.txt",
  56. "CodpageFiles/875.txt",
  57. "CodpageFiles/932.txt",
  58. "CodpageFiles/936.txt",
  59. "CodpageFiles/949.txt",
  60. "CodpageFiles/950.txt",
  61. "CodpageFiles/1026.txt",
  62. "CodpageFiles/1250.txt",
  63. "CodpageFiles/1251.txt",
  64. "CodpageFiles/1252.txt",
  65. "CodpageFiles/1253.txt",
  66. "CodpageFiles/1254.txt",
  67. "CodpageFiles/1255.txt",
  68. "CodpageFiles/1256.txt",
  69. "CodpageFiles/1257.txt",
  70. "CodpageFiles/1258.txt",
  71. "CodpageFiles/1361.txt",
  72. "CodpageFiles/10000.txt",
  73. "CodpageFiles/10001.txt",
  74. "CodpageFiles/10002.txt",
  75. "CodpageFiles/10003.txt",
  76. "CodpageFiles/10004.txt",
  77. "CodpageFiles/10005.txt",
  78. "CodpageFiles/10006.txt",
  79. "CodpageFiles/10007.txt",
  80. "CodpageFiles/10008.txt",
  81. "CodpageFiles/10010.txt",
  82. "CodpageFiles/10017.txt",
  83. "CodpageFiles/10021.txt",
  84. "CodpageFiles/10029.txt",
  85. "CodpageFiles/10079.txt",
  86. "CodpageFiles/10081.txt",
  87. "CodpageFiles/10082.txt",
  88. "CodpageFiles/20127.txt",
  89. "CodpageFiles/20866.txt",
  90. "CodpageFiles/21866.txt",
  91. "CodpageFiles/28591.txt",
  92. "CodpageFiles/28592.txt",
  93. "CodpageFiles/28593.txt",
  94. "CodpageFiles/28594.txt",
  95. "CodpageFiles/28595.txt",
  96. "CodpageFiles/28596.txt",
  97. "CodpageFiles/28597.txt",
  98. "CodpageFiles/28598.txt",
  99. "CodpageFiles/28599.txt",
  100. "CodpageFiles/28603.txt",
  101. "CodpageFiles/28605.txt",
  102. );
  103. my %ctype =
  104. (
  105. # CT_CTYPE1
  106. "upper" => 0x0001,
  107. "lower" => 0x0002,
  108. "digit" => 0x0004,
  109. "space" => 0x0008,
  110. "punct" => 0x0010,
  111. "cntrl" => 0x0020,
  112. "blank" => 0x0040,
  113. "xdigit" => 0x0080,
  114. "alpha" => 0x0100 | 0x80000000,
  115. "defin" => 0x0200,
  116. # CT_CTYPE3 in high 16 bits
  117. "nonspacing" => 0x00010000,
  118. "diacritic" => 0x00020000,
  119. "vowelmark" => 0x00040000,
  120. "symbol" => 0x00080000,
  121. "katakana" => 0x00100000,
  122. "hiragana" => 0x00200000,
  123. "halfwidth" => 0x00400000,
  124. "fullwidth" => 0x00800000,
  125. "ideograph" => 0x01000000,
  126. "kashida" => 0x02000000,
  127. "lexical" => 0x04000000,
  128. "highsurrogate" => 0x08000000,
  129. "lowsurrogate" => 0x10000000,
  130. );
  131. my %bracket_types =
  132. (
  133. "o" => 0x0000,
  134. "c" => 0x0001,
  135. );
  136. my %indic_types =
  137. (
  138. "Other" => 0x0000,
  139. "Bindu" => 0x0001,
  140. "Visarga" => 0x0002,
  141. "Avagraha" => 0x0003,
  142. "Nukta" => 0x0004,
  143. "Virama" => 0x0005,
  144. "Vowel_Independent" => 0x0006,
  145. "Vowel_Dependent" => 0x0007,
  146. "Vowel" => 0x0008,
  147. "Consonant_Placeholder" => 0x0009,
  148. "Consonant" => 0x000a,
  149. "Consonant_Dead" => 0x000b,
  150. "Consonant_Succeeding_Repha" => 0x000c,
  151. "Consonant_Subjoined" => 0x000d,
  152. "Consonant_Medial" => 0x000e,
  153. "Consonant_Final" => 0x000f,
  154. "Consonant_Head_Letter" => 0x0010,
  155. "Modifying_Letter" => 0x0011,
  156. "Tone_Letter" => 0x0012,
  157. "Tone_Mark" => 0x0013,
  158. "Register_Shifter" => 0x0014,
  159. "Consonant_Preceding_Repha" => 0x0015,
  160. "Pure_Killer" => 0x0016,
  161. "Invisible_Stacker" => 0x0017,
  162. "Gemination_Mark" => 0x0018,
  163. "Cantillation_Mark" => 0x0019,
  164. "Non_Joiner" => 0x001a,
  165. "Joiner" => 0x001b,
  166. "Number_Joiner" => 0x001c,
  167. "Number" => 0x001d,
  168. "Brahmi_Joining_Number" => 0x001e,
  169. "Consonant_With_Stacker" => 0x001f,
  170. "Consonant_Prefixed" => 0x0020,
  171. "Syllable_Modifier" => 0x0021,
  172. "Consonant_Killer" => 0x0022,
  173. "Consonant_Initial_Postfixed" => 0x0023,
  174. );
  175. my %matra_types =
  176. (
  177. "Right" => 0x01,
  178. "Left" => 0x02,
  179. "Visual_Order_Left" => 0x03,
  180. "Left_And_Right" => 0x04,
  181. "Top" => 0x05,
  182. "Bottom" => 0x06,
  183. "Top_And_Bottom" => 0x07,
  184. "Top_And_Right" => 0x08,
  185. "Top_And_Left" => 0x09,
  186. "Top_And_Left_And_Right" => 0x0a,
  187. "Bottom_And_Right" => 0x0b,
  188. "Top_And_Bottom_And_Right" => 0x0c,
  189. "Overstruck" => 0x0d,
  190. "Invisible" => 0x0e,
  191. "Bottom_And_Left" => 0x0f,
  192. "Top_And_Bottom_And_Left" => 0x10,
  193. );
  194. my %break_types =
  195. (
  196. "BK" => 0x0001,
  197. "CR" => 0x0002,
  198. "LF" => 0x0003,
  199. "CM" => 0x0004,
  200. "SG" => 0x0005,
  201. "GL" => 0x0006,
  202. "CB" => 0x0007,
  203. "SP" => 0x0008,
  204. "ZW" => 0x0009,
  205. "NL" => 0x000a,
  206. "WJ" => 0x000b,
  207. "JL" => 0x000c,
  208. "JV" => 0x000d,
  209. "JT" => 0x000e,
  210. "H2" => 0x000f,
  211. "H3" => 0x0010,
  212. "XX" => 0x0011,
  213. "OP" => 0x0012,
  214. "CL" => 0x0013,
  215. "CP" => 0x0014,
  216. "QU" => 0x0015,
  217. "NS" => 0x0016,
  218. "EX" => 0x0017,
  219. "SY" => 0x0018,
  220. "IS" => 0x0019,
  221. "PR" => 0x001a,
  222. "PO" => 0x001b,
  223. "NU" => 0x001c,
  224. "AL" => 0x001d,
  225. "ID" => 0x001e,
  226. "IN" => 0x001f,
  227. "HY" => 0x0020,
  228. "BB" => 0x0021,
  229. "BA" => 0x0022,
  230. "SA" => 0x0023,
  231. "AI" => 0x0024,
  232. "B2" => 0x0025,
  233. "HL" => 0x0026,
  234. "CJ" => 0x0027,
  235. "RI" => 0x0028,
  236. "EB" => 0x0029,
  237. "EM" => 0x002a,
  238. "ZWJ" => 0x002b,
  239. );
  240. my %vertical_types =
  241. (
  242. "R" => 0x0000,
  243. "U" => 0x0001,
  244. "Tr" => 0x0002,
  245. "Tu" => 0x0003,
  246. );
  247. my %categories =
  248. (
  249. "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
  250. "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
  251. "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
  252. "Mn" => $ctype{"defin"}|$ctype{"nonspacing"}, # Mark, Non-Spacing
  253. "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
  254. "Me" => $ctype{"defin"}, # Mark, Enclosing
  255. "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
  256. "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
  257. "No" => $ctype{"defin"}, # Number, Other
  258. "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
  259. "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
  260. "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
  261. "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
  262. "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
  263. "Cs" => $ctype{"defin"}, # Other, Surrogate
  264. "Co" => $ctype{"defin"}, # Other, Private Use
  265. "Cn" => $ctype{"defin"}, # Other, Not Assigned
  266. "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
  267. "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
  268. "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
  269. "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
  270. "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
  271. "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
  272. "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
  273. "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
  274. "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
  275. "Sm" => $ctype{"defin"}|$ctype{"symbol"}, # Symbol, Math
  276. "Sc" => $ctype{"defin"}|$ctype{"symbol"}, # Symbol, Currency
  277. "Sk" => $ctype{"defin"}|$ctype{"symbol"}, # Symbol, Modifier
  278. "So" => $ctype{"defin"}|$ctype{"symbol"} # Symbol, Other
  279. );
  280. # a few characters need additional categories that cannot be determined automatically
  281. my %special_categories =
  282. (
  283. "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
  284. 0xff10..0xff19, 0xff21..0xff26, 0xff41..0xff46 ],
  285. "space" => [ 0x09..0x0d, 0x85 ],
  286. "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
  287. "cntrl" => [ 0x070f, 0x200c, 0x200d,
  288. 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
  289. 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
  290. 0xfff9, 0xfffa, 0xfffb ],
  291. "punct" => [ 0x24, 0x2b, 0x3c..0x3e, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe,
  292. 0xd7, 0xf7 ],
  293. "digit" => [ 0xb2, 0xb3, 0xb9 ],
  294. "lower" => [ 0xaa, 0xba, 0x2071, 0x207f ],
  295. "nonspacing" => [ 0xc0..0xc5, 0xc7..0xcf, 0xd1..0xd6, 0xd8..0xdd, 0xe0..0xe5, 0xe7..0xef,
  296. 0xf1..0xf6, 0xf8..0xfd, 0xff, 0x6de, 0x1929..0x192b, 0x302e..0x302f ],
  297. "diacritic" => [ 0x5e, 0x60, 0xb7, 0xd8, 0xf8 ],
  298. "symbol" => [ 0x09..0x0d, 0x20..0x23, 0x25, 0x26, 0x28..0x2a, 0x2c, 0x2e..0x2f, 0x3a..0x40,
  299. 0x5b..0x60, 0x7b..0x7e, 0xa0..0xa9, 0xab..0xb1, 0xb4..0xb8, 0xbb, 0xbf,
  300. 0x02b9..0x02ba, 0x02c6..0x02cf ],
  301. "halfwidth" => [ 0x20..0x7e, 0xa2..0xa3, 0xa5..0xa6, 0xac, 0xaf, 0x20a9 ],
  302. "fullwidth" => [ 0x2018..0x2019, 0x201c..0x201d, 0x3000..0x3002, 0x300c..0x300d, 0x309b..0x309c,
  303. 0x30a1..0x30ab, 0x30ad, 0x30ad, 0x30af, 0x30b1, 0x30b3, 0x30b5, 0x30b7, 0x30b9,
  304. 0x30bb, 0x30bd, 0x30bf, 0x30c1, 0x30c3, 0x30c4, 0x30c6, 0x30c8, 0x30ca..0x30cf,
  305. 0x30d2, 0x30d5, 0x30d8, 0x30db, 0x30de..0x30ed, 0x30ef, 0x30f2..0x30f3, 0x30fb,
  306. 0x3131..0x3164 ],
  307. "ideograph" => [ 0x3006..0x3007 ],
  308. "lexical" => [ 0x22, 0x24, 0x27, 0x2d, 0x2f, 0x3d, 0x40, 0x5c, 0x5e..0x60, 0x7e,
  309. 0xa8, 0xaa, 0xad, 0xaf, 0xb4, 0xb8, 0xba,
  310. 0x02b0..0x02b8, 0x02bc, 0x02c7, 0x02ca..0x02cb, 0x02cf, 0x02d8..0x02dd, 0x02e0..0x02e3,
  311. 0x037a, 0x0384..0x0385, 0x0387, 0x0559..0x055a, 0x0640, 0x1fbd..0x1fc1,
  312. 0x1fcd..0x1fcf, 0x1fdd..0x1fdf, 0x1fed..0x1fef, 0x1ffd..0x1ffe, 0x2010..0x2015,
  313. 0x2032..0x2034, 0x2038, 0x2043..0x2044, 0x207b..0x207c, 0x207f, 0x208b..0x208c,
  314. 0x2212, 0x2215..0x2216, 0x2500, 0x2504..0x2505, 0x2508..0x2509, 0x254c..0x254d,
  315. 0x3003, 0x301c, 0x3030..0x3035, 0x309b..0x309e, 0x30fd..0x30fe, 0xfe31..0xfe32,
  316. 0xfe58, 0xfe63, 0xfe66, 0xfe68..0xfe69, 0xfe6b, 0xff04, 0xff07, 0xff0d, 0xff0f,
  317. 0xff1d, 0xff20, 0xff3c, 0xff3e, 0xff40, 0xff5e ],
  318. "kashida" => [ 0x0640 ],
  319. );
  320. my %directions =
  321. (
  322. "L" => 1, # Left-to-Right
  323. "R" => 2, # Right-to-Left
  324. "AL" => 12, # Right-to-Left Arabic
  325. "EN" => 3, # European Number
  326. "ES" => 4, # European Number Separator
  327. "ET" => 5, # European Number Terminator
  328. "AN" => 6, # Arabic Number
  329. "CS" => 7, # Common Number Separator
  330. "NSM" => 13, # Non-Spacing Mark
  331. "BN" => 14, # Boundary Neutral
  332. "B" => 8, # Paragraph Separator
  333. "S" => 9, # Segment Separator
  334. "WS" => 10, # Whitespace
  335. "ON" => 11, # Other Neutrals
  336. "LRE" => 15, # Left-to-Right Embedding
  337. "LRO" => 15, # Left-to-Right Override
  338. "RLE" => 15, # Right-to-Left Embedding
  339. "RLO" => 15, # Right-to-Left Override
  340. "PDF" => 15, # Pop Directional Format
  341. "LRI" => 15, # Left-to-Right Isolate
  342. "RLI" => 15, # Right-to-Left Isolate
  343. "FSI" => 15, # First Strong Isolate
  344. "PDI" => 15 # Pop Directional Isolate
  345. );
  346. my %c2_types =
  347. (
  348. "L" => 1, # C2_LEFTTORIGHT
  349. "R" => 2, # C2_RIGHTTOLEFT
  350. "AL" => 2, # C2_RIGHTTOLEFT
  351. "EN" => 3, # C2_EUROPENUMBER
  352. "ES" => 4, # C2_EUROPESEPARATOR
  353. "ET" => 5, # C2_EUROPETERMINATOR
  354. "AN" => 6, # C2_ARABICNUMBER
  355. "CS" => 7, # C2_COMMONSEPARATOR
  356. "NSM" => 11, # C2_OTHERNEUTRAL
  357. "BN" => 0, # C2_NOTAPPLICABLE
  358. "B" => 8, # C2_BLOCKSEPARATOR
  359. "S" => 9, # C2_SEGMENTSEPARATOR
  360. "WS" => 10, # C2_WHITESPACE
  361. "ON" => 11, # C2_OTHERNEUTRAL
  362. "LRE" => 11, # C2_OTHERNEUTRAL
  363. "LRO" => 11, # C2_OTHERNEUTRAL
  364. "RLE" => 11, # C2_OTHERNEUTRAL
  365. "RLO" => 11, # C2_OTHERNEUTRAL
  366. "PDF" => 11, # C2_OTHERNEUTRAL
  367. "LRI" => 11, # C2_OTHERNEUTRAL
  368. "RLI" => 11, # C2_OTHERNEUTRAL
  369. "FSI" => 11, # C2_OTHERNEUTRAL
  370. "PDI" => 11 # C2_OTHERNEUTRAL
  371. );
  372. my %bidi_types =
  373. (
  374. "ON" => 0, # Other Neutrals
  375. "L" => 1, # Left-to-Right
  376. "R" => 2, # Right-to-Left
  377. "AN" => 3, # Arabic Number
  378. "EN" => 4, # European Number
  379. "AL" => 5, # Right-to-Left Arabic
  380. "NSM" => 6, # Non-Spacing Mark
  381. "CS" => 7, # Common Number Separator
  382. "ES" => 8, # European Number Separator
  383. "ET" => 9, # European Number Terminator
  384. "BN" => 10, # Boundary Neutral
  385. "S" => 11, # Segment Separator
  386. "WS" => 12, # Whitespace
  387. "B" => 13, # Paragraph Separator
  388. "RLO" => 14, # Right-to-Left Override
  389. "RLE" => 15, # Right-to-Left Embedding
  390. "LRO" => 16, # Left-to-Right Override
  391. "LRE" => 17, # Left-to-Right Embedding
  392. "PDF" => 18, # Pop Directional Format
  393. "LRI" => 19, # Left-to-Right Isolate
  394. "RLI" => 20, # Right-to-Left Isolate
  395. "FSI" => 21, # First Strong Isolate
  396. "PDI" => 22 # Pop Directional Isolate
  397. );
  398. my %joining_types =
  399. (
  400. "U" => 0, # Non_Joining
  401. "T" => 1, # Transparent
  402. "R" => 2, # Right_Joining
  403. "L" => 3, # Left_Joining
  404. "D" => 4, # Dual_Joining
  405. "C" => 5, # Join_Causing
  406. );
  407. my @cp2uni = ();
  408. my @glyph2uni = ();
  409. my @lead_bytes = ();
  410. my @uni2cp = ();
  411. my @tolower_table = ();
  412. my @toupper_table = ();
  413. my @digitmap_table = ();
  414. my @category_table = ();
  415. my @joining_table = ();
  416. my @direction_table = ();
  417. my @decomp_table = ();
  418. my @combining_class_table = ();
  419. my @decomp_compat_table = ();
  420. my @comp_exclusions = ();
  421. my @idna_decomp_table = ();
  422. my @idna_disallowed = ();
  423. my %registry_keys;
  424. my $default_char;
  425. my $default_wchar;
  426. my %joining_forms =
  427. (
  428. "isolated" => [],
  429. "final" => [],
  430. "initial" => [],
  431. "medial" => []
  432. );
  433. sub to_utf16(@)
  434. {
  435. my @ret;
  436. foreach my $ch (@_)
  437. {
  438. if ($ch < 0x10000)
  439. {
  440. push @ret, $ch;
  441. }
  442. else
  443. {
  444. my $val = $ch - 0x10000;
  445. push @ret, 0xd800 | ($val >> 10), 0xdc00 | ($val & 0x3ff);
  446. }
  447. }
  448. return @ret;
  449. }
  450. ################################################################
  451. # fetch a unicode.org file and open it
  452. sub open_data_file($$)
  453. {
  454. my ($base, $name) = @_;
  455. my $cache = ($ENV{XDG_CACHE_HOME} || "$ENV{HOME}/.cache") . "/wine";
  456. (my $dir = "$cache/$name") =~ s/\/[^\/]+$//;
  457. my $suffix = ($base =~ /\/\Q$UNIVERSION\E/) ? "-$UNIVERSION" : "";
  458. local *FILE;
  459. if ($base =~ /.*\/([^\/]+)\.zip$/)
  460. {
  461. my $zip = "$1$suffix.zip";
  462. unless (-f "$cache/$zip")
  463. {
  464. system "mkdir", "-p", $cache;
  465. print "Fetching $base...\n";
  466. !system "wget", "-q", "-O", "$cache/$zip", $base or die "cannot fetch $base";
  467. }
  468. open FILE, "-|", "unzip", "-p", "$cache/$zip", $name or die "cannot extract $name from $zip";
  469. }
  470. else
  471. {
  472. (my $dest = "$cache/$name") =~ s/(.*)(\.[^\/.]+)$/$1$suffix$2/;
  473. unless (-f $dest)
  474. {
  475. system "mkdir", "-p", $dir;
  476. print "Fetching $base/$name...\n";
  477. !system "wget", "-q", "-O", $dest, "$base/$name" or die "cannot fetch $base/$name";
  478. }
  479. open FILE, "<$dest" or die "cannot open $dest";
  480. }
  481. return *FILE;
  482. }
  483. ################################################################
  484. # recursively get the decomposition for a character
  485. sub get_decomposition($$);
  486. sub get_decomposition($$)
  487. {
  488. my ($char, $table) = @_;
  489. my @ret;
  490. return $char unless defined $table->[$char];
  491. foreach my $ch (@{$table->[$char]})
  492. {
  493. push @ret, get_decomposition( $ch, $table );
  494. }
  495. return @ret;
  496. }
  497. ################################################################
  498. # get the composition that results in a given character
  499. sub get_composition($$)
  500. {
  501. my ($ch, $compat) = @_;
  502. return () unless defined $decomp_table[$ch]; # no decomposition
  503. my @ret = @{$decomp_table[$ch]};
  504. return () if @ret < 2; # singleton decomposition
  505. return () if $comp_exclusions[$ch]; # composition exclusion
  506. return () if $combining_class_table[$ch]; # non-starter
  507. return () if $combining_class_table[$ret[0]]; # first char is non-starter
  508. return () if $compat == 1 && !defined $decomp_table[$ret[0]] &&
  509. defined $decomp_compat_table[$ret[0]]; # first char has compat decomposition
  510. return () if $compat == 2 && !defined $decomp_table[$ret[0]] &&
  511. defined $idna_decomp_table[$ret[0]]; # first char has IDNA decomposition
  512. return () if $compat == 2 && defined $idna_decomp_table[$ret[0]] &&
  513. defined $idna_decomp_table[$idna_decomp_table[$ret[0]]->[0]]; # first char's decomposition has IDNA decomposition
  514. return () if $compat == 2 && defined $idna_decomp_table[$ret[1]]; # second char has IDNA decomposition
  515. return @ret;
  516. }
  517. ################################################################
  518. # recursively build decompositions
  519. sub build_decompositions(@)
  520. {
  521. my @src = @_;
  522. my @dst;
  523. for (my $i = 0; $i < @src; $i++)
  524. {
  525. next unless defined $src[$i];
  526. my @decomp = to_utf16( get_decomposition( $i, \@src ));
  527. $dst[$i] = \@decomp;
  528. }
  529. return @dst;
  530. }
  531. ################################################################
  532. # compose Hangul sequences
  533. sub compose_hangul(@)
  534. {
  535. my $SBASE = 0xac00;
  536. my $LBASE = 0x1100;
  537. my $VBASE = 0x1161;
  538. my $TBASE = 0x11a7;
  539. my $LCOUNT = 19;
  540. my $VCOUNT = 21;
  541. my $TCOUNT = 28;
  542. my $NCOUNT = $VCOUNT * $TCOUNT;
  543. my $SCOUNT = $LCOUNT * $NCOUNT;
  544. my @seq = @_;
  545. my @ret;
  546. my $i;
  547. for ($i = 0; $i < @seq; $i++)
  548. {
  549. my $ch = $seq[$i];
  550. if ($ch >= $LBASE && $ch < $LBASE + $LCOUNT && $i < @seq - 1 &&
  551. $seq[$i+1] >= $VBASE && $seq[$i+1] < $VBASE + $VCOUNT)
  552. {
  553. $ch = $SBASE + (($seq[$i] - $LBASE) * $VCOUNT + ($seq[$i+1] - $VBASE)) * $TCOUNT;
  554. $i++;
  555. }
  556. if ($ch >= $SBASE && $ch < $SBASE + $SCOUNT && !(($ch - $SBASE) % $TCOUNT) && $i < @seq - 1 &&
  557. $seq[$i+1] > $TBASE && $seq[$i+1] < $TBASE + $TCOUNT)
  558. {
  559. $ch += $seq[$i+1] - $TBASE;
  560. $i++;
  561. }
  562. push @ret, $ch;
  563. }
  564. return @ret;
  565. }
  566. ################################################################
  567. # remove linguistic-only mappings from the case table
  568. sub remove_linguistic_mappings($$)
  569. {
  570. my ($upper, $lower) = @_;
  571. # remove case mappings that don't round-trip
  572. for (my $i = 0; $i < @{$upper}; $i++)
  573. {
  574. next unless defined ${$upper}[$i];
  575. my $ch = ${$upper}[$i];
  576. ${$upper}[$i] = undef unless defined ${$lower}[$ch] && ${$lower}[$ch] == $i;
  577. }
  578. for (my $i = 0; $i < @{$lower}; $i++)
  579. {
  580. next unless defined ${$lower}[$i];
  581. my $ch = ${$lower}[$i];
  582. ${$lower}[$i] = undef unless defined ${$upper}[$ch] && ${$upper}[$ch] == $i;
  583. }
  584. }
  585. ################################################################
  586. # read in the Unicode database files
  587. sub load_data()
  588. {
  589. my $start;
  590. # now build mappings from the decomposition field of the Unicode database
  591. my $UNICODE_DATA = open_data_file( $UNIDATA, "UnicodeData.txt" );
  592. while (<$UNICODE_DATA>)
  593. {
  594. # Decode the fields ...
  595. my ($code, $name, $cat, $comb, $bidi,
  596. $decomp, $dec, $dig, $num, $mirror,
  597. $oldname, $comment, $upper, $lower, $title) = split /;/;
  598. my $src = hex $code;
  599. die "unknown category $cat" unless defined $categories{$cat};
  600. die "unknown directionality $bidi" unless defined $directions{$bidi};
  601. $category_table[$src] = $categories{$cat};
  602. $direction_table[$src] = $bidi;
  603. $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
  604. if ($lower ne "")
  605. {
  606. $tolower_table[$src] = hex $lower;
  607. }
  608. if ($upper ne "")
  609. {
  610. $toupper_table[$src] = hex $upper;
  611. }
  612. if ($dec ne "")
  613. {
  614. $category_table[$src] |= $ctype{"digit"};
  615. }
  616. if ($dig ne "")
  617. {
  618. $digitmap_table[$src] = ord $dig;
  619. }
  620. $combining_class_table[$src] = ($cat ne "Co") ? $comb : 0x100; # Private Use
  621. $category_table[$src] |= $ctype{"nonspacing"} if $bidi eq "NSM";
  622. $category_table[$src] |= $ctype{"diacritic"} if $name =~ /^(COMBINING)|(MODIFIER LETTER)\W/;
  623. $category_table[$src] |= $ctype{"vowelmark"} if $name =~ /\sVOWEL/ || $oldname =~ /\sVOWEL/;
  624. $category_table[$src] |= $ctype{"halfwidth"} if $name =~ /^HALFWIDTH\s/;
  625. $category_table[$src] |= $ctype{"fullwidth"} if $name =~ /^FULLWIDTH\s/;
  626. $category_table[$src] |= $ctype{"hiragana"} if $name =~ /(HIRAGANA)|(\WKANA\W)/;
  627. $category_table[$src] |= $ctype{"katakana"} if $name =~ /(KATAKANA)|(\WKANA\W)/;
  628. $category_table[$src] |= $ctype{"ideograph"} if $name =~ /^<CJK Ideograph/;
  629. $category_table[$src] |= $ctype{"ideograph"} if $name =~ /^CJK COMPATIBILITY IDEOGRAPH/;
  630. $category_table[$src] |= $ctype{"ideograph"} if $name =~ /^HANGZHOU/;
  631. $category_table[$src] |= $ctype{"highsurrogate"} if $name =~ /High Surrogate/;
  632. $category_table[$src] |= $ctype{"lowsurrogate"} if $name =~ /Low Surrogate/;
  633. # copy the category and direction for everything between First/Last pairs
  634. if ($name =~ /, First>/) { $start = $src; }
  635. if ($name =~ /, Last>/)
  636. {
  637. while ($start < $src)
  638. {
  639. $category_table[$start] = $category_table[$src];
  640. $direction_table[$start] = $direction_table[$src];
  641. $combining_class_table[$start] = $combining_class_table[$src];
  642. $start++;
  643. }
  644. }
  645. next if $decomp eq ""; # no decomposition, skip it
  646. if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)/)
  647. {
  648. my @seq = map { hex $_; } (split /\s+/, (split /\s+/, $decomp, 2)[1]);
  649. $decomp_compat_table[$src] = \@seq;
  650. }
  651. if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
  652. {
  653. # decomposition of the form "<foo> 1234" -> use char if type is known
  654. if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
  655. {
  656. ${joining_forms{$1}}[hex $2] = $src;
  657. }
  658. }
  659. elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
  660. {
  661. # decomposition "<compat> 0020 1234" -> combining accent
  662. }
  663. elsif ($decomp =~ /^([0-9a-fA-F]+)/)
  664. {
  665. # store decomposition
  666. if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
  667. {
  668. $decomp_table[$src] = $decomp_compat_table[$src] = [ hex $1, hex $2 ];
  669. }
  670. elsif ($decomp =~ /^([0-9a-fA-F]+)$/)
  671. {
  672. # Single char decomposition
  673. $decomp_table[$src] = $decomp_compat_table[$src] = [ hex $1 ];
  674. }
  675. }
  676. }
  677. close $UNICODE_DATA;
  678. # patch the category of some special characters
  679. for (my $i = 0; $i < @decomp_table; $i++)
  680. {
  681. next unless defined $decomp_table[$i];
  682. $category_table[$i] |= $category_table[$decomp_table[$i]->[0]];
  683. }
  684. foreach my $cat (keys %special_categories)
  685. {
  686. my $flag = $ctype{$cat};
  687. foreach my $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
  688. }
  689. for (my $i = 0; $i < @decomp_compat_table; $i++)
  690. {
  691. next unless defined $decomp_compat_table[$i];
  692. next unless @{$decomp_compat_table[$i]} == 2;
  693. $category_table[$i] |= $category_table[$decomp_compat_table[$i]->[1]] & $ctype{"diacritic"};
  694. }
  695. # load the composition exclusions
  696. my $EXCL = open_data_file( $UNIDATA, "CompositionExclusions.txt" );
  697. while (<$EXCL>)
  698. {
  699. s/\#.*//; # remove comments
  700. if (/^([0-9a-fA-F]+)\.\.([0-9a-fA-F]+)\s*$/)
  701. {
  702. foreach my $i (hex $1 .. hex $2) { $comp_exclusions[$i] = 1; }
  703. }
  704. elsif (/^([0-9a-fA-F]+)\s*$/)
  705. {
  706. $comp_exclusions[hex $1] = 1;
  707. }
  708. }
  709. close $EXCL;
  710. # load the IDNA mappings
  711. @idna_decomp_table = @decomp_compat_table;
  712. my $IDNA = open_data_file( $IDNADATA, "IdnaMappingTable.txt" );
  713. while (<$IDNA>)
  714. {
  715. s/\#.*//; # remove comments
  716. next if /^\s*$/;
  717. my ($char, $type, $mapping) = split /;/;
  718. my ($ch1, $ch2);
  719. if ($char =~ /([0-9a-fA-F]+)\.\.([0-9a-fA-F]+)/)
  720. {
  721. $ch1 = hex $1;
  722. $ch2 = hex $2;
  723. }
  724. elsif ($char =~ /([0-9a-fA-F]+)/)
  725. {
  726. $ch1 = $ch2 = hex $1;
  727. }
  728. if ($type =~ /mapped/ || $type =~ /deviation/)
  729. {
  730. $mapping =~ s/^\s*(([0-9a-fA-F]+\s+)+)\s*$/$1/;
  731. my @seq = map { hex $_; } split /\s+/, $mapping;
  732. foreach my $i ($ch1 .. $ch2) { $idna_decomp_table[$i] = @seq ? \@seq : [ 0 ]; }
  733. }
  734. elsif ($type =~ /valid/)
  735. {
  736. }
  737. elsif ($type =~ /ignored/)
  738. {
  739. foreach my $i ($ch1 .. $ch2) { $idna_decomp_table[$i] = [ 0 ]; }
  740. }
  741. elsif ($type =~ /disallowed/)
  742. {
  743. foreach my $i ($ch1 .. $ch2)
  744. {
  745. $idna_decomp_table[$i] = undef;
  746. $idna_disallowed[$i] = 1;
  747. }
  748. }
  749. }
  750. close $IDNA;
  751. }
  752. ################################################################
  753. # add a new registry key
  754. sub add_registry_key($$)
  755. {
  756. my ($key, $defval) = @_;
  757. $registry_keys{$key} = [ $defval ] unless defined $registry_keys{$key};
  758. }
  759. ################################################################
  760. # add a new registry value
  761. sub add_registry_value($$$)
  762. {
  763. my ($key, $name, $value) = @_;
  764. add_registry_key( $key, undef );
  765. push @{$registry_keys{$key}}, "'$name' = s '$value'";
  766. }
  767. ################################################################
  768. # define a new lead byte
  769. sub add_lead_byte($)
  770. {
  771. my $ch = shift;
  772. return if defined $cp2uni[$ch];
  773. push @lead_bytes, $ch;
  774. $cp2uni[$ch] = 0;
  775. }
  776. ################################################################
  777. # define a new char mapping
  778. sub add_mapping($$)
  779. {
  780. my ($cp, $uni) = @_;
  781. $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
  782. $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
  783. if ($cp > 0xff) { add_lead_byte( $cp >> 8 ); }
  784. }
  785. ################################################################
  786. # get a mapping including glyph chars for MB_USEGLYPHCHARS
  787. sub get_glyphs_mapping(@)
  788. {
  789. my @table = @_;
  790. for (my $i = 0; $i < @glyph2uni; $i++)
  791. {
  792. $table[$i] = $glyph2uni[$i] if defined $glyph2uni[$i];
  793. }
  794. return @table;
  795. }
  796. ################################################################
  797. # build EUC-JP table from the JIS 0208/0212 files
  798. sub dump_eucjp_codepage()
  799. {
  800. @cp2uni = ();
  801. @glyph2uni = ();
  802. @lead_bytes = ();
  803. @uni2cp = ();
  804. $default_char = $DEF_CHAR;
  805. $default_wchar = 0x30fb;
  806. # ASCII chars
  807. foreach my $i (0x00 .. 0x7f) { add_mapping( $i, $i ); }
  808. # lead bytes
  809. foreach my $i (0x8e, 0xa1 .. 0xfe) { add_lead_byte($i); }
  810. # JIS X 0201 right plane
  811. foreach my $i (0xa1 .. 0xdf) { add_mapping( 0x8e00 + $i, 0xfec0 + $i ); }
  812. # undefined chars
  813. foreach my $i (0x80 .. 0x8d, 0x8f .. 0x9f) { $cp2uni[$i] = $i; }
  814. $cp2uni[0xa0] = 0xf8f0;
  815. $cp2uni[0xff] = 0xf8f3;
  816. # Fix backslash conversion
  817. add_mapping( 0xa1c0, 0xff3c );
  818. # Add private mappings for rows undefined in JIS 0208/0212
  819. my $private = 0xe000;
  820. foreach my $hi (0xf5 .. 0xfe)
  821. {
  822. foreach my $lo (0xa1 .. 0xfe)
  823. {
  824. add_mapping( ($hi << 8) + $lo, $private++ );
  825. }
  826. }
  827. foreach my $hi (0xf5 .. 0xfe)
  828. {
  829. foreach my $lo (0x21 .. 0x7e)
  830. {
  831. add_mapping( ($hi << 8) + $lo, $private++ );
  832. }
  833. }
  834. my $INPUT = open_data_file( $JISDATA, "JIS0208.TXT" );
  835. while (<$INPUT>)
  836. {
  837. next if /^\#/; # skip comments
  838. next if /^$/; # skip empty lines
  839. next if /\x1a/; # skip ^Z
  840. if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
  841. {
  842. add_mapping( 0x8080 + hex $1, hex $2 );
  843. next;
  844. }
  845. die "Unrecognized line $_\n";
  846. }
  847. close $INPUT;
  848. $INPUT = open_data_file( $JISDATA, "JIS0212.TXT" );
  849. while (<$INPUT>)
  850. {
  851. next if /^\#/; # skip comments
  852. next if /^$/; # skip empty lines
  853. next if /\x1a/; # skip ^Z
  854. if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
  855. {
  856. add_mapping( 0x8000 + hex $1, hex $2 );
  857. next;
  858. }
  859. die "Unrecognized line $_\n";
  860. }
  861. close $INPUT;
  862. output_codepage_file( 20932 );
  863. }
  864. ################################################################
  865. # build the sort keys table
  866. sub dump_sortkeys($)
  867. {
  868. my $filename = shift;
  869. my @sortkeys = ();
  870. my $INPUT = open_data_file( $REPORTS, $SORTKEYS );
  871. while (<$INPUT>)
  872. {
  873. next if /^\#/; # skip comments
  874. next if /^$/; # skip empty lines
  875. next if /\x1a/; # skip ^Z
  876. next if /^\@version/; # skip @version header
  877. if (/^([0-9a-fA-F]+)\s+;\s+\[([*.])([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]+)\]/)
  878. {
  879. my ($uni,$variable) = (hex $1, $2);
  880. next if $uni > 65535;
  881. $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
  882. next;
  883. }
  884. if (/^([0-9a-fA-F]+\s+)+;\s+\[[*.]([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]+)\]/)
  885. {
  886. # multiple character sequence, ignored for now
  887. next;
  888. }
  889. die "$SORTKEYS: Unrecognized line $_\n";
  890. }
  891. close $INPUT;
  892. # compress the keys to 32 bit:
  893. # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
  894. @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
  895. ${$a}[2] <=> ${$b}[2] or
  896. ${$a}[3] <=> ${$b}[3] or
  897. ${$a}[4] <=> ${$b}[4] or
  898. $a cmp $b; } @sortkeys;
  899. my ($n2, $n3) = (1, 1);
  900. my @keys = (-1, -1, -1, -1, -1 );
  901. my @flatkeys = ();
  902. for (my $i = 0; $i < @sortkeys; $i++)
  903. {
  904. next unless defined $sortkeys[$i];
  905. my @current = @{$sortkeys[$i]};
  906. if ($current[1] == $keys[1])
  907. {
  908. if ($current[2] == $keys[2])
  909. {
  910. if ($current[3] == $keys[3])
  911. {
  912. # nothing
  913. }
  914. else
  915. {
  916. $keys[3] = $current[3];
  917. $n3++;
  918. die if ($n3 >= 16);
  919. }
  920. }
  921. else
  922. {
  923. $keys[2] = $current[2];
  924. $keys[3] = $current[3];
  925. $n2++;
  926. $n3 = 1;
  927. die if ($n2 >= 256);
  928. }
  929. }
  930. else
  931. {
  932. $keys[1] = $current[1];
  933. $keys[2] = $current[2];
  934. $keys[3] = $current[3];
  935. $n2 = 1;
  936. $n3 = 1;
  937. }
  938. if ($current[2]) { $current[2] = $n2; }
  939. if ($current[3]) { $current[3] = $n3; }
  940. if ($current[4]) { $current[4] = 1; }
  941. $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
  942. }
  943. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  944. printf "Building $filename\n";
  945. printf OUTPUT "/* Unicode collation element table */\n";
  946. printf OUTPUT "/* generated from %s */\n", "$REPORTS/$SORTKEYS";
  947. printf OUTPUT "/* DO NOT EDIT!! */\n\n";
  948. print OUTPUT "#include \"windef.h\"\n\n";
  949. dump_two_level_mapping( "collation_table", 0xffffffff, 32, @flatkeys );
  950. close OUTPUT;
  951. save_file($filename);
  952. }
  953. ################################################################
  954. # dump an array of integers
  955. sub dump_array($$@)
  956. {
  957. my ($bit_width, $default, @array) = @_;
  958. my $format = sprintf "0x%%0%ux", $bit_width / 4;
  959. my $i;
  960. my $ret = " ";
  961. for ($i = 0; $i < $#array; $i++)
  962. {
  963. $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
  964. $ret .= (($i % 8) != 7) ? ", " : ",\n ";
  965. }
  966. $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
  967. return $ret;
  968. }
  969. ################################################################
  970. # dump an SBCS mapping table in binary format
  971. sub dump_binary_sbcs_table($)
  972. {
  973. my $codepage = shift;
  974. my @header = ( 13, $codepage, 1, $default_char, $default_wchar, $cp2uni[$default_char], $uni2cp[$default_wchar] );
  975. my $wc_offset = 256 + 3 + (@glyph2uni ? 256 : 0);
  976. print OUTPUT pack "S<*", @header;
  977. print OUTPUT pack "C12", (0) x 12;
  978. print OUTPUT pack "S<*", $wc_offset, map { $_ || 0; } @cp2uni[0 .. 255];
  979. if (@glyph2uni)
  980. {
  981. print OUTPUT pack "S<*", 256, get_glyphs_mapping(@cp2uni[0 .. 255]);
  982. }
  983. else
  984. {
  985. print OUTPUT pack "S<*", 0;
  986. }
  987. print OUTPUT pack "S<*", 0, 0;
  988. print OUTPUT pack "C*", map { defined $_ ? $_ : $default_char; } @uni2cp[0 .. 65535];
  989. }
  990. ################################################################
  991. # dump a DBCS mapping table in binary format
  992. sub dump_binary_dbcs_table($)
  993. {
  994. my $codepage = shift;
  995. my @lb_ranges = get_lb_ranges();
  996. my @header = ( 13, $codepage, 2, $default_char, $default_wchar, $cp2uni[$default_char], $uni2cp[$default_wchar] );
  997. my @offsets = (0) x 256;
  998. my $pos = 0;
  999. foreach my $i (@lead_bytes)
  1000. {
  1001. $offsets[$i] = ($pos += 256);
  1002. $cp2uni[$i] = 0;
  1003. }
  1004. my $wc_offset = 256 + 3 + 256 * (1 + scalar @lead_bytes);
  1005. print OUTPUT pack "S<*", @header;
  1006. print OUTPUT pack "C12", @lb_ranges, 0 x 12;
  1007. print OUTPUT pack "S<*", $wc_offset, map { $_ || 0; } @cp2uni[0 .. 255];
  1008. print OUTPUT pack "S<*", 0, scalar @lb_ranges / 2, @offsets;
  1009. foreach my $i (@lead_bytes)
  1010. {
  1011. my $base = $i << 8;
  1012. print OUTPUT pack "S<*", map { defined $_ ? $_ : $default_wchar; } @cp2uni[$base .. $base + 255];
  1013. }
  1014. print OUTPUT pack "S<", 4;
  1015. print OUTPUT pack "S<*", map { defined $_ ? $_ : $default_char; } @uni2cp[0 .. 65535];
  1016. }
  1017. ################################################################
  1018. # get the list of defined lead byte ranges
  1019. sub get_lb_ranges()
  1020. {
  1021. my @list = ();
  1022. my @ranges = ();
  1023. foreach my $i (@lead_bytes) { $list[$i] = 1; }
  1024. my $on = 0;
  1025. for (my $i = 0; $i < 256; $i++)
  1026. {
  1027. if ($on)
  1028. {
  1029. if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
  1030. }
  1031. else
  1032. {
  1033. if ($list[$i]) { push @ranges, $i; $on = 1; }
  1034. }
  1035. }
  1036. if ($on) { push @ranges, 0xff; }
  1037. return @ranges;
  1038. }
  1039. ################################################################
  1040. # dump the Indic Syllabic Category table
  1041. sub dump_indic($)
  1042. {
  1043. my $filename = shift;
  1044. my @indic_table;
  1045. my $INPUT = open_data_file( $UNIDATA, "IndicSyllabicCategory.txt" );
  1046. while (<$INPUT>)
  1047. {
  1048. next if /^\#/; # skip comments
  1049. next if /^\s*$/; # skip empty lines
  1050. next if /\x1a/; # skip ^Z
  1051. if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
  1052. {
  1053. my $type = $2;
  1054. die "unknown indic $type" unless defined $indic_types{$type};
  1055. if (hex $1 < 65536)
  1056. {
  1057. $indic_table[hex $1] = $indic_types{$type};
  1058. }
  1059. next;
  1060. }
  1061. elsif (/^\s*([0-9a-fA-F]+)\.\.\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
  1062. {
  1063. my $type = $3;
  1064. die "unknown indic $type" unless defined $indic_types{$type};
  1065. if (hex $1 < 65536 and hex $2 < 65536)
  1066. {
  1067. foreach my $i (hex $1 .. hex $2)
  1068. {
  1069. $indic_table[$i] = $indic_types{$type};
  1070. }
  1071. }
  1072. next;
  1073. }
  1074. die "malformed line $_";
  1075. }
  1076. close $INPUT;
  1077. $INPUT = open_data_file( $UNIDATA, "IndicPositionalCategory.txt" );
  1078. while (<$INPUT>)
  1079. {
  1080. next if /^\#/; # skip comments
  1081. next if /^\s*$/; # skip empty lines
  1082. next if /\x1a/; # skip ^Z
  1083. if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
  1084. {
  1085. my $type = $2;
  1086. die "unknown matra $type" unless defined $matra_types{$type};
  1087. $indic_table[hex $1] |= $matra_types{$type} << 8;
  1088. next;
  1089. }
  1090. elsif (/^\s*([0-9a-fA-F]+)\.\.\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
  1091. {
  1092. my $type = $3;
  1093. die "unknown matra $type" unless defined $matra_types{$type};
  1094. foreach my $i (hex $1 .. hex $2)
  1095. {
  1096. $indic_table[$i] |= $matra_types{$type} << 8;
  1097. }
  1098. next;
  1099. }
  1100. die "malformed line $_";
  1101. }
  1102. close $INPUT;
  1103. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1104. print "Building $filename\n";
  1105. print OUTPUT "/* Unicode Indic Syllabic Category */\n";
  1106. print OUTPUT "/* generated from $UNIDATA:IndicSyllabicCategory.txt */\n";
  1107. print OUTPUT "/* and from $UNIDATA:IndicPositionalCategory.txt */\n";
  1108. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1109. print OUTPUT "#include \"windef.h\"\n\n";
  1110. dump_two_level_mapping( "indic_syllabic_table", $indic_types{'Other'}, 16, @indic_table );
  1111. close OUTPUT;
  1112. save_file($filename);
  1113. }
  1114. ################################################################
  1115. # dump the Line Break Properties table
  1116. sub dump_linebreak($)
  1117. {
  1118. my $filename = shift;
  1119. my @break_table;
  1120. my $next_group = 0;
  1121. my $INPUT = open_data_file( $UNIDATA, "LineBreak.txt" );
  1122. while (<$INPUT>)
  1123. {
  1124. next if /^\#/; # skip comments
  1125. next if /^\s*$/; # skip empty lines
  1126. next if /\x1a/; # skip ^Z
  1127. if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
  1128. {
  1129. my $type = $2;
  1130. die "unknown breaktype $type" unless defined $break_types{$type};
  1131. $break_table[hex $1] = $break_types{$type};
  1132. next;
  1133. }
  1134. elsif (/^\s*([0-9a-fA-F]+)\.\.\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
  1135. {
  1136. my $type = $3;
  1137. die "unknown breaktype $type" unless defined $break_types{$type};
  1138. foreach my $i (hex $1 .. hex $2)
  1139. {
  1140. $break_table[$i] = $break_types{$type};
  1141. }
  1142. next;
  1143. }
  1144. elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
  1145. {
  1146. my $type = $2;
  1147. die "unknown breaktype $type" unless defined $break_types{$type};
  1148. $break_table[hex $1] = $break_types{$type};
  1149. next;
  1150. }
  1151. elsif (/^\s*([0-9a-fA-F]+)\.\.\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
  1152. {
  1153. my $type = $3;
  1154. die "unknown breaktype $type" unless defined $break_types{$type};
  1155. foreach my $i (hex $1 .. hex $2)
  1156. {
  1157. $break_table[$i] = $break_types{$type};
  1158. }
  1159. next;
  1160. }
  1161. die "malformed line $_";
  1162. }
  1163. close $INPUT;
  1164. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1165. print "Building $filename\n";
  1166. print OUTPUT "/* Unicode Line Break Properties */\n";
  1167. print OUTPUT "/* generated from $UNIDATA:LineBreak.txt */\n";
  1168. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1169. print OUTPUT "#include \"windef.h\"\n\n";
  1170. dump_two_level_mapping( "wine_linebreak_table", $break_types{'XX'}, 16, @break_table );
  1171. close OUTPUT;
  1172. save_file($filename);
  1173. }
  1174. my %scripts =
  1175. (
  1176. "Unknown" => 0,
  1177. "Common" => 1,
  1178. "Inherited" => 2,
  1179. "Arabic" => 3,
  1180. "Armenian" => 4,
  1181. "Avestan" => 5,
  1182. "Balinese" => 6,
  1183. "Bamum" => 7,
  1184. "Batak" => 8,
  1185. "Bengali" => 9,
  1186. "Bopomofo" => 10,
  1187. "Brahmi" => 11,
  1188. "Braille" => 12,
  1189. "Buginese" => 13,
  1190. "Buhid" => 14,
  1191. "Canadian_Aboriginal" => 15,
  1192. "Carian" => 16,
  1193. "Cham" => 17,
  1194. "Cherokee" => 18,
  1195. "Coptic" => 19,
  1196. "Cuneiform" => 20,
  1197. "Cypriot" => 21,
  1198. "Cyrillic" => 22,
  1199. "Deseret" => 23,
  1200. "Devanagari" => 24,
  1201. "Egyptian_Hieroglyphs" => 25,
  1202. "Ethiopic" => 26,
  1203. "Georgian" => 27,
  1204. "Glagolitic" => 28,
  1205. "Gothic" => 29,
  1206. "Greek" => 30,
  1207. "Gujarati" => 31,
  1208. "Gurmukhi" => 32,
  1209. "Han" => 33,
  1210. "Hangul" => 34,
  1211. "Hanunoo" => 35,
  1212. "Hebrew" => 36,
  1213. "Hiragana" => 37,
  1214. "Imperial_Aramaic" => 38,
  1215. "Inscriptional_Pahlavi" => 39,
  1216. "Inscriptional_Parthian" => 40,
  1217. "Javanese" => 41,
  1218. "Kaithi" => 42,
  1219. "Kannada" => 43,
  1220. "Katakana" => 44,
  1221. "Kayah_Li" => 45,
  1222. "Kharoshthi" => 46,
  1223. "Khmer" => 47,
  1224. "Lao" => 48,
  1225. "Latin" => 49,
  1226. "Lepcha" => 50,
  1227. "Limbu" => 51,
  1228. "Linear_B" => 52,
  1229. "Lisu" => 53,
  1230. "Lycian" => 54,
  1231. "Lydian" => 55,
  1232. "Malayalam" => 56,
  1233. "Mandaic" => 57,
  1234. "Meetei_Mayek" => 58,
  1235. "Mongolian" => 59,
  1236. "Myanmar" => 60,
  1237. "New_Tai_Lue" => 61,
  1238. "Nko" => 62,
  1239. "Ogham" => 63,
  1240. "Ol_Chiki" => 64,
  1241. "Old_Italic" => 65,
  1242. "Old_Persian" => 66,
  1243. "Old_South_Arabian" => 67,
  1244. "Old_Turkic" => 68,
  1245. "Oriya" => 69,
  1246. "Osmanya" => 70,
  1247. "Phags_Pa" => 71,
  1248. "Phoenician" => 72,
  1249. "Rejang" => 73,
  1250. "Runic" => 74,
  1251. "Samaritan" => 75,
  1252. "Saurashtra" => 76,
  1253. "Shavian" => 77,
  1254. "Sinhala" => 78,
  1255. "Sundanese" => 79,
  1256. "Syloti_Nagri" => 80,
  1257. "Syriac" => 81,
  1258. "Tagalog" => 82,
  1259. "Tagbanwa" => 83,
  1260. "Tai_Le" => 84,
  1261. "Tai_Tham" => 85,
  1262. "Tai_Viet" => 86,
  1263. "Tamil" => 87,
  1264. "Telugu" => 88,
  1265. "Thaana" => 89,
  1266. "Thai" => 90,
  1267. "Tibetan" => 91,
  1268. "Tifinagh" => 92,
  1269. "Ugaritic" => 93,
  1270. "Vai" => 94,
  1271. "Yi" => 95,
  1272. # Win8/Win8.1
  1273. "Chakma" => 96,
  1274. "Meroitic_Cursive" => 97,
  1275. "Meroitic_Hieroglyphs" => 98,
  1276. "Miao" => 99,
  1277. "Sharada" => 100,
  1278. "Sora_Sompeng" => 101,
  1279. "Takri" => 102,
  1280. # Win10
  1281. "Bassa_Vah" => 103,
  1282. "Caucasian_Albanian" => 104,
  1283. "Duployan" => 105,
  1284. "Elbasan" => 106,
  1285. "Grantha" => 107,
  1286. "Khojki" => 108,
  1287. "Khudawadi" => 109,
  1288. "Linear_A" => 110,
  1289. "Mahajani" => 111,
  1290. "Manichaean" => 112,
  1291. "Mende_Kikakui" => 113,
  1292. "Modi" => 114,
  1293. "Mro" => 115,
  1294. "Nabataean" => 116,
  1295. "Old_North_Arabian" => 117,
  1296. "Old_Permic" => 118,
  1297. "Pahawh_Hmong" => 119,
  1298. "Palmyrene" => 120,
  1299. "Pau_Cin_Hau" => 121,
  1300. "Psalter_Pahlavi" => 122,
  1301. "Siddham" => 123,
  1302. "Tirhuta" => 124,
  1303. "Warang_Citi" => 125,
  1304. # Win10 RS1
  1305. "Adlam" => 126,
  1306. "Ahom" => 127,
  1307. "Anatolian_Hieroglyphs" => 128,
  1308. "Bhaiksuki" => 129,
  1309. "Hatran" => 130,
  1310. "Marchen" => 131,
  1311. "Multani" => 132,
  1312. "Newa" => 133,
  1313. "Old_Hungarian" => 134,
  1314. "Osage" => 135,
  1315. "SignWriting" => 136,
  1316. "Tangut" => 137,
  1317. # Win10 RS4
  1318. "Masaram_Gondi" => 138,
  1319. "Nushu" => 139,
  1320. "Soyombo" => 140,
  1321. "Zanabazar_Square" => 141,
  1322. # Win10 1903
  1323. "Dogra" => 142,
  1324. "Gunjala_Gondi" => 143,
  1325. "Hanifi_Rohingya" => 144,
  1326. "Makasar" => 145,
  1327. "Medefaidrin" => 146,
  1328. "Old_Sogdian" => 147,
  1329. "Sogdian" => 148,
  1330. # Win10 2004
  1331. "Elymaic" => 149,
  1332. "Nyiakeng_Puachue_Hmong" => 150,
  1333. "Nandinagari" => 151,
  1334. "Wancho" => 152,
  1335. );
  1336. ################################################################
  1337. # dump Script IDs table
  1338. sub dump_scripts($)
  1339. {
  1340. my $filename = shift;
  1341. my $header = $filename;
  1342. my @scripts_table;
  1343. my $script_index;
  1344. my $i;
  1345. my $INPUT = open_data_file( $UNIDATA, "Scripts.txt" );
  1346. # Fill the table
  1347. # Unknown script id is always 0, so undefined scripts are automatically treated as such
  1348. while (<$INPUT>)
  1349. {
  1350. my $type = "";
  1351. next if /^\#/; # skip comments
  1352. next if /^\s*$/; # skip empty lines
  1353. next if /\x1a/; # skip ^Z
  1354. if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
  1355. {
  1356. $type = $2;
  1357. if (defined $scripts{$type})
  1358. {
  1359. $scripts_table[hex $1] = $scripts{$type};
  1360. }
  1361. next;
  1362. }
  1363. elsif (/^\s*([0-9a-fA-F]+)\.\.\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
  1364. {
  1365. $type = $3;
  1366. if (defined $scripts{$type})
  1367. {
  1368. foreach my $i (hex $1 .. hex $2)
  1369. {
  1370. $scripts_table[$i] = $scripts{$type};
  1371. }
  1372. }
  1373. next;
  1374. }
  1375. }
  1376. close $INPUT;
  1377. $header = "$filename.h";
  1378. open OUTPUT,">$header.new" or die "Cannot create $header";
  1379. print "Building $header\n";
  1380. print OUTPUT "/* Unicode Script IDs */\n";
  1381. print OUTPUT "/* generated from $UNIDATA:Scripts.txt */\n";
  1382. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1383. print OUTPUT "enum unicode_script_id {\n";
  1384. foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
  1385. {
  1386. print OUTPUT " Script_$script = $scripts{$script},\n";
  1387. }
  1388. print OUTPUT " Script_LastId = ", (scalar keys %scripts) - 1, "\n";
  1389. print OUTPUT "};\n";
  1390. close OUTPUT;
  1391. save_file($header);
  1392. $filename = "$filename.c";
  1393. open OUTPUT,">$filename.new" or die "Cannot create $header";
  1394. print "Building $filename\n";
  1395. print OUTPUT "/* Unicode Script IDs */\n";
  1396. print OUTPUT "/* generated from $UNIDATA:Scripts.txt */\n";
  1397. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1398. print OUTPUT "#include \"windef.h\"\n\n";
  1399. dump_two_level_mapping( "wine_scripts_table", 0, 16, @scripts_table );
  1400. close OUTPUT;
  1401. save_file($filename);
  1402. }
  1403. ################################################################
  1404. # dump the BiDi mirroring table
  1405. sub dump_mirroring($)
  1406. {
  1407. my $filename = shift;
  1408. my @mirror_table = ();
  1409. my $INPUT = open_data_file( $UNIDATA, "BidiMirroring.txt" );
  1410. while (<$INPUT>)
  1411. {
  1412. next if /^\#/; # skip comments
  1413. next if /^$/; # skip empty lines
  1414. next if /\x1a/; # skip ^Z
  1415. if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
  1416. {
  1417. $mirror_table[hex $1] = hex $2;
  1418. next;
  1419. }
  1420. die "malformed line $_";
  1421. }
  1422. close $INPUT;
  1423. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1424. print "Building $filename\n";
  1425. print OUTPUT "/* Unicode BiDi mirroring */\n";
  1426. print OUTPUT "/* generated from $UNIDATA:BidiMirroring.txt */\n";
  1427. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1428. print OUTPUT "#include \"windef.h\"\n\n";
  1429. dump_two_level_mapping( "wine_mirror_map", 0, 16, @mirror_table );
  1430. close OUTPUT;
  1431. save_file($filename);
  1432. }
  1433. ################################################################
  1434. # dump the Bidi Brackets
  1435. sub dump_bracket($)
  1436. {
  1437. my $filename = shift;
  1438. my @bracket_table;
  1439. my $INPUT = open_data_file( $UNIDATA, "BidiBrackets.txt" );
  1440. while (<$INPUT>)
  1441. {
  1442. next if /^\#/; # skip comments
  1443. next if /^\s*$/; # skip empty lines
  1444. next if /\x1a/; # skip ^Z
  1445. if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
  1446. {
  1447. my $type = $3;
  1448. die "unknown bracket $type" unless defined $bracket_types{$type};
  1449. die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
  1450. $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
  1451. $bracket_table[hex $1] += $bracket_types{$type} << 8;
  1452. next;
  1453. }
  1454. die "malformed line $_";
  1455. }
  1456. close $INPUT;
  1457. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1458. print "Building $filename\n";
  1459. print OUTPUT "/* Unicode Bidirectional Bracket table */\n";
  1460. print OUTPUT "/* generated from $UNIDATA:BidiBrackets.txt */\n";
  1461. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1462. print OUTPUT "#include \"windef.h\"\n\n";
  1463. dump_two_level_mapping( "bidi_bracket_table", 0, 16, @bracket_table );
  1464. close OUTPUT;
  1465. save_file($filename);
  1466. }
  1467. ################################################################
  1468. # dump the Arabic shaping table
  1469. sub dump_shaping($)
  1470. {
  1471. my $filename = shift;
  1472. my %groups;
  1473. my $next_group = 0;
  1474. $groups{"No_Joining_Group"} = $next_group++;
  1475. my $INPUT = open_data_file( $UNIDATA, "ArabicShaping.txt" );
  1476. while (<$INPUT>)
  1477. {
  1478. next if /^\#/; # skip comments
  1479. next if /^\s*$/; # skip empty lines
  1480. next if /\x1a/; # skip ^Z
  1481. if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
  1482. {
  1483. my $type = $2;
  1484. my $group = $3;
  1485. $groups{$group} = $next_group++ unless defined $groups{$group};
  1486. $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
  1487. next;
  1488. }
  1489. die "malformed line $_";
  1490. }
  1491. close $INPUT;
  1492. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1493. print "Building $filename\n";
  1494. print OUTPUT "/* Unicode Arabic shaping */\n";
  1495. print OUTPUT "/* generated from $UNIDATA:ArabicShaping.txt */\n";
  1496. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1497. print OUTPUT "#include \"windef.h\"\n\n";
  1498. dump_two_level_mapping( "wine_shaping_table", 0, 16, @joining_table );
  1499. print OUTPUT "\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
  1500. for (my $i = 0x600; $i <= 0x6ff; $i++)
  1501. {
  1502. printf OUTPUT " { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
  1503. ${joining_forms{"isolated"}}[$i] || $i,
  1504. ${joining_forms{"final"}}[$i] || $i,
  1505. ${joining_forms{"initial"}}[$i] || $i,
  1506. ${joining_forms{"medial"}}[$i] || $i;
  1507. }
  1508. print OUTPUT "};\n";
  1509. close OUTPUT;
  1510. save_file($filename);
  1511. }
  1512. ################################################################
  1513. # dump the Vertical Orientation table
  1514. sub dump_vertical($)
  1515. {
  1516. my $filename = shift;
  1517. my @vertical_table;
  1518. my $INPUT = open_data_file( $UNIDATA, "VerticalOrientation.txt" );
  1519. while (<$INPUT>)
  1520. {
  1521. next if /^\#/; # skip comments
  1522. next if /^\s*$/; # skip empty lines
  1523. next if /\x1a/; # skip ^Z
  1524. if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
  1525. {
  1526. my $type = $2;
  1527. die "unknown vertical $type" unless defined $vertical_types{$type};
  1528. if (hex $1 < 65536)
  1529. {
  1530. $vertical_table[hex $1] = $vertical_types{$type};
  1531. }
  1532. next;
  1533. }
  1534. elsif (/^\s*([0-9a-fA-F]+)\.\.\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
  1535. {
  1536. my $type = $3;
  1537. die "unknown vertical $type" unless defined $vertical_types{$type};
  1538. foreach my $i (hex $1 .. hex $2)
  1539. {
  1540. $vertical_table[$i] = $vertical_types{$type};
  1541. }
  1542. next;
  1543. }
  1544. die "malformed line $_";
  1545. }
  1546. close $INPUT;
  1547. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1548. print "Building $filename\n";
  1549. print OUTPUT "/* Unicode Vertical Orientation */\n";
  1550. print OUTPUT "/* generated from $UNIDATA:VerticalOrientation.txt */\n";
  1551. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1552. print OUTPUT "#include \"windef.h\"\n\n";
  1553. dump_two_level_mapping( "vertical_orientation_table", $vertical_types{'R'}, 16, @vertical_table );
  1554. close OUTPUT;
  1555. save_file($filename);
  1556. }
  1557. ################################################################
  1558. # dump the digit folding tables
  1559. sub dump_digit_folding($)
  1560. {
  1561. my ($filename) = shift;
  1562. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1563. print "Building $filename\n";
  1564. print OUTPUT "/* Unicode digit folding mappings */\n";
  1565. print OUTPUT "/* generated from $UNIDATA:UnicodeData.txt */\n";
  1566. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1567. print OUTPUT "#include \"windef.h\"\n\n";
  1568. dump_two_level_mapping( "wine_digitmap", 0, 16, @digitmap_table );
  1569. close OUTPUT;
  1570. save_file($filename);
  1571. }
  1572. ################################################################
  1573. # dump the case mapping tables
  1574. sub dump_case_mappings($)
  1575. {
  1576. my $filename = shift;
  1577. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1578. print "Building $filename\n";
  1579. print OUTPUT "/* Unicode case mappings */\n";
  1580. print OUTPUT "/* generated from $UNIDATA:UnicodeData.txt */\n";
  1581. print OUTPUT "/* DO NOT EDIT!! */\n\n";
  1582. print OUTPUT "#include \"windef.h\"\n\n";
  1583. my @upper = @toupper_table;
  1584. my @lower = @tolower_table;
  1585. remove_linguistic_mappings( \@upper, \@lower );
  1586. dump_case_table( "wine_casemap_lower", @lower );
  1587. print OUTPUT "\n";
  1588. dump_case_table( "wine_casemap_upper", @upper );
  1589. close OUTPUT;
  1590. save_file($filename);
  1591. }
  1592. ################################################################
  1593. # dump a case mapping table
  1594. sub dump_case_table($@)
  1595. {
  1596. my ($name,@table) = @_;
  1597. for (my $i = 0; $i < 65536; $i++)
  1598. {
  1599. next unless defined $table[$i];
  1600. $table[$i] = ($table[$i] - $i) & 0xffff;
  1601. }
  1602. my @array = compress_array( 256, 0, @table[0..65535] );
  1603. printf OUTPUT "const WCHAR %s[%d] =\n", $name, scalar @array;
  1604. printf OUTPUT "{\n /* index */\n";
  1605. printf OUTPUT "%s,\n", dump_array( 16, 0, @array[0..255] );
  1606. printf OUTPUT " /* data */\n";
  1607. printf OUTPUT "%s", dump_array( 16, 0, @array[256..$#array] );
  1608. printf OUTPUT "\n};\n";
  1609. }
  1610. ################################################################
  1611. # compress a mapping table by removing identical rows
  1612. sub compress_array($$@)
  1613. {
  1614. my $rows = shift;
  1615. my $def = shift;
  1616. my @table = @_;
  1617. my $len = @table / $rows;
  1618. my @array;
  1619. my $data = "";
  1620. # try to merge table rows
  1621. for (my $row = 0; $row < $rows; $row++)
  1622. {
  1623. my $rowtxt = pack "U*", map { defined($_) ? $_ : $def; } @table[($row * $len)..(($row + 1) * $len - 1)];
  1624. my $pos = index $data, $rowtxt;
  1625. if ($pos == -1)
  1626. {
  1627. # check if the tail of the data can match the start of the new row
  1628. my $first = substr( $rowtxt, 0, 1 );
  1629. for (my $i = length($data) - 1; $i > 0; $i--)
  1630. {
  1631. $pos = index( substr( $data, -$i ), $first );
  1632. last if $pos == -1;
  1633. $i -= $pos;
  1634. next unless substr( $data, -$i ) eq substr( $rowtxt, 0, $i );
  1635. substr( $data, -$i ) = "";
  1636. last;
  1637. }
  1638. $pos = length $data;
  1639. $data .= $rowtxt;
  1640. }
  1641. $array[$row] = $rows + $pos;
  1642. }
  1643. return @array, unpack "U*", $data;
  1644. }
  1645. ################################################################
  1646. # dump a simple char -> 16-bit value mapping table
  1647. sub dump_simple_mapping($$@)
  1648. {
  1649. my $name = shift;
  1650. my $def = shift;
  1651. my @array = compress_array( 256, $def, @_[0..65535] );
  1652. printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, $#array+1;
  1653. printf OUTPUT " /* offsets */\n%s,\n", dump_array( 16, 0, @array[0..255] );
  1654. printf OUTPUT " /* values */\n%s\n};\n", dump_array( 16, 0, @array[256..$#array] );
  1655. }
  1656. ################################################################
  1657. # dump a char -> 16-bit value mapping table using two-level tables
  1658. sub dump_two_level_mapping($$@)
  1659. {
  1660. my $name = shift;
  1661. my $def = shift;
  1662. my $size = shift;
  1663. my $type = $size == 16 ? "unsigned short" : "unsigned int";
  1664. my @row_array = compress_array( 4096, $def, @_[0..65535] );
  1665. my @array = compress_array( 256, 0, @row_array[0..4095] );
  1666. for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
  1667. printf OUTPUT "const %s DECLSPEC_HIDDEN %s[%d] =\n{\n", $type, $name, @array + @row_array - 4096;
  1668. printf OUTPUT " /* level 1 offsets */\n%s,\n", dump_array( $size, 0, @array[0..255] );
  1669. printf OUTPUT " /* level 2 offsets */\n%s,\n", dump_array( $size, 0, @array[256..$#array] );
  1670. printf OUTPUT " /* values */\n%s\n};\n", dump_array( $size, 0, @row_array[4096..$#row_array] );
  1671. }
  1672. ################################################################
  1673. # dump a char -> value mapping table using three-level tables
  1674. sub dump_three_level_mapping($$@)
  1675. {
  1676. my $name = shift;
  1677. my $def = shift;
  1678. my $size = shift;
  1679. my $type = $size == 16 ? "unsigned short" : "unsigned int";
  1680. my $level3 = ($MAX_CHAR + 1) / 16;
  1681. my $level2 = $level3 / 16;
  1682. my $level1 = $level2 / 16;
  1683. my @array3 = compress_array( $level3, $def, @_[0..$MAX_CHAR] );
  1684. my @array2 = compress_array( $level2, 0, @array3[0..$level3-1] );
  1685. my @array1 = compress_array( $level1, 0, @array2[0..$level2-1] );
  1686. for (my $i = $level2; $i < @array2; $i++) { $array2[$i] += @array1 + @array2 - $level2 - $level3; }
  1687. for (my $i = $level1; $i < @array1; $i++) { $array1[$i] += @array1 - $level2; }
  1688. printf OUTPUT "const %s DECLSPEC_HIDDEN %s[%u] =\n{\n", $type, $name, @array1 + (@array2 - $level2) + (@array3 - $level3);
  1689. printf OUTPUT " /* level 1 offsets */\n%s,\n", dump_array( $size, 0, @array1[0..$level1-1] );
  1690. printf OUTPUT " /* level 2 offsets */\n%s,\n", dump_array( $size, 0, @array1[$level1..$#array1] );
  1691. printf OUTPUT " /* level 3 offsets */\n%s,\n", dump_array( $size, 0, @array2[$level2..$#array2] );
  1692. printf OUTPUT " /* values */\n%s\n};\n", dump_array( $size, 0, @array3[$level3..$#array3] );
  1693. }
  1694. ################################################################
  1695. # dump a binary case mapping table in l_intl.nls format
  1696. sub dump_binary_case_table(@)
  1697. {
  1698. my (@table) = @_;
  1699. my $max_char = 0x10000;
  1700. my $level1 = $max_char / 16;
  1701. my $level2 = $level1 / 16;
  1702. my @difftable;
  1703. for (my $i = 0; $i < @table; $i++)
  1704. {
  1705. next unless defined $table[$i];
  1706. $difftable[$i] = ($table[$i] - $i) & 0xffff;
  1707. }
  1708. my @row_array = compress_array( $level1, 0, @difftable[0..$max_char-1] );
  1709. my @array = compress_array( $level2, 0, @row_array[0..$level1-1] );
  1710. my $offset = @array - $level1;
  1711. for (my $i = $level2; $i < @array; $i++) { $array[$i] += $offset; }
  1712. return pack "S<*", 1 + $offset + @row_array, @array, @row_array[$level1..$#row_array];
  1713. }
  1714. ################################################################
  1715. # dump case mappings for l_intl.nls
  1716. sub dump_intl_nls($)
  1717. {
  1718. my @upper_table = @toupper_table;
  1719. my @lower_table = @tolower_table;
  1720. remove_linguistic_mappings( \@upper_table, \@lower_table );
  1721. my $upper = dump_binary_case_table( @upper_table );
  1722. my $lower = dump_binary_case_table( @lower_table );
  1723. my $filename = shift;
  1724. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1725. printf "Building $filename\n";
  1726. binmode OUTPUT;
  1727. print OUTPUT pack "S<", 1; # version
  1728. print OUTPUT $upper;
  1729. print OUTPUT $lower;
  1730. close OUTPUT;
  1731. save_file($filename);
  1732. }
  1733. ################################################################
  1734. # dump the bidi direction table
  1735. sub dump_bidi_dir_table($)
  1736. {
  1737. my $filename = shift;
  1738. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1739. printf "Building $filename\n";
  1740. printf OUTPUT "/* Unicode BiDi direction table */\n";
  1741. printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
  1742. printf OUTPUT "#include \"windef.h\"\n\n";
  1743. my @table;
  1744. for (my $i = 0; $i < 65536; $i++)
  1745. {
  1746. $table[$i] = $bidi_types{$direction_table[$i]} if defined $direction_table[$i];
  1747. }
  1748. dump_two_level_mapping( "bidi_direction_table", $bidi_types{"L"}, 16, @table );
  1749. close OUTPUT;
  1750. save_file($filename);
  1751. }
  1752. ################################################################
  1753. # dump the ctype tables
  1754. sub dump_ctype_tables($)
  1755. {
  1756. my $filename = shift;
  1757. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1758. printf "Building $filename\n";
  1759. printf OUTPUT "/* Unicode ctype tables */\n";
  1760. printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
  1761. printf OUTPUT "#include \"windef.h\"\n\n";
  1762. my @table = map { ($_ || 0) & 0xffff; } @category_table;
  1763. # add the direction in the high 4 bits of the category
  1764. for (my $i = 0; $i < 65536; $i++)
  1765. {
  1766. $table[$i] |= $directions{$direction_table[$i]} << 12 if defined $direction_table[$i];
  1767. }
  1768. dump_simple_mapping( "wine_wctype_table", 0, @table );
  1769. close OUTPUT;
  1770. save_file($filename);
  1771. }
  1772. sub rol($$)
  1773. {
  1774. my ($byte, $count) = @_;
  1775. return (($byte << $count) | ($byte >> (8 - $count))) & 0xff;
  1776. }
  1777. ################################################################
  1778. # compress the character properties table
  1779. sub compress_char_props_table($@)
  1780. {
  1781. my $rows = shift;
  1782. my @table = @_;
  1783. my $len = @table / $rows;
  1784. my $pos = 0;
  1785. my @array = (0) x $rows;
  1786. my %sequences;
  1787. # add some predefined sequences
  1788. foreach my $i (0, 0xfb .. 0xff) { $sequences{pack "L*", (rol($i,5)) x $len} = $i; }
  1789. # try to merge table rows
  1790. for (my $row = 0; $row < $rows; $row++)
  1791. {
  1792. my @table_row = map { defined $_ ? $_ : 0x7f; } @table[($row * $len)..(($row + 1) * $len - 1)];
  1793. my $rowtxt = pack "L*", @table_row;
  1794. if (defined($sequences{$rowtxt}))
  1795. {
  1796. # reuse an existing row
  1797. $array[$row] = $sequences{$rowtxt};
  1798. }
  1799. else
  1800. {
  1801. # create a new row
  1802. $sequences{$rowtxt} = $array[$row] = ++$pos;
  1803. push @array, @table_row;
  1804. }
  1805. }
  1806. return @array;
  1807. }
  1808. ################################################################
  1809. # dump a normalization table in binary format
  1810. sub dump_norm_table($)
  1811. {
  1812. my $filename = shift;
  1813. my %forms = ( "nfc" => 1, "nfd" => 2, "nfkc" => 5, "nfkd" => 6, "idna" => 13 );
  1814. my %decomp = ( "nfc" => \@decomp_table,
  1815. "nfd" => \@decomp_table,
  1816. "nfkc" => \@decomp_compat_table,
  1817. "nfkd" => \@decomp_compat_table ,
  1818. "idna" => \@idna_decomp_table );
  1819. open OUTPUT,">$filename.new" or die "Cannot create $filename";
  1820. print "Building $filename\n";
  1821. my $type = $filename;
  1822. $type =~ s!.*/norm(\w+)\.nls!$1!;
  1823. my $compose = $forms{$type} & 1;
  1824. my $compat = !!($forms{$type} & 4) + ($type eq "idna");
  1825. my @version = split /\./, $UNIVERSION;
  1826. # combining classes
  1827. my @classes;
  1828. my @class_values;
  1829. foreach my $c (grep defined, @combining_class_table)
  1830. {
  1831. $classes[$c] = 1 if $c < 0x100;
  1832. }
  1833. for (my $i = 0; $i < @classes; $i++)
  1834. {
  1835. next unless defined $classes[$i];
  1836. $classes[$i] = @class_values;
  1837. push @class_values, $i;
  1838. }
  1839. push @class_values, 0 if (@class_values % 2);
  1840. die "too many classes" if @class_values >= 0x40;
  1841. # character properties
  1842. my @char_props;
  1843. my @decomposed;
  1844. my @comp_hash_table;
  1845. my $comp_hash_size = $compose ? 254 : 0;
  1846. for (my $i = 0; $i <= $MAX_CHAR; $i++)
  1847. {
  1848. next unless defined $combining_class_table[$i];
  1849. if (defined $decomp{$type}->[$i])
  1850. {
  1851. my @dec = get_decomposition( $i, $decomp{$type} );
  1852. if ($compose && (my @comp = get_composition( $i, $compat )))
  1853. {
  1854. my $hash = ($comp[0] + 95 * $comp[1]) % $comp_hash_size;
  1855. push @{$comp_hash_table[$hash]}, to_utf16( @comp, $i );
  1856. my $val = 0;
  1857. foreach my $d (@dec)
  1858. {
  1859. $val = $combining_class_table[$d];
  1860. last if $val;
  1861. }
  1862. $char_props[$i] = $classes[$val];
  1863. }
  1864. else
  1865. {
  1866. $char_props[$i] = 0xbf;
  1867. }
  1868. @dec = compose_hangul( @dec ) if $compose;
  1869. @dec = to_utf16( @dec );
  1870. push @dec, 0 if @dec >= 7;
  1871. $decomposed[$i] = \@dec;
  1872. }
  1873. else
  1874. {
  1875. if ($combining_class_table[$i] == 0x100)
  1876. {
  1877. $char_props[$i] = 0x7f;
  1878. }
  1879. elsif ($combining_class_table[$i])
  1880. {
  1881. $char_props[$i] = $classes[$combining_class_table[$i]] | 0x80;
  1882. }
  1883. elsif ($type eq "idna" && defined $idna_disallowed[$i])
  1884. {
  1885. $char_props[$i] = 0xff;
  1886. }
  1887. else
  1888. {
  1889. $char_props[$i] = 0;
  1890. }
  1891. }
  1892. }
  1893. if ($compose)
  1894. {
  1895. for (my $i = 0; $i <= $MAX_CHAR; $i++)
  1896. {
  1897. my @comp = get_composition( $i, $compat );
  1898. next unless @comp;
  1899. if ($combining_class_table[$comp[1]])
  1900. {
  1901. $char_props[$comp[0]] |= 0x40 unless $char_props[$comp[0]] & 0x80;
  1902. $char_props[$comp[1]] |= 0x40;
  1903. }
  1904. else
  1905. {
  1906. $char_props[$comp[0]] = ($char_props[$comp[0]] & ~0x40) | 0x80;
  1907. $char_props[$comp[1]] |= 0xc0;
  1908. }
  1909. }
  1910. }
  1911. # surrogates
  1912. foreach my $i (0xd800..0xdbff) { $char_props[$i] = 0xdf; }
  1913. foreach my $i (0xdc00..0xdfff) { $char_props[$i] = 0x9f; }
  1914. # Hangul
  1915. if ($type eq "nfc") { foreach my $i (0x1100..0x117f) { $char_props[$i] = 0xff; } }
  1916. elsif ($compose) { foreach my $i (0x1100..0x11ff) { $char_props[$i] = 0xff; } }
  1917. foreach my $i (0xac00..0xd7ff) { $char_props[$i] = 0xff; }
  1918. # invalid chars
  1919. if ($type eq "idna") { foreach my $i (0x00..0x1f, 0x7f) { $char_props[$i] = 0xff; } }
  1920. foreach my $i (0xfdd0..0xfdef) { $char_props[$i] = 0xff; }
  1921. foreach my $i (0x00..0x10)
  1922. {
  1923. $char_props[($i << 16) | 0xfffe] = 0xff;
  1924. $char_props[($i << 16) | 0xffff] = 0xff;
  1925. }
  1926. # decomposition hash table
  1927. my @decomp_hash_table;
  1928. my @decomp_hash_index;
  1929. my @decomp_hash_data;
  1930. my $decomp_hash_size = 944;
  1931. # build string of character data, reusing substrings when possible
  1932. my $decomp_char_data = "";
  1933. foreach my $i (sort { @{$b} <=> @{$a} } grep defined, @decomposed)
  1934. {
  1935. my $str = pack "U*", @{$i};
  1936. $decomp_char_data .= $str if index( $decomp_char_data, $str) == -1;
  1937. }
  1938. for (my $i = 0; $i < @decomposed; $i++)
  1939. {
  1940. next unless defined $decomposed[$i];
  1941. my $pos = index( $decomp_char_data, pack( "U*", @{$decomposed[$i]} ));
  1942. die "sequence not found" if $pos == -1;
  1943. my $len = @{$decomposed[$i]};
  1944. $len = 7 if $len > 7;
  1945. my $hash = $i % $decomp_hash_size;
  1946. push @{$decomp_hash_table[$hash]}, [ $i, ($len << 13) | $pos ];
  1947. }
  1948. for (my $i = 0; $i < $decomp_hash_size; $i++)
  1949. {
  1950. $decomp_hash_index[$i] = @decomp_hash_data / 2;
  1951. next unless defined $decomp_hash_table[$i];
  1952. if (@{$decomp_hash_table[$i]} == 1)
  1953. {
  1954. my $entry = $decomp_hash_table[$i]->[0];
  1955. if ($char_props[$entry->[0]] == 0xbf)
  1956. {
  1957. $decomp_hash_index[$i] = $entry->[1];
  1958. next;
  1959. }
  1960. }
  1961. foreach my $entry (@{$decomp_hash_table[$i]})
  1962. {
  1963. push @decomp_hash_data, $entry->[0] & 0xffff, $entry->[1];
  1964. }
  1965. }
  1966. push @decomp_hash_data, 0, 0;
  1967. # composition hash table
  1968. my @comp_hash_index;
  1969. my @comp_hash_data;
  1970. if (@comp_hash_table)
  1971. {
  1972. for (my $i = 0; $i < $comp_hash_size; $i++)
  1973. {
  1974. $comp_hash_index[$i] = @comp_hash_data;
  1975. push @comp_hash_data, @{$comp_hash_table[$i]} if defined $comp_hash_table[$i];
  1976. }
  1977. $comp_hash_index[$comp_hash_size] = @comp_hash_data;
  1978. push @comp_hash_data, 0, 0, 0;
  1979. }
  1980. my $level1 = ($MAX_CHAR + 1) / 128;
  1981. my @rows = compress_char_props_table( $level1, @char_props[0..$MAX_CHAR] );
  1982. my @header = ( $version[0], $version[1], $version[2], 0, $forms{$type}, $compat ? 18 : 3,
  1983. 0, $decomp_hash_size, $comp_hash_size, 0 );
  1984. my @tables = (0) x 8;
  1985. $tables[0] = 16 + @header + @tables;
  1986. $tables[1] = $tables[0] + @class_values / 2;
  1987. $tables[2] = $tables[1] + $level1 / 2;
  1988. $tables[3] = $tables[2] + (@rows - $level1) / 2;
  1989. $tables[4] = $tables[3] + @decomp_hash_index;
  1990. $tables[5] = $tables[4] + @decomp_hash_data;
  1991. $tables[6] = $tables[5] + length $decomp_char_data;
  1992. $tables[7] = $tables[6] + @comp_hash_index;
  1993. print OUTPUT pack "S<16", unpack "U*", "norm$type.nlp";
  1994. print OUTPUT pack "S<*", @header;
  1995. print OUTPUT pack "S<*", @tables;
  1996. print OUTPUT pack "C*", @class_values;
  1997. print OUTPUT pack "C*", @rows[0..$level1-1];
  1998. print OUTPUT pack "C*", @rows[$level1..$#rows];
  1999. print OUTPUT pack "S<*", @decomp_hash_index;
  2000. print OUTPUT pack "S<*", @decomp_hash_data;
  2001. print OUTPUT pack "S<*", unpack "U*", $decomp_char_data;
  2002. print OUTPUT pack "S<*", @comp_hash_index;
  2003. print OUTPUT pack "S<*", @comp_hash_data;
  2004. close OUTPUT;
  2005. save_file($filename);
  2006. add_registry_value( "Normalization", sprintf( "%x", $forms{$type} ), "norm$type.nls" );
  2007. }
  2008. ################################################################
  2009. # output a codepage definition file from the global tables
  2010. sub output_codepage_file($)
  2011. {
  2012. my $codepage = shift;
  2013. my $output = sprintf "nls/c_%03d.nls", $codepage;
  2014. open OUTPUT,">$output.new" or die "Cannot create $output";
  2015. printf "Building %s\n", $output;
  2016. if (!@lead_bytes) { dump_binary_sbcs_table( $codepage ); }
  2017. else { dump_binary_dbcs_table( $codepage ); }
  2018. close OUTPUT;
  2019. save_file($output);
  2020. add_registry_value( "Codepage", sprintf( "%d", $codepage ), sprintf( "c_%03d.nls", $codepage ));
  2021. }
  2022. ################################################################
  2023. # output a codepage table from a Microsoft-style mapping file
  2024. sub dump_msdata_codepage($)
  2025. {
  2026. my $filename = shift;
  2027. my $state = "";
  2028. my ($codepage, $width, $count);
  2029. my ($lb_cur, $lb_end);
  2030. @cp2uni = ();
  2031. @glyph2uni = ();
  2032. @lead_bytes = ();
  2033. @uni2cp = ();
  2034. $default_char = $DEF_CHAR;
  2035. $default_wchar = $DEF_CHAR;
  2036. my $INPUT = open_data_file( $MSCODEPAGES, $filename ) or die "Cannot open $filename";
  2037. while (<$INPUT>)
  2038. {
  2039. next if /^;/; # skip comments
  2040. next if /^\s*$/; # skip empty lines
  2041. next if /\x1a/; # skip ^Z
  2042. last if /^ENDCODEPAGE/;
  2043. if (/^CODEPAGE\s+(\d+)/)
  2044. {
  2045. $codepage = $1;
  2046. next;
  2047. }
  2048. if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
  2049. {
  2050. $width = $1;
  2051. $default_char = hex $2;
  2052. $default_wchar = hex $3;
  2053. next;
  2054. }
  2055. if (/^(MBTABLE|GLYPHTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
  2056. {
  2057. $state = $1;
  2058. $count = $2;
  2059. next;
  2060. }
  2061. if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
  2062. {
  2063. if ($state eq "MBTABLE")
  2064. {
  2065. my $cp = hex $1;
  2066. my $uni = hex $2;
  2067. $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
  2068. next;
  2069. }
  2070. if ($state eq "GLYPHTABLE")
  2071. {
  2072. my $cp = hex $1;
  2073. my $uni = hex $2;
  2074. $glyph2uni[$cp] = $uni unless defined($glyph2uni[$cp]);
  2075. next;
  2076. }
  2077. if ($state eq "WCTABLE")
  2078. {
  2079. my $uni = hex $1;
  2080. my $cp = hex $2;
  2081. $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
  2082. next;
  2083. }
  2084. if ($state eq "DBCSRANGE")
  2085. {
  2086. my $start = hex $1;
  2087. my $end = hex $2;
  2088. for (my $i = $start; $i <= $end; $i++) { add_lead_byte( $i ); }
  2089. $lb_cur = $start;
  2090. $lb_end = $end;
  2091. next;
  2092. }
  2093. if ($state eq "DBCSTABLE")
  2094. {
  2095. my $mb = hex $1;
  2096. my $uni = hex $2;
  2097. my $cp = ($lb_cur << 8) | $mb;
  2098. $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
  2099. if (!--$count)
  2100. {
  2101. if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
  2102. }
  2103. next;
  2104. }
  2105. }
  2106. die "$filename: Unrecognized line $_\n";
  2107. }
  2108. close $INPUT;
  2109. output_codepage_file( $codepage );
  2110. }
  2111. ################################################################
  2112. # align a string length
  2113. sub align_string($$)
  2114. {
  2115. my ($align, $str) = @_;
  2116. $str .= pack "C*", (0) x ($align - length($str) % $align) if length($str) % $align;
  2117. return $str;
  2118. }
  2119. ################################################################
  2120. # pack a GUID string
  2121. sub pack_guid($)
  2122. {
  2123. $_ = shift;
  2124. /([0-9A-Fa-f]{8})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/;
  2125. return pack "L<S<2C8", hex $1, hex $2, hex $3, hex $4, hex $5, hex $6, hex $7, hex $8, hex $9, hex $10, hex $11;
  2126. }
  2127. ################################################################
  2128. # comparison function for compression sort
  2129. sub cmp_compression
  2130. {
  2131. return scalar @{$a} <=> scalar @{$b} ||
  2132. $a->[4] <=> $b->[4] ||
  2133. $a->[5] <=> $b->[5] ||
  2134. $a->[6] <=> $b->[6] ||
  2135. $a->[7] <=> $b->[7] ||
  2136. $a->[8] <=> $b->[8] ||
  2137. $a->[9] <=> $b->[9] ||
  2138. $a->[10] <=> $b->[10] ||
  2139. $a->[11] <=> $b->[11] ||
  2140. $a->[12] <=> $b->[12];
  2141. }
  2142. ################################################################
  2143. # build a binary sort keys table
  2144. sub dump_sortkey_table($$)
  2145. {
  2146. my ($filename, $download) = @_;
  2147. my @keys;
  2148. my ($part, $section, $subsection, $guid, $version, $ling_flag);
  2149. my @multiple_weights;
  2150. my @expansions;
  2151. my @compressions;
  2152. my %exceptions;
  2153. my %guids;
  2154. my %compr_flags;
  2155. my %locales;
  2156. my $default_guid = "00000001-57ee-1e5c-00b4-d0000bb1e11e";
  2157. my $jamostr = "";
  2158. my $re_hex = '0x[0-9A-Fa-f]+';
  2159. my $re_key = '(\d+\s+\d+\s+\d+\s+\d+)';
  2160. $guids{$default_guid} = { };
  2161. my %flags = ( "HAS_3_BYTE_WEIGHTS" => 0x01, "REVERSEDIACRITICS" => 0x10, "DOUBLECOMPRESSION" => 0x20, "INVERSECASING" => 0x40 );
  2162. my $KEYS = open_data_file( $MSDATA, $download );
  2163. printf "Building $filename\n";
  2164. while (<$KEYS>)
  2165. {
  2166. s/\s*;.*$//;
  2167. next if /^\s*$/; # skip empty lines
  2168. if (/^\s*(SORTKEY|SORTTABLES)/)
  2169. {
  2170. $part = $1;
  2171. next;
  2172. }
  2173. if (/^\s*(ENDSORTKEY|ENDSORTTABLES)/)
  2174. {
  2175. $part = $section = "";
  2176. next;
  2177. }
  2178. if (/^\s*(DEFAULT|RELEASE|REVERSEDIACRITICS|DOUBLECOMPRESSION|INVERSECASING|MULTIPLEWEIGHTS|EXPANSION|COMPATIBILITY|COMPRESSION|EXCEPTION|JAMOSORT)\s+/)
  2179. {
  2180. $section = $1;
  2181. $guid = undef;
  2182. next;
  2183. }
  2184. next unless $part;
  2185. if ("$part.$section" eq "SORTKEY.DEFAULT")
  2186. {
  2187. if (/^\s*($re_hex)\s+$re_key/)
  2188. {
  2189. $keys[hex $1] = [ split(/\s+/,$2) ];
  2190. next;
  2191. }
  2192. }
  2193. elsif ("$part.$section" eq "SORTTABLES.RELEASE")
  2194. {
  2195. if (/^\s*NLSVERSION\s+0x([0-9A-Fa-f]+)/)
  2196. {
  2197. $version = hex $1;
  2198. next;
  2199. }
  2200. if (/^\s*DEFINEDVERSION\s+0x([0-9A-Fa-f]+)/)
  2201. {
  2202. # ignore for now
  2203. next;
  2204. }
  2205. }
  2206. elsif ("$part.$section" eq "SORTTABLES.REVERSEDIACRITICS" ||
  2207. "$part.$section" eq "SORTTABLES.DOUBLECOMPRESSION" ||
  2208. "$part.$section" eq "SORTTABLES.INVERSECASING")
  2209. {
  2210. if (/^\s*SORTGUID\s+([-0-9A-Fa-f]+)/)
  2211. {
  2212. $guid = lc $1;
  2213. $guids{$guid} = { } unless defined $guids{$guid};
  2214. $guids{$guid}->{flags} |= $flags{$section};
  2215. next;
  2216. }
  2217. if (/^\s*LOCALENAME\s+([A-Za-z0-9-_]+)/)
  2218. {
  2219. $locales{$1} = $guid;
  2220. next;
  2221. }
  2222. }
  2223. elsif ("$part.$section" eq "SORTTABLES.MULTIPLEWEIGHTS")
  2224. {
  2225. if (/^\s*(\d+)\s+(\d+)/)
  2226. {
  2227. push @multiple_weights, $1, $2;
  2228. next;
  2229. }
  2230. }
  2231. elsif ("$part.$section" eq "SORTTABLES.EXPANSION")
  2232. {
  2233. if (/^\s*0x([0-9A-Fa-f]+)\s+0x([0-9A-Fa-f]+)\s+0x([0-9A-Fa-f]+)/)
  2234. {
  2235. my $pos = scalar @expansions / 2;
  2236. $keys[hex $1] = [ 2, 0, $pos & 0xff, $pos >> 8 ] unless defined $keys[hex $1];
  2237. push @expansions, hex $2, hex $3;
  2238. next;
  2239. }
  2240. }
  2241. elsif ("$part.$section" eq "SORTTABLES.COMPATIBILITY")
  2242. {
  2243. if (/^\s*0x([0-9A-Fa-f]+)\s+0x([0-9A-Fa-f]+)/)
  2244. {
  2245. $keys[hex $1] = $keys[hex $2];
  2246. next;
  2247. }
  2248. }
  2249. elsif ("$part.$section" eq "SORTTABLES.COMPRESSION")
  2250. {
  2251. if (/^\s*SORTGUID\s+([-0-9A-Fa-f]+)\s+\d*\s*([A-Z0-9_]+)?/)
  2252. {
  2253. if ($subsection || !$guid) # start a new one
  2254. {
  2255. $guid = lc $1;
  2256. $subsection = "";
  2257. $guids{$guid} = { } unless defined $guids{$guid};
  2258. $guids{$guid}->{flags} |= $flags{$2} if $2;
  2259. $guids{$guid}->{compr} = @compressions;
  2260. $exceptions{"$guid-"} = [ ] unless defined $exceptions{"$guid-"};
  2261. $compr_flags{$guid} = [ ] unless defined $compr_flags{$guid};
  2262. push @compressions, [ ];
  2263. }
  2264. else # merge with current one
  2265. {
  2266. $guids{lc $1} = { } unless defined $guids{lc $1};
  2267. $guids{lc $1}->{flags} |= $flags{$2} if $2;
  2268. $guids{lc $1}->{compr} = $guids{$guid}->{compr};
  2269. $compr_flags{lc $1} = $compr_flags{$guid};
  2270. }
  2271. next;
  2272. }
  2273. if (/^\s*LOCALENAME\s+([A-Za-z0-9-_]+)/)
  2274. {
  2275. $locales{$1} = $guid;
  2276. next;
  2277. }
  2278. if (/^\s*(TWO|THREE|FOUR|FIVE|SIX|SEVEN|EIGHT)/)
  2279. {
  2280. $subsection = $1;
  2281. next;
  2282. }
  2283. if ($subsection && /^\s*(($re_hex\s+){2,8})$re_key/)
  2284. {
  2285. my @comp = map { hex $_; } split(/\s+/,$1);
  2286. push @{$compressions[$#compressions]}, [ split(/\s+/,$3), @comp ];
  2287. # add compression flags
  2288. $compr_flags{$guid}->[$comp[0]] |= @comp >= 6 ? 0xc0 : @comp >= 4 ? 0x80 : 0x40;
  2289. next;
  2290. }
  2291. }
  2292. elsif ("$part.$section" eq "SORTTABLES.EXCEPTION")
  2293. {
  2294. if (/^\s*SORTGUID\s+([-0-9A-Fa-f]+)\s+\d*\s*(LINGUISTIC_CASING)?/)
  2295. {
  2296. $guid = lc $1;
  2297. $guids{$guid} = { } unless defined $guids{lc $1};
  2298. $ling_flag = ($2 ? "+" : "-");
  2299. $exceptions{"$guid$ling_flag"} = [ ] unless defined $exceptions{"$guid$ling_flag"};
  2300. next;
  2301. }
  2302. if (/^\s*LOCALENAME\s+([A-Za-z0-9-_]+)/)
  2303. {
  2304. $locales{$1} = $guid;
  2305. next;
  2306. }
  2307. if (/^\s*($re_hex)\s+$re_key/)
  2308. {
  2309. $exceptions{"$guid$ling_flag"}->[hex $1] = [ split(/\s+/,$2) ];
  2310. next;
  2311. }
  2312. }
  2313. elsif ("$part.$section" eq "SORTTABLES.JAMOSORT")
  2314. {
  2315. if (/^\s*$re_hex\s+(($re_hex\s*){5})/)
  2316. {
  2317. $jamostr .= pack "C8", map { hex $_; } split /\s+/, $1;
  2318. next;
  2319. }
  2320. }
  2321. die "$download: $part.$section: unrecognized line $_\n";
  2322. }
  2323. close $KEYS;
  2324. # Sortkey table
  2325. my $table;
  2326. for (my $i = 0; $i < 0x10000; $i++)
  2327. {
  2328. my @k = defined $keys[$i] ? @{$keys[$i]} : (0) x 4;
  2329. $table .= pack "C4", $k[1], $k[0], $k[2], $k[3];
  2330. }
  2331. foreach my $id (sort keys %exceptions)
  2332. {
  2333. my $pos = length($table) / 4;
  2334. my @exc = @{$exceptions{$id}};
  2335. my @filled;
  2336. my $key = (substr( $id, -1 ) eq "+" ? "ling_except" : "except");
  2337. my $guid = substr( $id, 0, -1 );
  2338. $guids{$guid}->{$key} = $pos;
  2339. $pos += 0x100;
  2340. my @flags = @{$compr_flags{$guid}} if defined $compr_flags{$guid};
  2341. for (my $j = 0; $j < 0x10000; $j++)
  2342. {
  2343. next unless defined $exc[$j] || defined $flags[$j];
  2344. $filled[$j >> 8] = 1;
  2345. $j |= 0xff;
  2346. }
  2347. for (my $j = 0; $j < 0x100; $j++)
  2348. {
  2349. $table .= pack "L<", $filled[$j] ? $pos : $j * 0x100;
  2350. $pos += 0x100 if $filled[$j];
  2351. }
  2352. for (my $j = 0; $j < 0x10000; $j++)
  2353. {
  2354. next unless $filled[$j >> 8];
  2355. my @k = defined $exc[$j] ? @{$exc[$j]} : defined $keys[$j] ? @{$keys[$j]} : (0) x 4;
  2356. $k[3] |= $flags[$j] || 0;
  2357. $table .= pack "C4", $k[1], $k[0], $k[2], $k[3];
  2358. }
  2359. }
  2360. # Case mapping tables
  2361. # standard table
  2362. my @casemaps;
  2363. my @upper = @toupper_table;
  2364. my @lower = @tolower_table;
  2365. remove_linguistic_mappings( \@upper, \@lower );
  2366. $casemaps[0] = pack( "S<*", 1) . dump_binary_case_table( @upper ) . dump_binary_case_table( @lower );
  2367. # linguistic table
  2368. $casemaps[1] = pack( "S<*", 1) . dump_binary_case_table( @toupper_table ) . dump_binary_case_table( @tolower_table );
  2369. # Turkish table
  2370. @upper = @toupper_table;
  2371. @lower = @tolower_table;
  2372. $upper[ord 'i'] = 0x130; # LATIN CAPITAL LETTER I WITH DOT ABOVE
  2373. $lower[ord 'I'] = 0x131; # LATIN SMALL LETTER DOTLESS I
  2374. $casemaps[2] = pack( "S<*", 1) . dump_binary_case_table( @upper ) . dump_binary_case_table( @lower );
  2375. my $casemaps = align_string( 8, $casemaps[0] . $casemaps[1] . $casemaps[2] );
  2376. # Char type table
  2377. my @table;
  2378. my $types = "";
  2379. my %typestr;
  2380. for (my $i = 0; $i < 0x10000; $i++)
  2381. {
  2382. my $str = pack "S<3",
  2383. ($category_table[$i] || 0) & 0xffff,
  2384. defined($direction_table[$i]) ? $c2_types{$direction_table[$i]} : 0,
  2385. ($category_table[$i] || 0) >> 16;
  2386. if (!defined($typestr{$str}))
  2387. {
  2388. $typestr{$str} = length($types) / 6;
  2389. $types .= $str;
  2390. }
  2391. $table[$i] = $typestr{$str};
  2392. }
  2393. my @rows = compress_array( 4096, 0, @table[0..65535] );
  2394. my @array = compress_array( 256, 0, @rows[0..4095] );
  2395. for (my $i = 0; $i < 256; $i++) { $array[$i] *= 2; } # we need byte offsets
  2396. for (my $i = 256; $i < @array; $i++) { $array[$i] += 2 * @array - 4096; }
  2397. my $arraystr = pack("S<*", @array) . pack("C*", @rows[4096..$#rows]);
  2398. my $chartypes = pack "S<2", 4 + length($types) + length($arraystr), 2 + length($types);
  2399. $chartypes = align_string( 8, $chartypes . $types . $arraystr );
  2400. # Sort tables
  2401. # guids
  2402. my $sorttables = pack "L<2", $version, scalar %guids;
  2403. foreach my $id (sort keys %guids)
  2404. {
  2405. my %guid = %{$guids{$id}};
  2406. my $flags = $guid{flags} || 0;
  2407. my $map = length($casemaps[0]) + (defined $guid{ling_except} ? length($casemaps[1]) : 0);
  2408. $sorttables .= pack_guid($id) . pack "L<5",
  2409. $flags,
  2410. defined($guid{compr}) ? $guid{compr} : 0xffffffff,
  2411. $guid{except} || 0,
  2412. $guid{ling_except} || 0,
  2413. $map / 2;
  2414. }
  2415. # expansions
  2416. $sorttables .= pack "L<S<*", scalar @expansions / 2, @expansions;
  2417. # compressions
  2418. $sorttables .= pack "L<", scalar @compressions;
  2419. my $rowstr = "";
  2420. foreach my $c (@compressions)
  2421. {
  2422. my $pos = length($rowstr) / 2;
  2423. my $min = 0xffff;
  2424. my $max = 0;
  2425. my @lengths = (0) x 8;
  2426. foreach my $r (sort cmp_compression @{$c})
  2427. {
  2428. my @row = @{$r};
  2429. $lengths[scalar @row - 6]++;
  2430. foreach my $val (@row[4..$#row])
  2431. {
  2432. $min = $val if $min > $val;
  2433. $max = $val if $max < $val;
  2434. }
  2435. $rowstr .= align_string( 4, pack "S<*", @row[4..$#row] );
  2436. $rowstr .= pack "C4", $row[1], $row[0], $row[2], $row[3];
  2437. }
  2438. $sorttables .= pack "L<S<10", $pos, $min, $max, @lengths;
  2439. }
  2440. $sorttables .= $rowstr;
  2441. # multiple weights
  2442. $sorttables .= align_string( 4, pack "L<C*", scalar @multiple_weights / 2, @multiple_weights );
  2443. # jamo sort
  2444. $sorttables .= pack("L<", length($jamostr) / 8) . $jamostr;
  2445. # Locales
  2446. add_registry_key( "Sorting\\Ids", "{$default_guid}" );
  2447. foreach my $loc (sort keys %locales)
  2448. {
  2449. # skip specific locales that match more general ones
  2450. my @parts = split /[-_]/, $loc;
  2451. next if @parts > 1 && defined($locales{$parts[0]}) && $locales{$parts[0]} eq $locales{$loc};
  2452. next if @parts > 2 && defined($locales{"$parts[0]-$parts[1]"}) && $locales{"$parts[0]-$parts[1]"} eq $locales{$loc};
  2453. add_registry_value( "Sorting\\Ids", $loc, "\{$locales{$loc}\}" );
  2454. }
  2455. # File header
  2456. my @header;
  2457. $header[0] = 16;
  2458. $header[1] = $header[0] + length $table;
  2459. $header[2] = $header[1] + length $casemaps;
  2460. $header[3] = $header[2] + length $chartypes;
  2461. open OUTPUT, ">$filename.new" or die "Cannot create $filename";
  2462. print OUTPUT pack "L<*", @header;
  2463. print OUTPUT $table, $casemaps, $chartypes, $sorttables;
  2464. close OUTPUT;
  2465. save_file($filename);
  2466. }
  2467. ################################################################
  2468. # build the script to create registry keys
  2469. sub dump_registry_script($%)
  2470. {
  2471. my ($filename, %keys) = @_;
  2472. my $indent = 1;
  2473. printf "Building %s\n", $filename;
  2474. open OUTPUT, ">$filename.new" or die "Cannot create $filename";
  2475. print OUTPUT "HKLM\n{\n";
  2476. foreach my $k (split /\\/, "SYSTEM\\CurrentControlSet\\Control\\Nls")
  2477. {
  2478. printf OUTPUT "%*sNoRemove %s\n%*s{\n", 4 * $indent, "", $k, 4 * $indent, "";
  2479. $indent++;
  2480. }
  2481. foreach my $k (sort keys %keys)
  2482. {
  2483. my @subkeys = split /\\/, $k;
  2484. my ($def, @vals) = @{$keys{$k}};
  2485. for (my $i = 0; $i < @subkeys; $i++)
  2486. {
  2487. printf OUTPUT "%*s%s%s\n%*s{\n", 4 * $indent, "", $subkeys[$i],
  2488. $i == $#subkeys && $def ? " = s '$def'" : "", 4 * $indent, "";
  2489. $indent++;
  2490. }
  2491. foreach my $v (@vals) { printf OUTPUT "%*sval $v\n", 4 * $indent, ""; }
  2492. for (my $i = 0; $i < @subkeys; $i++) { printf OUTPUT "%*s}\n", 4 * --$indent, ""; }
  2493. }
  2494. while ($indent) { printf OUTPUT "%*s}\n", 4 * --$indent, ""; }
  2495. close OUTPUT;
  2496. save_file($filename);
  2497. }
  2498. ################################################################
  2499. # save a file if modified
  2500. sub save_file($)
  2501. {
  2502. my $file = shift;
  2503. if (-f $file && !system "cmp $file $file.new >/dev/null")
  2504. {
  2505. unlink "$file.new";
  2506. }
  2507. else
  2508. {
  2509. rename "$file.new", "$file";
  2510. }
  2511. }
  2512. ################################################################
  2513. # main routine
  2514. chdir ".." if -f "./make_unicode";
  2515. load_data();
  2516. dump_case_mappings( "libs/port/casemap.c" );
  2517. dump_sortkeys( "dlls/kernelbase/collation.c" );
  2518. dump_ctype_tables( "libs/port/wctype.c" );
  2519. dump_bidi_dir_table( "dlls/gdi32/direction.c" );
  2520. dump_bidi_dir_table( "dlls/usp10/direction.c" );
  2521. dump_bidi_dir_table( "dlls/dwrite/direction.c" );
  2522. dump_digit_folding( "dlls/kernelbase/digitmap.c" );
  2523. dump_mirroring( "dlls/usp10/mirror.c" );
  2524. dump_mirroring( "dlls/dwrite/mirror.c" );
  2525. dump_bracket( "dlls/usp10/bracket.c" );
  2526. dump_bracket( "dlls/dwrite/bracket.c" );
  2527. dump_shaping( "dlls/usp10/shaping.c" );
  2528. dump_linebreak( "dlls/usp10/linebreak.c" );
  2529. dump_linebreak( "dlls/dwrite/linebreak.c" );
  2530. dump_scripts( "dlls/dwrite/scripts" );
  2531. dump_indic( "dlls/usp10/indicsyllable.c" );
  2532. dump_vertical( "dlls/gdi32/vertical.c" );
  2533. dump_vertical( "dlls/wineps.drv/vertical.c" );
  2534. dump_intl_nls("nls/l_intl.nls");
  2535. dump_norm_table( "nls/normnfc.nls" );
  2536. dump_norm_table( "nls/normnfd.nls" );
  2537. dump_norm_table( "nls/normnfkc.nls" );
  2538. dump_norm_table( "nls/normnfkd.nls" );
  2539. dump_norm_table( "nls/normidna.nls" );
  2540. dump_sortkey_table( "nls/sortdefault.nls", "Windows 10 Sorting Weight Table.txt" );
  2541. foreach my $file (@allfiles) { dump_msdata_codepage( $file ); }
  2542. dump_eucjp_codepage();
  2543. dump_registry_script( "dlls/kernelbase/kernelbase.rgs", %registry_keys );
  2544. exit 0;
  2545. # Local Variables:
  2546. # compile-command: "./make_unicode"
  2547. # End: