void Init_lzoruby() { if (lzo_init() != LZO_E_OK) { rb_warn("internal error - lzo_init() failed !!!"); return; } LZO = rb_define_module("LZO"); LZO_Error = rb_define_class_under(LZO, "Error", rb_eStandardError); rb_define_const(LZO, "VERSION", rb_str_new2(VERSION)); rb_define_const(LZO, "LZO_VERSION", rb_str_new2(lzo_version_string())); rb_define_module_function(LZO, "compress", lzoruby_compress, -1); rb_define_module_function(LZO, "decompress", lzoruby_decompress, 1); rb_define_module_function(LZO, "adler32", lzoruby_adler32, 2); }
int start(int argc, char ** argv) { //extern const char * _malloc_options; //_malloc_options = "A"; if (lzo_init() != LZO_E_OK) { sys_err("lzo_init() failed"); return 0; } thecore_init(25, heartbeat); signal_timer_disable(); return 1; }
int main(int argc, char *argv[]) { lzo_bytep buf; lzo_uint step; if (argc >= 2 && strcmp(argv[1],"-v") == 0) opt_verbose = 1; if (lzo_init() != LZO_E_OK) { printf("lzo_init() failed !!!\n"); return 3; } buf = (lzo_bytep) lzo_malloc(2*BLOCK_LEN + 256); if (buf == NULL) { printf("out of memory\n"); return 2; } printf("Align init: %p ( 0x%lx )\n", buf, (unsigned long) buf); for (step = 1; step <= 65536L; step *= 2) { lzo_bytep block = buf; long n; unsigned gap; gap = __lzo_align_gap(block,step); block = LZO_PTR_ALIGN_UP(block,step); if (opt_verbose >= 1) printf("STEP %5ld: GAP: %5lu %p %p %5ld\n", (long) step, (long) gap, buf, block, (long) (block - buf)); n = align_test(block,BLOCK_LEN,step); if (n == 0) return 1; if ((n + 1) * step != BLOCK_LEN) { printf("error 4: %ld %ld\n",(long)step,n); return 1; } } lzo_free(buf); printf("Alignment test passed.\n"); return 0; }
void lzoex_init( void(*lzo_error_fun)(const char* ) ) { if( lzo_error_fun == 0 ) { lzo_error_func = _lzo_default_error; } else { lzo_error_func = lzo_error_fun; } if( lzo_init() != LZO_E_OK ) { lzo_error_func( "init lzo failed\n" ); } }
int __lzo_cdecl_main main(int argc, char *argv[]) { int r; int i = 1; lzo_wildargv(&argc, &argv); printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); progname = argv[0]; if (i < argc && argv[i][0] == '-') opt_overhead = atoi(&argv[i++][1]); #if 1 if (opt_overhead != 0 && opt_overhead < 8) { printf("%s: invalid overhead value %ld\n", progname, (long)opt_overhead); exit(1); } #endif if (i >= argc) { printf("usage: %s [-overhead_in_bytes] file..\n", progname); exit(1); } /* * Step 1: initialize the LZO library */ if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); exit(1); } /* * Step 2: process files */ for (r = 0; r == 0 && i < argc; i++) r = do_file(argv[i]); printf("\nDone. Successfully processed %lu bytes in %lu files.\n", total_in, total_files); return r; }
bool CTextureBundleXBT::OpenBundle() { Cleanup(); // Find the correct texture file (skin or theme) CStdString strPath; if (m_themeBundle) { // if we are the theme bundle, we only load if the user has chosen // a valid theme (or the skin has a default one) CStdString theme = CSettings::Get().GetString("lookandfeel.skintheme"); if (!theme.IsEmpty() && theme.CompareNoCase("SKINDEFAULT")) { CStdString themeXBT(URIUtils::ReplaceExtension(theme, ".xbt")); strPath = URIUtils::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media"); strPath = URIUtils::AddFileToFolder(strPath, themeXBT); } else { return false; } } else { strPath = URIUtils::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media/Textures.xbt"); } strPath = CSpecialProtocol::TranslatePathConvertCase(strPath); // Load the texture file if (!m_XBTFReader.Open(strPath)) { return false; } CLog::Log(LOGDEBUG, "%s - Opened bundle %s", __FUNCTION__, strPath.c_str()); m_TimeStamp = m_XBTFReader.GetLastModificationTimestamp(); if (lzo_init() != LZO_E_OK) { return false; } return true; }
int main(int argc, char *argv[]) { lzo_bytep block; lzo_uint block_len; lzo_uint32 adler, crc; if (argc < 0 && argv == NULL) /* avoid warning about unused args */ return 0; if (lzo_init() != LZO_E_OK) { printf("lzo_init() failed !!!\n"); return 4; } /* prepare the block */ block_len = 128 * 1024L; block = (lzo_bytep) lzo_malloc(block_len); if (block == NULL) { printf("out of memory\n"); return 3; } lzo_memset(block, 0, block_len); /* adler32 checksum */ adler = lzo_adler32(0, NULL, 0); adler = lzo_adler32(adler, block, block_len); if (adler != 0x001e0001UL) { printf("adler32 checksum error !!! (0x%08lx)\n", (long) adler); return 2; } /* crc32 checksum */ crc = lzo_crc32(0, NULL, 0); crc = lzo_crc32(crc, block, block_len); if (crc != 0x7ee8cdcdUL) { printf("crc32 checksum error !!! (0x%08lx)\n", (long) crc); return 1; } lzo_free(block); printf("Checksum test passed.\n"); return 0; }
int pack_set_compression(pack_t pack, int compression) { if (unlikely(pack->running)) return EALREADY; if (compression == PACK_QUICKLZ) { #ifdef __QUICKLZ pack->thread.write_callback = &pack_quicklz_write_callback; glc_log(pack->glc, GLC_INFO, "pack", "compressing using QuickLZ"); #else glc_log(pack->glc, GLC_ERROR, "pack", "QuickLZ not supported"); return ENOTSUP; #endif } else if (compression == PACK_LZO) { #ifdef __LZO pack->thread.write_callback = &pack_lzo_write_callback; glc_log(pack->glc, GLC_INFO, "pack", "compressing using LZO"); lzo_init(); #else glc_log(pack->glc, GLC_ERROR, "pack", "LZO not supported"); return ENOTSUP; #endif } else if (compression == PACK_LZJB) { #ifdef __LZJB pack->thread.write_callback = &pack_lzjb_write_callback; glc_log(pack->glc, GLC_INFO, "pack", "compressing using LZJB"); #else glc_log(pack->glc, GLC_ERROR, "pack", "LZJB not supported"); return ENOTSUP; #endif } else { glc_log(pack->glc, GLC_ERROR, "pack", "unknown/unsupported compression algorithm 0x%02x", compression); return ENOTSUP; } pack->compression = compression; return 0; }
int ckptImageInitCompression() { buffer = F_REAL_MMAP(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (buffer != MAP_FAILED) { compress_work_buffer = buffer; compress_temp = (char *)buffer + LZO1X_1_MEM_COMPRESS; } else return 0; if (lzo_init() != LZO_E_OK) return 0; return 1; }
void *_tc_recencode(const void *ptr, int size, int *sp, void *op){ if(!_tc_lzo_init){ if(lzo_init() != LZO_E_OK) return NULL; _tc_lzo_init = false; } lzo_bytep buf = MYMALLOC(size + (size >> 4) + 80); if(!buf) return NULL; lzo_uint bsiz; char wrkmem[LZO1X_1_MEM_COMPRESS]; if(lzo1x_1_compress((lzo_bytep)ptr, size, buf, &bsiz, wrkmem) != LZO_E_OK){ MYFREE(buf); return NULL; } buf[bsiz] = '\0'; *sp = bsiz; return (char *)buf; }
bool CTextureBundleXBT::OpenBundle() { Cleanup(); // Find the correct texture file (skin or theme) if (m_themeBundle) { // if we are the theme bundle, we only load if the user has chosen // a valid theme (or the skin has a default one) std::string theme = CSettings::GetInstance().GetString(CSettings::SETTING_LOOKANDFEEL_SKINTHEME); if (!theme.empty() && !StringUtils::EqualsNoCase(theme, "SKINDEFAULT")) { std::string themeXBT(URIUtils::ReplaceExtension(theme, ".xbt")); m_path = URIUtils::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media"); m_path = URIUtils::AddFileToFolder(m_path, themeXBT); } else { return false; } } else { m_path = URIUtils::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media/Textures.xbt"); } m_path = CSpecialProtocol::TranslatePathConvertCase(m_path); // Load the texture file if (!XFILE::CXbtManager::GetInstance().GetReader(CURL(m_path), m_XBTFReader)) { return false; } CLog::Log(LOGDEBUG, "%s - Opened bundle %s", __FUNCTION__, m_path.c_str()); m_TimeStamp = m_XBTFReader->GetLastModificationTimestamp(); if (lzo_init() != LZO_E_OK) { return false; } return true; }
bool CTextureBundleXBT::OpenBundle() { Cleanup(); // Find the correct texture file (skin or theme) CStdString strPath; if (m_themeBundle) { // if we are the theme bundle, we only load if the user has chosen // a valid theme (or the skin has a default one) CStdString theme = g_guiSettings.GetString("lookandfeel.skintheme"); if (!theme.IsEmpty() && theme.CompareNoCase("SKINDEFAULT")) { CStdString themeXBT(CUtil::ReplaceExtension(theme, ".xbt")); strPath = CUtil::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media"); strPath = CUtil::AddFileToFolder(strPath, themeXBT); } else { return false; } } else { strPath = CUtil::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media/Textures.xbt"); } strPath = PTH_IC(strPath); // Load the texture file if (!m_XBTFReader.Open(strPath)) { return false; } m_TimeStamp = m_XBTFReader.GetLastModificationTimestamp(); if (lzo_init() != LZO_E_OK) { return false; } return true; }
static char *_qdbm_lzoencode_impl(const char *ptr, int size, int *sp) { char wrkmem[LZO1X_1_MEM_COMPRESS]; lzo_bytep buf; lzo_uint bsiz; if(!_qdbm_lzo_init) { if(lzo_init() != LZO_E_OK) return NULL; _qdbm_lzo_init = TRUE; } if(size < 0) size = strlen(ptr); if(!(buf = malloc(size + size / 16 + 80))) return NULL; if(lzo1x_1_compress((lzo_bytep)ptr, size, buf, &bsiz, wrkmem) != LZO_E_OK) { free(buf); return NULL; } buf[bsiz] = '\0'; *sp = bsiz; return (char *)buf; }
int __stdcall Compress(unsigned char* buf, int bInSz , unsigned char* bOut, int bOutSz) { #pragma EXPORT int r; char* b = (char*)lastError; if(!initilized){ if (lzo_init() != LZO_E_OK) { sprintf(b,"internal error - lzo_init() failed !!!\n"); strcat(b,"(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); return -1; } initilized = true; } lzo_uint in_len = bInSz; lzo_uint out_len = bOutSz; if(out_len <= in_len ){ sprintf(b,"Error Compress outbuffer (%d) must be larger than inbuffer(%d) just in case.",bOutSz,bInSz); return -2; } r = lzo1x_1_compress(buf,in_len,bOut,&out_len,wrkmem); if (r != LZO_E_OK) { /* this should NEVER happen */ sprintf(b, "internal error - compression failed: %d", r); return -3; } /* check for an incompressible block */ if (out_len >= in_len) { sprintf(b,"This block contains incompressible data."); return -4; } return out_len; }
static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len, u64 *decompress_len) { size_t new_len; size_t in_len; size_t out_len = 0; size_t tot_len; size_t tot_in; int ret; ret = lzo_init(); if (ret != LZO_E_OK) { fprintf(stderr, "lzo init returned %d\n", ret); return -1; } tot_len = read_compress_length(inbuf); inbuf += LZO_LEN; tot_in = LZO_LEN; while (tot_in < tot_len) { in_len = read_compress_length(inbuf); inbuf += LZO_LEN; tot_in += LZO_LEN; new_len = lzo1x_worst_compress(PAGE_CACHE_SIZE); ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len, (unsigned char *)outbuf, &new_len, NULL); if (ret != LZO_E_OK) { fprintf(stderr, "failed to inflate: %d\n", ret); return -1; } out_len += new_len; outbuf += new_len; inbuf += in_len; tot_in += in_len; } *decompress_len = out_len; return 0; }
int unpack_init(unpack_t *unpack, glc_t *glc) { *unpack = (unpack_t) calloc(1, sizeof(struct unpack_s)); (*unpack)->glc = glc; (*unpack)->thread.flags = GLC_THREAD_WRITE | GLC_THREAD_READ; (*unpack)->thread.ptr = *unpack; (*unpack)->thread.thread_finish_callback = &unpack_thread_finish_callback; (*unpack)->thread.read_callback = &unpack_read_callback; (*unpack)->thread.write_callback = &unpack_write_callback; (*unpack)->thread.finish_callback = &unpack_finish_callback; (*unpack)->thread.threads = glc_threads_hint(glc); #ifdef __LZO lzo_init(); #endif return 0; }
byte* LZEncoder::getPage() { buffer=encoder->getPage(); if(buffer != NULL){ //startPos = encoder->getStartPos(); //numValsPerPage=encoder->getNumValsPerPage(); //valsize=encoder->getValSize(); bufferSize = encoder->getBufferSize(); }else{ return NULL; } memset(page, 0, PAGE_SIZE); if(lzo_init() != LZO_E_OK) throw UnexpectedException("LZEncoder: Error, lzo initialization error!"); lzo_byte *compressedData = (lzo_bytep) lzo_malloc(bufferSize + bufferSize / 64 + 16 + 3); //new byte[numValsPerPage*valsize + numValsPerPage*valsize / 64 + 16 + 3]; lzo_byte *wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); int r = 0; r = lzo1x_1_compress((const unsigned char*)buffer, bufferSize, compressedData, &sizeCompressedData, wrkmem); if (r != LZO_E_OK) { throw new UnexpectedException("LZEncoder: compress error!"); } // Writing header for decoder to use *((int*) page)=sizeCompressedData; *((int*) (page+sizeof(int)))=bufferSize; //*((int*) (page+2*sizeof(int)))=startPos; //*((int*) (page+3*sizeof(int)))=valsize; if (sizeCompressedData>PAGE_SIZE-2*sizeof(int)) throw CodingException("LZEncoder: Error, compressed data larger than what we can fit on page"); memcpy(page+2*sizeof(int), compressedData, sizeCompressedData); delete[] compressedData; lzo_free(wrkmem); return page; }
int lcdLoadLZOImage(char *fname) { unsigned char img[864]; UINT readbytes; FRESULT ret; FIL file; uint16_t sz; lzo_uint len; ret=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ); if(ret) return 1; ret = lzo_init(); if(ret) return 2; ret = f_read(&file, &sz, 2, &readbytes); if(ret || readbytes != 2) { return 3; } if(sz == 0) { // uncompressed ret = f_read(&file, (unsigned char *)lcdBuffer, 864, &readbytes); if(ret) return 4; } else { ret = f_read(&file, img, sz, &readbytes); if(ret || readbytes != sz) { return 5; } lzo1x_decompress(img, sz, (unsigned char *)lcdBuffer, &len, NULL); } f_close(&file); return 0; }
void uncompress_lzo(uint8_t *dst, uint8_t *src) { unsigned len; lzo_uint out_len; int status; if(lzo_init() != LZO_E_OK) { crash("init fail"); } for(;;) { len = (*src++ << 8); len += (*src++); if(len == 0) break; status = lzo1x_decompress(src, len, dst, &out_len, NULL); if(status != LZO_E_OK) { crash("fail"); } dst += out_len; src += len; } }
enum ral_status f_lzo_compress(char *dest, size_t *destLen, const char *source, size_t sourceLen, void *param){ enum ral_status ret; if (lzo_init() != LZO_E_OK){ return RAL_EUNKNOWN; } unsigned char *workingMemory = (unsigned char*)malloc(LZO1X_1_11_MEM_COMPRESS); if( workingMemory == NULL ){ return RAL_ENOT_ENOUGH_MEM; } int res = lzo1x_1_11_compress((const unsigned char *)source, sourceLen, (unsigned char *)dest, destLen, workingMemory); switch (res){ case LZO_E_OK: ret = RAL_OK; break; default: ret = RAL_EUNKNOWN; break; } free(workingMemory); return ret; }
bool setup_decompression_buffers(JCR *jcr, uint32_t *decompress_buf_size) { uint32_t compress_buf_size; /* * Use the same buffer size to decompress all data. */ compress_buf_size = jcr->buf_size; if (compress_buf_size < DEFAULT_NETWORK_BUFFER_SIZE) { compress_buf_size = DEFAULT_NETWORK_BUFFER_SIZE; } *decompress_buf_size = compress_buf_size + 12 + ((compress_buf_size + 999) / 1000) + 100; #ifdef HAVE_LZO if (!jcr->compress.inflate_buffer && lzo_init() != LZO_E_OK) { Jmsg(jcr, M_FATAL, 0, _("LZO init failed\n")); return false; } #endif return true; }
void xboxIMGCompression::InitializeLZO( void ) { if ( !this->isUsingLZO ) { bool couldInit = false; if ( _lzoRefCount == 0 ) { couldInit = ( lzo_init() == LZO_E_OK ); } else { couldInit = true; } if ( couldInit ) { // Alright, we initialized. this->isUsingLZO = true; _lzoRefCount++; } } }
int __stdcall DeCompress(unsigned char* buf, int bInSz , unsigned char* bOut, int bOutSz) { #pragma EXPORT int r; char* b = (char*)lastError; if(!initilized){ if (lzo_init() != LZO_E_OK) { sprintf(b,"internal error - lzo_init() failed !!!\n"); strcat(b,"(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); return -1; } initilized = true; } lzo_uint in_len = bInSz; lzo_uint out_len = bOutSz; lzo_uint new_len; if(out_len <= in_len ){ sprintf(b,"Error Compress outbuffer (%d) must be larger than inbuffer(%d)",bOutSz,bInSz); return -2; } r = lzo1x_decompress_safe(buf,in_len,bOut,&out_len,NULL); if (r != LZO_E_OK) { sprintf(b,"internal error - decompression failed: %d", r); return -3; } return out_len; }
int register_lzo(char **version, char **date) { #ifdef HAVE_LZO_LIB H5Z_class_t filter_class = { H5Z_CLASS_T_VERS, /* H5Z_class_t version */ (H5Z_filter_t)(FILTER_LZO), /* filter_id */ 1, 1, /* Encoding and decoding enabled */ "lzo", /* comment */ NULL, /* can_apply_func */ NULL, /* set_local_func */ (H5Z_func_t)(lzo_deflate) /* filter_func */ }; /* Init the LZO library */ if (lzo_init()!=LZO_E_OK) { fprintf(stderr, "Problems initializing LZO library\n"); *version = NULL; *date = NULL; return 0; /* lib is not available */ } /* Register the lzo compressor */ H5Zregister(&filter_class); *version = strdup(LZO_VERSION_STRING); *date = strdup(LZO_VERSION_DATE); return 1; /* lib is available */ #else *version = NULL; *date = NULL; return 0; /* lib is not available */ #endif /* HAVE_LZO_LIB */ }
FileTreeItem::FileTreeItem(const QFileInfo &fileInfo, QMimeType mimeType, FileTreeItem *parent) : itemData(5), parentItem(parent), fileInfo(fileInfo), mimeType(mimeType), checked(false) { lzo_init(); if (!fileInfo.isDir()) { QFile file(fileInfo.absoluteFilePath()); file.open(QFile::ReadOnly); compressedData.resize(file.size() + (file.size() / 16) + 64 + 3); QVector<unsigned char> blob(file.size()); QVector<unsigned char> wrkmem(LZO1X_999_MEM_COMPRESS, Qt::Uninitialized); file.read((char*) blob.data(), file.size()); size_t out_len = compressedData.size(); //lzo1x_999_compress((const lzo_bytep) blob.data(), blob.size(), (lzo_bytep) compressedData.data(), &out_len, wrkmem.data()); compressedData.resize(out_len); } }
char* lzbench_lzo_init(size_t ) { lzo_init(); return (char*) malloc(LZO1B_999_MEM_COMPRESS); }
// // D_DoomMain // void D_DoomMain (void) { unsigned p; extern std::string defdemoname; gamestate = GS_STARTUP; M_FindResponseFile(); // [ML] 23/1/07 - Add Response file support back in if (lzo_init () != LZO_E_OK) // [RH] Initialize the minilzo package. I_FatalError ("Could not initialize LZO routines"); C_ExecCmdLineParams (false, true); // [Nes] test for +logfile command Printf (PRINT_HIGH, "Heapsize: %u megabytes\n", got_heapsize); M_LoadDefaults (); // load before initing other systems C_ExecCmdLineParams (true, false); // [RH] do all +set commands on the command line const char* iwad = Args.CheckValue("-iwad"); if (!iwad) iwad = ""; std::vector<std::string> newwadfiles, newpatchfiles; newwadfiles.push_back(iwad); D_AddWadCommandLineFiles(newwadfiles); D_AddDehCommandLineFiles(newpatchfiles); D_LoadResourceFiles(newwadfiles, newpatchfiles); I_Init(); V_Init(); atterm(V_Close); #ifdef _WIN32 const char *sdlv = getenv("SDL_VIDEODRIVER"); Printf (PRINT_HIGH, "Using %s video driver.\n",sdlv); #endif C_InitConsole(screen->width, screen->height, true); atterm(C_ShutdownConsole); // SDL needs video mode set up first before input code can be used I_InitInput(); D_Init(); atterm(D_Shutdown); // Base systems have been inited; enable cvar callbacks cvar_t::EnableCallbacks(); // [RH] User-configurable startup strings. Because BOOM does. if (GStrings(STARTUP1)[0]) Printf (PRINT_HIGH, "%s\n", GStrings(STARTUP1)); if (GStrings(STARTUP2)[0]) Printf (PRINT_HIGH, "%s\n", GStrings(STARTUP2)); if (GStrings(STARTUP3)[0]) Printf (PRINT_HIGH, "%s\n", GStrings(STARTUP3)); if (GStrings(STARTUP4)[0]) Printf (PRINT_HIGH, "%s\n", GStrings(STARTUP4)); if (GStrings(STARTUP5)[0]) Printf (PRINT_HIGH, "%s\n", GStrings(STARTUP5)); // Nomonsters sv_nomonsters = Args.CheckParm("-nomonsters"); // Respawn sv_monstersrespawn = Args.CheckParm("-respawn"); // Fast sv_fastmonsters = Args.CheckParm("-fast"); // developer mode devparm = Args.CheckParm ("-devparm"); // Record a vanilla demo p = Args.CheckParm ("-record"); if (p) { autorecord = true; autostart = true; demorecordfile = Args.GetArg (p+1); } // get skill / episode / map from parms strcpy (startmap, (gameinfo.flags & GI_MAPxx) ? "MAP01" : "E1M1"); // Check for -playdemo, play a single demo then quit. p = Args.CheckParm ("-playdemo"); // Hack to check for +playdemo command, since if you just add it normally // it won't run because it's attempting to run a demo and still set up the // first map as normal. if (!p) p = Args.CheckParm ("+playdemo"); if (p && p < Args.NumArgs()-1) { Printf (PRINT_HIGH, "Playdemo parameter found on command line.\n"); singledemo = true; defdemoname = Args.GetArg (p+1); } // [SL] check for -timedemo (was removed at some point) p = Args.CheckParm("-timedemo"); if (p && p < Args.NumArgs() - 1) { singledemo = true; G_TimeDemo(Args.GetArg(p + 1)); } const char *val = Args.CheckValue ("-skill"); if (val) { sv_skill.Set (val[0]-'0'); } p = Args.CheckParm ("-warp"); if (p && p < Args.NumArgs() - (1+(gameinfo.flags & GI_MAPxx ? 0 : 1))) { int ep, map; if (gameinfo.flags & GI_MAPxx) { ep = 1; map = atoi (Args.GetArg(p+1)); } else { ep = Args.GetArg(p+1)[0]-'0'; map = Args.GetArg(p+2)[0]-'0'; } strncpy (startmap, CalcMapName (ep, map), 8); autostart = true; } // [RH] Hack to handle +map p = Args.CheckParm ("+map"); if (p && p < Args.NumArgs()-1) { strncpy (startmap, Args.GetArg (p+1), 8); ((char *)Args.GetArg (p))[0] = '-'; autostart = true; } if (devparm) Printf (PRINT_HIGH, "%s", GStrings(D_DEVSTR)); // D_DEVSTR // [RH] Now that all text strings are set up, // insert them into the level and cluster data. G_SetLevelStrings(); // [RH] Parse through all loaded mapinfo lumps G_ParseMapInfo(); // [ML] Parse musinfo lump G_ParseMusInfo(); // [RH] Parse any SNDINFO lumps S_ParseSndInfo(); // NOTE(jsd): Set up local player color EXTERN_CVAR(cl_color); R_BuildPlayerTranslation (0, V_GetColorFromString (NULL, cl_color.cstring())); I_FinishClockCalibration (); Printf (PRINT_HIGH, "D_CheckNetGame: Checking network game status.\n"); D_CheckNetGame (); // [RH] Initialize items. Still only used for the give command. :-( InitItems (); // [RH] Lock any cvars that should be locked now that we're // about to begin the game. cvar_t::EnableNoSet (); // [RH] Now that all game subsystems have been initialized, // do all commands on the command line other than +set C_ExecCmdLineParams (false, false); Printf_Bold("\n\35\36\36\36\36 Odamex Client Initialized \36\36\36\36\37\n"); if(gamestate != GS_CONNECTING) Printf(PRINT_HIGH, "Type connect <address> or use the Odamex Launcher to connect to a game.\n"); Printf(PRINT_HIGH, "\n"); setmodeneeded = false; // [Fly] we don't need to set a video mode here! //gamestate = GS_FULLCONSOLE; // [SL] allow the user to pass the name of a netdemo as the first argument. // This allows easy launching of netdemos from Windows Explorer or other GUIs. // [Xyltol] if (Args.GetArg(1)) { std::string demoarg = Args.GetArg(1); if (demoarg.find(".odd") != std::string::npos) CL_NetDemoPlay(demoarg); } p = Args.CheckParm("-netplay"); if (p) { if (Args.GetArg(p + 1)) { std::string filename = Args.GetArg(p + 1); CL_NetDemoPlay(filename); } else { Printf(PRINT_HIGH, "No netdemo filename specified.\n"); } } // denis - bring back the demos if ( gameaction != ga_loadgame ) { if (autostart || netgame || singledemo) { if (singledemo) G_DoPlayDemo(); else { if(autostart) { // single player warp (like in g_level) serverside = true; sv_allowexit = "1"; sv_freelook = "1"; sv_allowjump = "1"; sv_allowredscreen = "1"; sv_gametype = GM_COOP; players.clear(); players.push_back(player_t()); players.back().playerstate = PST_REBORN; consoleplayer_id = displayplayer_id = players.back().id = 1; } G_InitNew (startmap); if (autorecord) if (G_RecordDemo(demorecordfile.c_str())) G_BeginRecording(); } } else { if (gamestate != GS_CONNECTING) gamestate = GS_HIDECONSOLE; C_HideConsole(); if (gamemode == commercial_bfg) // DOOM 2 BFG Edtion AddCommandString("menu_main"); D_StartTitle (); // start up intro loop } } // denis - this will run a demo and quit p = Args.CheckParm ("+demotest"); if (p && p < Args.NumArgs()-1) { demotest = 1; defdemoname = Args.GetArg (p+1); G_DoPlayDemo(); while(demoplayback) { DObject::BeginFrame (); G_Ticker(); DObject::EndFrame (); gametic++; } } else { demotest = 0; D_DoomLoop (); // never returns } }
bool setup_compression_buffers(JCR *jcr, bool compatible, uint32_t compression_algorithm, uint32_t *compress_buf_size) { uint32_t wanted_compress_buf_size; switch (compression_algorithm) { case 0: /* * No compression requested. */ break; #ifdef HAVE_LIBZ case COMPRESS_GZIP: { z_stream *pZlibStream; /** * Use compressBound() to get an idea what zlib thinks * what the upper limit is of what it needs to compress * a buffer of x bytes. To that we add 18 bytes and the size * of an compression header. * * This gives a bit extra plus room for the sparse addr if any. * Note, we adjust the read size to be smaller so that the * same output buffer can be used without growing it. * * The zlib compression workset is initialized here to minimize * the "per file" load. The jcr member is only set, if the init * was successful. */ wanted_compress_buf_size = compressBound(jcr->buf_size) + 18 + (int)sizeof(comp_stream_header); if (wanted_compress_buf_size > *compress_buf_size) { *compress_buf_size = wanted_compress_buf_size; } /* * See if this compression algorithm is already setup. */ if (jcr->compress.workset.pZLIB) { return true; } pZlibStream = (z_stream *)malloc(sizeof(z_stream)); memset(pZlibStream, 0, sizeof(z_stream)); pZlibStream->zalloc = Z_NULL; pZlibStream->zfree = Z_NULL; pZlibStream->opaque = Z_NULL; pZlibStream->state = Z_NULL; if (deflateInit(pZlibStream, Z_DEFAULT_COMPRESSION) == Z_OK) { jcr->compress.workset.pZLIB = pZlibStream; } else { Jmsg(jcr, M_FATAL, 0, _("Failed to initialize ZLIB compression\n")); free(pZlibStream); return false; } break; } #endif #ifdef HAVE_LZO case COMPRESS_LZO1X: { lzo_voidp pLzoMem; /** * For LZO1X compression the recommended value is: * output_block_size = input_block_size + (input_block_size / 16) + 64 + 3 + sizeof(comp_stream_header) * * The LZO compression workset is initialized here to minimize * the "per file" load. The jcr member is only set, if the init * was successful. */ wanted_compress_buf_size = jcr->buf_size + (jcr->buf_size / 16) + 64 + 3 + (int)sizeof(comp_stream_header); if (wanted_compress_buf_size > *compress_buf_size) { *compress_buf_size = wanted_compress_buf_size; } /* * See if this compression algorithm is already setup. */ if (jcr->compress.workset.pLZO) { return true; } pLzoMem = (lzo_voidp) malloc(LZO1X_1_MEM_COMPRESS); memset(pLzoMem, 0, LZO1X_1_MEM_COMPRESS); if (lzo_init() == LZO_E_OK) { jcr->compress.workset.pLZO = pLzoMem; } else { Jmsg(jcr, M_FATAL, 0, _("Failed to initialize LZO compression\n")); free(pLzoMem); return false; } break; } #endif #ifdef HAVE_FASTLZ case COMPRESS_FZFZ: case COMPRESS_FZ4L: case COMPRESS_FZ4H: { int level, zstat; zfast_stream *pZfastStream; if (compatible) { non_compatible_compression_algorithm(jcr, compression_algorithm); return false; } if (compression_algorithm == COMPRESS_FZ4H) { level = Z_BEST_COMPRESSION; } else { level = Z_BEST_SPEED; } /* * For FASTLZ compression the recommended value is: * output_block_size = input_block_size + (input_block_size / 10 + 16 * 2) + sizeof(comp_stream_header) * * The FASTLZ compression workset is initialized here to minimize * the "per file" load. The jcr member is only set, if the init * was successful. */ wanted_compress_buf_size = jcr->buf_size + (jcr->buf_size / 10 + 16 * 2) + (int)sizeof(comp_stream_header); if (wanted_compress_buf_size > *compress_buf_size) { *compress_buf_size = wanted_compress_buf_size; } /* * See if this compression algorithm is already setup. */ if (jcr->compress.workset.pZFAST) { return true; } pZfastStream = (zfast_stream *)malloc(sizeof(zfast_stream)); memset(pZfastStream, 0, sizeof(zfast_stream)); pZfastStream->zalloc = Z_NULL; pZfastStream->zfree = Z_NULL; pZfastStream->opaque = Z_NULL; pZfastStream->state = Z_NULL; if ((zstat = fastlzlibCompressInit(pZfastStream, level)) == Z_OK) { jcr->compress.workset.pZFAST = pZfastStream; } else { Jmsg(jcr, M_FATAL, 0, _("Failed to initialize FASTLZ compression\n")); free(pZfastStream); return false; } break; } #endif default: unknown_compression_algorithm(jcr, compression_algorithm); return false; } return true; }
int main(int argc, char *argv[]) { if(argc < 2) { fatal("PACK file argument required"); } if (lzo_init() != LZO_E_OK) { fatal("lzo_init() failed\n"); } char * packFileName = argv[1]; FILE * pFile = fopen(packFileName, "rb"); if(!pFile) { fatal("could not open '%s' for reading", packFileName); } struct pack_header header; if(fread(&header, sizeof(header), 1, pFile) != 1) { fatal("PACK file too small (not enough bytes for the complete header)"); } if(memcmp(header.magic, PACK_MAGIC, sizeof(PACK_MAGIC))) { fatal("PACK has invalid magic"); } char * indexData = NULL; size_t indexDataSize = 0; if(!carve_lzo(pFile, header.compressed_index_size, &indexData, &indexDataSize)) { fatal("failed to decompress PACK index"); } size_t startOfEntries = ftell(pFile); struct pack_index index; if(!pack_index_parse(indexData, indexDataSize, &index)) { fatal("failed to parse PACK index"); } char * dirName = NULL; char *packBaseName = basename(packFileName, false); asprintf(&dirName, "%s-out/", packBaseName); if(!create_dir(dirName)) { fatal("failed to create output directory"); } printf("Outputing files to %s\n", dirName); printf("Index listing:\n"); int i; for(i = 0; i < index.numEntries; i++) { struct pack_index_entry * e = index.index[i]; printf("{%d} %30s (compressed size %u -> %u, offset %6u, CRC-32 0x%08x, U1 %u, U3 %u)\n", i+1, e->name, e->compressedSize, e->decompressedSize, e->offset, e->crc, e->unk1, e->unk3); fseek(pFile, e->offset+startOfEntries, SEEK_SET); char *outName = NULL; asprintf(&outName, "./%s%s", dirName, e->name); //printf("Writting %s...\n", outName); if(e->compressedSize > 0) { if(!carve_lzo_to_file(pFile, outName, e->compressedSize)) { fatal("failed to unpack file %s", e->name); } } else { FILE * fp = fopen(outName, "wb"); // create a blank file fclose(fp); } } /*uint32_t sizeGood = 0x1df9-compressedSize-8-0x1c-0x7da; printf("Size good %u (0x%x)\n", sizeGood, sizeGood); carve_lzo(pFile, "file1", sizeGood); printf("\n"); // what is the size for this guy? carve_lzo(pFile, "file2", compressedSize); printf("\n");*/ return 0; }
int __lzo_cdecl_main main(int argc, char *argv[]) { int i = 1; int r; const char *dict_name; FILE *f; time_t t_total; int level = 7; lzo_wildargv(&argc, &argv); printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); progname = argv[0]; if (i < argc && argv[i][0] == '-' && isdigit(argv[i][1])) level = atoi(&argv[i++][1]); if (i + 1 >= argc || level < 1 || level > 9) { printf("usage: %s [-level] [ dictionary-file | -n ] file...\n", progname); exit(1); } printf("Compression level is LZO1X-999/%d\n", level); /* * Step 1: initialize the LZO library */ if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); exit(1); } /* * Step 2: prepare the dictionary */ dict = (lzo_bytep) lzo_malloc(DICT_LEN); if (dict == NULL) { printf("%s: out of memory\n", progname); exit(1); } dict_name = argv[i++]; if (strcmp(dict_name,"-n") == 0) { dict_name = "empty"; dict_len = 0; } else { f = fopen(dict_name,"rb"); if (!f) { printf("%s: cannot open dictionary file %s\n", progname, dict_name); exit(1); } dict_len = (lzo_uint) lzo_fread(f,dict,DICT_LEN); fclose(f); } dict_adler32 = lzo_adler32(0,NULL,0); dict_adler32 = lzo_adler32(dict_adler32,dict,dict_len); printf("Using dictionary '%s', %ld bytes, ID 0x%08lx.\n", dict_name, (long) dict_len, (long) dict_adler32); /* * Step 3: process files */ t_total = time(NULL); for (r = 0; r == 0 && i < argc; i++) r = do_file(argv[i], level); t_total = time(NULL) - t_total; lzo_free(dict); if (total_n > 1) print_file("***TOTALS***",total_d_len,total_c_len); printf("Dictionary compression test %s, execution time %lu seconds.\n", r == 0 ? "passed" : "FAILED", (unsigned long) t_total); return r; }