#!/bin/bash
prog_name=Xless
help_file_name=xless.hlp
about()
{
	echo "  This is the $prog_name an example script for the `xstep-shell -v` package ">$HOME/$help_file_name
	echo "  based on the XSTEP 3.5.1 - Toolkit for X Window System - ">>$HOME/$help_file_name
	echo "  Copyright (C) 1996-2000 by Marcelo Samsoniuk">>$HOME/$help_file_name
	echo " ">>$HOME/$help_file_name
	echo "  This program is free software; you can redistribute it and/or modify">>$HOME/$help_file_name
	echo "  it under the terms of the GNU General Public License as published by">>$HOME/$help_file_name
	echo "  the Free Software Foundation; either version 2 of the License, or">>$HOME/$help_file_name
	echo "  (at your option) any later version.">>$HOME/$help_file_name
	echo "  ">>$HOME/$help_file_name
	echo "  This program is distributed in the hope that it will be useful,">>$HOME/$help_file_name
	echo "  but WITHOUT ANY WARRANTY; without even the implied warranty of">>$HOME/$help_file_name
	echo "  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the">>$HOME/$help_file_name
	echo "  GNU General Public License for more details.">>$HOME/$help_file_name
	echo "  ">>$HOME/$help_file_name
	echo "  You should have received a copy of the GNU General Public License">>$HOME/$help_file_name
	echo "  along with this program; if not, write to the Free Software">>$HOME/$help_file_name
	echo "  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA">>$HOME/$help_file_name
	echo " ">>$HOME/$help_file_name
	echo "  `xstep-shell -v` (C) 2001-2002 by Tito Ragusa email: tito-wolit@tiscalinet.it">>$HOME/$help_file_name  
	echo "  ">>$HOME/$help_file_name
	xstep-shell -t $prog_name -vf $HOME/$help_file_name 
	rm -f $HOME/$help_file_name
}

x_click_exit_click()
{
# this to kill the process if x or exit is clicked
set -- $out
if [ "$1" = "Exit" ] 2>/dev/null ; then  
	if [ $child_pid -gt 0 ] 2>/dev/null ;then
		kill $child_pid
	fi
	close_it=0
	kill  $$ 
fi
if [ $1 =  ] 2>/dev/null ; then  
	if [ $child_pid -gt 0 ] 2>/dev/null ;then
		kill $child_pid
	fi
	close_it=0
	kill  $$ 
fi
}

clean_out()
{
out=
}

close_win()
{
# close the last window, but let script run
check=`ps | grep -c xstep-shell`
pid=`ps | grep xstep-shell| cut -b 1-6`
# checking if window was already closed by clicking x or exit
if [ $check = 1 ] ; then 
	kill $pid
else
kill $$
fi
}


# main
if [ $1 != " " ] 2>/dev/null ; then
	out2=`xstep-shell -t Xless -vf $1 -b About`
else 
	out=`xstep-shell -t "Xless : Select a file" -fs`
	x_click_exit_click
	out2=`xstep-shell -t Xless -vf $out -b About`
fi
if [ $out2 = About ] 2>/dev/null ; then
	about
fi


