#!/usr/bin/perl
# $Id: ident,v 1.9 2000/10/31 12:52:10 argggh Exp $

# ident --	Look up identifiers
#
#	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: ident,v 1.9 2000/10/31 12:52:10 argggh Exp $ ';

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

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


sub ident { 
    print("Type the full name of an identifier to summarize ",
	  "(a function name, variable name, typedef, etc).\n",
	  "<p>Matches are case-sensitive.\n");                    

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

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

    
    if ($identifier) {
	my @refs = $index->getindex($identifier, $release);

	print("<h1>$identifier</h1>\n");

	if (@refs) {
	    my $def;

	    print("<ul>\n");
	    while ($def = shift(@refs)) {
		my ($file, $line, $type, $rel) = @$def;

		$rel &&= "(member of ".idref($rel, $rel).")";
		
		print("<li> $type_names{$type} in ".
		      fileref("$file, line $line",
			      $file, $line).
		      " $rel<br>\n");
	    }
	    print("</ul>\n");

	    my @uses = $index->getreference($identifier, $release);

	    if (@uses) {
		@uses = sort { $$a[0] cmp $$b[0] } @uses;

		my $ref;
		while ($ref = shift(@uses)) {
		    my ($file, $line) = @$ref;

		    print("<li> ".
			  fileref("$file, line $line",
				  $file, $line).
			  "<br>\n");
		}
	    }
	}
	else {
	    print("<br><b>Not used</b>");
	}
    }
}


httpinit;

makeheader('ident');
ident;
makefooter('ident');

