about summary refs log tree commit diff stats
path: root/subtext.sh
diff options
context:
space:
mode:
Diffstat (limited to 'subtext.sh')
-rwxr-xr-xsubtext.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/subtext.sh b/subtext.sh new file mode 100755 index 0000000..d845955 --- /dev/null +++ b/subtext.sh
@@ -0,0 +1,57 @@
1#!/bin/sh
2
3stawk() {
4 awk -f subtext.awk "$@" # SUBTEXT AWK SCRIPT HERE
5}
6
7usage() {
8 cat>&2 <<EOF
9SUBTEXT v.meowmers (C) Case Duckworth
10Usage: subtext [OPTIONS] FILE...
11 subtext < FILE
12Options:
13 -h Show this help and exit.
14 -n Don't run the resulting script; just print it.
15 -m FILE Use macrofile FILE.
16 -I DIRECTORY Add DIRECTORY to the search path.
17EOF
18 exit $1
19}
20
21configure() {
22 ## Initialize state variables
23 : "${ST_MACROFILE:=}"
24 : "${ST_SOPATH:=.:$HOME/.subtext}"
25 : "${ST_PIPE_SH:=true}"
26 ## Process options
27 while getopts :hm:I:n OPT
28 do
29 case "$OPT" in
30 (h) usage ;;
31 (m) ST_MACROFILE="$OPTARG" ;;
32 (I) ST_SOPATH="$ST_SOPATH:$OPTARG" ;;
33 (n) ST_PIPE_SH=false ;;
34 (:) printf >&2 'Unknown option -%s\n' "$OPTARG";
35 usage 1 ;;
36 (*) usage 1 ;;
37 esac
38 done
39}
40
41main() {
42 configure "$@"
43 shift $((OPTIND-1))
44 stawk -vsopath="$ST_SOPATH" "$@" |
45 if "$ST_PIPE_SH"
46 then sh
47 else cat
48 fi
49}
50
51die() {
52 ec="$1"; shift
53 printf >&2 '!! %s\n' "$*"
54 exit "$ec"
55}
56
57main "$@"