#! perl -w

##
## This file is a simple utility file to simplify editing 
## configuration files which might not exist.
##

use Getopt::Long;
$Getopt::Long::passthrough = 1;
$Getopt::Long::ignorecase = 0;

my $editor;

if ($^O eq "MSWin32") {
    $editor = "write.exe";
} else {
    $editor = "/usr/bin/kedit";
}

my $file    = "";
my $verbose = 0;

GetOptions(
    "editor=s"  => \$editor,
    "file=s"    => \$file,
    "verbose" => \$verbose
) or die("Command line arguments not recognised.");

print "Editor: $editor\n" if $verbose;
print "File: $file\n" if $verbose;

if ( not -e $file ) {
    print "File does not exist.";
    open( my $fh, ">", $file)
        or die "Cannot open $file for writing.";
}

if ( not -f $file ) {
    die("Configuration file is not a writable file type.");
}

print "Calling: '$editor $file'" if $verbose;
`$editor $file`