3 # Copyright (C) 1995-2005 The Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # Sccs2rcs is a script to convert an existing SCCS
16 # history into an RCS history without losing any of
17 # the information contained therein.
18 # It has been tested under the following OS's:
19 # SunOS 3.5, 4.0.3, 4.1
23 # + It will NOT delete or alter your ./SCCS history under any circumstances.
25 # + Run in a directory where ./SCCS exists and where you can
28 # + /usr/local/bin is put in front of the default path.
29 # (SCCS under Ultrix is set-uid sccs, bad bad bad, so
30 # /usr/local/bin/sccs here fixes that)
32 # + Date, time, author, comments, branches, are all preserved.
34 # + If a command fails somewhere in the middle, it bombs with
35 # a message -- remove what it's done so far and try again.
36 # "rm -rf RCS; sccs unedit `sccs tell`; sccs clean"
37 # There is no recovery and exit is far from graceful.
38 # If a particular module is hanging you up, consider
39 # doing it separately; move it from the current area so that
40 # the next run will have a better chance or working.
41 # Also (for the brave only) you might consider hacking
42 # the s-file for simpler problems: I've successfully changed
43 # the date of a delta to be in sync, then run "sccs admin -z"
46 # + After everything finishes, ./SCCS will be moved to ./old-SCCS.
48 # This file may be copied, processed, hacked, mutilated, and
49 # even destroyed as long as you don't tell anyone you wrote it.
52 # Viewlogic Systems, Inc.
53 # kenstir@viewlogic.com
54 # ...!harvard!cg-atla!viewlog!kenstir
56 # Various hacks made by Brian Berliner before inclusion in CVS contrib area.
58 # Modified to detect SCCS binary files. If binary, skip the keyword
59 # substitution and flag the RCS file as binary (using rcs -i -kb).
60 # -Allan G. Schrum schrum@ofsoptics.com agschrum@mindspring.com
61 # Fri Sep 26 10:40:40 EDT 2003
65 #we'll assume the user set up the path correctly
66 # for the Pmax, /usr/ucb/sccs is suid sccs, what a pain
67 # /usr/local/bin/sccs should override /usr/ucb/sccs there
68 set path = (/usr/local/bin $path)
71 ############################################################
75 echo "Error: ./ not writeable by you."
79 echo "Error: ./SCCS directory not found."
82 set edits = (`sccs tell`)
84 echo "Error: $#edits file(s) out for edit...clean up before converting."
88 echo "Warning: RCS directory exists"
89 if (`ls -a RCS | wc -l` > 2) then
90 echo "Error: RCS directory not empty"
99 set logfile = /tmp/sccs2rcs_$$_log
101 set tmpfile = /tmp/sccs2rcs_$$_tmp
103 set emptyfile = /tmp/sccs2rcs_$$_empty
104 echo -n "" > $emptyfile
105 set initialfile = /tmp/sccs2rcs_$$_init
106 echo "Initial revision" > $initialfile
107 set sedfile = /tmp/sccs2rcs_$$_sed
109 set revfile = /tmp/sccs2rcs_$$_rev
112 # the quotes surround the dollar signs to fool RCS when I check in this script
113 set sccs_keywords = (\
117 '%Z%%M%[ ]*%I%[ ]*%G%'\
118 '%Z%%M%[ ]*%I%[ ]*%E%'\
126 set rcs_keywords = (\
141 ############################################################
142 # Get some answers from user
145 echo "Do you want to be prompted for a description of each"
146 echo "file as it is checked in to RCS initially?"
147 echo -n "(y=prompt for description, n=null description) [y] ?"
149 if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then
155 echo "The default keyword substitutions are as follows and are"
156 echo "applied in the order specified:"
158 while ($i <= $#sccs_keywords)
159 # echo ' '\"$sccs_keywords[$i]\"' ==> '\"$rcs_keywords[$i]\"
160 echo " $sccs_keywords[$i] ==> $rcs_keywords[$i]"
164 echo -n "Do you want to change them [n] ?"
166 if ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then
167 echo "You can't always get what you want."
168 echo "Edit this script file and change the variables:"
169 echo ' $sccs_keywords'
170 echo ' $rcs_keywords'
175 # create the sed script
177 while ($i <= $#sccs_keywords)
178 echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile
184 sort -k 1,1 /dev/null >& /dev/null
185 if ($status == 0) then
186 set sort_each_field = '-k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9'
188 set sort_each_field = '+0 +1 +2 +3 +4 +5 +6 +7 +8'
191 ############################################################
192 # Loop over every s-file in SCCS dir
194 foreach sfile (SCCS/s.*)
195 # get rid of the "s." at the beginning of the name
196 set file = `echo $sfile:t | sed -e "s/^..//"`
198 # work on each rev of that file in ascending order
201 # Only scan the file up to the "I" keyword, then see if
202 # the "f" keyword is set to binary. The SCCS file has
203 # <ctrl>-aI denoting the start of the file (or end of header).
204 set binary = (`sed -e '/^.I/,$d' < $sfile | grep '^.f e 1$'`)
206 # echo This is a binary file
208 # echo This is not a binary file
211 sccs prs $file | grep "^D " | @AWK@ '{print $2}' | sed -e 's/\./ /g' | sort -n -u $sort_each_field | sed -e 's/ /./g' > $revfile
212 foreach rev (`cat $revfile`)
213 if ($status != 0) goto ERROR
215 # get file into current dir and get stats
217 # Is the substr stuff and the +0 in the following awk script really
218 # necessary? It seems to me that if we didn't find the date format
219 # we expected in the output we have other problems.
220 # Note: Solaris awk does not like the following line. Use gawk
221 # mawk, or nawk instead.
222 set date = `sccs prs -r$rev $file | @AWK@ '/^D / {print (substr($3,0,2)+0<70?20:19) $3, $4; exit}'`
223 set author = `sccs prs -r$rev $file | @AWK@ '/^D / {print $5; exit}'`
225 echo "==> file $file, rev=$rev, date=$date, author=$author"
226 sccs edit -r$rev $file >>& $logfile
227 if ($status != 0) goto ERROR
228 echo checked out of SCCS
230 # add RCS keywords in place of SCCS keywords (only if not binary)
231 if ($#binary == 0) then
232 sed -f $sedfile $file > $tmpfile
233 if ($status != 0) goto ERROR
234 echo performed keyword substitutions
238 # check file into RCS
243 echo this is a binary file
244 # Mark initial, empty file as binary
245 rcs -i -kb -t$emptyfile $file
250 echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file
251 ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile
252 if ($status != 0) goto ERROR
253 echo initial rev checked into RCS without description
256 echo Enter a brief description of the file $file \(end w/ Ctrl-D\):
258 ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile
259 if ($status != 0) goto ERROR
260 echo initial rev checked into RCS
264 set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'`
265 if ("$lckrev" =~ [0-9]*.*) then
266 # need to lock the brach -- it is OK if the lock fails
267 rcs -l$lckrev $file >>& $logfile
269 # need to lock the trunk -- must succeed
270 rcs -l $file >>& $logfile
271 if ($status != 0) goto ERROR
274 sccs prs -r$rev $file | grep "." > $tmpfile
275 # it's OK if grep fails here and gives status == 1
276 # put the delta message in $tmpfile
277 ed $tmpfile >>& $logfile <<EOF
283 ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile
284 if ($status != 0) goto ERROR
285 echo checked into RCS
287 sccs unedit $file >>& $logfile
288 if ($status != 0) goto ERROR
294 ############################################################
299 rm -f $tmpfile $emptyfile $initialfile $sedfile
300 echo ===================================================
301 echo " Conversion Completed Successfully"
303 echo " SCCS history now in old-SCCS/"
304 echo ===================================================
309 foreach f (`sccs tell`)
314 echo Danger\! Danger\!
315 echo Some command exited with a non-zero exit status.
316 echo Log file exists in $logfile.
318 echo Incomplete history in ./RCS -- remove it
319 echo Original unchanged history in ./SCCS
324 rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile