/* Create or find a child anchor with a possible link ** -------------------------------------------------- ** ** Create new anchor with a given parent and possibly ** a name, and possibly a link to a _relatively_ named anchor. ** (Code originally in ParseHTML.h) */ PUBLIC HTChildAnchor * HTAnchor_findChildAndLink ARGS4( HTParentAnchor *,parent, /* May not be 0 */ CONST char *,tag, /* May be "" or 0 */ CONST char *,href, /* May be "" or 0 */ HTLinkType *,ltype /* May be 0 */ ) { HTChildAnchor * child = HTAnchor_findChild(parent, tag); if (href && *href) { char * parsed_address; HTAnchor * dest; parsed_address = HTParse(href, HTAnchor_address((HTAnchor *) parent), PARSE_ALL); dest = HTAnchor_findAddress(parsed_address); HTAnchor_link((HTAnchor *) child, dest, ltype); free(parsed_address); } return child; }
/* Create or find a child anchor with a possible link ** -------------------------------------------------- ** ** Create new anchor with a given parent and possibly ** a name, and possibly a link to a _relatively_ named anchor. ** (Code originally in ParseHTML.h) */ PUBLIC HTChildAnchor * HTAnchor_findChildAndLink ARGS4( HTParentAnchor *, parent, /* May not be 0 */ CONST char *, tag, /* May be "" or 0 */ CONST char *, href, /* May be "" or 0 */ HTLinkType *, ltype) /* May be 0 */ { HTChildAnchor * child; CTRACE((tfp,"Entered HTAnchor_findChildAndLink: tag=`%s',%s href=`%s'\n", NonNull(tag), (ltype == HTInternalLink) ? " (internal link)" : "", NonNull(href) )); if (tag && *tag) { child = HTAnchor_findNamedChild(parent->parent, tag); } else { child = HTAnchor_addChild(parent); } if (href && *href) { CONST char *fragment = NULL; HTParentAnchor0 * dest; if (ltype == HTInternalLink && *href == '#') { dest = parent->parent; } else { CONST char *relative_to = (parent->inBASE && *href != '#') ? parent->content_base : parent->address; DocAddress parsed_doc; parsed_doc.address = HTParse(href, relative_to, PARSE_ALL_WITHOUT_ANCHOR); parsed_doc.post_data = NULL; parsed_doc.post_content_type = NULL; if (ltype && parent->post_data && ltype == HTInternalLink) { /* for internal links, find a destination with the same post data if the source of the link has post data. - kw Example: LYNXIMGMAP: */ parsed_doc.post_data = parent->post_data; parsed_doc.post_content_type = parent->post_content_type; } parsed_doc.bookmark = NULL; parsed_doc.isHEAD = FALSE; parsed_doc.safe = FALSE; dest = HTAnchor_findAddress_in_adult_table(&parsed_doc); FREE(parsed_doc.address); } /* ** [from HTAnchor_findAddress()] ** If the address represents a sub-anchor, we load its parent (above), ** then we create a named child anchor within that parent. */ fragment = (*href == '#') ? href+1 : HTParseAnchor(href); if (*fragment) dest = (HTParentAnchor0 *)HTAnchor_findNamedChild(dest, fragment); if (tag && *tag) { if (child->dest) { /* DUPLICATE_ANCHOR_NAME_WORKAROUND - kw */ CTRACE((tfp, "*** Duplicate ChildAnchor %p named `%s'", child, tag)); if ((HTAnchor *)dest != child->dest || ltype != child->type) { CTRACE((tfp, ", different dest %p or type, creating unnamed child\n", child->dest)); child = HTAnchor_addChild(parent); } } } HTAnchor_link(child, (HTAnchor *)dest, ltype); } return child; }