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

📄 html.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 5 页
字号:
		if (me->style_change) {		    if ((c == '\n') || (c == ' ') || (c == '\t'))			continue;  /* Ignore it */		    UPDATE_STYLE;		}		if (c == '\n') {		    if (me->in_word) {			if (HText_getLastChar(me->text) != ' ')			    HText_appendCharacter(me->text, ' ');			me->in_word = NO;		    }		} else if (c == ' ' || c == '\t') {		   if (HText_getLastChar(me->text) != ' ')			HText_appendCharacter(me->text, ' ');		} else if (c == '\r') {			/* ignore */		} else {		    HText_appendCharacter(me->text, c);		    me->in_word = YES;		}		/* set the Last Character */		if (c == '\n' || c == '\t') {		    /* set it to a generic seperater */		    HText_setLastChar(me->text, ' ');		} else if (c == '\r' &&			   HText_getLastChar(me->text) == ' ') {		    /*		     *	\r's are ignored.  In order to keep collapsing		     *	spaces correctly, we must default back to the		     *	previous seperator, if there was one.  So we		     *	set LastChar to a generic seperater.		     */		    HText_setLastChar(me->text, ' ');		} else {		    HText_setLastChar(me->text, c);		}	    } /* for */	}    } /* end switch */}/*	Buffer write**	------------*/PUBLIC void HTML_write ARGS3(HTStructured *, me, CONST char*, s, int, l){    CONST char* p;    CONST char* e = s+l;    if (LYMapsOnly)	return;    for (p = s; s < e; p++)	HTML_put_character(me, *p);}/* *  "Internal links" are hyperlinks whose source and destination are *  within the same document, and for which the destination is given *  as a URL Reference with an empty URL, but possibly with a non-empty *  #fragment.	(This terminology re URL-Reference vs. URL follows the *  Fielding URL syntax and semantics drafts). *  Differences: *  (1) The document's base (in whatever way it is given) is not used for *	resolving internal link references. *  (2) Activating an internal link should not result in a new retrieval *	of a copy of the document. *  (3) Internal links are the only way to refer with a hyperlink to a document *	(or a location in it) which is only known as the result of a POST *	request (doesn't have a URL from which the document can be retrieved *	with GET), and can only be used from within that document. * * *If DONT_TRACK_INTERNAL_LINKS is not defined, we keep track of whether a *  link destination was given as an internal link.  This information is *  recorded in the type of the link between anchor objects, and is available *  to the HText object and the mainloop from there.  URL References to *  internal destinations are still resolved into an absolute form before *  being passed on, but using the current stream's retrieval address instead *  of the base URL. *  Examples:  (replace [...] to have a valid absolute URL) *  In document retrieved from [...]/mypath/mydoc.htm w/ base [...]/otherpath/ *  a. HREF="[...]/mypath/mydoc.htm"	  -> [...]/mypath/mydoc.htm *  b. HREF="[...]/mypath/mydoc.htm#frag" -> [...]/mypath/mydoc.htm#frag *  c. HREF="mydoc.htm" 		  -> [...]/otherpath/mydoc.htm *  d. HREF="mydoc.htm#frag"		  -> [...]/otherpath/mydoc.htm#frag *  e. HREF=""		      -> [...]/mypath/mydoc.htm      (marked internal) *  f. HREF="#frag"	      -> [...]/mypath/mydoc.htm#frag (marked internal) * * *If DONT_TRACK_INTERNAL_LINKS is defined, URL-less URL-References are *  resolved differently from URL-References with a non-empty URL (using the *  current stream's retrieval address instead of the base), but we make no *  further distinction.  Resolution is then as in the examples above, execept *  that there is no "(marked internal)". * * *Note that this doesn't apply to form ACTIONs (always resolved using base, *  never marked internal).  Also other references encountered or generated *  are not marked internal, whether they have a URL or not, if in a given *  context an internal link makes no sense (e.g. IMG SRC=). */#ifndef DONT_TRACK_INTERNAL_LINKS/* A flag is used to keep track of whether an "URL reference" encountered   had a real "URL" or not. In the latter case, it will be marked as   "internal".	The flag is set before we start messing around with the   string (resolution of relative URLs etc.). This variable only used   locally here, don't confuse with LYinternal_flag which is for   for overriding non-caching similar to LYoverride_no_cache. - kw */#define CHECK_FOR_INTERN(s) intern_flag = (s && (*s=='#' || *s=='\0')) ? TRUE : FALSE;/* Last argument to pass to HTAnchor_findChildAndLink() calls,   just an abbreviation. - kw */#define INTERN_LT (HTLinkType *)(intern_flag ? LINK_INTERNAL : NULL)#else  /* !DONT_TRACK_INTERNAL_LINKS */#define CHECK_FOR_INTERN(s)  /* do nothing */ ;#define INTERN_LT (HTLinkType *)NULL#endif /* DONT_TRACK_INTERNAL_LINKS */#ifdef USE_COLOR_STYLEchar class_string[TEMPSTRINGSIZE];char prevailing_class[TEMPSTRINGSIZE];#endif#ifdef USE_COLOR_STYLE    char myHash[128];    int hcode;#endif/*	Start Element**	-------------*/PRIVATE void HTML_start_element ARGS6(	HTStructured *, 	me,	int,			element_number,	CONST BOOL*,		present,	CONST char **,		value,	int,			tag_charset,	char **,		include){    char *alt_string = NULL;    char *id_string = NULL;    char *href = NULL;    char *map_href = NULL;    char *title = NULL;    char *I_value = NULL;    char *I_name = NULL;    char *temp = NULL;    int dest_char_set  = -1;    HTParentAnchor *dest = NULL;	     /* An anchor's destination */    BOOL dest_ismap = FALSE;		     /* Is dest an image map script? */    BOOL UseBASE = TRUE;		     /* Resoved vs. BASE if present? */    HTChildAnchor *ID_A = NULL; 	     /* HTML_foo_ID anchor */    int url_type = 0, i = 0;    char *cp = NULL;    int ElementNumber = element_number;    BOOL intern_flag = FALSE;    if (LYMapsOnly) {	if (!(ElementNumber == HTML_MAP || ElementNumber == HTML_AREA ||	      ElementNumber == HTML_BASE)) {	    return;	}    } else if (!me->text) {	UPDATE_STYLE;    }    if (tag_charset < 0)	me->tag_charset = me->UCLYhndl;    else	me->tag_charset = tag_charset;/* this should be done differently */#if defined(USE_COLOR_STYLE)	strcat (Style_className, ";");	strcat (Style_className, HTML_dtd.tags[element_number].name);	strcpy (myHash, HTML_dtd.tags[element_number].name);	if (class_string[0])	{		strcat (Style_className, ".");		strcat (Style_className, class_string);		strcat (myHash, ".");		strcat (myHash, class_string);#ifdef PREVAIL		strcpy (prevailing_class, class_string);#endif	}#ifdef PREVAIL	else if (prevailing_class[0])	{		strcat (Style_className, ".");		strcat (Style_className, prevailing_class);		strcat (myHash, ".");		strcat (myHash, prevailing_class);	}#endif /* PREVAIL */	class_string[0]='\0';	strtolower(myHash);	hcode=hash_code(myHash);	strtolower(Style_className);	if (TRACE)	{		fprintf(stderr, "CSSTRIM:%s -> %d", myHash, hcode);		if (hashStyles[hcode].code!=hcode)		{			char *rp=strrchr(myHash, '.');			fprintf(stderr, " (undefined) %s\n", myHash);			if (rp)			{				int hcd;				*rp='\0'; /* trim the class */				hcd = hash_code(myHash);				fprintf(stderr, "CSS:%s -> %d", myHash, hcd);				if (hashStyles[hcd].code!=hcd)					fprintf(stderr, " (undefined) %s\n", myHash);				else					fprintf(stderr, " ca=%d\n", hashStyles[hcd].color);			}		}		else			fprintf(stderr, " ca=%d\n", hashStyles[hcode].color);	}    if (displayStyles[element_number + STARTAT].color > -2) /* actually set */    {	if (TRACE)		fprintf(stderr, "CSSTRIM: start_element: top <%s>\n", HTML_dtd.tags[element_number].name);	HText_characterStyle(me->text, hcode, 1);    }#endif /* USE_COLOR_STYLE */    /*     *	Handle the start tag. - FM     */    switch (ElementNumber) {    case HTML_HTML:	break;    case HTML_HEAD:	break;    case HTML_BASE:	if (present && present[HTML_BASE_HREF] && !local_host_only &&	    value[HTML_BASE_HREF] && *value[HTML_BASE_HREF]) {	    char *base = NULL;	    char *related = NULL;	    StrAllocCopy(base, value[HTML_BASE_HREF]);	    if (!(url_type = LYLegitimizeHREF(me, (char**)&base,					      TRUE, TRUE))) {		if (TRACE)		    fprintf(stderr,			    "HTML: BASE '%s' is not an absolute URL.\n",			    (base ? base : ""));		if (me->inBadBASE == FALSE)		    HTAlert(BASE_NOT_ABSOLUTE);		me->inBadBASE = TRUE;	    }	    if (url_type == LYNXIMGMAP_URL_TYPE) {		/*		 *  These have a are non-standard form, basically		 *  strip the prefix or the code below would insert		 *  a nonsense host into the pseudo URL.  These		 *  should never occur where they would used for		 *  resolution of relative URLs anyway.  We can		 *  also strip the #map part. - kw		 */		temp = HTParse(base + 11, "",			       PARSE_ACCESS+PARSE_HOST+PARSE_PATH			       +PARSE_PUNCTUATION);		if (temp) {		    FREE(base);		    base = temp;		    temp = NULL;		}	    }	    /*	     *	Get parent's address for defaulted fields.	     */	    StrAllocCopy(related, me->node_anchor->address);	    /*	     *	Create the access field.	     */	    if ((temp = HTParse(base, related,				PARSE_ACCESS+PARSE_PUNCTUATION)) &&		*temp != '\0') {		StrAllocCopy(me->base_href, temp);	    } else {		FREE(temp);		StrAllocCopy(me->base_href, (temp = HTParse(related, "",					 PARSE_ACCESS+PARSE_PUNCTUATION)));	    }	    FREE(temp);	    /*	     *	Create the host[:port] field.	     */	    if ((temp = HTParse(base, "",				PARSE_HOST+PARSE_PUNCTUATION)) &&		!strncmp(temp, "//", 2)) {		StrAllocCat(me->base_href, temp);		if (!strcmp(me->base_href, "file://")) {		    StrAllocCat(me->base_href, "localhost");		}	    } else {		if (!strcmp(me->base_href, "file:")) {		    StrAllocCat(me->base_href, "//localhost");		} else if (strcmp(me->base_href, "news:")) {		    FREE(temp);		    StrAllocCat(me->base_href, (temp = HTParse(related, "",					    PARSE_HOST+PARSE_PUNCTUATION)));		}	    }	    FREE(temp);	    FREE(related);	    /*	     *	Create the path field.	     */	    if ((temp = HTParse(base, "",				PARSE_PATH+PARSE_PUNCTUATION)) &&		*temp != '\0') {		StrAllocCat(me->base_href, temp);	    } else if (!strcmp(me->base_href, "news:")) {		StrAllocCat(me->base_href, "*");	    } else if (!strncmp(me->base_href, "news:", 5) ||		       !strncmp(me->base_href, "nntp:", 5) ||		       !strncmp(me->base_href, "snews:", 6)) {		StrAllocCat(me->base_href, "/*");	    } else {		StrAllocCat(me->base_href, "/");	    }	    FREE(temp);	    FREE(base);	    me->inBASE = TRUE;	    StrAllocCopy(me->node_anchor->content_base, me->base_href);	}	break;    case HTML_META:	if (present)	    LYHandleMETA(me, present, value, (char **)&include);	break;    case HTML_TITLE:	HTChunkClear(&me->title);	break;    case HTML_LINK:#ifndef DONT_TRACK_INTERNAL_LINKS	intern_flag = FALSE;#endif	if (present && present[HTML_LINK_HREF]) {	    CHECK_FOR_INTERN(value[HTML_LINK_HREF]);	    /*	     *	Prepare to do housekeeping on the reference. - FM	     */	    if (!value[HTML_LINK_HREF]) {		if (me->inBASE && me->base_href && *me->base_href) {		    StrAllocCopy(href, me->base_href);		} else {		    StrAllocCopy(href, me->node_anchor->address);		}	    } else {		StrAllocCopy(href, value[HTML_LINK_HREF]);		url_type = LYLegitimizeHREF(me, (char**)&href, TRUE, TRUE);	    }	    /*	     *	Check whether a base tag is in effect. - FM	     */	    if ((me->inBASE && *href != '\0' && *href != '#') &&		(temp = HTParse(href, me->base_href, PARSE_ALL)) &&		*temp != '\0')		/*		 *  Use reference related to the base.		 */		StrAllocCopy(href, temp);	    FREE(temp);	    /*	     *	Check whether to fill in localhost. - FM	     */	    LYFillLocalFileURL((char **)&href,			       ((*href != '\0' && *href != '#' &&				 me->inBASE) ?			       me->base_href : me->node_anchor->address));	    /*	     *	Handle links with a REV attribute. - FM	     */	    if (present &&		present[HTML_LINK_REV] && value[HTML_LINK_REV]) {		/*		 *  Handle REV="made" or REV="owner". - LM & FM		 */		if (!strcasecomp("made", value[HTML_LINK_REV]) ||		    !strcasecomp("owner", value[HTML_LINK_REV])) {		    /*		     *	Load the owner element. - FM		     */		    if (!is_url(href)) {			temp = HTParse(href,				       (me->inBASE ?				     me->base_href : me->node_anchor->address),					PARSE_ALL);			StrAllocCopy(href, temp);			FREE(temp);			LYFillLocalFileURL((char **)&href,					   (me->inBASE ?					 me->base_href :					 me->node_anchor->address));		    }		    HTAnchor_setOwner(me->node_anchor, href);		    if (TRACE)			fprintf(stderr,				"HTML: DOC OWNER '%s' found\n", href);		    FREE(href);		    /*		     *	Load the RevTitle element if a TITLE attribute		     *	and value are present. - FM		     */		    if (present && present[HTML_LINK_TITLE] &&			value[HTML_LINK_TITLE] &&			*value[HTML_LINK_TITLE] != '\0') {			StrAllocCopy(title, value[HTML_LINK_TITLE]);			TRANSLATE_AND_UNESCAPE_ENTITIES(&title, TRUE, FALSE);			LYTrimHead(title);			LYTrimTail(title);			if (*title != '\0')			    HTAnchor_setRevTitle(me->node_anchor, title);			FREE(title);		    }		    break;		}	    }	    /*	     *	Handle REL links. - FM	     */	    if (present &&		present[HTML_LINK_REL] && value[HTML_LINK_REL]) {		/*		 *  Ignore style sheets, for now. - FM

⌨️ 快捷键说明

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