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

📄 htfwriter.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (LYPrependBaseToSource &&	!strncasecomp(pres->rep->name, "text/html", 9) &&	!anchor->content_encoding) {	/*	 *  Add the document's base as a BASE tag at the top of the file,	 *  so that any partial or relative URLs within it will be resolved	 *  relative to that if no BASE tag is present and replaces it.	 *  Note that the markup will be technically invalid if a DOCTYPE	 *  declaration, or HTML or HEAD tags, are present, and thus the	 *  file may need editing for perfection. - FM	 */	char *temp = NULL;	if (anchor->content_base && *anchor->content_base) {	    StrAllocCopy(temp, anchor->content_base);	} else if (anchor->content_location && *anchor->content_location) {	    StrAllocCopy(temp, anchor->content_location);	}	if (temp) {	    collapse_spaces(temp);	    if (!is_url(temp)) {		FREE(temp);	    }	}	fprintf(ret_obj->fp,		"<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n",		anchor->address, (temp ? temp : anchor->address));	FREE(temp);    }    if (LYPrependCharsetToSource &&	!strncasecomp(pres->rep->name, "text/html", 9) &&	!anchor->content_encoding) {	/*	 *  Add the document's charset as a META CHARSET tag	 *  at the top of the file, so HTTP charset header	 *  will not be forgotten when a document saved as local file.	 *  We add this line only(!) if HTTP charset present. - LP	 *  Note that the markup will be technically invalid if a DOCTYPE	 *  declaration, or HTML or HEAD tags, are present, and thus the	 *  file may need editing for perfection. - FM	 */	char *temp = NULL;	if (anchor->charset && *anchor->charset) {	    StrAllocCopy(temp, anchor->charset);	    collapse_spaces(temp);		fprintf(ret_obj->fp,		"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\">\n\n",		temp);	}	FREE(temp);    }    return ret_obj;}/*	Set up stream for uncompressing - FM**	-------------------------------*/PUBLIC HTStream* HTCompressed ARGS3(	HTPresentation *,	pres,	HTParentAnchor *,	anchor,	HTStream *,		sink){    HTStream* me;    HTFormat format;    char *type = NULL;    HTPresentation *Pres = NULL;    int n, i;    BOOL can_present = FALSE;    char fnam[256];    CONST char *suffix;    char *uncompress_mask = NULL;    char *compress_suffix = "";    char *cp;    CONST char *middle;    FILE *fp = NULL;    /*     *	Deal with any inappropriate invokations of this function,     *	or a download request, in which case we won't bother to     *	uncompress the file. - FM     */    if (!(anchor && anchor->content_encoding && anchor->content_type)) {	/*	 *  We have no idea what we're dealing with,	 *  so treat it as a binary stream. - FM	 */	format = HTAtom_for("application/octet-stream");	me = HTStreamStack(format, pres->rep_out, sink, anchor);	return me;    }    n = HTList_count(HTPresentations);    for (i = 0; i < n; i++) {	Pres = (HTPresentation *)HTList_objectAt(HTPresentations, i);	if (!strcasecomp(Pres->rep->name, anchor->content_type) &&	    Pres->rep_out == WWW_PRESENT) {	    /*	     *	We have a presentation mapping for it. - FM	     */	    can_present = TRUE;	    if (!strcasecomp(anchor->content_encoding, "x-gzip") ||		!strcasecomp(anchor->content_encoding, "gzip")) {		/*		 *  It's compressed with the modern gzip. - FM		 */		StrAllocCopy(uncompress_mask, GZIP_PATH);		StrAllocCat(uncompress_mask, " -d --no-name %s");		compress_suffix = "gz";	    } else if (!strcasecomp(anchor->content_encoding, "x-compress") ||		       !strcasecomp(anchor->content_encoding, "compress")) {		/*		 *  It's compressed the old fashioned Unix way. - FM		 */		StrAllocCopy(uncompress_mask, UNCOMPRESS_PATH);		StrAllocCat(uncompress_mask, " %s");		compress_suffix = "Z";	    }	    break;	}    }    if (can_present == FALSE || 		 /* no presentation mapping */	uncompress_mask == NULL ||		    /* not gzip or compress */	strchr(anchor->content_type, ';') ||		   /* wrong charset */	HTOutputFormat == HTAtom_for("www/download") || 	/* download */	!strcasecomp(pres->rep_out->name, "www/download") ||	/* download */	(traversal &&	   /* only handle html or plain text for traversals */	 strcasecomp(anchor->content_type, "text/html") &&	 strcasecomp(anchor->content_type, "text/plain"))) {	/*	 *  Cast the Content-Encoding to a Content-Type	 *  and pass it back to be handled as that type. - FM	 */	if (strchr(anchor->content_encoding, '/') == NULL) {	    StrAllocCopy(type, "application/");	    StrAllocCat(type, anchor->content_encoding);	} else {	    StrAllocCopy(type, anchor->content_encoding);	}	format = HTAtom_for(type);	FREE(type)	FREE(uncompress_mask);	me = HTStreamStack(format, pres->rep_out, sink, anchor);	return me;    }    /*     *	Set up the stream structure for uncompressing and then     *	handling based on the uncompressed Content-Type.- FM     */    me = (HTStream*)calloc(sizeof(*me),1);    if (me == NULL)	outofmem(__FILE__, "HTCompressed");    me->isa = &HTFWriter;    me->input_format = pres->rep;    me->output_format = pres->rep_out;    me->anchor = anchor;    me->sink = sink;    /*     *	Remove any old versions of the file. - FM     */    if (anchor->FileCache) {	while ((fp = fopen(anchor->FileCache, "r")) != NULL) {	    fclose(fp);	    remove(anchor->FileCache);	}	FREE(anchor->FileCache);    }    /*     *	Get a new temporary filename and substitute a suitable suffix. - FM     */Compressed_tempname:    tempname(fnam, NEW_FILE);    if ((cp = strrchr(fnam, '.')) != NULL) {	middle = NULL;	if (!strcasecomp(anchor->content_type, "text/html")) {	    middle = HTML_SUFFIX;	    middle++;		/* point to 'h' of .htm(l) - kw */	} else if (!strcasecomp(anchor->content_type, "text/plain")) {	    middle = "txt";	} else if (!strcasecomp(anchor->content_type,				"application/octet-stream")) {	    middle = "bin";	} else if ((suffix =		    HTFileSuffix(HTAtom_for(anchor->content_type), NULL)) &&		   *suffix == '.') {#if defined(VMS) || defined(FNAMES_8_3)	    if (strchr(suffix + 1, '.') == NULL)#endif		middle = suffix + 1;	}	if (middle) {	    *cp = '\0';#ifdef FNAMES_8_3	    me->idash = strlen(fnam);	  /* remember position of '-'  - kw */	    strcat(fnam, "-");	/* NAME-htm,  NAME-txt, etc. - hack for DOS */#else	    strcat(fnam, ".");	/* NAME.html, NAME-txt etc. */#endif /* FNAMES_8_3 */	    strcat(fnam, middle);#ifdef VMS	    strcat(fnam, "-");	/* NAME.html-gz, NAME.txt-gz, NAME.txt-Z etc.*/#else	    strcat(fnam, ".");	/* NAME-htm.gz (DOS), NAME.html.gz (UNIX)etc.*/#endif /* VMS */	} else {	    *(cp + 1) = '\0';	}    } else {	strcat(fnam, ".");    }    strcat(fnam, compress_suffix);    /*     *	It's not one of the suffixes checked for a     *	spoof in tempname(), so check it now. - FM     */    if ((fp = fopen(fnam, "r")) != NULL) {	fclose(fp);	fp = NULL;	goto Compressed_tempname;    }    /*     *	Open the file for receiving the compressed input stream. - FM     */    me->fp = LYNewBinFile (fnam);    if (!me->fp) {	HTAlert(CANNOT_OPEN_TEMP);	FREE(uncompress_mask);	FREE(me);	return NULL;    }    /*     *	me->viewer_command will be NULL if the converter Pres found above     *	is not for an external viewer but an internal HTStream converter.     *	We also don't set it under conditions where HTSaveAndExecute would     *	disallow execution of the command. - KW     */    if (!dump_output_immediately && !traversal#if defined(EXEC_LINKS) || defined(EXEC_SCRIPTS)	&& (Pres->quality != 999.0 ||	    (!no_exec &&	/* allowed exec link or script ? */	     (local_exec ||	      (local_exec_on_local_files &&	       (LYJumpFileURL ||		!strncmp(anchor->address,"file://localhost",16))))))#endif /* EXEC_LINKS || EXEC_SCRIPTS */	) {	StrAllocCopy(me->viewer_command, Pres->command);    }    /*     *	Make command to process file. - FM     */#ifdef USE_ZLIB    if (compress_suffix[0] == 'g' && /* must be gzip */	!me->viewer_command) {	/*	 *  We won't call gzip externally, so we don't need to supply	 *  a command for it. - kw	 */	StrAllocCopy(me->end_command, "");    } else#endif /* USE_ZLIB */    {	me->end_command = (char *)calloc(1, (strlen(uncompress_mask) + 10 +					     strlen(fnam)) * sizeof(char));	if (me->end_command == NULL)	    outofmem(__FILE__, "HTCompressed");	sprintf(me->end_command, uncompress_mask, fnam, "", "", "", "", "", "");    }    FREE(uncompress_mask);    /*     *	Make command to delete file. - FM     */    me->remove_command = (char *)calloc(1, (strlen(REMOVE_COMMAND) + 10 +					    strlen(fnam)) * sizeof(char));    if (me->remove_command == NULL)	outofmem(__FILE__, "HTCompressed");    sprintf(me->remove_command, REMOVE_COMMAND, fnam);    /*     *	Save the filename and return the structure. - FM     */    StrAllocCopy(anchor->FileCache, fnam);    return me;}/*	Dump output to stdout - LJM & FM**	---------------------***/PUBLIC HTStream* HTDumpToStdout ARGS3(	HTPresentation *,	pres GCC_UNUSED,	HTParentAnchor *,	anchor,	HTStream *,		sink GCC_UNUSED){    HTStream * ret_obj;    ret_obj = (HTStream*)calloc(sizeof(* ret_obj),1);    if (ret_obj == NULL)	outofmem(__FILE__, "HTDumpToStdout");    ret_obj->isa = &HTFWriter;    ret_obj->remove_command = NULL;    ret_obj->end_command = NULL;    ret_obj->anchor = anchor;    ret_obj->fp = stdout; /* stdout*/    return ret_obj;}#if defined(VMS) && !defined(USE_COMMAND_FILE)#include <fab.h>#include <rmsdef.h>		/* RMS status codes */#include <iodef.h>		/* I/O function codes */#include <fibdef.h>		/* file information block defs */#include <atrdef.h>		/* attribute request codes */#ifdef NOTDEFINED /*** Not all versions of VMS compilers have these.	 ***/#include <fchdef.h>		/* file characteristics */#include <fatdef.h>		/* file attribute defs */#else		  /*** So we'll define what we need from them ourselves. ***/#define FCH$V_CONTIGB	0x005			/* pos of cont best try bit */#define FCH$M_CONTIGB	(1 << FCH$V_CONTIGB)	/* contig best try bit mask *//* VMS I/O User's Reference Manual: Part I (V5.x doc set) */struct fatdef {    unsigned char	fat$b_rtype,	fat$b_rattrib;    unsigned short	fat$w_rsize;    unsigned long	fat$l_hiblk,	fat$l_efblk;    unsigned short	fat$w_ffbyte;    unsigned char	fat$b_bktsize,	fat$b_vfcsize;    unsigned short	fat$w_maxrec,	fat$w_defext,	fat$w_gbc;    unsigned	: 16, : 32, : 16;   /* 6 bytes reserved, 2 bytes not used */    unsigned short	fat$w_versions;};#endif /* NOTDEFINED *//* arbitrary descriptor without type and class info */typedef struct dsc { unsigned short len, mbz; void *adr; } Desc;extern unsigned long	sys$open(),  sys$qiow(),  sys$dassgn();#define syswork(sts)	((sts) & 1)#define sysfail(sts)	(!syswork(sts))/* *  25-Jul-1995 - Pat Rankin (rankin@eql.caltech.edu) * *  Force a file to be marked as having fixed-length, 512 byte records *  without implied carriage control, and with best_try_contiguous set. */PUBLIC unsigned long LYVMS_FixedLengthRecords ARGS1(char *, filename){    struct FAB	    fab;		/* RMS file access block */    struct fibdef   fib;		/* XQP file information block */    struct fatdef   recattr;		/* XQP file "record" attributes */    struct atrdef   attr_rqst_list[3];	/* XQP attribute request itemlist */    Desc	    fib_dsc;    unsigned short  channel,  iosb[4];    unsigned long   fchars,  sts,  tmp;    /* initialize file access block */    fab = cc$rms_fab;    fab.fab$l_fna = filename;    fab.fab$b_fns = (unsigned char) strlen(filename);    fab.fab$l_fop = FAB$M_UFO;	/* user file open; no further RMS processing */    fab.fab$b_fac = FAB$M_PUT;	/* need write access */    fab.fab$b_shr = FAB$M_NIL;	/* exclusive access */    sts = sys$open(&fab);	/* channel in stv; $dassgn to close */    if (sts == RMS$_FLK) {	/* For MultiNet, at least, if the file was just written by a remote	   NFS client, the local NFS server might still have it open, and the	   failed access attempt will provoke it to be closed, so try again. */	sts = sys$open(&fab);    }    if (sysfail(sts)) return sts;    /* RMS supplies a user-mode channel (see FAB$L_FOP FAB$V_UFO doc) */    channel = (unsigned short) fab.fab$l_stv;    /* set up ACP interface strutures */    /* file information block, passed by descriptor; it's okay to start with       an empty FIB after RMS has accessed the file for us */    fib_dsc.len = sizeof fib;    fib_dsc.mbz = 0;    fib_dsc.adr = &fib;    memset((void *)&fib, 0, sizeof fib);    /* attribute request list */    attr_rqst_list[0].atr$w_size = sizeof recattr;    attr_rqst_list[0].atr$w_type = ATR$C_RECATTR;    *(void **)&attr_rqst_list[0].atr$l_addr = (void *)&recattr;    attr_rqst_list[1].atr$w_size = sizeof fchars;    attr_rqst_list[1].atr$w_type = ATR$C_UCHAR;    *(void **)&attr_rqst_list[1].atr$l_addr = (void *)&fchars;    attr_rqst_list[2].atr$w_size = attr_rqst_list[2].atr$w_type = 0;    attr_rqst_list[2].atr$l_addr = 0;    /* file "record" attributes */    memset((void *)&recattr, 0, sizeof recattr);    fchars = 0; 	/* file characteristics */    /* get current attributes */    sts = sys$qiow(0, channel, IO$_ACCESS, iosb, (void(*)())0, 0,		   &fib_dsc, 0, 0, 0, attr_rqst_list, 0);    if (syswork(sts))	sts = iosb[0];    /* set desired attributes */    if (syswork(sts)) {	recattr.fat$b_rtype = FAB$C_SEQ | FAB$C_FIX;	/* org=seq, rfm=fix */	recattr.fat$w_rsize = recattr.fat$w_maxrec = 512;   /* lrl=mrs=512 */	recattr.fat$b_rattrib = 0;			/* rat=none */	fchars |= FCH$M_CONTIGB;		/* contiguous-best-try */	sts = sys$qiow(0, channel, IO$_DEACCESS, iosb, (void(*)())0, 0,		       &fib_dsc, 0, 0, 0, attr_rqst_list, 0);	if (syswork(sts))	    sts = iosb[0];    }    /* all done */    tmp = sys$dassgn(channel);    if (syswork(sts))	sts = tmp;    return sts;}#endif /* VMS && !USE_COMMAND_FILE */

⌨️ 快捷键说明

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