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

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11.  
  12. #ident    "@(#)cxref:common/cxref.sh    1.4"
  13. USRLIB=${USRLIB:-/udk/usr/ccs/lib}    # where the executables are
  14. TMPDIR=${TMPDIR:-/usr/tmp}    # where to put temporary files
  15. TOUT=$TMPDIR/tcx.$$        # combined input for second pass
  16. LINTF=                # options to pass to lint
  17. FILES=                # the *.c and *.cx files in order
  18. NDOTC=0                # how many *.c were there
  19. CONLY=                # set for "compile only" (no second pass)
  20. LINK=                # set for link together all sources
  21. SILENT=                # set with -s option
  22. FULLPATH=    
  23. OUTFILE=
  24. FNUM=0
  25. CXOPT=                # options to cxref
  26. TMPFILES="$TMPDIR/tcx.$$ $TMPDIR/cx.$$.*"
  27. XREF=$USRLIB/xref        # the cxref program
  28. LINT=${PFX}lint            # lint (with prefix if in cross)
  29.  
  30. trap "rm -f $TMPFILES; exit 2" 1 2 3 15
  31.  
  32. USAGE="Usage: cxref [-scCVFdlt] [-o file] [-w width] [-L cols] [-Wname,file,func,line] files ..."
  33. BADUSE="cxref: file with unknown suffix"
  34. OPTARG=cVFD:Y:I:U:1:dlW:L:OgCw:tso:K:
  35. set -- `getopt $OPTARG "$@"`
  36. if [ $? -ne 0 ]
  37. then
  38.     echo "$USAGE" >&2
  39.     rm -f $TMPFILES
  40.     exit 2
  41. fi
  42. while [ $# -gt 0 ]
  43. do
  44.     case $1 in
  45.     -[Og])    shift;;
  46.     -C)    shift; CONLY=1;;
  47.     -c)    shift; LINK=1;;
  48.     -s)    shift; SILENT=1;;
  49.     -F)    FULLPATH=1; LINTF="$LINTF $1"; shift;;
  50.     -[IDUYK])    LINTF="$LINTF $1$2"; shift 2;;
  51.     -1)    LINTF="$LINTF $1$2"; shift 2;;
  52.     -o)    OUTFILE=$2; shift 2;;
  53.     -V)    $XREF -V; shift;;
  54.     -[ldt])    CXOPT="$CXOPT $1"; shift;;
  55.     -[LWw])    CXOPT="$CXOPT $1$2"; shift 2;;
  56.     --)    shift;
  57.         while [ $# -gt 0 ]
  58.         do
  59.             case $1 in    
  60.             -*)    set -- `getopt $OPTARG "$@"`;
  61.                 if [ $? -ne 0 ]
  62.                 then
  63.                     echo "$USAGE" >&2
  64.                     exit 2
  65.                 fi
  66.                 break;;
  67.             *.[ci])    FILES="$FILES $1"
  68.                 NDOTC=`expr $NDOTC + 1`
  69.                 shift;;
  70.             *.cx)    FILES="$FILES $1"; shift;;
  71.             *)    echo $BADUSE $1 >&2
  72.                 exit 1
  73.                 shift;;
  74.             esac
  75.         done
  76.         ;;
  77.     -*)    echo "cxref: bad option ignored: $1" >&2;;
  78.     esac
  79. done
  80.  
  81. #
  82. # No files specified!
  83. #
  84. if [ "$FILES" = "" ]
  85. then
  86.     echo "cxref: no file arguments" >&2
  87.     exit 1
  88. fi
  89.  
  90. #
  91. # If no file has been specified for output, then direct to stdout
  92. #
  93. if [ "$OUTFILE" ]
  94. then
  95.     exec > $OUTFILE
  96. fi
  97.  
  98. #
  99. # Run pass1 (lint) only, creating .cx files.
  100. # Any .cx files on the command line will be ignored.
  101. #
  102. if [ "$CONLY" ]
  103. then
  104.     for i in $FILES
  105.     do
  106.     case $i in
  107.     *.cx)    ;;
  108.     *)    T=`basename $i .c`.cx
  109.         if [ "$SILENT" = "" ]
  110.         then
  111.             if [ "$FULLPATH" ]
  112.             then
  113.             echo "$i:" 
  114.             else
  115.             echo "`basename $i`:" 
  116.             fi
  117.         fi
  118.         $LINT $LINTF -R $TMPDIR/cx.$$ $i > /dev/null
  119.         RETVAL=$?
  120.         if [ $RETVAL = 0 ]
  121.         then
  122.             mv $TMPDIR/cx.$$.lnt $T
  123.         else
  124.             echo "cxref: errors in $i; no output created" >&2
  125.             rm -f $TMPFILES
  126.             exit $RETVAL
  127.         fi;;
  128.     esac
  129.     done
  130. else
  131.     for i in $FILES
  132.     do
  133.     case $i in
  134.     *.cx)    if [ "$SILENT" = "" ]
  135.         then
  136.             if [ "$FULLPATH" ]
  137.             then 
  138.             echo "$i:" 
  139.             else
  140.             echo "`basename $i`:" 
  141.             fi
  142.         fi
  143.         if [ "$LINK" ]
  144.         then
  145.             FNUM=`expr $FNUM + 1`
  146.             echo "M $FNUM" >> $TOUT
  147.             cat $i >> $TOUT
  148.         else
  149.             $XREF $CXOPT < $i 
  150.             if [ $? -ne 0 ]
  151.             then
  152.             echo "cxref: errors; no output created" >&2
  153.             rm -f $TMPFILES
  154.             exit 1
  155.             fi
  156.             echo " " 
  157.         fi;;
  158.     
  159.     *)    if [ "$SILENT" = "" ]
  160.         then
  161.             if [ "$FULLPATH" ]
  162.             then
  163.             echo $i: 
  164.             else
  165.             echo `basename $i`: 
  166.             fi
  167.         fi
  168.         $LINT $LINTF -R $TMPDIR/cx.$$ $i > /dev/null
  169.         RETVAL=$?
  170.         if [ $RETVAL = 0 ]
  171.         then
  172.             if [ "$LINK" ]
  173.             then
  174.             FNUM=`expr $FNUM + 1`
  175.             echo "M $FNUM" >> $TOUT
  176.             cat $TMPDIR/cx.$$.lnt >> $TOUT
  177.             else
  178.             $XREF $CXOPT < $TMPDIR/cx.$$.lnt 
  179.             if [ $? -ne 0 ]
  180.             then
  181.                 echo "cxref: errors; no output created" >&2
  182.                 rm -f $TMPFILES
  183.                 exit 1
  184.             fi
  185.             echo " " 
  186.             fi
  187.         else
  188.             echo "cxref: errors in $i; no output created" >&2
  189.             rm -f $TMPFILES
  190.             exit $RETVAL
  191.         fi
  192.         ;;
  193.     esac
  194.     done
  195.  
  196.     if [ "$LINK" ]
  197.     then
  198.     $XREF $CXOPT < $TOUT 
  199.     if [ $? -ne 0 ]
  200.     then
  201.         echo "cxref: errors; no output created" >&2
  202.         rm -f $TMPFILES
  203.         exit 1
  204.     fi
  205.     fi
  206.     RETVAL=$?
  207. fi
  208.  
  209. rm -f $TMPFILES
  210. exit 0
  211.