#!/bin/bash

# Mkbbmenu, script for making a menu for the Blackbox Window Manager.
# Copyright (C) 2000  Maxim Heijndijk

# This program 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.

# This program 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Email: cchq@wanadoo.nl"


# Run this script in your home directory

VERSION=0.2
# Set some variables
BBVERSION="0.60.x"
TTYDIALOG=`which dialog`
XDIALOG=`which Xdialog`
[ "$1" = "x" ] && DIALOG="$XDIALOG" || DIALOG="$TTYDIALOG"
MNAME=bbmenu
[ -d "$HOME/Blackbox" ] && BBDIR="$HOME/Blackbox"
[ -d "$HOME/blackbox" ] && BBDIR="$HOME/blackbox" || BBDIR="$HOME/.blackbox"

# Define some functions
function menubox {
    RETVAL=
    choice=
    [ "$DIALOG" = "$TTYDIALOG" ] && SIZE="0 0 0"
    if $DIALOG --menu "$MENU" $SIZE "$@" 2> /tmp/$MNAME.tmp.$$; then
	choice=`cat /tmp/$MNAME.tmp.$$`
	RETVAL=$?
	$MENUCHOICES
	[ -z "$MENUCHOICES" ] && menuchoices
#    rm -f /tmp/$MNAME.tmp.$$ 2> /dev/null
    fi
    rm -f /tmp/$MNAME.tmp.$$ 2> /dev/null
}

function checkbox {
    [ "$DIALOG" = "$TTYDIALOG" ] && SIZE="0 0 0"
    if $DIALOG --checklist "$CHK" $SIZE "$@" 2> /tmp/checklist.tmp.$$; then
	[ "$DIALOG" = "$TTYDIALOG" ] && \
	CHOICES=`cat /tmp/checklist.tmp.$$ | sed -n -e "s/\"//gp"`
	[ "$DIALOG" = "$XDIALOG" ] && \
	CHOICES=`cat /tmp/checklist.tmp.$$`
	clear; $INPUT
    fi
    rm -f /tmp/checklist.tmp.$$ 2> /dev/null
}

function inputbox {
    INPUT=
    RETVAL=
    [ "$DIALOG" = "$TTYDIALOG" ] && SIZE="0 0" || SIZE="10 50"
    if $DIALOG --inputbox "$1" $SIZE 2> /tmp/inputbox.tmp.$$; then
	INPUT=`cat /tmp/inputbox.tmp.$$`
	RETVAL=$?
    fi
    rm -f /tmp/inputbox.tmp.$$ 2> /dev/null
}

function menuchoices {
    case $choice in
	DM) default_menu;;
	GM) graphics;;
	OF) office;;
	MM) multimedia_category;;
	GA) games;;
	NW) networking;;
	PR) printing;;
	DV) development;;
	UT) utilities_category;;
	MT) mountumount;;
	WM) window_managers;;
	KA) kde_applications;;
	GN) gnome_applications;;
	WR) make_bbmenu;;
    esac
}

function main {
    MENU="Select Submenus"
    APPS1=(DM "DEFAULT MENU" \
	   GM "GRAPHICS MANIPULATION" \
	   OF "OFFICE" \
	   MM "MULTIMEDIA")
    [ "$USER" != "root" ] && NOROOT=(GA "GAMES")
    APPS2=(NW "NETWORKING" \
	   PR "PRINTING" \
	   DV "DEVELOPMENT" \
	   UT "UTILITIES" \
	   MT "MOUNT/UNMOUNT" \
	   WM "OTHER WINDOW MANAGERS" \
	   KA "KDE APPLICATIONS" \
	   GN "GNOME APPLICATIONS" \
	   WR "WRITE THE MENU")
    SIZE="25 55 14"
    menubox "${APPS1[@]}" "${NOROOT[@]}" "${APPS2[@]}"
}

function vars_to_tmp {
    for WORD in $CHOICES; do
	echo "$WORD" >> /tmp/mkbbmenu.tmp.$$
#	cat /tmp/mkbbmenu.tmp.$$ | sed "s|$WORD||" > /tmp/mkbbmenu.tmp.$$
    done
}

function default_menu {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    SIZE="25 55 4"
    DEF=("tclinputbox" "Inputbox to run a command" on \
	 "xmen" "X Console menu" on \
	 "xterm" "X-terminal" off \
	 "aterm" "Aterm with solid background" on \
	 "atermtr" "Aterm with transparent background" on \
	 "mc" "Midnight Commander" on \
	 "mc_su" "Midnight Commander su" on \
	 "sfm" "Simple Filemanager" on \
	 "sfm_su" "Simple Filemanager su" on \
	 "fr" "File Runner" on \
	 "fr_su" "File Runner su" on \
	 "toolbox" "Blackbox Style-file editor" on \
	 "DS" "Disable Xscreensaver" on \
         "xkill" "Kill an X application" off)
    SIZE="25 55 13"
    checkbox "${DEF[@]}"
    main
}

