2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "unarchive.h"
23 extern int dpkg_deb_main(int argc, char **argv)
26 char *filename = NULL;
27 char *output_buffer = NULL;
30 int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;
32 const int arg_type_prefix = 1;
33 const int arg_type_field = 2;
34 const int arg_type_filename = 4;
35 // const int arg_type_un_ar_gz = 8;
37 while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
40 deb_extract_funct |= extract_data_tar_gz;
41 deb_extract_funct |= extract_verbose_list;
44 arg_type = arg_type_prefix;
45 deb_extract_funct |= extract_control_tar_gz;
46 deb_extract_funct |= extract_all_to_fs;
49 arg_type = arg_type_field;
50 deb_extract_funct |= extract_control_tar_gz;
51 deb_extract_funct |= extract_one_to_buffer;
52 filename = xstrdup("./control");
54 case 't': /* --fsys-tarfile, i just made up this short name */
55 /* Integrate the functionality needed with some code from ar.c */
56 error_msg_and_die("Option disabled");
57 // arg_type = arg_type_un_ar_gz;
60 arg_type = arg_type_prefix;
61 deb_extract_funct |= extract_data_tar_gz;
62 deb_extract_funct |= extract_all_to_fs;
63 deb_extract_funct |= extract_list;
65 arg_type = arg_type_prefix;
66 deb_extract_funct |= extract_data_tar_gz;
67 deb_extract_funct |= extract_all_to_fs;
70 arg_type = arg_type_filename;
71 deb_extract_funct |= extract_control_tar_gz;
72 deb_extract_funct |= extract_one_to_buffer;
83 /* Workout where to extract the files */
84 if (arg_type == arg_type_prefix) {
85 /* argument is a dir name */
86 if ((optind + 1) == argc ) {
87 prefix = xstrdup("./DEBIAN/");
89 prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2);
90 strcpy(prefix, argv[optind + 1]);
91 /* Make sure the directory has a trailing '/' */
92 if (last_char_is(prefix, '/') == NULL) {
99 if (arg_type == arg_type_filename) {
100 if ((optind + 1) != argc) {
101 filename = xstrdup(argv[optind + 1]);
103 error_msg_and_die("-I currently requires a filename to be specified");
107 output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename);
109 if ((arg_type == arg_type_filename) && (output_buffer != NULL)) {
112 else if (arg_type == arg_type_field) {
119 field_start += read_package_field(&output_buffer[field_start], &name, &value);
123 if (strcmp(name, argv[optind + 1]) == 0) {
130 return(EXIT_SUCCESS);