mutt stable branch with some hacks
1#!/bin/sh
2
3txt2c_fallback () {
4 # consumes stdin
5
6 # declaration
7 echo "unsigned char $1[] = "
8
9 # initializer - filter out unwanted characters, then convert problematic
10 # or odd-looking sequences. The result is a sequence of quote-bounded
11 # C strings, which the compiler concatenates into a single C string.
12 tr -c '\011\012\015\040[!-~]' '?' |
13 sed \
14 -e 's/\\/\\\\/g' \
15 -e 's/"/\\"/g' \
16 -e 's/??/\\?\\?/g' \
17 -e 's/ /\\t/'g \
18 -e 's/
19/\\r/g' \
20 -e 's/^/ "/g' \
21 -e 's/$/\\n"/g'
22 echo ";"
23}
24
25./txt2c test </dev/null >/dev/null 2>&1 &&
26./txt2c "$1" ||
27txt2c_fallback "$1"