Commit | Line | Data |
---|---|---|
b86e8615 PE |
1 | #!/bin/sh |
2 | ||
3 | # RCS to ChangeLog generator | |
4 | ||
23a227f7 | 5 | # $Id: rcs2log,v 1.4 1992/03/21 05:58:05 eggert Exp eggert $ |
b86e8615 PE |
6 | |
7 | # Generate a change log prefix from RCS/* and the existing ChangeLog (if any). | |
8 | # Output the new prefix to standard output. | |
9 | # You can edit this prefix by hand, and then prepend it to ChangeLog. | |
10 | ||
11 | ||
4ca2c4b4 PE |
12 | # Parse options. |
13 | ||
14 | # defaults | |
15 | indent=8 # indent of log line | |
16 | length=79 # suggested max width of log line | |
17 | tabwidth=8 # width of horizontal tab | |
18 | ||
19 | while : | |
20 | do | |
21 | case $1 in | |
22 | -i) indent=${2?};; | |
23 | -l) length=${2?};; | |
24 | -t) tabwidth=${2?};; | |
25 | -*) echo >&2 "$0: usage: $0 [-i indent] [-l length] [-t tabwidth] [file ...]" | |
26 | exit 1;; | |
27 | *) break | |
28 | esac | |
29 | shift; shift | |
30 | done | |
31 | ||
32 | ||
b86e8615 PE |
33 | # Log into $rlogout the revisions checked in since the first ChangeLog entry. |
34 | ||
23a227f7 | 35 | date=1970 |
b86e8615 PE |
36 | if test -s ChangeLog |
37 | then | |
23a227f7 PE |
38 | # Add 1 to seconds to avoid duplicating most recent log. |
39 | # It's a good thing `rlog' doesn't mind a time ending in `:60'. | |
40 | e=' | |
41 | /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{ | |
42 | printf "%s%.2d %s\n", substr($0,1,17), substr($0,18,2)+1, $5 | |
43 | exit | |
44 | } | |
45 | ' | |
46 | d=`awk "$e" <ChangeLog` || exit | |
47 | case $d in | |
48 | ?*) date=$d | |
ff17867b | 49 | esac |
b86e8615 | 50 | fi |
23a227f7 | 51 | datearg="-d>$date" |
b86e8615 PE |
52 | |
53 | rlogout=/tmp/chg$$ | |
54 | trap exit 1 2 13 15 | |
55 | trap 'rm -f $rlogout; exit 1' 0 | |
56 | ||
4ca2c4b4 PE |
57 | case $# in |
58 | 0) set RCS/* | |
59 | esac | |
60 | ||
61 | rlog "$datearg" "$@" >$rlogout || exit | |
b86e8615 PE |
62 | |
63 | ||
64 | # Get the full name of each author the logs mention, and set initialize_fullname | |
65 | # to awk code that initializes the `fullname' awk associative array. | |
66 | # Warning: foreign authors (i.e. not known in the passwd file) are mishandled; | |
67 | # you have to fix the resulting output by hand. | |
68 | ||
69 | authors=` | |
70 | 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 | | |
71 | sort -u | |
72 | ` | |
73 | ||
74 | initialize_fullname= | |
75 | for author in $authors | |
76 | do | |
77 | fullname=` | |
78 | (grep "^$author:" /etc/passwd || ypmatch "$author" passwd) | | |
79 | sed -n 's/^[^:]*:[^:]*:[^:]*:[^:]*:\([^,:]*\).*$/\1/;p;q' | |
80 | ` | |
81 | case $fullname in | |
82 | *\&*) | |
83 | User=` | |
84 | expr " $author" : ' \(.\)' | | |
85 | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | |
86 | `` | |
87 | expr " $author" : ' .\(.*\)' | |
88 | ` | |
89 | fullname=`echo "$fullname" | sed "s:&:$User:"` | |
90 | esac | |
4ca2c4b4 PE |
91 | case $fullname in |
92 | ?*) | |
93 | initialize_fullname="$initialize_fullname | |
94 | fullname[\"$author\"] = \"$fullname\"" | |
95 | esac | |
b86e8615 PE |
96 | done |
97 | ||
98 | ||
99 | # Function to print a single log line. | |
100 | # We don't use awk functions, to stay compatible with old awk versions. | |
101 | # `Log' is the log message (with \n replaced by \r). | |
b19075d1 | 102 | # `files' contains the affected files. |
b86e8615 PE |
103 | printlogline='{ |
104 | ||
105 | # Following the GNU coding standards, rewrite | |
106 | # * file: (function): comment | |
107 | # to | |
108 | # * file (function): comment | |
109 | if (Log ~ /^\([^)]*\): /) { | |
110 | i = index(Log, ")") | |
111 | files = files " " substr(Log, 1, i) | |
112 | Log = substr(Log, i+3) | |
113 | } | |
114 | ||
115 | # If "label: comment" is too long, break the line after the ":". | |
116 | sep = " " | |
4ca2c4b4 | 117 | if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, "\r")) sep = "\n" indent_string |
b86e8615 PE |
118 | |
119 | # Print the label. | |
4ca2c4b4 | 120 | printf "%s*%s:", indent_string, files |
b86e8615 PE |
121 | |
122 | # Print each line of the log, transliterating \r to \n. | |
123 | while ((i = index(Log, "\r")) != 0) { | |
124 | printf "%s%s\n", sep, substr(Log, 1, i-1) | |
4ca2c4b4 | 125 | sep = indent_string |
b86e8615 PE |
126 | Log = substr(Log, i+1) |
127 | } | |
b86e8615 PE |
128 | }' |
129 | ||
130 | hostname=`( | |
131 | hostname || cat /etc/whoami || uuname -l || uname -n | |
132 | ) 2>/dev/null` || { | |
133 | echo >&2 "$0: cannot deduce hostname" | |
134 | exit 1 | |
135 | } | |
136 | ||
137 | ||
138 | # Process the rlog output, generating ChangeLog style entries. | |
139 | ||
140 | # First, reformat the rlog output so that each line contains one log entry. | |
141 | # Transliterate \n to \r so that multiline entries fit on a single line. | |
142 | # Discard irrelevant rlog output. | |
143 | awk <$rlogout ' | |
144 | /^Working file:/ { filename = $3 } | |
145 | /^date: /, /^(-----------*|===========*)$/ { | |
146 | if ($0 ~ /^branches: /) { next } | |
147 | if ($0 ~ /^date: [0-9][ /0-9:]*;/) { | |
148 | time = substr($3, 1, length($3)-1) | |
149 | author = substr($5, 1, length($5)-1) | |
150 | printf "%s %s %s %s \r", filename, $2, time, author | |
151 | next | |
152 | } | |
153 | if ($0 ~ /^(-----------*|===========*)/) { print ""; next } | |
154 | { printf "%s\r", $0 } | |
155 | } | |
156 | ' | | |
157 | ||
158 | # Now each line is of the form | |
159 | # FILENAME YYYY/MM/DD HH:MM:SS AUTHOR \rLOG | |
160 | # where \r stands for a carriage return, | |
161 | # and each line of the log is terminated by \r instead of \n. | |
162 | # Sort the log entries, first by date (in reverse order), | |
163 | # then by author, then by log entry, and finally by file name (just in case). | |
23a227f7 | 164 | sort +1 -3r +3 +0 | |
b86e8615 PE |
165 | |
166 | # Finally, reformat the sorted log entries. | |
167 | awk ' | |
168 | BEGIN { | |
169 | ||
170 | # Initialize the fullname associative array. | |
171 | '"$initialize_fullname"' | |
172 | ||
4ca2c4b4 PE |
173 | # Initialize indent string. |
174 | indent_string = "" | |
175 | i = '"$indent"' | |
176 | if (0 < '"$tabwidth"') | |
177 | for (; '"$tabwidth"' <= i; i -= '"$tabwidth"') | |
178 | indent_string = indent_string "\t" | |
179 | while (1 <= i--) | |
180 | indent_string = indent_string " " | |
181 | ||
b86e8615 PE |
182 | # Set up date conversion tables. |
183 | # RCS uses a nice, clean, sortable format, | |
184 | # but ChangeLog wants the traditional, ugly ctime format. | |
185 | ||
186 | # January 1, 0 AD (Gregorian) was Saturday = 6 | |
187 | EPOCH_WEEKDAY = 6 | |
188 | # Of course, there was no 0 AD, but the algorithm works anyway. | |
189 | ||
190 | w[0]="Sun"; w[1]="Mon"; w[2]="Tue"; w[3]="Wed" | |
191 | w[4]="Thu"; w[5]="Fri"; w[6]="Sat" | |
192 | ||
193 | m[0]="Jan"; m[1]="Feb"; m[2]="Mar" | |
194 | m[3]="Apr"; m[4]="May"; m[5]="Jun" | |
195 | m[6]="Jul"; m[7]="Aug"; m[8]="Sep" | |
196 | m[9]="Oct"; m[10]="Nov"; m[11]="Dec" | |
197 | ||
198 | # days in non-leap year thus far, indexed by month (0-12) | |
199 | mo[0]=0; mo[1]=31; mo[2]=59; mo[3]=90 | |
200 | mo[4]=120; mo[5]=151; mo[6]=181; mo[7]=212 | |
201 | mo[8]=243; mo[9]=273; mo[10]=304; mo[11]=334 | |
202 | mo[12]=365 | |
203 | } | |
204 | { | |
205 | newlog = substr($0, 1 + index($0, "\r")) | |
206 | if (Log != newlog || date != $2 || author != $4) { | |
b19075d1 | 207 | |
b86e8615 | 208 | # The previous log and this log differ. |
b19075d1 PE |
209 | |
210 | # Print the old log. | |
b86e8615 PE |
211 | if (date != "") '"$printlogline"' |
212 | ||
b19075d1 PE |
213 | # Logs that begin with "{clumpname} " should be grouped together, |
214 | # and the clumpname should be removed. | |
215 | # Extract the new clumpname from the log header, | |
216 | # and use it to decide whether to output a blank line. | |
217 | newclumpname = "" | |
218 | sep = "\n" | |
23a227f7 | 219 | if (date == "") sep = "" |
b19075d1 PE |
220 | if (newlog ~ /^{[^ }]+}[ ]/) { |
221 | i = index(newlog, "}") | |
222 | newclumpname = substr(newlog, 1, i) | |
223 | while (substr(newlog, i+1) ~ /^[ ]/) i++ | |
224 | newlog = substr(newlog, i+1) | |
225 | if (clumpname == newclumpname) sep = "" | |
226 | } | |
227 | printf sep | |
228 | clumpname = newclumpname | |
229 | ||
b86e8615 PE |
230 | # Get ready for the next log. |
231 | Log = newlog | |
4ca2c4b4 PE |
232 | if (files != "") |
233 | for (i in filesknown) | |
234 | filesknown[i] = 0 | |
b86e8615 PE |
235 | files = "" |
236 | } | |
237 | if (date != $2 || author != $4) { | |
238 | # The previous date+author and this date+author differ. | |
239 | # Print the new one. | |
240 | date = $2 | |
241 | author = $4 | |
242 | ||
243 | # Convert nice RCS date like "1992/01/03 00:03:44" | |
244 | # into ugly ctime date like "Fri Jan 3 00:03:44 1992". | |
245 | # Calculate day of week from Gregorian calendar. | |
246 | i = index($2, "/") | |
23a227f7 | 247 | year = substr($2, 1, i-1) + 0 |
b86e8615 PE |
248 | monthday = substr($2, i+1) |
249 | i = index(monthday, "/") | |
23a227f7 PE |
250 | month = substr(monthday, 1, i-1) + 0 |
251 | day = substr(monthday, i+1) + 0 | |
b86e8615 | 252 | leap = 0 |
23a227f7 | 253 | if (2 < month && year%4 == 0 && (year%100 != 0 || year%400 == 0)) leap = 1 |
b86e8615 PE |
254 | 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 |
255 | ||
4ca2c4b4 PE |
256 | # Print "date fullname (email address)" if the fullname is known; |
257 | # print "date author" otherwise. | |
b86e8615 PE |
258 | # Get the fullname from the associative array. |
259 | # The email address is just author@thishostname. | |
4ca2c4b4 PE |
260 | printf "%s %s %2d %s %d ", w[days_since_Sunday_before_epoch%7], m[month-1], day, $3, year |
261 | if (fullname[author]) | |
262 | printf "%s (%s@%s)\n\n", fullname[author], author, "'"$hostname"'" | |
263 | else | |
264 | printf "%s\n\n", author | |
265 | } | |
266 | if (! filesknown[$1]) { | |
267 | filesknown[$1] = 1 | |
b19075d1 PE |
268 | if (files == "") files = " " $1 |
269 | else files = files ", " $1 | |
b86e8615 | 270 | } |
b86e8615 PE |
271 | } |
272 | END { | |
273 | # Print the last log. | |
b19075d1 PE |
274 | if (date != "") { |
275 | '"$printlogline"' | |
276 | printf "\n" | |
277 | } | |
b86e8615 PE |
278 | } |
279 | ' && | |
280 | ||
281 | ||
282 | # Exit successfully. | |
283 | ||
284 | exec rm -f $rlogout |