File: fix-whatis

package info (click to toggle)
request-tracker3.6 3.6.1-4+etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 9,028 kB
  • ctags: 1,371
  • sloc: perl: 27,270; sh: 671; makefile: 327
file content (113 lines) | stat: -rw-r--r-- 2,607 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
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
#! /usr/bin/perl
#
# add-whatis: Add a short description to POD entry for whatis parsing
#
#   -- Andrew Stribblehill <ads@debian.org> 2003-04-10

use warnings;
use strict;
use Pod::Man;
use IO::File;

{ package WhatisPreprocessor;

  sub new {
      my ($self, $filename, $module, $desc) = @_;
      my $fh = new IO::File("<$filename") or return 0;
      return bless { state => "_pre", input => $fh,
		     module => $module, desc => $desc}, $self;
  }

  sub getline {
      my $self = shift;
      my $fh = $self->{input};

      unless ($self->{pause}) {
	  $_ = $fh->getline;
      } else {
	  $_ = $self->{pause};
      }

      return undef if (!defined $_);

      return $_ if /^\s*$/;
      # Terminal states don't begin with _
      #return $_ if ($self->{state} !~ /^_/);
      
    BLOCK: {
	if ($self->{state} eq "_pre") {
	    if (/^=head1 NAME/) {
		$self->{state} = "_pad";
		$self->{pause} = $_;
		$_ = "\n"; # Euw
	    }
	} elsif ($self->{state} eq "_pad") {
	    $self->{pause} = 0;
	    $self->{state} = "_head1";
	} elsif ($self->{state} eq "_head1") {
	    if (/(\S+)\s+-+\s+(.*)/) {
		$self->{state} = "tidied"; $_="$1 - $2\n";
		$self->{whatis} = chomp;
	    }
	    if (/(\S+)$/) {$self->{state} = "_active"; redo;}
	} elsif ($self->{state} eq "_active") {
	    if ($self->{desc}) {
		$self->{state} = "overwrote";
		$_ = "$self->{module} - $self->{desc}\n";
		$self->{whatis} = $_;
	    } else {
		$self->{state} = "default";
		$_ = "$self->{module} - Request Tracker internal module\n";
		$self->{whatis} = $_;
	    }
	}
    }
#      print $_;
      return $_;
  }

  sub bad_manpage {
      return ($_[0]->{state} =~ m/^_/);
  }
     
  sub close { 
      close $_[0]->{input};
  }
}

sub file2name {
    $_ = shift;
    if (s/\.pm$//) {
	# Special module code
	s(^lib/)();
	s(/)(::)g;
    } else {
	s(^.*/)();
    }
    return $_;
}

while (<>) {
    chomp;
    my ($file, $desc) = split /\s+/, $_, 2;
    my $mansect = "3pm";
    ($file, $mansect) = ($1, $2) if $file =~ m/^(\S+)\((\w+)\)$/;
    my $name = file2name($file);
    my $man = "man/$name.$mansect";
    open MAN, ">$man";

    my $filter = WhatisPreprocessor->new($file, $name, $desc);
    my $pod = Pod::Man->new(section => $mansect,
			    center => "Request Tracker Reference",
			    name => $name);
    $pod->parse_from_filehandle($filter, \*MAN);
    print while ($filter->getline);
    #print STDERR "$file -> $man: $filter->{state}\n";
    if ($filter->bad_manpage) {
	print STDERR " Bad manpage $man: deleting!\n";
	unlink $man;
    } else {
	print STDERR "$filter->{whatis}";
    }
    $filter->close;
}