| @@ -1,17 +1,17 @@ | | | @@ -1,17 +1,17 @@ |
1 | #!@PERL5@ | | 1 | #!@PERL5@ |
2 | # | | 2 | # |
3 | # $OpenBSD: mdoclint,v 1.14 2009/04/13 12:40:05 espie Exp $ | | 3 | # $OpenBSD: mdoclint,v 1.14 2009/04/13 12:40:05 espie Exp $ |
4 | # $NetBSD: mdoclint,v 1.32 2013/03/26 20:26:18 wiz Exp $ | | 4 | # $NetBSD: mdoclint,v 1.33 2013/06/02 11:58:36 wiz Exp $ |
5 | # | | 5 | # |
6 | # Copyright (c) 2001-2013 Thomas Klausner | | 6 | # Copyright (c) 2001-2013 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 | # |
| @@ -339,27 +339,27 @@ sub next_line | | | @@ -339,27 +339,27 @@ sub next_line |
339 | return $l; | | 339 | return $l; |
340 | } | | 340 | } |
341 | | | 341 | |
342 | sub close | | 342 | sub close |
343 | { | | 343 | { |
344 | my ($self) = @_; | | 344 | my ($self) = @_; |
345 | | | 345 | |
346 | close($self->{file}); | | 346 | close($self->{file}); |
347 | } | | 347 | } |
348 | | | 348 | |
349 | sub parse_macro_args | | 349 | sub parse_macro_args |
350 | { | | 350 | { |
351 | my ($s, $string) = @_; | | 351 | my ($s, $string) = @_; |
352 | my $_ = $string; | | 352 | $_ = $string; |
353 | my @params = (); | | 353 | my @params = (); |
354 | while (!/^$/) { | | 354 | while (!/^$/) { |
355 | if (s/^\"(.*?)\"\s*//) { | | 355 | if (s/^\"(.*?)\"\s*//) { |
356 | push(@params, $1); | | 356 | push(@params, $1); |
357 | } elsif (s/^(\S+)\s*//) { | | 357 | } elsif (s/^(\S+)\s*//) { |
358 | push(@params, $1); | | 358 | push(@params, $1); |
359 | } | | 359 | } |
360 | } | | 360 | } |
361 | if (@params > 9 and OPENBSD) { | | 361 | if (@params > 9 and OPENBSD) { |
362 | $s->warning("$string holds >9 parameters"); | | 362 | $s->warning("$string holds >9 parameters"); |
363 | } | | 363 | } |
364 | return @params; | | 364 | return @params; |
365 | } | | 365 | } |
| @@ -394,39 +394,41 @@ sub set_section_header | | | @@ -394,39 +394,41 @@ sub set_section_header |
394 | $s->{lastsh} = $sections{$section_header}; | | 394 | $s->{lastsh} = $sections{$section_header}; |
395 | } | | 395 | } |
396 | | | 396 | |
397 | if ($s->{lastline} =~ /^\.Pp/o) { | | 397 | if ($s->{lastline} =~ /^\.Pp/o) { |
398 | $s->warning("Paragraph problem: section header after .Pp") | | 398 | $s->warning("Paragraph problem: section header after .Pp") |
399 | if $opt_P; | | 399 | if $opt_P; |
400 | } | | 400 | } |
401 | | | 401 | |
402 | $s->{current_section_header} = $section_header; | | 402 | $s->{current_section_header} = $section_header; |
403 | } | | 403 | } |
404 | | | 404 | |
405 | sub process_and_save_line | | 405 | sub process_and_save_line |
406 | { | | 406 | { |
407 | my ($s, $_) = @_; | | 407 | my $s; |
| | | 408 | ($s, $_) = @_; |
408 | my $result = $s->process_line($_); | | 409 | my $result = $s->process_line($_); |
409 | # note that process_line chomps \n, then re-adds it, | | 410 | # note that process_line chomps \n, then re-adds it, |
410 | # so we detect a change on last lines without a \n. | | 411 | # so we detect a change on last lines without a \n. |
411 | if ($result ne $_) { | | 412 | if ($result ne $_) { |
412 | $s->{changes} = 1; | | 413 | $s->{changes} = 1; |
413 | } | | 414 | } |
414 | push(@{$s->{all}}, $result); | | 415 | push(@{$s->{all}}, $result); |
415 | } | | 416 | } |
416 | | | 417 | |
417 | sub process_line | | 418 | sub process_line |
418 | { | | 419 | { |
419 | my ($s, $_) = @_; | | 420 | my $s; |
| | | 421 | ($s, $_) = @_; |
420 | chomp; | | 422 | chomp; |
421 | # always cut trailing spaces | | 423 | # always cut trailing spaces |
422 | if (/\s+$/o) { | | 424 | if (/\s+$/o) { |
423 | $s->warning("trailing space: `$_'") if $opt_s; | | 425 | $s->warning("trailing space: `$_'") if $opt_s; |
424 | s/\s+$//o; | | 426 | s/\s+$//o; |
425 | } | | 427 | } |
426 | if (/\$OpenBSD\b.*\$/o) { | | 428 | if (/\$OpenBSD\b.*\$/o) { |
427 | $s->{oxrcsidseen}++; | | 429 | $s->{oxrcsidseen}++; |
428 | if (OPENBSD and ($s->{oxrcsidseen} > 1)) { | | 430 | if (OPENBSD and ($s->{oxrcsidseen} > 1)) { |
429 | $s->warning("RCS Id seen twice") if $opt_r; | | 431 | $s->warning("RCS Id seen twice") if $opt_r; |
430 | } | | 432 | } |
431 | return "$_\n"; | | 433 | return "$_\n"; |
432 | } | | 434 | } |
| @@ -658,27 +660,27 @@ sub finish | | | @@ -658,27 +660,27 @@ sub finish |
658 | if (not ($s->{shseen}{$i})) { | | 660 | if (not ($s->{shseen}{$i})) { |
659 | $s->warning("missing $i section") if $opt_S; | | 661 | $s->warning("missing $i section") if $opt_S; |
660 | } | | 662 | } |
661 | } | | 663 | } |
662 | } | | 664 | } |
663 | } | | 665 | } |
664 | | | 666 | |
665 | package main; | | 667 | package main; |
666 | | | 668 | |
667 | sub handle_file | | 669 | sub handle_file |
668 | { | | 670 | { |
669 | my $parser = Parser->new($_[0]); | | 671 | my $parser = Parser->new($_[0]); |
670 | | | 672 | |
671 | while (my $_ = $parser->next_line) { | | 673 | while ($_ = $parser->next_line) { |
672 | $parser->process_and_save_line($_); | | 674 | $parser->process_and_save_line($_); |
673 | } | | 675 | } |
674 | | | 676 | |
675 | $parser->finish; | | 677 | $parser->finish; |
676 | $parser->close; | | 678 | $parser->close; |
677 | if ($Parser::opt_F and $parser->{changes}) { | | 679 | if ($Parser::opt_F and $parser->{changes}) { |
678 | open OUT, ">$_[0].new" or | | 680 | open OUT, ">$_[0].new" or |
679 | die "can't open output file `$_[0].new'"; | | 681 | die "can't open output file `$_[0].new'"; |
680 | for my $l (@{$parser->{all}}) { | | 682 | for my $l (@{$parser->{all}}) { |
681 | print OUT $l | | 683 | print OUT $l |
682 | } | | 684 | } |
683 | close OUT; | | 685 | close OUT; |
684 | system("mv -i $_[0].new $_[0]"); | | 686 | system("mv -i $_[0].new $_[0]"); |