1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Split options_t::crp into multiple structs.

This commit is contained in:
Markus F.X.J. Oberhumer 2006-06-23 16:23:31 +02:00
parent ba065ec1d8
commit 7e1d9bc768
5 changed files with 42 additions and 24 deletions

View File

@ -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

View File

@ -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));
}
};

View File

@ -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

View File

@ -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 {

View File

@ -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;