face=" FACE=ARIAL "
echo "Starting Dirslide"
#==========================================================
# This is an all file directories
# produce page for files in a directory
# all files are in the same HTML page
# separated by an <HR>
#==========================================================

rootdir=$HOME/SLIDE
homeptr="index.html"
[ "$1" != "" ] && homeptr=$1
homedir=`dirname $homeptr`

pwd=`pwd`
currentdir=`basename $pwd`
src=".sliderc";
envfile="env.o";

export homedir
export rootdir


#-------------------------------------------------------------------
# Get .sliderc from . upward to $HOME and append to .env
#-------------------------------------------------------------------

rfind=`rfind $src`
[ "$rfind" != "" ] && cat $rfind > $envfile
[ -f .env ] && cat .env >> $envfile

#-----------------------------------------------
# Process things in env.o
# take care environmental instructions:
# .caption SecCaption
# .topframesz TopFrameSize
# .capsize Capsize
# .bgimg bgimg
# .preimg preimg
# .postimg postimg
#-----------------------------------------------


topframesz=`grep "^.topframesz" $envfile | sed "s/^\.topframesz //"`
echo topframesz $topframesz
[ "$topframesz" != "" ] && TopFrameSz="$topframesz" || TopFrameSz='15%'

capsize=`grep "\.capsize" $envfile | sed "s/.*\.capsize //"`
[ "$capsize" != "" ] && Capsize="$capsize" || Capsize='6'

caption=`grep "\.caption" $envfile | sed "s/.*\.caption //"`
[ "$caption" != "" ] && SecCaption="$caption" || SecCaption=$currentdir

SecCap=`echo $SecCaption |sed 's/ /<BR>/g'`

bgimg=$homedir/GIF/bg43.jpg
postimg=$homedir/GIF/darrw.gif
preimg=$homedir/GIF/uarrw.gif

#-------------------------------------------
# Set up file names
#-------------------------------------------

Section=Section.htm
SideIdx=SideIdx.htm
arrowfile=arrowfrm.htm
titlefile=titlefrm.htm

#---------------------------------------------
# Generate load function file load.o
#---------------------------------------------
echo '
<SCRIPT LANGUAGE="JAVASCRIPT">
function load(index) {
parent.leftframe.nextframe.load_specified_section(index);
}
</SCRIPT>
' > load.o

#---------------------------------------------
# Generate load function file load2.o
#---------------------------------------------
sed -e "s/.leftframe//" -e "s/load(/load2(/" load.o > load2.o

#---------------------------------------------
# Generate Root Frames
#---------------------------------------------
echo "
<HTML>
<title>TEST</title>
<frameset cols=\"90%,*\" frameborder=no border=0>
<frame src=\"leftframe.htm\" name=leftframe frameborder=0>
<frame src=\"SideIdx.htm\" name=sideidxframe frameborder=0>
</frameset>
</HTML>
" > index.html

#---------------------------------------------
# Generate LeftFrame
#---------------------------------------------
echo "
<Html>
<Frameset Rows=\"15%,*\" Frameborder=no>
<Frameset Cols=\"92%,*\" >
<Frame Src=$homeptr Name=titleframe Scrolling=no frameborder=0>
<Frame Src=$arrowfile Name=nextframe Scrolling=no frameborder=0>
</Frameset>
<Frame Src=Section.htm Name=bodyframe>
</Frameset>
</Html>
" > leftframe.htm

#---------------------------------------------
# Generate Header (Title and Caption) for Section Page
#---------------------------------------------

echo "<HTML>
<title>$currentdir</title>
<body background=$bgimg bgcolor=#ffffcc TEXT=black LINK=blue VLINK=blue>
<Center>
<table border=4 bgcolor=lightblue>
<TH align=left> <font color=black size=7 $face>
$SecCaption
</Table>
</center>
<HR><H2>
" > $Section
cat load2.o >> $Section


#---------------------------------------------
# Generate Header for Side Index (SideIdx)
#---------------------------------------------
echo "<HTML>
<title>$currentdir</title>
<body bgcolor=#99cccc TEXT=#ffff00 VLINK=#ffff00 LINK=#00ffff>
<H4>
" > $SideIdx

cat load.o >> $SideIdx

#---------------------------------------------
# The header (Home,Section) of SideIdx.htm
#---------------------------------------------
echo "
<TABLE BOARDER=2 BGColor=#ffcccc>
<TR><TH><a href=$homeptr target="_parent">
<font size=3 color=black $face>Home</a>
<TR><TH><a href=leftframe.htm target=leftframe>
<font size=2 color=black $face>Section<a>
</table>
<TABLE BOARDER=0 BGColor=#ffffcc>
" >> $SideIdx

