X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=5033877787b50a6adb4c768732f6a45834a90521;hb=44c3b5aabb8782b15e66d7d14ab19b280d7eb20f;hp=fd2c6de80f7a5b8eb2019eeda819da1431599c56;hpb=5a878b1d30583985f5d91d12de3b3aa19259434a;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index fd2c6de..5033877 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -309,12 +309,13 @@ XMLTree *XMLTree::Load(int fd, char *filename, bool load_tc,int sample_factor) // SubtreeSize(x): the number of nodes (and attributes) in the subtree of node x. -int XMLTree::SubtreeSize(treeNode x) +/*int XMLTree::SubtreeSize(treeNode x) { return subtree_size(Par, x); } - +*/ // SubtreeTags(x,tag): the number of occurrences of tag within the subtree of node x. +/* int XMLTree::SubtreeTags(treeNode x, TagType tag) { if (x == Root()) @@ -325,6 +326,7 @@ int XMLTree::SubtreeTags(treeNode x, TagType tag) return (Tags->rank(tag, s) - Tags->rank(tag, node2tagpos(x)-1))+1; } +*/ int XMLTree::SubtreeElements(treeNode x) { @@ -598,7 +600,7 @@ treeNode XMLTree::TaggedDescendant(treeNode x, TagType tag) return (fast_is_ancestor(Par,x,y) ? y : NULLT); } */ - +/* treeNode XMLTree::SelectDescendant(treeNode x, TagIdSet *tags) { NULLT_IF (x ==NULLT || fast_isleaf(Par,x)); @@ -616,7 +618,7 @@ treeNode XMLTree::SelectDescendant(treeNode x, TagIdSet *tags) return min; } - +*/ // TaggedPrec(x,tag): returns the first node tagged tag with smaller preorder than x and not an // ancestor of x. Returns NULLT if there is none. @@ -707,7 +709,7 @@ treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ance else return NULLT; } - +/* treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode ancestor_closing) { @@ -738,7 +740,7 @@ treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode anc else return NULLT; } - +*/ /* treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode closing) { @@ -899,17 +901,9 @@ bool XMLTree::IsOpen(treeNode x) { return fast_inspect(Par,x); } void XMLTree::Print(int fd,treeNode x, bool no_text){ - int newfd = dup(fd); - stream = fdopen(newfd,"wa"); - if (stream == 0){ - perror(NULL); - return; - }; - if (buffer == 0) buffer = new string(); - - FILE* fp = stream; + treeNode fin = fast_find_close(Par,x); treeNode n = x; TagType tag = Tag(n); @@ -920,92 +914,90 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ treeNode first_att = NULLT; if (first_att == NULLT) - first_idx = first_text; + first_idx = first_text; else if (first_text == NULLT) - first_idx = first_att; + first_idx = first_att; else - first_idx = min(first_att,first_text); + first_idx = min(first_att,first_text); uchar * current_text=NULL; + if (first_idx != NULLT) - current_text = GetText(MyText(first_idx)); + current_text = GetText(MyText(first_idx)); + size_t read = 0; std::vector st; - while (n <= fin){ - if (fast_inspect(Par,n)){ - if (tag == PCDATA_TAG_ID ) { - - if (no_text) - myfputs("<$/>",fp); - else{ - read = myfprintf((const char*) current_text, fp); - current_text += (read + 1); - }; - n+=2; // skip closing $ - tag = Tag(n); - - } - else { - myfputc('<',fp); - tagstr = (uchar*) GetTagNameByRef(tag); - myfputs((const char*) tagstr ,fp); - n++; - if (fast_inspect(Par,n)) { - st.push_back(tagstr); - tag = Tag(n); - if (tag == ATTRIBUTE_TAG_ID){ - n++; - if (no_text) myfputs("><@@>",fp); - while (fast_inspect(Par,n)){ - if (no_text) { - myfputc('<',fp); - myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp); - myfputc('>',fp); - myfputs("<$@/>',fp); - n+= 4; - } - else { - myfputc(' ',fp); - myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp); - n++; - myfputs("=\"",fp); - read = myfprintf((const char*) current_text,fp); - current_text += (read + 1); - myfputc('"',fp); - n+=3; - } - }; - if (no_text) - myfputs("",fp); - else myfputc('>',fp); - n++; - tag=Tag(n); - } + while (n <= fin){ + if (fast_inspect(Par,n)){ + if (tag == PCDATA_TAG_ID) { + + if (no_text) + _dputs("<$/>", fd); else { - myfputc('>',fp); + read = _dprintf((const char*) current_text, fd); + current_text += (read + 1); }; + n+=2; // skip closing $ + tag = Tag(n); + } - else {// tag - myfputs("/>",fp); + else { + _dputc('<',fd); + tagstr = (uchar*) GetTagNameByRef(tag); + _dputs((const char*) tagstr, fd); n++; - tag=Tag(n); - }; - }; - } - else - do { - myfputs("', fp); - st.pop_back(); - n++; - }while (!fast_inspect(Par,n) && !st.empty()); - tag=Tag(n); - }; - myfputc('\n',fp); - mybufferflush(fp); - //fflush(fp); - fclose(fp); + if (fast_inspect(Par,n)) { + st.push_back(tagstr); + tag = Tag(n); + if (tag == ATTRIBUTE_TAG_ID){ + n++; + if (no_text) _dputs("><@@>",fd); + + while (fast_inspect(Par,n)){ + if (no_text) { + _dputc('<', fd); + _dputs((const char*) &(GetTagNameByRef(Tag(n))[3]), fd); + _dputc('>', fd); + _dputs("<$@/>', fd); + n+= 4; + } else { + _dputc(' ', fd); + _dputs((const char*) &(GetTagNameByRef(Tag(n))[3]), fd); + n++; + _dputs("=\"", fd); + read = _dprintf((const char*) current_text, fd); + current_text += (read + 1); + _dputc('"', fd); + n+=3; + } + }; + if (no_text) _dputs("", fd); + else _dputc('>', fd); + n++; + tag=Tag(n); + + } else + _dputc('>', fd); + + } else {// tag + _dputs("/>", fd); + n++; + tag=Tag(n); + }; + }; + } + else + do { + _dputs("', fd); + st.pop_back(); + n++; + } while (!(fast_inspect(Par,n) || st.empty())); + tag = Tag(n); + }; + _dputc('\n', fd); + _flush(fd); }