function games {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    GAMES=("xpat" "Solitaire" on \
    	   "pysol" "Solitaire" on \
    	   "xhextris" "X Hextris" off \
    	   "gtktetris" "GTK Tetris" on \
    	   "lxdoom" "Doom I" on \
    	   "lxdoom2" "Doom II" on \
    	   "squake" "Quake" on \
    	   "quake2" "Quake II" on)
    SIZE="25 55 7"
    checkbox "${GAMES[@]}"
    [ ! -z "$CHOICES" ] && GA=on
    main
}

function graphics {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    GRAPH=("gimp" "The GIMP" on \
    	   "xv" "X Graphics viewer" on \
    	   "xzgv" "X Graphics viewer" on \
	   "xpcd" "Photo CD vieuwer" on \
    	   "screendump" "Desktop screendump" on \
    	   "windowdump" "Window screendump" on \
    	   "screenview" "View Desktop screendump" on \
    	   "windowview" "View Window screendump" on)
    SIZE="25 55 8"
    checkbox "${GRAPH[@]}"
    [ ! -z "$CHOICES" ] && GM=on
    main
}

function office {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    OFF=("abiword" "Abi wordprocessor" on \
    	 "nedit" "Nirvana text editor" on \
    	 "xesslite" "XessLite spreadsheet" on \
    	 "xpdf" "X PDF viewer" on)
    SIZE="25 55 4"
    checkbox "${OFF[@]}"
    [ ! -z "$CHOICES" ] && OF=on
    main
}

function multimedia_category {
    MENU="Select Multimedia Submenus"
    MENUCHOICES=mm_choices
    MMSUB=(MS "SOUND" \
	   MV "VISION")
    SIZE="25 55 2"
    menubox "${MMSUB[@]}"
    unset MENUCHOICES
    main
#    multimedia_category
}

function mm_choices {
    case $choice in
	MS) multimedia_sound;;
	MV) multimedia_vision;;
    esac
}

function multimedia_sound {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    MMSOUND=("aplayer" "Alsa sound player" off \
    	     "realplay" "Real audio/video player" off \
    	     "xmms" "Xmms audio player" on \
    	     "smix" "Sound mixer" on \
    	     "xmixer" "X Sound Mixer" off \
    	     "mxv" "MiXView sound editor" on \
    	     "xwave" "Xwave sound editor" on \
    	     "slab" "Soundlab (Multitracker)" on)
    SIZE="25 55 8"
    checkbox "${MMSOUND[@]}"
    [ ! -z "$CHOICES" ] && MS=on
    [ ! -z "$CHOICES" ] && MM=on
}

function multimedia_vision {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    MMVISION=("gxanim" "Quicktime-movie player" on \
    	      "mtv" "Mpeg-movie player" on \
    	      "realplay" "Real audio/video player" on)
    SIZE="25 55 3"
    checkbox "${MMVISION[@]}"
    [ ! -z "$CHOICES" ] && MV=on
    [ ! -z "$CHOICES" ] && MM=on
}


function networking {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    NET=("bluefish" "Bluefish HTML editor" off \
    	 "grail" "Grail Internet browser" off \
    	 "licq" "Licq Icq client" off \
    	 "napster" "GTK napster" on \
    	 "ncftp" "Ftp client" off \
    	 "netscape" "Netscape Communicator" on \
    	 "pppstats" "PPP statistics viewing" on \
    	 "xisp" "Dialup tool" on)
    SIZE="25 55 8"
    checkbox "${NET[@]}"
    [ ! -z "$CHOICES" ] && NW=on
    echo $CHOICES | grep -q netscape && netscape_communicator
    main
}

function netscape_communicator {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    NETSCAPE=("NB" "Component-bar" off \
    	      "NG" "Navigator" on \
    	      "NM" "Mail" on \
    	      "NN" "News" on \
    	      "NC" "Composer" on)
    SIZE="25 55 5"
    checkbox "${NETSCAPE[@]}"
    [ ! -z "$CHOICES" ] && NC=on
}

function printing {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    PRT=("gv" "Ghostview" on \
	 "lprm" "Cancel all printjobs" on \
	 "tixlpq" "Printer Queue Tool" on \
	 "xpdq" "Printing UtilitY" on \
	 "printtool" "Red Hat Printtool" off \
	 "CX" "Cancel Printjobs (XW-TOOLS)" on \
	 "bjc6000.sh" "Canon BJC6000 Printer Utility (XW-TOOLS)" on \
	 "xwgui" "XwGui (XW-TOOLS)" on)
    SIZE="25 55 7"
    checkbox "${PRT[@]}"
    [ ! -z "$CHOICES" ] && PR=on
    main
}

