| [632] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: srchpath.c 1398 2009-02-21 17:43:00Z gyoung $ | 
|---|
|  | 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 | 
|---|
| [1241] | 14 | 04 Oct 08 JBS Make searchapath non-static | 
|---|
| [632] | 15 |  | 
|---|
|  | 16 | ***********************************************************************/ | 
|---|
| [907] | 17 |  | 
|---|
|  | 18 | #include <string.h> | 
|---|
|  | 19 |  | 
|---|
| [632] | 20 | #define INCL_WIN | 
|---|
| [2] | 21 | #define INCL_DOS | 
|---|
| [907] | 22 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| [2] | 23 |  | 
|---|
| [1212] | 24 | #include "fm3dll.h" | 
|---|
| [632] | 25 | #include "fm3dlg.h" | 
|---|
|  | 26 | #include "fm3str.h" | 
|---|
| [1241] | 27 | #include "srchpath.h" | 
|---|
| [907] | 28 | #include "pathutil.h"                   // BldQuotedFileName | 
|---|
|  | 29 | #include "errutil.h"                    // Dos_Error... | 
|---|
| [1184] | 30 | #include "systemf.h"                    // runemf2 | 
|---|
| [1212] | 31 | #include "notebook.h"                   // Data declaration(s) | 
|---|
| [1398] | 32 | #include "init.h"                       // Data declaration(s) | 
|---|
| [632] | 33 |  | 
|---|
|  | 34 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 35 |  | 
|---|
| [1184] | 36 | // static CHAR *first_path(CHAR * path, CHAR * ret); | 
|---|
|  | 37 |  | 
|---|
| [2] | 38 | #pragma data_seg(DATA1) | 
|---|
|  | 39 |  | 
|---|
| [632] | 40 | //== RunFM2Util() Find and run an app from the FM2utilities == | 
|---|
|  | 41 | //== Search PATH plus 2 default install dirs == | 
|---|
|  | 42 |  | 
|---|
| [1398] | 43 | INT RunFM2Util(PCSZ appname, CHAR *filename) | 
|---|
| [632] | 44 | { | 
|---|
|  | 45 | CHAR fbuf[CCHMAXPATH]; | 
|---|
| [891] | 46 | CHAR szQuotedFileName[CCHMAXPATH]; | 
|---|
| [632] | 47 | APIRET rc, ret = -1; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | rc = DosSearchPath(SEARCH_IGNORENETERRS |SEARCH_ENVIRONMENT | | 
|---|
| [1398] | 50 | SEARCH_CUR_DIRECTORY, PCSZ_PATH, | 
|---|
| [1321] | 51 | appname, (PBYTE)fbuf, CCHMAXPATH - 1); | 
|---|
| [632] | 52 | if (rc != 0) { | 
|---|
|  | 53 | if (rc != 2){ | 
|---|
|  | 54 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| [1398] | 55 | PCSZ_DOSSEARCHPATH, appname); | 
|---|
| [632] | 56 | return ret; | 
|---|
|  | 57 | } | 
|---|
|  | 58 | else { | 
|---|
|  | 59 | rc = DosSearchPath(0, "UTILS;..\\FM2Utils", | 
|---|
| [1321] | 60 | appname, (PBYTE)fbuf, CCHMAXPATH - 1); | 
|---|
| [632] | 61 | if (rc != 0 && rc != 2){ | 
|---|
|  | 62 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| [1398] | 63 | PCSZ_DOSSEARCHPATH, appname); | 
|---|
| [632] | 64 | return ret; | 
|---|
|  | 65 | } | 
|---|
|  | 66 | } | 
|---|
|  | 67 | } | 
|---|
|  | 68 | ret = runemf2(SEPARATE | WINDOWED, | 
|---|
| [888] | 69 | HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| [632] | 70 | NULL, | 
|---|
|  | 71 | NULL, | 
|---|
| [891] | 72 | "%s %s", | 
|---|
|  | 73 | fbuf, BldQuotedFileName(szQuotedFileName, filename)); | 
|---|
| [632] | 74 | return ret; | 
|---|
|  | 75 | } | 
|---|
|  | 76 |  | 
|---|
| [1193] | 77 | #if 0   // JBS  11 Sep 08 | 
|---|
| [551] | 78 | CHAR *first_path(CHAR * path, CHAR * ret) | 
|---|
|  | 79 | { | 
|---|
| [2] | 80 |  | 
|---|
| [551] | 81 | CHAR *p, *pp; | 
|---|
| [2] | 82 |  | 
|---|
| [551] | 83 | if (!path || !ret) | 
|---|
| [2] | 84 | return ret; | 
|---|
| [551] | 85 | strcpy(ret, path); | 
|---|
|  | 86 | p = strchr(ret, ';'); | 
|---|
|  | 87 | if (p) { | 
|---|
| [2] | 88 | *p = 0; | 
|---|
|  | 89 | p++; | 
|---|
| [551] | 90 | if (*ret == '.') {                  /* skip initial "cur dir" */ | 
|---|
|  | 91 | pp = strchr(p, ';'); | 
|---|
|  | 92 | if (pp) | 
|---|
|  | 93 | *pp = 0; | 
|---|
|  | 94 | if (*p) | 
|---|
|  | 95 | memmove(ret, p, strlen(p) + 1); | 
|---|
| [2] | 96 | } | 
|---|
|  | 97 | } | 
|---|
|  | 98 | return ret; | 
|---|
|  | 99 | } | 
|---|
| [1184] | 100 | #endif | 
|---|
| [2] | 101 |  | 
|---|
| [809] | 102 | /** | 
|---|
|  | 103 | * Search for file in name PATH env variable | 
|---|
|  | 104 | * 23 Aug 07 SHL fixme to be MT safe | 
|---|
|  | 105 | */ | 
|---|
|  | 106 |  | 
|---|
| [1398] | 107 | CHAR *searchapath(PCSZ pathvar, PCSZ filename) | 
|---|
| [551] | 108 | { | 
|---|
| [2] | 109 | static CHAR fbuf[CCHMAXPATH]; | 
|---|
|  | 110 |  | 
|---|
| [551] | 111 | if (strchr(filename, '\\') || strchr(filename, '/') | 
|---|
|  | 112 | || strchr(filename, ':')) { | 
|---|
| [2] | 113 |  | 
|---|
| [847] | 114 | FILESTATUS3 fsa; | 
|---|
| [2] | 115 |  | 
|---|
| [1398] | 116 | strcpy(fbuf, filename); | 
|---|
|  | 117 | if (!DosQueryPathInfo(fbuf, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa))) | 
|---|
|  | 118 | return fbuf; | 
|---|
| [2] | 119 | *fbuf = 0; | 
|---|
|  | 120 | return fbuf; | 
|---|
|  | 121 | } | 
|---|
|  | 122 | *fbuf = 0; | 
|---|
| [551] | 123 | if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | | 
|---|
|  | 124 | SEARCH_CUR_DIRECTORY, | 
|---|
| [1321] | 125 | pathvar, filename, (PBYTE)fbuf, CCHMAXPATH - 1)) | 
|---|
| [2] | 126 | *fbuf = 0; | 
|---|
|  | 127 | return fbuf; | 
|---|
|  | 128 | } | 
|---|
|  | 129 |  | 
|---|
| [1398] | 130 | CHAR *searchpath(PCSZ filename) | 
|---|
| [551] | 131 | { | 
|---|
| [2] | 132 | CHAR *found; | 
|---|
|  | 133 |  | 
|---|
| [551] | 134 | if (!filename) | 
|---|
| [2] | 135 | return ""; | 
|---|
| [1398] | 136 | found = searchapath(PCSZ_PATH, filename); | 
|---|
| [551] | 137 | if (!*found) { | 
|---|
|  | 138 | found = searchapath("DPATH", filename); | 
|---|
|  | 139 | if (!*found) | 
|---|
|  | 140 | found = searchapath("XPATH", filename); | 
|---|
| [2] | 141 | } | 
|---|
|  | 142 | return found; | 
|---|
|  | 143 | } | 
|---|
| [793] | 144 |  | 
|---|
|  | 145 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util) | 
|---|