-
Notifications
You must be signed in to change notification settings - Fork 3
/
gen-text-file.sh
executable file
·66 lines (55 loc) · 1.25 KB
/
gen-text-file.sh
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
dir="$1"
shift
if [[ ! -d $dir ]]
then
echo "Directory not found: $dir" >&2
exit 1
fi
function gen_text()
{
local varname="$1"
local src="$2"
printf "\nconst char %s[] =\n{\n" "$varname"
if [[ $varname =~ _cr$ ]]
then
grep -v '^~' "$src" \
| sed 's/\\/\\\\/g; s/"/\\"/g; s/^/ "/; s/#FF#/#\\f/; s/$/\\r\\n"/'
else
grep -v '^~' "$src" \
| sed 's/\\/\\\\/g; s/"/\\"/g; s/^/ "/; s/#FF#/#\\f/; s/$/\\n"/'
fi
printf "};\n\n"
}
for src in "$@"
do
src="${src##*/}"
name="${src%.*}"
name="text_${name//[-.]/_}"
cname="$( echo "SZS_${name}_INC" | awk '{print toupper($0)}' )"
#echo "$name : $src -> $dest"
{
printf "\n#ifndef %s\n#define %s 1\n" "$cname" "$cname"
if [[ -f "$dir/$src" ]]
then
gen_text "$name" "$dir/$src"
echo "$src: $dir/$src" >"$src.d"
elif [[ -d "$dir/$src" ]]
then
printf '%s:' "$src" >"$src.d"
for inc in "$dir/$src"/*.inc
do
name="${inc##*/}"
name="${name%.*}"
name="text_${name//[-.]/_}"
gen_text "$name" "$inc"
printf ' \\\n\t%s' "$inc" >>"$src.d"
done
printf '\n' >>"$src.d"
else
printf '\n!! Text not found: %s\n' "$dir/$src"
exit 1
fi
printf "#endif // %s\n\n" "$cname"
} >"$src"
done