• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl
2
3####################################################################################
4# genindex.pl:
5# Reads the source directory and creates an index.html with the link
6# Author: Ram Viswanadha
7#
8####################################################################################
9use File::Find;
10use File::Basename;
11use IO::File;
12use Cwd;
13use File::Copy;
14use Getopt::Long;
15use File::Path;
16use File::Copy;
17
18GetOptions(
19           "--sourcedir=s" => \$sourceDir,
20           "--destdir=s" => \$destDir,
21           "--href=s" => \$href
22          );
23
24
25usage() unless defined $sourceDir;
26usage() unless defined $destDir;
27usage() unless defined $href;
28
29
30# create list of html files
31my @list;
32if (@ARGV) {
33    @list = @ARGV;
34    foreach (@list) { $_ .= ".html" unless (/\.html$/i); }
35} else {
36    opendir(DIR,$sourceDir);
37    @list = grep{/\.html$/} readdir(DIR);
38    closedir(DIR);
39}
40$outfile = $destDir."/index.html";
41$outFH = IO::File->new($outfile,"w")
42            or die  "could not open the file $outfile for writing: $! \n";
43print $outFH "<html>\n";
44print $outFH "\t<head>Index of all comparison charts</head>\n";
45print $outFH "\t<body bgcolor=\"#FFFFFF\">\n";
46print $outFH "\t\t<ul>\n";
47# now convert
48foreach $item (@list){
49    next if($item eq "." || $item eq ".." || $item eq "index.html");
50    ($s1, $s2) = split(/\./,$item);
51    #grab the english translation
52    $inFH = IO::File->new($item,"r")
53            or die  "could not open the file $outfile for reading: $! \n";
54    $fullName="";
55    while(defined ($line=<$inFH>)){
56          if($line =~ /.*?(\(.*\).*Cover Page.*)/){
57            $line =~ /.*?(\(.*\))/;
58            $fullName =  $1;
59            if($fullName eq ""){
60                print $line."\n";
61            }
62            break;
63          }
64    }
65
66    print $outFH "\t\t\t<li><a href=\"$href/$item\">$s1</a> $fullName</li>\n";
67    close($inFH);
68}
69
70print $outFH "\t\t</ul>\n";
71print $outFH "\t</body>\n";
72print $outFH "</html>\n";
73close($outFH);
74
75#-----------------------------------------------------------------------
76sub usage {
77    print << "END";
78Usage:
79txt2ldml.pl
80Options:
81        --sourcedir=<directory>
82        --destdir=<directory>
83        --href=<The URL to be prepended>
84
85END
86  exit(0);
87}
88