Back to index

tetex-bin  3.0
Defines | Functions | Variables
writezip.c File Reference
#include "ptexlib.h"
#include "zlib.h"

Go to the source code of this file.

Defines

#define ZIP_BUF_SIZE   32768
#define check_err(f, fn)
#define fixedcompresslevel   fixint(getintpar(cfgcompresslevelcode), 0, 9)

Functions

void writezip (boolean finish)

Variables

static const char perforce_id [] = "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writezip.c#5 $"
static char zipbuf [ZIP_BUF_SIZE]
static z_stream c_stream

Define Documentation

#define check_err (   f,
  fn 
)
Value:
if (f != Z_OK)                                         \
        pdftex_fail("zlib: %s() failed", fn)

Definition at line 31 of file writezip.c.

#define fixedcompresslevel   fixint(getintpar(cfgcompresslevelcode), 0, 9)

Definition at line 35 of file writezip.c.

#define ZIP_BUF_SIZE   32768

Definition at line 29 of file writezip.c.


Function Documentation

void writezip ( boolean  finish)

Definition at line 40 of file writezip.c.

{
    int err;

    if (!fixedcompresslevel) {
        if (pdfptr) {
            pdfgone += xfwrite(pdfbuf, 1, pdfptr, pdffile);
            pdfstreamlength += pdfptr;
            }
        return;
    }

    cur_file_name = NULL;
    if (pdfstreamlength == 0) {
        c_stream.zalloc = (alloc_func)0;
        c_stream.zfree = (free_func)0;
        c_stream.opaque = (voidpf)0;
        check_err(deflateInit(&c_stream, fixedcompresslevel), "deflateInit");
        c_stream.next_out = (Bytef*)zipbuf;
        c_stream.avail_out = ZIP_BUF_SIZE;
    }
    c_stream.next_in = pdfbuf;
    c_stream.avail_in = pdfptr;
    for(;;) {
        if (c_stream.avail_out == 0) {
            pdfgone += xfwrite(zipbuf, 1, ZIP_BUF_SIZE, pdffile);
            c_stream.next_out = (Bytef*)zipbuf;
            c_stream.avail_out = ZIP_BUF_SIZE;
        }
        err = deflate(&c_stream, finish ? Z_FINISH : Z_NO_FLUSH);
        if (finish && err == Z_STREAM_END)
            break;
        check_err(err, "deflate");
        if (!finish && c_stream.avail_in == 0)
            break;
    }
    if (finish) {
        if (c_stream.avail_out < ZIP_BUF_SIZE) /* at least one byte has been output */
            pdfgone += xfwrite(zipbuf, 1, ZIP_BUF_SIZE - c_stream.avail_out, pdffile);
        check_err(deflateEnd(&c_stream), "deflateEnd");
        xfflush(pdffile);
    }
    pdfstreamlength = c_stream.total_out;
}

Here is the call graph for this function:


Variable Documentation

z_stream c_stream [static]

Definition at line 38 of file writezip.c.

const char perforce_id[] = "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writezip.c#5 $" [static]

Definition at line 26 of file writezip.c.

char zipbuf[ZIP_BUF_SIZE] [static]

Definition at line 37 of file writezip.c.