Exemplo n.º 1
0
void walkpages()                  /* process the pages in the DVI-file */
{
    register bool wantpage;

    pagecounter = 0L;
    while ((opcode = skipnops()) != POST) {
        if (opcode != BOP)              /* should be at start of page now    */
            errorexit(nobop);
        else {
            pagecounter++;
            pagenr = sget4();           /* get TeX page number               */
            mseek(DVIfile, 36L, relative); /* skip page header */
            backpointer = sget4();      /* get previous page offset          */
            if (pageswitchon)
                if (sequenceon)
                    wantpage = inlist(pagecounter);
                else
                    wantpage = inlist(pagenr);
            else
                wantpage = TRUE;

            if (wantpage) {
                initpage();
                dopage();
                printpage();
            }
            else {
                skippage();
            }
        }
    }

} /* walkpages */
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
/*
 *   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;
   }
}