1#!/bin/sh
2# SPDX-License-Identifier: LGPL-2.1-or-later
3
4set -eu
5
6TOP="$(git rev-parse --show-toplevel)"
7
8case "${1:-}" in
9    recdiff)
10        if [ "${2:-}" = "" ] ; then
11            DIR="$TOP"
12        else
13            DIR="$2"
14        fi
15
16        find "$DIR" -type f \( -name '*.[ch]' -o -name '*.xml' \) -exec "$0" diff \{\} \;
17        ;;
18
19    recpatch)
20        if [ "${2:-}" = "" ] ; then
21            DIR="$TOP"
22        else
23            DIR="$2"
24        fi
25
26        find "$DIR" -type f \( -name '*.[ch]' -o -name '*.xml' \) -exec "$0" patch \{\} \;
27        ;;
28
29    diff)
30        T="$(mktemp)"
31        sed 's/\t/        /g' <"${2:?}" >"$T"
32        diff -u "$2" "$T"
33        rm -f "$T"
34        ;;
35
36    patch)
37        sed -i 's/\t/        /g' "${2:?}"
38        ;;
39
40    *)
41        echo "Expected recdiff|recpatch|diff|patch as verb." >&2
42        ;;
43esac
44