X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ffilexml.C;h=e4e281466dff68b862f85224eb0e6596023ca51e;hb=0678b17975f50a831fb8a1cda6baaa961e3b6de7;hp=8914ff4498b29412500936913104e40740fd8aee;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/cinelerra/filexml.C b/cinelerra-5.1/cinelerra/filexml.C index 8914ff44..e4e28146 100644 --- a/cinelerra-5.1/cinelerra/filexml.C +++ b/cinelerra-5.1/cinelerra/filexml.C @@ -46,6 +46,7 @@ XMLBuffer::XMLBuffer(long buf_size, long max_size, int del) lmt = bfr + bsz; isz = max_size; destroy = del; + share_lock = new Mutex("XMLBuffer::share_lock", 1); } XMLBuffer::XMLBuffer(const char *buf, long buf_size, int del) @@ -56,6 +57,7 @@ XMLBuffer::XMLBuffer(const char *buf, long buf_size, int del) lmt = inp = bfr+bsz; isz = bsz; destroy = del; + share_lock = new Mutex("XMLBuffer::share_lock"); } XMLBuffer::XMLBuffer(long buf_size, char *buf, int del) @@ -66,11 +68,13 @@ XMLBuffer::XMLBuffer(long buf_size, char *buf, int del) lmt = outp = bfr+bsz; isz = bsz; destroy = del; + share_lock = new Mutex("XMLBuffer::share_lock"); } XMLBuffer::~XMLBuffer() { if( destroy ) delete [] bfr; + delete share_lock; } int XMLBuffer::demand(long len) @@ -111,15 +115,13 @@ int XMLBuffer::read(char *bp, int len) void XMLBuffer::copy_from(XMLBuffer *xbuf) { - if( bsz != xbuf->bsz ) { delete [] bfr; bfr = 0; } - if( !bfr ) bfr = new unsigned char[bsz = xbuf->bsz]; - lmt = bfr + bsz; - long ilen = xbuf->otell(), olen = xbuf->itell(); - inp = pos(ilen); - outp = pos(olen); - if( ilen > 0 ) - memmove(bfr, xbuf->bfr, ilen); - destroy = xbuf->destroy; + xbuf->share_lock->lock("XMLBuffer::copy_from"); + share_lock->lock("XMLBuffer::copy_from"); + oseek(0); + write((const char*)xbuf->pos(0), xbuf->otell()); + iseek(xbuf->itell()); + xbuf->share_lock->unlock(); + share_lock->unlock(); } @@ -262,7 +264,7 @@ int XMLTag::write_tag(FileXML *xml) const char *prop = properties[i]->prop; const char *value = properties[i]->value; int plen = strlen(prop), vlen = strlen(value); - bool need_quotes = !vlen || strchr(value,' '); + bool need_quotes = !vlen || strchr(value,' ') || strchr(value,'\n'); buf->next(' '); xml->append_text(prop, plen); buf->next('='); @@ -382,6 +384,7 @@ FileXML::FileXML(int coded) FileXML::~FileXML() { if( !shared ) delete buffer; + else buffer->share_lock->unlock(); delete [] output; } @@ -449,8 +452,9 @@ int FileXML::append_text(const char *text, long len) char* FileXML::get_data() { + char *data = (char *)buffer->cstr(); long ofs = buffer->itell(); - return (char *)buffer->pos(ofs); + return data + ofs; } char* FileXML::string() { @@ -462,23 +466,40 @@ long FileXML::length() return buffer->otell(); } -char* FileXML::read_text() +char* FileXML::read_text(const char *tag_title) { + if( !tag_title ) tag_title = tag.title; int ch = buffer->next(); // filter out first char is new line if( ch == '\n' ) ch = buffer->next(); - long ipos = buffer->itell()-1; + long ipos = buffer->itell(); + if( ch >= 0 ) --ipos; + long pos = ipos; // scan for delimiter - while( ch >= 0 && ch != left_delm ) ch = buffer->next(); - long pos = buffer->itell()-1; - if( ch >= 0 ) buffer->iseek(pos); + while( ch >= 0 ) { + while( ch >= 0 && ch != left_delm ) ch = buffer->next(); + if( ch < 0 ) break; + pos = buffer->itell()-1; + if( (ch = buffer->next()) != '/' ) continue; + const char *cp = tag_title; + while( (ch=buffer->next()) >= 0 && ch == *cp ) ++cp; + if( ch < 0 ) break; + if( *cp ) continue; + while( ch == ' ' ) ch = buffer->next(); + if( ch == right_delm ) break; + } + if( ch < 0 ) + pos = buffer->itell(); + buffer->iseek(pos); long len = pos - ipos; if( len >= output_length ) { delete [] output; output_length = len+1; output = new char[output_length]; } - decode(output,(const char *)buffer->pos(ipos), len); + if( len > 0 ) + decode(output,(const char *)buffer->pos(ipos), len); + output[len] = 0; return output; } @@ -633,9 +654,10 @@ int FileXML::set_shared_input(XMLBuffer *xbuf) strcpy(this->filename, ""); delete buffer; buffer = xbuf; + xbuf->share_lock->lock("FileXML::set_shared_input"); xbuf->iseek(0); - set_coding(coded); shared = 1; + set_coding(coded); return 0; } @@ -644,9 +666,10 @@ int FileXML::set_shared_output(XMLBuffer *xbuf) strcpy(this->filename, ""); delete buffer; buffer = xbuf; + xbuf->share_lock->lock("FileXML::set_shared_output"); xbuf->oseek(0); - set_coding(coded); shared = 1; + set_coding(coded); return 0; }