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

&ReadArguments;

#### initialise parameters ####
$start_time = `date '+%d/%m/%y %H:%M:%S %Z'`;


#### read arguments ####
   ($to_compress,@letters_to_compress) = @ARGV;


$compressed =  &compress_pattern($to_compress,@letters_to_compress);
print "$to_compress\t$compressed\n";

exit(0);


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

sub PrintHelp {
#### display full help message #####
  open HELP, "| more";
  print HELP <<End_of_help;
NAME
	compress-pattern
	
DESCRIPTION
	Compresses a pattern (first argument) by replacing repeats of
	the same letter (e.g. NNNNNNNNNNNNNNNN) by the corresponding
	regular expression (e.g. N{16}).

CATEGORY
	util
	sequence

USAGE
        compress_pattern pattern letter1 letter2 ...

OPTIONS
	-h	(must be first argument) display full help message
	-help	(must be first argument) display options
End_of_help
  close HELP;
  exit;
}

sub PrintOptions {
#### display short help message #####
  open HELP, "| more";
  print HELP <<End_short_help;
compress-pattern options
-----------------------
-h	(must be first argument) display full help message
-help	(must be first argument) display options
End_short_help
  close HELP;
  exit;
}


sub ReadArguments {
#### read arguments ####
    foreach my $a (0..$#ARGV) {
	### verbose ###
	if ($ARGV[$a] eq "-v") {
	    if (&IsNatural($ARGV[$a+1])) {
		$verbose = $ARGV[$a+1];
	    } else {
		$verbose = 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") {
	    $infile{input} = $ARGV[$a+1];
	    
	    ### output file ###
	} elsif ($ARGV[$a] eq "-o") {
	    $outfile{output} = $ARGV[$a+1];
	    
	}
    }
}
