| 1 |
#!/usr/local/bin/new/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
|
| 5 |
use File::Find; |
| 6 |
use File::Copy; |
| 7 |
use File::Basename; |
| 8 |
use Getopt::Long; |
| 9 |
use blib; |
| 10 |
my %file; |
| 11 |
my @files; |
| 12 |
my %cat; |
| 13 |
my @cat; |
| 14 |
|
| 15 |
my $podindex; |
| 16 |
GetOptions("podindex!" => \$podindex); |
| 17 |
|
| 18 |
sub category |
| 19 |
{ |
| 20 |
my ($cat,$file) = @_; |
| 21 |
unless (exists $cat{$cat}) |
| 22 |
{ |
| 23 |
$cat{$cat} = []; |
| 24 |
push(@cat,$cat); |
| 25 |
} |
| 26 |
if (defined $file) |
| 27 |
{ |
| 28 |
if (exists $file{$file}) |
| 29 |
{ |
| 30 |
if ($file{$file} ne $cat) |
| 31 |
{ |
| 32 |
warn "$file already in $file{$file} not $cat\n"; |
| 33 |
} |
| 34 |
} |
| 35 |
else |
| 36 |
{ |
| 37 |
$file{$file} = $cat; |
| 38 |
push(@{$cat{$cat}},$file) |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
@ARGV = ("Tk.cmd") if (!@ARGV && -r "Tk.cmd"); |
| 44 |
|
| 45 |
if (@ARGV) |
| 46 |
{ |
| 47 |
my $sec; |
| 48 |
while (<>) |
| 49 |
{ |
| 50 |
if (/^beginBookmark\s+'(.*)'\s*$/i) |
| 51 |
{ |
| 52 |
$sec = $1; |
| 53 |
category($sec); |
| 54 |
} |
| 55 |
elsif (/^file\s+(\S+)/) |
| 56 |
{ |
| 57 |
my $file = $1; |
| 58 |
if (-f $file) |
| 59 |
{ |
| 60 |
category($sec,$file); |
| 61 |
} |
| 62 |
else |
| 63 |
{ |
| 64 |
warn "Cannot find $file\n"; |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
find(sub { |
| 71 |
$File::Find::prune = 1 if /\b(blib|doc|pod[3n])\b/; |
| 72 |
return if /^Tk.pod$/; |
| 73 |
push(@files,$File::Find::name) if /\.(pod|pm)$/ |
| 74 |
}, |
| 75 |
'..'); |
| 76 |
|
| 77 |
foreach my $file (sort @files) |
| 78 |
{ |
| 79 |
my $seen = 0; |
| 80 |
my $pod = 0; |
| 81 |
open(F,"$file") || die "Cannot open $file:$!"; |
| 82 |
while (<F>) |
| 83 |
{ |
| 84 |
if (/^=for\s+category\s+(.*)$/) |
| 85 |
{ |
| 86 |
category($1,$file); |
| 87 |
$seen = 1; |
| 88 |
last; |
| 89 |
} |
| 90 |
if (/^=head1\s*NAME/) |
| 91 |
{ |
| 92 |
$pod = 1; |
| 93 |
} |
| 94 |
} |
| 95 |
category('Other Documents',$file) if ($pod && !$seen); |
| 96 |
if (!$pod && $file =~ /\.pm$/) |
| 97 |
{ |
| 98 |
|
| 99 |
} |
| 100 |
close(F); |
| 101 |
} |
| 102 |
|
| 103 |
if (-f "Tk.cmd") |
| 104 |
{ |
| 105 |
copy("Tk.cmd","Tk.cmd.old"); |
| 106 |
} |
| 107 |
|
| 108 |
system("p4",'edit',"Tk.cmd") if (-e 'Tk.cmd' && !-w 'Tk.cmd'); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
eval { require Tk }; |
| 113 |
|
| 114 |
if ($podindex) |
| 115 |
{ |
| 116 |
open(POD,">../Tk.pod") || die "Cannot write to Tk.pod: $!"; |
| 117 |
print POD <<'END'; |
| 118 |
=head1 NAME |
| 119 |
|
| 120 |
Tk - a graphical user interface toolkit for Perl |
| 121 |
|
| 122 |
=head1 SYNOPSIS |
| 123 |
|
| 124 |
use Tk; |
| 125 |
$top = new MainWindow; |
| 126 |
MainLoop; |
| 127 |
|
| 128 |
=head1 DESCRIPTION |
| 129 |
|
| 130 |
The Perl/Tk manual is split up into a number of sections: |
| 131 |
|
| 132 |
END |
| 133 |
|
| 134 |
my $no_link = 0; |
| 135 |
foreach my $cat (@cat) |
| 136 |
{ |
| 137 |
$no_link = ($cat =~ /C Programming/); |
| 138 |
print POD "=head2 $cat\n\n=over 4\n\n"; |
| 139 |
foreach my $file (sort { lc($a) cmp lc($b) } @{$cat{$cat}}) |
| 140 |
{ |
| 141 |
my($base) = fileparse($file, ".(pod|pm)"); |
| 142 |
if ($no_link) |
| 143 |
{ |
| 144 |
print POD "=item *\n\n$base\n\n"; |
| 145 |
} |
| 146 |
else |
| 147 |
{ |
| 148 |
my $mod = "Tk::" . $base; |
| 149 |
print POD "=item *\n\nL<$mod|$mod>\n\n"; |
| 150 |
} |
| 151 |
} |
| 152 |
print POD "=back\n\n"; |
| 153 |
} |
| 154 |
|
| 155 |
print POD <<END; |
| 156 |
|
| 157 |
=head1 AUTHOR |
| 158 |
|
| 159 |
Nick Ing-Simmons |
| 160 |
|
| 161 |
=head1 SEE ALSO |
| 162 |
|
| 163 |
L<perl(1)|perl>, L<wish(1)|wish>. |
| 164 |
|
| 165 |
=cut |
| 166 |
END |
| 167 |
} |
| 168 |
else |
| 169 |
{ |
| 170 |
open(CMD,">Tk.cmd") || die "Cannot open Tk.cmd:$!"; |
| 171 |
print CMD <<END; |
| 172 |
# This is a command file for pod2ps |
| 173 |
# |
| 174 |
cover true |
| 175 |
booktitle 'Perl/Tk Reference' |
| 176 |
release 'Version Tk$Tk::VERSION' |
| 177 |
author 'Nick Ing-Simmons' |
| 178 |
linkbox off color |
| 179 |
pagesize a4 |
| 180 |
output tkman.ps |
| 181 |
path . |
| 182 |
END |
| 183 |
|
| 184 |
foreach my $cat (@cat) |
| 185 |
{ |
| 186 |
print CMD "beginBookmark '$cat'\n"; |
| 187 |
foreach my $file (@{$cat{$cat}}) |
| 188 |
{ |
| 189 |
print CMD "file $file '' '$cat' ''\n"; |
| 190 |
} |
| 191 |
print CMD "endBookmark\n"; |
| 192 |
} |
| 193 |
|
| 194 |
print CMD <<END; |
| 195 |
ToC 1 |
| 196 |
END |
| 197 |
} |