| [632] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: srchpath.c 907 2008-01-06 07:26:17Z stevenhl $ | 
|---|
|  | 5 |  | 
|---|
| [809] | 6 | Path search functions | 
|---|
| [632] | 7 |  | 
|---|
|  | 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| [907] | 9 | Copyright (c) 2003, 2008 Steven H. Levine | 
|---|
| [632] | 10 |  | 
|---|
|  | 11 | 22 Apr 07 GKY Add RunFM2Util to find and run apps from the FM2Utilities | 
|---|
| [793] | 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| [809] | 13 | 23 Aug 07 SHL Comments | 
|---|
| [632] | 14 |  | 
|---|
|  | 15 | ***********************************************************************/ | 
|---|
| [907] | 16 |  | 
|---|
|  | 17 | #include <string.h> | 
|---|
|  | 18 |  | 
|---|
| [632] | 19 | #define INCL_WIN | 
|---|
| [2] | 20 | #define INCL_DOS | 
|---|
| [907] | 21 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| [2] | 22 |  | 
|---|
| [632] | 23 | #include "fm3dlg.h" | 
|---|
|  | 24 | #include "fm3str.h" | 
|---|
| [907] | 25 | #include "pathutil.h"                   // BldQuotedFileName | 
|---|
|  | 26 | #include "errutil.h"                    // Dos_Error... | 
|---|
|  | 27 | #include "fm3dll.h" | 
|---|
| [632] | 28 |  | 
|---|
|  | 29 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 30 |  | 
|---|
| [2] | 31 | #pragma data_seg(DATA1) | 
|---|
|  | 32 |  | 
|---|
| [632] | 33 | //== RunFM2Util() Find and run an app from the FM2utilities == | 
|---|
|  | 34 | //== Search PATH plus 2 default install dirs == | 
|---|
|  | 35 |  | 
|---|
|  | 36 | INT RunFM2Util(CHAR *appname, CHAR *filename) | 
|---|
|  | 37 | { | 
|---|
|  | 38 | CHAR fbuf[CCHMAXPATH]; | 
|---|
| [891] | 39 | CHAR szQuotedFileName[CCHMAXPATH]; | 
|---|
| [632] | 40 | APIRET rc, ret = -1; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | rc = DosSearchPath(SEARCH_IGNORENETERRS |SEARCH_ENVIRONMENT | | 
|---|
|  | 43 | SEARCH_CUR_DIRECTORY,"PATH", | 
|---|
|  | 44 | appname, fbuf, CCHMAXPATH - 1); | 
|---|
|  | 45 | if (rc != 0) { | 
|---|
|  | 46 | if (rc != 2){ | 
|---|
|  | 47 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
|  | 48 | "DosSearchPath", appname); | 
|---|
|  | 49 | return ret; | 
|---|
|  | 50 | } | 
|---|
|  | 51 | else { | 
|---|
|  | 52 | rc = DosSearchPath(0, "UTILS;..\\FM2Utils", | 
|---|
|  | 53 | appname, fbuf, CCHMAXPATH - 1); | 
|---|
|  | 54 | if (rc != 0 && rc != 2){ | 
|---|
|  | 55 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
|  | 56 | "DosSearchPath", appname); | 
|---|
|  | 57 | return ret; | 
|---|
|  | 58 | } | 
|---|
|  | 59 | } | 
|---|
|  | 60 | } | 
|---|
|  | 61 | ret = runemf2(SEPARATE | WINDOWED, | 
|---|
| [888] | 62 | HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| [632] | 63 | NULL, | 
|---|
|  | 64 | NULL, | 
|---|
| [891] | 65 | "%s %s", | 
|---|
|  | 66 | fbuf, BldQuotedFileName(szQuotedFileName, filename)); | 
|---|
| [632] | 67 | return ret; | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [551] | 70 | CHAR *first_path(CHAR * path, CHAR * ret) | 
|---|
|  | 71 | { | 
|---|
| [2] | 72 |  | 
|---|
| [551] | 73 | CHAR *p, *pp; | 
|---|
| [2] | 74 |  | 
|---|
| [551] | 75 | if (!path || !ret) | 
|---|
| [2] | 76 | return ret; | 
|---|
| [551] | 77 | strcpy(ret, path); | 
|---|
|  | 78 | p = strchr(ret, ';'); | 
|---|
|  | 79 | if (p) { | 
|---|
| [2] | 80 | *p = 0; | 
|---|
|  | 81 | p++; | 
|---|
| [551] | 82 | if (*ret == '.') {                  /* skip initial "cur dir" */ | 
|---|
|  | 83 | pp = strchr(p, ';'); | 
|---|
|  | 84 | if (pp) | 
|---|
|  | 85 | *pp = 0; | 
|---|
|  | 86 | if (*p) | 
|---|
|  | 87 | memmove(ret, p, strlen(p) + 1); | 
|---|
| [2] | 88 | } | 
|---|
|  | 89 | } | 
|---|
|  | 90 | return ret; | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
| [809] | 93 | /** | 
|---|
|  | 94 | * Search for file in name PATH env variable | 
|---|
|  | 95 | * 23 Aug 07 SHL fixme to be MT safe | 
|---|
|  | 96 | */ | 
|---|
|  | 97 |  | 
|---|
|  | 98 | CHAR *searchapath(CHAR *pathvar, CHAR *filename) | 
|---|
| [551] | 99 | { | 
|---|
| [2] | 100 | static CHAR fbuf[CCHMAXPATH]; | 
|---|
|  | 101 |  | 
|---|
| [551] | 102 | if (strchr(filename, '\\') || strchr(filename, '/') | 
|---|
|  | 103 | || strchr(filename, ':')) { | 
|---|
| [2] | 104 |  | 
|---|
| [847] | 105 | FILESTATUS3 fsa; | 
|---|
| [2] | 106 |  | 
|---|
| [847] | 107 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa))) | 
|---|
| [2] | 108 | return filename; | 
|---|
|  | 109 | *fbuf = 0; | 
|---|
|  | 110 | return fbuf; | 
|---|
|  | 111 | } | 
|---|
|  | 112 | *fbuf = 0; | 
|---|
| [551] | 113 | if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | | 
|---|
|  | 114 | SEARCH_CUR_DIRECTORY, | 
|---|
| [809] | 115 | pathvar, filename, fbuf, CCHMAXPATH - 1)) | 
|---|
| [2] | 116 | *fbuf = 0; | 
|---|
|  | 117 | return fbuf; | 
|---|
|  | 118 | } | 
|---|
|  | 119 |  | 
|---|
| [551] | 120 | CHAR *searchpath(CHAR * filename) | 
|---|
|  | 121 | { | 
|---|
| [2] | 122 | CHAR *found; | 
|---|
|  | 123 |  | 
|---|
| [551] | 124 | if (!filename) | 
|---|
| [2] | 125 | return ""; | 
|---|
| [551] | 126 | found = searchapath("PATH", filename); | 
|---|
|  | 127 | if (!*found) { | 
|---|
|  | 128 | found = searchapath("DPATH", filename); | 
|---|
|  | 129 | if (!*found) | 
|---|
|  | 130 | found = searchapath("XPATH", filename); | 
|---|
| [2] | 131 | } | 
|---|
|  | 132 | return found; | 
|---|
|  | 133 | } | 
|---|
| [793] | 134 |  | 
|---|
|  | 135 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util) | 
|---|