#!/bin/sh
#	je - JE menu
#	Copyright (C) 1994
#		Takashi MANABE (manabe@Roy.dsl.tutics.tut.ac.jp)
#
#	jmenu is free software; you can redistribute it and/or modify it
#	under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2 of the License, or
#	(at your option) any later version.
#
#	jmenu is distributed in the hope that it will be useful, but
#	WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#	See the GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

DOCDIR=/usr/doc
if [ "$TERM" = "kterm" ]; then
 TERM=xterm
 KEYHELP="+/- ǥ˥塼򤷤Ʋ"
else
 KEYHELP="/ǥ˥塼򤷤Ʋ"
fi
#####################################################
# ǥ쥯ȥΰؿ
#####################################################
MakeCurrentList()
{
 dialog\
	--title "`pwd`"\
	--infobox "Ƥޤ"\
	3 40
 echo > /tmp/script
 echo dialog \
	--title "`pwd`" \
	--menu \"ɽե򤷤Ʋ\"\
	14 76 7 \\ >> /tmp/script
 for name in `ls -a` ; do
  if [ ! "$name" = "." ]; then
   if [ "$name" = ".." -a "`pwd`" = "$DOCDIR" ]; then
    continue
   fi
   if `test -d $name`; then
    echo " \"$name/\" \"\" \\" >> /tmp/script
   else
    echo " \"$name\" \"\" \\" >> /tmp/script
   fi
  fi
 done
 echo "2> /tmp/reply" >> /tmp/script
 chmod 766 /tmp/script
}
#####################################################
# եɽ
#####################################################
ViewFile()
{
 if [ "`basename $1 .gz`" = "`basename $1`" ]; then
  viewer=less
 else
  viewer=zless
 fi
 reset
 $viewer $1
#dialog\
#	--title "$1"\
#	--textbox "$1" \
#	22 76 2> /dev/null
}

while [ 0 ];do
 dialog\
	--title "J E  M e n u" \
	--menu	"\nLinux+JE ؤ褦\n"\
	14 70 5 \
	"README" "ɬɤ߲" \
	"Info" "Linux " \
	"Meta" "META FAQ  (JMETA-FAQ)" \
	"JE-HOWTO" "JE(Japanese Extensions)-HOWTO" \
	"Dir" "ɥȥǥ쥯ȥ" 2> /tmp/reply
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  reset
  exit
 fi
 REPLY="`cat /tmp/reply`"
 rm -f /tmp/reply
 if [ "$REPLY" = "Exit" ]; then
  reset
  exit
 fi
#####################################################
# ɬɤ߲
#####################################################
 if [ "$REPLY" = "README" ]; then
  ViewFile $DOCDIR/00READMES/README.JE.gz
 fi
#####################################################
# ɤ
#####################################################
 if [ "$REPLY" = "Info" ]; then
  ViewFile $DOCDIR/jfaq/howto/Jouhou-memo.gz
 fi
#####################################################
# ܸ Meta-FAQ ɤ
#####################################################
 if [ "$REPLY" = "Meta" ]; then
  ViewFile $DOCDIR/jfaq/faq/JMETA-FAQ.gz
 fi
#####################################################
# JE-HOWTO ɤ
#####################################################
 if [ "$REPLY" = "JE-HOWTO" ]; then
  ViewFile $DOCDIR/jfaq/howto/JE-HOWTO.gz
 fi
#####################################################
# ɥȥǥ쥯ȥ
#####################################################
 if [ "$REPLY" = "Dir" ]; then
  cd $DOCDIR
  MakeCurrentList
  while [ 0 ]; do
   /tmp/script
   REPLY="`cat /tmp/reply`"
   if [ ! "$REPLY" = "" ]; then
    if `test -d $REPLY`; then
     cd $REPLY
     MakeCurrentList
    else
     ViewFile $REPLY
    fi
    else
     break
    fi
  done
  rm -f /tmp/reply /tmp/script
  continue
 fi  
done
