| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: srchpath.c 1193 2008-09-11 11:08:14Z jbs $
|
|---|
| 5 |
|
|---|
| 6 | Path search functions
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2003, 2008 Steven H. Levine
|
|---|
| 10 |
|
|---|
| 11 | 22 Apr 07 GKY Add RunFM2Util to find and run apps from the FM2Utilities
|
|---|
| 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 13 | 23 Aug 07 SHL Comments
|
|---|
| 14 |
|
|---|
| 15 | ***********************************************************************/
|
|---|
| 16 |
|
|---|
| 17 | #include <string.h>
|
|---|
| 18 |
|
|---|
| 19 | #define INCL_WIN
|
|---|
| 20 | #define INCL_DOS
|
|---|
| 21 | #define INCL_LONGLONG // dircnrs.h
|
|---|
| 22 |
|
|---|
| 23 | #include "fm3dlg.h"
|
|---|
| 24 | #include "fm3str.h"
|
|---|
| 25 | #include "pathutil.h" // BldQuotedFileName
|
|---|
| 26 | #include "errutil.h" // Dos_Error...
|
|---|
| 27 | #include "srchpath.h"
|
|---|
| 28 | #include "systemf.h" // runemf2
|
|---|
| 29 | #include "fm3dll.h"
|
|---|
| 30 |
|
|---|
| 31 | static PSZ pszSrcFile = __FILE__;
|
|---|
| 32 |
|
|---|
| 33 | // static CHAR *first_path(CHAR * path, CHAR * ret);
|
|---|
| 34 | static CHAR *searchapath(CHAR * path, CHAR * filename);
|
|---|
| 35 |
|
|---|
| 36 | #pragma data_seg(DATA1)
|
|---|
| 37 |
|
|---|
| 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];
|
|---|
| 44 | CHAR szQuotedFileName[CCHMAXPATH];
|
|---|
| 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,
|
|---|
| 67 | HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 68 | NULL,
|
|---|
| 69 | NULL,
|
|---|
| 70 | "%s %s",
|
|---|
| 71 | fbuf, BldQuotedFileName(szQuotedFileName, filename));
|
|---|
| 72 | return ret;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | #if 0 // JBS 11 Sep 08
|
|---|
| 76 | CHAR *first_path(CHAR * path, CHAR * ret)
|
|---|
| 77 | {
|
|---|
| 78 |
|
|---|
| 79 | CHAR *p, *pp;
|
|---|
| 80 |
|
|---|
| 81 | if (!path || !ret)
|
|---|
| 82 | return ret;
|
|---|
| 83 | strcpy(ret, path);
|
|---|
| 84 | p = strchr(ret, ';');
|
|---|
| 85 | if (p) {
|
|---|
| 86 | *p = 0;
|
|---|
| 87 | p++;
|
|---|
| 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);
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 | return ret;
|
|---|
| 97 | }
|
|---|
| 98 | #endif
|
|---|
| 99 |
|
|---|
| 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)
|
|---|
| 106 | {
|
|---|
| 107 | static CHAR fbuf[CCHMAXPATH];
|
|---|
| 108 |
|
|---|
| 109 | if (strchr(filename, '\\') || strchr(filename, '/')
|
|---|
| 110 | || strchr(filename, ':')) {
|
|---|
| 111 |
|
|---|
| 112 | FILESTATUS3 fsa;
|
|---|
| 113 |
|
|---|
| 114 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
|
|---|
| 115 | return filename;
|
|---|
| 116 | *fbuf = 0;
|
|---|
| 117 | return fbuf;
|
|---|
| 118 | }
|
|---|
| 119 | *fbuf = 0;
|
|---|
| 120 | if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
|
|---|
| 121 | SEARCH_CUR_DIRECTORY,
|
|---|
| 122 | pathvar, filename, fbuf, CCHMAXPATH - 1))
|
|---|
| 123 | *fbuf = 0;
|
|---|
| 124 | return fbuf;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | CHAR *searchpath(CHAR * filename)
|
|---|
| 128 | {
|
|---|
| 129 | CHAR *found;
|
|---|
| 130 |
|
|---|
| 131 | if (!filename)
|
|---|
| 132 | return "";
|
|---|
| 133 | found = searchapath("PATH", filename);
|
|---|
| 134 | if (!*found) {
|
|---|
| 135 | found = searchapath("DPATH", filename);
|
|---|
| 136 | if (!*found)
|
|---|
| 137 | found = searchapath("XPATH", filename);
|
|---|
| 138 | }
|
|---|
| 139 | return found;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
|
|---|