3 HERE=$(cd $(dirname $0); pwd)
11 longopts='dir:,input:,output:,help'
13 Usage 1: $THIS [ options ] [ key=value ... ] < file.tt > file
14 Usage 2: $THIS [ options ] [ key=value ... ] file.tt ...
17 -d, --dir=DIR Directory of the output file
18 -i, --input=FILE Input file (usage 1 only)
19 -o, --output=FILE Output file (usage 1 only)
20 -h, --help Output this usage and do nothing else
22 In usage 1, the template is read from standard input or the file given
23 with --input and the processing result is output to standard output or
24 the file given with --output. When the output goes to stdout, the --dir
27 In usage 2, the templates are read from the files given as argument, and
28 the processing result for each of them is written to a corresponding file
29 without the '.tt' suffix. All given file names must have the '.tt' suffix.
30 In this usage, --input, --output, standard input and standard output are
33 In both usages, one can also set template variables with with the form
34 key=value. They must come before any file name."
36 # Standard getopt calling sequence
37 if ! TEMP=$(getopt -o "$shortopts" --long "$longopts" -n $THIS -- "$@"); then
44 # Check the parsed options
71 echo >&2 'Internal error!'
82 tpagecmd="$tpagecmd --define '$1'"
91 # If there are no other arguments, read from stdin, write to stdout.
92 # Otherwise, read from the input files and write to corresponding output files.
94 if [ -z "$dir" ]; then
95 echo >&2 'Directory must be set with -d / --dir in this mode'
100 ( cat $HERE/../inc/common.tt;
101 if [ -n "$input" ]; then cat "$HERE/../$input"; else cat; fi ) \
102 | eval "$tpagecmd --define 'dir=$HERE/../${dir:-filedir}'" \
103 | ( if [ -n "$output" ]; then cat > "$HERE/../$output"; else cat; fi )
109 base=$(basename "$f" .tt)
111 if [ "$base" = "$f" ]; then
112 errfiles="$errfiles '$f'"
113 elif [ ! -f "$f" ]; then
114 nofiles="$nofiles '$f'"
117 if [ -n "$errfiles" ]; then
118 echo >&2 "Files not ending with .tt:$errfiles"
120 if [ -n "$nofiles" ]; then
121 echo >&2 "Files no present:$nofiles"
123 if [ -n "$errfiles" -o -n "$nofiles" ]; then
128 base=$(basename "$f" .tt)
129 filedir=$(dirname "$f")
131 if [ "$f" != "$base" ]; then
134 ( cat $HERE/../inc/common.tt; cat $base.tt ) | \
135 eval "$tpagecmd --define 'dir=${dir:-filedir}'" \