# MK_CDECLIST

CDECLISTDIR="/Users/jar/src/cdeclist"
DEFAULTDIR="."
CDIR=`dirname $1`
if [ ${CDIR} = "." ]
then
	CDIR=${DEFAULTDIR}
fi
HDIR=${CDIR}
CDECLIST=""
#option: if define LLOUT="Sall.1", then output concatenated onto Sall.1;
#else get individual output files with prefix "LL";
#LLOUT="Sall.1"
LLOUT="dumdumdum"
CPPPROG="/usr/bin/cpp"
#CPPPROG="/usr/bin/cpp-3.3

for i in $*
do
	FILE=`basename ${i}`
	echo processing file: $i >&2
	if [ ${LLOUT} != "Sall.1" ]
	then
		LLOUT=LL${FILE}
		>${LLOUT}
		CDECLIST="${CDECLIST} ${LLOUT}"
	fi
	echo "\n\n/*********************************************/\n" >>${LLOUT}
	echo /*${FILE}*/ >>${LLOUT}
	echo >>${LLOUT}
#	echo ${i} ${FILE} ${LLOUT} ${CDECLIST} ${CDIR} ${HDIR} 1>&2
#	echo start of main pipe in loop 1>&2
 	cat ${CDIR}/${FILE} |
		${CDECLISTDIR}/uncomment |
		${CDECLISTDIR}/cdeclist1 |
		${CPPPROG} -I${HDIR} -P -C |
		${CDECLISTDIR}/cdeclist2 |
		${CDECLISTDIR}/cdeclist3 |
		${CDECLISTDIR}/cdeclist4 >>${LLOUT}
	echo done loop for: ${i} ${FILE} ${LLOUT} ${CDECLIST} 1>&2
done

#temporary++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#exit

#NOTE: what follows is an example of manipulation of the cdeclist output.

#the following cats a list of separate "LL" files onto Sall.1
echo
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo combining files: ${CDECLIST}
>Sall.1
for i in ${CDECLIST}
do

	cat ${i} >>Sall.1
done

#the following extracts a list of function definitions _only_;
#(no static or external declarations; no definitions of arrays/vars/structs);
#collect comment header lines, functions, and struct declarations;
#get rid of register specs;
#strip any variable declarations trailing struct declarations;
#change return (n) -> return (0), so ok for return of pointers;
#insert VARARGS where needed;
#to include structure definitions, add to 1st egrep: |struct[ ]+[^;({]+\{
#remove several functions with "static" scope -- and that give errors in
#compilation without struct definitions (same scope);
#this gives a partial lint library - full library needs array/variables;
#		-e "s/\}[^;}]*\;$/\}\ \;/"	\

cat Sall.1|egrep '\/\*[^L]|\{\}|\ return[ ;]' |
	egrep -v '^static\ |INITIALIZED' |
	egrep -v '\ engr_at[(]|^del_engr[(]|\ outentry[(]|^ini_inv[(]' |
	sed -e "s/register[ ]\([^;, ][^;, ]*[;,]\)/int\ \1/g"	\
		-e "s/register[ ]//g"	\
		-e "s/[}][^;}]*\;$/ \}\ \;/"	\
		-e "s/return\ .[1-3]./return\ \(0\)/g"	\
		-e "s/^panic/\/\*VARARGS1\*\/\\
panic/"	\
		-e "s/^error/\/\*VARARGS1\*\/\\
error/"	\
		-e "s/^pline/\/\*VARARGS1\*\/\\
pline/"	\
		-e "s/^impossible/\/\*VARARGS1\*\/\\
impossible/p" >Sall.2

