/*  ShowMe.rexx v1.0 June 20, 1991									*/  
/*																	*/
/*  Original script by Robert Kesterson -- bix: rkesterson    		*/
/*																	*/
/*	NOTE:  This script is designed for use with WorkBench 2.0 ONLY!	*/
/*																	*/
/*  This is a little ARexx script which ties together a bunch of   	*/
/*  other utilities and gives them an AppWindow on the WorkBench.  	*/
/*  The idea is that you can then pick up anything you want and 	*/
/*  drop it in the window and it will show it to you, whether it's 	*/
/*  a text file, an IFF picture, an executable file, or whatever.   */
/*	For more details, see the doc file.								*/

                    
parse arg target

if ~exists(target) then exit       


/* 	Next we need to try to figure out what the file is, so we know 	*/
/*  what to do with it.  First, let's check the file extension to 	*/
/*  find out if it's an archive or other special file.              */
/*  If it is, we'll build a script file in RAM to handle showing it.*/
/*  This is all done simply by checking the file extension against  */
/* 	a list of extension is s:showme.archivers, then building the  	*/
/*  command to use to view that archive with information from the 	*/
/*  s:showme.archivers file.										*/
               
               
if open(arcers,'s:showme.archivers','r') then do

	if open(ShowMeScript,'ram:ShowMe.Script','w') then 
		do while ~eof(arcers)
			arcerline = readln(arcers) 
			parse var arcerline extension arcer option
			if lastpos(extension,target) = length(target) - length(extension) + 1 then do
				if option = '©' then
					cmd = arcer || " " || target              
				else 
					cmd = arcer || " " || option || " " || target
				writeln(ShowMeScript,cmd)
				writeln(ShowMeScript,'ask "<*>---- Press RETURN to Exit ----<*>"')  
				writeln(ShowMeScript,"endcli")
				close(ShowMeScript)
				cmd = 'newshell "con:0/0/640/200/ShowMe" from ram:ShowMe.Script'
				address command cmd
				close(arcers)
				exit
				end
			end
	else 
		close(arcers)
	end

/*	If it gets to this point, the file type wasn't found in the 	*/
/* 	list of known archivers.  So we'll run WhatIs on it, and see if	*/
/*	that tells us anything useful.  If it does, we search the 		*/
/* 	path to find out where the utility we want to use lives, then	*/
/* 	fire it off below.												*/

address command "programs:utilities_2/whatis >ram:showme.temp" target

if open(WhatsIt,'ram:showme.temp','r') then do
	whatsitline = readln(WhatsIt)
	close(WhatsIt)                               
	if index(whatsitline,"100 % ASCII chars") > 0 then
		address command "programs:utilities/readtext " target
	else 
		if index(whatsitline,"Executable file") > 0 then
			address command "run " target
		else 
			if index(whatsitline,"IFF file") > 0 then
				address command "programs:c/Tiv " target
            else
				address command "programs:utilities_2/Hex " target
    end
                         
exit

	 