source: trunk/dll/srchpath.c@ 897

Last change on this file since 897 was 891, checked in by Gregg Young, 18 years ago

Additional argument quoting checks

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