// create_app static entry_ref create_app(const char *filename, const char *signature, bool install = false, bool makeExecutable = true, uint32 appFlags = B_SINGLE_LAUNCH) { BString testApp; CHK(find_test_app("RosterBroadcastTestApp1", &testApp) == B_OK); system((string("cp ") + testApp.String() + " " + filename).c_str()); if (makeExecutable) system((string("chmod a+x ") + filename).c_str()); BFile file; CHK(file.SetTo(filename, B_READ_WRITE) == B_OK); BAppFileInfo appFileInfo; CHK(appFileInfo.SetTo(&file) == B_OK); if (signature) CHK(appFileInfo.SetSignature(signature) == B_OK); CHK(appFileInfo.SetAppFlags(appFlags) == B_OK); if (install && signature) CHK(BMimeType(signature).Install() == B_OK); // We write the signature into a separate attribute, just in case we // decide to also test files without BEOS:APP_SIG attribute. BString signatureString(signature); file.WriteAttrString("signature", &signatureString); return ref_for_path(filename); }
bool FrBWTIndex::uncompress(const char *infile, const char *outfile) const { if (infile && *infile && outfile && *outfile && strcmp(infile,outfile) != 0) { FILE *infp = fopen(infile,FrFOPEN_READ_MODE) ; if (!infp) return false ; bool success = false ; // step 1: copy the header to the output file BWTHeader header ; Fr_read_BWT_header(infp,&header,signatureString()) ; if (header.m_compression == BWT_UNCOMP) { fclose(infp) ; errno = EINVAL ; return false ; // already uncompressed } FILE *outfp = fopen(outfile,FrFOPEN_WRITE_MODE) ; if (!outfp) { int e = errno ; fclose(infp) ; errno = e ; return false ; } // copy m_C to the output file copy_bytes(infp,outfp, (header.m_C_length + 1) * FrBWTIndex::bytesPerPointer()) ; // step 2: decode each byte and write the resulting pointers to the // output file FrBWTIndex compr ; compr.parseHeader(header,infile) ; compr.loadCompressionData(infp,header) ; uint32_t succ = 0 ; for (size_t i = 0 ; i < header.m_FL_length ; i++) { int byte = fgetc(infp) ; succ = compr.getCompressedSuccessor(i,byte,succ) ; Fr_write_long(outfp,succ) ; } // step 3: update header pointers header.m_compression = BWT_UNCOMP ; header.m_bucketsize = 0 ; header.m_buckets_offset = header.m_bucketpool_offset = 0 ; header.m_bucketpool_length = 0; header.m_maxdelta = 0 ; fseek(infp,0L,SEEK_END) ; size_t udata_size = ftell(infp) - header.m_userdata ; fseek(infp,header.m_userdata,SEEK_SET) ; header.m_userdata = (size_t)ftell(outfp) ; Fr_write_BWT_header(outfp,&header,signatureString()) ; // step 4: copy any user data from the uncompressed file into new file copy_bytes(infp,outfp,udata_size) ; fclose(infp) ; fclose(outfp) ; return success ; } return false ; }
bool FrBWTIndex::compress(const char *infile, const char *outfile) const { if (infile && *infile && outfile && *outfile && strcmp(infile,outfile) != 0) { FILE *infp = fopen(infile,FrFOPEN_READ_MODE) ; if (!infp) return false ; // step 1: copy the header to the output file, updating // compression-parameter fields BWTHeader header ; Fr_read_BWT_header(infp,&header,signatureString()) ; if (header.m_compression != BWT_UNCOMP) { fclose(infp) ; errno = EINVAL ; return false ; // already compressed } FILE *outfp = fopen(outfile,FrFOPEN_WRITE_MODE) ; if (!outfp) { int e = errno ; fclose(infp) ; errno = e ; return false ; } // (for now, we'll just hard-code some reasonable values for the params) header.m_bucketsize = DEFAULT_BUCKET_SIZE ; header.m_maxdelta = 255 - header.m_bucketsize ; // while we're at it, put in the pre-determined locations of the // bucket pointers and bucket pool size_t numbuckets = ((header.m_FL_length + header.m_bucketsize - 1) / header.m_bucketsize) ; header.m_buckets_offset = (header.m_FL_offset + header.m_FL_length) ; header.m_bucketpool_offset = (header.m_buckets_offset + numbuckets * bytesPerPointer()) ; Fr_write_BWT_header(outfp,&header,signatureString()) ; // copy m_C to the output file copy_bytes(infp,outfp, (header.m_C_length + 1) * FrBWTIndex::bytesPerPointer()) ; // step 2: convert m_items values to differences and encode in bytes, // writing the results to the output file CompressionBuffers compbuffers(header.m_bucketsize) ; compbuffers.setupEOR(header.m_eor_handling != 0,header.m_EOR) ; size_t prev = 0 ; bool success = true ; for (size_t i = 0 ; i < header.m_FL_length ; i++) { size_t succ ; if (!Fr_read_long(infp,succ)) { success = false ; break ; } (void)compbuffers.encode(i,prev,succ) ; if (!dump_buffers(outfp, compbuffers, header.m_FL_offset, header.m_buckets_offset, header.m_bucketpool_offset)) { success = false ; break ; } if (((i+1) % header.m_bucketsize) == 0) compbuffers.nextBucket() ; prev = succ ; } success = dump_buffers(outfp,compbuffers,header.m_buckets_offset, header.m_bucketpool_offset,true) ; header.m_bucketpool_length = compbuffers.poolSize() / bytesPerPointer() ; // step 3: update header pointers fseek(infp,0L,SEEK_END) ; size_t udata_size = ftell(infp) - header.m_userdata ; fseek(infp,header.m_userdata,SEEK_SET) ; header.m_userdata = (size_t)ftell(outfp) ; Fr_write_BWT_header(outfp,&header,signatureString()) ; // step 4: copy any user data from the uncompressed file into new file copy_bytes(infp,outfp,udata_size) ; fclose(infp) ; fclose(outfp) ; return success ; } return false ; }