/* vi: set sw=4 ts=4: */
/*
 * Gzip implementation for busybox
 *
 * Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
 *
 * Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
 * based on gzip sources
 *
 * Adjusted further by Erik Andersen <andersee@debian.org> to support files as
 * well as stdin/stdout, and to generally behave itself wrt command line
 * handling.
 *
 * General cleanup to better adhere to the style guide and make use of standard
 * busybox functions by Glenn McGrath <bug1@optushome.com.au>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
 * Copyright (C) 1992-1993 Jean-loup Gailly
 * The unzip code was written and put in the public domain by Mark Adler.
 * Portions of the lzw code are derived from the public domain 'compress'
 * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
 * Ken Turkowski, Dave Mack and Peter Jannesen.
 *
 * See the license_msg below and the file COPYING for the software license.
 * See the file algorithm.doc for the compression algorithms and file formats.
 */

#if 0
static char *license_msg[] = {
	"   Copyright (C) 1992-1993 Jean-loup Gailly",
	"   This program is free software; you can redistribute it and/or modify",
	"   it under the terms of the GNU General Public License as published by",
	"   the Free Software Foundation; either version 2, or (at your option)",
	"   any later version.",
	"",
	"   This program is distributed in the hope that it will be useful,",
	"   but WITHOUT ANY WARRANTY; without even the implied warranty of",
	"   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the",
	"   GNU General Public License for more details.",
	"",
	"   You should have received a copy of the GNU General Public License",
	"   along with this program; if not, write to the Free Software",
	"   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.",
	0
};
#endif

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include "busybox.h"

const int gunzip_to_stdout = 1;
const int gunzip_force = 2;
const int gunzip_test = 4;
const int gunzip_verbose = 8;

static int gunzip_file(const char *path, int flags)
{
	FILE *in_file, *out_file;
	struct stat stat_buf;
	const char *delete_path = NULL;
	char *out_path = NULL;

	if (path == NULL || strcmp(path, "-") == 0) {
		in_file = stdin;
		flags |= gunzip_to_stdout;
	} else {
		if ((in_file = wfopen(path, "r")) == NULL) {
			return -1;
		}
		if (flags & gunzip_verbose) {
			fprintf(stderr, "%s:\t", path);
		}

		/* set the buffer size */
		setvbuf(in_file, NULL, _IOFBF, 0x8000);

		/* Get the time stamp on the input file. */
		if (stat(path, &stat_buf) < 0) {
			error_msg_and_die("Couldn't stat file %s", path);
		}
	}

	/* Check that the input is sane.  */
	if (isatty(fileno(in_file)) && (flags & gunzip_force) == 0) {
		error_msg_and_die
			("compressed data not read from terminal.  Use -f to force it.");
	}

	/* Set output filename and number */
	if (flags & gunzip_test) {
		out_file = xfopen("/dev/null", "w");	/* why does test use filenum 2 ? */
	} else if (flags & gunzip_to_stdout) {
		out_file = stdout;
	} else {
		char *extension;
		int length = strlen(path);

		extension = strrchr(path, '.');
		if (extension && strcmp(extension, ".gz") == 0) {
			length -= 3;
		} else if (extension && strcmp(extension, ".tgz") == 0) {
			length -= 4;
		} else {
			error_msg_and_die("Invalid extension");
		}
		out_path = xstrndup(path, length);

		/* Open output file */
		out_file = xfopen(out_path, "w");

		/* Set permissions on the file */
		chmod(out_path, stat_buf.st_mode);
	}

	/* do the decompression, and cleanup */
	if (unzip(in_file, out_file) == 0) {
		/* Success, remove .gz file */
		if (!(flags & gunzip_to_stdout)) {
			delete_path = path;
		}
		if (flags & gunzip_verbose) {
			fprintf(stderr, "OK\n");
		}
	} else {
		/* remove failed attempt */
		delete_path = out_path;
	}

	if (out_file != stdout) {
		fclose(out_file);
	}
	if (in_file != stdin) {
		fclose(in_file);
	}

	if (delete_path && !(flags & gunzip_test)) {
		if (unlink(delete_path) < 0) {
			error_msg_and_die("Couldn't remove %s", delete_path);
		}
	}

	free(out_path);

	return 0;
}

extern int gunzip_main(int argc, char **argv)
{
	int flags = 0;
	int i, opt;
	int status = EXIT_SUCCESS;

	/* if called as zcat */
	if (strcmp(applet_name, "zcat") == 0) {
		flags |= gunzip_to_stdout;
	}

	while ((opt = getopt(argc, argv, "ctfhdqv")) != -1) {
		switch (opt) {
		case 'c':
			flags |= gunzip_to_stdout;
			break;
		case 'f':
			flags |= gunzip_force;
			break;
		case 't':
			flags |= gunzip_test;
			break;
		case 'v':
			flags |= gunzip_verbose;
			break;
		case 'd':		/* Used to convert gzip to gunzip. */
			break;
		case 'q':
			error_msg("-q option not supported, ignored");
			break;
		case 'h':
		default:
			show_usage();	/* exit's inside usage */
		}
	}

	if (optind == argc) {
		if (gunzip_file(NULL, flags) < 0) {
			status = EXIT_FAILURE;
		}
	} else {
		for (i = optind; i < argc; i++) {
			if (gunzip_file(argv[i], flags) < 0) {
				status = EXIT_FAILURE;
			}
		}
	}
	return status;
}