function development {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    DEV=("ddd" "ddd" off)
    SIZE="25 55 1"
    checkbox "${DEV[@]}"
    [ ! -z "$CHOICES" ] && DV=on
    main
}

function utilities_category {
    MENU="Select Utilities Submenu"
    MENUCHOICES=ut_choices
    UTSUB=(XU "Standard X Utilities" \
    	   TE "Terminal Emulators" \
	   SU "System Utilities" \
	   AU "Archiving Utilities")
    SIZE="25 55 2"
    menubox "${UTSUB[@]}"
    unset MENUCHOICES
    main
}

function ut_choices {
    case $choice in
	XU) util_x;;
	TE) util_term;;
	SU) util_system;;
	AU) util_archiving;;
    esac
}

function util_x {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    UTILX=("xfontsel" "Font viewer" on \
	   "xcalc" "Calculator" on \
	   "xclock" "Clock" off \
	   "xconsole" "Xconsole output viewer" off \
	   "xclipboard" "Clipboard" on \
	   "xmag" "Magnifier" off \
	   "xrefresh" "Screen refresh program" on \
	   "xvidtune" "Video tool" off \
	   "xman" "Manpage viewer" on \
	   "xditview" "Ditroff-document viewer" off \
	   "xedit" "Text editor" on \
    	   "editres" "Application resource editor" on \
	   "viewres" "Application resource viewer" off \
	   "xload" "System load monitor" off \
	   "xbiff" "Incoming mail notifier" off \
	   "xmh" "Mail handling program" off \
	   "xev" "X-event tester" off \
	   "xeyes" "Eyes that follow mouse pointer" off \
	   "xgc" "X graphics demo" off \
	   "ico" "Paints an animation on root window" off)
    SIZE="25 55 20"
    checkbox "${UTILX[@]}"
    [ ! -z "$CHOICES" ] && UT=on
    [ ! -z "$CHOICES" ] && UX=on
}

function util_term {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    UTILT=("xterm-" "Standard Xterm" off \
	   "rxvt-" "Alternative Xterm" off \
	   "aterm-" "Aterm (solid background)" off \
	   "atermtr-" "Aterm (transparent background)" off \
	   "eterm-" "Eterm (transparent background)" off)
    SIZE="25 55 5"
    checkbox "${UTILT[@]}"
    [ ! -z "$CHOICES" ] && UT=on
    [ ! -z "$CHOICES" ] && UTR=on
}

function util_system {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    UTILS=("top" "Process information" on \
	   "gpstree" "Process information" on \
	   "gmemusage" "Memory usage information" on \
	   "xosview" "System monitor" on \
	   "gkrellm" "System monitor" on \
	   "xproc" "Proc information" on \
	   "xlogmaster" "System and logfile information " on)
    SIZE="25 55 7"
    checkbox "${UTILS[@]}"
    [ ! -z "$CHOICES" ] && UT=on
    [ ! -z "$CHOICES" ] && US=on
}

function util_archiving {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    UTILA=("xrpm" "Graphical RPM tool" on)
    SIZE="25 55 1"
    checkbox "${UTILA[@]}"
    [ ! -z "$CHOICES" ] && UT=on
    [ ! -z "$CHOICES" ] && UA=on
}

function mountumount {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    MNT=("cd" "Mount/Unmount CD-ROM" on \
	 "cdrw" "Mount/Unmount CD-RW" on \
	 "linux_flop" "Mount/Unmount Ext2-Floppy" on \
	 "dos_flop" "Mount/Unmount DOS-Floppy" on \
	 "dos_c" "Mount/Unmount DOS C:\\" on \
	 "dos_d" "Mount/Unmount DOS D:\\" on)
    SIZE="25 55 6"
    checkbox "${MNT[@]}"
    [ ! -z "$CHOICES" ] && MT=on
    main
}

function window_managers {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    WMS=("gnome-session" "The Gnome Desktop" on \
	 "startkde" "The K Desktop Environment" off \
	 "icewm-light" "ICE Window Manager" off\
	 "fvwm" "Fvwm" off \
	 "wmaker" "Window Maker" off \
	 "afterstep" "Afterstep Window Manager" off \
	 "twm" "Tab Window Manager" off \
	 "kwm" "KWM" off \
	 "mwm" "Motif Window Manager" off \
	 "wm2" "Window Manager 2" off)
    SIZE="25 55 10"
    checkbox "${WMS[@]}"
    [ ! -z "$CHOICES" ] && WM=on
    main
}

