1#!/usr/bin/perl -w 2# ianb@nessie.mcc.ac.uk 20031019 3# $Id: mp3lint-tools.pod.PL,v 1.2 2003/10/26 19:32:00 ianb Exp $ 4# Create mp3lint-tools.pod from the docs for all the tools. 5use strict; 6use Cwd; 7use Pod::Select; 8 9my $me=($0=~/(?:.*\/)?(.*)/)[0]; 10 11chdir("docs") or die("$me: cannot chdir to docs/: $!\n"); 12 13my $toolspath="../lib/MP3/Archive/Lint/Tools/"; 14 15my $outfile="mp3lint-tools.pod"; 16my $tmpfile="mp3lint-tools.tmp"; 17my $startfile="mp3lint-tools.start"; 18my $endfile="mp3lint-tools.end"; 19my $OVERWRITE=0; my $APPEND=1; 20 21my @tools=(); 22 23opendir(D,$toolspath) or die("$me: $toolspath: opendir: $!\n"); 24while($_=readdir(D)) 25{ 26 if(/^([A-Z].*)\.pm$/) 27 { 28 push(@tools,Cwd::abs_path($toolspath)."/$_"); 29 } 30} 31closedir(D) or die("$me: $toolspath: closedir: $!\n"); 32 33writefile($outfile,$startfile,$OVERWRITE); 34 35open(W,">>$outfile") or die("$me: cannot open $outfile: $!\n"); 36# podselect only writes to a file the output from the last file, 37# hence this hack 38 39$SIG{PIPE}='IGNORE'; 40 41my $pid=open(PIPE,"-|"); 42unless(defined($pid)) { die("$me: cannot fork: $!\n"); } 43 44if(!$pid) #child 45{ 46 podselect(sort(@tools)); 47 exit 0; 48} 49# parent 50print W <PIPE>; 51close(PIPE) or die("$me: error running child process: $?\n"); 52close(W) or die("$me: error closing $outfile: $!\n"); 53 54writefile($outfile,$endfile,$APPEND); 55 56sub writefile 57{ 58 my ($writef,$readf,$mode)=@_; 59 my $writefile=">".$writef; 60 if($mode == $APPEND) 61 { 62 $writefile=">".$writefile; 63 } 64 65 open(W,$writefile) or die("$me: cannot open $writef for writing: $!\n"); 66 open(F,$readf) or die("Cannot open $readf: $!\n"); 67 print W <F>; 68 close(F) or die("Cannot close $readf: $!\n"); 69 close(W) or die("$me: cannot close $writef: $!\n"); 70} 71 72 73