[632] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: srchpath.c 1193 2008-09-11 11:08:14Z 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"
|
---|
[1184] | 28 | #include "systemf.h" // runemf2
|
---|
[907] | 29 | #include "fm3dll.h"
|
---|
[632] | 30 |
|
---|
| 31 | static PSZ pszSrcFile = __FILE__;
|
---|
| 32 |
|
---|
[1184] | 33 | // static CHAR *first_path(CHAR * path, CHAR * ret);
|
---|
| 34 | static CHAR *searchapath(CHAR * path, CHAR * filename);
|
---|
| 35 |
|
---|
[2] | 36 | #pragma data_seg(DATA1)
|
---|
| 37 |
|
---|
[632] | 38 | //== RunFM2Util() Find and run an app from the FM2utilities ==
|
---|
| 39 | //== Search PATH plus 2 default install dirs ==
|
---|
| 40 |
|
---|
| 41 | INT RunFM2Util(CHAR *appname, CHAR *filename)
|
---|
| 42 | {
|
---|
| 43 | CHAR fbuf[CCHMAXPATH];
|
---|
[891] | 44 | CHAR szQuotedFileName[CCHMAXPATH];
|
---|
[632] | 45 | APIRET rc, ret = -1;
|
---|
| 46 |
|
---|
| 47 | rc = DosSearchPath(SEARCH_IGNORENETERRS |SEARCH_ENVIRONMENT |
|
---|
| 48 | SEARCH_CUR_DIRECTORY,"PATH",
|
---|
| 49 | appname, fbuf, CCHMAXPATH - 1);
|
---|
| 50 | if (rc != 0) {
|
---|
| 51 | if (rc != 2){
|
---|
| 52 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
| 53 | "DosSearchPath", appname);
|
---|
| 54 | return ret;
|
---|
| 55 | }
|
---|
| 56 | else {
|
---|
| 57 | rc = DosSearchPath(0, "UTILS;..\\FM2Utils",
|
---|
| 58 | appname, fbuf, CCHMAXPATH - 1);
|
---|
| 59 | if (rc != 0 && rc != 2){
|
---|
| 60 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
| 61 | "DosSearchPath", appname);
|
---|
| 62 | return ret;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | ret = runemf2(SEPARATE | WINDOWED,
|
---|
[888] | 67 | HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
[632] | 68 | NULL,
|
---|
| 69 | NULL,
|
---|
[891] | 70 | "%s %s",
|
---|
| 71 | fbuf, BldQuotedFileName(szQuotedFileName, filename));
|
---|
[632] | 72 | return ret;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[1193] | 75 | #if 0 // JBS 11 Sep 08
|
---|
[551] | 76 | CHAR *first_path(CHAR * path, CHAR * ret)
|
---|
| 77 | {
|
---|
[2] | 78 |
|
---|
[551] | 79 | CHAR *p, *pp;
|
---|
[2] | 80 |
|
---|
[551] | 81 | if (!path || !ret)
|
---|
[2] | 82 | return ret;
|
---|
[551] | 83 | strcpy(ret, path);
|
---|
| 84 | p = strchr(ret, ';');
|
---|
| 85 | if (p) {
|
---|
[2] | 86 | *p = 0;
|
---|
| 87 | p++;
|
---|
[551] | 88 | if (*ret == '.') { /* skip initial "cur dir" */
|
---|
| 89 | pp = strchr(p, ';');
|
---|
| 90 | if (pp)
|
---|
| 91 | *pp = 0;
|
---|
| 92 | if (*p)
|
---|
| 93 | memmove(ret, p, strlen(p) + 1);
|
---|
[2] | 94 | }
|
---|
| 95 | }
|
---|
| 96 | return ret;
|
---|
| 97 | }
|
---|
[1184] | 98 | #endif
|
---|
[2] | 99 |
|
---|
[809] | 100 | /**
|
---|
| 101 | * Search for file in name PATH env variable
|
---|
| 102 | * 23 Aug 07 SHL fixme to be MT safe
|
---|
| 103 | */
|
---|
| 104 |
|
---|
| 105 | CHAR *searchapath(CHAR *pathvar, CHAR *filename)
|
---|
[551] | 106 | {
|
---|
[2] | 107 | static CHAR fbuf[CCHMAXPATH];
|
---|
| 108 |
|
---|
[551] | 109 | if (strchr(filename, '\\') || strchr(filename, '/')
|
---|
| 110 | || strchr(filename, ':')) {
|
---|
[2] | 111 |
|
---|
[847] | 112 | FILESTATUS3 fsa;
|
---|
[2] | 113 |
|
---|
[847] | 114 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
|
---|
[2] | 115 | return filename;
|
---|
| 116 | *fbuf = 0;
|
---|
| 117 | return fbuf;
|
---|
| 118 | }
|
---|
| 119 | *fbuf = 0;
|
---|
[551] | 120 | if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
|
---|
| 121 | SEARCH_CUR_DIRECTORY,
|
---|
[809] | 122 | pathvar, filename, fbuf, CCHMAXPATH - 1))
|
---|
[2] | 123 | *fbuf = 0;
|
---|
| 124 | return fbuf;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[551] | 127 | CHAR *searchpath(CHAR * filename)
|
---|
| 128 | {
|
---|
[2] | 129 | CHAR *found;
|
---|
| 130 |
|
---|
[551] | 131 | if (!filename)
|
---|
[2] | 132 | return "";
|
---|
[551] | 133 | found = searchapath("PATH", filename);
|
---|
| 134 | if (!*found) {
|
---|
| 135 | found = searchapath("DPATH", filename);
|
---|
| 136 | if (!*found)
|
---|
| 137 | found = searchapath("XPATH", filename);
|
---|
[2] | 138 | }
|
---|
| 139 | return found;
|
---|
| 140 | }
|
---|
[793] | 141 |
|
---|
| 142 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
|
---|