186d7f5d3SJohn Marino#! @CSH@ -f 286d7f5d3SJohn Marino 386d7f5d3SJohn Marino# Copyright (C) 1995-2005 The Free Software Foundation, Inc. 486d7f5d3SJohn Marino 586d7f5d3SJohn Marino# This program is free software; you can redistribute it and/or modify 686d7f5d3SJohn Marino# it under the terms of the GNU General Public License as published by 786d7f5d3SJohn Marino# the Free Software Foundation; either version 2, or (at your option) 886d7f5d3SJohn Marino# any later version. 986d7f5d3SJohn Marino# 1086d7f5d3SJohn Marino# This program is distributed in the hope that it will be useful, 1186d7f5d3SJohn Marino# but WITHOUT ANY WARRANTY; without even the implied warranty of 1286d7f5d3SJohn Marino# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1386d7f5d3SJohn Marino# GNU General Public License for more details. 1486d7f5d3SJohn Marino# 1586d7f5d3SJohn Marino# Sccs2rcs is a script to convert an existing SCCS 1686d7f5d3SJohn Marino# history into an RCS history without losing any of 1786d7f5d3SJohn Marino# the information contained therein. 1886d7f5d3SJohn Marino# It has been tested under the following OS's: 1986d7f5d3SJohn Marino# SunOS 3.5, 4.0.3, 4.1 2086d7f5d3SJohn Marino# Ultrix-32 2.0, 3.1 2186d7f5d3SJohn Marino# 2286d7f5d3SJohn Marino# Things to note: 2386d7f5d3SJohn Marino# + It will NOT delete or alter your ./SCCS history under any circumstances. 2486d7f5d3SJohn Marino# 2586d7f5d3SJohn Marino# + Run in a directory where ./SCCS exists and where you can 2686d7f5d3SJohn Marino# create ./RCS 2786d7f5d3SJohn Marino# 2886d7f5d3SJohn Marino# + /usr/local/bin is put in front of the default path. 2986d7f5d3SJohn Marino# (SCCS under Ultrix is set-uid sccs, bad bad bad, so 3086d7f5d3SJohn Marino# /usr/local/bin/sccs here fixes that) 3186d7f5d3SJohn Marino# 3286d7f5d3SJohn Marino# + Date, time, author, comments, branches, are all preserved. 3386d7f5d3SJohn Marino# 3486d7f5d3SJohn Marino# + If a command fails somewhere in the middle, it bombs with 3586d7f5d3SJohn Marino# a message -- remove what it's done so far and try again. 3686d7f5d3SJohn Marino# "rm -rf RCS; sccs unedit `sccs tell`; sccs clean" 3786d7f5d3SJohn Marino# There is no recovery and exit is far from graceful. 3886d7f5d3SJohn Marino# If a particular module is hanging you up, consider 3986d7f5d3SJohn Marino# doing it separately; move it from the current area so that 4086d7f5d3SJohn Marino# the next run will have a better chance or working. 4186d7f5d3SJohn Marino# Also (for the brave only) you might consider hacking 4286d7f5d3SJohn Marino# the s-file for simpler problems: I've successfully changed 4386d7f5d3SJohn Marino# the date of a delta to be in sync, then run "sccs admin -z" 4486d7f5d3SJohn Marino# on the thing. 4586d7f5d3SJohn Marino# 4686d7f5d3SJohn Marino# + After everything finishes, ./SCCS will be moved to ./old-SCCS. 4786d7f5d3SJohn Marino# 4886d7f5d3SJohn Marino# This file may be copied, processed, hacked, mutilated, and 4986d7f5d3SJohn Marino# even destroyed as long as you don't tell anyone you wrote it. 5086d7f5d3SJohn Marino# 5186d7f5d3SJohn Marino# Ken Cox 5286d7f5d3SJohn Marino# Viewlogic Systems, Inc. 5386d7f5d3SJohn Marino# kenstir@viewlogic.com 5486d7f5d3SJohn Marino# ...!harvard!cg-atla!viewlog!kenstir 5586d7f5d3SJohn Marino# 5686d7f5d3SJohn Marino# Various hacks made by Brian Berliner before inclusion in CVS contrib area. 5786d7f5d3SJohn Marino# 5886d7f5d3SJohn Marino# Modified to detect SCCS binary files. If binary, skip the keyword 5986d7f5d3SJohn Marino# substitution and flag the RCS file as binary (using rcs -i -kb). 6086d7f5d3SJohn Marino# -Allan G. Schrum schrum@ofsoptics.com agschrum@mindspring.com 6186d7f5d3SJohn Marino# Fri Sep 26 10:40:40 EDT 2003 6286d7f5d3SJohn Marino# 6386d7f5d3SJohn Marino 6486d7f5d3SJohn Marino 6586d7f5d3SJohn Marino#we'll assume the user set up the path correctly 6686d7f5d3SJohn Marino# for the Pmax, /usr/ucb/sccs is suid sccs, what a pain 6786d7f5d3SJohn Marino# /usr/local/bin/sccs should override /usr/ucb/sccs there 6886d7f5d3SJohn Marinoset path = (/usr/local/bin $path) 6986d7f5d3SJohn Marino 7086d7f5d3SJohn Marino 7186d7f5d3SJohn Marino############################################################ 7286d7f5d3SJohn Marino# Error checking 7386d7f5d3SJohn Marino# 7486d7f5d3SJohn Marinoif (! -w .) then 7586d7f5d3SJohn Marino echo "Error: ./ not writeable by you." 7686d7f5d3SJohn Marino exit 1 7786d7f5d3SJohn Marinoendif 7886d7f5d3SJohn Marinoif (! -d SCCS) then 7986d7f5d3SJohn Marino echo "Error: ./SCCS directory not found." 8086d7f5d3SJohn Marino exit 1 8186d7f5d3SJohn Marinoendif 8286d7f5d3SJohn Marinoset edits = (`sccs tell`) 8386d7f5d3SJohn Marinoif ($#edits) then 8486d7f5d3SJohn Marino echo "Error: $#edits file(s) out for edit...clean up before converting." 8586d7f5d3SJohn Marino exit 1 8686d7f5d3SJohn Marinoendif 8786d7f5d3SJohn Marinoif (-d RCS) then 8886d7f5d3SJohn Marino echo "Warning: RCS directory exists" 8986d7f5d3SJohn Marino if (`ls -a RCS | wc -l` > 2) then 9086d7f5d3SJohn Marino echo "Error: RCS directory not empty" 9186d7f5d3SJohn Marino exit 1 9286d7f5d3SJohn Marino endif 9386d7f5d3SJohn Marinoelse 9486d7f5d3SJohn Marino mkdir RCS 9586d7f5d3SJohn Marinoendif 9686d7f5d3SJohn Marino 9786d7f5d3SJohn Marinosccs clean 9886d7f5d3SJohn Marino 9986d7f5d3SJohn Marinoset logfile = /tmp/sccs2rcs_$$_log 10086d7f5d3SJohn Marinorm -f $logfile 10186d7f5d3SJohn Marinoset tmpfile = /tmp/sccs2rcs_$$_tmp 10286d7f5d3SJohn Marinorm -f $tmpfile 10386d7f5d3SJohn Marinoset emptyfile = /tmp/sccs2rcs_$$_empty 10486d7f5d3SJohn Marinoecho -n "" > $emptyfile 10586d7f5d3SJohn Marinoset initialfile = /tmp/sccs2rcs_$$_init 10686d7f5d3SJohn Marinoecho "Initial revision" > $initialfile 10786d7f5d3SJohn Marinoset sedfile = /tmp/sccs2rcs_$$_sed 10886d7f5d3SJohn Marinorm -f $sedfile 10986d7f5d3SJohn Marinoset revfile = /tmp/sccs2rcs_$$_rev 11086d7f5d3SJohn Marinorm -f $revfile 11186d7f5d3SJohn Marino 11286d7f5d3SJohn Marino# the quotes surround the dollar signs to fool RCS when I check in this script 11386d7f5d3SJohn Marinoset sccs_keywords = (\ 11486d7f5d3SJohn Marino '%W%[ ]*%G%'\ 11586d7f5d3SJohn Marino '%W%[ ]*%E%'\ 11686d7f5d3SJohn Marino '%W%'\ 11786d7f5d3SJohn Marino '%Z%%M%[ ]*%I%[ ]*%G%'\ 11886d7f5d3SJohn Marino '%Z%%M%[ ]*%I%[ ]*%E%'\ 11986d7f5d3SJohn Marino '%M%[ ]*%I%[ ]*%G%'\ 12086d7f5d3SJohn Marino '%M%[ ]*%I%[ ]*%E%'\ 12186d7f5d3SJohn Marino '%M%'\ 12286d7f5d3SJohn Marino '%I%'\ 12386d7f5d3SJohn Marino '%G%'\ 12486d7f5d3SJohn Marino '%E%'\ 12586d7f5d3SJohn Marino '%U%') 12686d7f5d3SJohn Marinoset rcs_keywords = (\ 12786d7f5d3SJohn Marino '$'Id'$'\ 12886d7f5d3SJohn Marino '$'Id'$'\ 12986d7f5d3SJohn Marino '$'Id'$'\ 13086d7f5d3SJohn Marino '$'SunId'$'\ 13186d7f5d3SJohn Marino '$'SunId'$'\ 13286d7f5d3SJohn Marino '$'Id'$'\ 13386d7f5d3SJohn Marino '$'Id'$'\ 13486d7f5d3SJohn Marino '$'RCSfile'$'\ 13586d7f5d3SJohn Marino '$'Revision'$'\ 13686d7f5d3SJohn Marino '$'Date'$'\ 13786d7f5d3SJohn Marino '$'Date'$'\ 13886d7f5d3SJohn Marino '') 13986d7f5d3SJohn Marino 14086d7f5d3SJohn Marino 14186d7f5d3SJohn Marino############################################################ 14286d7f5d3SJohn Marino# Get some answers from user 14386d7f5d3SJohn Marino# 14486d7f5d3SJohn Marinoecho "" 14586d7f5d3SJohn Marinoecho "Do you want to be prompted for a description of each" 14686d7f5d3SJohn Marinoecho "file as it is checked in to RCS initially?" 14786d7f5d3SJohn Marinoecho -n "(y=prompt for description, n=null description) [y] ?" 14886d7f5d3SJohn Marinoset ans = $< 14986d7f5d3SJohn Marinoif ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then 15086d7f5d3SJohn Marino set nodesc = 0 15186d7f5d3SJohn Marinoelse 15286d7f5d3SJohn Marino set nodesc = 1 15386d7f5d3SJohn Marinoendif 15486d7f5d3SJohn Marinoecho "" 15586d7f5d3SJohn Marinoecho "The default keyword substitutions are as follows and are" 15686d7f5d3SJohn Marinoecho "applied in the order specified:" 15786d7f5d3SJohn Marinoset i = 1 15886d7f5d3SJohn Marinowhile ($i <= $#sccs_keywords) 15986d7f5d3SJohn Marino# echo ' '\"$sccs_keywords[$i]\"' ==> '\"$rcs_keywords[$i]\" 16086d7f5d3SJohn Marino echo " $sccs_keywords[$i] ==> $rcs_keywords[$i]" 16186d7f5d3SJohn Marino @ i = $i + 1 16286d7f5d3SJohn Marinoend 16386d7f5d3SJohn Marinoecho "" 16486d7f5d3SJohn Marinoecho -n "Do you want to change them [n] ?" 16586d7f5d3SJohn Marinoset ans = $< 16686d7f5d3SJohn Marinoif ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then 16786d7f5d3SJohn Marino echo "You can't always get what you want." 16886d7f5d3SJohn Marino echo "Edit this script file and change the variables:" 16986d7f5d3SJohn Marino echo ' $sccs_keywords' 17086d7f5d3SJohn Marino echo ' $rcs_keywords' 17186d7f5d3SJohn Marinoelse 17286d7f5d3SJohn Marino echo "good idea." 17386d7f5d3SJohn Marinoendif 17486d7f5d3SJohn Marino 17586d7f5d3SJohn Marino# create the sed script 17686d7f5d3SJohn Marinoset i = 1 17786d7f5d3SJohn Marinowhile ($i <= $#sccs_keywords) 17886d7f5d3SJohn Marino echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile 17986d7f5d3SJohn Marino @ i = $i + 1 18086d7f5d3SJohn Marinoend 18186d7f5d3SJohn Marino 18286d7f5d3SJohn Marinoonintr ERROR 18386d7f5d3SJohn Marino 18486d7f5d3SJohn Marinosort -k 1,1 /dev/null >& /dev/null 18586d7f5d3SJohn Marinoif ($status == 0) then 18686d7f5d3SJohn Marino set sort_each_field = '-k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9' 18786d7f5d3SJohn Marinoelse 18886d7f5d3SJohn Marino set sort_each_field = '+0 +1 +2 +3 +4 +5 +6 +7 +8' 18986d7f5d3SJohn Marinoendif 19086d7f5d3SJohn Marino 19186d7f5d3SJohn Marino############################################################ 19286d7f5d3SJohn Marino# Loop over every s-file in SCCS dir 19386d7f5d3SJohn Marino# 19486d7f5d3SJohn Marinoforeach sfile (SCCS/s.*) 19586d7f5d3SJohn Marino # get rid of the "s." at the beginning of the name 19686d7f5d3SJohn Marino set file = `echo $sfile:t | sed -e "s/^..//"` 19786d7f5d3SJohn Marino 19886d7f5d3SJohn Marino # work on each rev of that file in ascending order 19986d7f5d3SJohn Marino set firsttime = 1 20086d7f5d3SJohn Marino 20186d7f5d3SJohn Marino # Only scan the file up to the "I" keyword, then see if 20286d7f5d3SJohn Marino # the "f" keyword is set to binary. The SCCS file has 20386d7f5d3SJohn Marino # <ctrl>-aI denoting the start of the file (or end of header). 20486d7f5d3SJohn Marino set binary = (`sed -e '/^.I/,$d' < $sfile | grep '^.f e 1$'`) 20586d7f5d3SJohn Marino #if ($#binary) then 20686d7f5d3SJohn Marino # echo This is a binary file 20786d7f5d3SJohn Marino #else 20886d7f5d3SJohn Marino # echo This is not a binary file 20986d7f5d3SJohn Marino #endif 21086d7f5d3SJohn Marino 21186d7f5d3SJohn Marino sccs prs $file | grep "^D " | @AWK@ '{print $2}' | sed -e 's/\./ /g' | sort -n -u $sort_each_field | sed -e 's/ /./g' > $revfile 21286d7f5d3SJohn Marino foreach rev (`cat $revfile`) 21386d7f5d3SJohn Marino if ($status != 0) goto ERROR 21486d7f5d3SJohn Marino 21586d7f5d3SJohn Marino # get file into current dir and get stats 21686d7f5d3SJohn Marino 21786d7f5d3SJohn Marino # Is the substr stuff and the +0 in the following awk script really 21886d7f5d3SJohn Marino # necessary? It seems to me that if we didn't find the date format 21986d7f5d3SJohn Marino # we expected in the output we have other problems. 22086d7f5d3SJohn Marino # Note: Solaris awk does not like the following line. Use gawk 22186d7f5d3SJohn Marino # mawk, or nawk instead. 22286d7f5d3SJohn Marino set date = `sccs prs -r$rev $file | @AWK@ '/^D / {print (substr($3,0,2)+0<70?20:19) $3, $4; exit}'` 22386d7f5d3SJohn Marino set author = `sccs prs -r$rev $file | @AWK@ '/^D / {print $5; exit}'` 22486d7f5d3SJohn Marino echo "" 22586d7f5d3SJohn Marino echo "==> file $file, rev=$rev, date=$date, author=$author" 22686d7f5d3SJohn Marino sccs edit -r$rev $file >>& $logfile 22786d7f5d3SJohn Marino if ($status != 0) goto ERROR 22886d7f5d3SJohn Marino echo checked out of SCCS 22986d7f5d3SJohn Marino 23086d7f5d3SJohn Marino # add RCS keywords in place of SCCS keywords (only if not binary) 23186d7f5d3SJohn Marino if ($#binary == 0) then 23286d7f5d3SJohn Marino sed -f $sedfile $file > $tmpfile 23386d7f5d3SJohn Marino if ($status != 0) goto ERROR 23486d7f5d3SJohn Marino echo performed keyword substitutions 23586d7f5d3SJohn Marino cp $tmpfile $file 23686d7f5d3SJohn Marino endif 23786d7f5d3SJohn Marino 23886d7f5d3SJohn Marino # check file into RCS 23986d7f5d3SJohn Marino if ($firsttime) then 24086d7f5d3SJohn Marino set firsttime = 0 24186d7f5d3SJohn Marino 24286d7f5d3SJohn Marino if ($#binary) then 24386d7f5d3SJohn Marino echo this is a binary file 24486d7f5d3SJohn Marino # Mark initial, empty file as binary 24586d7f5d3SJohn Marino rcs -i -kb -t$emptyfile $file 24686d7f5d3SJohn Marino endif 24786d7f5d3SJohn Marino 24886d7f5d3SJohn Marino if ($nodesc) then 24986d7f5d3SJohn Marino echo about to do ci 25086d7f5d3SJohn Marino echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file 25186d7f5d3SJohn Marino ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile 25286d7f5d3SJohn Marino if ($status != 0) goto ERROR 25386d7f5d3SJohn Marino echo initial rev checked into RCS without description 25486d7f5d3SJohn Marino else 25586d7f5d3SJohn Marino echo "" 25686d7f5d3SJohn Marino echo Enter a brief description of the file $file \(end w/ Ctrl-D\): 25786d7f5d3SJohn Marino cat > $tmpfile 25886d7f5d3SJohn Marino ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile 25986d7f5d3SJohn Marino if ($status != 0) goto ERROR 26086d7f5d3SJohn Marino echo initial rev checked into RCS 26186d7f5d3SJohn Marino endif 26286d7f5d3SJohn Marino else 26386d7f5d3SJohn Marino # get RCS lock 26486d7f5d3SJohn Marino set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'` 26586d7f5d3SJohn Marino if ("$lckrev" =~ [0-9]*.*) then 26686d7f5d3SJohn Marino # need to lock the brach -- it is OK if the lock fails 26786d7f5d3SJohn Marino rcs -l$lckrev $file >>& $logfile 26886d7f5d3SJohn Marino else 26986d7f5d3SJohn Marino # need to lock the trunk -- must succeed 27086d7f5d3SJohn Marino rcs -l $file >>& $logfile 27186d7f5d3SJohn Marino if ($status != 0) goto ERROR 27286d7f5d3SJohn Marino endif 27386d7f5d3SJohn Marino echo got lock 27486d7f5d3SJohn Marino sccs prs -r$rev $file | grep "." > $tmpfile 27586d7f5d3SJohn Marino # it's OK if grep fails here and gives status == 1 27686d7f5d3SJohn Marino # put the delta message in $tmpfile 27786d7f5d3SJohn Marino ed $tmpfile >>& $logfile <<EOF 27886d7f5d3SJohn Marino/COMMENTS 27986d7f5d3SJohn Marino1,.d 28086d7f5d3SJohn Marinow 28186d7f5d3SJohn Marinoq 28286d7f5d3SJohn MarinoEOF 28386d7f5d3SJohn Marino ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile 28486d7f5d3SJohn Marino if ($status != 0) goto ERROR 28586d7f5d3SJohn Marino echo checked into RCS 28686d7f5d3SJohn Marino endif 28786d7f5d3SJohn Marino sccs unedit $file >>& $logfile 28886d7f5d3SJohn Marino if ($status != 0) goto ERROR 28986d7f5d3SJohn Marino end 29086d7f5d3SJohn Marino rm -f $file 29186d7f5d3SJohn Marinoend 29286d7f5d3SJohn Marino 29386d7f5d3SJohn Marino 29486d7f5d3SJohn Marino############################################################ 29586d7f5d3SJohn Marino# Clean up 29686d7f5d3SJohn Marino# 29786d7f5d3SJohn Marinoecho cleaning up... 29886d7f5d3SJohn Marinomv SCCS old-SCCS 29986d7f5d3SJohn Marinorm -f $tmpfile $emptyfile $initialfile $sedfile 30086d7f5d3SJohn Marinoecho =================================================== 30186d7f5d3SJohn Marinoecho " Conversion Completed Successfully" 30286d7f5d3SJohn Marinoecho "" 30386d7f5d3SJohn Marinoecho " SCCS history now in old-SCCS/" 30486d7f5d3SJohn Marinoecho =================================================== 30586d7f5d3SJohn Marinoset exitval = 0 30686d7f5d3SJohn Marinogoto cleanup 30786d7f5d3SJohn Marino 30886d7f5d3SJohn MarinoERROR: 30986d7f5d3SJohn Marinoforeach f (`sccs tell`) 31086d7f5d3SJohn Marino sccs unedit $f 31186d7f5d3SJohn Marinoend 31286d7f5d3SJohn Marinoecho "" 31386d7f5d3SJohn Marinoecho "" 31486d7f5d3SJohn Marinoecho Danger\! Danger\! 31586d7f5d3SJohn Marinoecho Some command exited with a non-zero exit status. 31686d7f5d3SJohn Marinoecho Log file exists in $logfile. 31786d7f5d3SJohn Marinoecho "" 31886d7f5d3SJohn Marinoecho Incomplete history in ./RCS -- remove it 31986d7f5d3SJohn Marinoecho Original unchanged history in ./SCCS 32086d7f5d3SJohn Marinoset exitval = 1 32186d7f5d3SJohn Marino 32286d7f5d3SJohn Marinocleanup: 32386d7f5d3SJohn Marino# leave log file 32486d7f5d3SJohn Marinorm -f $tmpfile $emptyfile $initialfile $sedfile $revfile 32586d7f5d3SJohn Marino 32686d7f5d3SJohn Marinoexit $exitval 327