date and time created 91/04/12 16:25:12 by bostic
[unix-history] / usr / src / usr.bin / lorder / lorder.sh
CommitLineData
2a50b0b4
KB
1#!/bin/sh -
2#
e04f3552
KB
3# Copyright (c) 1990 The Regents of the University of California.
4# All rights reserved.
2a50b0b4 5#
e04f3552
KB
6# Redistribution and use in source and binary forms are permitted
7# provided that the above copyright notice and this paragraph are
8# duplicated in all such forms and that any documentation,
9# advertising materials, and other materials related to such
10# distribution and use acknowledge that the software was developed
11# by the University of California, Berkeley. The name of the
12# University may not be used to endorse or promote products derived
13# from this software without specific prior written permission.
14# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2a50b0b4 17#
e04f3552
KB
18# @(#)lorder.sh 5.2 (Berkeley) %G%
19#
20PATH=/bin:/usr/bin
21export PATH
2a50b0b4 22
e04f3552 23# only one argument is a special case, just output the name twice
2a50b0b4 24case $# in
e04f3552
KB
25 0)
26 echo "usage: lorder file ...";
27 exit ;;
28 1)
29 echo $1 $1;
30 exit ;;
2a50b0b4 31esac
e04f3552
KB
32
33# temporary files
34R=/tmp/_reference_$$
35S=/tmp/_symbol_$$
36
37# remove temporary files on HUP, INT, QUIT, PIPE, TERM
38trap "rm -f $R $S; exit 1" 1 2 3 13 15
39
40# if the line ends in a colon, assume it's the first occurrence of a new
41# object file. Echo it twice, just to make sure it gets into the output.
42#
43# if the line has " T " or " D " it's a globally defined symbol, put it
44# into the symbol file.
45#
46# if the line has " U " it's a globally undefined symbol, put it into
47# the reference file.
48nm -go $* | sed "
49 /:$/ {
2a50b0b4 50 s/://
2a50b0b4
KB
51 s/.*/& &/
52 p
53 d
54 }
e04f3552
KB
55 / [TD] / {
56 s/:.* [TD]//
57 w $S
2a50b0b4
KB
58 d
59 }
e04f3552
KB
60 / U / {
61 s/:.* U//
62 w $R
63 }
2a50b0b4 64 d
e04f3552
KB
65"
66
67# sort symbols and references on the first field (the symbol)
68# join on that field, and print out the file names.
69sort +1 $R -o $R
70sort +1 $S -o $S
71join -j 2 -o 1.1 2.1 $R $S
72rm -f $R $S