#!/usr/bin/perl # -*- perl -*- # Copyright 2006 DJ Delorie, licenced under GPL v2 # Additions by (* jcl *) # 1. Added support for multiple files on the command line # 2. Misc. Perlification use strict; use warnings; use Carp; my $Scale = shift; croak "Scale must be greater than 0" unless $Scale > 0; my %syntax = map { my @v = split; shift(@v) => [@v] } << 'END_SYNTAX' =~ /(.+)/g; L 1 1 1 1 0 1 0 0 1 1 G 1 1 1 1 0 0 0 0 B 1 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 V 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 A 1 1 1 0 0 0 1 0 0 1 1 T 1 1 0 1 0 0 0 0 0 N 1 1 1 1 0 U 1 1 1 1 0 0 P 1 1 1 1 0 0 0 C 1 1 0 0 0 0 F 0 1 0 END_SYNTAX my @Files = @ARGV; foreach my $infilename (@Files) { @ARGV = ($infilename); my $outfilename = $infilename; $outfilename =~ s/\.sym$/_$Scale.sym/; open(OUT, ">$outfilename") || croak "Could not open $outfilename for output"; while (<>) { s/[\r\n]+$//; my ($type, @args) = split; if ($syntax{$type}) { my @scale_p = @ { $syntax{$type} }; croak "The number of args does not match the syntax definition at input line $." unless $#args = $#scale_p; foreach my $i (0..$#scale_p) { next unless $scale_p[$i]; $args[$i] = int($args[$i] * $Scale); } print OUT join(' ', $type, @args), "\n"; if ($type eq "T") { foreach (1..$args[8]) { $_ = <>; print OUT; last if eof; } } } else { print OUT "$_\n"; } } close(OUT) || croak "Could not close $outfilename"; } # Style (adapted from the Perl Cookbook, First Edition, Recipe 12.4) # 1. Names of functions and local variables are all lowercase. # 2. The program's persistent variables (either file lexicals # or package globals) are capitalized. # 3. Identifiers with multiple words have each of these # separated by an underscore for readability. # 4. Constants are all uppercase. # 5. If the arrow operator (->) is followed by either a # method name or a variable containing a method name then # there is a space before and after the operator.