Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / groff / src / utils / afmtodit / make-afmtodit-tables
1 #! /bin/sh
2 #
3 # make-afmtodit-tables -- script for creating the `unicode_decomposed'
4 #                         and `AGL_to_unicode' tables
5 #
6 # Copyright (C) 2005, 2009
7 # Free Software Foundation, Inc.
8 #      Written by Werner Lemberg <wl@gnu.org>
9 #
10 # This file is part of groff.
11 #
12 # groff is free software; you can redistribute it and/or modify it under
13 # the terms of the GNU General Public License as published by the Free
14 # Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 # for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25 #
26 # usage:
27 #
28 #   make-afmtodit-tables \
29 #     UnicodeData.txt version-string glyphlist.txt > afmtodit.in
30 #
31 # `UnicodeData.txt' is the central database file from the Unicode standard.
32 # Unfortunately, it doesn't contain a version number which must be thus
33 # provided manually as an additional parameter.
34 #
35 # `glyphlist.txt' holds the Adobe Glyph List (AGL).
36 #
37 # This program needs a C preprocessor.
38 #
39
40 CPP=cpp
41
42 prog="$0"
43
44 if test $# -ne 3; then
45   echo "usage: $0 UnicodeData.txt <version-string> glyphlist.txt > afmtodit.in"
46   exit 1
47 fi
48
49 unicode_data="$1"
50 version_string="$2"
51 glyph_list="$3"
52
53 if test ! -f "$1"; then
54   echo "File \`$1' doesn't exist" >&2
55   exit 2
56 fi
57 if test ! -f "$3"; then
58   echo "File \`$3' doesn't exist" >&2
59   exit 2
60 fi
61
62 # Handle UnicodeData.txt.
63 #
64 # Remove ranges and control characters,
65 # then extract the decomposition field,
66 # then remove lines without decomposition,
67 # then remove all compatibility decompositions.
68 cat "$1" \
69 | sed -e '/^[^;]*;</d' \
70 | sed -e 's/;[^;]*;[^;]*;[^;]*;[^;]*;\([^;]*\);.*$/;\1/' \
71 | sed -e '/^[^;]*;$/d' \
72 | sed -e '/^[^;]*;</d' > $$1
73
74 # Prepare input for running cpp.
75 cat $$1 \
76 | sed -e 's/^\([^;]*\);/#define \1 /' \
77       -e 's/ / u/g' > $$2
78 cat $$1 \
79 | sed -e 's/^\([^;]*\);.*$/\1 u\1/' >> $$2
80
81 # Run C preprocessor to recursively decompose.
82 $CPP $$2 $$3
83
84 # Convert it back to original format.
85 cat $$3 \
86 | sed -e '/#/d' \
87       -e '/^$/d' \
88       -e 's/ \+/ /g' \
89       -e 's/ *$//' \
90       -e 's/u//g' \
91       -e 's/^\([^ ]*\) /\1;/' > $$4
92
93 # Write comment.
94 cat <<END
95 # This table has been algorithmically derived from the file
96 # UnicodeData.txt, version $version_string, available from unicode.org,
97 # on `date '+%Y-%m-%d'`.
98 END
99
100 # Emit first table.
101 echo 'my %unicode_decomposed = ('
102 cat $$4 \
103 | sed -e 's/ /_/g' \
104       -e 's/\(.*\);\(.*\)/  "\1", "\2",/'
105 echo ');'
106 echo ''
107
108 # Write comment.
109 cat <<END
110 # This table has been algorithmically derived from the file
111 # glyphlist.txt, version 2.0, available from partners.adobe.com,
112 # on `date '+%Y-%m-%d'`.
113 END
114
115 # Emit second table.
116 echo 'my %AGL_to_unicode = ('
117 cat "$3" \
118 | sed -e '/#/d' \
119       -e 's/ /_/g' \
120       -e '/;\(E\|F[0-8]\)/d' \
121       -e 's/\(.*\);\(.*\)/  "\1", "\2",/'
122 echo ');'
123
124 # Remove temporary files.
125 rm $$1 $$2 $$3 $$4
126
127 # EOF