#!/bin/bash
prog_name=Xpsman
help_file_name=xpsman.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
close_it=1 
while [ $close_it = 1 ]
do
	ps -A > $HOME/.xpsman
	out=`xstep-shell -t "XpsManager: Select a process" -vf $HOME/.xpsman -pl  -b Refresh Kill About `
	x_click_exit_click		
	echo $out #debug
	set -- $out
	case $1 in
	About)
		about
	;;
	Refresh)
		#dummy
	;;
	Kill)
		out=`xstep-shell -t XpsManager -l "Really Kill process $2 $5?" -bf -b No Yes -rb "kill -1" "kill -9" "kill -19" -sy 200`
		process=$2
		# now let's parse the radio button output in $3
		set -- $out
		case $1 in 
			Yes)
				eval $3 $process
			;;
			*)
			;;
		esac
	;;
	Ok)
		close_it=0
	;;
	*)
		echo "Unknown label"
	;;
	esac
done
rm -f $HOME/.xpsman







