pl.po: s/Kodowanie/Kompresja/
[elinks.git] / Unicode / gen-cp
blobb1e289b2aac8eeed43851e8d048922e6477031b3
1 #!/bin/sh
3 echo
4 echo Generating code page translation tables.
6 codepages=`cat index.txt`
8 if [ -n "$codepages" ]; then
12 n=0
14 echo '/* Automatically generated by gen-cp */'
15 echo '/* DO NOT EDIT THIS FILE! EDIT Unicode/<whatever> INSTEAD! */'
16 echo
18 for i in $codepages; do
19 echo -n $i' ' 1>&2
20 echo
22 echo
23 echo "/*** $i ***/"
24 echo
26 sed '1,2d
27 /^[ ]*\(#.*\)\{,1\}$/d
29 s/^[^#]*//
30 s!#[ ]*\(.*\)!/* \1 */!
32 s/#.*//
33 y/Xabcdef/xABCDEF/
34 /^0x[01234567]/d
35 /[^0x0123456789ABCDEF ]/d
37 s/\n//' "$i.cp" | {
38 for left in 8 9 A B C D E F; do
39 for right in 0 1 2 3 4 5 6 7 8 9 A B C D E F; do
40 eval "high0x$left$right="
41 done
42 done
43 table=
44 highuse=
45 while read byte unicode comment; do
46 if eval "[ \"\$high$byte\" ]"; then
47 table="$table {$byte, $unicode},${comment+ }$comment
49 else
50 eval "high$byte=\"\$unicode,\${comment+ }\$comment\""
51 highuse=1
53 done
54 if [ "$highuse" ]; then
55 printf "const uint16_t highhalf_%s [] = {\n" "$i"
56 for left in 8 9 A B C D E F; do
57 for right in 0 1 2 3 4 5 6 7 8 9 A B C D E F; do
58 eval "printf \"\\t/* %s */ %s\\n\" \"0x$left$right\" \"\${high0x$left$right:-0xFFFF,}\""
59 done
60 done
61 printf "};\n\n"
62 else
63 printf "#define highhalf_%s highhalf_NULL\n\n" "$i"
65 if [ "$table" ]; then
66 printf "const struct table_entry table_%s [] = {\n%s\t{0, 0}\n};\n" "$i" "$table"
67 else
68 printf "#define table_%s table_NULL\n" "$i"
70 printf "\n"
73 echo 'unsigned char *const aliases_'$i' [] = {'
74 head -n 2 $i.cp | tail -n +2 | sed 's/ \+/ /g; s/ $//; s/\", /\",£/g; s/$/,/' | tr "£" "\n" \
75 | sed 's/^/£/g' | tr "£" "\t"
76 echo ' NULL
77 };'
78 n=`expr $n + 1`
79 done
81 printf "\n/*** NULL ***/\n\n"
82 printf "const uint16_t highhalf_NULL [] = {\n"
83 for r in `seq 16`; do
84 printf "\t0xFFFF,0xFFFF,0xFFFF,0xFFFF, 0xFFFF,0xFFFF,0xFFFF,0xFFFF,\n"
85 done
86 printf "};\n\n"
87 printf "const struct table_entry table_NULL [] = {\n"
88 printf "\t{0, 0}\n"
89 printf "};\n"
91 echo
92 echo 'const struct codepage_desc codepages [] = {'
94 for i in $codepages; do
95 echo ' {"'`head -n 1 $i.cp`'", aliases_'$i', highhalf_'$i', table_'$i'},'
96 done
98 echo ' {NULL, NULL, NULL}'
99 echo '};'
101 echo
102 echo '#define N_CODEPAGES '$n | sed 's/ //g'
104 ) | sed 's/ //g' > ../src/intl/codepage.inc
106 echo
107 echo Done.
111 echo