-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatefromtemplate.sh
executable file
·110 lines (87 loc) · 3.53 KB
/
updatefromtemplate.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# FS Tools
# Copyright (C) 2009-2011 Jakob Klein, [email protected]
#
# This file is part of FS Tools.
#
# FS Tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FS Tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FS Tools. If not, see <http://www.gnu.org/licenses/>.
# Example usage: ./updatefromtemplate.sh FA_RJ100_WV_statetable_r001.csv FA_RJ100_WV_textures.txt FA_RJ100_WV_control.txt > FA_RJ100_WV_control_new.txt
# Input $1 lightstates csv, $2 texturelist txt, $3 control asm, output to stdout.
# Check arguments' validity.
if [[ ${#1} -lt 1 ]]; then
echo "Argument Error! Usage `basename $0` <lightstates csv file> <testurelist txt file> <control asm file>"
exit
fi
if [[ ${#2} -lt 1 ]]; then
echo "Argument Error! Usage `basename $0` <lightstates csv file> <testurelist txt file> <control asm file>"
exit
fi
if [[ ${#3} -lt 1 ]]; then
echo "Argument Error! Usage `basename $0` <lightstates csv file> <testurelist txt file> <control asm file>"
exit
fi
# Work on each line of control asm file.
while IFS="" read controlline; do
if [[ "${controlline:0:9}" = ";#insert#" ]]; then
substitutionname=$(echo "$controlline" | cut -d\ -f2)
# Work on each line of the lightstates csv file to see if the line matches the the requested substitution.
while read statesline; do
# If Stateline starts with Quoted Fields: unquote.
if [[ "${statesline:0:1}" = "\"" ]]; then
# Remove Quotes from fields if any.
statesline=`echo "$statesline" | perl -pe 's/^\"//g; s/\"$//g; s/\"\t/\t/g; s/\t\"/\t/g;'`;
fi
case ${statesline:0:1} in
\#)
# Do nothing (comment)
;;
*)
statename=$(echo "$statesline" | cut -f1)
if [[ $statename = $substitutionname ]]; then
# This is a very very dirty hack, missusing the bell character BEL U+0007 "\a"
# as a substitution for embeded spaces which should be conserved!
listelements=$(echo "$statesline" | cut -f2- | sed -e "y/\t\ /\ \a/")
istexturename=1
texturename=""
texturenum=0
texturelist=" TEXTURE_LIST_BEGIN\n"
for item in $listelements; do
if [[ $istexturename -eq 1 ]]; then
istexturename=0
# Sets and translates lowercase name of texture to upper.
# Added reverse for Space to BEL hack!
texturename=$(echo $item | tr "[:lower:]" "[:upper:]" | sed -e "y/\a/\ /")
if [[ ${#texturename} -gt 63 ]]; then
echo "ERROR! ${texturename} too long (${#texturename} of max 63 characters)."
exit
fi
else
istexturename=1
nexttexturenum=$(($texturenum + 1))
texturelist="${texturelist} TEXTURE_DEF ${item}, <`sed -n ${nexttexturenum}p $2 | cut -f4`>, `sed -n ${nexttexturenum}p $2 | cut -f5`, \"${texturename}\" ; ${texturenum}\n"
texturenum=$nexttexturenum
fi
done
texturelist="${texturelist} TEXTURE_LIST_END"
echo -e "$texturelist"
fi
;;
esac
# Done with Lightstates csv file.
done < $1
else
echo -e "$controlline"
fi
# Done with control asm file.
done < $3