#!/usr/bin/csh
#
# Directory selection
# --------------------
# Here we read the names of all the directories in
# $inputdirs to choose from
# ------------------------------------------------
#
#set echo 

set dirname = ''


while  ( 1 ) 		# Keep repeating the following
						# lines untill $dirname is really set.
						# Initialize GUI window
						# ---------------------
	echo "WIN 500 400" 					> $GUI_DATA
	echo "BW 1" 						>> $GUI_DATA
	echo "FONT tbr14" 					>> $GUI_DATA
	echo "BG 777777" 					>> $GUI_DATA
	echo "FG 000000" 					>> $GUI_DATA
	echo "TEXT dirname_keyb 20 Client Directory" 		>> $GUI_DATA
	echo "DTEXT dirname_keyb $inputdirs "                   >> $GUI_DATA
	echo "LABEL Select from list..." 			>> $GUI_DATA
	echo "LIST dirname 13 S 1" 				>> $GUI_DATA     # create a listbox for directories
	
	#
	# Look for directories in $inputdirs
	# ----------------------------------
	
	if ( ! -d $inputdirs ) then
	  PAUSE Input directory $inputdirs does not exist
	  set exit = 1
	  exit
	endif
	
	set filelist = (`ls $inputdirs`)

        set check_for_dirs = 0 
	foreach file ($filelist)                                                 # go through each file in $inputdirs
	    if (-d $inputdirs/$file) then			                 # if it is a directory add it to list
		echo "    $file:t" 				>> $GUI_DATA
		@ check_for_dirs++
	    endif
	    
	end # foreach file
			
	echo "  END" 						>> $GUI_DATA
	echo "RADIO finish  choose H 1 990000" 			>> $GUI_DATA
	echo "Continue" 					>> $GUI_DATA
	echo "Exit" 						>> $GUI_DATA
	echo "END" 						>> $GUI_DATA
	


	if ($check_for_dirs > 0) then	                                         # found at least one directory	
	   rm $GUI_RESP
	   $GUI < $GUI_DATA > $GUI_RESP
	   while (-z $GUI_RESP)
	      sleep 1
	   end
	   source $GUI_RESP    #; rm $GUI_DATA $GUI_RESP
           if (-e $inputdirs/$dirname) then
	      set inputdirs = $inputdirs/$dirname
              break
           endif
	
	   if ($finish == 2) then
	      set exit = 1;
	      exit
	   endif

	   if ($dirname_keyb != "" && -e $inputdirs/$dirname_keyb) then
              set dirname = $dirname_keyb
	      break
           endif
	else
	    PAUSE "No data in $inputdirs"
	    set exit = 1;
	    exit
	endif

	
	if ($debug_mode == "yes") PAUSE $inputdirs

	
end # of while

echo "Inputdir = $dirname"
set exit = 0

### EOF ###
