[BACK]Return to zdiff CVS log [TXT][DIR] Up to [local] / src / usr.bin / compress

Annotation of src/usr.bin/compress/zdiff, Revision 1.1

1.1     ! millert     1: #!/bin/sh -
        !             2: #
        !             3: # Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
        !             4: #
        !             5: # Permission to use, copy, modify, and distribute this software for any
        !             6: # purpose with or without fee is hereby granted, provided that the above
        !             7: # copyright notice and this permission notice appear in all copies.
        !             8: #
        !             9: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            10: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            11: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            12: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            13: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            14: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            15: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            16: #
        !            17: # Sponsored in part by the Defense Advanced Research Projects
        !            18: # Agency (DARPA) and Air Force Research Laboratory, Air Force
        !            19: # Materiel Command, USAF, under agreement number F39502-99-1-0512.
        !            20: #
        !            21:
        !            22: # Set $prog based on $0
        !            23: case $0 in
        !            24:        *cmp)   prog=cmp
        !            25:                ;;
        !            26:        *)      prog=diff
        !            27:                ;;
        !            28: esac
        !            29: USAGE="usage: z$prog [options] file1 [file2]"
        !            30:
        !            31: # Pull out any command line flags so we can pass them to diff/cmp
        !            32: # XXX - assumes there is no optarg
        !            33: flags=
        !            34: while test $# -ne 0; do
        !            35:        case "$1" in
        !            36:                --)
        !            37:                        shift
        !            38:                        break
        !            39:                        ;;
        !            40:                -*)
        !            41:                        flags="$flags $1"
        !            42:                        shift
        !            43:                        ;;
        !            44:                *)
        !            45:                        break
        !            46:                        ;;
        !            47:        esac
        !            48: done
        !            49:
        !            50: if [ $# -eq 1 ]; then
        !            51:        # One file given, compare compressed to uncompressed
        !            52:        files="$1"
        !            53:        case "$1" in
        !            54:                *[._-][Zz])
        !            55:                        files="${1%??}"
        !            56:                        ;;
        !            57:                *[._-]gz)
        !            58:                        files="${1%???}"
        !            59:                        ;;
        !            60:                *.t[ag]z)
        !            61:                        files="${1%??}"ar
        !            62:                        ;;
        !            63:                *)      echo "z$prog: unknown suffix" 1>&2
        !            64:                        exit 1
        !            65:        esac
        !            66:        compress -cdfq "$1" | $prog $flags - "$files"
        !            67:        status=$?
        !            68: elif [ $# -eq 2 ]; then
        !            69:        # Two files given, compare the two uncompressing as needed
        !            70:        case "$1" in
        !            71:                *[._-][Zz]|*[._-]gz|*.t[ag]z)
        !            72:                        files=-
        !            73:                        filt="compress -cdfq $1"
        !            74:                        ;;
        !            75:                *)
        !            76:                        files="$1"
        !            77:                        ;;
        !            78:        esac
        !            79:        case "$2" in
        !            80:                *[._-][Zz]|*[._-]gz|*.t[ag]z)
        !            81:                        if [ "$files" = "-" ]; then
        !            82:                                tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
        !            83:                                trap "rm -f $tmp" 0 1 2 3 13 15
        !            84:                                compress -cdfq "$2" > $tmp
        !            85:                                files="$files $tmp"
        !            86:                        else
        !            87:                                files="$files -"
        !            88:                                filt="compress -cdfq $2"
        !            89:                        fi
        !            90:                        ;;
        !            91:                *)
        !            92:                        files="$files $2"
        !            93:                        ;;
        !            94:        esac
        !            95:        if [ -n "$filt" ]; then
        !            96:                $filt | $prog $flags $files
        !            97:        else
        !            98:                $prog $flags $files
        !            99:        fi
        !           100:        status=$?
        !           101: else
        !           102:        echo "$USAGE" 1>&2
        !           103:        exit 1
        !           104: fi
        !           105:
        !           106: exit $status