#!/usr/bin/perl
#!/usr/eecs/bin/perl
#
# This just cats its input files to/local/bin/perlther, but inserts  a  blank  line
# between  each file.  It's a pity that, among all the obscure options
# that've been added to cat(1), this feechur wasn't included.  We also
# trim  trailing  whitestuff from each line, and reduce multiple blank
# lines to a single blank line.  We also renumber the X:  lines  while
# we're at it, to satisfy all those abc programs that need consecutive
# numbers.

$| = 1;
$tunenum = 0;

for $f (@ARGV) {
	if ($f =~ /^[-+]s/i) {
		$sep = 1;	# Generate separators.
	} elsif (open(F,$f)) {
		if ($last && $files) {
			print "%%sep 5 5 200\n" if $sep;
			print "\n";
		}
		$last = '';
		for $l (<F>) {
			$l =~ s/\s+$//;;
			if ($l || $last) {
				$l =~ s/^(\w:)\s */$1 /;
				if ($l =~ m/^X:\s*(\d+)/) {
					$oldnum = $1;	# The input tune's number.
#					if ($oldnum > $tunenum) {$tunenum = $oldnum} else {++$tunenum}
					++$tunenum;
					$l = "X: $tunenum";
				}
				print "$l\n";
			}
			$last = $l;
		}
		++$files;
	} else {
		print STDERR "$0: Can't read \"$f\" [$~]\n";
	}
}

