#/mnt/us/bin/perl
#our $file = "zz";
our $file = "/mnt/us/documents/My\ Clippings.txt";
open our $info, $file or die "Could not open $file: $!";
open(our $ftmp, '>', 'mycl-tmp');
open(our $fsl, '>', 'slowka');

print "\n\nAdding words from 'My Clippings.txt...'";
#$t1=~s/[^[:print:]]+//g;

our $ile=0;
our $ang="";
our $pol="";
our $line="";

sub saveword {
	print $fsl "0\t9999999999\t0\t9999999999\t".$ang."\t".$pol."\n";
	$ile++;
}

sub next {
	for ($i=0 ; $i < 5 ; $i++){
		$line = <$info>;
		print $ftmp $line;		
	}
}

while($line = <$info>)
{        
	our @tab=split(/\.\./, $line);

	if ( $tab[0] eq "m") { 
		$t1 = $tab[1];
		$t1=~s/[\n\r]+//g;
		if ( $t1 eq "m" ) {
			print $ftmp "\n";	# usun m
			&next();
			$ang=$line;
			$ang=~s/[\n\r]+//g;
			&next();	
			$pol=$line;
			$pol=~s/[\n\r]+//g;
			&saveword();
		}elsif ( $t1 eq "mm" ) {
			print $ftmp "\n";	# usun m
			&next();
			$ang=$line;
			$ang=~s/[\n\r]+//g;
			&next();
			$pol=$line;
			$pol=~s/[\n\r]+//g;
			&next();	
			$line=~s/[\n\r]+//g;
			$ang=$ang."   ".$line;
			&saveword();
		}else{
			$pol = $tab[1];
			$pol =~s/[\n\r]+//g;

			print $ftmp $tab[1]."\n";	# usun m

			&next();
		
			$ang=$line;
			$ang=~s/[\n\r]+//g;
			$t2 = $tab[2];
			$t2 =~s/[\n\r]+//g;

			if ( $t2 eq "m") { 
				&next();
				$line=~s/[\n\r]+//g;
				$ang = $ang."   ".$line;
			}
			&saveword();
		}

	}else {		
		print $ftmp $line;
	}
}

print "\n\nNumber of new words: ".$ile."\n\n";

close $info;
close $ftmp;
close $fsl;




