Blob


1 # Usage: cd $PLAN9; awk -f dist/checkman.awk man?/*.?
2 #
3 # Checks:
4 # - .TH is first line, and has proper name section number
5 # - sections are in order NAME, SYNOPSIS, DESCRIPTION, EXAMPLES,
6 # FILES, SOURCE, SEE ALSO, DIAGNOSTICS, BUGS
7 # - there's a manual page for each cross-referenced page
9 BEGIN {
11 # .SH sections should come in the following order
13 Weight["NAME"] = 1
14 Weight["SYNOPSIS"] = 2
15 Weight["DESCRIPTION"] = 4
16 Weight["EXAMPLE"] = 8
17 Weight["EXAMPLES"] = 16
18 Weight["FILES"] = 32
19 Weight["SOURCE"] = 64
20 Weight["SEE ALSO"] = 128
21 Weight["DIAGNOSTICS"] = 256
22 Weight["SYSTEM CALLS"] = 512
23 Weight["BUGS"] = 1024
25 Skipdirs["CVS"] = 1
27 # allow references to pages provded
28 # by the underlying Unix system
29 Omitman["awk(1)"] = 1
30 Omitman["bash(1)"] = 1
31 Omitman["chmod(1)"] = 1
32 Omitman["compress(1)"] = 1
33 Omitman["cp(1)"] = 1
34 Omitman["egrep(1)"] = 1
35 Omitman["gs(1)"] = 1
36 Omitman["gv(1)"] = 1
37 Omitman["lex(1)"] = 1
38 Omitman["lp(1)"] = 1
39 Omitman["lpr(1)"] = 1
40 Omitman["mail(1)"] = 1
41 Omitman["nm(1)"] = 1
42 Omitman["prof(1)"] = 1
43 Omitman["pwd(1)"] = 1
44 Omitman["qiv(1)"] = 1
45 Omitman["sh(1)"] = 1
46 Omitman["ssh(1)"] = 1
47 Omitman["stty(1)"] = 1
48 Omitman["tar(1)"] = 1
49 Omitman["tex(1)"] = 1
50 Omitman["unutf(1)"] = 1
51 Omitman["xterm(1)"] = 1
53 Omitman["access(2)"] = 1
54 Omitman["brk(2)"] = 1
55 Omitman["chdir(2)"] = 1
56 Omitman["close(2)"] = 1
57 Omitman["connect(2)"] = 1
58 Omitman["fork(2)"] = 1
59 Omitman["gethostname(2)"] = 1
60 Omitman["getpid(2)"] = 1
61 Omitman["getuid(2)"] = 1
62 Omitman["open(2)"] = 1
63 Omitman["pipe(2)"] = 1
64 Omitman["ptrace(2)"] = 1
65 Omitman["rmdir(2)"] = 1
66 Omitman["send(2)"] = 1
67 Omitman["signal(2)"] = 1
68 Omitman["sigprocmask(2)"] = 1
69 Omitman["socketpair(2)"] = 1
70 Omitman["unlink(2)"] = 1
72 Omitman["abort(3)"] = 1
73 Omitman["assert(3)"] = 1
74 Omitman["fprintf(3)"] = 1
75 Omitman["fscanf(3)"] = 1
76 Omitman["fopen(3)"] = 1
77 Omitman["isalpha(3)"] = 1
78 Omitman["malloc(3)"] = 1
79 Omitman["perror(3)"] = 1
80 Omitman["remove(3)"] = 1
81 Omitman["sin(3)"] = 1
82 Omitman["strerror(3)"] = 1
84 Omitman["factotum(4)"] = 1 # for now leave undocumented
86 Omitman["core(5)"] = 1
87 Omitman["passwd(5)"] = 1
89 Omitman["signal(7)"] = 1
91 Omitman["cron(8)"] = 1
93 # don't need documentation for these in bin
94 Omitted[".cvsignore"] = 1
95 Omitted["Getdir"] = 1
96 Omitted["tcolors"] = 1
97 Omitted["tref"] = 1
98 Omitted["unutf"] = 1
99 Omitted["vtdump"] = 1
101 # not for users
102 Omittedlib["creadimage"] = 1
103 Omittedlib["pixelbits"] = 1
104 Omittedlib["bouncemouse"] = 1
105 Omittedlib["main"] = 1 # in libthread
107 # functions provided for -lthread_db
108 Omittedlib["ps_get_thread_area"] = 1
109 Omittedlib["ps_getpid"] = 1
110 Omittedlib["ps_lcontinue"] = 1
111 Omittedlib["ps_lgetfpregs"] = 1
112 Omittedlib["ps_lgetregs"] = 1
113 Omittedlib["ps_lsetfpregs"] = 1
114 Omittedlib["ps_lsetregs"] = 1
115 Omittedlib["ps_lstop"] = 1
116 Omittedlib["ps_pcontinue"] = 1
117 Omittedlib["ps_pdread"] = 1
118 Omittedlib["ps_pdwrite"] = 1
119 Omittedlib["ps_pglobal_lookup"] = 1
120 Omittedlib["ps_pstop"] = 1
121 Omittedlib["ps_ptread"] = 1
122 Omittedlib["ps_ptwrite"] = 1
124 # libmach includes a small dwarf and elf library
125 Omittedlib["corecmdfreebsd386"] = 1
126 Omittedlib["corecmdlinux386"] = 1
127 Omittedlib["coreregsfreebsd386"] = 1
128 Omittedlib["coreregslinux386"] = 1
129 Omittedlib["coreregsmachopower"] = 1
130 Omittedlib["crackelf"] = 1
131 Omittedlib["crackmacho"] = 1
132 Omittedlib["dwarfaddrtounit"] = 1
133 Omittedlib["dwarfclose"] = 1
134 Omittedlib["dwarfenum"] = 1
135 Omittedlib["dwarfenumunit"] = 1
136 Omittedlib["dwarfget1"] = 1
137 Omittedlib["dwarfget128"] = 1
138 Omittedlib["dwarfget128s"] = 1
139 Omittedlib["dwarfget2"] = 1
140 Omittedlib["dwarfget4"] = 1
141 Omittedlib["dwarfget8"] = 1
142 Omittedlib["dwarfgetabbrev"] = 1
143 Omittedlib["dwarfgetaddr"] = 1
144 Omittedlib["dwarfgetn"] = 1
145 Omittedlib["dwarfgetnref"] = 1
146 Omittedlib["dwarfgetstring"] = 1
147 Omittedlib["dwarflookupfn"] = 1
148 Omittedlib["dwarflookupname"] = 1
149 Omittedlib["dwarflookupnameinunit"] = 1
150 Omittedlib["dwarflookupsubname"] = 1
151 Omittedlib["dwarflookuptag"] = 1
152 Omittedlib["dwarfnextsym"] = 1
153 Omittedlib["dwarfnextsymat"] = 1
154 Omittedlib["dwarfopen"] = 1
155 Omittedlib["dwarfpctoline"] = 1
156 Omittedlib["dwarfseeksym"] = 1
157 Omittedlib["dwarfskip"] = 1
158 Omittedlib["dwarfunwind"] = 1
159 Omittedlib["elfclose"] = 1
160 Omittedlib["elfdl386mapdl"] = 1
161 Omittedlib["elfinit"] = 1
162 Omittedlib["elfmachine"] = 1
163 Omittedlib["elfmap"] = 1
164 Omittedlib["elfopen"] = 1
165 Omittedlib["elfsection"] = 1
166 Omittedlib["elfsym"] = 1
167 Omittedlib["elfsymlookup"] = 1
168 Omittedlib["elftype"] = 1
169 Omittedlib["machoclose"] = 1
170 Omittedlib["machoinit"] = 1
171 Omittedlib["machoopen"] = 1
172 Omittedlib["stabsym"] = 1
173 Omittedlib["symdwarf"] = 1
174 Omittedlib["symelf"] = 1
175 Omittedlib["symmacho"] = 1
176 Omittedlib["symstabs"] = 1
178 Renamelib["chanalt"] = "alt"
179 Renamelib["channbrecv"] = "nbrecv"
180 Renamelib["channbrecvp"] = "nbrecvp"
181 Renamelib["channbrecvul"] = "nbrecvul"
182 Renamelib["channbsend"] = "nbsend"
183 Renamelib["channbsendp"] = "nbsendp"
184 Renamelib["channbsendul"] = "nbsendul"
185 Renamelib["chanrecv"] = "recv"
186 Renamelib["chanrecvp"] = "recvp"
187 Renamelib["chanrecvul"] = "recvul"
188 Renamelib["chansend"] = "send"
189 Renamelib["chansendp"] = "sendp"
190 Renamelib["chansendul"] = "sendul"
191 Renamelib["threadyield"] = "yield"
193 Renamelib["fmtcharstod"] = "charstod"
194 Renamelib["fmtstrtod"] = "strtod"
196 Renamelib["regcomp9"] = "regcomp"
197 Renamelib["regcomplit9"] = "regcomplit"
198 Renamelib["regcompnl9"] = "regcompnl"
199 Renamelib["regerror9"] = "regerror"
200 Renamelib["regexec9"] = "regexec"
201 Renamelib["regsub9"] = "regsub"
202 Renamelib["rregexec9"] = "rregexec"
203 Renamelib["rregsub9"] = "rregsub"
205 lastline = "XXX";
206 lastfile = FILENAME;
209 FNR==1 {
210 if(lastline == ""){
211 # screws up troff headers
212 print lastfile ":$ is a blank line"
215 n = length(FILENAME)
216 nam = FILENAME
217 if(nam ~ /\.html$/)
218 next
219 if(nam !~ /^man\/man(.*)\/(.*)\.(.*)$/){
220 print "nam", nam, "not of form [0-9][0-9]?/*"
221 next
223 nam = substr(nam, 8)
224 gsub("[/.]", " ", nam);
225 n = split(nam, a)
226 sec = a[1]
227 name = a[2]
228 section = a[3]
229 if($1 != ".TH" || NF != 3)
230 print "First line of", FILENAME, "not a proper .TH"
231 else if(($2 != toupper(name) || substr($3, 1, length(sec)) != sec || $3 != toupper(section)) \
232 && ($2!="INTRO" || name!="0intro") \
233 && (name !~ /^9/ || $2!=toupper(substr(name, 2)))){
234 print ".TH of", FILENAME, "doesn't match filename"
235 }else
236 Pages[tolower($2) "(" tolower($3) ")"] = 1
237 Sh = 0
240 { lastline=$0; lastfile=FILENAME; }
242 $1 == ".SH" {
243 if(inex)
244 print "Unterminated .EX in", FILENAME, ":", $0
245 inex = 0;
246 if (substr($2, 1, 1) == "\"") {
247 if (NF == 2) {
248 print "Unneeded quote in", FILENAME, ":", $0
249 $2 = substr($2, 2, length($2)-2)
250 } else if (NF == 3) {
251 $2 = substr($2, 2) substr($3, 1, length($3)-1)
252 NF = 2
255 if(Sh == 0 && $2 != "NAME")
256 print FILENAME, "has no .SH NAME"
257 w = Weight[$2]
258 if (w) {
259 if (w < Sh)
260 print "Heading", $2, "out of order in", FILENAME
261 Sh += w
263 sh = $2
266 $1 == ".EX" {
267 if(inex)
268 print "Nested .EX in", FILENAME ":" FNR, ":", $0
269 inex = 1
272 $1 == ".EE" {
273 if(!inex)
274 print "Bad .EE in", FILENAME ":" FNR ":", $0
275 inex = 0;
278 $1 == ".TF" {
279 smallspace = 1
282 $1 == ".PD" || $1 == ".SH" || $1 == ".SS" || $1 == ".TH" {
283 smallspace = 0
286 $1 == ".RE" {
287 lastre = 1
290 $1 == ".PP" {
291 if(smallspace && !lastre)
292 print "Possible missing .PD at " FILENAME ":" FNR
293 smallspace = 0
296 $1 != ".RE" {
297 lastre = 0
300 sh == "BUGS" && $1 == ".br" {
301 print FILENAME ":" FNR ": .br in BUGS"
304 sh == "SOURCE" && $1 ~ /^\\\*9\// {
305 s = ENVIRON["PLAN9"] substr($1, 4)
306 Sources[s] = 1
309 sh == "SOURCE" && $2 ~ /^\\\*9\// {
310 s = ENVIRON["PLAN9"] substr($2, 4)
311 Sources[s] = 1
314 sh == "SOURCE" && $1 ~ /^\// {
315 Sources[$1] = 1
318 sh == "SOURCE" && $2 ~ /^\// {
319 Sources[$2] = 1
322 $0 ~ /^\.[A-Z].*\([1-9]\)/ {
323 if ($1 == ".IR" && $3 ~ /\([0-9]\)/) {
324 name = $2
325 section = $3
326 }else if ($1 == ".RI" && $2 == "(" && $4 ~ /\([0-9]\)/) {
327 name = $3
328 section = $4
329 }else if ($1 == ".IR" && $3 ~ /9.\([0-9]\)/) {
330 name = $2
331 section = "9"
332 }else if ($1 == ".RI" && $2 == "(" && $4 ~ /9.\([0-9]\)/) {
333 name = $3
334 section = "9"
335 } else {
336 print "Possible bad cross-reference format in", FILENAME ":" FNR
337 print $0
338 next
340 gsub(/[^0-9]/, "", section)
341 Refs[toupper(name) "(" section ")"]++
344 END {
345 if(lastline == ""){
346 print lastfile ":$ is a blank line"
349 print "Checking Source References"
350 cmd = "xargs -n 100 ls -d 2>&1 >/dev/null | sed 's/^ls: / /; s/: .*//'"
351 for (i in Sources) {
352 print i |cmd
354 close(cmd)
355 print ""
356 print "Checking Cross-Referenced Pages"
357 for (i in Refs) {
358 if (!(tolower(i) in Pages) && !(tolower(i) in Omitman)){
359 b = tolower(i)
360 gsub("\\(", " \\(", b)
361 gsub("\\)", "\\)", b)
362 split(tolower(i), a, "/")
363 print "egrep -in '^\\.IR.*" b "' $PLAN9/man/man*/* # Need " tolower(i) |"sort"
366 close("sort")
367 print ""
368 print "Checking commands"
369 getindex("man/man1")
370 getindex("man/man4")
371 getindex("man/man7")
372 getindex("man/man8")
373 getbinlist("bin")
374 for (i in List) {
375 if (!(i in Index) && !(i in Omitted))
376 print "Need", i, "(in " List[i] ")" |"sort"
378 close("sort")
379 print ""
380 for (i in List) {
381 if (!(i in Index) && (i in Omitted))
382 print "Omit", i, "(in " List[i] ")" |"sort"
384 close("sort")
385 clearindex()
386 clearlist()
387 print ""
388 print "Checking libraries"
389 getindex("man/man3")
390 getnmlist("lib/lib9.a")
391 getnmlist("lib/lib9p.a")
392 getnmlist("lib/lib9pclient.a")
393 getnmlist("lib/libString.a")
394 # getnmlist("lib/libauth.a")
395 # getnmlist("lib/libauthsrv.a")
396 getnmlist("lib/libbin.a")
397 getnmlist("lib/libbio.a")
398 getnmlist("lib/libcomplete.a")
399 # getnmlist("lib/libcontrol.a")
400 getnmlist("lib/libdisk.a")
401 getnmlist("lib/libdraw.a")
402 getnmlist("lib/libflate.a")
403 getnmlist("lib/libframe.a")
404 getnmlist("lib/libgeometry.a")
405 getnmlist("lib/libhtml.a")
406 # getnmlist("lib/libhttpd.a")
407 getnmlist("lib/libip.a")
408 getnmlist("lib/libmach.a")
409 # getnmlist("lib/libmemdraw.a")
410 # getnmlist("lib/libmemlayer.a")
411 getnmlist("lib/libmp.a")
412 getnmlist("lib/libmux.a")
413 # getnmlist("lib/libndb.a")
414 getnmlist("lib/libplumb.a")
415 getnmlist("lib/libregexp9.a")
416 getnmlist("lib/libsec.a")
417 getnmlist("lib/libthread.a")
418 # getnmlist("lib/libventi.a")
419 for (i in List) {
420 if (!(i in Index) && !(i in Omittedlib))
421 print "Need", List[i], i |"sort"
422 # print "Need", i, "(in " List[i] ")" |"sort"
424 close("sort")
425 print ""
426 for (i in List) {
427 if (!(i in Index) && (i in Omittedlib))
428 print "Omit", List[i], i |"sort"
429 # print "Omit", i, "(in " List[i] ")" |"sort"
431 close("sort")
434 func getindex(dir, fname)
436 fname = dir "/INDEX"
437 while ((getline < fname) > 0)
438 Index[$1] = dir
439 close(fname)
442 func getbinlist(dir, cmd, subdirs, nsd)
444 cmd = "ls -p -l " dir
445 nsd = 0
446 while (cmd | getline) {
447 if ($1 ~ /^d/) {
448 if (!($10 in Skipdirs))
449 subdirs[++nsd] = $10
450 } else if ($10 !~ "^_")
451 List[$10] = dir
453 for ( ; nsd > 0 ; nsd--)
454 getbinlist(dir "/" subdirs[nsd])
455 close(cmd)
458 func getnmlist(lib, cmd)
460 cmd = "nm -g " lib
461 while (cmd | getline) {
462 if (($2 == "T" || $2 == "L") && $3 !~ "^_"){
463 sym = $3
464 sub("^p9", "", sym)
465 if(sym in Renamelib)
466 List[Renamelib[sym]] = lib " as " sym
467 else
468 List[sym] = lib
471 close(cmd)
474 func clearindex( i)
476 for (i in Index)
477 delete Index[i]
480 func clearlist( i)
482 for (i in List)
483 delete List[i]