w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dviinfo.c
Go to the documentation of this file.
1 /*
2  * Dviinfo $Revision: 1.3 $ (c) 1991-93 by Valentino Kyriakides.
3  *
4  * $Log: dviinfo.c,v $
5  * Revision 1.3 1993/11/23 22:49:30 vkyr
6  * Added -h,-v options and a Makefile with one compilation def
7  * for inch or centimeter.
8  *
9  * Revision 1.2 1992/05/09 12:30:26 vkyr
10  * Added page metric options and a man-page, changed the
11  * output text to english.
12  *
13  * Revision 1.1 1991/06/08 18:31:22 vkyr
14  * Initial revision
15  *
16  * Compile: "cc -o dviinfo dviinfo.c ; strip dviinfo" or
17  * use the supplied Makefile.
18  */
19 
20 
21 /*
22  * RCS stuff
23  */
24 
25 #ifdef lint
26  static char RCSid[] = "$Id: dviinfo.c,v 1.3 1993/11/23 22:49:30 vkyr Exp $";
27 #endif
28 
29 /*
30  * Needed header-files
31  */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <math.h>
36 
37 /*
38  * Info and version defs
39  */
40 
41 #define version "Dviinfo, version 1.3 \n" /* version is $Revision: 1.3 $ */
42 #define info "This is dviinfo, a little TeX dvi-file tool.\n\n"
43 
44 /*
45  * Needed defs
46  */
47 
48 #define error(a) {fprintf(stderr, a); exit(1);}
49 #define post 248
50 #define post_post 249
51 #define dvi_id 2
52 #define nop 138
53 #define fnt_def1 243
54 #define fnt_def2 244
55 #define fnt_def3 245
56 #define fnt_def4 246
57 
58 typedef unsigned long four_bytes;
59 
60 /*
61  * Global vars
62  */
63 
65 double unity;
68 
69 
70 /*
71  * Functions
72  */
73 
75 {
76  double val;
77  char *unity_name;
78 
79  val = unity*x / 10000.0;
80  if (getargv[1][0] == '-')
81  {
82  switch (getargv[1][1])
83  {
84  default:
85  case 'c': if (val > 10)
86  {
87  unity_name = "cms";
88  val /= 10;
89  }
90  else
91  unity_name = "mm";
92  break;
93  case 'i': val /= 10;
94  val = val * 0.3937;
95  unity_name = "inches";
96  break;
97  case 'p': val /= 10;
98  val = val * 28.346;
99  unity_name = "points";
100  break;
101  case 'P': val /= 10;
102  val = val * 2.3623;
103  unity_name = "picas";
104  break;
105  }
106  } else {
107 #ifdef INCH /* defaults page metric to inches */
108  val /= 10;
109  val = val * 0.3937;
110  unity_name = "inches";
111 #else /* Not INCH defaults page metric to centimeters */
112  if (val > 10)
113  {
114  unity_name = "cms";
115  val /= 10;
116  }
117  else
118  unity_name = "mm";
119 #endif /* INCH */
120  }
121  printf("%5.2f %s", val, unity_name);
122 }
123 
124 
125 
127 {
128  four_bytes x;
129 
130  x = getc(dvi_file);
131  while (bytes-- >1)
132  {
133  x *= 256;
134  x += getc(dvi_file);
135  }
136  return(x);
137 }
138 
139 
140 int reverse_getc(void)
141 {
142  fseek(dvi_file, -2, SEEK_CUR);
143  return(getc(dvi_file));
144 }
145 
146 
148 {
149  four_bytes design_size, at_size;
152  int a, l, pages;
153  double font_size;
154  fpos_t post_loc;
155 
156 
157  fseek(dvi_file,0,SEEK_END); /* EOF */
158  /* ignore fillbytes */
159  while ((cur_command = reverse_getc()) == 223)
160  ;
161  if (cur_command != dvi_id)
162  error("Wrong id-Byte in postamble");
163  /* read backwards till post_post */
166  if (cur_command != post_post)
167  error("Postamble not found");
168  post_loc = (fpos_t)read_unsigned(4);
169  /* jump to postamble */
170  if (fseek(dvi_file,(long)post_loc,SEEK_SET) != 0)
171  error("Seek error, `postamble' not found");
172  if ((cur_command = (int) read_unsigned(1)) != post)
173  error("Postamble not found");
174  read_unsigned(4);
175  /* pointer to begin of last page */
176  num = read_unsigned(4); den = read_unsigned(4);
178  unity = (num*((double) magnification/1000))/den;
181  read_unsigned(2); /* ignore stacksize */
182  pages = (int) read_unsigned(2);
183  printf("\nThe dvi-file \"%s\" contains (%d) pages.\n",filename, pages);
184  printf("Each page is ");
185  print_dimen(page_width); printf(" wide and ");
186  print_dimen(page_height); printf(" high.\n\n");
187  printf("The dvi-file \"%s\" needs the following fonts: \n\n", filename);
188  while (cur_command != post_post)
189  {
191  switch (cur_command)
192  {
193  case nop:
194  case post_post : break;
195  case fnt_def1 :
196  case fnt_def2 :
197  case fnt_def3 :
198  case fnt_def4 :
200  read_unsigned(4); /* overread checksum */
201  at_size = read_unsigned(4);
203  a = (int) read_unsigned(1);
204  l = (int) read_unsigned(1);
205  while (a-- > 0)
207  fputs(" -> ", stdout); /* previously putc(':', stdout); */
208  while (l-- > 0)
210  font_size = (at_size*((double)magnification/1000))/design_size;
211  printf(" at magstep %5.3f\n", font_size);
212  break;
213  default : error("Illegal command");
214  }
215  }
216  printf("\n(EOF - bye!)\n\n");
217 }
218 
219 int usage(char *prgname)
220 {
221  fputs(info, stderr);
222  fprintf(stderr,"Usage: %s [-c | -i | -p | -P] [-h] [-v] [dvi-file]\n", prgname);
223  fprintf(stderr,"Where: \n");
224  fprintf(stderr,"\t -c \t Show page layout in cms (default)\n");
225  fprintf(stderr,"\t -i \t Show page layout in inches \n");
226  fprintf(stderr,"\t -p \t Show page layout in points \n");
227  fprintf(stderr,"\t -P \t Show page layout in picas \n");
228  fprintf(stderr,"\t -h \t Print a summary of the options \n");
229  fprintf(stderr,"\t -v \t Print the version number \n\n");
230  exit(0);
231 }
232 
233 #ifdef WIN32
234 #include <fcntl.h>
235 #include <io.h>
236 #endif
237 
238 int main(int argc, char **argv)
239 {
240 #ifdef WIN32
241  strcpy(argv[0], "dviinfo");
242  setmode(fileno(stdin), _O_BINARY);
243 #endif
244  getargv = argv;
245  prgname = *argv;
246  if (argc < 2)
247  {
248  usage(prgname);
249  }
250  argv++;
251  if (argc == 3)
252  argv++;
253  if (getargv[1][0] == '-')
254  {
255  switch (getargv[1][1])
256  {
257  case 'v': fputs(version, stderr);
258  return(1);
259  break;
260  case 'h': usage(prgname);
261  break;
262  }
263  }
264  dvi_file = fopen(*argv, "rb");
265  if (dvi_file == NULL)
266  {
267  fprintf(stderr,"Can't open DVI-file %s \n", *argv);
268  return(1);
269  }
270  filename = *argv;
272  return(0);
273 }
char RCSid[]
Definition: drawPS.c:38
#define fopen
Definition: xxstdio.h:21
#define fseek
Definition: xxstdio.h:30
int printf()
char * strcpy()
struct pagespec pages[(32)]
#define info
Definition: dviinfo.c:42
int usage(char *prgname)
Definition: dviinfo.c:219
#define post
Definition: dviinfo.c:49
four_bytes read_unsigned(int bytes)
Definition: dviinfo.c:126
FILE * dvi_file
Definition: dviinfo.c:67
int main(int argc, char **argv)
Definition: dviinfo.c:238
#define fnt_def1
Definition: dviinfo.c:53
int reverse_getc(void)
Definition: dviinfo.c:140
void print_dimen(four_bytes x)
Definition: dviinfo.c:74
#define fnt_def3
Definition: dviinfo.c:55
#define nop
Definition: dviinfo.c:52
#define fnt_def4
Definition: dviinfo.c:56
char * prgname
Definition: dviinfo.c:66
char ** getargv
Definition: dviinfo.c:66
unsigned long four_bytes
Definition: dviinfo.c:58
void process_dvi_file(void)
Definition: dviinfo.c:147
#define error(a)
Definition: dviinfo.c:48
int cur_command
Definition: dviinfo.c:64
#define post_post
Definition: dviinfo.c:50
#define dvi_id
Definition: dviinfo.c:51
double unity
Definition: dviinfo.c:65
#define version
Definition: dviinfo.c:41
char * filename
Definition: dviinfo.c:66
#define fnt_def2
Definition: dviinfo.c:54
#define a(n)
Definition: gpos-common.c:148
#define putc
Definition: jbib.h:20
#define SEEK_SET
Definition: jmemansi.c:26
#define NULL
Definition: ftobjs.h:61
#define SEEK_CUR
Definition: ftzconf.h:250
#define SEEK_END
Definition: ftzconf.h:251
void exit()
int den
Definition: dvi.c:19
int num
Definition: disdvi.c:621
static double page_width
Definition: pdfdev.c:71
static double page_height
Definition: pdfdev.c:71
#define getc
Definition: line.c:39
#define fileno
Definition: win32lib.h:72
#define fputs
Definition: mendex.h:67
#define fprintf
Definition: mendex.h:64
int setmode()
#define _O_BINARY
Definition: lfs.c:127
#define design_size
Definition: mfluac.c:339
float x
Definition: cordic.py:15
char * magnification(int dpi, int BDPI)
static long bytes
Definition: psutil.c:35
Definition: pdfdoc.c:79
Definition: strexpr.c:21
#define FILE
Definition: t1stdio.h:34
val
Definition: tex4ht.c:3227
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
#define font_size(a)
Definition: texfont.h:235
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269