#!/bin/bash

# Check that the temp space exists
if [ -d mctemp ]
then
  echo "Warning: mctemp already existed"
else
  mkdir mctemp
  echo "Made the mctemp directory, you might need to clean it up..."
fi

# Copy all the c files there
cp *.c mctemp/

# Now go through what we have there and add some space to the mallocs
for item in `ls *.c`
do
  cat mctemp/$item | sed 's/malloc(/malloc(100 + /g' > $item
done

make
./panda

if [ $? -eq 0 ]
then
  echo "No problem found!"
  exit
fi

# Find the file
for item in `ls *.c`
do
  cp mctemp/$item $item
  make
  ./panda

  if [ $? -eq 0 ]
  then
    echo "Changing $item fixed it"
    exit
  fi
done

echo "Didn't find anything of interest"