#!/bin/bash

# Reindents the C++ source code files given in argument

[[ -n $1 ]] || { echo "Give filename(s) in argument" 2>&1; exit 1; }

pushd "$(dirname "$0")" > /dev/null
SCRIPTS_DIR=$(pwd)
popd > /dev/null

for f in "$@"; do
    echo "*** Indenting $f…"

    uncrustify -l CPP --replace -c "${SCRIPTS_DIR}"/uncrustify.cfg "$f"

    pushd "$(dirname "$f")" > /dev/null
    emacs -batch "$(basename "$f")" -l "${SCRIPTS_DIR}"/indent-c++.el
    popd > /dev/null

    echo
done
