]> Dogcows Code - chaz/tar/blob - src/suffix.c
(set_comression_program_by_suffix): New prototype.
[chaz/tar] / src / suffix.c
1 /* This file is part of GNU tar.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3
4 Written by Sergey Poznyakoff.
5
6 GNU tar is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GNU tar is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with GNU tar. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include <system.h>
20 #include "common.h"
21
22 struct compression_suffix
23 {
24 const char *suffix;
25 size_t length;
26 const char *program;
27 };
28
29 struct compression_suffix compression_suffixes[] = {
30 #define S(s,p) #s, sizeof (#s) - 1, #p
31 { S(gz, gzip) },
32 { S(tgz, gzip) },
33 { S(taz, gzip) },
34 { S(Z, compress) },
35 { S(taZ, compress) },
36 { S(bz2, bzip2) },
37 { S(tbz, bzip2) },
38 { S(tbz2, bzip2) },
39 { S(tz2, bzip2) },
40 { S(lzma, lzma) },
41 { S(tlz, lzma) },
42 #undef S
43 };
44
45 int nsuffixes = sizeof (compression_suffixes) /
46 sizeof (compression_suffixes[0]);
47
48 static const char *
49 find_compression_program (const char *name, const char *defprog)
50 {
51 char *suf = strrchr (name, '.');
52
53 if (suf)
54 {
55 int i;
56 size_t len;
57
58 suf++;
59 len = strlen (suf);
60
61 for (i = 0; i < nsuffixes; i++)
62 {
63 if (compression_suffixes[i].length == len
64 && memcmp (compression_suffixes[i].suffix, suf, len) == 0)
65 return compression_suffixes[i].program;
66 }
67 }
68 return defprog;
69 }
70
71 void
72 set_comression_program_by_suffix (const char *name, const char *defprog)
73 {
74 const char *program = find_compression_program (name, defprog);
75 if (program)
76 use_compress_program_option = program;
77 }
78
This page took 0.037024 seconds and 4 git commands to generate.