function kde_applications {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    KDEAPP=("kedit" "Text editor" off \
    	    "kwrite" "Advanced text editor" off \
	    "kpackage" "RPM tool for KDE" off \
	    "kconsole" "Kconsole" off \
	    "kvt" "Kvt terminal" off \
	    "kppp" "Kppp dialup tool" off \
	    "klpq" "Printer queue tool" off \
    	    "xqmixer" "XQ sound mixer" off \
	    "aktion" "Aktion (Quicktime-movie player)" off)
    SIZE="25 55 9"
    checkbox "${KDEAPP[@]}"
    [ ! -z "$CHOICES" ] && KA=on
    main
}

function gnome_applications {
    CHK="Select Applications"
    INPUT=vars_to_tmp
    GNOMEAPP=("gtop" "Process Manager" off \
	      "gmc" "Gnome File Manager" on \
	      "gnapster" "Napster" on \
	      "gftp" "Ftp Client" off \
	      "gfcc" "Firewall configuration tool" off)
    SIZE="25 55 5"
    checkbox "${GNOMEAPP[@]}"
    [ ! -z "$CHOICES" ] && GN=on
    main
}

##############################################################################
#WRITE THE MENU
##############################################################################
function make_bbmenu {
clear
# make the blackbox-user directory if its not there already
[ -d $BBDIR/styles ] || mkdir -p $BBDIR/styles
[ -d $BBDIR/backgrounds ] || mkdir -p $BBDIR/backgrounds

# backup original menu file
if [ ! -f $BBDIR/bbmenu.orig ]; then
    echo -e "Saving your original menu to $BBDIR/bbmenu.orig"
    cp $BBDIR/menu $BBDIR/bbmenu.orig 
    sleep 2
fi

echo -e "# Each menu item consists of 2 or 3 fields:
#
#	[command]  (label)  {data}
#
# where [command] is one of:
#
# [begin] [end] [exec] [exit] [reconfig] [restart] [submenu] [style] [include]
#
# [begin] is used for the top level menu
# [submenu] is used for submenus
# [end] must be used with BOTH [begin] and [submenu] to tell the parser to stop
#   reading from the file.
#
# [exec] (label) {string}
# This will insert an item that runs a program.
#
# [exit] (label)
# This will insert an item that exits the window manager.
#
# [reconfig] (label) {string}
# This will insert an item that tells blackbox to re-read it's configuration
#  files.  {string} is optional, and if supplied, will execute the string with
#  /bin/sh -c before the reconfiguration is performed.  (this is helpful for
#  writing multiple config files and switching between them)
#
# [restart] (label) {string}
# This will insert an item to restart the window manager.  {string} is
# optional, and if omitted, blackbox will restart itself.  If {string} is
# specified, then a different window manager will be started.
#
# [style] (filename)
# This will insert an item to reconfigure blackbox with the new style. This
# change is saved when blackbox exits or restarts.
#
# [include] (filename)
# This will read more menu items from the file \"filename\".  The file cannot
# contain a [begin] or [end], except for the [end] needed for submenus.

[begin] (Blackbox $BBVERSION)\n" > $BBDIR/menu

CHOICES=`cat /tmp/mkbbmenu.tmp.$$`
rm -f /tmp/mkbbmenu.tmp.$$

for WORD in $CHOICES ;do
    case $WORD in
	tclinputbox) echo "  [exec] (Run a command)		{tclinputbox}" >> $BBDIR/menu;;
	xmen)	     echo "  [exec] (Xmen)			{xterm -e conmen x}" >> $BBDIR/menu;;
	xterm) 	     echo "  [exec] (Xterminal)			{xterm}" >> $BBDIR/menu;;
	aterm) 	     echo "  [exec] (Aterm)			{aterm +tr}" >> $BBDIR/menu;;
	atermtr)     echo "  [exec] (Aterm transparent)		{aterm -tr -tint grey}" >> $BBDIR/menu;;
	mc)    	     echo "  [exec] (Midnight Commander)	{xterm -geometry 86x38+0+0 -fn 9x15 -title \"Midnight Commander\" -e mc}" >> $BBDIR/menu;;
	mc_su)       echo "  [exec] (Midnight Commander - su)	{xterm -geometry 86x38+0+0 -fn 9x15 -title \"Midnight Commander (su)\" -e su -c mc}" >> $BBDIR/menu;;
	sfm)   	     echo "  [exec] (Simple Filemanager)	{sfm -geometry 250x350+0+0}" >> $BBDIR/menu;;
	sfm_su)	     echo "  [exec] (Simple Filemanager - su)	{xterm -e su -c sfm}" >> $BBDIR/menu;;
	fr)    	     echo "  [exec] (File Runner)		{fr}" >> $BBDIR/menu;;
	fr_su)       echo "  [exec] (File Runner - su)		{xterm -e su -c fr}" >> $BBDIR/menu;;
	toolbox)     echo "  [exec] (Toolbox)			{toolbox}" >> $BBDIR/menu;;
	DS)    	     echo "  [exec] (Disable Xscreensaver)	{killall xscreensaver}" >> $BBDIR/menu;;
	xkill) 	     echo "  [exec] (Xkill)			{xkill}" >> $BBDIR/menu;;
    esac
