chiark / gitweb /
mkrules: Handle multiple files with the same metrics.
[xfonts-traditional] / 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
29 while read keyword rest; do
30         case "$keyword" in
31         '#'|'') continue ;;
32         pcf)
33                 pcf=$rest
34                 for f in good bad; do
35                         out=$f/$pcf.bdf
36                         zcat $f/$pcf.pcf.gz | pcf2bdf >$out
37                         eval "$f=\$out"
38                 done
39                 ;;
40         rules)
41                 newfoundry=$rest
42                 eval `perl -ne '
43                         next unless s/^BBX\s+//;
44                         s/\s+$//;
45                         s/\s+/,/g;
46                         s/[-+]?\b\d+\b/ sprintf "%d", $& /ge;
47                         m/^\d+\,(\d+)\b/ or die;
48                         print "key=$_; height=$1\n" or die $!;
49                         exit;
50                 ' <$good`
51                 oldfoundry=`perl -ne '
52                         next unless s/^FOUNDRY\s+\"?//;
53                         s/\"?\s+$//;
54                         print or die $!;
55                         exit;
56                 ' <$good`
57                 printf "%s %s" "$oldfoundry" "$newfoundry" >>rules/foundries.new
58                 case "$seenrules" in
59                 */"$newfoundry,$key"/*)
60                         exec 3>>rules/$newfoundry,$key.rules
61                         ;;
62                 *)
63                         exec 3>rules/$newfoundry,$key.rules
64                         echo >&3 '# -*- perl -*-'
65                         echo >&3 '# autogenerated by mkrules'
66                         echo >&3 'sub {'
67                         seenrules=$seenrules$newfoundry,$key/
68                         ;;
69                 esac
70                 echo >&3 "    # $pcf"
71                 ;;
72         endrules)
73                 exec 3</dev/null
74                 ;;
75         entire)
76                 partial=0
77                 chars
78                 ;;
79         partial)
80                 partial=1
81                 chars
82                 ;;
83         verbatim)
84                 echo >&3 "    $rest"
85                 ;;
86         *)
87                 echo >&2 "??? $keyword"
88                 exit 1
89                 ;;
90         esac
91 done
92
93 while :; do
94         case "$seenrules" in /) break ;; esac
95         seenrules=${seenrules#/}
96         rulefile=${seenrules%%/*}
97         seenrules=/${seenrules#*/}
98         echo "}" >>rules/$rulefile.rules
99 done
100
101 mv rules/foundries.new rules/foundries