Commit | Line | Data |
---|---|---|
463f5630 | 1 | #!/bin/sh |
9ad5de0c | 2 | |
5df4f04c | 3 | # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
463f5630 KH |
4 | # National Institute of Advanced Industrial Science and Technology (AIST) |
5 | # Registration Number H13PRO009 | |
9ad5de0c | 6 | |
463f5630 | 7 | # This file is part of GNU Emacs. |
9ad5de0c GM |
8 | |
9 | # GNU Emacs is free software: you can redistribute it and/or modify | |
463f5630 | 10 | # it under the terms of the GNU General Public License as published by |
9ad5de0c GM |
11 | # the Free Software Foundation, either version 3 of the License, or |
12 | # (at your option) any later version. | |
13 | ||
463f5630 KH |
14 | # GNU Emacs is distributed in the hope that it will be useful, |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | # GNU General Public License for more details. | |
9ad5de0c | 18 | |
463f5630 | 19 | # You should have received a copy of the GNU General Public License |
9ad5de0c GM |
20 | # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
21 | ||
22 | # Commentary: | |
463f5630 | 23 | |
463f5630 KH |
24 | # Convert charset map of various format into this: |
25 | # 0xXX 0xYYYY | |
26 | # where, | |
27 | # XX is a code point of the charset in hexa-decimal, | |
28 | # YYYY is the corresponding Unicode character code in hexa-decimal. | |
29 | # Arguments are: | |
30 | # $1: source map file | |
31 | # $2: address pattern for sed (optionally with substitution command) | |
32 | # $3: format of source map file | |
c9acd49d | 33 | # GLIBC-1 GLIBC-2 GLIBC-2-7 CZYBORRA IANA UNICODE UNICODE2 YASUOKA |
463f5630 KH |
34 | # $4: awk script |
35 | ||
64ace564 KH |
36 | FILE="admin/charsets/$1" |
37 | BASE=`basename $1 .gz` | |
463f5630 KH |
38 | |
39 | case "$3" in | |
40 | GLIBC*) | |
64ace564 KH |
41 | FILE="$BASE in localedate/charmaps of glibc"; |
42 | SOURCE="";; | |
463f5630 | 43 | CZYBORRA) |
64ace564 | 44 | BASE="$BASE.gz"; |
463f5630 KH |
45 | SOURCE="http://czyborra.com/charsets/${BASE}";; |
46 | IANA) | |
47 | SOURCE="http://www.iana.org/assignments/charset-reg/${BASE}";; | |
48 | UNICODE) | |
64ace564 | 49 | SOURCE="http://www.unicode.org/Public/MAPPINGS/VENDORS/ADOBE/${BASE}";; |
4f356551 | 50 | UNICODE2) |
64ace564 | 51 | SOURCE="http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/${BASE}";; |
463f5630 | 52 | YASUOKA) |
64ace564 KH |
53 | BASE="$BASE.Z"; |
54 | SOURCE="http://kanji.zinbun.kyoto-u.ac.jp/~yasuoka/ftp/CJKtable/${BASE}";; | |
b0588326 | 55 | KANJI-DATABASE) |
64ace564 | 56 | SOURCE="http://kanji-database.cvs.sourceforge.net/viewvc/*checkout*/kanji-database/kanji-database/data/cns2ucsdkw.txt?revision=1.4";; |
463f5630 KH |
57 | *) |
58 | echo "Unknown file type: $3"; | |
59 | exit 1;; | |
60 | esac | |
61 | ||
64ace564 KH |
62 | if [ -n "$SOURCE" ] ; then |
63 | echo "# Generated from $FILE which is a copy of"; | |
64 | echo "# $SOURCE" | |
65 | else | |
66 | echo "# Generated from $FILE" | |
67 | fi | |
68 | ||
463f5630 KH |
69 | |
70 | if [ -n "$4" ] ; then | |
71 | if [ -f "$4" ] ; then | |
72 | AWKPROG="gawk -f $4" | |
73 | else | |
74 | echo "Awk program does not exist: $4" | |
75 | exit 1 | |
76 | fi | |
77 | else | |
78 | AWKPROG=cat | |
79 | fi | |
80 | ||
64ace564 | 81 | if [ "$3" = "GLIBC-1" ] ; then |
463f5630 KH |
82 | # Source format is: |
83 | # <UYYYY> /xXX | |
64ace564 | 84 | zcat $1 | sed -n -e "$2 p" \ |
463f5630 KH |
85 | | sed -e 's,<U\([^>]*\)>[ ]*/x\(..\).*,0x\2 0x\1,' \ |
86 | | sort | ${AWKPROG} | |
64ace564 | 87 | elif [ "$3" = "GLIBC-2" ] ; then |
463f5630 KH |
88 | # Source format is: |
89 | # <UYYYY> /xXX/xZZ | |
64ace564 | 90 | zcat $1 | sed -n -e "$2 p" \ |
463f5630 KH |
91 | | sed -e 's,<U\([^>]*\)>[ ]*/x\(..\)/x\(..\).*,0x\2\3 0x\1,' \ |
92 | | sort | ${AWKPROG} | |
64ace564 | 93 | elif [ "$3" = "GLIBC-2-7" ] ; then |
463f5630 KH |
94 | # Source format is: |
95 | # <UYYYY> /xXX/xZZ | |
96 | # We must drop MSBs of XX and ZZ | |
64ace564 | 97 | zcat $1 | sed -n -e "$2 p" \ |
463f5630 KH |
98 | | sed -e 's/xa/x2/g' -e 's/xb/x3/g' -e 's/xc/x4/g' \ |
99 | -e 's/xd/x5/g' -e 's/xe/x6/g' -e 's/xf/x7/g' \ | |
100 | -e 's,<U\([^>]*\)>[ ]*/x\(..\)/x\(..\).*,0x\2\3 0x\1,' \ | |
463f5630 | 101 | | sort | ${AWKPROG} |
64ace564 | 102 | elif [ "$3" = "CZYBORRA" ] ; then |
463f5630 KH |
103 | # Source format is: |
104 | # =XX U+YYYY | |
cde44a77 | 105 | sed -n -e "$2 p" < $1 \ |
463f5630 KH |
106 | | sed -e 's/=\(..\)[^U]*U+\([0-9A-F]*\).*/0x\1 0x\2/' \ |
107 | | sort | ${AWKPROG} | |
64ace564 | 108 | elif [ "$3" = "IANA" ] ; then |
463f5630 KH |
109 | # Source format is: |
110 | # 0xXX 0xYYYY | |
cde44a77 | 111 | sed -n -e "$2 p" < $1 \ |
463f5630 KH |
112 | | sed -e 's/\(0x[0-9A-Fa-f]*\)[^0]*\(0x[0-9A-Fa-f]*\).*/\1 \2/' \ |
113 | | sort | ${AWKPROG} | |
64ace564 | 114 | elif [ "$3" = "UNICODE" ] ; then |
463f5630 KH |
115 | # Source format is: |
116 | # YYYY XX | |
c9acd49d KH |
117 | # We perform reverse sort to prefer the first one in the |
118 | # duplicated mappings (e.g. 0x20->U+0020, 0x20->U+00A0). | |
cde44a77 | 119 | sed -n -e "$2 p" < $1 \ |
463f5630 | 120 | | sed -e 's/\([0-9A-F]*\)[^0-9A-F]*\([0-9A-F]*\).*/0x\2 0x\1/' \ |
c9acd49d | 121 | | sort -r |
64ace564 | 122 | elif [ "$3" = "UNICODE2" ] ; then |
4f356551 KH |
123 | # Source format is: |
124 | # 0xXXXX 0xYYYY # ... | |
cde44a77 | 125 | sed -n -e "$2 p" < $1 \ |
4f356551 | 126 | | sed -e 's/\([0-9A-Fx]*\)[^0]*\([0-9A-Fx]*\).*/\1 \2/' \ |
16a207a8 | 127 | | ${AWKPROG} | sort -n -k 4,4 |
64ace564 | 128 | elif [ "$3" = "YASUOKA" ] ; then |
463f5630 KH |
129 | # Source format is: |
130 | # YYYY 0-XXXX (XXXX is a Kuten code) | |
cde44a77 | 131 | sed -n -e "$2 p" < $1 \ |
463f5630 KH |
132 | | sed -e 's/\([0-9A-F]*\)[^0]*0-\([0-9]*\).*/0x\2 0x\1/' \ |
133 | | sort | ${AWKPROG} | |
64ace564 | 134 | elif [ "$3" = "KANJI-DATABASE" ] ; then |
b0588326 KH |
135 | # Source format is: |
136 | # C?-XXXX U+YYYYY ..... | |
cde44a77 | 137 | sed -n -e "$2 p" < $1 \ |
b0588326 KH |
138 | | sed -e 's/...\(....\) U+\([0-9A-F]*\).*/0x\1 0x\2/' \ |
139 | | sort | ${AWKPROG} | |
463f5630 | 140 | else |
64ace564 | 141 | echo "Invalid arguments: $3" |
463f5630 KH |
142 | exit 1 |
143 | fi | |
21e99729 | 144 |