#!/bin/bash

# poziva se sa ./testn "1.c ..." 1.t

ELIMINACIONI=1;
SUMA=0;
BROJAC=0;
ELIMINACIONIH=1;
PROSAO=0;
DETALJI=0;
POTESTPRIMERIMA="";

if [ -n "$3" ]; then
	ELIMINACIONIH=$3;
fi

if [ -n "$4" ] && [ $4 == "-v" ]; then
	DETALJI=1;
fi

FOLDER=$(pwd);
MULTILINE="";

IFS='';

while read LINE    
do
	[ -z "$LINE" ] && continue; # preskacemo prazne linije
	if [[ "$LINE" == \|* ]]; then
		PROSAO=$("./test1.sh" "$1" "$MULTILINE");
		if [ "$BROJAC" -lt "$ELIMINACIONIH" ]; then
			if [ "$PROSAO" == "DA" ]; then
				ELIMINACIONI=$[ELIMINACIONI*1];
			else
				ELIMINACIONI=0;
			fi
		else
			if [ "$PROSAO" == "DA" ]; then
				SUMA=$[SUMA+1];
			fi
		fi
		POTESTPRIMERIMA="$POTESTPRIMERIMA,$PROSAO";
		BROJAC=$[BROJAC + 1];
		if [ $DETALJI == 1 ]; then
			echo "$BROJAC : $PROSAO";
		fi
		MULTILINE="";
	else
		MULTILINE="$MULTILINE\n$LINE";
	fi
done < $2

TOTAL=$[ELIMINACIONI*SUMA];
echo "$FOLDER, $1, el:$ELIMINACIONI, pts:$SUMA,$TOTAL $POTESTPRIMERIMA";

