#include "filter_common.h"
+// liblzma itself doesn't use gettext to translate messages.
+// Mark the strings still so that xz can translate them.
+#define N_(msgid) msgid
+
+
/////////////////////
// String building //
/////////////////////
assert(*str < str_end);
if (!(**str >= '0' && **str <= '9'))
- return "Unsupported preset";
+ return N_("Unsupported preset");
*preset = (uint32_t)(**str - '0');
break;
default:
- return "Unsupported flag in the preset";
+ return N_("Unsupported flag in the preset");
}
}
lzma_options_lzma *opts = filter_options;
if (lzma_lzma_preset(opts, preset))
- return "Unsupported preset";
+ return N_("Unsupported preset");
return NULL;
}
return errmsg;
if (opts->lc + opts->lp > LZMA_LCLP_MAX)
- return "The sum of lc and lp must not exceed 4";
+ return N_("The sum of lc and lp must not exceed 4");
return NULL;
}
// Fail if the '=' wasn't found or the option name is missing
// (the first char is '=').
if (equals_sign == NULL || **str == '=')
- return "Options must be 'name=value' pairs separated "
- "with commas";
+ return N_("Options must be 'name=value' pairs "
+ "separated with commas");
// Reject a too long option name so that the memcmp()
// in the loop below won't read past the end of the
// string in optmap[i].name.
const size_t name_len = (size_t)(equals_sign - *str);
if (name_len > NAME_LEN_MAX)
- return "Unknown option name";
+ return N_("Unknown option name");
// Find the option name from optmap[].
size_t i = 0;
while (true) {
if (i == optmap_size)
- return "Unknown option name";
+ return N_("Unknown option name");
if (memcmp(*str, optmap[i].name, name_len) == 0
&& optmap[i].name[name_len] == '\0')
// string so check it here.
const size_t value_len = (size_t)(name_eq_value_end - *str);
if (value_len == 0)
- return "Option value cannot be empty";
+ return N_("Option value cannot be empty");
// LZMA1/2 preset has its own parsing function.
if (optmap[i].type == OPTMAP_TYPE_LZMA_PRESET) {
// in the loop below won't read past the end of the
// string in optmap[i].u.map[j].name.
if (value_len > NAME_LEN_MAX)
- return "Invalid option value";
+ return N_("Invalid option value");
const name_value_map *map = optmap[i].u.map;
size_t j = 0;
while (true) {
// The array is terminated with an empty name.
if (map[j].name[0] == '\0')
- return "Invalid option value";
+ return N_("Invalid option value");
if (memcmp(*str, map[j].name, value_len) == 0
&& map[j].name[value_len]
} else if (**str < '0' || **str > '9') {
// Note that "max" isn't supported while it is
// supported in xz. It's not useful here.
- return "Value is not a non-negative decimal integer";
+ return N_("Value is not a non-negative "
+ "decimal integer");
} else {
// strtoul() has locale-specific behavior so it cannot
// be relied on to get reproducible results since we
v = 0;
do {
if (v > UINT32_MAX / 10)
- return "Value out of range";
+ return N_("Value out of range");
v *= 10;
const uint32_t add = (uint32_t)(*p - '0');
if (UINT32_MAX - add < v)
- return "Value out of range";
+ return N_("Value out of range");
v += add;
++p;
if ((optmap[i].flags & OPTMAP_USE_BYTE_SUFFIX)
== 0) {
*str = multiplier_start;
- return "This option does not "
+ return N_("This option does not "
"support any multiplier "
- "suffixes";
+ "suffixes");
}
uint32_t shift;
default:
*str = multiplier_start;
- return "Invalid multiplier suffix "
- "(KiB, MiB, or GiB)";
+
+ // TRANSLATORS: Don't translate the
+ // suffixes "KiB", "MiB", or "GiB"
+ // because a user can only specify
+ // untranslated suffixes.
+ return N_("Invalid multiplier suffix "
+ "(KiB, MiB, or GiB)");
}
++p;
// Now we must have no chars remaining.
if (p < name_eq_value_end) {
*str = multiplier_start;
- return "Invalid multiplier suffix "
- "(KiB, MiB, or GiB)";
+ return N_("Invalid multiplier suffix "
+ "(KiB, MiB, or GiB)");
}
if (v > (UINT32_MAX >> shift))
- return "Value out of range";
+ return N_("Value out of range");
v <<= shift;
}
if (v < optmap[i].u.range.min
|| v > optmap[i].u.range.max)
- return "Value out of range";
+ return N_("Value out of range");
}
// Set the value in filter_options. Enums are handled
// string in filter_name_map[i].name.
const size_t name_len = (size_t)(name_end - *str);
if (name_len > NAME_LEN_MAX)
- return "Unknown filter name";
+ return N_("Unknown filter name");
for (size_t i = 0; i < ARRAY_SIZE(filter_name_map); ++i) {
if (memcmp(*str, filter_name_map[i].name, name_len) == 0
&& filter_name_map[i].name[name_len] == '\0') {
if (only_xz && filter_name_map[i].id
>= LZMA_FILTER_RESERVED_START)
- return "This filter cannot be used in "
- "the .xz format";
+ return N_("This filter cannot be used in "
+ "the .xz format");
// Allocate the filter-specific options and
// initialize the memory with zeros.
filter_name_map[i].opts_size,
allocator);
if (options == NULL)
- return "Memory allocation failed";
+ return N_("Memory allocation failed");
// Filter name was found so the input string is good
// at least this far.
}
}
- return "Unknown filter name";
+ return N_("Unknown filter name");
}
++*str;
if (**str == '\0')
- return "Empty string is not allowed, "
- "try '6' if a default value is needed";
+ return N_("Empty string is not allowed, "
+ "try '6' if a default value is needed");
// Detect the type of the string.
//
// there are no chars other than spaces.
for (size_t i = 1; str_end[i] != '\0'; ++i)
if (str_end[i] != ' ')
- return "Unsupported preset";
+ return N_("Unsupported preset");
} else {
// There are no trailing spaces. Use the whole string.
str_end = *str + str_len;
lzma_options_lzma *opts = lzma_alloc(sizeof(*opts), allocator);
if (opts == NULL)
- return "Memory allocation failed";
+ return N_("Memory allocation failed");
if (lzma_lzma_preset(opts, preset)) {
lzma_free(opts, allocator);
- return "Unsupported preset";
+ return N_("Unsupported preset");
}
filters[0].id = LZMA_FILTER_LZMA2;
size_t i = 0;
do {
if (i == LZMA_FILTERS_MAX) {
- errmsg = "The maximum number of filters is four";
+ errmsg = N_("The maximum number of filters is four");
goto error;
}
// Inputs that have "--" at the end or "-- " in the middle
// will result in an empty filter name.
if (filter_end == *str) {
- errmsg = "Filter name is missing";
+ errmsg = N_("Filter name is missing");
goto error;
}
const lzma_ret ret = lzma_validate_chain(temp_filters, &dummy);
assert(ret == LZMA_OK || ret == LZMA_OPTIONS_ERROR);
if (ret != LZMA_OK) {
- errmsg = "Invalid filter chain "
- "('lzma2' missing at the end?)";
+ errmsg = N_("Invalid filter chain "
+ "('lzma2' missing at the end?)");
goto error;
}
}
if (error_pos != NULL)
*error_pos = 0;
- if (str == NULL || filters == NULL)
+ if (str == NULL || filters == NULL) {
+ // Don't translate this because it's only shown in case of
+ // a programming error.
return "Unexpected NULL pointer argument(s) "
"to lzma_str_to_filters()";
+ }
// Validate the flags.
const uint32_t supported_flags
= LZMA_STR_ALL_FILTERS
| LZMA_STR_NO_VALIDATION;
- if (flags & ~supported_flags)
+ if (flags & ~supported_flags) {
+ // This message is possible only if the caller uses flags
+ // that are only supported in a newer liblzma version (or
+ // the flags are simply buggy). Don't translate this at least
+ // when liblzma itself doesn't use gettext; xz and liblzma
+ // are usually upgraded at the same time.
return "Unsupported flags to lzma_str_to_filters()";
+ }
const char *used = str;
const char *errmsg = str_to_filters(&used, filters, flags, allocator);