#!/usr/local/bin/perl $Version = "0.1 (8 May 1999)" ; # Generate a dvips-style page listing for all those pages with # specials. If -grep option is given, only 'see' those lines that # contain the string given following the option. $usage_string = "specials.pl $Version\nUSAGE: specials [--grep regex] dvi_file\n" ; use Getopt::Long ; &GetOptions("g|grep=s" => \$grep_string ); # Quote grep_string $grep_string = quotemeta($grep_string) ; # Check that there are at least two arguments. if ($#ARGV < 0) { print STDOUT "Not enough arguments.\n" ; print STDOUT $usage_string ; exit 0 ; } # Execute dvii -s on the given file and store output. $pages = `dvii -s $ARGV[0] ` ; # Store each line in an array. while ($pages) { if ($pages =~ s?s:\[(\d*)/([\-|\d]\d*)\]::([^\n]*\n)??) { push @lines, ("$2!!!$3") ; } } # Extract those lines that match $grep_string. @match_lines = grep /$grep_string/, @lines ; # Cycle through specials extracting the TeX page. foreach $value (@match_lines) { if ($value =~ /([\-|\d]\d*)!!!([^\n])*\n/) { push @specials, ("$1") ; #print "$1\n" ; } } if ($#specials ge 0) { # Winnow special pages $prev = 'nonesuch'; @unique_special_pages = grep($_ ne $prev && ($prev = $_), @specials) ; foreach $value (@unique_special_pages) { $dvips_string = "$dvips_string$value," ; } # Remove last comma from string. substr($dvips_string, -1) = "" ; print "-pp$dvips_string\n" ; } # History # # 0.0 (April 199) Initial version. # 0.0 (8 May 199) Added -grep option.