source: trunk/dll/srchpath.c@ 632

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

Move RunFM2Util from systemf.c to srchpath.c added error includes and header to srchpath.c

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: srchpath.c 632 2007-04-22 23:01:43Z 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
13***********************************************************************/
14#define INCL_WIN
15#define INCL_WINERRORS
16#define INCL_DOS
17#define INCL_DOSERRORS
18
19#include <os2.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23#include <stdarg.h>
24//#include <ctype.h>
25//#include <time.h>
26
27#include "fm3dll.h"
28#include "fm3dlg.h"
29#include "fm3str.h"
30
31static PSZ pszSrcFile = __FILE__;
32
33#pragma data_seg(DATA1)
34#pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
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 APIRET rc, ret = -1;
43
44 rc = DosSearchPath(SEARCH_IGNORENETERRS |SEARCH_ENVIRONMENT |
45 SEARCH_CUR_DIRECTORY,"PATH",
46 appname, fbuf, CCHMAXPATH - 1);
47 if (rc != 0) {
48 if (rc != 2){
49 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
50 "DosSearchPath", appname);
51 return ret;
52 }
53 else {
54 rc = DosSearchPath(0, "UTILS;..\\FM2Utils",
55 appname, fbuf, CCHMAXPATH - 1);
56 if (rc != 0 && rc != 2){
57 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
58 "DosSearchPath", appname);
59 return ret;
60 }
61 }
62 }
63 ret = runemf2(SEPARATE | WINDOWED,
64 HWND_DESKTOP,
65 NULL,
66 NULL,
67 "%s \"%s\"",
68 fbuf, filename);
69 return ret;
70}
71
72CHAR *first_path(CHAR * path, CHAR * ret)
73{
74
75 CHAR *p, *pp;
76
77 if (!path || !ret)
78 return ret;
79 strcpy(ret, path);
80 p = strchr(ret, ';');
81 if (p) {
82 *p = 0;
83 p++;
84 if (*ret == '.') { /* skip initial "cur dir" */
85 pp = strchr(p, ';');
86 if (pp)
87 *pp = 0;
88 if (*p)
89 memmove(ret, p, strlen(p) + 1);
90 }
91 }
92 return ret;
93}
94
95CHAR *searchapath(CHAR * path, CHAR * filename)
96{
97
98 static CHAR fbuf[CCHMAXPATH];
99
100 if (strchr(filename, '\\') || strchr(filename, '/')
101 || strchr(filename, ':')) {
102
103 FILESTATUS3 fsa;
104
105 if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
106 return filename;
107 *fbuf = 0;
108 return fbuf;
109 }
110 *fbuf = 0;
111 if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
112 SEARCH_CUR_DIRECTORY,
113 path, filename, fbuf, CCHMAXPATH - 1))
114 *fbuf = 0;
115 return fbuf;
116}
117
118CHAR *searchpath(CHAR * filename)
119{
120
121 CHAR *found;
122
123 if (!filename)
124 return "";
125 found = searchapath("PATH", filename);
126 if (!*found) {
127 found = searchapath("DPATH", filename);
128 if (!*found)
129 found = searchapath("XPATH", filename);
130 }
131 return found;
132}
Note: See TracBrowser for help on using the repository browser.