From: joel@abigale.UUCP (Joel Rosi-Schwartz)
Newsgroups: comp.lang.perl,alt.sources
Subject: locsym - First major upgrade ;-)
Summary: Now uses 70% less disk space!
Date: 18 Aug 92 19:27:56 GMT
Followup-To: comp.lang.perl
Organization: Techne Research, Finchampstead, Berkshire (UK)


Hi folks,

Well after an extensive development effort I have been able to reduce
the disk usage of the symbols database by an amazing 70% ;-)

Well, okay, it wasn't really that hard.  By creating a numeric key for
each library path in the database itself, I was able to avoid putting
the path inside the record of each function it contains---just put
the short one or two char key.  Then locsym simply does a lookup on the
number to derefrence it back to the path name.  My database dropped
from 900k down to 260k.

My thanks to John Paul Adams for the info on AIX and to Lauren Weinstein
for checking it out on ISC.  Lauren found that ISC ran fine as is.

Enjoy,
joel

----  cut here  --------  snip/snip  --------------------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  INSTALL MANIFEST locsym mksymdb readme.aix
# Wrapped by joel@abigale on Tue Aug 18 19:51:35 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'INSTALL' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'INSTALL'\"
else
echo shar: Extracting \"'INSTALL'\" \(393 characters\)
sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
XNo big deal here.  The two things to look out for are the
Xlocation of the symbols database and the list of directories
Xwhich are parsed for libraries.  Not that the list of dirs is
Xfor the "root" to start the search in, as I use find to pick
Xup all of the libs below these points.  If you change the
Xlocation of the database in "mksymdb" make sure to also change
Xit in "locsym".
X
XCheers,
Xjoel
END_OF_FILE
if test 393 -ne `wc -c <'INSTALL'`; then
    echo shar: \"'INSTALL'\" unpacked with wrong size!
