- Timestamp:
- Apr 26, 2001, 10:21:31 PM (24 years ago)
- Location:
- trunk/src/helpers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r63 r64 2186 2186 2187 2187 /* 2188 *@@ doshFindExecutable:2189 * this searches the PATH for the specified pcszCommand2190 * by calling DosSearchPath.2191 *2192 * papcszExtensions determines if additional searches are to be2193 * performed if DosSearchPath returns ERROR_FILE_NOT_FOUND.2194 * This must point to an array of strings specifying the extra2195 * extensions to search for.2196 *2197 * If both papcszExtensions and cExtensions are null, no2198 * extra searches are performed.2199 *2200 * If this returns NO_ERROR, pszExecutable receives2201 * the full path of the executable found by DosSearchPath.2202 * Otherwise ERROR_FILE_NOT_FOUND is returned.2203 *2204 * Example:2205 *2206 + const char *aExtensions[] = { "EXE",2207 + "COM",2208 + "CMD"2209 + };2210 + CHAR szExecutable[CCHMAXPATH];2211 + APIRET arc = doshFindExecutable("lvm",2212 + szExecutable,2213 + sizeof(szExecutable),2214 + aExtensions,2215 + 3);2216 *2217 *@@added V0.9.9 (2001-03-07) [umoeller]2218 */2219 2220 APIRET doshFindExecutable(const char *pcszCommand, // in: command (e.g. "lvm")2221 PSZ pszExecutable, // out: full path (e.g. "F:\os2\lvm.exe")2222 ULONG cbExecutable, // in: sizeof (*pszExecutable)2223 const char **papcszExtensions, // in: array of extensions (without dots)2224 ULONG cExtensions) // in: array item count2225 {2226 APIRET arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,2227 "PATH",2228 (PSZ)pcszCommand,2229 pszExecutable,2230 cbExecutable);2231 if ( (arc == ERROR_FILE_NOT_FOUND) // not found?2232 && (cExtensions) // any extra searches wanted?2233 )2234 {2235 // try additional things then2236 PSZ psz2 = (PSZ)malloc(strlen(pcszCommand) + 20);2237 if (psz2)2238 {2239 ULONG ul;2240 for (ul = 0;2241 ul < cExtensions;2242 ul++)2243 {2244 const char *pcszExtThis = papcszExtensions[ul];2245 sprintf(psz2, "%s.%s", pcszCommand, pcszExtThis);2246 arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,2247 "PATH",2248 psz2,2249 pszExecutable,2250 cbExecutable);2251 if (arc != ERROR_FILE_NOT_FOUND)2252 break;2253 }2254 2255 free(psz2);2256 }2257 else2258 arc = ERROR_NOT_ENOUGH_MEMORY;2259 }2260 2261 return (arc);2262 }2263 2264 /*2265 2188 *@@ doshExecVIO: 2266 2189 * executes cmd.exe with the /c parameter -
trunk/src/helpers/dosh2.c
r59 r64 2359 2359 free(paResources); 2360 2360 return (NO_ERROR); 2361 } 2362 2363 /* 2364 * FindFile: 2365 * helper for doshFindExecutable. 2366 * 2367 *added V0.9.11 (2001-04-25) [umoeller] 2368 */ 2369 2370 APIRET FindFile(const char *pcszCommand, // in: command (e.g. "lvm") 2371 PSZ pszExecutable, // out: full path (e.g. "F:\os2\lvm.exe") 2372 ULONG cbExecutable) // in: sizeof (*pszExecutable) 2373 { 2374 APIRET arc = NO_ERROR; 2375 FILESTATUS3 fs3; 2376 2377 if ( (strchr(pcszCommand, '\\')) 2378 || (strchr(pcszCommand, ':')) 2379 ) 2380 { 2381 // looks like this is qualified: 2382 arc = DosQueryPathInfo((PSZ)pcszCommand, 2383 FIL_STANDARD, 2384 &fs3, 2385 sizeof(fs3)); 2386 if (!arc) 2387 if (!(fs3.attrFile & FILE_DIRECTORY)) 2388 strhncpy0(pszExecutable, 2389 pcszCommand, 2390 cbExecutable); 2391 else 2392 // directory: 2393 arc = ERROR_INVALID_EXE_SIGNATURE; 2394 } 2395 else 2396 // non-qualified: 2397 arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY, 2398 "PATH", 2399 (PSZ)pcszCommand, 2400 pszExecutable, 2401 cbExecutable); 2402 2403 return (arc); 2404 } 2405 2406 /* 2407 *@@ doshFindExecutable: 2408 * this attempts to find an executable by doing the 2409 * following: 2410 * 2411 * 1) If pcszCommand appears to be qualified (i.e. contains 2412 * a backslash), this checks for whether the file exists. 2413 * 2414 * 2) If pcszCommand contains no backslash, this calls 2415 * DosSearchPath in order to find the full path of the 2416 * executable. 2417 * 2418 * papcszExtensions determines if additional searches are to be 2419 * performed if the file doesn't exist (case 1) or DosSearchPath 2420 * returned ERROR_FILE_NOT_FOUND (case 2). 2421 * This must point to an array of strings specifying the extra 2422 * extensions to search for. 2423 * 2424 * If both papcszExtensions and cExtensions are null, no 2425 * extra searches are performed. 2426 * 2427 * If this returns NO_ERROR, pszExecutable receives 2428 * the full path of the executable found by DosSearchPath. 2429 * Otherwise ERROR_FILE_NOT_FOUND is returned. 2430 * 2431 * Example: 2432 * 2433 + const char *aExtensions[] = { "EXE", 2434 + "COM", 2435 + "CMD" 2436 + }; 2437 + CHAR szExecutable[CCHMAXPATH]; 2438 + APIRET arc = doshFindExecutable("lvm", 2439 + szExecutable, 2440 + sizeof(szExecutable), 2441 + aExtensions, 2442 + 3); 2443 * 2444 *@@added V0.9.9 (2001-03-07) [umoeller] 2445 *@@changed V0.9.11 (2001-04-25) [umoeller]: this never worked for qualified pcszCommand's, fixed 2446 */ 2447 2448 APIRET doshFindExecutable(const char *pcszCommand, // in: command (e.g. "lvm") 2449 PSZ pszExecutable, // out: full path (e.g. "F:\os2\lvm.exe") 2450 ULONG cbExecutable, // in: sizeof (*pszExecutable) 2451 const char **papcszExtensions, // in: array of extensions (without dots) 2452 ULONG cExtensions) // in: array item count 2453 { 2454 APIRET arc = FindFile(pcszCommand, 2455 pszExecutable, 2456 cbExecutable); 2457 2458 if ( (arc == ERROR_FILE_NOT_FOUND) // not found? 2459 && (cExtensions) // any extra searches wanted? 2460 ) 2461 { 2462 // try additional things then 2463 PSZ psz2 = (PSZ)malloc(strlen(pcszCommand) + 20); 2464 if (psz2) 2465 { 2466 ULONG ul; 2467 for (ul = 0; 2468 ul < cExtensions; 2469 ul++) 2470 { 2471 const char *pcszExtThis = papcszExtensions[ul]; 2472 sprintf(psz2, "%s.%s", pcszCommand, pcszExtThis); 2473 arc = FindFile(psz2, 2474 pszExecutable, 2475 cbExecutable); 2476 if (arc != ERROR_FILE_NOT_FOUND) 2477 break; 2478 } 2479 2480 free(psz2); 2481 } 2482 else 2483 arc = ERROR_NOT_ENOUGH_MEMORY; 2484 } 2485 2486 return (arc); 2361 2487 } 2362 2488
Note:
See TracChangeset
for help on using the changeset viewer.