chiark / gitweb /
mkrules: Handle multiple files with the same metrics.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 10 Jan 2012 23:59:05 +0000 (23:59 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 11 Jan 2012 01:35:52 +0000 (01:35 +0000)
If we had two PCF files with the same metrics previously, we'd overwrite
the rules file from the first with a new file from the second.  Keep
track of which files we've written during the run, and append to them if
we've already started writing.  Finish them all up at the end.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
mkrules

diff --git a/mkrules b/mkrules
index 5b07879..b55b397 100755 (executable)
--- a/mkrules
+++ b/mkrules
@@ -24,6 +24,8 @@ chars () {
        done
 }
 
+seenrules=/
+
 while read keyword rest; do
        case "$keyword" in
        '#'|'') continue ;;
@@ -53,13 +55,21 @@ while read keyword rest; do
                        exit;
                ' <$good`
                printf "%s %s" "$oldfoundry" "$newfoundry" >>rules/foundries.new
-               exec 3>rules/$newfoundry,$key.rules
-               echo >&3 '# -*- perl -*-'
-               echo >&3 '# autogenerated by mkrules'
-               echo >&3 'sub {'
+               case "$seenrules" in
+               */"$newfoundry,$key"/*)
+                       exec 3>>rules/$newfoundry,$key.rules
+                       ;;
+               *)
+                       exec 3>rules/$newfoundry,$key.rules
+                       echo >&3 '# -*- perl -*-'
+                       echo >&3 '# autogenerated by mkrules'
+                       echo >&3 'sub {'
+                       seenrules=$seenrules$newfoundry,$key/
+                       ;;
+               esac
+               echo >&3 "    # $pcf"
                ;;
        endrules)
-               echo >&3 '}'
                exec 3</dev/null
                ;;
        entire)
@@ -80,4 +90,12 @@ while read keyword rest; do
        esac
 done
 
+while :; do
+       case "$seenrules" in /) break ;; esac
+       seenrules=${seenrules#/}
+       rulefile=${seenrules%%/*}
+       seenrules=/${seenrules#*/}
+       echo "}" >>rules/$rulefile.rules
+done
+
 mv rules/foundries.new rules/foundries