#!/bin/sh

usage()
{
    echo "This script unifies the sdf files to be commited into l10n git repo"
    echo
    echo "Usage: ${0##*/} in [out]"
    echo
    echo "Options:"
    echo
    echo "	in      input file"
    echo "	out     output file"
}

in="$1"
out="$2"
tempdir=

if test -z "$in" ; then
    echo "Error: Please, define input file"
    exit 1;
fi

if test ! -f "$in" ; then
    echo "Error: input file does not exist: $in"
    exit 1;
fi

if test -z "$out" ; then
    tempdir=`mktemp -D -t lo-unify-sdf-XXXXXX`
    out="$tempdir/out.sdf"
fi

echo "Cleaning $in..."
grep -v "^[^	]*	[^	]*	[^	]*	[^	]*	[^	]*	[^	]*	[^	]*	[^	]*	[^	]*	en-US" "$in" | \
LANG=C sort >$out

dos2unix $out

# no input file define, so overwrite the original file
if test -n "$temp_out" ; then
    chmod --reference="$in" "$out"
    mv "$out" "$in"
    rm -rf "$tempdir"
fi
