Populated Bestine Capitol Building with missing NPCs. Also spawns several other missi...
[swg-src.git] / tools / moveUpOrAddAttribute.pl
blob7b1a13ab2d1df6a983d36215a06f8f790a6769f8
1 # ======================================================================
3 # moveUpOrAddAttribute.pl
5 # Copyright 2001 Sony Online Entertainment Inc.
6 # All Rights Reserved.
7 #
8 # PURPOSE (object template .tpf file utility):
10 # If a given attribute exists for a specified class, move the attribute
11 # from the old class into the new class. The new class must be higher
12 # up (more general) in the class hierarchy. If the given attribute
13 # doesn't exist, add (or replace) it with the given default value in the
14 # new class section. If the new class section doesn't exist, create
15 # the new class section.
17 # SYNTAX:
19 # perl moveUpOrAddAttribute.pl <tpf filename> <old class name> <new class name> <attribute name> <default value>
21 # ======================================================================
23 # check for proper argument count
24 if (scalar(@ARGV) != 5)
26 die "syntax: perl moveUpOrAddAttribute.pl <tpf filename> <old class name> <new class name> <attribute name> <default value>\n";
29 # states
30 $SCAN_OUTSIDE = 1;
31 $SCAN_OLD_CLASS = 2;
32 $SCAN_NEW_CLASS = 3;
33 $COPY_REMAINDER = 4;
35 # open source tpf file
36 $sourcePathname = $ARGV[0];
37 open (SOURCE, $sourcePathname) or die "failed to open source filename for reading [$sourcePathname]\n";
39 # open temp work filename
40 $destPathname = $sourcePathname . '.tmp';
41 open (DEST, '>' . $destPathname) or die "failed to open dest filename for writing [$destPathname]\n";
43 # initialize state
44 $oldClassName = $ARGV[1];
45 $newClassName = $ARGV[2];
46 $attributeName = $ARGV[3];
48 $currentState = $SCAN_OUTSIDE;
49 $writeValue = $ARGV[4];
51 # process each line from source file
52 while (<SOURCE>)
54 SWITCH:
56 if ($currentState == $SCAN_OUTSIDE)
58 # check for new states
59 if (/^\@class $oldClassName/)
61 $currentState = $SCAN_OLD_CLASS;
63 elsif (/^\@class $newClassName/)
65 $currentState = $SCAN_NEW_CLASS;
68 # always copy input
69 print DEST;
71 last SWITCH;
74 if ($currentState == $SCAN_OLD_CLASS)
76 # check for new states
77 if (/^$attributeName\s=\s(.*)$/)
79 # found the old attribute, save its setting.
80 # do not emit the attribute in the new file (we're moving it)
81 $writeValue = $1;
83 else
85 # for all other input, we do copy the input
86 if (/^\@class\s(.*)\s$/)
88 # we're in the old class, moving to a new class
89 if ($1 eq $newClassName)
91 $currentState = $SCAN_NEW_CLASS;
93 else
95 $currentState = $SCAN_OUTSIDE;
99 # copy the input
100 print DEST;
102 last SWITCH;
105 if ($currentState == $SCAN_NEW_CLASS)
107 if (/^$attributeName\s=/)
109 # found the attribute in the new class, replace it.
110 # do not emit the attribute in the new file (we're moving it)
112 print DEST "$attributeName = $writeValue\n";
114 # we're done, copy the rest
115 $currentState = $COPY_REMAINDER;
117 else
119 # for all other input, we do copy the input
121 if (/^\@class\s/)
123 # we're moving to a new class, need to inject the attribute since it hasn't appeared yet.
124 print DEST "$attributeName = $writeValue\n\n";
126 # we're done, copy the rest
127 $currentState = $COPY_REMAINDER;
130 # copy the input
131 print DEST;
134 last SWITCH;
137 if ($currentState == $COPY_REMAINDER)
139 # always copy input
140 print DEST;
142 last SWITCH;
145 die "unknown state $currentState\n";
149 # let all states deal with the end-of-source-file event
151 SWITCH:
153 if ($currentState == $SCAN_OUTSIDE)
155 # print missing class and attribute
156 print DEST "\n\@class $newClassName\n$attributeName = $writeValue\n";
158 last SWITCH;
160 if ($currentState == $SCAN_OLD_CLASS)
162 # print missing class and attribute
163 print DEST "\n\@class $newClassName\n$attributeName = $writeValue\n";
165 last SWITCH;
167 if ($currentState == $SCAN_NEW_CLASS)
169 # print missing attribute
170 print DEST "$attributeName = $writeValue\n";
172 last SWITCH;
174 if ($currentState == $COPY_REMAINDER)
176 # nothing to do
177 last SWITCH;
180 die "unknown state $currentState\n";
184 # close the source and dest file
185 close SOURCE;
186 close DEST;
188 # rename dest filename to source filename, clobbering the original source
189 rename $destPathname, $sourcePathname