NEWS: Critical bug 674 is a duplicate of 956.
[elinks/elinks-j605.git] / Unicode / gen-cp
blob2c2d30227f5c2f6c41c1af70a8986d1f23f28baf
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 echo 'struct table_entry table_'$i' [] = {'
28 # TODO: Comments inside of the structure are ugliness in a pure clean
29 # form, and my aesthetical feeling shivers upon glancing at it. However
30 # we should handle commentless records. A loop with read inside would
31 # be ideal, I suppose. --pasky
32 tail -n +3 $i.cp | sed 's/# *\(.*\) *$/\/* \1 *\/ /' | grep '^0x[89a-zA-Z]' \
33 | sed 's/[ ][ ]*/ /g' | sed 's/[ ]*$/ },/' | sed 's/ /, /' \
34 | sed 's/^[ ]*/ {/' | grep '.*,.*,'
36 echo ' {0, 0}'
37 echo '};'
38 echo
40 echo 'unsigned char *aliases_'$i' [] = {'
41 head -n 2 $i.cp | tail -n +2 | sed 's/ \+/ /g; s/ $//; s/\", /\",£/g; s/$/,/' | tr "£" "\n" \
42 | sed 's/^/£/g' | tr "£" "\t"
43 echo ' NULL
44 };'
45 n=`expr $n + 1`
46 done
48 echo
49 echo 'struct codepage_desc codepages [] = {'
51 for i in $codepages; do
52 echo ' {"'`head -n 1 $i.cp`'", aliases_'$i', table_'$i'},'
53 done
55 echo ' {NULL, NULL, NULL}'
56 echo '};'
58 echo
59 echo '#define N_CODEPAGES '$n | sed 's/ //g'
61 ) | sed 's/ //g' > ../src/intl/codepage.inc
63 echo
64 echo Done.
68 echo