done

[ "$GA" = "on" -o "$GM" = "on" -o "$OF" = "on" -o "$MM" = "on" -o \
"$NW" = "on" -o "$PR" = "on" -o "$DV" = "on" -o "$UT" = "on" -o \
"$MT" = "on" -o "$WM" = "on" ] && echo -e "\n[nop]" >> $BBDIR/menu 

if [ "$GM" = "on" ]; then
    echo -e "\n[submenu] (Graphics Manipulation)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    gimp)       echo "  [exec] (The GIMP)	{gimp}" >> $BBDIR/menu;;
	    xv)         echo "  [exec] (Xv)		{xv}" >> $BBDIR/menu;;
	    xzgv)       echo "  [exec] (Xzgv)		{xzgv -g 794x570+0+0}" >> $BBDIR/menu;;
	    xpcd)       echo "  [exec] (Photo-CD Viewer){xpcd}" >> $BBDIR/menu;;
	    screendump) echo "  [exec] (Make Desktop Screendump) {xwd -root -out ~/desktopscreendump.xwd}" >> $BBDIR/menu;;
	    windowdump) echo "  [exec] (Make Window Screendump)  {xwd -out ~/windowscreendump.xwd}" >> $BBDIR/menu;;
	    screenview) echo "  [exec] (View Desktop Screendump) {xwud -scale -geometry 640x480+0+0 -in ~/desktopscreendump.xwd}" >> $BBDIR/menu;;
	    windowview) echo "  [exec] (View Window Screendump)  {xwud -scale -in ~/windowscreendump.xwd}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$GA" = "on" ]; then
    echo -e "\n[submenu] (Games)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    xpat)       echo "  [exec] (XPat)		{xpat}" >> $BBDIR/menu;;
	    pysol)      echo "  [exec] (PySol)		{pysol}" >> $BBDIR/menu;;
	    xhextris)   echo "  [exec] (X Hextris)	{cxhextris}" >> $BBDIR/menu;;
	    gtktetris)  echo "  [exec] (GTK Tetris)	{gtktetris}" >> $BBDIR/menu;;
	    lxdoom)     echo "  [exec] (LX Doom)	{sudo runlxdoom}" >> $BBDIR/menu;;
	    lxdoom2)    echo "  [exec] (LX Doom 2)	{sudo runlxdoom 2}" >> $BBDIR/menu;;
	    squake)     echo "  [exec] (X Quake)	{sudo runxquake}" >> $BBDIR/menu;;
	    quake2)     echo "  [exec] (X Quake 2)	{sudo runxquake 2}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$MM" = "on" ]; then
    echo -e "\n[submenu] (Multimedia)" >> $BBDIR/menu

    if [ "$MS" = "on" ]; then
	echo -e "\n  [submenu] (Sound)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
		xmms)		echo "    [exec] (Xmms Audio Player)	{xmms}" >> $BBDIR/menu;;
		aplayer)	echo "    [exec] (Alsa Audio Player)	{alsaplayer}" >> $BBDIR/menu;;
		realplay)	echo "    [exec] (Real Player 7)	{realplayer7}" >> $BBDIR/menu;;
		smix)		echo "    [exec] (Smixer)		{smix}" >> $BBDIR/menu;;
		xmixer)		echo "    [exec] (Xmixer)		{xmixer}" >> $BBDIR/menu;;
		mxv)		echo "    [exec] (MixView Sound Editor)	{mxv}" >> $BBDIR/menu;;
		xwave)		echo "    [exec] (Xwave Sound Editor)	{xwave}" >> $BBDIR/menu;;
		slab)		echo "    [exec] (Sound Lab Multitracker){slab}" >> $BBDIR/menu;;
	    esac
	done
    echo "  [end]" >> $BBDIR/menu
    fi

    if [ "$MV" = "on" ]; then
	echo -e "\n  [submenu] (Vision)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
		gxanim)	  echo "    [exec] (GXanim Movie Player){gxanim}" >> $BBDIR/menu;;
		mtv)	  echo "    [exec] (Mpeg TV Player)	{mtv}" >> $BBDIR/menu;;
		realplay) echo "    [exec] (Real Player 7)	{realplayer7}" >> $BBDIR/menu;;
    	    esac
	done
	echo "  [end]" >> $BBDIR/menu
    fi
    echo -e "\n[end]" >> $BBDIR/menu
