1ea1625f77d9bd079da56867037d529aa1a3d370
2 * WHERE.C - file serch functions.
7 * 07/15/95 (Tim Norman)
10 * 08/08/95 (Matt Rains)
11 * i have cleaned up the source code. changes now bring this source into
12 * guidelines for recommended programming practice.
14 * 12/12/95 (Steffan Kaiser & Tim Norman)
15 * added some patches to fix some things and make more efficient
18 * fixed a stupid pointer mistake... Thanks to everyone who noticed it!
21 * fixed a bug when getenv returns NULL
23 * 8/7/96 (Steffan Kaiser and Tim Norman)
24 * speed improvements and bug fixes
26 * 8/27/96 (Tim Norman)
27 * changed code to use pointers directly into PATH environment variable
28 * rather than making our own copy. This saves some memory, but requires
29 * we write our own function to copy pathnames out of the variable.
31 * 12/23/96 (Aaron Kaufman)
32 * Fixed a bug in get_paths() that did not point to the first PATH in the
33 * environment variable.
35 * 7/12/97 (Tim Norman)
36 * Apparently, Aaron's bugfix got lost, so I fixed it again.
38 * 16 July 1998 (John P. Price)
39 * Added stand alone code.
41 * 17 July 1998 (John P. Price)
42 * Rewrote find_which to use searchpath function
44 * 24-Jul-1998 (John P Price <linux-guru@gcfl.net>)
45 * - fixed bug where didn't check all extensions when path was specified
47 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
48 * - added config.h include
50 * 30-Jul-1998 (John P Price <linux-guru@gcfl.net>)
51 * - fixed so that it find_which returns NULL if filename is not executable
52 * (does not have .bat, .com, or .exe extention). Before command would
53 * to execute any file with any extension (opps!)
55 * 03-Dec_1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
56 * Changed find_which().
58 * 07-Dec_1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
59 * Added ".CMD" extension.
60 * Replaced numeric constant by _NR_OF_EXTENSIONS.
63 #define WIN32_LEAN_AND_MEAN
74 static LPTSTR ext
[] = {".BAT", ".CMD", ".COM", ".EXE"};
75 static INT nExtCount
= sizeof(ext
) / sizeof(LPTSTR
);
78 /* searches for file using path info. */
80 BOOL
find_which (LPCTSTR fname
, LPTSTR fullbuffer
)
82 static TCHAR temp
[MAX_PATH
];
86 *fullbuffer
= _T('\0');
88 /* if there an extension and it is in the last path component, then
89 * don't test all the extensions. */
90 if (!(fullname
= _tcsrchr (fname
, _T('.'))) ||
91 _tcschr (fullname
+ 1, _T('\\')))
94 DebugPrintf ("No filename extension!\n");
97 for (x
= 0; x
< nExtCount
; x
++)
99 _tcscpy (temp
, fname
);
100 _tcscat (temp
, ext
[x
]);
102 DebugPrintf ("Checking for %s\n", temp
);
104 if (_tcschr (fname
, _T('\\')))
106 if (IsValidFileName (temp
))
108 _tcscpy (fullbuffer
, temp
);
114 _searchenv (temp
, _T("PATH"), fullbuffer
);
115 if (*fullbuffer
!= '\0')
122 /* there is an extension... don't test other extensions */
123 /* make sure that the extention is one of the four */
125 DebugPrintf ("No filename extension!\n");
127 for (x
= 0; x
< nExtCount
; x
++)
129 if (!_tcsicmp (_tcsrchr (fname
, _T('.')), ext
[x
]))
131 if (_tcschr (fname
, _T('\\')))
133 if (IsValidFileName (fname
))
135 _tcscpy (fullbuffer
, fname
);
137 DebugPrintf ("Found: %s\n", fullbuffer
);
145 DebugPrintf ("Checking for %s\n", fname
);
147 _searchenv (fname
, _T("PATH"), fullbuffer
);
148 if (*fullbuffer
!= _T('\0'))
151 DebugPrintf ("Found: %s\n", fullbuffer
);