From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (unknown [IPv6:2602:4b:a4d8:4b00:12bf:48ff:fe7c:5584]) by hurricane.the-brannons.com (Postfix) with ESMTPSA id BFF6F77892 for ; Thu, 30 Jan 2014 07:14:27 -0800 (PST) From: Christopher Brannon To: edbrowse-dev@lists.the-brannons.com Date: Thu, 30 Jan 2014 07:14:03 -0800 Message-Id: <1391094843-5217-1-git-send-email-chris@the-brannons.com> X-Mailer: git-send-email 1.8.3.2 Subject: [Edbrowse-dev] [PATCH] Use the list class from the C++ STL, rather than C list macros. X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jan 2014 15:14:28 -0000 --- src/html.cpp | 90 ++++++++++++++++++++++++++++++++++-------------------------- src/makefile | 2 +- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/html.cpp b/src/html.cpp index 31e8045..50613af 100644 --- a/src/html.cpp +++ b/src/html.cpp @@ -6,6 +6,10 @@ #include "eb.h" #include "js.h" +#include +#include +#include +using namespace std; /* Close an open anchor when you see this tag. */ #define TAG_CLOSEA 1 @@ -45,7 +49,9 @@ static const char *const inp_types[] = { static const char dfvl[] = "defaultValue"; static const char dfck[] = "defaultChecked"; -static struct listHead htmlStack; +static list < struct htmlTag *>htmlStack; +typedef list < struct htmlTag *>::iterator tagListIterator; +typedef list < struct htmlTag *>::reverse_iterator tagListBackIterator; static struct htmlTag **tagArray, *topTag; static int ntags; /* number of tags in this page */ static char *topAttrib; @@ -63,8 +69,6 @@ static int preamble_l; static void buildTagArray(void) { - int j = 0; - struct htmlTag *t; if(!parsePage) return; if(tagArray) @@ -73,9 +77,8 @@ buildTagArray(void) (struct htmlTag **)allocMem(sizeof (struct htmlTag *) * ((ntags + 32) & ~31)); cw->tags = tagArray; - foreach(t, htmlStack) - tagArray[j++] = t; - tagArray[j] = 0; + struct htmlTag **last = copy(htmlStack.begin(), htmlStack.end(), tagArray); + *last = 0; } /* buildTagArray */ static eb_bool @@ -232,7 +235,6 @@ static const struct tagInfo elements[] = { }; struct htmlTag { - struct htmlTag *next, *prev; HeapRootedObject jv; /* corresponding java variable */ int seqno; int ln; /* line number */ @@ -735,7 +737,7 @@ static void makeButton(void) { struct htmlTag *t = (struct htmlTag *)allocZeroMem(sizeof (struct htmlTag)); - addToListBack(&htmlStack, t); + htmlStack.push_back(t); t->seqno = ntags++; t->info = elements + 2; t->action = TAGACT_INPUT; @@ -747,11 +749,12 @@ makeButton(void) static char * displayOptions(const struct htmlTag *sel) { - const struct htmlTag *t; char *outstr; int l; outstr = initString(&l); - foreach(t, htmlStack) { + for(tagListIterator iter = htmlStack.begin(); iter != htmlStack.end(); + iter++) { + const struct htmlTag *t = *iter; if(t->controller != sel) continue; if(!t->checked) @@ -1009,7 +1012,9 @@ findOpenTag(const char *name) eb_bool match; const char *desc = topTag->info->desc; - foreachback(t, htmlStack) { + for(tagListBackIterator r_iter = htmlStack.rbegin(); + r_iter != htmlStack.rend(); r_iter++) { + t = *r_iter; if(t == topTag) continue; /* last one doesn't count */ if(t->balanced) @@ -1058,7 +1063,7 @@ newTag(const char *name) t->balanced = eb_true; if(stringEqual(name, "a")) t->clickable = eb_true; - addToListBack(&htmlStack, t); + htmlStack.push_back(t); return t; } /* newTag */ @@ -1157,10 +1162,11 @@ encodeTags(char *html) JS::RootedObject ev(cw->jss->jcx, NULL); /* generic event variable */ JS::RootedObject jwin(cw->jss->jcx, cw->jss->jwin); JS::RootedObject jdoc(cw->jss->jcx, cw->jss->jdoc); + tagListBackIterator r_iter; currentA = currentForm = currentSel = currentOpt = currentTitle = currentTA = 0; - initList(&htmlStack); + htmlStack.clear(); tagArray = 0; newstr = initString(&l); preamble = 0; @@ -1282,7 +1288,7 @@ encodeTags(char *html) continue; /* tag not recognized */ topTag = t = (struct htmlTag *)allocZeroMem(sizeof (struct htmlTag)); - addToListBack(&htmlStack, t); + htmlStack.push_back(t); t->seqno = ntags; sprintf(hnum, "%c%d", InternalCodeChar, ntags); ++ntags; @@ -1526,7 +1532,9 @@ encodeTags(char *html) case TAGACT_LI: /* Look for the open UL or OL */ j = -1; - foreachback(v, htmlStack) { + for(r_iter = htmlStack.rbegin(); r_iter != htmlStack.rend(); + r_iter++) { + v = *r_iter; if(v->balanced || !v->info->nest) continue; if(v->slash) @@ -1554,16 +1562,18 @@ encodeTags(char *html) continue; case TAGACT_DT: - foreachback(v, htmlStack) { - if(v->balanced || !v->info->nest) - continue; - if(v->slash) - continue; /* should never happen */ - s = v->info->name; - if(stringEqual(s, "DL")) - break; - } - if(v == (struct htmlTag *)&htmlStack) + for(r_iter = htmlStack.rbegin(); r_iter != htmlStack.rend(); + r_iter++) { + v = *r_iter; + if(v->balanced || !v->info->nest) + continue; + if(v->slash) + continue; /* should never happen */ + s = v->info->name; + if(stringEqual(s, "DL")) + break; + } + if(r_iter == htmlStack.rend()) browseError(MSG_NotInList, ti->desc); goto nop; @@ -1978,7 +1988,9 @@ encodeTags(char *html) nzFree(html); html = h = after; /* After the realloc, the inner pointers are no longer valid. */ - foreach(z, htmlStack) z->inner = 0; + for(tagListIterator iter = htmlStack.begin(); + iter != htmlStack.end(); iter++) + (*iter)->inner = 0; } /* document.write */ } } @@ -2038,27 +2050,23 @@ encodeTags(char *html) /* Run the various onload functions */ /* Turn the onunload functions into hyperlinks */ if(!cw->jsdead && !onload_done) { - const struct htmlTag *lasttag; onloadGo(jwin, 0, "window"); onloadGo(jdoc, 0, "document"); - lasttag = (const struct htmlTag *)htmlStack.prev; - foreach(t, htmlStack) { + for(tagListIterator iter = htmlStack.begin(); iter != htmlStack.end(); + iter++) { + t = *iter; char *jsrc; ev = t->jv; /* in case the option has disappeared */ if(t->action == TAGACT_OPTION) - goto next_onload; + continue; if(!ev) - goto next_onload; + continue; if(t->slash) - goto next_onload; + continue; jsrc = htmlAttrVal(t->attrib, "onunload"); onloadGo(ev, jsrc, t->info->name); nzFree(jsrc); - - next_onload: - if(t == lasttag) - break; } /* loop over tags */ } onload_done = eb_true; @@ -2073,7 +2081,10 @@ encodeTags(char *html) } if(browseLocal == 1) { /* no errors yet */ - foreach(t, htmlStack) { + for(tagListIterator iter = htmlStack.begin(); iter != htmlStack.end(); + iter++) { + tagListIterator iter2; + t = *iter; browseLine = t->ln; if(t->info->nest && !t->slash && !t->balanced) { browseError(MSG_TagNotClosed, t->info->desc); @@ -2091,7 +2102,8 @@ encodeTags(char *html) if(h[1] == 0) continue; a = h + 1; /* this is what we're looking for */ - foreach(v, htmlStack) { + for(iter2 = htmlStack.begin(); iter2 != htmlStack.end(); iter2++) { + v = *iter2; if(v->action != TAGACT_A) continue; /* not achor */ if(!v->name) @@ -2099,7 +2111,7 @@ encodeTags(char *html) if(stringEqual(a, v->name)) break; } - if(v == (struct htmlTag *)&htmlStack) { /* end of list */ + if(iter2 == htmlStack.end()) { browseError(MSG_NoLable2, a); break; } diff --git a/src/makefile b/src/makefile index a8ac73e..4f7e6ee 100644 --- a/src/makefile +++ b/src/makefile @@ -14,7 +14,7 @@ bindir = $(prefix)/bin JS_CXXFLAGS =-I/usr/include/mozjs # we need to only use the js flags when building with c++, so use CXXFLAGS -CXXFLAGS += -fpermissive $(JS_CXXFLAGS) +CXXFLAGS += $(JS_CXXFLAGS) # By default, we strip the executables. # Override this behavior on the command line, by setting STRIP to the -- 1.8.3.2