#! /bin/bash
for i in "$@"; do
   echo "====== applying ${i##*/} ========="
   #patch --dry-run -Np1 < "$i" 2>&1 | awk '/^patching/ { st=0; file=$3; };  /^Hunk.*fuzz 2|saving rejects/ { if (st == 0) print "\n" file " :"; st = 1; print "   " $0; }' >&2
   #patch --dry-run -Np1 < "$i" 2>&1 | awk '/^patching/ { st=0; file=$3; };  /^Hunk.*fuzz 2/ { print "  " file " : " $2 " at " $5 FS $7 FS $8 FS $9 FS $10 FS $11; }; /saving rejects/ { print "  " file " : " $1 FS $2 FS $3 FS $4 FS $5 FS $6; }'
   patch --dry-run -Np1 < "$i" 2>&1 | awk '/^patching/ { st=0; file=$3; };  /^Hunk.*fuzz 2/ { print "  " $2 " at " $5 FS $7 FS $8 FS $9 FS $10 FS $11 " -- " file; }; /saving rejects/ { print "  " $6 FS $1 FS $2 FS $3 FS $4 FS $5 " -- " file; }; /^can.t find/ { print "  " $0; }'
   patch -Nsp1 < "$i" >/dev/null
done

