#!/usr/local/bin/perl -w

$user_file = "../Mondial-facts/mondial-rel-facts.flp";
$output_file = "../Mondial-facts/mondial-inputs.sql";

`rm ../Mondial-facts/mondial-inputs.sql`;

# Oeffne die Eingabe- und Ausgabe-datei
open user_file or die "can not open file" ;
open (OUT,">>$output_file") or die "can not open output file" ;

while (<user_file>) {
    $_=~s/%.*printed.*/COMMIT;/g;
    $_=~s/%.*//g;
    $_=~s/\Amountain\(([^,]*,[^,]*),([^,]*,[^)]*)\)/mountain\($1,GeoCoord\($2\)\)/g;
    $_=~s/\Aisland\(([^,]*,[^,]*,[^,]*),([^,]*,[^)]*)\)/island\($1,GeoCoord\($2\)\)/g;
    $_=~s/\A([^( ]*)\(/INSERT INTO $1 VALUES \(/g;
    $_=~s/\)\./\);/g;
    $_=~s/null/NULL/g;
    $_=~s/#//g;
    $_=~s/"/'/g;
    print OUT $_;
}

# Schliesse die offenen Dateien.
close(user_file);
close(OUT);


