I keep the following in the Unix Filters.

#!/usr/bin/perl -w
# Gather lines, print in columns

use strict;

my $MAXLINE = 76 ;
my $COLUMN_WIDTH = 19 ;
my $INDENT = 1 ;

my $cols = int( $MAXLINE / $COLUMN_WIDTH ) ;

my @data = () ;

while (<>)
{
        s/\s+$// ;  #  Trim trailing spaces.
        if ( /^.?$/ {  #  Print empty or single char line.
                printup() if @data ;
                print "$_\n" ;
        } else {
                s/^\s+// ;  #  Trim leading spaces.
                push @data, $_ ;
        }
}

printup() ;

sub printup {

        # Determine boundaries of screen.
        my $rows = int( ( @data + $cols - 1 ) / $cols );

        my ( $filler, $width, $next ) ;
        
        # Now process each item, picking proper piece for this position.
        for ( my $item = 0 ; $item < $rows * $cols ; $item++ )
        {
                my $slot = ( $item % $cols ) * $rows + int( $item / $cols ) ;
                my $text = ( $slot < @data ? $data[$slot] : "" ) ;
                $filler = $width = $next = 0 unless $item % $cols ;
                print " " x $INDENT unless $item % $cols ;

                print " " x $filler, $text ;

                $width += $filler + length $text ;
                $next += $COLUMN_WIDTH ;
                $filler = $width < $next - 1 ? $next - $width : 2 ;
                
                print "\n" unless ( $item + 1 ) % $cols ;
        }
        @data = () ;
}

__END__
--
Wil Baden   Costa Mesa, California


--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to