Update of /cvsroot/pure-data/externals/grill/pool/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3803/source
Modified Files: data.cpp main.cpp pool.cpp Log Message: implemented output sorting (ogetall, ogetrec, ogetsub), see bug #154 Fixed bug #148. added success/error reporting for file operations implemented UTF-8 conversion for OSX Additionally XML files are now encoded with UTF-8. changed obviously buggy pool name registering some assertions sorting fixes and optimizations
Index: data.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/pool/source/data.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** data.cpp 30 Sep 2006 19:23:16 -0000 1.7 --- data.cpp 20 Jan 2007 14:27:39 -0000 1.8 *************** *** 196,200 **** if(absdir) tmp = d; if(file.good()) { ! file << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" << endl; file << "<!DOCTYPE pool SYSTEM \"http://grrrr.org/ext/pool/pool-0.2.dtd\">" << endl; file << "<pool>" << endl; --- 196,200 ---- if(absdir) tmp = d; if(file.good()) { ! file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; file << "<!DOCTYPE pool SYSTEM \"http://grrrr.org/ext/pool/pool-0.2.dtd\">" << endl; file << "<pool>" << endl;
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/pool/source/main.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** main.cpp 30 Sep 2006 19:23:16 -0000 1.16 --- main.cpp 20 Jan 2007 14:27:39 -0000 1.17 *************** *** 78,82 **** V m_getrec(I argc,const A *argv); // also subdirectories V m_getsub(I argc,const A *argv); // only subdirectories ! V m_ogetall(); // only values (ordered) V m_ogetrec(I argc,const A *argv); // also subdirectories (ordered) V m_ogetsub(I argc,const A *argv); // only subdirectories (ordered) --- 78,82 ---- V m_getrec(I argc,const A *argv); // also subdirectories V m_getsub(I argc,const A *argv); // only subdirectories ! V m_ogetall(int argc,const A *argv); // only values (ordered) V m_ogetrec(I argc,const A *argv); // also subdirectories (ordered) V m_ogetsub(I argc,const A *argv); // only subdirectories (ordered) *************** *** 132,137 **** V set(I argc,const A *argv,BL over); V getdir(const S *tag); ! I getrec(const S *tag,I level,BL order,get_t how /*= get_norm*/,const AtomList &rdir); ! I getsub(const S *tag,I level,BL order,get_t how /*= get_norm*/,const AtomList &rdir);
V paste(const S *tag,I argc,const A *argv,BL repl); --- 132,137 ---- V set(I argc,const A *argv,BL over); V getdir(const S *tag); ! int getrec(const S *tag,int level,int order,bool rev,get_t how /*= get_norm*/,const AtomList &rdir); ! int getsub(const S *tag,int level,int order,bool rev,get_t how /*= get_norm*/,const AtomList &rdir);
V paste(const S *tag,I argc,const A *argv,BL repl); *************** *** 205,209 **** FLEXT_CALLBACK_V(m_getrec) FLEXT_CALLBACK_V(m_getsub) ! FLEXT_CALLBACK(m_ogetall) FLEXT_CALLBACK_V(m_ogetrec) FLEXT_CALLBACK_V(m_ogetsub) --- 205,209 ---- FLEXT_CALLBACK_V(m_getrec) FLEXT_CALLBACK_V(m_getsub) ! FLEXT_CALLBACK_V(m_ogetall) FLEXT_CALLBACK_V(m_ogetrec) FLEXT_CALLBACK_V(m_ogetsub) *************** *** 638,685 **** }
! I pool::getrec(const t_symbol *tag,I level,BL order,get_t how,const AtomList &rdir) { Atoms gldir(curdir); gldir.Append(rdir);
! I ret = 0;
switch(how) { ! case get_cnt: ! ret = pl->CntAll(gldir); ! break; ! case get_print: ! ret = pl->PrintAll(gldir); ! break; ! case get_norm: { ! A *k; ! Atoms *r; ! I cnt = pl->GetAll(gldir,k,r); ! if(!k) ! post("%s - %s: error retrieving values",thisName(),GetString(tag)); ! else { ! for(I i = 0; i < cnt; ++i) { ! ToSysAnything(3,tag,0,NULL); ! ToSysList(2,absdir?gldir:rdir); ! ToOutAtom(1,k[i]); ! ToSysList(0,r[i]); ! } ! delete[] k; ! delete[] r; ! } ! ret = cnt; ! } }
if(level != 0) { const A **r; ! I cnt = pl->GetSub(gldir,r); if(!r) post("%s - %s: error retrieving directories",thisName(),GetString(tag)); else { ! I lv = level > 0?level-1:-1; ! for(I i = 0; i < cnt; ++i) { Atoms l(rdir); l.Append(*r[i]); ! ret += getrec(tag,lv,order,how,l); } delete[] r; --- 638,771 ---- }
! ! // ---- some sorting stuff ---------------------------------- ! ! inline bool smaller(const A &a,const A &b,int index) { return a < b; } ! inline void swap(A &a,A &b) { A c = a; a = b; b = c; } ! ! inline bool smaller(const A *a,const A *b,int index) { return *a < *b; } ! inline void swap(A *a,A *b) { A *c = a; a = b; b = c; } ! ! inline bool smaller(const Atoms &a,const Atoms &b,int index) ! { ! if(a.Count()-1 < index) ! return true; ! else if(b.Count()-1 < index) ! return false; ! else ! return a[index] < b[index]; ! } ! ! inline void swap(Atoms &a,Atoms &b) { Atoms c(a); a = b; b = c; } ! ! inline bool smaller(const Atoms *a,const Atoms *b,int index) { return smaller(*a,*b,index); } ! inline void swap(Atoms *a,Atoms *b) { Atoms *c = a; a = b; b = c; } ! ! template <typename T1,typename T2> ! void sift(T1 *a,T2 *b,int start,int count,int index,bool rev) ! { ! int root = start; // Point to a root node ! int child; ! ! while((child = root * 2 + 1) < count) { // While the root has child(ren) point to its left child ! // If the child has a sibling and the child's value is less than its sibling's... ! if(child < count-1 && smaller(a[child],a[child+1],index) != rev) ! child++; // ... point to the right child instead ! ! if(smaller(a[root],a[child],index) == rev) break; ! ! // If the value in root is less than in child... ! swap(a[root], a[child]); // ... swap the values in root and child and... ! if(b) swap(b[root], b[child]); ! ! root = child; // ... make root point to its child ! } ! } ! ! template <typename T1,typename T2> ! void heapsort(T1 *a,T2 *b,int count,int index,bool rev) ! { ! int start = count/2-1; ! int end = count-1; ! ! for(; start >= 0; start--) ! sift(a, b, start, count, index, rev); ! ! for(; end > 0; --end) { ! swap(a[end], a[0]); ! if(b) swap(b[end], b[0]); ! sift(a, b, 0, end, index, rev); ! } ! } ! ! template <typename T1,typename T2> ! static void orderpairs(T1 *keys,T2 *atoms,int count,int index,bool rev) ! { ! FLEXT_ASSERT(index >= 0); ! ! if(!count) return; ! ! if(index) ! heapsort(atoms,keys,count,index-1,rev); ! else ! heapsort(keys,atoms,count,0,rev); ! } ! ! // ---- sorting stuff ends ---------------------------------- ! ! int pool::getrec(const t_symbol *tag,int level,int order,bool rev,get_t how,const AtomList &rdir) { Atoms gldir(curdir); gldir.Append(rdir);
! int ret = 0;
switch(how) { ! case get_cnt: ! ret = pl->CntAll(gldir); ! break; ! case get_print: ! ret = pl->PrintAll(gldir); ! break; ! case get_norm: { ! A *k; ! Atoms *r; ! int cnt = pl->GetAll(gldir,k,r); ! if(!k) { ! FLEXT_ASSERT(!k); ! post("%s - %s: error retrieving values",thisName(),GetString(tag)); ! } ! else { ! FLEXT_ASSERT(r); ! ! if(order >= 0) ! orderpairs(k,r,cnt,order,rev); ! ! for(int i = 0; i < cnt; ++i) { ! ToSysAnything(3,tag,0,NULL); ! ToSysList(2,absdir?gldir:rdir); ! ToOutAtom(1,k[i]); ! ToSysList(0,r[i]); ! } ! delete[] k; ! delete[] r; ! } ! ret = cnt; ! } }
if(level != 0) { const A **r; ! int cnt = pl->GetSub(gldir,r); if(!r) post("%s - %s: error retrieving directories",thisName(),GetString(tag)); else { ! if(order >= 0) ! orderpairs(r,(Atoms *)NULL,cnt,order,rev); ! ! int lv = level > 0?level-1:-1; ! for(int i = 0; i < cnt; ++i) { Atoms l(rdir); l.Append(*r[i]); ! ret += getrec(tag,lv,order,rev,how,l); } delete[] r; *************** *** 693,697 **** { AtomList l; ! getrec(thisTag(),0,false,get_norm,l); ToSysBang(3);
--- 779,783 ---- { AtomList l; ! getrec(thisTag(),0,-1,false,get_norm,l); ToSysBang(3);
*************** *** 699,706 **** }
! V pool::m_ogetall() { AtomList l; ! getrec(thisTag(),0,true,get_norm,l); ToSysBang(3);
--- 785,813 ---- }
! V pool::m_ogetall(I argc,const A *argv) { + int index = 0; + if(argc) { + if(!CanbeInt(*argv) || (index = GetAInt(*argv)) < 0) { + index = 0; + post("%s - %s: invalid sort index specification - set to 0",thisName(),GetString(thisTag())); + } + --argc,++argv; + } + + bool rev = false; + if(argc) { + if(!CanbeBool(*argv)) + post("%s - %s: invalid sort direction specification - set to forward",thisName(),GetString(thisTag())); + else + rev = GetABool(*argv); + --argc,++argv; + } + + if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); + AtomList l; ! getrec(thisTag(),0,index,rev,get_norm,l); ToSysBang(3);
*************** *** 710,726 **** V pool::m_getrec(I argc,const A *argv) { ! I lvls = -1; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to infinite",thisName(),GetString(thisTag())); }
AtomList l; ! getrec(thisTag(),lvls,false,get_norm,l); ToSysBang(3);
--- 817,834 ---- V pool::m_getrec(I argc,const A *argv) { ! int lvls = -1; ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = -1; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls); } ! --argc,++argv; }
+ if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); + AtomList l; ! getrec(thisTag(),lvls,-1,false,get_norm,l); ToSysBang(3);
*************** *** 731,747 **** V pool::m_ogetrec(I argc,const A *argv) { ! I lvls = -1; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to infinite",thisName(),GetString(thisTag())); }
AtomList l; ! getrec(thisTag(),lvls,true,get_norm,l); ToSysBang(3);
--- 839,874 ---- V pool::m_ogetrec(I argc,const A *argv) { ! int lvls = -1; ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = -1; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls); } ! --argc,++argv; ! } ! ! int index = 0; ! if(argc) { ! if(!CanbeInt(*argv) || (index = GetAInt(*argv)) < 0) { ! index = 0; ! post("%s - %s: invalid sort index specification - set to 0",thisName(),GetString(thisTag())); ! } ! --argc,++argv; }
+ bool rev = false; + if(argc) { + if(!CanbeBool(*argv)) + post("%s - %s: invalid sort direction specification - set to forward",thisName(),GetString(thisTag())); + else + rev = GetABool(*argv); + --argc,++argv; + } + + if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); + AtomList l; ! getrec(thisTag(),lvls,index,rev,get_norm,l); ToSysBang(3);
*************** *** 750,768 ****
! I pool::getsub(const S *tag,I level,BL order,get_t how,const AtomList &rdir) { Atoms gldir(curdir); gldir.Append(rdir); ! I ret = 0;
const A **r = NULL; // CntSub is not used here because it doesn't allow checking for valid directory ! I cnt = pl->GetSub(gldir,r); if(!r) post("%s - %s: error retrieving directories",thisName(),GetString(tag)); else { ! I lv = level > 0?level-1:-1; ! for(I i = 0; i < cnt; ++i) { Atoms ndir(absdir?gldir:rdir); ndir.Append(*r[i]); --- 877,898 ----
! int pool::getsub(const S *tag,int level,int order,bool rev,get_t how,const AtomList &rdir) { Atoms gldir(curdir); gldir.Append(rdir); ! int ret = 0;
const A **r = NULL; // CntSub is not used here because it doesn't allow checking for valid directory ! int cnt = pl->GetSub(gldir,r); if(!r) post("%s - %s: error retrieving directories",thisName(),GetString(tag)); else { ! if(order >= 0) ! orderpairs(r,(Atoms *)NULL,cnt,order,rev); ! ! int lv = level > 0?level-1:-1; ! for(int i = 0; i < cnt; ++i) { Atoms ndir(absdir?gldir:rdir); ndir.Append(*r[i]); *************** *** 778,782 **** if(level != 0) { AtomList l(rdir); l.Append(*r[i]); ! ret += getsub(tag,lv,order,how,l); } } --- 908,912 ---- if(level != 0) { AtomList l(rdir); l.Append(*r[i]); ! ret += getsub(tag,lv,order,rev,how,l); } } *************** *** 787,805 **** }
! V pool::m_getsub(I argc,const A *argv) { ! I lvls = 0; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to 0",thisName(),GetString(thisTag())); } AtomList l; ! getsub(thisTag(),lvls,false,get_norm,l); ToSysBang(3);
--- 917,936 ---- }
! V pool::m_getsub(int argc,const A *argv) { ! int lvls = 0; ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = 0; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls); } ! --argc,++argv; } + + if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); AtomList l; ! getsub(thisTag(),lvls,-1,false,get_norm,l); ToSysBang(3);
*************** *** 808,826 ****
! V pool::m_ogetsub(I argc,const A *argv) { ! I lvls = 0; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to 0",thisName(),GetString(thisTag())); }
AtomList l; ! getsub(thisTag(),lvls,true,get_norm,l); ToSysBang(3);
--- 939,976 ----
! V pool::m_ogetsub(int argc,const A *argv) { ! int lvls = 0; ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = 0; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls); } ! --argc,++argv; ! } ! ! int index = 0; ! if(argc) { ! if(!CanbeInt(*argv) || (index = GetAInt(*argv)) < 0) { ! index = 0; ! post("%s - %s: invalid sort index specification - set to 0",thisName(),GetString(thisTag())); ! } ! --argc,++argv; }
+ bool rev = false; + if(argc) { + if(!CanbeBool(*argv)) + post("%s - %s: invalid sort direction specification - set to forward",thisName(),GetString(thisTag())); + else + rev = GetABool(*argv); + --argc,++argv; + } + + if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); + AtomList l; ! getsub(thisTag(),lvls,index,rev,get_norm,l); ToSysBang(3);
*************** *** 832,836 **** { AtomList l; ! I cnt = getrec(thisTag(),0,false,get_cnt,l); ToSysSymbol(3,thisTag()); ToSysBang(2); --- 982,986 ---- { AtomList l; ! I cnt = getrec(thisTag(),0,-1,false,get_cnt,l); ToSysSymbol(3,thisTag()); ToSysBang(2); *************** *** 841,859 **** }
! V pool::m_cntrec(I argc,const A *argv) { ! I lvls = -1; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to infinite",thisName(),GetString(thisTag())); } AtomList l; ! I cnt = getrec(thisTag(),lvls,false,get_cnt,l); ToSysSymbol(3,thisTag()); ToSysBang(2); --- 991,1010 ---- }
! V pool::m_cntrec(int argc,const A *argv) { ! int lvls = -1; ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = -1; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls); } ! --argc,++argv; } + + if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); AtomList l; ! I cnt = getrec(thisTag(),lvls,-1,false,get_cnt,l); ToSysSymbol(3,thisTag()); ToSysBang(2); *************** *** 867,883 **** V pool::m_cntsub(I argc,const A *argv) { ! I lvls = 0; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to 0",thisName(),GetString(thisTag())); }
AtomList l; ! I cnt = getsub(thisTag(),lvls,false,get_cnt,l); ToSysSymbol(3,thisTag()); ToSysBang(2); --- 1018,1035 ---- V pool::m_cntsub(I argc,const A *argv) { ! int lvls = 0; ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = 0; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(thisTag()),lvls); } ! --argc,++argv; }
+ if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(thisTag())); + AtomList l; ! I cnt = getsub(thisTag(),lvls,-1,false,get_cnt,l); ToSysSymbol(3,thisTag()); ToSysBang(2); *************** *** 891,895 **** { AtomList l; ! I cnt = getrec(thisTag(),0,false,get_print,l); post(""); } --- 1043,1047 ---- { AtomList l; ! I cnt = getrec(thisTag(),0,-1,false,get_print,l); post(""); } *************** *** 898,917 **** { const S *tag = thisTag(); ! I lvls = -1; ! if(argc > 0) { ! if(CanbeInt(argv[0])) { ! if(argc > 1) ! post("%s - %s: superfluous arguments ignored",thisName(),GetString(tag)); ! lvls = GetAInt(argv[0]); } ! else ! post("%s - %s: invalid level specification - set to infinite",thisName(),GetString(tag)); }
Atoms svdir(curdir); if(fromroot) curdir.Clear();
AtomList l; ! I cnt = getrec(tag,lvls,false,get_print,l); post("");
--- 1050,1071 ---- { const S *tag = thisTag(); ! int lvls = -1; ! ! if(argc) { ! if(!CanbeInt(*argv) || (lvls = GetAInt(*argv)) < -1) { ! lvls = 0; ! post("%s - %s: invalid level specification - set to %i",thisName(),GetString(tag),lvls); } ! --argc,++argv; }
+ if(argc) + post("%s - %s: superfluous arguments ignored",thisName(),GetString(tag)); + Atoms svdir(curdir); if(fromroot) curdir.Clear();
AtomList l; ! I cnt = getrec(tag,lvls,-1,false,get_print,l); post("");
Index: pool.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/pool/source/pool.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** pool.cpp 30 Sep 2006 19:23:16 -0000 1.23 --- pool.cpp 20 Jan 2007 14:27:39 -0000 1.24 *************** *** 16,22 **** --- 16,118 ---- #include <fstream>
+ #if FLEXT_OS == FLEXT_OS_WIN + #include <windows.h> // for charset conversion functions + #elif FLEXT_OS == FLEXT_OS_MAC + #include <Carbon/Carbon.h> + #else + static bool WCStoUTF8(char *sdst,const wchar_t *src,int dstlen) + { + unsigned char *dst = (unsigned char *)sdst; + unsigned char *max = dst+dstlen; + for(;;) { + wchar_t ud = *(src++); + if(ud < 128) { + if(dst+1 >= max) return false; + *(dst++) = (unsigned char)ud; + } + else if(ud < 2048) { + if(dst+2 >= max) return false; + *(dst++) = 192+(unsigned char)(ud/64); + *(dst++) = 128+(unsigned char)(ud%64); + } + else if(ud < 65535) { + if(dst+3 >= max) return false; + *(dst++) = 224+(unsigned char)(ud/4096); + *(dst++) = 128+(unsigned char)((ud/64)%64); + *(dst++) = 128+(unsigned char)(ud%64); + } + else if(ud < 2097151) { + if(dst+4 >= max) return false; + *(dst++) = 240+(unsigned char)(ud/262144); + *(dst++) = 128+(unsigned char)((ud/4096)%64); + *(dst++) = 128+(unsigned char)((ud/64)%64); + *(dst++) = 128+(unsigned char)(ud%64); + } + else if(ud < 67108863) { + if(dst+5 >= max) return false; + *(dst++) = 248+(unsigned char)(ud/16777216); + *(dst++) = 128+(unsigned char)((ud/262144)%64); + *(dst++) = 128+(unsigned char)((ud/4096)%64); + *(dst++) = 128+(unsigned char)((ud/64)%64); + *(dst++) = 128+(unsigned char)(ud%64); + } + else { + if(dst+6 >= max) return false; + *(dst++) = 252+(unsigned char)(ud/1073741824); + *(dst++) = 128+(unsigned char)((ud/16777216)%64); + *(dst++) = 128+(unsigned char)((ud/262144)%64); + *(dst++) = 128+(unsigned char)((ud/4096)%64); + *(dst++) = 128+(unsigned char)((ud/64)%64); + *(dst++) = 128+(unsigned char)(ud%64); + } + if(!ud) break; + } + return true; + } + + static bool UTF8toWCS(wchar_t *dst,const char *ssrc,int dstlen) + { + const unsigned char *src = (const unsigned char *)ssrc; + wchar_t *max = dst+dstlen; + for(;;) { + if(*src < 128) { + *dst = *(src++); + if(!*dst) break; + } + else if(*src < 224) { + *dst = wchar_t(src[0]-192)*64+wchar_t(src[1]-128); + src += 2; + } + else if(*src < 240) { + *dst = wchar_t(src[0]-224)*4096+wchar_t(src[1]-128)*64+wchar_t(src[2]-128); + src += 3; + } + else if(*src < 248) { + *dst = wchar_t(src[0]-240)*262144+wchar_t(src[1]-128)*4096+wchar_t(src[2]-128)*64+wchar_t(src[3]-128); + src += 4; + } + else if(*src < 252) { + *dst = wchar_t(src[0]-248)*16777216+wchar_t(src[1]-128)*262144+wchar_t(src[2]-128)*4096+wchar_t(src[3]-128)*64+wchar_t(src[4]-128); + src += 5; + } + else if(*src < 254) { + *dst = wchar_t(src[0]-252)*1073741824+wchar_t(src[1]-128)*16777216+wchar_t(src[2]-128)*262144+wchar_t(src[3]-128)*4096+wchar_t(src[4]-128)*64+wchar_t(src[5]-128); + src += 6; + } + else + // invalid string + return false; + + if(++dst >= max) return false; + } + return true; + } + + #endif + using namespace std;
+ inline I compare(I a,I b) { return a == b?0:(a < b?-1:1); } inline I compare(F a,F b) { return a == b?0:(a < b?-1:1); } *************** *** 488,496 **** }
! static const char *ReadAtom(const char *c,A &a) { ! // skip leading whitespace ! while(*c && isspace(*c)) ++c; if(!*c) return NULL;
--- 584,593 ---- }
+ static bool _isspace(char c) { return c > 0 && isspace(c); }
! static const char *ReadAtom(const char *c,A &a,bool utf8) { ! // skip leading whitespace (NON-ASCII character are < 0) ! while(*c && _isspace(*c)) ++c; if(!*c) return NULL;
*************** *** 519,527 **** // end of string ++c; ! FLEXT_ASSERT(!*c || isspace(*c)); *m = 0; break; } ! else if(!*c || (isspace(*c) && !escaped)) { *m = 0; break; --- 616,624 ---- // end of string ++c; ! FLEXT_ASSERT(!*c || _isspace(*c)); *m = 0; break; } ! else if(!*c || (_isspace(*c) && !escaped)) { *m = 0; break; *************** *** 551,561 **** } // no, it's a symbol ! else ! flext::SetString(a,tmp);
return c; }
! static BL ParseAtoms(C *tmp,flext::AtomList &l) { const int MAXATOMS = 1024; --- 648,701 ---- } // no, it's a symbol ! else { ! const char *c; ! if(utf8) { ! #if FLEXT_OS == FLEXT_OS_WIN ! wchar_t wtmp[1024]; ! int err = MultiByteToWideChar(CP_UTF8,0,tmp,strlen(tmp),wtmp,1024); ! if(!err) return false; ! err = WideCharToMultiByte(CP_ACP,0,wtmp,err,tmp,1024,NULL,FALSE); ! if(!err) return false; ! tmp[err] = 0; ! c = tmp; ! #elif FLEXT_OS == FLEXT_OS_MAC ! char ctmp[1024]; ! ! // is the output always MacRoman? ! TextEncoding inconv = CreateTextEncoding(kTextEncodingUnicodeDefault,kTextEncodingDefaultVariant,kUnicodeUTF8Format); ! TextEncoding outconv = CreateTextEncoding(kTextEncodingMacRoman,kTextEncodingDefaultVariant,kTextEncodingDefaultFormat); ! ! TECObjectRef converter; ! OSStatus status = TECCreateConverter(&converter,inconv,outconv); ! if(status) return false; ! ! ByteCount inlen,outlen; ! status = TECConvertText( ! converter, ! (ConstTextPtr)tmp,strlen(tmp),&inlen, ! (TextPtr)ctmp,sizeof(ctmp),&outlen ! ); ! ctmp[outlen] = 0; ! ! TECDisposeConverter(converter); ! c = ctmp; ! if(status) return false; ! #else ! wchar_t wtmp[1024]; ! size_t len = mbstowcs(wtmp,tmp,1024); ! if(len < 0) return false; ! if(!WCStoUTF8(tmp,wtmp,sizeof(tmp))) return false; ! c = tmp; ! #endif ! } ! else ! c = tmp; ! flext::SetString(a,c); ! }
return c; }
! static BL ParseAtoms(C *tmp,flext::AtomList &l,bool utf8) { const int MAXATOMS = 1024; *************** *** 563,567 **** t_atom atoms[MAXATOMS]; for(const char *t = tmp; *t && cnt < MAXATOMS; ++cnt) { ! t = ReadAtom(t,atoms[cnt]); if(!t) break; } --- 703,707 ---- t_atom atoms[MAXATOMS]; for(const char *t = tmp; *t && cnt < MAXATOMS; ++cnt) { ! t = ReadAtom(t,atoms[cnt],utf8); if(!t) break; } *************** *** 570,617 **** }
! static BL ParseAtoms(string &s,flext::AtomList &l) { ! return ParseAtoms((C *)s.c_str(),l); }
! static BL ReadAtoms(istream &is,flext::AtomList &l,C del) { ! C tmp[1024]; is.getline(tmp,sizeof tmp,del); if(is.eof() || !is.good()) return false; else ! return ParseAtoms(tmp,l); }
! static V WriteAtom(ostream &os,const A &a) { ! switch(a.a_type) { ! case A_FLOAT: ! os << a.a_w.w_float; ! break; ! #if FLEXT_SYS == FLEXT_SYS_MAX ! case A_LONG: ! os << a.a_w.w_long; ! break; #endif ! case A_SYMBOL: { ! const char *c = flext::GetString(flext::GetSymbol(a)); os << '"'; for(; *c; ++c) { ! if(isspace(*c) || *c == '\' || *c == ',' || *c == '"') os << '\'; os << *c; } os << '"'; - break; } ! } }
! static V WriteAtoms(ostream &os,const flext::AtomList &l) { for(I i = 0; i < l.Count(); ++i) { ! WriteAtom(os,l[i]); if(i < l.Count()-1) os << ' '; } --- 710,797 ---- }
! static BL ParseAtoms(string &s,flext::AtomList &l,bool utf8) { ! return ParseAtoms((C *)s.c_str(),l,utf8); }
! static bool ReadAtoms(istream &is,flext::AtomList &l,C del,bool utf8) { ! char tmp[1024]; is.getline(tmp,sizeof tmp,del); if(is.eof() || !is.good()) return false; else ! return ParseAtoms(tmp,l,utf8); }
! static bool WriteAtom(ostream &os,const A &a,bool utf8) { ! if(flext::IsFloat(a)) ! os << flext::GetFloat(a); ! else if(flext::IsInt(a)) ! os << flext::GetInt(a); ! else if(flext::IsSymbol(a)) { ! const char *c = flext::GetString(a); ! if(utf8) { ! #if FLEXT_OS == FLEXT_OS_WIN ! char tmp[1024]; ! wchar_t wtmp[1024]; ! int err = MultiByteToWideChar(CP_ACP,0,c,strlen(c),wtmp,1024); ! if(!err) return false; ! err = WideCharToMultiByte(CP_UTF8,0,wtmp,err,tmp,1024,NULL,FALSE); ! if(!err) return false; ! tmp[err] = 0; ! c = tmp; ! #elif FLEXT_OS == FLEXT_OS_MAC ! char tmp[1024]; ! ! // is the input always MacRoman? ! TextEncoding inconv = CreateTextEncoding(kTextEncodingMacRoman,kTextEncodingDefaultVariant,kTextEncodingDefaultFormat); ! TextEncoding outconv = CreateTextEncoding(kTextEncodingUnicodeDefault,kTextEncodingDefaultVariant,kUnicodeUTF8Format); ! ! TECObjectRef converter; ! OSStatus status = TECCreateConverter(&converter,inconv,outconv); ! if(status) return false; ! ! ByteCount inlen,outlen; ! status = TECConvertText( ! converter, ! (ConstTextPtr)c,strlen(c),&inlen, ! (TextPtr)tmp,sizeof(tmp),&outlen ! ); ! tmp[outlen] = 0; ! ! TECDisposeConverter(converter); ! ! if(status) return false; ! c = tmp; ! #else ! char tmp[1024]; ! wchar_t wtmp[1024]; ! if(!UTF8toWCS(wtmp,c,1024)) return false; ! size_t len = wcstombs(tmp,wtmp,sizeof(tmp)); ! if(len < 0) return false; ! c = tmp; #endif ! } ! os << '"'; for(; *c; ++c) { ! // escape some special characters ! if(_isspace(*c) || *c == '\' || *c == ',' || *c == '"') os << '\'; os << *c; } os << '"'; } ! else ! FLEXT_ASSERT(false); ! return true; }
! static void WriteAtoms(ostream &os,const flext::AtomList &l,bool utf8) { for(I i = 0; i < l.Count(); ++i) { ! WriteAtom(os,l[i],utf8); if(i < l.Count()-1) os << ' '; } *************** *** 623,629 **** Atoms d,k,*v = new Atoms; BL r = ! ReadAtoms(is,d,',') && ! ReadAtoms(is,k,',') && ! ReadAtoms(is,*v,'\n');
if(r) { --- 803,809 ---- Atoms d,k,*v = new Atoms; BL r = ! ReadAtoms(is,d,',',false) && ! ReadAtoms(is,k,',',false) && ! ReadAtoms(is,*v,'\n',false);
if(r) { *************** *** 656,664 **** for(I vi = 0; vi < vsize; ++vi) { for(poolval *ix = vals[vi].v; ix; ix = ix->nxt) { ! WriteAtoms(os,dir); os << " , "; ! WriteAtom(os,ix->key); os << " , "; ! WriteAtoms(os,*ix->data); os << endl; ++cnt; --- 836,844 ---- for(I vi = 0; vi < vsize; ++vi) { for(poolval *ix = vals[vi].v; ix; ix = ix->nxt) { ! WriteAtoms(os,dir,false); os << " , "; ! WriteAtom(os,ix->key,false); os << " , "; ! WriteAtoms(os,*ix->data,false); os << endl; ++cnt; *************** *** 667,671 **** if(!cnt) { // no key/value pairs present -> force empty directory ! WriteAtoms(os,dir); os << " , ," << endl; } --- 847,851 ---- if(!cnt) { // no key/value pairs present -> force empty directory ! WriteAtoms(os,dir,false); os << " , ," << endl; } *************** *** 707,711 **** for(;;) { // eat whitespace ! while(isspace(is.peek())) is.get();
// no tag begin -> break --- 887,891 ---- for(;;) { // eat whitespace ! while(_isspace(is.peek())) is.get();
// no tag begin -> break *************** *** 754,768 **** char *tb = tmp,*te = t-1,*tf;
! for(; isspace(*tb); ++tb) {} if(*tb == '/') { // slash at the beginning -> end tag tag.type = xmltag::t_end; ! for(++tb; isspace(*tb); ++tb) {} } else { ! for(; isspace(*te); --te) {} if(*te == '/') { // slash at the end -> empty tag ! for(--te; isspace(*te); --te) {} tag.type = xmltag::t_empty; } --- 934,948 ---- char *tb = tmp,*te = t-1,*tf;
! for(; _isspace(*tb); ++tb) {} if(*tb == '/') { // slash at the beginning -> end tag tag.type = xmltag::t_end; ! for(++tb; _isspace(*tb); ++tb) {} } else { ! for(; _isspace(*te); --te) {} if(*te == '/') { // slash at the end -> empty tag ! for(--te; _isspace(*te); --te) {} tag.type = xmltag::t_empty; } *************** *** 773,779 ****
// copy tag text without slashes ! for(tf = tb; tf <= te && *tf && !isspace(*tf); ++tf) {} tag.tag.assign(tb,tf-tb); ! while(isspace(*tf)) ++tf; tag.attr.assign(tf,te-tf+1);
--- 953,959 ----
// copy tag text without slashes ! for(tf = tb; tf <= te && *tf && !_isspace(*tf); ++tf) {} tag.tag.assign(tb,tf-tb); ! while(_isspace(*tf)) ++tf; tag.attr.assign(tf,te-tf+1);
*************** *** 825,829 **** post("pool - XML load: value data already given, ignoring new data"); else ! ret = ParseAtoms(s,v); } else // inkey --- 1005,1009 ---- post("pool - XML load: value data already given, ignoring new data"); else ! ret = ParseAtoms(s,v,true); } else // inkey *************** *** 832,836 **** post("pool - XML load, value key already given, ignoring new key"); else ! ret = ParseAtoms(s,k); } else { --- 1012,1016 ---- post("pool - XML load, value key already given, ignoring new key"); else ! ret = ParseAtoms(s,k,true); } else { *************** *** 842,846 **** post("pool - XML load: dir key already given, ignoring new key"); else ! ReadAtom(s.c_str(),dkey);
ret = true; --- 1022,1026 ---- post("pool - XML load: dir key already given, ignoring new key"); else ! ReadAtom(s.c_str(),dkey,true);
ret = true; *************** *** 894,898 **** post("pool - XML load: dir key must be given prior to values");
! // else: one directoy level has been left unintialized, ignore items } else { --- 1074,1078 ---- post("pool - XML load: dir key must be given prior to values");
! // else: one directory level has been left unintialized, ignore items } else { *************** *** 982,986 **** indent(os,ind+i+1); os << "<key>"; ! WriteAtom(os,dir[ind+i]); os << "</key>" << endl; } --- 1162,1166 ---- indent(os,ind+i+1); os << "<key>"; ! WriteAtom(os,dir[ind+i],true); os << "</key>" << endl; } *************** *** 990,996 **** indent(os,ind+lvls); os << "<value><key>"; ! WriteAtom(os,ix->key); os << "</key><data>"; ! WriteAtoms(os,*ix->data); os << "</data></value>" << endl; } --- 1170,1176 ---- indent(os,ind+lvls); os << "<value><key>"; ! WriteAtom(os,ix->key,true); os << "</key><data>"; ! WriteAtoms(os,*ix->data,true); os << "</data></value>" << endl; }