#!/bin/bash setvar BALLS_LIB = $(readlink -f $(dirname $0)/../lib) shopt -s extglob source $BALLS_LIB/balls.sh proc dash_trim_r { local str="${!1}" setvar str = "${str%%*( )}" export "$1"="$str" } proc compile { local code local chunk local trim_next=0 while read_until '<%' chunk { if test $FOUND = 1 { read_until '%>' code trim code match ${code:0:1} { with = setvar code = "${code:1}" trim code setvar code = ""echo -n $code"" with - setvar code = "${code:1}" dash_trim_r chunk trim code } match ${code:${#code}-1} { with - # read off the next line read setvar code = "${code:0:${#code}-1}" trim code } } # if [ "$FOUND" = 1 ] # echo "echo -n $(bash_safe <<< "$chunk")" bash_safe chunk echo "echo -n $chunk" test $FOUND = 1 && echo $code } # while read_until '<%' chunk true } setvar fname = "$1"; shift export eof="$(echo -e '\004')" if test -n $fname { cat $fname || exit 1 } else { cat - } | compile