#!/bin/sh


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


#-----------------------------------------------------------------------
ROOT_DIR="bochs qemu makeit"
ROOT_DIR_ENCLOSED="mount umount fsck listings indent COPYRIGHT WARRANTY"
#-----------------------------------------------------------------------
SKEL_ENCLOSED=""
for f in `find skel -print | LC_ALL=C sort`
do
    if [ -f "$f" ]
    then
        SKEL_ENCLOSED="$SKEL_ENCLOSED $f"
    fi
done
#-----------------------------------------------------------------------
PORTED_ENCLOSED=""
for f in `find ported -print | LC_ALL=C sort`
do
    if [ -f "$f" ]
    then
        PORTED_ENCLOSED="$PORTED_ENCLOSED $f"
    fi
done
#-----------------------------------------------------------------------
#INCLUDE=""
#for f in `find include -print | sort`
#do
#    if   echo $f | grep "\.h$"  2>&1 > /dev/null
#    then
#        INCLUDE="$INCLUDE $f"
#    elif echo $f | grep "\.s$"  2>&1 > /dev/null
#    then
#        INCLUDE="$INCLUDE $f"
#    elif echo $f | grep "\.c$"  2>&1 > /dev/null
#    then
#        INCLUDE="$INCLUDE $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_BCC=""
LIB_SINGLE=""
for f in `find lib -print | LC_ALL=C sort`
do
    if   echo $f | grep "lib/bcc/"      2>&1 > /dev/null
    then
        if   echo $f | grep "\.h$"      2>&1 > /dev/null
        then
            LIB_BCC="$LIB_BCC $f"
        elif echo $f | grep "\.s$"      2>&1 > /dev/null
        then
            LIB_BCC="$LIB_BCC $f"
        elif echo $f | grep "\.c$"      2>&1 > /dev/null
        then
            LIB_BCC="$LIB_BCC $f"
        fi
    elif 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=""
for f in `find applic -print | LC_ALL=C sort`
do
    if   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
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<!--=================================================================-->"
echo "<h1>"
echo "Script e sorgenti del kernel"
echo "</h1>"
echo ""
echo "&A2COPY;"
echo ""
echo "<chaptercontents levels=\"4\">"
echo ""
#
TEMPORARY=`tempfile`
uuencode -m floppy.a floppy.a | grep -F -v "begin-base64 644" > $TEMPFILE.a
uuencode -m floppy.b floppy.b | grep -F -v "begin-base64 644" > $TEMPFILE.b
#
echo "<enclosure enclosure=\"base64\" file=\"allegati/os16/floppy.a\">"
echo "<![CDATA["

cat $TEMPFILE.a

echo \]\]\>
echo "</enclosure>"
echo ""
#
echo "<enclosure enclosure=\"base64\" file=\"allegati/os16/floppy.b\">"
echo "<![CDATA["

cat $TEMPFILE.b

echo \]\]\>
echo "</enclosure>"
echo ""

rm -f $TEMPFILE.a
rm -f $TEMPFILE.b
rm -f $TEMPFILE

#-----------------------------------------------------------------------
for f in $ROOT_DIR_ENCLOSED \
         $SKEL_ENCLOSED $PORTED_ENCLOSED
do
    echo "<enclosure enclosure=\"literal\" file=\"allegati/os16/$f\">"
    echo "<![CDATA["

    cat $f | expand

    echo \]\]\>
    echo "</enclosure>"
    echo ""
done
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<h2 id=\"os16listing-root\">"
echo "os16: directory principale"
echo "</h2>"
echo ""
#echo "&A2COPY;"
#echo ""
#echo "<chaptercontents levels=\"4\">"
#echo ""
for f in $ROOT_DIR
do
    echo "<!--=================================================================-->"
    echo "<h3 id=\"os16listing-$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=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
    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=\"os16listing-$f\">"
        echo "os16: «$f»"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h2>"
        echo ""
#        echo "&A2COPY;"
#        echo ""
        echo "<ifref id=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
#        echo "<chaptercontents 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=\"os16listing-$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=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
    fi
done
#-----------------------------------------------------------------------
#echo "&ALTRAILERTOMO;"
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
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 "os16: file isolati della directory «lib/»"
    echo "</h2>"
    echo ""
#    echo "&A2COPY;"
#    echo ""
#    echo "<chaptercontents levels=\"4\">"
#    echo ""
    for f in $LIB_SINGLE
    do
        echo "<!--=================================================================-->"
        echo "<h3 id=\"os16listing-$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=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
        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=\"os16listing-$f\">"
        echo "os16: «$f»"
        g=`basename $f`
        echo "<indexentry><code>$g</code></indexentry>"
        echo "<indexentry index=\"code\"><code>$g</code></indexentry>"
        echo "</h2>"
        echo ""
#        echo "&A2COPY;"
#        echo ""
        echo "<ifref id=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
#        echo "<chaptercontents 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=\"os16listing-$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=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
        echo "<![CDATA["

        cat $f | expand

        echo \]\]\>
        echo "</verbatimpre>"
        echo "</object>"
        echo ""
    fi
done
#-----------------------------------------------------------------------
for f in $LIB_BCC
do
    echo "<enclosure enclosure=\"literal\" file=\"allegati/os16/$f\">"
    echo "<![CDATA["

    cat $f | expand

    echo \]\]\>
    echo "</enclosure>"
    echo ""
done
#-----------------------------------------------------------------------
#echo "&ALTRAILERTOMO;"
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<!--=================================================================-->"
echo "<h1>"
echo "Sorgenti delle applicazioni"
echo "</h1>"
echo ""
echo "&A2COPY;"
echo ""
echo "<chaptercontents levels=\"4\">"
echo ""
#-----------------------------------------------------------------------
echo "<!--=================================================================-->"
echo "<h2 id=\"os16listing-applic\">"
echo "os16: directory «applic/»"
echo "<indexentry index=\"directory\"><code>applic/</code></indexentry>"
echo "</h2>"
echo ""
#echo "&A2COPY;"
#echo ""
#echo "<chaptercontents levels=\"4\">"
#echo ""
for f in $APPLIC
do
    echo "<!--=================================================================-->"
    echo "<h3 id=\"os16listing-$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=\"os16description-$f\"><p>Si veda la sezione <sectionref id=\"os16description-$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=\"78\" numbering=\"cont/1000\" file=\"allegati/os16/$f\">"
    echo "<![CDATA["

    cat $f | expand

    echo \]\]\>
    echo "</verbatimpre>"
    echo "</object>"
    echo ""
done
#-----------------------------------------------------------------------
#echo "&ALTRAILERTOMO;"
#-----------------------------------------------------------------------
