#!/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 "\\". (removed "\\". on Sun 12 Oct 2008) } $charstr =~ s/(.*)\|$/$1/; #get rid of the last vertical line. print STDOUT "charstr - $charstr\n"; open(INDEX, ">index.html") || die "cannot open index.html $!\n"; #The top index.html select INDEX; &printhead; open(FINFO, "){ print INDEX $_; } close(FINFO); find(\&mkdirlist,"."); #print STDOUT @dirs; foreach $dir (@dirs){ ($onlydir = $dir ) =~ s/(.*)\/(.*)?/$2/; if ("$topdir" eq "$dir") { $reldir = "\."; } else{ ($reldir = $dir) =~ s/$topdir\/(.*)/$1/; } #print STDOUT "Only Dir: $onlydir\n"; #print STDOUT "Dir: $dir\n"; #print STDOUT "Rel Dir: $reldir\n"; chdir("$dir"); #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 (<*>) { #for all the files in the directory $file = $_; #print STDOUT $file, "\n"; if ($file =~ m/^thumb/i){next;} if ($file =~ m/($charstr)/i){ # print STDOUT "file - $file\n"; $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;} #build topref if (2 > 3){ for ($ctr=0; $ctr<$numoffiles ;$ctr++){ $file = $filelist[$ctr]; $onlyfile = $onlyfilelist[$ctr]; $topref = "$topref" . " $onlyfile |"; #print STDOUT "$topref/n"; } $topref =~ s/(.*)\|$/$1/; #get rid of the last vertical line. $topref = "$topref" . "]
"; #printed via printhead subroutine. } # unless ($topdir =~ m/$onlydir/){ #do not create link for the localindex file open(LOCALINDEX, ">$onlydir\.html") or die "cannot open $onlydir\.html $!\n"; &getmonth($onlydir); print INDEX ""; print INDEX "$smy
\n"; #print month and year } select LOCALINDEX; &printhead; #$topref string is printed via printhead open(FINFO, "){ print LOCALINDEX $_; } close(FINFO); # for ($ctr=0; $ctr<$numoffiles ;$ctr++){ $file = $filelist[$ctr]; $onlyfile = $onlyfilelist[$ctr]; if ($onlyfile =~ m/$onlydir/){ #do not create link for the localindex file #print STDOUT $onlydir; next; } print LOCALINDEX " $file | "; print LOCALINDEX " $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 LOCALINDEX "$1
\n"; #print what is between the paragraph marks #print STDOUT "$file: $line \n"; last; } } close(LFILE); #$topref = "$topref" . " $onlyfile |"; #print STDOUT "$topref/n"; } if (2 > 3){ $numofcols = 4; $ctr=0; for ($ctr=0; $ctr < $numoffiles; $ctr=$ctr+$numofcols){ $tr1str=""; $tr2str=""; for ($imgctr=0; $imgctr < $numofcols; $imgctr++) { if ($filelist[$ctr+$imgctr]) { $file = $filelist[$ctr+$imgctr]; $onlyfile = $onlyfilelist[$ctr+$imgctr]; $thumbfile = "$thumbstr" . "$file"; $clonlyfile = "cl" . "$onlyfile"; #$fsize = -s "$dir/$file"; #file size #$ksize = int($fsize/1000) . "k"; $tr1str = "$tr1str" . " \"$file\""; $tr2str = "$tr2str" . " $onlyfile \n"; $winIndex = $winIndex + 1; } } print LOCALINDEX "$tr1str Top \n"; print LOCALINDEX "$tr2str \n"; } } select LOCALINDEX; &printtail; close(LOCALINDEX); 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 <Index $onlydir

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


HEADER } sub printtail { ×tamp; print <[ Sentences | Dhaatus | Vibhakti | Misc | Learn Sanskrit | Home Personal | Home ]

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 { $fname = @_[0]; if ($fname =~ m/(\d\d\d\d)-(\d\d)-(\d\d)/){ $ddmonth=$2; $ddddyear = $1; } else {print STDOUT "file name not in the correct dddd-dd-dd format\n";} 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";} $smy = $smmonth . " " . $ddddyear; }