aboutsummaryrefslogtreecommitdiff
path: root/archival/gzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/gzip.c')
-rw-r--r--archival/gzip.c171
1 files changed, 85 insertions, 86 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index c8444ac25..90075272d 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -2074,6 +2074,7 @@ static void zip(int in, int out)
2074 2074
2075 2075
2076/* ======================================================================== */ 2076/* ======================================================================== */
2077#if 0
2077static void abort_gzip(int ATTRIBUTE_UNUSED ignored) 2078static void abort_gzip(int ATTRIBUTE_UNUSED ignored)
2078{ 2079{
2079 exit(1); 2080 exit(1);
@@ -2082,92 +2083,6 @@ static void abort_gzip(int ATTRIBUTE_UNUSED ignored)
2082int gzip_main(int argc, char **argv); 2083int gzip_main(int argc, char **argv);
2083int gzip_main(int argc, char **argv) 2084int gzip_main(int argc, char **argv)
2084{ 2085{
2085 enum {
2086 OPT_tostdout = 0x1,
2087 OPT_force = 0x2,
2088 };
2089
2090 unsigned opt;
2091 int inFileNum;
2092 int outFileNum;
2093 int i;
2094 struct stat statBuf;
2095
2096 opt = getopt32(argc, argv, "cf123456789qv" USE_GUNZIP("d"));
2097 //if (opt & 0x1) // -c
2098 //if (opt & 0x2) // -f
2099 /* Ignore 1-9 (compression level) options */
2100 //if (opt & 0x4) // -1
2101 //if (opt & 0x8) // -2
2102 //if (opt & 0x10) // -3
2103 //if (opt & 0x20) // -4
2104 //if (opt & 0x40) // -5
2105 //if (opt & 0x80) // -6
2106 //if (opt & 0x100) // -7
2107 //if (opt & 0x200) // -8
2108 //if (opt & 0x400) // -9
2109 //if (opt & 0x800) // -q
2110 //if (opt & 0x1000) // -v
2111#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
2112 if (opt & 0x2000) { // -d
2113 /* FIXME: getopt32 should not depend on optind */
2114 optind = 1;
2115 return gunzip_main(argc, argv);
2116 }
2117#endif
2118
2119 /* Comment?? */
2120 if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
2121 signal(SIGINT, abort_gzip);
2122 }
2123#ifdef SIGTERM
2124 if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
2125 signal(SIGTERM, abort_gzip);
2126 }
2127#endif
2128#ifdef SIGHUP
2129 if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
2130 signal(SIGHUP, abort_gzip);
2131 }
2132#endif
2133
2134 ptr_to_globals = xzalloc(sizeof(struct global1) + sizeof(struct global2));
2135 ptr_to_globals++;
2136 G2.l_desc.dyn_tree = G2.dyn_ltree;
2137 G2.l_desc.static_tree = G2.static_ltree;
2138 G2.l_desc.extra_bits = extra_lbits;
2139 G2.l_desc.extra_base = LITERALS + 1;
2140 G2.l_desc.elems = L_CODES;
2141 G2.l_desc.max_length = MAX_BITS;
2142 //G2.l_desc.max_code = 0;
2143
2144 G2.d_desc.dyn_tree = G2.dyn_dtree;
2145 G2.d_desc.static_tree = G2.static_dtree;
2146 G2.d_desc.extra_bits = extra_dbits;
2147 //G2.d_desc.extra_base = 0;
2148 G2.d_desc.elems = D_CODES;
2149 G2.d_desc.max_length = MAX_BITS;
2150 //G2.d_desc.max_code = 0;
2151
2152 G2.bl_desc.dyn_tree = G2.bl_tree;
2153 //G2.bl_desc.static_tree = NULL;
2154 G2.bl_desc.extra_bits = extra_blbits,
2155 //G2.bl_desc.extra_base = 0;
2156 G2.bl_desc.elems = BL_CODES;
2157 G2.bl_desc.max_length = MAX_BL_BITS;
2158 //G2.bl_desc.max_code = 0;
2159
2160 /* Allocate all global buffers (for DYN_ALLOC option) */
2161 ALLOC(uch, G1.l_buf, INBUFSIZ);
2162 ALLOC(uch, G1.outbuf, OUTBUFSIZ);
2163 ALLOC(ush, G1.d_buf, DIST_BUFSIZE);
2164 ALLOC(uch, G1.window, 2L * WSIZE);
2165 ALLOC(ush, G1.prev, 1L << BITS);
2166
2167 /* Initialise the CRC32 table */
2168 G1.crc_32_tab = crc32_filltable(0);
2169
2170 clear_bufs();
2171 2086
2172 if (optind == argc) { 2087 if (optind == argc) {
2173 G1.time_stamp = 0; 2088 G1.time_stamp = 0;
@@ -2240,3 +2155,87 @@ int gzip_main(int argc, char **argv)
2240 2155
2241 return 0; //##G1.exit_code; 2156 return 0; //##G1.exit_code;
2242} 2157}
2158#endif
2159
2160int bbunpack(char **argv,
2161 char* (*make_new_name)(char *filename),
2162 USE_DESKTOP(long long) int (*unpacker)(void)
2163);
2164
2165static
2166char* make_new_name_gzip(char *filename)
2167{
2168 return xasprintf("%s.gz", filename);
2169}
2170
2171static
2172USE_DESKTOP(long long) int pack_gzip(void)
2173{
2174 struct stat s;
2175
2176 G1.time_stamp = 0;
2177 if (!fstat(STDIN_FILENO, &s))
2178 G1.time_stamp = s.st_ctime;
2179 zip(STDIN_FILENO, STDOUT_FILENO);
2180 return 0;
2181}
2182
2183int gzip_main(int argc, char **argv);
2184int gzip_main(int argc, char **argv)
2185{
2186 unsigned opt;
2187
2188 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
2189 opt = getopt32(argc, argv, "cfv" USE_GUNZIP("d") "q123456789" );
2190 option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */
2191 //if (opt & 0x1) // -c
2192 //if (opt & 0x2) // -f
2193 //if (opt & 0x4) // -v
2194#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
2195 if (opt & 0x8) { // -d
2196 /* FIXME: getopt32 should not depend on optind */
2197 optind = 1;
2198 return gunzip_main(argc, argv);
2199 }
2200#endif
2201
2202 ptr_to_globals = xzalloc(sizeof(struct global1) + sizeof(struct global2));
2203 ptr_to_globals++;
2204 G2.l_desc.dyn_tree = G2.dyn_ltree;
2205 G2.l_desc.static_tree = G2.static_ltree;
2206 G2.l_desc.extra_bits = extra_lbits;
2207 G2.l_desc.extra_base = LITERALS + 1;
2208 G2.l_desc.elems = L_CODES;
2209 G2.l_desc.max_length = MAX_BITS;
2210 //G2.l_desc.max_code = 0;
2211
2212 G2.d_desc.dyn_tree = G2.dyn_dtree;
2213 G2.d_desc.static_tree = G2.static_dtree;
2214 G2.d_desc.extra_bits = extra_dbits;
2215 //G2.d_desc.extra_base = 0;
2216 G2.d_desc.elems = D_CODES;
2217 G2.d_desc.max_length = MAX_BITS;
2218 //G2.d_desc.max_code = 0;
2219
2220 G2.bl_desc.dyn_tree = G2.bl_tree;
2221 //G2.bl_desc.static_tree = NULL;
2222 G2.bl_desc.extra_bits = extra_blbits,
2223 //G2.bl_desc.extra_base = 0;
2224 G2.bl_desc.elems = BL_CODES;
2225 G2.bl_desc.max_length = MAX_BL_BITS;
2226 //G2.bl_desc.max_code = 0;
2227
2228 /* Allocate all global buffers (for DYN_ALLOC option) */
2229 ALLOC(uch, G1.l_buf, INBUFSIZ);
2230 ALLOC(uch, G1.outbuf, OUTBUFSIZ);
2231 ALLOC(ush, G1.d_buf, DIST_BUFSIZE);
2232 ALLOC(uch, G1.window, 2L * WSIZE);
2233 ALLOC(ush, G1.prev, 1L << BITS);
2234
2235 /* Initialise the CRC32 table */
2236 G1.crc_32_tab = crc32_filltable(0);
2237
2238 clear_bufs();
2239
2240 return bbunpack(argv, make_new_name_gzip, pack_gzip);
2241}