aboutsummaryrefslogtreecommitdiff
path: root/dist/checkman.awk
blob: 3567cc2d2d86553dd99426d92637a60b39fe5ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# Usage: cd $PLAN9; awk -f dist/checkman.awk man?/*.?
#
# Checks:
#	- .TH is first line, and has proper name section number
#	- sections are in order NAME, SYNOPSIS, DESCRIPTION, EXAMPLES,
#		FILES, SOURCE, SEE ALSO, DIAGNOSTICS, BUGS
#	- there's a manual page for each cross-referenced page

BEGIN {

#	.SH sections should come in the following order

	Weight["NAME"] = 1
	Weight["SYNOPSIS"] = 2
	Weight["DESCRIPTION"] = 4
	Weight["EXAMPLE"] = 8
	Weight["EXAMPLES"] = 16
	Weight["FILES"] = 32
	Weight["SOURCE"] = 64
	Weight["SEE ALSO"] = 128
	Weight["DIAGNOSTICS"] = 256
	Weight["SYSTEM CALLS"] = 512
	Weight["BUGS"] = 1024

	Skipdirs["CVS"] = 1

	# allow references to pages provded
	# by the underlying Unix system
	Omitman["awk(1)"] = 1
	Omitman["bash(1)"] = 1
	Omitman["chmod(1)"] = 1
	Omitman["compress(1)"] = 1
	Omitman["cp(1)"] = 1
	Omitman["egrep(1)"] = 1
	Omitman["gs(1)"] = 1
	Omitman["gv(1)"] = 1
	Omitman["lex(1)"] = 1
	Omitman["lp(1)"] = 1
	Omitman["lpr(1)"] = 1
	Omitman["mail(1)"] = 1
	Omitman["make(1)"] = 1
	Omitman["nm(1)"] = 1
	Omitman["prof(1)"] = 1
	Omitman["pwd(1)"] = 1
	Omitman["qiv(1)"] = 1
	Omitman["sh(1)"] = 1
	Omitman["ssh(1)"] = 1
	Omitman["stty(1)"] = 1
	Omitman["tar(1)"] = 1
	Omitman["tex(1)"] = 1
	Omitman["unutf(1)"] = 1
	Omitman["vnc(1)"] = 1
	Omitman["xterm(1)"] = 1

	Omitman["access(2)"] = 1
	Omitman["brk(2)"] = 1
	Omitman["chdir(2)"] = 1
	Omitman["close(2)"] = 1
	Omitman["connect(2)"] = 1
	Omitman["fork(2)"] = 1
	Omitman["gethostname(2)"] = 1
	Omitman["getpid(2)"] = 1
	Omitman["getuid(2)"] = 1
	Omitman["open(2)"] = 1
	Omitman["pipe(2)"] = 1
	Omitman["ptrace(2)"] = 1
	Omitman["rmdir(2)"] = 1
	Omitman["send(2)"] = 1
	Omitman["signal(2)"] = 1
	Omitman["sigprocmask(2)"] = 1
	Omitman["socketpair(2)"] = 1
	Omitman["unlink(2)"] = 1

	Omitman["abort(3)"] = 1
	Omitman["assert(3)"] = 1
	Omitman["fprintf(3)"] = 1
	Omitman["fscanf(3)"] = 1
	Omitman["fopen(3)"] = 1
	Omitman["isalpha(3)"] = 1
	Omitman["malloc(3)"] = 1
	Omitman["perror(3)"] = 1
	Omitman["remove(3)"] = 1
	Omitman["sin(3)"] = 1
	Omitman["strerror(3)"] = 1

	Omitman["factotum(4)"] = 1	# for now leave undocumented

	Omitman["core(5)"] = 1
	Omitman["passwd(5)"] = 1

	Omitman["signal(7)"] = 1

	Omitman["cron(8)"] = 1

	# don't need documentation for these in bin
	Omitted[".cvsignore"] = 1
	Omitted["Getdir"] = 1
	Omitted["Irc"] = 1
	Omitted["Juke"] = 1
	Omitted["ajuke"] = 1
	Omitted["goodmk"] = 1
	Omitted["jukefmt"] = 1
	Omitted["jukeget"] = 1
	Omitted["jukeindex"] = 1
	Omitted["jukeinfo"] = 1
	Omitted["jukeplay"] = 1
	Omitted["jukeput"] = 1
	Omitted["jukesearch"] = 1
	Omitted["jukesongfile"] = 1
	Omitted["m4ainfo"] = 1
	Omitted["mp3info"] = 1
	Omitted["notes"] = 1
	Omitted["tcolors"] = 1
	Omitted["tref"] = 1
	Omitted["unutf"] = 1
	Omitted["volume"] = 1
	Omitted["vtdump"] = 1

	# not for users
	Omittedlib["creadimage"] = 1
	Omittedlib["pixelbits"] = 1
	Omittedlib["bouncemouse"] = 1
	Omittedlib["main"] = 1	# in libthread
	
	Omittedlib["opasstokey"] = 1	# in libauthsrv

	# functions provided for -lthread_db
	Omittedlib["ps_get_thread_area"] = 1
	Omittedlib["ps_getpid"] = 1
	Omittedlib["ps_lcontinue"] = 1
	Omittedlib["ps_lgetfpregs"] = 1
	Omittedlib["ps_lgetregs"] = 1
	Omittedlib["ps_lsetfpregs"] = 1
	Omittedlib["ps_lsetregs"] = 1
	Omittedlib["ps_lstop"] = 1
	Omittedlib["ps_pcontinue"] = 1
	Omittedlib["ps_pdread"] = 1
	Omittedlib["ps_pdwrite"] = 1
	Omittedlib["ps_pglobal_lookup"] = 1
	Omittedlib["ps_pstop"] = 1
	Omittedlib["ps_ptread"] = 1
	Omittedlib["ps_ptwrite"] = 1

	# libmach includes a small dwarf and elf library
	Omittedlib["corecmdfreebsd386"] = 1
	Omittedlib["corecmdlinux386"] = 1
	Omittedlib["coreregsfreebsd386"] = 1
	Omittedlib["coreregslinux386"] = 1
	Omittedlib["coreregsmachopower"] = 1
	Omittedlib["crackelf"] = 1
	Omittedlib["crackmacho"] = 1
	Omittedlib["dwarfaddrtounit"] = 1
	Omittedlib["dwarfclose"] = 1
	Omittedlib["dwarfenum"] = 1
	Omittedlib["dwarfenumunit"] = 1
	Omittedlib["dwarfget1"] = 1
	Omittedlib["dwarfget128"] = 1
	Omittedlib["dwarfget128s"] = 1
	Omittedlib["dwarfget2"] = 1
	Omittedlib["dwarfget4"] = 1
	Omittedlib["dwarfget8"] = 1
	Omittedlib["dwarfgetabbrev"] = 1
	Omittedlib["dwarfgetaddr"] = 1
	Omittedlib["dwarfgetn"] = 1
	Omittedlib["dwarfgetnref"] = 1
	Omittedlib["dwarfgetstring"] = 1
	Omittedlib["dwarflookupfn"] = 1
	Omittedlib["dwarflookupname"] = 1
	Omittedlib["dwarflookupnameinunit"] = 1
	Omittedlib["dwarflookupsubname"] = 1
	Omittedlib["dwarflookuptag"] = 1
	Omittedlib["dwarfnextsym"] = 1
	Omittedlib["dwarfnextsymat"] = 1
	Omittedlib["dwarfopen"] = 1
	Omittedlib["dwarfpctoline"] = 1
	Omittedlib["dwarfseeksym"] = 1
	Omittedlib["dwarfskip"] = 1
	Omittedlib["dwarfunwind"] = 1
	Omittedlib["elfclose"] = 1
	Omittedlib["elfdl386mapdl"] = 1
	Omittedlib["elfinit"] = 1
	Omittedlib["elfmachine"] = 1
	Omittedlib["elfmap"] = 1
	Omittedlib["elfopen"] = 1
	Omittedlib["elfsection"] = 1
	Omittedlib["elfsym"] = 1
	Omittedlib["elfsymlookup"] = 1
	Omittedlib["elftype"] = 1
	Omittedlib["machoclose"] = 1
	Omittedlib["machoinit"] = 1
	Omittedlib["machoopen"] = 1
	Omittedlib["stabsym"] = 1
	Omittedlib["symdwarf"] = 1
	Omittedlib["symelf"] = 1
	Omittedlib["symmacho"] = 1
	Omittedlib["symstabs"] = 1
	Omittedlib["elfcorelinux386"] = 1
	Omittedlib["linux2ureg386"] = 1
	Omittedlib["ureg2linux386"] = 1
	Omittedlib["coreregs"] = 1	# haven't documented mach yet
	Omittedlib["regdesc"] = 1

	Omittedlib["auth_attr"] = 1	# not happy about this

	Omittedlib["ndbnew"] = 1		# private to library
	Omittedlib["ndbsetval"] = 1

	Renamelib["chanalt"] = "alt"
	Renamelib["channbrecv"] = "nbrecv"
	Renamelib["channbrecvp"] = "nbrecvp"
	Renamelib["channbrecvul"] = "nbrecvul"
	Renamelib["channbsend"] = "nbsend"
	Renamelib["channbsendp"] = "nbsendp"
	Renamelib["channbsendul"] = "nbsendul"
	Renamelib["chanrecv"] = "recv"
	Renamelib["chanrecvp"] = "recvp"
	Renamelib["chanrecvul"] = "recvul"
	Renamelib["chansend"] = "send"
	Renamelib["chansendp"] = "sendp"
	Renamelib["chansendul"] = "sendul"
	Renamelib["threadyield"] = "yield"

	Renamelib["fmtcharstod"] = "charstod"
	Renamelib["fmtstrtod"] = "strtod"

	Renamelib["regcomp9"] = "regcomp"
	Renamelib["regcomplit9"] = "regcomplit"
	Renamelib["regcompnl9"] = "regcompnl"
	Renamelib["regerror9"] = "regerror"
	Renamelib["regexec9"] = "regexec"
	Renamelib["regsub9"] = "regsub"
	Renamelib["rregexec9"] = "rregexec"
	Renamelib["rregsub9"] = "rregsub"

	lastline = "XXX";
	lastfile = FILENAME;
}

