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