#!/bin/sh
# gpatch - GNU patch wrapper for Solaris /usr/bin/patch
# - Converts -d<dir> to an explicit cd (Solaris patch ignores -d)
# - Strips -F (fuzz factor, not supported)
# - Passes -u explicitly so Solaris patch handles unified diffs
DIR=""
ARGS="-u"
skip_next=0
for arg in "$@"; do
    if [ "$skip_next" = 1 ]; then
        DIR="$arg"
        skip_next=0
        continue
    fi
    case "$arg" in
        -F*)  ;;
        -u)   ;;               # already added
        -d)   skip_next=1 ;;
        -d*)  DIR="${arg#-d}" ;;
        *)    ARGS="$ARGS $arg" ;;
    esac
done
if [ -n "$DIR" ]; then
    cd "$DIR" || exit 1
fi
exec /usr/bin/patch $ARGS
