#!/usr/bin/perl -w

$lehmindent = "";
$indent = "";
$print = 1;

while (<>) {
	if (m!<svg\b!) {
		s! xml:space="preserve"!!;
	}
	
	print;

	if (m!<style\b!) {
		print ".lehmpunkte { fill:#cccccc }\r\n";
	}

	if (m!^(\s*)<g (.* )?id="Lehmpunkte"!) {
		$lehmindent = $1;
		last;
	}
}

while (<>) {
	if (m!^$indent</g>!) {
		$indent = "";
		$print = 1;

		$_ = <>;
		if (m!<(polygon|path)\b!) {
			s! class="[^"]*"!!;
			s!<(polygon|path)\b!<$1 class="lehmpunkte"!;
		}
	}

	if (m!^(\s*)<g (.* )?style="clip-path:url!) {
		$indent = $1;
		$print = 0;
	}

	print if ($print);

	last if m!^$lehmindent</g>!;
}

while (<>) {
	print;
}
