| 1 | #!/bin/sh |
| 2 | set -e |
| 3 | LC_ALL=C |
| 4 | export LC_ALL |
| 5 | echo |
| 6 | echo Generating code page translation tables. |
| 7 | codepages=`cat index.txt|sed 's/ //g'` |
| 8 | if [ -n "$codepages" ]; then |
| 9 | ( |
| 10 | n=0 |
| 11 | echo '/* Automatically generated by gen-cp */' |
| 12 | for i in $codepages; do |
| 13 | printf $i' ' 1>&2 |
| 14 | echo |
| 15 | echo 'static_const struct table_entry table_'$i' [] = {' |
| 16 | tail -n +3 $i.cp | sed 's/#.*$//' | grep '^0x[89a-fA-F]' | sed 's/[ ][ ]*/ /g' | sed 's/[ ]*$/ },/' | sed 's/ /, /' | sed 's/^[ ]*/ { /' | grep '.*, .*,' | grep -v ', 0x0*[89][0-9a-fA-F] ' || true |
| 17 | echo ' { 0, 0 }' |
| 18 | echo '};' |
| 19 | echo |
| 20 | echo 'static_const const_char_ptr aliases_'$i' [] = {'`head -2 $i.cp | tail -n +2`', NULL };' |
| 21 | n=`expr $n + 1` |
| 22 | done |
| 23 | echo |
| 24 | echo 'static_const struct codepage_desc codepages [] = {' |
| 25 | for i in $codepages; do |
| 26 | echo ' { "'`head -1 $i.cp`'", aliases_'$i', table_'$i' },' |
| 27 | done |
| 28 | echo ' { NULL, NULL, NULL }' |
| 29 | echo '};' |
| 30 | echo '#define N_CODEPAGES '$n | sed 's/ //g' > codepage.h |
| 31 | if cmp -s ../codepage.h codepage.h; then |
| 32 | rm -f codepage.h |
| 33 | else |
| 34 | mv codepage.h ../codepage.h |
| 35 | fi |
| 36 | ) | sed 's/ //g' > ../codepage.inc |
| 37 | echo |
| 38 | echo Done. |
| 39 | fi |
| 40 | echo |