#!/bin/csh -f # diffreview # ----------------------------------------------------------------------------- # Shell script to compare the specified 1st and 2nd file, invoking windiff # if there are diffs to allow the user to reconcile the diffs. # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with -h or --help to see usage. # Assumptions: # Effects: # - Compares file # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ----------------------------------------------------------------------------- # Prevent wildcard and command line pattern expansion because there may # be a regular expression in the --ignore-matching-lines value. We want to # avoid "No match." errors when the shell tries to expand it into filenames. # Also, we really do want the regular expression to get passed to diff. set noglob set option_quiet = "false" set option_interactive = "false" set option_noninteractive = "false" set diff_cmd = "diff" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options] newfile oldfile" echo "Options:" echo " -h = Show this help text" echo " --help = Show this help text" echo " -q = Quiet. Be less verbose about messages" echo " -I pattern = Ignore diff of lines containing pattern" echo " --ignore-matching-lines pattern" echo " = Ignore diff of lines containing pattern" echo " -i = Interactive. Use an interactive diff that" echo " allows the user to view and resolve diffs." echo " Otherwise, ask the user whether to use an" echo " interactive diff or regular diff." echo " Overridden by subsequent -d." echo " -d = Diff. Use regular non-interactive diff that" echo " shows thew diffs w/o requiring any further" echo " user input." echo " Overridden by subsequent -i." exit 1 else if ("$1" == "-q") then shift set option_quiet = "true" else if ("$1" == "-I" || "$1" == "--ignore-matching-lines") then shift if ("$1" == "") then echo "Error: Missing argument to -I or --ignore-matching-lines option" $0 --help exit 1 else set diff_cmd = "diff --ignore-matching-lines $1" shift endif else if ("$1" == "-i") then shift set option_interactive = "true" if ("$option_noninteractive" == "true") then echo "${0:t}: Option -d overridden by subsequent option -i" endif set option_noninteractive = "false" else if ("$1" == "-d") then shift set option_noninteractive = "true" if ("$option_interactive" == "true") then echo "${0:t}: Option -i overridden by subsequent option -d" endif set option_interactive = "false" else if ("-" == "`echo $1:q | cut -c 1`") then echo "Error: Invalid option: $1:q" $0 --help exit 1 else # Not a recognized option. Assume it's the first argument break endif end # Collect command line arguments if ($#argv < 2) then $0:t --help exit 1 else if (! -e $1:q) then echo "Error: File $1:q does not exist." exit 1 else if (! -r $1:q) then echo "Error: File $1:q is not readable." exit 1 else if (! -e $2:q) then echo "Error: File $2:q does not exist." exit 1 else if (! -r $2:q) then echo "Error: File $2:q is not readable." exit 1 endif # Return exit status 3 if there are still diffs when exiting, but the user # has already seen them, and had no chance to fix them. Use 3 since normal # diff returns only 0, 1, 2. set status_remaining_diffs_already_shown = 3 if ("${option_quiet}" == "false") then echo "$diff_cmd -s $1:q $2:q" endif $diff_cmd -s $1:q $2:q >& /dev/null if ($status) then if ("${option_interactive}" == "true") then set action = "w" else if ("${option_noninteractive}" == "true") then set action = "d" else set action = `promptloop "Some differences found. Review via windiff(w), diff(d), neither(n)? " w d n` endif if ("${action}" == "n") then exit 0 else if ("${action}" == "d") then $diff_cmd $1:q $2:q | less $diff_cmd $1:q $2:q >& /dev/null if ($status) then exit $status_remaining_diffs_already_shown endif else if ("${action}" == "w") then windiff $1:q $2:q exit 0 endif else if (${option_quiet} == "false") then echo "Files $1:q and $2:q are identical." endif endif