3 * Copyright (c) 2009, 2010, 2011
4 * Phillip Lougher <phillip@squashfs.org.uk>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2,
9 * or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "compressor.h"
26 #include "squashfs_fs.h"
29 static struct compressor gzip_comp_ops
= {
30 ZLIB_COMPRESSION
, "gzip"
33 extern struct compressor gzip_comp_ops
;
37 static struct compressor lzma_comp_ops
= {
38 LZMA_COMPRESSION
, "lzma"
41 extern struct compressor lzma_comp_ops
;
45 static struct compressor lzo_comp_ops
= {
46 LZO_COMPRESSION
, "lzo"
49 extern struct compressor lzo_comp_ops
;
53 static struct compressor lz4_comp_ops
= {
54 LZ4_COMPRESSION
, "lz4"
57 extern struct compressor lz4_comp_ops
;
61 static struct compressor xz_comp_ops
= {
65 extern struct compressor xz_comp_ops
;
69 static struct compressor zstd_comp_ops
= {
70 ZSTD_COMPRESSION
, "zstd"
73 extern struct compressor zstd_comp_ops
;
76 static struct compressor unknown_comp_ops
= {
81 struct compressor
*compressor
[] = {
92 struct compressor
*lookup_compressor(char *name
)
96 for(i
= 0; compressor
[i
]->id
; i
++)
97 if(strcmp(compressor
[i
]->name
, name
) == 0)
100 return compressor
[i
];
104 struct compressor
*lookup_compressor_id(int id
)
108 for(i
= 0; compressor
[i
]->id
; i
++)
109 if(id
== compressor
[i
]->id
)
112 return compressor
[i
];
116 void display_compressors(char *indent
, char *def_comp
)
120 for(i
= 0; compressor
[i
]->id
; i
++)
121 if(compressor
[i
]->supported
)
122 fprintf(stderr
, "%s\t%s%s\n", indent
,
124 strcmp(compressor
[i
]->name
, def_comp
) == 0 ?
129 void display_compressor_usage(char *def_comp
)
133 for(i
= 0; compressor
[i
]->id
; i
++)
134 if(compressor
[i
]->supported
) {
135 char *str
= strcmp(compressor
[i
]->name
, def_comp
) == 0 ?
137 if(compressor
[i
]->usage
) {
138 fprintf(stderr
, "\t%s%s\n",
139 compressor
[i
]->name
, str
);
140 compressor
[i
]->usage();
142 fprintf(stderr
, "\t%s (no options)%s\n",
143 compressor
[i
]->name
, str
);