[632] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: srchpath.c 1750 2014-03-01 13:55:57Z jbs $
|
---|
| 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 *.
|
---|
[1750] | 16 | 01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
|
---|
[632] | 17 |
|
---|
| 18 | ***********************************************************************/
|
---|
[907] | 19 |
|
---|
| 20 | #include <string.h>
|
---|
| 21 |
|
---|
[632] | 22 | #define INCL_WIN
|
---|
[2] | 23 | #define INCL_DOS
|
---|
[1750] | 24 | #define INCL_DOSERRORS
|
---|
[907] | 25 | #define INCL_LONGLONG // dircnrs.h
|
---|
[2] | 26 |
|
---|
[1212] | 27 | #include "fm3dll.h"
|
---|
[632] | 28 | #include "fm3dlg.h"
|
---|
| 29 | #include "fm3str.h"
|
---|
[1241] | 30 | #include "srchpath.h"
|
---|
[907] | 31 | #include "pathutil.h" // BldQuotedFileName
|
---|
| 32 | #include "errutil.h" // Dos_Error...
|
---|
[1184] | 33 | #include "systemf.h" // runemf2
|
---|
[1212] | 34 | #include "notebook.h" // Data declaration(s)
|
---|
[1398] | 35 | #include "init.h" // Data declaration(s)
|
---|
[632] | 36 |
|
---|
| 37 | static PSZ pszSrcFile = __FILE__;
|
---|
| 38 |
|
---|
[1184] | 39 | // static CHAR *first_path(CHAR * path, CHAR * ret);
|
---|
| 40 |
|
---|
[2] | 41 | #pragma data_seg(DATA1)
|
---|
| 42 |
|
---|
[632] | 43 | //== RunFM2Util() Find and run an app from the FM2utilities ==
|
---|
| 44 | //== Search PATH plus 2 default install dirs ==
|
---|
| 45 |
|
---|
[1398] | 46 | INT RunFM2Util(PCSZ appname, CHAR *filename)
|
---|
[632] | 47 | {
|
---|
| 48 | CHAR fbuf[CCHMAXPATH];
|
---|
[891] | 49 | CHAR szQuotedFileName[CCHMAXPATH];
|
---|
[632] | 50 | APIRET rc, ret = -1;
|
---|
| 51 |
|
---|
| 52 | rc = DosSearchPath(SEARCH_IGNORENETERRS |SEARCH_ENVIRONMENT |
|
---|
[1498] | 53 | SEARCH_CUR_DIRECTORY, (CHAR *) PCSZ_PATH,
|
---|
| 54 | (CHAR *) appname, (PBYTE)fbuf, CCHMAXPATH - 1);
|
---|
[632] | 55 | if (rc != 0) {
|
---|
| 56 | if (rc != 2){
|
---|
| 57 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
[1398] | 58 | PCSZ_DOSSEARCHPATH, appname);
|
---|
[632] | 59 | return ret;
|
---|
| 60 | }
|
---|
| 61 | else {
|
---|
| 62 | rc = DosSearchPath(0, "UTILS;..\\FM2Utils",
|
---|
[1498] | 63 | (CHAR *) appname, (PBYTE)fbuf, CCHMAXPATH - 1);
|
---|
[632] | 64 | if (rc != 0 && rc != 2){
|
---|
| 65 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
[1398] | 66 | PCSZ_DOSSEARCHPATH, appname);
|
---|
[632] | 67 | return ret;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | ret = runemf2(SEPARATE | WINDOWED,
|
---|
[888] | 72 | HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
[632] | 73 | NULL,
|
---|
| 74 | NULL,
|
---|
[891] | 75 | "%s %s",
|
---|
| 76 | fbuf, BldQuotedFileName(szQuotedFileName, filename));
|
---|
[632] | 77 | return ret;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[1193] | 80 | #if 0 // JBS 11 Sep 08
|
---|
[551] | 81 | CHAR *first_path(CHAR * path, CHAR * ret)
|
---|
| 82 | {
|
---|
[2] | 83 |
|
---|
[551] | 84 | CHAR *p, *pp;
|
---|
[2] | 85 |
|
---|
[551] | 86 | if (!path || !ret)
|
---|
[2] | 87 | return ret;
|
---|
[551] | 88 | strcpy(ret, path);
|
---|
| 89 | p = strchr(ret, ';');
|
---|
| 90 | if (p) {
|
---|
[2] | 91 | *p = 0;
|
---|
| 92 | p++;
|
---|
[1673] | 93 | if (*ret == '.') { // skip initial "cur dir"
|
---|
[551] | 94 | pp = strchr(p, ';');
|
---|
| 95 | if (pp)
|
---|
| 96 | *pp = 0;
|
---|
| 97 | if (*p)
|
---|
| 98 | memmove(ret, p, strlen(p) + 1);
|
---|
[2] | 99 | }
|
---|
| 100 | }
|
---|
| 101 | return ret;
|
---|
| 102 | }
|
---|
[1184] | 103 | #endif
|
---|
[2] | 104 |
|
---|
[809] | 105 | /**
|
---|
[1750] | 106 | * SearchPathForFile: Search for a file along a path
|
---|
| 107 | *
|
---|
| 108 | * @param pPathname: the name of a path environment variable (input)
|
---|
| 109 | * Used only if pFilename has no directory separators or ':' for a drive sepcification
|
---|
| 110 | *
|
---|
| 111 | * @param pFilename: the name of a file to search for (input)
|
---|
| 112 | * If the file name includes a directory separator or the ':' for a drive specification then
|
---|
| 113 | * DosQueryPathInfo is used for the search
|
---|
| 114 | * else
|
---|
| 115 | * DosSearchPath is used, along with the pPathname parameter
|
---|
| 116 | *
|
---|
| 117 | * @param pFullFilename: address of where to place fully-qulified name if search succeeds (output)
|
---|
| 118 | * This parameter may be NULL if the fully-qualified filename is not desired.
|
---|
| 119 | *
|
---|
| 120 | * @return Return code from call to DosQueryPathInfo/DosSearchPath
|
---|
| 121 | *
|
---|
[809] | 122 | */
|
---|
[1750] | 123 | APIRET SearchPathForFile(PCSZ pPathname,
|
---|
| 124 | PCSZ pFilename,
|
---|
| 125 | PCHAR pFullFilename)
|
---|
[551] | 126 | {
|
---|
[1750] | 127 | APIRET rc;
|
---|
| 128 | CHAR szFullFilename[CCHMAXPATH];
|
---|
[2] | 129 |
|
---|
[1750] | 130 | if (!pPathname || !*pPathname || !pFilename || !*pFilename)
|
---|
| 131 | return ERROR_INVALID_PARAMETER;
|
---|
[2] | 132 |
|
---|
[1750] | 133 | if (strchr(pFilename, '\\') || strchr(pFilename, '/')
|
---|
| 134 | || strchr(pFilename, ':')) {
|
---|
| 135 | rc = DosQueryPathInfo(pFilename, FIL_QUERYFULLNAME,
|
---|
| 136 | (PVOID)szFullFilename, (ULONG) CCHMAXPATH-1);
|
---|
[2] | 137 | }
|
---|
[1750] | 138 | else {
|
---|
| 139 | rc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
|
---|
| 140 | SEARCH_CUR_DIRECTORY,
|
---|
| 141 | (CHAR *) pPathname,
|
---|
| 142 | (CHAR *) pFilename,
|
---|
| 143 | (PBYTE) szFullFilename,
|
---|
| 144 | CCHMAXPATH - 1);
|
---|
| 145 | }
|
---|
| 146 | if (!rc && pFullFilename) {
|
---|
| 147 | strcpy(pFullFilename, szFullFilename);
|
---|
| 148 | }
|
---|
| 149 | return rc;
|
---|
[2] | 150 | }
|
---|
| 151 |
|
---|
[1750] | 152 | /**
|
---|
| 153 | * SearchMultiplePathsForFile: Search for a file along multiple paths.
|
---|
| 154 | * Currently these paths are hard-coded to: PATH, DPATH and XPATH.
|
---|
| 155 | *
|
---|
| 156 | * @param pFilename: the name of a file to search for (input)
|
---|
| 157 | *
|
---|
| 158 | * @param pFullFilename: address of where to place fully-qulified name if search succeeds (output)
|
---|
| 159 | * This parameter may be NULL if the fully-qualified filename is not desired.
|
---|
| 160 | *
|
---|
| 161 | * @return Return code from call to SearchPathForFile (DosQueryPathInfo/DosSearchPath)
|
---|
| 162 | *
|
---|
| 163 | * @note: The code uses DosSearchPathForFile for all searches. First it searches PATH.
|
---|
| 164 | * If this fails it searches DPATH. If this fails it seaches XPATH.
|
---|
| 165 | *
|
---|
| 166 | */
|
---|
| 167 | APIRET SearchMultiplePathsForFile(PCSZ pFilename,
|
---|
| 168 | PSZ pFullFilename)
|
---|
[551] | 169 | {
|
---|
[1750] | 170 | APIRET rc;
|
---|
[2] | 171 |
|
---|
[1750] | 172 | rc = SearchPathForFile(PCSZ_PATH,
|
---|
| 173 | pFilename,
|
---|
| 174 | pFullFilename);
|
---|
| 175 | if (rc && rc != ERROR_INVALID_PARAMETER) {
|
---|
| 176 | rc = SearchPathForFile("DPATH",
|
---|
| 177 | pFilename,
|
---|
| 178 | pFullFilename);
|
---|
| 179 | if (rc && rc != ERROR_INVALID_PARAMETER)
|
---|
| 180 | rc = SearchPathForFile("XPATH",
|
---|
| 181 | pFilename,
|
---|
| 182 | pFullFilename);
|
---|
[2] | 183 | }
|
---|
[1750] | 184 | return rc;
|
---|
[2] | 185 | }
|
---|
[793] | 186 |
|
---|
[1750] | 187 | //#pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
|
---|
| 188 | // jbs: first_path seems to be unused
|
---|
| 189 | #pragma alloc_text(MISC9,first_path,SearchPathForFile,SearchMultiplePathsForFile,RunFM2Util)
|
---|