xref: /netbsd-src/external/bsd/openldap/dist/doc/devel/variadic_debug/script.sh (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1#!/bin/bash
2
3set -e
4
5PATCH_DIR=doc/devel/variadic_debug
6
7SPATCH=${SPATCH:-spatch}
8SPATCH_OPTS=( --macro-file-builtins "$PATCH_DIR/macros.h" )
9#SPATCH_OPTS+=( --timeout 300 )
10
11SED_TRANSFORMATIONS=()
12
13# split out multipart strings back to original form (one per line)
14SED_TRANSFORMATIONS+=( -e 's/^\(+\s*\)\(.*"\) \(".*\)"$/\1\2\n+\1\3/' )
15
16# re-add whitespace around parentheses
17SED_TRANSFORMATIONS+=( -e 's/^\(+.*Debug[0-3]\?(\)\s*/\1 /' )
18SED_TRANSFORMATIONS+=( -e 's/^\(+.*[^ ]\));$/\1 );/' )
19
20# strip trailing whitespace copied from source on affected lines
21SED_TRANSFORMATIONS+=( -e 's/^\(+.*\)\s\+$/\1/' )
22
23# fix whitespace errors in source we touch
24SED_TRANSFORMATIONS+=( -e 's/^\(+.*\)    \t/\1\t\t/' )
25SED_TRANSFORMATIONS+=( -e 's/^\(+\t*\) \{1,3\}\t/\1\t/' )
26
27normalise() {
28    patch="$1"
29    shift
30
31    # iterate until we've reached fixpoint
32    while ! cmp "$patch" "${patch}.new" 2>/dev/null; do
33        if [ -e "${patch}.new" ]; then
34            mv -- "${patch}.new" "$patch"
35        fi
36        sed "${SED_TRANSFORMATIONS[@]}" -- "$patch" >"${patch}.new"
37    done
38    rediff "$patch" >"${patch}.new"
39    mv -- "${patch}.new" "$patch"
40}
41
42git add "$PATCH_DIR"
43git commit -m "ITS#8731 Add the documentation and scripts"
44
45git am "$PATCH_DIR/00-fixes.patch"
46git am "$PATCH_DIR/01-logging.patch"
47git am "$PATCH_DIR/02-manual.patch"
48
49$SPATCH "${SPATCH_OPTS[@]}" -sp_file "$PATCH_DIR/03-libldap_Debug.cocci" \
50    -dir libraries/libldap \
51    >"$PATCH_DIR/03-libldap_Debug.patch"
52normalise "$PATCH_DIR/03-libldap_Debug.patch"
53git apply --index --directory libraries/libldap "$PATCH_DIR/03-libldap_Debug.patch"
54git commit -m "ITS#8731 Apply $PATCH_DIR/03-libldap_Debug.cocci"
55
56$SPATCH "${SPATCH_OPTS[@]}" -sp_file "$PATCH_DIR/04-variadic.cocci" \
57    -dir . \
58    >"$PATCH_DIR/04-variadic.patch"
59normalise "$PATCH_DIR/04-variadic.patch"
60git apply --index "$PATCH_DIR/04-variadic.patch"
61git commit -m "ITS#8731 Apply $PATCH_DIR/04-variadic.cocci"
62
63git am "$PATCH_DIR/05-back-sql.patch"
64git am "$PATCH_DIR/06-nssov.patch"
65
66$SPATCH "${SPATCH_OPTS[@]}" -sp_file "$PATCH_DIR/07-shortcut.cocci" \
67    -dir . \
68    >"$PATCH_DIR/07-shortcut.patch"
69normalise "$PATCH_DIR/07-shortcut.patch"
70git apply --index "$PATCH_DIR/07-shortcut.patch"
71git commit -m "ITS#8731 Apply $PATCH_DIR/07-shortcut.cocci"
72
73git am "$PATCH_DIR/08-snprintf-manual.patch"
74