Rizin
unix-like reverse engineering framework and cli tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Macros Modules Pages
list.h File Reference

List information about .xz files. More...

Go to the source code of this file.

Functions

void list_file (const char *filename)
 List information about the given .xz file. More...
 
void list_totals (void)
 Show the totals after all files have been listed. More...
 

Detailed Description

List information about .xz files.

Definition in file list.h.

Function Documentation

◆ list_file()

void list_file ( const char *  filename)

List information about the given .xz file.

Definition at line 1143 of file list.c.

1144 {
1146  message_fatal(_("--list works only on .xz files "
1147  "(--format=xz or --format=auto)"));
1148 
1150 
1151  if (filename == stdin_filename) {
1152  message_error(_("--list does not support reading from "
1153  "standard input"));
1154  return;
1155  }
1156 
1157  // Unset opt_stdout so that io_open_src() won't accept special files.
1158  // Set opt_force so that io_open_src() will follow symlinks.
1159  opt_stdout = false;
1160  opt_force = true;
1161  file_pair *pair = io_open_src(filename);
1162  if (pair == NULL)
1163  return;
1164 
1166  if (!parse_indexes(&xfi, pair)) {
1167  bool fail;
1168 
1169  // We have three main modes:
1170  // - --robot, which has submodes if --verbose is specified
1171  // once or twice
1172  // - Normal --list without --verbose
1173  // - --list with one or two --verbose
1174  if (opt_robot)
1175  fail = print_info_robot(&xfi, pair);
1176  else if (message_verbosity_get() <= V_WARNING)
1177  fail = print_info_basic(&xfi, pair);
1178  else
1179  fail = print_info_adv(&xfi, pair);
1180 
1181  // Update the totals that are displayed after all
1182  // the individual files have been listed. Don't count
1183  // broken files.
1184  if (!fail)
1185  update_totals(&xfi);
1186 
1187  lzma_index_end(xfi.idx, NULL);
1188  }
1189 
1190  io_close(pair, false);
1191  return;
1192 }
bool opt_robot
Definition: args.c:24
const char stdin_filename[]
Definition: args.c:29
bool opt_stdout
Definition: args.c:21
bool opt_force
Definition: args.c:22
enum format_type opt_format
Definition: coder.c:25
@ FORMAT_AUTO
Definition: coder.h:23
@ FORMAT_XZ
Definition: coder.h:24
#define NULL
Definition: cris-opc.c:27
void io_close(file_pair *pair, bool success)
Closes the file descriptors and frees possible allocated memory.
Definition: file_io.c:1052
file_pair * io_open_src(const char *src_name)
Open the source file.
Definition: file_io.c:741
const char * filename
Definition: ioapi.h:137
void message_filename(const char *src_name)
Set the name of the current file and possibly print it too.
Definition: message.c:232
void message_error(const char *fmt,...)
Definition: message.c:764
void message_fatal(const char *fmt,...)
Definition: message.c:777
enum message_verbosity message_verbosity_get(void)
Get the current verbosity level.
Definition: message.c:181
@ V_WARNING
Errors and warnings.
Definition: message.h:17
#define _(String)
Definition: opintl.h:53
Information about a .xz file.
Definition: list.c:18
lzma_index * idx
Combined Index of all Streams in the file.
Definition: list.c:20
static bool print_info_robot(xz_file_info *xfi, file_pair *pair)
Definition: list.c:916
static void update_totals(const xz_file_info *xfi)
Definition: list.c:1001
static bool print_info_adv(xz_file_info *xfi, file_pair *pair)
Definition: list.c:738
static bool print_info_basic(const xz_file_info *xfi, file_pair *pair)
Definition: list.c:668
#define XZ_FILE_INFO_INIT
Definition: list.c:37
static bool parse_indexes(xz_file_info *xfi, file_pair *pair)
Parse the Index(es) from the given .xz file.
Definition: list.c:150
#define fail(test)
Definition: tests.h:29

References _, fail, FORMAT_AUTO, FORMAT_XZ, xz_file_info::idx, io_close(), io_open_src(), message_error(), message_fatal(), message_filename(), message_verbosity_get(), NULL, opt_force, opt_format, opt_robot, opt_stdout, parse_indexes(), print_info_adv(), print_info_basic(), print_info_robot(), stdin_filename, update_totals(), V_WARNING, and XZ_FILE_INFO_INIT.

Referenced by main().

◆ list_totals()

void list_totals ( void  )

Show the totals after all files have been listed.

Definition at line 1121 of file list.c.

1122 {
1123  if (opt_robot) {
1124  // Always print totals in --robot mode. It can be convenient
1125  // in some cases and doesn't complicate usage of the
1126  // single-file case much.
1128 
1129  } else if (totals.files > 1) {
1130  // For non-robot mode, totals are printed only if there
1131  // is more than one file.
1134  else
1135  print_totals_adv();
1136  }
1137 
1138  return;
1139 }
static struct @659 totals
static void print_totals_basic(void)
Definition: list.c:1025
static void print_totals_robot(void)
Definition: list.c:1091
static void print_totals_adv(void)
Definition: list.c:1067

References message_verbosity_get(), opt_robot, print_totals_adv(), print_totals_basic(), print_totals_robot(), totals, and V_WARNING.

Referenced by main().