3 # A state machine that post processes a mup postscript file to alter
4 # the colour of various things
6 # Copyright (c) 2004 Dirk Koopman
8 # $Id: mupcolour,v 1.2 2004/06/02 13:35:29 djk Exp $
14 my %staff = (); # contains the actions for each staff
16 # arguments are of the form: -l1=#275643 -s2=#324524
17 # ie '-', a letter, a staff no, '=', an RGB triple
18 while ($ARGV[0] =~ /^-/) {
20 if (my ($let, $staffno, $r, $g, $b) = $arg =~ /^-([a-zA-Z])(\d+)=#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/) {
21 my $staff = $staff{$staffno} || {};
22 $staff->{$let} = [hex($r)/256, hex($g)/256, hex($b)/256];
23 $staff{$staffno} = $staff;
25 usage("Don't recognise '$arg'");
31 usage("Need an input filename");
42 rename($fn, "$fn.bak") || usage("cannot rename $fn -> $fn.bak") || exit(1);
43 open IN, "$fn.bak" || usage("cannot open $fn.bak ($!)") || exit(1);
44 open OUT, ">$fn" || usage("cannot open $fn ($!)") || exit(1);
54 print OUT $store if $store;
56 $dostore = $staffno = 0;
58 } elsif (/^%\s+staff\s(\d+)/ && $state eq 'waitstaff') {
61 } elsif (/findfont$/ && $state eq 'waitfont') {
64 } elsif (/\)\s+show$/ && $state eq 'waitshow') {
66 my $st = $staff{$staffno};
70 print OUT "$rgb->[0] $rgb->[1] $rgb->[2] setrgbcolor\n$store$_\n0 0 0 setrgbcolor\n";
89 print "mupcolour: A program to add colour to mup output\n\n";
90 print "$mess\n\n" if $mess;
91 print "usage: mupcolour -l1=#324532 -l2=#453232 file.ps\n";
92 print "arguments are of the form: -,letter,staffno,=#,rgb triple\n";
93 print "the letters available are:\n";
94 print " 'l' - lyric colour\n";