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)  

dv2dt.c
Go to the documentation of this file.
1 /* dv2dt - convert DVI file to human-readable "DTL" format.
2 
3  This file is public domain.
4  Originally written 1995, Geoffrey Tobin.
5  The author has expressed the hope that any modification will retain enough content to remain useful. He would also appreciate being acknowledged as the original author in the documentation.
6  This declaration added 2008/11/14 by Clea F. Rees with the permission of Geoffrey Tobin.
7 
8  - (ANSI C) version 0.6.0 - 17:54 GMT +11 Wed 8 March 1995
9  - author: Geoffrey Tobin ecsgrt@luxor.latrobe.edu.au
10  - patch: Michal Tomczak-Jaegermann ntomczak@vm.ucs.ualberta.ca
11  - Reference: "The DVI Driver Standard, Level 0",
12  by The TUG DVI Driver Standards Committee.
13  Appendix A, "Device-Independent File Format".
14 */
15 
16 /* unix version; read from stdin, write to stdout, by default. */
17 
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
30 
31 #ifdef KPATHSEA
32 #include <kpathsea/c-fopen.h>
33 #include <kpathsea/progname.h>
34 #endif
35 
36 #include "dtl.h"
37 
38 #define PRINT_BCOM if (group) fprintf (dtl, "%s", BCOM)
39 #define PRINT_ECOM if (group) fprintf (dtl, "%s", ECOM)
40 
41 /*
42  operation's:
43  opcode,
44  name,
45  number of args,
46  string of arguments.
47 */
48 struct op_info_st {int code; const char * name; int nargs; const char * args; };
49 
50 typedef struct op_info_st op_info;
51 
52 /*
53  table's:
54  name,
55  first opcode,
56  last opcode,
57  pointer to opcode info.
58 */
59 struct op_table_st {const char * name; int first; int last; op_info * list; };
60 
61 typedef struct op_table_st op_table;
62 
63 /* Table for opcodes 128 to 170 inclusive. */
64 
66 {
67  {128, "s1", 1, "1"},
68  {129, "s2", 1, "2"},
69  {130, "s3", 1, "3"},
70  {131, "s4", 1, "-4"},
71  {132, "sr", 2, "-4 -4"},
72  {133, "p1", 1, "1"},
73  {134, "p2", 1, "2"},
74  {135, "p3", 1, "3"},
75  {136, "p4", 1, "-4"},
76  {137, "pr", 2, "-4 -4"},
77  {138, "nop", 0, ""},
78  {139, "bop", 11, "-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4"},
79  {140, "eop", 0, ""},
80  {141, "[", 0, ""},
81  {142, "]", 0, ""},
82  {143, "r1", 1, "-1"},
83  {144, "r2", 1, "-2"},
84  {145, "r3", 1, "-3"},
85  {146, "r4", 1, "-4"},
86  {147, "w0", 0, ""},
87  {148, "w1", 1, "-1"},
88  {149, "w2", 1, "-2"},
89  {150, "w3", 1, "-3"},
90  {151, "w4", 1, "-4"},
91  {152, "x0", 0, ""},
92  {153, "x1", 1, "-1"},
93  {154, "x2", 1, "-2"},
94  {155, "x3", 1, "-3"},
95  {156, "x4", 1, "-4"},
96  {157, "d1", 1, "-1"},
97  {158, "d2", 1, "-2"},
98  {159, "d3", 1, "-3"},
99  {160, "d4", 1, "-4"},
100  {161, "y0", 0, ""},
101  {162, "y1", 1, "-1"},
102  {163, "y2", 1, "-2"},
103  {164, "y3", 1, "-3"},
104  {165, "y4", 1, "-4"},
105  {166, "z0", 0, ""},
106  {167, "z1", 1, "-1"},
107  {168, "z2", 1, "-2"},
108  {169, "z3", 1, "-3"},
109  {170, "z4", 1, "-4"}
110 }; /* op_info op_info_128_170 [] */
111 
112 op_table op_128_170 = {"op_128_170", 128, 170, op_info_128_170};
113 
114 /* Table for font with 1 to 4 bytes (opcodes 235 to 238) inclusive. */
115 
117 {
118  {235, "f1", 1, "1"},
119  {236, "f2", 1, "2"},
120  {237, "f3", 1, "3"},
121  {238, "f4", 1, "-4"}
122 }; /* op_info fnt_n [] */
123 
124 op_table fnt = {"f", 235, 238, fnt_n};
125 
126 
127 /* function prototypes */
128 
129 int open_dvi ARGS((char * dvi_file, FILE ** dvi));
130 int open_dtl ARGS((char * dtl_file, FILE ** dtl));
131 int dv2dt ARGS((FILE * dvi, FILE * dtl));
132 
133 COUNT wunsigned ARGS((int n, FILE * dvi, FILE * dtl));
134 COUNT wsigned ARGS((int n, FILE * dvi, FILE * dtl));
135 S4 rsigned ARGS((int n, FILE * dvi));
136 U4 runsigned ARGS((int n, FILE * dvi));
137 
139 
140 COUNT setseq ARGS((int opcode, FILE * dvi, FILE * dtl));
141 Void setpchar ARGS((int charcode, FILE * dtl));
142 Void xferstring ARGS((int k, FILE * dvi, FILE * dtl));
143 
144 COUNT special ARGS((FILE * dvi, FILE * dtl, int n));
145 COUNT fontdef ARGS((FILE * dvi, FILE * dtl, int n));
146 COUNT preamble ARGS((FILE * dvi, FILE * dtl));
147 COUNT postamble ARGS((FILE * dvi, FILE * dtl));
150 
151 
152 const char * program; /* name of dv2dt program */
153 
154 #define PRINT_PROGNAME fprintf (stderr, "%s ", program)
155 
156 
157 int
159 #ifdef STDC
160  (int argc, char * argv[])
161 #else
162  (argc, argv)
163  int argc;
164  char * argv[];
165 #endif
166 {
167  FILE * dvi = stdin;
168  FILE * dtl = stdout;
169 
170 #ifdef KPATHSEA
171  kpse_set_program_name(argv[0], "dv2dt");
173 #else
174  program = argv[0];
175 #endif
176 
177  if (argc > 1)
178  open_dvi (argv[1], &dvi);
179  else
180  {
181  if (isatty(fileno(dvi)))
182  {
183  give_help();
184  return 0;
185  }
187  }
188 
189  if (argc > 2)
190  open_dtl (argv[2], &dtl);
191 
192  dv2dt (dvi, dtl);
193 
194  return 0; /* OK */
195 }
196 /* end main */
197 
198 int
200 #ifdef STDC
201  (char * dvi_file, FILE ** pdvi)
202 #else
203  (dvi_file, pdvi)
204  char * dvi_file;
205  FILE ** pdvi;
206 #endif
207 /* I: dvi_file; I: pdvi; O: *pdvi. */
208 {
209  if (pdvi == NULL)
210  {
211  fprintf (stderr, "%s: address of dvi variable is NULL.\n", program);
212  exit (1);
213  }
214 
215  *pdvi = fopen (dvi_file, "rb");
216 
217  if (*pdvi == NULL)
218  {
219  fprintf (stderr, "%s: Cannot open \"%s\" for binary reading.\n",
220  program, dvi_file);
221  exit (1);
222  }
223 
224  return 1; /* OK */
225 }
226 /* open_dvi */
227 
228 int
230 #ifdef STDC
231  (char * dtl_file, FILE ** pdtl)
232 #else
233  (dtl_file, pdtl)
234  char * dtl_file;
235  FILE ** pdtl;
236 #endif
237 /* I: dtl_file; I: pdtl; O: *pdtl. */
238 {
239  if (pdtl == NULL)
240  {
241  fprintf (stderr, "%s: address of dtl variable is NULL.\n", program);
242  exit (1);
243  }
244 
245  *pdtl = fopen (dtl_file, "wb");
246 
247  if (*pdtl == NULL)
248  {
249  fprintf (stderr, "%s: Cannot open \"%s\" for writing.\n",
250  program, dtl_file);
251  exit (1);
252  }
253 
254  return 1; /* OK */
255 }
256 /* open_dtl */
257 
258 int
260 #ifdef STDC
261  (FILE * dvi, FILE * dtl)
262 #else
263  (dvi, dtl)
264  FILE * dvi;
265  FILE * dtl;
266 #endif
267 {
268  int opcode;
269  COUNT count; /* intended to count bytes to DVI file; as yet unused. */
270 
271  PRINT_BCOM;
272  fprintf (dtl, "variety ");
273 /* fprintf (dtl, BMES); */
274  fprintf (dtl, VARIETY);
275 /* fprintf (dtl, EMES); */
276  PRINT_ECOM;
277  fprintf (dtl, "\n");
278 
279  /* start counting DVI bytes */
280  count = 0;
281  while ((opcode = fgetc (dvi)) != EOF)
282  {
283  PRINT_BCOM; /* start of command and parameters */
284  if (opcode < 0 || opcode > 255)
285  {
286  count += 1;
287  fprintf (stderr, "%s: Non-byte from \"fgetc()\"!\n", program);
288  exit (1);
289  }
290  else if (opcode <= 127)
291  {
292  /* setchar commands */
293  /* count += 1; */
294  /* fprintf (dtl, "%s%d", SETCHAR, opcode); */
295  count +=
296  setseq (opcode, dvi, dtl);
297  }
298  else if (opcode >= 128 && opcode <= 170)
299  {
300  count +=
301  wtable (op_128_170, opcode, dvi, dtl);
302  }
303  else if (opcode >= 171 && opcode <= 234)
304  {
305  count += 1;
306  fprintf (dtl, "%s%d", FONTNUM, opcode - 171);
307  }
308  else if (opcode >= 235 && opcode <= 238)
309  {
310  count +=
311  wtable (fnt, opcode, dvi, dtl);
312  }
313  else if (opcode >= 239 && opcode <= 242)
314  {
315  count +=
316  special (dvi, dtl, opcode - 238);
317  }
318  else if (opcode >= 243 && opcode <= 246)
319  {
320  count +=
321  fontdef (dvi, dtl, opcode - 242);
322  }
323  else if (opcode == 247)
324  {
325  count +=
326  preamble (dvi, dtl);
327  }
328  else if (opcode == 248)
329  {
330  count +=
331  postamble (dvi, dtl);
332  }
333  else if (opcode == 249)
334  {
335  count +=
336  postpost (dvi, dtl);
337  }
338  else if (opcode >= 250 && opcode <= 255)
339  {
340  count += 1;
341  fprintf (dtl, "opcode%d", opcode);
342  }
343  else
344  {
345  count += 1;
346  fprintf (stderr, "%s: unknown byte.\n", program);
347  exit (1);
348  }
349  PRINT_ECOM; /* end of command and parameters */
350  fprintf (dtl, "\n");
351  if (fflush (dtl) == EOF)
352  {
353  fprintf (stderr, "%s: fflush on dtl file gave write error!\n", program);
354  exit (1);
355  }
356  } /* end while */
357 
358  return 1; /* OK */
359 }
360 /* dv2dt */
361 
362 
363 COUNT
365 #ifdef STDC
366  (int n, FILE * dvi, FILE * dtl)
367 #else
368  (n, dvi, dtl)
369  int n;
370  FILE * dvi;
371  FILE * dtl;
372 #endif
373 {
374  U4 unum;
375 
376  fprintf (dtl, " ");
377  unum = runsigned (n, dvi);
378  fprintf (dtl, UF4, unum);
379  return n;
380 }
381 /* end wunsigned */
382 
383 COUNT
385 #ifdef STDC
386  (int n, FILE * dvi, FILE * dtl)
387 #else
388  (n, dvi, dtl)
389  int n;
390  FILE * dvi;
391  FILE * dtl;
392 #endif
393 {
394  S4 snum;
395 
396  fprintf (dtl, " ");
397  snum = rsigned (n, dvi);
398  fprintf (dtl, SF4, snum);
399  return n;
400 }
401 /* end wsigned */
402 
403 U4
405 #ifdef STDC
406  (int n, FILE * dvi)
407 #else
408  (n, dvi)
409  int n;
410  FILE * dvi;
411 #endif
412 /* read 1 <= n <= 4 bytes for an unsigned integer from dvi file */
413 /* DVI format uses Big-endian storage of numbers. */
414 {
415  U4 integer;
416  int ibyte = 0;
417  int i;
418 
419  if (n < 1 || n > 4)
420  {
421  fprintf (stderr,
422  "%s: runsigned() asked for %d bytes. Must be 1 to 4.\n", program, n);
423  exit (1);
424  }
425 
426  /* Following calculation works iff storage is big-endian. */
427  integer = 0;
428  for (i = 0; i < n; i++)
429  {
430  integer *= 256;
431  ibyte = fgetc (dvi);
432  integer += ibyte;
433  }
434 
435  return integer;
436 }
437 /* end runsigned */
438 
439 S4
441 #ifdef STDC
442  (int n, FILE * dvi)
443 #else
444  (n, dvi)
445  int n;
446  FILE * dvi;
447 #endif
448 /* read 1 <= n <= 4 bytes for a signed integer from dvi file */
449 /* DVI format uses Big-endian storage of numbers. */
450 {
451  S4 integer;
452  int ibyte = 0;
453  int i;
454 
455  if (n < 1 || n > 4)
456  {
457  fprintf (stderr,
458  "%s: rsigned() asked for %d bytes. Must be 1 to 4.\n", program, n);
459  exit (1);
460  }
461 
462  /* Following calculation works iff storage is big-endian. */
463  integer = 0;
464  for (i = 0; i < n; i++)
465  {
466  integer *= 256;
467  ibyte = fgetc (dvi);
468  /* Big-endian implies sign byte is first byte. */
469  if (i == 0 && ibyte >= 128)
470  {
471  ibyte -= 256;
472  }
473  integer += ibyte;
474  }
475 
476  return integer;
477 }
478 /* end rsigned */
479 
480 COUNT
482 #ifdef STDC
483  (op_table table, int opcode, FILE * dvi, FILE * dtl)
484 #else
485  (table, opcode, dvi, dtl)
486  op_table table;
487  int opcode;
488  FILE * dvi;
489  FILE * dtl;
490 #endif
491 /* write command with given opcode in given table */
492 /* return number of DVI bytes in this command */
493 {
494  op_info op; /* pointer into table of operations and arguments */
495  COUNT bcount = 0; /* number of bytes in arguments of this opcode */
496  String args; /* arguments string */
497  int i; /* count of arguments read from args */
498  int pos; /* position in args */
499 
500  /* Defensive programming. */
501  if (opcode < table.first || opcode > table.last)
502  {
503  fprintf (stderr,
504  "%s: opcode %d is outside table %s [ %d to %d ] !\n",
505  program, opcode, table.name, table.first, table.last);
506  exit (1);
507  }
508 
509  op = table.list [opcode - table.first];
510 
511  /* Further defensive programming. */
512  if (op.code != opcode)
513  {
514  fprintf (stderr, "%s: internal table %s wrong!\n", program, table.name);
515  exit (1);
516  }
517 
518  bcount = 1;
519  fprintf (dtl, "%s", op.name);
520 
521  /* NB: sscanf does an ungetc, */
522  /* so args must be writable. */
523 
525 
526  pos = 0;
527  for (i = 0; i < op.nargs; i++)
528  {
529  int argtype; /* sign and number of bytes in current argument */
530  int nconv; /* number of successful conversions from args */
531  int nread; /* number of bytes read from args */
532 
533  nconv = sscanf (args + pos, "%d%n", &argtype, &nread);
534 
535  /* internal consistency checks */
536  if (nconv != 1 || nread <= 0)
537  {
538  fprintf (stderr,
539  "%s: internal read of table %s failed!\n", program, table.name);
540  exit (1);
541  }
542 
543  pos += nread;
544 
545  bcount += ( argtype < 0 ?
546  wsigned (-argtype, dvi, dtl) :
547  wunsigned (argtype, dvi, dtl) ) ;
548  } /* end for */
549 
550  return bcount;
551 
552 }
553 /* wtable */
554 
555 COUNT
557 #ifdef STDC
558  (int opcode, FILE * dvi, FILE * dtl)
559 #else
560  (opcode, dvi, dtl)
561  int opcode;
562  FILE * dvi;
563  FILE * dtl;
564 #endif
565 /* write a sequence of setchar commands */
566 /* return count of DVI bytes interpreted into DTL */
567 {
568  int charcode = opcode; /* fortuitous */
569  int ccount = 0;
570 
571  if (!isprint (charcode))
572  {
573  ccount = 1;
574  fprintf (dtl, "%s%02X", SETCHAR, opcode);
575  }
576  else
577  {
578  /* start of sequence of font characters */
579  fprintf (dtl, BSEQ);
580 
581  /* first character */
582  ccount = 1;
583  setpchar (charcode, dtl);
584 
585  /* subsequent characters */
586  while ((opcode = fgetc (dvi)) != EOF)
587  {
588  if (opcode < 0 || opcode > 127)
589  {
590  break; /* not a setchar command, so sequence has ended */
591  }
592  charcode = opcode; /* fortuitous */
593  if (!isprint (charcode)) /* not printable ascii */
594  {
595  break; /* end of font character sequence, as for other commands */
596  }
597  else /* printable ASCII */
598  {
599  ccount += 1;
600  setpchar (charcode, dtl);
601  }
602  } /* end for loop */
603 
604  /* prepare to reread opcode of next DVI command */
605  if (ungetc (opcode, dvi) == EOF)
606  {
607  fprintf (stderr, "setseq: cannot push back a byte\n");
608  exit (1);
609  }
610 
611  /* end of sequence of font characters */
612  fprintf (dtl, ESEQ);
613  }
614  return ccount;
615 }
616 /* setseq */
617 
618 Void
620 #ifdef STDC
621  (int charcode, FILE * dtl)
622 #else
623  (charcode, dtl)
624  int charcode;
625  FILE * dtl;
626 #endif
627 /* set printable character */
628 {
629  switch (charcode)
630  {
631  case ESC_CHAR:
632  fprintf (dtl, "%c", ESC_CHAR);
633  fprintf (dtl, "%c", ESC_CHAR);
634  break;
635  case QUOTE_CHAR:
636  fprintf (dtl, "%c", ESC_CHAR);
637  fprintf (dtl, "%c", QUOTE_CHAR);
638  break;
639  case BSEQ_CHAR:
640  fprintf (dtl, "%c", ESC_CHAR);
641  fprintf (dtl, "%c", BSEQ_CHAR);
642  break;
643  case ESEQ_CHAR:
644  fprintf (dtl, "%c", ESC_CHAR);
645  fprintf (dtl, "%c", ESEQ_CHAR);
646  break;
647  default:
648  fprintf (dtl, "%c", charcode);
649  break;
650  }
651 }
652 /* setpchar */
653 
654 Void
656 #ifdef STDC
657  (int k, FILE * dvi, FILE * dtl)
658 #else
659  (k, dvi, dtl)
660  int k;
661  FILE * dvi;
662  FILE * dtl;
663 #endif
664 /* copy string of k characters from dvi file to dtl file */
665 {
666  int i;
667  int ch;
668 
669  fprintf (dtl, " ");
670  fprintf (dtl, "'");
671  for (i=0; i < k; i++)
672  {
673  ch = fgetc (dvi);
674  if (ch == ESC_CHAR || ch == EMES_CHAR)
675  {
676  fprintf (dtl, "%c", ESC_CHAR);
677  }
678  fprintf (dtl, "%c", ch);
679  }
680  fprintf (dtl, "'");
681 }
682 /* xferstring */
683 
684 COUNT
686 #ifdef STDC
687  (FILE * dvi, FILE * dtl, int n)
688 #else
689  (dvi, dtl, n)
690  FILE * dvi;
691  FILE * dtl;
692  int n;
693 #endif
694 /* read special 1 .. 4 from dvi and write in dtl */
695 /* return number of DVI bytes interpreted into DTL */
696 {
697  U4 k;
698 
699  if (n < 1 || n > 4)
700  {
701  fprintf (stderr, "%s: special %d, range is 1 to 4.\n", program, n);
702  exit (1);
703  }
704 
705  fprintf (dtl, "%s%d", SPECIAL, n);
706 
707  /* k[n] = length of special string */
708  fprintf (dtl, " ");
709  k = runsigned (n, dvi);
710  fprintf (dtl, UF4, k);
711 
712  /* x[k] = special string */
713  xferstring (k, dvi, dtl);
714 
715  return (1 + n + k);
716 }
717 /* end special */
718 
719 COUNT
721 #ifdef STDC
722  (FILE * dvi, FILE * dtl, int n)
723 #else
724  (dvi, dtl, n)
725  FILE * dvi;
726  FILE * dtl;
727  int n;
728 #endif
729 /* read fontdef 1 .. 4 from dvi and write in dtl */
730 /* return number of DVI bytes interpreted into DTL */
731 {
732  U4 ku, c, s, d, a, l;
733  S4 ks;
734 
735  if (n < 1 || n > 4)
736  {
737  fprintf (stderr, "%s: font def %d, range is 1 to 4.\n", program, n);
738  exit (1);
739  }
740 
741  fprintf (dtl, "%s%d", FONTDEF, n);
742 
743  /* k[n] = font number */
744  fprintf (dtl, " ");
745  if (n == 4)
746  {
747  ks = rsigned (n, dvi);
748  fprintf (dtl, SF4, ks);
749  }
750  else
751  {
752  ku = runsigned (n, dvi);
753  fprintf (dtl, UF4, ku);
754  }
755 
756  /* c[4] = checksum */
757  fprintf (dtl, " ");
758  c = runsigned (4, dvi);
759 #ifdef HEX_CHECKSUM
760  fprintf (dtl, XF4, c);
761 #else /* NOT HEX_CHECKSUM */
762  /* write in octal, to allow quick comparison with tftopl's output */
763  fprintf (dtl, OF4, c);
764 #endif
765 
766  /* s[4] = scale factor */
767  fprintf (dtl, " ");
768  s = runsigned (4, dvi);
769  fprintf (dtl, UF4, s);
770 
771  /* d[4] = design size */
772  fprintf (dtl, " ");
773  d = runsigned (4, dvi);
774  fprintf (dtl, UF4, d);
775 
776  /* a[1] = length of area (directory) name */
777  a = runsigned (1, dvi);
778  fprintf (dtl, " ");
779  fprintf (dtl, UF4, a);
780 
781  /* l[1] = length of font name */
782  l = runsigned (1, dvi);
783  fprintf (dtl, " ");
784  fprintf (dtl, UF4, l);
785 
786  /* n[a+l] = font pathname string => area (directory) + font */
787  xferstring (a, dvi, dtl);
788  xferstring (l, dvi, dtl);
789 
790  return (1 + n + 4 + 4 + 4 + 1 + 1 + a + l);
791 }
792 /* end fontdef */
793 
794 COUNT
796 #ifdef STDC
797  (FILE * dvi, FILE * dtl)
798 #else
799  (dvi, dtl)
800  FILE * dvi;
801  FILE * dtl;
802 #endif
803 /* read preamble from dvi and write in dtl */
804 /* return number of DVI bytes interpreted into DTL */
805 {
806  U4 id, num, den, mag, k;
807 
808  fprintf (dtl, "pre");
809 
810  /* i[1] = DVI format identification */
811  fprintf (dtl, " ");
812  id = runsigned (1, dvi);
813  fprintf (dtl, UF4, id);
814 
815  /* num[4] = numerator of DVI unit */
816  fprintf (dtl, " ");
817  num = runsigned (4, dvi);
818  fprintf (dtl, UF4, num);
819 
820  /* den[4] = denominator of DVI unit */
821  fprintf (dtl, " ");
822  den = runsigned (4, dvi);
823  fprintf (dtl, UF4, den);
824 
825  /* mag[4] = 1000 x magnification */
826  fprintf (dtl, " ");
827  mag = runsigned (4, dvi);
828  fprintf (dtl, UF4, mag);
829 
830  /* k[1] = length of comment */
831  fprintf (dtl, " ");
832  k = runsigned (1, dvi);
833  fprintf (dtl, UF4, k);
834 
835  /* x[k] = comment string */
836  xferstring (k, dvi, dtl);
837 
838  return (1 + 1 + 4 + 4 + 4 + 1 + k);
839 }
840 /* end preamble */
841 
842 COUNT
844 #ifdef STDC
845  (FILE * dvi, FILE * dtl)
846 #else
847  (dvi, dtl)
848  FILE * dvi;
849  FILE * dtl;
850 #endif
851 /* read postamble from dvi and write in dtl */
852 /* return number of bytes */
853 {
854  S4 p;
855  U4 num, den, mag, l, u, s, t;
856 
857  fprintf (dtl, "post");
858 
859  /* p[4] = pointer to final bop */
860  fprintf (dtl, " ");
861  p = rsigned (4, dvi);
862  fprintf (dtl, SF4, p);
863 
864  /* num[4] = numerator of DVI unit */
865  fprintf (dtl, " ");
866  num = runsigned (4, dvi);
867  fprintf (dtl, UF4, num);
868 
869  /* den[4] = denominator of DVI unit */
870  fprintf (dtl, " ");
871  den = runsigned (4, dvi);
872  fprintf (dtl, UF4, den);
873 
874  /* mag[4] = 1000 x magnification */
875  fprintf (dtl, " ");
876  mag = runsigned (4, dvi);
877  fprintf (dtl, UF4, mag);
878 
879  /* l[4] = height + depth of tallest page */
880  fprintf (dtl, " ");
881  l = runsigned (4, dvi);
882  fprintf (dtl, UF4, l);
883 
884  /* u[4] = width of widest page */
885  fprintf (dtl, " ");
886  u = runsigned (4, dvi);
887  fprintf (dtl, UF4, u);
888 
889  /* s[2] = maximum stack depth */
890  fprintf (dtl, " ");
891  s = runsigned (2, dvi);
892  fprintf (dtl, UF4, s);
893 
894  /* t[2] = total number of pages (bop commands) */
895  fprintf (dtl, " ");
896  t = runsigned (2, dvi);
897  fprintf (dtl, UF4, t);
898 
899 /* return (29); */
900  return (1 + 4 + 4 + 4 + 4 + 4 + 4 + 2 + 2);
901 }
902 /* end postamble */
903 
904 COUNT
906 #ifdef STDC
907  (FILE * dvi, FILE * dtl)
908 #else
909  (dvi, dtl)
910  FILE * dvi;
911  FILE * dtl;
912 #endif
913 /* read post_post from dvi and write in dtl */
914 /* return number of bytes */
915 {
916  S4 q;
917  U4 id;
918  int b223; /* hope this is 8-bit clean */
919  int n223; /* number of "223" bytes in final padding */
920 
921  fprintf (dtl, "post_post");
922 
923  /* q[4] = pointer to post command */
924  fprintf (dtl, " ");
925  q = rsigned (4, dvi);
926  fprintf (dtl, SF4, q);
927 
928  /* i[1] = DVI identification byte */
929  fprintf (dtl, " ");
930  id = runsigned (1, dvi);
931  fprintf (dtl, UF4, id);
932 
933  /* final padding by "223" bytes */
934  /* hope this way of obtaining b223 is 8-bit clean */
935  for (n223 = 0; (b223 = fgetc (dvi)) == 223; n223++)
936  {
937  fprintf (dtl, " ");
938  fprintf (dtl, "%d", 223);
939  }
940  if (n223 < 4)
941  {
942  fprintf (stderr,
943  "%s: bad post_post: fewer than four \"223\" bytes.\n", program);
944  exit (1);
945  }
946  if (b223 != EOF)
947  {
948  fprintf (stderr,
949  "%s: bad post_post: doesn't end with a \"223\".\n", program);
950  exit (1);
951  }
952 
953  return (1 + 4 + 1 + n223);
954 }
955 /* end postpost */
956 
957 Void
959 {
960  fprintf (stderr,
961  "Program \"%s\" version %s (%s).\n",
963  fprintf (stderr, "usage: ");
965  fprintf (stderr, " dvi_file dtl_file");
966  fprintf (stderr, "\n");
967  fprintf (stderr, "\nEmail bug reports to %s.\n", PACKAGE_BUGREPORT);
968 }
969 
970 /* end of "dv2dt.c" */
q
Definition: afm2pl.c:2287
struct @88 table[500]
#define count(a)
Definition: aptex-macros.h:781
#define mag
Definition: aptex-macros.h:802
void Void
Definition: cfuncs.h:8
#define n
Definition: t4ht.c:1290
#define QUOTE_CHAR
Definition: dtl.h:114
#define FONTDEF
Definition: dtl.h:175
#define BSEQ_CHAR
Definition: dtl.h:108
#define ESEQ_CHAR
Definition: dtl.h:109
#define FONTNUM
Definition: dtl.h:176
#define EMES_CHAR
Definition: dtl.h:101
#define ESEQ
Definition: dtl.h:106
#define OF4
Definition: dtl.h:61
#define BSEQ
Definition: dtl.h:105
#define VOID
Definition: dtl.h:47
#define SPECIAL
Definition: dtl.h:177
unsigned long U4
Definition: dtl.h:53
#define ESC_CHAR
Definition: dtl.h:113
#define XF4
Definition: dtl.h:59
#define MAXSTRLEN
Definition: dtl.h:74
U4 COUNT
Definition: dtl.h:65
#define VARIETY
Definition: dtl.h:19
long S4
Definition: dtl.h:52
#define SF4
Definition: dtl.h:55
#define UF4
Definition: dtl.h:56
#define PRINT_BCOM
Definition: dv2dt.c:38
COUNT postpost()
COUNT postamble()
Definition: scanst.c:47
int main(int argc, char *argv[])
Definition: dv2dt.c:160
op_info op_info_128_170[]
Definition: dv2dt.c:65
int open_dvi()
int xferstring()
op_table fnt
Definition: dv2dt.c:124
COUNT setseq()
#define PRINT_PROGNAME
Definition: dv2dt.c:154
int open_dtl()
U4 runsigned()
int setpchar()
int give_help()
Definition: dv2dt.c:958
COUNT fontdef()
COUNT wsigned()
S4 rsigned()
COUNT wunsigned()
int dv2dt()
const char * program
Definition: dv2dt.c:152
op_table op_128_170
Definition: dv2dt.c:112
#define PRINT_ECOM
Definition: dv2dt.c:39
op_info fnt_n[]
Definition: dv2dt.c:116
COUNT special()
COUNT wtable()
COUNT preamble()
Definition: scanst.c:46
static int id
Definition: bifont.c:66
#define ku(c)
Definition: decompfont.c:104
#define fopen
Definition: xxstdio.h:21
#define fflush
Definition: xxstdio.h:24
#define fgetc
Definition: xxstdio.h:26
#define SET_BINARY(fd)
Definition: dvips.h:109
char * strncpy()
int sscanf()
FILE * dvi_file
Definition: dviinfo.c:67
struct dvi_data * dvi
#define s
Definition: afcover.h:80
#define t
Definition: afcover.h:96
@ VERSION
Definition: genrb.cpp:69
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
#define d(n)
Definition: gpos-common.c:151
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific f u
Definition: afcover.h:88
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
#define EOF
Definition: afmparse.c:59
#define PACKAGE_BUGREPORT
Definition: config.h:93
#define TL_VERSION
Definition: config.h:131
int den
Definition: dvi.c:19
int num
Definition: disdvi.c:621
int argtype
Definition: cff_dict.c:116
#define kpse_program_name
Definition: types.h:322
#define fileno
Definition: win32lib.h:72
#define isatty
Definition: win32lib.h:80
#define fprintf
Definition: mendex.h:64
char args[100]
Definition: fixwrites.c:7
const int * pos
Definition: combiners.h:905
int k
Definition: otp-parser.c:70
#define ARGS(alist)
Definition: pbmplus.h:235
int integer
Definition: pbmtopk.c:38
@ SETCHAR
Definition: pl-parser.h:85
static int snum[8]
Definition: renumout.c:145
A string of characters.
Definition: t1part.c:49
Definition: usprintf.c:39
int nargs
Definition: dv2dt.c:48
int code
Definition: dv2dt.c:48
const char * args
Definition: dv2dt.c:48
const char * name
Definition: dv2dt.c:48
Definition: dt2dv.c:137
int last
Definition: dv2dt.c:59
op_info * list
Definition: dv2dt.c:59
const char * name
Definition: dv2dt.c:59
int first
Definition: dv2dt.c:59
Definition: sh.h:1226
char ** args
Definition: sh.h:1228
Definition: dvips.h:235
Definition: table.h:30
#define FILE
Definition: t1stdio.h:34
#define ungetc(c, f)
Definition: t1stdio.h:106
ch
Definition: t4ht.c:1443
op
Definition: tex4ht.c:3129
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269