#! /usr/bin/env bash
#
# Default canonifier used with the trace-based tests in testing/external/*.

if [ $# != 1 ]; then
    echo "usage: $(basename $0) <filename>"
    exit 1
fi

filename=$(basename $1)

addl="cat"

if [ "$filename" == "capture_loss.log" ]; then
    addl="$(dirname $0)/diff-remove-fractions"
fi

if [ "$filename" == "ssh.log" ]; then
    addl="$(dirname $0)/diff-remove-fields remote_location"
fi

if [ "$filename" == "analyzer_debug.log" ]; then
    addl="$(dirname $0)/diff-remove-abspath"
fi

if [ "$filename" == "analyzer.log" ]; then
    addl="$(dirname $0)/diff-remove-abspath"
fi

$(dirname $0)/diff-remove-timestamps |
    $(dirname $0)/diff-remove-uids |
    $(dirname $0)/diff-remove-file-ids |
    $(dirname $0)/diff-remove-x509-names |
    $(dirname $0)/diff-sort-set-elements |
    $(dirname $0)/diff-remove-spicy-abspath |
    $(dirname $0)/diff-sort |
    eval $addl
