xdelta3-main.h (xdelta3-3.0.10) | : | xdelta3-main.h (xdelta3-3.0.11) | ||
---|---|---|---|---|
skipping to change at line 222 | skipping to change at line 222 | |||
#define DEFAULT_VERBOSE 0 | #define DEFAULT_VERBOSE 0 | |||
/* Program options: various command line flags and options. */ | /* Program options: various command line flags and options. */ | |||
static int option_stdout = 0; | static int option_stdout = 0; | |||
static int option_force = 0; | static int option_force = 0; | |||
static int option_verbose = DEFAULT_VERBOSE; | static int option_verbose = DEFAULT_VERBOSE; | |||
static int option_quiet = 0; | static int option_quiet = 0; | |||
static int option_use_appheader = 1; | static int option_use_appheader = 1; | |||
static uint8_t* option_appheader = NULL; | static uint8_t* option_appheader = NULL; | |||
static int option_use_secondary = 0; | static int option_use_secondary = 1; | |||
static const char* option_secondary = NULL; | static const char* option_secondary = NULL; | |||
static int option_use_checksum = 1; | static int option_use_checksum = 1; | |||
static const char* option_smatch_config = NULL; | static const char* option_smatch_config = NULL; | |||
static int option_no_compress = 0; | static int option_no_compress = 0; | |||
static int option_no_output = 0; /* do not write output */ | static int option_no_output = 0; /* do not write output */ | |||
static const char *option_source_filename = NULL; | static const char *option_source_filename = NULL; | |||
static int option_level = XD3_DEFAULT_LEVEL; | static int option_level = XD3_DEFAULT_LEVEL; | |||
static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE; | static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE; | |||
static usize_t option_winsize = XD3_DEFAULT_WINSIZE; | static usize_t option_winsize = XD3_DEFAULT_WINSIZE; | |||
skipping to change at line 341 | skipping to change at line 341 | |||
} else { | } else { | |||
size_t ignore = fwrite(buf, 1, size, stderr); | size_t ignore = fwrite(buf, 1, size, stderr); | |||
(void) ignore; | (void) ignore; | |||
} | } | |||
} | } | |||
static int | static int | |||
main_version (void) | main_version (void) | |||
{ | { | |||
/* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, Joshua MacDonald\\n\");" $ */ | /* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, Joshua MacDonald\\n\");" $ */ | |||
XPR(NTR "Xdelta version 3.0.10, Copyright (C) 2007, 2008, 2009, 2010, 2011, 20 12, 2013, 2014, 2015 Joshua MacDonald\n"); | XPR(NTR "Xdelta version 3.0.11, Copyright (C) 2007, 2008, 2009, 2010, 2011, 20 12, 2013, 2014, 2015 Joshua MacDonald\n"); | |||
XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n"); | XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n"); | |||
XPR(NTR "This is free software, and you are welcome to redistribute it\n"); | XPR(NTR "This is free software, and you are welcome to redistribute it\n"); | |||
XPR(NTR "under certain conditions; see \"COPYING\" for details.\n"); | XPR(NTR "under certain conditions; see \"COPYING\" for details.\n"); | |||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | |||
} | } | |||
static int | static int | |||
main_config (void) | main_config (void) | |||
{ | { | |||
main_version (); | main_version (); | |||
skipping to change at line 394 | skipping to change at line 394 | |||
} | } | |||
static void | static void | |||
reset_defaults(void) | reset_defaults(void) | |||
{ | { | |||
option_stdout = 0; | option_stdout = 0; | |||
option_force = 0; | option_force = 0; | |||
option_verbose = DEFAULT_VERBOSE; | option_verbose = DEFAULT_VERBOSE; | |||
option_quiet = 0; | option_quiet = 0; | |||
option_appheader = NULL; | option_appheader = NULL; | |||
option_use_secondary = 0; | option_use_secondary = 1; | |||
option_secondary = NULL; | option_secondary = NULL; | |||
option_smatch_config = NULL; | option_smatch_config = NULL; | |||
option_no_compress = 0; | option_no_compress = 0; | |||
option_no_output = 0; | option_no_output = 0; | |||
option_source_filename = NULL; | option_source_filename = NULL; | |||
program_name = NULL; | program_name = NULL; | |||
appheader_used = NULL; | appheader_used = NULL; | |||
main_bdata = NULL; | main_bdata = NULL; | |||
main_bsize = 0; | main_bsize = 0; | |||
allow_fake_source = 0; | allow_fake_source = 0; | |||
skipping to change at line 859 | skipping to change at line 859 | |||
xfile->mode = mode; | xfile->mode = mode; | |||
XD3_ASSERT (name != NULL); | XD3_ASSERT (name != NULL); | |||
XD3_ASSERT (! main_file_isopen (xfile)); | XD3_ASSERT (! main_file_isopen (xfile)); | |||
if (name[0] == 0) | if (name[0] == 0) | |||
{ | { | |||
XPR(NT "invalid file name: empty string\n"); | XPR(NT "invalid file name: empty string\n"); | |||
return XD3_INVALID; | return XD3_INVALID; | |||
} | } | |||
IF_DEBUG1(DP(RINT "[main] open source %s\n", name)); | ||||
#if XD3_STDIO | #if XD3_STDIO | |||
xfile->file = fopen (name, XOPEN_STDIO); | xfile->file = fopen (name, XOPEN_STDIO); | |||
ret = (xfile->file == NULL) ? get_errno () : 0; | ret = (xfile->file == NULL) ? get_errno () : 0; | |||
#elif XD3_POSIX | #elif XD3_POSIX | |||
/* TODO: Should retry this call if interrupted, similar to read/write */ | /* TODO: Should retry this call if interrupted, similar to read/write */ | |||
if ((ret = open (name, XOPEN_POSIX, XOPEN_MODE)) < 0) | if ((ret = open (name, XOPEN_POSIX, XOPEN_MODE)) < 0) | |||
{ | { | |||
ret = get_errno (); | ret = get_errno (); | |||
skipping to change at line 1030 | skipping to change at line 1032 | |||
/* POSIX is unbuffered, while STDIO is buffered. main_file_read() | /* POSIX is unbuffered, while STDIO is buffered. main_file_read() | |||
* should always be called on blocks. */ | * should always be called on blocks. */ | |||
int | int | |||
main_file_read (main_file *ifile, | main_file_read (main_file *ifile, | |||
uint8_t *buf, | uint8_t *buf, | |||
size_t size, | size_t size, | |||
size_t *nread, | size_t *nread, | |||
const char *msg) | const char *msg) | |||
{ | { | |||
int ret = 0; | int ret = 0; | |||
IF_DEBUG1(DP(RINT "[main] read %s up to %"Z"u\n", ifile->filename, size)); | ||||
#if XD3_STDIO | #if XD3_STDIO | |||
size_t result; | size_t result; | |||
result = fread (buf, 1, size, ifile->file); | result = fread (buf, 1, size, ifile->file); | |||
if (result < size && ferror (ifile->file)) | if (result < size && ferror (ifile->file)) | |||
{ | { | |||
ret = get_errno (); | ret = get_errno (); | |||
} | } | |||
skipping to change at line 1070 | skipping to change at line 1073 | |||
} | } | |||
return ret; | return ret; | |||
} | } | |||
int | int | |||
main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg) | main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg) | |||
{ | { | |||
int ret = 0; | int ret = 0; | |||
IF_DEBUG1(DP(RINT "[main] write %u\n bytes", size)); | ||||
#if XD3_STDIO | #if XD3_STDIO | |||
usize_t result; | usize_t result; | |||
result = fwrite (buf, 1, size, ofile->file); | result = fwrite (buf, 1, size, ofile->file); | |||
if (result != size) { ret = get_errno (); } | if (result != size) { ret = get_errno (); } | |||
#elif XD3_POSIX | #elif XD3_POSIX | |||
ret = xd3_posix_io (ofile->file, buf, size, (xd3_posix_func*) &write, NULL); | ret = xd3_posix_io (ofile->file, buf, size, (xd3_posix_func*) &write, NULL); | |||
skipping to change at line 1139 | skipping to change at line 1144 | |||
} | } | |||
/* This function simply writes the stream output buffer, if there is | /* This function simply writes the stream output buffer, if there is | |||
* any, for encode, decode and recode commands. (The VCDIFF tools use | * any, for encode, decode and recode commands. (The VCDIFF tools use | |||
* main_print_func()). */ | * main_print_func()). */ | |||
static int | static int | |||
main_write_output (xd3_stream* stream, main_file *ofile) | main_write_output (xd3_stream* stream, main_file *ofile) | |||
{ | { | |||
int ret; | int ret; | |||
IF_DEBUG1(DP(RINT "[main] write(%s) %u\n bytes", ofile->filename, stream->avai | ||||
l_out)); | ||||
if (option_no_output) | if (option_no_output) | |||
{ | { | |||
return 0; | return 0; | |||
} | } | |||
if (stream->avail_out > 0 && | if (stream->avail_out > 0 && | |||
(ret = main_file_write (ofile, stream->next_out, | (ret = main_file_write (ofile, stream->next_out, | |||
stream->avail_out, "write failed"))) | stream->avail_out, "write failed"))) | |||
{ | { | |||
return ret; | return ret; | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
static int | static int | |||
main_set_secondary_flags (xd3_config *config) | main_set_secondary_flags (xd3_config *config) | |||
{ | { | |||
int ret; | int ret; | |||
if (option_use_secondary) | if (!option_use_secondary) | |||
{ | ||||
return 0; | ||||
} | ||||
if (option_secondary == NULL) | ||||
{ | { | |||
/* The default secondary compressor is DJW, if it's compiled. */ | /* Set a default secondary compressor if LZMA is built in, otherwise | |||
if (option_secondary == NULL) | * default to no secondary compressor. */ | |||
if (SECONDARY_LZMA) | ||||
{ | { | |||
if (SECONDARY_DJW) | config->flags |= XD3_SEC_LZMA; | |||
{ | ||||
config->flags |= XD3_SEC_DJW; | ||||
} | ||||
} | } | |||
else | } | |||
else | ||||
{ | ||||
if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA) | ||||
{ | { | |||
if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK) | config->flags |= XD3_SEC_LZMA; | |||
{ | } | |||
config->flags |= XD3_SEC_FGK; | else if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK) | |||
} | { | |||
else if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA) | config->flags |= XD3_SEC_FGK; | |||
} | ||||
else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW) | ||||
{ | ||||
usize_t level = XD3_DEFAULT_SECONDARY_LEVEL; | ||||
config->flags |= XD3_SEC_DJW; | ||||
if (strlen (option_secondary) > 3 && | ||||
(ret = main_atou (option_secondary + 3, | ||||
&level, | ||||
0, 9, 'S')) != 0 && | ||||
!option_quiet) | ||||
{ | { | |||
config->flags |= XD3_SEC_LZMA; | return XD3_INVALID; | |||
} | } | |||
else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW) | ||||
{ | ||||
usize_t level = XD3_DEFAULT_SECONDARY_LEVEL; | ||||
config->flags |= XD3_SEC_DJW; | /* XD3_SEC_NOXXXX flags disable secondary compression on | |||
* a per-section basis. For djw, ngroups=1 indicates | ||||
* minimum work, ngroups=0 uses default settings, which | ||||
* is > 1 groups by default. */ | ||||
if (level < 1) { config->flags |= XD3_SEC_NODATA; } | ||||
if (level < 7) { config->sec_data.ngroups = 1; } | ||||
else { config->sec_data.ngroups = 0; } | ||||
if (strlen (option_secondary) > 3 && | if (level < 3) { config->flags |= XD3_SEC_NOINST; } | |||
(ret = main_atou (option_secondary + 3, | if (level < 8) { config->sec_inst.ngroups = 1; } | |||
&level, | else { config->sec_inst.ngroups = 0; } | |||
0, 9, 'S')) != 0 && | ||||
!option_quiet) | ||||
{ | ||||
return XD3_INVALID; | ||||
} | ||||
/* XD3_SEC_NOXXXX flags disable secondary compression on | if (level < 5) { config->flags |= XD3_SEC_NOADDR; } | |||
* a per-section basis. For djw, ngroups=1 indicates | if (level < 9) { config->sec_addr.ngroups = 1; } | |||
* minimum work, ngroups=0 uses default settings, which | else { config->sec_addr.ngroups = 0; } | |||
* is > 1 groups by default. */ | } | |||
if (level < 1) { config->flags |= XD3_SEC_NODATA; } | else if (*option_secondary == 0 || | |||
if (level < 7) { config->sec_data.ngroups = 1; } | strcmp (option_secondary, "none") == 0) | |||
else { config->sec_data.ngroups = 0; } | { | |||
} | ||||
if (level < 3) { config->flags |= XD3_SEC_NOINST; } | else | |||
if (level < 8) { config->sec_inst.ngroups = 1; } | { | |||
else { config->sec_inst.ngroups = 0; } | if (!option_quiet) | |||
if (level < 5) { config->flags |= XD3_SEC_NOADDR; } | ||||
if (level < 9) { config->sec_addr.ngroups = 1; } | ||||
else { config->sec_addr.ngroups = 0; } | ||||
} | ||||
else if (strcmp (option_secondary, "none") == 0 && SECONDARY_DJW) | ||||
{ | ||||
/* No secondary */ | ||||
} | ||||
else | ||||
{ | { | |||
if (!option_quiet) | XPR(NT "unrecognized or not compiled secondary compressor: %s\n", | |||
{ | option_secondary); | |||
XPR(NT "unrecognized secondary compressor type: %s\n", | ||||
option_secondary); | ||||
return XD3_INVALID; | ||||
} | ||||
} | } | |||
return XD3_INVALID; | ||||
} | } | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
/****************************************************************** | /****************************************************************** | |||
VCDIFF TOOLS | VCDIFF TOOLS | |||
*****************************************************************/ | *****************************************************************/ | |||
skipping to change at line 2401 | skipping to change at line 2410 | |||
static int | static int | |||
main_secondary_decompress_check (main_file *file, | main_secondary_decompress_check (main_file *file, | |||
uint8_t *input_buf, | uint8_t *input_buf, | |||
size_t input_size, | size_t input_size, | |||
size_t *nread) | size_t *nread) | |||
{ | { | |||
int ret; | int ret; | |||
usize_t i; | usize_t i; | |||
usize_t try_read = xd3_min (input_size, XD3_ALLOCSIZE); | usize_t try_read = xd3_min (input_size, XD3_ALLOCSIZE); | |||
size_t check_nread = 0; | size_t check_nread = 0; | |||
uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: stack limit */ | uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: heap allocate */ | |||
const main_extcomp *decompressor = NULL; | const main_extcomp *decompressor = NULL; | |||
if ((ret = main_file_read (file, check_buf, | if ((ret = main_file_read (file, check_buf, | |||
try_read, | try_read, | |||
& check_nread, "input read failed"))) | & check_nread, "input read failed"))) | |||
{ | { | |||
return ret; | return ret; | |||
} | } | |||
if (file->flags & RD_DECOMPSET) | if (file->flags & RD_DECOMPSET) | |||
skipping to change at line 3316 | skipping to change at line 3325 | |||
XPR(NT "%"Q"u: in %s (%s): out %s (%s): " | XPR(NT "%"Q"u: in %s (%s): out %s (%s): " | |||
"total in %s: out %s: %s: srcpos %s\n", | "total in %s: out %s: %s: srcpos %s\n", | |||
stream.current_window, | stream.current_window, | |||
main_format_bcnt (this_read, &rdb), | main_format_bcnt (this_read, &rdb), | |||
main_format_rate (this_read, millis, &rrateavg), | main_format_rate (this_read, millis, &rrateavg), | |||
main_format_bcnt (this_write, &wdb), | main_format_bcnt (this_write, &wdb), | |||
main_format_rate (this_write, millis, &wrateavg), | main_format_rate (this_write, millis, &wrateavg), | |||
main_format_bcnt (stream.total_in, &trdb), | main_format_bcnt (stream.total_in, &trdb), | |||
main_format_bcnt (stream.total_out, &twdb), | main_format_bcnt (stream.total_out, &twdb), | |||
main_format_millis (millis, &tm), | main_format_millis (millis, &tm), | |||
main_format_bcnt (sfile->source_position, &srcpos)); | main_format_bcnt (stream.srcwin_cksum_pos, &srcpos)); | |||
} | } | |||
else | else | |||
{ | { | |||
XPR(NT "%"Q"u: in %s: out %s: total in %s: " | XPR(NT "%"Q"u: in %s: out %s: total in %s: " | |||
"out %s: %s\n", | "out %s: %s\n", | |||
stream.current_window, | stream.current_window, | |||
main_format_bcnt (this_read, &rdb), | main_format_bcnt (this_read, &rdb), | |||
main_format_bcnt (this_write, &wdb), | main_format_bcnt (this_write, &wdb), | |||
main_format_bcnt (stream.total_in, &trdb), | main_format_bcnt (stream.total_in, &trdb), | |||
main_format_bcnt (stream.total_out, &twdb), | main_format_bcnt (stream.total_out, &twdb), | |||
main_format_millis (millis, &tm)); | main_format_millis (millis, &tm)); | |||
} | } | |||
} | } | |||
} | } | |||
goto again; | goto again; | |||
} | } | |||
default: | default: | |||
/* input_func() error */ | /* input_func() error */ | |||
XPR(NT XD3_LIB_ERRMSG (& stream, ret)); | XPR(NT XD3_LIB_ERRMSG (& stream, ret)); | |||
if (! option_quiet && ret == XD3_INVALID_INPUT) | if (! option_quiet && ret == XD3_INVALID_INPUT && | |||
sfile != NULL && sfile->filename != NULL) | ||||
{ | { | |||
XPR(NT "normally this indicates that the source file is incorrect\n "); | XPR(NT "normally this indicates that the source file is incorrect\n "); | |||
XPR(NT "please verify the source file with sha1sum or equivalent\n" ); | XPR(NT "please verify the source file with sha1sum or equivalent\n" ); | |||
} | } | |||
return EXIT_FAILURE; | return EXIT_FAILURE; | |||
} | } | |||
} | } | |||
while (nread == config.winsize); | while (nread == config.winsize); | |||
done: | done: | |||
/* Close the inputs. (ifile must be open, sfile may be open) */ | /* Close the inputs. (ifile must be open, sfile may be open) */ | |||
skipping to change at line 3742 | skipping to change at line 3752 | |||
XPR(NT "encoder support not compiled\n"); | XPR(NT "encoder support not compiled\n"); | |||
return EXIT_FAILURE; | return EXIT_FAILURE; | |||
#endif | #endif | |||
case 'n': option_use_checksum = 0; break; | case 'n': option_use_checksum = 0; break; | |||
case 'N': option_no_compress = 1; break; | case 'N': option_no_compress = 1; break; | |||
case 'C': option_smatch_config = my_optarg; break; | case 'C': option_smatch_config = my_optarg; break; | |||
case 'J': option_no_output = 1; break; | case 'J': option_no_output = 1; break; | |||
case 'S': if (my_optarg == NULL) | case 'S': if (my_optarg == NULL) | |||
{ | { | |||
option_use_secondary = 1; | option_use_secondary = 0; | |||
option_secondary = "none"; | option_secondary = NULL; | |||
} | } | |||
else | else | |||
{ | { | |||
option_use_secondary = 1; | option_use_secondary = 1; | |||
option_secondary = my_optarg; | option_secondary = my_optarg; | |||
} | } | |||
break; | break; | |||
case 'A': if (my_optarg == NULL) { option_use_appheader = 0; } | case 'A': if (my_optarg == NULL) { option_use_appheader = 0; } | |||
else { option_appheader = (uint8_t*) my_optarg; } break; | else { option_appheader = (uint8_t*) my_optarg; } break; | |||
case 'B': { | case 'B': { | |||
End of changes. 23 change blocks. | ||||
61 lines changed or deleted | 72 lines changed or added |