1 /* vi: set sw=4 ts=4: */
3 * Mini unzip implementation for busybox
5 * Copyright (C) 2001 by Laurence Anderson
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "unarchive.h"
31 extern int unzip_main(int argc, char **argv)
34 int extract_function = extract_all_to_fs | extract_create_leading_dirs;
35 char **extract_names = NULL;
36 char **exclude_names = NULL;
38 int num_of_entries = 0;
41 FILE *msgout = stdout;
43 while ((opt = getopt(argc, argv, "lnopqxd:")) != -1) {
46 extract_function |= extract_verbose_list;
47 extract_function ^= extract_all_to_fs;
52 extract_function |= extract_unconditional;
55 extract_function |= extract_to_stdout;
56 extract_function ^= extract_all_to_fs;
59 msgout = xfopen("/dev/null", "w");
62 outdir = xstrdup(optarg);
75 if (*argv[optind] == '-') src_stream = stdin;
76 else src_stream = xfopen(argv[optind++], "r");
78 while (optind < argc) {
80 exclude_names = xrealloc(exclude_names, sizeof(char *) * (num_of_entries + 2));
81 exclude_names[num_of_entries] = xstrdup(argv[optind]);
83 extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
84 extract_names[num_of_entries] = xstrdup(argv[optind]);
87 if (exclude) exclude_names[num_of_entries] = NULL;
88 else extract_names[num_of_entries] = NULL;
92 unarchive(src_stream, msgout, &get_header_zip, extract_function, outdir, extract_names, exclude_names);