1 /* vi: set sw=4 ts=4: */
3 * dpkg-deb packs, unpacks and provides information about Debian archives.
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 #define DPKG_DEB_OPT_CONTENTS 1
11 #define DPKG_DEB_OPT_CONTROL 2
12 #define DPKG_DEB_OPT_FIELD 4
13 #define DPKG_DEB_OPT_EXTRACT 8
14 #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
16 int dpkg_deb_main(int argc, char **argv)
18 archive_handle_t *ar_archive;
19 archive_handle_t *tar_archive;
20 llist_t *control_tar_llist = NULL;
22 char *extract_dir = NULL;
25 /* Setup the tar archive handle */
26 tar_archive = init_handle();
28 /* Setup an ar archive handle that refers to the gzip sub archive */
29 ar_archive = init_handle();
30 ar_archive->sub_archive = tar_archive;
31 ar_archive->filter = filter_accept_list_reassign;
33 #ifdef CONFIG_FEATURE_DEB_TAR_GZ
34 llist_add_to(&(ar_archive->accept), "data.tar.gz");
35 llist_add_to(&control_tar_llist, "control.tar.gz");
38 #ifdef CONFIG_FEATURE_DEB_TAR_BZ2
39 llist_add_to(&(ar_archive->accept), "data.tar.bz2");
40 llist_add_to(&control_tar_llist, "control.tar.bz2");
43 opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
44 opt = getopt32(argc, argv, "cefXx");
46 if (opt & DPKG_DEB_OPT_CONTENTS) {
47 tar_archive->action_header = header_verbose_list;
49 if (opt & DPKG_DEB_OPT_CONTROL) {
50 ar_archive->accept = control_tar_llist;
51 tar_archive->action_data = data_extract_all;
52 if (optind + 1 == argc) {
53 extract_dir = "./DEBIAN";
58 if (opt & DPKG_DEB_OPT_FIELD) {
59 /* Print the entire control file
60 * it should accept a second argument which specifies a
61 * specific field to print */
62 ar_archive->accept = control_tar_llist;
63 llist_add_to(&(tar_archive->accept), "./control");
64 tar_archive->filter = filter_accept_list;
65 tar_archive->action_data = data_extract_to_stdout;
67 if (opt & DPKG_DEB_OPT_EXTRACT) {
68 tar_archive->action_header = header_list;
70 if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
71 tar_archive->action_data = data_extract_all;
75 if ((optind + argcount) != argc) {
79 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
81 /* Workout where to extract the files */
82 /* 2nd argument is a dir name */
84 extract_dir = argv[optind];
87 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
90 unpack_ar_archive(ar_archive);
93 close(ar_archive->src_fd);