home *** CD-ROM | disk | FTP | other *** search
-
-
- WHICH, v2.0
- -------------
- from TifaWARE
-
-
-
-
- What's New
- ----------
-
-
- New to version 2.0 is a verbose reporting option; with it you see
- exactly which directories are being searched. Additionally, several of the
- main functions in WHICH have been rewritten, and AT&T's getopt() function
- is now used for a consistent method of option processing. Finally, memory
- problems at run-time should be a thing of the past as directory names no
- longer require additional memory allocation.
-
- Version 1.2 of WHICH does not represent much of an improvement over
- the preceding release, at least from the user's viewpoint. Some of the code
- for displaying the on-line help message was improved, and error messages
- are formated in a slightly different fashion. Also, program names are not
- converted to uppercase if no match is found.
-
-
-
-
- Introduction
- ------------
-
-
- With the increasing popularity and size of hard disks, keeping track
- of executable programs is becoming more and more difficult. If you're like
- me, you probably have a few programs on your disk with the same filename,
- possibly even some in the same directory. Which one will be run when you
- type the command's name at the DOS prompt?
-
- The answer, of course, depends on your current directory as well as
- the setting of the PATH environment variable. When you type a command at
- the DOS prompt and press <ENTER>, DOS determines if the command is internal
- or external. Internal commands - CLS, DIR, COPY, etc... - are implemented
- within DOS itself; external ones are disk files with an extension of COM,
- EXE, or BAT. First, DOS compares your command against its list of internal
- ones. If no match is found, DOS assumes the command is external and tries
- to find the program on disk. It looks in the current directory for a file
- with the same filename as the command and an extension of COM, EXE, or BAT
- in _that_ order. If DOS is still unsuccessful, it then continues to search
- sequentially through the directories specified by the environment variable
- PATH until a match is found. Only if DOS runs out of directories to scan
- does it print the dreaded "Bad command or file name" message.
-
- As the name suggests, WHICH searches your system for programs that
- MS-DOS is capable of running. It is not a general file-search utility a la
- PKFIND or WHEREIS; rather, it scans only a few directories for executable
- programs or batch files. But it can save a lot of frustration if any of
- your programs have the same names.
-
-
-
-
- Usage
- -----
-
-
- Running this program is straightforward. Once you've placed WHICH.COM
- on your disk where DOS can find it (either in the current directory or one
- specified by PATH), you're ready to use it. Type WHICH -? and you'll see a
- message similar to the following:
-
- TifaWARE WHICH, v2.0, Jan 02 1990 - scans path for executable programs.
- Usage: which [-options] prog(s)
-
- Options:
- -a = find all possible matches
- -v = verbose reporting
- -? = provide this help message
-
- Prog(s) must not contain wildcards or drive/path/extension info.
-
- [If you don't remember anything else from reading the documentation, at
- least remember how to display this help message.]
-
- To search for one or more files, simply add their filenames to the
- command line when you invoke WHICH. [Note: Only "filenames" are accepted
- as arguments; i.e., that part of a file's name located between the drive
- and path specifiers on one hand and the extension on the other. For the
- file named "C:\AUTOEXEC.BAT", the filename is "AUTOEXEC".] Suppose you want
- to determine which versions of GREP, WP, and DV will be executed by DOS.
- Then you could simply type "which grep wp dv". On my system, this produces
- the following output:
-
- C:\BIN\GREP.EXE
- which: no matches for wp.
- C:\USR\BIN\DV.BAT
-
- Notice that when reporting matches, WHICH converts filenames to uppercase
- regardless of how they are specified on the commandline. MS-DOS does not
- distinguish between upper- and lower-case letters in filenames; neither
- does WHICH.
-
- You can force WHICH to search all directories in the path by using the
- 'a' option. What good is this? For one, it's a way of locating extra copies
- of programs and freeing up vital disk space. You'd be surprised how many
- people keep two or three copies of COMMAND.COM, for example, on their hard
- disk! For another, this option can help determine why a particular program
- exhibits different behaviour depending on where you are when it's invoked.
- Rather than pulling out all your hair you might discover two distinct batch
- files with the same name but in different locations on your hard disk.
-
- The 'v' option is primarily designed for debugging purposes. It simply
- enables verbose reporting of WHICH's progress through each directory. With
- this option you can tell exactly which directories are being searched. As a
- bonus, you'll see if any tricks were used to name a directory (like hidden
- characters!) since each name should end with a backslash.
-
- When WHICH is successful, it writes a program's complete file name to
- standard output. Using the DOS redirection characters '>' and '|', you
- could send this ouput to a disk file, printer, or even use it as input into
- another program.
-
-
-
-
- If You Have Any Trouble
- -----------------------
-
-
- WHICH will either report the full file names for the programs you
- specify on the command line or notify you of a problem. Here are the error
- messages you might see and how you should deal with them:
-
- which: illegal option -- x.
- - Type "WHICH -?" for a list of valid options. If your
- program's name starts with a '-', you can avoid
- having WHICH treat the name as a set of options by
- preceding it with another name. For instance, typing
- WHICH AUTOEXEC -ODDNAME would search for the program
- -ODDNAME as desired.
-
- which: can't determine directories to search.
- - WHICH can't figure out the default directory perhaps
- because of trouble with the current drive.
-
- which: invalid filename -- c:progname.
- - Look back at the definition of a filename. It must
- not contain any drive, path, or extension information
- *nor* wildcards.
-
- which: no matches for progname.
- - Check the setting of PATH, the current directory, and
- the spelling of the program's name. Or perhaps the
- program simply doesn't exist on your machine.
-
- These error messages are written to the standard error device. In this
- way, they won't disappear down a pipe or into a file should you try to
- redirect WHICH's output.
-
- Additionally, WHICH uses a return code to convey information about the
- success or failure of its searches. Possible return values are:
-
- Code Meaning
- ---- -------
- 0 Matches were found for all program names
- 1 Help message was displayed
- 5 WHICH could not determine which directories to search
- 10 At least 1 program name could not be matched
- 20 At least 1 program name was an invalid filename.
-
- You can test for these codes using the ERRORLEVEL variable in a batch file.
-
- Finally, it should be noted that WHICH limits processing to 25
- directories; it will simply ignore any others listed in your PATH. If this
- is a problem for you, you can either reorganize your hard disk or change
- the constant MAX_DIRS in the source and recompile. I strongly recommend
- the first course of action.
-
-
-
-
- Requirements
- ------------
-
-
- TifaWARE WHICH runs on machines operating under MS-DOS v2.xx or later,
- and requires roughly 10K of memory. It does not use BIOS calls, make
- direct writes to video RAM, or otherwise require machines to be
- "PC-compatible". In fact, WHICH even runs properly on a DEC Rainbow!
-
- WHICH makes no attempt to work with any command aliasing utilities or
- path-extenders for the PC; eg, ALIAS, SEARCH, GLOBALS, ... If you try to
- use it with one of the former, WHICH will probably report no matches; with
- one of the latter, probably a match in the current directory regardless of
- how PATH is set.
-
-
-
-
- Who Owns WHICH?
- ---------------
-
-
- I am releasing this implementation of WHICH into the public domain.
- Since my involvement with MS-DOS began in 1984, I've been a heavy user of
- public domain software (especially Kermit and a host of utilities for the
- DEC Rainbow). Public domain software is a terrific idea. For the most
- part, programs are useful and the source code instructive, all at no cost!
- With this small contribution to the public domain I hope to pay back, in
- some sense, my gratitude to those other programmers who have made my
- computing so much easier.
-
- As a public domain program, WHICH carries no obligation on my part to
- support users or provide future upgrades. I have tried to write clean code
- and believe it to be for the most part "bug-free". Nevertheless, you must
- use this program ***AT YOUR OWN RISK***. I strongly urge you to scan the
- source code yourself, make any desired changes, and recompile the program,
- if this is possible. If you make this standard practice with newly
- acquired public domain software, you'll not only protect your system from
- worms and viruses but also get a better feel for exactly how each program
- works!
-
- As author of WHICH, I ask of you two things: First, if you distribute
- this program, please keep together my original source code, documentation,
- and executable. This just makes it easier for others to use the software.
- Second, let me hear what you think of WHICH. You don't have to send any
- money, just comments and suggestions.
-
-
-
-
- Kudos
- -----
-
-
- The idea for WHICH came to me while reading _The UNIX Programming
- Environment_ by Kernighan & Pike. The code itself was written using
- Borland's TURBO C, v2.0. I've seen several implementations of WHICH
- already in the public domain, but I wanted to try out TURBO C's integrated
- development environment. Not bad!
-
-
-
-
-
- George A. Theall
-
- TifaWARE
- 506 South 41st St., #3M
- Philadelphia, PA. 19104
- U.S.A.
-
- (215) 662-0558
-
- GTHEALL@PENNDRLS.UPENN.EDU (ARPA Internet)
-