Sync-to-go: update copyright for 2015
[s-roff.git] / src / ute-afmtodit / make-afmtodit-tables
blob5bb2d203cfe1fe5abbb094bb082f6885d3394744
1 #!/bin/sh
2 #@ make-afmtodit-tables -- script for creating the `unicode_decomposed'
3 #@ and `AGL_to_unicode' tables
4 #@ Synopsis:
5 #@ make-afmtodit-tables \
6 #@ UnicodeData.txt version-string glyphlist.txt > afmtodit.in
7 #@
8 #@ `UnicodeData.txt' is the central database file from the Unicode standard.
9 #@ Unfortunately, it doesn't contain a version number which must be thus
10 #@ provided manually as an additional parameter.
11 #@ `glyphlist.txt' holds the Adobe Glyph List (AGL).
12 #@ This program needs a C preprocessor.
13 #@ TODO remove in favour of S-CText
15 # Copyright (c) 2014 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
17 # Copyright (C) 2005
18 # Free Software Foundation, Inc.
19 # Written by Werner Lemberg <wl@gnu.org>
21 # This is free software; you can redistribute it and/or modify it under
22 # the terms of the GNU General Public License as published by the Free
23 # Software Foundation; either version 2, or (at your option) any later
24 # version.
26 # This is distributed in the hope that it will be useful, but WITHOUT ANY
27 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
28 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 # for more details.
31 # You should have received a copy of the GNU General Public License along
32 # with groff; see the file COPYING. If not, write to the Free Software
33 # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
35 CPP=cpp
37 prog="$0"
39 if test $# -ne 3; then
40 echo "Synopsis: $0 UnicodeData.txt <version-string> glyphlist.txt > afmtodit.in"
41 exit 1
44 unicode_data="$1"
45 version_string="$2"
46 glyph_list="$3"
48 if test ! -f "$1"; then
49 echo "File \`$1' doesn't exist" >&2
50 exit 2
52 if test ! -f "$3"; then
53 echo "File \`$3' doesn't exist" >&2
54 exit 2
57 # Handle UnicodeData.txt.
59 # Remove ranges and control characters,
60 # then extract the decomposition field,
61 # then remove lines without decomposition,
62 # then remove all compatibility decompositions.
63 cat "$1" \
64 | sed -e '/^[^;]*;</d' \
65 | sed -e 's/;[^;]*;[^;]*;[^;]*;[^;]*;\([^;]*\);.*$/;\1/' \
66 | sed -e '/^[^;]*;$/d' \
67 | sed -e '/^[^;]*;</d' > $$1
69 # Prepare input for running cpp.
70 cat $$1 \
71 | sed -e 's/^\([^;]*\);/#define \1 /' \
72 -e 's/ / u/g' > $$2
73 cat $$1 \
74 | sed -e 's/^\([^;]*\);.*$/\1 u\1/' >> $$2
76 # Run C preprocessor to recursively decompose.
77 $CPP $$2 $$3
79 # Convert it back to original format.
80 cat $$3 \
81 | sed -e '/#/d' \
82 -e '/^$/d' \
83 -e 's/ \+/ /g' \
84 -e 's/ *$//' \
85 -e 's/u//g' \
86 -e 's/^\([^ ]*\) /\1;/' > $$4
88 # Write comment.
89 cat <<END
90 # This table has been algorithmically derived from the file
91 # UnicodeData.txt, version $version_string, available from unicode.org,
92 # on `date '+%Y-%m-%d'`.
93 END
95 # Emit first table.
96 echo 'my %unicode_decomposed = ('
97 cat $$4 \
98 | sed -e 's/ /_/g' \
99 -e 's/\(.*\);\(.*\)/ "\1", "\2",/'
100 echo ');'
101 echo ''
103 # Write comment.
104 cat <<END
105 # This table has been algorithmically derived from the file
106 # glyphlist.txt, version 2.0, available from partners.adobe.com,
107 # on `date '+%Y-%m-%d'`.
110 # Emit second table.
111 echo 'my %AGL_to_unicode = ('
112 cat "$3" \
113 | sed -e '/#/d' \
114 -e 's/ /_/g' \
115 -e '/;\(E\|F[0-8]\)/d' \
116 -e 's/\(.*\);\(.*\)/ "\1", "\2",/'
117 echo ');'
119 # Remove temporary files.
120 rm $$1 $$2 $$3 $$4
122 # s-sh-mode