xz: Clean up suffix.c.
struct suffix_pair isn't needed in compresed_name() so get rid of it there.
This commit is contained in:
parent
8930c7ae3f
commit
96f94bc925
|
@ -21,12 +21,6 @@
|
||||||
static char *custom_suffix = NULL;
|
static char *custom_suffix = NULL;
|
||||||
|
|
||||||
|
|
||||||
struct suffix_pair {
|
|
||||||
const char *compressed;
|
|
||||||
const char *uncompressed;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// \brief Test if the char is a directory separator
|
/// \brief Test if the char is a directory separator
|
||||||
static bool
|
static bool
|
||||||
is_dir_sep(char c)
|
is_dir_sep(char c)
|
||||||
|
@ -86,7 +80,10 @@ test_suffix(const char *suffix, const char *src_name, size_t src_len)
|
||||||
static char *
|
static char *
|
||||||
uncompressed_name(const char *src_name, const size_t src_len)
|
uncompressed_name(const char *src_name, const size_t src_len)
|
||||||
{
|
{
|
||||||
static const struct suffix_pair suffixes[] = {
|
static const struct {
|
||||||
|
const char *compressed;
|
||||||
|
const char *uncompressed;
|
||||||
|
} suffixes[] = {
|
||||||
{ ".xz", "" },
|
{ ".xz", "" },
|
||||||
{ ".txz", ".tar" }, // .txz abbreviation for .txt.gz is rare.
|
{ ".txz", ".tar" }, // .txz abbreviation for .txt.gz is rare.
|
||||||
{ ".lzma", "" },
|
{ ".lzma", "" },
|
||||||
|
@ -145,25 +142,25 @@ static char *
|
||||||
compressed_name(const char *src_name, const size_t src_len)
|
compressed_name(const char *src_name, const size_t src_len)
|
||||||
{
|
{
|
||||||
// The order of these must match the order in args.h.
|
// The order of these must match the order in args.h.
|
||||||
static const struct suffix_pair all_suffixes[][3] = {
|
static const char *const all_suffixes[][3] = {
|
||||||
{
|
{
|
||||||
{ ".xz", "" },
|
".xz",
|
||||||
{ ".txz", ".tar" },
|
".txz",
|
||||||
{ NULL, NULL }
|
NULL
|
||||||
}, {
|
}, {
|
||||||
{ ".lzma", "" },
|
".lzma",
|
||||||
{ ".tlz", ".tar" },
|
".tlz",
|
||||||
{ NULL, NULL }
|
NULL
|
||||||
/*
|
/*
|
||||||
}, {
|
}, {
|
||||||
{ ".gz", "" },
|
".gz",
|
||||||
{ ".tgz", ".tar" },
|
".tgz",
|
||||||
{ NULL, NULL }
|
NULL
|
||||||
*/
|
*/
|
||||||
}, {
|
}, {
|
||||||
// --format=raw requires specifying the suffix
|
// --format=raw requires specifying the suffix
|
||||||
// manually or using stdout.
|
// manually or using stdout.
|
||||||
{ NULL, NULL }
|
NULL
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -171,14 +168,13 @@ compressed_name(const char *src_name, const size_t src_len)
|
||||||
assert(opt_format != FORMAT_AUTO);
|
assert(opt_format != FORMAT_AUTO);
|
||||||
|
|
||||||
const size_t format = opt_format - 1;
|
const size_t format = opt_format - 1;
|
||||||
const struct suffix_pair *const suffixes = all_suffixes[format];
|
const char *const *suffixes = all_suffixes[format];
|
||||||
|
|
||||||
for (size_t i = 0; suffixes[i].compressed != NULL; ++i) {
|
for (size_t i = 0; suffixes[i] != NULL; ++i) {
|
||||||
if (test_suffix(suffixes[i].compressed, src_name, src_len)
|
if (test_suffix(suffixes[i], src_name, src_len) != 0) {
|
||||||
!= 0) {
|
|
||||||
message_warning(_("%s: File already has `%s' "
|
message_warning(_("%s: File already has `%s' "
|
||||||
"suffix, skipping"), src_name,
|
"suffix, skipping"), src_name,
|
||||||
suffixes[i].compressed);
|
suffixes[i]);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +198,7 @@ compressed_name(const char *src_name, const size_t src_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *suffix = custom_suffix != NULL
|
const char *suffix = custom_suffix != NULL
|
||||||
? custom_suffix : suffixes[0].compressed;
|
? custom_suffix : suffixes[0];
|
||||||
const size_t suffix_len = strlen(suffix);
|
const size_t suffix_len = strlen(suffix);
|
||||||
|
|
||||||
char *dest_name = xmalloc(src_len + suffix_len + 1);
|
char *dest_name = xmalloc(src_len + suffix_len + 1);
|
||||||
|
|
Loading…
Reference in New Issue