home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
mflms104.arj
/
INPATH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-15
|
4KB
|
128 lines
/*
** INPATH UTILITY
** This is a program similar to many "filefind" programs, except that
** it works like the UNIX "whereis" command. The command line argument
** (only one, please) is taken to be the name of an executable
** program, and is searched under extensions .BAT, .COM, and .EXE
** for the first occurance of the program. The search starts
** in the current directory, and if not found, procedes using the
** PATH environment variable (if there is one). The program reports the
** first occurance of the specified file, just as it would be found
** by DOS if executed.
**
** The input filename need not contain an extension, since the
** extension is discarded anyway.
**
** Version 1.05 for Turbo-C 2.0
** 11-08-88 A
**
** Copyright 1988-89 by Steven E. Margison
**
** Modified 1989 by Bob Stout
**
** As distributed, this program requires (for compilation):
** "The MicroFirm Function LIbrary for MS/QC"
** which may be obtained without registration from many Bulletin
** Board Systems.
**
** or by registration:
** $25 for Docs, C, S, M, L, H libraries, and complete library source
** in C and Assembler
** MicroFirm
** P.O. Box 428
** Alief, TX 77411
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mflfiles.h>
char paths[256],
fullname[100],
dirname[100],
batname[14],
comname[14],
exename[14],
fname[14];
int current;
main(argc, argv)
int argc;
char *argv[];
{
int i, j, k;
char c;
if(argc != 2)
usage();
strcpy(fname, argv[1]); /* copy argument to fname */
newext(fname, batname, "BAT"); /* make fname.bat */
newext(fname, comname, "COM"); /* make fname.com */
newext(fname, exename, "EXE"); /* make fname.exe */
dirname[0] = NUL;
current = TRUE;
findpgm();
current = FALSE;
if((j = getpath(paths)) == 0)
notfound();
k = 0;
while(j > 0)
{
i = 0;
while(paths[k] != NUL)
{
c = paths[k]; /* save for slash check */
dirname[i++] = paths[k++];
--j;
}
if (c != '\\')
dirname[i++] = '\\';
dirname[i] = NUL;
++k; /* position to next charcter in paths[] */
--j;
findpgm();
}
notfound();
}
findpgm()
{
strcpy(fullname, dirname); /* test for .com file */
strcat(fullname, comname);
if(exists(fullname))
goto found;
strcpy(fullname, dirname);
strcat(fullname, exename); /* test for .exe file */
if(exists(fullname))
goto found;
strcpy(fullname, dirname);
strcat(fullname, batname); /* test for .bat file */
if(exists(fullname))
goto found;
return(FALSE); /* file not found */
found: if(current)
puts("File found in current directory");
fputs(fullname, stdout);
fputc('\n', stdout);
exit(0);
return(FALSE); /* to eliminate a compiler warning */
}
notfound()
{
error("File not found in PATH");
}
usage()
{
fputs("INPATH Version 1.10\n", stderr);
fputs("Copyright 1988-89, Steven E. Margison\n", stderr);
error("usage: inpath <filename>");
}