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