ack/lang/cem/lint/lpass2/lint

187 lines
3.4 KiB
Text
Raw Normal View History

1988-10-13 11:31:00 +00:00
#!/bin/sh
# (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
# See the copyright notice in the ACK home directory, in the file "Copyright".
#
1994-06-24 14:02:31 +00:00
# $Id$
1988-10-13 11:31:00 +00:00
# L I N T D R I V E R
PATH=/bin:/usr/bin
1991-10-01 14:59:33 +00:00
EMDIR=/usr/em
EMLINT=$EMDIR/lib.bin/lint
INCLUDES=-I$EMDIR/include/_tail_cc
1988-10-13 11:31:00 +00:00
#LDEFMACH=-Dmc68000
1988-10-28 16:27:32 +00:00
1991-09-30 16:53:21 +00:00
PARAMS1=$LDEFMACH
LPASS1=${LPASS1-"$EMLINT/lpass1"} # pass 1 program
LPASS2=${LPASS2-"$EMLINT/lpass2"} # pass 2 program
LLIB=${LLIB-"$EMLINT/llib"} # lint libraries directory
LINTLIB=${LINTLIB-$LLIB}
1991-09-30 16:53:21 +00:00
CLIB=c.llb
1988-10-13 11:31:00 +00:00
TMP=/tmp/lint1.$$
NEW=/tmp/lint2.$$
1988-10-13 11:31:00 +00:00
trap "rm -f $TMP $NEW; exit 1" 1 2 15
trap "rm -f $TMP $NEW; exit 0" 0
1994-09-16 12:41:55 +00:00
set dummy $LINTFLAGS "$@" # dummy as a shield for $LINTFLAGS
1988-10-13 11:31:00 +00:00
shift # remove dummy
1988-10-28 16:27:32 +00:00
LIBRARY=
1988-10-13 11:31:00 +00:00
# get the non-library options
while test -n "$1"
do
case "$1" in
1991-09-30 16:53:21 +00:00
-ansi) LPASS1=${LPASS1}.ansi
1991-10-01 14:59:33 +00:00
INCLUDES=-I$EMDIR/include/tail_ac
1991-09-30 16:53:21 +00:00
CLIB=ansi_c.llb
shift
;;
1988-10-13 11:31:00 +00:00
-l*) # library parameter; start pass 1
break
;;
-KR) # strictly Kernighan & Ritchie, pass 1
PARAMS1="$PARAMS1 -R"
shift
;;
1994-09-16 12:41:55 +00:00
-D*=*) # Define with equal sign; for pass 1 only
# be careful about funny characters in -D
# this is still not entirely correct
HD=`expr "$1" : '\([^=]*\)=.*'`
TL=`expr "$1" : '[^=]*=\(.*\)'`
PARAMS1="$PARAMS1 $HD='$TL'"
shift
;;
-[DUI]*)# Define, Undef and Include, otherwise; for pass 1 only
# this is the simple case
1988-10-13 11:31:00 +00:00
PARAMS1="$PARAMS1 $1"
shift
;;
-L*) # make a lint library
1988-10-28 16:27:32 +00:00
LIBRARY=`expr "$1" : '-L\(.*\)'`
1988-10-13 11:31:00 +00:00
shift
;;
-*) # for pass 1 or pass 2
PARAMS1="$PARAMS1 $1"
PARAMS2="$PARAMS2 $1"
shift
;;
*) # input file; start pass 1
break
;;
esac
done
case "$LIBRARY" in
1988-10-28 16:27:32 +00:00
'') # normal lint; we want its messages on stdout; this takes some doing
1988-10-13 11:31:00 +00:00
( # intermediate file has to go to stdout for pipe connection
( # pass 1: messages to stderr
1991-09-30 16:53:21 +00:00
LIBC=true # true if $CLIB to be included
1988-10-13 11:31:00 +00:00
STATNR=0 # static scope number
for F in $*
do
case $F in
1991-09-30 16:53:21 +00:00
-l) # do NOT include $CLIB
LIBC=false
1988-10-13 11:31:00 +00:00
;;
1991-09-30 16:53:21 +00:00
-lc) # do include $CLIB
1988-10-13 11:31:00 +00:00
LIBC=true
;;
-l*) # include special lint library
1988-10-28 16:27:32 +00:00
cat $LINTLIB/`expr $F : '-l\(.*\)'`.llb
1988-10-13 11:31:00 +00:00
;;
*.c) # a real C-file
STATNR=` expr $STATNR + 1 `
1994-09-16 12:41:55 +00:00
eval "$LPASS1 -S$STATNR -Dlint \
$PARAMS1 $INCLUDES $F"
1988-10-13 11:31:00 +00:00
;;
*) # a lint library?
case `basename $F` in
1988-10-28 16:27:32 +00:00
*.llb) # yes, it is
1988-10-13 11:31:00 +00:00
cat $F
;;
*)
echo $0: unknown input $F >&2
;;
esac
;;
esac
done
case "$LIBC" in
1991-09-30 16:53:21 +00:00
true) # append $CLIB
cat $LINTLIB/$CLIB
1988-10-13 11:31:00 +00:00
;;
esac
) |
sort -u |
( # pass 2: divert messages to avoid interleaving
$LPASS2 $PARAMS2 2>$TMP
)
) 2>&1 # messages pass 1 to stdout
# append messages pass 2
cat $TMP
;;
1988-10-28 16:27:32 +00:00
?*) # making a lint library
1988-10-13 11:31:00 +00:00
set -e # stop at first sign of trouble
case `basename $LIBRARY` in
1988-10-28 16:27:32 +00:00
*.llb) # OK
1988-10-13 11:31:00 +00:00
;;
1988-10-28 16:27:32 +00:00
*) # no suffix .llb
LIBRARY=$LIBRARY.llb
1988-10-13 11:31:00 +00:00
;;
esac
1993-11-16 12:00:06 +00:00
if test ! -r $LIBRARY
1988-10-13 11:31:00 +00:00
then cp /dev/null $LIBRARY
fi
# collect pass 1 intermediate output for all input files
for F in $@
do
case $F in
*.c) # a C file
1994-09-16 12:41:55 +00:00
eval "$LPASS1 $PARAMS1 $INCLUDES -Dlint -L $F"
1988-10-13 11:31:00 +00:00
;;
*) # a library?
case `basename $F` in
1988-10-28 16:27:32 +00:00
*.llb) # yes, it is
1988-10-13 11:31:00 +00:00
cat $F
;;
*)
echo $0: unknown input $F >&2
;;
esac
;;
esac
done >$NEW
# get the last line for each name and sort them
cat $LIBRARY $NEW |
awk -F: '
1988-10-28 16:27:32 +00:00
{
entry[$1] = $0;
}
END {
for (e in entry) {print entry[e];}
}
1988-10-13 11:31:00 +00:00
' |
1988-10-28 16:27:32 +00:00
sort |
grep -v '^main:' >$TMP
1988-10-13 11:31:00 +00:00
cp $TMP $LIBRARY
esac
rm -f $TMP $NEW