Commit | Line | Data |
---|---|---|
dfc1084e | 1 | /* rvcat.c 4.3 83/04/29 */ |
d87898db RC |
2 | /* |
3 | * Cat Simulator for Versatec and Varian | |
4 | * Modified for Varian with rotated fonts: wnj 5/30/80. | |
5 | * | |
6 | * Takes two extra special codes defined by rvsort: | |
7 | * 0115 - break for new page, goto (0,0) | |
8 | * 0116 - lead 64* following byte | |
9 | */ | |
10 | ||
5af70e5e RC |
11 | #include <stdio.h> |
12 | #include <sys/vcmd.h> | |
13 | #include <vfont.h> | |
d87898db | 14 | |
dfc1084e RC |
15 | int prtmode[] = {VPRINT}; |
16 | int pltmode[] = {VPLOT}; | |
d87898db RC |
17 | |
18 | #define DISPATCHSIZE 256 /* must be a power of two */ | |
19 | #define CHARMASK (DISPATCHSIZE-1) | |
20 | #define NFONTS 25 | |
21 | #define SPECIALFONT 3 | |
22 | #define DSIZ ((sizeof *dispatch)*DISPATCHSIZE) | |
23 | #define MAXF 4 | |
24 | ||
25 | #define LOCAL_RAILMAG ".railmag" | |
26 | #define GLOBAL_RAILMAG "/usr/lib/vfont/railmag" | |
27 | ||
28 | /* | |
29 | * Here we make up for the fact that we only have 2112 | |
30 | * bits vertically when we need 2200 (11''*200/in), by | |
31 | * a 4% vertical size squashing. | |
32 | */ | |
33 | #define CONVERT(n) ((n*(200./432.))*(2112./2200.)) | |
34 | #define RECONVERT(n) ((n*(432./200.))*(2200./2112.)) | |
35 | ||
36 | #define VA_RASTER_LENGTH 2112 | |
37 | ||
38 | #define VA_BYTES_PER_LINE (VA_RASTER_LENGTH/8) | |
39 | ||
40 | #define NLINES 110 | |
41 | #define VA_BUFFER_SIZE (NLINES*VA_BYTES_PER_LINE) | |
42 | ||
43 | #define FF_LINES 1600 /* Scan lines to output before formfeeding. */ | |
44 | #define PAGE_LINES 1700 /* 8.5 inches * 200 lines/inch. */ | |
45 | ||
46 | #define min(a,b) (a<b ? a : b) | |
47 | ||
48 | char buffer[VA_BUFFER_SIZE]; /* Big line buffers */ | |
49 | char *buf0p = &buffer[0]; /* Zero origin in circular buffer */ | |
50 | ||
51 | char *calloc(); | |
52 | char *nalloc(); | |
53 | char *allpanic(); | |
54 | ||
55 | struct header header; | |
56 | struct dispatch *dispatch; | |
57 | ||
58 | struct fontdes { | |
59 | int fnum; | |
60 | int psize; | |
61 | struct dispatch *disp; | |
62 | char *bits; | |
63 | } fontdes[NFONTS] = { | |
64 | -1, | |
65 | -1 | |
66 | }; | |
67 | ||
68 | struct point_sizes { | |
69 | int stupid_code; | |
70 | int real_code; | |
71 | } point_sizes[] = { | |
72 | 010, 6, | |
73 | 0, 7, | |
74 | 01, 8, | |
75 | 07, 9, | |
76 | 02, 10, | |
77 | 03, 11, | |
78 | 04, 12, | |
79 | 05, 14, | |
80 | 0211, 16, | |
81 | 06, 18, | |
82 | 0212, 20, | |
83 | 0213, 22, | |
84 | 0214, 24, | |
85 | 0215, 28, | |
86 | 0216, 36, | |
87 | 0, 0 | |
88 | }; | |
89 | ||
90 | #define VA_FFLINES 2200 | |
91 | #define VP_FFLINES 650 | |
92 | #define VP_EOTLINES 1400 | |
93 | ||
94 | int lines; | |
95 | ||
96 | int vc = 1; /* varian/versatec output file descriptor */ | |
97 | int varian; /* 0 for versatec, 1 for varian. */ | |
98 | int BYTES_PER_LINE; /* VA_BYTES_PER_LINE or VP_BYTES_PER_LINE. */ | |
99 | int BUFFER_SIZE; /* VA_BUFFER_SIZE or VP_BUFFER_SIZE. */ | |
100 | int cfnum = -1; | |
101 | int cpsize = 10; | |
102 | int cfont = 1; | |
103 | char *bits; | |
104 | int nfontnum = -1; | |
105 | int fontwanted = 1; | |
106 | int npsize = 10; | |
107 | int last_ssize = 02; | |
108 | int xpos, ypos; | |
109 | int esc, lead, back, verd, mcase, railmag; | |
110 | double row, col; | |
111 | char *fontname[MAXF]; | |
112 | char fnbuf[120]; | |
113 | char *scanline; | |
114 | int linecount; | |
115 | ||
116 | char asctab[128] = { | |
117 | '\0', /*blank*/ | |
118 | 'h', /*h*/ | |
119 | 't', /*t*/ | |
120 | 'n', /*n*/ | |
121 | 'm', /*m*/ | |
122 | 'l', /*l*/ | |
123 | 'i', /*i*/ | |
124 | 'z', /*z*/ | |
125 | 's', /*s*/ | |
126 | 'd', /*d*/ | |
127 | 'b', /*b*/ | |
128 | 'x', /*x*/ | |
129 | 'f', /*f*/ | |
130 | 'j', /*j*/ | |
131 | 'u', /*u*/ | |
132 | 'k', /*k*/ | |
133 | '\0', /*blank*/ | |
134 | 'p', /*p*/ | |
135 | '\06', /*_ 3/4 em dash*/ | |
136 | ';', /*;*/ | |
137 | '\0', /*blank*/ | |
138 | 'a', /*a*/ | |
139 | '\05', /*rule*/ | |
140 | 'c', /*c*/ | |
141 | '`', /*` open*/ | |
142 | 'e', /*e*/ | |
143 | '\'', /*' close*/ | |
144 | 'o', /*o*/ | |
145 | '\021', /*1/4*/ | |
146 | 'r', /*r*/ | |
147 | '\022', /*1/2*/ | |
148 | 'v', /*v*/ | |
149 | '-', /*- hyphen*/ | |
150 | 'w', /*w*/ | |
151 | 'q', /*q*/ | |
152 | '/', /*/*/ | |
153 | '.', /*.*/ | |
154 | 'g', /*g*/ | |
155 | '\023', /*3/4*/ | |
156 | ',', /*,*/ | |
157 | '&', /*&*/ | |
158 | 'y', /*y*/ | |
159 | '\0', /*blank*/ | |
160 | '%', /*%*/ | |
161 | '\0', /*blank*/ | |
162 | 'Q', /*Q*/ | |
163 | 'T', /*T*/ | |
164 | 'O', /*O*/ | |
165 | 'H', /*H*/ | |
166 | 'N', /*N*/ | |
167 | 'M', /*M*/ | |
168 | 'L', /*L*/ | |
169 | 'R', /*R*/ | |
170 | 'G', /*G*/ | |
171 | 'I', /*I*/ | |
172 | 'P', /*P*/ | |
173 | 'C', /*C*/ | |
174 | 'V', /*V*/ | |
175 | 'E', /*E*/ | |
176 | 'Z', /*Z*/ | |
177 | 'D', /*D*/ | |
178 | 'B', /*B*/ | |
179 | 'S', /*S*/ | |
180 | 'Y', /*Y*/ | |
181 | '\0', /*blank*/ | |
182 | 'F', /*F*/ | |
183 | 'X', /*X*/ | |
184 | 'A', /*A*/ | |
185 | 'W', /*W*/ | |
186 | 'J', /*J*/ | |
187 | 'U', /*U*/ | |
188 | 'K', /*K*/ | |
189 | '0', /*0*/ | |
190 | '1', /*1*/ | |
191 | '2', /*2*/ | |
192 | '3', /*3*/ | |
193 | '4', /*4*/ | |
194 | '5', /*5*/ | |
195 | '6', /*6*/ | |
196 | '7', /*7*/ | |
197 | '8', /*8*/ | |
198 | '9', /*9*/ | |
199 | '*', /***/ | |
200 | '\04', /*minus*/ | |
201 | '\01', /*fi*/ | |
202 | '\02', /*fl*/ | |
203 | '\03', /*ff*/ | |
204 | '\020', /* cent sign */ | |
205 | '\012', /*ffl*/ | |
206 | '\011', /*ffi*/ | |
207 | '(', /*(*/ | |
208 | ')', /*)*/ | |
209 | '[', /*[*/ | |
210 | ']', /*]*/ | |
211 | '\013', /* degree */ | |
212 | '\014', /* dagger */ | |
213 | '=', /*=*/ | |
214 | '\017', /* registered */ | |
215 | ':', /*:*/ | |
216 | '+', /*+*/ | |
217 | '\0', /*blank*/ | |
218 | '!', /*!*/ | |
219 | '\07', /* bullet */ | |
220 | '?', /*?*/ | |
221 | '\015', /*foot mark*/ | |
222 | '|', /*|*/ | |
223 | '\0', /*blank*/ | |
224 | '\016', /* copyright */ | |
225 | '\010', /* square */ | |
226 | '$', /*$*/ | |
227 | '\0', | |
228 | '\0', | |
229 | '"', /*"*/ | |
230 | '#', /*#*/ | |
231 | '<', /*<*/ | |
232 | '>', /*>*/ | |
233 | '@', /*@*/ | |
234 | '\\', /*\\*/ | |
235 | '^', /*^*/ | |
236 | '{', /*{*/ | |
237 | '}', /*}*/ | |
238 | '~' /*~*/ | |
239 | }; | |
240 | ||
241 | char spectab[128] = { | |
242 | '\0', /*blank*/ | |
243 | 'w', /*psi*/ | |
244 | 'h', /*theta*/ | |
245 | 'm', /*nu*/ | |
246 | 'l', /*mu*/ | |
247 | 'k', /*lambda*/ | |
248 | 'i', /*iota*/ | |
249 | 'f', /*zeta*/ | |
250 | 'r', /*sigma*/ | |
251 | 'd', /*delta*/ | |
252 | 'b', /*beta*/ | |
253 | 'n', /*xi*/ | |
254 | 'g', /*eta*/ | |
255 | 'u', /*phi*/ | |
256 | 't', /*upsilon*/ | |
257 | 'j', /*kappa*/ | |
258 | '\0', /*blank*/ | |
259 | 'p', /*pi*/ | |
260 | '@', /*at-sign*/ | |
261 | '7', /*down arrow*/ | |
262 | '\0', /*blank*/ | |
263 | 'a', /*alpha*/ | |
264 | '|', /*or*/ | |
265 | 'v', /*chi*/ | |
266 | '"', /*"*/ | |
267 | 'e', /*epsilon*/ | |
268 | '=', /*=*/ | |
269 | 'o', /*omicron*/ | |
270 | '4', /*left arrow*/ | |
271 | 'q', /*rho*/ | |
272 | '6', /*up arrow*/ | |
273 | 's', /*tau*/ | |
274 | '_', /*underrule*/ | |
275 | '\\', /*\*/ | |
276 | 'W', /*Psi*/ | |
277 | '\07', /*bell system sign*/ | |
278 | '\001', /*infinity*/ | |
279 | 'c', /*gamma*/ | |
280 | '\002', /*improper superset*/ | |
281 | '\003', /*proportional to*/ | |
282 | '\004', /*right hand*/ | |
283 | 'x', /*omega*/ | |
284 | '\0', /*blank*/ | |
285 | '(', /*gradient*/ | |
286 | '\0', /*blank*/ | |
287 | 'U', /*Phi*/ | |
288 | 'H', /*Theta*/ | |
289 | 'X', /*Omega*/ | |
290 | '\005', /*cup (union)*/ | |
291 | '\006', /*root en*/ | |
292 | '\014', /*terminal sigma*/ | |
293 | 'K', /*Lambda*/ | |
294 | '-', /*minus*/ | |
295 | 'C', /*Gamma*/ | |
296 | '\015', /*integral sign*/ | |
297 | 'P', /*Pi*/ | |
298 | '\032', /*subset of*/ | |
299 | '\033', /*superset of*/ | |
300 | '2', /*approximates*/ | |
301 | 'y', /*partial derivative*/ | |
302 | 'D', /*Delta*/ | |
303 | '\013', /*square root*/ | |
304 | 'R', /*Sigma*/ | |
305 | '1', /*approx =*/ | |
306 | '\0', /*blank*/ | |
307 | '>', /*>*/ | |
308 | 'N', /*Xi*/ | |
309 | '<', /*<*/ | |
310 | '\016', /*slash (longer)*/ | |
311 | '\034', /*cap (intersection)*/ | |
312 | 'T', /*Upsilon*/ | |
313 | '\035', /*not*/ | |
314 | '\023', /*right ceiling (rt of ")*/ | |
315 | '\024', /*left top (of big curly)*/ | |
316 | '\017', /*bold vertical*/ | |
317 | '\030', /*left center of big curly bracket*/ | |
318 | '\025', /*left bottom*/ | |
319 | '\026', /*right top*/ | |
320 | '\031', /*right center of big curly bracket*/ | |
321 | '\027', /*right bot*/ | |
322 | '\021', /*right floor (rb of ")*/ | |
323 | '\020', /*left floor (left bot of big sq bract)*/ | |
324 | '\022', /*left ceiling (lt of ")*/ | |
325 | '*', /*multiply*/ | |
326 | '/', /*divide*/ | |
327 | '\010', /*plus-minus*/ | |
328 | '\011', /*<=*/ | |
329 | '\012', /*>=*/ | |
330 | '0', /*identically equal*/ | |
331 | '3', /*not equal*/ | |
332 | '{', /*{*/ | |
333 | '}', /*}*/ | |
334 | '\'', /*' acute accent*/ | |
335 | '\`', /*` grave accent*/ | |
336 | '^', /*^*/ | |
337 | '#', /*sharp*/ | |
338 | '\036', /*left hand*/ | |
339 | '\037', /*member of*/ | |
340 | '~', /*~*/ | |
341 | 'z', /*empty set*/ | |
342 | '\0', /*blank*/ | |
343 | 'Y', /*dbl dagger*/ | |
344 | 'Z', /*box rule*/ | |
345 | '9', /*asterisk*/ | |
346 | '[', /*improper subset*/ | |
347 | ']', /*circle*/ | |
348 | '\0', /*blank*/ | |
349 | '+', /*eqn plus*/ | |
350 | '5', /*right arrow*/ | |
351 | '8' /*section mark*/ | |
352 | }; | |
353 | ||
d87898db RC |
354 | main(argc, argv) |
355 | int argc; | |
356 | char *argv[]; | |
357 | { | |
5af70e5e RC |
358 | char *namearg = NULL; |
359 | char *hostarg = NULL; | |
360 | char *acctfile = NULL; | |
361 | ||
d87898db | 362 | varian = 1; /* Default is the varian */ |
d87898db RC |
363 | BYTES_PER_LINE = VA_BYTES_PER_LINE; |
364 | BUFFER_SIZE = VA_BUFFER_SIZE; | |
365 | ||
366 | if (argv[0][strlen(argv[0])-1] == 'W') { /* Wide: the versatec. */ | |
367 | /* | |
368 | varian = 0; | |
369 | BYTES_PER_LINE = VP_BYTES_PER_LINE; | |
370 | BUFFER_SIZE = VP_BUFFER_SIZE; | |
371 | */ | |
372 | fprintf(stderr, "rvcat: W not implemented\n"); | |
373 | } | |
374 | ||
375 | while (--argc) { | |
376 | if (*(*++argv) == '-') | |
377 | switch (argv[0][1]) { | |
378 | ||
379 | case 'n': | |
380 | if (argc > 1) { | |
381 | argc--; | |
382 | namearg = *++argv; | |
383 | } | |
384 | break; | |
385 | ||
386 | case 'h': | |
387 | if (argc > 1) { | |
388 | argc--; | |
389 | hostarg = *++argv; | |
390 | } | |
391 | break; | |
392 | ||
393 | default: | |
394 | fprintf(stderr, "usage: rvcat[W] [-n name] [-h host] [accounting file]\n"); | |
395 | exit(2); | |
396 | } | |
397 | else | |
398 | acctfile = *argv; | |
399 | } | |
400 | ioctl(vc, VSETSTATE, pltmode); | |
401 | readrm(); | |
402 | ofile(); | |
403 | ioctl(vc, VSETSTATE, prtmode); | |
404 | if (varian) | |
405 | write(vc, "\f", 2); | |
406 | else | |
407 | write(vc, "\n\n\n\n\n", 6); | |
408 | account(namearg, hostarg, acctfile); | |
409 | exit(0); | |
410 | } | |
411 | ||
412 | readrm() | |
413 | { | |
414 | register int i; | |
415 | register char *cp; | |
416 | register int rmfd; | |
417 | char c; | |
418 | ||
419 | if ((rmfd = open(LOCAL_RAILMAG, 0)) < 0) | |
420 | if ((rmfd = open(GLOBAL_RAILMAG, 0)) < 0) { | |
421 | fprintf(stderr, "rvcat: No railmag file\n"); | |
422 | exit(2); | |
423 | } | |
424 | cp = fnbuf; | |
5af70e5e | 425 | for (i = 0; i < MAXF; i++) { |
d87898db RC |
426 | fontname[i] = cp; |
427 | while (read(rmfd, &c, 1) == 1 && c != '\n') | |
428 | *cp++ = c; | |
429 | *cp++ = '\0'; | |
430 | } | |
431 | close(rmfd); | |
432 | } | |
433 | ||
434 | ofile() | |
435 | { | |
436 | register int c; | |
437 | register int i; | |
438 | double scol; | |
439 | static int initialized; | |
440 | ||
441 | lines = 0; | |
442 | while ((c = getchar()) != EOF) { | |
443 | if (!c) | |
444 | continue; | |
445 | if (c & 0200) { | |
446 | esc += (~c) & 0177; | |
447 | continue; | |
448 | } | |
449 | if (esc) { | |
450 | if (back) | |
451 | esc = -esc; | |
452 | col += esc; | |
453 | esc = 0; | |
454 | i = CONVERT(col); | |
455 | while (i >= NLINES) { | |
456 | slop_lines(15); | |
457 | i = CONVERT(col); | |
458 | } | |
459 | ypos = i; | |
460 | } | |
461 | if ((c & 0377) < 0100) /* Purely for efficiency */ | |
462 | goto normal_char; | |
463 | switch (c) { | |
464 | ||
465 | case 0100: | |
466 | esc = 0; | |
467 | lead = 0; | |
468 | linecount = 0; | |
469 | verd = 0; | |
470 | back = 0; | |
471 | mcase = 0; | |
472 | railmag = 0; | |
473 | if (loadfont(railmag, cpsize) < 0) | |
474 | fprintf(stderr, "rvcat: Can't load initial font\n"); | |
475 | if (initialized) | |
476 | goto reset; | |
477 | initialized = 1; | |
478 | row = 0; | |
479 | xpos = CONVERT(row); | |
480 | for (c = 0; c < BUFFER_SIZE; c++) | |
481 | buffer[c] = 0; | |
482 | col = 0; | |
483 | ypos = 0; | |
484 | break; | |
485 | ||
486 | case 0101: /* lower rail */ | |
487 | crail(railmag &= ~01); | |
488 | break; | |
489 | ||
490 | case 0102: /* upper rail */ | |
491 | crail(railmag |= 01); | |
492 | break; | |
493 | ||
494 | case 0103: /* upper mag */ | |
495 | crail(railmag |= 02); | |
496 | break; | |
497 | ||
498 | case 0104: /* lower mag */ | |
499 | crail(railmag &= ~02); | |
500 | break; | |
501 | ||
502 | case 0105: /* lower case */ | |
503 | mcase = 0; | |
504 | break; | |
505 | ||
506 | case 0106: /* upper case */ | |
507 | mcase = 0100; | |
508 | break; | |
509 | ||
510 | case 0107: /* escape forward */ | |
511 | back = 0; | |
512 | break; | |
513 | ||
514 | case 0110: /* escape backwards */ | |
515 | back = 1; | |
516 | break; | |
517 | ||
518 | case 0111: /* stop */ | |
519 | break; | |
520 | ||
521 | case 0112: /* lead forward */ | |
522 | verd = 0; | |
523 | break; | |
524 | ||
525 | case 0113: /* undefined */ | |
526 | break; | |
527 | ||
528 | case 0114: /* lead backward */ | |
529 | verd = 1; | |
530 | break; | |
531 | ||
532 | case 0115: /* undefined */ | |
533 | reset: | |
534 | c = lines % PAGE_LINES; | |
535 | while (c < FF_LINES) { | |
536 | slop_lines(min(FF_LINES - c, NLINES)); | |
537 | c = lines % PAGE_LINES; | |
538 | } | |
539 | new_page(PAGE_LINES - c); | |
540 | break; | |
541 | ||
542 | case 0116: | |
543 | lead = (getchar() & 0377) * 64; | |
544 | goto leadin; | |
545 | ||
546 | case 0117: | |
547 | break; | |
548 | ||
549 | default: | |
550 | if ((c & 0340) == 0140) /* leading */ { | |
551 | lead = (~c) & 037; | |
552 | leadin: | |
553 | if (verd) | |
554 | lead = -lead; | |
555 | row += lead*3; /* Lead is 3 units */ | |
556 | xpos = CONVERT(row); | |
557 | continue; | |
558 | } | |
559 | if ((c & 0360) == 0120) /* size change */ { | |
560 | loadfont(railmag, findsize(c & 017)); | |
561 | continue; | |
562 | } | |
563 | if (c & 0300) | |
564 | continue; | |
565 | ||
566 | normal_char: | |
567 | if (row < 0 || CONVERT(row) >= VA_RASTER_LENGTH) | |
568 | continue; | |
569 | c = (c & 077) | mcase; | |
570 | outc(c); | |
571 | } | |
572 | } | |
573 | out: | |
574 | slop_lines(NLINES); | |
575 | } | |
576 | ||
577 | findsize(code) | |
578 | register int code; | |
579 | { | |
580 | register struct point_sizes *psp; | |
581 | ||
582 | psp = point_sizes; | |
583 | while (psp->real_code != 0) { | |
584 | if ((psp->stupid_code & 017) == code) | |
585 | break; | |
586 | psp++; | |
587 | } | |
588 | code = 0; | |
589 | if (!(last_ssize & 0200) && (psp->stupid_code & 0200)) | |
590 | code = -55; | |
591 | else if ((last_ssize & 0200) && !(psp->stupid_code & 0200)) | |
592 | code = 55; | |
593 | if (back) | |
594 | code = -code; | |
595 | esc += code; | |
596 | last_ssize = psp->stupid_code; | |
dfc1084e | 597 | return(psp->real_code); |
d87898db RC |
598 | } |
599 | ||
600 | account(who, from, acctfile) | |
601 | char *who, *from, *acctfile; | |
602 | { | |
603 | register FILE *a; | |
604 | ||
605 | if (who == NULL || acctfile == NULL) | |
606 | return; | |
607 | if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL) | |
608 | return; | |
609 | /* | |
dfc1084e | 610 | * Varian accounting is done by 8.5 inch pages; |
d87898db RC |
611 | * Versatec accounting is by the (12 inch) foot. |
612 | */ | |
dfc1084e | 613 | fprintf(a, "t%6.2f\t", (lines / 200.0) / (varian ? 8.5 : 12.0)); |
d87898db RC |
614 | if (from != NULL) |
615 | fprintf(a, "%s:", from); | |
616 | fprintf(a, "%s\n", who); | |
617 | fclose(a); | |
618 | } | |
619 | ||
620 | crail(nrail) | |
621 | register int nrail; | |
622 | { | |
623 | register int psize; | |
624 | ||
625 | psize = cpsize; | |
626 | if (fontwanted && psize != npsize) | |
627 | psize = npsize; | |
628 | loadfont(nrail, psize); | |
629 | } | |
630 | ||
631 | ||
632 | loadfont(fnum, size) | |
633 | register int fnum; | |
634 | register int size; | |
635 | { | |
636 | register int i; | |
637 | char cbuf[80]; | |
638 | ||
639 | fontwanted = 0; | |
640 | if (fnum == cfnum && size == cpsize) | |
641 | return(0); | |
642 | for (i = 0; i < NFONTS; i++) | |
643 | if (fontdes[i].fnum == fnum && fontdes[i].psize == size) { | |
644 | cfnum = fontdes[i].fnum; | |
645 | cpsize = fontdes[i].psize; | |
646 | dispatch = &fontdes[i].disp[0]; | |
647 | bits = fontdes[i].bits; | |
648 | cfont = i; | |
dfc1084e | 649 | return(0); |
d87898db RC |
650 | } |
651 | if (fnum < 0 || fnum >= MAXF) { | |
652 | fprintf(stderr, "rvcat: Internal error: illegal font\n"); | |
653 | return(-1); | |
654 | } | |
655 | nfontnum = fnum; | |
656 | npsize = size; | |
657 | fontwanted++; | |
dfc1084e | 658 | return(0); |
d87898db RC |
659 | } |
660 | ||
661 | ||
662 | getfont() | |
663 | { | |
664 | register int fnum, size, font; | |
665 | int d; | |
666 | char cbuf[BUFSIZ]; | |
667 | char *cp = cbuf; | |
668 | char *dp; | |
669 | ||
670 | if (!fontwanted) | |
671 | return(0); | |
672 | fnum = nfontnum; | |
673 | size = npsize; | |
674 | sprintf(cbuf, "%s.%dr", fontname[fnum], size); | |
675 | font = open(cbuf, 0); | |
676 | if (font == -1) { | |
5af70e5e | 677 | fprintf(stderr, "rvcat: "); |
d87898db RC |
678 | perror(cbuf); |
679 | fontwanted = 0; | |
dfc1084e | 680 | return(-1); |
d87898db RC |
681 | } |
682 | if (read(font, &header, sizeof header)!=sizeof header || header.magic!=0436) | |
683 | fprintf(stderr, "rvcat: %s: Bad font file", cbuf); | |
684 | else { | |
685 | cfont = relfont(); | |
686 | if (((bits=nalloc(header.size+DSIZ+1,1))== NULL) | |
687 | && ((bits=allpanic(header.size+DSIZ+1))== NULL)) { | |
688 | fprintf(stderr, "rvcat: %s: ran out of memory\n", cbuf); | |
689 | exit(2); | |
690 | } else { | |
691 | /* | |
692 | * have allocated one chunk of mem for font, dispatch. | |
693 | * get the dispatch addr, align to word boundary. | |
694 | */ | |
695 | d = (int) bits+header.size; | |
696 | d += 1; | |
697 | d &= ~1; | |
698 | if (read(font, d, DSIZ)!=DSIZ | |
699 | || read(font, bits, header.size)!=header.size) | |
700 | fprintf(stderr, "rvcat: bad font header"); | |
701 | else { | |
702 | close(font); | |
703 | cfnum = fontdes[cfont].fnum = fnum; | |
704 | cpsize = fontdes[cfont].psize = size; | |
705 | fontdes[cfont].bits = bits; | |
706 | fontdes[cfont].disp = (struct dispatch *) d; | |
707 | dispatch = &fontdes[cfont].disp[0]; | |
708 | fontwanted = 0; | |
dfc1084e | 709 | return(0); |
d87898db RC |
710 | } |
711 | } | |
712 | } | |
713 | close(font); | |
714 | fontwanted = 0; | |
715 | return(-1); | |
716 | } | |
717 | ||
dfc1084e | 718 | int lastloaded = -1; |
d87898db RC |
719 | |
720 | relfont() | |
721 | { | |
722 | register int newfont; | |
723 | ||
724 | newfont = lastloaded; | |
725 | /* | |
726 | * optimization for special font. since we think that usually | |
727 | * there is only one character at a time from any special math | |
728 | * font, make it the candidate for removal. | |
729 | */ | |
730 | if (fontdes[cfont].fnum != SPECIALFONT || fontdes[cfont].bits==0) | |
731 | if (++newfont>=NFONTS) | |
732 | newfont = 0; | |
733 | lastloaded = newfont; | |
734 | if ((int)fontdes[newfont].bits != -1 && fontdes[newfont].bits != 0) | |
735 | nfree(fontdes[newfont].bits); | |
736 | fontdes[newfont].bits = 0; | |
dfc1084e | 737 | return(newfont); |
d87898db RC |
738 | } |
739 | ||
740 | char * | |
741 | allpanic(nbytes) | |
742 | int nbytes; | |
743 | { | |
744 | register int i; | |
745 | ||
746 | for (i = 0; i <= NFONTS; i++) | |
747 | if (fontdes[i].bits != (char *)-1 && fontdes[i].bits != (char *)0) | |
748 | nfree(fontdes[i].bits); | |
749 | lastloaded = cfont; | |
750 | for (i = 0; i <= NFONTS; i++) { | |
751 | fontdes[i].fnum = fontdes[i].psize = -1; | |
752 | fontdes[i].bits = 0; | |
753 | cfnum = cpsize = -1; | |
754 | } | |
755 | return(nalloc(nbytes,1)); | |
756 | } | |
757 | ||
758 | int M[] = { 0xffffffff, 0xfefefefe, 0xfcfcfcfc, 0xf8f8f8f8, | |
759 | 0xf0f0f0f0, 0xe0e0e0e0, 0xc0c0c0c0, 0x80808080, 0x0 }; | |
760 | int N[] = { 0x00000000, 0x01010101, 0x03030303, 0x07070707, | |
761 | 0x0f0f0f0f, 0x1f1f1f1f, 0x3f3f3f3f, 0x7f7f7f7f, 0xffffffff }; | |
762 | int strim[] = { 0xffffffff, 0xffffff00, 0xffff0000, 0xff000000, 0 }; | |
763 | ||
764 | outc(code) | |
765 | int code; | |
766 | { | |
767 | char c; /* character to print */ | |
768 | register struct dispatch *d; /* ptr to character font record */ | |
769 | register char *addr; /* addr of font data */ | |
770 | int llen; /* length of each font line */ | |
771 | int nlines; /* number of font lines */ | |
772 | register char *scanp; /* ptr to output buffer */ | |
773 | int scanp_inc; /* increment to start of next buffer */ | |
774 | int offset; /* bit offset to start of font data */ | |
775 | int i; /* loop counter */ | |
776 | register int count; /* font data ptr */ | |
777 | register unsigned fontdata; /* font data temporary */ | |
778 | register int off8; /* offset + 8 */ | |
779 | int b0poff; /* bit offset back towards buf0p */ | |
780 | ||
781 | if (fontwanted) | |
782 | getfont(); | |
783 | if (railmag == SPECIALFONT) { | |
784 | if ((c = spectab[code]) < 0) | |
785 | return(0); | |
786 | } else if ((c = asctab[code]) < 0) | |
787 | return(0); | |
788 | d = dispatch+c; | |
789 | if (d->nbytes) { | |
790 | addr = bits+d->addr; | |
791 | llen = (d->down+d->up+7)/8; | |
792 | nlines = d->left+d->right; | |
793 | if (ypos+d->right >= NLINES) | |
794 | slop_lines(ypos+d->right-NLINES+6); | |
795 | b0poff = BYTES_PER_LINE*8 - 1 - (xpos+d->down); | |
796 | scanp = ((ypos-d->left-1)*BYTES_PER_LINE+b0poff/8)+buf0p; | |
797 | if (scanp < &buffer[0]) | |
798 | scanp += BUFFER_SIZE; | |
799 | scanp_inc = BYTES_PER_LINE-llen; | |
800 | offset = -(b0poff&07); | |
801 | off8 = offset+8; | |
802 | for (i = 0; i < nlines; i++) { | |
803 | if (scanp >= &buffer[BUFFER_SIZE]) | |
804 | scanp -= BUFFER_SIZE; | |
805 | count = llen; | |
806 | if (scanp + count <= &buffer[BUFFER_SIZE]) | |
807 | do { | |
808 | fontdata = *(unsigned *)addr; | |
809 | addr += 4; | |
810 | if (count < 4) | |
811 | fontdata &= ~strim[count]; | |
812 | *(unsigned *)scanp |= (fontdata << offset) &~ M[off8]; | |
813 | scanp++; | |
814 | *(unsigned *)scanp |= (fontdata << off8) &~ N[off8]; | |
815 | scanp += 3; | |
816 | count -= 4; | |
817 | } while (count > 0); | |
818 | scanp += scanp_inc+count; | |
819 | addr += count; | |
820 | } | |
dfc1084e | 821 | return(1); |
d87898db | 822 | } |
dfc1084e | 823 | return(0); |
d87898db RC |
824 | } |
825 | ||
826 | slop_lines(ncols) | |
827 | int ncols; | |
828 | { | |
829 | register int i, rcols; | |
830 | ||
831 | lines += ncols; | |
832 | rcols = (&buffer[BUFFER_SIZE] - buf0p) / BYTES_PER_LINE; | |
833 | if (rcols < ncols) { | |
834 | if (write(vc, buf0p, BYTES_PER_LINE * rcols) < 0) | |
835 | exit(1); | |
836 | clear(buf0p, rcols * BYTES_PER_LINE); | |
837 | buf0p = buffer; | |
838 | ncols -= rcols; | |
839 | ypos -= rcols; | |
840 | col -= RECONVERT(rcols); | |
841 | } | |
842 | if (write(vc, buf0p, BYTES_PER_LINE * ncols) < 0) | |
843 | exit(1); | |
844 | clear(buf0p, BYTES_PER_LINE * ncols); | |
845 | buf0p += BYTES_PER_LINE * ncols; | |
846 | if (buf0p >= &buffer[BUFFER_SIZE]) | |
847 | buf0p -= BUFFER_SIZE; | |
848 | ypos -= ncols; | |
849 | col -= RECONVERT(ncols); | |
850 | } | |
851 | ||
852 | /*ARGSUSED*/ | |
853 | clear(lp, nbytes) | |
854 | int *lp; | |
855 | int nbytes; | |
856 | { | |
857 | asm("movc5 $0,(sp),$0,8(ap),*4(ap)"); | |
858 | } | |
859 | ||
860 | /* Start a new page by formfeeding, resetting buffer and column counters. */ | |
861 | new_page(lines_left) | |
862 | int lines_left; /* ... on page. */ | |
863 | { | |
864 | lines += lines_left; | |
865 | buf0p = buffer; /* Clear out buffer and reset pointers. */ | |
866 | clear(buf0p, BYTES_PER_LINE * NLINES); | |
867 | row = 0; | |
868 | col = 0; | |
869 | xpos = CONVERT(row); | |
870 | ypos = 0; | |
871 | ioctl(vc, VSETSTATE, prtmode); | |
872 | write (vc, "\f", 2); | |
873 | ioctl(vc, VSETSTATE, pltmode); | |
874 | } | |
875 | ||
876 | char * | |
877 | nalloc(i, j) | |
878 | int i, j; | |
879 | { | |
880 | register char *cp; | |
881 | ||
882 | cp = calloc(i, j); | |
883 | return(cp); | |
884 | } | |
885 | ||
886 | nfree(cp) | |
887 | char *cp; | |
888 | { | |
889 | free(cp); | |
890 | } |