| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: srchpath.c 1241 2008-10-09 11:12:04Z 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 |   04 Oct 08 JBS Make searchapath non-static
 | 
|---|
| 15 | 
 | 
|---|
| 16 | ***********************************************************************/
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <string.h>
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #define INCL_WIN
 | 
|---|
| 21 | #define INCL_DOS
 | 
|---|
| 22 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "fm3dll.h"
 | 
|---|
| 25 | #include "fm3dlg.h"
 | 
|---|
| 26 | #include "fm3str.h"
 | 
|---|
| 27 | #include "srchpath.h"
 | 
|---|
| 28 | #include "pathutil.h"                   // BldQuotedFileName
 | 
|---|
| 29 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 30 | #include "systemf.h"                    // runemf2
 | 
|---|
| 31 | #include "notebook.h"                   // Data declaration(s)
 | 
|---|
| 32 | 
 | 
|---|
| 33 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
| 34 | 
 | 
|---|
| 35 | // static CHAR *first_path(CHAR * path, CHAR * ret);
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #pragma data_seg(DATA1)
 | 
|---|
| 38 | 
 | 
|---|
| 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];
 | 
|---|
| 45 |     CHAR szQuotedFileName[CCHMAXPATH];
 | 
|---|
| 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,
 | 
|---|
| 68 |                   HWND_DESKTOP, pszSrcFile, __LINE__,
 | 
|---|
| 69 |                   NULL,
 | 
|---|
| 70 |                   NULL,
 | 
|---|
| 71 |                   "%s %s",
 | 
|---|
| 72 |                   fbuf, BldQuotedFileName(szQuotedFileName, filename));
 | 
|---|
| 73 |     return ret;
 | 
|---|
| 74 | }
 | 
|---|
| 75 | 
 | 
|---|
| 76 | #if 0   // JBS  11 Sep 08
 | 
|---|
| 77 | CHAR *first_path(CHAR * path, CHAR * ret)
 | 
|---|
| 78 | {
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   CHAR *p, *pp;
 | 
|---|
| 81 | 
 | 
|---|
| 82 |   if (!path || !ret)
 | 
|---|
| 83 |     return ret;
 | 
|---|
| 84 |   strcpy(ret, path);
 | 
|---|
| 85 |   p = strchr(ret, ';');
 | 
|---|
| 86 |   if (p) {
 | 
|---|
| 87 |     *p = 0;
 | 
|---|
| 88 |     p++;
 | 
|---|
| 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);
 | 
|---|
| 95 |     }
 | 
|---|
| 96 |   }
 | 
|---|
| 97 |   return ret;
 | 
|---|
| 98 | }
 | 
|---|
| 99 | #endif
 | 
|---|
| 100 | 
 | 
|---|
| 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)
 | 
|---|
| 107 | {
 | 
|---|
| 108 |   static CHAR fbuf[CCHMAXPATH];
 | 
|---|
| 109 | 
 | 
|---|
| 110 |   if (strchr(filename, '\\') || strchr(filename, '/')
 | 
|---|
| 111 |       || strchr(filename, ':')) {
 | 
|---|
| 112 | 
 | 
|---|
| 113 |     FILESTATUS3 fsa;
 | 
|---|
| 114 | 
 | 
|---|
| 115 |     if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
 | 
|---|
| 116 |       return filename;
 | 
|---|
| 117 |     *fbuf = 0;
 | 
|---|
| 118 |     return fbuf;
 | 
|---|
| 119 |   }
 | 
|---|
| 120 |   *fbuf = 0;
 | 
|---|
| 121 |   if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
 | 
|---|
| 122 |                     SEARCH_CUR_DIRECTORY,
 | 
|---|
| 123 |                     pathvar, filename, fbuf, CCHMAXPATH - 1))
 | 
|---|
| 124 |     *fbuf = 0;
 | 
|---|
| 125 |   return fbuf;
 | 
|---|
| 126 | }
 | 
|---|
| 127 | 
 | 
|---|
| 128 | CHAR *searchpath(CHAR * filename)
 | 
|---|
| 129 | {
 | 
|---|
| 130 |   CHAR *found;
 | 
|---|
| 131 | 
 | 
|---|
| 132 |   if (!filename)
 | 
|---|
| 133 |     return "";
 | 
|---|
| 134 |   found = searchapath("PATH", filename);
 | 
|---|
| 135 |   if (!*found) {
 | 
|---|
| 136 |     found = searchapath("DPATH", filename);
 | 
|---|
| 137 |     if (!*found)
 | 
|---|
| 138 |       found = searchapath("XPATH", filename);
 | 
|---|
| 139 |   }
 | 
|---|
| 140 |   return found;
 | 
|---|
| 141 | }
 | 
|---|
| 142 | 
 | 
|---|
| 143 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
 | 
|---|