File: txt2c.sh

package info (click to toggle)
mutt 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,432 kB
  • sloc: ansic: 95,029; sh: 4,720; perl: 1,152; makefile: 708; yacc: 318; python: 211
file content (26 lines) | stat: -rwxr-xr-x 606 bytes parent folder | download | duplicates (3)
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/'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"