X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=scripts%2Fgen_utf8.php;h=43b49e382fdc2c64c4dac5e216ec0453b6f2e7c2;hp=865a2f5d5f4e92159e925e76bf4becfa783403e7;hb=cbfdc466d8a364445ba3389e876b7c7e7f0189b2;hpb=bdd6edb59194cda9e5fcb393c48ab4230fceb32a diff --git a/scripts/gen_utf8.php b/scripts/gen_utf8.php index 865a2f5..43b49e3 100755 --- a/scripts/gen_utf8.php +++ b/scripts/gen_utf8.php @@ -11,6 +11,8 @@ $i18n = $argc >= 2 ? $argv[1] : "/usr/share/i18n/locales/i18n"; $f = fopen($i18n, "r"); $c = false; $a = false; +$r = []; +$n = []; ob_start(null, 0xffff); while (!feof($f)) { @@ -55,23 +57,14 @@ while (!feof($f)) { sscanf($sstart, "", $start); break; } - print "\t{"; - if ($start >= 0xffff) { - printf("0x%08X, ", $start); - if ($end) { - printf("0x%08X, ", $end); - } else { - print(" 0, "); + if ($end) { + if ($step != 1) { + die("UNEXPECTED step=$step\n"); } + $r[] = [$start, $end]; } else { - printf(" 0x%04X, ", $start); - if ($end) { - printf(" 0x%04X, ", $end); - } else { - print(" 0, "); - } + $n[] = $start; } - printf("%d},\n", $step); } } break; @@ -85,6 +78,29 @@ while (!feof($f)) { } } +$maxstep = 0; +printf("static const utf8_range_t utf8_ranges[] = {\n\t{"); +foreach ($r as $i => list($start, $end)) { + if ($i) if ($i%3) { + printf(", {"); + } else { + printf(",\n\t{"); + } + + printf("0x%08X, 0x%08X}", $start, $end); +} +printf("\n};\n\n"); +printf("static const unsigned utf8_chars[] = {\n\t"); +foreach ($n as $i => $u) { + if ($i) if (($i%6)) { + printf(", "); + } else { + printf(",\n\t"); + } + printf("0x%08X", $u); +} +printf("\n};\n"); + file_put_contents("php_http_utf8.h", preg_replace('/(\/\* BEGIN::UTF8TABLE \*\/\n).*(\n\s*\/\* END::UTF8TABLE \*\/)/s', '$1'. ob_get_contents() .'$2', file_get_contents("php_http_utf8.h")));