#!/usr/bin/perl use File::Find; use Cwd; $topdir=cwd(); print STDOUT "$topdir\n"; @itransextns = ("txt", "itx"); @htmlextns = ("htm", "html"); @pixextns = ("gif","jpg","jpeg","jpe"); @dirs =(); #all the directories below @reldirs=(); $thumbstr = "thumb"; $charstr = ""; $topref=""; #string contains links from the top of the page to things on the page itself #$/ = ""; # Enable paragraph mode. #$* = 1; # Enable multi-line patterns. foreach $extn (@htmlextns){ $charstr = $charstr . "\\". $extn. "|"; #building an array of extensions to match } $charstr =~ s/(.*)\|$/$1/; #get rid of the last vertical line. #open(INDEX, ">index.html") || die "cannot open index.html $!\n"; #The top index.html open(INDEX, ">MasterFile.html") || die "cannot open MasterFile.html $!\n"; #The masterfile select INDEX; &printhead; open(FINFO, "){ print INDEX $_; } find(\&mkdirlist,"."); #print STDOUT @dirs; $smref = "
["; #sentence month reference header foreach $dir (@dirs){ #build header for the sentence month-index files ($onlydir = $dir ) =~ s/(.*)\/(.*)?/$2/; if ("$topdir" eq "$dir") { $reldir = "\."; } else{ ($reldir = $dir) =~ s/$topdir\/(.*)/$1/; } if ($onlydir =~ m/(\d\d\d\d)-(\d\d)-(\d\d)/){ $smyear = $1; &getmonth($2); $smref = "$smref" . " $smmonth $smyear |"; #print STDOUT "$smref/n"; } } $smref =~ s/(.*)\|$/$1/; #get rid of the last vertical line. $smref = "$smref" . "]
\n"; #printed in the month-index file #print STDOUT "$smref"; # foreach $dir (@dirs){ ($onlydir = $dir ) =~ s/(.*)\/(.*)?/$2/; if ("$topdir" eq "$dir") { $reldir = "\."; } else{ ($reldir = $dir) =~ s/$topdir\/(.*)/$1/; } if ($topdir =~ m/$onlydir/){ #do not create a folder index for the top directory next; #don't do anything for the top directory } if ($onlydir =~ /^Sentences$/){ #don't do anything in the top sentence directory next; } #print STDOUT "Only Dir: $onlydir\n"; #print STDOUT "Dir: $dir\n"; #print STDOUT "Rel Dir: $reldir\n"; chdir("$dir"); @lindexstat = stat "$onlydir\.html"; #local index file statistics #system("pwd"); @filelist = (); #a list of all the files (with full path) in a directory @onlyfilelist = (); #only file list without directory information $winIndex = 0; while (<*>) { $file = $_; if ($file =~ m/^thumb/i){next;} if ($file =~ m/($charstr)/i){ # $extn = $1; #the match above ($onlyfile = $file) =~ s/(.*)$\.$extn/$1/; #filename without the extension push(@filelist,$file); push(@onlyfilelist,$onlyfile); } } #$topref = "
["; #this string is put on the top #print STDOUT @filelist, "\n"; $numoffiles = @filelist; if ($numoffiles == 0){next;} $topref =~ s/(.*)\|$/$1/; #get rid of the last vertical line. $topref = "$topref" . "]
"; #printed via printhead subroutine. # print INDEX "
\n"; if ($onlydir =~ m/(\d\d\d\d)-(\d\d)-(\d\d)/){ #if it's a file with date then print the day &getmonth($2); print INDEX ""; #$onlydir\.html print INDEX "$smmonth $1 Sentences
\n"; } else { print INDEX ""; #$onlydir\.html print INDEX "$onlydir
\n"; } # select LOCALINDEX; # &printhead; #$topref string is printed via printhead if ($onlydir =~ m/(\d\d\d\d)-(\d\d)-(\d\d)/){ #print month-year for sentence subdirectories print INDEX $smref; } # open(FINFO, "){ # print LOCALINDEX $_; # } # for ($ctr=0; $ctr<$numoffiles ;$ctr++){ $file = $filelist[$ctr]; $onlyfile = $onlyfilelist[$ctr]; if ($onlyfile =~ m/$onlydir/){ #m/$onlydir/){ #do not create link for the localindex file #print STDOUT $onlydir; next; } if ($onlyfile =~ m/(\d\d\d\d)-(\d\d)-(\d\d)/){ #if it's a file with date then print the day print INDEX "$3 - "; } print INDEX "html | "; #$file | "; unless ($onlyfile =~ /index/){ #don't link the index.txt file if (-e "$onlyfile\.txt"){ #link only if a txt file exists print INDEX " txt \ "; #$onlyfile\.txt "; } } open(LFILE, "<$file") or die "cannot open $file $!\n"; $keepskipping = 0; while(){ $line = $_; $line =~ s/\r//g; #print STDOUT "Beginning: $line \n"; if ($line =~ m/^$/){ next; } if ($line =~ m//i){ $keepskipping = 1; #print STDOUT "$file: $line \n"; next; } if ($line =~ m|

(.*)

|i & $keepskipping == 1){ #pick up the first paragraph print INDEX "$1
\n"; #print what is between the paragraph marks #print STDOUT "$file: $line \n"; last; } } close(LFILE); #end of link copying code #$topref = "$topref" . " $onlyfile |"; #print STDOUT "$topref/n"; } chdir("$topdir"); } select INDEX; &printtail; close(INDEX); sub mkdirlist { if (-d $_) { ($dirname = $File::Find::name )=~ s/./$topdir/; #replace the first dot with $topdir push(@dirs, "$dirname"); } } sub printhead { print <Master Index - Learn Sanskrit HR Pota

[ Sentences | Dhaatus | Vibhakti | Misc | Learn Sanskrit | Home Personal | Home ]


HEADER } sub printtail { print <

[ Sentences | Dhaatus | Vibhakti | Misc | Learn Sanskrit | Home Personal | Home ]

EOF ×tamp; print < TAIL } sub timestamp { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $mon = $mon+1; $year = $year+1900; $sec = "0" . $sec if ($sec =~ /^\d$/); $min = "0" . $min if ($min =~ /^\d$/); $hour = "0" . $hour if ($hour =~ /^\d$/); $mday = "0" . $mday if ($mday =~ /^\d$/); $mon = "0" . $mon if ($mon =~ /^\d$/); print "


Last Modified: $hour:$min:$sec "; print "$year/$mon/$mday
"; } sub STEXT { local($tstring) = @_[0]; local(@outstr)=(); local(@astr) = split(//,$tstring); #make an array of characters. local($numlbraces) = 0; #initialise local($numrbraces) = 0; #initialise local($strlen) = length($tstring); local($pos) = $[; local($braceLev, $i); $pos = index($tstring, "\{", $pos); if ($pos >= 0 ){ $braceLev = 1; $numlbraces++; } $i = $pos; while(($braceLev >= 1) && ($pos <= $strlen)){ $i++; if (@astr[$i] =~ /\{/){ $numlbraces++; $braceLev++; } if (@astr[$i] =~ /\}/){ $numrbraces++; $braceLev--; } push(@outstr,$astr[$i]); } pop(@outstr); # Get rid of the last right brace. join('',@outstr); # convert the string back to a variable } sub getmonth { $ddmonth = @_[0]; if ($ddmonth =~ m/01/) {$smmonth = "January";} elsif ($ddmonth =~ m/02/) {$smmonth = "February";} elsif ($ddmonth =~ m/03/) {$smmonth = "March";} elsif ($ddmonth =~ m/04/) {$smmonth = "April";} elsif ($ddmonth =~ m/05/) {$smmonth = "May";} elsif ($ddmonth =~ m/06/) {$smmonth = "June";} elsif ($ddmonth =~ m/07/) {$smmonth = "July";} elsif ($ddmonth =~ m/08/) {$smmonth = "August";} elsif ($ddmonth =~ m/09/) {$smmonth = "September";} elsif ($ddmonth =~ m/10/) {$smmonth = "October";} elsif ($ddmonth =~ m/11/) {$smmonth = "November";} elsif ($ddmonth =~ m/12/) {$smmonth = "December";} }