#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
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;
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.
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;
///////////////////////////////////////////////////////////////////////////////
/// \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
}
+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)
{
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) {
}
// 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
// read_name() doesn't return empty names.
assert(name[0] != '\0');
- run(name);
+ process_entry(name);
}
if (args.files_name != stdin_filename)