#!/bin/sh

if [ "$#" -lt 1 ]; then
    echo "You must enter at least one CNF file or the folder that contains them!" && exit
fi

firstParam="${1}"
filesCNF="${*}"

if [ -d "$firstParam" ]; then
  filesCNF="${firstParam}/*.cnf"
  prevLastCharacter=$(echo -n "${firstParam}" | tail -c 1)
  if [ "$prevLastCharacter" = "/" ]; then
    filesCNF="${firstParam}*.cnf"
  fi
fi

valgrind --leak-check=full --track-origins=yes ./solve ${filesCNF} > valgrindSolve.output 2>&1
./solve ${filesCNF} | valgrind --leak-check=full --show-leak-kinds=all ./view > valgrindView.output 2>&1
ls ${filesCNF} | head -n 1 | valgrind --leak-check=full ./slave.o > valgrindSlave.output 2>&1