source: trunk/dll/srchpath.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

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