source: trunk/dll/srchpath.c@ 793

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

Move #pragma alloc_text to end for OpenWatcom compat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
RevLine 
[632]1
2/***********************************************************************
3
4 $Id: srchpath.c 793 2007-08-21 02:53:38Z 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
[793]12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[632]13
14***********************************************************************/
15#define INCL_WIN
16#define INCL_WINERRORS
[2]17#define INCL_DOS
[632]18#define INCL_DOSERRORS
[2]19
20#include <os2.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
[632]24#include <stdarg.h>
[2]25
[632]26#include "fm3dll.h"
27#include "fm3dlg.h"
28#include "fm3str.h"
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];
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,
63 NULL,
64 NULL,
65 "%s \"%s\"",
66 fbuf, filename);
67 return ret;
68}
69
[551]70CHAR *first_path(CHAR * path, CHAR * ret)
71{
[2]72
[551]73 CHAR *p, *pp;
[2]74
[551]75 if (!path || !ret)
[2]76 return ret;
[551]77 strcpy(ret, path);
78 p = strchr(ret, ';');
79 if (p) {
[2]80 *p = 0;
81 p++;
[551]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);
[2]88 }
89 }
90 return ret;
91}
92
[551]93CHAR *searchapath(CHAR * path, CHAR * filename)
94{
[2]95
96 static CHAR fbuf[CCHMAXPATH];
97
[551]98 if (strchr(filename, '\\') || strchr(filename, '/')
99 || strchr(filename, ':')) {
[2]100
101 FILESTATUS3 fsa;
102
[551]103 if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
[2]104 return filename;
105 *fbuf = 0;
106 return fbuf;
107 }
108 *fbuf = 0;
[551]109 if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
110 SEARCH_CUR_DIRECTORY,
111 path, filename, fbuf, CCHMAXPATH - 1))
[2]112 *fbuf = 0;
113 return fbuf;
114}
115
[551]116CHAR *searchpath(CHAR * filename)
117{
[2]118
119 CHAR *found;
120
[551]121 if (!filename)
[2]122 return "";
[551]123 found = searchapath("PATH", filename);
124 if (!*found) {
125 found = searchapath("DPATH", filename);
126 if (!*found)
127 found = searchapath("XPATH", filename);
[2]128 }
129 return found;
130}
[793]131
132#pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
Note: See TracBrowser for help on using the repository browser.