#!/bin/sh

for try in /usr/include/sys/acct.h /usr/include/linux/acct.h
do
  if [ -s ${try} ]; then
	acctfile=${try};
	break;
  fi
done

if [ -z "${acctfile}" ]; then
  exit 1
fi

tmpfile=/tmp/bleagh
flag=no

echo "/* automatically generated by makecnst -- do not edit */"
echo ""
echo "#define ACCT_H_FILE \"${acctfile}\""

/lib/cpp ${acctfile} > ${tmpfile}

out=`grep ac_comm ${tmpfile} | head -1 | sed -e 's/^.*\[//' -e 's/\].*$//'`
echo "#define CMD_LEN ${out}"

for field in AC_UTIME AC_STIME AC_ETIME AC_IO AC_MEM
do
  out=`grep -i ${field} ${tmpfile} | head -1 | sed 's/\;.*$//' \
	  | awk '{ printf ("%s", $1); \
			   for (i=2; i<NF; i++) \
				 printf (" %s", $i); \
			   printf ("\n"); }'`
  if [ "${out}" = "comp_t" ]; then
    echo "#define ${field}_COMP_T"
    flag=yes
  else
    echo "/* #undef ${field}_COMP_T */"
  fi
done

if [ "${flag}" = "yes" ]; then
  echo "#define HAVE_COMP_T"
else
  echo "/* #undef HAVE_COMP_T */"
fi

rm -f ${tmpfile}
