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