3 # Copyright (C) 2015 Free Software Foundation, Inc.
5 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 # National Institute of Advanced Industrial Science and Technology (AIST)
7 # Registration Number H13PRO009
9 # This file is part of GNU Emacs.
11 # GNU Emacs is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # GNU Emacs is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 # Convert charset map of various format into this:
29 # XX is a code point of the charset in hexa-decimal,
30 # YYYY is the corresponding Unicode character code in hexa-decimal.
33 # $2: address pattern for sed (optionally with substitution command)
34 # $3: format of source map file
35 # GLIBC-1 GLIBC-2 GLIBC-2-7 CZYBORRA IANA UNICODE UNICODE2 YASUOKA
38 ## So that eg [A-F] as used by KANJI-DATABASE branch below works as expected.
39 ## Otherwise with LANG=en_US.utf8, CNS-6.map was generated with a
40 ## bogus entry. By experiment, LC_COLLATE=C was not enough.
43 BASE
=`expr "$1" : '.*/\(.*\)' '|' "$1"` # basename
44 FILE
="admin/charsets/mapfiles/$BASE"
45 BASE
=`expr "$BASE" : '\(.*\)\.gz$' '|' "$BASE"` # remove any .gz suffix
50 FILE
="$BASE in localedata/charmaps of glibc";
54 SOURCE
="http://czyborra.com/charsets/${BASE}";;
56 SOURCE
="http://www.iana.org/assignments/charset-reg/${BASE}";;
58 SOURCE
="http://www.unicode.org/Public/MAPPINGS/VENDORS/ADOBE/${BASE}";;
60 SOURCE
="http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/${BASE}";;
63 SOURCE
="http://kanji.zinbun.kyoto-u.ac.jp/~yasuoka/ftp/CJKtable/${BASE}";;
65 SOURCE
="http://kanji-database.cvs.sourceforge.net/viewvc/*checkout*/kanji-database/kanji-database/data/cns2ucsdkw.txt?revision=1.4";;
67 echo "Unknown file type: $3";
71 if [ -n "$SOURCE" ] ; then
72 echo "# Generated from $FILE which is a copy of";
75 echo "# Generated from $FILE"
83 echo "Awk program does not exist: $4"
90 if [ "$3" = "GLIBC-1" ] ; then
93 gunzip
-c $1 |
sed -n -e "${2}p" \
94 |
sed -e 's,<U\([^>]*\)>[ ]*/x\(..\).*,0x\2 0x\1,' \
96 elif [ "$3" = "GLIBC-2" ] ; then
99 gunzip
-c $1 |
sed -n -e "${2}p" \
100 |
sed -e 's,<U\([^>]*\)>[ ]*/x\(..\)/x\(..\).*,0x\2\3 0x\1,' \
102 elif [ "$3" = "GLIBC-2-7" ] ; then
105 # We must drop MSBs of XX and ZZ
106 gunzip
-c $1 |
sed -n -e "${2}p" \
107 |
sed -e 's/xa/x2/g' -e 's/xb/x3/g' -e 's/xc/x4/g' \
108 -e 's/xd/x5/g' -e 's/xe/x6/g' -e 's/xf/x7/g' \
109 -e 's,<U\([^>]*\)>[ ]*/x\(..\)/x\(..\).*,0x\2\3 0x\1,' \
111 elif [ "$3" = "CZYBORRA" ] ; then
114 sed -n -e "${2}p" < $1 \
115 |
sed -e 's/=\(..\)[^U]*U+\([0-9A-F]*\).*/0x\1 0x\2/' \
117 elif [ "$3" = "IANA" ] ; then
120 sed -n -e "${2}p" < $1 \
121 |
sed -e 's/\(0x[0-9A-Fa-f]*\)[^0]*\(0x[0-9A-Fa-f]*\).*/\1 \2/' \
123 elif [ "$3" = "UNICODE" ] ; then
126 # We perform reverse sort to prefer the first one in the
127 # duplicated mappings (e.g. 0x20->U+0020, 0x20->U+00A0).
128 sed -n -e "${2}p" < $1 \
129 |
sed -e 's/\([0-9A-F]*\)[^0-9A-F]*\([0-9A-F]*\).*/0x\2 0x\1/' \
131 elif [ "$3" = "UNICODE2" ] ; then
133 # 0xXXXX 0xYYYY # ...
134 sed -n -e "${2}p" < $1 \
135 |
sed -e 's/\([0-9A-Fx]*\)[^0]*\([0-9A-Fx]*\).*/\1 \2/' \
136 |
${AWKPROG} |
sort -n -k 4,4
137 elif [ "$3" = "YASUOKA" ] ; then
139 # YYYY 0-XXXX (XXXX is a Kuten code)
140 sed -n -e "${2}p" < $1 \
141 |
sed -e 's/\([0-9A-F]*\)[^0]*0-\([0-9]*\).*/0x\2 0x\1/' \
143 elif [ "$3" = "KANJI-DATABASE" ] ; then
145 # C?-XXXX U+YYYYY .....
146 sed -n -e "${2}p" < $1 \
147 |
sed -e 's/...\(....\) U+\([0-9A-F]*\).*/0x\1 0x\2/' \
150 echo "Invalid arguments: $3"