1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile apps.c:
|
---|
4 | * contains program helpers (environments, application start).
|
---|
5 | *
|
---|
6 | * This file is new with V0.9.12 and contains functions
|
---|
7 | * previously in winh.c and dosh2.c.
|
---|
8 | *
|
---|
9 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
10 | * numbering.
|
---|
11 | *
|
---|
12 | *@@header "helpers\apps.h"
|
---|
13 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
---|
14 | */
|
---|
15 |
|
---|
16 | /*
|
---|
17 | * Copyright (C) 1997-2001 Ulrich Mller.
|
---|
18 | * This file is part of the "XWorkplace helpers" source package.
|
---|
19 | * This is free software; you can redistribute it and/or modify
|
---|
20 | * it under the terms of the GNU General Public License as published
|
---|
21 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
22 | * "COPYING" file of the XWorkplace main distribution.
|
---|
23 | * This program is distributed in the hope that it will be useful,
|
---|
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
26 | * GNU General Public License for more details.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #define OS2EMX_PLAIN_CHAR
|
---|
30 | // this is needed for "os2emx.h"; if this is defined,
|
---|
31 | // emx will define PSZ as _signed_ char, otherwise
|
---|
32 | // as unsigned char
|
---|
33 |
|
---|
34 | #define INCL_DOSPROCESS
|
---|
35 | #define INCL_DOSMODULEMGR
|
---|
36 | #define INCL_DOSSESMGR
|
---|
37 | #define INCL_DOSERRORS
|
---|
38 |
|
---|
39 | #define INCL_WINPROGRAMLIST // needed for PROGDETAILS, wppgm.h
|
---|
40 | #define INCL_WINERRORS
|
---|
41 | #define INCL_SHLERRORS
|
---|
42 | #include <os2.h>
|
---|
43 |
|
---|
44 | #include <stdio.h>
|
---|
45 |
|
---|
46 | #include "setup.h" // code generation and debugging options
|
---|
47 |
|
---|
48 | #include "helpers\apps.h"
|
---|
49 | #include "helpers\dosh.h"
|
---|
50 | #include "helpers\prfh.h"
|
---|
51 | #include "helpers\standards.h" // some standard macros
|
---|
52 | #include "helpers\stringh.h"
|
---|
53 | #include "helpers\winh.h"
|
---|
54 | #include "helpers\xstring.h"
|
---|
55 |
|
---|
56 | /*
|
---|
57 | *@@category: Helpers\PM helpers\Application helpers
|
---|
58 | */
|
---|
59 |
|
---|
60 | /* ******************************************************************
|
---|
61 | *
|
---|
62 | * Environment helpers
|
---|
63 | *
|
---|
64 | ********************************************************************/
|
---|
65 |
|
---|
66 | /*
|
---|
67 | *@@ appQueryEnvironmentLen:
|
---|
68 | * returns the total length of the passed in environment
|
---|
69 | * string buffer, including the terminating two null bytes.
|
---|
70 | *
|
---|
71 | *@@added V0.9.16 (2002-01-09) [umoeller]
|
---|
72 | */
|
---|
73 |
|
---|
74 | ULONG appQueryEnvironmentLen(PCSZ pcszEnvironment)
|
---|
75 | {
|
---|
76 | ULONG cbEnvironment = 0;
|
---|
77 | if (pcszEnvironment)
|
---|
78 | {
|
---|
79 | PCSZ pVarThis = pcszEnvironment;
|
---|
80 | // go thru the environment strings; last one has two null bytes
|
---|
81 | while (*pVarThis)
|
---|
82 | {
|
---|
83 | ULONG ulLenThis = strlen(pVarThis) + 1;
|
---|
84 | cbEnvironment += ulLenThis;
|
---|
85 | pVarThis += ulLenThis;
|
---|
86 | }
|
---|
87 |
|
---|
88 | cbEnvironment++; // last null byte
|
---|
89 | }
|
---|
90 |
|
---|
91 | return (cbEnvironment);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*
|
---|
95 | *@@ appParseEnvironment:
|
---|
96 | * this takes one of those ugly environment strings
|
---|
97 | * as used by DosStartSession and WinStartApp (with
|
---|
98 | * lots of zero-terminated strings one after another
|
---|
99 | * and a duplicate zero byte as a terminator) as
|
---|
100 | * input and splits it into an array of separate
|
---|
101 | * strings in pEnv.
|
---|
102 | *
|
---|
103 | * The newly allocated strings are stored in in
|
---|
104 | * pEnv->papszVars. The array count is stored in
|
---|
105 | * pEnv->cVars.
|
---|
106 | *
|
---|
107 | * Each environment variable will be copied into
|
---|
108 | * one newly allocated string in the array. Use
|
---|
109 | * appFreeEnvironment to free the memory allocated
|
---|
110 | * by this function.
|
---|
111 | *
|
---|
112 | * Use the following code to browse thru the array:
|
---|
113 | +
|
---|
114 | + DOSENVIRONMENT Env = {0};
|
---|
115 | + if (appParseEnvironment(pszEnv,
|
---|
116 | + &Env)
|
---|
117 | + == NO_ERROR)
|
---|
118 | + {
|
---|
119 | + if (Env.papszVars)
|
---|
120 | + {
|
---|
121 | + PSZ *ppszThis = Env.papszVars;
|
---|
122 | + for (ul = 0;
|
---|
123 | + ul < Env.cVars;
|
---|
124 | + ul++)
|
---|
125 | + {
|
---|
126 | + PSZ pszThis = *ppszThis;
|
---|
127 | + // pszThis now has something like PATH=C:\TEMP
|
---|
128 | + // ...
|
---|
129 | + // next environment string
|
---|
130 | + ppszThis++;
|
---|
131 | + }
|
---|
132 | + }
|
---|
133 | + appFreeEnvironment(&Env);
|
---|
134 | + }
|
---|
135 | *
|
---|
136 | *@@added V0.9.4 (2000-08-02) [umoeller]
|
---|
137 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
138 | */
|
---|
139 |
|
---|
140 | APIRET appParseEnvironment(const char *pcszEnv,
|
---|
141 | PDOSENVIRONMENT pEnv) // out: new environment
|
---|
142 | {
|
---|
143 | APIRET arc = NO_ERROR;
|
---|
144 | if (!pcszEnv)
|
---|
145 | arc = ERROR_INVALID_PARAMETER;
|
---|
146 | else
|
---|
147 | {
|
---|
148 | PSZ pszVarThis = (PSZ)pcszEnv;
|
---|
149 | ULONG cVars = 0;
|
---|
150 | // count strings
|
---|
151 | while (*pszVarThis)
|
---|
152 | {
|
---|
153 | cVars++;
|
---|
154 | pszVarThis += strlen(pszVarThis) + 1;
|
---|
155 | }
|
---|
156 |
|
---|
157 | pEnv->cVars = 0;
|
---|
158 | pEnv->papszVars = 0;
|
---|
159 |
|
---|
160 | if (cVars)
|
---|
161 | {
|
---|
162 | ULONG cbArray = sizeof(PSZ) * cVars;
|
---|
163 | PSZ *papsz;
|
---|
164 | if (!(papsz = (PSZ*)malloc(cbArray)))
|
---|
165 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
166 | else
|
---|
167 | {
|
---|
168 | PSZ *ppszTarget = papsz;
|
---|
169 | memset(papsz, 0, cbArray);
|
---|
170 | pszVarThis = (PSZ)pcszEnv;
|
---|
171 | while (*pszVarThis)
|
---|
172 | {
|
---|
173 | ULONG ulThisLen;
|
---|
174 | if (!(*ppszTarget = strhdup(pszVarThis, &ulThisLen)))
|
---|
175 | {
|
---|
176 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
177 | break;
|
---|
178 | }
|
---|
179 | (pEnv->cVars)++;
|
---|
180 | ppszTarget++;
|
---|
181 | pszVarThis += ulThisLen + 1;
|
---|
182 | }
|
---|
183 |
|
---|
184 | pEnv->papszVars = papsz;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | return (arc);
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | *@@ appGetEnvironment:
|
---|
194 | * calls appParseEnvironment for the current
|
---|
195 | * process environment, which is retrieved from
|
---|
196 | * the info blocks.
|
---|
197 | *
|
---|
198 | * Returns:
|
---|
199 | *
|
---|
200 | * -- NO_ERROR:
|
---|
201 | *
|
---|
202 | * -- ERROR_INVALID_PARAMETER
|
---|
203 | *
|
---|
204 | * -- ERROR_BAD_ENVIRONMENT: no environment found in
|
---|
205 | * info blocks.
|
---|
206 | *
|
---|
207 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
208 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
209 | */
|
---|
210 |
|
---|
211 | APIRET appGetEnvironment(PDOSENVIRONMENT pEnv)
|
---|
212 | {
|
---|
213 | APIRET arc = NO_ERROR;
|
---|
214 | if (!pEnv)
|
---|
215 | arc = ERROR_INVALID_PARAMETER;
|
---|
216 | else
|
---|
217 | {
|
---|
218 | PTIB ptib = 0;
|
---|
219 | PPIB ppib = 0;
|
---|
220 | arc = DosGetInfoBlocks(&ptib, &ppib);
|
---|
221 | if (arc == NO_ERROR)
|
---|
222 | {
|
---|
223 | PSZ pszEnv;
|
---|
224 | if (pszEnv = ppib->pib_pchenv)
|
---|
225 | arc = appParseEnvironment(pszEnv, pEnv);
|
---|
226 | else
|
---|
227 | arc = ERROR_BAD_ENVIRONMENT;
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | return (arc);
|
---|
232 | }
|
---|
233 |
|
---|
234 | /*
|
---|
235 | *@@ appFindEnvironmentVar:
|
---|
236 | * returns the PSZ* in the pEnv->papszVars array
|
---|
237 | * which specifies the environment variable in pszVarName.
|
---|
238 | *
|
---|
239 | * With pszVarName, you can either specify the variable
|
---|
240 | * name only ("VARNAME") or a full environment string
|
---|
241 | * ("VARNAME=BLAH"). In any case, only the variable name
|
---|
242 | * is compared.
|
---|
243 | *
|
---|
244 | * Returns NULL if no such variable name was found in
|
---|
245 | * the array.
|
---|
246 | *
|
---|
247 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
248 | *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
|
---|
249 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
250 | *@@changed V0.9.16 (2002-01-01) [umoeller]: removed extra heap allocation
|
---|
251 | */
|
---|
252 |
|
---|
253 | PSZ* appFindEnvironmentVar(PDOSENVIRONMENT pEnv,
|
---|
254 | PSZ pszVarName)
|
---|
255 | {
|
---|
256 | PSZ *ppszRet = 0;
|
---|
257 |
|
---|
258 | if ( (pEnv)
|
---|
259 | && (pEnv->papszVars)
|
---|
260 | && (pszVarName)
|
---|
261 | )
|
---|
262 | {
|
---|
263 | ULONG ul = 0;
|
---|
264 | ULONG ulVarNameLen = 0;
|
---|
265 |
|
---|
266 | PSZ pFirstEqual;
|
---|
267 | // rewrote all the following for speed V0.9.16 (2002-01-01) [umoeller]
|
---|
268 | if (pFirstEqual = strchr(pszVarName, '='))
|
---|
269 | // VAR=VALUE
|
---|
270 | // ^ pFirstEqual
|
---|
271 | ulVarNameLen = pFirstEqual - pszVarName;
|
---|
272 | else
|
---|
273 | ulVarNameLen = strlen(pszVarName);
|
---|
274 |
|
---|
275 | for (ul = 0;
|
---|
276 | ul < pEnv->cVars;
|
---|
277 | ul++)
|
---|
278 | {
|
---|
279 | PSZ pszThis = pEnv->papszVars[ul];
|
---|
280 | if (pFirstEqual = strchr(pszThis, '='))
|
---|
281 | {
|
---|
282 | ULONG ulLenThis = pFirstEqual - pszThis;
|
---|
283 | if ( (ulLenThis == ulVarNameLen)
|
---|
284 | && (!memicmp(pszThis,
|
---|
285 | pszVarName,
|
---|
286 | ulVarNameLen))
|
---|
287 | )
|
---|
288 | {
|
---|
289 | ppszRet = &pEnv->papszVars[ul];
|
---|
290 | break;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | return (ppszRet);
|
---|
297 | }
|
---|
298 |
|
---|
299 | /*
|
---|
300 | *@@ appSetEnvironmentVar:
|
---|
301 | * sets an environment variable in the specified
|
---|
302 | * environment, which must have been initialized
|
---|
303 | * using appGetEnvironment first.
|
---|
304 | *
|
---|
305 | * pszNewEnv must be a full environment string
|
---|
306 | * in the form "VARNAME=VALUE".
|
---|
307 | *
|
---|
308 | * If "VARNAME" has already been set to something
|
---|
309 | * in the string array in pEnv, that array item
|
---|
310 | * is replaced.
|
---|
311 | *
|
---|
312 | * OTOH, if "VARNAME" has not been set yet, a new
|
---|
313 | * item is added to the array, and pEnv->cVars is
|
---|
314 | * raised by one. In that case, fAddFirst determines
|
---|
315 | * whether the new array item is added to the front
|
---|
316 | * or the tail of the environment list.
|
---|
317 | *
|
---|
318 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
319 | *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst
|
---|
320 | *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
|
---|
321 | *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed crash if !fAddFirst
|
---|
322 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
323 | */
|
---|
324 |
|
---|
325 | APIRET appSetEnvironmentVar(PDOSENVIRONMENT pEnv,
|
---|
326 | PSZ pszNewEnv,
|
---|
327 | BOOL fAddFirst)
|
---|
328 | {
|
---|
329 | APIRET arc = NO_ERROR;
|
---|
330 | if ((!pEnv) || (!pszNewEnv))
|
---|
331 | arc = ERROR_INVALID_PARAMETER;
|
---|
332 | else
|
---|
333 | {
|
---|
334 | if (!pEnv->papszVars)
|
---|
335 | {
|
---|
336 | // no variables set yet:
|
---|
337 | pEnv->papszVars = (PSZ*)malloc(sizeof(PSZ));
|
---|
338 | pEnv->cVars = 1;
|
---|
339 |
|
---|
340 | *(pEnv->papszVars) = strdup(pszNewEnv);
|
---|
341 | }
|
---|
342 | else
|
---|
343 | {
|
---|
344 | PSZ *ppszEnvLine;
|
---|
345 | if (ppszEnvLine = appFindEnvironmentVar(pEnv, pszNewEnv))
|
---|
346 | // was set already: replace
|
---|
347 | arc = strhStore(ppszEnvLine,
|
---|
348 | pszNewEnv,
|
---|
349 | NULL);
|
---|
350 | else
|
---|
351 | {
|
---|
352 | // not set already:
|
---|
353 | PSZ *ppszNew = NULL;
|
---|
354 |
|
---|
355 | // allocate new array, with one new entry
|
---|
356 | // fixed V0.9.12 (2001-05-26) [umoeller], this crashed
|
---|
357 | PSZ *papszNew;
|
---|
358 |
|
---|
359 | if (!(papszNew = (PSZ*)malloc(sizeof(PSZ) * (pEnv->cVars + 1))))
|
---|
360 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
361 | else
|
---|
362 | {
|
---|
363 | if (fAddFirst)
|
---|
364 | {
|
---|
365 | // add as first entry:
|
---|
366 | // overwrite first entry
|
---|
367 | ppszNew = papszNew;
|
---|
368 | // copy old entries
|
---|
369 | memcpy(papszNew + 1, // second new entry
|
---|
370 | pEnv->papszVars, // first old entry
|
---|
371 | sizeof(PSZ) * pEnv->cVars);
|
---|
372 | }
|
---|
373 | else
|
---|
374 | {
|
---|
375 | // append at the tail:
|
---|
376 | // overwrite last entry
|
---|
377 | ppszNew = papszNew + pEnv->cVars;
|
---|
378 | // copy old entries
|
---|
379 | memcpy(papszNew, // first new entry
|
---|
380 | pEnv->papszVars, // first old entry
|
---|
381 | sizeof(PSZ) * pEnv->cVars);
|
---|
382 | }
|
---|
383 |
|
---|
384 | free(pEnv->papszVars); // was missing V0.9.12 (2001-05-21) [umoeller]
|
---|
385 | pEnv->papszVars = papszNew;
|
---|
386 | pEnv->cVars++;
|
---|
387 | *ppszNew = strdup(pszNewEnv);
|
---|
388 | }
|
---|
389 | }
|
---|
390 | }
|
---|
391 | }
|
---|
392 |
|
---|
393 | return (arc);
|
---|
394 | }
|
---|
395 |
|
---|
396 | /*
|
---|
397 | *@@ appConvertEnvironment:
|
---|
398 | * converts an environment initialized by appGetEnvironment
|
---|
399 | * to the string format required by WinStartApp and DosExecPgm,
|
---|
400 | * that is, one memory block is allocated in *ppszEnv and all
|
---|
401 | * strings in pEnv->papszVars are copied to that block. Each
|
---|
402 | * string is terminated with a null character; the last string
|
---|
403 | * is terminated with two null characters.
|
---|
404 | *
|
---|
405 | * Use free() to free the memory block allocated by this
|
---|
406 | * function in *ppszEnv.
|
---|
407 | *
|
---|
408 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
409 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
410 | */
|
---|
411 |
|
---|
412 | APIRET appConvertEnvironment(PDOSENVIRONMENT pEnv,
|
---|
413 | PSZ *ppszEnv, // out: environment string
|
---|
414 | PULONG pulSize) // out: size of block allocated in *ppszEnv; ptr can be NULL
|
---|
415 | {
|
---|
416 | APIRET arc = NO_ERROR;
|
---|
417 | if ( (!pEnv)
|
---|
418 | || (!pEnv->papszVars)
|
---|
419 | )
|
---|
420 | arc = ERROR_INVALID_PARAMETER;
|
---|
421 | else
|
---|
422 | {
|
---|
423 | // count memory needed for all strings
|
---|
424 | ULONG cbNeeded = 0,
|
---|
425 | ul = 0;
|
---|
426 | PSZ *ppszThis = pEnv->papszVars;
|
---|
427 |
|
---|
428 | for (ul = 0;
|
---|
429 | ul < pEnv->cVars;
|
---|
430 | ul++)
|
---|
431 | {
|
---|
432 | cbNeeded += strlen(*ppszThis) + 1; // length of string plus null terminator
|
---|
433 |
|
---|
434 | // next environment string
|
---|
435 | ppszThis++;
|
---|
436 | }
|
---|
437 |
|
---|
438 | cbNeeded++; // for another null terminator
|
---|
439 |
|
---|
440 | if (!(*ppszEnv = (PSZ)malloc(cbNeeded)))
|
---|
441 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
442 | else
|
---|
443 | {
|
---|
444 | PSZ pTarget = *ppszEnv;
|
---|
445 | if (pulSize)
|
---|
446 | *pulSize = cbNeeded;
|
---|
447 | ppszThis = pEnv->papszVars;
|
---|
448 |
|
---|
449 | // now copy each string
|
---|
450 | for (ul = 0;
|
---|
451 | ul < pEnv->cVars;
|
---|
452 | ul++)
|
---|
453 | {
|
---|
454 | PSZ pSource = *ppszThis;
|
---|
455 |
|
---|
456 | while ((*pTarget++ = *pSource++))
|
---|
457 | ;
|
---|
458 |
|
---|
459 | // *pTarget++ = 0; // append null terminator per string
|
---|
460 |
|
---|
461 | // next environment string
|
---|
462 | ppszThis++;
|
---|
463 | }
|
---|
464 |
|
---|
465 | *pTarget++ = 0; // append second null terminator
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | return (arc);
|
---|
470 | }
|
---|
471 |
|
---|
472 | /*
|
---|
473 | *@@ appFreeEnvironment:
|
---|
474 | * frees memory allocated by appGetEnvironment.
|
---|
475 | *
|
---|
476 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
477 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
478 | */
|
---|
479 |
|
---|
480 | APIRET appFreeEnvironment(PDOSENVIRONMENT pEnv)
|
---|
481 | {
|
---|
482 | APIRET arc = NO_ERROR;
|
---|
483 | if ( (!pEnv)
|
---|
484 | || (!pEnv->papszVars)
|
---|
485 | )
|
---|
486 | arc = ERROR_INVALID_PARAMETER;
|
---|
487 | else
|
---|
488 | {
|
---|
489 | PSZ *ppszThis = pEnv->papszVars;
|
---|
490 | PSZ pszThis;
|
---|
491 | ULONG ul = 0;
|
---|
492 |
|
---|
493 | for (ul = 0;
|
---|
494 | ul < pEnv->cVars;
|
---|
495 | ul++)
|
---|
496 | {
|
---|
497 | pszThis = *ppszThis;
|
---|
498 | free(pszThis);
|
---|
499 | // *ppszThis = NULL;
|
---|
500 | // next environment string
|
---|
501 | ppszThis++;
|
---|
502 | }
|
---|
503 |
|
---|
504 | free(pEnv->papszVars);
|
---|
505 | pEnv->cVars = 0;
|
---|
506 | }
|
---|
507 |
|
---|
508 | return (arc);
|
---|
509 | }
|
---|
510 |
|
---|
511 | /* ******************************************************************
|
---|
512 | *
|
---|
513 | * Application information
|
---|
514 | *
|
---|
515 | ********************************************************************/
|
---|
516 |
|
---|
517 | /*
|
---|
518 | *@@ appQueryAppType:
|
---|
519 | * returns the Control Program (Dos) and
|
---|
520 | * Win* PROG_* application types for the
|
---|
521 | * specified executable. Essentially, this
|
---|
522 | * is a wrapper around DosQueryAppType.
|
---|
523 | *
|
---|
524 | * pcszExecutable must be fully qualified.
|
---|
525 | * You can use doshFindExecutable to qualify
|
---|
526 | * it.
|
---|
527 | *
|
---|
528 | * This returns the APIRET of DosQueryAppType.
|
---|
529 | * If this is NO_ERROR; *pulDosAppType receives
|
---|
530 | * the app type of DosQueryAppType. In addition,
|
---|
531 | * *pulWinAppType is set to one of the following:
|
---|
532 | *
|
---|
533 | * -- PROG_FULLSCREEN
|
---|
534 | *
|
---|
535 | * -- PROG_PDD
|
---|
536 | *
|
---|
537 | * -- PROG_VDD
|
---|
538 | *
|
---|
539 | * -- PROG_DLL
|
---|
540 | *
|
---|
541 | * -- PROG_WINDOWEDVDM
|
---|
542 | *
|
---|
543 | * -- PROG_PM
|
---|
544 | *
|
---|
545 | * -- PROG_31_ENHSEAMLESSCOMMON
|
---|
546 | *
|
---|
547 | * -- PROG_WINDOWABLEVIO
|
---|
548 | *
|
---|
549 | * -- PROG_DEFAULT
|
---|
550 | *
|
---|
551 | *@@added V0.9.9 (2001-03-07) [umoeller]
|
---|
552 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
---|
553 | *@@changed V0.9.14 (2001-08-07) [pr]: use FAPPTYP_* constants
|
---|
554 | *@@changed V0.9.16 (2001-12-08) [umoeller]: added checks for batch files, other optimizations
|
---|
555 | */
|
---|
556 |
|
---|
557 | APIRET appQueryAppType(const char *pcszExecutable,
|
---|
558 | PULONG pulDosAppType,
|
---|
559 | PULONG pulWinAppType)
|
---|
560 | {
|
---|
561 | APIRET arc;
|
---|
562 |
|
---|
563 | /*
|
---|
564 | #define FAPPTYP_NOTSPEC 0x0000
|
---|
565 | #define FAPPTYP_NOTWINDOWCOMPAT 0x0001
|
---|
566 | #define FAPPTYP_WINDOWCOMPAT 0x0002
|
---|
567 | #define FAPPTYP_WINDOWAPI 0x0003
|
---|
568 | #define FAPPTYP_BOUND 0x0008
|
---|
569 | #define FAPPTYP_DLL 0x0010
|
---|
570 | #define FAPPTYP_DOS 0x0020
|
---|
571 | #define FAPPTYP_PHYSDRV 0x0040 // physical device driver
|
---|
572 | #define FAPPTYP_VIRTDRV 0x0080 // virtual device driver
|
---|
573 | #define FAPPTYP_PROTDLL 0x0100 // 'protected memory' dll
|
---|
574 | #define FAPPTYP_WINDOWSREAL 0x0200 // Windows real mode app
|
---|
575 | #define FAPPTYP_WINDOWSPROT 0x0400 // Windows protect mode app
|
---|
576 | #define FAPPTYP_WINDOWSPROT31 0x1000 // Windows 3.1 protect mode app
|
---|
577 | #define FAPPTYP_32BIT 0x4000
|
---|
578 | */
|
---|
579 |
|
---|
580 | ULONG ulWinAppType = PROG_DEFAULT;
|
---|
581 |
|
---|
582 | if (!(arc = DosQueryAppType((PSZ)pcszExecutable, pulDosAppType)))
|
---|
583 | {
|
---|
584 | // clear the 32-bit flag
|
---|
585 | // V0.9.16 (2001-12-08) [umoeller]
|
---|
586 | ULONG ulDosAppType = (*pulDosAppType) & ~FAPPTYP_32BIT,
|
---|
587 | ulLoAppType = ulDosAppType & 0xFFFF;
|
---|
588 |
|
---|
589 | if (ulDosAppType & FAPPTYP_PHYSDRV) // 0x40
|
---|
590 | ulWinAppType = PROG_PDD;
|
---|
591 | else if (ulDosAppType & FAPPTYP_VIRTDRV) // 0x80
|
---|
592 | ulWinAppType = PROG_VDD;
|
---|
593 | else if ((ulDosAppType & 0xF0) == FAPPTYP_DLL) // 0x10
|
---|
594 | // DLL bit set
|
---|
595 | ulWinAppType = PROG_DLL;
|
---|
596 | else if (ulDosAppType & FAPPTYP_DOS) // 0x20
|
---|
597 | // DOS bit set?
|
---|
598 | ulWinAppType = PROG_WINDOWEDVDM;
|
---|
599 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) // 0x0003)
|
---|
600 | // "Window-API" == PM
|
---|
601 | ulWinAppType = PROG_PM;
|
---|
602 | else if (ulLoAppType == FAPPTYP_WINDOWSREAL)
|
---|
603 | ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // @@todo really?
|
---|
604 | else if ( (ulLoAppType == FAPPTYP_WINDOWSPROT31) // 0x1000) // windows program (?!?)
|
---|
605 | || (ulLoAppType == FAPPTYP_WINDOWSPROT) // ) // windows program (?!?)
|
---|
606 | )
|
---|
607 | ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // PROG_31_ENH;
|
---|
608 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_WINDOWCOMPAT) // 0x02)
|
---|
609 | ulWinAppType = PROG_WINDOWABLEVIO;
|
---|
610 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_NOTWINDOWCOMPAT) // 0x01)
|
---|
611 | ulWinAppType = PROG_FULLSCREEN;
|
---|
612 | }
|
---|
613 |
|
---|
614 | if (ulWinAppType == PROG_DEFAULT)
|
---|
615 | {
|
---|
616 | // added checks for batch files V0.9.16 (2001-12-08) [umoeller]
|
---|
617 | PCSZ pcszExt;
|
---|
618 | if (pcszExt = doshGetExtension(pcszExecutable))
|
---|
619 | {
|
---|
620 | if (!stricmp(pcszExt, "BAT"))
|
---|
621 | {
|
---|
622 | ulWinAppType = PROG_WINDOWEDVDM;
|
---|
623 | arc = NO_ERROR;
|
---|
624 | }
|
---|
625 | else if (!stricmp(pcszExt, "CMD"))
|
---|
626 | {
|
---|
627 | ulWinAppType = PROG_WINDOWABLEVIO;
|
---|
628 | arc = NO_ERROR;
|
---|
629 | }
|
---|
630 | }
|
---|
631 | }
|
---|
632 |
|
---|
633 | *pulWinAppType = ulWinAppType;
|
---|
634 |
|
---|
635 | return (arc);
|
---|
636 | }
|
---|
637 |
|
---|
638 | /*
|
---|
639 | *@@ PROGTYPESTRING:
|
---|
640 | *
|
---|
641 | *@@added V0.9.16 (2002-01-13) [umoeller]
|
---|
642 | */
|
---|
643 |
|
---|
644 | typedef struct _PROGTYPESTRING
|
---|
645 | {
|
---|
646 | PROGCATEGORY progc;
|
---|
647 | PCSZ pcsz;
|
---|
648 | } PROGTYPESTRING, *PPROGTYPESTRING;
|
---|
649 |
|
---|
650 | PROGTYPESTRING G_aProgTypes[] =
|
---|
651 | {
|
---|
652 | PROG_DEFAULT, "PROG_DEFAULT",
|
---|
653 | PROG_FULLSCREEN, "PROG_FULLSCREEN",
|
---|
654 | PROG_WINDOWABLEVIO, "PROG_WINDOWABLEVIO",
|
---|
655 | PROG_PM, "PROG_PM",
|
---|
656 | PROG_GROUP, "PROG_GROUP",
|
---|
657 | PROG_VDM, "PROG_VDM",
|
---|
658 | // same as PROG_REAL, "PROG_REAL",
|
---|
659 | PROG_WINDOWEDVDM, "PROG_WINDOWEDVDM",
|
---|
660 | PROG_DLL, "PROG_DLL",
|
---|
661 | PROG_PDD, "PROG_PDD",
|
---|
662 | PROG_VDD, "PROG_VDD",
|
---|
663 | PROG_WINDOW_REAL, "PROG_WINDOW_REAL",
|
---|
664 | PROG_30_STD, "PROG_30_STD",
|
---|
665 | // same as PROG_WINDOW_PROT, "PROG_WINDOW_PROT",
|
---|
666 | PROG_WINDOW_AUTO, "PROG_WINDOW_AUTO",
|
---|
667 | PROG_30_STDSEAMLESSVDM, "PROG_30_STDSEAMLESSVDM",
|
---|
668 | // same as PROG_SEAMLESSVDM, "PROG_SEAMLESSVDM",
|
---|
669 | PROG_30_STDSEAMLESSCOMMON, "PROG_30_STDSEAMLESSCOMMON",
|
---|
670 | // same as PROG_SEAMLESSCOMMON, "PROG_SEAMLESSCOMMON",
|
---|
671 | PROG_31_STDSEAMLESSVDM, "PROG_31_STDSEAMLESSVDM",
|
---|
672 | PROG_31_STDSEAMLESSCOMMON, "PROG_31_STDSEAMLESSCOMMON",
|
---|
673 | PROG_31_ENHSEAMLESSVDM, "PROG_31_ENHSEAMLESSVDM",
|
---|
674 | PROG_31_ENHSEAMLESSCOMMON, "PROG_31_ENHSEAMLESSCOMMON",
|
---|
675 | PROG_31_ENH, "PROG_31_ENH",
|
---|
676 | PROG_31_STD, "PROG_31_STD",
|
---|
677 |
|
---|
678 | // Warp 4 toolkit defines, whatever these were designed for...
|
---|
679 | #ifndef PROG_DOS_GAME
|
---|
680 | #define PROG_DOS_GAME (PROGCATEGORY)21
|
---|
681 | #endif
|
---|
682 | #ifndef PROG_WIN_GAME
|
---|
683 | #define PROG_WIN_GAME (PROGCATEGORY)22
|
---|
684 | #endif
|
---|
685 | #ifndef PROG_DOS_MODE
|
---|
686 | #define PROG_DOS_MODE (PROGCATEGORY)23
|
---|
687 | #endif
|
---|
688 |
|
---|
689 | PROG_DOS_GAME, "PROG_DOS_GAME",
|
---|
690 | PROG_WIN_GAME, "PROG_WIN_GAME",
|
---|
691 | PROG_DOS_MODE, "PROG_DOS_MODE",
|
---|
692 |
|
---|
693 | // added this V0.9.16 (2001-12-08) [umoeller]
|
---|
694 | PROG_WIN32, "PROG_WIN32"
|
---|
695 | };
|
---|
696 |
|
---|
697 | /*
|
---|
698 | *@@ appDescribeAppType:
|
---|
699 | * returns a "PROG_*" string for the given
|
---|
700 | * program type. Useful for WPProgram setup
|
---|
701 | * strings and such.
|
---|
702 | *
|
---|
703 | *@@added V0.9.16 (2001-10-06)
|
---|
704 | */
|
---|
705 |
|
---|
706 | PCSZ appDescribeAppType(PROGCATEGORY progc) // in: from PROGDETAILS.progc
|
---|
707 | {
|
---|
708 | ULONG ul;
|
---|
709 | for (ul = 0;
|
---|
710 | ul < ARRAYITEMCOUNT(G_aProgTypes);
|
---|
711 | ul++)
|
---|
712 | {
|
---|
713 | if (G_aProgTypes[ul].progc == progc)
|
---|
714 | return (G_aProgTypes[ul].pcsz);
|
---|
715 | }
|
---|
716 |
|
---|
717 | return NULL;
|
---|
718 | }
|
---|
719 |
|
---|
720 | /*
|
---|
721 | *@@ appIsWindowsApp:
|
---|
722 | * checks the specified program category
|
---|
723 | * (PROGDETAILS.progt.progc) for whether
|
---|
724 | * it represents a Win-OS/2 application.
|
---|
725 | *
|
---|
726 | * Returns:
|
---|
727 | *
|
---|
728 | * -- 0: no windows app (it's VIO, OS/2
|
---|
729 | * or DOS fullscreen, or PM).
|
---|
730 | *
|
---|
731 | * -- 1: Win-OS/2 standard app.
|
---|
732 | *
|
---|
733 | * -- 2: Win-OS/2 enhanced-mode app.
|
---|
734 | *
|
---|
735 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
---|
736 | */
|
---|
737 |
|
---|
738 | ULONG appIsWindowsApp(ULONG ulProgCategory)
|
---|
739 | {
|
---|
740 | switch (ulProgCategory)
|
---|
741 | {
|
---|
742 | case PROG_31_ENHSEAMLESSVDM: // 17
|
---|
743 | case PROG_31_ENHSEAMLESSCOMMON: // 18
|
---|
744 | case PROG_31_ENH: // 19
|
---|
745 | return (2);
|
---|
746 |
|
---|
747 | #ifndef PROG_30_STD
|
---|
748 | #define PROG_30_STD (PROGCATEGORY)11
|
---|
749 | #endif
|
---|
750 |
|
---|
751 | #ifndef PROG_30_STDSEAMLESSVDM
|
---|
752 | #define PROG_30_STDSEAMLESSVDM (PROGCATEGORY)13
|
---|
753 | #endif
|
---|
754 |
|
---|
755 | case PROG_WINDOW_REAL: // 10
|
---|
756 | case PROG_30_STD: // 11
|
---|
757 | case PROG_WINDOW_AUTO: // 12
|
---|
758 | case PROG_30_STDSEAMLESSVDM: // 13
|
---|
759 | case PROG_30_STDSEAMLESSCOMMON: // 14
|
---|
760 | case PROG_31_STDSEAMLESSVDM: // 15
|
---|
761 | case PROG_31_STDSEAMLESSCOMMON: // 16
|
---|
762 | case PROG_31_STD: // 20
|
---|
763 | return (1);
|
---|
764 | }
|
---|
765 |
|
---|
766 | return (0);
|
---|
767 | }
|
---|
768 |
|
---|
769 | /* ******************************************************************
|
---|
770 | *
|
---|
771 | * Application start
|
---|
772 | *
|
---|
773 | ********************************************************************/
|
---|
774 |
|
---|
775 | /*
|
---|
776 | *@@ CallBatchCorrectly:
|
---|
777 | * fixes the specified PROGDETAILS for
|
---|
778 | * command files in the executable part
|
---|
779 | * by inserting /C XXX into the parameters
|
---|
780 | * and setting the executable according
|
---|
781 | * to an environment variable.
|
---|
782 | *
|
---|
783 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
---|
784 | *@@changed V0.9.7 (2001-01-15) [umoeller]: now using XSTRING
|
---|
785 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
---|
786 | */
|
---|
787 |
|
---|
788 | static VOID CallBatchCorrectly(PPROGDETAILS pProgDetails,
|
---|
789 | PXSTRING pstrParams, // in/out: modified parameters (reallocated)
|
---|
790 | const char *pcszEnvVar, // in: env var spec'g command proc
|
---|
791 | // (e.g. "OS2_SHELL"); can be NULL
|
---|
792 | const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE")
|
---|
793 | {
|
---|
794 | // XXX.CMD file as executable:
|
---|
795 | // fix args to /C XXX.CMD
|
---|
796 |
|
---|
797 | PSZ pszOldParams = NULL;
|
---|
798 | ULONG ulOldParamsLength = pstrParams->ulLength;
|
---|
799 | if (ulOldParamsLength)
|
---|
800 | // we have parameters already:
|
---|
801 | // make a backup... we'll append that later
|
---|
802 | pszOldParams = strdup(pstrParams->psz);
|
---|
803 |
|
---|
804 | // set new params to "/C filename.cmd"
|
---|
805 | xstrcpy(pstrParams, "/C ", 0);
|
---|
806 | xstrcat(pstrParams,
|
---|
807 | pProgDetails->pszExecutable,
|
---|
808 | 0);
|
---|
809 |
|
---|
810 | if (pszOldParams)
|
---|
811 | {
|
---|
812 | // .cmd had params:
|
---|
813 | // append space and old params
|
---|
814 | xstrcatc(pstrParams, ' ');
|
---|
815 | xstrcat(pstrParams,
|
---|
816 | pszOldParams,
|
---|
817 | ulOldParamsLength);
|
---|
818 | free(pszOldParams);
|
---|
819 | }
|
---|
820 |
|
---|
821 | // set executable to $(OS2_SHELL)
|
---|
822 | pProgDetails->pszExecutable = NULL;
|
---|
823 | if (pcszEnvVar)
|
---|
824 | pProgDetails->pszExecutable = getenv(pcszEnvVar);
|
---|
825 | if (!pProgDetails->pszExecutable)
|
---|
826 | pProgDetails->pszExecutable = (PSZ)pcszDefProc;
|
---|
827 | // should be on PATH
|
---|
828 | }
|
---|
829 |
|
---|
830 | /*
|
---|
831 | *@@ strhSize:
|
---|
832 | * returns the size of the given string, which
|
---|
833 | * is the memory required to allocate a copy,
|
---|
834 | * including the null terminator.
|
---|
835 | *
|
---|
836 | * Returns 0 if pcsz is NULL or points to a
|
---|
837 | * null character.
|
---|
838 | *
|
---|
839 | *@@added V0.9.18 (2002-02-13) [umoeller]
|
---|
840 | */
|
---|
841 |
|
---|
842 | ULONG strhSize(PCSZ pcsz)
|
---|
843 | {
|
---|
844 | if (pcsz && *pcsz)
|
---|
845 | return (strlen(pcsz) + 1);
|
---|
846 |
|
---|
847 | return (0);
|
---|
848 | }
|
---|
849 |
|
---|
850 | /*
|
---|
851 | *@@ appQueryDefaultWin31Environment:
|
---|
852 | * returns the default Win-OS/2 3.1 environment
|
---|
853 | * from OS2.INI, which you can then merge with
|
---|
854 | * your process environment to be able to
|
---|
855 | * start Win-OS/2 sessions properly with
|
---|
856 | * appStartApp.
|
---|
857 | *
|
---|
858 | * Caller must free() the return value.
|
---|
859 | *
|
---|
860 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
---|
861 | */
|
---|
862 |
|
---|
863 | PSZ appQueryDefaultWin31Environment(VOID)
|
---|
864 | {
|
---|
865 | PSZ pszReturn = NULL;
|
---|
866 | ULONG ulSize = 0;
|
---|
867 | // get default environment (from Win-OS/2 settings object)
|
---|
868 | // from OS2.INI
|
---|
869 | PSZ pszDefEnv = prfhQueryProfileData(HINI_USER,
|
---|
870 | "WINOS2",
|
---|
871 | "PM_GlobalWindows31Settings",
|
---|
872 | &ulSize);
|
---|
873 | if (pszDefEnv)
|
---|
874 | {
|
---|
875 | if (pszReturn = (PSZ)malloc(ulSize + 2))
|
---|
876 | {
|
---|
877 | PSZ p;
|
---|
878 | memset(pszReturn, 0, ulSize + 2);
|
---|
879 | memcpy(pszReturn, pszDefEnv, ulSize);
|
---|
880 |
|
---|
881 | for (p = pszReturn;
|
---|
882 | p < pszReturn + ulSize;
|
---|
883 | p++)
|
---|
884 | if (*p == ';')
|
---|
885 | *p = 0;
|
---|
886 |
|
---|
887 | // okay.... now we got an OS/2-style environment
|
---|
888 | // with 0, 0, 00 strings
|
---|
889 | }
|
---|
890 |
|
---|
891 | free(pszDefEnv);
|
---|
892 | }
|
---|
893 |
|
---|
894 | return (pszReturn);
|
---|
895 | }
|
---|
896 |
|
---|
897 | /*
|
---|
898 | *@@ CallWinStartApp:
|
---|
899 | * wrapper around WinStartApp which copies all the
|
---|
900 | * parameters into a contiguous block of tiled memory.
|
---|
901 | *
|
---|
902 | * This might fix some of the problems with truncated
|
---|
903 | * environments we were having because apparently the
|
---|
904 | * WinStartApp thunking to 16-bit doesn't always work.
|
---|
905 | *
|
---|
906 | *@@added V0.9.18 (2002-02-13) [umoeller]
|
---|
907 | */
|
---|
908 |
|
---|
909 | static APIRET CallWinStartApp(HAPP *phapp, // out: application handle if NO_ERROR is returned
|
---|
910 | HWND hwndNotify, // in: notify window or NULLHANDLE
|
---|
911 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
---|
912 | PCSZ pcszParamsPatched)
|
---|
913 | {
|
---|
914 | ULONG cb,
|
---|
915 | cbTitle,
|
---|
916 | cbExecutable,
|
---|
917 | cbParameters,
|
---|
918 | cbStartupDir,
|
---|
919 | cbIcon,
|
---|
920 | cbEnvironment;
|
---|
921 |
|
---|
922 | APIRET arc = NO_ERROR;
|
---|
923 |
|
---|
924 | /*
|
---|
925 | if (WinMessageBox(HWND_DESKTOP,
|
---|
926 | NULLHANDLE,
|
---|
927 | (ProgDetails.pszExecutable) ? ProgDetails.pszExecutable : "NULL",
|
---|
928 | "Start?",
|
---|
929 | 0,
|
---|
930 | MB_YESNO | MB_MOVEABLE)
|
---|
931 | != MBID_YES)
|
---|
932 | return (ERROR_INTERRUPT);
|
---|
933 | */
|
---|
934 |
|
---|
935 | // allocate a chunk of tiled memory from OS/2 to make sure
|
---|
936 | // this is aligned on a 64K memory (backed up by a 16-bit
|
---|
937 | // LDT selector)
|
---|
938 | cb = sizeof(PROGDETAILS);
|
---|
939 | if (cbTitle = strhSize(pcProgDetails->pszTitle))
|
---|
940 | cb += cbTitle;
|
---|
941 | if (cbExecutable = strhSize(pcProgDetails->pszExecutable))
|
---|
942 | cb += cbExecutable;
|
---|
943 | if (cbParameters = strhSize(pcProgDetails->pszParameters))
|
---|
944 | cb += cbParameters;
|
---|
945 | if (cbStartupDir = strhSize(pcProgDetails->pszStartupDir))
|
---|
946 | cb += cbStartupDir;
|
---|
947 | if (cbIcon = strhSize(pcProgDetails->pszIcon))
|
---|
948 | cb += cbIcon;
|
---|
949 | if (cbEnvironment = appQueryEnvironmentLen(pcProgDetails->pszEnvironment))
|
---|
950 | cb += cbEnvironment;
|
---|
951 |
|
---|
952 | if (cb > 60000) // to be on the safe side
|
---|
953 | arc = ERROR_BAD_ENVIRONMENT; // 10;
|
---|
954 | else
|
---|
955 | {
|
---|
956 | PPROGDETAILS pNewProgDetails;
|
---|
957 | if (!(arc = DosAllocMem((PVOID*)&pNewProgDetails,
|
---|
958 | cb,
|
---|
959 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)))
|
---|
960 | {
|
---|
961 | // alright, copy stuff
|
---|
962 | PBYTE pThis;
|
---|
963 |
|
---|
964 | memset(pNewProgDetails, 0, sizeof(PROGDETAILS));
|
---|
965 |
|
---|
966 | pNewProgDetails->Length = sizeof(PROGDETAILS);
|
---|
967 | pNewProgDetails->progt.progc = pcProgDetails->progt.progc;
|
---|
968 | pNewProgDetails->progt.fbVisible = pcProgDetails->progt.fbVisible;
|
---|
969 | memcpy(&pNewProgDetails->swpInitial, &pcProgDetails->swpInitial, sizeof(SWP));
|
---|
970 |
|
---|
971 | pThis = (PBYTE)(pNewProgDetails + 1);
|
---|
972 |
|
---|
973 | if (cbTitle)
|
---|
974 | {
|
---|
975 | memcpy(pThis, pcProgDetails->pszTitle, cbTitle);
|
---|
976 | pNewProgDetails->pszTitle = pThis;
|
---|
977 | pThis += cbTitle;
|
---|
978 | }
|
---|
979 |
|
---|
980 | if (cbExecutable)
|
---|
981 | {
|
---|
982 | memcpy(pThis, pcProgDetails->pszExecutable, cbExecutable);
|
---|
983 | pNewProgDetails->pszExecutable = pThis;
|
---|
984 | pThis += cbExecutable;
|
---|
985 | }
|
---|
986 |
|
---|
987 | if (cbParameters)
|
---|
988 | {
|
---|
989 | memcpy(pThis, pcProgDetails->pszParameters, cbParameters);
|
---|
990 | pNewProgDetails->pszParameters = pThis;
|
---|
991 | pThis += cbParameters;
|
---|
992 | }
|
---|
993 |
|
---|
994 | if (cbStartupDir)
|
---|
995 | {
|
---|
996 | memcpy(pThis, pcProgDetails->pszStartupDir, cbStartupDir);
|
---|
997 | pNewProgDetails->pszStartupDir = pThis;
|
---|
998 | pThis += cbStartupDir;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | if (cbIcon)
|
---|
1002 | {
|
---|
1003 | memcpy(pThis, pcProgDetails->pszIcon, cbIcon);
|
---|
1004 | pNewProgDetails->pszIcon = pThis;
|
---|
1005 | pThis += cbIcon;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | if (cbEnvironment)
|
---|
1009 | {
|
---|
1010 | memcpy(pThis, pcProgDetails->pszEnvironment, cbEnvironment);
|
---|
1011 | pNewProgDetails->pszEnvironment = pThis;
|
---|
1012 | pThis += cbEnvironment;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | _Pmpf((__FUNCTION__ ": progt.progc: %d", pNewProgDetails->progt.progc));
|
---|
1016 | _Pmpf((" progt.fbVisible: 0x%lX", pNewProgDetails->progt.fbVisible));
|
---|
1017 | _Pmpf((" progt.pszTitle: \"%s\"", (pNewProgDetails->pszTitle) ? pNewProgDetails->pszTitle : "NULL"));
|
---|
1018 | _Pmpf((" exec: \"%s\"", (pNewProgDetails->pszExecutable) ? pNewProgDetails->pszExecutable : "NULL"));
|
---|
1019 | _Pmpf((" params: \"%s\"", (pNewProgDetails->pszParameters) ? pNewProgDetails->pszParameters : "NULL"));
|
---|
1020 | _Pmpf((" startup: \"%s\"", (pNewProgDetails->pszStartupDir) ? pNewProgDetails->pszStartupDir : "NULL"));
|
---|
1021 | _Pmpf((" pszIcon: \"%s\"", (pNewProgDetails->pszIcon) ? pNewProgDetails->pszIcon : "NULL"));
|
---|
1022 | _Pmpf((" environment: "));
|
---|
1023 | {
|
---|
1024 | PSZ pszThis = pNewProgDetails->pszEnvironment;
|
---|
1025 | while (pszThis && *pszThis)
|
---|
1026 | {
|
---|
1027 | _Pmpf((" \"%s\"", pszThis));
|
---|
1028 | pszThis += strlen(pszThis) + 1;
|
---|
1029 | }
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | _Pmpf((" swpInitial.fl = 0x%lX, x = %d, y = %d, cx = %d, cy = %d:",
|
---|
1033 | pNewProgDetails->swpInitial.fl,
|
---|
1034 | pNewProgDetails->swpInitial.x,
|
---|
1035 | pNewProgDetails->swpInitial.y,
|
---|
1036 | pNewProgDetails->swpInitial.cx,
|
---|
1037 | pNewProgDetails->swpInitial.cy));
|
---|
1038 | _Pmpf((" behind = %d, hwnd = %d, res1 = %d, res2 = %d",
|
---|
1039 | pNewProgDetails->swpInitial.hwndInsertBehind,
|
---|
1040 | pNewProgDetails->swpInitial.hwnd,
|
---|
1041 | pNewProgDetails->swpInitial.ulReserved1,
|
---|
1042 | pNewProgDetails->swpInitial.ulReserved2));
|
---|
1043 |
|
---|
1044 | if (!(*phapp = WinStartApp(hwndNotify,
|
---|
1045 | // receives WM_APPTERMINATENOTIFY
|
---|
1046 | pNewProgDetails,
|
---|
1047 | pNewProgDetails->pszParameters,
|
---|
1048 | NULL, // "reserved", PMREF says...
|
---|
1049 | SAF_INSTALLEDCMDLINE)))
|
---|
1050 | // we MUST use SAF_INSTALLEDCMDLINE
|
---|
1051 | // or no Win-OS/2 session will start...
|
---|
1052 | // whatever is going on here... Warp 4 FP11
|
---|
1053 |
|
---|
1054 | // do not use SAF_STARTCHILDAPP, or the
|
---|
1055 | // app will be terminated automatically
|
---|
1056 | // when the WPS terminates!
|
---|
1057 | {
|
---|
1058 | // cannot start app:
|
---|
1059 | // _Pmpf((__FUNCTION__ ": WinStartApp failed"));
|
---|
1060 | arc = ERROR_FILE_NOT_FOUND;
|
---|
1061 | // unfortunately WinStartApp doesn't
|
---|
1062 | // return meaningful codes like DosStartSession, so
|
---|
1063 | // try to see what happened
|
---|
1064 | /*
|
---|
1065 | switch (ERRORIDERROR(WinGetLastError(0)))
|
---|
1066 | {
|
---|
1067 | case PMERR_DOS_ERROR: // (0x1200)
|
---|
1068 | {
|
---|
1069 | arc = ERROR_FILE_NOT_FOUND;
|
---|
1070 |
|
---|
1071 | // this is probably the case where the module
|
---|
1072 | // couldn't be loaded, so try DosStartSession
|
---|
1073 | // to get a meaningful return code... note that
|
---|
1074 | // this cannot handle hwndNotify then
|
---|
1075 | RESULTCODES result;
|
---|
1076 | arc = DosExecPgm(pszFailingName,
|
---|
1077 | cbFailingName,
|
---|
1078 | EXEC_ASYNC,
|
---|
1079 | NULL, // ProgDetails.pszParameters,
|
---|
1080 | NULL, // ProgDetails.pszEnvironment,
|
---|
1081 | &result,
|
---|
1082 | ProgDetails.pszExecutable);
|
---|
1083 | ULONG sid, pid;
|
---|
1084 | STARTDATA SData;
|
---|
1085 | SData.Length = sizeof(STARTDATA);
|
---|
1086 | SData.Related = SSF_RELATED_CHILD; //INDEPENDENT;
|
---|
1087 | SData.FgBg = SSF_FGBG_FORE;
|
---|
1088 | SData.TraceOpt = SSF_TRACEOPT_NONE;
|
---|
1089 |
|
---|
1090 | SData.PgmTitle = ProgDetails.pszTitle;
|
---|
1091 | SData.PgmName = ProgDetails.pszExecutable;
|
---|
1092 | SData.PgmInputs = ProgDetails.pszParameters;
|
---|
1093 |
|
---|
1094 | SData.TermQ = NULL;
|
---|
1095 | SData.Environment = ProgDetails.pszEnvironment;
|
---|
1096 | SData.InheritOpt = SSF_INHERTOPT_PARENT; // ignored
|
---|
1097 | SData.SessionType = SSF_TYPE_DEFAULT;
|
---|
1098 | SData.IconFile = 0;
|
---|
1099 | SData.PgmHandle = 0;
|
---|
1100 |
|
---|
1101 | SData.PgmControl = SSF_CONTROL_VISIBLE;
|
---|
1102 |
|
---|
1103 | SData.InitXPos = 30;
|
---|
1104 | SData.InitYPos = 40;
|
---|
1105 | SData.InitXSize = 200;
|
---|
1106 | SData.InitYSize = 140;
|
---|
1107 | SData.Reserved = 0;
|
---|
1108 | SData.ObjectBuffer = pszFailingName;
|
---|
1109 | SData.ObjectBuffLen = cbFailingName;
|
---|
1110 |
|
---|
1111 | arc = DosStartSession(&SData, &sid, &pid);
|
---|
1112 | }
|
---|
1113 | break;
|
---|
1114 |
|
---|
1115 | case PMERR_INVALID_APPL: // (0x1530)
|
---|
1116 | // Attempted to start an application whose type is not
|
---|
1117 | // recognized by OS/2.
|
---|
1118 | arc = ERROR_INVALID_EXE_SIGNATURE;
|
---|
1119 | break;
|
---|
1120 |
|
---|
1121 | case PMERR_INVALID_PARAMETERS: // (0x1208)
|
---|
1122 | // An application parameter value is invalid for
|
---|
1123 | // its converted PM type. For example: a 4-byte
|
---|
1124 | // value outside the range -32 768 to +32 767 cannot be
|
---|
1125 | // converted to a SHORT, and a negative number cannot
|
---|
1126 | // be converted to a ULONG or USHORT.
|
---|
1127 | arc = ERROR_INVALID_DATA;
|
---|
1128 | break;
|
---|
1129 |
|
---|
1130 | case PMERR_STARTED_IN_BACKGROUND: // (0x1532)
|
---|
1131 | // The application started a new session in the
|
---|
1132 | // background.
|
---|
1133 | arc = ERROR_SMG_START_IN_BACKGROUND;
|
---|
1134 | break;
|
---|
1135 |
|
---|
1136 | case PMERR_INVALID_WINDOW: // (0x1206)
|
---|
1137 | // The window specified with a Window List call
|
---|
1138 | // is not a valid frame window.
|
---|
1139 |
|
---|
1140 | default:
|
---|
1141 | arc = ERROR_BAD_FORMAT;
|
---|
1142 | break;
|
---|
1143 | }
|
---|
1144 | */
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | DosFreeMem(pNewProgDetails);
|
---|
1148 | }
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | return (arc);
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | /*
|
---|
1155 | *@@ appStartApp:
|
---|
1156 | * wrapper around WinStartApp which fixes the
|
---|
1157 | * specified PROGDETAILS to (hopefully) work
|
---|
1158 | * work with all executable types.
|
---|
1159 | *
|
---|
1160 | * This fixes the executable info to support:
|
---|
1161 | *
|
---|
1162 | * -- starting "*" executables (command prompts
|
---|
1163 | * for OS/2, DOS, Win-OS/2);
|
---|
1164 | *
|
---|
1165 | * -- starting ".CMD" and ".BAT" files as
|
---|
1166 | * PROGDETAILS.pszExecutable;
|
---|
1167 | *
|
---|
1168 | * -- starting apps which are not fully qualified
|
---|
1169 | * and therefore assumed to be on the PATH.
|
---|
1170 | *
|
---|
1171 | * Unless it is "*", PROGDETAILS.pszExecutable must
|
---|
1172 | * be a proper file name. The full path may be omitted
|
---|
1173 | * if it is on the PATH, but the extension (.EXE etc.)
|
---|
1174 | * must be given. You can use doshFindExecutable to
|
---|
1175 | * find executables if you don't know the extension.
|
---|
1176 | *
|
---|
1177 | * This also handles and merges special and default
|
---|
1178 | * environments for the app to be started. The
|
---|
1179 | * following should be respected:
|
---|
1180 | *
|
---|
1181 | * -- As with WinStartApp, if PROGDETAILS.pszEnvironment
|
---|
1182 | * is NULL, the new app inherits a default environment
|
---|
1183 | * from the shell.
|
---|
1184 | *
|
---|
1185 | * -- However, if you specify an environment, you _must_
|
---|
1186 | * specify a complete environment. This function
|
---|
1187 | * will not merge environments. Use
|
---|
1188 | * appSetEnvironmentVar to change environment
|
---|
1189 | * variables in a complete environment set.
|
---|
1190 | *
|
---|
1191 | * -- If PROGDETAILS specifies a Win-OS/2 session
|
---|
1192 | * and PROGDETAILS.pszEnvironment is empty,
|
---|
1193 | * this uses the default Win-OS/2 environment.
|
---|
1194 | * See appQueryDefaultWin31Environment.
|
---|
1195 | *
|
---|
1196 | * Even though this isn't clearly said in PMREF,
|
---|
1197 | * PROGDETAILS.swpInitial is important:
|
---|
1198 | *
|
---|
1199 | * -- To start a session minimized, set SWP_MINIMIZE.
|
---|
1200 | *
|
---|
1201 | * -- To start a VIO session with auto-close disabled,
|
---|
1202 | * set the half-documented SWP_NOAUTOCLOSE flag (0x8000)
|
---|
1203 | * This flag is now in the newer toolkit headers.
|
---|
1204 | *
|
---|
1205 | * In addition, this supports the following session
|
---|
1206 | * flags with ulFlags if PROG_DEFAULT is specified:
|
---|
1207 | *
|
---|
1208 | * -- APP_RUN_FULLSCREEN
|
---|
1209 | *
|
---|
1210 | * -- APP_RUN_ENHANCED
|
---|
1211 | *
|
---|
1212 | * -- APP_RUN_STANDARD
|
---|
1213 | *
|
---|
1214 | * -- APP_RUN_SEPARATE
|
---|
1215 | *
|
---|
1216 | * Since this calls WinStartApp in turn, this
|
---|
1217 | * requires a message queue on the calling thread.
|
---|
1218 | *
|
---|
1219 | * Note that this also does minimal checking on
|
---|
1220 | * the specified parameters so it can return something
|
---|
1221 | * more meaningful than FALSE like WinStartApp.
|
---|
1222 | * As a result, you get a DOS error code now (V0.9.16).
|
---|
1223 | *
|
---|
1224 | * Most importantly:
|
---|
1225 | *
|
---|
1226 | * -- ERROR_INVALID_THREADID: not running on thread 1.
|
---|
1227 | * Since this uses WinStartApp internally and
|
---|
1228 | * WinStartApp completely hangs the session manager
|
---|
1229 | * if a Win-OS/2 full-screen session is started from
|
---|
1230 | * a thread that is NOT thread 1, this will now fail
|
---|
1231 | * with this error for safety (V0.9.16).
|
---|
1232 | *
|
---|
1233 | * -- ERROR_INVALID_PARAMETER: pcProgDetails or
|
---|
1234 | * phapp is NULL; or PROGDETAILS.pszExecutable is NULL.
|
---|
1235 | *
|
---|
1236 | * -- ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND:
|
---|
1237 | * PROGDETAILS.pszExecutable and/or PROGDETAILS.pszStartupDir
|
---|
1238 | * are invalid.
|
---|
1239 | * A NULL PROGDETAILS.pszStartupDir is supported though.
|
---|
1240 | *
|
---|
1241 | * -- ERROR_NOT_ENOUGH_MEMORY
|
---|
1242 | *
|
---|
1243 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
---|
1244 | *@@changed V0.9.7 (2000-12-10) [umoeller]: PROGDETAILS.swpInitial no longer zeroed... this broke VIOs
|
---|
1245 | *@@changed V0.9.7 (2000-12-17) [umoeller]: PROGDETAILS.pszEnvironment no longer zeroed
|
---|
1246 | *@@changed V0.9.9 (2001-01-27) [umoeller]: crashed if PROGDETAILS.pszExecutable was NULL
|
---|
1247 | *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed PROG_DEFAULT
|
---|
1248 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
---|
1249 | *@@changed V0.9.14 (2001-08-07) [pr]: removed some env. strings for Win. apps.
|
---|
1250 | *@@changed V0.9.14 (2001-08-23) [pr]: added session type options
|
---|
1251 | *@@changed V0.9.16 (2001-10-19) [umoeller]: added prototype to return APIRET
|
---|
1252 | *@@changed V0.9.16 (2001-10-19) [umoeller]: added thread-1 check
|
---|
1253 | *@@changed V0.9.16 (2001-12-06) [umoeller]: now using doshSearchPath for finding pszExecutable if not qualified
|
---|
1254 | *@@changed V0.9.16 (2002-01-04) [umoeller]: removed error report if startup directory was drive letter only
|
---|
1255 | *@@changed V0.9.16 (2002-01-04) [umoeller]: added more detailed error reports and *FailingName params
|
---|
1256 | *@@changed V0.9.18 (2002-02-13) [umoeller]: added CallWinStartApp to fix possible memory problems
|
---|
1257 | */
|
---|
1258 |
|
---|
1259 | APIRET appStartApp(HWND hwndNotify, // in: notify window or NULLHANDLE
|
---|
1260 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
---|
1261 | ULONG ulFlags, // in: APP_RUN_* flags
|
---|
1262 | HAPP *phapp, // out: application handle if NO_ERROR is returned
|
---|
1263 | ULONG cbFailingName,
|
---|
1264 | PSZ pszFailingName)
|
---|
1265 | {
|
---|
1266 | APIRET arc = NO_ERROR;
|
---|
1267 | PROGDETAILS ProgDetails;
|
---|
1268 |
|
---|
1269 | if (pszFailingName)
|
---|
1270 | *pszFailingName = '\0';
|
---|
1271 |
|
---|
1272 | if (!pcProgDetails || !phapp)
|
---|
1273 | return (ERROR_INVALID_PARAMETER);
|
---|
1274 |
|
---|
1275 | memcpy(&ProgDetails, pcProgDetails, sizeof(PROGDETAILS));
|
---|
1276 | // pointers still point into old prog details buffer
|
---|
1277 | ProgDetails.Length = sizeof(PROGDETAILS);
|
---|
1278 | ProgDetails.progt.fbVisible = SHE_VISIBLE;
|
---|
1279 |
|
---|
1280 | // all this only makes sense if this contains something...
|
---|
1281 | // besides, this crashed on string comparisons V0.9.9 (2001-01-27) [umoeller]
|
---|
1282 | if ( (!ProgDetails.pszExecutable)
|
---|
1283 | || (!(*(ProgDetails.pszExecutable)))
|
---|
1284 | )
|
---|
1285 | arc = ERROR_INVALID_PARAMETER;
|
---|
1286 | else if (doshMyTID() != 1) // V0.9.16 (2001-10-19) [umoeller]
|
---|
1287 | arc = ERROR_INVALID_THREADID;
|
---|
1288 | else
|
---|
1289 | {
|
---|
1290 | ULONG ulIsWinApp;
|
---|
1291 |
|
---|
1292 | CHAR szFQExecutable[CCHMAXPATH];
|
---|
1293 |
|
---|
1294 | XSTRING strParamsPatched;
|
---|
1295 | PSZ pszWinOS2Env = 0;
|
---|
1296 |
|
---|
1297 | // memset(&ProgDetails.swpInitial, 0, sizeof(SWP));
|
---|
1298 | // this wasn't a good idea... WPProgram stores stuff
|
---|
1299 | // in here, such as the "minimize on startup" -> SWP_MINIMIZE
|
---|
1300 |
|
---|
1301 | // duplicate parameters...
|
---|
1302 | // we need this for string manipulations below...
|
---|
1303 | if (ProgDetails.pszParameters)
|
---|
1304 | xstrInitCopy(&strParamsPatched,
|
---|
1305 | ProgDetails.pszParameters,
|
---|
1306 | 100);
|
---|
1307 | else
|
---|
1308 | // no old params:
|
---|
1309 | xstrInit(&strParamsPatched, 100);
|
---|
1310 |
|
---|
1311 | // _Pmpf((__FUNCTION__ ": old progc: 0x%lX", pcProgDetails->progt.progc));
|
---|
1312 | // _Pmpf((" pszTitle: %s", (ProgDetails.pszTitle) ? ProgDetails.pszTitle : NULL));
|
---|
1313 | // _Pmpf((" pszIcon: %s", (ProgDetails.pszIcon) ? ProgDetails.pszIcon : NULL));
|
---|
1314 |
|
---|
1315 | // program type fixups
|
---|
1316 | switch (ProgDetails.progt.progc) // that's a ULONG
|
---|
1317 | {
|
---|
1318 | case ((ULONG)-1): // we get that sometimes...
|
---|
1319 | case PROG_DEFAULT:
|
---|
1320 | {
|
---|
1321 | // V0.9.12 (2001-05-26) [umoeller]
|
---|
1322 | ULONG ulDosAppType;
|
---|
1323 | appQueryAppType(ProgDetails.pszExecutable,
|
---|
1324 | &ulDosAppType,
|
---|
1325 | &ProgDetails.progt.progc);
|
---|
1326 | }
|
---|
1327 | break;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | // set session type from option flags
|
---|
1331 | if (ulFlags & APP_RUN_FULLSCREEN)
|
---|
1332 | {
|
---|
1333 | if (ProgDetails.progt.progc == PROG_WINDOWABLEVIO)
|
---|
1334 | ProgDetails.progt.progc = PROG_FULLSCREEN;
|
---|
1335 |
|
---|
1336 | if (ProgDetails.progt.progc == PROG_WINDOWEDVDM)
|
---|
1337 | ProgDetails.progt.progc = PROG_VDM;
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | if (ulIsWinApp = appIsWindowsApp(ProgDetails.progt.progc))
|
---|
1341 | {
|
---|
1342 | if (ulFlags & APP_RUN_FULLSCREEN)
|
---|
1343 | ProgDetails.progt.progc = (ulFlags & APP_RUN_ENHANCED)
|
---|
1344 | ? PROG_31_ENH
|
---|
1345 | : PROG_31_STD;
|
---|
1346 | else
|
---|
1347 | {
|
---|
1348 | if (ulFlags & APP_RUN_STANDARD)
|
---|
1349 | ProgDetails.progt.progc = (ulFlags & APP_RUN_SEPARATE)
|
---|
1350 | ? PROG_31_STDSEAMLESSVDM
|
---|
1351 | : PROG_31_STDSEAMLESSCOMMON;
|
---|
1352 |
|
---|
1353 | if (ulFlags & APP_RUN_ENHANCED)
|
---|
1354 | ProgDetails.progt.progc = (ulFlags & APP_RUN_SEPARATE)
|
---|
1355 | ? PROG_31_ENHSEAMLESSVDM
|
---|
1356 | : PROG_31_ENHSEAMLESSCOMMON;
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | // re-run V0.9.16 (2001-10-19) [umoeller]
|
---|
1360 | ulIsWinApp = appIsWindowsApp(ProgDetails.progt.progc);
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | /*
|
---|
1364 | * command lines fixups:
|
---|
1365 | *
|
---|
1366 | */
|
---|
1367 |
|
---|
1368 | if (!strcmp(ProgDetails.pszExecutable, "*"))
|
---|
1369 | {
|
---|
1370 | /*
|
---|
1371 | * "*" for command sessions:
|
---|
1372 | *
|
---|
1373 | */
|
---|
1374 |
|
---|
1375 | if (ulIsWinApp == 2)
|
---|
1376 | {
|
---|
1377 | // enhanced Win-OS/2 session:
|
---|
1378 | PSZ psz = NULL;
|
---|
1379 | if (strParamsPatched.ulLength)
|
---|
1380 | // "/3 " + existing params
|
---|
1381 | psz = strdup(strParamsPatched.psz);
|
---|
1382 |
|
---|
1383 | xstrcpy(&strParamsPatched, "/3 ", 0);
|
---|
1384 |
|
---|
1385 | if (psz)
|
---|
1386 | {
|
---|
1387 | xstrcat(&strParamsPatched, psz, 0);
|
---|
1388 | free(psz);
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | if (ulIsWinApp)
|
---|
1393 | {
|
---|
1394 | // cheat: WinStartApp doesn't support NULL
|
---|
1395 | // for Win-OS2 sessions, so manually start winos2.com
|
---|
1396 | ProgDetails.pszExecutable = "WINOS2.COM";
|
---|
1397 | // this is a DOS app, so fix this to DOS fullscreen
|
---|
1398 | ProgDetails.progt.progc = PROG_VDM;
|
---|
1399 | }
|
---|
1400 | else
|
---|
1401 | // for all other executable types
|
---|
1402 | // (including OS/2 and DOS sessions),
|
---|
1403 | // set pszExecutable to NULL; this will
|
---|
1404 | // have WinStartApp start a cmd shell
|
---|
1405 | ProgDetails.pszExecutable = NULL;
|
---|
1406 |
|
---|
1407 | } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
|
---|
1408 | else
|
---|
1409 | {
|
---|
1410 | // check if the executable is fully qualified; if so,
|
---|
1411 | // check if the executable file exists
|
---|
1412 | if ( (ProgDetails.pszExecutable[1] == ':')
|
---|
1413 | && (strchr(ProgDetails.pszExecutable, '\\'))
|
---|
1414 | )
|
---|
1415 | {
|
---|
1416 | ULONG ulAttr;
|
---|
1417 | if (!(arc = doshQueryPathAttr(ProgDetails.pszExecutable,
|
---|
1418 | &ulAttr)))
|
---|
1419 | {
|
---|
1420 | // make sure startup dir is really a directory
|
---|
1421 | if (ProgDetails.pszStartupDir)
|
---|
1422 | {
|
---|
1423 | // it is valid to specify a startup dir of "C:"
|
---|
1424 | if ( (strlen(ProgDetails.pszStartupDir) > 2)
|
---|
1425 | && (!(arc = doshQueryPathAttr(ProgDetails.pszStartupDir,
|
---|
1426 | &ulAttr)))
|
---|
1427 | && (!(ulAttr & FILE_DIRECTORY))
|
---|
1428 | )
|
---|
1429 | arc = ERROR_PATH_NOT_FOUND;
|
---|
1430 | }
|
---|
1431 | }
|
---|
1432 | }
|
---|
1433 | else
|
---|
1434 | {
|
---|
1435 | // _not_ fully qualified: look it up on the PATH then
|
---|
1436 | // V0.9.16 (2001-12-06) [umoeller]
|
---|
1437 | if (!(arc = doshSearchPath("PATH",
|
---|
1438 | ProgDetails.pszExecutable,
|
---|
1439 | szFQExecutable,
|
---|
1440 | sizeof(szFQExecutable))))
|
---|
1441 | // alright, found it:
|
---|
1442 | ProgDetails.pszExecutable = szFQExecutable;
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | if (!arc)
|
---|
1446 | {
|
---|
1447 | PSZ pszExtension;
|
---|
1448 | switch (ProgDetails.progt.progc)
|
---|
1449 | {
|
---|
1450 | /*
|
---|
1451 | * .CMD files fixups
|
---|
1452 | *
|
---|
1453 | */
|
---|
1454 |
|
---|
1455 | case PROG_FULLSCREEN: // OS/2 fullscreen
|
---|
1456 | case PROG_WINDOWABLEVIO: // OS/2 window
|
---|
1457 | {
|
---|
1458 | if ( (pszExtension = doshGetExtension(ProgDetails.pszExecutable))
|
---|
1459 | && (!stricmp(pszExtension, "CMD"))
|
---|
1460 | )
|
---|
1461 | {
|
---|
1462 | CallBatchCorrectly(&ProgDetails,
|
---|
1463 | &strParamsPatched,
|
---|
1464 | "OS2_SHELL",
|
---|
1465 | "CMD.EXE");
|
---|
1466 | }
|
---|
1467 | break; }
|
---|
1468 |
|
---|
1469 | case PROG_VDM: // DOS fullscreen
|
---|
1470 | case PROG_WINDOWEDVDM: // DOS window
|
---|
1471 | {
|
---|
1472 | if ( (pszExtension = doshGetExtension(ProgDetails.pszExecutable))
|
---|
1473 | && (!stricmp(pszExtension, "BAT"))
|
---|
1474 | )
|
---|
1475 | {
|
---|
1476 | CallBatchCorrectly(&ProgDetails,
|
---|
1477 | &strParamsPatched,
|
---|
1478 | NULL,
|
---|
1479 | "COMMAND.COM");
|
---|
1480 | }
|
---|
1481 | break; }
|
---|
1482 | } // end switch (ProgDetails.progt.progc)
|
---|
1483 | }
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | if (!arc)
|
---|
1487 | {
|
---|
1488 | if ( (ulIsWinApp)
|
---|
1489 | && ( (ProgDetails.pszEnvironment == NULL)
|
---|
1490 | || (!strlen(ProgDetails.pszEnvironment))
|
---|
1491 | )
|
---|
1492 | )
|
---|
1493 | {
|
---|
1494 | // this is a windoze app, and caller didn't bother
|
---|
1495 | // to give us an environment:
|
---|
1496 | // we MUST set one then, or we'll get the strangest
|
---|
1497 | // errors, up to system hangs. V0.9.12 (2001-05-26) [umoeller]
|
---|
1498 |
|
---|
1499 | DOSENVIRONMENT Env = {0};
|
---|
1500 |
|
---|
1501 | // get standard WIN-OS/2 environment
|
---|
1502 | PSZ pszTemp = appQueryDefaultWin31Environment();
|
---|
1503 |
|
---|
1504 | if (!(arc = appParseEnvironment(pszTemp,
|
---|
1505 | &Env)))
|
---|
1506 | {
|
---|
1507 | // now override KBD_CTRL_BYPASS=CTRL_ESC
|
---|
1508 | if ( (!(arc = appSetEnvironmentVar(&Env,
|
---|
1509 | "KBD_CTRL_BYPASS=CTRL_ESC",
|
---|
1510 | FALSE))) // add last
|
---|
1511 | && (!(arc = appConvertEnvironment(&Env,
|
---|
1512 | &pszWinOS2Env, // freed at bottom
|
---|
1513 | NULL)))
|
---|
1514 | )
|
---|
1515 | ProgDetails.pszEnvironment = pszWinOS2Env;
|
---|
1516 |
|
---|
1517 | appFreeEnvironment(&Env);
|
---|
1518 | }
|
---|
1519 |
|
---|
1520 | free(pszTemp);
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | if (!arc)
|
---|
1524 | {
|
---|
1525 | if (!ProgDetails.pszTitle)
|
---|
1526 | ProgDetails.pszTitle = ProgDetails.pszExecutable;
|
---|
1527 |
|
---|
1528 | ProgDetails.pszParameters = strParamsPatched.psz;
|
---|
1529 |
|
---|
1530 | if (pszFailingName)
|
---|
1531 | strhncpy0(pszFailingName, ProgDetails.pszExecutable, cbFailingName);
|
---|
1532 |
|
---|
1533 | arc = CallWinStartApp(phapp,
|
---|
1534 | hwndNotify,
|
---|
1535 | &ProgDetails,
|
---|
1536 | strParamsPatched.psz);
|
---|
1537 | }
|
---|
1538 | }
|
---|
1539 |
|
---|
1540 | xstrClear(&strParamsPatched);
|
---|
1541 | if (pszWinOS2Env)
|
---|
1542 | free(pszWinOS2Env);
|
---|
1543 | } // end if (ProgDetails.pszExecutable)
|
---|
1544 |
|
---|
1545 | // _Pmpf((__FUNCTION__ ": returning %d", arc));
|
---|
1546 |
|
---|
1547 | return (arc);
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | /*
|
---|
1551 | *@@ appWaitForApp:
|
---|
1552 | * waits for the specified application to terminate
|
---|
1553 | * and returns its exit code.
|
---|
1554 | *
|
---|
1555 | *@@added V0.9.9 (2001-03-07) [umoeller]
|
---|
1556 | */
|
---|
1557 |
|
---|
1558 | BOOL appWaitForApp(HWND hwndNotify, // in: notify window
|
---|
1559 | HAPP happ, // in: app to wait for
|
---|
1560 | PULONG pulExitCode) // out: exit code (ptr can be NULL)
|
---|
1561 | {
|
---|
1562 | BOOL brc = FALSE;
|
---|
1563 |
|
---|
1564 | if (happ)
|
---|
1565 | {
|
---|
1566 | // app started:
|
---|
1567 | // enter a modal message loop until we get the
|
---|
1568 | // WM_APPTERMINATENOTIFY for happ. Then we
|
---|
1569 | // know the app is done.
|
---|
1570 | HAB hab = WinQueryAnchorBlock(hwndNotify);
|
---|
1571 | QMSG qmsg;
|
---|
1572 | // ULONG ulXFixReturnCode = 0;
|
---|
1573 | while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
|
---|
1574 | {
|
---|
1575 | if ( (qmsg.msg == WM_APPTERMINATENOTIFY)
|
---|
1576 | && (qmsg.hwnd == hwndNotify)
|
---|
1577 | && (qmsg.mp1 == (MPARAM)happ)
|
---|
1578 | )
|
---|
1579 | {
|
---|
1580 | // xfix has terminated:
|
---|
1581 | // get xfix return code from mp2... this is:
|
---|
1582 | // -- 0: everything's OK, continue.
|
---|
1583 | // -- 1: handle section was rewritten, restart Desktop
|
---|
1584 | // now.
|
---|
1585 | if (pulExitCode)
|
---|
1586 | *pulExitCode = (ULONG)qmsg.mp2;
|
---|
1587 | brc = TRUE;
|
---|
1588 | // do not dispatch this
|
---|
1589 | break;
|
---|
1590 | }
|
---|
1591 |
|
---|
1592 | WinDispatchMsg(hab, &qmsg);
|
---|
1593 | }
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | return (brc);
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | /*
|
---|
1600 | *@@ appQuickStartApp:
|
---|
1601 | * shortcut for simply starting an app and
|
---|
1602 | * waiting until it's finished.
|
---|
1603 | *
|
---|
1604 | * On errors, NULLHANDLE is returned.
|
---|
1605 | *
|
---|
1606 | * If pulReturnCode != NULL, it receives the
|
---|
1607 | * return code of the app.
|
---|
1608 | *
|
---|
1609 | *@@added V0.9.16 (2001-10-19) [umoeller]
|
---|
1610 | */
|
---|
1611 |
|
---|
1612 | HAPP appQuickStartApp(const char *pcszFile,
|
---|
1613 | ULONG ulProgType, // e.g. PROG_PM
|
---|
1614 | const char *pcszArgs,
|
---|
1615 | PULONG pulExitCode)
|
---|
1616 | {
|
---|
1617 | PROGDETAILS pd = {0};
|
---|
1618 | HAPP happ,
|
---|
1619 | happReturn = NULLHANDLE;
|
---|
1620 | CHAR szDir[CCHMAXPATH] = "";
|
---|
1621 | PCSZ p;
|
---|
1622 | HWND hwndObject;
|
---|
1623 |
|
---|
1624 | pd.Length = sizeof(pd);
|
---|
1625 | pd.progt.progc = ulProgType;
|
---|
1626 | pd.progt.fbVisible = SHE_VISIBLE;
|
---|
1627 | pd.pszExecutable = (PSZ)pcszFile;
|
---|
1628 | pd.pszParameters = (PSZ)pcszArgs;
|
---|
1629 | if (p = strrchr(pcszFile, '\\'))
|
---|
1630 | {
|
---|
1631 | strhncpy0(szDir,
|
---|
1632 | pcszFile,
|
---|
1633 | p - pcszFile);
|
---|
1634 | pd.pszStartupDir = szDir;
|
---|
1635 | }
|
---|
1636 |
|
---|
1637 | if ( (hwndObject = winhCreateObjectWindow(WC_STATIC, NULL))
|
---|
1638 | && (!appStartApp(hwndObject,
|
---|
1639 | &pd,
|
---|
1640 | 0,
|
---|
1641 | &happ,
|
---|
1642 | 0,
|
---|
1643 | NULL))
|
---|
1644 | )
|
---|
1645 | {
|
---|
1646 | if (appWaitForApp(hwndObject,
|
---|
1647 | happ,
|
---|
1648 | pulExitCode))
|
---|
1649 | happReturn = happ;
|
---|
1650 | }
|
---|
1651 |
|
---|
1652 | return (happReturn);
|
---|
1653 | }
|
---|