#!/usr/bin/env bash

src_dir="lib/src"

allocation_functions=(
  malloc
  calloc
  realloc
  free
)

for function in ${allocation_functions[@]}; do
  usages=$(grep --line-number -E "\b${function}\(" -r "${src_dir}" --exclude alloc.h )

  if [[ ! -z $usages ]]; then
    echo "The ${function} function should not be called directly, but is called here:"
    echo "$usages"
    exit 1
  fi
done
