home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / uccs / root.14 / udk / usr / ccs / bin / cflow next >
Text File  |  1998-08-19  |  4KB  |  226 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    "@(#)cflow:common/cflow.sh    1.5"
  13. USRLIB=${USRLIB:-/udk/usr/ccs/lib}        # where the executables are
  14. INVFLG=                    # invert caller:callee relationship
  15. DFLAG=                    # depth for flowgraph
  16. AFLAG=                    # report duplicate calls
  17. IFLAG=                    # ix: include external, static:
  18.                     #      ix doesn't work right
  19.                     # i_: include names with _
  20. NDOTC=0                    # how many files to process
  21. CONLY=                    # first pass only
  22. LINTF=                    # options to pass to lint
  23. TMPDIR=${TMPDIR:-/usr/tmp}        # place to put temp files
  24. TMP=$TMPDIR/cf.$$            # temp file for first pass
  25. TMPG=$TMPDIR/tcf.$$            # temp file for second pass
  26.  
  27. #
  28. # If we are in a cross environment, pick up the correct nm and lint
  29. # (they will be prefixed with PFX)
  30. #
  31. NM=${PFX}nm
  32. LINT=${PFX}lint
  33. AS=${PFX}as
  34.  
  35. #
  36. # Abbreviations for the 4 cflow programs.
  37. #
  38. LPFX=$USRLIB/lpfx
  39. FLIP=$USRLIB/flip
  40. DAG=$USRLIB/dag
  41. NMF=$USRLIB/nmf
  42.  
  43. trap "rm -f $TMP $TMPG; kill $$" 1 2 3
  44. USAGE="Usage: cflow [-acrV] [-ix] [-i_] [-d tag] [-Kdollar] files ..."
  45. BADUSE="cflow: file with unknown suffix ignored:"
  46. ERRORS="cflow: errors in source file"
  47. OPTARG=Oagrcd:i:I:D:U:Y:VK:
  48.  
  49. set -- `getopt $OPTARG "$@"`
  50. if [ $? -ne 0 ]
  51. then
  52.     echo $USAGE >&2
  53.     rm -f $TMP $TMPG
  54.     exit 2
  55. fi
  56.  
  57. while [ $# -gt 0 ]
  58. do
  59.     case $1 in
  60.     -[Og])    shift;;
  61.     -V)    $LPFX -V; shift;;
  62.     -r)    INVFLG=1; shift;;
  63.     -c)    CONLY=1; shift;;
  64.     -a)    AFLAG="$1"; shift;;
  65.     -d)    DFLAG="$1$2"; shift 2;;
  66.     -i)    IFLAG="$IFLAG $1 $2"
  67.         if [ "$2" = "x" ]
  68.         then
  69.             LINTF="$LINTF -x"
  70.         fi
  71.         shift 2;;
  72.     -[IDUYK])    LINTF="$LINTF $1$2"; shift 2;;
  73.     --)    shift;
  74.         while [ $# -gt 0 ]
  75.         do
  76.             case $1 in    
  77.             -*)    set -- `getopt $OPTARG "$@"`;
  78.                 if [ $? -ne 0 ]
  79.                 then
  80.                     echo $USAGE >&2
  81.                     exit 2
  82.                 fi
  83.                 break;;
  84.             *.[cilyos])    
  85.                 FILES="$FILES $1"
  86.                 NDOTC=`expr $NDOTC + 1`
  87.                 shift;;
  88.             *.cf)    FILES="$FILES $1"; shift;;
  89.             *)    echo $BADUSE $1 >&2
  90.                 shift;;
  91.             esac
  92.         done
  93.         ;;
  94.     -*)    echo "cflow: bad option ignored: $1" >&2; shift;;
  95.     esac
  96. done
  97.  
  98. #
  99. # Give something to cflow to do!
  100. #
  101. if [ "$FILES" = "" ]
  102. then
  103.     echo "cflow: no file arguments" >&2
  104.     rm -f $TMP $TMPG
  105.     exit 1
  106. fi
  107.  
  108. #
  109. # Process the files
  110. #
  111. for I in $FILES
  112. do
  113.     case $I in
  114.     #
  115.     # Run pass2 only on a .cf file
  116.     #
  117.     *.cf)
  118.         if [ "$CONLY" = "" ]
  119.         then
  120.             cat $I >> $TMPG
  121.         fi
  122.         ;;
  123.  
  124.     #
  125.     # .y and .l files should be passed directly to cflow, rather than
  126.     # the file proceduced by yacc/lex; otherwise line numbers
  127.     # will get confused.
  128.     #
  129.     *.[yl])
  130.         case $I in
  131.         *.y) CMD=yacc; SUF=y; CMDFILE=y.tab.c;;
  132.         *.l) CMD=lex; SUF=l; CMDFILE=lex.yy.c;;
  133.         esac
  134.         $CMD $I
  135.         if [ $? != 0 ]
  136.         then
  137.             echo $ERRORS >&2
  138.             rm -f $TMP $TMPG $CMDFILE
  139.             exit 1
  140.         fi
  141.         sed -e "/^# line/d" $CMDFILE > $I.c
  142.         $LINT $LINTF -W $TMP $I.c > /dev/null
  143.         if [ $? != 0 ]
  144.         then
  145.             echo $ERRORS >&2
  146.             rm -f $TMP $TMPG $CMDFILE $I.c
  147.             exit 1
  148.         fi
  149.         if [ "$CONLY" ]
  150.         then
  151.             $LPFX $IFLAG < $TMP > `basename $I .$SUF`.cf
  152.         else
  153.             $LPFX $IFLAG < $TMP >> $TMPG
  154.         fi
  155.         rm $CMDFILE $I.c
  156.         ;;
  157.  
  158.     *.[ci])
  159.         case $I in
  160.         *.c)  SUF=c;;
  161.         *.i)  SUF=i;;
  162.         esac
  163.         $LINT $LINTF -W $TMP $I > /dev/null
  164.         if [ $? != 0 ]
  165.         then
  166.             echo $ERRORS >&2
  167.             rm -f $TMP $TMPG
  168.             exit 1
  169.         fi
  170.         if [ "$CONLY" ]
  171.         then
  172.             $LPFX $IFLAG < $TMP > `basename $I .$SUF`.cf
  173.         else
  174.             $LPFX $IFLAG < $TMP >> $TMPG
  175.         fi
  176.         ;;
  177.  
  178.     *.[os])
  179.         TMPNM=$TMPDIR/cfnm.$$
  180.         case $I in
  181.         *.s) SUF=s; $AS -o $TMP.o $I
  182.             if [ $? != 0 ]
  183.             then
  184.                 echo $ERRORS >&2
  185.                 rm -f $TMP $TMPG
  186.                 exit 1
  187.             fi
  188.             DOTO=$TMP.o;;
  189.         *.o) SUF=o; DOTO=$I;;
  190.         esac
  191.  
  192.         a=`basename $I .$SUF`
  193.                 $NM -h $DOTO | sort -t'|' -n +1 -2 > $TMPNM 
  194.         if [ $? != 0 ]
  195.         then
  196.             echo $ERRORS >&2
  197.             rm -f $TMP $TMPG $TMPNM
  198.             exit 1
  199.         fi
  200.         if [ "$CONLY" ]
  201.         then
  202.             $NMF $a ${a}.$SUF < $TMPNM > $a.cf
  203.         else
  204.             $NMF $a ${a}.$SUF < $TMPNM >>$TMPG
  205.         fi
  206.         rm -f $TMPNM
  207.         ;;
  208.     esac
  209. done
  210.  
  211. if [ "$CONLY" = "" ]
  212. then
  213.     if [ "$INVFLG" != "" ]
  214.     then
  215.         sed -n "/=/p" < $TMPG > $TMP.q
  216.         sed -n "/:/p" < $TMPG | $FLIP >> $TMP.q
  217.         sort < $TMP.q > $TMPG
  218.         rm $TMP.q
  219.     fi
  220.     $DAG $DFLAG $AFLAG < $TMPG
  221.     rm -f $TMP.?
  222. fi
  223.  
  224. rm -f $TMP $TMPG
  225. exit 0
  226.