#!/bin/bash # # Compares two files using CodeWarrior # # Other diff utilities: opendiff (runs OS X FileMerge), # cmp (byte-by-byte versus diff's line-by-line) # p4merge # # # Version 1.4 April 10, 2007 # Randall Gellens #----------------------------------------------- # Show script usage #----------------------------------------------- function usage () { X=`basename $0` echo "Usage: [options] $X new-file [old-file]" echo "Options:" echo " -i: ignore case" echo " -b: without extra space" echo " -d: files are Internet Drafts" echo " -x: use OS X FileMerge" echo " -p: use Perforce p4merge" echo " -c: use CodeWarrior for diff (default)" echo " -v: verbose mode" exit 1 } #----------------------------------------------- # Verbose messages #----------------------------------------------- function say () { if [ "${opt_verb}" = "y" ]; then echo "$*" fi } opt_ext_sp="with" opt_case="without" opt_draft="n" opt_verb="n" opt_diff="c" draft_dir="$HOME/IETF/Internet_Drafts" while getopts ":ibvdxpc" opt do case $opt in i) say "ignoring case" opt_case="with" ;; b) say "without extra space" opt_ext_sp="without" ;; x) say "Using OS X FileMerge" opt_diff="x" ;; p) say "Using Perforce p4merge" opt_diff="p" ;; c) say "Using CodeWarrior" opt_diff="c" ;; v) opt_verb="y" say "Verbose mode" ;; d) say "Internet Drafts" opt_draft="y" targ_dir=$draft_dir ;; *) echo "Unrecognized option: ${opt}" echo "" usage ;; esac done shift $(($OPTIND - 1)) new_file=${1} old_file=${2} # if -d was used to set targ_dir, do nothing, otherwise set # targ_dir to the path of the first parameter, if it has one, # otherwise set targ_dir to our directory: if [ -z "$targ_dir" ]; then targ_dir="`expr "$1" : '\(.*\)/'`" targ_dir=${targ_dir:=`pwd`} fi say "directory: $targ_dir" say "new_file: $new_file" say "old_file: $old_file" # # If only one file specified, and file name contains "-[0-9][0-9]", # second file is first file with a lower number # if [ $# -eq 1 ]; then vers="`expr "$1" : '.*-\([0-9][0-9]\)'`" if [ -n "$vers" ]; then base="`expr "$1" : '\(.*-\)[0-9][0-9]'`" extn="`expr "$1" : '.*-[0-9][0-9]\(.*\)'`" targ="`expr "$vers" - 1`" if [ $vers -eq 0 ]; then echo "New file is version -00" exit 1 fi if [ $targ -lt 10 ]; then fill=0 fi say "Old file assumed to be ${base}${fill}${targ}${extn}" old_file=${base}${fill}${targ}${extn} else echo "old_file not specified; new_file does not contain \"-xx\"" exit 1 fi fi if [ $# -eq 0 -o $# -gt 2 ]; then usage fi # Guess if filename appears to contain a path or not, and # if not, prepend our path to it DIRN="`expr "$new_file" : '\(.*\)/'`" say "new file's directory: $DIRN" if [ -z "$DIRN" ]; then say "new file is bare filename" new_file="${targ_dir}/${new_file}" say "new file now $new_file" fi DIRO="`expr "$old_file" : '\(.*\)/'`" say "old file's directory: $DIRO" if [ -z "$DIRO" ]; then say "old file is bare filename" old_file="${targ_dir}/${old_file}" say "old file now $old_file" fi if [ ! -f "$new_file" ]; then echo "New file $new_file does not exist" MATCHES=`ls "$new_file"` echo "$MATCHES" exit 1 fi if [ ! -f "$old_file" ]; then echo "Old file $old_file does not exist" MATCHES=`ls "$old_file"` echo "$MATCHES" exit 1 fi say "new file: $new_file" say "old file: $old_file" case $opt_diff in c) /usr/bin/osascript << EOI tell application "CodeWarrior IDE" Compare Files "$new_file" to "$old_file" $opt_case case sensitive $opt_ext_sp ignore extra space with compare text file contents activate end tell EOI ;; x) # FileMerge shows the second file in the lower pane, so we swap # the usual order we pass the files say /usr/bin/opendiff "$old_file" "$new_file" /usr/bin/opendiff "$old_file" "$new_file" ;; p) /Volumes/TiLand/Applications/p4merge.app/Contents/Resources/p4merge "$new_file" "$old_file" ;; *) echo "Internal error: opt_diff = $opt_diff" exit 1 ;; esac