FNR==1	{
	if(lastline == ""){
		# screws up troff headers
		print lastfile ":$ is a blank line"
	}

	n = length(FILENAME)
	nam = FILENAME
	if(nam ~ /\.html$/)
		next
	if(nam !~ /^man\/man(.*)\/(.*)\.(.*)$/){
		print "nam", nam, "not of form [0-9][0-9]?/*"
		next
	}
	nam = substr(nam, 8)
	gsub("[/.]", " ", nam);
	n = split(nam, a)
	sec = a[1]
	name = a[2]
	section = a[3]
	if($1 != ".TH" || NF != 3)
		print "First line of", FILENAME, "not a proper .TH"
	else if(($2 != toupper(name) || substr($3, 1, length(sec)) != sec || $3 != toupper(section)) \
			&& ($2!="INTRO" || name!="0intro") \
			&& (name !~ /^9/ || $2!=toupper(substr(name, 2)))){
		print ".TH of", FILENAME, "doesn't match filename"
	}else
		Pages[tolower($2) "(" tolower($3) ")"] = 1
	Sh = 0
}

{ lastline=$0; lastfile=FILENAME; }

$1 == ".SH" {
	if(inex)
		print "Unterminated .EX in", FILENAME, ":", $0
	inex = 0;
	if (substr($2, 1, 1) == "\"") {
		if (NF == 2) {
			print "Unneeded quote in", FILENAME, ":", $0
			$2 = substr($2, 2, length($2)-2)
		} else if (NF == 3) {
			$2 = substr($2, 2) substr($3, 1, length($3)-1)
			NF = 2
		}
	}
	if(Sh == 0 && $2 != "NAME")
		print FILENAME, "has no .SH NAME"
	w = Weight[$2]
	if (w) {
		if (w < Sh)
			print "Heading", $2, "out of order in", FILENAME
		Sh += w
	}
	sh = $2
}

