3 # RCS to ChangeLog generator
5 # Generate a change log prefix from RCS files and the 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.
9 # Ignore log entries that start with `#'.
10 # Clump together log entries that start with `{topic} ',
11 # where `topic' contains neither white space nor `}'.
13 # Author: Paul Eggert <eggert@twinsun.com>
15 # $Id: rcs2log,v 1.13.1.1 1993/09/24 00:54:33 eggert Exp $
17 # Copyright 1992, 1993 Free Software Foundation, Inc.
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)
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.
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.
40 hostname
= # name of local host (if empty, will deduce it later)
41 indent
=8 # indent of log line
42 initialize_fullname
= # awk assignments to set up fullname array
43 initialize_mailaddr
= # awk assignments to set up mailaddr array
44 length
=79 # suggested max width of log line
45 logins
= # login names for people we know fullnames and mailaddresses of
46 loginsout
= # temporary file holding sorted logins
47 rlog_options
= # options to pass to rlog
48 tabwidth
=8 # width of horizontal tab
56 -n) logins
=$logins$nl${2?}
57 loginsout
=$TMPDIR/rcs2log$
$l
59 *\"* |
*\\* |
*"$nl"*)
60 echo >&2 "$0: -n '$2' '$3' '$4': special characters not allowed"
63 initialize_fullname
="$initialize_fullname
64 fullname[\"$2\"] = \"$3\""
65 initialize_mailaddr
="$initialize_mailaddr
66 mailaddr[\"$2\"] = \"$4\""
68 -r) rlog_options
=$rlog_options$nl${2?};;
70 -*) echo >&2 "$0: usage: $0 [options] [file ...]
72 [-h hostname] [-i indent] [-l length] [-n login fullname mailaddr]...
73 [-r rlog_option]... [-t tabwidth]"
81 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
82 m[3]="Apr"; m[4]="May"; m[5]="Jun"
83 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
84 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
86 # days in non-leap year thus far, indexed by month (0-12)
87 mo[0]=0; mo[1]=31; mo[2]=59; mo[3]=90
88 mo[4]=120; mo[5]=151; mo[6]=181; mo[7]=212
89 mo[8]=243; mo[9]=273; mo[10]=304; mo[11]=334
94 # Log into $rlogout the revisions checked in since the first ChangeLog entry.
99 # Add 1 to seconds to avoid duplicating most recent log.
101 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
104 for (i=0; i<=11; i++) if (m[i] == $2) break
119 monthdays = mo[i+1] - mo[i]
120 if (i == 1 && year%4 == 0 && (year%100 != 0 || year%400 == 0)) monthdays++
121 if (dd == monthdays + 1) {
132 printf "%d/%02d/%02d %02d:%02d:%02d\n", year, i+1, dd, hh, mm, ss
136 d
=`awk "$e" <ChangeLog` ||
exit
143 # With no arguments, examine all files under the RCS directory.
147 for file in RCS
/.
* RCS
/* .
*,v
*,v
150 RCS
/. | RCS
/..
) continue;;
151 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue
164 rlogout
=$TMPDIR/rcs2log$
$r
166 trap "rm -f $loginsout $rlogout; exit 1" 0
168 rlog
"$datearg" $rlog_options "$@" >$rlogout ||
exit
171 # Get the full name of each author the logs mention, and set initialize_fullname
172 # to awk code that initializes the `fullname' awk associative array.
173 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
174 # you have to fix the resulting output by hand.
177 ?
*) sort -u -o $loginsout <<EOF || exit
182 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 |
185 ?*) sort -u | comm -23 - $loginsout
191 for author
in $authors
193 initialize_author
="$initialize_author
194 author[\"$author\"] = 1
199 alphabet = "abcdefghijklmnopqrstuvwxyz"
200 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
201 '"$initialize_author"'
206 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
207 # Remove the junk from fullnames like "0000-Admin(0000)".
208 fullname = substr(fullname, index(fullname, "-") + 1)
209 fullname = substr(fullname, 1, index(fullname, "(") - 1)
211 if (fullname ~ /,[^ ]/) {
212 # Some sites put comma-separated junk after the fullname.
213 # Remove it, but leave "Bill Gates, Jr" alone.
214 fullname = substr(fullname, 1, index(fullname, ",") - 1)
216 abbr = index(fullname, "&")
220 i = index(alphabet, a)
221 if (i) A = substr(ALPHABET, i, 1)
222 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
224 printf "fullname[\"%s\"] = \"%s\"\n", $1, fullname
230 initialize_fullname
=`
231 (cat /etc/passwd; ypmatch $authors passwd) 2>/dev/null |
233 `$initialize_fullname
237 # Function to print a single log line.
238 # We don't use awk functions, to stay compatible with old awk versions.
239 # `Log' is the log message (with \n replaced by \r).
240 # `files' contains the affected files.
243 # Following the GNU coding standards, rewrite
244 # * file: (function): comment
246 # * file (function): comment
247 if (Log ~ /^\([^)]*\): /) {
249 files = files " " substr(Log, 1, i)
250 Log = substr(Log, i+3)
253 # If "label: comment" is too long, break the line after the ":".
255 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string
258 printf "%s*%s:", indent_string, files
260 # Print each line of the log, transliterating \r to \n.
261 while ((i = index(Log, CR)) != 0) {
262 printf "%s%s\n", sep, substr(Log, 1, i-1)
264 Log = substr(Log, i+1)
271 hostname || uname -n || uuname -l || cat /etc/whoami
273 echo >&2 "$0: cannot deduce hostname"
279 # Process the rlog output, generating ChangeLog style entries.
281 # First, reformat the rlog output so that each line contains one log entry.
282 # Transliterate \n to \r so that multiline entries fit on a single line.
283 # Discard irrelevant rlog output.
285 /^Working file:/ { filename = $3 }
286 /^date: /, /^(-----------*|===========*)$/ {
287 if ($0 ~ /^branches: /) { next }
288 if ($0 ~ /^date: [0-9][ \/0-9:]*;/) {
289 time = substr($3, 1, length($3)-1)
290 author = substr($5, 1, length($5)-1)
291 printf "%s %s %s %s %c", filename, $2, time, author, 13
294 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next }
295 printf "%s%c", $0, 13
299 # Now each line is of the form
300 # FILENAME YYYY/MM/DD HH:MM:SS AUTHOR \rLOG
301 # where \r stands for a carriage return,
302 # and each line of the log is terminated by \r instead of \n.
303 # Sort the log entries, first by date+time (in reverse order),
304 # then by author, then by log entry, and finally by file name (just in case).
307 # Finally, reformat the sorted log entries.
310 # Some awks do not understand "\r" or "\013", so we have to
311 # put a carriage return directly in the file.
312 CR="
" # <-- There is a single CR between the " chars here.
314 # Initialize the fullname and mailaddr associative arrays.
315 '"$initialize_fullname"'
316 '"$initialize_mailaddr"'
318 # Initialize indent string.
321 if (0 < '"$tabwidth"')
322 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
323 indent_string = indent_string "\t"
325 indent_string = indent_string " "
327 # Set up date conversion tables.
328 # RCS uses a nice, clean, sortable format,
329 # but ChangeLog wants the traditional, ugly ctime format.
331 # January 1, 0 AD (Gregorian) was Saturday = 6
333 # Of course, there was no 0 AD, but the algorithm works anyway.
335 w[0]="Sun"; w[1]="Mon"; w[2]="Tue"; w[3]="Wed"
336 w[4]="Thu"; w[5]="Fri"; w[6]="Sat"
342 newlog = substr($0, 1 + index($0, CR))
344 # Ignore log entries prefixed by "#".
345 if (newlog ~ /^#/) { next }
347 if (Log != newlog || date != $2 || author != $4) {
349 # The previous log and this log differ.
352 if (date != "") '"$printlogline"'
354 # Logs that begin with "{clumpname} " should be grouped together,
355 # and the clumpname should be removed.
356 # Extract the new clumpname from the log header,
357 # and use it to decide whether to output a blank line.
360 if (date == "") sep = ""
361 if (newlog ~ /^\{[^ }]*}[ ]/) {
362 i = index(newlog, "}")
363 newclumpname = substr(newlog, 1, i)
364 while (substr(newlog, i+1) ~ /^[ ]/) i++
365 newlog = substr(newlog, i+1)
366 if (clumpname == newclumpname) sep = ""
369 clumpname = newclumpname
371 # Get ready for the next log.
374 for (i in filesknown)
378 if (date != $2 || author != $4) {
379 # The previous date+author and this date+author differ.
384 # Convert nice RCS date like "1992/01/03 00:03:44"
385 # into ugly ctime date like "Fri Jan 3 00:03:44 1992".
386 # Calculate day of week from Gregorian calendar.
388 year = substr($2, 1, i-1) + 0
389 monthday = substr($2, i+1)
390 i = index(monthday, "/")
391 month = substr(monthday, 1, i-1) + 0
392 day = substr(monthday, i+1) + 0
394 if (2 < month && year%4 == 0 && (year%100 != 0 || year%400 == 0)) leap = 1
395 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
397 # Print "date fullname (email address)".
398 # Get fullname and email address from associative arrays;
399 # default to author and author@hostname if not in arrays.
400 if (fullname[author])
401 auth = fullname[author]
404 printf "%s %s %2d %s %d %s ", w[days_since_Sunday_before_epoch%7], m[month-1], day, $3, year, auth
405 if (mailaddr[author])
406 printf "(%s)\n\n", mailaddr[author]
408 printf "(%s@%s)\n\n", author, "'"$hostname"'"
410 if (! filesknown[$1]) {
412 if (files == "") files = " " $1
413 else files = files ", " $1
417 # Print the last log.
428 exec rm -f $loginsout $rlogout