xz: Change the way coder_run() and list_run() are called in main().
Previously, a function pointer was used to determine if coder_run() or list_run() should be called in the main entry processing loop. This was replaced by an extra function call to process_entry(). coder_run() and list_run() were changed to accept a file_pair * argument instead of a filename. The common repeated code was moved to process_entry() instead.
This commit is contained in:
parent
a3bac71fe3
commit
b10b2e4a8f
|
@ -789,11 +789,17 @@ args_parse(args_info *args, int argc, char **argv)
|
|||
#else
|
||||
// List mode is only available when decoders are enabled and is
|
||||
// only valid with .xz files.
|
||||
if (opt_mode == MODE_LIST
|
||||
&& opt_format != FORMAT_XZ
|
||||
&& opt_format != FORMAT_AUTO)
|
||||
message_fatal(_("--list works only on .xz files "
|
||||
"(--format=xz or --format=auto)"));
|
||||
if (opt_mode == MODE_LIST) {
|
||||
if (opt_format != FORMAT_XZ && opt_format != FORMAT_AUTO)
|
||||
message_fatal(_("--list works only on .xz files "
|
||||
"(--format=xz or --format=auto)"));
|
||||
|
||||
// Unset opt_stdout so that io_open_src() won't accept
|
||||
// special files.
|
||||
opt_stdout = false;
|
||||
// Set opt_force so that io_open_src() will follow symlinks.
|
||||
opt_force = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LZIP_DECODER
|
||||
|
|
|
@ -1429,16 +1429,8 @@ coder_passthru(file_pair *pair)
|
|||
|
||||
|
||||
extern void
|
||||
coder_run(const char *filename)
|
||||
coder_run(file_pair *pair)
|
||||
{
|
||||
// Set and possibly print the filename for the progress message.
|
||||
message_filename(filename);
|
||||
|
||||
// Try to open the input file.
|
||||
file_pair *pair = io_open_src(filename);
|
||||
if (pair == NULL)
|
||||
return;
|
||||
|
||||
// Assume that something goes wrong.
|
||||
bool success = false;
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ extern void coder_add_filter(lzma_vli id, void *options);
|
|||
extern void coder_set_compression_settings(void);
|
||||
|
||||
/// Compress or decompress the given file
|
||||
extern void coder_run(const char *filename);
|
||||
extern void coder_run(file_pair *pair);
|
||||
|
||||
#ifndef NDEBUG
|
||||
/// Free the memory allocated for the coder and kill the worker threads.
|
||||
|
|
|
@ -1274,26 +1274,10 @@ list_totals(void)
|
|||
|
||||
|
||||
extern void
|
||||
list_file(const char *filename)
|
||||
list_file(file_pair *pair)
|
||||
{
|
||||
message_filename(filename);
|
||||
|
||||
if (filename == stdin_filename) {
|
||||
message_error(_("--list does not support reading from "
|
||||
"standard input"));
|
||||
return;
|
||||
}
|
||||
|
||||
init_field_widths();
|
||||
|
||||
// Unset opt_stdout so that io_open_src() won't accept special files.
|
||||
// Set opt_force so that io_open_src() will follow symlinks.
|
||||
opt_stdout = false;
|
||||
opt_force = true;
|
||||
file_pair *pair = io_open_src(filename);
|
||||
if (pair == NULL)
|
||||
return;
|
||||
|
||||
xz_file_info xfi = XZ_FILE_INFO_INIT;
|
||||
if (!parse_indexes(&xfi, pair)) {
|
||||
bool fail;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// \brief List information about the given .xz file
|
||||
extern void list_file(const char *filename);
|
||||
extern void list_file(file_pair *pair);
|
||||
|
||||
|
||||
/// \brief Show the totals after all files have been listed
|
||||
|
|
|
@ -146,6 +146,34 @@ read_name(const args_info *args)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
process_entry(const char *path)
|
||||
{
|
||||
// Set and possibly print the filename for the progress message.
|
||||
message_filename(path);
|
||||
|
||||
// Open the entry
|
||||
file_pair *pair = io_open_src(path);
|
||||
if (pair == NULL)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_DECODERS
|
||||
if (opt_mode == MODE_LIST) {
|
||||
if (path == stdin_filename) {
|
||||
message_error(_("--list does not support reading from "
|
||||
"standard input"));
|
||||
return;
|
||||
}
|
||||
|
||||
list_file(pair);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
coder_run(pair);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
@ -256,14 +284,6 @@ main(int argc, char **argv)
|
|||
io_allow_sandbox();
|
||||
#endif
|
||||
|
||||
// coder_run() handles compression, decompression, and testing.
|
||||
// list_file() is for --list.
|
||||
void (*run)(const char *filename) = &coder_run;
|
||||
#ifdef HAVE_DECODERS
|
||||
if (opt_mode == MODE_LIST)
|
||||
run = &list_file;
|
||||
#endif
|
||||
|
||||
// Process the files given on the command line. Note that if no names
|
||||
// were given, args_parse() gave us a fake "-" filename.
|
||||
for (unsigned i = 0; i < args.arg_count && !user_abort; ++i) {
|
||||
|
@ -298,7 +318,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
// Do the actual compression or decompression.
|
||||
run(args.arg_names[i]);
|
||||
process_entry(args.arg_names[i]);
|
||||
}
|
||||
|
||||
// If --files or --files0 was used, process the filenames from the
|
||||
|
@ -314,7 +334,7 @@ main(int argc, char **argv)
|
|||
|
||||
// read_name() doesn't return empty names.
|
||||
assert(name[0] != '\0');
|
||||
run(name);
|
||||
process_entry(name);
|
||||
}
|
||||
|
||||
if (args.files_name != stdin_filename)
|
||||
|
|
Loading…
Reference in New Issue