fi

if [ "$NW" = "on" ]; then
    echo -e "\n[submenu] (Networking)" >> $BBDIR/menu
    if [ "$NC" = "on" ]; then
	echo -e "\n  [submenu] (Netscape Communicator)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
		NB)  echo "    [exec] (Component-bar)	{netscape -component-bar}" >> $BBDIR/menu;;
		NG)  echo "    [exec] (Navigator)	{netscape -geometry 794x570+0+0}" >> $BBDIR/menu;;
		NM)  echo "    [exec] (Mail)		{netscape -mail}" >> $BBDIR/menu;;
		NN)  echo "    [exec] (News)		{netscape -news}" >> $BBDIR/menu;;
		NC)  echo "    [exec] (Composer)	{netscape -edit}" >> $BBDIR/menu;;
	    esac
	done
	echo -e "  [end]\n" >> $BBDIR/menu
    fi
    for WORD in $CHOICES ;do
	case $WORD in
	    bluefish) echo "  [exec] (Bluefish HTML editor){bluefish}" >> $BBDIR/menu;;
	    grail)    echo "  [exec] (Grail HTML Browser)  {python /usr/local/lib/grail/grail.py}" >> $BBDIR/menu;;
	    licq)     echo "  [exec] (L-ICQ)		   {licq}" >> $BBDIR/menu;;
	    napster)  echo "  [exec] (GTK napster)	   {napster}" >> $BBDIR/menu;;
	    ncftp)    echo "  [exec] (Ncftp)		   {xterm -e ncftp open}" >> $BBDIR/menu;;
	    pppstats) echo "  [exec] (View Ppp Statistics) {xterm -e sudo /usr/sbin/pppstats -a -w 5}" >> $BBDIR/menu;;
	    xisp)     echo "  [exec] (Xisp)		   {sudo xisp -nohints}" >> $BBDIR/menu;;
	esac
    done
    echo  -e "\n[end]" >> $BBDIR/menu
fi

