source: trunk/dll/srchpath.c@ 1750

Last change on this file since 1750 was 1750, checked in by John Small, 11 years ago

Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.

So calls to these functions, direct and indirect, had to be changed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: srchpath.c 1750 2014-03-01 13:55:57Z jbs $
5
6 Path search functions
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2003, 2010 Steven H. Levine
10
11 22 Apr 07 GKY Add RunFM2Util to find and run apps from the FM2Utilities
12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
13 23 Aug 07 SHL Comments
14 04 Oct 08 JBS Make searchapath non-static
15 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
16 01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
17
18***********************************************************************/
19
20#include <string.h>
21
22#define INCL_WIN
23#define INCL_DOS
24#define INCL_DOSERRORS
25#define INCL_LONGLONG // dircnrs.h
26
27#include "fm3dll.h"
28#include "fm3dlg.h"
29#include "fm3str.h"
30#include "srchpath.h"
31#include "pathutil.h" // BldQuotedFileName
32#include "errutil.h" // Dos_Error...
33#include "systemf.h" // runemf2
34#include "notebook.h" // Data declaration(s)
35#include "init.h" // Data declaration(s)
36
37static PSZ pszSrcFile = __FILE__;
38
39// static CHAR *first_path(CHAR * path, CHAR * ret);
40
41#pragma data_seg(DATA1)
42
43//== RunFM2Util() Find and run an app from the FM2utilities ==
44//== Search PATH plus 2 default install dirs ==
45
46INT RunFM2Util(PCSZ appname, CHAR *filename)
47{
48 CHAR fbuf[CCHMAXPATH];
49 CHAR szQuotedFileName[CCHMAXPATH];
50 APIRET rc, ret = -1;
51
52 rc = DosSearchPath(SEARCH_IGNORENETERRS |SEARCH_ENVIRONMENT |
53 SEARCH_CUR_DIRECTORY, (CHAR *) PCSZ_PATH,
54 (CHAR *) appname, (PBYTE)fbuf, CCHMAXPATH - 1);
55 if (rc != 0) {
56 if (rc != 2){
57 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
58 PCSZ_DOSSEARCHPATH, appname);
59 return ret;
60 }
61 else {
62 rc = DosSearchPath(0, "UTILS;..\\FM2Utils",
63 (CHAR *) appname, (PBYTE)fbuf, CCHMAXPATH - 1);
64 if (rc != 0 && rc != 2){
65 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
66 PCSZ_DOSSEARCHPATH, appname);
67 return ret;
68 }
69 }
70 }
71 ret = runemf2(SEPARATE | WINDOWED,
72 HWND_DESKTOP, pszSrcFile, __LINE__,
73 NULL,
74 NULL,
75 "%s %s",
76 fbuf, BldQuotedFileName(szQuotedFileName, filename));
77 return ret;
78}
79
80#if 0 // JBS 11 Sep 08
81CHAR *first_path(CHAR * path, CHAR * ret)
82{
83
84 CHAR *p, *pp;
85
86 if (!path || !ret)
87 return ret;
88 strcpy(ret, path);
89 p = strchr(ret, ';');
90 if (p) {
91 *p = 0;
92 p++;
93 if (*ret == '.') { // skip initial "cur dir"
94 pp = strchr(p, ';');
95 if (pp)
96 *pp = 0;
97 if (*p)
98 memmove(ret, p, strlen(p) + 1);
99 }
100 }
101 return ret;
102}
103#endif
104
105/**
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 *
122 */
123APIRET SearchPathForFile(PCSZ pPathname,
124 PCSZ pFilename,
125 PCHAR pFullFilename)
126{
127 APIRET rc;
128 CHAR szFullFilename[CCHMAXPATH];
129
130 if (!pPathname || !*pPathname || !pFilename || !*pFilename)
131 return ERROR_INVALID_PARAMETER;
132
133 if (strchr(pFilename, '\\') || strchr(pFilename, '/')
134 || strchr(pFilename, ':')) {
135 rc = DosQueryPathInfo(pFilename, FIL_QUERYFULLNAME,
136 (PVOID)szFullFilename, (ULONG) CCHMAXPATH-1);
137 }
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;
150}
151
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 */
167APIRET SearchMultiplePathsForFile(PCSZ pFilename,
168 PSZ pFullFilename)
169{
170 APIRET rc;
171
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);
183 }
184 return rc;
185}
186
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)
Note: See TracBrowser for help on using the repository browser.