| [632] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: srchpath.c 633 2007-04-22 23:28:09Z 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> | 
|---|
| [2] | 24 |  | 
|---|
| [632] | 25 | #include "fm3dll.h" | 
|---|
|  | 26 | #include "fm3dlg.h" | 
|---|
|  | 27 | #include "fm3str.h" | 
|---|
|  | 28 |  | 
|---|
|  | 29 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 30 |  | 
|---|
| [2] | 31 | #pragma data_seg(DATA1) | 
|---|
| [632] | 32 | #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util) | 
|---|
| [2] | 33 |  | 
|---|
| [632] | 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 |  | 
|---|
| [551] | 70 | CHAR *first_path(CHAR * path, CHAR * ret) | 
|---|
|  | 71 | { | 
|---|
| [2] | 72 |  | 
|---|
| [551] | 73 | CHAR *p, *pp; | 
|---|
| [2] | 74 |  | 
|---|
| [551] | 75 | if (!path || !ret) | 
|---|
| [2] | 76 | return ret; | 
|---|
| [551] | 77 | strcpy(ret, path); | 
|---|
|  | 78 | p = strchr(ret, ';'); | 
|---|
|  | 79 | if (p) { | 
|---|
| [2] | 80 | *p = 0; | 
|---|
|  | 81 | p++; | 
|---|
| [551] | 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); | 
|---|
| [2] | 88 | } | 
|---|
|  | 89 | } | 
|---|
|  | 90 | return ret; | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
| [551] | 93 | CHAR *searchapath(CHAR * path, CHAR * filename) | 
|---|
|  | 94 | { | 
|---|
| [2] | 95 |  | 
|---|
|  | 96 | static CHAR fbuf[CCHMAXPATH]; | 
|---|
|  | 97 |  | 
|---|
| [551] | 98 | if (strchr(filename, '\\') || strchr(filename, '/') | 
|---|
|  | 99 | || strchr(filename, ':')) { | 
|---|
| [2] | 100 |  | 
|---|
|  | 101 | FILESTATUS3 fsa; | 
|---|
|  | 102 |  | 
|---|
| [551] | 103 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa))) | 
|---|
| [2] | 104 | return filename; | 
|---|
|  | 105 | *fbuf = 0; | 
|---|
|  | 106 | return fbuf; | 
|---|
|  | 107 | } | 
|---|
|  | 108 | *fbuf = 0; | 
|---|
| [551] | 109 | if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | | 
|---|
|  | 110 | SEARCH_CUR_DIRECTORY, | 
|---|
|  | 111 | path, filename, fbuf, CCHMAXPATH - 1)) | 
|---|
| [2] | 112 | *fbuf = 0; | 
|---|
|  | 113 | return fbuf; | 
|---|
|  | 114 | } | 
|---|
|  | 115 |  | 
|---|
| [551] | 116 | CHAR *searchpath(CHAR * filename) | 
|---|
|  | 117 | { | 
|---|
| [2] | 118 |  | 
|---|
|  | 119 | CHAR *found; | 
|---|
|  | 120 |  | 
|---|
| [551] | 121 | if (!filename) | 
|---|
| [2] | 122 | return ""; | 
|---|
| [551] | 123 | found = searchapath("PATH", filename); | 
|---|
|  | 124 | if (!*found) { | 
|---|
|  | 125 | found = searchapath("DPATH", filename); | 
|---|
|  | 126 | if (!*found) | 
|---|
|  | 127 | found = searchapath("XPATH", filename); | 
|---|
| [2] | 128 | } | 
|---|
|  | 129 | return found; | 
|---|
|  | 130 | } | 
|---|