$winner=39;

open(SVG, shift);
while(<SVG>) {
	chomp;
	if (/(polygon|path) / && /id="([^"]*)"/) {
		$polygons{$1} = $_;
	}
}
close SVG;

open(RES, shift);
while (<RES>) {
	@res = split /;/;
	$res[$winner] =~ s/ /_/g;
	$gagnantcommunes{$res[$winner]}{$res[6].$res[10]} = 1;
}
close RES;
print <<_EOF_;
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="0 0 1143149 1060877" height="800" width="600" xmlns="http://www.w3.org/2000/svg" version="1.1">

<style type="text/css" >
<![CDATA[
.SARKOZY {fill: #0066cc;}
.HOLLANDE {fill: #ff8080;}
]]>
</style>

<g style="fill: #b9b9b9; fill-opacity: 1; stroke:white; stroke-opacity: 0; stroke-width:0;">
_EOF_

foreach $gagnant (keys %gagnantcommunes) {
	print "<g class='$gagnant'>\n";
	foreach $commune (keys %{$gagnantcommunes{$gagnant}}) {
		print "\t".$polygons{$commune} if($polygons{$commune})."\n";
		delete $polygons{$commune};
	}
	print "</g>\n";
}
print "<g class='nondef'>\n";
foreach $commune (keys %polygons) {
	print "\t".$polygons{$commune}."\n";
}
print "</g>";
print <<_EOS_;
</g>

</svg>
_EOS_