$1 == ".EX" {
		if(inex)
			print "Nested .EX in", FILENAME ":" FNR, ":", $0
		inex = 1
}

$1 == ".EE" {
	if(!inex)
		print "Bad .EE in", FILENAME ":" FNR ":", $0
	inex = 0;
}

$1 == ".TF" {
	smallspace = 1
}

$1 == ".PD" || $1 == ".SH" || $1 == ".SS" || $1 == ".TH" {
	smallspace = 0
}

$1 == ".RE" {
	lastre = 1
}

$1 == ".PP" {
	if(smallspace && !lastre)
		print "Possible missing .PD at " FILENAME ":" FNR
	smallspace = 0
}

$1 != ".RE" {
	lastre = 0
}

sh == "BUGS" && $1 == ".br" {
	print FILENAME ":" FNR ": .br in BUGS"
}

sh == "SOURCE" && $1 ~ /^\\\*9\// {
	s = ENVIRON["PLAN9"] substr($1, 4)
	Sources[s] = 1
}

sh == "SOURCE" && $2 ~ /^\\\*9\// {
	s = ENVIRON["PLAN9"] substr($2, 4)
	Sources[s] = 1
}

sh == "SOURCE" && $1 ~ /^\// {
	Sources[$1] = 1
}

sh == "SOURCE" && $2 ~ /^\// {
	Sources[$2] = 1
}

$0 ~ /^\.[A-Z].*\([1-9]\)/ {
		if ($1 == ".IR" && $3 ~ /\([0-9]\)/) {
			name = $2
			section = $3
		}else if ($1 == ".RI" && $2 == "(" && $4 ~ /\([0-9]\)/) {
			name = $3
			section = $4
		}else if ($1 == ".IR" && $3 ~ /9.\([0-9]\)/) {
			name = $2
			section = "9"
		}else if ($1 == ".RI" && $2 == "(" && $4 ~ /9.\([0-9]\)/) {
			name = $3
			section = "9"
		} else {
			if ($1 == ".HR" && $3 == "\"Section")
				next;
			print "Possible bad cross-reference format in", FILENAME ":" FNR
			print $0
			next
		}
		gsub(/[^0-9]/, "", section)
		Refs[toupper(name) "(" section ")"]++
}

