#!/usr/bin/perl

# Vypíše /etc/fstab ve formě XML souboru.
# 
# Závislosti:
#	aptitude install libxml-writer-perl

use strict;
use warnings;

use IO::String;
use XML::Writer;

my $xml;
my $output = new IO::String->new($xml);
my $writer = new XML::Writer(	OUTPUT => $output,
								DATA_MODE => 1,
								DATA_INDENT => "	");

$writer->xmlDecl("UTF-8");
$writer->startTag("fstab");

my $fstab;
open($fstab, "<", "/etc/fstab");
while (my $r = <$fstab>) {
	if ($r !~ /^\x23/ && $r =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/) {
		$writer->startTag("bod");
		$writer->dataElement("zařízení", "$1");
		$writer->dataElement("přípojnýBod", "$2");
		$writer->dataElement("souborovýSystém", "$3");

		$writer->startTag("volby");
		my @volby = split(",", $4);
		foreach my $volba (@volby) {
			$writer->dataElement("volba", "$volba");
		}
		$writer->endTag();

		$writer->dataElement("dump", "$5");
		$writer->dataElement("pass", "$6");
		$writer->endTag();
	}
}

$writer->endTag();
print $xml;
print "\n";

