2 eval 'exec perl -wS $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: header.hxx,v $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
36 # mapgen - generate a dependencies file for zip commando
42 ( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
44 $id_str = ' $Revision: 1.12 $ ';
45 $id_str =~ /Revision:\s+(\S+)\s+\$/
46 ?
($script_rev = $1) : ($script_rev = "-");
48 print STDERR
"$script_name -- version: $script_rev\n";
49 print STDERR
"Multi Platform Enabled Edition\n";
51 #########################
55 #########################
62 @given_patterns = (); # patterns(files) list from command line
64 @exc_patterns = (); # array of all patterns for files to be excluded
65 @inc_patterns = (); # array of all patterns for files to be included
66 %exc_files_hash = (); # hash of files to be excluded (according to @exc_patterns)
67 %inc_files_hash = (); # hash of files to be included (according to @inc_patterns)
76 #### end of main procedure ####
78 #########################
82 #########################
85 # procedure writes zipdep file
88 my @dependencies = keys %files_in_arch;
89 if ($#dependencies != -1) {
90 print "\n". &convert_slashes
($zip_file) . ' :';
91 foreach (@dependencies) {
93 print " \\\n\t" . $prefix . &convert_slashes
($_);
102 sub convert_slashes
{
104 $path =~ s/\//\
$\
//g;
105 $path =~ s/\\/\$\//g
;
110 # convert slashes to internal perl representation
120 # Collect all files to zip in @patterns_array array
122 sub get_zip_content
{
123 &get_zip_entries
(\
@given_patterns);
125 foreach $file_name (keys %files_in_arch) {
127 &get_dir_content
($file_name, \
%files_in_arch) if ($r || $R);
128 undef $files_in_arch{$file_name};
131 &remove_uncompliant
(\
@given_patterns) if ($R);
132 &get_patterns_files
(\
@exc_patterns, \
%exc_files_hash) if ($exclude);
133 &get_patterns_files
(\
@inc_patterns, \
%inc_files_hash) if ($include);
134 foreach my $file_name (keys %exc_files_hash) {
135 if (defined $files_in_arch{$file_name}) {
136 delete $files_in_arch{$file_name};
137 #print STDERR "excluded $file_name\n";
141 foreach my $file_name (keys %files_in_arch) {
142 if (!(defined $inc_files_hash{$file_name})) {
143 delete $files_in_arch{$file_name};
150 # Procedure removes from %files_in_arch all files which
151 # are not compliant to patterns in @given_patterns
153 sub remove_uncompliant
{
154 my $given_patterns = shift;
157 foreach $pattern (@
$given_patterns) {
158 push(@reg_exps, &make_reg_exp
($pattern));
160 # write file name as a value for the path(key)
161 foreach my $file (keys %files_in_arch) {
164 if ($file =~ /[\\ | \/](.+)$/) {
165 $files_in_arch{$file} = $1;
167 $files_in_arch{$file} = $file;
170 foreach $pattern (@reg_exps) {
171 foreach my $file (keys %files_in_arch) {
172 if (!($files_in_arch{$file} =~ /$pattern/)) {
173 delete $files_in_arch{$file};
175 # print "Complient: $file\n";
182 # Procedure adds/removes to/from %files_in_arch all files, that are
183 # compliant to the patterns in array passed
185 sub get_zip_entries
{
188 my @dir_content = readdir(DIR
);
190 foreach my $file_name(@dir_content) {
191 $file_name =~ /^\.$/ and next;
192 $file_name =~ /^\.\.$/ and next;
193 $files_in_arch{$file_name}++;
194 #print "included $file_name\n";
197 my $patterns_array = shift;
199 foreach $pattern (@
$patterns_array) {
200 if ((-d
$pattern) || (-f
$pattern)) {
201 $files_in_arch{$pattern}++;
205 foreach $file_name (glob $pattern) {
206 #next if (!(-d $file_name) || !(-f $file_name));
207 $files_in_arch{$file_name}++;
214 # Procedure converts given parameter to a regular expression
226 #$arg = '/'.$arg.'/';
227 #print "Regular expression: $arg\n";
232 # Procedure retrieves shell pattern and converts them into regular expressions
235 my $patterns = shift;
237 while ($arg = shift @ARGV) {
238 $arg =~ /^-/ and unshift(@ARGV, $arg) and return;
243 $arg = &make_reg_exp
($arg);
244 push(@
$patterns, $arg);
249 # Get all options passed
253 &usage
() && exit(0) if ($#ARGV == -1);
254 while ($arg = shift @ARGV) {
255 $arg = &perled_slashes
($arg);
256 #print STDERR "$arg\n";
257 $arg =~ /^-R$/ and $R = 1 and next;
258 $arg =~ /^-r$/ and $r = 1 and next;
259 $arg =~ /^-x$/ and $exclude = 1 and &get_patterns
(\
@exc_patterns) and next;
260 $arg =~ /^-i$/ and $include = 1 and &get_patterns
(\
@inc_patterns) and next;
261 $arg =~ /^-prefix$/ and $prefix = shift @ARGV and next;
262 $arg =~ /^-b$/ and shift @ARGV and next;
263 $arg =~ /^-n$/ and shift @ARGV and next;
264 $arg =~ /^-t$/ and shift @ARGV and next;
265 $arg =~ /^-tt$/ and shift @ARGV and next;
266 $arg =~ /^-h$/ and &usage
and exit(0);
267 $arg =~ /^--help$/ and &usage
and exit(0);
268 $arg =~ /^-?$/ and &usage
and exit(0);
269 if ($arg =~ /^-(\w)(\w+)$/) {
270 unshift (@ARGV, '-'.$1);
271 unshift (@ARGV, '-'.$2);
274 # just ignore other switches...
275 $arg =~ /^-(\w+)$/ and next;
276 $arg =~ /^\/\?$/ and &usage
and exit(0);
277 $zip_file = $arg and next if (!$zip_file);
278 push(@given_patterns, $arg);
280 &print_error
('error: Invalid command arguments (do not specify both -r and -R)') if ($r && $R);
281 if ($r && ($#given_patterns == -1)) {
282 &print_error
('no list specified');
287 # Procedure fills out passed hash with files from passed dir
288 # compliant to the pattern from @$patterns
290 sub get_patterns_files
{
291 my $patterns_array = shift;
292 my $files_hash = shift;
293 my @zip_files = keys %files_in_arch;
294 foreach my $pattern (@
$patterns_array) {
295 my @fit_pattern = grep /$pattern/, @zip_files;
296 foreach my $entry (@fit_pattern) {
297 $$files_hash{$entry}++;
304 # Get dir stuff to pack
306 sub get_dir_content
{
308 my $dir_hash_ref = shift;
310 if (opendir(DIR
, $dir)) {
311 my @prj_dir_list = readdir(DIR
);
313 foreach $entry (@prj_dir_list) {
314 $entry =~ /^\.$/ and next;
315 $entry =~ /^\.\.$/ and next;
317 $entry = $dir . '/' . $entry;
318 # if $enry is a dir - read all its files,
319 # otherwise store $entry itself
321 &get_dir_content
($entry, $dir_hash_ref);
323 $$dir_hash_ref{$entry}++;
332 print STDERR
"\nERROR: $message\n";
337 print STDERR
" zipdep [-aABcdDeEfFghjklLmoqrRSTuvVwXyz] [-b path]\n";
338 print STDERR
" [-n suffixes] [-t mmddyyyy] [-tt mmddyyyy] [ zipfile [\n";
339 print STDERR
" file1 file2 ...]] [-xi list]\n";