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

📄 htfile.c

📁 elinks下lynx是最重要的二个文本浏览器, 在linux下非常实用, lynx比elinks早的多, 目前好像停止开发, 这是lynx源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    StrAllocCopy(suff->desc, desc);    suff->quality = (float) value;}#ifdef LY_FIND_LEAKS/***	Purpose:	Free all added suffixes.**	Arguments:	void**	Return Value:	void**	Remarks/Portability/Dependencies/Restrictions:**		To be used at program exit.**	Revision History:**		05-28-94	created Lynx 2-3-1 Garrett Arch Blythe*/PRIVATE void free_suffixes NOARGS{    HTSuffix * suff = NULL;    /*    **	Loop through all suffixes.    */    while (!HTList_isEmpty(HTSuffixes)) {	/*	**  Free off each item and its members if need be.	*/	suff = (HTSuffix *)HTList_removeLastObject(HTSuffixes);	FREE(suff->suffix);	FREE(suff->desc);	FREE(suff);    }    /*    **	Free off the list itself.    */    HTList_delete(HTSuffixes);    HTSuffixes = NULL;}#endif /* LY_FIND_LEAKS *//*	Make the cache file name for a W3 document.**	-------------------------------------------**	Make up a suitable name for saving the node in****	E.g.	/tmp/WWW_Cache_news/1234@cernvax.cern.ch**		/tmp/WWW_Cache_http/crnvmc/FIND/xx.xxx.xx****  On exit:**	Returns a malloc'ed string which must be freed by the caller.*/PUBLIC char * HTCacheFileName ARGS1(	CONST char *,	name){    char * acc_method = HTParse(name, "", PARSE_ACCESS);    char * host = HTParse(name, "", PARSE_HOST);    char * path = HTParse(name, "", PARSE_PATH+PARSE_PUNCTUATION);    char * result = NULL;    HTSprintf0(&result, "%s/WWW/%s/%s%s", HTCacheRoot, acc_method, host, path);    FREE(path);    FREE(acc_method);    FREE(host);    return result;}/*	Open a file for write, creating the path.**	-----------------------------------------*/#ifdef NOT_IMPLEMENTEDPRIVATE int HTCreatePath ARGS1(CONST char *,path){    return -1;}#endif /* NOT_IMPLEMENTED *//*	Convert filename from URL-path syntax to local path format**	----------------------------------------------------------**	Input name is assumed to be the URL-path of a local file**      URL, i.e. what comes after the "file://localhost".**      '#'-fragments to be treated as such must already be stripped.**      If expand_all is FALSE, unescape only escaped '/'. - kw****  On exit:**	Returns a malloc'ed string which must be freed by the caller.*/PUBLIC char * HTURLPath_toFile ARGS3(	CONST char *,	name,	BOOL,		expand_all,	BOOL,		is_remote GCC_UNUSED){    char * path = NULL;    char * result = NULL;    StrAllocCopy(path, name);    if (expand_all)	HTUnEscape(path);		/* Interpret all % signs */    else	HTUnEscapeSome(path, "/");	/* Interpret % signs for path delims */    CTRACE((tfp, "URLPath `%s' means path `%s'\n", name, path));#if defined(USE_DOS_DRIVES)    StrAllocCopy(result, is_remote ? path : HTDOS_name(path));#else    StrAllocCopy(result, path);#endif    FREE(path);    return result;}/*	Convert filenames between local and WWW formats.**	------------------------------------------------**	Make up a suitable name for saving the node in****	E.g.	$(HOME)/WWW/news/1234@cernvax.cern.ch**		$(HOME)/WWW/http/crnvmc/FIND/xx.xxx.xx****  On exit:**	Returns a malloc'ed string which must be freed by the caller.*//* NOTE: Don't use this function if you know that the input is a URL path	 rather than a full URL, use HTURLPath_toFile instead.  Otherwise	 this function will return the wrong thing for some unusual	 paths (like ones containing "//", possibly escaped). - kw*/PUBLIC char * HTnameOfFile_WWW ARGS3(	CONST char *,	name,	BOOL,		WWW_prefix,	BOOL,		expand_all){    char * acc_method = HTParse(name, "", PARSE_ACCESS);    char * host = HTParse(name, "", PARSE_HOST);    char * path = HTParse(name, "", PARSE_PATH+PARSE_PUNCTUATION);    char * home;    char * result = NULL;    if (expand_all) {	HTUnEscape(path);		/* Interpret all % signs */    } else	HTUnEscapeSome(path, "/");	/* Interpret % signs for path delims */    if (0 == strcmp(acc_method, "file")	/* local file */     || !*acc_method) {			/* implicitly local? */	if ((0 == strcasecomp(host, HTHostName())) ||	    (0 == strcasecomp(host, "localhost")) || !*host) {	    CTRACE((tfp, "Node `%s' means path `%s'\n", name, path));	    StrAllocCopy(result, HTSYS_name(path));	} else if (WWW_prefix) {	    HTSprintf0(&result, "%s%s%s", "/Net/", host, path);	    CTRACE((tfp, "Node `%s' means file `%s'\n", name, result));	} else {	    StrAllocCopy(result, path);	}    } else if (WWW_prefix) {  /* other access */#ifdef VMS	if ((home = LYGetEnv("HOME")) == 0)	    home = HTCacheRoot;	else	    home = HTVMS_wwwName(home);#else#if defined(_WINDOWS)	/* 1997/10/16 (Thu) 20:42:51 */	home =  (char *)Home_Dir();#else	home = LYGetEnv("HOME");#endif	if (home == 0)	    home = "/tmp";#endif /* VMS */	HTSprintf0(&result, "%s/WWW/%s/%s%s", home, acc_method, host, path);    } else {	StrAllocCopy(result, path);    }    FREE(host);    FREE(path);    FREE(acc_method);    CTRACE((tfp, "HTnameOfFile_WWW(%s,%d,%d) = %s\n",	    name, WWW_prefix, expand_all, result));    return result;}/*	Make a WWW name from a full local path name.**	--------------------------------------------****  Bugs:**	At present, only the names of two network root nodes are hand-coded**	in and valid for the NeXT only.  This should be configurable in**	the general case.*/PUBLIC char * WWW_nameOfFile ARGS1(	CONST char *,	name){    char * result = NULL;#ifdef NeXT    if (0 == strncmp("/private/Net/", name, 13)) {	HTSprintf0(&result, "%s//%s", STR_FILE_URL, name+13);    } else#endif /* NeXT */    if (0 == strncmp(HTMountRoot, name, 5)) {	HTSprintf0(&result, "%s//%s", STR_FILE_URL, name+5);    } else {	HTSprintf0(&result, "%s//%s%s", STR_FILE_URL, HTHostName(), name);    }    CTRACE((tfp, "File `%s'\n\tmeans node `%s'\n", name, result));    return result;}/*	Determine a suitable suffix, given the representation.**	------------------------------------------------------****  On entry,**	rep	is the atomized MIME style representation**	enc	is an encoding, trivial (8bit, binary, etc.) or gzip etc.****  On exit:**	Returns a pointer to a suitable suffix string if one has been**	found, else "".*/PUBLIC CONST char * HTFileSuffix ARGS2(	HTAtom*,	rep,	CONST char *,	enc){    HTSuffix * suff;#ifdef FNAMES_8_3    HTSuffix * first_found = NULL;#endif    BOOL trivial_enc;    int n;    int i;#define NO_INIT  /* don't init anymore since I do it in Lynx at startup */#ifndef NO_INIT    if (!HTSuffixes)	HTFileInit();#endif /* !NO_INIT */    trivial_enc = (BOOL) IsUnityEncStr(enc);    n = HTList_count(HTSuffixes);    for (i = 0; i < n; i++) {	suff = (HTSuffix *)HTList_objectAt(HTSuffixes, i);	if (suff->rep == rep &&#if defined(VMS) || defined(FNAMES_8_3)	    /*	Don't return a suffix whose first char is a dot, and which		has more dots or asterisks after that, for		these systems - kw */	    (!suff->suffix || !suff->suffix[0] || suff->suffix[0] != '.' ||	     (strchr(suff->suffix + 1, '.') == NULL &&	      strchr(suff->suffix + 1, '*') == NULL)) &&#endif	    ((trivial_enc && IsUnityEnc(suff->encoding)) ||	     (!trivial_enc && !IsUnityEnc(suff->encoding) &&	      strcmp(enc, HTAtom_name(suff->encoding)) == 0))) {#ifdef FNAMES_8_3	    if (suff->suffix && (strlen(suff->suffix) <= 4)) {		/*		 *  If length of suffix (including dot) is 4 or smaller,		 *  return this one even if we found a longer one		 *  earlier - kw		 */		return suff->suffix;	    } else if (!first_found) {		first_found = suff;		/* remember this one */	    }#else	    return suff->suffix;		/* OK -- found */#endif	}    }#ifdef FNAMES_8_3    if (first_found)	return first_found->suffix;#endif    return "";		/* Dunno */}/*	Determine file format from file name.**	-------------------------------------****	This version will return the representation and also set**	a variable for the encoding.****	Encoding may be a unity encoding (binary, 8bit, etc.) or**	a content-coding like gzip, compress.****	It will handle for example  x.txt, x.txt,Z, x.Z*/PUBLIC HTFormat HTFileFormat ARGS3(	CONST char *,	filename,	HTAtom **,	pencoding,	CONST char**,	pdesc){    HTSuffix * suff;    int n;    int i;    int lf;#ifdef VMS    char *semicolon = NULL;#endif /* VMS */    if (pencoding)	*pencoding = NULL;    if (pdesc)	*pdesc = NULL;    if (LYforce_HTML_mode) {	if (pencoding)	    *pencoding = WWW_ENC_8BIT;	return WWW_HTML;    }#ifdef VMS    /*    **	Trim at semicolon if a version number was    **	included, so it doesn't interfere with the    **	code for getting the MIME type. - FM    */    if ((semicolon = strchr(filename, ';')) != NULL)	*semicolon = '\0';#endif /* VMS */#ifndef NO_INIT    if (!HTSuffixes)	HTFileInit();#endif /* !NO_INIT */    lf	= strlen(filename);    n = HTList_count(HTSuffixes);    for (i = 0; i < n; i++) {	int ls;	suff = (HTSuffix *)HTList_objectAt(HTSuffixes, i);	ls = strlen(suff->suffix);	if ((ls <= lf) && 0 == strcasecomp(suff->suffix, filename + lf - ls)) {	    int j;	    if (pencoding)		*pencoding = suff->encoding;	    if (pdesc)		*pdesc = suff->desc;	    if (suff->rep) {#ifdef VMS		if (semicolon != NULL)		    *semicolon = ';';#endif /* VMS */		return suff->rep;		/* OK -- found */	    }	    for (j = 0; j < n; j++) {  /* Got encoding, need representation */		int ls2;		suff = (HTSuffix *)HTList_objectAt(HTSuffixes, j);		ls2 = strlen(suff->suffix);		if ((ls + ls2 <= lf) && 0 == strncasecomp(			suff->suffix, filename + lf - ls -ls2, ls2)) {		    if (suff->rep) {			if (pdesc && !(*pdesc))			    *pdesc = suff->desc;			if (pencoding && IsUnityEnc(*pencoding) &&			    *pencoding != WWW_ENC_7BIT &&			    !IsUnityEnc(suff->encoding))			    *pencoding = suff->encoding;#ifdef VMS			if (semicolon != NULL)			    *semicolon = ';';#endif /* VMS */			return suff->rep;		    }		}	    }	}    }    /* defaults tree */    suff = strchr(filename, '.') ?	/* Unknown suffix */	 ( unknown_suffix.rep ? &unknown_suffix : &no_suffix)	 : &no_suffix;    /*    **	Set default encoding unless found with suffix already.    */    if (pencoding && !*pencoding)	*pencoding = suff->encoding ? suff->encoding				    : HTAtom_for("binary");#ifdef VMS    if (semicolon != NULL)	*semicolon = ';';#endif /* VMS */    return suff->rep ? suff->rep : WWW_BINARY;}/*	Revise the file format in relation to the Lynx charset. - FM**	-------------------------------------------------------****	This checks the format associated with an anchor for**	an extended MIME Content-Type, and if a charset is**	indicated, sets Lynx up for proper handling in relation**	to the currently selected character set. - FM*/PUBLIC HTFormat HTCharsetFormat ARGS3(	HTFormat,		format,	HTParentAnchor *,	anchor,	int,			default_LYhndl){    char *cp = NULL, *cp1, *cp2, *cp3 = NULL, *cp4;    BOOL chartrans_ok = FALSE;    int chndl = -1;    FREE(anchor->charset);    StrAllocCopy(cp, format->name);    LYLowerCase(cp);    if (((cp1 = strchr(cp, ';')) != NULL) &&	(cp2 = strstr(cp1, "charset")) != NULL) {	CTRACE((tfp, "HTCharsetFormat: Extended MIME Content-Type is %s\n",		    format->name));	cp2 += 7;	while (*cp2 == ' ' || *cp2 == '=')	    cp2++;	StrAllocCopy(cp3, cp2); /* copy to mutilate more */	for (cp4 = cp3; (*cp4 != '\0' && *cp4 != '"' &&			 *cp4 != ';'  && *cp4 != ':' &&			 !WHITE(*cp4)); cp4++) {	    ; /* do nothing */	}	*cp4 = '\0';	cp4 = cp3;	chndl = UCGetLYhndl_byMIME(cp3);	if (UCCanTranslateFromTo(chndl, current_char_set)) {	    chartrans_ok = YES;	    *cp1 = '\0';	    format = HTAtom_for(cp);	    StrAllocCopy(anchor->charset, cp4);	    HTAnchor_setUCInfoStage(anchor, chndl,				    UCT_STAGE_MIME,				    UCT_SETBY_MIME);	} else if (chndl < 0) {	    /*	    **	Got something but we don't recognize it.	    */	    chndl = UCLYhndl_for_unrec;	    if (chndl < 0)	    /*	    **  UCLYhndl_for_unrec not defined :-(	    **  fallback to UCLYhndl_for_unspec which always valid.	    */	    chndl = UCLYhndl_for_unspec;  /* always >= 0 */	    if (UCCanTranslateFromTo(chndl, current_char_set)) {		chartrans_ok = YES;		HTAnchor_setUCInfoStage(anchor, chndl,					UCT_STAGE_MIME,					UCT_SETBY_DEFAULT);	    }	}	if (chartrans_ok) {	    LYUCcharset *p_in = HTAnchor_getUCInfoStage(anchor,							UCT_STAGE_MIME);	    LYUCcharset *p_out = HTAnchor_setUCInfoStage(anchor,							 current_char_set,							 UCT_STAGE_HTEXT,							 UCT_SETBY_DEFAULT);	    if (!p_out) {		/*		**  Try again.		*/		p_out = HTAnchor_getUCInfoStage(anchor, UCT_STAGE_HTEXT);	    }	    if (!strcmp(p_in->MIMEname, "x-transparent")) {		HTPassEightBitRaw = TRUE;		HTAnchor_setUCInfoStage(anchor,					HTAnchor_getUCLYhndl(anchor,							     UCT_STAGE_HTEXT),					UCT_STAGE_MIME,					UCT_SETBY_DEFAULT);	    }	    if (!strcmp(p_out->MIMEname, "x-transparent")) {		HTPassEightBitRaw = TRUE;		HTAnchor_setUCInfoStage(anchor,					HTAnchor_getUCLYhndl(anchor,							     UCT_STAGE_MIME),					UCT_STAGE_HTEXT,					UCT_SETBY_DEFAULT);	    }	    if (p_in->enc != UCT_ENC_CJK) {		HTCJK = NOCJK;		if (!(p_in->codepoints &		      UCT_CP_SUBSETOF_LAT1) &&		    chndl == current_char_set) {		    HTPassEightBitRaw = TRUE;		}	    } else if (p_out->enc == UCT_ENC_CJK) {		Set_HTCJK(p_in->MIMEname, p_out->MIMEname);	    }	} else {	    /*	    **  Cannot translate.	    **  If according to some heuristic the given	    **  charset and the current display character	    **  both are likely to be like ISO-8859 in	    **  structure, pretend we have some kind	    **  of match.	    */	    BOOL given_is_8859		= (BOOL) (!strncmp(cp4, "iso-8859-", 9) &&		   isdigit(UCH(cp4[9])));	    BOOL given_is_8859like		= (BOOL) (given_is_8859 ||		   !strncmp(cp4, "windows-", 8) ||		   !strncmp(cp4, "cp12", 4) ||		   !strncmp(cp4, "cp-12", 5));	    BOOL given_and_display_8859like		= (BOOL) (given_is_8859like &&

⌨️ 快捷键说明

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