2 eval 'exec perl -w -S $0 ${1+"$@"}' # Portability kludge
5 # Author: Martin Buchholz
6 # This program is in the public domain.
11 (my $myName = $0) =~ s@.*/@@; my $usage="
14 Finds DOCSTRING arg mismatches between
15 formal parameters, docstrings, and lispref texi.
17 This program is in the public domain.\n";
20 die $usage unless -r "src/alloc.c" && -d "CVS" && -d "lisp";
30 open (FILE, "< $_[0]") or die "$_[0]: $!";
35 my ($show_details, $function, $parms, $docstring) = @_;
37 print "function = $function $parms\n$docstring\n", "-" x 70, "\n";
41 sub Check_texi_function {
42 my ($function, $funtype, $docstring, @parms) = @_;
48 if (exists $texi_funtype{$function}) {
49 print "duplicate texidoc: $function @parms\n";
50 return; # later definition likely bogus package def
53 $texi_funtype{$function} = $funtype;
54 $texi_arglist{$function} = "@parms";
56 foreach my $parm (@parms) {
57 next if $parm eq '&optional' || $parm eq '&rest';
58 $arglist_parm{$parm} = 1;
61 foreach my $parm ($docstring =~ /\@var{([^{}]+)}/g) {
62 $docstring_parm{$parm} = 1;
65 foreach my $hit ($docstring =~ /[^\`]\`[A-Za-z-]+\'/g)
67 print "texi \@code missing: $function: $hit\n";
71 # (my $raw_docstring = $docstring) =~ s/\@var{[^{}]+}//g;
72 # $raw_docstring =~ s/[^a-zA-Z_-]+/ /g;
73 # foreach my $word (split (' ', $raw_docstring)) {
74 # if ($word =~ /^[A-Z][A-Z-]+$/) {
75 # print "Missing \@var: $function: $word\n";
79 foreach my $parm (keys %docstring_parm) {
80 if (! exists $arglist_parm{$parm}) {
81 print "bogus texi parm: $function: $parm\n";
86 foreach my $parm (keys %arglist_parm) {
87 if (! exists $docstring_parm{$parm}) {
88 print "undocumented texi parm: $function: $parm\n";
93 Show_details $show_details, $function, "@parms", $docstring;
97 my ($function, $funtype, $docstring, @parms) = @_;
100 my $show_details = 0;
102 if (exists $code_funtype{$function}) {
103 print "duplicate codedef: $function @parms\n";
104 return; # later definition likely bogus package def
107 $code_funtype{$function} = $funtype;
108 $code_arglist{$function} = "@parms";
109 #foreach my $parm ($parms =~ /\b[a-z0-9-]{3,}\b/g) {
110 # $arglist_parm{$parm} = 1;
112 foreach my $parm (@parms) {
113 next if $parm eq '&optional' || $parm eq '&rest';
114 $arglist_parm{$parm} = 1;
116 my $doc_tmp = $docstring;
117 $doc_tmp =~ s/[^A-Za-z0-9_-]/ /g;
118 foreach my $parm (split (' ', $doc_tmp)) {
119 if ($parm =~ /^[A-Z][A-Z0-9-]*$/) {
120 next if $parm =~ /I18N/;
121 next if $parm =~ /M17N/;
122 $parm =~ tr[A-Z][a-z];
123 $docstring_parm{$parm} = 1;
126 # foreach my $parm ($docstring =~ /\b[A-Z0-9-]{1,}\b/g) {
127 # next if $parm =~ /-$/;
128 # $parm =~ tr[A-Z][a-z];
129 # $docstring_parm{$parm} = 1;
131 foreach my $parm (keys %docstring_parm) {
132 next if $parm eq 'tty';
133 next if $parm eq 'fsf';
134 next if $parm eq 'note';
135 next if $parm eq 'warning';
136 next if $parm eq 'bug';
137 next if $parm eq 'ascii';
138 next if $parm eq 'iso';
139 next if $parm eq 'and';
140 next if $parm eq 'absolutely';
141 next if $parm eq 'doc';
142 next if $parm eq 'user';
143 next if $parm eq 'not';
144 next if $parm eq 'must';
145 next if $parm eq 'nil';
146 next if $parm eq 'esc';
147 next if $parm eq 'lfd';
148 next if $parm eq 'gpm';
149 next if $parm eq 'primary';
150 next if $parm eq 'secondary';
151 next if $parm eq 'clipboard';
152 next if length $parm < 3;
153 if (! exists $arglist_parm{$parm}) {
154 print "bogus parm: $function: $parm\n";
158 foreach my $parm (keys %arglist_parm) {
159 if (! exists $docstring_parm{$parm}) {
160 print "Undocumented parm: $function: $parm\n";
165 if ($docstring !~ /[\]}!\)\.]\s*\Z/m &&
166 $docstring =~ /\S/ &&
167 $docstring !~ /Keywords supported/)
169 print "Missing trailing period: $function\n";
173 if (exists $texi_arglist{$function}
174 and "@parms" ne $texi_arglist{$function}
175 and not ("@parms" eq 'int nargs Lisp-Object *args'
176 && $texi_arglist{$function} =~ /&rest/)) {
177 my @texi_parms = split (' ', $texi_arglist{$function});
178 my @a = ("@parms" =~ /&optional/g);
179 my @b = ("@parms" =~ /&rest/g);
180 my @c = ("@texi_parms" =~ /&optional/g);
181 my @d = ("@texi_parms" =~ /&rest/g);
182 if (@parms != @texi_parms
183 || (@a != @c) || (@b != @d)) {
184 print "serious mismatch: $function: @parms --- @texi_parms\n";
186 print "texi mismatch: $function: @parms --- $texi_arglist{$function}\n";
191 if (exists $texi_funtype{$function}
192 && $texi_funtype{$function} ne $funtype) {
193 print "interactiveness mismatch: $function: $funtype --- $texi_funtype{$function}\n";
197 Show_details $show_details, $function, "@parms", $docstring;
201 if (-d "man/lispref") { $lisprefdir = "man/lispref"; }
202 elsif (-d "lispref") { $lisprefdir = "lispref"; }
203 else { die "Can't find lispref texi directory.\n"; }
205 open (FIND, "find $lisprefdir -name '*.texi' -print |") or die;
206 while (my $file = <FIND>) {
207 my @matches = ((FileContents $file) =~
208 /\@(def(?:fn|un))([^\n]+)\n(.*?)\n\@end def(?:un|fn)/sgo);
209 # /^\@(def(?:un|fn))\s+(.*)\n([.|\n]*?)^\@end def(?:un|fn)\n/mgo);
211 my ($defform, $defn, $docstring) = splice (@matches, 0, 3);
212 #print "defform = $defform\n";
213 #print "defn = $defn\n";
214 #print "docstring = $docstring\n";
215 my ($function, @parms, $funtype);
216 if ($defform eq 'defun') {
217 ($funtype, $function, @parms) = ('Function', split (' ', $defn));
219 die unless $defform eq 'deffn';
220 ($funtype, $function, @parms) = split (' ', $defn);
222 next if $funtype eq '{Syntax' or $funtype eq '{Prefix';
224 Check_texi_function $function, $funtype, $docstring, @parms;
228 open (FIND, "find src -name '*.c' -print |") or die;
229 while (my $file = <FIND>) {
231 ((FileContents $file) =~
232 /\bDEFUN\s*\(\s*\"((?:[^\\\"]|\\.)+)\"\s*,\s*\S+\s*,\s*(\S+)\s*,\s*(\S+)\s*,\s*((?:0|\"(?:(?:[^\\\"]|\\.)*)\"))\s*,\s*\/\*(.*?)\*\/\s*\(([^()]*)\)\)/sgo);
234 my ($function, $minargs, $maxargs, $interactive, $docstring, $parms) = splice (@matches, 0, 6);
235 $docstring =~ s/^\n+//s;
236 $docstring =~ s/\n+$//s;
238 my @parms = split (' ',$parms);
239 for (@parms) { tr/_/-/; s/-$//; }
240 if ($parms !~ /Lisp_Object/) {
241 if ($minargs < @parms) {
242 if ($maxargs =~ /^\d+$/) {
243 die unless $maxargs eq @parms;
244 splice (@parms, $minargs, 0, '&optional');
248 my $funtype = ($interactive =~ /\"/ ? 'Command' : 'Function');
249 Check_function $function, $funtype, $docstring, @parms;
254 if (-d "../xemacs-packages") {
255 @pkgs = qw (libs/edebug libs/xemacs-base comm/eudc oa/edit-utils);
259 for (@pkgs) { s@^@../xemacs-packages/@; }
260 open (FIND, "find lisp @pkgs -name '*.el' -print |") or die;
261 while (my $file = <FIND>) {
262 my $contents = FileContents $file;
263 $contents =~ s/(?:\s|;);.*//mog;
266 /\((def(?:un|subst|macro))\s+(\S+)\s+\(([^()]*)\)\s+\"((?:[^\\\"]|\\.)+)\"(.*?)\)/sgo);
268 my ($defform, $function, $parms, $docstring, $code_fragment) = splice (@matches, 0, 5);
271 $defform eq 'defmacro' ? 'Macro' :
272 $code_fragment =~ /^\s*\(interactive\b/so ? 'Command' :
275 $docstring =~ s/^\n+//s;
276 $docstring =~ s/\n+$//s;
278 my @parms = split (' ', $parms);
280 Check_function $function, $funtype, $docstring, @parms;
284 open (FIND, "find lisp @pkgs -name '*.el' -print |") or die;
285 while (my $file = <FIND>) {
286 my $contents = FileContents $file;
287 $contents =~ s/(?:\s|;);.*//mog;
289 my @matches = ($contents =~ /^\((?:defalias|fset|define-function)\s+\'([A-Za-z0-9_-]+)\s+\'([A-Za-z0-9_-]+)/mog);
291 my ($alias, $aliasee) = splice (@matches, 0, 2);
292 print "alias $alias aliasee $aliasee\n";
293 if (exists $code_funtype{$aliasee}) { $code_funtype{$alias} = $code_funtype{$aliasee}; }
294 if (exists $code_arglist{$aliasee}) { $code_arglist{$alias} = $code_arglist{$aliasee}; }
298 foreach my $fun (sort keys %texi_funtype) {
299 if (not exists $code_funtype{$fun}) {
300 print "nuke-this-doc: $fun $texi_funtype{$fun}\n";