(parse_grp_str): PIDLIST is supposed to have NGRPS elements.
[glibc/history.git] / locale / gen-translit.pl
blobd44310b3165fe018fb63bd938daa19ee719f9dab
1 #! /usr/bin/perl -w
2 open F, "cat C-translit.h.in | gcc -E - |" || die "Cannot preprocess input file";
5 sub cstrlen {
6 my($str) = @_;
7 my($len) = length($str);
8 my($cnt);
9 my($res) = 0;
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') {
15 my($inner);
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'));
21 last;
23 $cnt = $inner;
24 ++$res;
25 } else {
26 die "invalid input" if ($cnt + 1 >= $len);
27 ++$res;
28 ++$cnt;
30 } else {
31 ++$res;
35 return $res;
38 while (<F>) {
39 next if (/^#/);
40 next if (/^[ ]*$/);
41 chop;
43 if (/"([^\"]*)"[ ]*"(.*)"/) {
44 my($from) = $1;
45 my($to) = $2;
46 my($fromlen) = cstrlen($from);
47 my($tolen) = cstrlen($to);
49 push(@froms, $from);
50 push(@fromlens, $fromlen);
51 push(@tos, $to);
52 push(@tolens, $tolen);
56 printf "#define NTRANSLIT %d\n", $#froms + 1;
58 printf "static const uint32_t translit_from_idx[] =\n{\n ";
59 $col = 2;
60 $total = 0;
61 for ($cnt = 0; $cnt <= $#fromlens; ++$cnt) {
62 if ($cnt != 0) {
63 if ($col + 7 >= 79) {
64 printf(",\n ");
65 $col = 2;
66 } else {
67 printf(", ");
68 $col += 2;
71 printf("%4d", $total);
72 $total += $fromlens[$cnt] + 1;
73 $col += 4;
75 printf("\n};\n");
77 printf "static const wchar_t translit_from_tbl[] =\n ";
78 $col = 1;
79 for ($cnt = 0; $cnt <= $#froms; ++$cnt) {
80 if ($cnt != 0) {
81 if ($col + 6 >= 79) {
82 printf("\n ");
83 $col = 1;
85 printf(" L\"\\0\"");
86 $col += 6;
88 if ($col > 2 && $col + length($froms[$cnt]) + 4 >= 79) {
89 printf("\n ");
90 $col = 2;
91 } else {
92 printf(" ");
93 ++$col;
95 printf("L\"$froms[$cnt]\"");
96 $col += length($froms[$cnt]) + 3;
98 printf(";\n");
100 printf "static const uint32_t translit_to_idx[] =\n{\n ";
101 $col = 2;
102 $total = 0;
103 for ($cnt = 0; $cnt <= $#tolens; ++$cnt) {
104 if ($cnt != 0) {
105 if ($col + 7 >= 79) {
106 printf(",\n ");
107 $col = 2;
108 } else {
109 printf(", ");
110 $col += 2;
113 printf("%4d", $total);
114 $total += $tolens[$cnt] + 2;
115 $col += 4;
117 printf("\n};\n");
119 printf "static const wchar_t translit_to_tbl[] =\n ";
120 $col = 1;
121 for ($cnt = 0; $cnt <= $#tos; ++$cnt) {
122 if ($cnt != 0) {
123 if ($col + 6 >= 79) {
124 printf("\n ");
125 $col = 1;
127 printf(" L\"\\0\"");
128 $col += 6;
130 if ($col > 2 && $col + length($tos[$cnt]) + 6 >= 79) {
131 printf("\n ");
132 $col = 2;
133 } else {
134 printf(" ");
135 ++$col;
137 printf("%s", "L\"$tos[$cnt]\\0\"");
138 $col += length($tos[$cnt]) + 5;
140 printf(";\n");
142 exit 0;