merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / zipdep.pl
blob9ea67d86e0fa796c844985d243c22e9a7a187c0c
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: header.hxx,v $
14 # $Revision: 1.1 $
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
38 use Cwd;
40 #### script id #####
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 #########################
52 # #
53 # Globale Variablen #
54 # #
55 #########################
57 $zip_file = '';
58 $R = '';
59 $r = '';
60 $exclude = '';
61 $include = '';
62 @given_patterns = (); # patterns(files) list from command line
63 %files_in_arch = ();
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)
68 $prefix = '';
70 #### main ####
72 &get_options;
73 &get_zip_content;
74 &write_zip_file;
76 #### end of main procedure ####
78 #########################
79 # #
80 # Procedures #
81 # #
82 #########################
85 # procedure writes zipdep file
87 sub write_zip_file {
88 my @dependencies = keys %files_in_arch;
89 if ($#dependencies != -1) {
90 print "\n". &convert_slashes($zip_file) . ' :';
91 foreach (@dependencies) {
92 next if (-d);
93 print " \\\n\t" . $prefix . &convert_slashes($_);
95 print "\n\n";
100 # convert slashes
102 sub convert_slashes {
103 my $path = shift;
104 $path =~ s/\//\$\//g;
105 $path =~ s/\\/\$\//g;
106 return $path;
110 # convert slashes to internal perl representation
112 sub perled_slashes {
113 my $path = shift;
114 $path =~ s/\\/\//g;
115 $path =~ s/\/+/\//g;
116 return $path;
120 # Collect all files to zip in @patterns_array array
122 sub get_zip_content {
123 &get_zip_entries(\@given_patterns);
124 my $file_name = '';
125 foreach $file_name (keys %files_in_arch) {
126 if (-d $file_name) {
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";
140 if ($include) {
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;
155 my @reg_exps = ();
156 my $pattern = '';
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) {
162 next if (-d $file);
163 #print "$file\n";
164 if ($file =~ /[\\ | \/](.+)$/) {
165 $files_in_arch{$file} = $1;
166 } else {
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};
174 #} else {
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 {
186 if ($R) {
187 opendir DIR, '.';
188 my @dir_content = readdir(DIR);
189 close 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";
196 } else {
197 my $patterns_array = shift;
198 my $pattern = '';
199 foreach $pattern (@$patterns_array) {
200 if ((-d $pattern) || (-f $pattern)) {
201 $files_in_arch{$pattern}++;
202 next;
204 my $file_name = '';
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
216 sub make_reg_exp {
217 my $arg = shift;
218 $arg =~ s/\\/\\\\/g;
219 $arg =~ s/\//\\\//g;
220 $arg =~ s/\./\\\./g;
221 $arg =~ s/\+/\\\+/g;
222 $arg =~ s/\{/\\\{/g;
223 $arg =~ s/\}/\\\}/g;
224 $arg =~ s/\*/\.\*/g;
225 $arg =~ s/\?/\./g;
226 #$arg = '/'.$arg.'/';
227 #print "Regular expression: $arg\n";
228 return $arg;
232 # Procedure retrieves shell pattern and converts them into regular expressions
234 sub get_patterns {
235 my $patterns = shift;
236 my $arg = '';
237 while ($arg = shift @ARGV) {
238 $arg =~ /^-/ and unshift(@ARGV, $arg) and return;
239 if (!$zip_file) {
240 $zip_file = $arg;
241 next;
243 $arg = &make_reg_exp($arg);
244 push(@$patterns, $arg);
249 # Get all options passed
251 sub get_options {
252 my ($arg);
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);
272 next;
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}++;
298 #print "$entry\n";
304 # Get dir stuff to pack
306 sub get_dir_content {
307 my $dir = shift;
308 my $dir_hash_ref = shift;
309 my $entry = '';
310 if (opendir(DIR, $dir)) {
311 my @prj_dir_list = readdir(DIR);
312 closedir (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
320 if (-d $entry) {
321 &get_dir_content($entry, $dir_hash_ref);
322 } else {
323 $$dir_hash_ref{$entry}++;
327 return '1';
330 sub print_error {
331 my $message = shift;
332 print STDERR "\nERROR: $message\n";
333 exit (1);
336 sub usage {
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";