#! /bin/bash

# filter out chunks that are for Firefox or for xulrunner
function mfilter()
{
allowbrowser="$1"
allowother="$2"
allow=1
while IFS= read -r line; do
    if echo "$line" | grep -q '^--- mozilla/'; then
        if echo "$line" | grep -q '^--- mozilla/browser/'; then
            allow="$allowbrowser"
        else
            allow="$allowother"
        fi
    fi
    if test -n "$allow"; then
        echo "$line"
    fi
done
}

function fixdebug()
{
sed 's,^+#define DEBUG_KDE,+//#define DEBUG_KDE,'
}

if ! test -e ../mozilla.patch; then
    echo No mozilla patch.
    exit 1
fi
cat ../mozilla.patch | fixdebug | mfilter "" "1" > mozilla-xulrunner191.patch
cat ../mozilla.patch | fixdebug | mfilter "1" "" > MozillaFirefox.patch
