XZ Utils 5.4.0
Data Structures | Macros | Enumerations | Functions | Variables
list.c File Reference

Listing information about .xz files. More...

#include "private.h"
#include "tuklib_integer.h"

Data Structures

struct  xz_file_info
 Information about a .xz file. More...
 
struct  block_header_info
 Information about a .xz Block. More...
 

Macros

#define XZ_FILE_INFO_INIT   { NULL, 0, 0, true, 50000002 }
 
#define BLOCK_HEADER_INFO_INIT   { .filter_chain = NULL }
 
#define block_header_info_end(bhi)   free((bhi)->filter_chain)
 
#define COLON_STR(num)   colon_strs_fw[num], _(colon_strs[num])
 
#define HEADING_STR(num)   headings[num].fw, _(headings[num].str)
 
#define CHECKS_STR_SIZE   1024
 

Enumerations

enum  {
  COLON_STR_STREAMS , COLON_STR_BLOCKS , COLON_STR_COMPRESSED_SIZE , COLON_STR_UNCOMPRESSED_SIZE ,
  COLON_STR_RATIO , COLON_STR_CHECK , COLON_STR_STREAM_PADDING , COLON_STR_MEMORY_NEEDED ,
  COLON_STR_SIZES_IN_HEADERS , COLON_STR_NUMBER_OF_FILES
}
 Enum matching the above strings. More...
 
enum  {
  HEADING_STREAM , HEADING_BLOCK , HEADING_BLOCKS , HEADING_COMPOFFSET ,
  HEADING_UNCOMPOFFSET , HEADING_COMPSIZE , HEADING_UNCOMPSIZE , HEADING_TOTALSIZE ,
  HEADING_RATIO , HEADING_CHECK , HEADING_CHECKVAL , HEADING_PADDING ,
  HEADING_HEADERSIZE , HEADING_HEADERFLAGS , HEADING_MEMUSAGE , HEADING_FILTERS
}
 Enum matching the above strings. More...
 

Functions

static void init_colon_strs (void)
 Initialize colon_strs_fw[]. More...
 
static void init_headings (void)
 Initialize headings[]. More...
 
static void init_field_widths (void)
 
static const char * xz_ver_to_str (uint32_t ver)
 Convert XZ Utils version number to a string. More...
 
static bool parse_indexes (xz_file_info *xfi, file_pair *pair)
 Parse the Index(es) from the given .xz file. More...
 
static bool parse_block_header (file_pair *pair, const lzma_index_iter *iter, block_header_info *bhi, xz_file_info *xfi)
 Parse the Block Header. More...
 
static bool parse_check_value (file_pair *pair, const lzma_index_iter *iter)
 Parse the Check field and put it into check_value[]. More...
 
static bool parse_details (file_pair *pair, const lzma_index_iter *iter, block_header_info *bhi, xz_file_info *xfi)
 Parse detailed information about a Block. More...
 
static const char * get_ratio (uint64_t compressed_size, uint64_t uncompressed_size)
 Get the compression ratio. More...
 
static void get_check_names (char buf[CHECKS_STR_SIZE], uint32_t checks, bool space_after_comma)
 Get a comma-separated list of Check names. More...
 
static bool print_info_basic (const xz_file_info *xfi, file_pair *pair)
 
static void print_adv_helper (uint64_t stream_count, uint64_t block_count, uint64_t compressed_size, uint64_t uncompressed_size, uint32_t checks, uint64_t stream_padding)
 
static bool print_info_adv (xz_file_info *xfi, file_pair *pair)
 
static bool print_info_robot (xz_file_info *xfi, file_pair *pair)
 
static void update_totals (const xz_file_info *xfi)
 
static void print_totals_basic (void)
 
static void print_totals_adv (void)
 
static void print_totals_robot (void)
 
void list_totals (void)
 Show the totals after all files have been listed. More...
 
void list_file (const char *filename)
 List information about the given .xz file. More...
 

Variables

static const char * colon_strs []
 
static int colon_strs_fw [ARRAY_SIZE(colon_strs)]
 
struct {
   const char *   str
 Table column heading string. More...
 
   int   columns
 
   int   fw
 
headings []
 Column headings. More...
 
static const char check_names [LZMA_CHECK_ID_MAX+1][12]
 Check ID to string mapping. More...
 
static char check_value [2 *LZMA_CHECK_SIZE_MAX+1]
 
struct {
   uint64_t   files
 
   uint64_t   streams
 
   uint64_t   blocks
 
   uint64_t   compressed_size
 
   uint64_t   uncompressed_size
 
   uint64_t   stream_padding
 
   uint64_t   memusage_max
 
   uint32_t   checks
 
   uint32_t   min_version
 
