2 eval "exec perl -S $0 $*"
3 if $running_under_some_shell;
5 # $Id: patname.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 # $Log: patname.SH,v $
16 # Revision 3.0.1.2 1994/01/24 14:31:02 ram
17 # patch16: now prefix error messages with program's name
18 # patch16: added ~/.dist_profile awareness
20 # Revision 3.0.1.1 1993/08/19 06:42:40 ram
21 # patch1: leading config.sh searching was not aborting properly
23 # Revision 3.0 1993/08/18 12:10:46 ram
24 # Baseline for dist 3.0 netwide release.
30 $progname = &profile; # Read ~/.dist_profile
32 &usage unless $#ARGV >= 0;
33 &usage() unless &Getopts("ahnmv:V");
36 print STDERR "$progname $version PL$patchlevel\n";
42 $RCSEXT = ',v' unless $RCSEXT;
43 $ENV{'DIST'} = '/dev/null'; # Disable ~/.dist_profile
45 chop($pwd = `pwd`) unless -f '.package';
46 until (-f '.package') {
47 die "$progname: no .package file! Run packinit.\n" unless $pwd;
48 chdir '..' || die "$progname: can't cd ..: $!\n";
49 $pwd =~ s|(.*)/(.*)|$1|;
50 $prefix = $2 . '/' . $prefix;
54 s/^/$prefix/ unless m|^[-/]|;
58 # We now are at the top level
63 print STDERR "$progname: version number must be specified using -v.\n";
68 &newer; # Look for files newer than patchlevel.h
70 open(MANI,"MANIFEST.new") || die "$progname: can't read MANIFEST.new: $!\n";
74 next if m|^patchlevel.h|; # This file is built by hand
82 open(MODS,"bugs/.mods$bnum") || die "$progname: no modification found.\n";
85 next if m|^patchlevel.h$|; # This file is built by hand
93 # Now loop over each file specified, doing a 'rcsfreeze'
94 foreach $file (@ARGV) {
95 $files = &rcsargs($file);
96 @files = split(' ', $files);
97 $rlog = `rlog -rlastpat- $files 2>&1`;
98 ($revs) = ($rlog =~ /selected revisions: (\d+)/);
100 print "$progname: $file has never been checked in--checking in...\n";
101 system 'perl', '-S', 'patcil', '-p', $file;
102 $revs = 2; # At least null trunk + new fresh revision
104 # Look whether there is a branch
106 $rlog = `rlog -r$revbranch $files 2>&1`;
107 ($revs) = ($rlog =~ /selected revisions: (\d+)/);
108 $revs++; # add the base revision
110 # If working file exists, make sure latest version was checked in
113 $delta = `rcsdiff -r$baserev $files 2>/dev/null`;
115 $delta = `rcsdiff -r$revbranch $files 2>/dev/null`;
118 # File changed; check it in.
119 system 'perl', '-S', 'patcil', '-p', $file;
121 # Have to re-run rlog after a new ci
122 $rlog = `rlog -r$revbranch $files 2>&1`;
126 # Now assign symbolic revision number
128 system 'rcs', "-N$opt_v:$baserev", @files;
130 ($lastrev) = ($rlog =~ /revision $revbranch\.(\d+)/);
131 system 'rcs', "-N$opt_v:$revbranch.$lastrev", @files;
137 Usage: $progname [-ahnmV] -v version [filelist]
138 -a : all the files in MANIFEST.new
139 -h : print this message and exit
140 -n : all the files newer than patchlevel.h
141 -m : all the modified files (which have been patciled)
142 -v : set version number (mandatory)
143 -V : print version number and exit
149 open(FIND, "find . -type f -newer patchlevel.h -print | sort |") ||
150 die "Can't run find.\n";
151 open(NEWER,">.newer") || die "Can't create .newer.\n";
152 open(MANI,"MANIFEST.new");
154 ($name,$foo) = split;
161 next if m|^MANIFEST|;
162 next if m|^PACKLIST$|;
164 next if m|^MANIFEST.new$|;
165 next if m|^Changes$|;
167 next if m|^.package$|;
173 next if m|^config.sh$|;
174 next if m|/config.sh$|;
175 next if m|^make.out$|;
176 next if m|/make.out$|;
189 next if $mani{$_ . ".SH"};
190 next if m|(.*)\.c$| && $mani{$1 . ".y"};
191 next if m|(.*)\.c$| && $mani{$1 . ".l"};
192 next if (-x $_ && !m|^Configure$|);
198 print "Please remove unwanted files...\n";
200 system '${EDITOR-vi} .newer';
201 die "Aborted.\n" unless -s '.newer' > 1;
202 @ARGV = split(' ',`cat .newer`);
206 if (! -f '.package') {
209 -f '../../.package' ||
210 -f '../../../.package' ||
211 -f '../../../../.package'
213 die "Run in top level directory only.\n";
215 die "No .package file! Run packinit.\n";
218 open(PACKAGE,'.package');
222 if (($var,$val) = /^\s*(\w+)=(.*)/) {
223 $val = "\"$val\"" unless $val =~ /^['"]/;
224 eval "\$$var = $val;";
233 while ($_ = shift(@_)) {
236 } elsif ($#_ >= 0 && do equiv($_,$_[0])) {
237 $result .= $_ . ' ' . $_[0] . ' ';
240 $result .= $_ . ' ' . do other($_) . ' ';
247 local($s1, $s2) = @_;
252 } elsif ($s1 =~ s/$RCSEXT$// || $s2 =~ s/$RCSEXT$//) {
261 ($dir,$file) = ('./',$s1) unless local($dir,$file) = ($s1 =~ m|(.*/)(.*)|);
262 $dir = $TOPDIR . $dir if -d $TOPDIR . "$dir/RCS";
263 local($wasrcs) = ($file =~ s/$RCSEXT$//);
265 `mkdir $dir` unless -d $dir;
269 `mkdir $dir` unless -d $dir;
275 # Perform ~name expansion ala ksh...
276 # (banish csh from your vocabulary ;-)
279 return $path unless $path =~ /^~/;
280 $path =~ s:^~([^/]+):(getpwnam($1))[$[+7]:e; # ~name
281 $path =~ s:^~:$ENV{'HOME'} || (getpwuid($<))[$[+7]:e; # ~
285 # Set up profile components into %Profile, add any profile-supplied options
286 # into @ARGV and return the command invocation name.
288 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
289 local($me) = $0; # Command name
290 $me =~ s|.*/(.*)|$1|; # Keep only base name
291 return $me unless -s $profile;
292 local(*PROFILE); # Local file descriptor
293 local($options) = ''; # Options we get back from profile
294 unless (open(PROFILE, $profile)) {
295 warn "$me: cannot open $profile: $!\n";
301 next if /^\s*#/; # Skip comments
303 if (s/^$me://o) { # progname: options
305 $options .= $_; # Merge options if more than one line
307 elsif (s/^$me-([^:]+)://o) { # progname-component: value
310 s/^\s+//; # Trim leading and trailing spaces
312 $Profile{$component} = $_;
316 return unless $options;
317 require 'shellwords.pl';
319 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
320 unshift(@ARGV, @opts);
321 return $me; # Return our invocation name