fit keyframe spanning for sketcher,tracer,crikey, rework keyframegui preset, tweak...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / filexml.C
index 8914ff4498b29412500936913104e40740fd8aee..fe0ec15fa082e247f3f48cf3a04108303dc91dc5 100644 (file)
@@ -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()
 {
@@ -467,18 +471,34 @@ char* FileXML::read_text()
        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;
+               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 +653,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 +665,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;
 }