home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 6.ddi / usr / bin / dircmp < prev    next >
Encoding:
Text File  |  1990-12-08  |  3.1 KB  |  139 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12. #ident    "@(#)/usr/bin/dircmp.sl 1.1 4.0 12/08/90 19425 AT&T-USL"
  13. PATH=/usr/bin
  14. USAGE="dircmp: usage: dircmp -s -d -wn directory directory"
  15. trap "rm -f /usr/tmp/dc$$*;exit" 1 2 3 15
  16. Sflag=""
  17. Dflag=""
  18. width=72
  19. if type getopts | grep 'not found' > /dev/null
  20. then
  21.     eval set -- "`getopt dsw: "$@"`"
  22.     if [ $? != 0 ]
  23.     then
  24.         echo $USAGE
  25.         exit 2
  26.     fi
  27.     for i in $*
  28.     do
  29.         case $i in
  30.         -d)    Dflag="yes"; shift;;
  31.         -s)    Sflag="yes"; shift;;
  32.         -w)    width=`expr $2 + 0 2>/dev/null`
  33.             if [ $? = 2 ]
  34.             then echo "dircmp: numeric argument required"
  35.                 exit 2
  36.             fi
  37.             shift 2
  38.             ;;
  39.         --)    shift; break;;
  40.         esac
  41.     done
  42. else
  43.     while getopts dsw: i
  44.     do
  45.         case $i in
  46.         d)    Dflag="yes";; 
  47.         s)    Sflag="yes";; 
  48.         w)    width=`expr $OPTARG + 0 2>/dev/null`
  49.             if [ $? = 2 ]
  50.             then echo "dircmp: numeric argument required"
  51.                 exit 2
  52.             fi
  53.             ;;
  54.         \?)    echo $USAGE
  55.             exit 2;;
  56.         esac
  57.     done
  58.     shift `expr $OPTIND - 1`
  59. fi
  60. D0=`pwd`
  61. D1=$1
  62. D2=$2
  63. if [ $# -lt 2 ]
  64. then echo $USAGE
  65.      exit 1
  66. elif [ ! -d "$D1" ]
  67. then echo $D1 not a directory !
  68.      exit 2
  69. elif [ ! -d "$D2" ]
  70. then echo $D2 not a directory !
  71.      exit 2
  72. fi
  73. cd $D1
  74. find . -print | sort > /usr/tmp/dc$$a
  75. cd $D0
  76. cd $D2
  77. find . -print | sort > /usr/tmp/dc$$b
  78. comm /usr/tmp/dc$$a /usr/tmp/dc$$b | sed -n \
  79.     -e "/^        /w /usr/tmp/dc$$c" \
  80.     -e "/^    [^    ]/w /usr/tmp/dc$$d" \
  81.     -e "/^[^    ]/w /usr/tmp/dc$$e"
  82. rm -f /usr/tmp/dc$$a /usr/tmp/dc$$b
  83. pr -w${width} -h "$D1 only and $D2 only" -m /usr/tmp/dc$$e /usr/tmp/dc$$d
  84. rm -f /usr/tmp/dc$$e /usr/tmp/dc$$d
  85. sed -e s/..// < /usr/tmp/dc$$c > /usr/tmp/dc$$f
  86. rm -f /usr/tmp/dc$$c
  87. cd $D0
  88. > /usr/tmp/dc$$g
  89. while read a
  90. do
  91.     if [ -d $D1/"$a" ]
  92.     then if [ "$Sflag" != "yes" ]
  93.          then echo "directory    $a"
  94.          fi
  95.     elif [ -f $D1/"$a" ]
  96.     then cmp -s $D1/"$a" $D2/"$a"
  97.          if [ $? = 0 ]
  98.          then if [ "$Sflag" != "yes" ]
  99.           then echo "same         $a"
  100.           fi
  101.          else echo "different    $a"
  102.           if [ "$Dflag" = "yes" ]
  103.           then
  104.             type=`file $D1/"$a"`
  105.             case "$type" in
  106.                 *text)    ;;
  107.                 *empty)    echo $D1/`basename "$a"` is an empty file |
  108.                      pr -h "diff of $a in $D1 and $D2" >> /usr/tmp/dc$$g
  109.                     continue
  110.                 ;;
  111.                 *)    echo $D1/`basename "$a"` is an object file |
  112.                      pr -h "diff of $a in $D1 and $D2" >> /usr/tmp/dc$$g
  113.                     continue
  114.                 ;;
  115.             esac
  116.             type=`file $D2/"$a"`
  117.             case "$type" in
  118.                 *text)    ;;
  119.                 *empty)    echo $D2/`basename "$a"` is an empty file |
  120.                      pr -h "diff of $a in $D1 and $D2" >> /usr/tmp/dc$$g
  121.                     continue
  122.                 ;;
  123.                 *)    echo $D2/`basename "$a"` is an object file |
  124.                      pr -h "diff of $a in $D1 and $D2" >> /usr/tmp/dc$$g
  125.                     continue
  126.                 ;;
  127.             esac
  128.             diff $D1/"$a" $D2/"$a" | pr -h "diff of $a in $D1 and $D2" >> /usr/tmp/dc$$g
  129.           fi
  130.          fi
  131.     elif [ "$Sflag" != "yes" ]
  132.     then echo "special      $a"
  133.     fi
  134. done < /usr/tmp/dc$$f | pr -r -h "Comparison of $D1 $D2"
  135. if [ "$Dflag" = "yes" ]
  136. then cat /usr/tmp/dc$$g
  137. fi
  138. rm -f /usr/tmp/dc$$*
  139.