Some fixes to follow coding conventions in files maintained by FSF.
[bpt/emacs.git] / lisp / emacs-lisp / authors.el
1 ;;; authors.el --- utility for maintaining Emacs' AUTHORS file
2
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4
5 ;; Author: Gerd Moellmann <gerd@gnu.org>
6 ;; Maintainer: FSF
7 ;; Keywords: maint
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Use M-x authors RET to create an *Authors* buffer that can used as
29 ;; or merged with Emacs' AUTHORS file.
30
31 ;;; Code:
32
33 (defconst authors-many-files 20
34 "Maximum number of files for which to print individual information.
35 If an author has modified more files, only a single entry is
36 printed telling how many files he changed, instead of listing each
37 file individually.")
38
39 (defconst authors-aliases
40 '(("eliz" . "Eli Zaretskii")
41 ("Richard Stallman" . "Richard M. Stallman")
42 ("Richard M. Stallman,,," . "Richard M. Stallman")
43 ("Richard Stallmao" . "Richard M. Stallman")
44 ("rms@gnu.org" . "Richard M. Stallman")
45 ("NIIBE Yutaka" . "Yutaka NIIBE")
46 ("(saw@cebaf.gov)" . "Stephen A. Wood")
47 ("(pmr@legacy.pajato.com)" . "Paul Reilly")
48 ("(Eric Youngdale at youngdale@v6550c.nrl.navy.mil)" . "Eric Youngdale")
49 ("<Daniel.Pfeiffer@Informatik.START.db.de>" . "Daniel Pfeiffer")
50 ("<Daniel.Pfeiffer@Informatik.START.dbp.de>" . "Daniel Pfeiffer")
51 ("(afs@hplb.hpl.hp.com)" . "ignore")
52 ("<Use-Author-Address-Header@\\[127.1\\]>" . "ignore")
53 ("Code Extracted" . "ignore")
54 ("Fsf" . "ignore")
55 ("David M. Koppelman, Koppel@Ee.Lsu.Edu" . "David M. Koppelman")
56 ("jka@ece.cmu.edu" . "Jay K. Adams")
57 ("Per Abhiddenware; you can redistribute it and/or modify" . "Per Abrahamsen")
58 ("Andrw Innes" . "Andrew Innes")
59 ("Barry Warsaw" . "Barry A. Warsaw")
60 ("Barry A. Warsaw, Century Computing, Inc." . "Barry A. Warsaw")
61 ("Barry A. Warsaw, ITB" . "Barry A. Warsaw")
62 ("Ken'ichi Handa" . "Kenichi Handa")
63 ("Bob Chassell" . "Robert J. Chassell")
64 ("SL Baur" . "Steven L. Baur")
65 ("Steven L Baur" . "Steven L. Baur")
66 ("eggert" . "Paul Eggert")
67 ("voelker" . "Geoff Voelker")
68 ("rms" . "Richard M. Stallman")
69 ("Edward M Reingold" . "Edward M. Reingold")
70 ("Eric Ludlam" . "Eric M. Ludlam")
71 ("Eric Raymond" . "Eric S. Raymond")
72 ("Francois Pinard" . "François Pinard")
73 ("Fred Pierresteguy" . "Frederic Pierresteguy")
74 ("Hallvard B Furuseth" . "Hallvard B. Furuseth")
75 ("ISO-2022-JP" . "ignore")
76 ("Jens-Ulrik Petersen" . "Jens-Ulrik Holger Petersen")
77 ("Christoph.Wedler@sap.com" . "Christoph Wedler")
78 ("Jonathan Kamens" . "Jonathan I. Kamens")
79 ("Kim Storm" . "Kim F. Storm")
80 ("Marcus Daniels" . "Marcus G. Daniels")
81 ("Michael I Bushnell" . "Michael I. Bushnell")
82 ("Michael I. Bushnell, P/Bsg" . "Michael I. Bushnell")
83 ("Reingold Edward M" . "Edward M. Reingold")
84 ("Roland B Roberts" . "Roland B. Roberts")
85 ("Sam Shteingold" . "Sam Steingold")
86 ("W{\L}Odek Bzyl" . "Wlodzimierz Bzyl")
87 ("Kenneth Manheimer" . "Ken Manheimer")
88 ("Kenichi HANDA" . "Kenichi Handa")
89 ("Jay Adams" . "Jay R. Adams")
90 ("Joe Arceneaux" . "Josef Arceneaux")
91 ("K. Berry" . "Karl Berry")
92 ("Michael Ernst" . "Michael D. Ernst")
93 ("Dave Gillespie" . "David Gillespie")
94 ("Shane Hartman" . "K. Shane Hartman")
95 ("Francesco Potorti`" . "Francesco Potorti")
96 ("Roland Roberts" . "Roland B. Roberts")
97 ("David Smith" . "David M. Smith")
98 )
99 "Alist of author aliases.
100
101 Each entry is of the form (REGEXP . ALIAS). If an author's name
102 matches REGEXP, use ALIAS instead. The special alias \"ignore\" means
103 ignore that author.")
104
105
106 (defvar authors-public-domain-files
107 '("auto-show\\.el"
108 "form-d2\\.el"
109 "emerge\\.el"
110 "unused\\.el"
111 "vi\\.el"
112 "feedmail\\.el"
113 "mailpost\\.el"
114 "hanoi\\.el"
115 "meese\\.el"
116 "studly\\.el"
117 "modula2\\.el")
118 "List of regexps matching files for which the FSF doesn't need papers.")
119
120
121 (defvar authors-obsolete-files-regexps
122 '("vc-\\*\\.el$"
123 "spec.txt$"
124 "vc-\\(rcs\\|cvs\\|sccs\\)-hooks\\.el$")
125 "List of regexps matching obsolete files.
126 Changes to files matching one of the regexps in this list are not
127 listed.")
128
129
130 (defconst authors-fixed-entries
131 '(("Joe Arceneax" :wrote "xrdb.c")
132 ("Blitz Product Development Corporation" :wrote "ispell.el")
133 ("Frank Bresz" :wrote "diff.el")
134 ("David M. Brown" :wrote "array.el")
135 ("Gary Byers" :changed "xenix.h")
136 ("Shawn M. Carey" :wrote "freebsd.h")
137 ("Eric Decker" :changed "hp9000s800.h" "hpux.h" "sysdep.c")
138 ("Lawrence R. Dodd" :wrote "dired-x.el")
139 ("Viktor Dukhovni" :wrote "unexsunos4.c")
140 ("Paul Eggert" :wrote "rcs2log" "vcdiff")
141 ("Fred Fish" :changed "unexec.c")
142 ("Tim Fleehart" :wrote "makefile.nt")
143 ("Keith Gabryelski" :wrote "hexl.c")
144 ("Kevin Gallagher" :wrote "flow-ctrl.el")
145 ("Howard Gayle" :wrote "disp-table.el" "iso-syntax.el" "casetab.c")
146 ("Stephen Gildea" :wrote "refcard.tex" "mh-funcs.el" "mh-pick.el")
147 ("David Gillespie" :wrote "cl.texinfo")
148 ("Hewlett-Packard" :changed "emacsclient.c" "emacsserver.c"
149 "server.el" "keyboard.c")
150 ("Thomas Horsley" :wrote "cxux.h" "cxux7.h")
151 ("Indiana University Foundation" :changed "buffer.c" "buffer.h"
152 "indent.c" "search.c" "xdisp.c" "region-cache.c" "region-cache.h")
153 ("International Business Machines" :changed "emacs.c" "fileio.c"
154 "ibmrt.h" "process.c" "sysdep.c" "unexec.c" "ibmrt-aix.h")
155 ("Ishikawa Chiaki" :changed "aviion.h" "dgux.h")
156 ("Michael K. Johnson" :changed "configure.in" "emacs.c" "intel386.h"
157 "mem-limits.h" "process.c" "template.h" "sysdep.c" "syssignal.h" "systty.h" "unexec.c"
158 "ymakefile" "linux.h")
159 ("Kyle E. Jones" :wrote "mldrag.el")
160 ("Kenry Kautz" :wrote "bib-mode.el")
161 ("Joseph M. Kelsey" :changed "fileio.c" "vms-pwd.h" "vmsfns.c" "dir.h"
162 "uaf.h")
163 ("Sam Kendall" :changed "etags.c" "etags.el")
164 ("Richard King" :wrote "backquote.el" "userlock.el" "filelock.c")
165 ("Larry Kolodney" :wrote "cvtmail.c")
166 ("Sebastian Kremer" :changed "add-log.el")
167 ("Mark Lambert" :changed "process.c" "process.h")
168 ("Aaron Larson" :changed "bibtex.el")
169 ("James R. Larus" :wrote "mh-e.el")
170 ("Lars Lindberg" :changed "dabbrev.el" :wrote "imenu.el")
171 ("Lucid, Inc." :changed "bytecode.c" "byte-opt.el" "byte-run.el"
172 "bytecomp.el" "delsel.el" "disass.el" "faces.el" "font-lock.el"
173 "lmenu.el" "lselect.el" "mailabbrev.el" "select.el" "xfaces.c"
174 "xselect.c")
175 ("MCC" :changed "etags.c" "emacsclient.c" "emacsserver.c" "movemail.c"
176 "rmail.el" "rmailedit.el" "rmailkwd.el"
177 "rmailmsc.el" "rmailout.el" "rmailsum.el" "scribe.el"
178 "server.el" "lisp.h" "sysdep.c" "unexec.c" :wrote "xmenu.c")
179 ("Niall Mansfield" :changed "etags.c")
180 ("Brian Marick" :wrote "hideif.el")
181 ("Marko Kohtala" :changed "info.el")
182 ("Sidney Markowitz" :changed "doctor.el")
183 ("Richard Mlynarik" :wrote "env.c" "ehelp.el")
184 ("Mosur Mohan" :changed "etags.c")
185 ("Jeff Morgenthaler" :changed "flow-ctrl.el" "vt200.el" "vt201.el"
186 "vt220.el" "vt240.el")
187 ("Motorola" :changed "buff-menu.el")
188 ("Hiroshi Nakano" :changed "ralloc.c")
189 ("Sundar Narasimhan" :changed "rnewspost.el")
190 ("NeXT, Inc." :wrote "unexnext.c")
191 ("Mark Neale" :changed "fortran.el")
192 ("Martin Neitzel" :changed "sc.el")
193 ("Andrew Oram" :changed "miscellaneous changes to files in man/"
194 "man/calendar.texi")
195 ("Frederic Pierresteguy" :wrote "widget.c")
196 ("Michael D. Prange" :changed "tex-mode.el")
197 ("Paul Reilly" :wrote "gux5-4r2.h" "dgux5-4r3.h")
198 ("Roland B Roberts" :changed "files.el" "sort.el" "vmsproc.el"
199 "buffer.h" "callproc.c" "dired.c" "process.c" "sysdep.c" "systty.h"
200 "vmspaths.h" "build.com" "compile.com" "kepteditor.com" "precomp.com"
201 :wrote "logout.com" "mailemacs.com")
202 ("Guillermo J. Rozas" :wrote "fakemail.c")
203 ("Wolfgang Rupprecht" :changed "lisp-mode.el" "loadup.el"
204 "sort.el" "alloc.c" "callint.c"
205 "config.h.in" "crt0.c" "data.c" "fns.c"
206 "lisp.h" "lread.c" "sun3.h"
207 "print.c" "ymakefile" :wrote "float-sup.el" "floatfns.c")
208 ("Schlumberger Technology Corporation" :changed "gud.el")
209 ("Gregor Schmid" :wrote "tcl-mode.el")
210 ("Rainer Schoepf" :wrote "alpha.h" "unexalpha.c")
211 ("William Sommerfeld" :wrote "emacsclient.c" "emacsserver.c" "scribe.el")
212 ("Leigh Stoller" :changed "emacsclient.c" "emacsserver.c" "server.el")
213 ("Steve Strassman" :wrote "spook.el")
214 ("Shinichirou Sugou" :changed "etags.c")
215 ("Sun Microsystems, Inc" :changed "emacsclient.c" "emacsserver.c"
216 "server.el" :wrote "emacs.icon" "emacstool.1" "emacstool.c" "sun-curs.el"
217 "sun-fns.el" "sun-mouse.el" "sun.el" "sunfns.c")
218 ("Kayvan Sylvan" :changed "sc.el")
219 ("Spencer Thomas" :changed "emacsclient.c" "emacsserver.c" "server.el"
220 "dabbrev.el" "unexec.c" "tcp.c" "gnus.texi")
221 ("Jonathan Vail" :changed "vc.el")
222 ("James Van Artsdalen" :changed "usg5-4.h" "unexec.c")
223 ("Geoff Voelker" :wrote "src/makefile.nt" "lisp/makefile.nt" "winnt.el"
224 "nt.c" "nt.h" "ntheap.c" "ntheap.h" "ntinevt.c"
225 "ntproc.c" "ntterm.c" "windowsnt.h")
226 ("Morten Welinder" :wrote "dosfns.c" "[many MSDOS files]" "msdos.h")
227 ("Pace Willisson" :wrote "ispell.el")
228 ("Garrett Wollman" :changed "sendmail.el")
229 ("Dale Worley" :changed "mail-extr.el")
230 ("Jamie Zawinski" :changed "bytecode.c" :wrote "disass.el" "tar-mode.el"))
231 "Actions taken from the original, manually (un)maintained AUTHORS file.")
232
233
234 (defun authors-add-fixed-entries (table)
235 "Add actions from `authors-fixed-entries' to TABLE."
236 (dolist (entry authors-fixed-entries)
237 (let ((author (car entry))
238 action)
239 (dolist (item (cdr entry))
240 (if (symbolp item)
241 (setq action item)
242 (authors-add author item action table))))))
243
244
245 (defun authors-obsolete-file-p (file)
246 "Return non-nil if FILE is obsolete.
247 FILE is considered obsolete if it matches on of the regular expressions
248 from `authors-obsolete-files-regexps'."
249 (let (obsolete-p
250 (regexps authors-obsolete-files-regexps))
251 (while (and regexps (not obsolete-p))
252 (setq obsolete-p (string-match (car regexps) file)
253 regexps (cdr regexps)))
254 obsolete-p))
255
256
257 (defun authors-add (author file action table)
258 "Record that AUTHOR worked on FILE.
259 ACTION is a keyword symbol describing what he did. Record file,
260 author and what he did in hash table TABLE. See the description of
261 `authors-scan-change-log' for the structure of the hash table."
262 (unless (or (authors-obsolete-file-p file)
263 (equal author ""))
264 (let* ((value (gethash author table))
265 (entry (assoc file value)))
266 (if (null entry)
267 (puthash author (cons (list file action) value) table)
268 (unless (memq action entry)
269 (nconc entry (list action)))))))
270
271
272 (defun authors-process-lines (program &rest args)
273 "Execute PROGRAM with ARGS, returning its output as a list of lines.
274 Signal an error if the program returns with a non-zero exit status."
275 (with-temp-buffer
276 (let ((status (apply 'call-process program nil (current-buffer) nil args)))
277 (unless (eq status 0)
278 (error "%s exited with status %s" program status))
279 (goto-char (point-min))
280 (let (lines)
281 (while (not (eobp))
282 (setq lines (cons (buffer-substring-no-properties
283 (line-beginning-position)
284 (line-end-position))
285 lines))
286 (forward-line 1))
287 (nreverse lines)))))
288
289
290 (defun authors-canonical-author-name (author)
291 "Return a canonicalized form of AUTHOR, an author name.
292 If AUTHOR has an alias, use that. Remove email addresses. Capitalize
293 words in the author's name."
294 (let ((aliases authors-aliases))
295 (while aliases
296 (when (string-match (car (car aliases)) author)
297 (setq author (cdr (car aliases))
298 aliases nil))
299 (setq aliases (cdr aliases))))
300 (setq author (replace-regexp-in-string "[ \t]*[(<].*$" "" author))
301 (setq author (replace-regexp-in-string "^[ \t]+" "" author))
302 (setq author (replace-regexp-in-string "[ \t]+$" "" author))
303 (capitalize author))
304
305
306 (defun authors-scan-change-log (file table)
307 "Scan change log FILE for author information.
308
309 For each change mentioned in the log, add an entry to hash table TABLE
310 under the author's canonical name.
311
312 Keys of TABLE are author names. Values are alists of entries (FILE
313 ACTION...). FILE is one file the author worked on. The rest of the
314 entry is a list of keyword symbols describing what he did with the
315 file.
316
317 :wrote means the author wrote the file
318 :changed means he changed the file."
319
320 (let* ((enable-local-variables t)
321 (enable-local-eval t)
322 (existing-buffer (get-file-buffer file))
323 (buffer (find-file-noselect file))
324 author)
325 (save-excursion
326 (set-buffer buffer)
327 (save-restriction
328 (widen)
329 (goto-char (point-min))
330 (while (re-search-forward "^[0-9]\\|^[ \t]+\\* " nil t)
331 (beginning-of-line)
332 (cond ((looking-at "^[0-9]+-[0-9]+-[0-9]+")
333 (skip-chars-forward " \t+:0-9-")
334 (setq author (buffer-substring-no-properties
335 (point) (line-end-position)))
336 (setq author (authors-canonical-author-name author))
337 (forward-line 1))
338 ((looking-at "^[ \t]+\\*")
339 (let ((line (buffer-substring-no-properties
340 (match-end 0) (line-end-position))))
341 (while (and (not (string-match ":" line))
342 (forward-line 1)
343 (not (looking-at ":\\|^[ \t]*$")))
344 (setq line (concat line
345 (buffer-substring-no-properties
346 (line-beginning-position)
347 (line-end-position)))))
348 (when (string-match ":" line)
349 (setq line (substring line 0 (match-beginning 0)))
350 (setq line (replace-regexp-in-string "[[(<{].*$" "" line))
351 (setq line (replace-regexp-in-string "," "" line))
352 (dolist (file (split-string line))
353 (setq file (file-name-nondirectory file))
354 ;(message "%s changed %s" author file)
355 (authors-add author file :changed table)))
356 (forward-line 1)))))))
357 (unless existing-buffer
358 (kill-buffer buffer))))
359
360
361 (defun authors-scan-el (file table)
362 "Scan Lisp file FILE for author information.
363 TABLE is a hash table to add author information to."
364 (let* ((existing-buffer (get-file-buffer file))
365 (enable-local-variables t)
366 (enable-local-eval t)
367 (buffer (find-file-noselect file)))
368 (save-excursion
369 (set-buffer buffer)
370 (save-restriction
371 (widen)
372 (goto-char (point-min))
373 (while (and (re-search-forward
374 "^;+[ \t]*\\(Author\\|Commentary\\):[ \t]*" nil t)
375 (not (string= (match-string 1) "Commentary")))
376 ;; Some entries contain a year range in front of the
377 ;; author's name.
378 (skip-chars-forward "-0-9 \t")
379 (let ((author (buffer-substring-no-properties
380 (point) (line-end-position))))
381 (setq author (authors-canonical-author-name author))
382 (setq file (file-name-nondirectory file))
383 (authors-add author file :wrote table)))))
384 (unless existing-buffer
385 (kill-buffer buffer))))
386
387
388 (defun authors-public-domain-p (file)
389 "Return t if FILE is a file that was put in public domain."
390 (let ((public-domain-p nil)
391 (list authors-public-domain-files))
392 (while (and list (not public-domain-p))
393 (when (string-match (car list) file)
394 (setq public-domain-p t))
395 (setq list (cdr list)))
396 public-domain-p))
397
398
399 (defun authors-print (author changes)
400 "Insert information about AUTHOR's work on Emacs into the current buffer.
401 CHANGES is an alist of entries (FILE ACTION...), as produced by
402 `authors-scan-change-log'."
403 (unless (equal author "Ignore")
404 (let ((nchanged 0))
405 (dolist (change changes)
406 (let ((actions (cdr change))
407 (file (car change)))
408 (if (memq :wrote actions)
409 (progn
410 (insert author " (wrote) " file)
411 (when (authors-public-domain-p file)
412 (insert " (public domain)"))
413 (insert "\n"))
414 (setq nchanged (1+ nchanged)))))
415 (if (> nchanged authors-many-files)
416 (insert author " (changed) [more than "
417 (int-to-string authors-many-files) " files]\n")
418 (dolist (change changes)
419 (let ((actions (cdr change))
420 (file (car change)))
421 (unless (memq :wrote actions)
422 (insert author " (changed) " file "\n"))))))))
423
424
425 (defun authors (root)
426 "Extract author information from change logs and Lisp source files.
427 ROOT is the root directory under which to find the files. If called
428 interactively, ROOT is read from the minibuffer. Result is a
429 buffer *Authors* containing authorship information."
430 (interactive "DEmacs source directory: ")
431 (setq root (expand-file-name root))
432 (let ((logs (authors-process-lines "find" root "-name" "ChangeLog*"))
433 (table (make-hash-table :test 'equal))
434 (buffer-name "*Authors*"))
435 (authors-add-fixed-entries table)
436 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
437 (error "Not the root directory of Emacs: %s" root))
438 (dolist (log logs)
439 (when (and (string-match "ChangeLog\\(.[0-9]+\\)?$" log)
440 (not (string-match "/lispref/" log)))
441 (message "Scanning %s..." log)
442 (authors-scan-change-log log table)))
443 (let ((els (authors-process-lines "find" root "-name" "*.el")))
444 (dolist (file els)
445 (message "Scanning %s..." file)
446 (authors-scan-el file table)))
447 (set-buffer (get-buffer-create buffer-name))
448 (erase-buffer)
449 (set-buffer-file-coding-system 'iso-2022-7bit)
450 (maphash #'authors-print table)
451 (sort-lines nil (point-min) (point-max))
452 (insert "\nLocal" " Variables:\ncoding: iso-2022-7bit\nEnd:\n")
453 (unless noninteractive
454 (pop-to-buffer buffer-name))))
455
456
457 (defun batch-update-authors ()
458 "Produce an AUTHORS file.
459 Call this function in batch mode with two command line arguments FILE
460 and ROOT. FILE is the file to write, ROOT is the root directory of
461 the Emacs source tree, from which to build the file."
462 (unless noninteractive
463 (error "`batch-update-authors' is to be used only with -batch"))
464 (when (/= (length command-line-args-left) 2)
465 (error "Call `batch-update-authors' with the name of the file to write"))
466 (let* ((file (pop command-line-args-left))
467 (root (pop command-line-args-left)))
468 (authors root)
469 (write-file file)))
470
471 ;;; authors.el ends here