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