#! /bin/tcsh -ef

if (("x$1" == "x") || ("x$2" == "x")) then
    echo "Usage: do-astyle-onefile <style> <file>"
    echo "where <style> is ansi or kr (and others available)"
    echo "and <file> is a c, cpp or cxx file"
    echo "http://astyle.sourceforge.net/"
    echo ""
    echo "ansi style:"
    echo "-----------"
    echo "int Foo(bool isBar)"
    echo "{"
    echo "  if (isBar)"
    echo "  {"
    echo "    bar();"
    echo "    return 1;"
    echo "  }"
    echo "  else"
    echo "    return 0;"
    echo "}"
    echo ""
    echo "kr style:"
    echo "---------"
    echo "int Foo(bool isBar)"
    echo "{"
    echo "  if (isBar) {"
    echo "    bar();"
    echo "    return 1;"
    echo "  } else"
    echo "    return 0;"
    echo "}"
    echo ""
    exit 1
endif

set echo=1

# add one space after commas
#sed 's/\(\,\)\([a-zA-Z\"]\)/\, \2/g' $2 > $2.orig
#mv $2.orig $2

# delete trailing whitespace (spaces/tabs) from end of each line
sed 's/[ 	]*$//' $2 > $2.orig
mv $2.orig $2

# run re-styler
set OPTS="--style=$1 --indent=spaces=2 --convert-tabs --add-brackets"
astyle $OPTS $2
sleep 1
~nicks/bin/astyle $OPTS $2

# delete trailing whitespace (spaces/tabs) from end of each line
sed 's/[ 	]*$//' $2 > $2.orig
mv $2.orig $2
