#!/bin/perl
eval "exec /usr/local/bin/perl -S $0 $*"
    if $running_under_some_shell;

  #          $Id: locsym,v 1.3 1992/08/18 18:38:43 joel Exp root $
  # ======================================================================== #
  #                                                                          #
  #  locsym and its sister program mksymdb attemts to handle the common      #
  #  progamming problem of finding which library or libraries contains       #
  #  the definition of a given symbol.  mksymdb needs only be run once to    #
  #  set up the dbm database (or, of course, if you change your libraries).  #
  #  After that to find a given function or extern definition is a quick     #
  #  look-up using locdb.                                                    #
  #                                                                          #
  #  This code is for sure not portable across systems at this point.  I've  #
  #  looked at Larry Wall's Configrue program to get an idea of what needs   #
  #  to be done to make it portable and only understand half of it (maybe;-) #
  #  Please send me any code towards this end and I will try to maintain     #
  #  this such that as many systems as possible work without kluges.         #
  #                                                                          #
  #  The sole purpose of the copyright is so I don't get sued and my soul ;-)#
  #  intention is that it should be as helpful and useful to as many folks   #
  #  as possible, without anyone trying to hoard it or claim it as their     #
  #  own.  Use it in peace and good health.                                  #
  #                                                                          #
  #  Suggestions, advice, bug reports and flames to:                         #
  #                                                                          #
  #        Joel Rosi-Schwartz                                                #
  #        Techne Research                                                   #
  #        The United Kingdom                                                #
  #        E-mail: joel@abigale.UUPC                                         #
  #        Or: uknet.ac.uk!pyrltd.uucp!abigale.uucp!joel                     #
  #        Phone: +44 734 730.260                                            #
  #        Fax: +44 734 730.272                                              #
  #                                                                          #
  # ======================================================================== #

#
# How much noise do we want ;-)
#
$verbose = 0;
$quiet = 0;
$debug = 0;

#
# Our symbols database.
#
$symdb = '/usr/local/etc/symdb';
%SYMDB = ();

#
# Open up a existing symbols database.
#
dbmopen (%SYMDB, $symdb, undef());

#
# Loop over ARGV and find all the requested symbols.
# If the user hands us a regex, then we do a long
# search through the whole database, otherwise we
# do a quick lookup.
#
#  The database tends to get very big fast. Instead of listing
#  each library in full for every subroutine, we use a bit
#  of indirection.  Each library is listed once and keyed.  Then
#  we just list the short key in the subroutine record.  A fast
#  lookup will give us back the library name.  The keys are numbers
#  so the is no chance of a conflict with a real function name.
#
foreach $symbol (@ARGV) {
	if ( $symbol =~ /[*?+[{\\^]/) {
		$found = 0;

		while (($key, $val) = each %SYMDB) {
			if ($key =~ /$symbol/) {
				@archives = split (' ', $val);
				if (@archives) {
					$found = 1;
					print "$key:\n";
					foreach $archive (@archives) {
						print "        $SYMDB{$archive}\n";
					}
				#	print "\n";
				}
			}
		}

		print "$symbol: not found\n" unless $found;
	} else {
		@archives = split (' ', $SYMDB{$symbol});
		if (@archives) {
			print "$symbol:\n";
			foreach $archive (@archives) {
				print "        $SYMDB{$archive}\n";
			}
		#	print "\n";
		}
		else {
			print "$symbol: not found\n";
		#	print "\n";
		}
	}
}

#
# And say bye
#
dbmclose (SYMDB);
exit 0;

  #############################################################################
  #                                                                           #
  #  Copyright (c) 1992 Techne Research                                       #
  #  Copyright (c) 1992 Joel Rosi-Schwartz                                    #
  #  All rights reserved.                                                     #
  #                                                                           #
  #  Redistribution and use in source and binary forms, with or without       #
  #  modification, are permitted provided that the following conditions       #
  #  are met:                                                                 #
  #  1. Redistributions of source code must retain the above copyright        #
  #     notice, this list of conditions and the following disclaimer.         #
  #  2. Redistributions in binary form must reproduce the above copyright     #
  #     notice, this list of conditions and the following disclaimer in the   #
  #     documentation and/or other materials provided with the distribution.  #
  #  3. All advertising materials mentioning features or use of this software #
  #     must display the following acknowledgement:                           #
  #       This product includes software developed by the Techne Research     #
  #  4. The name of Techne Research may not be used to endorse or promote     #
  #     products derived from this software without specific prior written    #
  #     permission.                                                           #
  #                                                                           #
  #  THIS SOFTWARE IS PROVIDED BY THE TECHNE RESEARCH (UK) ``AS IS'' AND      #
  #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE    #
  #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR       #
  #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COMDISCO SYSTEMS INC BE       #
  #  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR      #
  #  CONSEQUENTIAL #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT     #
  #  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR       #
  #  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,    #
  #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE     #
  #  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,        #
  #  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                       #
  #                                                                           #
  # This copyright notice derived from material copyrighted by the Regents    #
  # of the University of California.                                          #
  #                                                                           #
  #############################################################################

#
