table2map.sh - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
table2map.sh (918B)
---
1 #!/bin/sh
2 # generate codepage conversion to C array.
3 # NOTE: does not work for all codepages.
4 # see also cp1250toutf8.c and cp1252toutf8.c
5
6 f="bestfit1250.txt"
7 curl 'ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit1250.txt' | tr -d '\r' > "$f"
8
9 awk -F ' ' \
10 '
11 /^CODEPAGE / {
12 print "/* " $0 " */";
13 }
14 /^\s*$/ {
15 next;
16 }
17 /^CPINFO 1 / {
18 # only support single-byte code point.
19 correct = 1
20 }
21 /^WCTABLE / {
22 start = 0;
23 next;
24 }
25 /^MBTABLE 256/ {
26 if (correct) {
27 start = 1;
28 }
29 next;
30 }
31 {
32 ch = $1;
33 cp = $2;
34
35 comment = $3;
36
37 if (start == 1) {
38 charcount++
39 print $2 ", /* " $3 " */"
40 }
41 next;
42 }
43 /^ENDCODEPAGE/ {
44 exit;
45 }
46 END {
47 if (!correct) {
48 print "input codepage not of type single-byte codepoint (CPINFO 1 *)!" > "/dev/stderr";
49 exit 1;
50 }
51 if (charcount != 256) {
52 print "invalid amount of characters (" charcount "), should be 256!" > "/dev/stderr";
53 exit 1;
54 }
55 }
56 ' \
57 < "$f"