#!/usr/bin/perl -w use strict; (my $basename = $0) =~ s!.*/!!; my $Verbose; sub usage () { return <= 2) { if ($ARGV[0] eq '-v') { $Verbose = 1; shift; } else { die usage; } } # The "0" keeps the test false for non-existent files (warn itself seems # to return 1, and I don't want the skip silent...). @ARGV = grep {-e $_ or warn("$basename: Couldn't find file $_, skipping...\n"),0 } @ARGV; foreach my $File (@ARGV) { -e $File or warn "$basename: Could not find file $File, skipping...\n"; open(DVI, "dvi2tty -w132 -q $File |") or die "$basename: Could not run dvi2tty command: $!"; while () { while (/\*$/) { $_ .= || last; s/\*\n \*//; } next unless /(\w+)-$/; #Look for lines ending with a word+hyphen next if ($1 =~ /^\d+$/); #Skip if the word's just digits (biblio?) my $First_line = $_; my $first = $1; while () { s/^\s+//; #Remove leading whitespace. next if /^$/; #Ignore blanks. next if /^\d/; #Ignore leading digits (again, only biblio?) next if /^Fig/; #Ignore "Figure" blurbs. last; #Probably found it, so end "skipping" loop } my $Second_line = $_; if (/^(\w+)/) { my $second = $1; print $Verbose ? ("$File:\n${First_line}${Second_line}\n") : ("$first-$second\n"); } else { warn "$basename: !!! PROBLEM ($File): $first-\n$_!!!\n"; } redo if (/-$/); } close(DVI) or die "$basename: Error closing dvi2tty command: $!"; }