blob: 17b5476d0ddefc1f4ab7d1114a788b1af1cc1887 [file] [log] [blame]
Glenn L McGrath58a40852001-01-02 23:49:26 +00001/*
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.
6 *
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.
11 *
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.
15 */
16
Glenn L McGrath58a40852001-01-02 23:49:26 +000017#include <stdlib.h>
Glenn L McGrath33431eb2001-04-16 04:52:19 +000018#include <string.h>
Glenn L McGrathd22e5602001-04-11 02:12:08 +000019#include <getopt.h>
Glenn L McGrath58a40852001-01-02 23:49:26 +000020#include "busybox.h"
21
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000022extern int dpkg_deb_main(int argc, char **argv)
23{
Glenn L McGrath445fb952001-04-13 04:02:57 +000024 char *argument = NULL;
Glenn L McGrath33431eb2001-04-16 04:52:19 +000025 char *output_buffer = NULL;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000026 int opt = 0;
27 int optflag = 0;
Glenn L McGrath58a40852001-01-02 23:49:26 +000028
Glenn L McGrath445fb952001-04-13 04:02:57 +000029 while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
Glenn L McGrath58a40852001-01-02 23:49:26 +000030 switch (opt) {
31 case 'c':
Glenn L McGrath359c1062001-04-12 10:19:08 +000032 optflag |= extract_contents;
Glenn L McGrath58a40852001-01-02 23:49:26 +000033 break;
34 case 'e':
Glenn L McGrath359c1062001-04-12 10:19:08 +000035 optflag |= extract_control;
Glenn L McGrath58a40852001-01-02 23:49:26 +000036 break;
Glenn L McGrath445fb952001-04-13 04:02:57 +000037 case 'f':
38 optflag |= extract_field;
39 break;
Glenn L McGrath3e2ab882001-04-12 13:49:09 +000040 case 't':
41 optflag |= extract_fsys_tarfile;
42 break;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000043 case 'X':
Glenn L McGrath359c1062001-04-12 10:19:08 +000044 optflag |= extract_verbose_extract;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000045 break;
46 case 'x':
Glenn L McGrath359c1062001-04-12 10:19:08 +000047 optflag |= extract_extract;
Glenn L McGrathbc9afad2001-02-11 03:32:41 +000048 break;
Glenn L McGrath445fb952001-04-13 04:02:57 +000049 case 'I':
Glenn L McGrath359c1062001-04-12 10:19:08 +000050 optflag |= extract_info;
Glenn L McGrath58a40852001-01-02 23:49:26 +000051 break;
Glenn L McGrath58a40852001-01-02 23:49:26 +000052 default:
Eric Andersen67991cf2001-02-14 21:23:06 +000053 show_usage();
Glenn L McGrath58a40852001-01-02 23:49:26 +000054 }
55 }
56
Glenn L McGrath6785b512001-04-12 11:48:02 +000057 if (optind == argc) {
Eric Andersen67991cf2001-02-14 21:23:06 +000058 show_usage();
Glenn L McGrath58a40852001-01-02 23:49:26 +000059 }
Glenn L McGrath6785b512001-04-12 11:48:02 +000060
Glenn L McGrath359c1062001-04-12 10:19:08 +000061 switch (optflag) {
62 case (extract_control):
63 case (extract_extract):
64 case (extract_verbose_extract):
Glenn L McGrath445fb952001-04-13 04:02:57 +000065 /* argument is a dir name */
Glenn L McGrath359c1062001-04-12 10:19:08 +000066 if ( (optind + 1) == argc ) {
Glenn L McGrath445fb952001-04-13 04:02:57 +000067 argument = xstrdup("DEBIAN");
Glenn L McGrath6785b512001-04-12 11:48:02 +000068 } else {
Glenn L McGrath445fb952001-04-13 04:02:57 +000069 argument = xstrdup(argv[optind + 1]);
Glenn L McGrath359c1062001-04-12 10:19:08 +000070 }
71 break;
Glenn L McGrath445fb952001-04-13 04:02:57 +000072 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 }
87 /* argument is a filename */
Glenn L McGrath6785b512001-04-12 11:48:02 +000088 default:
Glenn L McGrath58a40852001-01-02 23:49:26 +000089 }
Glenn L McGrath6785b512001-04-12 11:48:02 +000090
Glenn L McGrath33431eb2001-04-16 04:52:19 +000091 output_buffer = deb_extract(argv[optind], optflag, argument, NULL);
92
93 if (optflag & extract_field) {
94 char *field = NULL;
95 int field_length = 0;
96 int field_start = 0;
97
98 while ((field = read_package_field(&output_buffer[field_start])) != NULL) {
99 field_length = strlen(field);
100 field_start += (field_length + 1);
101 if (strstr(field, argument) == field) {
Matt Kraai59df6f72001-05-16 14:21:09 +0000102 puts(field + strlen(argument) + 2);
Glenn L McGrath33431eb2001-04-16 04:52:19 +0000103 }
104 free(field);
105 }
106 }
Glenn L McGrath445fb952001-04-13 04:02:57 +0000107
Glenn L McGrath58a40852001-01-02 23:49:26 +0000108 return(EXIT_SUCCESS);
109}