4 |
# by searching the level code for lines containing either |
# by searching the level code for lines containing either |
5 |
# '(C)', 'Copyright' or 'written by' in comments. |
# '(C)', 'Copyright' or 'written by' in comments. |
6 |
|
|
7 |
|
if ($#ARGV ne 0) { |
8 |
|
print "Usage: 01fix_indices.pl [ fix | force ]\n"; |
9 |
|
print "\n"; |
10 |
|
print " * Adds author information from *.lua files to index_*.txt files\n"; |
11 |
|
print " * Formats columns according to widest element\n"; |
12 |
|
print "\n"; |
13 |
|
print " fix update files (does not touch files if no changes needed)\n"; |
14 |
|
print " force update files (force write of all files)\n"; |
15 |
|
print "\n"; |
16 |
|
print "Tipp: If you want to force formatting of a single file remove 1 author entry\n"; |
17 |
|
die "Missing parameter"; |
18 |
|
} |
19 |
|
|
20 |
|
my $force = 0; |
21 |
|
if ($ARGV[0] eq "force") { |
22 |
|
$force = 1; |
23 |
|
} |
24 |
|
elsif ($ARGV[0] ne "fix") { |
25 |
|
die "invalid argument '$ARGV[0]'"; |
26 |
|
} |
27 |
|
|
28 |
my $items_per_line = 3; # currently: filename, fullname and author |
my $items_per_line = 3; # currently: filename, fullname and author |
29 |
|
|
30 |
sub crop($) { |
sub crop($) { |
52 |
my $author = ''; |
my $author = ''; |
53 |
|
|
54 |
if ($fname ne 'todo.lua') { |
if ($fname ne 'todo.lua') { |
55 |
print " Searching '$fname' for authors name..\n"; |
# print " Searching '$fname' for authors name..\n"; |
56 |
open FILE,"<$fname" || die "Can't open levelfile '$fname'"; |
open FILE,"<$fname" || die "Can't open levelfile '$fname'"; |
57 |
foreach (<FILE>) { |
foreach (<FILE>) { |
58 |
chomp; |
chomp; |
78 |
# skip email address: |
# skip email address: |
79 |
if ($maybe_author =~ /\([\w\.]+@[\w\.]+\)/ig) { $maybe_author = $`; } |
if ($maybe_author =~ /\([\w\.]+@[\w\.]+\)/ig) { $maybe_author = $`; } |
80 |
|
|
81 |
|
# remove '/ant_39' |
82 |
|
$maybe_author =~ s/\/\s*ant_39//ig; |
83 |
|
|
84 |
if ($maybe_author ne '') { |
if ($maybe_author ne '') { |
85 |
$maybe_author = crop($maybe_author); |
$maybe_author = crop($maybe_author); |
86 |
if ($author eq '') { $author = $maybe_author; } |
if ($author eq '') { $author = $maybe_author; } |
98 |
sub correct_indexfile($) { |
sub correct_indexfile($) { |
99 |
my ($fname) = @_; |
my ($fname) = @_; |
100 |
|
|
101 |
print "Fixing $fname..\n"; |
print "Checking ".substr($fname.".. ",0,35); |
102 |
|
|
103 |
# -------------------- |
# -------------------- |
104 |
# load index: |
# load index: |
111 |
|
|
112 |
my @what = ( 'Name', 'Fullname', 'Author' ); |
my @what = ( 'Name', 'Fullname', 'Author' ); |
113 |
my @max_len; |
my @max_len; |
114 |
|
my $fixed = 0; |
115 |
for (my $i=0; $i<$items_per_line; $i++) { push @max_len, 0; } |
for (my $i=0; $i<$items_per_line; $i++) { push @max_len, 0; } |
116 |
|
|
117 |
@lines = map { |
@lines = map { |
126 |
if ($len[2] == 0) { # author missing? |
if ($len[2] == 0) { # author missing? |
127 |
$split[2] = parse_author($split[0].".lua"); |
$split[2] = parse_author($split[0].".lua"); |
128 |
$len[2] = length $split[2]; |
$len[2] = length $split[2]; |
129 |
|
if ($len[2] > 0) { |
130 |
|
$fixed++; |
131 |
|
} |
132 |
} |
} |
133 |
|
|
134 |
for (my $i=0; $i<$items_per_line; $i++) { |
for (my $i=0; $i<$items_per_line; $i++) { |
171 |
} |
} |
172 |
} @lines; |
} @lines; |
173 |
|
|
174 |
|
# -------------------- |
175 |
|
# save changes: |
176 |
|
|
177 |
# for (my $i=0; $i<$items_per_line; $i++) { |
if ($fixed>0 || $force==1) { |
178 |
# print "max_len[$i] = $max_len[$i]\n"; |
my $fname_out = $fname; |
179 |
# } |
open FILE,">$fname_out" || die "Can't open $fname_out"; |
180 |
|
foreach (@lines) { |
181 |
|
print FILE "$_\n"; |
182 |
|
} |
183 |
|
close FILE; |
184 |
|
|
185 |
# -------------------- |
print "added $fixed authors\n"; |
186 |
# save fixed index: |
} |
187 |
# my $fname_out = $fname.".fixed"; |
else { |
188 |
my $fname_out = $fname; |
print "up-to-date\n" |
189 |
open FILE,">$fname_out" || die "Can't open $fname_out"; |
} |
|
foreach (@lines) { print FILE "$_\n"; } |
|
|
close FILE; |
|
190 |
} |
} |
191 |
|
|
192 |
correct_indexfile("index_enigma.txt"); |
correct_indexfile("index_enigma.txt"); |