[632] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: srchpath.c 632 2007-04-22 23:01:43Z 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 |
|
---|
| 13 | ***********************************************************************/
|
---|
| 14 | #define INCL_WIN
|
---|
| 15 | #define INCL_WINERRORS
|
---|
[2] | 16 | #define INCL_DOS
|
---|
[632] | 17 | #define INCL_DOSERRORS
|
---|
[2] | 18 |
|
---|
| 19 | #include <os2.h>
|
---|
| 20 | #include <stdlib.h>
|
---|
| 21 | #include <stdio.h>
|
---|
| 22 | #include <string.h>
|
---|
[632] | 23 | #include <stdarg.h>
|
---|
| 24 | //#include <ctype.h>
|
---|
| 25 | //#include <time.h>
|
---|
[2] | 26 |
|
---|
[632] | 27 | #include "fm3dll.h"
|
---|
| 28 | #include "fm3dlg.h"
|
---|
| 29 | #include "fm3str.h"
|
---|
| 30 |
|
---|
| 31 | static PSZ pszSrcFile = __FILE__;
|
---|
| 32 |
|
---|
[2] | 33 | #pragma data_seg(DATA1)
|
---|
[632] | 34 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
|
---|
[2] | 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 |
|
---|
[551] | 95 | CHAR *searchapath(CHAR * path, CHAR * filename)
|
---|
| 96 | {
|
---|
[2] | 97 |
|
---|
| 98 | static CHAR fbuf[CCHMAXPATH];
|
---|
| 99 |
|
---|
[551] | 100 | if (strchr(filename, '\\') || strchr(filename, '/')
|
---|
| 101 | || strchr(filename, ':')) {
|
---|
[2] | 102 |
|
---|
| 103 | FILESTATUS3 fsa;
|
---|
| 104 |
|
---|
[551] | 105 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
|
---|
[2] | 106 | return filename;
|
---|
| 107 | *fbuf = 0;
|
---|
| 108 | return fbuf;
|
---|
| 109 | }
|
---|
| 110 | *fbuf = 0;
|
---|
[551] | 111 | if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
|
---|
| 112 | SEARCH_CUR_DIRECTORY,
|
---|
| 113 | path, filename, fbuf, CCHMAXPATH - 1))
|
---|
[2] | 114 | *fbuf = 0;
|
---|
| 115 | return fbuf;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[551] | 118 | CHAR *searchpath(CHAR * filename)
|
---|
| 119 | {
|
---|
[2] | 120 |
|
---|
| 121 | CHAR *found;
|
---|
| 122 |
|
---|
[551] | 123 | if (!filename)
|
---|
[2] | 124 | return "";
|
---|
[551] | 125 | found = searchapath("PATH", filename);
|
---|
| 126 | if (!*found) {
|
---|
| 127 | found = searchapath("DPATH", filename);
|
---|
| 128 | if (!*found)
|
---|
| 129 | found = searchapath("XPATH", filename);
|
---|
[2] | 130 | }
|
---|
| 131 | return found;
|
---|
| 132 | }
|
---|