if [ "$OF" = "on" ]; then
    echo  -e "\n[submenu] (Office)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    abiword)  echo "  [exec] (Abi Wordprocessor)	{AbiWord -geometry 785x570+0+0}" >> $BBDIR/menu;;
	    nedit)    echo "  [exec] (Nirvana Text Editor)	{nedit}" >> $BBDIR/menu;;
	    xesslite) echo "  [exec] (XessLite Spreadsheet)	{xesslite}" >> $BBDIR/menu;;
	    xpdf)     echo "  [exec] (PDF Viewer)		{xpdf}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$PR" = "on" ]; then
    echo -e "\n[submenu] (Printing)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    lprm)       echo "  [exec] (Cancel all printjobs)		{lprm -}" >> $BBDIR/menu;;
	    tixlpq)     echo "  [exec] (TixLPQ Printer Queue Tool)	{tixlpq}" >> $BBDIR/menu;;
	    xpdq)       echo "  [exec] (Xpdq Printing Tool)		{xpdq}" >> $BBDIR/menu;;
	    gv)         echo "  [exec] (Ghostview)			{gv}" >> $BBDIR/menu;;
	    printtool)  echo "  [exec] (Red Hat Printtool)		{xterm -e printtool}" >> $BBDIR/menu;;
	    CX)         echo "  [exec] (Cancel Xw printjobs \(XW-TOOLS\))		{xw_snd -h localhost -s /var/spool/xw_tools -C}" >> $BBDIR/menu;;
	    bjc6000.sh) echo "  [exec] (Canon BJC6000 Printer Utility \(XW-TOOLS\))	{bj6000.sh}" >> $BBDIR/menu;;
	    xwgui)      echo "  [exec] (XwGui \(XW-TOOLS\))				{xwgui}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$DV" = "on" ]; then
    echo -e "\n[submenu] (Development)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    ddd) echo "  [exec] (DDD)	{ddd}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$UT" = "on" ]; then
    echo -e "\n[submenu] (Utilities)" >> $BBDIR/menu

    if [ "$UX" = "on" ]; then
	echo -e "\n  [submenu] (Standard X)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
	    xfontsel)   echo "    [exec] (Font viewer) {xfontsel}" >> $BBDIR/menu;;
	    xcalc)      echo "    [exec] (Calculator) {xcalc -geometry 260x390+0+0}" >> $BBDIR/menu;;
	    xclock)     echo "    [exec] (Clock) {xclock}" >> $BBDIR/menu;;
	    xconsole)   echo "    [exec] (Xconsole) {xconsole /dev/console}" >> $BBDIR/menu;;
	    xclipboard) echo "    [exec] (Clipboard) {xclipboard}" >> $BBDIR/menu;;
	    xmag)       echo "    [exec] (Magnifier) {xmag}" >> $BBDIR/menu;;
	    xrefresh)   echo "    [exec] (Screen refresh) {xrefresh}" >> $BBDIR/menu;;
	    xvidtune)   echo "    [exec] (Video tool) {xvidtune}" >> $BBDIR/menu;;
	    xman)       echo "    [exec] (Manpage viewer) {xman}" >> $BBDIR/menu;;
	    xditview)   echo "    [exec] (Ditroff-document viewer) {xditview -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    xedit)      echo "    [exec] (Text editor) {xedit -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    editres)    echo "    [exec] (Resource editor) {editres -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    viewres)    echo "    [exec] (Resource viewer) {viewres -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    xload)      echo "    [exec] (System load monitor) {xload}" >> $BBDIR/menu;;
	    xbiff)      echo "    [exec] (Incoming mail) {xbiff -geometry 110x80+0+0}" >> $BBDIR/menu;;
	    xmh)        echo "    [exec] (Mail) {xmh -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    xev)        echo "    [exec] (X-event viewer) {xev -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    xeyes)      echo "    [exec] (Xeyes) {xeyes}" >> $BBDIR/menu;;
	    xgc)        echo "    [exec] (X graphics demo) {xgc -geometry 480x480+0+0}" >> $BBDIR/menu;;
	    ico)        echo "    [exec] (Ico) {ico -r}" >> $BBDIR/menu;;
	    esac
	done
    echo "  [end]" >> $BBDIR/menu
    fi

    if [ "$UTR" = "on" ]; then
	echo -e "\n  [submenu] (X Terminals)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
	    xterm-)   echo "    [exec] (Xterm) {xterm -ls}" >> $BBDIR/menu;;
	    rxvt-)    echo "    [exec] (Rxvt) {rxvt -ls}" >> $BBDIR/menu;;
	    aterm-)   echo "    [exec] (Aterm /(solid background/) {aterm -ls +tr}" >> $BBDIR/menu;;
	    atermtr-) echo "    [exec] (Aterm /(transparent background/) {aterm -ls -tr -tint grey}" >> $BBDIR/menu;;
	    eterm-)   echo "    [exec] (Eterm /(transparent background/)) {eterm -ls}" >> $BBDIR/menu;;
	    esac
	done
    echo "  [end]" >> $BBDIR/menu
    fi

    if [ "$US" = "on" ]; then
	echo -e "\n  [submenu] (System)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
	    top)       echo "    [exec] (Top)		{xterm -geometry 86x38+0+0 -fn 9x15 -e top}" >> $BBDIR/menu;;
	    gpstree)   echo "    [exec] (Gpstree)	{gpstree}" >> $BBDIR/menu;;
	    gmemusage) echo "    [exec] (Gmemusage)	{gmemusage}" >> $BBDIR/menu;;
	    xosview)   echo "    [exec] (Xosview)	{xosview}" >> $BBDIR/menu;;
	    gkrellm)   echo "    [exec] (GKrellM)	{gkrellm}" >> $BBDIR/menu;;
	    xproc)     echo "    [exec] (Xproc)		{xproc}" >> $BBDIR/menu;;
	    xlogmaster) if [ "$USER" = "root" ]; then
			    echo "    [exec] (Xlogmaster)	{xlogmaster -geometry 794x570+0+0 -terse}" >> $BBDIR/menu
			else
			    echo "    [exec] (Xlogmaster)	{xterm -e su -c \"xlogmaster -geometry 794x570+0+0 -terse\"}" >> $BBDIR/menu
			fi;;
	    esac
	done
    echo "  [end]" >> $BBDIR/menu
    fi

    if [ "$UA" = "on" ]; then
	echo -e "\n  [submenu] (Archiving)" >> $BBDIR/menu
	for WORD in $CHOICES ;do
	    case $WORD in
	    xrpm)     echo "    [exec] (Xrpm)	{xterm -e su -c xrpm}" >> $BBDIR/menu;;
	    esac
	done
    echo "  [end]" >> $BBDIR/menu
    fi
    echo -e "\n[end]" >> $BBDIR/menu
fi

