2 eval "exec perl -S $0 $*"
3 if $running_under_some_shell;
5 # $Id: patftp.SH 1 2006-08-24 12:32:52Z rmanfredi $
7 # Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
9 # You may redistribute only under the terms of the Artistic Licence,
10 # as specified in the README file that comes with the distribution.
11 # You may reuse parts of this distribution only within the terms of
12 # that same Artistic Licence; a copy of which may be found at the root
13 # of the source tree for dist 4.0.
15 # Original Author: Larry Wall <lwall@netlabs.com>
18 # Revision 3.0.1.3 1994/01/24 14:30:43 ram
19 # patch16: now prefix error messages with program's name
20 # patch16: added ~/.dist_profile awareness
22 # Revision 3.0.1.2 1993/08/24 12:16:57 ram
23 # patch3: removed useless orgname variable
25 # Revision 3.0.1.1 1993/08/19 06:42:36 ram
26 # patch1: leading config.sh searching was not aborting properly
28 # Revision 3.0 1993/08/18 12:10:44 ram
29 # Baseline for dist 3.0 netwide release.
35 $progname = &profile; # Read ~/.dist_profile
37 &usage unless &Getopts("hV");
40 print STDERR "$progname $version PL$patchlevel\n";
46 $RCSEXT = ',v' unless $RCSEXT;
47 chdir '..' if -d '../bugs';
52 open(PL,"patchlevel.h") || die "$progname: can't open patchlevel.h: $!\n";
54 $argv = $1 if /^#define\s+PATCHLEVEL\s+(\d+)/;
57 die "$progname: malformed patchlevel.h file.\n" if $argv eq '';
63 $argv = &rangeargs(@ARGV);
64 @ARGV = split(' ',$argv);
68 print STDERR "$progname: no patches specified.\n";
71 print "$progname: copying $package $baserev patches $argv to $ftpdir...\n";
73 print "$progname: copying $package $baserev patch $argv to $ftpdir...\n";
76 chdir 'bugs' || die "$progname: can't cd to bugs: $!\n";
80 `cp patch$patnum $ftpdir`;
85 Usage: $progname [-hV] patchlist
86 -h : print this message and exit
87 -V : print version number and exit
93 if (! -f '.package') {
96 -f '../../.package' ||
97 -f '../../../.package' ||
98 -f '../../../../.package'
100 die "Run in top level directory only.\n";
102 die "No .package file! Run packinit.\n";
105 open(PACKAGE,'.package');
109 if (($var,$val) = /^\s*(\w+)=(.*)/) {
110 $val = "\"$val\"" unless $val =~ /^['"]/;
111 eval "\$$var = $val;";
120 open(PL,"patchlevel.h") || die "Can't open patchlevel.h\n";
122 $maxspec = $1 if /^#define\s+PATCHLEVEL\s+(\d+)/;
125 die "Malformed patchlevel.h file.\n" if $maxspec eq '';
133 } elsif (s/^-(\d*)//) {
135 if ($max == 0 && $maxspec) {
142 for ($i = $min; $i <= $max; ++$i) {
150 # Perform ~name expansion ala ksh...
151 # (banish csh from your vocabulary ;-)
154 return $path unless $path =~ /^~/;
155 $path =~ s:^~([^/]+):(getpwnam($1))[$[+7]:e; # ~name
156 $path =~ s:^~:$ENV{'HOME'} || (getpwuid($<))[$[+7]:e; # ~
160 # Set up profile components into %Profile, add any profile-supplied options
161 # into @ARGV and return the command invocation name.
163 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
164 local($me) = $0; # Command name
165 $me =~ s|.*/(.*)|$1|; # Keep only base name
166 return $me unless -s $profile;
167 local(*PROFILE); # Local file descriptor
168 local($options) = ''; # Options we get back from profile
169 unless (open(PROFILE, $profile)) {
170 warn "$me: cannot open $profile: $!\n";
176 next if /^\s*#/; # Skip comments
178 if (s/^$me://o) { # progname: options
180 $options .= $_; # Merge options if more than one line
182 elsif (s/^$me-([^:]+)://o) { # progname-component: value
185 s/^\s+//; # Trim leading and trailing spaces
187 $Profile{$component} = $_;
191 return unless $options;
192 require 'shellwords.pl';
194 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
195 unshift(@ARGV, @opts);
196 return $me; # Return our invocation name