chiark / gitweb /
exactly as found in #660965 message 34
[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                         out=$f/$pcf.bdf
37                         zcat $f/$pcf.pcf.gz | pcf2bdf >$out
38                         eval "$f=\$out"
39                 done
40                 ;;
41         rules)
42                 newfoundry=$rest
43                 eval `perl -ne '
44                         next unless s/^BBX\s+//;
45                         s/\s+$//;
46                         s/\s+/,/g;
47                         s/[-+]?\b\d+\b/ sprintf "%d", $& /ge;
48                         m/^\d+\,(\d+)\b/ or die;
49                         print "key=$_; height=$1\n" or die $!;
50                         exit;
51                 ' <$good`
52                 oldfoundry=`perl -ne '
53                         next unless s/^FOUNDRY\s+\"?//;
54                         s/\"?\s+$//;
55                         print or die $!;
56                         exit;
57                 ' <$good`
58                 case "$seenfoundries" in
59                 */"$oldfoundry,$newfoundry"/*)
60                         ;;
61                 */"$oldfoundry,"*)
62                         echo >&2 "inconsistent foundry mapping"
63                         exit 1
64                         ;;
65                 *)
66                         seenfoundries=$seenfoundries$oldfoundry,$newfoundry/
67                         printf >>rules/foundries.new \
68                                 "%s %s\n" "$oldfoundry" "$newfoundry"
69                         ;;
70                 esac
71                 case "$seenrules" in
72                 */"$newfoundry,$key"/*)
73                         exec 3>>rules/$newfoundry,$key.rules
74                         ;;
75                 *)
76                         exec 3>rules/$newfoundry,$key.rules
77                         echo >&3 '# -*- perl -*-'
78                         echo >&3 '# autogenerated by mkrules'
79                         echo >&3 'sub {'
80                         seenrules=$seenrules$newfoundry,$key/
81                         ;;
82                 esac
83                 echo >&3 "    # $pcf"
84                 ;;
85         endrules)
86                 exec 3</dev/null
87                 ;;
88         entire)
89                 partial=0
90                 chars
91                 ;;
92         partial)
93                 partial=1
94                 chars
95                 ;;
96         verbatim)
97                 echo >&3 "    $rest"
98                 ;;
99         *)
100                 echo >&2 "??? $keyword"
101                 exit 1
102                 ;;
103         esac
104 done
105
106 while :; do
107         case "$seenrules" in /) break ;; esac
108         seenrules=${seenrules#/}
109         rulefile=${seenrules%%/*}
110         seenrules=/${seenrules#*/}
111         echo "}" >>rules/$rulefile.rules
112 done
113
114 mv rules/foundries.new rules/foundries