aboutsummaryrefslogtreecommitdiff
path: root/archival/dpkg_deb.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-06-13 07:26:39 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-06-13 07:26:39 +0000
commit9aff9036035fbed074e8e711b96c5c934e668884 (patch)
tree4db8fdd4b9f429b416d068794c79bfc0df844e20 /archival/dpkg_deb.c
parentdab3d46b9d35e0a0279b3700fe411f876bb25781 (diff)
downloadbusybox-w32-9aff9036035fbed074e8e711b96c5c934e668884.tar.gz
busybox-w32-9aff9036035fbed074e8e711b96c5c934e668884.tar.bz2
busybox-w32-9aff9036035fbed074e8e711b96c5c934e668884.zip
Reorganise archive extraction code
Diffstat (limited to 'archival/dpkg_deb.c')
-rw-r--r--archival/dpkg_deb.c105
1 files changed, 60 insertions, 45 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 17b5476d0..400f2385a 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -21,33 +21,54 @@
21 21
22extern int dpkg_deb_main(int argc, char **argv) 22extern int dpkg_deb_main(int argc, char **argv)
23{ 23{
24 char *argument = NULL; 24 char *prefix = NULL;
25 char *filename = NULL;
25 char *output_buffer = NULL; 26 char *output_buffer = NULL;
26 int opt = 0; 27 int opt = 0;
27 int optflag = 0; 28 int arg_type = 0;
29 int deb_extract_funct = 0;
28 30
31 const int arg_type_prefix = 1;
32 const int arg_type_field = 2;
33 const int arg_type_filename = 4;
34// const int arg_type_un_ar_gz = 8;
35
29 while ((opt = getopt(argc, argv, "ceftXxI")) != -1) { 36 while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
30 switch (opt) { 37 switch (opt) {
31 case 'c': 38 case 'c':
32 optflag |= extract_contents; 39 deb_extract_funct |= extract_data_tar_gz;
40 deb_extract_funct |= extract_verbose_list;
33 break; 41 break;
34 case 'e': 42 case 'e':
35 optflag |= extract_control; 43 arg_type = arg_type_prefix;
44 deb_extract_funct |= extract_control_tar_gz;
45 deb_extract_funct |= extract_all_to_fs;
36 break; 46 break;
37 case 'f': 47 case 'f':
38 optflag |= extract_field; 48 arg_type = arg_type_field;
49 deb_extract_funct |= extract_control_tar_gz;
50 deb_extract_funct |= extract_one_to_buffer;
51 filename = xstrdup("./control");
39 break; 52 break;
40 case 't': 53 case 't': /* --fsys-tarfile, i just made up this short name */
41 optflag |= extract_fsys_tarfile; 54 /* Integrate the functionality needed with some code from ar.c */
55 error_msg_and_die("Option disabled");
56// arg_type = arg_type_un_ar_gz;
42 break; 57 break;
43 case 'X': 58 case 'X':
44 optflag |= extract_verbose_extract; 59 arg_type = arg_type_prefix;
45 break; 60 deb_extract_funct |= extract_data_tar_gz;
61 deb_extract_funct |= extract_all_to_fs;
62 deb_extract_funct |= extract_list;
46 case 'x': 63 case 'x':
47 optflag |= extract_extract; 64 arg_type = arg_type_prefix;
65 deb_extract_funct |= extract_data_tar_gz;
66 deb_extract_funct |= extract_all_to_fs;
48 break; 67 break;
49 case 'I': 68 case 'I':
50 optflag |= extract_info; 69 arg_type = arg_type_filename;
70 deb_extract_funct |= extract_control_tar_gz;
71 deb_extract_funct |= extract_one_to_buffer;
51 break; 72 break;
52 default: 73 default:
53 show_usage(); 74 show_usage();
@@ -58,48 +79,42 @@ extern int dpkg_deb_main(int argc, char **argv)
58 show_usage(); 79 show_usage();
59 } 80 }
60 81
61 switch (optflag) { 82 /* Workout where to extract the files */
62 case (extract_control): 83 if (arg_type == arg_type_prefix) {
63 case (extract_extract): 84 /* argument is a dir name */
64 case (extract_verbose_extract): 85 if ((optind + 1) == argc ) {
65 /* argument is a dir name */ 86 prefix = xstrdup("./DEBIAN/");
66 if ( (optind + 1) == argc ) { 87 } else {
67 argument = xstrdup("DEBIAN"); 88 prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2);
68 } else { 89 strcpy(prefix, argv[optind + 1]);
69 argument = xstrdup(argv[optind + 1]); 90 /* Make sure the directory has a trailing '/' */
70 } 91 if (last_char_is(prefix, '/') == NULL) {
71 break; 92 strcat(prefix, "/");
72 case (extract_field):
73 /* argument is a control field name */
74 if ((optind + 1) != argc) {
75 argument = xstrdup(argv[optind + 1]);
76 }
77 break;
78 case (extract_info):
79 /* argument is a control field name */
80 if ((optind + 1) != argc) {
81 argument = xstrdup(argv[optind + 1]);
82 break;
83 } else {
84 error_msg("-I currently requires a filename to be specifies");
85 return(EXIT_FAILURE);
86 } 93 }
87 /* argument is a filename */ 94 }
88 default:
89 } 95 }
90 96
91 output_buffer = deb_extract(argv[optind], optflag, argument, NULL); 97 if (arg_type == arg_type_filename) {
98 if ((optind + 1) != argc) {
99 filename = xstrdup(argv[optind + 1]);
100 } else {
101 error_msg_and_die("-I currently requires a filename to be specified");
102 }
103 }
92 104
93 if (optflag & extract_field) { 105 output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename);
106
107 if ((arg_type == arg_type_filename) && (output_buffer != NULL)) {
108 puts(output_buffer);
109 }
110 else if (arg_type == arg_type_field) {
94 char *field = NULL; 111 char *field = NULL;
95 int field_length = 0;
96 int field_start = 0; 112 int field_start = 0;
97 113
98 while ((field = read_package_field(&output_buffer[field_start])) != NULL) { 114 while ((field = read_package_field(&output_buffer[field_start])) != NULL) {
99 field_length = strlen(field); 115 field_start += (strlen(field) + 1);
100 field_start += (field_length + 1); 116 if (strstr(field, argv[optind + 1]) == field) {
101 if (strstr(field, argument) == field) { 117 puts(field + strlen(argv[optind + 1]) + 2);
102 puts(field + strlen(argument) + 2);
103 } 118 }
104 free(field); 119 free(field);
105 } 120 }