#!/bin/env bash
# Usage :
# 1) render
# 2) render indent FILE
# 3) render ascii FILE

function cmd_indent()
{
    ACTIONS='(f90-mode) (indent-region (point-min) (point-max) nil) (delete-trailing-whitespace)'
    emacs -batch $1 --eval "(progn $ACTIONS)" -f save-buffer 2>/dev/null
}

function cmd_ascii()
{
    TMP=$(mktemp)
    iconv -f utf-8 -t ascii//translit $1 > $TMP || exit
    cp $TMP $1
}

function cmd_()
{
    TMP=$(mktemp)
    for x in $(cd jsrc ; find . -name "*.?90") ; do
	wc jsrc/$x
	jsrc/jinja2 jsrc/$x > $TMP
	cmd_indent $TMP
	cmp -s $TMP src/$x || cp $TMP src/$x
	wc src/$x
    done
    rm -f $TMP
}

CMD=$1 ; shift
cmd_$CMD $*

