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
RevLine 
[632]1
2/***********************************************************************
3
4 $Id: srchpath.c 891 2007-12-28 19:16:11Z gyoung $
5
[809]6 Path search functions
[632]7
8 Copyright (c) 1993-98 M. Kimes
[809]9 Copyright (c) 2003, 2007 Steven H. Levine
[632]10
11 22 Apr 07 GKY Add RunFM2Util to find and run apps from the FM2Utilities
[793]12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[809]13 23 Aug 07 SHL Comments
[632]14
15***********************************************************************/
16#define INCL_WIN
17#define INCL_WINERRORS
[2]18#define INCL_DOS
[632]19#define INCL_DOSERRORS
[841]20#define INCL_LONGLONG
[2]21
22#include <os2.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
[632]26#include <stdarg.h>
[2]27
[632]28#include "fm3dll.h"
29#include "fm3dlg.h"
30#include "fm3str.h"
31
32static PSZ pszSrcFile = __FILE__;
33
[2]34#pragma data_seg(DATA1)
35
[632]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];
[891]42 CHAR szQuotedFileName[CCHMAXPATH];
[632]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,
[888]65 HWND_DESKTOP, pszSrcFile, __LINE__,
[632]66 NULL,
67 NULL,
[891]68 "%s %s",
69 fbuf, BldQuotedFileName(szQuotedFileName, filename));
[632]70 return ret;
71}
72
[551]73CHAR *first_path(CHAR * path, CHAR * ret)
74{
[2]75
[551]76 CHAR *p, *pp;
[2]77
[551]78 if (!path || !ret)
[2]79 return ret;
[551]80 strcpy(ret, path);
81 p = strchr(ret, ';');
82 if (p) {
[2]83 *p = 0;
84 p++;
[551]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);
[2]91 }
92 }
93 return ret;
94}
95
[809]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)
[551]102{
[2]103 static CHAR fbuf[CCHMAXPATH];
104
[551]105 if (strchr(filename, '\\') || strchr(filename, '/')
106 || strchr(filename, ':')) {
[2]107
[847]108 FILESTATUS3 fsa;
[2]109
[847]110 if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
[2]111 return filename;
112 *fbuf = 0;
113 return fbuf;
114 }
115 *fbuf = 0;
[551]116 if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
117 SEARCH_CUR_DIRECTORY,
[809]118 pathvar, filename, fbuf, CCHMAXPATH - 1))
[2]119 *fbuf = 0;
120 return fbuf;
121}
122
[551]123CHAR *searchpath(CHAR * filename)
124{
[2]125 CHAR *found;
126
[551]127 if (!filename)
[2]128 return "";
[551]129 found = searchapath("PATH", filename);
130 if (!*found) {
131 found = searchapath("DPATH", filename);
132 if (!*found)
133 found = searchapath("XPATH", filename);
[2]134 }
135 return found;
136}
[793]137
138#pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
Note: See TracBrowser for help on using the repository browser.