fi
# end of 'INSTALL'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(357 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X INSTALL                    1	How to install package
X MANIFEST                   1	This file
X locsym                     1	Look up functions in database
X mksymdb                    1	Build the symbol database
X readme.aix                 1	How to set up for AIX
END_OF_FILE
if test 357 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'locsym' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'locsym'\"
else
echo shar: Extracting \"'locsym'\" \(7076 characters\)
sed "s/^X//" >'locsym' <<'END_OF_FILE'
X#!/usr/local/bin/perl
Xeval "exec /usr/local/bin/perl -S $0 $*"
X    if $running_under_some_shell;
X
X  #          $Id: locsym,v 1.3 1992/08/18 18:38:43 joel Exp root $
X  # ======================================================================== #
X  #                                                                          #
X  #  locsym and its sister program mksymdb attemts to handle the common      #
X  #  progamming problem of finding which library or libraries contains       #
X  #  the definition of a given symbol.  mksymdb needs only be run once to    #
X  #  set up the dbm database (or, of course, if you change your libraries).  #
X  #  After that to find a given function or extern definition is a quick     #
X  #  look-up using locdb.                                                    #
X  #                                                                          #
X  #  This code is for sure not portable across systems at this point.  I've  #
X  #  looked at Larry Wall's Configrue program to get an idea of what needs   #
X  #  to be done to make it portable and only understand half of it (maybe;-) #
X  #  Please send me any code towards this end and I will try to maintain     #
X  #  this such that as many systems as possible work without kluges.         #
X  #                                                                          #
X  #  The sole purpose of the copyright is so I don't get sued and my soul ;-)#
X  #  intention is that it should be as helpful and useful to as many folks   #
X  #  as possible, without anyone trying to hoard it or claim it as their     #
X  #  own.  Use it in peace and good health.                                  #
X  #                                                                          #
X  #  Suggestions, advice, bug reports and flames to:                         #
X  #                                                                          #
X  #        Joel Rosi-Schwartz                                                #
X  #        Techne Research                                                   #
X  #        The United Kingdom                                                #
X  #        E-mail: joel@abigale.UUPC                                         #
X  #        Or: uknet.ac.uk!pyrltd.uucp!abigale.uucp!joel                     #
X  #        Phone: +44 734 730.260                                            #
X  #        Fax: +44 734 730.272                                              #
X  #                                                                          #
X  # ======================================================================== #
X
X#
X# How much noise do we want ;-)
X#
X$verbose = 0;
X$quiet = 0;
X$debug = 0;
X
X#
X# Our symbols database.
X#
X$symdb = '/usr/local/etc/symdb';
X%SYMDB = ();
X
X#
X# Open up a existing symbols database.
X#
Xdbmopen (%SYMDB, $symdb, undef());
X
X#
X# Loop over ARGV and find all the requested symbols.
X# If the user hands us a regex, then we do a long
X# search through the whole database, otherwise we
X# do a quick lookup.
X#
X#  The database tends to get very big fast. Instead of listing
X#  each library in full for every subroutine, we use a bit
X#  of indirection.  Each library is listed once and keyed.  Then
X#  we just list the short key in the subroutine record.  A fast
X#  lookup will give us back the library name.  The keys are numbers
X#  so the is no chance of a conflict with a real function name.
X#
Xforeach $symbol (@ARGV) {
X	if ( $symbol =~ /[*?+[{\\^]/) {
X		$found = 0;
X
X		while (($key, $val) = each %SYMDB) {
X			if ($key =~ /$symbol/) {
X				@archives = split (' ', $val);
X				if (@archives) {
X					$found = 1;
X					print "$key:\n";
X					foreach $archive (@archives) {
X						print "        $SYMDB{$archive}\n";
X					}
X					print "\n";
X				}
X			}
X		}
X
X		print "$symbol: not found\n" unless $found;
X	} else {
X		@archives = split (' ', $SYMDB{$symbol});
X		if (@archives) {
X			print "$symbol:\n";
X			foreach $archive (@archives) {
X				print "        $SYMDB{$archive}\n";
X			}
X			print "\n";
X		}
X		else {
X			print "$symbol: not found\n";
X			print "\n";
X		}
X	}
X}
X
X#
X# And say bye
X#
Xdbmclose (SYMDB);
Xexit 0;
X
X  #############################################################################
X  #                                                                           #
X  #  Copyright (c) 1992 Techne Research                                       #
X  #  Copyright (c) 1992 Joel Rosi-Schwartz                                    #
X  #  All rights reserved.                                                     #
X  #                                                                           #
X  #  Redistribution and use in source and binary forms, with or without       #
X  #  modification, are permitted provided that the following conditions       #
X  #  are met:                                                                 #
X  #  1. Redistributions of source code must retain the above copyright        #
X  #     notice, this list of conditions and the following disclaimer.         #
X  #  2. Redistributions in binary form must reproduce the above copyright     #
X  #     notice, this list of conditions and the following disclaimer in the   #
X  #     documentation and/or other materials provided with the distribution.  #
X  #  3. All advertising materials mentioning features or use of this software #
X  #     must display the following acknowledgement:                           #
X  #       This product includes software developed by the Techne Research     #
X  #  4. The name of Techne Research may not be used to endorse or promote     #
X  #     products derived from this software without specific prior written    #
X  #     permission.                                                           #
X  #                                                                           #
X  #  THIS SOFTWARE IS PROVIDED BY THE TECHNE RESEARCH (UK) ``AS IS'' AND      #
X  #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE    #
X  #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR       #
X  #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COMDISCO SYSTEMS INC BE       #
X  #  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR      #
X  #  CONSEQUENTIAL #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT     #
X  #  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR       #
X  #  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,    #
X  #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE     #
X  #  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,        #
X  #  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                       #
X  #                                                                           #
X  # This copyright notice derived from material copyrighted by the Regents    #
X  # of the University of California.                                          #
X  #                                                                           #
X  #############################################################################
X
X#
END_OF_FILE
if test 7076 -ne `wc -c <'locsym'`; then
    echo shar: \"'locsym'\" unpacked with wrong size!
fi
chmod +x 'locsym'
# end of 'locsym'
fi
if test -f 'mksymdb' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mksymdb'\"
else
echo shar: Extracting \"'mksymdb'\" \(8455 characters\)
sed "s/^X//" >'mksymdb' <<'END_OF_FILE'
X#!/usr/local/bin/perl
Xeval "exec /usr/local/bin/perl -S $0 $*"
X    if $running_under_some_shell;
X
X  #          $Id: mksymdb,v 1.4 1992/08/18 18:37:54 joel Exp root $
X  # ======================================================================== #
X  #                                                                          #
X  #   Copyright (c)       1992 by Techne Resarch                             #
X  #   Copyright (c)       1992 by Joel Rosi-Schwartz                         #
X  #   All Rights Reserved                                                    #
X  #                                                                          #
X  #   Full Copyright notice at bottom of file.                               #
X  #                                                                          #
X  #  mksymdb and its sister program locsym attemts to handle the common      #
X  #  progamming problem of finding which library or libraries contains       #
X  #  the definition of a given symbol.  mksymdb needs only be run once to    #
X  #  set up the dbm database (or, of course, if you change your libraries).  #
X  #  After that to find a given function or extern definition is a quick     #
X  #  look-up using locdb.                                                    #
X  #                                                                          #
X  #  This code is for sure not portable across systems at this point.  I've  #
X  #  looked at Larry Wall's Configrue program to get an idea of what needs   #
X  #  to be done to make it portable and only understand half of it (maybe;-) #
X  #  Please send me any code towards this end and I will try to maintain     #
X  #  this such that as many systems as possible work without kluges.         #
X  #                                                                          #
X  #  The sole purpose of the copyright is so I don't get sued and my soul ;-)#
X  #  intention is that it should be as helpful and useful to as many folks   #
X  #  as possible, without anyone trying to hoard it or claim it as their     #
X  #  own.  Use it in peace and good health.                                  #
X  #                                                                          #
X  #  Suggestions, advice, bug reports and flames to:                         #
X  #                                                                          #
X  #        Joel Rosi-Schwartz                                                #
X  #        Techne Research                                                   #
X  #        The United Kingdom                                                #
X  #        E-mail: joel@abigale.UUPC                                         #
X  #        Or: uknet.ac.uk!pyrltd.uucp!abigale.uucp!joel                     #
X  #        Phone: +44 734 730.260                                            #
X  #        Fax: +44 734 730.272                                              #
X  #                                                                          #
X  # ======================================================================== #
X
X#
X# How much noise do we want ;-)
X#
X$verbose = 0;
X$quiet = 0;
X$debug = 0;
X
X#
X# The root directories of all archives we will parse.
X#
X@libroots = (
X	'/lib',
X	'/usr/lib',
X	'/usr/local/lib',
X	);
X
X#
X# The "nm" command which will create quickly parseable output.
X#
X$nmcmd = 'nm -p';
X
X#
X# Our symbols database.
X#
X$symdb = '/usr/local/etc/symdb';
X%SYMDB = ();
X
X#
X# Save the sysmdb iff it exists, JIC.
X#
Xif ( -e "${symdb}.pag") {
X	print STDERR "${symdb}.pag exists. Saving in ${symdb}.pag-\n"
X		unless $quiet;
X	rename ("${symdb}.pag", "${symdb}.pag-") ||
X		die "Could not rename ${symdb}.pag: $!\n";
X}
X
Xif ( -e "${symdb}.dir") {
X	print STDERR "${symdb}.dir exists. Saving in ${symdb}.dir-\n"
X		unless $quiet;
X	rename ("${symdb}.dir", "${symdb}.dir-") ||
X		die "Could not rename ${symdb}.dir: $!\n";
X}
X
X#
X# Open up a new one.
X#
Xdbmopen (%SYMDB, $symdb, 0666);
X
X#
X# Gather up all of the ".a" files to parse.
X# Note that the regex in find is "lib*.a", since I explicity
X# want to avoid the Xenix [SML] libs.
X#
Xprint STDERR "Locating all archives, please be patient ..." unless $quiet;
X@archives = `find @libroots -type f -name "lib*.a" -print`;
X
Xprint STDERR " done\n" unless $quiet;
X
X#
X# Okay, lets take a look.
X# We open each archive in turn and add the archive name to
X# the list for each externally visible symbol.
X#
X#  The database tends to get very big fast. Instead of listing
X#  each library in full for every subroutine, we use a bit
X#  of indirection.  Each library is listed once and keyed.  Then
X#  we just list the short key in the subroutine record.  A fast
X#  lookup will give us back the library name.  The keys are numbers
X#  so the is no chance of a conflict with a real function name.
X#
X$indir = 0;
X
Xforeach $archive (@archives) {
X	$indir++;
X	%seen = ();		# to weed out duplicate symbols
X	chop $archive;
X	$SYMDB{$indir} = $archive;
X	print STDERR "Processing $archive\n" unless $quiet;
X	open (NMOUT, "$nmcmd $archive|");
X
XSYMBOL:
X	while (<NMOUT>) {
X		$symbol = '';
X		chop;
X		if (/^.*\s+[ATDS]\s+([^_.].*)/o) { $symbol = $1 };
X		next unless $symbol;
X		# weed out file names from shared libs
X		next SYMBOL if $symbol =~ m=^/shlib/=o;
X		# only one per archive, thank you
X		next SYMBOL if $seen{$symbol}++;
X		$SYMDB{$symbol} .= " $indir";
X		print STDERR "$symbol: $SYMDB{$symbol}\n" if $verbose;
X	}
X}
X
X#
X# And say bye
X#
Xdbmclose (SYMDB);
Xprint STDERR "Processing complete\n" unless $quiet;
Xexit 0;
X
X  #############################################################################
X  #                                                                           #
X  #  Copyright (c) 1992 Techne Research                                       #
X  #  Copyright (c) 1992 Joel Rosi-Schwartz                                    #
X  #  All rights reserved.                                                     #
X  #                                                                           #
X  #  Redistribution and use in source and binary forms, with or without       #
X  #  modification, are permitted provided that the following conditions       #
X  #  are met:                                                                 #
X  #  1. Redistributions of source code must retain the above copyright        #
X  #     notice, this list of conditions and the following disclaimer.         #
X  #  2. Redistributions in binary form must reproduce the above copyright     #
X  #     notice, this list of conditions and the following disclaimer in the   #
X  #     documentation and/or other materials provided with the distribution.  #
X  #  3. All advertising materials mentioning features or use of this software #
X  #     must display the following acknowledgement:                           #
X  #       This product includes software developed by the Techne Research     #
X  #  4. The name of Techne Research may not be used to endorse or promote     #
X  #     products derived from this software without specific prior written    #
X  #     permission.                                                           #
X  #                                                                           #
X  #  THIS SOFTWARE IS PROVIDED BY THE TECHNE RESEARCH (UK) ``AS IS'' AND      #
X  #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE    #
X  #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR       #
X  #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COMDISCO SYSTEMS INC BE       #
X  #  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR      #
X  #  CONSEQUENTIAL #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT     #
X  #  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR       #
X  #  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,    #
X  #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE     #
X  #  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,        #
X  #  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                       #
X  #                                                                           #
X  # This copyright notice derived from material copyrighted by the Regents    #
X  # of the University of California.                                          #
X  #                                                                           #
X  #############################################################################
X
X#
END_OF_FILE
if test 8455 -ne `wc -c <'mksymdb'`; then
    echo shar: \"'mksymdb'\" unpacked with wrong size!
fi
chmod +x 'mksymdb'
# end of 'mksymdb'
fi
if test -f 'readme.aix' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'readme.aix'\"
else
echo shar: Extracting \"'readme.aix'\" \(1542 characters\)
sed "s/^X//" >'readme.aix' <<'END_OF_FILE'
X
XJohn tested out mksymdb/locsym on his RS6000 running AIX and has
Xthe following advice for getting it working.
X
XThanks John
X======================================================================
X
XFrom: John Paul Adams <ccaajpa@ucl.ac.uk>
XDate: Tue, 18 Aug 92 11:02:55 +0100
X
XMany thanks for posting your "locsym" program yesterday to the Perl
Xnewsgroup. It has already prooved useful here and furthers my cause
Xfor having Perl on our system!
X
XI used it on our mainframe service, an IBM RS/6000 workstation running
XAIX version 3.1 which is fully supported by Perl version 4.035. I thought
Xyou may be interested in what I needed to do to get your script
Xworking correctly.
X
XAIX is a horrendous mixture of BSD and System V. This means that the
X'nm' program is linked to the System V version and hence doesn't take
Xthe "-p" option. Fortunately you provided a define for that so we could
Xspecify "/usr/ucb/nm -p" to force it to use the BSD version.
X
XThe only other problem I encountered was when a the find command
Xwas looking in a directory that was a symbolic link. If you do an 'ls' 
Xon a directory that is actually a link to somewhereelse, then you just
Xget the directory name, hence it wasnt going into those directories.
XThis is fixed under AIX 3.1 by putting "directory/." so that it goes
Xinto that directory.
X
XOther than that, a wonderfully simple script that would mean a I could
Xhave compiled many more programs in the past when porting to AIX !!!
X
XJohn Adams,
XUser Support,
XUniversity College London Computer Centre.
X
XJ.Adams@uk.ac.ucl
END_OF_FILE
if test 1542 -ne `wc -c <'readme.aix'`; then
    echo shar: \"'readme.aix'\" unpacked with wrong size!
fi
# end of 'readme.aix'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0


-- 
     ==================================================================
     ||               T E C H N E   R E S E A R C H                  ||
     ||  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  ||
     ||                     Joel Rosi-Schwartz                       ||
     ||   Hildorien House            +   Email: joel@abigale.UUCP    ||
     ||   12 Waverley Way            +    (pyrltd!abigale.UUCP!joel) ||
     ||   Finchampstead, Wokingham   +   Phone: +44 (734) 730.260    ||
     ||   Berkshire RG11 4YD (UK)    +   Fax:   +44 (734) 730.272    ||
     ==================================================================