home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / uccs / root.14 / udk / usr / ccs / bin / lint < prev    next >
Text File  |  1998-08-19  |  7KB  |  311 lines

  1. #!/bin/sh
  2. #ident    "@(#)alint:common/lint    1.39"
  3.  
  4. PATH=/bin:/usr/bin
  5. if [ "$TMPDIR" = "" ]
  6. then
  7.     unixver=`uname -r`
  8.     case $unixver in
  9.     4*) TMPDIR=/var/tmp ;;
  10.     3*) TMPDIR=/usr/tmp ;;
  11.     *)  TMPDIR=/usr/tmp ;;    # uts, etc.
  12.     esac
  13. fi
  14. LPASS=${_CCSLIB:-/udk/usr/ccs/lib}    # where pass 1 and pass2 are found
  15. LLDIR=${_CCSLIB:-/udk/usr/ccs/lib}    # where lint libraries are found
  16. TOUT=$TMPDIR/tlint.$$        # combined input for second pass
  17. T1=$TMPDIR/tlint1$$        # definitions from C source
  18. T2=$TMPDIR/tlint2$$        # tentative definitions from C source
  19. T3=$TMPDIR/tlint3$$        # function calls, misc
  20. T4=$TMPDIR/tlint4$$        # strings for printf/scanf checking
  21. HOUT=$TMPDIR/hlint$$        # header messages file
  22. NOUT=$TMPDIR/nlint$$        # holds names of included files
  23. LINT1=$LPASS/lint1        # pass 1 of lint
  24. LINT2=$LPASS/lint2        # pass 2 of lint
  25.  
  26. CPPF="-C '-Alint(on)'"        # options for cpp part of lint1
  27. LINTF=                # options for the lint passes
  28. FILES=                # the *.c and *.ln files in order
  29. NDOTC=0                # how many *.c were there
  30. DEFL=$LLDIR/llib-lc.ln        # the default lint library to use
  31. LLIB=                # lint library file to create
  32. LNOUT=                # for cflow
  33. CXOUT=                # for cxref
  34. CONLY=                # set for compile only (no second pass)
  35. PREONLY=            # run cpp only on file
  36. FULLPATH=            # set if -F option
  37. DIRLST=                # ordered list of args to -L option
  38. LIBLST=                # lint libs to look for in DIRLST
  39. RETVAL=
  40. EXIT=0                # Normal exit code
  41. VERSION=
  42. ERRORS=                # list of files with errors in them
  43. AMODE=                # ANSI modes: -Xt, -Xa, -Xc
  44. TMPFILES="$TOUT $HOUT $NOUT $T1 $T2 $T3 $T4"
  45.  
  46. trap "rm -f $TMPFILES; exit 2" 1 2 3 15
  47.  
  48. USAGE="Usage: lint [-abchkmnpsuvxyFV] [-I dir] [-lx] [-o lib] [-L libdir] file ..."
  49. BADUSE="lint: file with unknown suffix ignored:"
  50. ARGLIST=abcdefghijkl:mno:pqrstuvwxyz1:2:ABCD:EFGHI:JK:L:MN:OPQR:STU:VW:X:Y:Z
  51. while getopts $ARGLIST OPT "$@"
  52. do
  53.     case $OPT in
  54.     p)    LINTF="$LINTF -$OPT";;
  55.     n)    DEFL=;;
  56.     c)    CONLY=1;;
  57. #
  58. # W option for cfloW only - makes output go to specified file
  59. # R option for cxRef only - makes identifier output go to specified file
  60. #
  61.     W)    LINTF="$LINTF -$OPT"; LNOUT=$OPTARG;;
  62.     R)    LINTF="$LINTF -$OPT$OPTARG"; CXOUT=$OPTARG;;
  63.     [abhkmsuvxy]) LINTF="$LINTF -$OPT";;
  64.     V)    LINTF="$LINTF -$OPT"; VERSION=1;;
  65.     F)    LINTF="$LINTF -$OPT"; FULLPATH=1;;
  66.     [IDUY]) CPPF="$CPPF '-$OPT$OPTARG'";;
  67.     [PE])    CPPF="$CPPF -$OPT"; PREONLY=1;;
  68.     L)    DIRLST="$DIRLST $OPTARG";;
  69.     l)    LIBLST="$LIBLST llib-l$OPTARG.ln";;
  70.     o)    LLIB="llib-l$OPTARG.ln";;
  71.     [12K])    LINTF="$LINTF -$OPT$OPTARG";;
  72.     X)    LINTF="$LINTF -$OPT$OPTARG"; AMODE=$OPTARG;;
  73. #
  74. # some cc options to be ignored.
  75. #
  76.     [Og])    ;;
  77.     +*)    echo "lint: illegal option: +$OPT" >&2
  78.             echo $USAGE >&2
  79.             exit 2;;
  80.     \?)    echo $USAGE >&2
  81.             exit 2;;
  82.     *)    echo  "lint: unrecognized option: -$OPT, ignored" >&2
  83.         ;;
  84.     esac
  85. done
  86.  
  87. shift `expr $OPTIND - 1`
  88.  
  89. # pick up file names.  -o, -L or -l options may be specified anywhere
  90. # on the command line.  Other options are not permitted at this point.
  91.  
  92. while [ $# -gt 0 ]
  93. do
  94.     case $1 in    
  95.     --)    shift;;    
  96.     -*)    set -- `getopt "o:l:L:" "$@"`
  97.         if [ $? -ne 0 ]
  98.         then
  99.             echo $USAGE >&2
  100.             exit 2
  101.         fi
  102.         case $1 in
  103.             -o)    LLIB="llib-l$2.ln";    shift 2;;
  104.             -L)    DIRLST="$DIRLST $2";    shift 2;;
  105.             -l)    LIBLST="$LIBLST llib-l$2.ln"; shift 2;;
  106.             *)    echo $USAGE >&2
  107.                 exit 2;;
  108.         esac;;
  109.  
  110.     *.[ci])    FILES="$FILES $1"
  111.         NDOTC=`expr $NDOTC + 1`
  112.         shift;;
  113.     *.ln)    FILES="$FILES $1"; shift;;
  114. #
  115. # If making a lint library, then allow any suffix.  This is because
  116. # lint libraries typically look like: llib-lX where X stands for the
  117. # library (i.e. llib-lc, llib-lm, llib-lmalloc, etc ...)
  118.     *)    if [ ! "$LLIB" ]
  119.         then
  120.             echo $BADUSE $1 >&2
  121.         else
  122.             FILES="$FILES $1"
  123.             NDOTC=`expr $NDOTC + 1`
  124.         fi
  125.         shift;;
  126.     esac
  127. done
  128.  
  129.  
  130. #
  131. # Only use -Dlint if this isn't running as cxref (CXOUT) or
  132. # as cflow (LNOUT) or mode is not -Xc
  133. #
  134. if [ "$LNOUT" = "" -a "$CXOUT" = "" -a "$AMODE" != "c" ]
  135. then
  136.     CPPF="$CPPF -Dlint"
  137. fi
  138.     
  139.  
  140. # Give something to lint to do!
  141. if [ "$FILES" = "" ]
  142. then
  143.     if [ "$VERSION" = "" ]
  144.     then
  145.         echo "lint: no file arguments" >&2
  146.         exit 1
  147.     else
  148.         $LINT1 -V
  149.         exit 0
  150.     fi
  151. fi
  152.  
  153. #
  154. # Check to see if all the lint libraries specified on the command line
  155. # can be found either in the initial lint directory (normally /usr/ccs/lib),
  156. # /usr/lib, or in one of the user specified directories (via -L <dir>).
  157. #
  158. LLDIR="$DIRLST $LLDIR /usr/lib"
  159. for LIB in $LIBLST
  160. do
  161.     for DIR in $LLDIR
  162.     do
  163.         if [ -r "$DIR"/"$LIB" ]
  164.         then
  165.             FILES="$FILES $DIR/$LIB"
  166.             break
  167.         fi
  168.     done
  169.     if [ ! -r "$DIR"/"$LIB" ]
  170.     then
  171.         echo "lint: $LIB not found" >&2
  172.     fi
  173. done
  174.  
  175. #
  176. # Run pass1 only, creating .ln files.
  177. # Any .ln files on the command line will be ignored.
  178. #
  179. if [ "$CONLY" -o "$PREONLY" ]
  180. then
  181.     for i in $FILES
  182.     do
  183.     case $i in
  184.     *.ln)    ;;
  185.     *)    T=`basename $i .c`.ln
  186.         if [ "$FULLPATH" ]
  187.         then
  188.             FNAME=$i
  189.         else
  190.             FNAME=`basename $i`
  191.         fi
  192.  
  193.         if [ $NDOTC -gt 1 ]
  194.         then
  195.             echo $FNAME:
  196.         fi
  197.         CMD=`echo $LINT1 $CPPF $LINTF -T $HOUT,$NOUT,$T1,$T2,$T3,$T4 $i`
  198.         eval $CMD
  199. #
  200. # If return value is 0, save the output to the .ln file, and print
  201. # header file warnings.
  202.         RETVAL=$?
  203.         if [ $RETVAL = 0 ]
  204.         then
  205.             if [ ! "$PREONLY" ]
  206.             then
  207.             cat $T1 $T2 $T3 $T4 > $T
  208.             cat -s $HOUT
  209.             fi
  210.         else
  211.             cat -s $HOUT
  212.             echo "lint: errors in $FNAME; no output created" >&2
  213.             EXIT=$RETVAL
  214.         fi
  215.         rm -f $HOUT $NOUT;;
  216.     esac
  217.     done
  218. else
  219.     for i in $FILES
  220.     do
  221.     case $i in
  222.     *.ln)    cat <$i >> $TOUT;;
  223.     *)    if [ "$FULLPATH" ]
  224.         then
  225.             FNAME=$i
  226.         else
  227.             FNAME=`basename $i`
  228.         fi
  229.  
  230.         if [ $NDOTC -gt 1 ]
  231.         then
  232.             echo $FNAME:
  233.         fi
  234.         CMD=`echo $LINT1 $CPPF $LINTF -T $HOUT,$NOUT,$T1,$T2,$T3,$T4 $i`
  235.         eval $CMD
  236.         RETVAL=$?
  237. #
  238. # If return value ok, save into temp file for later use by lint2.
  239. # Otherwise, cat the header file messages, and indicate there was
  240. # a problem.
  241. #
  242.  
  243.         if [ $RETVAL = 0 ]
  244.         then
  245.             cat $T1 $T2 $T3 $T4 >> $TOUT
  246.         else
  247.         #rm -f $HOUT $NOUT
  248.             echo "lint: errors in $FNAME; no output created" >&2
  249.             if [ "$ERRORS" = "" ]
  250.             then
  251.             ERRORS=$FNAME
  252.             else
  253.             ERRORS="$ERRORS,$FNAME"
  254.             fi
  255.             EXIT=$RETVAL
  256.         fi
  257.         ;;
  258.     esac
  259.     done
  260.  
  261.     if [ $EXIT != 0 ]
  262.     then
  263.     cat -s $HOUT
  264.     rm -f $TMPFILES
  265.     echo "lint: pass2 not run - errors in $ERRORS" >&2
  266.     exit $EXIT
  267.     fi
  268.  
  269. # A lint library is to be created.
  270.     if [ "$LLIB" ]
  271.     then
  272.     cp $TOUT $LLIB
  273.     fi
  274.  
  275.     if [ "$LNOUT" ]
  276.     then
  277.     cp $TOUT $LNOUT
  278.     rm -f $TMPFILES
  279.     exit 0
  280.     fi
  281.  
  282.     if [ "$CXOUT" ]
  283.     then
  284.     rm -f $TMPFILES
  285.     exit 0
  286.     fi
  287.  
  288. # Add in the default lint library (if -n was not used)
  289.     if [ "$DEFL" ]
  290.     then
  291.     cat <$DEFL >> $TOUT
  292.     fi
  293.  
  294. # Print the errors/warnings from the header file
  295.     cat -s $HOUT
  296.  
  297.     CMD=`echo $LINT2 $LINTF $TOUT`
  298.     eval $CMD
  299.     RETVAL=$?
  300.     if [ $RETVAL != 0 ]
  301.     then
  302.     rm -f $TMPFILES
  303.     exit $RETVAL
  304.     fi
  305. fi
  306.  
  307. rm -f $TMPFILES
  308. exit $EXIT
  309.