home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume15 / sccs2rcs_kc / part01 / sccs2rcs < prev   
Text File  |  1990-10-05  |  7KB  |  262 lines

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