Mercurial > emacs
annotate admin/charsets/mapconv @ 89746:b7afe7c870d3
In UNICODE2 case, sort by 4th field after
running an awk program.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sun, 25 Jan 2004 23:37:19 +0000 |
parents | a750cf193ec6 |
children | 59bbae51ad73 |
rev | line source |
---|---|
88123 | 1 #!/bin/sh |
2 # | |
3 # Copyright (C) 2003 | |
4 # National Institute of Advanced Industrial Science and Technology (AIST) | |
5 # Registration Number H13PRO009 | |
6 # | |
7 # This file is part of GNU Emacs. | |
8 # | |
9 # GNU Emacs is free software; you can redistribute it and/or modify | |
10 # it under the terms of the GNU General Public License as published by | |
11 # the Free Software Foundation; either version 2, or (at your option) | |
12 # any later version. | |
13 # | |
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. | |
18 # | |
19 # You should have received a copy of the GNU General Public License | |
20 # along with GNU Emacs; see the file COPYING. If not, write to the | |
21 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 # Boston, MA 02111-1307, USA. | |
23 | |
24 # Comment: | |
25 # Convert charset map of various format into this: | |
26 # 0xXX 0xYYYY | |
27 # where, | |
28 # XX is a code point of the charset in hexa-decimal, | |
29 # YYYY is the corresponding Unicode character code in hexa-decimal. | |
30 # Arguments are: | |
31 # $1: source map file | |
32 # $2: address pattern for sed (optionally with substitution command) | |
33 # $3: format of source map file | |
34 # GLIBC-1 GLIBC-2 GLIBC-2-7 CZYBORRA IANA UNICODE YASUOKA MICROSOFT | |
35 # $4: awk script | |
36 | |
37 BASE=`basename $1` | |
38 | |
39 case "$3" in | |
40 GLIBC*) | |
41 SOURCE=`echo $1 | sed 's/.*\(glibc.*$\)/\1/'`;; | |
42 CZYBORRA) | |
43 SOURCE="http://czyborra.com/charsets/${BASE}";; | |
44 IANA) | |
45 SOURCE="http://www.iana.org/assignments/charset-reg/${BASE}";; | |
46 UNICODE) | |
47 SOURCE="http://www.unicode.org/Public/MAPPINGS/.../${BASE}";; | |
89742 | 48 UNICODE2) |
49 SOURCE="http://www.unicode.org/Public/MAPPINGS/.../${BASE}";; | |
88123 | 50 YASUOKA) |
51 SOURCE="http://kanji.zinbun.kyoto-u.ac.jp/~yasuoka/.../${BASE}";; | |
52 MICROSOFT) | |
53 SOURCE="http://www.microsoft.com/globaldev/reference/oem/${BASE}";; | |
54 *) | |
55 echo "Unknown file type: $3"; | |
56 exit 1;; | |
57 esac | |
58 | |
59 echo "# Generated from $SOURCE" | |
60 | |
61 if [ -n "$4" ] ; then | |
62 if [ -f "$4" ] ; then | |
63 AWKPROG="gawk -f $4" | |
64 else | |
65 echo "Awk program does not exist: $4" | |
66 exit 1 | |
67 fi | |
68 else | |
69 AWKPROG=cat | |
70 fi | |
71 | |
72 if [ "$3" == "GLIBC-1" ] ; then | |
73 # Source format is: | |
74 # <UYYYY> /xXX | |
75 sed -n -e "$2 p" < $1 \ | |
76 | sed -e 's,<U\([^>]*\)>[ ]*/x\(..\).*,0x\2 0x\1,' \ | |
77 | sort | ${AWKPROG} | |
78 elif [ "$3" == "GLIBC-2" ] ; then | |
79 # Source format is: | |
80 # <UYYYY> /xXX/xZZ | |
81 sed -n -e "$2 p" < $1 \ | |
82 | sed -e 's,<U\([^>]*\)>[ ]*/x\(..\)/x\(..\).*,0x\2\3 0x\1,' \ | |
83 | sort | ${AWKPROG} | |
84 elif [ "$3" == "GLIBC-2-7" ] ; then | |
85 # Source format is: | |
86 # <UYYYY> /xXX/xZZ | |
87 # We must drop MSBs of XX and ZZ | |
88 sed -n -e "$2 p" < $1 \ | |
89 | sed -e 's/xa/x2/g' -e 's/xb/x3/g' -e 's/xc/x4/g' \ | |
90 -e 's/xd/x5/g' -e 's/xe/x6/g' -e 's/xf/x7/g' \ | |
91 -e 's,<U\([^>]*\)>[ ]*/x\(..\)/x\(..\).*,0x\2\3 0x\1,' \ | |
92 | tee temp \ | |
93 | sort | ${AWKPROG} | |
94 elif [ "$3" == "CZYBORRA" ] ; then | |
95 # Source format is: | |
96 # =XX U+YYYY | |
97 zcat $1 | sed -n -e "$2 p" \ | |
98 | sed -e 's/=\(..\)[^U]*U+\([0-9A-F]*\).*/0x\1 0x\2/' \ | |
99 | sort | ${AWKPROG} | |
100 elif [ "$3" == "IANA" ] ; then | |
101 # Source format is: | |
102 # 0xXX 0xYYYY | |
103 sed -n -e "$2 p" < $1 \ | |
104 | sed -e 's/\(0x[0-9A-Fa-f]*\)[^0]*\(0x[0-9A-Fa-f]*\).*/\1 \2/' \ | |
105 | sort | ${AWKPROG} | |
106 elif [ "$3" == "UNICODE" ] ; then | |
107 # Source format is: | |
108 # YYYY XX | |
109 sed -n -e "$2 p" < $1 \ | |
110 | sed -e 's/\([0-9A-F]*\)[^0-9A-F]*\([0-9A-F]*\).*/0x\2 0x\1/' \ | |
111 | sort | ${AWKPROG} | |
89742 | 112 elif [ "$3" == "UNICODE2" ] ; then |
113 # Source format is: | |
114 # 0xXXXX 0xYYYY # ... | |
115 sed -n -e "$2 p" < $1 \ | |
116 | sed -e 's/\([0-9A-Fx]*\)[^0]*\([0-9A-Fx]*\).*/\1 \2/' \ | |
89746
b7afe7c870d3
In UNICODE2 case, sort by 4th field after
Kenichi Handa <handa@m17n.org>
parents:
89742
diff
changeset
|
117 | ${AWKPROG} | sort -n -k 4,4 |
88123 | 118 elif [ "$3" == "YASUOKA" ] ; then |
119 # Source format is: | |
120 # YYYY 0-XXXX (XXXX is a Kuten code) | |
121 sed -n -e "$2 p" < $1 \ | |
122 | sed -e 's/\([0-9A-F]*\)[^0]*0-\([0-9]*\).*/0x\2 0x\1/' \ | |
123 | sort | ${AWKPROG} | |
124 elif [ "$3" == "MICROSOFT" ] ; then | |
125 # Source format is: | |
126 # XX = U+YYYY | |
127 sed -n -e "$2 p" < $1 \ | |
128 | sed -e 's/\([0-9A-F]*\).*U+\([0-9A-F]*\).*/0x\1 0x\2/' \ | |
129 | sort | ${AWKPROG} | |
130 else | |
131 echo "Invalid arguments" | |
132 exit 1 | |
133 fi |