summaryrefslogtreecommitdiff
path: root/dviware/kane/prtpage_p.h
blob: 7273769fe838246b443f54dc2bccd8edd49c14d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

Date:		20-MAR-1989 17:20:43 GMT
From:		PHYOKANE@CS8700.UCG.IE
To:		abbottp@ASTON.AC.UK
Subject:        file prtpage_p.h
sender: 	hea"phyokane@cs8700.ucg.ie"  <phyokane@cs8700.ucg.ie>

/* -*-C-*- prtpage.h */
/*-->prtpage*/
/**********************************************************************/
/****************************** prtpage *******************************/
/**********************************************************************/

void
prtpage(bytepos)		/* print page whose BOP is at bytepos */
long bytepos;

{
    struct stack_entry
    {
	INT32 h;
	COORDINATE hh;
	INT32 v;
	COORDINATE vv;
	INT32 w, x, y, z;	/* what's on stack */
    };
    register BYTE command;  /* current command				*/
    register INT16 i;	    /* command parameter; loop index		*/
    char tc;		    /* temporary character			*/
    UNSIGN32 ht_rule;	    /* rule height                              */
    UNSIGN32 wd_rule;	    /* rule width                               */
    INT32 k,m;		    /* temporary parameter			*/
    INT16 page_number;      /* TeX's \count0 parameter                  */
    BOOLEAN seen_bop;	    /* flag for noting processing of BOP	*/
    register INT16 sp;	    /* stack pointer				*/
    struct stack_entry stack[STACKSIZE];    /* stack			*/
    char specstr[MAXSPECIAL+1];		/* \special{} string		*/
    INT32 w;		    /* current horizontal spacing		*/
    INT32 x;		    /* current horizontal spacing		*/
    INT32 y;		    /* current vertical spacing			*/
    INT32 z;		    /* current vertical spacing			*/

/***********************************************************************
Process all commands  between the  BOP at bytepos  and the  next BOP  or
POST.  The page is  printed when the  EOP is met,  but font changes  can
also happen between EOP and BOP, so we have to keep going after EOP.
***********************************************************************/

/*    (void) checkpage(bytepos); */

    seen_bop = FALSE;			/* this is first time through */
    (void) FSEEK(dvifp,bytepos,0);	/* start at the desired position */

    for (;;)	/* "infinite" loop - exits when POST or second BOP met */
    {
#if    BBNBITGRAPH
	/* If the test here on every byte proves to carry objectionable
	   overhead, it can be moved into the default, PUTx, and SETx
	   command sections. The goal is to give the user instant
	   response in page screen positioning, without having to wait
	   for the entire screen to be painted when it is just going
	   to be moved anyway.  This is the sort of display algorithm
	   that EMACS uses. */
	if (kbinput() > 0)	/* user has typed something */
	    command = EOP;	/* so set for end-of-page action */
	else
#endif
	command = (BYTE)nosignex(dvifp,(BYTE)1);
	switch (command)
	{

	case SET1:
	case SET2:
	case SET3:
	case SET4:
	    (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-SET1+1)),TRUE);
	    break;

	case SET_RULE:
	    ht_rule = nosignex(dvifp,(BYTE)4);
	    wd_rule = nosignex(dvifp,(BYTE)4);
	    (void)setrule(ht_rule,wd_rule,TRUE);
	    break;

	case PUT1:
	case PUT2:
	case PUT3:
	case PUT4:
	    (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-PUT1+1)),FALSE);
	    break;

	case PUT_RULE:
	    ht_rule = nosignex(dvifp,(BYTE)4);
	    wd_rule = nosignex(dvifp,(BYTE)4);
	    (void)setrule(ht_rule,wd_rule,FALSE);
	    break;

	case NOP:
	    break;

	case BOP:
	    if (seen_bop)
		return;			/* we have been here already */
	    seen_bop = TRUE;

	    for (i=0; i<=9; i++)
		tex_counter[i] = (INT32)signex(dvifp,(BYTE)4);

            page_number = (INT16)tex_counter[0];
#if    BBNBITGRAPH
	    (void)bopact();		/* display menu at top of page */
#else /* not BBNBITGRAPH */

#if    (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT)
#else /* NOT (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */
	    (void)clrbmap();
#endif /* (CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */

	    if (!quiet)
	      { (void)fprintf(stderr,"{%s}",tctos()); /* TeX page counters */
		fflush(stderr);
	      }
	    (void) nosignex(dvifp,(BYTE)4);	/* skip prev. page ptr */
#endif /* BBNBITGRAPH */

	    h = v = w = x = y = z = 0;
	    hh = lmargin;
	    vv = tmargin;
	    sp = 0;
	    fontptr = (struct font_entry*)NULL;
	    break;

	case EOP:

