source: trunk/dll/srchpath.c@ 1398

Last change on this file since 1398 was 1398, checked in by Gregg Young, 16 years ago

Move embeded strings to PCSZ variables or string table; Eliminate Error2 functions Runtime_Error with NULL format string returns "No data" error. Change declares from PSZ to PCSZ in functions where the variable isn't changed. Added btm as an executable file type in several additional places. Use fProtectOnly to prevent attempt to execute Dos and Win programs on "Protect only" installs in several additional places.

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