]> rtime.felk.cvut.cz Git - wvtest.git/blob - tools/wvwrap
189481d0f52c26b0db017af8252132fab3493a31
[wvtest.git] / tools / wvwrap
1 #!/usr/bin/perl -w
2 #
3 # WvTest:
4 #   Copyright (C) 2007-2009 Versabanq Innovations Inc. and contributors.
5 #   Copyright (C) 2012 Michal Sojka <sojka@os.inf.tu-dresden.de>
6 #       Licensed under the GNU Library General Public License, version 2.
7 #       See the included file named LICENSE for license information.
8 #
9 use strict;
10 use Getopt::Long;
11
12 sub usage() {
13     print STDERR "Usage: $0 < wvtest.log\n";
14     exit 127;
15 }
16
17 usage() if (@ARGV > 0);
18
19 my $istty = -t STDOUT && $ENV{'TERM'} ne "dumb";
20 my $columns;
21 if ($istty) {
22     $columns = `tput cols`;
23 } else {
24     $columns = $ENV{'COLUMNS'} || 80;
25 }
26
27 $| = 1;
28
29 while (<>)
30 {
31     chomp;
32     s/\r//g;
33
34     if (/^(\([0-9]+\) (#   )?)?!\s*(.*?)\s+(\S+)\s*$/) {
35         my $line = $_;
36         do {
37             print substr($line, 0, $columns) . "\n";
38             $line = length($line) > $columns ? substr($line, $columns) : '';
39         } while (length($line));
40     } else {
41         print "$_\n";
42     }
43 }