#!/usr/bin/perl # # civgame-clean - reduce the number of Freeciv savefiles # # for usage informatiuon, call me without arguments or options # $Id: civgame-clean,v 1.1$ # # if you modify this script, please notify # the author: reinpost@xxxxxxxxxx (Reinier Post) # # should run under Perl 4.036 or any Perl 5 sub usage { print < $maxyear; } #--- mark all years that would be saved with saveturns set to $freq ---# # undef(%freqsaved); for ($i = 0, $year = -4000; $year <= $maxyear; ++$i, $year += ($year < 1000 ? 20 : $year < 1500 ? 10 : 5)) { $freqsaved{$year || 1} = 1 unless $i % $freq; } #--- also mark the latest savefile in each directory, if requested ---# # # bug: treats the same directory under different names as different # if ($savelatest) { undef(%foundoneindir); foreach (sort {$year{$b} <=> $year{$a}} keys(%year)) { $mydir = m#^(.*)/# ? $1 : '.'; next if defined($foundoneindir{$mydir}); $foundoneindir{$mydir} = 1; $freqsaved{$year{$_} || 1} = 1; } } #--- remove all saved games corresponding to unmarked years ---# # if ($justshow) { foreach (sort {$year{$a} <=> $year{$b}} keys(%year)) { warn(($freqsaved{$year{$_}} ? '# not: ' : '') . "rm $_\n"); } } else { while (($_,$year) = each(%year)) { unlink($_) unless $freqsaved{$year{$_}}; } }