cvs: pecl /hyperwave hg_comm.c

From: Date: Fri, 20 Oct 2006 07:25:00 +0000
Subject: cvs: pecl /hyperwave hg_comm.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6520@lists.php.net to get a copy of this message
steinm Fri Oct 20 07:25:00 2006 UTC Modified files: /pecl/hyperwave hg_comm.c Log: - support links in documents of type <xx yy=""></xx>. xx and yy are stored as TagName and DestAttr. If both are empty the default <a href=""></a> will be used

http://cvs.php.net/viewvc.cgi/pecl/hyperwave/hg_comm.c?r1=1.61&r2=1.62&diff_format=u Index: pecl/hyperwave/hg_comm.c diff -u pecl/hyperwave/hg_comm.c:1.61 pecl/hyperwave/hg_comm.c:1.62 --- pecl/hyperwave/hg_comm.c:1.61 Thu Jun 30 08:21:55 2005 +++ pecl/hyperwave/hg_comm.c Fri Oct 20 07:25:00 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: hg_comm.c,v 1.61 2005/06/30 08:21:55 steinm Exp $ */ +/* $Id: hg_comm.c,v 1.62 2006/10/20 07:25:00 steinm Exp $ */ /* #define HW_DEBUG */ @@ -186,6 +186,8 @@ cur_ptr->code = NULL; cur_ptr->keyword = NULL; cur_ptr->fragment = NULL; + cur_ptr->tagname = NULL; + cur_ptr->destattr = NULL; #ifdef newlist zend_llist_prepend_element(pAnchorList, &cur_ptr); @@ -225,6 +227,8 @@ if(ptr->code) efree(ptr->code); if(ptr->keyword) efree(ptr->keyword); if(ptr->fragment) efree(ptr->fragment); + if(ptr->tagname) efree(ptr->tagname); + if(ptr->destattr) efree(ptr->destattr); #ifdef newlist efree(ptr); @@ -372,30 +376,30 @@ a document is annotated and the annotation text doesn't contain a link of type annotation, In such a case the Position has the value 'invisible' */ - str = strstr(object, "Position"); + str = strstr(object, "Position="); str += 9; if(((int) str != 9) && (0 != strncmp(str, "invisible", 9))) { sscanf(str, "0x%X 0x%X", &start, &end); /* Determine ObjectID */ objectID = 0; - if(NULL != (str = strstr(object, "ObjectID"))) { + if(NULL != (str = strstr(object, "ObjectID="))) { str += 9; sscanf(str, "0x%X", &objectID); } cur_ptr = fnAddAnchor(pAnchorList, objectID, start, end); - + /* Determine Type of Anchor */ - str = strstr(object, "TAnchor"); + str = strstr(object, "TAnchor="); str += 8; if(*str == 'S') { char destdocname[200]; char nameanchor[200]; cur_ptr->tanchor = 1; - + cur_ptr->destdocname = NULL; - if(NULL != (str = strstr(object, "Dest"))) { + if(NULL != (str = strstr(object, "Dest="))) { char *tempptr; /* No need to care about the value of Dest, because we take the info @@ -439,7 +443,7 @@ /* } */ } } - + /* Get the Id of the anchor destination and the document id that belongs to that anchor. We need that soon in order to determine if the anchor points to a document or a dest anchor in a document. @@ -570,11 +574,32 @@ memcpy(cur_ptr->code, str, str1 - str); cur_ptr->code[str1 - str] = '\0'; } - } else + } else { cur_ptr->linktype=HW_DEFAULT_LINK; - } else + } + } else { cur_ptr->linktype=HW_DEFAULT_LINK; - + } + + if(NULL != (str = strstr(object, "TagName="))) { + str += 8; + str1 = str; + while((*str1 != '\n') && (*str1 != '\0')) + str1++; + cur_ptr->tagname = emalloc(str1 - str + 1); + memcpy(cur_ptr->tagname, str, str1 - str); + cur_ptr->tagname[str1 - str] = '\0'; + } + if(NULL != (str = strstr(object, "DestAttr="))) { + str += 9; + str1 = str; + while((*str1 != '\n') && (*str1 != '\0')) + str1++; + cur_ptr->destattr = emalloc(str1 - str + 1); + memcpy(cur_ptr->destattr, str, str1 - str); + cur_ptr->destattr[str1 - str] = '\0'; + } + } else { /* Destination Anchor */ char nameanchor[200]; @@ -595,9 +620,7 @@ if(sscanf(str, "%s\n", nameanchor)) cur_ptr->keyword = estrdup(nameanchor); } - } - } /* free memory even if it is an invisible anchor */ efree(anchors[i]); @@ -631,6 +654,7 @@ int offset = 0; int laststart=0; char emptystring[BUFFERLEN]; + char endtag[20]; int i; TSRMLS_FETCH(); @@ -701,10 +725,10 @@ /* The link is only set if the Link points to an external document */ switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: - snprintf(istr, BUFFERLEN, " background='%s'", cur_ptr->link); + snprintf(istr, BUFFERLEN, " background=\"%s\"", cur_ptr->link); break; case HW_INTAG_LINK: - snprintf(istr, BUFFERLEN, " %s='%s'", cur_ptr->tagattr, cur_ptr->link); + snprintf(istr, BUFFERLEN, " %s=\"%s\"", cur_ptr->tagattr, cur_ptr->link); offset -= 4; /* because there is no closing tag </a> */ /* laststart = cur_ptr->start; */ break; @@ -715,16 +739,17 @@ break; case HW_APPLET_LINK: if(cur_ptr->codebase) - snprintf(istr, BUFFERLEN, " codebase='%s' code='%s'", cur_ptr->codebase, cur_ptr->code); + snprintf(istr, BUFFERLEN, " codebase=\"%s\" code=\"%s\"", cur_ptr->codebase, cur_ptr->code); else - snprintf(istr, BUFFERLEN, " codebase='/' code='%s'", cur_ptr->code); + snprintf(istr, BUFFERLEN, " codebase=\"/\" code=\"%s\"", cur_ptr->code); break; default: - newtext = fnInsStr(newtext, cur_ptr->end+offset, "</a>"); + snprintf(endtag, 20, "</%s>", cur_ptr->tagname ? cur_ptr->tagname : "a"); + newtext = fnInsStr(newtext, cur_ptr->end+offset, endtag); if(cur_ptr->fragment) - snprintf(istr, BUFFERLEN, "<a href='%s#%s'", cur_ptr->link, cur_ptr->fragment); + snprintf(istr, BUFFERLEN, "<%s %s=\"%s#%s\"", cur_ptr->tagname ? cur_ptr->tagname : "a", cur_ptr->destattr ? cur_ptr->destattr : "href", cur_ptr->link, cur_ptr->fragment); else - snprintf(istr, BUFFERLEN, "<a href='%s'", cur_ptr->link); + snprintf(istr, BUFFERLEN, "<%s %s=\"%s\"", cur_ptr->tagname ? cur_ptr->tagname : "a", cur_ptr->destattr ? cur_ptr->destattr : "href", cur_ptr->link); if(cur_ptr->htmlattr) { strncat(istr, " ", BUFFERLEN - 1 - strlen(istr)); strncat(istr, cur_ptr->htmlattr, BUFFERLEN - 1 - strlen(istr)); @@ -735,15 +760,15 @@ switch(cur_ptr->linktype) { case HW_BACKGROUND_LINK: if(NULL != cur_ptr->destdocname) { - snprintf(istr, BUFFERLEN, " background='%s%s'", scriptname[HW_BACKGROUND_LINK], cur_ptr->destdocname); + snprintf(istr, BUFFERLEN, " background=\"%s%s\"", scriptname[HW_BACKGROUND_LINK], cur_ptr->destdocname); } else istr[0] = '\0'; break; case HW_INTAG_LINK: if(cur_ptr->fragment) - snprintf(istr, BUFFERLEN, " %s='#%s'", cur_ptr->tagattr, cur_ptr->fragment); + snprintf(istr, BUFFERLEN, " %s=\"#%s\"", cur_ptr->tagattr, cur_ptr->fragment); else - snprintf(istr, BUFFERLEN, " %s='%s%s'", cur_ptr->tagattr, scriptname[HW_INTAG_LINK], cur_ptr->destdocname); + snprintf(istr, BUFFERLEN, " %s=\"%s%s\"", cur_ptr->tagattr, scriptname[HW_INTAG_LINK], cur_ptr->destdocname); offset -= 4; /* because there is no closing tag </a> */ break; case HW_INTAGNODEL_LINK: @@ -753,19 +778,20 @@ case HW_APPLET_LINK: if(cur_ptr->codebase) /* snprintf(istr, BUFFERLEN, " codebase='%s%s' code='%s'", scriptname == NULL ? "" : scriptname, cur_ptr->codebase, cur_ptr->code); */ - snprintf(istr, BUFFERLEN, " codebase='%s%s' code='%s'", scriptname[HW_APPLET_LINK], cur_ptr->codebase, cur_ptr->code); + snprintf(istr, BUFFERLEN, " codebase=\"%s%s\" code=\"%s\"", scriptname[HW_APPLET_LINK], cur_ptr->codebase, cur_ptr->code); else - snprintf(istr, BUFFERLEN, " codebase='/' code='%s'", cur_ptr->code); + snprintf(istr, BUFFERLEN, " codebase=\"/\" code=\"%s\"", cur_ptr->code); break; default: - newtext = fnInsStr(newtext, cur_ptr->end+offset, "</a>"); + snprintf(endtag, 20, "</%s>", cur_ptr->tagname ? cur_ptr->tagname : "a"); + newtext = fnInsStr(newtext, cur_ptr->end+offset, endtag); if(cur_ptr->nameanchor) - snprintf(istr, BUFFERLEN, "<a href='%s%s#%s'", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->nameanchor); + snprintf(istr, BUFFERLEN, "<%s %s=\"%s%s#%s\"", cur_ptr->tagname ? cur_ptr->tagname : "a", cur_ptr->destattr ? cur_ptr->destattr : "href", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->nameanchor); else if(cur_ptr->fragment) - snprintf(istr, BUFFERLEN, "<a href=\"%s%s#%s\"", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->fragment); + snprintf(istr, BUFFERLEN, "<%s %s=\"%s%s#%s\"", cur_ptr->tagname ? cur_ptr->tagname : "a", cur_ptr->destattr ? cur_ptr->destattr : "href", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname, cur_ptr->fragment); else - snprintf(istr, BUFFERLEN, "<a href='%s%s'", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname); + snprintf(istr, BUFFERLEN, "<%s %s=\"%s%s\"", cur_ptr->tagname ? cur_ptr->tagname : "a", cur_ptr->destattr ? cur_ptr->destattr : "href", scriptname[HW_DEFAULT_LINK], cur_ptr->destdocname); if(cur_ptr->htmlattr) { strncat(istr, " ", BUFFERLEN - 1 - strlen(istr)); @@ -783,9 +809,9 @@ instead of the destdocname */ if(cur_ptr->keyword) - snprintf(istr, BUFFERLEN, "<a name='%s'>", cur_ptr->keyword); + snprintf(istr, BUFFERLEN, "<a name=\"%s\">", cur_ptr->keyword); else if(cur_ptr->nameanchor) - snprintf(istr, BUFFERLEN, "<a name='%s'>", cur_ptr->nameanchor); + snprintf(istr, BUFFERLEN, "<a name=\"%s\">", cur_ptr->nameanchor); } newtext = fnInsStr(newtext, cur_ptr->start, istr); /* In case there are several TAGS nested, we accumulate the offset @@ -2203,6 +2229,7 @@ #endif pAnchorList = fnCreateAnchorList(objectID, anchors, destrec, reldestrec, ancount, mode); + /* Free only the array, the objrecs has been freed in fnCreateAnchorList() */ if(anchors) efree(anchors); if(destrec) efree(destrec);
« previous php.pecl.cvs (#6520) next »