JU Bat Blinker Development Docs: do_doc

File: do_doc

#!/bin/bash
# Copyright (C) 2004 by Nathan (Acorn) Pooley
#
# do_doc
#
#@DOC@ script for creating documentation files in html format
#

pgpfx="bl_"

ddir="ju_blinker_docs"

docstr='@DO'"C@"

do_code=1
if [[ $1 = '-nosource' ]] ; then
    do_code=0
fi

_abort() {
    if [[ -n $1 ]] ; then
        echo "$*"
    fi
    echo "Aborting"
    exit 1
}

_verb() {
    echo "do_doc: $*"
}

if [[ ! -d $ddir ]] ; then
    mkdir $ddir
fi
if [[ ! -d $ddir ]] ; then
    _abort "Could not create directory '$ddir'"
fi
if [[ ! -a Docs ]] ; then
    ln -s $ddir Docs
fi

if (( do_code )) ; then
    _verb "deleting old documents"
    for i in $ddir/*
    do
        echo "<html><body><h1>DELETED</h1></body></html>" > $i
    done
fi

_verb "making documents in '$ddir'"

_docname() {
    echo -n "$1" |              \
        sed -e 's|\.|_|g'       \
            -e 's|\.htm$||'     \
            -e 's|\.html$||'    \
            -e 's|$|.html|'     \
            -e "s|^$pgpfx||"    \
            -e "s|^$pgpfx||"    \
            -e "s|^$pgpfx||"    \
            -e "s|^|$pgpfx|"
}

_html_begin() {
    typeset title=""
    typeset title2=""
    if [[ -n $1 ]] ; then
        title="JU Bat Blinker Development Docs: $*"
        title2="<a href=\"blinker_devel.html\">JU Bat Blinker Development Docs:</a> $*"
    else
        title="JU Bat Blinker Development Documentation"
        title2="<a href=\"blinker.html\">$title</a>"
    fi
    echo "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">"
    echo "<html>"
    echo "<head>"
    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
    echo "<meta name=\"Author\" content=\"tohtml by Acorn\">"
    echo "<title>$title</title>"
    echo "</head>"
    echo "<body text=\"#330000\" bgcolor=\"#FFCC00\" link=\"#CC0000\" vlink=\"#660066\" alink=\"#660066\">"

    echo "<h1>$title2</h1>"
}

_html_end() {
    echo "<center>"
    echo "<hr WIDTH=\"100%\"></center>"
    echo "<p>"
    echo "This file Copyright (C) 2004 by Nathan (Acorn) Pooley<br>"
    echo "<a href="blinker_devel.html">Go to Bat Blinker Development page</a><br>"
    echo "<a href="blinker.html">Go to Bat Blinker page</a><br>"
    echo "<a href="index.html">Go to JU Gadgets page</a><br>"
    echo "<a href="http://www.fobik.org/JU">Go to Justice Unlimited homepage</a><br>"
    echo "<a href="http://www.rawbw.com/~acorn">Go to Acorn's personal webpage</a><br>"
    echo "File created by do_doc at `date`"
    echo "</p>"

    echo "</body>"
    echo "</html>"
}

_html_code_begin() {
    typeset title="$1"
    typeset color="$2"

    if [[ -z $color ]] ; then
        color='#FFCCFF'
    fi

    echo "<table CELLSPACING=5 CELLPADDING=0 WIDTH=\"100%\">"
    if [[ -n $title ]] ; then
        echo "<caption>"
        echo "<h1>$title</h1>"
        echo "</caption>"
    fi
    echo "<tr>"
    echo "<td BGCOLOR=\"$color\">"
    echo "<PRE>"
}

_html_code_end() {
    echo "</PRE>"
    echo "</td></tr></table>"
}


_filter_inc() {
    typeset dn=`_docname "$1"`
    _html_begin "$1"
    _html_code_begin "Gadget Sourcecode: $1" "#FFCCFF"
    sed -f source.seds \
        -e "s|<a href=\"$dn\">\([^<]*\)</a>|\1|g"
    _html_code_end
    _html_end
}

_filter_asm() {
    typeset dn=`_docname "$1"`
    _html_begin "$1"
    _html_code_begin "Gadget Sourcecode: $1" "#FFCCFF"
    sed -f source.seds \
        -e "s|<a href=\"$dn\">\([^<]*\)</a>|\1|g"
    _html_code_end
    _html_end
}

_filter_c() {
    typeset dn=`_docname "$1"`
    _html_begin "$1"
    _html_code_begin "Gadget Sourcecode: $1" "#COCOCO"
    sed -f source.seds \
        -e "s|<a href=\"$dn\">\([^<]*\)</a>|\1|g"
    _html_code_end
    _html_end
}

_filter_txt() {
    typeset dn=`_docname "$1"`
    _html_begin "$1"
    _html_code_begin "File: $1" "#33CCFF"
    cat
    _html_code_end
    _html_end
}
#   sed -f source.seds \
#       -e "s|<a href=\"$dn\">\([^<]*\)</a>|\1|g"

_filter_str() {
    typeset dn=`_docname "$1"`
    _html_begin "$1"
    _html_code_begin "File: $1" "#66FF99"
    sed -f source.seds \
        -e "s|<a href=\"$dn\">\([^<]*\)</a>|\1|g"
    _html_code_end
    _html_end
}

_filter_script() {
    typeset dn=`_docname "$1"`
    _html_begin  "$1"
    _html_code_begin "File: $1" "#C0C0C0"
    sed -f source.seds \
        -e "s|<a href=\"$dn\">\([^<]*\)</a>|\1|g"
    _html_code_end
    _html_end
}

#_filter_secret() {
#   typeset dn=`_docname "$1"`
#   _html_begin "$1"
#   _html_code_begin "File: $1" "#FFFFFF"
#   echo "<h2>This file is confidential</h2>"
#   _html_code_end
#   _html_end
#}


#
# build sed script
#

if (( do_code )) ; then

\rm -f source.seds
echo 's|<|\<|g' >> source.seds
echo 's|>|\>|g' >> source.seds

echo 's|\<\([a-zA-Z0-9_]\+\)\.inc\>|<a href="bl_\1_inc.html">&</a>|g' >> source.seds
echo 's|\<\([a-zA-Z0-9_]\+\)\.asm\>|<a href="bl_\1_asm.html">&</a>|g' >> source.seds
echo 's|\<\([a-zA-Z0-9_]\+\)\.txt\>|<a href="bl_\1_txt.html">&</a>|g' >> source.seds
echo 's|\<\([a-zA-Z0-9_]\+\)\.str\>|<a href="bl_\1_str.html">&</a>|g' >> source.seds
echo 's|\<\([a-zA-Z0-9_]\+\)\.stxt\>|<a href="bl_\1_stxt.html">&</a>|g' >> source.seds
echo 's|\<\([a-zA-Z0-9_]\+\)\.sstr\>|<a href="bl_\1_sstr.html">&</a>|g' >> source.seds
echo 's|\<\([a-zA-Z0-9_]\+\)\.c\>|<a href="bl_\1_c.html">&</a>|g' >> source.seds

get_def='^[     ]*#*[   ]*define[   ]\+\([a-zA-Z_][a-zA-Z0-9_]*\)[  ].*'
get_sdf='^define[   ]\+\([a-zA-Z_][a-zA-Z0-9_]*\)[  ].*'
get_equ='^\([a-zA-Z_][a-zA-Z0-9_]*\)[   ]*[Ee][Qq][Uu].*'
get_lab='^\([a-zA-Z_][a-zA-Z0-9_]*\):.*'
get_str='^\(str_[a-zA-Z0-9_]\+\)[   ].*'
get_menu='^MENU[    ]\+\(mode_[a-zA-Z0-9_]\+\)[     ].*'
get_text='^TEXT[    ]\+\(mode_[a-zA-Z0-9_]\+\)[     ].*'
get_entry='^ENTRY[  ]\+\(mode_[a-zA-Z0-9_]\+\)[     ].*'
get_func='^FPTR[    ]\+\([a-zA-Z_][a-zA-Z0-9_]*\)[  ].*'
to_link1='s:\\<\1\\>:<a href="'
to_link2='doctarget_\1">\&</a>:g'

to_link1func='s:\\<func_\1\\>:<a href="'

_filter_tosed() {
    typeset fn="$1"
    typeset dfn=`_docname "$1"`
    sed -n  \
        -e "s|$get_def|$to_link1$dfn#d$to_link2|p" \
        $fn >> source.seds
    sed -n  \
        -e "s|$get_equ|$to_link1$dfn#e$to_link2|p" \
        $fn >> source.seds
    sed -n  \
        -e "s|$get_lab|$to_link1$dfn#l$to_link2|p" \
        $fn >> source.seds
}

_filter_tosed_str() {
    typeset fn="$1"
    typeset dfn=`_docname "$1"`
    sed -n  \
        -e "s|$get_sdf|$to_link1$dfn#sd$to_link2|p" \
            $fn >> source.seds
    sed -n  \
        -e "s|$get_str|$to_link1$dfn#ss$to_link2|p" \
        $fn >> source.seds
    sed -n  \
        -e "s|$get_menu|$to_link1$dfn#sm$to_link2|p" \
        $fn >> source.seds
    sed -n  \
        -e "s|$get_text|$to_link1$dfn#st$to_link2|p" \
        $fn >> source.seds
    sed -n  \
        -e "s|$get_entry|$to_link1$dfn#se$to_link2|p" \
        $fn >> source.seds
    sed -n  \
        -e "s|$get_func|$to_link1func$dfn#l$to_link2|p" \
        $fn >> source.seds
}


echo "s|$get_def|<a name=\"ddoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_equ|<a name=\"edoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_lab|<a name=\"ldoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_sdf|<a name=\"sddoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_str|<a name=\"ssdoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_menu|<a name=\"smdoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_text|<a name=\"stdoctarget_\\1\"></a>&|" >> source.seds
echo "s|$get_entry|<a name=\"sedoctarget_\\1\"></a>&|" >> source.seds

for i in *.asm
do
    _verb "Checking for symbols in '$i'"
    _filter_tosed $i
done

for i in *.inc
do
    _verb "Checking for symbols in '$i'"
    _filter_tosed $i
done

#for i in *.str *.sstr
#do
#   _verb "Checking for symbols in '$i'"
#   _filter_tosed_str $i
#done

#
# turn off links to self (3x in case there are nested instances)
#           1          1 2                 2 3         3                    4      4
dbl_link='^\(<a name="\)\([lde]doctarget_[^"]\+\)\("></a>.*\)<a href="[^"]*#\2">\([^<]*\)</a>'
to_unlink='\1\2\3\4'
echo "s|$dbl_link|$to_unlink|g" >> source.seds
echo "s|$dbl_link|$to_unlink|g" >> source.seds
echo "s|$dbl_link|$to_unlink|g" >> source.seds

opcodes="addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf"
opcodes="$opcodes incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf"
opcodes="$opcodes subfwb subwf subwfb swapf tstfsz xorwf bcf bsf btfsc btfss btg bc bn bnc"
opcodes="$opcodes bnn bnov bnz bov bra bz call clrwdt daw goto nop pop push rcall reset retfie"
opcodes="$opcodes retlw return sleep addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw"
opcodes="$opcodes tblrd tblwt"
opcodes="$opcodes equ org radix end __config include define if else endif ifdef ifndef"
opcodes="$opcodes ADDWF ADDWFC ANDWF CLRF COMF CPFSEQ CPFSGT CPFSLT DECF DECFSZ DCFSNZ INCF"
opcodes="$opcodes INCFSZ INFSNZ IORWF MOVF MOVFF MOVWF MULWF NEGF RLCF RLNCF RRCF RRNCF SETF"
opcodes="$opcodes SUBFWB SUBWF SUBWFB SWAPF TSTFSZ XORWF BCF BSF BTFSC BTFSS BTG BC BN BNC"
opcodes="$opcodes BNN BNOV BNZ BOV BRA BZ CALL CLRWDT DAW GOTO NOP POP PUSH RCALL RESET RETFIE"
opcodes="$opcodes RETLW RETURN SLEEP ADDLW ANDLW IORLW LFSR MOVLB MOVLW MULLW RETLW SUBLW XORLW"
opcodes="$opcodes TBLRD TBLWT"
opcodes="$opcodes EQU ORG RADIX END __CONFIG"

for i in $opcodes
do
    echo "s|^\\([   a-zA-Z0-9_:]*\\)\\(\\<$i\\>\\)|\1<B>\2</B>|g" >> source.seds
done

echo 's|<|\&lt;|g' >> source.seds
echo 's|>|\>|g' >> source.seds


#
# convert files to html
#
for i in *.asm
do
    _verb "Converting '$i'"
    cat "$i" | detab -t4 | _filter_asm $i > $ddir/`_docname $i`
done

for i in *.inc
do
    _verb "Converting '$i'"
    cat "$i" | detab -t4 | _filter_inc $i > $ddir/`_docname $i`
done

for i in *.c
do
    _verb "Converting '$i'"
    cat "$i" | detab -t4 | _filter_c $i > $ddir/`_docname $i`
done

for i in *.txt
do
    _verb "Converting '$i'"
    cat "$i" | detab -t4 | _filter_txt $i > $ddir/`_docname $i`
done

for i in *.str *.sstr
do
    _verb "Converting '$i'"
    cat "$i" | detab -t4 | _filter_str $i > $ddir/`_docname $i`
done

#for i in *.sstr
#do
#   _verb "Converting '$i' (secret)"
#   echo "xxx" | _filter_secret $i > $ddir/`_docname $i`
#done

for i in do_* Makef* gg
do
    _verb "Converting '$i'"
    cat "$i" | detab -t4 | _filter_script $i > $ddir/`_docname $i`
done

fi

#
# create index file
#
_add_file() {
    typeset pfx="$1"
    typeset fn="$2"
    typeset title="$3"
    if [[ -z $title ]] ; then
        title=`grep "$docstr" "$fn" | sed "s|.*$docstr||"`
    fi
    if [[ -z $title ]] ; then
        title="$fn"
    else
        title="$fn : $title"
    fi
    typeset dfn=`_docname "$fn"`
    echo "<li><a href=\"$pfx$dfn\">$title</a><br></li>"
}

_add_file_check() {
    typeset sofar="$1"
    typeset pfx="$2"
    typeset fn="$3"
    typeset title="$4"
    typeset already=0
    typeset dfn=`_docname "$fn"`
    grep "href=\"$pfx$dfn" "$sofar" > /dev/null && already=1
    if (( ! already )) ; then
        _add_file "$2" "$3" "$4"
    fi
}

_add_link() {
    typeset targ="$1"
    typeset title="$2"
    if [[ -z $title ]] ; then
        title="$targ"
    fi
    echo "<li><a href=\"$targ\">$title</a><br></li>"
}

_add_image() {
    typeset targ="$1"
    typeset title="$2"
    if [[ -z $title ]] ; then
        title="$targ"
    fi
    echo "<p><table>"
    echo "<tr><td align=CENTER>$title</td></tr>"
    echo "<tr><td align=CENTER><img src=\"$targ\"></td></tr>"
    echo "</table><br></p>"
}

_make_index() {
    idx="$1"
    pfx="$2"

    _html_begin

    doc_files=""



#   #
#   # STRINGS FILES
#   #
#   echo "<h2>Files Defining all Menus, Screens, and Strings</h2>"
#   echo "<ul>"
#   for i in *.str *.sstr
#   do
#       _add_file "$pfx" "$i"
#   done
#   echo "</ul>"


    #
    # SOURCE
    #
    echo "<h2>Sourcecode for the Bad Blinker</h2>"

    echo "<ul>"
    for i in *.asm
    do
        _add_file "$pfx" "$i"
    done
    for i in *.inc
    do
        _add_file "$pfx" "$i"
    done
    echo "</ul>"

    #
    # OTHER SOURCE
    #
    echo "<h2>Other files used to create the gadget</h2>"
    echo "<ul>"
    _add_file "$pfx" "Makefile"
    _add_file "$pfx" "spinwords.c" "Program for creating swords.inc for the story"
    _add_file "$pfx" "volt.c" "Program for figuring out resistance values"
    _add_file "$pfx" "volt2.c" "Online Program for figuring out resistance values"
    for i in Makef* do_* *.c
    do
        _add_file_check "$idx" "$pfx" "$i"
    done
    echo "</ul>"

    #
    # TEXT FILES
    #
    echo "<h2>Other Text Files</h2>"
    echo "<ul>"
    for i in *.txt
    do
        _add_file_check "$idx" "$pfx" "$i"
    done
    echo "</ul>"

    #
    # TAR
    #
    echo "<h2>Get Sourcecode</h2>"
    echo "<p>"
    echo "Download all files needed to build the Bat Blinker"
    echo "<ul>"
    echo "<li><a href="ju_blinker.tgz">ju_blinker.tgz</a></li>"
    echo "</ul>"
    echo "</p>"

    

    #
    # PARTS COMPANY LINKS
    #
    echo "<h2>Parts Company Links</h2>"
    echo "<ul>"
    _add_link   "http://www.superbrightleds.com" "Bright LED supplier"
    _add_link   "http://www.digikey.com" \
                "Digikey - mail order parts store"
    echo "</ul>"

    _html_end
}

_verb "Creating blinker_devel.html"
_make_index "$ddir/blinker_devel.html" "" > "$ddir/blinker_devel.html"

_verb "Creating docs.html"
_make_index "docs.html" "$ddir/" > "docs.html"




#
# build tar of all non-secret files
#
if [[ -L ju_blinker2 ]] ; then
    \rm ju_blinker2
fi
if [[ -a ju_blinker ]] ; then
    echo "there is already a file called 'ju_blinker'"
    echo "Cannot create tar file"
else
    mkdir ju_blinker
    ( cd ju_blinker ; ln -s .. sw )

    \rm -f file_list
    for i in    ju_blinker/sw/*.txt         \
                ju_blinker/sw/*.asm         \
                ju_blinker/sw/*.inc         \
                ju_blinker/sw/*.str         \
                ju_blinker/sw/Makef*        \
                ju_blinker/sw/do_*          \
                ju_blinker/sw/*.c           \
                ju_blinker/sw/*.Fsti        \
                ju_blinker/sw/*.Psti        \
                ju_blinker/sw/*.mcp         \
                ju_blinker/sw/*.mcw
    do
        if [[ -a $i ]] ; then
            echo "$i" >> file_list
        fi
    done

    tar cz -f $ddir/ju_blinker.tgz --files-from=file_list

    \rm ju_blinker/sw
    rmdir ju_blinker
fi

This file Copyright (C) 2004 by Nathan (Acorn) Pooley
Go to Bat Blinker Development page
Go to Bat Blinker page
Go to JU Gadgets page
Go to Justice Unlimited homepage
Go to Acorn's personal webpage
Contact Acorn
See comments from others
Post your own comments
File created by do_doc at Wed Aug 4 20:17:57 2004