END {
	if(lastline == ""){
		print lastfile ":$ is a blank line"
	}

	print "Checking Source References"
	cmd = "xargs -n 100 ls -d 2>&1 >/dev/null | sed 's/^ls: /	/; s/: .*//'"
	for (i in Sources) {
		print i |cmd
	}
	close(cmd)
	print ""
	print "Checking Cross-Referenced Pages"
	for (i in Refs) {
		if (!(tolower(i) in Pages) && !(tolower(i) in Omitman)){
			b = tolower(i)
			gsub("\\(", " \\(", b)
			gsub("\\)", "\\)", b)
			split(tolower(i), a, "/")
			print "egrep -in '^\\.IR.*" b "' $PLAN9/man/man*/* # Need " tolower(i) |"sort"
		}
	}
	close("sort")
	print ""
	print "Checking commands"
	getindex("man/man1")
	getindex("man/man4")
	getindex("man/man7")
	getindex("man/man8")
	getbinlist("bin")
	for (i in List) {
		if (!(i in Index) && !(i in Omitted))
			print "Need", i, "(in " List[i] ")" |"sort"
	}
	close("sort")
	print ""
	for (i in List) {
		if (!(i in Index) && (i in Omitted))
			print "Omit", i, "(in " List[i] ")" |"sort"
	}
	close("sort")
	clearindex()
	clearlist()
	print ""
	print "Checking libraries"
	getindex("man/man3")
	getnmlist("lib/lib9.a")
	getnmlist("lib/lib9p.a")
	getnmlist("lib/lib9pclient.a")
	getnmlist("lib/libString.a")
	getnmlist("lib/libauth.a")
	getnmlist("lib/libauthsrv.a")
	getnmlist("lib/libbin.a")
	getnmlist("lib/libbio.a")
	getnmlist("lib/libcomplete.a")
	# getnmlist("lib/libcontrol.a")
	getnmlist("lib/libdisk.a")
	getnmlist("lib/libdraw.a")
	getnmlist("lib/libflate.a")
	getnmlist("lib/libframe.a")
	getnmlist("lib/libgeometry.a")
	getnmlist("lib/libhtml.a")
	# getnmlist("lib/libhttpd.a")
	getnmlist("lib/libip.a")
	getnmlist("lib/libmach.a")
	# getnmlist("lib/libmemdraw.a")
	# getnmlist("lib/libmemlayer.a")
	getnmlist("lib/libmp.a")
	getnmlist("lib/libmux.a")
	getnmlist("lib/libndb.a")
	getnmlist("lib/libplumb.a")
	getnmlist("lib/libregexp9.a")
	getnmlist("lib/libsec.a")
	getnmlist("lib/libthread.a")
	# getnmlist("lib/libventi.a")
	for (i in List) {
		if (!(i in Index) && !(i in Omittedlib))
			print "Need", List[i], i |"sort"
			# print "Need", i, "(in " List[i] ")" |"sort"
	}
	close("sort")
	print ""
	for (i in List) {
		if (!(i in Index) && (i in Omittedlib))
			print "Omit", List[i], i |"sort"
			# print "Omit", i, "(in " List[i] ")" |"sort"
	}
	close("sort")
}

func getindex(dir,    fname)
{
	fname = dir "/INDEX"
	while ((getline < fname) > 0)
		Index[$1] = dir
	close(fname)
}

func getbinlist(dir,    cmd, subdirs, nsd)
{
	cmd = "ls -p -l " dir
	nsd = 0
	while (cmd | getline) {
		if ($1 ~ /^d/) {
			if (!($10 in Skipdirs))
				subdirs[++nsd] = $10
		} else if ($10 !~ "^_")
			List[$10] = dir
	}
	for ( ; nsd > 0 ; nsd--)
		getbinlist(dir "/" subdirs[nsd])
	close(cmd)
}

func getnmlist(lib,    cmd)
{
	cmd = "nm -g " lib
	while (cmd | getline) {
		if (($2 == "T" || $2 == "L") && $3 !~ "^_"){
			sym = $3
			sub("^p9", "", sym)
			if(sym in Renamelib)
				List[Renamelib[sym]] = lib " as " sym
			else
				List[sym] = lib
		}
	}
	close(cmd)
}

func clearindex(    i)
{
	for (i in Index)
		delete Index[i]
}

func clearlist(    i)
{
	for (i in List)
		delete List[i]
}