#!/usr/local/bin/perl # declarations $filename; $NumberOfDashes = 0; $NewDashes = 0; $title; @list; # opening and reading from the directory @list = &Read("forum"); chdir("forum") || &PrintDead; $head = &MakeTop; $tail = &MakeTail; # begining to print output; ie the header print "Content-type: text/html\n\n $head\n"; # printing the forum body $it = 0; $size = @list; while ($it < $size) { $it = &prinThread($it,@list); } # printing footer print " $tail\n"; exit; # SubRoutines Start Here sub prinThread { local($iterator,@files)=@_; local($size,$ans,$current,$quit); local($title,$newName); $title = &FindTitle($files[$iterator]); $newName = &ConvertName($files[$iterator]); print "\n";} $size = @files; while ($quit == 0) { $ans = &PartOfThread($files[$current],$files[$iterator]); if (($ans == 1)&&($iterator < $size)) {$iterator = &prinThread($iterator,@files);} else {$quit = 1; print "\n";} } return($iterator); } # Returns 1 if B is part of A's thread sub PartOfThread { local($A, $B)=@_; local(@A,@B,$size,$szA,$szB,$i,$equal); @A = split(/.html/,$A); $A = $A[0]; @B = split(/.html/,$B); $B = $B[0]; @A = split(/-/,$A); @B = split(/-/,$B); $szA = @A; $szB = @B; if ($szA >= $szB) {return (0);} $size = $szA; $equal = 1; for($i = 0; $i < $size; $i++) { if ($A[$i] != $B[$i]) {$equal = 0;} } if ($equal == 1) {return (1);} else {return(0);} } sub ConvertName { local($name)=@_; local($replace,$with); $replace = "-"; $with = "%2D"; $name =~ s/$replace/$with/g; $replace = ".html"; $with = "%2Ehtml"; $name =~ s/$replace/$with/g; return ($name); } sub CountDashes { local ($line) = @_; local ($count); $count = 0; while($line =~ /-/) { $count++; $line =~ s/-/ /; } return ($count); } sub FindTitle { local ($file) = @_; local (@infile,$sentance); local (@BrokenSentance,@AnswerHere); open(TITLEFILE,$file) || return ("file not found"); @infile = ; close(TITLEFILE); foreach $sentance (@infile) { if ($sentance =~ /<\/title>/) {return("No Title");} if ($sentance =~ /<title>/) { @BrokenSentance = split(/<title>/,$sentance); @AnswerHere = split(/</,$BrokenSentance[1]); return($AnswerHere[0]); } } return("No Title"); } # accepts a directory name as input, then reads in and sorts all the file # names which it returns as an array of strings sub Read { local($dirname)=@_; local(@list,$filename,$i); opendir(FORUMDIR, $dirname) || &PrintDead; $i = 0; while ($filename = readdir(FORUMDIR)) { if($filename =~ /html/) { @list[$i] = $filename; $i++; } } closedir(FORUMDIR); @list = &MySort(@list); return(@list); } sub MySort { local(@list)=@_; local($size,$i,$ans,$tmp,$j); $size = @list; for($j = 0; $j < $size; $j++) { for($i = 0; $i < ($size-1); $i++) { $ans = &GreaterThen($list[$i+1],$list[$i]); if ($ans == 1) {$tmp = $list[$i]; $list[$i] = $list[$i+1]; $list[$i+1] = $tmp;} } } return (@list); } # Returns 1 if A is greater then B, 0 otherwise sub GreaterThen { local($A, $B)=@_; local(@A,@B,$size,$szA,$szB,$i); @A = split(/.html/,$A); $A = $A[0]; @B = split(/.html/,$B); $B = $B[0]; @A = split(/-/,$A); @B = split(/-/,$B); $szA = @A; $szB = @B; if ($szA > $szB) {$size = $szB;} else {$size = $szA;} for($i = 0; $i < $size; $i++) { if ($A[$i] > $B[$i]) {return(1);} if ($A[$i] < $B[$i]) {return(0);} } if ($szA < $szB) {return (1);} else {return(0);} } sub PrintDead { print "Content-type: text/html\n\n <html>\n<head>\n<title> SAAC - Sorry This page is currently unavailable \n\n\n

We're sorry but the forum seems to be unavailable at the present

\n\n

\nPlease try again and if the problem persists email us\n

\n "; exit; } sub MakeTail { $tmp = "




Subject:
Name:
Email Address:

Your Message:




"; return($tmp); } sub MakeTop { $tmp = " Students Against Animal Cruelty - Main Page








SAAC Message Board


"; return($tmp); }