Debian Codegraph @

texk/xdvipsk/dviinput.c

raw
1 /*
2 * Input bytes from the dvi file or the current virtual character.
3 * These routines could probably be sped up significantly; but they are
4 * very machine dependent, so I will leave such tuning to the installer.
5 * They simply get and return bytes in batches of one, two, three, and four,
6 * updating the current position as necessary.
7 */
8 #ifndef XDVIPSK
9 #include "dvips.h" /* The copyright notice in that file is included too! */
10 #else
11 #include "xdvips.h" /* The copyright notice in that file is included too! */
12 #endif /* XDVIPSK */
13 /*
14 * The external declarations:
15 */
16 #include "protos.h"
17
18 static void
19 abortpage(void)
20 {
21 error("! unexpected eof on DVI file");
22 }
23
24 shalfword /* the value returned is, however, between 0 and 255 */
25 dvibyte(void)
26 {
27 register shalfword i;
28 if (curpos) {
29 if (curpos>=curlim) return((shalfword)140);
30 return (*curpos++);
31 }
32 if ((i=getc(dvifile))==EOF)
33 abortpage();
34 return(i);
35 }
36
37 halfword
38 twobytes(void)
39 {
40 register halfword i;
41 i = dvibyte();
42 return(i*256+dvibyte()); }
43
44 integer
45 threebytes(void)
46 {
47 register integer i;
48 i = twobytes();
49 return(i*256+dvibyte()); }
50
51 shalfword
52 signedbyte(void)
53 {
54 register shalfword i;
55 if (curpos) {
56 if (curpos>=curlim)
57 error("! unexpected end of virtual packet");
58 i = *curpos++;
59 } else if ((i=getc(dvifile))==EOF)
60 abortpage();
61 if (i<128) return(i);
62 else return(i-256);
63 }
64
65 shalfword
66 signedpair(void)
67 {
68 register shalfword i;
69 i = signedbyte();
70 return(i*256+dvibyte());
71 }
72
73 integer
74 signedtrio(void)
75 {
76 register integer i;
77 i = signedpair();
78 return(i*256+dvibyte());
79 }
80
81 integer
82 signedquad(void)
83 {
84 register integer i;
85 i = signedpair();
86 return(i*65536+twobytes());
87 }
88
89 void
90 skipover(int i)
91 {
92 while (i-->0) dvibyte();
93 }