summaryrefslogtreecommitdiff
path: root/man/example-filter.sh
blob: 2a71d40d7c595fe9f21bdf1d78c93d979ed07b75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

# This is a super bootleg script for converting plaintext examples into groff.

while read line; do
	echo "$line" | while read -n 1 char; do
		if [[ $char == "%" ]]; then
			echo -n '%'
			continue
		fi
		ord=$(printf '%d' "'$char")
		if [[ $ord -eq 0 ]]; then
			printf ' '
		elif [[ $ord -gt 127 ]]; then
			printf '\[u%X]' "'$char"
		else
			printf "$char"
		fi
	done
	echo
	echo ".br"
done