xref: /original-bsd/usr.bin/lorder/lorder.sh (revision c3e32dec)
1#!/bin/sh -
2#
3# Copyright (c) 1990, 1993
4#	The Regents of the University of California.  All rights reserved.
5#
6# %sccs.include.redist.sh%
7#
8#	@(#)lorder.sh	8.1 (Berkeley) 06/06/93
9#
10
11PATH=/bin:/usr/bin
12export PATH
13
14# only one argument is a special case, just output the name twice
15case $# in
16	0)
17		echo "usage: lorder file ...";
18		exit ;;
19	1)
20		echo $1 $1;
21		exit ;;
22esac
23
24# temporary files
25R=/tmp/_reference_$$
26S=/tmp/_symbol_$$
27
28# remove temporary files on HUP, INT, QUIT, PIPE, TERM
29trap "rm -f $R $S; exit 1" 1 2 3 13 15
30
31# if the line ends in a colon, assume it's the first occurrence of a new
32# object file.  Echo it twice, just to make sure it gets into the output.
33#
34# if the line has " T " or " D " it's a globally defined symbol, put it
35# into the symbol file.
36#
37# if the line has " U " it's a globally undefined symbol, put it into
38# the reference file.
39nm -go $* | sed "
40	/:$/ {
41		s/://
42		s/.*/& &/
43		p
44		d
45	}
46	/ [TD] / {
47		s/:.* [TD] / /
48		w $S
49		d
50	}
51	/ U / {
52		s/:.* U / /
53		w $R
54	}
55	d
56"
57
58# sort symbols and references on the first field (the symbol)
59# join on that field, and print out the file names.
60sort +1 $R -o $R
61sort +1 $S -o $S
62join -j 2 -o 1.1 2.1 $R $S
63rm -f $R $S
64