codekingpro/portable-devtools
116k
1#!/bin/sh2# sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh3 4# Copyright (C) 1998, 2002, 2006-2007, 2009-2025 Free Software Foundation, Inc.5# Copyright (C) 1993 Jean-loup Gailly6 7# This program is free software; you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation; either version 3 of the License, or10# (at your option) any later version.11 12# This program is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15# GNU General Public License for more details.16 17# You should have received a copy of the GNU General Public License18# along with this program. If not, see <https://www.gnu.org/licenses/>.19 20case $1 in21 --__cmp) shift22 prog=cmp; cmp='${CMP-cmp}' ;;23 *) prog=diff; cmp='${DIFF-diff}';;24esac25 26version="z$prog (gzip) 1.1427Copyright (C) 2025 Free Software Foundation, Inc.28This is free software. You may redistribute copies of it under the terms of29the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.30There is NO WARRANTY, to the extent permitted by law.31 32Written by Jean-loup Gailly."33 34usage="Usage: $0 [OPTION]... FILE1 [FILE2]35Compare FILE1 to FILE2, using their uncompressed contents if they are36compressed. If FILE2 is omitted, compare FILE1 to the uncompressed37contents of FILE1.gz. Do comparisons like '$prog' does.38 39OPTIONs are the same as for '$prog'.40 41Report bugs to <bug-gzip@gnu.org>."42 43# sed script to escape all ' for the shell, and then (to handle trailing44# newlines correctly) turn trailing X on last line into '.45escape='46 s/'\''/'\''\\'\'''\''/g47 $s/X$/'\''/48'49 50filesonly=51file1=52file2=53needop=54 55for arg56do57 case $filesonly$needop$arg in58 --h*) printf '%s\n' "$usage" || exit 2; exit;;59 --v*) printf '%s\n' "$version" || exit 2; exit;;60 --) filesonly=t;;61 -*\'*) cmp="$cmp '"`printf '%sX\n' "$arg" | LC_ALL=C sed "$escape"`;;62 -[CDFISUWXx]) needop="'$arg'";;63 -?*) cmp="$cmp '$arg'";;64 *) case $needop in65 '') case $arg in66 '') printf >&2 '%s\n' "$0: empty file name"; exit 2;;67 esac68 case $file1 in69 '') file1=$arg;;70 *) case $file2 in71 '') file2=$arg;;72 *) printf >&2 '%s\n' "$0: extra operand '$arg'"; exit 2;;73 esac;;74 esac;;75 *) cmp="$cmp $needop '$arg'"76 needop=;;77 esac;;78 esac79done80case $needop in81'') ;;82*) printf >&2 '%s\n' "$0: $prevarg: option requires an argument -- $needop"83 exit 2;;84esac85 86cmp="$cmp --"87 88case $file1 in89'') printf >&2 '%s\n' "$0: missing operand"; exit 2;;90-) ;;91*) <"$file1" || exit 2;;92esac93case $file2 in94''|-) ;;95*) <"$file2" || exit 2;;96esac97 98gzip_status=099exec 3>&1100 101case $file2 in102'')103 case $file1 in104 *[-.]gz* | *[-.][zZ] | *.t[ga]z)105 FILE=`LC_ALL=C expr "X$file1" : 'X\(.*\)[-.][zZtga]*$'`106 gzip_status=$(107 exec 4>&1108 (gzip -cd -- "$file1" 4>&-; echo $? >&4) 3>&- |109 eval "$cmp" - '"$FILE"' >&3110 );;111 *)112 printf >&2 '%s\n' "$0: $file1: unknown compressed file extension"113 exit 2;;114 esac;;115*)116 case $file1,$file2 in117 -,-)118 gzip_status=$(119 exec 4>&1120 (gzip -cdfq - 4>&-; echo $? >&4) 3>&- |121 eval "$cmp" - - >&3122 );;123 *)124 case $file1 in125 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)126 case $file2 in127 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)128 if129 # Reject Solaris 8's buggy /bin/bash 2.03.130 echo X |131 (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) \132 5<&0133 then134 gzip_status=$(135 exec 4>&1136 (gzip -cdfq -- "$file1" 4>&-; echo $? >&4) 3>&- |137 ((gzip -cdfq -- "$file2" 4>&-138 echo $? >&4) 3>&- 5<&- </dev/null |139 eval "$cmp" /dev/fd/5 - >&3) 5<&0140 )141 cmp_status=$?142 case $gzip_status in143 *[1-9]*) gzip_status=1;;144 *) gzip_status=0;;145 esac146 (exit $cmp_status)147 else148 tmp=149 trap '150 test -n "$tmp" && rm -f "$tmp"151 (exit 2); exit 2152 ' HUP INT PIPE TERM 0153 case $TMPDIR in154 / | /*/) ;;155 /*) TMPDIR=$TMPDIR/;;156 *) TMPDIR=/tmp/;;157 esac158 if command -v mktemp >/dev/null 2>&1; then159 tmp=`mktemp "${TMPDIR}zdiffXXXXXXXXX"` ||160 exit 2161 else162 set -C163 tmp=${TMPDIR}zdiff$$164 fi165 gzip -cdfq -- "$file2" > "$tmp" || exit 2166 gzip_status=$(167 exec 4>&1168 (gzip -cdfq -- "$file1" 4>&-; echo $? >&4) 3>&- |169 eval "$cmp" - '"$tmp"' >&3170 )171 cmp_status=$?172 rm -f "$tmp" || gzip_status=$?173 trap - HUP INT PIPE TERM 0174 (exit $cmp_status)175 fi;;176 *)177 gzip_status=$(178 exec 4>&1179 (gzip -cdfq -- "$file1" 4>&-; echo $? >&4) 3>&- |180 eval "$cmp" - '"$file2"' >&3181 );;182 esac;;183 *) case $file2 in184 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)185 gzip_status=$(186 exec 4>&1187 (gzip -cdfq -- "$file2" 4>&-; echo $? >&4) 3>&- |188 eval "$cmp" '"$file1"' - >&3189 );;190 *) eval "$cmp" '"$file1"' '"$file2"';;191 esac;;192 esac;;193 esac;;194esac195 196cmp_status=$?197test "$gzip_status" -eq 0 || exit 2198exit $cmp_status199 