source: trunk/dll/srchpath.c@ 1161

Last change on this file since 1161 was 1161, checked in by John Small, 17 years ago

Ticket 187: Draft 1: Functions only

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