#!/bin/sh


./makeit.sep clean 2>&1 > "/dev/null"


#-----------------------------------------------------------------------
ROOT_DIR="applic.sep.ld bochs elf-to-os32 fdisk file_image_functions format kernel.ld makeit.sep qemu syslinux tap0"
ROOT_DIR_ENCLOSED="applic.mer.ld gdb-qemu gdb-qemu.txt m64.txt makeit.mer mount os32indent qemu-gdb umount listings COPYRIGHT WARRANTY x-bochs x-qemu x-cp-kimage"
ROOT_DIR_ENCLOSED_BASE64="disk.hda disk.hdb disk.hdc disk.hdd"
#-----------------------------------------------------------------------
SKEL_ENCLOSED=""
for f in `find skel -print | LC_ALL=C sort`
do
    if [ -f "$f" ]
    then
        SKEL_ENCLOSED="$SKEL_ENCLOSED $f"
    fi
done
#-----------------------------------------------------------------------
KERNEL=""
for f in `find kernel -print | LC_ALL=C sort`
do
    if   echo $f | grep "\.h$"  2>&1 > /dev/null
    then
        KERNEL="$KERNEL $f"
    elif echo $f | grep "\.s$"  2>&1 > /dev/null
    then
        KERNEL="$KERNEL $f"
    elif echo $f | grep "\.c$"  2>&1 > /dev/null
    then
        KERNEL="$KERNEL $f"
    fi
done
#-----------------------------------------------------------------------
LIB=""
LIB_SINGLE=""
for f in `find lib -print | LC_ALL=C sort`
do
    if echo $f | grep "lib[/][^/.]*\.h$"      2>&1 > /dev/null
    then
        BASE_NAME=`basename $f .h`
        if [ -d "lib/$BASE_NAME" ]
        then
            LIB="$LIB $f"
        else
            LIB_SINGLE="$LIB_SINGLE $f"
        fi
    else
        if   echo $f | grep "\.h$"      2>&1 > /dev/null
        then
            LIB="$LIB $f"
        elif echo $f | grep "\.s$"      2>&1 > /dev/null
        then
            LIB="$LIB $f"
        elif echo $f | grep "\.c$"      2>&1 > /dev/null
        then
            LIB="$LIB $f"
        fi
    fi
done
#-----------------------------------------------------------------------
APPLIC=""
APPLIC_ENCLOSED=""
for f in `find applic -print | LC_ALL=C sort`
do
    if   echo $f | grep "^t_"  2>&1 > /dev/null
    then
        if   echo $f | grep "\.c"  2>&1 > /dev/null
        then
            APPLIC_ENCLOSED="$APPLIC_ENCLOSED $f"
        fi
    elif echo $f | grep "\.h$"  2>&1 > /dev/null
    then
        APPLIC="$APPLIC $f"
    elif echo $f | grep "\.s$"  2>&1 > /dev/null
    then
        APPLIC="$APPLIC $f"
    elif echo $f | grep "\.c$"  2>&1 > /dev/null
    then
        APPLIC="$APPLIC $f"
    fi
done
#-----------------------------------------------------------------------
PORTED=""
for f in `find ported -print | LC_ALL=C sort`
do
    if [ -f $f ]
    then
        PORTED="$PORTED $f"
    fi
done
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<!--=================================================================-->"
echo "<h1>"
echo "Script e sorgenti del kernel"
echo "</h1>"
echo ""
echo "&A2COPY;"
echo ""
echo "<chaptercontents levels=\"4\">"
echo ""
#
#TEMPORARY=`tempfile`
#if [ -e disk.hda ]
#then
#    uuencode -m disk.hda disk.hda | grep -F -v "begin-base64 644" > $TEMPFILE.hda
#    echo "<enclosure enclosure=\"base64\" file=\"allegati/os32/disk.hda\">"
#    echo "<![CDATA["
#    cat $TEMPFILE.hda
#    echo \]\]\>
#    echo "</enclosure>"
#    echo ""
#    rm -f $TEMPFILE.hda
#fi
#if [ -e disk.hdb ]
#then
#    uuencode -m disk.hdb disk.hdb | grep -F -v "begin-base64 644" > $TEMPFILE.hdb
#    echo "<enclosure enclosure=\"base64\" file=\"allegati/os32/disk.hdb\">"
#    echo "<![CDATA["
#    cat $TEMPFILE.hdb
#    echo \]\]\>
#    echo "</enclosure>"
#    echo ""
#    rm -f $TEMPFILE.hdb
#fi
#if [ -e disk.hdc ]
#then
#    uuencode -m disk.hdc disk.hdc | grep -F -v "begin-base64 644" > $TEMPFILE.hdc
#    echo "<enclosure enclosure=\"base64\" file=\"allegati/os32/disk.hdc\">"
#    echo "<![CDATA["
#    cat $TEMPFILE.hdc
#    echo \]\]\>
#    echo "</enclosure>"
#    echo ""
#    rm -f $TEMPFILE.hdc
#fi
#if [ -e disk.hdd ]
#then
#    uuencode -m disk.hdd disk.hdd | grep -F -v "begin-base64 644" > $TEMPFILE.hdd
#    echo "<enclosure enclosure=\"base64\" file=\"allegati/os32/disk.hdd\">"
#    echo "<![CDATA["
#    cat $TEMPFILE.hdd
#    echo \]\]\>
#    echo "</enclosure>"
#    echo ""
#    rm -f $TEMPFILE.hdd
#fi
#rm -f $TEMPFILE
#-----------------------------------------------------------------------
for f in $ROOT_DIR_ENCLOSED_BASE64
do
    if [ -e $f ]
    then
        echo "<enclosure enclosure=\"base64\" file=\"allegati/os32/$f\">"
        echo "<![CDATA["
        uuencode -m $f ciaociaociao | grep -v "^begin-base64.*ciaociaociao"
        echo \]\]\>
        echo "</enclosure>"
        echo ""
    fi
