| @@ -1,17 +1,17 @@ | | | @@ -1,17 +1,17 @@ |
1 | #!@PERL5@ | | 1 | #!@PERL5@ |
2 | # | | 2 | # |
3 | # $OpenBSD: mdoclint,v 1.48 2016/01/24 20:10:48 schwarze Exp $ | | 3 | # $OpenBSD: mdoclint,v 1.48 2016/01/24 20:10:48 schwarze Exp $ |
4 | # $NetBSD: mdoclint,v 1.74 2017/06/01 14:38:50 wiz Exp $ | | 4 | # $NetBSD: mdoclint,v 1.75 2017/06/07 19:09:55 wiz Exp $ |
5 | # | | 5 | # |
6 | # Copyright (c) 2001-2017 Thomas Klausner | | 6 | # Copyright (c) 2001-2017 Thomas Klausner |
7 | # All rights reserved. | | 7 | # All rights reserved. |
8 | # | | 8 | # |
9 | # Redistribution and use in source and binary forms, with or without | | 9 | # Redistribution and use in source and binary forms, with or without |
10 | # modification, are permitted provided that the following conditions | | 10 | # modification, are permitted provided that the following conditions |
11 | # are met: | | 11 | # are met: |
12 | # 1. Redistributions of source code must retain the above copyright | | 12 | # 1. Redistributions of source code must retain the above copyright |
13 | # notice, this list of conditions and the following disclaimer. | | 13 | # notice, this list of conditions and the following disclaimer. |
14 | # 2. Redistributions in binary form must reproduce the above copyright | | 14 | # 2. Redistributions in binary form must reproduce the above copyright |
15 | # notice, this list of conditions and the following disclaimer in the | | 15 | # notice, this list of conditions and the following disclaimer in the |
16 | # documentation and/or other materials provided with the distribution. | | 16 | # documentation and/or other materials provided with the distribution. |
17 | # | | 17 | # |
| @@ -33,49 +33,48 @@ use warnings; | | | @@ -33,49 +33,48 @@ use warnings; |
33 | | | 33 | |
34 | $| = 1; | | 34 | $| = 1; |
35 | | | 35 | |
36 | package Parser; | | 36 | package Parser; |
37 | use Getopt::Std; | | 37 | use Getopt::Std; |
38 | | | 38 | |
39 | use constant { | | 39 | use constant { |
40 | OPENBSD => 0, | | 40 | OPENBSD => 0, |
41 | NETBSD => 1, | | 41 | NETBSD => 1, |
42 | }; | | 42 | }; |
43 | | | 43 | |
44 | use vars qw( | | 44 | use vars qw( |
45 | $opt_D $opt_d $opt_e $opt_F $opt_h $opt_l | | 45 | $opt_D $opt_d $opt_e $opt_F $opt_h $opt_l |
46 | $opt_m $opt_n $opt_o $opt_p $opt_r $opt_S $opt_v $opt_w $opt_x | | 46 | $opt_m $opt_o $opt_p $opt_r $opt_S $opt_v $opt_w $opt_x |
47 | ); | | 47 | ); |
48 | | | 48 | |
49 | | | 49 | |
50 | my $arch=`uname -m`; | | 50 | my $arch=`uname -m`; |
51 | chomp($arch); | | 51 | chomp($arch); |
52 | my $options="aDdeFfHhlmnoprSvwXx"; | | 52 | my $options="DdeFhlmoprSvwx"; |
53 | | | 53 | |
54 | sub usage | | 54 | sub usage |
55 | { | | 55 | { |
56 | my $default = OPENBSD ? "-DdmnoprSx" : "-DdelmnoprSx"; | | 56 | my $default = OPENBSD ? "-DdmoprSx" : "-DdelmoprSx"; |
57 | | | 57 | |
58 | print STDERR <<"EOF"; | | 58 | print STDERR <<"EOF"; |
59 | mdoclint: verify man page correctness | | 59 | mdoclint: verify man page correctness |
60 | usage: mdoclint [-$options] file ... | | 60 | usage: mdoclint [-$options] file ... |
61 | -D warn about bad casing and archs in .Dt | | 61 | -D warn about bad casing and archs in .Dt |
62 | -d warn about bad date strings (in .Dd only) | | 62 | -d warn about bad date strings (in .Dd only) |
63 | -e warn about unsorted errors (for functions) | | 63 | -e warn about unsorted errors (for functions) |
64 | -F fix whitespace problems (asks before overwriting) | | 64 | -F fix whitespace problems (asks before overwriting) |
65 | -h display this help text | | 65 | -h display this help text |
66 | -l warn about unknown libraries | | 66 | -l warn about unknown libraries |
67 | -m warn about man pages that are not in mdoc(7) format | | 67 | -m warn about man pages that are not in mdoc(7) format |
68 | -n warn about .Nd's ending in '.' | | | |
69 | -o warn about non-empty .Os strings | | 68 | -o warn about non-empty .Os strings |
70 | -p warn about punctuation problems | | 69 | -p warn about punctuation problems |
71 | -r warn about missing RCS Id | | 70 | -r warn about missing RCS Id |
72 | -S warn about any .Sh weirdness | | 71 | -S warn about any .Sh weirdness |
73 | -v verbose output | | 72 | -v verbose output |
74 | -w show section header in warnings | | 73 | -w show section header in warnings |
75 | -x warn about cross-references with missing targets | | 74 | -x warn about cross-references with missing targets |
76 | Default is $default if no flag is specified. | | 75 | Default is $default if no flag is specified. |
77 | EOF | | 76 | EOF |
78 | exit(0); | | 77 | exit(0); |
79 | } | | 78 | } |
80 | | | 79 | |
81 | | | 80 | |
| @@ -226,32 +225,30 @@ sub warning | | | @@ -226,32 +225,30 @@ sub warning |
226 | my $extra = ""; | | 225 | my $extra = ""; |
227 | if ($opt_w) { | | 226 | if ($opt_w) { |
228 | $extra = $self->{current_section_header}.":"; | | 227 | $extra = $self->{current_section_header}.":"; |
229 | } | | 228 | } |
230 | print STDOUT "$self->{fn}:$extra$self->{ln}: ", join('', @_), "\n"; | | 229 | print STDOUT "$self->{fn}:$extra$self->{ln}: ", join('', @_), "\n"; |
231 | } | | 230 | } |
232 | | | 231 | |
233 | sub handle_options | | 232 | sub handle_options |
234 | { | | 233 | { |
235 | getopts($options); | | 234 | getopts($options); |
236 | $opt_h and usage(); | | 235 | $opt_h and usage(); |
237 | | | 236 | |
238 | # default to all warnings if no flag is set | | 237 | # default to all warnings if no flag is set |
239 | unless ($opt_D or $opt_d or $opt_e or $opt_l | | 238 | unless ($opt_D or $opt_d or $opt_e or $opt_l or $opt_m |
240 | or $opt_m or $opt_n or $opt_o or $opt_p or $opt_r | | 239 | or $opt_o or $opt_p or $opt_r or $opt_S or $opt_x) { |
241 | or $opt_S or $opt_x) { | | | |
242 | $opt_D = $opt_d = $opt_m = | | 240 | $opt_D = $opt_d = $opt_m = |
243 | $opt_n = $opt_o = $opt_p = $opt_r = $opt_S = | | 241 | $opt_o = $opt_p = $opt_r = $opt_S = $opt_x = 1; |
244 | $opt_x = 1; | | | |
245 | $opt_e = $opt_l = 1 if NETBSD; | | 242 | $opt_e = $opt_l = 1 if NETBSD; |
246 | } | | 243 | } |
247 | } | | 244 | } |
248 | | | 245 | |
249 | | | 246 | |
250 | sub verify_xref | | 247 | sub verify_xref |
251 | { | | 248 | { |
252 | my ($self, $page, $section, $pre, $post) = @_; | | 249 | my ($self, $page, $section, $pre, $post) = @_; |
253 | if ($self->{names}{$page.$section}) { | | 250 | if ($self->{names}{$page.$section}) { |
254 | $self->warning("Xref to itself (use .Nm instead)") if $opt_x; | | 251 | $self->warning("Xref to itself (use .Nm instead)") if $opt_x; |
255 | } | | 252 | } |
256 | # try to find corresponding man page | | 253 | # try to find corresponding man page |
257 | if (OPENBSD) { | | 254 | if (OPENBSD) { |
| @@ -428,30 +425,26 @@ sub process_line | | | @@ -428,30 +425,26 @@ sub process_line |
428 | $s->{names}{$1.$s->{sec}} = 1; | | 425 | $s->{names}{$1.$s->{sec}} = 1; |
429 | } | | 426 | } |
430 | } | | 427 | } |
431 | | | 428 | |
432 | if (/^\.Lb\s+(\S+)/o) { | | 429 | if (/^\.Lb\s+(\S+)/o) { |
433 | if (not $libraries{$1}) { | | 430 | if (not $libraries{$1}) { |
434 | $s->warning("Unknown library `$1' used as Lb argument") if $opt_l; | | 431 | $s->warning("Unknown library `$1' used as Lb argument") if $opt_l; |
435 | } | | 432 | } |
436 | } | | 433 | } |
437 | if (/^\.Os\s+(.+)/o) { | | 434 | if (/^\.Os\s+(.+)/o) { |
438 | $s->warning(".Os used with argument `$1'") if $opt_o; | | 435 | $s->warning(".Os used with argument `$1'") if $opt_o; |
439 | } | | 436 | } |
440 | | | 437 | |
441 | if (/^\.Nd.*\.$/o) { | | | |
442 | $s->warning(".Nd ends with a dot: `$_'") if $opt_n; | | | |
443 | } | | | |
444 | | | | |
445 | if (/(\w\w)\.\s+[A-Z]/o and not /^.%T/ and not $s->{inliteral}) { | | 438 | if (/(\w\w)\.\s+[A-Z]/o and not /^.%T/ and not $s->{inliteral}) { |
446 | if ("$1" ne "St") { | | 439 | if ("$1" ne "St") { |
447 | $s->warning("new sentence, new line: `$_'") if $opt_p; | | 440 | $s->warning("new sentence, new line: `$_'") if $opt_p; |
448 | } | | 441 | } |
449 | } | | 442 | } |
450 | if (/^\... .*[^\s][\.();,\[\]\{\}:]$/o | | 443 | if (/^\... .*[^\s][\.();,\[\]\{\}:]$/o |
451 | and not /\s\.\.\.$/o and not /\\&.$/o) { | | 444 | and not /\s\.\.\.$/o and not /\\&.$/o) { |
452 | $s->warning("punctuation in format string ", | | 445 | $s->warning("punctuation in format string ", |
453 | "without space: `$_'") if $opt_p; | | 446 | "without space: `$_'") if $opt_p; |
454 | } | | 447 | } |
455 | if (/^\./o and /Ns [\.();,\[\]\{\}:]/o) { | | 448 | if (/^\./o and /Ns [\.();,\[\]\{\}:]/o) { |
456 | $s->warning("possible Ns abuse: `$_'") if $opt_p; | | 449 | $s->warning("possible Ns abuse: `$_'") if $opt_p; |
457 | } | | 450 | } |