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

📄 htformat.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 3 页
字号:
    int gzerrnum;    int rv = HT_OK;    /*	Push the data down the stream    */    targetClass = *(sink->isa); /* Copy pointers to procedures */    /*	read and inflate gzip'd file, and push binary down sink    */    HTReadProgress(bytes = 0, 0);    for (;;) {	status = gzread(gzfp, input_buffer, INPUT_BUFFER_SIZE);	if (status <= 0) { /* EOF or error */	    if (status == 0) {		rv = HT_LOADED;		break;	    }	    CTRACE((tfp, "HTGzFileCopy: Read error, gzread returns %d\n",			status));	    CTRACE((tfp, "gzerror   : %s\n",			gzerror(gzfp, &gzerrnum)));	    if (TRACE) {		if (gzerrnum == Z_ERRNO)		    perror("gzerror   ");	    }	    if (bytes) {		rv = HT_PARTIAL_CONTENT;	    } else {		rv = -1;	    }	    break;	}	(*targetClass.put_block)(sink, input_buffer, status);	bytes += status;	HTReadProgress(bytes, -1);	HTDisplayPartial();	if (HTCheckForInterrupt()) {	    _HTProgress (TRANSFER_INTERRUPTED);	    if (bytes) {		rv = HT_INTERRUPTED;	    } else {		rv = -1;	    }	    break;	}    } /* next bufferload */    HTFinishDisplayPartial();    return rv;}#endif /* USE_ZLIB *//*	Push data from a socket down a stream STRIPPING CR**	--------------------------------------------------****   This routine is responsible for creating and PRESENTING any**   graphic (or other) objects described by the socket.****   The file number given is assumed to be a TELNET stream ie containing**   CRLF at the end of lines which need to be stripped to LF for unix**   when the format is textual.***/PUBLIC void HTCopyNoCR ARGS3(	HTParentAnchor *,	anchor GCC_UNUSED,	int,			file_number,	HTStream*,		sink){    HTStreamClass targetClass;    int character;    /*	Push the data, ignoring CRLF, down the stream    */    targetClass = *(sink->isa); /* Copy pointers to procedures */    /*	Push text from telnet socket down sink    **    **	@@@@@ To push strings could be faster? (especially is we    **	cheat and don't ignore CR! :-}    */    HTInitInput(file_number);    for (;;) {	character = HTGetCharacter();	if (character == EOF)	    break;	(*targetClass.put_character)(sink, UCH(character));    }}/*	Parse a socket given format and file number****   This routine is responsible for creating and PRESENTING any**   graphic (or other) objects described by the file.****   The file number given is assumed to be a TELNET stream ie containing**   CRLF at the end of lines which need to be stripped to LF for unix**   when the format is textual.****  State of socket and target stream on entry:**			socket (file_number) assumed open,**			target (sink) usually NULL (will call stream stack).****  Return values:**	HT_INTERRUPTED  Interruption or error after some data received.**	-501		Stream stack failed (cannot present or convert).**	-2		Unexpected disconnect before any data received.**	-1		Stream stack failed (cannot present or convert), or**			Interruption or error before any data received, or**			(UNIX) other read error before any data received, or**			download cancelled.**	HT_LOADED	Normal close of socket (end of file indication**			received), or**			unexpected disconnect after some data received, or**			other read error after some data received, or**			(not UNIX) other read error before any data received.****  State of socket and target stream on return depends on return value:**	HT_INTERRUPTED	socket still open, target aborted.**	-501		socket still open, target stream NULL.**	-2		socket still open, target freed.**	-1		socket still open, target stream aborted or NULL.**	otherwise	socket closed,	target stream freed.*/PUBLIC int HTParseSocket ARGS5(	HTFormat,		rep_in,	HTFormat,		format_out,	HTParentAnchor *,	anchor,	int,			file_number,	HTStream*,		sink){    HTStream * stream;    HTStreamClass targetClass;    int rv;    stream = HTStreamStack(rep_in, format_out, sink, anchor);    if (!stream) {	char *buffer = 0;	if (LYCancelDownload) {	    LYCancelDownload = FALSE;	    return -1;	}	HTSprintf0(&buffer, CANNOT_CONVERT_I_TO_O,		HTAtom_name(rep_in), HTAtom_name(format_out));	CTRACE((tfp, "HTFormat: %s\n", buffer));	rv = HTLoadError(sink, 501, buffer); /* returns -501 */	FREE(buffer);    } else {	/*	** Push the data, don't worry about CRLF we can strip them later.	*/	targetClass = *(stream->isa);	/* Copy pointers to procedures */	rv = HTCopy(anchor, file_number, NULL, stream);	if (rv != -1 && rv != HT_INTERRUPTED)	    (*targetClass._free)(stream);    }    return rv;    /* Originally:  full: HT_LOADED;  partial: HT_INTERRUPTED;  no bytes: -1 */}/*	Parse a file given format and file pointer****   This routine is responsible for creating and PRESENTING any**   graphic (or other) objects described by the file.****   The file number given is assumed to be a TELNET stream ie containing**   CRLF at the end of lines which need to be stripped to \n for unix**   when the format is textual.****  State of file and target stream on entry:**			FILE* (fp) assumed open,**			target (sink) usually NULL (will call stream stack).****  Return values:**	-501		Stream stack failed (cannot present or convert).**	-1		Download cancelled.**	HT_NO_DATA	Error before any data read.**	HT_PARTIAL_CONTENT	Interruption or error after some data read.**	HT_LOADED	Normal end of file indication on reading.****  State of file and target stream on return:**	always		fp still open; target freed, aborted, or NULL.*/PUBLIC int HTParseFile ARGS5(	HTFormat,		rep_in,	HTFormat,		format_out,	HTParentAnchor *,	anchor,	FILE *,			fp,	HTStream*,		sink){    HTStream * stream;    HTStreamClass targetClass;    int rv;#ifdef SH_EX		/* 1998/01/04 (Sun) 16:04:09 */    if (fp == NULL)	return HT_LOADED;#endif    stream = HTStreamStack(rep_in, format_out, sink, anchor);    if (!stream) {	char *buffer = 0;	if (LYCancelDownload) {	    LYCancelDownload = FALSE;	    return -1;	}	HTSprintf0(&buffer, CANNOT_CONVERT_I_TO_O,		HTAtom_name(rep_in), HTAtom_name(format_out));	CTRACE((tfp, "HTFormat(in HTParseFile): %s\n", buffer));	rv = HTLoadError(sink, 501, buffer);	FREE(buffer);	return rv;    }    /*	Push the data down the stream    **    **	@@  Bug:  This decision ought to be made based on "encoding"    **	rather than on content-type.  @@@  When we handle encoding.    **	The current method smells anyway.    */    targetClass = *(stream->isa);	/* Copy pointers to procedures */    rv = HTFileCopy(fp, stream);    if (rv == -1 || rv == HT_INTERRUPTED) {	(*targetClass._abort)(stream, NULL);    } else {	(*targetClass._free)(stream);    }    if (rv == -1)	return HT_NO_DATA;    else if (rv == HT_INTERRUPTED || (rv > 0 && rv != HT_LOADED))	return HT_PARTIAL_CONTENT;    else	return HT_LOADED;}#ifdef SOURCE_CACHE/*	Parse a document in memory given format and memory block pointer****   This routine is responsible for creating and PRESENTING any**   graphic (or other) objects described by the file.****  State of memory and target stream on entry:**			HTChunk* (chunk) assumed valid,**			target (sink) usually NULL (will call stream stack).****  Return values:**	-501		Stream stack failed (cannot present or convert).**	HT_LOADED	All data sent.****  State of memory and target stream on return:**	always		chunk unchanged; target freed, aborted, or NULL.*/PUBLIC int HTParseMem ARGS5(	HTFormat,		rep_in,	HTFormat,		format_out,	HTParentAnchor *,	anchor,	HTChunk *,		chunk,	HTStream *,		sink){    HTStream * stream;    HTStreamClass targetClass;    int rv;    stream = HTStreamStack(rep_in, format_out, sink, anchor);    if (!stream) {	char *buffer = 0;	HTSprintf0(&buffer, CANNOT_CONVERT_I_TO_O,		   HTAtom_name(rep_in), HTAtom_name(format_out));	CTRACE((tfp, "HTFormat(in HTParseMem): %s\n", buffer));	rv = HTLoadError(sink, 501, buffer);	FREE(buffer);	return rv;    }    /* Push the data down the stream    */    targetClass = *(stream->isa);    rv = HTMemCopy(chunk, stream);    (*targetClass._free)(stream);    return HT_LOADED;}#endif#ifdef USE_ZLIBPRIVATE int HTCloseGzFile ARGS1(	gzFile,			gzfp){    int gzres;    if (gzfp == NULL)	return 0;    gzres = gzclose(gzfp);    if (TRACE) {	if (gzres == Z_ERRNO) {	    perror("gzclose   ");	} else if (gzres != Z_OK) {	    CTRACE((tfp, "gzclose   : error number %d\n", gzres));	}    }    return(gzres);}/*	HTParseGzFile****  State of file and target stream on entry:**			gzFile (gzfp) assumed open,**			target (sink) usually NULL (will call stream stack).****  Return values:**	-501		Stream stack failed (cannot present or convert).**	-1		Download cancelled.**	HT_NO_DATA	Error before any data read.**	HT_PARTIAL_CONTENT	Interruption or error after some data read.**	HT_LOADED	Normal end of file indication on reading.****  State of file and target stream on return:**	always		gzfp closed; target freed, aborted, or NULL.*/PUBLIC int HTParseGzFile ARGS5(	HTFormat,		rep_in,	HTFormat,		format_out,	HTParentAnchor *,	anchor,	gzFile,			gzfp,	HTStream*,		sink){    HTStream * stream;    HTStreamClass targetClass;    int rv;    stream = HTStreamStack(rep_in, format_out, sink, anchor);    if (!stream) {	char *buffer = 0;	HTCloseGzFile(gzfp);	if (LYCancelDownload) {	    LYCancelDownload = FALSE;	    return -1;	}	HTSprintf0(&buffer, CANNOT_CONVERT_I_TO_O,		HTAtom_name(rep_in), HTAtom_name(format_out));	CTRACE((tfp, "HTFormat(in HTParseGzFile): %s\n", buffer));	rv = HTLoadError(sink, 501, buffer);	FREE(buffer);	return rv;    }    /*	Push the data down the stream    **    **	@@  Bug:  This decision ought to be made based on "encoding"    **	rather than on content-type.  @@@  When we handle encoding.    **	The current method smells anyway.    */    targetClass = *(stream->isa);	/* Copy pointers to procedures */    rv = HTGzFileCopy(gzfp, stream);    if (rv == -1 || rv == HT_INTERRUPTED) {	(*targetClass._abort)(stream, NULL);    } else {	(*targetClass._free)(stream);    }    HTCloseGzFile(gzfp);    if (rv == -1)	return HT_NO_DATA;    else if (rv == HT_INTERRUPTED || (rv > 0 && rv != HT_LOADED))	return HT_PARTIAL_CONTENT;    else	return HT_LOADED;}#endif /* USE_ZLIB *//*	Converter stream: Network Telnet to internal character text**	-----------------------------------------------------------****	The input is assumed to be in ASCII, with lines delimited**	by (13,10) pairs, These pairs are converted into (CR,LF)**	pairs in the local representation.  The (CR,LF) sequence**	when found is changed to a '\n' character, the internal**	C representation of a new line.*/PRIVATE void NetToText_put_character ARGS2(HTStream *, me, char, net_char){    char c = FROMASCII(net_char);    if (me->had_cr) {	if (c == LF) {	    me->sink->isa->put_character(me->sink, '\n');	/* Newline */	    me->had_cr = NO;	    return;	} else {	    me->sink->isa->put_character(me->sink, CR); /* leftover */	}    }    me->had_cr = (BOOL) (c == CR);    if (!me->had_cr)	me->sink->isa->put_character(me->sink, c);		/* normal */}PRIVATE void NetToText_put_string ARGS2(HTStream *, me, CONST char *, s){    CONST char * p;    for (p = s; *p; p++)	NetToText_put_character(me, *p);}PRIVATE void NetToText_put_block ARGS3(HTStream *, me, CONST char*, s, int, l){    CONST char * p;    for (p = s; p < (s+l); p++)	NetToText_put_character(me, *p);}PRIVATE void NetToText_free ARGS1(HTStream *, me){    (me->sink->isa->_free)(me->sink);		/* Close rest of pipe */    FREE(me);}PRIVATE void NetToText_abort ARGS2(HTStream *, me, HTError, e){    me->sink->isa->_abort(me->sink,e);		/* Abort rest of pipe */    FREE(me);}/*	The class structure*/PRIVATE HTStreamClass NetToTextClass = {    "NetToText",    NetToText_free,    NetToText_abort,    NetToText_put_character,    NetToText_put_string,    NetToText_put_block};/*	The creation method*/PUBLIC HTStream * HTNetToText ARGS1(HTStream *, sink){    HTStream* me = typecalloc(HTStream);    if (me == NULL)	outofmem(__FILE__, "NetToText");    me->isa = &NetToTextClass;    me->had_cr = NO;    me->sink = sink;    return me;}PRIVATE HTStream	HTBaseStreamInstance;		      /* Made static *//***	ERROR STREAM**	------------**	There is only one error stream shared by anyone who wants a**	generic error returned from all stream methods.*/PRIVATE void HTErrorStream_put_character ARGS2(HTStream *, me GCC_UNUSED, char, c GCC_UNUSED){    LYCancelDownload = TRUE;}PRIVATE void HTErrorStream_put_string ARGS2(HTStream *, me GCC_UNUSED, CONST char *, s){    if (s && *s)	LYCancelDownload = TRUE;}PRIVATE void HTErrorStream_write ARGS3(HTStream *, me GCC_UNUSED, CONST char *, s, int, l){    if (l && s)	LYCancelDownload = TRUE;}PRIVATE void HTErrorStream_free ARGS1(HTStream *, me GCC_UNUSED){    return;}PRIVATE void HTErrorStream_abort ARGS2(HTStream *, me GCC_UNUSED, HTError, e GCC_UNUSED){    return;}PRIVATE CONST HTStreamClass HTErrorStreamClass ={    "ErrorStream",    HTErrorStream_free,    HTErrorStream_abort,    HTErrorStream_put_character,    HTErrorStream_put_string,    HTErrorStream_write};PUBLIC HTStream * HTErrorStream NOARGS{    CTRACE((tfp, "ErrorStream. Created\n"));    HTBaseStreamInstance.isa = &HTErrorStreamClass;    /* The rest is random */    return &HTBaseStreamInstance;}

⌨️ 快捷键说明

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