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.25 1995/07/07 22:47:57 eggert Exp eggert $
17 # Copyright 1992, 1993, 1994, 1995 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.
42 hostname
= # name of local host (if empty, will deduce it later)
43 indent
=8 # indent of log line
44 length
=79 # suggested max width of log line
45 logins
= # login names for people we know fullnames and mailaddrs of
46 loginFullnameMailaddrs
= # login<tab>fullname<tab>mailaddr triplets
47 recursive
= # t if we want recursive rlog
48 rlog_options
= # options to pass to rlog
49 tabwidth
=8 # width of horizontal tab
54 -i) indent
=${2?}; shift;;
55 -h) hostname
=${2?}; shift;;
56 -l) length
=${2?}; shift;;
57 -[nu
]) # -n is obsolescent; it is replaced by -u.
59 -n) case ${2?}${3?}${4?} in
61 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
64 loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$2$tab$3$tab$4
67 # If $2 is not tab-separated, use colon for separator.
70 echo >&2 "$0: -u '$2': newlines not allowed"
79 echo >&2 "$0: -u '$2': too many fields"
84 echo >&2 "$0: -u '$2': not enough fields"
87 loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$2
90 logins
=$logins$nl$login
92 -r) rlog_options
=$rlog_options$nl${2?}; shift;;
94 -t) tabwidth
=${2?}; shift;;
95 -*) echo >&2 "$0: usage: $0 [options] [file ...]
97 [-h hostname] [-i indent] [-l length] [-R] [-r rlog_option]
98 [-t tabwidth] [-u 'login<TAB>fullname<TAB>mailaddr']..."
106 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
107 m[3]="Apr"; m[4]="May"; m[5]="Jun"
108 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
109 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
111 # days in non-leap year thus far, indexed by month (0-12)
112 mo[0]=0; mo[1]=31; mo[2]=59; mo[3]=90
113 mo[4]=120; mo[5]=151; mo[6]=181; mo[7]=212
114 mo[8]=243; mo[9]=273; mo[10]=304; mo[11]=334
119 # Put rlog output into $rlogout.
121 # If no rlog options are given,
122 # log the revisions checked in since the first ChangeLog entry.
123 case $rlog_options in
128 # Add 1 to seconds to avoid duplicating most recent log.
130 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
133 for (i=0; i<=11; i++) if (m[i] == $2) break
148 monthdays = mo[i+1] - mo[i]
149 if (i == 1 && year%4 == 0 && (year%100 != 0 || year%400 == 0)) monthdays++
150 if (dd == monthdays + 1) {
161 # Output comma instead of space to avoid CVS 1.5 bug.
162 printf "%d/%02d/%02d,%02d:%02d:%02d\n", year,i+1,dd,hh,mm,ss
166 d
=`$AWK "$e" <ChangeLog` ||
exit
174 # If CVS is in use, examine its repository, not the normal RCS files.
175 if test ! -f CVS
/Repository
181 repository
=`sed 1q <CVS/Repository` ||
exit
182 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
191 *) repository
=${CVSROOT?}/$repository
193 if test ! -d "$repository"
195 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
201 # With no arguments, examine all files under the RCS directory.
210 RCSdirs
=`find . -name RCS -type d -print`
211 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
215 ?*) find $RCSdirs -type f -print
217 find . -name '*,v' -print
220 sed "$filesFromRCSfiles"
224 for file in RCS
/.
* RCS
/* .
*,v
*,v
227 RCS
/. | RCS
/..
) continue;;
228 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue
242 llogout
=$TMPDIR/rcs2log$
$l
243 rlogout
=$TMPDIR/rcs2log$
$r
245 trap "rm -f $llogout $rlogout; exit 1" 0
247 case $rlog_options in
248 ?
*) $rlog $rlog_options ${1+"$@"} >$rlogout;;
249 '') $rlog "$datearg" ${1+"$@"} >$rlogout
253 # Get the full name of each author the logs mention, and set initialize_fullname
254 # to awk code that initializes the `fullname' awk associative array.
255 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
256 # you have to fix the resulting output by hand.
261 case $loginFullnameMailaddrs in
263 case $loginFullnameMailaddrs in
265 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
266 $loginFullnameMailaddrs
268 loginFullnameMailaddrs
=`cat $llogout`
273 for loginFullnameMailaddr
in $loginFullnameMailaddrs
275 case $loginFullnameMailaddr in
279 set x
$loginFullnameMailaddr
283 initialize_fullname
="$initialize_fullname
284 fullname[\"$login\"] = \"$fullname\""
285 initialize_mailaddr
="$initialize_mailaddr
286 mailaddr[\"$login\"] = \"$mailaddr\""
292 ?
*) sort -u -o $llogout <<EOF || exit
296 output_authors
='/^date: / {
297 if ($2 ~ /^[0-9]*[-\/][0-9][0-9][-\/][0-9][0-9]$/ && $3 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9][-+0-9:]*;$/ && $4 == "author:" && $5 ~ /^[^;]*;$/) {
298 print substr($5, 1, length($5)-1)
302 $AWK "$output_authors" <$rlogout |
305 ?*) sort -u | comm -23 - $llogout
310 cat >$llogout <<EOF || exit
313 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
314 initialize_author
=`sed -e "$initialize_author_script" <$llogout`
317 alphabet = "abcdefghijklmnopqrstuvwxyz"
318 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
319 '"$initialize_author"'
324 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
325 # Remove the junk from fullnames like "0000-Admin(0000)".
326 fullname = substr(fullname, index(fullname, "-") + 1)
327 fullname = substr(fullname, 1, index(fullname, "(") - 1)
329 if (fullname ~ /,[^ ]/) {
330 # Some sites put comma-separated junk after the fullname.
331 # Remove it, but leave "Bill Gates, Jr" alone.
332 fullname = substr(fullname, 1, index(fullname, ",") - 1)
334 abbr = index(fullname, "&")
338 i = index(alphabet, a)
339 if (i) A = substr(ALPHABET, i, 1)
340 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
343 # Quote quotes and backslashes properly in full names.
344 # Do not use gsub; traditional awk lacks it.
348 p = index(rest, "\\")
349 q = index(rest, "\"")
356 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
357 rest = substr(rest, p+1)
360 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
366 initialize_fullname
=`
367 (cat /etc/passwd; ypmatch $authors passwd) 2>/dev/null |
368 $AWK -F: "$awkscript"
369 `$initialize_fullname
373 # Function to print a single log line.
374 # We don't use awk functions, to stay compatible with old awk versions.
375 # `Log' is the log message (with \n replaced by \r).
376 # `files' contains the affected files.
379 # Following the GNU coding standards, rewrite
380 # * file: (function): comment
382 # * file (function): comment
383 if (Log ~ /^\([^)]*\): /) {
385 files = files " " substr(Log, 1, i)
386 Log = substr(Log, i+3)
389 # If "label: comment" is too long, break the line after the ":".
391 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string
394 printf "%s*%s:", indent_string, files
396 # Print each line of the log, transliterating \r to \n.
397 while ((i = index(Log, CR)) != 0) {
398 logline = substr(Log, 1, i-1)
399 if (logline ~ /[^'"$tab"' ]/) {
400 printf "%s%s\n", sep, logline
405 Log = substr(Log, i+1)
412 hostname || uname -n || uuname -l || cat /etc/whoami
414 echo >&2 "$0: cannot deduce hostname"
420 # Process the rlog output, generating ChangeLog style entries.
422 # First, reformat the rlog output so that each line contains one log entry.
423 # Transliterate \n to \r so that multiline entries fit on a single line.
424 # Discard irrelevant rlog output.
426 BEGIN { repository = "'"$repository"'" }
428 if (repository != "") {
430 if (substr(filename, 1, length(repository) + 1) == repository "/") {
431 filename = substr(filename, length(repository) + 2)
433 if (filename ~ /,v$/) {
434 filename = substr(filename, 1, length(filename) - 2)
438 /^Working file:/ { if (repository == "") filename = $3 }
439 /^date: /, /^(-----------*|===========*)$/ {
440 if ($0 ~ /^branches: /) { next }
441 if ($0 ~ /^date: [0-9][- +\/0-9:]*;/) {
444 # An ISO format date. Replace all "-"s with "/"s.
446 while ((i = index(date, "-")) != 0) {
447 newdate = newdate substr(date, 1, i-1) "/"
448 date = substr(date, i+1)
452 # Ignore any time zone; ChangeLog has no room for it.
453 time = substr($3, 1, 8)
454 author = substr($5, 1, length($5)-1)
455 printf "%s %s %s %s %c", filename, date, time, author, 13
458 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next }
459 printf "%s%c", $0, 13
463 # Now each line is of the form
464 # FILENAME YYYY/MM/DD HH:MM:SS AUTHOR \rLOG
465 # where \r stands for a carriage return,
466 # and each line of the log is terminated by \r instead of \n.
467 # Sort the log entries, first by date+time (in reverse order),
468 # then by author, then by log entry, and finally by file name (just in case).
471 # Finally, reformat the sorted log entries.
474 # Some awk variants do not understand "\r" or "\013", so we have to
475 # put a carriage return directly in the file.
476 CR="
" # <-- There is a single CR between the " chars here.
478 # Initialize the fullname and mailaddr associative arrays.
479 '"$initialize_fullname"'
480 '"$initialize_mailaddr"'
482 # Initialize indent string.
485 if (0 < '"$tabwidth"')
486 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
487 indent_string = indent_string "\t"
489 indent_string = indent_string " "
491 # Set up date conversion tables.
492 # RCS uses a nice, clean, sortable format,
493 # but ChangeLog wants the traditional, ugly ctime format.
495 # January 1, 0 AD (Gregorian) was Saturday = 6
497 # Of course, there was no 0 AD, but the algorithm works anyway.
499 w[0]="Sun"; w[1]="Mon"; w[2]="Tue"; w[3]="Wed"
500 w[4]="Thu"; w[5]="Fri"; w[6]="Sat"
506 newlog = substr($0, 1 + index($0, CR))
508 # Ignore log entries prefixed by "#".
509 if (newlog ~ /^#/) { next }
511 if (Log != newlog || date != $2 || author != $4) {
513 # The previous log and this log differ.
516 if (date != "") '"$printlogline"'
518 # Logs that begin with "{clumpname} " should be grouped together,
519 # and the clumpname should be removed.
520 # Extract the new clumpname from the log header,
521 # and use it to decide whether to output a blank line.
524 if (date == "") sep = ""
525 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
526 i = index(newlog, "}")
527 newclumpname = substr(newlog, 1, i)
528 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
529 newlog = substr(newlog, i+1)
530 if (clumpname == newclumpname) sep = ""
533 clumpname = newclumpname
535 # Get ready for the next log.
538 for (i in filesknown)
542 if (date != $2 || author != $4) {
543 # The previous date+author and this date+author differ.
548 # Convert nice RCS date like "1992/01/03 00:03:44"
549 # into ugly ctime date like "Fri Jan 3 00:03:44 1992".
550 # Calculate day of week from Gregorian calendar.
552 year = substr($2, 1, i-1) + 0
553 monthday = substr($2, i+1)
554 i = index(monthday, "/")
555 month = substr(monthday, 1, i-1) + 0
556 day = substr(monthday, i+1) + 0
558 if (2 < month && year%4 == 0 && (year%100 != 0 || year%400 == 0)) leap = 1
559 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
561 # Print "date fullname (email address)".
562 # Get fullname and email address from associative arrays;
563 # default to author and author@hostname if not in arrays.
564 if (fullname[author])
565 auth = fullname[author]
568 printf "%s %s %2d %s %d %s ", w[days_since_Sunday_before_epoch%7], m[month-1], day, $3, year, auth
569 if (mailaddr[author])
570 printf "<%s>\n\n", mailaddr[author]
572 printf "<%s@%s>\n\n", author, "'"$hostname"'"
574 if (! filesknown[$1]) {
576 if (files == "") files = " " $1
577 else files = files ", " $1
581 # Print the last log.
592 exec rm -f $llogout $rlogout