missing ncurses sources
[tomato.git] / release / src / router / libncurses / test / listused.sh
blob1c3fe0a64d5130a908c09ce2ffb19c887923458c
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2003-2006,2010 Free Software Foundation, Inc. #
4 # #
5 # Permission is hereby granted, free of charge, to any person obtaining a #
6 # copy of this software and associated documentation files (the "Software"), #
7 # to deal in the Software without restriction, including without limitation #
8 # the rights to use, copy, modify, merge, publish, distribute, distribute #
9 # with modifications, sublicense, and/or sell copies of the Software, and to #
10 # permit persons to whom the Software is furnished to do so, subject to the #
11 # following conditions: #
12 # #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
15 # #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
19 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
22 # DEALINGS IN THE SOFTWARE. #
23 # #
24 # Except as contained in this notice, the name(s) of the above copyright #
25 # holders shall not be used in advertising or otherwise to promote the sale, #
26 # use or other dealings in this Software without prior written #
27 # authorization. #
28 ##############################################################################
29 # $Id: listused.sh,v 1.8 2010/09/18 15:15:15 tom Exp $
30 # A very simple script to list all entrypoints that are used by either a test
31 # program, or within the libraries. This relies on the output format of 'nm',
32 # and assumes that the libraries are configured with TRACE defined, and using
33 # these options:
34 # --disable-macros
35 # --enable-sp-funcs
36 # --enable-widec
37 # Static libraries are used, to provide some filtering based on internal usage
38 # of the different symbols.
40 # keep the sorting independent of locale:
41 if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
42 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
43 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
44 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
45 if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
46 if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
48 NM_OPTS=
50 if test ! -d ../objects ; then
51 echo "? need objects to run this script"
52 exit 1
53 elif test ! -d ../lib ; then
54 echo "? need libraries to run this script"
55 exit 1
58 PROGS=
59 for name in `(echo "test:";sort modules; echo "progs:";sort ../progs/modules) |sed -e 's/[ ].*//' -e '/^[#@]/d'`
61 case $name in
62 *:)
63 PROGS="$PROGS $name"
66 NAME=../objects/${name}.o
67 if test -f $NAME
68 then
69 PROGS="$PROGS $NAME"
72 esac
73 done
75 # For each library -
76 for lib in ../lib/*.a
78 LIB=`basename $lib .a`
79 case $LIB in
80 *_*|*+*)
81 continue
83 esac
85 tmp=`echo $LIB|sed -e 's/w$//'`
86 echo
87 echo "${tmp}:"
88 echo $tmp |sed -e 's/./-/g'
89 # Construct a list of public externals provided by the library.
90 WANT=`nm $NM_OPTS $lib |\
91 sed -e 's/^[^ ]*//' \
92 -e 's/^ *//' \
93 -e '/^[ a-z] /d' \
94 -e '/:$/d' \
95 -e '/^$/d' \
96 -e '/^U /d' \
97 -e 's/^[A-Z] //' \
98 -e '/^_/d' |\
99 sort -u`
100 # List programs which use that external.
101 for name in $WANT
103 HAVE=
104 tags=
105 last=
106 for prog in $PROGS
108 case $prog in
110 tags=$prog
113 TEST=`nm $NM_OPTS $prog |\
114 sed -e 's/^[^ ]*//' \
115 -e 's/^ *//' \
116 -e '/^[ a-z] /d' \
117 -e '/:$/d' \
118 -e '/^$/d' \
119 -e 's/^[A-Z] //' \
120 -e '/^_/d' \
121 -e 's/^'${name}'$/_/' \
122 -e '/^[^_]/d'`
123 if test -n "$TEST"
124 then
125 have=`basename $prog .o`
126 if test -n "$HAVE"
127 then
128 if test "$last" = "$tags"
129 then
130 HAVE="$HAVE $have"
131 else
132 HAVE="$HAVE $tags $have"
134 else
135 HAVE="$tags $have"
137 last="$tags"
140 esac
141 done
142 # if we did not find a program using it directly, see if it
143 # is used within a library.
144 if test -z "$HAVE"
145 then
146 for tmp in ../lib/*.a
148 case $tmp in
149 *_*|*+*)
150 continue
152 esac
153 TEST=`nm $NM_OPTS $tmp |\
154 sed -e 's/^[^ ]*//' \
155 -e 's/^ *//' \
156 -e '/^[ a-z] /d' \
157 -e '/:$/d' \
158 -e '/^$/d' \
159 -e '/^[A-TV-Z] /d' \
160 -e 's/^[A-Z] //' \
161 -e '/^_/d' \
162 -e 's/^'${name}'$/_/' \
163 -e '/^[^_]/d'`
164 if test -n "$TEST"
165 then
166 tmp=`basename $tmp .a |sed -e 's/w$//'`
167 HAVE=`echo $tmp | sed -e 's/lib/lib: /'`
168 break
170 done
172 test -z "$HAVE" && HAVE="-"
173 lenn=`expr 39 - length $name`
174 lenn=`expr $lenn / 8`
175 tabs=
176 while test $lenn != 0
178 tabs="${tabs} "
179 lenn=`expr $lenn - 1`
180 done
181 echo "${name}${tabs}${HAVE}"
182 done
183 done