#!/usr/bin/perl %formdata = &parseForm(); print "content-type:text/html\n\n"; #get newscode from env variables $newscode = $formdata{"CODE"}; #compose config file location $scriptstring1 = ""; $scriptstring2 = ""; if ($newscode eq "S") { &createSportsHeadline(); } elsif ($newscode eq "N") { &createNewsHeadline(); } elsif ($newscode eq "F") { &createFinancialHeadline(); } sub createNewsHeadline { #open the news file and copy all lines to array... open (FILE, "../ACCUDATA/news.txt"); @newsfile = ; close (FILE); print "\n"; print $scriptstring1; print $scriptstring2; print ""; #print "\n"; print ""; #go through news file replacing shit and then displaying foreach $line (@newsfile) { if ($line =~ "News Headlines") { @headlinearray = split(/,/, $line); $headlinearray =~ s/\n//; print "".$headlinearray[0]."
".$headlinearray[1]."

"; } elsif ($line =~ m/Copyright/) {} #do nothing... copyright line elsif ($line =~ m/([a-z]|[A-Z]|[0-9])/) { $line =~ s/\[/
/; $line =~ s/\]/<\/B>/; $line =~ s/\n//; print $line."
"; } } } sub createFinancialHeadline { #open the news file and copy all lines to array... open (FILE, "../ACCUDATA/financial.txt"); @newsfile = ; close (FILE); print "\n"; print $scriptstring1; print $scriptstring2; print ""; #print "\n"; print ""; #go through news file replacing shit and then displaying foreach $line (@newsfile) { if ($line =~ "News Headlines") { @headlinearray = split(/,/, $line); $headlinearray =~ s/\n//; print "".$headlinearray[0]."
".$headlinearray[1]."

"; } elsif ($line =~ m/Copyright/) {} #do nothing... copyright line elsif ($line =~ m/([a-z]|[A-Z]|[0-9])/) { $line =~ s/\[/
/; $line =~ s/\]/<\/B>/; $line =~ s/\n//; print $line."
"; } } } sub createSportsHeadline { #open the news file and copy all lines to array... open (FILE, "../ACCUDATA/sphead.txt"); @newsfile = ; close (FILE); #go thru file backwards and modify lines, sending them to a new array my @modifiednewsfile; #get the number of elements in the array... $totalelements = $#newsfile; #set flags for modification and marking $mainheadlineflag=0; $locationflag=0; for ($x=$totalelements; $x>0; $x--) { #if the line is an extra long line... if ($newsfile[$x] =~ m/-------------------------------/) { if ($mainheadlineflag==1) { $mainheadlineflag=0; } else { $mainheadlineflag=1; } } #if the line is the actual headline after the SHIOT line (many -'s) then format.. elsif ($mainheadlineflag==1 && $newsfile[$x] =~ m/([a-z]|[A-Z]|[0-9])/) { $mainheadlineflag=0; $modifiednewsfile[$x] = "
".$newsfile[$x].""; $modifiednewsfile[$x] =~ s/\n//; } #if the line contains the indicative "space--space" of a minor headline, format it appropriately elsif ($newsfile[$x] =~ m/--/ && $newsfile[$x] =~ m/([a-z]|[A-Z]|[0-9])/) { @minorheadlinearray = split(/--/, $newsfile[$x]); $modifiednewsfile[$x] = "
".$minorheadlinearray[0]."".$minorheadlinearray[1]; } #if the line is the sports headline main line separate and format... elsif ($newsfile[$x] =~ m/Sports News/) { @headlinearray = split(/,/, $newsfile[$x]); $headlinearray =~ s/\n//; $modifiednewsfile[$x] = "".$headlinearray[0]."
".$headlinearray[1]."
"; $modifiednewsfile[$x] =~ s/\n//; } elsif ($newsfile[$x] =~ m/Copyright/) {} #do nothing... copyright line elsif ($newsfile[$x] eq "") {} #do nothing... copyright line else { $modifiednewsfile[$x] = "
".$newsfile[$x]; $modifiednewsfile[$x] =~ s/\n//; } } #print "\n\n"; print "\n"; print $scriptstring1; print $scriptstring2; print ""; #print "\n"; print ""; #go through news file replacing shit and then displaying foreach $line (@modifiednewsfile) { print $line; } } #****** this subroutine parses the form for data *************************** # returns the hash containing the values... #*************************************************************************** sub parseForm{ if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split (/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); if ($ENV{'QUERY_STRING'}) { @getpairs = split(/&/, $ENV{'QUERY_STRING'}); push (@pairs,@getpairs); } } else { #could not use the given method (not get or post) # put error code text in here... } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-0][a-fA-F0-9]) /pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-0][a-fA-F0-9]) /pack("C", hex($1))/eg; $value =~s///g; if ($formdata{$key}) { $formdata{$key}.=", $value"; } else { $formdata{$key} = $value; } } return %formdata; }