⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlib.xs

📁 perl中编译使用zlib
💻 XS
📖 第 1 页 / 共 2 页
字号:
/* Filename: Zlib.xs * Author  : Paul Marquess, <Paul.Marquess@btinternet.com> * Created : 6th January 2000 * Version : 1.08 * *   Copyright (c) 1995-2000 Paul Marquess. All rights reserved. *   This program is free software; you can redistribute it and/or *   modify it under the same terms as Perl itself. * *//* Part of this code is based on the file gzio.c *//* gzio.c -- IO on .gz files * Copyright (C) 1995 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include <zlib.h> #ifndef PERL_VERSION#include "patchlevel.h"#define PERL_REVISION	5#define PERL_VERSION	PATCHLEVEL#define PERL_SUBVERSION	SUBVERSION#endif#if PERL_REVISION == 5 && (PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION <= 75 ))#    define PL_sv_undef		sv_undef#    define PL_na		na#    define PL_curcop		curcop#    define PL_compiling	compiling#endiftypedef struct di_stream {    z_stream stream;    int	     bufsize;     SV *     dictionary ;    uLong    dict_adler ;} di_stream;typedef di_stream * deflateStream ;typedef di_stream * Compress__Zlib__deflateStream ;typedef di_stream * inflateStream ;typedef di_stream * Compress__Zlib__inflateStream ;/* typedef gzFile Compress__Zlib__gzFile ; */typedef struct gzType {    gzFile gz ;    SV *   buffer ;    int	   offset ;    bool   closed ;}  gzType ;typedef gzType* Compress__Zlib__gzFile ; #define Zip_gzflush(file, flush) gzflush(file->gz, flush) #define Zip_gzclose(file) gzclose(file->gz)#define GZERRNO	"Compress::Zlib::gzerrno"#if 1static char *my_z_errmsg[] = {    "need dictionary",     /* Z_NEED_DICT     2 */    "stream end",          /* Z_STREAM_END    1 */    "",                    /* Z_OK            0 */    "file error",          /* Z_ERRNO        (-1) */    "stream error",        /* Z_STREAM_ERROR (-2) */    "data error",          /* Z_DATA_ERROR   (-3) */    "insufficient memory", /* Z_MEM_ERROR    (-4) */    "buffer error",        /* Z_BUF_ERROR    (-5) */    "incompatible version",/* Z_VERSION_ERROR(-6) */    ""};#endifstatic uLong adlerInitial ;static uLong crcInitial ;static int trace = 0 ;SV *sv_NULL ;static void#ifdef CAN_PROTOTYPESetGzErrorNo(int error_no)#elseSetGzErrorNo(error_no)int error_no ;#endif{    char * errstr ;    SV * gzerror_sv = perl_get_sv(GZERRNO, FALSE) ;      if (error_no == Z_ERRNO) {        error_no = errno ;        errstr = Strerror(errno) ;    }    else        /* errstr = gzerror(fil, &error_no) ; */        errstr = (char*) my_z_errmsg[2 - error_no];     if (SvIV(gzerror_sv) != error_no) {        sv_setiv(gzerror_sv, error_no) ;        sv_setpv(gzerror_sv, errstr) ;        SvIOK_on(gzerror_sv) ;    }}static void#ifdef CAN_PROTOTYPESetGzError(gzFile file)#elseSetGzError(file)gzFile file ;#endif{    int error_no ;    (void)gzerror(file, &error_no) ;    SetGzErrorNo(error_no) ;}static di_stream *#ifdef CAN_PROTOTYPEInitStream(int bufsize)#elseInitStream(bufsize)    int bufsize ;#endif{    di_stream *s = (di_stream *)safemalloc(sizeof(di_stream));    if (s)  {        s->stream.zalloc = (alloc_func) 0;        s->stream.zfree = (free_func) 0;        s->stream.opaque = (voidpf) 0;        s->stream.next_in = Z_NULL;        s->stream.next_out = Z_NULL;        s->stream.avail_in = s->stream.avail_out = 0;        s->bufsize = bufsize ;	s->dictionary = (SV*)NULL ;	s->dict_adler = 0 ;    }    return s ;    }#define SIZE 4096static int#ifdef CAN_PROTOTYPEgzreadline(Compress__Zlib__gzFile file, SV * output)#elsegzreadline(file, output)  Compress__Zlib__gzFile file ;  SV * output ;#endif{    SV * store = file->buffer ;    char *nl = "\n";     char *p;    char *out_ptr = SvPVX(store) ;    int n;    while (1) {	/* anything left from last time */	if (n = SvCUR(store)) {    	    out_ptr = SvPVX(store) + file->offset ;	    if (p = ninstr(out_ptr, out_ptr + n - 1, nl, nl)) {            /* if (rschar != 0777 && */                /* p = ninstr(out_ptr, out_ptr + n - 1, rs, rs+rslen-1)) { */         	sv_catpvn(output, out_ptr, p - out_ptr + 1);		file->offset += (p - out_ptr + 1) ;	        n = n - (p - out_ptr + 1);	        SvCUR_set(store, n) ;	        return SvCUR(output);            }	    else /* no EOL, so append the complete buffer */         	sv_catpvn(output, out_ptr, n);	    	}	SvCUR_set(store, 0) ;	file->offset = 0 ;        out_ptr = SvPVX(store) ;	n = gzread(file->gz, out_ptr, SIZE) ;	if (n <= 0) 	    /* Either EOF or an error */	    /* so return what we have so far else signal eof */	    return (SvCUR(output)>0) ? SvCUR(output) : n ;	SvCUR_set(store, n) ;    }}static SV* #ifdef CAN_PROTOTYPEdeRef(SV * sv, char * string)#elsedeRef(sv, string)SV * sv ;char * string;#endif{    if (SvROK(sv)) {	sv = SvRV(sv) ;	switch(SvTYPE(sv)) {            case SVt_PVAV:            case SVt_PVHV:            case SVt_PVCV:                croak("%s: buffer parameter is not a SCALAR reference", string);	}	if (SvROK(sv))	    croak("%s: buffer parameter is a reference to a reference", string) ;    }    if (!SvOK(sv)) {         sv = sv_NULL ;    }	    return sv ;}static double#ifdef CAN_PROTOTYPEconstant(char * name, int arg)#elseconstant(name, arg)char *name;int arg;#endif{    errno = 0;    switch (*name) {    case 'A':	break;    case 'B':	break;    case 'C':	break;    case 'D':	if (strEQ(name, "DEF_WBITS"))#ifdef DEF_WBITS	    return DEF_WBITS;#else	    goto not_there;#endif	break;    case 'E':	break;    case 'F':	    goto not_there;	break;    case 'G':	break;    case 'H':	break;    case 'I':	break;    case 'J':	break;    case 'K':	break;    case 'L':	break;    case 'M':	if (strEQ(name, "MAX_MEM_LEVEL"))#ifdef MAX_MEM_LEVEL	    return MAX_MEM_LEVEL;#else	    goto not_there;#endif	if (strEQ(name, "MAX_WBITS"))#ifdef MAX_WBITS	    return MAX_WBITS;#else	    goto not_there;#endif	break;    case 'N':	break;    case 'O':	if (strEQ(name, "OS_CODE"))#ifdef OS_CODE	    return OS_CODE;#else	    goto not_there;#endif	break;    case 'P':	break;    case 'Q':	break;    case 'R':	break;    case 'S':	break;    case 'T':	break;    case 'U':	break;    case 'V':	break;    case 'W':	break;    case 'X':	break;    case 'Y':	break;    case 'Z':	if (strEQ(name, "Z_ASCII"))#ifdef Z_ASCII	    return Z_ASCII;#else	    goto not_there;#endif	if (strEQ(name, "Z_BEST_COMPRESSION"))#ifdef Z_BEST_COMPRESSION	    return Z_BEST_COMPRESSION;#else	    goto not_there;#endif	if (strEQ(name, "Z_BEST_SPEED"))#ifdef Z_BEST_SPEED	    return Z_BEST_SPEED;#else	    goto not_there;#endif	if (strEQ(name, "Z_BINARY"))#ifdef Z_BINARY	    return Z_BINARY;#else	    goto not_there;#endif	if (strEQ(name, "Z_BUF_ERROR"))#ifdef Z_BUF_ERROR	    return Z_BUF_ERROR;#else	    goto not_there;#endif	if (strEQ(name, "Z_DATA_ERROR"))#ifdef Z_DATA_ERROR	    return Z_DATA_ERROR;#else	    goto not_there;#endif	if (strEQ(name, "Z_DEFAULT_COMPRESSION"))#ifdef Z_DEFAULT_COMPRESSION	    return Z_DEFAULT_COMPRESSION;#else	    goto not_there;#endif	if (strEQ(name, "Z_DEFAULT_STRATEGY"))#ifdef Z_DEFAULT_STRATEGY	    return Z_DEFAULT_STRATEGY;#else	    goto not_there;#endif	if (strEQ(name, "Z_DEFLATED"))#ifdef Z_DEFLATED	    return Z_DEFLATED;#else	    goto not_there;#endif	if (strEQ(name, "Z_ERRNO"))#ifdef Z_ERRNO	    return Z_ERRNO;#else	    goto not_there;#endif	if (strEQ(name, "Z_FILTERED"))#ifdef Z_FILTERED	    return Z_FILTERED;#else	    goto not_there;#endif	if (strEQ(name, "Z_FINISH"))#ifdef Z_FINISH	    return Z_FINISH;#else	    goto not_there;#endif	if (strEQ(name, "Z_FULL_FLUSH"))#ifdef Z_FULL_FLUSH	    return Z_FULL_FLUSH;#else	    goto not_there;#endif	if (strEQ(name, "Z_HUFFMAN_ONLY"))#ifdef Z_HUFFMAN_ONLY	    return Z_HUFFMAN_ONLY;#else	    goto not_there;#endif	if (strEQ(name, "Z_MEM_ERROR"))#ifdef Z_MEM_ERROR	    return Z_MEM_ERROR;#else	    goto not_there;#endif	if (strEQ(name, "Z_NEED_DICT"))#ifdef Z_NEED_DICT	    return Z_NEED_DICT;#else	    goto not_there;#endif	if (strEQ(name, "Z_NO_COMPRESSION"))#ifdef Z_NO_COMPRESSION	    return Z_NO_COMPRESSION;#else	    goto not_there;#endif	if (strEQ(name, "Z_NO_FLUSH"))#ifdef Z_NO_FLUSH	    return Z_NO_FLUSH;#else	    goto not_there;#endif	if (strEQ(name, "Z_NULL"))#ifdef Z_NULL	    return Z_NULL;#else	    goto not_there;#endif	if (strEQ(name, "Z_OK"))#ifdef Z_OK	    return Z_OK;#else	    goto not_there;#endif	if (strEQ(name, "Z_PARTIAL_FLUSH"))#ifdef Z_PARTIAL_FLUSH	    return Z_PARTIAL_FLUSH;#else	    goto not_there;#endif	if (strEQ(name, "Z_STREAM_END"))#ifdef Z_STREAM_END	    return Z_STREAM_END;#else	    goto not_there;#endif	if (strEQ(name, "Z_STREAM_ERROR"))#ifdef Z_STREAM_ERROR	    return Z_STREAM_ERROR;#else	    goto not_there;#endif	if (strEQ(name, "Z_SYNC_FLUSH"))#ifdef Z_SYNC_FLUSH	    return Z_SYNC_FLUSH;#else	    goto not_there;#endif	if (strEQ(name, "Z_UNKNOWN"))#ifdef Z_UNKNOWN	    return Z_UNKNOWN;#else	    goto not_there;#endif	if (strEQ(name, "Z_VERSION_ERROR"))#ifdef Z_VERSION_ERROR	    return Z_VERSION_ERROR;#else	    goto not_there;#endif	break;    }    errno = EINVAL;    return 0;not_there:    errno = ENOENT;    return 0;}MODULE = Compress::Zlib		PACKAGE = Compress::Zlib	PREFIX = Zip_REQUIRE:	1.924PROTOTYPES:	DISABLEBOOT:    /* Check this version of zlib is == 1 */    if (zlibVersion()[0] != '1')	croak("Compress::Zlib needs zlib version 1.x\n") ;	    {        /* Create the $gzerror scalar */        SV * gzerror_sv = perl_get_sv(GZERRNO, GV_ADDMULTI) ;        sv_setiv(gzerror_sv, 0) ;        sv_setpv(gzerror_sv, "") ;        SvIOK_on(gzerror_sv) ;    }    sv_NULL = newSVpv("", 0);#define Zip_zlib_version()	(char*)zlib_versionchar*Zip_zlib_version()#define Zip_ZLIB_VERSION()	ZLIB_VERSIONchar *Zip_ZLIB_VERSION()doubleconstant(name,arg)	char *		name	int		argCompress::Zlib::gzFilegzopen_(path, mode)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -