aboutsummaryrefslogtreecommitdiff
path: root/format.sh
diff options
context:
space:
mode:
Diffstat (limited to 'format.sh')
-rwxr-xr-xformat.sh52
1 files changed, 51 insertions, 1 deletions
diff --git a/format.sh b/format.sh
index 9af69f1..a8f2265 100755
--- a/format.sh
+++ b/format.sh
@@ -1,2 +1,52 @@
1#!/bin/sh 1#!/bin/sh
2exec recfmt "`cat $1`" 2##
3# Usage: format.sh TEMPLATE [SELEXP]
4#
5# This runs recfmt w/ template file TEMPLATE, taking input from stdin,
6# and writing output to stdout.
7#
8# Optional arg SELEXP is an expression passed to ‘recsel -e’. If specified,
9# stdin is first processed by recsel and its output is then piped to recfmt
10# for formatting. If recsel exits failurefully (e.g., given invalid SELEXP),
11# no output is written and format.sh exits failurefully as well.
12##
13me=$(basename $0)
14
15version='1.4'
16# 1.4 -- create $TMPDIR if it does not exist
17# 1.3 -- add support for optional arg SELEXP
18# 1.2 -- add check for required arg TEMPLATE
19# 1.1 -- add --help/--version support
20# 1.0 -- initial release
21
22if [ x"$1" = x--help ] ; then
23 sed '/^##/,/^##/!d;/^##/d;s/^# //g;s/^#$//g' $0
24 exit 0
25fi
26
27if [ x"$1" = x--version ] ; then
28 echo $me '(gana)' $version
29 exit 0
30fi
31
32if [ x"$1" = x ] ; then
33 echo >&2 "$me: ERROR: missing arg TEMPLATE (try --help)"
34 exit 1
35fi
36
37template="$1"
38
39if [ x"$2" = x ] ; then : ; else
40 selexp="$2"
41fi
42
43if [ "$selexp" ] ; then
44 t=$(mktemp)
45 trap "rm -f $t" EXIT
46 recsel -e "$selexp" > $t &&
47 recfmt -f "$template" < $t
48else
49 exec recfmt -f "$template"
50fi
51
52# format.sh ends here