2 eval 'exec perl -w -S $0 ${1+"$@"}' # Portability kludge
3 if 0; # Author: Martin Buchholz
8 (my $myName = $0) =~ s@.*/@@; my $usage="
11 Finds DOCSTRING arg mismatches between
12 formal parameters, docstrings, and lispref texi.
14 This program is in the public domain.\n";
17 die $usage unless -r "src/alloc.c" && -d "CVS" && -d "lisp";
27 open (FILE, "< $_[0]") or die "$_[0]: $!";
32 my ($show_details, $function, $parms, $docstring) = @_;
34 print "function = $function $parms\n$docstring\n", "-" x 70, "\n";
38 sub Check_texi_function {
39 my ($function, $funtype, $docstring, @parms) = @_;
45 if (exists $texi_funtype{$function}) {
46 print "duplicate texidoc: $function @parms\n";
47 return; # later definition likely bogus package def
50 $texi_funtype{$function} = $funtype;
51 $texi_arglist{$function} = "@parms";
53 foreach my $parm (@parms) {
54 next if $parm eq '&optional' || $parm eq '&rest';
55 $arglist_parm{$parm} = 1;
58 foreach my $parm ($docstring =~ /\@var{([^{}]+)}/g) {
59 $docstring_parm{$parm} = 1;
62 foreach my $hit ($docstring =~ /[^\`]\`[A-Za-z-]+\'/g)
64 print "texi \@code missing: $function: $hit\n";
68 # (my $raw_docstring = $docstring) =~ s/\@var{[^{}]+}//g;
69 # $raw_docstring =~ s/[^a-zA-Z_-]+/ /g;
70 # foreach my $word (split (' ', $raw_docstring)) {
71 # if ($word =~ /^[A-Z][A-Z-]+$/) {
72 # print "Missing \@var: $function: $word\n";
76 foreach my $parm (keys %docstring_parm) {
77 if (! exists $arglist_parm{$parm}) {
78 print "bogus texi parm: $function: $parm\n";
83 foreach my $parm (keys %arglist_parm) {
84 if (! exists $docstring_parm{$parm}) {
85 print "undocumented texi parm: $function: $parm\n";
90 Show_details $show_details, $function, "@parms", $docstring;
94 my ($function, $funtype, $docstring, @parms) = @_;
99 if (exists $code_funtype{$function}) {
100 print "duplicate codedef: $function @parms\n";
101 return; # later definition likely bogus package def
104 $code_funtype{$function} = $funtype;
105 $code_arglist{$function} = "@parms";
106 #foreach my $parm ($parms =~ /\b[a-z0-9-]{3,}\b/g) {
107 # $arglist_parm{$parm} = 1;
109 foreach my $parm (@parms) {
110 next if $parm eq '&optional' || $parm eq '&rest';
111 $arglist_parm{$parm} = 1;
113 my $doc_tmp = $docstring;
114 $doc_tmp =~ s/[^A-Za-z0-9_-]/ /g;
115 foreach my $parm (split (' ', $doc_tmp)) {
116 if ($parm =~ /^[A-Z][A-Z0-9-]*$/) {
117 next if $parm =~ /I18N/;
118 next if $parm =~ /M17N/;
119 $parm =~ tr[A-Z][a-z];
120 $docstring_parm{$parm} = 1;
123 # foreach my $parm ($docstring =~ /\b[A-Z0-9-]{1,}\b/g) {
124 # next if $parm =~ /-$/;
125 # $parm =~ tr[A-Z][a-z];
126 # $docstring_parm{$parm} = 1;
128 foreach my $parm (keys %docstring_parm) {
129 next if $parm eq 'tty';
130 next if $parm eq 'fsf';
131 next if $parm eq 'note';
132 next if $parm eq 'warning';
133 next if $parm eq 'bug';
134 next if $parm eq 'ascii';
135 next if $parm eq 'iso';
136 next if $parm eq 'and';
137 next if $parm eq 'absolutely';
138 next if $parm eq 'doc';
139 next if $parm eq 'user';
140 next if $parm eq 'not';
141 next if $parm eq 'must';
142 next if $parm eq 'nil';
143 next if $parm eq 'esc';
144 next if $parm eq 'lfd';
145 next if $parm eq 'gpm';
146 next if $parm eq 'primary';
147 next if $parm eq 'secondary';
148 next if $parm eq 'clipboard';
149 next if length $parm < 3;
150 if (! exists $arglist_parm{$parm}) {
151 print "bogus parm: $function: $parm\n";
155 foreach my $parm (keys %arglist_parm) {
156 if (! exists $docstring_parm{$parm}) {
157 print "Undocumented parm: $function: $parm\n";
162 if ($docstring !~ /[\]}!\)\.]\s*\Z/m &&
163 $docstring =~ /\S/ &&
164 $docstring !~ /Keywords supported/)
166 print "Missing trailing period: $function\n";
170 if (exists $texi_arglist{$function}
171 and "@parms" ne $texi_arglist{$function}
172 and not ("@parms" eq 'int nargs Lisp-Object *args'
173 && $texi_arglist{$function} =~ /&rest/)) {
174 my @texi_parms = split (' ', $texi_arglist{$function});
175 my @a = ("@parms" =~ /&optional/g);
176 my @b = ("@parms" =~ /&rest/g);
177 my @c = ("@texi_parms" =~ /&optional/g);
178 my @d = ("@texi_parms" =~ /&rest/g);
179 if (@parms != @texi_parms
180 || (@a != @c) || (@b != @d)) {
181 print "serious mismatch: $function: @parms --- @texi_parms\n";
183 print "texi mismatch: $function: @parms --- $texi_arglist{$function}\n";
188 if (exists $texi_funtype{$function}
189 && $texi_funtype{$function} ne $funtype) {
190 print "interactiveness mismatch: $function: $funtype --- $texi_funtype{$function}\n";
194 Show_details $show_details, $function, "@parms", $docstring;
198 if (-d "man/lispref") { $lisprefdir = "man/lispref"; }
199 elsif (-d "lispref") { $lisprefdir = "lispref"; }
200 else { die "Can't find lispref texi directory.\n"; }
202 open (FIND, "find $lisprefdir -name '*.texi' -print |") or die;
203 while (my $file = <FIND>) {
204 my @matches = ((FileContents $file) =~
205 /\@(def(?:fn|un))([^\n]+)\n(.*?)\n\@end def(?:un|fn)/sgo);
206 # /^\@(def(?:un|fn))\s+(.*)\n([.|\n]*?)^\@end def(?:un|fn)\n/mgo);
208 my ($defform, $defn, $docstring) = splice (@matches, 0, 3);
209 #print "defform = $defform\n";
210 #print "defn = $defn\n";
211 #print "docstring = $docstring\n";
212 my ($function, @parms, $funtype);
213 if ($defform eq 'defun') {
214 ($funtype, $function, @parms) = ('Function', split (' ', $defn));
216 die unless $defform eq 'deffn';
217 ($funtype, $function, @parms) = split (' ', $defn);
219 next if $funtype eq '{Syntax' or $funtype eq '{Prefix';
221 Check_texi_function $function, $funtype, $docstring, @parms;
225 open (FIND, "find src -name '*.c' -print |") or die;
226 while (my $file = <FIND>) {
228 ((FileContents $file) =~
229 /\bDEFUN\s*\(\s*\"((?:[^\\\"]|\\.)+)\"\s*,\s*\S+\s*,\s*(\S+)\s*,\s*(\S+)\s*,\s*((?:0|\"(?:(?:[^\\\"]|\\.)*)\"))\s*,\s*\/\*(.*?)\*\/\s*\(([^()]*)\)\)/sgo);
231 my ($function, $minargs, $maxargs, $interactive, $docstring, $parms) = splice (@matches, 0, 6);
232 $docstring =~ s/^\n+//s;
233 $docstring =~ s/\n+$//s;
235 my @parms = split (' ',$parms);
236 for (@parms) { tr/_/-/; s/-$//; }
237 if ($parms !~ /Lisp_Object/) {
238 if ($minargs < @parms) {
239 if ($maxargs =~ /^\d+$/) {
240 die unless $maxargs eq @parms;
241 splice (@parms, $minargs, 0, '&optional');
245 my $funtype = ($interactive =~ /\"/ ? 'Command' : 'Function');
246 Check_function $function, $funtype, $docstring, @parms;
251 if (-d "../xemacs-packages") {
252 @pkgs = qw (libs/edebug libs/xemacs-base comm/eudc oa/edit-utils);
256 for (@pkgs) { s@^@../xemacs-packages/@; }
257 open (FIND, "find lisp @pkgs -name '*.el' -print |") or die;
258 while (my $file = <FIND>) {
259 my $contents = FileContents $file;
260 $contents =~ s/(?:\s|;);.*//mog;
263 /\((def(?:un|subst|macro))\s+(\S+)\s+\(([^()]*)\)\s+\"((?:[^\\\"]|\\.)+)\"(.*?)\)/sgo);
265 my ($defform, $function, $parms, $docstring, $code_fragment) = splice (@matches, 0, 5);
268 $defform eq 'defmacro' ? 'Macro' :
269 $code_fragment =~ /^\s*\(interactive\b/so ? 'Command' :
272 $docstring =~ s/^\n+//s;
273 $docstring =~ s/\n+$//s;
275 my @parms = split (' ', $parms);
277 Check_function $function, $funtype, $docstring, @parms;
281 open (FIND, "find lisp @pkgs -name '*.el' -print |") or die;
282 while (my $file = <FIND>) {
283 my $contents = FileContents $file;
284 $contents =~ s/(?:\s|;);.*//mog;
286 my @matches = ($contents =~ /^\((?:defalias|fset|define-function)\s+\'([A-Za-z0-9_-]+)\s+\'([A-Za-z0-9_-]+)/mog);
288 my ($alias, $aliasee) = splice (@matches, 0, 2);
289 print "alias $alias aliasee $aliasee\n";
290 if (exists $code_funtype{$aliasee}) { $code_funtype{$alias} = $code_funtype{$aliasee}; }
291 if (exists $code_arglist{$aliasee}) { $code_arglist{$alias} = $code_arglist{$aliasee}; }
295 foreach my $fun (sort keys %texi_funtype) {
296 if (not exists $code_funtype{$fun}) {
297 print "nuke-this-doc: $fun $texi_funtype{$fun}\n";
301 # arch-tag: e75331f5-5d1b-4393-ad5b-b0f87b5d47b0