File: htest-man.pl

package info (click to toggle)
docbook2x 0.8.8-8
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 4,532 kB
  • ctags: 321
  • sloc: xml: 16,229; sh: 3,684; perl: 3,445; ansic: 639; makefile: 404; sed: 11
file content (86 lines) | stat: -rwxr-xr-x 2,214 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

# Heuristic tests (necessary conditions) for a man page to be good.
#
# This script checks for:
# 1. the file ends in a newline 
#    (detects some cases where a man-page got cut off from a processing error)
# 2. no consecutive blank lines except in verbatim environments
# 3. whitespace is collapsed except in verbatim environments
#
# Synopsis:
#  htest-man.pl [man-page files...]
#
# Potential errors in the given files will be logged to standard output.
# The return status will be non-zero whenever they occur.

use strict;

unshift(@ARGV, '-') unless @ARGV;

my $has_error = 0;

foreach my $ARGV (@ARGV) {

  my $has_name = 0;
  my $has_description = 0;
  my $in_verbatim = 0;
  my $last_line_is_blank = 0;
  my $line_num = 0;
  my $newline_exists = 1;

  open(IN, $ARGV);

  while (<IN>) {
    $line_num++;

    if(chomp == 0) {
      print STDERR "$0:$ARGV:${line_num}: no newline at end of file\n";
      $has_error = 1;
    }

    $in_verbatim = 1  if /^.nf\s*$/;
    $in_verbatim = 0  if /^.fi\s*$/;

    # FIXME this doesn't work for non-English-language pages
    $has_name++        if /^.SH\s+NAME$/;
    $has_description++ if /^.SH\s+DESCRIPTION$/;

    unless($in_verbatim) {
      my $line_is_blank = ($_ =~ /^(.PP)?\s*$/);
      if($line_is_blank and $last_line_is_blank) {
        print STDERR "$0:$ARGV:${line_num}: duplicate blank line\n";
        $has_error = 1;
      }
      $last_line_is_blank = $line_is_blank or 
                              ($_ =~ /^(.SH|.SS|.TP)(\s.*)?$/);
    }

    unless($in_verbatim) {
      if(/[ \t]{2,}/) {
        print STDERR "$0:$ARGV:${line_num}: non-collapsed whitespace\n";
        $has_error = 1;
      }
    }

  }

  if($has_name == 0) {
    print STDERR "$0:$ARGV:${line_num}: no NAME section found\n";
    $has_error = 1;
  } elsif($has_name > 1) {
    print STDERR "$0:$ARGV:${line_num}: too many NAME sections found\n";
    $has_error = 1;
  }
  
  if($has_description == 0) {
    print STDERR "$0:$ARGV:${line_num}: no DESCRIPTION section found\n";
    $has_error = 1;
  } elsif($has_description > 1) {
    print STDERR "$0:$ARGV:${line_num}: too many DESCRIPTION sections found\n";
    $has_error = 1;
  }
}

exit $has_error;