chiark / gitweb /
slopecalc showing args is more abstract and can wrap properly
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 6 Nov 2010 13:50:53 +0000 (13:50 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 6 Nov 2010 13:50:53 +0000 (13:50 +0000)
layout/slopecalc

index be0fd0d440605f3b2c7c5e002d62dcfa597e0a00..f42cfe27e4c8513b5c3d085c00443c95dc2c3ec6 100755 (executable)
@@ -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();