// compressor must be initialized! void testCompressDecompress(int size_kb, ICompressor &compressor, IDecompressor& decompressor) { GrowBuf data; GrowBuf compressed; GrowBuf decompressed; randData(data, size_kb); compress(compressor, data, compressed); decompress(decompressor, compressed, decompressed); CPPUNIT_ASSERT_MESSAGE( "decompressed data is smaller", data.getlen() <= decompressed.getlen() ); CPPUNIT_ASSERT_MESSAGE( "decompressed data is larger", data.getlen() >= decompressed.getlen() ); CPPUNIT_ASSERT_MESSAGE( "decompressed data is different", !memcmp(data.get(), decompressed.get(), data.getlen()) ); }
static QCString detab(const QCString &s) { static int tabSize = Config_getInt(TAB_SIZE); GrowBuf out; int size = s.length(); const char *data = s.data(); int i=0; int col=0; const int maxIndent=1000000; // value representing infinity int minIndent=maxIndent; while (i<size) { char c = data[i++]; switch(c) { case '\t': // expand tab { int stop = tabSize - (col%tabSize); //printf("expand at %d stop=%d\n",col,stop); col+=stop; while (stop--) out.addChar(' '); } break; case '\n': // reset colomn counter out.addChar(c); col=0; break; case ' ': // increment column counter out.addChar(c); col++; break; default: // non-whitespace => update minIndent out.addChar(c); if (c<0 && i<size) // multibyte sequence { out.addChar(data[i++]); // >= 2 bytes if (((uchar)c&0xE0)==0xE0 && i<size) { out.addChar(data[i++]); // 3 bytes } if (((uchar)c&0xF0)==0xF0 && i<size) { out.addChar(data[i++]); // 4 byres } } if (col<minIndent) minIndent=col; col++; } } out.addChar(0); //printf("detab refIndent=%d\n",refIndent); return out.get(); }
void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) { DWORD v; WORD wSize; int p, p1; WCHAR *KeyName, *KeyValue; strm.resize(0); SaveVersionHeader (strm, 0, sizeof (VS_FIXEDFILEINFO), 0, L"VS_VERSION_INFO", &m_FixedInfo); DefineList *pChildStrings = m_ChildStringLists.get_strings(Index); if ( pChildStrings->getnum() > 0 ) { GrowBuf stringInfoStream; int codepage = m_ChildStringLists.get_codepage(Index); LANGID langid = m_ChildStringLists.get_lang(Index); WCHAR Buff[16]; _snwprintf(Buff, COUNTOF(Buff), L"%04x%04x", langid, codepage); SaveVersionHeader (stringInfoStream, 0, 0, 0, Buff, &ZEROS); for ( int i = 0; i < pChildStrings->getnum(); i++ ) { PadStream (stringInfoStream); p = stringInfoStream.getlen(); KeyName = wcsdup_fromTchar(pChildStrings->getname(i), codepage); KeyValue = wcsdup_fromTchar(pChildStrings->getvalue(i), codepage); SaveVersionHeader (stringInfoStream, 0, WORD(wcslen(KeyValue) + 1), 1, KeyName, (void*)KeyValue); free(KeyName); free(KeyValue); wSize = WORD(stringInfoStream.getlen() - p); *(WORD*)((PBYTE)stringInfoStream.get()+p)=wSize; } wSize = WORD(stringInfoStream.getlen()); *(WORD*)((PBYTE)stringInfoStream.get())=wSize; PadStream (strm); p = strm.getlen(); SaveVersionHeader (strm, 0, 0, 0, L"StringFileInfo", &ZEROS); strm.add (stringInfoStream.get(), stringInfoStream.getlen()); wSize = WORD(strm.getlen() - p); *(WORD*)((PBYTE)strm.get()+p)=wSize; } // Show all languages avaiable using Var-Translations if ( m_ChildStringLists.getnum() > 0 ) { PadStream (strm); p = strm.getlen(); SaveVersionHeader (strm, 0, 0, 0, L"VarFileInfo", &ZEROS); PadStream (strm); p1 = strm.getlen(); SaveVersionHeader (strm, 0, 0, 0, L"Translation", &ZEROS); // First add selected code language translation v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index)); strm.add (&v, sizeof (v)); for ( int k =0; k < m_ChildStringLists.getnum(); k++ ) { if ( k != Index ) { v = MAKELONG(m_ChildStringLists.get_lang(k), m_ChildStringLists.get_codepage(k)); strm.add (&v, sizeof (v)); } } wSize = WORD(strm.getlen() - p1); *(WORD*)((PBYTE)strm.get()+p1)=wSize; wSize = WORD(sizeof (int) * m_ChildStringLists.getnum()); p1+=sizeof(WORD); *(WORD*)((PBYTE)strm.get()+p1)=wSize; wSize = WORD(strm.getlen() - p); *(WORD*)((PBYTE)strm.get()+p)=wSize; } wSize = WORD(strm.getlen()); *(WORD*)((PBYTE)strm.get())=wSize; }
void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index) { DWORD v; WORD wSize; int p, p1; strm.resize(0); SaveVersionHeader(strm, 0, sizeof (VS_FIXEDFILEINFO), 0, L"VS_VERSION_INFO", &m_FixedInfo); DefineList *pChildStrings = m_ChildStringLists.get_strings(Index); if ( pChildStrings->getnum() > 0 ) { GrowBuf stringInfoStream; int codepage = m_ChildStringLists.get_codepage(Index); LANGID langid = m_ChildStringLists.get_lang(Index); wchar_t Buff[16]; _snwprintf(Buff, COUNTOF(Buff), L"%04x%04x", langid, codepage); SaveVersionHeader(stringInfoStream, 0, 0, 0, Buff, &ZEROS); for ( int i = 0; i < pChildStrings->getnum(); i++ ) { PadStream (stringInfoStream); WCToUTF16LEHlpr cnvName, cnvValue; if (!cnvName.Create(pChildStrings->getname(i), codepage)) throw std::runtime_error("Unicode conversion failed"); if (!cnvValue.Create(pChildStrings->getvalue(i), codepage)) throw std::runtime_error("Unicode conversion failed"); p = stringInfoStream.getlen(); SaveVersionHeaderUTF16LE(stringInfoStream, 0, WORD(StrLenUTF16(cnvValue.Get()) + 1), 1, cnvName.Get(), (void*)cnvValue.Get()); cnvName.Destroy(), cnvValue.Destroy(); wSize = WORD(stringInfoStream.getlen() - p); *(WORD*)((PBYTE)stringInfoStream.get()+p)=wSize; } wSize = WORD(stringInfoStream.getlen()); *(WORD*)((PBYTE)stringInfoStream.get())=wSize; PadStream (strm); p = strm.getlen(); SaveVersionHeader(strm, 0, 0, 0, L"StringFileInfo", &ZEROS); strm.add (stringInfoStream.get(), stringInfoStream.getlen()); wSize = WORD(strm.getlen() - p); *(WORD*)((PBYTE)strm.get()+p)=wSize; } // Show all languages avaiable using Var-Translations if ( m_ChildStringLists.getnum() > 0 ) { PadStream (strm); p = strm.getlen(); SaveVersionHeader(strm, 0, 0, 0, L"VarFileInfo", &ZEROS); PadStream (strm); p1 = strm.getlen(); SaveVersionHeader(strm, 0, 0, 0, L"Translation", &ZEROS); // First add selected code language translation v = MAKELONG(m_ChildStringLists.get_lang(Index), m_ChildStringLists.get_codepage(Index)); strm.add (&v, sizeof (v)); for ( int k =0; k < m_ChildStringLists.getnum(); k++ ) { if ( k != Index ) { v = MAKELONG(m_ChildStringLists.get_lang(k), m_ChildStringLists.get_codepage(k)); strm.add (&v, sizeof (v)); } } wSize = WORD(strm.getlen() - p1); *(WORD*)((PBYTE)strm.get()+p1)=wSize; wSize = WORD(sizeof (int) * m_ChildStringLists.getnum()); p1+=sizeof(WORD); *(WORD*)((PBYTE)strm.get()+p1)=wSize; wSize = WORD(strm.getlen() - p); *(WORD*)((PBYTE)strm.get()+p)=wSize; } wSize = WORD(strm.getlen()); *(WORD*)((PBYTE)strm.get())=wSize; }