Add cryp32.lib to config.w32 dependent libs
[m6w6/ext-http] / scripts / gen_if_utf8.php
1 #!/usr/bin/env php
2 <?php
3
4 error_reporting(E_ALL);
5 set_error_handler(function($c, $e, $f, $l) {
6 throw new Exception("$e in $f on line $l");
7 });
8
9 $i18n = $argc >= 2 ? $argv[1] : "/usr/share/i18n/locales/i18n";
10
11 $f = fopen($i18n, "r");
12 $c = false;
13 $a = false;
14
15 ob_start(null, 0xfffff);
16
17 while (!feof($f)) {
18 $line = fgets($f);
19 if (!$c && $line !== "LC_CTYPE\n") {
20 continue;
21 }
22 $c = true;
23 if ($line === "END LC_CTYPE\n") {
24 break;
25 }
26 switch($line{0}) {
27 case "%":
28 break;
29 case "\n":
30 if ($a) {
31 break 2;
32 }
33 break;
34 case " ":
35 if ($a) {
36 foreach (explode(";", trim($line, "\n/ ;")) as $ranges) {
37 $range = explode("..", $ranges);
38 $step = 0;
39 $end = 0;
40 switch (count($range)) {
41 case 3:
42 list($sstart, $sstep, $send) = $range;
43 sscanf($sstart, "<U%X>", $start);
44 sscanf($sstep, "(%d)", $step);
45 sscanf($send, "<U%X>", $end);
46
47 break;
48 case 2:
49 list($sstart, $send) = $range;
50 $step = 1;
51 sscanf($sstart, "<U%X>", $start);
52 sscanf($send, "<U%X>", $end);
53 break;
54 case 1:
55 list($sstart) = $range;
56 sscanf($sstart, "<U%X>", $start);
57 break;
58 }
59 $r[]=[$start,$end,$step];
60 }
61 }
62 break;
63 default:
64 if ($a) {
65 break 2;
66 } elseif ($line === "alpha /\n") {
67 $a = true;
68 }
69 break;
70 }
71 }
72 function sp($sp, $ch = " ") { return str_repeat($ch, $sp); }
73 $sp = 1;
74 foreach ($r as list($start, $end, $step)) {
75 if ($end) {
76 if ($step > 1) {
77 die("\nUNEXPECTED: step>1\n");
78 printf("\tfor (i=0x%08X; i <= 0x%08X; i+= %d) { if (i == ch) return 1; }\n", $start, $end, $step);
79 } else {
80 //printf(" if (ch >= 0x%08X && ch <= 0x%08X) return 1;\n", $start, $end);
81 printf("%sif (ch >= 0x%08X) {\n", sp($sp), $start);
82 printf("%sif (ch <= 0x%08X) return 1;\n", sp(++$sp), $end);
83 }
84 } else {
85 printf("%sif (ch == 0x%08X) return 1;\n", sp($sp), $start);
86 }
87 }
88 printf(" %s\n", sp($sp-1, "}"));
89
90 file_put_contents("php_http_utf8.h",
91 preg_replace('/(\/\* BEGIN::UTF8SWITCH \*\/\n).*(\n\s*\/\* END::UTF8SWITCH \*\/)/s', '$1'. ob_get_contents() .'$2',
92 file_get_contents("php_http_utf8.h")));