#!/usr/bin/perl

#CORPORATE BINARY CLEANSER
#Hacked by Andyman
#No guarantees expressed or implied,
#however, it's working for me.
#For Netscape 4.51 (Linux, ELF)

$nscape = "/opt/netscape/netscape";
while($resp ne "y" && $resp ne "n"){
    print "Is your Netscape 4.51 binary in /opt/netscape/netscape   [y/n]?";
    $resp = <STDIN>;
    chop($resp);
}
if($resp eq "n"){
  do{
    print "Location of existing netscape 4.51 binary [/opt/netscape/netscape]: ";
    $resp = <STDIN>;
    chop($resp);
  }
  while (length($resp)<2 || ! -e $resp);
  $nscape = $resp;
}

$new = ">".$nscape.".new";


while(length($resp) != 31){
    print "Now, a *folder* url to replace the links to netscape.com.  They all\n";
    print "begin with home.netscape.com/bookmark/4_51   Hopefully, you\n";
    print "have a homepage someplace you can replace this with. If not,\n";
    print "you can hit <enter> to use my substitutes, which will work for you.\n";
    print "In order to preserve the functioning of the binary, you can't make\n";
    print "your *folder* url longer than this:\n\n";
    print "home.netscape.com/bookmark/4_51\n";
    $resp = <STDIN>;
    chop($resp);	
    if($resp eq ""){ $resp = "199.105.128.138//////////search";}
    else{
	if(length($resp)>31) {
		print "Too long! ". length($resp) . "\n";
	}
	else{
		$len = 31-length($resp);
		while($len > 0){
			$resp .= "/";
			print $resp, "\n";
			$len -=1;
		}	
	}
    }
}

$n = "n";
do{
  print "What name, 8 letters or less, should appear on the \"My Netscape\" button?\n";
  $n =  <STDIN>;
  chop($n);
}while(length($n)>8);

$len = 8-length($n);

while($len > 0){
    $n .= "\ ";
    $len -= 1;
}
$name = $n;

print "-------------------------------------------------\n";
print "Creating $nscape.new...\n";
open(NEW, $new);
open(FILE,$nscape);
while($line =<FILE>){
	#Use local URL for Search button
	$line =~ s/home.netscape.com\/bookmark\/4_51/$resp/g;	

	#Use local url for N image button
	$line =~ s/tnetscape.html/newssites.html/g;	

	#Remove Netscape from title bar
	$line =~ s/Netscape:/\ \ \ \ \ \ \ \ \ /g;	

	#This was tricky to find -- the instance of Netscape
	#that appears on the "My Netscape" button
	if($line =~ /toolBar/){
		if($line =~ /destinations/){
		    $left = index($line,'destinations');
		    $line =~ s/\tNetscape/\t$name/;
		}
	}
	print NEW $line;
}
close(FILE);
close(NEW);;

`chmod uog+x $nscape.new`;