#!/bin/sh
#
# SUMMARY:      Test whether symbol appears within a set of C libraries.
# USAGE:        <script-name> <symbol-string>
#
# AUTHOR:       Bob Weiner
# ORG:          BeOpen.com
#
# ORIG-DATE:     5-Oct-91 at 03:29:05
# LAST-MOD:     13-Jun-99 at 01:54:47 by Bob Weiner
#
# Copyright (C) 1991-1995, BeOpen.com and the Free Software Foundation, Inc.
# See the "HY-COPY" file for license information.
#
# This file is part of Hyperbole.
#
# DESCRIPTION:  
#
#   Create the file given by the variable 'clib_list' below, and place in that
#   file the full path for each C, C++ or Objective-C library that you want
#   scanned for symbol names.  One filename per line.  Do not quote the
#   filenames.
#
#   Handles exact name matches only.  Echos and exits with same output value.
#   Either 1 if symbol is found or 0 if not.
#
# DESCRIP-END.

# Create this file and place in the file the full path for each C, C++ or
# Objective-C library that you want scanned for symbol names.  One filename
# per line.  Do not quote the filenames.
#
clib_list="$HOME/.CLIBS-LIST"

# This file will automatically be created to cache the symbol names.
# Remove it if you ever want to rebuild the symbol table.
#
clib_symbols="$HOME/.clibs-symbols"

st=0
if [ -s $clib_list ] ; then
    if [ ! -s $clib_symbols ] || \
       [ -n "`find $clib_list -prune -newer $clib_symbols`" ] ; then
        nm -gP `cat $clib_list` 2>/dev/null | grep '^_[A-Za-z]' \
        | sed -e 's/^_//' -e 's/ .*//' | sort -u > $clib_symbols
    fi
    grep -Fx "$1" $clib_symbols >/dev/null 2>&1 && st=1
fi

echo $st
exit $st
