[comp.os.msdos.misc] WHICH.BTM for 4DOS again

richard@calvin.ee.cornell.edu (Richard Brittain - VOS hacker) (04/17/91)

A few days ago a version of WHICH for 4DOS was posted, along with a 
'challenge' to make it identify internal commands also.

>  From: ggurman@cory.Berkeley.EDU (Gail Gurman)
>  Subject: My version of WHICH.BTM for 4DOS
>  Message-ID: <12624@pasteur.Berkeley.EDU>
>  Date: 10 Apr 91 03:03:17 GMT
>  
>  Somebody recently posted WHICH.BTM for 4DOS.  It was really great
>  but I thought it should allow you to say WHICH *NAME to skip over
>  the check for aliases.  My version sacrifices the ability to
>  use more than one name on the command line however.  It's that nasty
>  FOR command.  It only works on file names.
>  
>  I also tried to make a version that would check if the argument
>  was an internal command.  Again, I tried the FOR command
>  (e.g. for %NAME in (BREAK CLS COPY DEL DIR) echo Internal command.)
>  but, again, it only works on file names.  If anyone has any ideas,
>  please tell me.  I'd really like this to work for every possibility.
>  
>  Anyway, here's my version.  It is basically the other one, edited.
>  
>  Gail

Well, here goes - again, basically the other version, edited.  It needs
to use the msdos "find" utility which everyone should have available, and
it runs respectably fast if %TMP points to a ram disk to help the pipe along.

----------
@echo off
setlocal
alias # REM
# WHICH.BTM -- usage is WHICH name

if %#==0 goto error

set NAME = %@upper[%1]
# Is it an aliased command that we don't want expanded?
iff "%@substr[%1,0,1]" == "*" then
	set NAME = %@substr[%NAME,1,12]
	gosub search
else
# Is it an alias?
	iff isalias %NAME then
		echo alias:
		alias %NAME
	else
# Is it an internal or external command?
		gosub search
	endiff
endiff
quit

:error
# Oops!  No argument!
echo Usage:  WHICH [filename][.ext]
quit

:search
# Here's where we check if it is a program or file.
# First check for internal commands - this will work for all versions of 4dos
? | find /C `" `%NAME` "` | input %%count
iff %count GT 0 then
	echo internal command:
	echo %NAME
else
	set FILE=%@search[%NAME]
	iff "%FILE" == "" then
		echo no "%NAME" found in PATH
	else
		echo %FILE
	endiff
endiff
return
---------------

Using the ? command makes sure that future new commands are covered.

-- 
Richard Brittain,                 School of Elect. Eng.,  Eng. and Theory Center
                                  Cornell university, Ithaca, NY 14853
INTERNET: richard@calvin.ee.cornell.edu	
    UUCP: {uunet,uw-beaver,rochester,cmcl2}!cornell!calvin!richard