chiark / gitweb /
debian/changelog: Tidy up a bit
[xfonts-traditional.git] / mkrules
1 #!/bin/bash
2 set -e
3 set -o pipefail
4 rm -f rules/foundries
5 rm -f rules/*.rules rules/foundries.new
6
7 chars () {
8         for c in $rest; do
9                 case " $c " in
10                 " "?" ")
11                         ord=`perl -e 'print ord($ARGV[0]),"\n" or die $!' "$c"`
12                         ;;
13                 " "d?*" ")
14                         ord="${c#d}"
15                         c=`perl -e 'printf "%c", $ARGV[0]' "$ord"`
16                         ;;
17                 *)
18                         echo >&2 "??? $c"
19                         exit 1
20                         ;;
21                 esac
22                 ./printrule >&3 "$bad" "$good" $height \
23                         "^ENCODING $ord$" $partial "$c"
24         done
25 }
26
27 seenrules=/
28 seenfoundries=/
29
30 while read keyword rest; do
31         case "$keyword" in
32         '#'|'') continue ;;
33         pcf)
34                 pcf=$rest
35                 for f in good bad; do
36                         in=$f/$pcf.pcf.gz
37                         out=$f/$pcf.bdf
38                         if [ -e $in ]; then
39                                 zcat $in | pcf2bdf >$out
40                         elif [ -e "$out.direct" ]; then
41                                 cp "$out.direct" "$out"
42                         elif [ -e "$f/$pcf.sfd" ]; then
43                                 ./ffconvert.pe "$f/$pcf"
44                                 # 1. fontforge writes a silly filename
45                                 # 2. our crappy machinery copes only
46                                 #  with BDFs all of whose chars have
47                                 #  the bbox of the font
48                                 ./bdfnorm <"$f/$pcf".BDF*.bdf >$out
49                         else
50                                 echo >&2 "cannot make $out!"
51                                 exit 1
52                         fi
53                         eval "$f=\$out"
54                 done
55                 ;;
56         rules)
57                 newfoundry=$rest
58                 eval `perl -ne '
59                         next unless s/^BBX\s+//;
60                         s/\s+$//;
61                         s/\s+/,/g;
62                         s/[-+]?\b\d+\b/ sprintf "%d", $& /ge;
63                         m/^\d+\,(\d+)\b/ or die;
64                         print "key=$_; height=$1\n" or die $!;
65                         exit;
66                 ' <$bad`
67                 oldfoundry=`perl -ne '
68                         next unless s/^FOUNDRY\s+\"?//;
69                         s/\"?\s+$//;
70                         print or die $!;
71                         exit;
72                 ' <$good`
73                 case "$seenfoundries" in
74                 */"$oldfoundry,$newfoundry"/*)
75                         ;;
76                 */"$oldfoundry,"*)
77                         echo >&2 "inconsistent foundry mapping"
78                         exit 1
79                         ;;
80                 *)
81                         seenfoundries=$seenfoundries$oldfoundry,$newfoundry/
82                         printf >>rules/foundries.new \
83                                 "%s %s\n" "$oldfoundry" "$newfoundry"
84                         ;;
85                 esac
86                 case "$seenrules" in
87                 */"$newfoundry,$key"/*)
88                         exec 3>>rules/$newfoundry,$key.rules
89                         ;;
90                 *)
91                         exec 3>rules/$newfoundry,$key.rules
92                         echo >&3 '# -*- perl -*-'
93                         echo >&3 '# autogenerated by mkrules'
94                         echo >&3 'sub {'
95                         seenrules=$seenrules$newfoundry,$key/
96                         ;;
97                 esac
98                 echo >&3 "    # $pcf"
99                 ;;
100         endrules)
101                 exec 3</dev/null
102                 ;;
103         entire)
104                 partial=0
105                 chars
106                 ;;
107         partial)
108                 partial=1
109                 chars
110                 ;;
111         verbatim)
112                 echo >&3 "    $rest"
113                 ;;
114         *)
115                 echo >&2 "??? $keyword"
116                 exit 1
117                 ;;
118         esac
119 done
120
121 while :; do
122         case "$seenrules" in /) break ;; esac
123         seenrules=${seenrules#/}
124         rulefile=${seenrules%%/*}
125         seenrules=/${seenrules#*/}
126         echo "}" >>rules/$rulefile.rules
127 done
128
129 mv rules/foundries.new rules/foundries