2 open F
, "cat C-translit.h.in | gcc -E - |" || die "Cannot preprocess input file";
7 my($len) = length($str);
11 for ($cnt = 0; $cnt < $len; ++$cnt) {
12 if (substr($str, $cnt, 1) eq '\\') {
13 # Recognize the escape sequence.
14 if (substr($str, $cnt + 1, 1) eq 'x') {
16 for ($inner = $cnt + 2; $inner < $len && $inner < $cnt + 10; ++$inner) {
17 my($ch) = substr($str, $inner, 1);
18 next if (($ch ge '0' && $ch le '9')
19 || ($ch ge 'a' && $ch le 'f')
20 || ($ch ge 'A' && $ch le 'F'));
26 die "invalid input" if ($cnt + 1 >= $len);
43 if (/"([^\"]*)"[ ]*"(.*)"/) {
46 my($fromlen) = cstrlen
($from);
47 my($tolen) = cstrlen
($to);
50 push(@fromlens, $fromlen);
52 push(@tolens, $tolen);
56 printf "#define NTRANSLIT %d\n", $#froms + 1;
58 printf "static const uint32_t translit_from_idx[] =\n{\n ";
61 for ($cnt = 0; $cnt <= $#fromlens; ++$cnt) {
71 printf("%4d", $total);
72 $total += $fromlens[$cnt] + 1;
77 printf "static const wchar_t translit_from_tbl[] =\n ";
79 for ($cnt = 0; $cnt <= $#froms; ++$cnt) {
88 if ($col > 2 && $col + length($froms[$cnt]) + 4 >= 79) {
95 printf("L\"$froms[$cnt]\"");
96 $col += length($froms[$cnt]) + 3;
100 printf "static const uint32_t translit_to_idx[] =\n{\n ";
103 for ($cnt = 0; $cnt <= $#tolens; ++$cnt) {
105 if ($col + 7 >= 79) {
113 printf("%4d", $total);
114 $total += $tolens[$cnt] + 2;
119 printf "static const wchar_t translit_to_tbl[] =\n ";
121 for ($cnt = 0; $cnt <= $#tos; ++$cnt) {
123 if ($col + 6 >= 79) {
130 if ($col > 2 && $col + length($tos[$cnt]) + 6 >= 79) {
137 printf("%s", "L\"$tos[$cnt]\\0\"");
138 $col += length($tos[$cnt]) + 5;