Debian Codegraph @

texk/dvipsk/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 #include "dvips.h" /* The copyright notice in that file is included too! */
9 /*
10 * The external declarations:
11 */
12 #include "protos.h"
13
14 static void
15 abortpage(void)
16 {
17 error("! unexpected eof on DVI file");
18 }
19
20 shalfword /* the value returned is, however, between 0 and 255 */
21 dvibyte(void)
22 {
23 register shalfword i;
24 if (curpos) {
25 if (curpos>=curlim) return((shalfword)140);
26 return (*curpos++);
27 }
28 if ((i=getc(dvifile))==EOF)
29 abortpage();
30 return(i);
31 }
32
33 halfword
34 twobytes(void)
35 {
36 register halfword i;
37 i = dvibyte();
38 return(i*256+dvibyte()); }
39
40 integer
41 threebytes(void)
42 {
43 register integer i;
44 i = twobytes();
45 return(i*256+dvibyte()); }
46
47 shalfword
48 signedbyte(void)
49 {
50 register shalfword i;
51 if (curpos) {
52 if (curpos>=curlim)
53 error("! unexpected end of virtual packet");
54 i = *curpos++;
55 } else if ((i=getc(dvifile))==EOF)
56 abortpage();
57 if (i<128) return(i);
58 else return(i-256);
59 }
60
61 shalfword
62 signedpair(void)
63 {
64 register shalfword i;
65 i = signedbyte();
66 return(i*256+dvibyte());
67 }
68
69 integer
70 signedtrio(void)
71 {
72 register integer i;
73 i = signedpair();
74 return(i*256+dvibyte());
75 }
76
77 integer
78 signedquad(void)
79 {
80 register integer i;
81 i = signedpair();
82 return(i*65536+twobytes());
83 }
84
85 void
86 skipover(int i)
87 {
88 while (i-->0) dvibyte();
89 }