xref: /openbsd-src/gnu/usr.bin/cvs/contrib/sccs2rcs.in (revision 43c1707e6f6829177cb1974ee6615ce6c1307689)
1*43c1707eStholo#! @CSH@ -f
2*43c1707eStholo#
3*43c1707eStholo# Sccs2rcs is a script to convert an existing SCCS
4*43c1707eStholo# history into an RCS history without losing any of
5*43c1707eStholo# the information contained therein.
6*43c1707eStholo# It has been tested under the following OS's:
7*43c1707eStholo#     SunOS 3.5, 4.0.3, 4.1
8*43c1707eStholo#     Ultrix-32 2.0, 3.1
9*43c1707eStholo#
10*43c1707eStholo# Things to note:
11*43c1707eStholo#   + It will NOT delete or alter your ./SCCS history under any circumstances.
12*43c1707eStholo#
13*43c1707eStholo#   + Run in a directory where ./SCCS exists and where you can
14*43c1707eStholo#       create ./RCS
15*43c1707eStholo#
16*43c1707eStholo#   + /usr/local/bin is put in front of the default path.
17*43c1707eStholo#     (SCCS under Ultrix is set-uid sccs, bad bad bad, so
18*43c1707eStholo#     /usr/local/bin/sccs here fixes that)
19*43c1707eStholo#
20*43c1707eStholo#   + Date, time, author, comments, branches, are all preserved.
21*43c1707eStholo#
22*43c1707eStholo#   + If a command fails somewhere in the middle, it bombs with
23*43c1707eStholo#     a message -- remove what it's done so far and try again.
24*43c1707eStholo#         "rm -rf RCS; sccs unedit `sccs tell`; sccs clean"
25*43c1707eStholo#     There is no recovery and exit is far from graceful.
26*43c1707eStholo#     If a particular module is hanging you up, consider
27*43c1707eStholo#     doing it separately; move it from the current area so that
28*43c1707eStholo#     the next run will have a better chance or working.
29*43c1707eStholo#     Also (for the brave only) you might consider hacking
30*43c1707eStholo#     the s-file for simpler problems:  I've successfully changed
31*43c1707eStholo#     the date of a delta to be in sync, then run "sccs admin -z"
32*43c1707eStholo#     on the thing.
33*43c1707eStholo#
34*43c1707eStholo#   + After everything finishes, ./SCCS will be moved to ./old-SCCS.
35*43c1707eStholo#
36*43c1707eStholo# This file may be copied, processed, hacked, mutilated, and
37*43c1707eStholo# even destroyed as long as you don't tell anyone you wrote it.
38*43c1707eStholo#
39*43c1707eStholo# Ken Cox
40*43c1707eStholo# Viewlogic Systems, Inc.
41*43c1707eStholo# kenstir@viewlogic.com
42*43c1707eStholo# ...!harvard!cg-atla!viewlog!kenstir
43*43c1707eStholo#
44*43c1707eStholo# Various hacks made by Brian Berliner before inclusion in CVS contrib area.
45*43c1707eStholo
46*43c1707eStholo
47*43c1707eStholo#we'll assume the user set up the path correctly
48*43c1707eStholo# for the Pmax, /usr/ucb/sccs is suid sccs, what a pain
49*43c1707eStholo#   /usr/local/bin/sccs should override /usr/ucb/sccs there
50*43c1707eStholoset path = (/usr/local/bin $path)
51*43c1707eStholo
52*43c1707eStholo
53*43c1707eStholo############################################################
54*43c1707eStholo# Error checking
55*43c1707eStholo#
56*43c1707eStholoif (! -w .) then
57*43c1707eStholo    echo "Error: ./ not writeable by you."
58*43c1707eStholo    exit 1
59*43c1707eStholoendif
60*43c1707eStholoif (! -d SCCS) then
61*43c1707eStholo    echo "Error: ./SCCS directory not found."
62*43c1707eStholo    exit 1
63*43c1707eStholoendif
64*43c1707eStholoset edits = (`sccs tell`)
65*43c1707eStholoif ($#edits) then
66*43c1707eStholo    echo "Error: $#edits file(s) out for edit...clean up before converting."
67*43c1707eStholo    exit 1
68*43c1707eStholoendif
69*43c1707eStholoif (-d RCS) then
70*43c1707eStholo    echo "Warning: RCS directory exists"
71*43c1707eStholo    if (`ls -a RCS | wc -l` > 2) then
72*43c1707eStholo        echo "Error: RCS directory not empty
73*43c1707eStholo        exit 1
74*43c1707eStholo    endif
75*43c1707eStholoelse
76*43c1707eStholo    mkdir RCS
77*43c1707eStholoendif
78*43c1707eStholo
79*43c1707eStholosccs clean
80*43c1707eStholo
81*43c1707eStholoset logfile = /tmp/sccs2rcs_$$_log
82*43c1707eStholorm -f $logfile
83*43c1707eStholoset tmpfile = /tmp/sccs2rcs_$$_tmp
84*43c1707eStholorm -f $tmpfile
85*43c1707eStholoset emptyfile = /tmp/sccs2rcs_$$_empty
86*43c1707eStholoecho -n "" > $emptyfile
87*43c1707eStholoset initialfile = /tmp/sccs2rcs_$$_init
88*43c1707eStholoecho "Initial revision" > $initialfile
89*43c1707eStholoset sedfile = /tmp/sccs2rcs_$$_sed
90*43c1707eStholorm -f $sedfile
91*43c1707eStholoset revfile = /tmp/sccs2rcs_$$_rev
92*43c1707eStholorm -f $revfile
93*43c1707eStholo
94*43c1707eStholo# the quotes surround the dollar signs to fool RCS when I check in this script
95*43c1707eStholoset sccs_keywords = (\
96*43c1707eStholo    '%W%[ 	]*%G%'\
97*43c1707eStholo    '%W%[ 	]*%E%'\
98*43c1707eStholo    '%W%'\
99*43c1707eStholo    '%Z%%M%[ 	]*%I%[ 	]*%G%'\
100*43c1707eStholo    '%Z%%M%[ 	]*%I%[ 	]*%E%'\
101*43c1707eStholo    '%M%[ 	]*%I%[ 	]*%G%'\
102*43c1707eStholo    '%M%[ 	]*%I%[ 	]*%E%'\
103*43c1707eStholo    '%M%'\
104*43c1707eStholo    '%I%'\
105*43c1707eStholo    '%G%'\
106*43c1707eStholo    '%E%'\
107*43c1707eStholo    '%U%')
108*43c1707eStholoset rcs_keywords = (\
109*43c1707eStholo    '$'Id'$'\
110*43c1707eStholo    '$'Id'$'\
111*43c1707eStholo    '$'Id'$'\
112*43c1707eStholo    '$'SunId'$'\
113*43c1707eStholo    '$'SunId'$'\
114*43c1707eStholo    '$'Id'$'\
115*43c1707eStholo    '$'Id'$'\
116*43c1707eStholo    '$'RCSfile'$'\
117*43c1707eStholo    '$'Revision'$'\
118*43c1707eStholo    '$'Date'$'\
119*43c1707eStholo    '$'Date'$'\
120*43c1707eStholo    '')
121*43c1707eStholo
122*43c1707eStholo
123*43c1707eStholo############################################################
124*43c1707eStholo# Get some answers from user
125*43c1707eStholo#
126*43c1707eStholoecho ""
127*43c1707eStholoecho "Do you want to be prompted for a description of each"
128*43c1707eStholoecho "file as it is checked in to RCS initially?"
129*43c1707eStholoecho -n "(y=prompt for description, n=null description) [y] ?"
130*43c1707eStholoset ans = $<
131*43c1707eStholoif ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then
132*43c1707eStholo    set nodesc = 0
133*43c1707eStholoelse
134*43c1707eStholo    set nodesc = 1
135*43c1707eStholoendif
136*43c1707eStholoecho ""
137*43c1707eStholoecho "The default keyword substitutions are as follows and are"
138*43c1707eStholoecho "applied in the order specified:"
139*43c1707eStholoset i = 1
140*43c1707eStholowhile ($i <= $#sccs_keywords)
141*43c1707eStholo#    echo '	'\"$sccs_keywords[$i]\"'	==>	'\"$rcs_keywords[$i]\"
142*43c1707eStholo    echo "	$sccs_keywords[$i]	==>	$rcs_keywords[$i]"
143*43c1707eStholo    @ i = $i + 1
144*43c1707eStholoend
145*43c1707eStholoecho ""
146*43c1707eStholoecho -n "Do you want to change them [n] ?"
147*43c1707eStholoset ans = $<
148*43c1707eStholoif ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then
149*43c1707eStholo    echo "You can't always get what you want."
150*43c1707eStholo    echo "Edit this script file and change the variables:"
151*43c1707eStholo    echo '    $sccs_keywords'
152*43c1707eStholo    echo '    $rcs_keywords'
153*43c1707eStholoelse
154*43c1707eStholo    echo "good idea."
155*43c1707eStholoendif
156*43c1707eStholo
157*43c1707eStholo# create the sed script
158*43c1707eStholoset i = 1
159*43c1707eStholowhile ($i <= $#sccs_keywords)
160*43c1707eStholo    echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile
161*43c1707eStholo    @ i = $i + 1
162*43c1707eStholoend
163*43c1707eStholo
164*43c1707eStholoonintr ERROR
165*43c1707eStholo
166*43c1707eStholo############################################################
167*43c1707eStholo# Loop over every s-file in SCCS dir
168*43c1707eStholo#
169*43c1707eStholoforeach sfile (SCCS/s.*)
170*43c1707eStholo    # get rid of the "s." at the beginning of the name
171*43c1707eStholo    set file = `echo $sfile:t | sed -e "s/^..//"`
172*43c1707eStholo
173*43c1707eStholo    # work on each rev of that file in ascending order
174*43c1707eStholo    set firsttime = 1
175*43c1707eStholo    sccs prs $file | grep "^D " | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile
176*43c1707eStholo    foreach rev (`cat $revfile`)
177*43c1707eStholo        if ($status != 0) goto ERROR
178*43c1707eStholo
179*43c1707eStholo        # get file into current dir and get stats
180*43c1707eStholo	set year = `echo $date | cut -c3-4`
181*43c1707eStholo	if ($year < 70) then
182*43c1707eStholo		# Y2K Bug, change century to 20
183*43c1707eStholo		set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("20%s %s", $3, $4); exit}'`
184*43c1707eStholo	else
185*43c1707eStholo		set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("19%s %s", $3, $4); exit}'`
186*43c1707eStholo	endif
187*43c1707eStholo        set author = `sccs prs -r$rev $file | grep "^D " | awk '{print $5; exit}'`
188*43c1707eStholo        echo ""
189*43c1707eStholo        echo "==> file $file, rev=$rev, date=$date, author=$author"
190*43c1707eStholo        sccs edit -r$rev $file >>& $logfile
191*43c1707eStholo        if ($status != 0) goto ERROR
192*43c1707eStholo        echo checked out of SCCS
193*43c1707eStholo
194*43c1707eStholo        # add RCS keywords in place of SCCS keywords
195*43c1707eStholo        sed -f $sedfile $file > $tmpfile
196*43c1707eStholo        if ($status != 0) goto ERROR
197*43c1707eStholo        echo performed keyword substitutions
198*43c1707eStholo        cp $tmpfile $file
199*43c1707eStholo
200*43c1707eStholo        # check file into RCS
201*43c1707eStholo        if ($firsttime) then
202*43c1707eStholo            set firsttime = 0
203*43c1707eStholo            if ($nodesc) then
204*43c1707eStholo		echo about to do ci
205*43c1707eStholo                echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file
206*43c1707eStholo                ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile
207*43c1707eStholo                if ($status != 0) goto ERROR
208*43c1707eStholo                echo initial rev checked into RCS without description
209*43c1707eStholo            else
210*43c1707eStholo                echo ""
211*43c1707eStholo                echo Enter a brief description of the file $file \(end w/ Ctrl-D\):
212*43c1707eStholo                cat > $tmpfile
213*43c1707eStholo                ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile
214*43c1707eStholo                if ($status != 0) goto ERROR
215*43c1707eStholo                echo initial rev checked into RCS
216*43c1707eStholo            endif
217*43c1707eStholo        else
218*43c1707eStholo            # get RCS lock
219*43c1707eStholo	    set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'`
220*43c1707eStholo	    if ("$lckrev" =~ [0-9]*.*) then
221*43c1707eStholo		# need to lock the brach -- it is OK if the lock fails
222*43c1707eStholo		rcs -l$lckrev $file >>& $logfile
223*43c1707eStholo	    else
224*43c1707eStholo		# need to lock the trunk -- must succeed
225*43c1707eStholo                rcs -l $file >>& $logfile
226*43c1707eStholo                if ($status != 0) goto ERROR
227*43c1707eStholo	    endif
228*43c1707eStholo            echo got lock
229*43c1707eStholo            sccs prs -r$rev $file | grep "." > $tmpfile
230*43c1707eStholo            # it's OK if grep fails here and gives status == 1
231*43c1707eStholo            # put the delta message in $tmpfile
232*43c1707eStholo            ed $tmpfile >>& $logfile <<EOF
233*43c1707eStholo/COMMENTS
234*43c1707eStholo1,.d
235*43c1707eStholow
236*43c1707eStholoq
237*43c1707eStholoEOF
238*43c1707eStholo            ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile
239*43c1707eStholo            if ($status != 0) goto ERROR
240*43c1707eStholo            echo checked into RCS
241*43c1707eStholo        endif
242*43c1707eStholo        sccs unedit $file >>& $logfile
243*43c1707eStholo        if ($status != 0) goto ERROR
244*43c1707eStholo    end
245*43c1707eStholo    rm -f $file
246*43c1707eStholoend
247*43c1707eStholo
248*43c1707eStholo
249*43c1707eStholo############################################################
250*43c1707eStholo# Clean up
251*43c1707eStholo#
252*43c1707eStholoecho cleaning up...
253*43c1707eStholomv SCCS old-SCCS
254*43c1707eStholorm -f $tmpfile $emptyfile $initialfile $sedfile
255*43c1707eStholoecho ===================================================
256*43c1707eStholoecho "       Conversion Completed Successfully"
257*43c1707eStholoecho ""
258*43c1707eStholoecho "         SCCS history now in old-SCCS/"
259*43c1707eStholoecho ===================================================
260*43c1707eStholoset exitval = 0
261*43c1707eSthologoto cleanup
262*43c1707eStholo
263*43c1707eStholoERROR:
264*43c1707eStholoforeach f (`sccs tell`)
265*43c1707eStholo    sccs unedit $f
266*43c1707eStholoend
267*43c1707eStholoecho ""
268*43c1707eStholoecho ""
269*43c1707eStholoecho Danger\!  Danger\!
270*43c1707eStholoecho Some command exited with a non-zero exit status.
271*43c1707eStholoecho Log file exists in $logfile.
272*43c1707eStholoecho ""
273*43c1707eStholoecho Incomplete history in ./RCS -- remove it
274*43c1707eStholoecho Original unchanged history in ./SCCS
275*43c1707eStholoset exitval = 1
276*43c1707eStholo
277*43c1707eStholocleanup:
278*43c1707eStholo# leave log file
279*43c1707eStholorm -f $tmpfile $emptyfile $initialfile $sedfile $revfile
280*43c1707eStholo
281*43c1707eStholoexit $exitval
282