#!/bin/bash

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

ELIMINACIONI=0;
SUMA=0;
BROJAC=0;
PROSAO=0;
DETALJI=0;


if [ -n "$3" ] && [ $3 == "-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" == "0" ]; then
			if [ "$PROSAO" == "DA" ]; then
				ELIMINACIONI=1;
			fi
		else
			if [ "$PROSAO" == "DA" ]; then
				SUMA=$[SUMA+1];
			fi
		fi
		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, uk:$TOTAL";

