0
  A   mˆl–ßi~” ”Ð?Je@‚ãn\ªbÑ¿�þDû±¬Ü£�’>Ñ[”€þë„ÿê_ˆI|¥�+V[(Ãè ){    m#!/usr/bin/perl
# Debian required shebang above
# Original shebang below
# #!/usr/bin/env perl

# dviinfox
# ========
# 
# This script is a joint effort of
#   Dag Langmyhr, Department of Informatics, University of Oslo
#     (dag at ifi.uio.no)
# and
#   Hironobu Yamashita, Japanese TeX Development Community
#     (h.y.acetaminophen at gmail.com)
#
# A program to print information about a DVI file.
#
# Usage: dviinfox [options] file1 file2 ...
# where the flags indicate which information is desired.
#  -f  Give information about the fonts used.
#  -p  Give information about the number of pages.
#  -v  List the program version number.
#  -h  Show help message.
# No options will provide all information available.
#
# Example:
# % dviinfox alltt.dvi
# alltt.dvi: DVI format 2; 3 pages
#   Magnification: 1000/1000
#   Size unit: 1000x25400000/(1000x473628672)dum = 0.054dum = 1.000sp
#   Page size: 407ptx682pt = 14.340cmx23.970cm
#   Stack size: 8
#   Comment: " TeX output 1995.07.07:1513"
#   Font  27:      cmr9 at  9.000 (design size  9.000, checksum=1874103239)
#   Font  26:     cmsy6 at  6.000 (design size  6.000, checksum=1906386187)
#   Font  21:      cmr8 at  8.000 (design size  8.000, checksum=2088458503)
#   Font  20:    cmsy10 at 12.000 (design size 10.000, checksum=555887770)
#   Font  16:     cmr12 at 12.000 (design size 12.000, checksum=1487622411)
#   Font  15:    cmtt12 at 17.280 (design size 12.000, checksum=3750147412)
#   Font  14:     cmr17 at 17.280 (design size 17.280, checksum=1154739572)
#   Font  13:    cmsy10 at 10.000 (design size 10.000, checksum=555887770)
#   Font   7:     cmr10 at 10.000 (design size 10.000, checksum=1274110073)
#   Font   6:      cmr7 at  7.000 (design size  7.000, checksum=3650330706)

use strict;

my $Prog    = "dviinfox";
my $Version = "1.06";
my $Author = "Dag Langmyhr and Hironobu Yamashita";

my $True = 1;
my $False = 0;

my $List_all = $True;
my $List_fonts = $False;
my $List_pages = $False;

# DVI commands:
my $DVI_Filler    = "\337"; # 223 = 0xdf
my $DVI_Post      = "\370"; # 248 = 0xf8
my $DVI_Post_post = "\371"; # 249 = 0xf9
my $DVI_Pre       = "\367"; # 247 = 0xf7
my $DVI_Font      = "\363"; # 243 = 0xf3
my $DVI_Font2     = "\364"; # 244 = 0xf4
my $DVI_Font3     = "\365"; # 245 = 0xf5
my $DVI_Font4     = "\366"; # 246 = 0xf6
my $XDV_Font      = "\374"; # 252 = 0xfc

my $Unit;

if (!@ARGV) {
    show_usage();
    print "Try \"$Prog -h\" for more information.\n";
}

Param:
foreach (@ARGV) {
    /^-f$/ && do {
	$List_fonts = $True;  $List_all = $False;  next Param; };
    /^-p$/ && do {
	$List_pages = $True;  $List_all = $False;  next Param; };
    /^-v$/ && do {
	show_version();  next Param; };
    /^-h$/ && do {
	show_help();  next Param; };
    /^-/ && do {
	print STDERR "$Prog: Unknown option '$_' ignored.\n";  next Param; };
    
    &Read_DVI_file($_);
}

exit 0;

# Only sub definitions from here on

sub show_version {
    print "This is $Prog $Version, by $Author\n";
}

sub show_usage {
    show_version();
    print "Usage: $Prog [-f][-p][-v] file...\n";
}

sub show_help {
    show_usage();
    print "A program to print information about a DVI file.\n";
    print "Options:\n";
    print "  -f  Give information about the fonts used.\n";
    print "  -p  Give information about the number of pages.\n";
    print "  -v  List the program version number.\n";
    print "  -h  Show help message.\n";
    exit 0;
}

sub Read_DVI_file {
    local($_) = @_;
    my ($c, $cn);
    my $IS_XDV = 0;

    print "$_: ";

    open(F, $_) || do { print STDERR "Could not open!\n\n"; exit 1; };

    # First, read info at start of DVI file:

    if (($c = getc(F)) ne $DVI_Pre) {
	printf STDERR ("Not a DVI file (first byte is 0x%02x, not 0x%02x)!\n\n", 
	       ord($c), ord($DVI_Pre));
	close F;  exit 1;
    };

    my $Format  = ord(getc(F));
    my $Numer   = &Read4;
    my $Denom   = &Read4;
    my $Magni   = &Read4;
    my $Comment = &Read_text;

    # Then, read information at the end of the DVI fil