4 echo Generating code page translation tables.
6 codepages
=`cat index.txt`
8 if [ -n "$codepages" ]; then
14 echo '/* Automatically generated by gen-cp */'
15 echo '/* DO NOT EDIT THIS FILE! EDIT Unicode/<whatever> INSTEAD! */'
16 echo '/* See the input files for copyrights and licences. */'
19 for i
in $codepages; do
27 sed ' # Delete the name and aliases lines.
29 # Delete comment-only and blank lines.
30 /^[ ]*\(#.*\)\{,1\}$/d
31 # Copy to the hold space.
33 # Delete everything except the comment.
35 # If there is a comment, change it to use /* */ delimiters.
36 s!#[ ]*\(.*\)!/* \1 */!
37 # Exchange spaces; now hold space = comment and pattern space = all.
41 # Canonicalize case so the strings can be used as lookup keys.
43 # Delete mappings of bytes 0x00...0x7F. ELinks assumes those match ASCII.
45 # Delete lines that do not map the byte to exactly one character.
46 /^[ ]*0x[0123456789ABCDEF]\{2\}[ ]\{1,\}0x[0123456789ABCDEF]\{1,\}[ ]*$/!d
47 # Append a newline and the comment from the hold space.
49 # Delete the newline added by the previous command.
51 for left
in 8 9 A B C D E F
; do
52 for right
in 0 1 2 3 4 5 6 7 8 9 A B C D E F
; do
53 eval "high0x$left$right="
58 while read byte unicode comment
; do
59 if eval "[ \"\$high$byte\" ]"; then
60 table
="$table {$byte, $unicode},${comment+ }$comment
63 eval "high$byte=\"\$unicode,\${comment+ }\$comment\""
67 if [ "$highuse" ]; then
68 printf "const uint16_t highhalf_%s [] = {\n" "$i"
69 for left
in 8 9 A B C D E F
; do
70 for right
in 0 1 2 3 4 5 6 7 8 9 A B C D E F
; do
71 eval "printf \"\\t/* %s */ %s\\n\" \"0x$left$right\" \"\${high0x$left$right:-0xFFFF,}\""
76 printf "#define highhalf_%s highhalf_NULL\n\n" "$i"
79 printf "const struct table_entry table_%s [] = {\n%s\t{0, 0}\n};\n" "$i" "$table"
81 printf "#define table_%s table_NULL\n" "$i"
86 echo 'unsigned char *const aliases_'$i' [] = {'
87 head -n 2 $i.
cp |
tail -n +2 |
sed 's/ \+/ /g; s/ $//; s/\", /\",£/g; s/$/,/' |
tr "£" "\n" \
88 |
sed 's/^/£/g' |
tr "£" "\t"
94 printf "\n/*** NULL ***/\n\n"
95 printf "const uint16_t highhalf_NULL [] = {\n"
97 printf "\t0xFFFF,0xFFFF,0xFFFF,0xFFFF, 0xFFFF,0xFFFF,0xFFFF,0xFFFF,\n"
100 printf "const struct table_entry table_NULL [] = {\n"
105 echo 'const struct codepage_desc codepages [] = {'
107 for i
in $codepages; do
108 echo ' {"'`head -n 1 $i.cp`'", aliases_'$i', highhalf_'$i', table_'$i'},'
111 echo ' {NULL, NULL, NULL}'
115 echo '#define N_CODEPAGES '$n |
sed 's/
//g'
117 ) |
sed 's/
//g' > ..
/src
/intl
/codepage.inc