1;;; authors.el --- utility for maintaining Emacs' AUTHORS file -*-coding: iso-2022-7bit;-*-
2
3;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,
4;;   2006, 2007 Free Software Foundation, Inc.
5
6;; Author: Gerd Moellmann <gerd@gnu.org>
7;; Maintainer: Kim F. Storm <storm@cua.dk>
8;; Keywords: maint
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING.  If not, write to the
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
26
27;;; Commentary:
28
29;; Use M-x authors RET to create an *Authors* buffer that can used as
30;; or merged with Emacs' AUTHORS file.
31
32;;; Code:
33
34(defvar authors-coding-system 'iso-2022-7bit
35  "Coding system used in the AUTHORS file.")
36
37(defconst authors-many-files 20
38  "Maximum number of files for which to print individual information.
39If an author has modified more files, only the names of the most
40frequently modified files are printed and a count of the additional
41files.")
42
43(defconst authors-aliases
44  '(
45    ("Andrew Csillag" "Drew Csillag")
46    ("Anna M. Bigatti" "Anna Bigatti")
47    ("Barry A. Warsaw" "Barry A. Warsaw, Century Computing, Inc."
48     "Barry A. Warsaw, ITB" "Barry Warsaw")
49    ("Bj,Av(Brn Torkelsson" "Bjorn Torkelsson")
50    ("Brian Fox" "Brian J. Fox")
51    ("Christoph Wedler" "Christoph.Wedler@sap.com")
52    ("Daniel Pfeiffer" "<Daniel.Pfeiffer@Informatik.START.db.de>"
53     "<Daniel.Pfeiffer@Informatik.START.dbp.de>")
54    ("David Gillespie" "Dave Gillespie")
55    ("David K,Ae(Bgedal" "David K..edal")
56    ("David M. Koppelman" "David M. Koppelman, Koppel@Ee.Lsu.Edu"
57     "David Koppelman")
58    ("David M. Smith" "David Smith" "David M Smith")
59    ("Ed L. Cashin" "Ed L Cashin")
60    ("Edward M. Reingold" "Ed Reingold" "Edward M Reingold"
61     "Reingold Edward M")
62    ("Eli Zaretskii" "eliz")
63    ("Emilio C. Lopes" "Emilio Lopes")
64    ("Era Eriksson" "Era@Iki.Fi")
65    ("Eric M. Ludlam" "Eric Ludlam")
66    ("Eric S. Raymond" "Eric Raymond")
67    ("Eric Youngdale" "(Eric Youngdale at youngdale@v6550c.nrl.navy.mil)")
68    ("Francis J. Wright" "Dr Francis J. Wright" "Francis Wright")
69    ("Fran,Ag(Bois Pinard" "Francois Pinard")
70    ("Francesco Potort,Al(B" "Francesco Potorti" "Francesco Potorti`")
71    ("Frederic Pierresteguy" "Fred Pierresteguy")
72    ("Geoff Voelker" "voelker")
73    ("Gerd M,Av(Bllmann" "Gerd Moellmann")
74    ("Hallvard B. Furuseth" "Hallvard B Furuseth")
75    ("Hrvoje Nik,B9(Bi,Bf(B" "Hrvoje Niksic")
76    (nil "(afs@hplb.hpl.hp.com)")
77    (nil "<Use-Author-Address-Header@\\[127.1\\]>")
78    (nil "Code Extracted")
79    (nil "\\`FSF")
80    (nil "ISO-2022-JP")
81    ("Jaeyoun Chung" "Jae-youn Chung" "Jae-you Chung" "Chung Jae-youn")
82    ("Jan Dj,Ad(Brv" "Jan D." "Jan Djarv")
83    ("Jay K. Adams" "jka@ece.cmu.edu" "Jay Adams")
84    ("J,Ai(Br,At(Bme Marant" "J,bi(Br,bt(Bme Marant" "Jerome Marant")
85    ("Jens-Ulrik Holger Petersen" "Jens-Ulrik Petersen")
86    ("Jeremy Bertram Maitin-Shepard" "Jeremy Maitin-Shepard")
87    ("Johan Bockg,Ae(Brd" "Johan Bockgard")
88    ("John W. Eaton" "John Eaton")
89    ("Jonathan I. Kamens" "Jonathan Kamens")
90    ("Joseph Arceneaux" "Joe Arceneaux")
91    ("Juan Le,As(Bn Lahoz Garc,Am(Ba" "Juan-Leon Lahoz Garcia")
92    ("K. Shane Hartman" "Shane Hartman")
93    ("Kai Gro,A_(Bjohann" "Kai Grossjohann" "Kai Gro,b_(Bjohann"
94     "Kai.Grossjohann@Cs.Uni-Dortmund.De"
95     "Kai.Grossjohann@Gmx.Net")
96    ("Karl Berry" "K. Berry")
97    ("K,Aa(Broly L$,1 q(Brentey" "K,Aa(Broly L,Bu(Brentey" "L$,1 q(Brentey K,Aa(Broly")
98    ("Kazushi Marukawa" "Kazushi")
99    ("Ken Manheimer" "Kenneth Manheimer")
100    ("Kenichi Handa" "Ken'ichi Handa" "Kenichi HANDA")
101    ("Kevin Greiner" "Kevin J. Greiner")
102    ("Kim F. Storm" "Kim Storm")
103    ("Kyle Jones" "Kyle E. Jones")
104    ("Marcus G. Daniels" "Marcus Daniels")
105    ("Mark D. Baushke" "Mark D Baushke")
106    ("Agust,Am(Bn Mart,Am(Bn" "Agustin Martin")
107    ("Martin Lorentzon" "Martin Lorentzson")
108    ("Matt Swift" "Matthew Swift")
109    ("Michael R. Mauger" "Michael Mauger")
110    ("Michael D. Ernst" "Michael Ernst")
111    ("Micha,Ak(Bl Cadilhac" "Michael Cadilhac")
112    ("Michael I. Bushnell" "Michael I Bushnell" "Michael I. Bushnell, P/Bsg")
113    ("Mikio Nakajima" "Nakajima Mikio")
114    ("Paul Eggert" "eggert")
115    ("Paul Reilly" "(pmr@legacy.pajato.com)")
116    ("Pavel Jan,Bm(Bk" "Pavel Jan,Am(Bk Ml." "Pavel Jan,Am(Bk" "Pavel@Janik.Cz")
117    ("Per Abrahamsen" "Per Abhiddenware")
118    ("Peter S. Galbraith" "Peter Galbraith")
119    ("Peter Runestig" "Peter 'luna' Runestig")
120    ("Peter S. Galbraith" "Peter S Galbraith")
121    ("Richard M. Stallman" "Richard M. Stallman,,," "Richard Stallman"
122     "rms" "rms@gnu.org")
123    ("Robert J. Chassell" "Bob Chassell")
124    ("Roland B. Roberts" "Roland B Roberts" "Roland Roberts")
125    ("Rui-Tao Dong" "Rui-Tao Dong ~{6-Hpln~}")
126    ("Sacha Chua" "Sandra Jean Chua")
127    ("Sam Steingold" "Sam Shteingold")
128    ("Satyaki Das" "Indexed search by Satyaki Das")
129    ("Stefan Monnier" "Stefan")
130    ("Stephen A. Wood" "(saw@cebaf.gov)")
131    ("Steven L. Baur" "SL Baur" "Steven L Baur")
132    ("Takaaki Ota" "Tak Ota")
133    ("Takahashi Naoto" "Naoto Takahashi")
134    ("Teodor Zlatanov" "Ted Zlatanov")
135    ("Torbj,Av(Brn Axelsson" "Torbjvrn Axelsson")
136    ("Torbj,Av(Brn Einarsson" "Torbj.*rn Einarsson")
137    ("Toru Tomabechi" "Toru Tomabechi,")
138    ("Vincent Del Vecchio" "Vince Del Vecchio")
139    ("William M. Perry" "Bill Perry")
140    ("Wlodzimierz Bzyl" "W.*dek Bzyl")
141    ("Yutaka NIIBE" "NIIBE Yutaka")
142    )
143  "Alist of author aliases.
144
145Each entry is of the form (REALNAME REGEXP...).  If an author's name
146matches one of the REGEXPs, use REALNAME instead.
147If REALNAME is nil, ignore that author.")
148
149
150(defvar authors-public-domain-files
151  '("auto-show\\.el"
152    "form-d2\\.el"
153    "emerge\\.el"
154    "unused\\.el"
155    "vi\\.el"
156    "feedmail\\.el"
157    "mailpost\\.el"
158    "hanoi\\.el"
159    "meese\\.el"
160    "studly\\.el"
161    "modula2\\.el")
162  "List of regexps matching files for which the FSF doesn't need papers.")
163
164
165(defvar authors-obsolete-files-regexps
166  '("vc-\\*\\.el$"
167    "spec.txt$"
168    "vc-\\(rcs\\|cvs\\|sccs\\)-hooks\\.el$")
169  "List of regexps matching obsolete files.
170Changes to files matching one of the regexps in this list are not
171listed.")
172
173(defconst authors-ignored-files
174  '("external-lisp"
175    "lock" "share-lib" "local-lisp"
176    "noleim-Makefile.in"
177    "NEWS" "PROBLEMS" "FAQ" "AUTHORS" "FOR-RELEASE" "TODO")
178  "List of files and directories to ignore.
179Changes to files in this list are not listed.")
180
181(defconst authors-fixed-entries
182  '(("Richard M. Stallman" :wrote "[The original GNU Emacs and numerous files]")
183    ("Joseph Arceneaux" :wrote "xrdb.c")
184    ("Blitz Product Development Corporation" :wrote "ispell.el")
185    ("Frank Bresz" :wrote "diff.el")
186    ("David M. Brown" :wrote "array.el")
187    ("Gary Byers" :changed "xenix.h")
188    ("Shawn M. Carey" :wrote "freebsd.h")
189    ("Eric Decker"  :changed "hp9000s800.h" "hpux.h" "sysdep.c")
190    ("Lawrence R. Dodd" :wrote "dired-x.el")
191    ("Viktor Dukhovni" :wrote "unexsunos4.c")
192    ("Paul Eggert" :wrote "rcs2log" "vcdiff")
193    ("Fred Fish" :changed "unexec.c")
194    ("Tim Fleehart" :wrote "makefile.nt")
195    ("Keith Gabryelski" :wrote "hexl.c")
196    ("Kevin Gallagher" :wrote "flow-ctrl.el")
197    ("Howard Gayle" :wrote "disp-table.el" "iso-syntax.el" "casetab.c")
198    ("Stephen Gildea" :wrote "refcard.tex" "mh-funcs.el" "mh-pick.el")
199    ("David Gillespie" :wrote "cl.texinfo")
200    ("Hewlett-Packard" :changed "emacsclient.c" "emacsserver.c"
201     "server.el" "keyboard.c")
202    ("Thomas Horsley" :wrote "cxux.h" "cxux7.h")
203    ("Indiana University Foundation" :changed "buffer.c" "buffer.h"
204     "indent.c" "search.c" "xdisp.c" "region-cache.c" "region-cache.h")
205    ("International Business Machines" :changed "emacs.c" "fileio.c"
206     "ibmrt.h" "process.c" "sysdep.c" "unexec.c" "ibmrt-aix.h")
207    ("Ishikawa Chiaki" :changed "aviion.h" "dgux.h")
208    ("Michael K. Johnson" :changed "configure.in" "emacs.c" "intel386.h"
209     "mem-limits.h" "process.c" "template.h" "sysdep.c" "syssignal.h" "systty.h" "unexec.c"
210      "ymakefile" "linux.h")
211    ("Kyle Jones" :wrote "mldrag.el")
212    ("Henry Kautz" :wrote "bib-mode.el")
213    ("Joseph M. Kelsey" :changed "fileio.c" "vms-pwd.h" "vmsfns.c" "dir.h"
214     "uaf.h")
215    ("Sam Kendall" :changed "etags.c" "etags.el")
216    ("Richard King" :wrote "backquote.el" "userlock.el" "filelock.c")
217    ("Larry Kolodney" :wrote "cvtmail.c")
218    ("Sebastian Kremer" :changed "add-log.el")
219    ("Mark Lambert" :changed "process.c" "process.h")
220    ("Aaron Larson" :changed "bibtex.el")
221    ("James R. Larus" :wrote "mh-e.el")
222    ("Lars Lindberg" :changed "dabbrev.el" :wrote "imenu.el")
223    ("Lucid, Inc." :changed "bytecode.c" "byte-opt.el" "byte-run.el"
224     "bytecomp.el" "delsel.el" "disass.el" "faces.el" "font-lock.el"
225     "lmenu.el" "lselect.el" "mailabbrev.el" "select.el" "xfaces.c"
226     "xselect.c")
227    ("MCC" :changed "etags.c" "emacsclient.c" "emacsserver.c" "movemail.c"
228     "rmail.el" "rmailedit.el" "rmailkwd.el"
229     "rmailmsc.el" "rmailout.el" "rmailsum.el" "scribe.el"
230     "server.el" "lisp.h" "sysdep.c" "unexec.c" :wrote "xmenu.c")
231    ("Niall Mansfield" :changed "etags.c")
232    ("Brian Marick" :wrote "hideif.el")
233    ("Marko Kohtala" :changed "info.el")
234    ("Sidney Markowitz" :changed "doctor.el")
235    ("Richard Mlynarik" :wrote "env.c" "ehelp.el")
236    ("Mosur Mohan" :changed "etags.c")
237    ("Jeff Morgenthaler" :changed "flow-ctrl.el" "vt200.el" "vt201.el"
238     "vt220.el" "vt240.el")
239    ("Motorola" :changed "buff-menu.el")
240    ("Hiroshi Nakano" :changed "ralloc.c")
241    ("Sundar Narasimhan" :changed "rnewspost.el")
242    ("NeXT, Inc." :wrote "unexnext.c")
243    ("Mark Neale" :changed "fortran.el")
244    ("Martin Neitzel" :changed "sc.el")
245    ("Andrew Oram" :changed "miscellaneous changes to files in man/"
246     "man/calendar.texi")
247    ("Frederic Pierresteguy" :wrote "widget.c")
248    ("Michael D. Prange" :changed "tex-mode.el")
249    ("Paul Reilly" :wrote "gux5-4r2.h" "dgux5-4r3.h")
250    ("Roland B. Roberts" :changed "files.el" "sort.el" "vmsproc.el"
251     "buffer.h" "callproc.c" "dired.c" "process.c" "sysdep.c" "systty.h"
252     "vmspaths.h" "build.com" "compile.com" "kepteditor.com" "precomp.com"
253     :wrote "logout.com" "mailemacs.com")
254    ("Guillermo J. Rozas" :wrote "fakemail.c")
255    ("Wolfgang Rupprecht" :changed "lisp-mode.el" "loadup.el"
256     "sort.el" "alloc.c" "callint.c"
257     "config.h.in" "crt0.c" "data.c" "fns.c"
258     "lisp.h" "lread.c" "sun3.h"
259     "print.c" "ymakefile" :wrote "float-sup.el" "floatfns.c")
260    ("Schlumberger Technology Corporation" :changed "gud.el")
261    ("Gregor Schmid" :wrote "tcl-mode.el")
262    ("Rainer Schoepf" :wrote "alpha.h" "unexalpha.c")
263    ("William Sommerfeld" :wrote "emacsclient.c" "emacsserver.c" "scribe.el")
264    ("Leigh Stoller" :changed "emacsclient.c" "emacsserver.c" "server.el")
265    ("Steve Strassman" :wrote "spook.el")
266    ("Shinichirou Sugou" :changed "etags.c")
267    ("Sun Microsystems, Inc" :changed "emacsclient.c" "emacsserver.c"
268     "server.el" :wrote "emacs.icon" "emacstool.1" "emacstool.c" "sun-curs.el"
269     "sun-fns.el" "sun-mouse.el" "sun.el" "sunfns.c")
270    ("Kayvan Sylvan" :changed "sc.el")
271    ("Spencer Thomas" :changed "emacsclient.c" "emacsserver.c" "server.el"
272     "dabbrev.el" "unexec.c" "tcp.c" "gnus.texi")
273    ("Jonathan Vail" :changed "vc.el")
274    ("James Van Artsdalen" :changed "usg5-4.h" "unexec.c")
275    ("Geoff Voelker" :wrote "src/makefile.nt" "lisp/makefile.nt" "winnt.el"
276     "nt.c" "nt.h" "ntheap.c" "ntheap.h" "ntinevt.c"
277     "ntproc.c" "ntterm.c" "windowsnt.h")
278    ("Morten Welinder" :wrote "dosfns.c" "[many MSDOS files]" "msdos.h")
279    ("Pace Willisson" :wrote "ispell.el")
280    ("Garrett Wollman" :changed "sendmail.el")
281    ("Dale R. Worley" :changed "mail-extr.el")
282    ("Jamie Zawinski" :changed "bytecode.c" :wrote "disass.el" "tar-mode.el"))
283  "Actions taken from the original, manually (un)maintained AUTHORS file.")
284
285
286(defconst authors-valid-file-names
287  '("aclocal.m4"
288    "makedist.bat"
289    "make-delta")
290  "File names which are valid, but no longer exists (or cannot be
291found) in the repository.")
292
293(defconst authors-renamed-files-alist
294  '(("nt.c" . "w32.c") ("nt.h" . "w32.h")
295    ("ntheap.c" . "w32heap.c") ("ntheap.h" . "w32heap.h")
296    ("ntinevt.c" . "w32inevt.c") ("ntinevt.h" . "w32inevt.h")
297    ("ntproc.c" . "w32proc.c")
298    ("w32console.c" . "w32term.c")
299    ("unexnt.c" . "unexw32.c")
300    ("s/windowsnt.h" . "s/ms-w32.h")
301    ("config.emacs" . "configure")
302    ("GETTING.GNU.SOFTWARE" . "FTP")
303    ("leim-Makefile" . "leim/Makefile")
304    ("leim-Makefile.in" . "leim/Makefile.in")
305    ("emacs-lisp/testcover-ses.el" . "tcover-ses.el")
306    ("emacs-lisp/testcover-unsafep.el" . "tcover-unsafep.el")
307    ("INSTALL-CVS" . "INSTALL.CVS")
308    )
309  "Alist of files which have been renamed during their lifetime.
310Elements are (OLDNAME . NEWNAME).")
311
312(defconst authors-renamed-files-regexps
313  '(("^m/m-\\(.*\\.h\\)$" . "m/\\1")
314    ("^m-\\(.*\\.h\\)$" . "\\1")
315    ("^s/s-\\(.*\\.h\\)$" . "s/\\1")
316    ("^s-\\(.*\\.h\\)$" . "\\1")
317    ("^s/[-.a-zA-Z0-9_]+\\.h$" . t)
318    ("\\(.*\\)\\.cmd$" . "\\1.bat")
319    ("\\.bat$" . t)
320    ("\\.[ch]$" . t)
321    ("\\.el$" . t)
322    ("\\.ps$" . t)
323    ("\\.texi?$" . t)
324    ("\\.texinfo$" . t)
325    ("\\.xml?$" . t)
326    ("\\.x[pb]m$" . t)
327    ("\\.[xp]bm$" . t)
328    ("^paths\\." . t)
329    ("^install\\." . t)
330    )
331  "List regexps and rewriting rules for renamed files.
332Elements are (REGEXP . REPLACE).  If REPLACE is a string, the file
333name matching REGEXP is replaced by REPLACE using `replace-string'.
334Otherwise, the file name is accepted as is.")
335
336(defvar authors-checked-files-alist)
337(defvar authors-invalid-file-names)
338
339(defun authors-canonical-file-name (file log-file pos author)
340  "Return canonical file name for FILE found in LOG-FILE at POS for AUTHOR.
341Checks whether FILE is a valid (existing) file name, has been renamed,
342or is on the list of removed files.  Returns the non-diretory part of
343the file name."
344  (let ((entry (assoc file authors-checked-files-alist))
345	relname
346	valid)
347    (if entry
348	(cdr entry)
349      (setq relname (file-name-nondirectory file))
350      (if (or (member relname authors-valid-file-names)
351	      (file-exists-p file)
352	      (file-exists-p relname)
353	      (file-exists-p (concat "etc/" relname)))
354	  (setq valid relname)
355	(setq valid (assoc file authors-renamed-files-alist))
356	(if valid
357	    (setq valid (cdr valid))
358	  (let ((rules authors-renamed-files-regexps))
359	    (while rules
360	      (if (string-match (car (car rules)) file)
361		  (setq valid (if (stringp (cdr (car rules)))
362				  (file-name-nondirectory
363				   (replace-match (cdr (car rules)) t nil file))
364				relname)
365			rules nil))
366	      (setq rules (cdr rules))))))
367      (setq authors-checked-files-alist
368	    (cons (cons file valid) authors-checked-files-alist))
369      (unless (or valid
370		  (string-match "[*]" file)
371		  (string-match "^[0-9.]+$" file))
372	(setq authors-invalid-file-names
373	      (cons (format "%s:%d: unrecognized `%s' for %s"
374			    log-file
375			    (1+ (count-lines (point-min) pos))
376			    file author)
377		    authors-invalid-file-names)))
378      valid)))
379
380(defun authors-add-fixed-entries (table)
381  "Add actions from `authors-fixed-entries' to TABLE."
382  (dolist (entry authors-fixed-entries)
383    (let ((author (car entry))
384	  action)
385      (dolist (item (cdr entry))
386	(if (symbolp item)
387	    (setq action item)
388	  (authors-add author item action table))))))
389
390
391(defun authors-obsolete-file-p (file)
392  "Return non-nil if FILE is obsolete.
393FILE is considered obsolete if it matches one of the regular expressions
394from `authors-obsolete-files-regexps'."
395  (let (obsolete-p
396	(regexps authors-obsolete-files-regexps))
397    (while (and regexps (not obsolete-p))
398      (setq obsolete-p (string-match (car regexps) file)
399	    regexps (cdr regexps)))
400    obsolete-p))
401
402
403(defun authors-add (author file action table)
404  "Record that AUTHOR worked on FILE.
405ACTION is a keyword symbol describing what he did.  Record file,
406author and what he did in hash table TABLE.  See the description of
407`authors-scan-change-log' for the structure of the hash table."
408  (unless (or (member file authors-ignored-files)
409	      (authors-obsolete-file-p file)
410	      (equal author ""))
411    (let* ((value (gethash author table))
412	   (entry (assoc file value))
413	   slot)
414      (if (null entry)
415	  (puthash author (cons (list file (cons action 1)) value) table)
416	(if (setq slot (assoc action (cdr entry)))
417	    (setcdr slot (1+ (cdr slot)))
418	  (nconc entry (list (cons action 1))))))))
419
420
421(defun authors-process-lines (program &rest args)
422  "Execute PROGRAM with ARGS, returning its output as a list of lines.
423Signal an error if the program returns with a non-zero exit status."
424  (with-temp-buffer
425    (let ((status (apply 'call-process program nil (current-buffer) nil args)))
426      (unless (eq status 0)
427	(error "%s exited with status %s" program status))
428      (goto-char (point-min))
429      (let (lines)
430	(while (not (eobp))
431	  (setq lines (cons (buffer-substring-no-properties
432			     (line-beginning-position)
433			     (line-end-position))
434			    lines))
435	  (forward-line 1))
436	(nreverse lines)))))
437
438
439(defun authors-canonical-author-name (author)
440  "Return a canonicalized form of AUTHOR, an author name.
441If AUTHOR has an alias, use that.  Remove email addresses.  Capitalize
442words in the author's name."
443  (let* ((aliases authors-aliases)
444	 regexps realname)
445    (while aliases
446      (setq realname (car (car aliases))
447	    regexps (cdr (car aliases))
448	    aliases (cdr aliases))
449      (while regexps
450	(if (string-match (car regexps) author)
451	    (setq author realname
452		  regexps nil
453		  aliases nil)
454	  (setq regexps (cdr regexps))))))
455  (when author
456    (setq author (replace-regexp-in-string "[ \t]*[(<].*$" "" author))
457    (setq author (replace-regexp-in-string "\`[ \t]+" "" author))
458    (setq author (replace-regexp-in-string "[ \t]+$" "" author))
459    (setq author (replace-regexp-in-string "[ \t]+" " " author))
460    (unless (string-match "[-, \t]" author)
461      (setq author ""))
462    (capitalize author)))
463
464(defun authors-scan-change-log (log-file table)
465  "Scan change log LOG-FILE for author information.
466
467For each change mentioned in the log, add an entry to hash table TABLE
468under the author's canonical name.
469
470Keys of TABLE are author names.  Values are alists of entries (FILE
471\(ACTION . COUNT) ...).  FILE is one file the author worked on.  The
472rest of the entry is a list of keyword symbols describing what he did
473with the file and the number of each action.
474
475:wrote		means the author wrote the file
476:changed	means he changed the file COUNT times."
477
478  (let* ((enable-local-variables t)
479	 (enable-local-eval t)
480	 (existing-buffer (get-file-buffer log-file))
481	 (buffer (find-file-noselect log-file))
482	 author file pos)
483    (save-excursion
484      (set-buffer buffer)
485      (save-restriction
486	(widen)
487	(goto-char (point-min))
488	(while (re-search-forward "^[0-9]\\|^[ \t]+\\* " nil t)
489	  (beginning-of-line)
490	  (setq pos (point))
491	  (cond ((looking-at "^[0-9]+-[0-9]+-[0-9]+")
492		 (skip-chars-forward " \t+:0-9-")
493		 (setq author (buffer-substring-no-properties
494			       (point) (line-end-position)))
495		 (setq author (authors-canonical-author-name author))
496		 (forward-line 1))
497		((looking-at "^[ \t]+\\*")
498		 (let ((line (buffer-substring-no-properties
499			      (match-end 0) (line-end-position))))
500		   (while (and (not (string-match ":" line))
501			       (forward-line 1)
502			       (not (looking-at ":\\|^[ \t]*$")))
503		     (setq line (concat line
504					(buffer-substring-no-properties
505					 (line-beginning-position)
506					 (line-end-position)))))
507		   (when (string-match ":" line)
508		     (setq line (substring line 0 (match-beginning 0)))
509		     (setq line (replace-regexp-in-string "[[(<{].*$" "" line))
510		     (setq line (replace-regexp-in-string "," "" line))
511		     (dolist (file (split-string line))
512		       (when (setq file (authors-canonical-file-name file log-file pos author))
513			 ;;(message "%s changed %s" author file)
514			 (authors-add author file :changed table))))
515		   (forward-line 1)))))))
516    (unless existing-buffer
517      (kill-buffer buffer))))
518
519
520(defun authors-scan-el (file table)
521  "Scan Lisp file FILE for author information.
522TABLE is a hash table to add author information to."
523  (let* ((existing-buffer (get-file-buffer file))
524	 (enable-local-variables t)
525	 (enable-local-eval t)
526	 (buffer (find-file-noselect file)))
527    (save-excursion
528      (set-buffer buffer)
529      (save-restriction
530	(widen)
531	(goto-char (point-min))
532	(while (and (re-search-forward
533		     "^;+[ \t]*\\(Author\\|Commentary\\):[ \t]*" nil t)
534		    (not (string= (match-string 1) "Commentary")))
535	  ;; Some entries contain a year range in front of the
536	  ;; author's name.
537	  (skip-chars-forward "-0-9 \t")
538	  (let ((author (buffer-substring-no-properties
539			 (point) (line-end-position))))
540	    (setq author (authors-canonical-author-name author))
541	    (setq file (file-name-nondirectory file))
542	    (authors-add author file :wrote table)))))
543    (unless existing-buffer
544      (kill-buffer buffer))))
545
546
547(defun authors-public-domain-p (file)
548  "Return t if FILE is a file that was put in public domain."
549  (let ((public-domain-p nil)
550	(list authors-public-domain-files))
551    (while (and list (not public-domain-p))
552      (when (string-match (car list) file)
553	(setq public-domain-p t))
554      (setq list (cdr list)))
555    public-domain-p))
556
557(defvar authors-author-list)
558
559(defun authors-add-to-author-list (author changes)
560  "Insert information about AUTHOR's work on Emacs into `authors-author-list'.
561CHANGES is an alist of entries (FILE (ACTION . COUNT) ...), as produced by
562`authors-scan-change-log'.
563The element added to `authors-author-list' is (AUTHOR WROTE CHANGED), where
564WROTE and CHANGED are lists of the files written and changed by AUTHOR."
565  (when author
566    (let ((nchanged 0)
567	  wrote-list
568	  changed-list)
569      (dolist (change changes)
570	(let ((actions (cdr change))
571	      (file (car change))
572	      slot)
573	  (if (assq :wrote actions)
574	      (setq wrote-list
575		    (cons
576		     (if (authors-public-domain-p file)
577			 (concat file " (public domain)")
578		       file)
579		     wrote-list))
580	    (setq changed-list
581		  (cons (cons file (cdr (assq :changed actions)))
582			changed-list)))))
583      (if wrote-list
584	  (setq wrote-list (sort wrote-list 'string-lessp)))
585      (when changed-list
586	(setq changed-list (sort changed-list
587				 (lambda (a b)
588				   (if (= (cdr a) (cdr b))
589				       (string-lessp (car a) (car b))
590				     (> (cdr a) (cdr b))))))
591	(setq nchanged (length changed-list))
592	(setq changed-list (mapcar 'car changed-list)))
593      (if (> (- nchanged authors-many-files) 2)
594	  (setcdr (nthcdr authors-many-files changed-list)
595		  (list (format "and %d other files" (- nchanged authors-many-files)))))
596      (setq authors-author-list
597	    (cons (list author wrote-list changed-list)
598		  authors-author-list)))))
599
600(defun authors (root)
601  "Extract author information from change logs and Lisp source files.
602ROOT is the root directory under which to find the files.  If called
603interactively, ROOT is read from the minibuffer.
604Result is a buffer *Authors* containing authorship information, and a
605buffer *Authors Errors* containing references to unknown files."
606  (interactive "DEmacs source directory: ")
607  (setq root (expand-file-name root))
608  (let ((logs (authors-process-lines "find" root "-name" "ChangeLog*"))
609	(table (make-hash-table :test 'equal))
610	(buffer-name "*Authors*")
611	authors-checked-files-alist
612	authors-invalid-file-names)
613    (authors-add-fixed-entries table)
614    (unless (file-exists-p (expand-file-name "src/emacs.c" root))
615      (error "Not the root directory of Emacs: %s" root))
616    (dolist (log logs)
617      (when (string-match "ChangeLog\\(.[0-9]+\\)?$" log)
618	(message "Scanning %s..." log)
619	(authors-scan-change-log log table)))
620    (let ((els (authors-process-lines "find" root "-name" "*.el")))
621      (dolist (file els)
622	(message "Scanning %s..." file)
623	(authors-scan-el file table)))
624    (message "Generating buffer %s..." buffer-name)
625    (set-buffer (get-buffer-create buffer-name))
626    (erase-buffer)
627    (set-buffer-file-coding-system authors-coding-system)
628    (insert
629"Many people have contributed code included in the Free Software
630Foundation's distribution of GNU Emacs.  To show our appreciation for
631their public spirit, we list here in alphabetical order a condensed
632list of their contributions.\n")
633    (let (authors-author-list a)
634      (maphash #'authors-add-to-author-list table)
635      (setq authors-author-list
636	    (sort authors-author-list
637		  (lambda (a b) (string-lessp (car a) (car b)))))
638      (dolist (a authors-author-list)
639	(let ((author (car a))
640	      (wrote (nth 1 a))
641	      (changed (nth 2 a))
642	      file)
643	(insert "\n" author ": ")
644	(when wrote
645	  (insert "wrote")
646	  (dolist (file wrote)
647	    (if (> (+ (current-column) (length file)) 72)
648	      (insert "\n "))
649	    (insert " " file))
650	  (insert "\n"))
651	(when changed
652	  (if wrote
653	      (insert "and "))
654	  (insert "changed")
655	  (dolist (file changed)
656	    (if (> (+ (current-column) (length file)) 72)
657		(insert "\n "))
658	    (insert " " file))
659	  (insert "\n")))))
660    (insert "\nLocal" " Variables:\ncoding: "
661	    (symbol-name authors-coding-system) "\nEnd:\n")
662    (message "Generating buffer %s... done" buffer-name)
663    (unless noninteractive
664      (when authors-invalid-file-names
665	(with-current-buffer (get-buffer-create "*Authors Errors*")
666	  (erase-buffer)
667	  (set-buffer-file-coding-system authors-coding-system)
668	  (insert "Unrecognized file entries found:\n\n")
669	  (mapcar (lambda (f) (if (not (string-match "^[A-Za-z]+$" f)) (insert f "\n")))
670		  (sort authors-invalid-file-names 'string-lessp))
671	  (goto-char (point-min))
672	  (compilation-mode)
673	  (message "Errors were found.  See buffer %s" (buffer-name))))
674      (pop-to-buffer buffer-name))))
675
676
677(defun batch-update-authors ()
678  "Produce an AUTHORS file.
679Call this function in batch mode with two command line arguments FILE
680and ROOT.  FILE is the file to write, ROOT is the root directory of
681the Emacs source tree, from which to build the file."
682  (unless noninteractive
683    (error "`batch-update-authors' is to be used only with -batch"))
684  (when (/= (length command-line-args-left) 2)
685    (error "Call `batch-update-authors' with the name of the file to write"))
686  (let* ((file (pop command-line-args-left))
687	 (root (pop command-line-args-left)))
688    (authors root)
689    (write-file file)))
690
691(provide 'authors)
692
693;;; arch-tag: 659d5900-5ff2-43b0-954c-a315cc1e4dc1
694;;; authors.el ends here
695