#-----------------------------------------
# Generate Header for arrowfrm.htm
#-----------------------------------------

echo '
<body bgcolor=#ffffcc TEXT=black LINK=blue VLINK=blue onload="javascript:initial()">

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var curr = 0;
var maintopic = "Wireless<BR>Internet"; //­È¥Ñ convertor assign
section = new Array();

//My data structure
function arrayValue(subtopic, filename) {
this.subtopic = subtopic;
this.filename = filename;
}

//initial setting when loading
function initial() { //­È¥Ñ convertor assign
' > $arrowfile

#=============================================
# Parse File names from .order or 'ls'
# Get Page Captions (Long and Abbr)
#=============================================

ls=`ls`
[ -f .order ] && ls=`grep -v "^#" .order`

#-----------------------------------------
# make up file of Page Captions (Long and Abbr)
#-----------------------------------------


> pageabbr
> pagecapt
for i in $ls
do
head -3 $i |egrep '^0 |^0t '|sed -e 's/0t* *//'>>pageabbr
head -3 $i |egrep '^0 |^00 '|sed -e 's/00* *//'>>pagecapt
done


#=============================================
# Make up all links arrowfile Section SideIdx
#=============================================

count=1
for i in $ls
do
curr=`expr $count - 1`
bodyfile=$i.htm
pageabbr=`gl $count $count pageabbr`
pagecapt=`gl $count $count pagecapt`

link="<A href=\"javascript:load($curr)\">"
link2="<A href=\"javascript:load2($curr)\">"

#-----------------------------------------
# arrowfile initial()
#-----------------------------------------

echo "section[$curr] = new arrayValue(\"$pageabbr\",\"$i.htm\");" >> $arrowfile
#-----------------------------------------
# Section (Page Captions)
#-----------------------------------------

echo $pagecapt | sed -e "s/..*/ <table border=3 bgcolor=#ffcccc><TH align=left> <font color=black size=6 $face> $link2 &<\\/a><\\/Table> /" >> $Section

#-----------------------------------------
# SideIdx
#-----------------------------------------

echo "<TR><TD> $link <font size=2 color=black $face ><B>$pageabbr</B></a> " >> $SideIdx

#-----------------------------------------
# bodyframe
#-----------------------------------------

chmod a+rx $bodyfile
htxp.pl $i | sed '/^0/d'|s2html.pl|sed -e "s/<H3/<H4/g" -e "s/H2/H3/g" -e "s/<H1/<H2/g" > $bodyfile
(echo "; $i.htm, ";date;echo "</h6>") >> $bodyfile

count=`expr $count + 1`
done


#=========================================
# End
#=========================================


echo "</TABLE>" >> $SideIdx
echo "curr=$curr;" >> $arrowfile
echo '
}

function load_specified_section(index) {
if(index > section.length-1)
curr = section.length-1;
else if(index < 0)
curr = 0;
else
curr = index;

load_page();
}

function prev() {
curr = (curr == 0)? (section.length - 1) : (curr-1);

load_page();
}

function next() {
curr = (curr == section.length-1)? 0 : (curr+1);

load_page();
}

function load_page() {
//load title
parent.titleframe.document.open();
parent.titleframe.document.write("<body bgcolor=#000066 TEXT=black>");
parent.titleframe.document.write("<table align=center border=0 bgcolor=#006699>");
parent.titleframe.document.write("<TH align=top bgcolor=orange>");
parent.titleframe.document.write("<font color=darkblue size=3 FACE=ARIAL >");
parent.titleframe.document.write(maintopic);
parent.titleframe.document.write("<TH align=top bgcolor=Black>");
parent.titleframe.document.write("<font color=Yellow size=6 FACE=ARIAL >");
parent.titleframe.document.write(section[curr].subtopic);
parent.titleframe.document.write("</Table>");
parent.titleframe.document.close();

//load body
parent.bodyframe.location.href = section[curr].filename;
}
//-->
</SCRIPT>

<DIV Style="
position: absolute;
top:2;
left:5;
">
<Table BGColor=darked Align=left>
<Tr><Td><font size=5 FACE=ARIAL>
<A Href="javascript:next()">
<IMG SRC='$postimg' height=20 ALT=N>
<Tr><Td><font size=5 FACE=ARIAL>
<A Href="javascript:prev()">
<IMG SRC='$preimg' height=20 ALT=P>
</A></Td></Tr></Table>
</DIV>
' >> $arrowfile

rm pagecapt pageabbr
rm load.o load2.o
chmod a+rx $SideIdx $Section index.html
chmod a+rx *.htm