|
Packit Service |
82fcde |
#!/usr/bin/perl -w
|
|
Packit Service |
82fcde |
open F, "cat C-translit.h.in | gcc -E - |" || die "Cannot preprocess input file";
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
sub cstrlen {
|
|
Packit Service |
82fcde |
my($str) = @_;
|
|
Packit Service |
82fcde |
my($len) = length($str);
|
|
Packit Service |
82fcde |
my($cnt);
|
|
Packit Service |
82fcde |
my($res) = 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
for ($cnt = 0; $cnt < $len; ++$cnt) {
|
|
Packit Service |
82fcde |
if (substr($str, $cnt, 1) eq '\\') {
|
|
Packit Service |
82fcde |
# Recognize the escape sequence.
|
|
Packit Service |
82fcde |
if (substr($str, $cnt + 1, 1) eq 'x') {
|
|
Packit Service |
82fcde |
my($inner);
|
|
Packit Service |
82fcde |
for ($inner = $cnt + 2; $inner < $len && $inner < $cnt + 10; ++$inner) {
|
|
Packit Service |
82fcde |
my($ch) = substr($str, $inner, 1);
|
|
Packit Service |
82fcde |
next if (($ch ge '0' && $ch le '9')
|
|
Packit Service |
82fcde |
|| ($ch ge 'a' && $ch le 'f')
|
|
Packit Service |
82fcde |
|| ($ch ge 'A' && $ch le 'F'));
|
|
Packit Service |
82fcde |
last;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
$cnt = $inner;
|
|
Packit Service |
82fcde |
++$res;
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
die "invalid input" if ($cnt + 1 >= $len);
|
|
Packit Service |
82fcde |
++$res;
|
|
Packit Service |
82fcde |
++$cnt;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
++$res;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return $res;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (<F>) {
|
|
Packit Service |
82fcde |
next if (/^#/);
|
|
Packit Service |
82fcde |
next if (/^[ ]*$/);
|
|
Packit Service |
82fcde |
chop;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (/"([^\"]*)"[ ]*"(.*)"/) {
|
|
Packit Service |
82fcde |
my($from) = $1;
|
|
Packit Service |
82fcde |
my($to) = $2;
|
|
Packit Service |
82fcde |
my($fromlen) = cstrlen($from);
|
|
Packit Service |
82fcde |
my($tolen) = cstrlen($to);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
push(@froms, $from);
|
|
Packit Service |
82fcde |
push(@fromlens, $fromlen);
|
|
Packit Service |
82fcde |
push(@tos, $to);
|
|
Packit Service |
82fcde |
push(@tolens, $tolen);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf "#include <stdint.h>\n";
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf "#define NTRANSLIT %d\n", $#froms + 1;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf "static const uint32_t translit_from_idx[] =\n{\n ";
|
|
Packit Service |
82fcde |
$col = 2;
|
|
Packit Service |
82fcde |
$total = 0;
|
|
Packit Service |
82fcde |
for ($cnt = 0; $cnt <= $#fromlens; ++$cnt) {
|
|
Packit Service |
82fcde |
if ($cnt != 0) {
|
|
Packit Service |
82fcde |
if ($col + 7 >= 79) {
|
|
Packit Service |
82fcde |
printf(",\n ");
|
|
Packit Service |
82fcde |
$col = 2;
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
printf(", ");
|
|
Packit Service |
82fcde |
$col += 2;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf("%4d", $total);
|
|
Packit Service |
82fcde |
$total += $fromlens[$cnt] + 1;
|
|
Packit Service |
82fcde |
$col += 4;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf("\n};\n");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf "static const wchar_t translit_from_tbl[] =\n ";
|
|
Packit Service |
82fcde |
$col = 1;
|
|
Packit Service |
82fcde |
for ($cnt = 0; $cnt <= $#froms; ++$cnt) {
|
|
Packit Service |
82fcde |
if ($cnt != 0) {
|
|
Packit Service |
82fcde |
if ($col + 6 >= 79) {
|
|
Packit Service |
82fcde |
printf("\n ");
|
|
Packit Service |
82fcde |
$col = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf(" L\"\\0\"");
|
|
Packit Service |
82fcde |
$col += 6;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if ($col > 2 && $col + length($froms[$cnt]) + 4 >= 79) {
|
|
Packit Service |
82fcde |
printf("\n ");
|
|
Packit Service |
82fcde |
$col = 2;
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
printf(" ");
|
|
Packit Service |
82fcde |
++$col;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf("L\"$froms[$cnt]\"");
|
|
Packit Service |
82fcde |
$col += length($froms[$cnt]) + 3;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf(";\n");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf "static const uint32_t translit_to_idx[] =\n{\n ";
|
|
Packit Service |
82fcde |
$col = 2;
|
|
Packit Service |
82fcde |
$total = 0;
|
|
Packit Service |
82fcde |
for ($cnt = 0; $cnt <= $#tolens; ++$cnt) {
|
|
Packit Service |
82fcde |
if ($cnt != 0) {
|
|
Packit Service |
82fcde |
if ($col + 7 >= 79) {
|
|
Packit Service |
82fcde |
printf(",\n ");
|
|
Packit Service |
82fcde |
$col = 2;
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
printf(", ");
|
|
Packit Service |
82fcde |
$col += 2;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf("%4d", $total);
|
|
Packit Service |
82fcde |
$total += $tolens[$cnt] + 2;
|
|
Packit Service |
82fcde |
$col += 4;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf("\n};\n");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf "static const wchar_t translit_to_tbl[] =\n ";
|
|
Packit Service |
82fcde |
$col = 1;
|
|
Packit Service |
82fcde |
for ($cnt = 0; $cnt <= $#tos; ++$cnt) {
|
|
Packit Service |
82fcde |
if ($cnt != 0) {
|
|
Packit Service |
82fcde |
if ($col + 6 >= 79) {
|
|
Packit Service |
82fcde |
printf("\n ");
|
|
Packit Service |
82fcde |
$col = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf(" L\"\\0\"");
|
|
Packit Service |
82fcde |
$col += 6;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if ($col > 2 && $col + length($tos[$cnt]) + 6 >= 79) {
|
|
Packit Service |
82fcde |
printf("\n ");
|
|
Packit Service |
82fcde |
$col = 2;
|
|
Packit Service |
82fcde |
} else {
|
|
Packit Service |
82fcde |
printf(" ");
|
|
Packit Service |
82fcde |
++$col;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf("%s", "L\"$tos[$cnt]\\0\"");
|
|
Packit Service |
82fcde |
$col += length($tos[$cnt]) + 5;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
printf(";\n");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
exit 0;
|