From: stefan@bagdad.nbg.sub.org (Stefan Lindner)
Newsgroups: de.comp.tex
Subject: Re: DVI Info
Keywords: DVI Tex HELP
Date: 11 Apr 92 23:46:57 GMT
Distribution: sub
Organization: Le Volksbuerau

hilgert@troja.informatik.uni-dortmund.de (Thomas Hilgert) schreibt:

> ich muss aus einem DVI File die Anzahl der Seiten lesen. Kann mir einer die 
> Strucktur eines DVI Files send ??

Man verwende folgendes C-Programm: (das dazugehoerige WEB-File mit den
Erklaerungen steht in Bagdad im TeX-Server)
---------------------------- Schnipp -------------------------------
#define banner "This is DVIinfo Version 1.0\n"
#define error(a){fprintf(stderr,a);exit(1);} \

#define post 248
#define post_post 249
#define dvi_id 2
#define nop 138
#define fnt_def1 243
#define fnt_def2 244
#define fnt_def3 245
#define fnt_def4 246
#define dvi_id 2 \

/*2:*/
#line 34 "g:\ct\dviinfo.web"

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/*:2*//*3:*/
#line 42 "g:\ct\dviinfo.web"

typedef unsigned long four_bytes;


/*:3*//*4:*/
#line 67 "g:\ct\dviinfo.web"

int cur_command;

/*:4*//*5:*/
#line 81 "g:\ct\dviinfo.web"

double unity;

/*:5*//*6:*/
#line 87 "g:\ct\dviinfo.web"

void print_dimen(four_bytes x){
double val;
char*unity_name;

val= unity*x/10000.0;

unity_name= "cm";
val/= 10;}
else
unity_name= "mm";
printf("%5.2f %s",val,unity_name);
}


/*:6*//*7:*/
#line 109 "g:\ct\dviinfo.web"

FILE*dvi_file;

four_bytes read_unsigned(int bytes){
four_bytes x;

x= getc(dvi_file);
while(bytes-->1){
x*= 256;
x+= getc(dvi_file);}
return(x);


/*:7*//*8:*/
#line 124 "g:\ct\dviinfo.web"

int reverse_getc(void){

fseek(dvi_file,-2,SEEK_CUR);
return(getc(dvi_file));
}


/*:8*//*22:*/
#line 293 "g:\ct\dviinfo.web"

void process_dvi_file(void){
/*9:*/
#line 156 "g:\ct\dviinfo.web"

four_bytes design_size,at_size;
int a,l;
double font_size;

/*:9*//*13:*/
#line 221 "g:\ct\dviinfo.web"

fpos_t post_loc;

/*:13*//*16:*/
#line 262 "g:\ct\dviinfo.web"

four_bytes num,den,magnification;
/*:16*//*19:*/
#line 274 "g:\ct\dviinfo.web"

four_bytes page_width,page_height;

/*:19*/
#line 295 "g:\ct\dviinfo.web"

int pages;

/*14:*/
#line 229 "g:\ct\dviinfo.web"

fseek(dvi_file,0,SEEK_END);

while((cur_command= reverse_getc())==223)
;
if(cur_command!=dvi_id)
error("Falsches id-Byte in Postamble");


reverse_getc();
reverse_getc();
reverse_getc();
reverse_getc();
cur_command= reverse_getc();
if(cur_command!=post_post)
error("Postamble nicht gefunden");

post_loc= (fpos_t)read_unsigned(4);

if(fseek(dvi_file,post_loc,SEEK_SET)!=0)
error("Seek Fehler, `postamble' nicht gefunden");


error("Postamble nicht gefunden");

read_unsigned(4);



/*:14*/
#line 298 "g:\ct\dviinfo.web"

/*18:*/
#line 266 "g:\ct\dviinfo.web"

num= read_unsigned(4);
den= read_unsigned(4);
magnification= read_unsigned(4);
unity= (num*((double)magnification/1000))/den;

/*:18*/
#line 300 "g:\ct\dviinfo.web"

/*20:*/


page_height= read_unsigned(4);
page_width= read_unsigned(4);

/*:20*/
#line 301 "g:\ct\dviinfo.web"

read_unsigned(2);
pages= (int)read_unsigned(2);

printf("Die DVI-Datei enthlt %d Seiten\n",pages);
/*21:*/
#line 283 "g:\ct\dviinfo.web"

printf("Jede Seite ist ");
print_dimen(page_width);
printf(" breit und ");
print_dimen(page_height);
printf(" hoch.\n");



#line 306 "g:\ct\dviinfo.web"

/*11:*/
#line 186 "g:\ct\dviinfo.web"

while(cur_command!=post_post){
cur_command= (int)read_unsigned(1);
switch(cur_command){
case nop:
case post_post:break;
case fnt_def1:
case fnt_def2:
case fnt_def3:
case fnt_def4:
read_unsigned(cur_command-fnt_def1+1);
/*10:*/
#line 162 "g:\ct\dviinfo.web"

read_unsigned(4);
at_size= read_unsigned(4);
design_size= read_unsigned(4);

l= (int)read_unsigned(1);
while(a-->0)
putc(getc(dvi_file),stdout);
putc(':',dvi_file);
while(l-->0)
putc(getc(dvi_file),stdout);
font_size= (at_size*((double)magnification/
1000))/design_size;
printf(" in Vergrerung %5.3f\n",font_size);

/*:10*/
#line 197 "g:\ct\dviinfo.web"

break;
default:error("Illegaler Befehl");
}
}


/*:11*/
#line 307 "g:\ct\dviinfo.web"

}

/*:22*//*23:*/
#line 311 "g:\ct\dviinfo.web"

int main(int argc,char**argv){

fputs(banner,stderr);
if(argc!=2){
fprintf(stderr,"usage: DVIinfo dvi-file\n");
return(1);}
argv++;
dvi_file= fopen(*argv,"rb");
if(dvi_file==NULL){
fprintf(stderr,"Die DVI-Datei %s kann "
"nicht geffnet werden\n",*argv);
return(1);}
process_dvi_file();

return(0);
}

/*:23*/

---------------------------- Schnapp -------------------------------

PS. Das Programm enthaelt leider in paar Umlaute, die beim Posten verloren
gehen. Ich bitte um Nachsicht.

-- 
Stefan Lindner, Iltisstr. 3, W-8510 F"urth, Voice (09 11)7 59 18 86
texserver ANY1000-2400 ACU 2400 0911758547 gin:--gin nuucp\n sword: anonymous\n
uucp bagdad!/server/README /your/home