527
|
1 #!/bin/sh
|
|
2
|
|
3 # RCS to ChangeLog generator
|
|
4
|
|
5 # Generate a change log prefix from RCS/* and the existing ChangeLog (if any).
|
|
6 # Output the new prefix to standard output.
|
|
7 # You can edit this prefix by hand, and then prepend it to ChangeLog.
|
|
8
|
636
|
9 # Ignore log entries that start with `#'.
|
|
10 # Clump together log entries that start with `{topic} ',
|
|
11 # where `topic' contains neither white space nor `}'.
|
527
|
12
|
1800
|
13 # Author: Paul Eggert <eggert@twinsun.com>
|
|
14
|
4654
0f5dd4938af9
Change /{/ to /\{/ for Posix compatibility; otherwise, HP awk complains.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
15 # $Id: rcs2log,v 1.13 1993/08/09 22:06:00 eggert Exp eggert $
|
1800
|
16
|
|
17 # Copyright 1992, 1993 Free Software Foundation, Inc.
|
|
18
|
|
19 # This program is free software; you can redistribute it and/or modify
|
|
20 # it under the terms of the GNU General Public License as published by
|
|
21 # the Free Software Foundation; either version 2, or (at your option)
|
|
22 # any later version.
|
|
23 #
|
|
24 # This program is distributed in the hope that it will be useful,
|
|
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
27 # GNU General Public License for more details.
|
|
28 #
|
|
29 # You should have received a copy of the GNU General Public License
|
|
30 # along with this program; see the file COPYING. If not, write to
|
|
31 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
32
|
3248
|
33 nl='
|
|
34 '
|
1800
|
35
|
534
|
36 # Parse options.
|
|
37
|
|
38 # defaults
|
|
39 indent=8 # indent of log line
|
|
40 length=79 # suggested max width of log line
|
|
41 tabwidth=8 # width of horizontal tab
|
|
42
|
|
43 while :
|
|
44 do
|
|
45 case $1 in
|
|
46 -i) indent=${2?};;
|
|
47 -l) length=${2?};;
|
|
48 -t) tabwidth=${2?};;
|
|
49 -*) echo >&2 "$0: usage: $0 [-i indent] [-l length] [-t tabwidth] [file ...]"
|
|
50 exit 1;;
|
|
51 *) break
|
|
52 esac
|
|
53 shift; shift
|
|
54 done
|
|
55
|
2220
|
56 month_data='
|
|
57 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
|
|
58 m[3]="Apr"; m[4]="May"; m[5]="Jun"
|
|
59 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
|
|
60 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
|
|
61
|
|
62 # days in non-leap year thus far, indexed by month (0-12)
|
|
63 mo[0]=0; mo[1]=31; mo[2]=59; mo[3]=90
|
|
64 mo[4]=120; mo[5]=151; mo[6]=181; mo[7]=212
|
|
65 mo[8]=243; mo[9]=273; mo[10]=304; mo[11]=334
|
|
66 mo[12]=365
|
|
67 '
|
|
68
|
534
|
69
|
527
|
70 # Log into $rlogout the revisions checked in since the first ChangeLog entry.
|
|
71
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
72 date=1970
|
527
|
73 if test -s ChangeLog
|
|
74 then
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
75 # Add 1 to seconds to avoid duplicating most recent log.
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
76 e='
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
77 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
|
2220
|
78 '"$month_data"'
|
|
79 year = $5
|
|
80 for (i=0; i<=11; i++) if (m[i] == $2) break
|
|
81 dd = $3
|
|
82 hh = substr($0,12,2)
|
|
83 mm = substr($0,15,2)
|
|
84 ss = substr($0,18,2)
|
|
85 ss++
|
|
86 if (ss == 60) {
|
|
87 ss = 0
|
|
88 mm++
|
|
89 if (mm == 60) {
|
|
90 mm = 0
|
|
91 hh++
|
|
92 if (hh == 24) {
|
|
93 hh = 0
|
|
94 dd++
|
|
95 monthdays = mo[i+1] - mo[i]
|
|
96 if (i == 1 && year%4 == 0 && (year%100 != 0 || year%400 == 0)) monthdays++
|
|
97 if (dd == monthdays + 1) {
|
|
98 dd = 1
|
|
99 i++
|
|
100 if (i == 12) {
|
|
101 i = 0
|
|
102 year++
|
|
103 }
|
|
104 }
|
|
105 }
|
|
106 }
|
|
107 }
|
|
108 printf "%d/%02d/%02d %02d:%02d:%02d\n", year, i+1, dd, hh, mm, ss
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
109 exit
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
110 }
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
111 '
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
112 d=`awk "$e" <ChangeLog` || exit
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
113 case $d in
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
114 ?*) date=$d
|
535
|
115 esac
|
527
|
116 fi
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
117 datearg="-d>$date"
|
527
|
118
|
3248
|
119 # With no arguments, examine all files under the RCS directory.
|
|
120 case $# in
|
|
121 0)
|
|
122 files=
|
|
123 for file in RCS/.* RCS/*
|
|
124 do
|
|
125 case $file in
|
|
126 RCS/. | RCS/..) ;;
|
|
127 RCS/.\* | RCS/\*) test -f "$file" && files=$files$nl$file;;
|
|
128 *) files=$files$nl$file
|
|
129 esac
|
|
130 done
|
|
131 case $files in
|
|
132 '') exit 0
|
|
133 esac
|
|
134 oldIFS=$IFS
|
|
135 IFS=$nl
|
|
136 set $files
|
|
137 IFS=$oldIFS
|
|
138 esac
|
|
139
|
527
|
140 rlogout=/tmp/chg$$
|
|
141 trap exit 1 2 13 15
|
|
142 trap 'rm -f $rlogout; exit 1' 0
|
|
143
|
534
|
144 rlog "$datearg" "$@" >$rlogout || exit
|
527
|
145
|
|
146
|
|
147 # Get the full name of each author the logs mention, and set initialize_fullname
|
|
148 # to awk code that initializes the `fullname' awk associative array.
|
|
149 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
|
|
150 # you have to fix the resulting output by hand.
|
|
151
|
640
|
152 initialize_fullname=
|
527
|
153 authors=`
|
|
154 sed -n 's|^date: *[0-9]*/[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]; *author: *\([^; ]*\).*|\1|p' <$rlogout |
|
|
155 sort -u
|
|
156 `
|
640
|
157 case $authors in
|
|
158 ?*)
|
|
159 initialize_author=
|
|
160 for author in $authors
|
|
161 do
|
|
162 initialize_author="$initialize_author
|
|
163 author[\"$author\"] = 1
|
|
164 "
|
|
165 done
|
527
|
166
|
640
|
167 awkscript='
|
|
168 BEGIN {
|
|
169 alphabet = "abcdefghijklmnopqrstuvwxyz"
|
|
170 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
171 '"$initialize_author"'
|
|
172 }
|
|
173 {
|
|
174 if (author[$1]) {
|
|
175 fullname = $5
|
4504
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
176 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
177 # Remove the junk from fullnames like "0000-Admin(0000)".
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
178 fullname = substr(fullname, index(fullname, "-") + 1)
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
179 fullname = substr(fullname, 1, index(fullname, "(") - 1)
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
180 }
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
181 if (fullname ~ /,[^ ]/) {
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
182 # Some sites put comma-separated junk after the fullname.
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
183 # Remove it, but leave "Bill Gates, Jr" alone.
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
184 fullname = substr(fullname, 1, index(fullname, ",") - 1)
|
65ef94a9e2c4
(awkscript): Some sites put comma-separated junk after the fullname.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
185 }
|
640
|
186 abbr = index(fullname, "&")
|
|
187 if (abbr) {
|
|
188 a = substr($1, 1, 1)
|
|
189 A = a
|
|
190 i = index(alphabet, a)
|
|
191 if (i) A = substr(ALPHABET, i, 1)
|
|
192 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
|
|
193 }
|
|
194 printf "fullname[\"%s\"] = \"%s\"\n", $1, fullname
|
|
195 author[$1] = 0
|
|
196 }
|
|
197 }
|
|
198 '
|
|
199
|
|
200 initialize_fullname=`
|
|
201 (cat /etc/passwd; ypmatch $authors passwd) 2>/dev/null |
|
|
202 awk -F: "$awkscript"
|
527
|
203 `
|
640
|
204 esac
|
527
|
205
|
|
206
|
|
207 # Function to print a single log line.
|
|
208 # We don't use awk functions, to stay compatible with old awk versions.
|
|
209 # `Log' is the log message (with \n replaced by \r).
|
594
|
210 # `files' contains the affected files.
|
527
|
211 printlogline='{
|
|
212
|
|
213 # Following the GNU coding standards, rewrite
|
|
214 # * file: (function): comment
|
|
215 # to
|
|
216 # * file (function): comment
|
|
217 if (Log ~ /^\([^)]*\): /) {
|
|
218 i = index(Log, ")")
|
|
219 files = files " " substr(Log, 1, i)
|
|
220 Log = substr(Log, i+3)
|
|
221 }
|
|
222
|
|
223 # If "label: comment" is too long, break the line after the ":".
|
|
224 sep = " "
|
2220
|
225 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string
|
527
|
226
|
|
227 # Print the label.
|
534
|
228 printf "%s*%s:", indent_string, files
|
527
|
229
|
|
230 # Print each line of the log, transliterating \r to \n.
|
2220
|
231 while ((i = index(Log, CR)) != 0) {
|
527
|
232 printf "%s%s\n", sep, substr(Log, 1, i-1)
|
534
|
233 sep = indent_string
|
527
|
234 Log = substr(Log, i+1)
|
|
235 }
|
|
236 }'
|
|
237
|
|
238 hostname=`(
|
|
239 hostname || cat /etc/whoami || uuname -l || uname -n
|
|
240 ) 2>/dev/null` || {
|
|
241 echo >&2 "$0: cannot deduce hostname"
|
|
242 exit 1
|
|
243 }
|
|
244
|
|
245
|
|
246 # Process the rlog output, generating ChangeLog style entries.
|
|
247
|
|
248 # First, reformat the rlog output so that each line contains one log entry.
|
|
249 # Transliterate \n to \r so that multiline entries fit on a single line.
|
|
250 # Discard irrelevant rlog output.
|
|
251 awk <$rlogout '
|
|
252 /^Working file:/ { filename = $3 }
|
|
253 /^date: /, /^(-----------*|===========*)$/ {
|
|
254 if ($0 ~ /^branches: /) { next }
|
2639
0e6a6d065a94
mawk, SunOS 4.1.3 nawk, and Ultrix/MKS nawk all barf on /[/]/, so change
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
255 if ($0 ~ /^date: [0-9][ \/0-9:]*;/) {
|
527
|
256 time = substr($3, 1, length($3)-1)
|
|
257 author = substr($5, 1, length($5)-1)
|
2220
|
258 printf "%s %s %s %s %c", filename, $2, time, author, 13
|
527
|
259 next
|
|
260 }
|
636
|
261 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next }
|
2220
|
262 printf "%s%c", $0, 13
|
527
|
263 }
|
|
264 ' |
|
|
265
|
|
266 # Now each line is of the form
|
|
267 # FILENAME YYYY/MM/DD HH:MM:SS AUTHOR \rLOG
|
|
268 # where \r stands for a carriage return,
|
|
269 # and each line of the log is terminated by \r instead of \n.
|
640
|
270 # Sort the log entries, first by date+time (in reverse order),
|
527
|
271 # then by author, then by log entry, and finally by file name (just in case).
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
272 sort +1 -3r +3 +0 |
|
527
|
273
|
|
274 # Finally, reformat the sorted log entries.
|
|
275 awk '
|
|
276 BEGIN {
|
2220
|
277 # Some awks do not understand "\r" or "\013", so we have to
|
|
278 # put a carriage return directly in the file.
|
|
279 CR="
" # <-- There is a single CR between the " chars here.
|
527
|
280
|
|
281 # Initialize the fullname associative array.
|
|
282 '"$initialize_fullname"'
|
|
283
|
534
|
284 # Initialize indent string.
|
|
285 indent_string = ""
|
|
286 i = '"$indent"'
|
|
287 if (0 < '"$tabwidth"')
|
|
288 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
|
|
289 indent_string = indent_string "\t"
|
|
290 while (1 <= i--)
|
|
291 indent_string = indent_string " "
|
|
292
|
527
|
293 # Set up date conversion tables.
|
|
294 # RCS uses a nice, clean, sortable format,
|
|
295 # but ChangeLog wants the traditional, ugly ctime format.
|
|
296
|
|
297 # January 1, 0 AD (Gregorian) was Saturday = 6
|
|
298 EPOCH_WEEKDAY = 6
|
|
299 # Of course, there was no 0 AD, but the algorithm works anyway.
|
|
300
|
|
301 w[0]="Sun"; w[1]="Mon"; w[2]="Tue"; w[3]="Wed"
|
|
302 w[4]="Thu"; w[5]="Fri"; w[6]="Sat"
|
|
303
|
2220
|
304 '"$month_data"'
|
527
|
305 }
|
636
|
306
|
527
|
307 {
|
2220
|
308 newlog = substr($0, 1 + index($0, CR))
|
636
|
309
|
|
310 # Ignore log entries prefixed by "#".
|
|
311 if (newlog ~ /^#/) { next }
|
|
312
|
527
|
313 if (Log != newlog || date != $2 || author != $4) {
|
594
|
314
|
527
|
315 # The previous log and this log differ.
|
594
|
316
|
|
317 # Print the old log.
|
527
|
318 if (date != "") '"$printlogline"'
|
|
319
|
594
|
320 # Logs that begin with "{clumpname} " should be grouped together,
|
|
321 # and the clumpname should be removed.
|
|
322 # Extract the new clumpname from the log header,
|
|
323 # and use it to decide whether to output a blank line.
|
|
324 newclumpname = ""
|
|
325 sep = "\n"
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
326 if (date == "") sep = ""
|
4654
0f5dd4938af9
Change /{/ to /\{/ for Posix compatibility; otherwise, HP awk complains.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
327 if (newlog ~ /^\{[^ }]*}[ ]/) {
|
594
|
328 i = index(newlog, "}")
|
|
329 newclumpname = substr(newlog, 1, i)
|
|
330 while (substr(newlog, i+1) ~ /^[ ]/) i++
|
|
331 newlog = substr(newlog, i+1)
|
|
332 if (clumpname == newclumpname) sep = ""
|
|
333 }
|
|
334 printf sep
|
|
335 clumpname = newclumpname
|
|
336
|
527
|
337 # Get ready for the next log.
|
|
338 Log = newlog
|
534
|
339 if (files != "")
|
|
340 for (i in filesknown)
|
|
341 filesknown[i] = 0
|
527
|
342 files = ""
|
|
343 }
|
|
344 if (date != $2 || author != $4) {
|
|
345 # The previous date+author and this date+author differ.
|
|
346 # Print the new one.
|
|
347 date = $2
|
|
348 author = $4
|
|
349
|
|
350 # Convert nice RCS date like "1992/01/03 00:03:44"
|
|
351 # into ugly ctime date like "Fri Jan 3 00:03:44 1992".
|
|
352 # Calculate day of week from Gregorian calendar.
|
|
353 i = index($2, "/")
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
354 year = substr($2, 1, i-1) + 0
|
527
|
355 monthday = substr($2, i+1)
|
|
356 i = index(monthday, "/")
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
357 month = substr(monthday, 1, i-1) + 0
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
358 day = substr(monthday, i+1) + 0
|
527
|
359 leap = 0
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
diff
changeset
|
360 if (2 < month && year%4 == 0 && (year%100 != 0 || year%400 == 0)) leap = 1
|
527
|
361 days_since_Sunday_before_epoch = EPOCH_WEEKDAY + year * 365 + int((year + 3) / 4) - int((year + 99) / 100) + int((year + 399) / 400) + mo[month-1] + leap + day - 1
|
|
362
|
534
|
363 # Print "date fullname (email address)" if the fullname is known;
|
|
364 # print "date author" otherwise.
|
527
|
365 # Get the fullname from the associative array.
|
|
366 # The email address is just author@thishostname.
|
534
|
367 printf "%s %s %2d %s %d ", w[days_since_Sunday_before_epoch%7], m[month-1], day, $3, year
|
|
368 if (fullname[author])
|
|
369 printf "%s (%s@%s)\n\n", fullname[author], author, "'"$hostname"'"
|
|
370 else
|
|
371 printf "%s\n\n", author
|
527
|
372 }
|
534
|
373 if (! filesknown[$1]) {
|
|
374 filesknown[$1] = 1
|
594
|
375 if (files == "") files = " " $1
|
|
376 else files = files ", " $1
|
534
|
377 }
|
527
|
378 }
|
|
379 END {
|
|
380 # Print the last log.
|
594
|
381 if (date != "") {
|
|
382 '"$printlogline"'
|
|
383 printf "\n"
|
|
384 }
|
527
|
385 }
|
|
386 ' &&
|
|
387
|
|
388
|
|
389 # Exit successfully.
|
|
390
|
|
391 exec rm -f $rlogout
|