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