#!/usr/bin/perl -w
#use strict;;
if ($0 =~ /([^(\/)]+)$/) {
    push (@INC, "$`lib/");
}
require "RSA.lib";


#### initialise parameters ####
local $start_time = &RSAT::util::StartScript();
local $inputfile = "";
local $outputfile = "";
local $verbose = 0;
local $in = STDIN;
local $out = STDOUT;

&ReadArguments;

### temp : take 2 last arguments as query strings
my $str1 = $ARGV[$#ARGV -1];
my $str2 = $ARGV[$#ARGV];

my $distance = &EditDistance($str1,$str2,$hyperverbose);

printf "distance: %d\n", $distance;


#### check argument values ####


### open output file ###
$out = &OpenOutputFile($outputfile);

##### read input #####
#($in, $input_dir) = &OpenInputFile($inputfile);
#while (<$in>) {
#
#}

close $in if ($inputfile);
close $out if ($inputfile);

#### verbose ####
if ($verbose) {
  print $out "; edit-distance ";
  &PrintArguments;
}


################################################################
## Report execution time and close output stream
my $exec_time = &RSAT::util::ReportExecutionTime($start_time); ## This has to be exectuted by all scripts
print $main::out $exec_time if ($main::verbose >= 1); ## only report exec time if verbosity is specified
close $main::out if ($outputfile);


exit(0);


########################## subroutine definition ############################

sub PrintHelp {
#### display full help message #####
  open HELP, "| more";
  print HELP <<End_of_help;
NAME
	edit-distance

        1999 by Jacques van Helden (Jacques.van-Helden\@univ-amu.fr)
	
USAGE
        edit-distance [-v] [-o outputflie] string1 string2

DESCRIPTION
	calculated the minimal edit distance between two strings

CATEGORY
	sequences

OPTIONS
	-h	(must be first argument) display full help message
	-help	(must be first argument) display options
	-v	verbose
	-i inputfile
		if not specified, the standard input is used.
		This allows to place the command within a pipe.
	-o outputfile
		if not specified, the standard output is used.
		This allows to place the command within a pipe.

End_of_help
  close HELP;
  exit;
}

sub PrintOptions {
#### display short help message #####
  open HELP, "| more";
  print HELP <<End_short_help;
edit-distance options
----------------
-h	(must be first argument) display full help message
-help	(must be first argument) display options
-i	input file
-o	output file
-v	verbose
End_short_help
  close HELP;
  exit;
}


sub ReadArguments {
#### read arguments ####
  foreach my $a (0..$#ARGV) {
    ### verbose ###
    if ($ARGV[$a] eq "-v") {
      $verbose = 1;
    } elsif ($ARGV[$a] eq "-vv") {
      $verbose = 1;
      $hyperverbose = 1;
    
      ### detailed help
    } elsif ($ARGV[$a] eq "-h") {
      &PrintHelp;
      
      ### list of options
    } elsif ($ARGV[$a] eq "-help") {
      &PrintOptions;
      
      ### input file ###
    } elsif ($ARGV[$a] eq "-i") {
      $inputfile = $ARGV[$a+1];
      
      ### output file ###
    } elsif ($ARGV[$a] eq "-o") {
      $outputfile = $ARGV[$a+1];
      
    }
  }
}

