2 eval 'exec perl -wS $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
32 # mapgen - generate a dependencies file for zip commando
36 #########################
40 #########################
47 @given_patterns = (); # patterns(files) list from command line
49 @exc_patterns = (); # array of all patterns for files to be excluded
50 @inc_patterns = (); # array of all patterns for files to be included
51 %exc_files_hash = (); # hash of files to be excluded (according to @exc_patterns)
52 %inc_files_hash = (); # hash of files to be included (according to @inc_patterns)
61 #### end of main procedure ####
63 #########################
67 #########################
70 # procedure writes zipdep file
73 my @dependencies = keys %files_in_arch;
74 if ($#dependencies != -1) {
75 print "\n". &convert_slashes
($zip_file) . ' :';
76 foreach (@dependencies) {
78 print " \\\n\t" . $prefix . &convert_slashes
($_);
95 # convert slashes to internal perl representation
105 # Collect all files to zip in @patterns_array array
107 sub get_zip_content
{
108 &get_zip_entries
(\
@given_patterns);
110 foreach $file_name (keys %files_in_arch) {
112 &get_dir_content
($file_name, \
%files_in_arch) if ($r || $R);
113 undef $files_in_arch{$file_name};
116 &remove_uncompliant
(\
@given_patterns) if ($R);
117 &get_patterns_files
(\
@exc_patterns, \
%exc_files_hash) if ($exclude);
118 &get_patterns_files
(\
@inc_patterns, \
%inc_files_hash) if ($include);
119 foreach my $file_name (keys %exc_files_hash) {
120 if (defined $files_in_arch{$file_name}) {
121 delete $files_in_arch{$file_name};
122 #print STDERR "excluded $file_name\n";
126 foreach my $file_name (keys %files_in_arch) {
127 if (!(defined $inc_files_hash{$file_name})) {
128 delete $files_in_arch{$file_name};
135 # Procedure removes from %files_in_arch all files which
136 # are not compliant to patterns in @given_patterns
138 sub remove_uncompliant
{
139 my $given_patterns = shift;
142 foreach $pattern (@
$given_patterns) {
143 push(@reg_exps, &make_reg_exp
($pattern));
145 # write file name as a value for the path(key)
146 foreach my $file (keys %files_in_arch) {
149 if ($file =~ /[\\ | \/](.+)$/) {
150 $files_in_arch{$file} = $1;
152 $files_in_arch{$file} = $file;
155 foreach $pattern (@reg_exps) {
156 foreach my $file (keys %files_in_arch) {
157 if (!($files_in_arch{$file} =~ /$pattern/)) {
158 delete $files_in_arch{$file};
160 # print "Complient: $file\n";
167 # Procedure adds/removes to/from %files_in_arch all files, that are
168 # compliant to the patterns in array passed
170 sub get_zip_entries
{
173 my @dir_content = readdir(DIR
);
175 foreach my $file_name(@dir_content) {
176 $file_name =~ /^\.$/ and next;
177 $file_name =~ /^\.\.$/ and next;
178 $files_in_arch{$file_name}++;
179 #print "included $file_name\n";
182 my $patterns_array = shift;
184 foreach $pattern (@
$patterns_array) {
185 if ((-d
$pattern) || (-f
$pattern)) {
186 $files_in_arch{$pattern}++;
190 foreach $file_name (glob $pattern) {
191 #next if (!(-d $file_name) || !(-f $file_name));
192 $files_in_arch{$file_name}++;
199 # Procedure converts given parameter to a regular expression
211 #$arg = '/'.$arg.'/';
212 #print "Regular expression: $arg\n";
217 # Procedure retrieves shell pattern and converts them into regular expressions
220 my $patterns = shift;
222 while ($arg = shift @ARGV) {
223 $arg =~ /^-/ and unshift(@ARGV, $arg) and return;
228 $arg = &make_reg_exp
($arg);
229 push(@
$patterns, $arg);
234 # Get all options passed
238 &usage
() && exit(0) if ($#ARGV == -1);
239 while ($arg = shift @ARGV) {
240 $arg = &perled_slashes
($arg);
241 #print STDERR "$arg\n";
242 $arg =~ /^-R$/ and $R = 1 and next;
243 $arg =~ /^-r$/ and $r = 1 and next;
244 $arg =~ /^-x$/ and $exclude = 1 and &get_patterns
(\
@exc_patterns) and next;
245 $arg =~ /^-i$/ and $include = 1 and &get_patterns
(\
@inc_patterns) and next;
246 $arg =~ /^-prefix$/ and $prefix = shift @ARGV and next;
247 $arg =~ /^-b$/ and shift @ARGV and next;
248 $arg =~ /^-n$/ and shift @ARGV and next;
249 $arg =~ /^-t$/ and shift @ARGV and next;
250 $arg =~ /^-tt$/ and shift @ARGV and next;
251 $arg =~ /^-h$/ and &usage
and exit(0);
252 $arg =~ /^--help$/ and &usage
and exit(0);
253 $arg =~ /^-?$/ and &usage
and exit(0);
254 if ($arg =~ /^-(\w)(\w+)$/) {
255 unshift (@ARGV, '-'.$1);
256 unshift (@ARGV, '-'.$2);
259 # just ignore other switches...
260 $arg =~ /^-(\w+)$/ and next;
261 $arg =~ /^\/\?$/ and &usage
and exit(0);
262 $zip_file = $arg and next if (!$zip_file);
263 push(@given_patterns, $arg);
265 &print_error
('error: Invalid command arguments (do not specify both -r and -R)') if ($r && $R);
266 if ($r && ($#given_patterns == -1)) {
267 &print_error
('no list specified');
272 # Procedure fills out passed hash with files from passed dir
273 # compliant to the pattern from @$patterns
275 sub get_patterns_files
{
276 my $patterns_array = shift;
277 my $files_hash = shift;
278 my @zip_files = keys %files_in_arch;
279 foreach my $pattern (@
$patterns_array) {
280 my @fit_pattern = grep /$pattern/, @zip_files;
281 foreach my $entry (@fit_pattern) {
282 $$files_hash{$entry}++;
289 # Get dir stuff to pack
291 sub get_dir_content
{
293 my $dir_hash_ref = shift;
295 if (opendir(DIR
, $dir)) {
296 my @prj_dir_list = readdir(DIR
);
298 foreach $entry (@prj_dir_list) {
299 $entry =~ /^\.$/ and next;
300 $entry =~ /^\.\.$/ and next;
302 $entry = $dir . '/' . $entry;
303 # if $enry is a dir - read all its files,
304 # otherwise store $entry itself
306 &get_dir_content
($entry, $dir_hash_ref);
308 $$dir_hash_ref{$entry}++;
317 print STDERR
"\nERROR: $message\n";
322 print STDERR
" zipdep [-aABcdDeEfFghjklLmoqrRSTuvVwXyz] [-b path]\n";
323 print STDERR
" [-n suffixes] [-t mmddyyyy] [-tt mmddyyyy] [ zipfile [\n";
324 print STDERR
" file1 file2 ...]] [-xi list]\n";