… | |
… | |
81 | } |
81 | } |
82 | } |
82 | } |
83 | } |
83 | } |
84 | |
84 | |
85 | sub insert { |
85 | sub insert { |
|
|
86 | my ($apply) = @_; |
|
|
87 | |
86 | shift @ARGV; |
88 | shift @ARGV; |
87 | my $format = <STDIN>; |
89 | my $format = <STDIN>; |
88 | my @slots = unpack $format, <STDIN>; |
90 | my @slots = unpack $format, <STDIN>; |
89 | |
91 | |
90 | my %res; |
92 | my %res; |
… | |
… | |
128 | print $fh Deliantra::archlist_to_string [ |
130 | print $fh Deliantra::archlist_to_string [ |
129 | map $arch->{$_}, |
131 | map $arch->{$_}, |
130 | sort keys %$arch |
132 | sort keys %$arch |
131 | ]; |
133 | ]; |
132 | close $fh; |
134 | close $fh; |
|
|
135 | |
|
|
136 | if ($apply) { |
|
|
137 | rename "$path~", $path; |
|
|
138 | } else { |
133 | system "diff", "-u", $path, "$path~"; |
139 | system "diff", "-u", $path, "$path~"; |
134 | unlink "$path~"; |
140 | unlink "$path~"; |
|
|
141 | } |
135 | } |
142 | } |
136 | }; |
143 | }; |
137 | } |
144 | } |
138 | |
145 | |
139 | binmode STDIN, ":utf8"; |
146 | binmode STDIN, ":utf8"; |
140 | binmode STDOUT, ":utf8"; |
147 | binmode STDOUT, ":utf8"; |
141 | |
148 | |
142 | if ($ARGV[0] eq "extract") { |
149 | if ($ARGV[0] eq "extract") { |
143 | extract; |
150 | extract; |
144 | } elsif ($ARGV[0] eq "diff") { |
151 | } elsif ($ARGV[0] eq "diff") { |
145 | insert; |
152 | insert 0; |
|
|
153 | } elsif ($ARGV[0] eq "apply") { |
|
|
154 | insert 1; |
146 | } else { |
155 | } else { |
147 | die <<EOF; |
156 | die <<EOF; |
148 | Usage: |
157 | Usage: |
149 | |
158 | |
150 | $0 extract 'filter' slot... |
159 | $0 extract 'filter' slot... |
151 | |
160 | |
152 | extract slots from server archetypes file (NOT the .arc files!) |
161 | extract slots from server archetypes file (NOT the .arc files!) |
153 | Example: $0 extract '%type == 101' level |
162 | Example: $0 extract '%type == 101' level |
154 | |
163 | |
155 | $0 diff [really] |
164 | $0 diff |
156 | |
165 | |
157 | generates a diff against the .arc files found |
166 | generates a diff against the .arc files found |
158 | in \$DELIANTRA_ARCHDIR or ".". |
167 | in \$DELIANTRA_ARCHDIR or ".". |
159 | |
168 | |
160 | Example: $0 diff <file |
169 | Example: $0 diff <file |
161 | |
170 | |
|
|
171 | $0 apply |
|
|
172 | |
|
|
173 | like diff, but applies it in-place |
|
|
174 | |
162 | EOF |
175 | EOF |
163 | } |
176 | } |
164 | |
177 | |
165 | |
178 | |
166 | |
179 | |