~kevin8t8/mutt

mutt/txt2c.sh -rwxr-xr-x 606 bytes View raw
14709d7dKevin McCarthy Change postpone mode to write Date header too. 2 days ago
                                                                                
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
#!/bin/sh

txt2c_fallback () {
	# consumes stdin

	# declaration
	echo "unsigned char $1[] = "

	# initializer - filter out unwanted characters, then convert problematic
	# or odd-looking sequences.  The result is a sequence of quote-bounded
	# C strings, which the compiler concatenates into a single C string.
	tr -c '\011\012\015\040[!-~]' '?' |
	sed \
	    -e 's/\\/\\\\/g' \
	    -e 's/"/\\"/g' \
	    -e 's/??/\\?\\?/g' \
	    -e 's/	/\\t/'g \
	    -e 's/
/\\r/g' \
	    -e 's/^/	"/g' \
	    -e 's/$/\\n"/g'
	echo ";"
}

./txt2c test </dev/null >/dev/null 2>&1 &&
./txt2c "$1" ||
txt2c_fallback "$1"