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