<?php
	$title = "Archive Search";
	include("pre.php3");
?>

Type in a word below to search the "The BBC Lives!" archive for a file name containing that word.
The search will find games, software, utilities, emulators, ROM images and documentation.

<FORM ACTION="archive-search.php3" METHOD=GET>
<?php 
  $word = ereg_replace(" .*", "", $word);
	$word = eregi_replace("[^a-zA-Z0-9._@-]", "", $word);

  echo "<INPUT NAME=\"word\" SIZE=25 VALUE=\"$word\">";
?>
<INPUT TYPE="submit" VALUE="Search!">
</FORM>

<?php

	if ($word != "") {
	
		echo "Results:<P>";
	
		$result = `find -iname *$word*`;
		
		$lines = split("\n", $result);
		reset ($lines);
		
		$ok = false;
		echo "<PRE>";
		while (list($dummy, $line) = each($lines)) {

			$line = substr($line, 2);		
			if ($line != "") {
				$ok = true;
		  	if (is_dir($line)) {
		  	  $dir  = $line;
		  	  $name = "";
		  	} 
		  	else if ($slashpos = strrpos($line, '/')) {
			  	$dir  = substr($line, 0, $slashpos);
			  	$name = substr($line, $slashpos+1);
			  }
			  else {
			    $dir  = "";
			    $name = "$line";
			  }
					
				echo "<A HREF=\"dir.php3?dir=$dir\">$dir</A>/";
				echo "<A HREF=\"$dir/$name\">$name</A>\n";
			}
		}
		
		echo "</PRE>";
		
		if (!$ok) 
			echo "Nothing found!<P>";
	}

?>


<?php include("post.php3") ?>
