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