summaryrefslogtreecommitdiff
path: root/m4n.sh
blob: 989adcec50a69962389876866bb852c92e8153f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
die() {
	printf '%s: ' $(basename $0)
	printf "$@" >&2
	exit 1
}

main() {
	om4=text_m4

	while getopts O: opt; do
		case $opt in

		O)
			if ! command -v "${OPTARG}_m4" >/dev/null 2>/dev/null; then
				die 'invalid output type %s\n' "$OPTARG"
			fi

			om4=${OPTARG}_m4
			;;

		?)	exit 1;;
		esac
	done

	shift $((OPTIND - 1))

	if [ $# -eq 0 ]; then
		$om4 - | m4
	else
		while [ $# -gt 0 ]; do
			$om4 $1 | m4
			shift
		done
	fi
}

main "$@"