/[wait]/trunk/lib/WAIT/Document/Nroff.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/WAIT/Document/Nroff.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (show annotations)
Tue May 25 19:13:11 2004 UTC (19 years, 11 months ago) by dpavlin
File size: 2666 byte(s)
support for gziped man pages (as used by Debian), move usage of FileHandle
to IO::File and IO::Zlib

1 # -*- Mode: Cperl -*-
2 # Nroff.pm --
3 # ITIID : $ITI$ $Header $__Header$
4 # Author : Ulrich Pfeifer
5 # Created On : Mon Sep 16 19:04:37 1996
6 # Last Modified By: Ulrich Pfeifer
7 # Last Modified On: Sun Nov 22 18:44:48 1998
8 # Language : CPerl
9 # Update Count : 76
10 # Status : Unknown, Use with caution!
11 #
12 # Copyright (c) 1996-1997, Ulrich Pfeifer
13 #
14
15 package WAIT::Document::Nroff;
16 @ISA = qw(WAIT::Document::Base);
17 require WAIT::Document::Base;
18
19 use IO::File;
20 use IO::Zlib;
21 use strict;
22 #use diagnostics;
23 use Carp;
24
25 sub TIEHASH {
26 my $type = shift;
27 my $pipe = shift;
28 my @files = grep -f $_, @_;
29
30 my $self = {
31 Pipe => $pipe || 'nroff',
32 Files => \@files
33 };
34 bless $self, ref($type) || $type;
35 }
36
37 #$ENV{PATH} .= ':/usr/local/groff-1.09/bin:/app/sun4_55/unido-inf/groff/1.10/bin';
38
39 use File::Basename;
40
41 sub catfile ($) {
42 my $fullname = shift;
43 my ($name,$path) = fileparse($fullname);
44 $path =~ s{man([^/]+)\/$}
45 {cat$1/};
46 "$path$name";
47 }
48
49 sub nroff {
50 my $self = shift;
51 my $path = shift;
52
53 return undef unless -f $path;
54
55 my $fh;
56 if ($path =~ m/\.gz$/i) {
57 $fh = new IO::Zlib("$path","rb");
58 } else {
59 $fh = new IO::File "< $path";
60 }
61 return undef unless defined $fh;
62 my $first = <$fh>;
63 $fh->close;
64 return undef if $first =~ /^\.so man/;
65 return undef unless defined $first;
66 $first =~ /\'\\\"\s.*((e)|(t))+/;
67 my @pre;
68 my $pipe;
69 if ($path =~ m/\.gz$/i) {
70 $pipe .= 'gzip -cd';
71 } else {
72 $pipe .= 'cat';
73 }
74 $pipe .= " $path |";
75 push @pre, 'eqn -Tascii' if $2;
76 push @pre, 'tbl' if $3;
77 push @pre, $self->{Pipe};
78 if (@pre) {
79 $pipe .= join ('|', @pre) . '|';;
80 }
81 local($/) = undef;
82 $fh = new IO::File "$pipe";
83 return unless defined $fh;
84 <$fh>;
85 }
86
87 sub FETCH {
88 my $self = shift;
89 my $path = shift;
90 my $catp = catfile $path;
91 return undef unless defined $path;
92
93 local($/) = undef;
94
95 if (-e $catp) {
96 my $fh;
97 if ($path =~ m/\.gz$/) {
98 $fh = new IO::Zlib("$path","rb");
99 } else {
100 $fh = new IO::File "< $path";
101 }
102 return <$fh>;
103 }
104 my $cont = $self->nroff($path);
105 if ($cont) {
106 my $fh = new IO::File "> $catp";
107 if ($fh) {
108 warn "Generating $catp\n";
109 $fh->print($cont);
110 }
111 }
112 $cont;
113 }
114
115 sub FIRSTKEY {
116 my $self = shift;
117 $self->{fno} = 0;
118 $self->NEXTKEY;
119 }
120
121 sub NEXTKEY {
122 my $self = shift;
123 return undef if ($self->{fno}++ > @{$self->{Files}});
124 $self->{Files}->[$self->{fno}-1];
125 }
126
127 sub close {
128 my $self = shift;
129
130 delete $self->{fno};
131 delete $self->{Files}; # no need at query time
132 }
133
134 1;

Properties

Name Value
cvs2svn:cvs-rev 1.1.1.2

  ViewVC Help
Powered by ViewVC 1.1.26