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
|
#!/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/\\t/'g \
-e 's/\r/\\r/g' \
-e 's/^/ "/g' \
-e 's/$/\\n"/g'
echo ";"
}
./txt2c test </dev/null >/dev/null 2>&1 &&
./txt2c "$1" ||
txt2c_fallback "$1"
|