lint 3.4 KB

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