diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-07 09:24:06 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-07 09:24:06 +0000 |
commit | 1f28b90a9c934a2e56e50da279bfca136b802114 (patch) | |
tree | 147f004006149d806adfeec6f870d7f204c25292 | |
parent | 9d65ab2beb0e418510a42f6802cf6daa1d7a2106 (diff) | |
download | busybox-w32-1f28b90a9c934a2e56e50da279bfca136b802114.tar.gz busybox-w32-1f28b90a9c934a2e56e50da279bfca136b802114.tar.bz2 busybox-w32-1f28b90a9c934a2e56e50da279bfca136b802114.zip |
Use bb_getopt_ulflags, save 100 bytes and strict argument checking.
-rw-r--r-- | archival/dpkg_deb.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 2d7383fd7..da94b394f 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
@@ -12,24 +12,32 @@ | |||
12 | * You should have received a copy of the GNU General Public License | 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 | 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. | 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
15 | * | ||
15 | */ | 16 | */ |
16 | #include <fcntl.h> | 17 | #include <fcntl.h> |
17 | #include <stdlib.h> | 18 | #include <stdlib.h> |
18 | #include <string.h> | 19 | #include <string.h> |
19 | #include <unistd.h> | 20 | #include <unistd.h> |
20 | #include <getopt.h> | 21 | #include <getopt.h> |
22 | |||
21 | #include "unarchive.h" | 23 | #include "unarchive.h" |
22 | #include "busybox.h" | 24 | #include "busybox.h" |
23 | 25 | ||
26 | #define DPKG_DEB_OPT_CONTENTS 1 | ||
27 | #define DPKG_DEB_OPT_CONTROL 2 | ||
28 | #define DPKG_DEB_OPT_FIELD 4 | ||
29 | #define DPKG_DEB_OPT_EXTRACT 8 | ||
30 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 | ||
31 | |||
24 | extern int dpkg_deb_main(int argc, char **argv) | 32 | extern int dpkg_deb_main(int argc, char **argv) |
25 | { | 33 | { |
26 | archive_handle_t *ar_archive; | 34 | archive_handle_t *ar_archive; |
27 | archive_handle_t *tar_archive; | 35 | archive_handle_t *tar_archive; |
28 | int opt = 0; | ||
29 | #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY | ||
30 | llist_t *control_tar_llist = NULL; | 36 | llist_t *control_tar_llist = NULL; |
31 | #endif | 37 | unsigned long opt; |
32 | 38 | char *extract_dir = NULL; | |
39 | short argcount = 1; | ||
40 | |||
33 | /* Setup the tar archive handle */ | 41 | /* Setup the tar archive handle */ |
34 | tar_archive = init_handle(); | 42 | tar_archive = init_handle(); |
35 | 43 | ||
@@ -40,53 +48,47 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
40 | 48 | ||
41 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ | 49 | #ifdef CONFIG_FEATURE_DEB_TAR_GZ |
42 | ar_archive->accept = llist_add_to(NULL, "data.tar.gz"); | 50 | ar_archive->accept = llist_add_to(NULL, "data.tar.gz"); |
43 | # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY | ||
44 | control_tar_llist = llist_add_to(NULL, "control.tar.gz"); | 51 | control_tar_llist = llist_add_to(NULL, "control.tar.gz"); |
45 | # endif | ||
46 | #endif | 52 | #endif |
47 | 53 | ||
48 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 | 54 | #ifdef CONFIG_FEATURE_DEB_TAR_BZ2 |
49 | ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2"); | 55 | ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2"); |
50 | # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY | ||
51 | control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2"); | 56 | control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2"); |
52 | # endif | ||
53 | #endif | 57 | #endif |
54 | 58 | ||
55 | #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY | 59 | bb_opt_complementaly = "c~efXx:e~cfXx:f~ceXx:X~cefx:x~cefX"; |
56 | while ((opt = getopt(argc, argv, "cefXx")) != -1) { | 60 | opt = bb_getopt_ulflags(argc, argv, "cefXx"); |
57 | #else | 61 | |
58 | while ((opt = getopt(argc, argv, "x")) != -1) { | 62 | if (opt & DPKG_DEB_OPT_CONTENTS) { |
59 | #endif | 63 | tar_archive->action_header = header_verbose_list; |
60 | switch (opt) { | 64 | } |
61 | #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY | 65 | if (opt & DPKG_DEB_OPT_CONTROL) { |
62 | case 'c': | 66 | ar_archive->accept = control_tar_llist; |
63 | tar_archive->action_header = header_verbose_list; | 67 | tar_archive->action_data = data_extract_all; |
64 | break; | 68 | if (optind + 1 == argc) { |
65 | case 'e': | 69 | extract_dir = "./DEBIAN"; |
66 | ar_archive->accept = control_tar_llist; | 70 | } else { |
67 | tar_archive->action_data = data_extract_all; | 71 | argcount++; |
68 | break; | ||
69 | case 'f': | ||
70 | /* Print the entire control file | ||
71 | * it should accept a second argument which specifies a | ||
72 | * specific field to print */ | ||
73 | ar_archive->accept = control_tar_llist; | ||
74 | tar_archive->accept = llist_add_to(NULL, "./control");; | ||
75 | tar_archive->filter = filter_accept_list; | ||
76 | tar_archive->action_data = data_extract_to_stdout; | ||
77 | break; | ||
78 | case 'X': | ||
79 | tar_archive->action_header = header_list; | ||
80 | #endif | ||
81 | case 'x': | ||
82 | tar_archive->action_data = data_extract_all; | ||
83 | break; | ||
84 | default: | ||
85 | bb_show_usage(); | ||
86 | } | 72 | } |
87 | } | 73 | } |
74 | if (opt & DPKG_DEB_OPT_FIELD) { | ||
75 | /* Print the entire control file | ||
76 | * it should accept a second argument which specifies a | ||
77 | * specific field to print */ | ||
78 | ar_archive->accept = control_tar_llist; | ||
79 | tar_archive->accept = llist_add_to(NULL, "./control");; | ||
80 | tar_archive->filter = filter_accept_list; | ||
81 | tar_archive->action_data = data_extract_to_stdout; | ||
82 | } | ||
83 | if (opt & DPKG_DEB_OPT_EXTRACT) { | ||
84 | tar_archive->action_header = header_list; | ||
85 | } | ||
86 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { | ||
87 | tar_archive->action_data = data_extract_all; | ||
88 | argcount = 2; | ||
89 | } | ||
88 | 90 | ||
89 | if (optind + 2 < argc) { | 91 | if ((optind + argcount != argc) || (opt & 0x80000000UL)) { |
90 | bb_show_usage(); | 92 | bb_show_usage(); |
91 | } | 93 | } |
92 | 94 | ||
@@ -94,9 +96,13 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
94 | 96 | ||
95 | /* Workout where to extract the files */ | 97 | /* Workout where to extract the files */ |
96 | /* 2nd argument is a dir name */ | 98 | /* 2nd argument is a dir name */ |
97 | mkdir(argv[optind], 0777); | 99 | if (argv[optind]) { |
98 | chdir(argv[optind]); | 100 | extract_dir = argv[optind]; |
99 | 101 | } | |
102 | if (extract_dir) { | ||
103 | mkdir(extract_dir, 0777); | ||
104 | chdir(extract_dir); | ||
105 | } | ||
100 | unpack_ar_archive(ar_archive); | 106 | unpack_ar_archive(ar_archive); |
101 | 107 | ||
102 | /* Cleanup */ | 108 | /* Cleanup */ |
@@ -104,4 +110,3 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
104 | 110 | ||
105 | return(EXIT_SUCCESS); | 111 | return(EXIT_SUCCESS); |
106 | } | 112 | } |
107 | |||