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