#!/bin/bash
# This scripts handles everything for one document that is 
# already on local system. The first arg should be the 
# complete path to the file. 

# prepare names
folder=$(dirname $1)
file=$(basename $1)
filene="${file%.*}"

# unzip
7z e -o$folder $folder/$file > /dev/null

# check for 7z errors
if [ $? -ne 0 ]
then
	echo "ERROR while uncompresssing the file $file"
fi

# delete zip
rm -f $1

# fix 
 characters
tr -d '
' < $folder/$filene.txt > $folder/$filene.txt.tr
mv $folder/$filene.txt.tr $folder/$filene.txt
#cp $folder/$filene.txt $folder/$filene.txt.before
#sed -i 's/
//g' $folder/$filene.txt 

# call perl that prepares arguments
# and calls java code
./run_java.pl $folder/$filene.txt

# delete txt
rm -f $folder/$filene.txt
