5 # Copyright © 2024 Guillem Jover <guillem@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
25 use Dpkg
::ErrorHandling
;
26 use Dpkg
::Archive
::Ar
;
28 textdomain
('dpkg-dev');
34 printf(g_
("Debian %s version %s.\n"), $Dpkg::PROGNAME
, $Dpkg::PROGVERSION
);
39 printf(g_
("Usage: %s [<option>...]\n"), $Dpkg::PROGNAME
);
43 --create <archive> <file>... create an ar archive.
44 --list <archive> list the contents of an ar archive.
45 --extract <archive> [<file>...] extract the contents of an ar archive.
46 -?, --help show this help message.
47 --version show the version.
53 my ($archive, @files) = @_;
55 my $ar = Dpkg
::Archive
::Ar
->new(
60 foreach my $file (@files) {
69 my $ar = Dpkg
::Archive
::Ar
->new(filename
=> $archive);
71 foreach my $member (@
{$ar->get_members()}) {
72 print "$member->{name}\n";
78 my ($archive, @files) = @_;
79 my %file = map { $_ => 1 } @files;
81 my $ar = Dpkg
::Archive
::Ar
->new(filename
=> $archive);
83 foreach my $member (@
{$ar->get_members()}) {
84 next if @files && ! exists $file{$member->{name
}};
86 $ar->extract_member($member);
93 my $arg = shift @ARGV;
94 if ($arg eq '-?' or $arg eq '--help') {
97 } elsif ($arg eq '-v' or $arg eq '--version') {
100 } elsif ($arg eq '--create') {
102 } elsif ($arg eq '--list') {
104 } elsif ($arg eq '--extract') {
106 } elsif ($arg eq '--') {
109 } elsif ($arg =~ m/^-/) {
110 usageerr
(g_
("unknown option '%s'"), $arg);
116 @files or usageerr
(g_
('need at least an archive filename'));
118 if ($action eq 'create') {
120 usageerr
(g_
('need at least a file to add into the archive'));
123 } elsif ($action eq 'list') {
125 } elsif ($action eq 'extract') {