#if    (BBNBITGRAPH | CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT)
	    (void)eopact();
#else
	    (void)prtbmap();
#endif /* (BBNBITGRAPH | CANON_A2 | HPJETPLUS | IMPRESS | POSTSCRIPT) */

	    return;

	case PUSH:
	    if (sp >= STACKSIZE)
		(void)fatal("prtpage():  stack overflow");
	    stack[sp].h = h;
	    stack[sp].hh = hh;
	    stack[sp].v = v;
	    stack[sp].vv = vv;
	    stack[sp].w = w;
	    stack[sp].x = x;
	    stack[sp].y = y;
	    stack[sp].z = z;
	    sp++;
	    break;

	case POP:
	    --sp;
	    if (sp < 0)
		(void)fatal("prtpage():  stack underflow");
	    h = stack[sp].h;
	    hh = stack[sp].hh;
	    v = stack[sp].v;
	    vv = stack[sp].vv;
	    w = stack[sp].w;
	    x = stack[sp].x;
	    y = stack[sp].y;
	    z = stack[sp].z;
	    break;

	case RIGHT1:
	case RIGHT2:
	case RIGHT3:
	case RIGHT4:
	    (void)moveover(signex(dvifp,(BYTE)(command-RIGHT1+1)));
	    break;

	case W0:
	    (void)moveover(w);
	    break;

	case W1:
	case W2:
	case W3:
	case W4:
	    w = (INT32)signex(dvifp,(BYTE)(command-W1+1));
	    (void)moveover(w);
	    break;

	case X0:
	    (void)moveover(x);
	    break;

	case X1:
	case X2:
	case X3:
	case X4:
	    x = (INT32)signex(dvifp,(BYTE)(command-X1+1));
	    (void)moveover(x);
	    break;

	case DOWN1:
	case DOWN2:
	case DOWN3:
	case DOWN4:
	    (void)movedown(signex(dvifp,(BYTE)(command-DOWN1+1)));
	    break;

	case Y0:
	    (void)movedown(y);
	    break;

	case Y1:
	case Y2:
	case Y3:
	case Y4:
	    y = signex(dvifp,(BYTE)(command-Y1+1));
	    (void)movedown(y);
	    break;

	case Z0:
	    (void)movedown(z);
	    break;

	case Z1:
	case Z2:
	case Z3:
	case Z4:
	    z = signex(dvifp,(BYTE)(command-Z1+1));
	    (void)movedown(z);
	    break;

	case FNT1:
	case FNT2:
	case FNT3:
	case FNT4:
	    (void)setfntnm((INT32)nosignex(dvifp,
		(BYTE)(command-FNT1+1)));
	    break;

	case XXX1:
	case XXX2:
	case XXX3:
	case XXX4:
	    k = (INT32)nosignex(dvifp,(BYTE)(command-XXX1+1));
	    if (k > MAXSPECIAL)
	    {
		(void)sprintf(message,
		    "prtpage():  \\special{} string of %d characters longer \
than DVI driver limit of %d -- truncated.",
		k,MAXSPECIAL);
		(void)warning(message);
	    }
	    m = 0;
	    while (k--)
	    {
		 tc = (char)nosignex(dvifp,(BYTE)1);
		 if (m < MAXSPECIAL)
		     specstr[m++] = tc;
	    }
	    specstr[m] = '\0';
 	    (void) special(specstr);
	    break;

	case FNT_DEF1:
	case FNT_DEF2:
	case FNT_DEF3:
	case FNT_DEF4:
		(void)skipfont ((INT32) nosignex(dvifp,
		    (BYTE)(command-FNT_DEF1+1)));
	    break;

	case PRE:
	    (void)fatal("prtpage():  PRE occurs within file");
	    break;

	case POST:
	    (void)devterm();		/* terminate device output */
	    (void)dviterm();		/* terminate DVI file processing */
	    (void)alldone();		/* this will never return */
	    break;

	case POST_POST:
	    (void)fatal("prtpage():  POST_POST with no preceding POST");
	    break;

	default:
	    if (command >= FONT_00 && command <= FONT_63)
		(void)setfntnm((INT32)(command - FONT_00));
	    else if (command >= SETC_000 && command <= SETC_127)

#if    (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
		(void)setstr((BYTE)command); /* this sets several chars */
#else
		(void)setchar((BYTE)(command-SETC_000), TRUE);
#endif /* (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2) */

	    else
	    {
		(void)sprintf(message,"prtpage():  %d is an undefined command",
		    command);
		(void)fatal(message);
	    }
	    break;
	}
    }
}