X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ffilexml.C;h=f474317853562554b3a36b9429adc3352ff90bc3;hb=9f0e523f895dabf635f694efc854f2be479d712c;hp=eccb503ac6143b1e9f5fa44c04236c89a87b670d;hpb=30bdb85eb33a8ee7ba675038a86c6be59c43d7bd;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/cinelerra/filexml.C b/cinelerra-5.1/cinelerra/filexml.C index eccb503a..f4743178 100644 --- a/cinelerra-5.1/cinelerra/filexml.C +++ b/cinelerra-5.1/cinelerra/filexml.C @@ -2,21 +2,21 @@ /* * CINELERRA * Copyright (C) 2008 Adam Williams - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * */ #include @@ -58,7 +58,7 @@ XMLBuffer::XMLBuffer(const char *buf, long buf_size, int del) destroy = del; } -XMLBuffer::XMLBuffer(long buf_size, const char *buf, int del) +XMLBuffer::XMLBuffer(long buf_size, char *buf, int del) { // writing bfr = (unsigned char *)buf; bsz = buf_size; @@ -73,24 +73,26 @@ XMLBuffer::~XMLBuffer() if( destroy ) delete [] bfr; } -unsigned char *&XMLBuffer::demand(long len) +int XMLBuffer::demand(long len) { if( len > bsz ) { - len += BCTEXTLEN; + if( !destroy ) return 0; + long sz = inp-bfr; + len += sz/2 + BCTEXTLEN; unsigned char *np = new unsigned char[len]; - if( inp > bfr ) memcpy(np,bfr,inp-bfr); + if( sz > 0 ) memcpy(np,bfr,sz); inp = np + (inp-bfr); outp = np + (outp-bfr); lmt = np + len; bsz = len; delete [] bfr; bfr = np; } - return bfr; + return 1; } int XMLBuffer::write(const char *bp, int len) { - if( !destroy && lmt-inp < len ) len = lmt-inp; if( len <= 0 ) return 0; + if( !destroy && lmt-inp < len ) len = lmt-inp; demand(otell()+len); memmove(inp,bp,len); inp += len; @@ -277,7 +279,7 @@ int XMLTag::read_tag(FileXML *xml) // skip ws while( ch>=0 && ws(ch) ) ch = buf->next(); if( ch < 0 ) EOB_RETURN(); - + // read title ttl = buf->itell() - 1; for( int i=0; i=0; ++i, ch=buf->next() ) { @@ -323,8 +325,12 @@ int XMLTag::read_tag(FileXML *xml) else term = ' '; value_start = buf->itell()-1; - while( ch >= 0 && (ch!=term && ch!=right_delm && ch!='\n') ) + while( ch >= 0 ) { +// old edl bug work-around, allow nl in quoted string + if( ch==term || ch==right_delm ) break; + if( ch=='\n' && term!='\"' ) break; ch = buf->next(); + } if( ch < 0 ) EOB_RETURN(); value_end = buf->itell()-1; // add property @@ -472,7 +478,23 @@ int FileXML::read_tag() return tag.read_tag(this); } -int FileXML::read_data_until(const char *tag_end, char *out, int len) +int FileXML::skip_tag() +{ + char tag_title[sizeof(tag.title)]; + strcpy(tag_title, tag.title); + int n = 1; + while( !read_tag() ) { + if( tag.title[0] == tag_title[0] ) { + if( !strcasecmp(&tag_title[1], &tag.title[1]) ) ++n; + } + else if( tag.title[0] != '/' ) continue; + else if( strcasecmp(&tag_title[0], &tag.title[1]) ) continue; + else if( --n <= 0 ) return 0; + } + return 1; +} + +int FileXML::read_data_until(const char *tag_end, char *out, int len, int skip) { long ipos = buffer->itell(); int opos = 0, pos = -1; @@ -501,15 +523,15 @@ int FileXML::read_data_until(const char *tag_end, char *out, int len) ++pos; } // if end tag is reached, pos is left on the < of the end tag - if( pos >= 0 && !tag_end[pos] ) + if( !skip && pos >= 0 && !tag_end[pos] ) buffer->iseek(ipos); return opos; } -int FileXML::read_text_until(const char *tag_end, char *out, int len) +int FileXML::read_text_until(const char *tag_end, char *out, int len, int skip) { char data[len+1]; - int opos = read_data_until(tag_end, data, len); + int opos = read_data_until(tag_end, data, len, skip); decode(out, data, opos); return 0; } @@ -542,11 +564,11 @@ int FileXML::write_to_file(FILE *file, const char *filename) int FileXML::read_from_file(const char *filename, int ignore_error) { - + strcpy(this->filename, filename); FILE *in = fopen(filename, "rb"); if( !in ) { - if(!ignore_error) + if(!ignore_error) eprintf("\"%s\" %m\n", filename); return 1; }