#!/bin/bash

# Constants
DIR=docdir

function macro_rewrite
{


	file=$1
	fileout="$1.out"

	echo "Processing $file"

	awk '/@fn/       { macrof = 1;  ; print " * @note This is a macro-function." }
	     /@fn/       { split($0, array, "@fn"); prototipe=array[2] }
             /#define/   { if(macrof){ define = 1; macrof = 0 } }
             define == 1 { if(prototipe){ print prototipe ";"; prototipe=0 } }
	     define == 1 { print "//" $0 }
	     define == 0 { print $0 }
	     $0 !~ /\\$/ { if(define) {define = 0}} ' "$file" > "$fileout"

        rm -Rf "$file"
        mv "$fileout" "$file"


}




# Delete the doxygen folder.
rm -Rf doxygen docdir

# Create the directory and copy the sources.
mkdir $DIR
cp -Rf lib $DIR
cp -Rf include $DIR
cp -Rf Doxyfile $DIR

# Move to the doc folder.
cd $DIR

for i in include/*.h
do
	macro_rewrite $i
done

for i in lib/*.c
do
	macro_rewrite $i
done

doxygen Doxyfile

mv doxygen ..

cd ..
rm -Rf docdir
