File: make_string.sh

package info (click to toggle)
usb-modeswitch 2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 380 kB
  • sloc: ansic: 1,839; tcl: 792; sh: 224; makefile: 136
file content (23 lines) | stat: -rwxr-xr-x 473 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

# (c) Josua Dietze 2019-2020
#
# Usage: make_string.sh source.tcl > [condensed tcl]

# Converts a Tcl source file into C code suitable
# for using as an embedded script.

input="$1"
rawout="#define RAWSCRIPT \""

while IFS= read -r line
do
	if [ -z "$line" ]; then
		continue
	fi
	clean2="${line//\\/\\\\}"
	clean3="${clean2//\"/\\\"}"
	rawout="$rawout$clean3\\n"
done < <(sed -E 's/^[[:space:]]+|[[:space:]]+$|^[[:space:]]*#.*$//' "$input")

echo "$rawout\""