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
RevLine 
[632]1
2/***********************************************************************
3
4 $Id: srchpath.c 1161 2008-09-05 21:42:27Z jbs $
5
[809]6 Path search functions
[632]7
8 Copyright (c) 1993-98 M. Kimes
[907]9 Copyright (c) 2003, 2008 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***********************************************************************/
[907]16
17#include <string.h>
18
[632]19#define INCL_WIN
[2]20#define INCL_DOS
[907]21#define INCL_LONGLONG // dircnrs.h
[2]22
[632]23#include "fm3dlg.h"
24#include "fm3str.h"
[907]25#include "pathutil.h" // BldQuotedFileName
26#include "errutil.h" // Dos_Error...
[1161]27#include "srchpath.h"
[907]28#include "fm3dll.h"
[632]29
30static PSZ pszSrcFile = __FILE__;
31
[2]32#pragma data_seg(DATA1)
33
[632]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];
[891]40 CHAR szQuotedFileName[CCHMAXPATH];
[632]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,
[888]63 HWND_DESKTOP, pszSrcFile, __LINE__,
[632]64 NULL,
65 NULL,
[891]66 "%s %s",
67 fbuf, BldQuotedFileName(szQuotedFileName, filename));
[632]68 return ret;
69}
70
[551]71CHAR *first_path(CHAR * path, CHAR * ret)
72{
[2]73
[551]74 CHAR *p, *pp;
[2]75
[551]76 if (!path || !ret)
[2]77 return ret;
[551]78 strcpy(ret, path);
79 p = strchr(ret, ';');
80 if (p) {
[2]81 *p = 0;
82 p++;
[551]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);
[2]89 }
90 }
91 return ret;
92}
93
[809]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)
[551]100{
[2]101 static CHAR fbuf[CCHMAXPATH];
102
[551]103 if (strchr(filename, '\\') || strchr(filename, '/')
104 || strchr(filename, ':')) {
[2]105
[847]106 FILESTATUS3 fsa;
[2]107
[847]108 if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
[2]109 return filename;
110 *fbuf = 0;
111 return fbuf;
112 }
113 *fbuf = 0;
[551]114 if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
115 SEARCH_CUR_DIRECTORY,
[809]116 pathvar, filename, fbuf, CCHMAXPATH - 1))
[2]117 *fbuf = 0;
118 return fbuf;
119}
120
[551]121CHAR *searchpath(CHAR * filename)
122{
[2]123 CHAR *found;
124
[551]125 if (!filename)
[2]126 return "";
[551]127 found = searchapath("PATH", filename);
128 if (!*found) {
129 found = searchapath("DPATH", filename);
130 if (!*found)
131 found = searchapath("XPATH", filename);
[2]132 }
133 return found;
134}
[793]135
136#pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
Note: See TracBrowser for help on using the repository browser.