3 # TODO Don't hardcode xdump columns, get them from xdump meta
9 $Getopt::Std::STANDARD_HELP_VERSION = 1;
12 or die "$0: invalid options\n";
13 die "$0: either -j or -s, not both\n"
16 my $ctime_re = qr/(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 123][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9] [0-9][0-9][0-9][0-9]/;
17 my $xdfld_re = qr/\([^)]*\)|[^ (][^ ]*/;
19 # Current dump, if any
20 # Either zero or the name of the dump we're currently processing.
21 # Legacy dump names start with an uppercase letter, and xdump names
22 # start with a lowercase letter.
27 $s =~ s/$ctime_re/Thu Jan 1 00:00:00 1970/g;
35 if ($opt_j || $opt_s) {
36 die "$0: malformed line" unless /^$ctime_re /;
40 # Split off prefix that is not to be normalized
43 die "$0: malformed line" unless substr($_, 10, 1) eq ' ';
44 $pfx .= substr($_, 0, 11);
45 # Normalize only player output
47 if (/(^output [^ ]* 1 )(.*)/) {
58 ### Host environment in logs
59 # getrusage() results in server.log
60 s/(End update|done assembling paths) .* user .* system/$1 0.0 user 0.0 system/g;
62 s/(Empire server \(pid) [0-9]+(\) started)/$1 42$2/g;
64 # shutdown wins race with logout
65 next if /Waiting for player threads to terminate/;
74 and (/\: No (sector|ship|plane|unit|nuke)\(s\)|\: Nothing lost/
75 or /^[0-9]+ (sector|ship|plane|unit|nuke|lost item)/));
78 # nat_timeused in prompt
79 s/^\[[0-9]+(:[0-9]+\] Command \:)/[0$1/g;
80 # TODO command play column time
81 # result of ctime() in many commands
84 ### Time values in legacy dumps
85 s/(DUMP (SECTOR|SHIPS|PLANES|LAND UNITS|NUKES|LOST ITEMS)) [0-9]+$/$1 0/g;
87 if $dump eq 'LOST ITEMS';
88 ### Time values in xdump
89 s/(XDUMP (meta )?[-a-z0-9]+) [0-9]+$/$1 0/
91 # HACK: assume any integer with more than 10 digits is time
92 # TODO don't do that, use xdump meta instead
93 s/(^| )[0-9]{10,}/${1}0/g
95 # timeused in xdump country timeused (column 10)
96 s/^(($xdfld_re ){10})([0-9]+) /${1}255 /
97 if $dump eq 'country';
98 # timeused in xdump nat (column 15)
99 s/^(($xdfld_re ){15})([0-9]+) /${1}255 /
101 # duration in xdump news (column 4)
102 s/^(($xdfld_re ){4})([0-9]+) /${1}0 /
104 ### nsc_type values in xdump
105 # Can vary between systems, because the width of enumeration types
106 # is implementation-defined.
107 # TODO type in xdump meta
108 ### nrndx values in xdump
109 # Encoding depends on the host, see resources[]. Too clever by half;
110 # perhaps we should change it.
111 # nrndx in xdump product (column 12)
112 s/^(($xdfld_re ){12})([0-9]+) /${1}0 /
113 if $dump eq 'product';
114 # value in xdump resources (column 0)
116 if $dump eq 'resources';
117 ### Floating-point zero in xdump
118 # Windows %#g prints it with seven significant digits instead of six
119 s/ 0\.000000/ 0.00000/g
120 if $dump =~ /^[a-z]/;
124 if (/(XDUMP|^config) (meta )?([-a-z0-9]+)/) {
126 die unless $dump =~ /^[a-z]/;
127 } elsif (/DUMP (SECTOR|SHIPS|PLANES|LAND UNITS|NUKES|LOST ITEMS) /) {