#!perl
## start at the end of the dvi file.  There will be between 4 and 7 instances
## of byte 223 (dec), a padding byte which makes the total file length a
## multiple of 4 bytes.
## @ 4..7
open(DVIFILE,"<$ARGV[0]") || die "$?: $@";
seek(DVIFILE,-(4+7),2) || die "$?: $@";
read(DVIFILE,$var,4+4);
# print $var;
$var =~ /([\000-\377]{4})\002\337+$/;
$off = unpack("N",$1);
seek(DVIFILE,$off,0);
read(DVIFILE,$v2,34);
@vals=unpack("CNNNNNNnn",$v2);
# print join(":",@vals),"\n";
print $vals[8],"\n";
## These are preceded by a byte 2, which is the id byte.
## @+1
## This is preceded by a 32-bit word, containing the offset in the dvi
## file at which the postamble begins.
## @+4
## If we now start at this location, which is the beginning of the postamble,
## we get the following sequence of data:
## 
## @+1 byte 248 (dec) {beginning of postamble}
## @+4 long pointer to start of last page
## @+4 long 25400000 (dec) {conversion ratio for sp}
## @+4 long 473628672 (dec) {the other half of the conversion ratio}
## @+4 long magnification
## @+4 long max_v
## @+4 long max_h
## @+2 short [MSB first] max_push
## @+2 short [MSB first] total_pages
## @+0 ==> 34
## Keith, you said you'd be interested in writing a program to grab
## this information, if I could get you the pertinent data.  Here they
## are, I don't have time to write such a program and I need it this
## week; if you feel like writing and debugging such a dvinumpages,
## I'd appreciate it.
## 
## Note that this is the number of times \shipout was invoked, and
## corresponds to the total number of pages printed, regardless of any
## \count0 frobbery.  (It's the same variable as in
## 
## print_nl("Output written on"); print(output_file_name); print(" (");
##   print_int(total_pages); print(" page");
## if total_pages =/ 1 then print_char("s");
## 
## etc.)
