From 7e1d9bc7686793268cd159fa2b28973e726924b3 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Fri, 23 Jun 2006 16:23:31 +0200 Subject: [PATCH] Split options_t::crp into multiple structs. --- .hgignore | 2 ++ src/conf.h | 7 ++++++- src/main.cpp | 20 ++++++++++---------- src/options.h | 15 +++++++++++++-- src/packer.cpp | 22 +++++++++++----------- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.hgignore b/.hgignore index b9626df8..fab9cfb6 100644 --- a/.hgignore +++ b/.hgignore @@ -14,6 +14,7 @@ syntax: glob *.lib *.map *.o +*.obj *.out *.py[cdo] *.so @@ -28,6 +29,7 @@ doc/*.man doc/*.ps doc/*.tex +src/GNUmakefile src/MMakefile src/compress_nrv* src/*.rc diff --git a/src/conf.h b/src/conf.h index 188838fd..e91a8f24 100644 --- a/src/conf.h +++ b/src/conf.h @@ -217,8 +217,9 @@ struct lzma_compress_config_t unsigned dict_size; unsigned mf_passes; #else - unsigned dummy; + int dummy; #endif + void reset() { memset(this, 0, sizeof(*this)); } }; #define upx_compress_config_p upx_compress_config_t * @@ -226,6 +227,10 @@ struct upx_compress_config_t { lzma_compress_config_t conf_lzma; ucl_compress_config_t conf_ucl; + void reset() { + conf_lzma.reset(); + memset(&conf_ucl, 0xff, sizeof(conf_ucl)); + } }; diff --git a/src/main.cpp b/src/main.cpp index eb3cf318..e70e664f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK; void init_options(struct options_t *o) { memset(o, 0, sizeof(*o)); - memset(&o->crp, 0xff, sizeof(o->crp)); + o->crp.reset(); o->cmd = CMD_NONE; o->method = -1; @@ -537,7 +537,7 @@ static int do_option(int optc, const char *arg) opt->method = -1; opt->all_filters = true; opt->filter = -1; - opt->crp.m_size = 999999; + opt->crp.crp_ucl.m_size = 999999; /* fallthrough */ case 900: // --best if (!set_method(-1, 10)) @@ -600,27 +600,27 @@ static int do_option(int optc, const char *arg) opt->all_methods = true; opt->method = -1; break; - // compression parms + // compression runtime parameters case 531: - getoptvar(&opt->crp.c_flags, 0, 3); + getoptvar(&opt->crp.crp_ucl.c_flags, 0, 3); break; case 532: - getoptvar(&opt->crp.s_level, 0, 2); + getoptvar(&opt->crp.crp_ucl.s_level, 0, 2); break; case 533: - getoptvar(&opt->crp.h_level, 0, 1); + getoptvar(&opt->crp.crp_ucl.h_level, 0, 1); break; case 534: - getoptvar(&opt->crp.p_level, 0, 7); + getoptvar(&opt->crp.crp_ucl.p_level, 0, 7); break; case 535: - getoptvar(&opt->crp.max_offset, 256u, ~0u); + getoptvar(&opt->crp.crp_ucl.max_offset, 256u, ~0u); break; case 536: - getoptvar(&opt->crp.max_match, 16u, ~0u); + getoptvar(&opt->crp.crp_ucl.max_match, 16u, ~0u); break; case 537: - if (getoptvar(&opt->crp.m_size, 10000u, 999999u) != 0) + if (getoptvar(&opt->crp.crp_ucl.m_size, 10000u, 999999u) != 0) e_optval("--crp-ms="); break; // backup diff --git a/src/options.h b/src/options.h index a0a53c99..0511fde0 100644 --- a/src/options.h +++ b/src/options.h @@ -84,7 +84,11 @@ struct options_t { int overlay; // compression runtime parameters - see struct ucl_compress_config_t - struct { + struct crp_lzma_t { + int dummy; + void reset() { memset(this, 0, sizeof(*this)); } + }; + struct crp_ucl_t { unsigned max_offset; unsigned max_match; int s_level; @@ -92,7 +96,14 @@ struct options_t { int p_level; int c_flags; unsigned m_size; - } crp; + void reset() { memset(this, 0xff, sizeof(*this)); } + }; + struct crp_t { + crp_lzma_t crp_lzma; + crp_ucl_t crp_ucl; + void reset() { crp_lzma.reset(); crp_ucl.reset(); } + }; + crp_t crp; // CPU enum { diff --git a/src/packer.cpp b/src/packer.cpp index a1d3d72a..a9f66a7d 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -171,23 +171,23 @@ bool Packer::compress(upx_bytep in, upx_bytep out, // set compression paramters upx_compress_config_t conf; - memset(&conf.conf_ucl, 0xff, sizeof(conf.conf_ucl)); + conf.reset(); // arguments if (max_offset != 0) conf.conf_ucl.max_offset = max_offset; if (max_match != 0) conf.conf_ucl.max_match = max_match; // options - if (opt->crp.c_flags != -1) - conf.conf_ucl.c_flags = opt->crp.c_flags; - if (opt->crp.p_level != -1) - conf.conf_ucl.p_level = opt->crp.p_level; - if (opt->crp.h_level != -1) - conf.conf_ucl.h_level = opt->crp.h_level; - if (opt->crp.max_offset != UINT_MAX && opt->crp.max_offset < conf.conf_ucl.max_offset) - conf.conf_ucl.max_offset = opt->crp.max_offset; - if (opt->crp.max_match != UINT_MAX && opt->crp.max_match < conf.conf_ucl.max_match) - conf.conf_ucl.max_match = opt->crp.max_match; + if (opt->crp.crp_ucl.c_flags != -1) + conf.conf_ucl.c_flags = opt->crp.crp_ucl.c_flags; + if (opt->crp.crp_ucl.p_level != -1) + conf.conf_ucl.p_level = opt->crp.crp_ucl.p_level; + if (opt->crp.crp_ucl.h_level != -1) + conf.conf_ucl.h_level = opt->crp.crp_ucl.h_level; + if (opt->crp.crp_ucl.max_offset != UINT_MAX && opt->crp.crp_ucl.max_offset < conf.conf_ucl.max_offset) + conf.conf_ucl.max_offset = opt->crp.crp_ucl.max_offset; + if (opt->crp.crp_ucl.max_match != UINT_MAX && opt->crp.crp_ucl.max_match < conf.conf_ucl.max_match) + conf.conf_ucl.max_match = opt->crp.crp_ucl.max_match; // Avoid too many progress bar updates. 64 is s->bar_len in ui.cpp. unsigned step = (ph.u_len < 64*1024) ? 0 : ph.u_len / 64;