/* * Now our scanpage routine. */ static void pscanpage(void) { register shalfword cmd; register chardesctype *cd; register fontmaptype *cfnt = 0; integer fnt; integer mychar; register frametype *frp = frames; #ifdef DEBUG if (dd(D_PAGE)) #ifdef SHORTINT fprintf(stderr,"PPrescanning page %ld\n", pagenum); #else /* ~SHORTINT */ fprintf(stderr,"PPrescanning page %d\n", pagenum); #endif /* ~SHORTINT */ #endif /* DEBUG */ curfnt = NULL; curpos = NULL; bopcolor(0); while (1) { switch (cmd=dvibyte()) { case 255: /* pTeX's dir or undefined */ if (!noptex) { dvibyte(); break; } /* illegal commands */ case 131: case 136: case 139: /* set4, put4, bop */ case 247: case 248: case 249: /* pre, post, post_post */ case 250: case 251: case 252: case 253: case 254: /* undefined */ sprintf(errbuf, "! DVI file contains unexpected command (%d)",cmd); error(errbuf); case 132: case 137: /* eight-byte commands setrule, putrule */ dvibyte(); dvibyte(); dvibyte(); dvibyte(); case 146: case 151: case 156: case 160: case 165: case 170: /* four-byte commands right4, w4, x4, down4, y4, z4 */ dvibyte(); case 145: case 150: case 155: case 159: case 164: case 169: /* three-byte commands right3, w3, x3, down3, y3, z3 */ dvibyte(); case 144: case 149: case 154: case 158: case 163: case 168: /* two-byte commands right2, w2, x2, down2, y2, z2 */ dvibyte(); case 143: case 148: case 153: case 157: case 162: case 167: /* one-byte commands right1, w1, x1, down1, y1, z1 */ dvibyte(); case 147: case 152: case 161: case 166: /* w0, x0, y0, z0 */ case 138: case 141: case 142: /* nop, push, pop */ break; case 130: case 135: /* set3, put3 */ if (noptex) { sprintf(errbuf, "! DVI file contains unexpected pTeX command (%d)",cmd); error(errbuf); } mychar = dvibyte(); mychar = (mychar << 8) + dvibyte(); mychar = (mychar << 8) + dvibyte(); goto dochar; case 129: case 134: /* set2, put2 */ if (noomega && noptex) { sprintf(errbuf, "! DVI file contains unexpected command (%d)",cmd); error(errbuf); } mychar = dvibyte(); mychar = (mychar << 8) + dvibyte(); goto dochar; case 128: case 133: cmd = dvibyte(); /* set1, put1 commands drops through */ default: /* these are commands 0 (setchar0) thru 127 (setchar 127) */ mychar = cmd; dochar: if (curfnt==NULL) error("! Bad DVI file: no font selected"); if (mychar>=curfnt->maxchars) { sprintf(errbuf,"! invalid char %d from font %s", mychar, curfnt->name); error(errbuf); } if (curfnt->loaded == 2) { /* scanning a virtual font character */ frp->curp = curpos; frp->curl = curlim; frp->ff = ffont; frp->curf = curfnt; if (++frp == &frames[MAXFRAME] ) error("! virtual recursion stack overflow"); cd = curfnt->chardesc + mychar; if (cd->packptr == 0) { fprintf(stderr, "Wrong char code: %04X\n", mychar); error("! a non-existent virtual char is being used; check vf/tfm files"); } curpos = cd->packptr + 2; curlim = curpos + (256*(long)(*cd->packptr)+(*(cd->packptr+1))); ffont = curfnt->localfonts; if (ffont==NULL) curfnt = NULL; else ppreselectfont(ffont->desc); } else if (curfnt->loaded == 3) curfnt->chardesc[mychar].flags = EXISTS; break; case 171: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 201: case 202: case 203: case 204: case 205: case 206: case 207: case 208: case 209: case 210: case 211: case 212: case 213: case 214: case 215: case 216: case 217: case 218: case 219: case 220: case 221: case 222: case 223: case 224: case 225: case 226: case 227: case 228: case 229: case 230: case 231: case 232: case 233: case 234: case 235: case 236: case 237: case 238: /* font selection commands */ if (cmd < 235) fnt = cmd - 171; /* fntnum0 thru fntnum63 */ else { fnt = dvibyte(); /* fnt1 */ while (cmd-- > 235) fnt = (fnt << 8) + dvibyte(); } for (cfnt=ffont; cfnt; cfnt = cfnt->next) if (cfnt->fontnum == fnt) goto fontfound; error("! no font selected"); fontfound: curfnt = cfnt->desc; ppreselectfont(curfnt); break; case 239: predospecial((integer)dvibyte(), 1); break; /* xxx1 */ case 240: predospecial((integer)twobytes(), 1); break; /* xxx2 */ case 241: predospecial(threebytes(), 1); break; /* xxx3 */ case 242: predospecial(signedquad(), 1); break; /* xxx4 */ case 243: case 244: case 245: case 246: fontdef(cmd-242); break; /* fntdef1 */ case 140: /* eop or end of virtual char */ if (curpos) { --frp; curfnt = frp->curf; ffont = frp->ff; curlim = frp->curl; curpos = frp->curp; break; } return; } } }
void dopage P1H(void) { register shalfword cmd ; register integer p ; register chardesctype *cd ; register integer h ; register fontmaptype *cfnt ; register frametype *frp = frames ; integer fnt ; #ifdef Omega integer mychar; #endif int charmove ; struct dvistack *sp = stack ; integer v, w, x, y, z ; integer roundpos ; integer thinspace ; integer vertsmallspace ; #ifdef XENIX integer iconv ; integer viconv ; iconv = (integer)(1.0 / conv + 0.5) ; viconv = (integer)(1.0 / vconv + 0.5) ; #else #ifdef __THINK__ integer iconv ; integer viconv ; iconv = (integer)(1.0 / conv + 0.5) ; viconv = (integer)(1.0 / vconv + 0.5) ; #endif #endif #ifdef EMTEX emclear() ; #endif pageinit() ; bopcolor(1) ; thinspace = (integer)(0.025*DPI/conv) ; /* 0.025 inches */ vertsmallspace = (integer)(0.025*VDPI/vconv) ; /* 0.025 inches */ #ifdef HPS if (HPS_FLAG) pagecounter++ ; H_BREAK = (30 * DPI / 400 ) ; /* 30 seems to have worked well at 400 dpi */ #endif w = x = y = z = 0 ; h = (integer) (DPI / conv * hoff / 4736286.72) ; v = (integer) (DPI / conv * voff / 4736286.72) ; hh = PixRound(h) ; vv = PixRound(v) ; curfnt = NULL ; curpos = NULL ; charmove = 0 ; beginloop: switch (cmd=dvibyte()) { case 138: goto beginloop ; /* nop command does nuttin */ /* * For put1 commands, we subtract the width of the character before * dropping through to the normal character setting routines. This */ #ifdef Omega case 134: /* put2 */ mychar = dvibyte() ; mychar = (mychar << 8) + dvibyte() ; charmove = 0 ; goto dochar ; case 133: /* put1 */ mychar = dvibyte() ; charmove = 0 ; goto dochar ; case 129: /* set2 */ mychar = dvibyte() ; mychar = (mychar << 8) + dvibyte() ; charmove = 1 ; goto dochar ; case 128: /* set1 */ mychar = dvibyte() ; charmove = 1 ; goto dochar ; default: /* these are commands 0 (setchar0) thru 127 (setchar127) */ mychar = cmd ; charmove = 1 ; dochar: #else case 133: /* put1 */ cmd = dvibyte() ; charmove = 0 ; goto dochar ; case 128: cmd = dvibyte() ; /* set1 command drops through to setchar */ default: /* these are commands 0 (setchar0) thru 127 (setchar127) */ charmove = 1 ; dochar: #endif #ifdef HPS if (HPS_FLAG && PAGEUS_INTERUPPTUS) { HREF_COUNT-- ; start_new_box() ; PAGEUS_INTERUPPTUS = 0 ; } if (HPS_FLAG && NEED_NEW_BOX) { vertical_in_hps(); NEED_NEW_BOX = 0; } #endif #ifdef Omega cd = &(curfnt->chardesc[mychar]) ; #else cd = &(curfnt->chardesc[cmd]) ; #endif if (cd->flags & EXISTS) { if (curfnt->loaded == 2) { /* virtual character being typeset */ if (charmove) { sp->hh = hh + cd->pixelwidth ; sp->h = h + cd->TFMwidth ; } else { sp->hh = hh ; sp->h = h ; } sp->vv = vv ; sp-> v = v ; sp->w = w ; sp->x = x ; sp->y = y ; sp->z = z ; if (++sp >= &stack[STACKSIZE]) error("! Out of stack space") ; w = x = y = z = 0 ; /* will be in relative units at new stack level */ frp->curp = curpos ; frp->curl = curlim ; frp->ff = ffont ; frp->curf = curfnt ; if (++frp == &frames[MAXFRAME] ) error("! virtual recursion stack overflow") ; curpos = cd->packptr + 2 ; curlim = curpos + (256*(long)(*cd->packptr)+(*(cd->packptr+1))) ; ffont = curfnt->localfonts ; if (ffont) { curfnt = ffont->desc ; thinspace = curfnt->thinspace ; } else { curfnt = NULL ; thinspace = vertsmallspace ; } goto beginloop ; } #ifdef Omega drawchar(cd, mychar) ; #else drawchar(cd, cmd) ; #endif } if (charmove) { h += cd->TFMwidth ; hh += cd->pixelwidth ; } goto setmotion ; #ifdef Omega case 130: case 131: case 135: case 136: case 139: #else case 129: case 130: case 131: case 134: case 135: case 136: case 139: #endif case 247: case 248: case 249: case 250: case 251: case 252: case 253: case 254: case 255: /* unimplemented or illegal commands */ error("! synch") ; case 132: case 137: /* rules */ { integer ry, rx , rxx, ryy ; ry = signedquad() ; rx = signedquad() ; if (rx>0 && ry>0) { if (curpos) { rx = scalewidth(rx, (frp-1)->curf->scaledsize) ; ry = scalewidth(ry, (frp-1)->curf->scaledsize) ; } rxx = (int)(conv * rx + 0.9999999) ; ryy = (int)(vconv * ry + 0.9999999) ; drawrule(rxx, ryy) ; } else rxx = 0 ; if (cmd == 137) goto beginloop ; h += rx ; hh += rxx ; goto setmotion ; } case 141: /* push */ #ifdef HPS if (HPS_FLAG) pushcount++ ; /* if (HPS_FLAG && PAGEUS_INTERUPPTUS) { HREF_COUNT-- ; start_new_box() ; PAGEUS_INTERUPPTUS = 0 ; } */ if (HPS_FLAG && NEED_NEW_BOX) { vertical_in_hps(); NEED_NEW_BOX = 0; } /* printf("push %i, %i\n", pushcount, inHTMLregion) ; */ #endif sp->hh = hh ; sp->vv = vv ; sp->h = h ; sp->v = v ; sp->w = w ; sp->x = x ; sp->y = y ; sp->z = z ; if (++sp >= &stack[STACKSIZE]) error("! Out of stack space") ; goto beginloop ; case 140: /* eop or end of virtual character */ if (curpos == NULL) { /* eop */ #ifdef HPS if (HPS_FLAG && inHTMLregion) PAGEUS_INTERUPPTUS = 1 ; /* printf("Page interrupted"); */ #endif break; } --frp ; curfnt = frp->curf ; thinspace = (curfnt) ? curfnt->thinspace : vertsmallspace ; ffont = frp->ff ; curlim = frp->curl ; curpos = frp->curp ; if (hh < (sp-1)->hh+2 && hh > (sp-1)->hh-2) (sp-1)->hh = hh; /* retain `intelligence' of pixel width, if close */ /* falls through */ case 142: /* pop */ #ifdef HPS pushcount-- ; /* printf("pop %i\n", pushcount) ; */ #endif if (--sp < stack) error("! More pops than pushes") ; #ifdef HPS if (HPS_FLAG) { hhmem = hh ; vvmem = vv ; } #endif hh = sp->hh ; vv = sp->vv ; h = sp->h ; v = sp->v ; w = sp->w ; x = sp->x ; y = sp->y ; z = sp->z ; #ifdef HPS if (HPS_FLAG && inHTMLregion && (hhmem - hh > H_BREAK) && (pushcount > 0) && (pushcount < current_pushcount)) end_current_box() ; #endif goto beginloop ; case 143: /* right1 */ p = signedbyte() ; goto horizontalmotion ; case 144: /* right2 */ p = signedpair() ; goto horizontalmotion ; case 145: /* right3 */ p = signedtrio() ; goto horizontalmotion ; case 146: /* right4 */ p = signedquad() ; goto horizontalmotion ; case 147: /* w0 */ p = w ; goto horizontalmotion ; case 148: /* w1 */ p = w = signedbyte() ; goto horizontalmotion ; case 149: /* w2 */ p = w = signedpair() ; goto horizontalmotion ; case 150: /* w3 */ p = w = signedtrio() ; goto horizontalmotion ; case 151: /* w4 */ p = w = signedquad() ; goto horizontalmotion ; case 152: /* x0 */ p = x ; goto horizontalmotion ; case 153: /* x1 */ p = x = signedbyte() ; goto horizontalmotion ; case 154: /* x2 */ p = x = signedpair() ; goto horizontalmotion ; case 155: /* x3 */ p = x = signedtrio() ; goto horizontalmotion ; case 156: /* x4 */ p = x = signedquad() ; goto horizontalmotion ; case 157: /* down1 */ p = signedbyte() ; goto verticalmotion ; case 158: /* down2 */ p = signedpair() ; goto verticalmotion ; case 159: /* down3 */ p = signedtrio() ; goto verticalmotion ; case 160: /* down4 */ p = signedquad() ; goto verticalmotion ; case 161: /* y0 */ p = y ; goto verticalmotion ; case 162: /* y1 */ p = y = signedbyte() ; goto verticalmotion ; case 163: /* y2 */ p = y = signedpair() ; goto verticalmotion ; case 164: /* y3 */ p = y = signedtrio() ; goto verticalmotion ; case 165: /* y4 */ p = y = signedquad() ; goto verticalmotion ; case 166: /* z0 */ p = z ; goto verticalmotion ; case 167: /* z1 */ p = z = signedbyte() ; goto verticalmotion ; case 168: /* z2 */ p = z = signedpair() ; goto verticalmotion ; case 169: /* z3 */ p = z = signedtrio() ; goto verticalmotion ; case 170: /* z4 */ p = z = signedquad() ; goto verticalmotion ; case 171: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 201: case 202: case 203: case 204: case 205: case 206: case 207: case 208: case 209: case 210: case 211: case 212: case 213: case 214: case 215: case 216: case 217: case 218: case 219: case 220: case 221: case 222: case 223: case 224: case 225: case 226: case 227: case 228: case 229: case 230: case 231: case 232: case 233: case 234: case 235: case 236: case 237: case 238: /* font selection commands */ if (cmd < 235) fnt = cmd - 171 ; /* fntnum0 thru fntnum63 */ else { fnt = dvibyte() ; while (cmd-- > 235) fnt = (fnt << 8) + dvibyte() ; } if (curpos || fnt > 255) { for (cfnt=ffont; cfnt; cfnt = cfnt->next) if (cfnt->fontnum == fnt) break ; curfnt = cfnt->desc ; } else curfnt = baseFonts[fnt] ; thinspace = curfnt->thinspace ; goto beginloop ; case 243: case 244: case 245: case 246: /*fntdef1 */ skipover(cmd - 230) ; skipover(dvibyte() + dvibyte()) ; goto beginloop ; case 239: /* xxx1 */ p = dvibyte() ; dospecial(p) ; goto beginloop ; case 240: /* xxx2 */ p = twobytes() ; dospecial(p) ; goto beginloop ; case 241: /* xxx3 */ p = threebytes() ; dospecial(p) ; goto beginloop ; case 242: /* xxx4 */ p = signedquad() ; dospecial(p) ; goto beginloop ; /* * The calculations here are crucial to the appearance of the document. * If the motion is small, we round the amount of relative motion; otherwise, * we update the position and round the new position. Then we check to * insure that the rounded position didn't accumulate an error that was * greater than maxdrift. */ verticalmotion: /* vertical motion cases */ if (curpos) p = scalewidth(p, (frp-1)->curf->scaledsize) ; v += p ; if (p >= vertsmallspace) vv = VPixRound(v) ; else if (p <= -vertsmallspace) vv = VPixRound(v) ; else { vv += VPixRound(p) ; roundpos = VPixRound(v) ; if (roundpos - vv > vmaxdrift) vv = roundpos - vmaxdrift ; else if (vv - roundpos > vmaxdrift) vv = roundpos + vmaxdrift ; } #ifdef HPS /* printf("Doing vertical motion: p = %i, v = %i, vv = %i\n",p,v,vv); */ /* printf("inHTMLregion %i\n", inHTMLregion) ; */ if (HPS_FLAG && inHTMLregion) NEED_NEW_BOX = 1 /* vertical_in_hps() */; #endif goto beginloop ; /* * Horizontal motion is analogous. We know the exact width of each * character in pixels. Kerning is distinguished from space between * words if it's less than a thinspace and not more negative than would * occur when an accent is being positioned by backspacing. */ horizontalmotion: /* horizontal motion cases */ if (curpos) p = scalewidth(p, (frp-1)->curf->scaledsize) ; h += p ; if (p >= thinspace || p <= -6 * thinspace) { hh = PixRound(h) ; goto beginloop ; } else hh += PixRound(p) ; #ifdef HPS /* printf("Doing horizontal motion: p = %i, h = %i, hh = %i\n",p,h,hh); */ #endif setmotion: roundpos = PixRound(h) ; if (roundpos - hh > maxdrift) { hh = roundpos - maxdrift ; } else if (hh - roundpos > maxdrift) { hh = roundpos + maxdrift ; } goto beginloop ; } /* end of the big switch */ pageend() ; }
integer zfirstpar ( eightbits o ) { register integer Result; switch ( o ) {case 0 : case 1 : case 2 : case 3 : case 4 : case 5 : case 6 : case 7 : case 8 : case 9 : case 10 : case 11 : case 12 : case 13 : case 14 : case 15 : case 16 : case 17 : case 18 : case 19 : case 20 : case 21 : case 22 : case 23 : case 24 : case 25 : case 26 : case 27 : case 28 : case 29 : case 30 : case 31 : case 32 : case 33 : case 34 : case 35 : case 36 : case 37 : case 38 : case 39 : case 40 : case 41 : case 42 : case 43 : case 44 : case 45 : case 46 : case 47 : case 48 : case 49 : case 50 : case 51 : case 52 : case 53 : case 54 : case 55 : case 56 : case 57 : case 58 : case 59 : case 60 : case 61 : case 62 : case 63 : Result = o - 0 ; break ; case 64 : case 71 : case 245 : case 246 : case 239 : Result = getbyte () ; break ; case 65 : case 72 : case 240 : Result = gettwobytes () ; break ; case 66 : case 73 : case 241 : Result = getthreebytes () ; break ; case 242 : case 243 : Result = signedquad () ; break ; case 67 : case 68 : case 69 : case 70 : case 244 : case 247 : case 248 : case 249 : case 250 : case 251 : case 252 : case 253 : case 254 : case 255 : Result = 0 ; break ; case 74 : case 75 : case 76 : case 77 : case 78 : case 79 : case 80 : case 81 : case 82 : case 83 : case 84 : case 85 : case 86 : case 87 : case 88 : case 89 : case 90 : case 91 : case 92 : case 93 : case 94 : case 95 : case 96 : case 97 : case 98 : case 99 : case 100 : case 101 : case 102 : case 103 : case 104 : case 105 : case 106 : case 107 : case 108 : case 109 : case 110 : case 111 : case 112 : case 113 : case 114 : case 115 : case 116 : case 117 : case 118 : case 119 : case 120 : case 121 : case 122 : case 123 : case 124 : case 125 : case 126 : case 127 : case 128 : case 129 : case 130 : case 131 : case 132 : case 133 : case 134 : case 135 : case 136 : case 137 : Result = o - 74 ; break ; case 138 : case 139 : case 140 : case 141 : case 142 : case 143 : case 144 : case 145 : case 146 : case 147 : case 148 : case 149 : case 150 : case 151 : case 152 : case 153 : case 154 : case 155 : case 156 : case 157 : case 158 : case 159 : case 160 : case 161 : case 162 : case 163 : case 164 : case 165 : case 166 : case 167 : case 168 : case 169 : case 170 : case 171 : case 172 : case 173 : case 174 : case 175 : case 176 : case 177 : case 178 : case 179 : case 180 : case 181 : case 182 : case 183 : case 184 : case 185 : case 186 : case 187 : case 188 : case 189 : case 190 : case 191 : case 192 : case 193 : case 194 : case 195 : case 196 : case 197 : case 198 : case 199 : case 200 : case 201 : Result = o - 74 ; break ; case 202 : case 203 : case 204 : case 205 : case 206 : case 207 : case 208 : case 209 : case 210 : case 211 : case 212 : case 213 : case 214 : case 215 : case 216 : case 217 : case 218 : case 219 : case 220 : case 221 : case 222 : case 223 : case 224 : case 225 : case 226 : case 227 : case 228 : case 229 : case 230 : case 231 : case 232 : case 233 : case 234 : case 235 : case 236 : case 237 : case 238 : Result = o - 74 ; break ; default: { fprintf ( stderr , "%s\n", "internal error" ) ; uexit ( 1 ) ; } break ; } return Result ; }
void pprescanpages(void) { register int cmd; integer lmaxpages = maxpages; integer mpagenum; integer pageseq = 0; int ntfirst = notfirst; pprescan = 1; readpreamble(); /* * Now we look for the first page to process. If we get to the end of * the file before the page, we complain (fatally). * Incidentally, we don't use the DVI file's bop backpointer to skip * over pages at high speed, because we want to look to for special * header that might be in skipped pages. */ while (1) { cmd = skipnop(); if (cmd==248) error("! End of document before first specified page"); if (cmd!=139) error("! Bad DVI file: expected bop"); pagenum = signedquad(); pageseq++; mpagenum = abspage ? pageseq : pagenum; if (mpagenum == firstpage && ntfirst) firstmatch++; if (mpagenum == lastpage && notlast) lastmatch++; if (ntfirst && mpagenum == firstpage && firstmatch == firstseq) ntfirst = 0; if (ntfirst || ((evenpages && (pagenum & 1)) || (oddpages && (pagenum & 1)==0) || (pagelist && !InPageList(pagenum)))) { skipover(40); skippage(); } else { if (notlast && mpagenum == lastpage) lastmatch--; break; } } /* * Here we scan for each of the sections. First we initialize some of * the variables we need. We don't have to be as smart as before in * skipping pages. */ skipover(40); while (lmaxpages > 0) { if (!(evenpages && (pagenum & 1)) && !(oddpages && (pagenum & 1)==0) && !(pagelist && !InPageList(pagenum))) { pscanpage(); lmaxpages--; } else skippage(); mpagenum = abspage ? pageseq : pagenum; if (mpagenum == lastpage && notlast) lastmatch++; if (notlast && mpagenum == lastpage && lastmatch == lastseq) lmaxpages = -1; /* we are done after this page. */ cmd=skipnop(); if (cmd==248) break; if (cmd!=139) error("! Bad DVI file: expected bop"); pagenum = signedquad(); skipover(40); pageseq++; } fseek(dvifile, 0L, 0); pprescan = 0; }
void mainbody( void ) { initialize () ; opengffile () ; o = getbyte () ; if ( o != 247 ) { fprintf ( stderr , "%s%s%c\n", "Bad GF file: " , "First byte isn't start of preamble!" , '!' ) ; uexit ( 1 ) ; } o = getbyte () ; if ( o != 131 ) { fprintf ( stderr , "%s%s%ld%s%ld%c\n", "Bad GF file: " , "identification byte should be " , (long)131 , " not " , (long)o , '!' ) ; uexit ( 1 ) ; } o = getbyte () ; putc ( '\'' , stdout ); while ( o > 0 ) { o = o - 1 ; putc ( xchr [getbyte () ], stdout ); } { putc ( '\'' , stdout ); putc ( '\n', stdout ); } do { gfprevptr = curloc ; do { a = curloc ; o = getbyte () ; p = firstpar ( o ) ; if ( eof ( gffile ) ) { fprintf ( stderr , "%s%s%c\n", "Bad GF file: " , "the file ended prematurely" , '!' ) ; uexit ( 1 ) ; } if ( o == 243 ) { { if ( wantsmnemonics ) { putc ('\n', stdout ); fprintf ( stdout , "%ld%s%s%ld%s", (long)a , ": " , "yyy " , (long)p , " (" ) ; } if ( wantsmnemonics ) { printscaled ( p ) ; putc ( ')' , stdout ); } } o = 244 ; } else if ( ( o >= 239 ) && ( o <= 242 ) ) { { if ( wantsmnemonics ) { putc ('\n', stdout ); fprintf ( stdout , "%ld%s%s", (long)a , ": " , "xxx '" ) ; } badchar = false ; b = 16 ; if ( p < 0 ) { putc ('\n', stdout ); fprintf ( stdout , "%ld%s%s%s", (long)a , ": " , "! " , "string of negative length!" ) ; putc ('\n', stdout ); } while ( p > 0 ) { q = getbyte () ; if ( ( q < 32 ) || ( q > 126 ) ) badchar = true ; if ( wantsmnemonics ) { putc ( xchr [q ], stdout ); if ( b < linelength ) b = b + 1 ; else { putc ('\n', stdout ); b = 2 ; } } p = p - 1 ; } if ( wantsmnemonics ) putc ( '\'' , stdout ); if ( badchar ) { putc ('\n', stdout ); fprintf ( stdout , "%ld%s%s%s", (long)a , ": " , "! " , "non-ASCII character in xxx command!" ) ; putc ('\n', stdout ); } } o = 244 ; } else if ( o == 244 ) { if ( wantsmnemonics ) { putc ('\n', stdout ); fprintf ( stdout , "%ld%s%s", (long)a , ": " , "no op" ) ; } } } while ( ! ( o != 244 ) ) ; if ( o != 248 ) { if ( o != 67 ) { if ( o != 68 ) { fprintf ( stderr , "%s%s%ld%s%ld%c%c\n", "Bad GF file: " , "byte " , (long)curloc - 1 , " is not boc (" , (long)o , ')' , '!' ) ; uexit ( 1 ) ; } } putc ('\n', stdout ); fprintf ( stdout , "%ld%s", (long)curloc - 1 , ": beginning of char " ) ; a = curloc - 1 ; totalchars = totalchars + 1 ; if ( o == 67 ) { charactercode = signedquad () ; p = signedquad () ; c = charactercode % 256 ; if ( c < 0 ) c = c + 256 ; minmstated = signedquad () ; maxmstated = signedquad () ; minnstated = signedquad () ; maxnstated = signedquad () ; } else { charactercode = getbyte () ; p = -1 ; c = charactercode ; q = getbyte () ; maxmstated = getbyte () ; minmstated = maxmstated - q ; q = getbyte () ; maxnstated = getbyte () ; minnstated = maxnstated - q ; } fprintf ( stdout , "%ld", (long)c ) ; if ( charactercode != c ) fprintf ( stdout , "%s%ld", " with extension " , (long)( charactercode - c ) / 256 ) ; if ( wantsmnemonics ) fprintf ( stdout , "%s%ld%s%ld%c%ld%s%ld\n", ": " , (long)minmstated , "<=m<=" , (long)maxmstated , ' ' , (long)minnstated , "<=n<=" , (long)maxnstated ) ; maxmobserved = -1 ; if ( charptr [c ]!= p ) { fprintf ( stdout , "%ld%s%s%s%ld%s%ld%c", (long)a , ": " , "! " , "previous character pointer should be " , (long)charptr [c ], ", not " , (long)p , '!' ) ; putc ('\n', stdout ); } else if ( p > 0 ) { if ( wantsmnemonics ) fprintf ( stdout , "%s%ld%c\n", "(previous character with the same code started at byte " , (long)p , ')' ) ; } charptr [c ]= gfprevptr ; if ( wantsmnemonics ) fprintf ( stdout , "%s%ld%c", "(initially n=" , (long)maxnstated , ')' ) ; if ( wantspixels ) { maxcol = maxmstated - minmstated - 1 ; if ( maxcol > maxcols ) maxcol = maxcols ; maxrow = maxnstated - minnstated ; if ( maxrow > maxrows ) maxrow = maxrows ; if ( ( maxrow >= 0 ) && ( maxcol >= 0 ) ) imagearray = xcallocarray ( pixel , maxcol , maxrow ) ; } m = 0 ; n = 0 ; paintswitch = 0 ; if ( ! dochar () ) { fprintf ( stderr , "%s%s%c\n", "Bad GF file: " , "char ended unexpectedly" , '!' ) ; uexit ( 1 ) ; } maxnobserved = n ; if ( wantspixels ) { if ( ( maxmobserved > maxcol ) || ( maxnobserved > maxrow ) ) fprintf ( stdout , "%s\n", "(The character is too large to be displayed in full.)" ) ; if ( maxcol > maxmobserved ) maxcol = maxmobserved ; if ( maxrow > maxnobserved ) maxrow = maxnobserved ; if ( maxcol >= 0 ) { fprintf ( stdout , "%s%ld%c%ld%s\n", ".<--This pixel's lower left corner is at (" , (long)minmstated , ',' , (long)maxnstated + 1 , ") in METAFONT coordinates" ) ; n = 0 ; while ( n <= maxrow ) { m = 0 ; b = 0 ; while ( m <= maxcol ) { if ( imagearray [m + ( maxcol + 1 ) * n ]== 0 ) b = b + 1 ; else { while ( b > 0 ) { putc ( ' ' , stdout ); b = b - 1 ; } putc ( '*' , stdout ); } m = m + 1 ; } putc ('\n', stdout ); n = n + 1 ; } fprintf ( stdout , "%s%ld%c%ld%s\n", ".<--This pixel's upper left corner is at (" , (long)minmstated , ',' , (long)maxnstated - maxrow , ") in METAFONT coordinates" ) ; } else fprintf ( stdout , "%s\n", "(The character is entirely blank.)" ) ; if ( ( maxrow >= 0 ) && ( maxcol >= 0 ) ) { libcfree ( imagearray ) ; imagearray = nil ; } } maxmobserved = minmstated + maxmobserved + 1 ; n = maxnstated - maxnobserved ; if ( minmstated < minmoverall ) minmoverall = minmstated ; if ( maxmobserved > maxmoverall ) maxmoverall = maxmobserved ; if ( n < minnoverall ) minnoverall = n ; if ( maxnstated > maxnoverall ) maxnoverall = maxnstated ; if ( maxmobserved > maxmstated ) fprintf ( stdout , "%s%ld%c\n", "The previous character should have had max m >= " , (long)maxmobserved , '!' ) ; if ( n < minnstated ) fprintf ( stdout , "%s%ld%c\n", "The previous character should have had min n <= " , (long)n , '!' ) ; } } while ( ! ( o == 248 ) ) ; putc ('\n', stdout ); readpostamble () ; fprintf ( stdout , "%s%ld%s", "The file had " , (long)totalchars , " character" ) ; if ( totalchars != 1 ) putc ( 's' , stdout ); fprintf ( stdout , "%s\n", " altogether." ) ; }
void readpostamble ( void ) { integer k ; integer p, q, m, u, v, w, c ; postloc = curloc - 1 ; fprintf ( stdout , "%s%ld", "Postamble starts at byte " , (long)postloc ) ; if ( postloc == gfprevptr ) { putc ( '.' , stdout ); putc ( '\n', stdout ); } else fprintf ( stdout , "%s%ld%c\n", ", after special info at byte " , (long)gfprevptr , '.' ) ; p = signedquad () ; if ( p != gfprevptr ) { fprintf ( stdout , "%ld%s%s%s%ld%s%ld%s%ld%c", (long)a , ": " , "! " , "backpointer in byte " , (long)curloc - 4 , " should be " , (long)gfprevptr , " not " , (long)p , '!' ) ; putc ('\n', stdout ); } designsize = signedquad () ; checksum = signedquad () ; fprintf ( stdout , "%s%ld%s", "design size = " , (long)designsize , " (" ) ; printscaled ( designsize / 16 ) ; fprintf ( stdout , "%s\n", "pt)" ) ; fprintf ( stdout , "%s%ld\n", "check sum = " , (long)checksum ) ; hppp = signedquad () ; vppp = signedquad () ; fprintf ( stdout , "%s%ld%s", "hppp = " , (long)hppp , " (" ) ; printscaled ( hppp ) ; { putc ( ')' , stdout ); putc ( '\n', stdout ); } fprintf ( stdout , "%s%ld%s", "vppp = " , (long)vppp , " (" ) ; printscaled ( vppp ) ; { putc ( ')' , stdout ); putc ( '\n', stdout ); } pixratio = ( designsize / ((double) 1048576L ) ) * ( hppp / ((double) 1048576L ) ) ; minmstated = signedquad () ; maxmstated = signedquad () ; minnstated = signedquad () ; maxnstated = signedquad () ; fprintf ( stdout , "%s%ld%s%ld\n", "min m = " , (long)minmstated , ", max m = " , (long)maxmstated ) ; if ( minmstated > minmoverall ) { fprintf ( stdout , "%ld%s%s%s%ld%c", (long)a , ": " , "! " , "min m should be <=" , (long)minmoverall , '!' ) ; putc ('\n', stdout ); } if ( maxmstated < maxmoverall ) { fprintf ( stdout , "%ld%s%s%s%ld%c", (long)a , ": " , "! " , "max m should be >=" , (long)maxmoverall , '!' ) ; putc ('\n', stdout ); } fprintf ( stdout , "%s%ld%s%ld\n", "min n = " , (long)minnstated , ", max n = " , (long)maxnstated ) ; if ( minnstated > minnoverall ) { fprintf ( stdout , "%ld%s%s%s%ld%c", (long)a , ": " , "! " , "min n should be <=" , (long)minnoverall , '!' ) ; putc ('\n', stdout ); } if ( maxnstated < maxnoverall ) { fprintf ( stdout , "%ld%s%s%s%ld%c", (long)a , ": " , "! " , "max n should be >=" , (long)maxnoverall , '!' ) ; putc ('\n', stdout ); } do { a = curloc ; k = getbyte () ; if ( ( k == 245 ) || ( k == 246 ) ) { c = firstpar ( k ) ; if ( k == 245 ) { u = signedquad () ; v = signedquad () ; } else { u = getbyte () * 65536L ; v = 0 ; } w = signedquad () ; p = signedquad () ; fprintf ( stdout , "%s%ld%s%ld%s", "Character " , (long)c , ": dx " , (long)u , " (" ) ; printscaled ( u ) ; if ( v != 0 ) { fprintf ( stdout , "%s%ld%s", "), dy " , (long)v , " (" ) ; printscaled ( v ) ; } fprintf ( stdout , "%s%ld%s", "), width " , (long)w , " (" ) ; w = round ( w * pixratio ) ; printscaled ( w ) ; fprintf ( stdout , "%s%ld\n", "), loc " , (long)p ) ; if ( charptr [c ]== 0 ) { fprintf ( stdout , "%ld%s%s%s", (long)a , ": " , "! " , "duplicate locator for this character!" ) ; putc ('\n', stdout ); } else if ( p != charptr [c ]) { fprintf ( stdout , "%ld%s%s%s%ld%c", (long)a , ": " , "! " , "character location should be " , (long)charptr [c ], '!' ) ; putc ('\n', stdout ); } charptr [c ]= 0 ; k = 244 ; } } while ( ! ( k != 244 ) ) ; if ( k != 249 ) { fprintf ( stdout , "%ld%s%s%s", (long)a , ": " , "! " , "should be postpost!" ) ; putc ('\n', stdout ); } {register integer for_end; k = 0 ;for_end = 255 ; if ( k <= for_end) do if ( charptr [k ]> 0 ) { fprintf ( stdout , "%ld%s%s%s%ld%c", (long)a , ": " , "! " , "missing locator for character " , (long)k , '!' ) ; putc ('\n', stdout ); } while ( k++ < for_end ) ;} q = signedquad () ; if ( q != postloc ) { fprintf ( stdout , "%ld%s%s%s%ld%s%ld%c", (long)a , ": " , "! " , "postamble pointer should be " , (long)postloc , " not " , (long)q , '!' ) ; putc ('\n', stdout ); } m = getbyte () ; if ( m != 131 ) { fprintf ( stdout , "%ld%s%s%s%ld%s%ld%c", (long)a , ": " , "! " , "identification byte should be " , (long)131 , ", not " , (long)m , '!' ) ; putc ('\n', stdout ); } k = curloc ; m = 223 ; while ( ( m == 223 ) && ! eof ( gffile ) ) m = getbyte () ; if ( ! eof ( gffile ) ) { fprintf ( stderr , "%s%s%ld%s%c\n", "Bad GF file: " , "signature in byte " , (long)curloc - 1 , " should be 223" , '!' ) ; uexit ( 1 ) ; } else if ( curloc < k + 4 ) { fprintf ( stdout , "%ld%s%s%s", (long)a , ": " , "! " , "not enough signature bytes at end of file!" ) ; putc ('\n', stdout ); } }
/* * And now the big routine. */ void skippage() { register shalfword cmd ; register integer i ; #ifdef DEBUG if (dd(D_PAGE)) #ifdef SHORTINT (void)fprintf(stderr,"Skipping page %ld\n", pagenum) ; #else /* ~SHORTINT */ (void)fprintf(stderr,"Skipping page %d\n", pagenum) ; #endif /* ~SHORTINT */ #endif /* DEBUG */ skipover(40) ; /* skip rest of bop command */ while ((cmd=dvibyte())!=140) { switch (cmd) { /* illegal options */ case 129: case 130: case 131: case 134: case 135: case 136: case 139: case 247: case 248: case 249: case 250: case 251: case 252: case 253: case 254: case 255: (void)sprintf(errbuf, #ifdef SHORTINT "! DVI file contains unexpected command (%ld)",cmd) ; #else /* ~SHORTINT */ "! DVI file contains unexpected command (%d)",cmd) ; #endif /* ~SHORTINT */ error(errbuf) ; /* eight byte commands */ case 132: case 137: cmd = dvibyte() ; cmd = dvibyte() ; cmd = dvibyte() ; cmd = dvibyte() ; /* four byte commands */ case 146: case 151: case 156: case 160: case 165: case 170: case 238: cmd = dvibyte() ; /* three byte commands */ case 145: case 150: case 155: case 159: case 164: case 169: case 237: cmd = dvibyte() ; /* two byte commands */ case 144: case 149: case 154: case 158: case 163: case 168: case 236: cmd = dvibyte() ; /* one byte commands */ case 128: case 133: case 143: case 148: case 153: case 157: case 162: case 167: case 235: cmd = dvibyte() ; break ; /* specials */ case 239: i = dvibyte() ; predospecial(i, 0) ; break ; case 240: i = twobytes() ; predospecial(i, 0) ; break ; case 241: i = threebytes() ; predospecial(i, 0) ; break ; case 242: i = signedquad() ; predospecial(i, 0) ; break ; /* font definition */ case 243: case 244: case 245: case 246: fontdef(cmd - 242) ; break ; default: ; } } }
/* * Now we have the main procedure. */ void dosection(sectiontype *s, int c) { charusetype *cu; integer prevptr; int np; int k; integer thispage = 0; char buf[104]; dopsfont(s); #ifdef HPS if (HPS_FLAG) pagecounter = 0; #endif if (multiplesects) { setup(); } cmdout("TeXDict"); cmdout("begin"); numout(hpapersize); numout(vpapersize); doubleout(mag); numout((integer)DPI); numout((integer)VDPI); snprintf(buf, sizeof(buf), "(%.99s)", fulliname); cmdout(buf); newline(); cmdout("@start"); if (multiplesects) cmdout("bos"); /* * We insure raster is even-word aligned, because download might want that. */ if (bytesleft & 1) { bytesleft--; raster++; } cleanres(); cu = (charusetype *) (s + 1); psfont = 1; while (cu->fd) { if (cu->psfused) cu->fd->psflag = EXISTS; download(cu++, psfont++); } fonttableout(); if (! multiplesects) { cmdout("end"); setup(); } for (cu=(charusetype *)(s+1); cu->fd; cu++) cu->fd->psflag = 0; while (c > 0) { c--; prevptr = s->bos; if (! reverse) fseek(dvifile, (long)prevptr, 0); np = s->numpages; while (np-- != 0) { if (reverse) fseek(dvifile, (long)prevptr, 0); pagenum = signedquad(); if ((evenpages && (pagenum & 1)) || (oddpages && (pagenum & 1)==0) || (pagelist && !InPageList(pagenum))) { if (reverse) { skipover(36); prevptr = signedquad()+1; } else { skipover(40); skippage(); skipnop(); } ++np; /* this page wasn't counted for s->numpages */ continue; } /* * We want to take the base 10 log of the number. It's probably * small, so we do it quick. */ if (! quiet) { int t = pagenum, i = 0; if (t < 0) { t = -t; i++; } do { i++; t /= 10; } while (t > 0); if (pagecopies < 20) i += pagecopies - 1; if (i + prettycolumn > STDOUTSIZE) { fprintf(stderr, "\n"); prettycolumn = 0; } prettycolumn += i + 1; #ifdef SHORTINT fprintf(stderr, "[%ld", pagenum); #else /* ~SHORTINT */ fprintf(stderr, "[%d", pagenum); #endif /* ~SHORTINT */ fflush(stderr); } skipover(36); prevptr = signedquad()+1; for (k=0; k<pagecopies; k++) { if (k == 0) { if (pagecopies > 1) thispage = ftell(dvifile); } else { fseek(dvifile, (long)thispage, 0); if (prettycolumn + 1 > STDOUTSIZE) { fprintf(stderr, "\n"); prettycolumn = 0; } fprintf(stderr, "."); fflush(stderr); prettycolumn++; } dopage(); } if (! quiet) { fprintf(stderr, "] "); fflush(stderr); prettycolumn += 2; } if (! reverse) skipnop(); } } if (! multiplesects && ! disablecomments) { newline(); fprintf(bitfile, "%%%%Trailer\n"); } if (multiplesects) { if (! disablecomments) { newline(); fprintf(bitfile, "%%DVIPSSectionTrailer\n"); } cmdout("eos"); cmdout("end"); } #ifdef HPS if (HPS_FLAG) cmdout("\nend"); /* close off HPSDict */ #endif if (multiplesects && ! disablecomments) { newline(); fprintf(bitfile, "%%DVIPSEndSection\n"); linepos = 0; } }
/* * And now the big routine. */ void skippage(void) { register shalfword cmd; register integer i; #ifdef DEBUG if (dd(D_PAGE)) #ifdef SHORTINT fprintf(stderr,"Skipping page %ld\n", pagenum); #else /* ~SHORTINT */ fprintf(stderr,"Skipping page %d\n", pagenum); #endif /* ~SHORTINT */ #endif /* DEBUG */ /* skipover(40); skip rest of bop command? how did this get in here? */ bopcolor(0); while ((cmd=dvibyte())!=140) { switch (cmd) { case 255: /* pTeX's dir or undefined */ if (!noptex) { cmd = dvibyte(); break; } /* illegal commands */ case 139: case 247: case 248: case 249: /* bop, pre, post, post_post */ case 250: case 251: case 252: case 253: case 254: /* undefined */ sprintf(errbuf, "! DVI file contains unexpected command (%d)",cmd); error(errbuf); /* eight byte commands */ case 132: case 137: cmd = dvibyte(); cmd = dvibyte(); cmd = dvibyte(); cmd = dvibyte(); /* four byte commands */ case 131: case 136: case 146: case 151: case 156: case 160: case 165: case 170: case 238: cmd = dvibyte(); /* three byte commands */ case 130: case 135: case 145: case 150: case 155: case 159: case 164: case 169: case 237: cmd = dvibyte(); /* two byte commands */ case 129: case 134: case 144: case 149: case 154: case 158: case 163: case 168: case 236: cmd = dvibyte(); /* one byte commands */ case 128: case 133: case 143: case 148: case 153: case 157: case 162: case 167: case 235: cmd = dvibyte(); break; /* specials */ case 239: i = dvibyte(); predospecial(i, 0); break; case 240: i = twobytes(); predospecial(i, 0); break; case 241: i = threebytes(); predospecial(i, 0); break; case 242: i = signedquad(); predospecial(i, 0); break; /* font definition */ case 243: case 244: case 245: case 246: fontdef(cmd - 242); break; default:; } } }