1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#!/usr/bin/perl
use strict;
use packdrake;
use Pod::Usage;
#- general information.
my $default_size = 400000;
my $default_ratio = 6;
sub usage () {
pod2usage({ -verbose => 1 });
exit 0;
}
my ($file, $mode, $dir, $size, $method, $compress, $uncompress, $ratio, $quiet);
my @nextargv = (\$file);
my @list;
#- some quite useful error message.
my $error_mode = "packdrake: choose only --build, --extract, --list or --cat\n";
foreach (@ARGV) {
/^--help$/ and usage();
/^--build$/ and do { $mode and die $error_mode; $mode = "build"; @nextargv = (\$file); next };
/^--extract$/ and do { $mode and die $error_mode; $mode = "extract"; @nextargv = (\$file, \$dir); next };
/^--list$/ and do { $mode and die $error_mode; $mode = "list"; @nextargv = (\$file); next };
/^--cat$/ and do { $mode and die $error_mode; $mode = "cat"; @nextargv = (\$file); next };
/^--dir$/ and do { push @nextargv, \$dir; next };
/^--size$/ and do { push @nextargv, \$size; next };
/^--method$/ and do { push @nextargv, \$method; next };
/^--compress$/ and do { push @nextargv, \$compress; next };
/^--uncompress$/ and do { push @nextargv, \$uncompress; next };
/^--quiet$/ and $quiet = 1, next;
/^-(.*)$/ and do { foreach (split //, $1) {
/[1-9]/ and do { $ratio = $_; next };
/b/ and do { $mode and die $error_mode; $mode = "build"; @nextargv = (\$file); next };
/x/ and do { $mode and die $error_mode; $mode = "extract"; @nextargv = (\$file, \$dir); next };
/l/ and do { $mode and die $error_mode; $mode = "list"; @nextargv = (\$file); next };
/c/ and do { $mode and die $error_mode; $mode = "cat"; @nextargv = (\$file); next };
/d/ and do { push @nextargv, \$dir; next };
/s/ and do { push @nextargv, \$size; next };
/m/ and do { push @nextargv, \$method; next };
die qq(packdrake: unknown option "-$1", check usage with --help\n) } next };
$mode =~ /extract|list|cat/
or @nextargv
or die qq(packdrake: unknown option "$_", check usage with --help\n);
my $ref = shift @nextargv;
$ref ? ($$ref = $_) : push @list, $_;
$mode ||= "list";
}
#- examine and lauch.
$file or die "packdrake: no archive filename given, check usage with --help\n";
$size ||= $default_size;
$ratio ||= $default_ratio;
unless ($method) {
$file =~ /\.cz$/ and $method = "gzip";
$file =~ /\.cz2$/ and $method = "bzip2";
}
$compress ||= "$method -$ratio";
$uncompress ||= "$method -d";
$mode =~ /extract/ && !$dir && !@list and ($mode, @list) = ('list', $file);
for ($mode) {
/build/ and do { packdrake::build_archive(\*STDIN, $dir, $file, $size, $compress, $uncompress); last };
/extract/ and do {
my $packer = new packdrake($file, quiet => $quiet);
$packer->extract_archive($dir, @list);
last;
};
/list/ and do { packdrake::list_archive($file, @list); last };
/cat/ and do { packdrake::cat_archive($file, @list); last };
die "packdrake: internal error, unable to select right mode?\n";
}
__END__
=head1 NAME
packdrake - manipulates archives
=head1 SYNOPSIS
packdrake [options] [--build|-b] file
packdrake [options] [--extract|-x] file
packdrake [options] [--list|-l] file
packdrake [options] [--cat|-c] file
=head1 OPTIONS
=over 2
=item --build file
Build mode; build archive file with filenames given on standard input.
Sub-options are:
=over 4
=item -1 .. -9
Select appropriate compression ratio.
=item --dir srcdir
set source directory where to search files, C<.> by default.
=item --size
Set maximum chunk size, 400000 by default.
=item --method
Select standard compression command method.
Default is deduced from the archive filename (gzip or bzip2).
=item --compress cmd
Select compression command.
=back
=item --extract file dir file1...fileN
Extracts archive file to specified directory.
Specific files to extract may be given on the command line.
=over 4
=item --uncompress cmd
Select uncompression command.
=back
=item --list file
Lists contents of archive.
=item --cat file
Dumps archive to standard output.
=item General options
=over 4
=item --quiet
Silent mode.
=back
=back
=head1 DESCRIPTION
=head1 SEE ALSO
=head1 COPYRIGHT
Copyright (C) 2000-2005 Mandrakesoft.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=cut
|