A truck load of updates/fixes/tweaks
[pkgusr] / usr / bin / header-symbol-search
1 #!/bin/bash
2
3 # Copyright (C) 2008 - 2014 Steve Youngs
4
5 # Author:     Steve Youngs <steve@sxemacs.org>
6 # Maintainer: Steve Youngs <steve@sxemacs.org>
7 # Created:    <2008-03-10>
8 # Time-stamp: <Monday Mar  3, 2014 17:24:16 steve>
9 # Homepage:   N/A
10 # Keywords:   utils package-management
11
12 # This file is part of pkgusr.
13
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions
16 # are met:
17 #
18 # 1. Redistributions of source code must retain the above copyright
19 #    notice, this list of conditions and the following disclaimer.
20 #
21 # 2. Redistributions in binary form must reproduce the above copyright
22 #    notice, this list of conditions and the following disclaimer in the
23 #    documentation and/or other materials provided with the distribution.
24 #
25 # 3. Neither the name of the author nor the names of any contributors
26 #    may be used to endorse or promote products derived from this
27 #    software without specific prior written permission.
28 #
29 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
30 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 # DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
37 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
38 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
39 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41 ## Commentary:
42
43 #  This script is used to locate headers that declare symbol.  symbol
44 #  being the thing you are searching for.  This is good for those
45 #  "unknown reference" errors.
46
47 ## Code:
48 ourname=${0##*/}
49
50 # Usage
51 if [ $# -lt 1 -o "$1" = "--help" -o "$1" = "--usage" -o "$1" = "-h" ]; then
52         echo 1>&2
53         echo 1>&2 'USAGE:  ${ourname} <symbol_regexp>'
54         echo 1>&2
55         echo 1>&2 '  Find headers that declare symbol matching <symbol_regexp>.'
56         echo 1>&2
57         echo 1>&2 '  See grep(1), '"'REGULAR EXPRESSIONS'"' for the syntax of regexps'
58         echo 1>&2 '  used by this script.'
59         echo 1>&2
60         exit 1
61 fi
62
63 # Header directories.
64 # These are the directories we search.  If you have other header directories
65 # such as /usr/local/include, /opt/include, add them here.
66 header_dirs=(/usr/include /usr/X11R6/include)
67
68 ## bastard header directories...
69 #header_dirs=(\
70 #       /usr/include \
71 #       /usr/X11R6/include \
72 #       /opt/jdk/include \
73 #       /opt/qt/include \
74 #       /opt/kde/include)
75
76 sym=${1}
77
78 all_headers=$(find -H -L ${header_dirs[*]} -type f -name "*.h" -print)
79
80 ### FIXME: This is totally brain dead, it'll match on shit you don't
81 #          want like comments.
82 #    A possible solution might be to use etags in some way.
83 for header in ${all_headers} ; do
84     grep -E -l --mmap --colour ${sym} ${header} 2>/dev/null
85 done
86
87 ## header-symbol-search ends here