if [ "$MT" = "on" ]; then
    echo -e "\n[submenu] (Mount / Unmount)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    cd)         echo "  [exec] (CD-ROM)		{cmm cd}" >> $BBDIR/menu;;
	    cdrw)       echo "  [exec] (CD-RW)		{cmm cdr}" >> $BBDIR/menu;;
	    linux_flop) echo "  [exec] (Ext2-Floppy)	{cmm e2f}" >> $BBDIR/menu;;
	    dos_flop)   echo "  [exec] (DOS-Floppy)	{cmm df}" >> $BBDIR/menu;;
	    dos_c)      echo "  [exec] (DOS C)		{cmm dosc}" >> $BBDIR/menu;;
	    dos_d)      echo "  [exec] (DOS D)		{cmm dosd}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$WM" = "on" ]; then
    echo -e "\n[submenu] (Other Window Managers)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    gnome-session) echo "  [exec]    (Gnome)		{gnome-session}" >> $BBDIR/menu;;
            startkde)      echo "  [restart] (KDE)		{startkde}" >> $BBDIR/menu;;
            icewm-light)   echo "  [restart] (Start IceWM-light){icewm-light}" >> $BBDIR/menu;;
            fvwm)          echo "  [restart] (Start FVWM)       {fvwm}" >> $BBDIR/menu;;
            wmaker)        echo "  [restart] (Start WindowMaker){wmaker}" >> $BBDIR/menu;;
            afterstep)     echo "  [restart] (Start Afterstep)  {afterstep}" >> $BBDIR/menu;;
            twm)           echo "  [restart] (Start TWM)        {twm}" >> $BBDIR/menu;;
            kwm)           echo "  [restart] (Start KWM)        {kwm}" >> $BBDIR/menu;;
            mwm)           echo "  [restart] (Start MWM)        {mwm}" >> $BBDIR/menu;;
            wm2)           echo "  [restart] (Start WM2)        {wm2}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

[ "$KA" = "on" -o "$GN" = "on" ] && echo -e "\n[nop]" >> $BBDIR/menu

if [ "$KA" = "on" ]; then
    echo -e "\n[submenu] (KDE Applications)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    kedit)    echo "  [exec] (Kedit)		{kedit}" >> $BBDIR/menu;;
	    kwrite)   echo "  [exec] (Kwrite)		{kwrite}" >> $BBDIR/menu;;
	    kconsole) echo "  [exec] (Kconsole)		{konsole}" >> $BBDIR/menu;;
	    kvt)      echo "  [exec] (Kvt)		{kvt}" >> $BBDIR/menu;;
	    kpackage) echo "  [exec] (Kpackage)		{xterm -e su -c kpackage}" >> $BBDIR/menu;;
	    klpq)     echo "  [exec] (Printer Queue)	{klpq -caption \"%c\" %u}" >> $BBDIR/menu;;
	    kppp)     echo "  [exec] (Kppp Dialup Tool) {kppp}" >> $BBDIR/menu;;
	    xqmixer)  echo "  [exec] (Xqmixer)		{xqmixer}" >> $BBDIR/menu;;
	    aktion)   echo "  [exec] (Aktion)		{aktion}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

if [ "$GN" = "on" ]; then
    echo -e "\n[submenu] (Gnome Applications)" >> $BBDIR/menu
    for WORD in $CHOICES ;do
	case $WORD in
	    gtop)     echo "  [exec] (Gtop Process Manager)	{gtop}" >> $BBDIR/menu;;
	    gmc)      echo "  [exec] (Gnome File Manager)	{gmc}" >> $BBDIR/menu;;
	    gnapster) echo "  [exec] (Napster)			{gnapster}" >> $BBDIR/menu;;
	    gftp)     echo "  [exec] (FTP Client)		{gftp}" >> $BBDIR/menu;;
	    gfcc)     echo "  [exec] (Firewall Configuration)	{gfcc}" >> $BBDIR/menu;;
	esac
    done
    echo "[end]" >> $BBDIR/menu
fi

echo -e "\n[nop]" >> $BBDIR/menu

echo -e "\n[submenu] (Styles) {Choose a style...}" >> $BBDIR/menu
if [ -d /usr/local/share/Blackbox/styles ]; then
    echo -e "  [stylesdir] (/usr/local/share/Blackbox/styles)" >> $BBDIR/menu
fi
if [ -d /usr/local/share/blackbox/styles ]; then
    echo -e "  [stylesdir] (/usr/local/share/blackbox/styles)" >> $BBDIR/menu
fi
if [ -d /usr/share/Blackbox/styles ]; then
  echo -e "  [stylesdir] (/usr/share/Blackbox/styles)" >> $BBDIR/menu
fi
if [ -d /usr/share/blackbox/styles ]; then
  echo -e "  [stylesdir] (/usr/share/blackbox/styles)" >> $BBDIR/menu
fi
if [ -d $BBDIR/styles ]; then
  echo -e "  [stylesdir] ($BBDIR/styles)" >> $BBDIR/menu
fi
echo -e "[end]
  [workspaces] (Workspace List)
  [config] (Configuration)
  \n[nop]\n
  [reconfig] (Reconfigure)
  [restart] (Restart)
  [exit] (Exit)
[end]" >> $BBDIR/menu

}

main

exit 0
