Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 1 | /* |
| 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 McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 18 | #include <string.h> |
Glenn L McGrath | d22e560 | 2001-04-11 02:12:08 +0000 | [diff] [blame] | 19 | #include <getopt.h> |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 20 | #include "busybox.h" |
| 21 | |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 22 | extern int dpkg_deb_main(int argc, char **argv) |
| 23 | { |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 24 | char *argument = NULL; |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 25 | char *output_buffer = NULL; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 26 | int opt = 0; |
| 27 | int optflag = 0; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 28 | |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 29 | while ((opt = getopt(argc, argv, "ceftXxI")) != -1) { |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 30 | switch (opt) { |
| 31 | case 'c': |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 32 | optflag |= extract_contents; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 33 | break; |
| 34 | case 'e': |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 35 | optflag |= extract_control; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 36 | break; |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 37 | case 'f': |
| 38 | optflag |= extract_field; |
| 39 | break; |
Glenn L McGrath | 3e2ab88 | 2001-04-12 13:49:09 +0000 | [diff] [blame] | 40 | case 't': |
| 41 | optflag |= extract_fsys_tarfile; |
| 42 | break; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 43 | case 'X': |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 44 | optflag |= extract_verbose_extract; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 45 | break; |
| 46 | case 'x': |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 47 | optflag |= extract_extract; |
Glenn L McGrath | bc9afad | 2001-02-11 03:32:41 +0000 | [diff] [blame] | 48 | break; |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 49 | case 'I': |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 50 | optflag |= extract_info; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 51 | break; |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 52 | default: |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 53 | show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 57 | if (optind == argc) { |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 58 | show_usage(); |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 59 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 60 | |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 61 | switch (optflag) { |
| 62 | case (extract_control): |
| 63 | case (extract_extract): |
| 64 | case (extract_verbose_extract): |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 65 | /* argument is a dir name */ |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 66 | if ( (optind + 1) == argc ) { |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 67 | argument = xstrdup("DEBIAN"); |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 68 | } else { |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 69 | argument = xstrdup(argv[optind + 1]); |
Glenn L McGrath | 359c106 | 2001-04-12 10:19:08 +0000 | [diff] [blame] | 70 | } |
| 71 | break; |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 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 | } |
| 87 | /* argument is a filename */ |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 88 | default: |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 89 | } |
Glenn L McGrath | 6785b51 | 2001-04-12 11:48:02 +0000 | [diff] [blame] | 90 | |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 91 | 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 Kraai | 59df6f7 | 2001-05-16 14:21:09 +0000 | [diff] [blame] | 102 | puts(field + strlen(argument) + 2); |
Glenn L McGrath | 33431eb | 2001-04-16 04:52:19 +0000 | [diff] [blame] | 103 | } |
| 104 | free(field); |
| 105 | } |
| 106 | } |
Glenn L McGrath | 445fb95 | 2001-04-13 04:02:57 +0000 | [diff] [blame] | 107 | |
Glenn L McGrath | 58a4085 | 2001-01-02 23:49:26 +0000 | [diff] [blame] | 108 | return(EXIT_SUCCESS); |
| 109 | } |