From: Ian Jackson Date: Sat, 6 Nov 2010 13:50:53 +0000 (+0000) Subject: slopecalc showing args is more abstract and can wrap properly X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=b63bf9500f050f5b87df2dde8d7a3cc75d85be7f;p=trains.git slopecalc showing args is more abstract and can wrap properly --- diff --git a/layout/slopecalc b/layout/slopecalc index be0fd0d..f42cfe2 100755 --- a/layout/slopecalc +++ b/layout/slopecalc @@ -238,23 +238,50 @@ sub dump_schedule ($) { parse_args(); sub dump_args () { - my @oargs; - my @ounders; - my @opoints; + my @out; + my $lmax= 78; + my $xpos= -1; + + lprintf("args:"); + lprintf(""); + + my $writeout= sub { + foreach my $oi (0..2) { + lprintf(" %s", + join(($oi==1 ? '|' : ' '), + @{ $out[$oi] })); + } + }; + my $push= sub { + $xpos += 1 + length($_[0]); + if ($xpos >= $lmax) { + foreach my $oi (0..2) { + push @{ $out[$oi] }, + ($oi==1 && $_[$oi] =~ m/^\-/ ? '-' : ''); + } + $writeout->(); + lprintf(''); + @out= (); + $xpos= length($_[0]); + } + foreach my $oi (0..2) { + push @{ $out[$oi] }, $_[$oi]; + } + }; + foreach (my $i=0; $i<@cp; $i++) { my $cp= $cp[$i]; my @iargs= @{ $cp->{Args} }; if (@iargs && $iargs[0] =~ m/^\+$numre$/) { my $relmove= shift @iargs; - push @oargs, $relmove; - my $spc= ' 'x length $relmove;; - push @ounders, '-'x length $relmove;; - push @opoints, $spc; + $push->($relmove, + '-'x length $relmove, + ' 'x length $relmove); } elsif ($i) { - push @oargs, ' '; - push @ounders, '-'; - push @opoints, ' '; + $push->(' ', + '-', + ' '); } my $ipoint= "#$i"; @@ -263,15 +290,13 @@ sub dump_args () { my $lip= $lipoint; my $l= $lipoint > length($iargs) ? $lipoint : length($iargs); - push @oargs, sprintf "%-*s", $l, $iargs; - push @ounders, ' 'x $l; - my $pad= int(($l-$lipoint)/2); - push @opoints, (' 'x $pad). $ipoint. (' ' x ($l-$lipoint-$pad)); + + $push->((sprintf "%-*s", $l, $iargs), + ' 'x $l, + (' 'x $pad). $ipoint. (' ' x ($l-$lipoint-$pad))); } - lprintf("args: %s", join ' ', @oargs); - lprintf(" %s", join '|', @ounders); - lprintf(" %s", join ' ', @opoints); + $writeout->(); } dump_args();