Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / lint / lpass2 / lint
1 #!/bin/sh
2 # (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 # See the copyright notice in the ACK home directory, in the file "Copyright".
4 #
5 # $Id: lint,v 1.9 1994/09/16 12:41:55 ceriel Exp $
6
7 #       L I N T   D R I V E R
8
9 PATH=/bin:/usr/bin
10
11 EMDIR=/usr/em
12 EMLINT=$EMDIR/lib.bin/lint
13 INCLUDES=-I$EMDIR/include/_tail_cc
14
15 #LDEFMACH=-Dmc68000
16
17 PARAMS1=$LDEFMACH
18 LPASS1=${LPASS1-"$EMLINT/lpass1"}               # pass 1 program
19 LPASS2=${LPASS2-"$EMLINT/lpass2"}               # pass 2 program
20 LLIB=${LLIB-"$EMLINT/llib"}                     # lint libraries directory
21
22 LINTLIB=${LINTLIB-$LLIB}
23 CLIB=c.llb
24
25 TMP=/usr/tmp/lint1.$$
26 NEW=/usr/tmp/lint2.$$
27
28 trap "rm -f $TMP $NEW; exit 1" 1 2 15
29 trap "rm -f $TMP $NEW; exit 0" 0
30
31 set dummy $LINTFLAGS "$@"               # dummy as a shield for $LINTFLAGS
32 shift                                   # remove dummy
33
34 LIBRARY=
35
36 # get the non-library options
37 while   test -n "$1"
38 do
39         case "$1" in
40         -ansi)  LPASS1=${LPASS1}.ansi
41                 INCLUDES=-I$EMDIR/include/tail_ac
42                 CLIB=ansi_c.llb
43                 shift
44                 ;;
45         -l*)    # library parameter; start pass 1
46                 break
47                 ;;
48         -KR)    # strictly Kernighan & Ritchie, pass 1
49                 PARAMS1="$PARAMS1 -R"
50                 shift
51                 ;;
52         -D*=*)  # Define with equal sign; for pass 1 only
53                 # be careful about funny characters in -D
54                 # this is still not entirely correct
55                 HD=`expr "$1" : '\([^=]*\)=.*'`
56                 TL=`expr "$1" : '[^=]*=\(.*\)'`
57                 PARAMS1="$PARAMS1 $HD='$TL'"
58                 shift
59                 ;;
60         -[DUI]*)# Define, Undef and Include, otherwise; for pass 1 only
61                 # this is the simple case
62                 PARAMS1="$PARAMS1 $1"
63                 shift
64                 ;;
65         -L*)    # make a lint library
66                 LIBRARY=`expr "$1" : '-L\(.*\)'`
67                 shift
68                 ;;
69         -*)     # for pass 1 or pass 2
70                 PARAMS1="$PARAMS1 $1"
71                 PARAMS2="$PARAMS2 $1"
72                 shift
73                 ;;
74         *)      # input file; start pass 1
75                 break
76                 ;;
77         esac
78 done
79
80 case "$LIBRARY" in
81 '')     # normal lint; we want its messages on stdout; this takes some doing
82         (       # intermediate file has to go to stdout for pipe connection
83                 (       # pass 1: messages to stderr
84                         LIBC=true       # true if $CLIB to be included
85                         STATNR=0        # static scope number
86
87                         for F in $*
88                         do
89                                 case $F in
90                                 -l)     # do NOT include $CLIB
91                                         LIBC=false
92                                         ;;
93                                 -lc)    # do include $CLIB
94                                         LIBC=true
95                                         ;;
96                                 -l*)    # include special lint library
97                                         cat $LINTLIB/`expr $F : '-l\(.*\)'`.llb
98                                         ;;
99                                 *.c)    # a real C-file
100                                         STATNR=` expr $STATNR + 1 `
101                                         eval "$LPASS1 -S$STATNR -Dlint \
102                                                 $PARAMS1 $INCLUDES $F"
103                                         ;;
104                                 *)      # a lint library?
105                                         case `basename $F` in
106                                         *.llb)  # yes, it is
107                                                 cat $F
108                                                 ;;
109                                         *)
110                                                 echo $0: unknown input $F >&2
111                                                 ;;
112                                         esac
113                                         ;;
114                                 esac
115                         done
116
117                         case "$LIBC" in
118                         true)   # append $CLIB
119                                 cat $LINTLIB/$CLIB
120                                 ;;
121                         esac
122                 ) |
123                 sort -u |
124                 (       # pass 2: divert messages to avoid interleaving
125                         $LPASS2 $PARAMS2 2>$TMP
126                 )
127         ) 2>&1                          # messages pass 1 to stdout
128
129         # append messages pass 2
130         cat $TMP
131         ;;
132
133 ?*)     # making a lint library
134         set -e                          # stop at first sign of trouble
135
136         case `basename $LIBRARY` in
137         *.llb)  # OK
138                 ;;
139         *)      # no suffix .llb
140                 LIBRARY=$LIBRARY.llb
141                 ;;
142         esac
143
144         if      test ! -r $LIBRARY
145         then    cp /dev/null $LIBRARY
146         fi
147
148         # collect pass 1 intermediate output for all input files
149         for F in $@
150         do
151                 case $F in
152                 *.c)    # a C file
153                         eval "$LPASS1 $PARAMS1 $INCLUDES -Dlint -L $F"
154                         ;;
155                 *)      # a library?
156                         case `basename $F` in
157                         *.llb)  # yes, it is
158                                 cat $F
159                                 ;;
160                         *)
161                                 echo $0: unknown input $F >&2
162                                 ;;
163                         esac
164                         ;;
165                 esac
166         done >$NEW
167
168         # get the last line for each name and sort them
169         cat $LIBRARY $NEW |
170         awk -F: '
171                 {
172                 entry[$1] = $0;
173         }
174         END     {
175                 for (e in entry) {print entry[e];}
176         }
177         ' |
178         sort |
179         grep -v '^main:' >$TMP
180
181         cp $TMP $LIBRARY
182
183 esac
184
185 rm -f $TMP $NEW
186