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