#use strict;
use warnings;

our $dir = $0;

$dir =~ s/\\/\//g;
$dir =~ s/^(.*)\/(.*?)$/$1/;

sub read_config
{
	my $file = shift;
	my %conf;
	my @tmp = &readf("$file");
	
	for(@tmp)
	{
		chomp;                  # no newline
		s/#.*//;                # no comments
		s/^\s+//;               # no leading white
		s/\s+$//;               # no trailing white
		next unless length;     # anything left?
		my ($var, $value) = split(/\s*\t*=\s*/, $_, 2);
		$conf{$var} = $value;		
	}

	return %conf;
}

sub read_dir
{
	my $d = shift;
	
	opendir(DIR, "$d") or die "ERROR: read_dir couldnt open \"$d\"";
	my @data = readdir(DIR);
	close(DIR);
	
	return @data;
	
}

sub uniq_arr
{
	my @list = @_;

	my %seen = ();
	my @uniqu = grep { ! $seen{$_} ++ } @list;
	
	return @uniqu;
}

sub readf 
{
        my $file = $_[0];

        open(FILE, "$file") or die("ERROR: Couldnt open $file to read.\n");
        my @file = <FILE>;
        close(FILE);

        return @file;
        
        return 1;
}

sub read_dir_s
{
	my $d = shift;
	my @dl_1 = ();
	my @dl_2 = ();
	my @dl_3 = ();
	my @dl_4 = ();


	opendir(DIR, "$d") or die "sub readdir cant open directory $d, $!";
	@dl_1 = readdir(DIR);
       	closedir DIR;

	for(@dl_1) 
	{
		if($_ eq ".") 
		{
			next;
		}
		push @dl_2, $_;
	}

	for(@dl_2)
	{
		if(-d $_)
		{
			push @dl_3, $_;
		}
		else
		{
			push @dl_4, $_;
		}
	}
	
	@dl_3 = sort(@dl_3);
	@dl_4 = sort(@dl_4);
	
	push @dl_3, @dl_4;

        return @dl_3;
}

sub drive_arr
{
	my $list = shift;
	$list =~ s/^\s+|\s+$//;
	my @drives = split(/\s+/, $list);
	
	return @drives;
}


1;