done
#-----------------------------------------------------------------------
for f in $ROOT_DIR_ENCLOSED \
         $SKEL_ENCLOSED \
         $APPLIC_ENCLOSED
do
    echo "<enclosure enclosure=\"literal\" file=\"allegati/os32/$f\">"
    echo "<![CDATA["

    cat $f | expand

    echo \]\]\>
    echo "</enclosure>"
    echo ""
done
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<h2 id=\"os32listing-root\">"
echo "os32: directory principale"
echo "</h2>"
echo ""
for f in $ROOT_DIR
do
    echo "<!--=================================================================-->"
    echo "<h3 id=\"os32listing-$f\">"
    echo "$f"
    g=`basename $f`
    echo "<indexentry><code>$g</code></indexentry>"
    echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
    echo "</h3>"
    echo ""
    echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
    echo ""

    echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
    echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
    echo "<![CDATA["

    cat $f | expand

    echo \]\]\>
    echo "</verbatimpre>"
    echo "</object>"
    echo ""
done
#-----------------------------------------------------------------------
for f in $KERNEL
do
    if   echo "$f" | grep "^kernel/[^/.]*.h$" > "/dev/null"
    then
        #
        # File di intestazione del livello `kernel/'.
        #
        echo "<!--=================================================================-->"
        echo "<h2 id=\"os32listing-$f\">"
        echo "os32: «$f»"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h2>"
        echo ""
        echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
        echo ""
        echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
        echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
        echo "<sectioncontents levels=\"4\">"
        echo ""
    else
        #
        # Diamo per scontato che si tratti della
        # realizzazione di quanto si riferisce al file di intestazione
        # che introduce il capitolo.
        #
        echo "<!--=================================================================-->"
        echo "<h3 id=\"os32listing-$f\">"
        echo "$f"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h3>"
        echo ""
        echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
        echo ""
        echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
        echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
    fi
done
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<!--=================================================================-->"
echo "<h1>"
echo "Sorgenti della libreria generale"
echo "</h1>"
echo ""
echo "&A2COPY;"
echo ""
echo "<chaptercontents levels=\"4\">"
echo ""
#-----------------------------------------------------------------------
LIB_SINGLE=`echo $LIB_SINGLE`
if [ -n "$LIB_SINGLE" ]
then
    echo "<!--=================================================================-->"
    echo "<h2>"
    echo "os32: file isolati della directory «lib/»"
    echo "</h2>"
    echo ""
    for f in $LIB_SINGLE
    do
        echo "<!--=================================================================-->"
        echo "<h3 id=\"os32listing-$f\">"
        echo "$f"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h3>"
        echo ""
        echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
        echo ""
        echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
        echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
    done
fi
#-----------------------------------------------------------------------
for f in $LIB
do
    if   echo "$f" | grep "^lib/[^ .]*.h$" > "/dev/null"
    then
        #
        # Librerie generali.
        #
        echo "<!--=================================================================-->"
        echo "<h2 id=\"os32listing-$f\">"
        echo "os32: «$f»"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h2>"
        echo ""
        echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
        echo ""
        echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
        echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
        echo "<sectioncontents levels=\"4\">"
        echo ""
    else
        #
        # Diamo per scontato che si tratti della
        # realizzazione di quanto si riferisce al file di intestazione
        # che introduce il capitolo.
        #
        echo "<!--=================================================================-->"
        echo "<h3 id=\"os32listing-$f\">"
        echo "$f"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h3>"
        echo ""
        echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
        echo ""
        echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
        echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
    fi
done
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<!--=================================================================-->"
echo "<h1>"
echo "Sorgenti delle applicazioni"
echo "</h1>"
echo ""
echo "&A2COPY;"
echo ""
echo "<chaptercontents levels=\"4\">"
echo ""
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<h2 id=\"os32listing-applic\">"
echo "os32: directory «applic/»"
echo "<indexentry index=\"directory\"><code>applic/</code></indexentry>"
echo "</h2>"
echo ""
for f in $APPLIC
do
    echo "<!--=================================================================-->"
    echo "<h3 id=\"os32listing-$f\">"
    echo "$f"
    g=`basename $f`
    echo "<indexentry><code>$g</code></indexentry>"
    echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
    echo "</h3>"
    echo ""
    echo "<ifref id=\"os32description-$f\"><p>Si veda la sezione <sectionref id=\"os32description-$f\">.</p></ifref>"
    echo ""
    echo "<object sep=\"&STYLE.LISTING.SEP.FILE.CONTENT;\" pos=\"fixed\" split=\"1\">"
    echo "<verbatimpre border=\"&STYLE.PRE.BORDER.FILE.CONTENT;\" width=\"65\" numbering=\"cont/1000\" file=\"allegati/os32/$f\" highlight=\"c\">"
    echo "<![CDATA["

    cat $f | expand

    echo \]\]\>
    echo "</verbatimpre>"
    echo "</object>"
    echo ""
done
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
for f in $PORTED
do
    echo "<enclosure enclosure=\"literal\" file=\"allegati/os32/$f\">"
    echo "<![CDATA["
    cat $f | expand
    echo \]\]\>
    echo "</enclosure>"
    echo ""
done
#-----------------------------------------------------------------------

