mirror of
https://git.tukaani.org/xz.git
synced 2024-04-04 12:36:23 +02:00
Add support for --info-memory and --robot to xz.
Currently --robot works only with --info-memory and --version. --help and --long-help work too, but --robot has no effect on them. Thanks to Jonathan Nieder for the original patches.
This commit is contained in:
parent
e330fb7e6b
commit
d315ca4930
6 changed files with 133 additions and 55 deletions
|
@ -21,6 +21,7 @@
|
||||||
bool opt_stdout = false;
|
bool opt_stdout = false;
|
||||||
bool opt_force = false;
|
bool opt_force = false;
|
||||||
bool opt_keep_original = false;
|
bool opt_keep_original = false;
|
||||||
|
bool opt_robot = false;
|
||||||
|
|
||||||
// We don't modify or free() this, but we need to assign it in some
|
// We don't modify or free() this, but we need to assign it in some
|
||||||
// non-const pointers.
|
// non-const pointers.
|
||||||
|
@ -44,6 +45,8 @@ parse_real(args_info *args, int argc, char **argv)
|
||||||
|
|
||||||
OPT_FILES,
|
OPT_FILES,
|
||||||
OPT_FILES0,
|
OPT_FILES0,
|
||||||
|
OPT_INFO_MEMORY,
|
||||||
|
OPT_ROBOT,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char short_opts[]
|
static const char short_opts[]
|
||||||
|
@ -93,6 +96,8 @@ parse_real(args_info *args, int argc, char **argv)
|
||||||
{ "quiet", no_argument, NULL, 'q' },
|
{ "quiet", no_argument, NULL, 'q' },
|
||||||
{ "verbose", no_argument, NULL, 'v' },
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
{ "no-warn", no_argument, NULL, 'Q' },
|
{ "no-warn", no_argument, NULL, 'Q' },
|
||||||
|
{ "robot", no_argument, NULL, OPT_ROBOT },
|
||||||
|
{ "info-memory", no_argument, NULL, OPT_INFO_MEMORY },
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "long-help", no_argument, NULL, 'H' },
|
{ "long-help", no_argument, NULL, 'H' },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
|
@ -169,6 +174,11 @@ parse_real(args_info *args, int argc, char **argv)
|
||||||
opt_force = true;
|
opt_force = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// --info-memory
|
||||||
|
case OPT_INFO_MEMORY:
|
||||||
|
// This doesn't return.
|
||||||
|
message_memlimit();
|
||||||
|
|
||||||
// --help
|
// --help
|
||||||
case 'h':
|
case 'h':
|
||||||
// This doesn't return.
|
// This doesn't return.
|
||||||
|
@ -207,6 +217,11 @@ parse_real(args_info *args, int argc, char **argv)
|
||||||
message_verbosity_increase();
|
message_verbosity_increase();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// --robot
|
||||||
|
case OPT_ROBOT:
|
||||||
|
opt_robot = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'z':
|
case 'z':
|
||||||
opt_mode = MODE_COMPRESS;
|
opt_mode = MODE_COMPRESS;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -35,6 +35,7 @@ extern bool opt_stdout;
|
||||||
extern bool opt_force;
|
extern bool opt_force;
|
||||||
extern bool opt_keep_original;
|
extern bool opt_keep_original;
|
||||||
// extern bool opt_recursive;
|
// extern bool opt_recursive;
|
||||||
|
extern bool opt_robot;
|
||||||
|
|
||||||
extern const char *stdin_filename;
|
extern const char *stdin_filename;
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,13 @@ main(int argc, char **argv)
|
||||||
args_info args;
|
args_info args;
|
||||||
args_parse(&args, argc, argv);
|
args_parse(&args, argc, argv);
|
||||||
|
|
||||||
|
if (opt_mode == MODE_LIST)
|
||||||
|
message_fatal("--list is not implemented yet.");
|
||||||
|
|
||||||
|
if (opt_robot)
|
||||||
|
message_fatal(_("Compression and decompression with --robot "
|
||||||
|
"are not supported yet."));
|
||||||
|
|
||||||
// Tell the message handling code how many input files there are if
|
// Tell the message handling code how many input files there are if
|
||||||
// we know it. This way the progress indicator can show it.
|
// we know it. This way the progress indicator can show it.
|
||||||
if (args.files_name != NULL)
|
if (args.files_name != NULL)
|
||||||
|
@ -172,10 +179,6 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_mode == MODE_LIST) {
|
|
||||||
message_fatal("--list is not implemented yet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hook the signal handlers. We don't need these before we start
|
// Hook the signal handlers. We don't need these before we start
|
||||||
// the actual action, so this is done after parsing the command
|
// the actual action, so this is done after parsing the command
|
||||||
// line arguments.
|
// line arguments.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
/// \file message.c
|
/// \file message.c
|
||||||
/// \brief Printing messages to stderr
|
/// \brief Printing messages
|
||||||
//
|
//
|
||||||
// Author: Lasse Collin
|
// Author: Lasse Collin
|
||||||
//
|
//
|
||||||
|
@ -152,7 +152,7 @@ message_init(void)
|
||||||
if (progress_automatic) {
|
if (progress_automatic) {
|
||||||
// stderr is a terminal. Check the COLUMNS environment
|
// stderr is a terminal. Check the COLUMNS environment
|
||||||
// variable to see if the terminal is wide enough. If COLUMNS
|
// variable to see if the terminal is wide enough. If COLUMNS
|
||||||
// doesn't exist or it has some unparseable value, we assume
|
// doesn't exist or it has some unparsable value, we assume
|
||||||
// that the terminal is wide enough.
|
// that the terminal is wide enough.
|
||||||
const char *columns_str = getenv("COLUMNS");
|
const char *columns_str = getenv("COLUMNS");
|
||||||
if (columns_str != NULL) {
|
if (columns_str != NULL) {
|
||||||
|
@ -1012,13 +1012,33 @@ message_try_help(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern void
|
||||||
|
message_memlimit(void)
|
||||||
|
{
|
||||||
|
if (opt_robot)
|
||||||
|
printf("%" PRIu64 "\n", hardware_memlimit_get());
|
||||||
|
else
|
||||||
|
printf(_("%s MiB (%s bytes)\n"),
|
||||||
|
uint64_to_str(hardware_memlimit_get() >> 20, 0),
|
||||||
|
uint64_to_str(hardware_memlimit_get(), 1));
|
||||||
|
|
||||||
|
tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
message_version(void)
|
message_version(void)
|
||||||
{
|
{
|
||||||
// It is possible that liblzma version is different than the command
|
// It is possible that liblzma version is different than the command
|
||||||
// line tool version, so print both.
|
// line tool version, so print both.
|
||||||
|
if (opt_robot) {
|
||||||
|
printf("XZ_VERSION=%d\nLIBLZMA_VERSION=%d\n",
|
||||||
|
LZMA_VERSION, lzma_version_number());
|
||||||
|
} else {
|
||||||
printf("xz (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n");
|
printf("xz (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n");
|
||||||
printf("liblzma %s\n", lzma_version_string());
|
printf("liblzma %s\n", lzma_version_string());
|
||||||
|
}
|
||||||
|
|
||||||
tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
|
tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1137,22 +1157,25 @@ message_help(bool long_help)
|
||||||
" -q, --quiet suppress warnings; specify twice to suppress errors too\n"
|
" -q, --quiet suppress warnings; specify twice to suppress errors too\n"
|
||||||
" -v, --verbose be verbose; specify twice for even more verbose"));
|
" -v, --verbose be verbose; specify twice for even more verbose"));
|
||||||
|
|
||||||
if (long_help)
|
if (long_help) {
|
||||||
puts(_(
|
puts(_(
|
||||||
" -Q, --no-warn make warnings not affect the exit status"));
|
" -Q, --no-warn make warnings not affect the exit status"));
|
||||||
|
|
||||||
if (long_help)
|
|
||||||
puts(_(
|
puts(_(
|
||||||
"\n"
|
" --robot use machine-parsable messages (useful for scripts)"));
|
||||||
|
puts("");
|
||||||
|
puts(_(
|
||||||
|
" --info-memory display the memory usage limit and exit"));
|
||||||
|
puts(_(
|
||||||
" -h, --help display the short help (lists only the basic options)\n"
|
" -h, --help display the short help (lists only the basic options)\n"
|
||||||
" -H, --long-help display this long help"));
|
" -H, --long-help display this long help and exit"));
|
||||||
else
|
} else {
|
||||||
puts(_(
|
puts(_(
|
||||||
" -h, --help display this short help\n"
|
" -h, --help display this short help and exit\n"
|
||||||
" -H, --long-help display the long help (lists also the advanced options)"));
|
" -H, --long-help display the long help (lists also the advanced options)"));
|
||||||
|
}
|
||||||
|
|
||||||
puts(_(
|
puts(_(
|
||||||
" -V, --version display the version number"));
|
" -V, --version display the version number and exit"));
|
||||||
|
|
||||||
puts(_("\nWith no FILE, or when FILE is -, read standard input.\n"));
|
puts(_("\nWith no FILE, or when FILE is -, read standard input.\n"));
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,10 @@ extern void message_filters(
|
||||||
extern void message_try_help(void);
|
extern void message_try_help(void);
|
||||||
|
|
||||||
|
|
||||||
|
/// Print the memory usage limit and exit.
|
||||||
|
extern void message_memlimit(void) lzma_attribute((noreturn));
|
||||||
|
|
||||||
|
|
||||||
/// Prints the version number to stdout and exits with exit status SUCCESS.
|
/// Prints the version number to stdout and exits with exit status SUCCESS.
|
||||||
extern void message_version(void) lzma_attribute((noreturn));
|
extern void message_version(void) lzma_attribute((noreturn));
|
||||||
|
|
||||||
|
|
40
src/xz/xz.1
40
src/xz/xz.1
|
@ -5,7 +5,7 @@
|
||||||
.\" This file has been put into the public domain.
|
.\" This file has been put into the public domain.
|
||||||
.\" You can do whatever you want with this file.
|
.\" You can do whatever you want with this file.
|
||||||
.\"
|
.\"
|
||||||
.TH XZ 1 "2009-11-14" "Tukaani" "XZ Utils"
|
.TH XZ 1 "2009-11-16" "Tukaani" "XZ Utils"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
|
xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
@ -219,8 +219,9 @@ but it is possible that a block later in the file will exceed the memory usage
|
||||||
limit, and an error about too low memory usage limit gets displayed after some
|
limit, and an error about too low memory usage limit gets displayed after some
|
||||||
data has already been decompressed.
|
data has already been decompressed.
|
||||||
.PP
|
.PP
|
||||||
The absolute value of the active memory usage limit can be seen near
|
The absolute value of the active memory usage limit can be seen with
|
||||||
the bottom of the output of
|
.B \-\-info-memory
|
||||||
|
or near the bottom of the output of
|
||||||
.BR \-\-long\-help .
|
.BR \-\-long\-help .
|
||||||
The default limit can be overriden with
|
The default limit can be overriden with
|
||||||
\fB\-\-memory=\fIlimit\fR.
|
\fB\-\-memory=\fIlimit\fR.
|
||||||
|
@ -1052,6 +1053,34 @@ and
|
||||||
.B \-\-no\-warn
|
.B \-\-no\-warn
|
||||||
have to be used to not display warnings and to not alter the exit status.
|
have to be used to not display warnings and to not alter the exit status.
|
||||||
.TP
|
.TP
|
||||||
|
.B \-\-robot
|
||||||
|
Print messages in a machine-parsable format. This is intended to ease
|
||||||
|
writing frontends that want to use
|
||||||
|
.B xz
|
||||||
|
instead of liblzma, which may be the case with various scripts. The output
|
||||||
|
with this option enabled is meant to be stable across
|
||||||
|
.B xz
|
||||||
|
releases. Currently
|
||||||
|
.B \-\-robot
|
||||||
|
is implemented only for
|
||||||
|
.B \-\-info\-memory
|
||||||
|
and
|
||||||
|
.BR \-\-version ,
|
||||||
|
but the idea is to make it usable for actual compression
|
||||||
|
and decompression too.
|
||||||
|
.TP
|
||||||
|
.BR \-\-info-memory
|
||||||
|
Display the current memory usage limit in human-readable format on
|
||||||
|
a single line, and exit successfully. To see how much RAM
|
||||||
|
.B xz
|
||||||
|
thinks your system has, use
|
||||||
|
.BR "\-\-memory=100% \-\-info\-memory" .
|
||||||
|
To get machine-parsable output
|
||||||
|
(memory usage limit as bytes without thousand separators), specify
|
||||||
|
.B \-\-robot
|
||||||
|
before
|
||||||
|
.BR \-\-info-memory .
|
||||||
|
.TP
|
||||||
.BR \-h ", " \-\-help
|
.BR \-h ", " \-\-help
|
||||||
Display a help message describing the most commonly used options,
|
Display a help message describing the most commonly used options,
|
||||||
and exit successfully.
|
and exit successfully.
|
||||||
|
@ -1064,7 +1093,10 @@ and exit successfully
|
||||||
.BR \-V ", " \-\-version
|
.BR \-V ", " \-\-version
|
||||||
Display the version number of
|
Display the version number of
|
||||||
.B xz
|
.B xz
|
||||||
and liblzma.
|
and liblzma in human readable format. To get machine-parsable output, specify
|
||||||
|
.B \-\-robot
|
||||||
|
before
|
||||||
|
.BR \-\-version .
|
||||||
.SH "EXIT STATUS"
|
.SH "EXIT STATUS"
|
||||||
.TP
|
.TP
|
||||||
.B 0
|
.B 0
|
||||||
|
|
Loading…
Reference in a new issue