Back to index

tetex-bin  3.0
Functions
dvisel.h File Reference
#include "dvi-init.h"
#include "print-internal.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Boolean check_pagerange (struct select_pages_info *pinfo, int pageno)
Boolean check_marked (struct select_pages_info *pinfo, int pageno)
void select_pages (struct select_pages_info *pinfo)

Function Documentation

Boolean check_marked ( struct select_pages_info pinfo,
int  pageno 
)

Definition at line 585 of file dvisel.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean check_pagerange ( struct select_pages_info pinfo,
int  pageno 
)

Definition at line 579 of file dvisel.c.

{
    return (page >= info->from && page <= info->to);
}

Here is the caller graph for this function:

void select_pages ( struct select_pages_info pinfo)

Definition at line 592 of file dvisel.c.

{
    int c, n, page, pagecnt;
    long fout_pos = 0L;
    unsigned long curr_page_offset = 0xffffffff; /* pattern to be overwritten later */
    unsigned long post_cmd_offset = 0xffffffff; /* pattern to be overwritten later */
    struct fontinfo *fontp;
    FILE *in_fp = pinfo->finfo->dvi_in.fp;
    FILE *out_fp = pinfo->finfo->dvi_tmp.fp;
    
    Boolean headers_dumped = False;
    free(dvips_papersize_special); /* re-initialize */
    dvips_papersize_special = NULL;

    ASSERT(in_fp != NULL, "input file mustn't be NULL in select_pages()!");
    ASSERT(out_fp != NULL, "output file mustn't be NULL in select_pages()!");
    
    pinfo->errflag = NO_ERROR; /* reset errflag, in case we're recovering from a previous error */
    
    /* get font list from postamble; in_fp already has been positioned
       at correct position (start of postamble) in caller. */
    (void)fseek(in_fp, ftell(in_fp), SEEK_SET); /* paranoia */
    (void)get_bytes(in_fp, POSTAMBLE_LEN);
    fontinfo_head = NULL;
    for (;;) {
       if ((c = get_byte(in_fp)) < FNTDEF1 || c > FNTDEF4) /* maybe POSTPOST */
           break;
       fontp = (struct fontinfo *) xmalloc(sizeof(struct fontinfo));
       fontp->TeXnumber = get_bytes(in_fp, c - FNTDEF1 + 1);
       fread(fontp->info, sizeof(char), 14, in_fp);
       n = fontp->info[12] + fontp->info[13];
       fontp->fontname = xmalloc(n);
       fread(fontp->fontname, sizeof(char), n, in_fp);
       fontp->next = fontinfo_head;
       fontinfo_head = fontp;
       fontp->used = False;
    }

    /* preamble */
    fseek(in_fp, 0L, SEEK_SET);
    fout_pos = pageinfo_get_offset(0);
    CopyNum(in_fp, out_fp, fout_pos);

    /* each page */
    pagecnt = 0;
    for (page = 0; page < total_pages; page++) {
       scan_page_for_specials(in_fp, page, True, stack_save, NULL);

       /* should the current page be selected? */
       if (pinfo->callback == NULL || pinfo->callback(pinfo, page)) {
           scan_page_for_specials(in_fp, page, False, scan_for_included_files, pinfo);

           /* read BOP except for p[4] */
           CopyNum(in_fp, out_fp, BOP_PART_LEN);
           /* read p[4] (previous bop pointer */
           (void)get_bytes(in_fp, 4);
           /* write actual value of p[4] */
           PutFour(curr_page_offset, out_fp);
           /* remember offset of current page, for postamble */
           curr_page_offset = fout_pos;
           /* update fout_pos to current position */
           fout_pos += BOP_LEN;
           
           if (!headers_dumped) {
              headers_dumped = True;
              dump_literal_headers(out_fp, &fout_pos);
           }

           /*            if (!written_pre_cmds) { */
           stack_dump_open_commands(out_fp, &fout_pos);
/*            written_pre_cmds = True; */
/*         } */

           while ((c = getc(in_fp)) != EOF) {
              if ((c & 0x80) == 0) { /* ordinary character */
                  putc(c, out_fp);
                  fout_pos++;
              }
              else if (c == EOP) { /* End Of Page */
/*                fprintf(stderr, "EOP at %ld\n", ftell(fin)); */

/*                if (page == to) {  */ /* print close stack for last page */
                  stack_dump_close_commands(out_fp, &fout_pos);
/*                } */

                  putc(c, out_fp);
                  fout_pos++;
                  break;
              }
              else {
/*                fprintf(stderr, "WRITE_DVI before: %ld, in_fp before: %ld\n", fout_pos, ftell(in_fp)); */
                  WriteDVI(in_fp, out_fp, &fout_pos, c);
/*                fprintf(stderr, "WRITE_DVI after: %ld; in_fp after: %ld\n", fout_pos, ftell(in_fp)); */
              }
              /* HACK alert: force synchronization - why is this neccessary?
                 Seems to have something do with the fact that two FILE *'s on the same
                 file are open. POSIX.1,
                 `Interaction of File Descriptors and Standard I/O Streams' seems to
                 say the seek()s on one of them also affect the other, but I'm not sure
                 about this.
               */
              fseek(in_fp, 0L, SEEK_CUR);
           }
           pagecnt++;
       }
    }

    /* postamble */
    if (!find_postamble(in_fp, &(pinfo->errflag))) {
       return;
    }

    /* read/write POST command */
    putc(get_byte(in_fp), out_fp);
    /* read over last page offset */
    get_bytes(in_fp, 4);
    /* write last page offset */
    PutFour(curr_page_offset, out_fp);
    /* remember start of POST */
    post_cmd_offset = fout_pos;
    /* copy part of postamble */
    CopyNum(in_fp, out_fp, POSTAMBLE_PART_LEN);
    /* read t[2], total number of pages */
    get_bytes(in_fp, 2);
    /* write t[2] (two calls) */
    putc((pagecnt >> 8) & 0xff, out_fp);
    putc(pagecnt & 0xff, out_fp);
    /* update fout_pos to current pos */
    fout_pos += POSTAMBLE_LEN;

    /* output font list */
    for (;;) {
       if ((c = get_byte(in_fp)) < FNTDEF1 || c > FNTDEF4) /* maybe POSTPOST */
           break;
       n = get_bytes(in_fp, c - FNTDEF1 + 1);
       for (fontp = fontinfo_head; fontp; fontp = fontp->next)
           if (n == fontp->TeXnumber)
              break;
       if (fontp && fontp->used == True)
           FontWrite(out_fp, fontp, &fout_pos);
       (void) get_bytes(in_fp, 12);
       (void) get_bytes(in_fp, (int)(get_byte(in_fp) + get_byte(in_fp)));
    }

    /* free list */
    for (fontp = fontinfo_head; fontp;) {
       struct fontinfo *nextp;
       free(fontp->fontname);
       nextp = fontp->next;
       free(fontp);
       fontp = nextp;
    }

    /* POSTPOST */
    putc(c, out_fp);
    get_bytes(in_fp, 4);
    PutFour(post_cmd_offset, out_fp);
    CopyNum(in_fp, out_fp, 1 + 4);
    for (fout_pos += 1 + 4 + 1 + 4;
        fout_pos & 3;
        fout_pos++) {
       putc(TRAILER, out_fp);
    }

/*      fclose(in_fp); */
    fflush(out_fp);
}

Here is the call graph for this function:

Here is the caller graph for this function: