#!/perl/bin/perl # # trim.pl -- trim input file to wrap at the column specified... use strict; use warnings; use diagnostics; my @text; my $length = ( $ARGV[1] or 59 ); my $lineno = 1; my @delimiters = ( '~', '!', '@', '#', '$', '%', '^', '&', '*', '_', '+', '-', '=', '`' ); foreach (<>) { chomp; s/\t/ /g; if ( length($_) > $length ) { push ( @text, cleanline( substr( $_, 0, $length ) ) ); $_ = substr( $_, $length ); while ( length($_) > $length ) { push ( @text, wrapline( substr( $_, 0, $length ) ) ); $_ = substr( $_, $length ); $_ = '' unless (/[^_]+/); } push ( @text, wrapline($_) ) if (/[^_]+/); } else { push ( @text, cleanline($_) ); } } print "\\vskip .125in {\\offinterlineskip\\setlength{\\parindent}{0pt}\\small\n"; print join ( '', @text ); print "}\\vskip .125in\n"; sub clean { my $s = shift; my $d = '|'; if ( $s =~ /\|/ ) { my %list; @list{ split ( '', $s ) } = (); foreach (@delimiters) { unless ( exists( $list{$_} ) ) { $d = $_; last; } } } return "\\verb$d$s$d"; } sub wrapline { return "\\vr{}", clean(shift), "\\par\\wrapmark\n"; } sub cleanline { if ( $lineno % 5 ) { return "\\vr{", $lineno++, "}", clean(shift), "\\par\n"; } else { return "\\vr{\\textcolor{red}{", $lineno++, "}}", clean(shift), "\\par\n"; } }