bool opt_stdout = false;
bool opt_force = 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
// non-const pointers.
OPT_FILES,
OPT_FILES0,
+ OPT_INFO_MEMORY,
+ OPT_ROBOT,
};
static const char short_opts[]
static const struct option long_opts[] = {
// Operation mode
- { "compress", no_argument, NULL, 'z' },
- { "decompress", no_argument, NULL, 'd' },
- { "uncompress", no_argument, NULL, 'd' },
- { "test", no_argument, NULL, 't' },
- { "list", no_argument, NULL, 'l' },
+ { "compress", no_argument, NULL, 'z' },
+ { "decompress", no_argument, NULL, 'd' },
+ { "uncompress", no_argument, NULL, 'd' },
+ { "test", no_argument, NULL, 't' },
+ { "list", no_argument, NULL, 'l' },
// Operation modifiers
- { "keep", no_argument, NULL, 'k' },
- { "force", no_argument, NULL, 'f' },
- { "stdout", no_argument, NULL, 'c' },
- { "to-stdout", no_argument, NULL, 'c' },
- { "suffix", required_argument, NULL, 'S' },
+ { "keep", no_argument, NULL, 'k' },
+ { "force", no_argument, NULL, 'f' },
+ { "stdout", no_argument, NULL, 'c' },
+ { "to-stdout", no_argument, NULL, 'c' },
+ { "suffix", required_argument, NULL, 'S' },
// { "recursive", no_argument, NULL, 'r' }, // TODO
- { "files", optional_argument, NULL, OPT_FILES },
- { "files0", optional_argument, NULL, OPT_FILES0 },
+ { "files", optional_argument, NULL, OPT_FILES },
+ { "files0", optional_argument, NULL, OPT_FILES0 },
// Basic compression settings
- { "format", required_argument, NULL, 'F' },
- { "check", required_argument, NULL, 'C' },
- { "memory", required_argument, NULL, 'M' },
- { "threads", required_argument, NULL, 'T' },
+ { "format", required_argument, NULL, 'F' },
+ { "check", required_argument, NULL, 'C' },
+ { "memory", required_argument, NULL, 'M' },
+ { "threads", required_argument, NULL, 'T' },
- { "extreme", no_argument, NULL, 'e' },
- { "fast", no_argument, NULL, '0' },
- { "best", no_argument, NULL, '9' },
+ { "extreme", no_argument, NULL, 'e' },
+ { "fast", no_argument, NULL, '0' },
+ { "best", no_argument, NULL, '9' },
// Filters
- { "lzma1", optional_argument, NULL, OPT_LZMA1 },
- { "lzma2", optional_argument, NULL, OPT_LZMA2 },
- { "x86", optional_argument, NULL, OPT_X86 },
- { "powerpc", optional_argument, NULL, OPT_POWERPC },
- { "ia64", optional_argument, NULL, OPT_IA64 },
- { "arm", optional_argument, NULL, OPT_ARM },
- { "armthumb", optional_argument, NULL, OPT_ARMTHUMB },
- { "sparc", optional_argument, NULL, OPT_SPARC },
- { "delta", optional_argument, NULL, OPT_DELTA },
- { "subblock", optional_argument, NULL, OPT_SUBBLOCK },
+ { "lzma1", optional_argument, NULL, OPT_LZMA1 },
+ { "lzma2", optional_argument, NULL, OPT_LZMA2 },
+ { "x86", optional_argument, NULL, OPT_X86 },
+ { "powerpc", optional_argument, NULL, OPT_POWERPC },
+ { "ia64", optional_argument, NULL, OPT_IA64 },
+ { "arm", optional_argument, NULL, OPT_ARM },
+ { "armthumb", optional_argument, NULL, OPT_ARMTHUMB },
+ { "sparc", optional_argument, NULL, OPT_SPARC },
+ { "delta", optional_argument, NULL, OPT_DELTA },
+ { "subblock", optional_argument, NULL, OPT_SUBBLOCK },
// Other options
- { "quiet", no_argument, NULL, 'q' },
- { "verbose", no_argument, NULL, 'v' },
- { "no-warn", no_argument, NULL, 'Q' },
- { "help", no_argument, NULL, 'h' },
- { "long-help", no_argument, NULL, 'H' },
- { "version", no_argument, NULL, 'V' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "verbose", no_argument, NULL, 'v' },
+ { "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' },
+ { "long-help", no_argument, NULL, 'H' },
+ { "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
};
opt_force = true;
break;
+ // --info-memory
+ case OPT_INFO_MEMORY:
+ // This doesn't return.
+ message_memlimit();
+
// --help
case 'h':
// This doesn't return.
message_verbosity_increase();
break;
+ // --robot
+ case OPT_ROBOT:
+ opt_robot = true;
+ break;
+
case 'z':
opt_mode = MODE_COMPRESS;
break;
///////////////////////////////////////////////////////////////////////////////
//
/// \file message.c
-/// \brief Printing messages to stderr
+/// \brief Printing messages
//
// Author: Lasse Collin
//
if (progress_automatic) {
// stderr is a terminal. Check the COLUMNS environment
// 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.
const char *columns_str = getenv("COLUMNS");
if (columns_str != NULL) {
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
message_version(void)
{
// It is possible that liblzma version is different than the command
// line tool version, so print both.
- printf("xz (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n");
- printf("liblzma %s\n", lzma_version_string());
+ 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("liblzma %s\n", lzma_version_string());
+ }
+
tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
}
" -q, --quiet suppress warnings; specify twice to suppress errors too\n"
" -v, --verbose be verbose; specify twice for even more verbose"));
- if (long_help)
+ if (long_help) {
puts(_(
" -Q, --no-warn make warnings not affect the exit status"));
-
- if (long_help)
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, --long-help display this long help"));
- else
+" -H, --long-help display this long help and exit"));
+ } else {
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)"));
+ }
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"));