   bool   all_have_sizes
 
totals = { 0, 0, 0, 0, 0, 0, 0, 0, 50000002, true }
 

Detailed Description

Listing information about .xz files.

Macro Definition Documentation

◆ COLON_STR

#define COLON_STR (   num)    colon_strs_fw[num], _(colon_strs[num])

Convenience macro to get the translated string and its field width using a COLON_STR_foo enum.

◆ CHECKS_STR_SIZE

#define CHECKS_STR_SIZE   1024

Buffer size for get_check_names(). This may be a bit ridiculous, but at least it's enough if some language needs many multibyte chars.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Enum matching the above strings.

◆ anonymous enum

anonymous enum

Enum matching the above strings.

Function Documentation

◆ init_colon_strs()

static void init_colon_strs ( void  )
static

Initialize colon_strs_fw[].

Referenced by init_field_widths().

◆ init_headings()

static void init_headings ( void  )
static

Initialize headings[].

Referenced by init_field_widths().

◆ init_field_widths()

static void init_field_widths ( void  )
static

Initialize the printf field widths that are needed to get nicely aligned output with translated strings.

References init_colon_strs(), and init_headings().

◆ xz_ver_to_str()

static const char * xz_ver_to_str ( uint32_t  ver)
static

Convert XZ Utils version number to a string.

◆ parse_indexes()

static bool parse_indexes ( xz_file_info xfi,
file_pair pair 
)
static

Parse the Index(es) from the given .xz file.

Parameters
xfiPointer to structure where the decoded information is stored.
pairInput file
Returns
On success, false is returned. On error, true is returned.

References message_error(), and file_pair::src_st.

◆ parse_block_header()

static bool parse_block_header ( file_pair pair,
const lzma_index_iter iter,
block_header_info bhi,
xz_file_info xfi 
)
static

Parse the Block Header.

The result is stored into *bhi. The caller takes care of initializing it.

Returns
False on success, true on error.

Referenced by parse_details().

◆ parse_check_value()

static bool parse_check_value ( file_pair pair,
const lzma_index_iter iter 
)
static

Parse the Check field and put it into check_value[].

Returns
False on success, true on error.

References lzma_stream_flags::check, check_value, lzma_index_iter::compressed_file_offset, lzma_index_iter::flags, io_pread(), LZMA_CHECK_NONE, lzma_check_size(), and lzma_index_iter::total_size.

Referenced by parse_details().

◆ parse_details()

static bool parse_details ( file_pair pair,
const lzma_index_iter iter,
block_header_info bhi,
xz_file_info xfi 
)
static

Parse detailed information about a Block.

Since this requires seek(s), listing information about all Blocks can be slow.

Parameters
pairInput file
iterLocation of the Block whose Check value should be printed.
bhiPointer to structure where to store the information about the Block Header field.
Returns
False on success, true on error. If an error occurs, the error message is printed too so the caller doesn't need to worry about that.

References parse_block_header(), and parse_check_value().

◆ get_ratio()

static const char * get_ratio ( uint64_t  compressed_size,
uint64_t  uncompressed_size 
)
static

Get the compression ratio.

This has slightly different format than that is used in message.c.

◆ get_check_names()

static void get_check_names ( char  buf[CHECKS_STR_SIZE],
uint32_t  checks,
bool  space_after_comma 
)
static

Get a comma-separated list of Check names.

The check names are translated with gettext except when in robot mode.

Parameters
bufBuffer to hold the resulting string
checksBit mask of Checks to print
space_after_commaIt's better to not use spaces in table-like listings, but in more verbose formats a space after a comma is good for readability.

◆ list_totals()

void list_totals ( void  )

Show the totals after all files have been listed.

◆ list_file()

void list_file ( const char *  filename)

List information about the given .xz file.

References opt_format.

Variable Documentation

◆ colon_strs

const char* colon_strs[]
static
Initial value:
= {
N_("Streams:"),
N_("Blocks:"),
N_("Compressed size:"),
N_("Uncompressed size:"),
N_("Ratio:"),
N_("Check:"),
N_("Stream Padding:"),
N_("Memory needed:"),
N_("Sizes in headers:"),
N_("Number of files:"),
}

Strings ending in a colon. These are used for lines like " Foo: 123 MiB". These are grouped because translated strings may have different maximum string length, and we want to pad all strings so that the values are aligned nicely.

◆ colon_strs_fw

int colon_strs_fw[ARRAY_SIZE(colon_strs)]
static

Field widths to use with printf to pad the strings to use the same number of columns on a terminal.

◆ str

const char* str

Table column heading string.

Referenced by has_dir_sep(), and parse_options().

◆ columns

int columns

Number of terminal-columns to use for this table-column. If a translated string is longer than the initial value, this value will be increased in init_headings().

◆ fw

int fw

Field width to use for printf() to pad "str" to use "columns" number of columns on a terminal. This is calculated in init_headings().

Referenced by memlimit_show().

◆ 

struct { ... } headings[]
Initial value:
= {
{ N_("Stream"), 6, 0 },
{ N_("Block"), 9, 0 },
{ N_("Blocks"), 9, 0 },
{ N_("CompOffset"), 15, 0 },
{ N_("UncompOffset"), 15, 0 },
{ N_("CompSize"), 15, 0 },
{ N_("UncompSize"), 15, 0 },
{ N_("TotalSize"), 15, 0 },
{ N_("Ratio"), 5, 0 },
{ N_("Check"), 10, 0 },
{ N_("CheckVal"), 1, 0 },
{ N_("Padding"), 7, 0 },
{ N_("Header"), 5, 0 },
{ N_("Flags"), 2, 0 },
{ N_("MemUsage"), 7 + 4, 0 },
{ N_("Filters"), 1, 0 },
}

Column headings.

◆ check_names

const char check_names[LZMA_CHECK_ID_MAX+1][12]
static
Initial value:
= {
N_("None"),
"CRC32",
N_("Unknown-2"),
N_("Unknown-3"),
"CRC64",
N_("Unknown-5"),
N_("Unknown-6"),
N_("Unknown-7"),
N_("Unknown-8"),
N_("Unknown-9"),
"SHA-256",
N_("Unknown-11"),
N_("Unknown-12"),
N_("Unknown-13"),
N_("Unknown-14"),
N_("Unknown-15"),
}

Check ID to string mapping.

◆ check_value

char check_value[2 *LZMA_CHECK_SIZE_MAX+1]
static

Value of the Check field as hexadecimal string. This is set by parse_check_value().

Referenced by parse_check_value().

◆ 

struct { ... } totals

Totals that are displayed if there was more than one file. The "files" counter is also used in print_info_adv() to show the file number.