#!/usr/bin/perl
# $Id: find,v 1.8 2002/03/18 14:55:43 mbox Exp $

# find   --	Find files
#
#	Arne Georg Gleditsch <argggh@ifi.uio.no>
#	Per Kristian Gjermshus <pergj@ifi.uio.no>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

######################################################################

$CVSID = '$Id: find,v 1.8 2002/03/18 14:55:43 mbox Exp $ ';

use lib do { $0 =~ m{(.*)/} ? "$1/lib" : "lib" };

use LXR::Common qw(:html);
use LXR::Config;

sub find {

    print("<p align=\"center\">\n",
	  "Search for files (by name) using regular expressions.\n",
	  "<br>(Need some <a href=\"search-help.html\">Hints</a> ",
	  "on performing searches?)</p>\n");

    print ("<form method=\"get\" action=\"find\">\n");

    foreach ($config->allvariables) {
	if ($config->variable($_) ne $config->vardefault($_)) {
	    print("<input type=\"hidden\" name=\"",$_, "\" ",
		  "value=\"", $config->variable($_), "\">\n");
	}
    }			       
    
    print("<b>Find file: </b><input type=\"text\" name=\"string\" ",
	  "value=\"",$searchtext,"\" size=\"50\">\n",
	  "<input type=\"submit\" value=\"search\">\n",
	  "</form>\n");


    if ($searchtext ne "") {
	unless (open(FILELLISTING,$config->glimpsedir."/.glimpse_filenames")) {
	    &warning("Could not open .glimpse_filenames.");
	    return;
	}
	print("<hr>\n");
	$sourceroot = $config->sourceroot;
	while($file = <FILELLISTING>) {
	    $file =~ s/^$sourceroot//;
	    if($file =~ /$searchtext/) {
		print(&fileref("$file", "find-file", "/$file"),"<br>\n");
	    }
	}
    }
}

httpinit;

$searchtext = $HTTP->{'param'}->{'string'};

&makeheader('find');
&find;
&makefooter('find');

httpclean;

