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-2005 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_DOSEXCEPTIONS
|
---|
36 | #define INCL_DOSMODULEMGR
|
---|
37 | #define INCL_DOSSESMGR
|
---|
38 | #define INCL_DOSERRORS
|
---|
39 |
|
---|
40 | #define INCL_WINPROGRAMLIST // needed for PROGDETAILS, wppgm.h
|
---|
41 | #define INCL_WINSHELLDATA
|
---|
42 | #define INCL_WINERRORS
|
---|
43 | #define INCL_SHLERRORS
|
---|
44 | #include <os2.h>
|
---|
45 |
|
---|
46 | #include <stdio.h>
|
---|
47 | #include <setjmp.h> // needed for except.h
|
---|
48 | #include <assert.h> // needed for except.h
|
---|
49 |
|
---|
50 | #include "setup.h" // code generation and debugging options
|
---|
51 |
|
---|
52 | #include "helpers\dosh.h"
|
---|
53 | #include "helpers\except.h" // exception handling
|
---|
54 | #include "helpers\prfh.h"
|
---|
55 | #include "helpers\standards.h" // some standard macros
|
---|
56 | #include "helpers\stringh.h"
|
---|
57 | #include "helpers\winh.h"
|
---|
58 | #include "helpers\xstring.h"
|
---|
59 |
|
---|
60 | #include "helpers\apps.h"
|
---|
61 |
|
---|
62 | /*
|
---|
63 | *@@category: Helpers\PM helpers\Application helpers
|
---|
64 | */
|
---|
65 |
|
---|
66 | /* ******************************************************************
|
---|
67 | *
|
---|
68 | * Environment helpers
|
---|
69 | *
|
---|
70 | ********************************************************************/
|
---|
71 |
|
---|
72 | /*
|
---|
73 | *@@ appQueryEnvironmentLen:
|
---|
74 | * returns the total length of the passed in environment
|
---|
75 | * string buffer, including the terminating two null bytes.
|
---|
76 | *
|
---|
77 | *@@added V0.9.16 (2002-01-09) [umoeller]
|
---|
78 | */
|
---|
79 |
|
---|
80 | ULONG appQueryEnvironmentLen(PCSZ pcszEnvironment)
|
---|
81 | {
|
---|
82 | ULONG cbEnvironment = 0;
|
---|
83 | if (pcszEnvironment)
|
---|
84 | {
|
---|
85 | PCSZ pVarThis = pcszEnvironment;
|
---|
86 | // go thru the environment strings; last one has two null bytes
|
---|
87 | while (*pVarThis)
|
---|
88 | {
|
---|
89 | ULONG ulLenThis = strlen(pVarThis) + 1;
|
---|
90 | cbEnvironment += ulLenThis;
|
---|
91 | pVarThis += ulLenThis;
|
---|
92 | }
|
---|
93 |
|
---|
94 | cbEnvironment++; // last null byte
|
---|
95 | }
|
---|
96 |
|
---|
97 | return cbEnvironment;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*
|
---|
101 | *@@ appParseEnvironment:
|
---|
102 | * this takes one of those ugly environment strings
|
---|
103 | * as used by DosStartSession and WinStartApp (with
|
---|
104 | * lots of zero-terminated strings one after another
|
---|
105 | * and a duplicate zero byte as a terminator) as
|
---|
106 | * input and splits it into an array of separate
|
---|
107 | * strings in pEnv.
|
---|
108 | *
|
---|
109 | * The newly allocated strings are stored in in
|
---|
110 | * pEnv->papszVars. The array count is stored in
|
---|
111 | * pEnv->cVars.
|
---|
112 | *
|
---|
113 | * Each environment variable will be copied into
|
---|
114 | * one newly allocated string in the array. Use
|
---|
115 | * appFreeEnvironment to free the memory allocated
|
---|
116 | * by this function.
|
---|
117 | *
|
---|
118 | * Use the following code to browse thru the array:
|
---|
119 | +
|
---|
120 | + DOSENVIRONMENT Env = {0};
|
---|
121 | + if (appParseEnvironment(pszEnv,
|
---|
122 | + &Env)
|
---|
123 | + == NO_ERROR)
|
---|
124 | + {
|
---|
125 | + if (Env.papszVars)
|
---|
126 | + {
|
---|
127 | + PSZ *ppszThis = Env.papszVars;
|
---|
128 | + for (ul = 0;
|
---|
129 | + ul < Env.cVars;
|
---|
130 | + ul++)
|
---|
131 | + {
|
---|
132 | + PSZ pszThis = *ppszThis;
|
---|
133 | + // pszThis now has something like PATH=C:\TEMP
|
---|
134 | + // ...
|
---|
135 | + // next environment string
|
---|
136 | + ppszThis++;
|
---|
137 | + }
|
---|
138 | + }
|
---|
139 | + appFreeEnvironment(&Env);
|
---|
140 | + }
|
---|
141 | *
|
---|
142 | *@@added V0.9.4 (2000-08-02) [umoeller]
|
---|
143 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
144 | */
|
---|
145 |
|
---|
146 | APIRET appParseEnvironment(const char *pcszEnv,
|
---|
147 | PDOSENVIRONMENT pEnv) // out: new environment
|
---|
148 | {
|
---|
149 | APIRET arc = NO_ERROR;
|
---|
150 | if (!pcszEnv)
|
---|
151 | arc = ERROR_INVALID_PARAMETER;
|
---|
152 | else
|
---|
153 | {
|
---|
154 | PSZ pszVarThis = (PSZ)pcszEnv;
|
---|
155 | ULONG cVars = 0;
|
---|
156 | // count strings
|
---|
157 | while (*pszVarThis)
|
---|
158 | {
|
---|
159 | cVars++;
|
---|
160 | pszVarThis += strlen(pszVarThis) + 1;
|
---|
161 | }
|
---|
162 |
|
---|
163 | pEnv->cVars = 0;
|
---|
164 | pEnv->papszVars = 0;
|
---|
165 |
|
---|
166 | if (cVars)
|
---|
167 | {
|
---|
168 | ULONG cbArray = sizeof(PSZ) * cVars;
|
---|
169 | PSZ *papsz;
|
---|
170 | if (!(papsz = (PSZ*)malloc(cbArray)))
|
---|
171 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
172 | else
|
---|
173 | {
|
---|
174 | PSZ *ppszTarget = papsz;
|
---|
175 | memset(papsz, 0, cbArray);
|
---|
176 | pszVarThis = (PSZ)pcszEnv;
|
---|
177 | while (*pszVarThis)
|
---|
178 | {
|
---|
179 | ULONG ulThisLen;
|
---|
180 | if (!(*ppszTarget = strhdup(pszVarThis, &ulThisLen)))
|
---|
181 | {
|
---|
182 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
183 | break;
|
---|
184 | }
|
---|
185 | (pEnv->cVars)++;
|
---|
186 | ppszTarget++;
|
---|
187 | pszVarThis += ulThisLen + 1;
|
---|
188 | }
|
---|
189 |
|
---|
190 | pEnv->papszVars = papsz;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | return arc;
|
---|
196 | }
|
---|
197 |
|
---|
198 | /*
|
---|
199 | *@@ appGetEnvironment:
|
---|
200 | * calls appParseEnvironment for the current
|
---|
201 | * process environment, which is retrieved from
|
---|
202 | * the info blocks.
|
---|
203 | *
|
---|
204 | * Returns:
|
---|
205 | *
|
---|
206 | * -- NO_ERROR:
|
---|
207 | *
|
---|
208 | * -- ERROR_INVALID_PARAMETER
|
---|
209 | *
|
---|
210 | * -- ERROR_BAD_ENVIRONMENT: no environment found in
|
---|
211 | * info blocks.
|
---|
212 | *
|
---|
213 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
214 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
215 | */
|
---|
216 |
|
---|
217 | APIRET appGetEnvironment(PDOSENVIRONMENT pEnv)
|
---|
218 | {
|
---|
219 | APIRET arc = NO_ERROR;
|
---|
220 | if (!pEnv)
|
---|
221 | arc = ERROR_INVALID_PARAMETER;
|
---|
222 | else
|
---|
223 | {
|
---|
224 | PTIB ptib = 0;
|
---|
225 | PPIB ppib = 0;
|
---|
226 | arc = DosGetInfoBlocks(&ptib, &ppib);
|
---|
227 | if (arc == NO_ERROR)
|
---|
228 | {
|
---|
229 | PSZ pszEnv;
|
---|
230 | if (pszEnv = ppib->pib_pchenv)
|
---|
231 | arc = appParseEnvironment(pszEnv, pEnv);
|
---|
232 | else
|
---|
233 | arc = ERROR_BAD_ENVIRONMENT;
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | return arc;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /*
|
---|
241 | *@@ appFindEnvironmentVar:
|
---|
242 | * returns the PSZ* in the pEnv->papszVars array
|
---|
243 | * which specifies the environment variable in pszVarName.
|
---|
244 | *
|
---|
245 | * With pszVarName, you can either specify the variable
|
---|
246 | * name only ("VARNAME") or a full environment string
|
---|
247 | * ("VARNAME=BLAH"). In any case, only the variable name
|
---|
248 | * is compared.
|
---|
249 | *
|
---|
250 | * Returns NULL if no such variable name was found in
|
---|
251 | * the array.
|
---|
252 | *
|
---|
253 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
254 | *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
|
---|
255 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
256 | *@@changed V0.9.16 (2002-01-01) [umoeller]: removed extra heap allocation
|
---|
257 | */
|
---|
258 |
|
---|
259 | PSZ* appFindEnvironmentVar(PDOSENVIRONMENT pEnv,
|
---|
260 | PCSZ pszVarName)
|
---|
261 | {
|
---|
262 | PSZ *ppszRet = 0;
|
---|
263 |
|
---|
264 | if ( (pEnv)
|
---|
265 | && (pEnv->papszVars)
|
---|
266 | && (pszVarName)
|
---|
267 | )
|
---|
268 | {
|
---|
269 | ULONG ul = 0;
|
---|
270 | ULONG ulVarNameLen = 0;
|
---|
271 |
|
---|
272 | PSZ pFirstEqual;
|
---|
273 | // rewrote all the following for speed V0.9.16 (2002-01-01) [umoeller]
|
---|
274 | if (pFirstEqual = strchr(pszVarName, '='))
|
---|
275 | // VAR=VALUE
|
---|
276 | // ^ pFirstEqual
|
---|
277 | ulVarNameLen = pFirstEqual - pszVarName;
|
---|
278 | else
|
---|
279 | ulVarNameLen = strlen(pszVarName);
|
---|
280 |
|
---|
281 | for (ul = 0;
|
---|
282 | ul < pEnv->cVars;
|
---|
283 | ul++)
|
---|
284 | {
|
---|
285 | PSZ pszThis = pEnv->papszVars[ul];
|
---|
286 | if (pFirstEqual = strchr(pszThis, '='))
|
---|
287 | {
|
---|
288 | ULONG ulLenThis = pFirstEqual - pszThis;
|
---|
289 | if ( (ulLenThis == ulVarNameLen)
|
---|
290 | && (!memicmp(pszThis,
|
---|
291 | (PVOID)pszVarName,
|
---|
292 | ulVarNameLen))
|
---|
293 | )
|
---|
294 | {
|
---|
295 | ppszRet = &pEnv->papszVars[ul];
|
---|
296 | break;
|
---|
297 | }
|
---|
298 | }
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | return ppszRet;
|
---|
303 | }
|
---|
304 |
|
---|
305 | /*
|
---|
306 | *@@ appSetEnvironmentVar:
|
---|
307 | * sets an environment variable in the specified
|
---|
308 | * environment, which must have been initialized
|
---|
309 | * using appGetEnvironment first.
|
---|
310 | *
|
---|
311 | * pszNewEnv must be a full environment string
|
---|
312 | * in the form "VARNAME=VALUE".
|
---|
313 | *
|
---|
314 | * If "VARNAME" has already been set to something
|
---|
315 | * in the string array in pEnv, that array item
|
---|
316 | * is replaced.
|
---|
317 | *
|
---|
318 | * OTOH, if "VARNAME" has not been set yet, a new
|
---|
319 | * item is added to the array, and pEnv->cVars is
|
---|
320 | * raised by one. In that case, fAddFirst determines
|
---|
321 | * whether the new array item is added to the front
|
---|
322 | * or the tail of the environment list.
|
---|
323 | *
|
---|
324 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
325 | *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst
|
---|
326 | *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
|
---|
327 | *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed crash if !fAddFirst
|
---|
328 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
329 | */
|
---|
330 |
|
---|
331 | APIRET appSetEnvironmentVar(PDOSENVIRONMENT pEnv,
|
---|
332 | PCSZ pszNewEnv,
|
---|
333 | BOOL fAddFirst)
|
---|
334 | {
|
---|
335 | APIRET arc = NO_ERROR;
|
---|
336 | if ((!pEnv) || (!pszNewEnv))
|
---|
337 | arc = ERROR_INVALID_PARAMETER;
|
---|
338 | else
|
---|
339 | {
|
---|
340 | if (!pEnv->papszVars)
|
---|
341 | {
|
---|
342 | // no variables set yet:
|
---|
343 | pEnv->papszVars = (PSZ*)malloc(sizeof(PSZ));
|
---|
344 | pEnv->cVars = 1;
|
---|
345 |
|
---|
346 | *(pEnv->papszVars) = strdup(pszNewEnv);
|
---|
347 | }
|
---|
348 | else
|
---|
349 | {
|
---|
350 | PSZ *ppszEnvLine;
|
---|
351 | if (ppszEnvLine = appFindEnvironmentVar(pEnv, pszNewEnv))
|
---|
352 | // was set already: replace
|
---|
353 | arc = strhStore(ppszEnvLine,
|
---|
354 | pszNewEnv,
|
---|
355 | NULL);
|
---|
356 | else
|
---|
357 | {
|
---|
358 | // not set already:
|
---|
359 | PSZ *ppszNew = NULL;
|
---|
360 |
|
---|
361 | // allocate new array, with one new entry
|
---|
362 | // fixed V0.9.12 (2001-05-26) [umoeller], this crashed
|
---|
363 | PSZ *papszNew;
|
---|
364 |
|
---|
365 | if (!(papszNew = (PSZ*)malloc(sizeof(PSZ) * (pEnv->cVars + 1))))
|
---|
366 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
367 | else
|
---|
368 | {
|
---|
369 | if (fAddFirst)
|
---|
370 | {
|
---|
371 | // add as first entry:
|
---|
372 | // overwrite first entry
|
---|
373 | ppszNew = papszNew;
|
---|
374 | // copy old entries
|
---|
375 | memcpy(papszNew + 1, // second new entry
|
---|
376 | pEnv->papszVars, // first old entry
|
---|
377 | sizeof(PSZ) * pEnv->cVars);
|
---|
378 | }
|
---|
379 | else
|
---|
380 | {
|
---|
381 | // append at the tail:
|
---|
382 | // overwrite last entry
|
---|
383 | ppszNew = papszNew + pEnv->cVars;
|
---|
384 | // copy old entries
|
---|
385 | memcpy(papszNew, // first new entry
|
---|
386 | pEnv->papszVars, // first old entry
|
---|
387 | sizeof(PSZ) * pEnv->cVars);
|
---|
388 | }
|
---|
389 |
|
---|
390 | free(pEnv->papszVars); // was missing V0.9.12 (2001-05-21) [umoeller]
|
---|
391 | pEnv->papszVars = papszNew;
|
---|
392 | pEnv->cVars++;
|
---|
393 | *ppszNew = strdup(pszNewEnv);
|
---|
394 | }
|
---|
395 | }
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | return arc;
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | /*
|
---|
404 | *@@ appSetEnvironmentVars:
|
---|
405 | * Apply a number of changes or additions to an environment
|
---|
406 | * initialized by appGetEnvironment. The changes or additions
|
---|
407 | * is to the environment is passed in as a pointer (pcszEnv) to
|
---|
408 | * a set of zero terminated VARNAME=VALUE string which ends with
|
---|
409 | * an empty string. (Hence just like the environment block
|
---|
410 | * representation in OS/2.)
|
---|
411 | *
|
---|
412 | *@@added V1.0.0 (2002-09-04) [bird]
|
---|
413 | */
|
---|
414 |
|
---|
415 | APIRET appSetEnvironmentVars(PDOSENVIRONMENT pEnv,
|
---|
416 | PCSZ pcszEnv)
|
---|
417 | {
|
---|
418 | APIRET arc = NO_ERROR;
|
---|
419 | if ( (!pEnv)
|
---|
420 | || (!pcszEnv)
|
---|
421 | )
|
---|
422 | arc = ERROR_INVALID_PARAMETER;
|
---|
423 | else
|
---|
424 | {
|
---|
425 | while (arc == NO_ERROR && *pcszEnv != '\0')
|
---|
426 | {
|
---|
427 | arc = appSetEnvironmentVar(pEnv, pcszEnv, FALSE);
|
---|
428 | pcszEnv += strlen(pcszEnv) + 1;
|
---|
429 | }
|
---|
430 | }
|
---|
431 | return arc;
|
---|
432 | }
|
---|
433 |
|
---|
434 |
|
---|
435 | /*
|
---|
436 | *@@ appConvertEnvironment:
|
---|
437 | * converts an environment initialized by appGetEnvironment
|
---|
438 | * to the string format required by WinStartApp and DosExecPgm,
|
---|
439 | * that is, one memory block is allocated in *ppszEnv and all
|
---|
440 | * strings in pEnv->papszVars are copied to that block. Each
|
---|
441 | * string is terminated with a null character; the last string
|
---|
442 | * is terminated with two null characters.
|
---|
443 | *
|
---|
444 | * Use free() to free the memory block allocated by this
|
---|
445 | * function in *ppszEnv.
|
---|
446 | *
|
---|
447 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
448 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
449 | */
|
---|
450 |
|
---|
451 | APIRET appConvertEnvironment(PDOSENVIRONMENT pEnv,
|
---|
452 | PSZ *ppszEnv, // out: environment string
|
---|
453 | PULONG pulSize) // out: size of block allocated in *ppszEnv; ptr can be NULL
|
---|
454 | {
|
---|
455 | APIRET arc = NO_ERROR;
|
---|
456 | if ( (!pEnv)
|
---|
457 | || (!pEnv->papszVars)
|
---|
458 | )
|
---|
459 | arc = ERROR_INVALID_PARAMETER;
|
---|
460 | else
|
---|
461 | {
|
---|
462 | // count memory needed for all strings
|
---|
463 | ULONG cbNeeded = 0,
|
---|
464 | ul = 0;
|
---|
465 | PSZ *ppszThis = pEnv->papszVars;
|
---|
466 |
|
---|
467 | for (ul = 0;
|
---|
468 | ul < pEnv->cVars;
|
---|
469 | ul++)
|
---|
470 | {
|
---|
471 | cbNeeded += strlen(*ppszThis) + 1; // length of string plus null terminator
|
---|
472 |
|
---|
473 | // next environment string
|
---|
474 | ppszThis++;
|
---|
475 | }
|
---|
476 |
|
---|
477 | cbNeeded++; // for another null terminator
|
---|
478 |
|
---|
479 | if (!(*ppszEnv = (PSZ)malloc(cbNeeded)))
|
---|
480 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
481 | else
|
---|
482 | {
|
---|
483 | PSZ pTarget = *ppszEnv;
|
---|
484 | if (pulSize)
|
---|
485 | *pulSize = cbNeeded;
|
---|
486 | ppszThis = pEnv->papszVars;
|
---|
487 |
|
---|
488 | // now copy each string
|
---|
489 | for (ul = 0;
|
---|
490 | ul < pEnv->cVars;
|
---|
491 | ul++)
|
---|
492 | {
|
---|
493 | PSZ pSource = *ppszThis;
|
---|
494 |
|
---|
495 | while ((*pTarget++ = *pSource++))
|
---|
496 | ;
|
---|
497 |
|
---|
498 | // *pTarget++ = 0; // append null terminator per string
|
---|
499 |
|
---|
500 | // next environment string
|
---|
501 | ppszThis++;
|
---|
502 | }
|
---|
503 |
|
---|
504 | *pTarget++ = 0; // append second null terminator
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | return arc;
|
---|
509 | }
|
---|
510 |
|
---|
511 | /*
|
---|
512 | *@@ appFreeEnvironment:
|
---|
513 | * frees memory allocated by appGetEnvironment.
|
---|
514 | *
|
---|
515 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
---|
516 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
---|
517 | */
|
---|
518 |
|
---|
519 | APIRET appFreeEnvironment(PDOSENVIRONMENT pEnv)
|
---|
520 | {
|
---|
521 | APIRET arc = NO_ERROR;
|
---|
522 | if ( (!pEnv)
|
---|
523 | || (!pEnv->papszVars)
|
---|
524 | )
|
---|
525 | arc = ERROR_INVALID_PARAMETER;
|
---|
526 | else
|
---|
527 | {
|
---|
528 | PSZ *ppszThis = pEnv->papszVars;
|
---|
529 | PSZ pszThis;
|
---|
530 | ULONG ul = 0;
|
---|
531 |
|
---|
532 | for (ul = 0;
|
---|
533 | ul < pEnv->cVars;
|
---|
534 | ul++)
|
---|
535 | {
|
---|
536 | pszThis = *ppszThis;
|
---|
537 | free(pszThis);
|
---|
538 | // *ppszThis = NULL;
|
---|
539 | // next environment string
|
---|
540 | ppszThis++;
|
---|
541 | }
|
---|
542 |
|
---|
543 | free(pEnv->papszVars);
|
---|
544 | pEnv->cVars = 0;
|
---|
545 | }
|
---|
546 |
|
---|
547 | return arc;
|
---|
548 | }
|
---|
549 |
|
---|
550 | /* ******************************************************************
|
---|
551 | *
|
---|
552 | * Application information
|
---|
553 | *
|
---|
554 | ********************************************************************/
|
---|
555 |
|
---|
556 | /*
|
---|
557 | *@@ appQueryAppType:
|
---|
558 | * returns the Control Program (Dos) and
|
---|
559 | * Win* PROG_* application types for the
|
---|
560 | * specified executable. Essentially, this
|
---|
561 | * is a wrapper around DosQueryAppType.
|
---|
562 | *
|
---|
563 | * pcszExecutable must be fully qualified.
|
---|
564 | * You can use doshFindExecutable to qualify
|
---|
565 | * it.
|
---|
566 | *
|
---|
567 | * This returns the APIRET of DosQueryAppType.
|
---|
568 | * If this is NO_ERROR; *pulDosAppType receives
|
---|
569 | * the app type of DosQueryAppType. In addition,
|
---|
570 | * *pulWinAppType is set to one of the following:
|
---|
571 | *
|
---|
572 | * -- PROG_FULLSCREEN
|
---|
573 | *
|
---|
574 | * -- PROG_PDD
|
---|
575 | *
|
---|
576 | * -- PROG_VDD
|
---|
577 | *
|
---|
578 | * -- PROG_DLL
|
---|
579 | *
|
---|
580 | * -- PROG_WINDOWEDVDM
|
---|
581 | *
|
---|
582 | * -- PROG_PM
|
---|
583 | *
|
---|
584 | * -- PROG_31_ENHSEAMLESSCOMMON
|
---|
585 | *
|
---|
586 | * -- PROG_WINDOWABLEVIO
|
---|
587 | *
|
---|
588 | * -- PROG_DEFAULT
|
---|
589 | *
|
---|
590 | *@@added V0.9.9 (2001-03-07) [umoeller]
|
---|
591 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
---|
592 | *@@changed V0.9.14 (2001-08-07) [pr]: use FAPPTYP_* constants
|
---|
593 | *@@changed V0.9.16 (2001-12-08) [umoeller]: added checks for batch files, other optimizations
|
---|
594 | */
|
---|
595 |
|
---|
596 | APIRET appQueryAppType(const char *pcszExecutable,
|
---|
597 | PULONG pulDosAppType, // out: DOS app type
|
---|
598 | PULONG pulWinAppType) // out: PROG_* app type
|
---|
599 | {
|
---|
600 | APIRET arc;
|
---|
601 |
|
---|
602 | /*
|
---|
603 | #define FAPPTYP_NOTSPEC 0x0000
|
---|
604 | #define FAPPTYP_NOTWINDOWCOMPAT 0x0001
|
---|
605 | #define FAPPTYP_WINDOWCOMPAT 0x0002
|
---|
606 | #define FAPPTYP_WINDOWAPI 0x0003
|
---|
607 | #define FAPPTYP_BOUND 0x0008
|
---|
608 | #define FAPPTYP_DLL 0x0010
|
---|
609 | #define FAPPTYP_DOS 0x0020
|
---|
610 | #define FAPPTYP_PHYSDRV 0x0040 // physical device driver
|
---|
611 | #define FAPPTYP_VIRTDRV 0x0080 // virtual device driver
|
---|
612 | #define FAPPTYP_PROTDLL 0x0100 // 'protected memory' dll
|
---|
613 | #define FAPPTYP_WINDOWSREAL 0x0200 // Windows real mode app
|
---|
614 | #define FAPPTYP_WINDOWSPROT 0x0400 // Windows protect mode app
|
---|
615 | #define FAPPTYP_WINDOWSPROT31 0x1000 // Windows 3.1 protect mode app
|
---|
616 | #define FAPPTYP_32BIT 0x4000
|
---|
617 | */
|
---|
618 |
|
---|
619 | ULONG ulWinAppType = PROG_DEFAULT;
|
---|
620 |
|
---|
621 | if (!(arc = DosQueryAppType((PSZ)pcszExecutable, pulDosAppType)))
|
---|
622 | {
|
---|
623 | // clear the 32-bit flag
|
---|
624 | // V0.9.16 (2001-12-08) [umoeller]
|
---|
625 | ULONG ulDosAppType = (*pulDosAppType) & ~FAPPTYP_32BIT,
|
---|
626 | ulLoAppType = ulDosAppType & 0xFFFF;
|
---|
627 |
|
---|
628 | if (ulDosAppType & FAPPTYP_PHYSDRV) // 0x40
|
---|
629 | ulWinAppType = PROG_PDD;
|
---|
630 | else if (ulDosAppType & FAPPTYP_VIRTDRV) // 0x80
|
---|
631 | ulWinAppType = PROG_VDD;
|
---|
632 | else if ((ulDosAppType & 0xF0) == FAPPTYP_DLL) // 0x10
|
---|
633 | // DLL bit set
|
---|
634 | ulWinAppType = PROG_DLL;
|
---|
635 | else if (ulDosAppType & FAPPTYP_DOS) // 0x20
|
---|
636 | // DOS bit set?
|
---|
637 | ulWinAppType = PROG_WINDOWEDVDM;
|
---|
638 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) // 0x0003)
|
---|
639 | // "Window-API" == PM
|
---|
640 | ulWinAppType = PROG_PM;
|
---|
641 | else if (ulLoAppType == FAPPTYP_WINDOWSREAL)
|
---|
642 | ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // @@todo really?
|
---|
643 | else if ( (ulLoAppType == FAPPTYP_WINDOWSPROT31) // 0x1000) // windows program (?!?)
|
---|
644 | || (ulLoAppType == FAPPTYP_WINDOWSPROT) // ) // windows program (?!?)
|
---|
645 | )
|
---|
646 | ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // PROG_31_ENH;
|
---|
647 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_WINDOWCOMPAT) // 0x02)
|
---|
648 | ulWinAppType = PROG_WINDOWABLEVIO;
|
---|
649 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_NOTWINDOWCOMPAT) // 0x01)
|
---|
650 | ulWinAppType = PROG_FULLSCREEN;
|
---|
651 | }
|
---|
652 |
|
---|
653 | if (ulWinAppType == PROG_DEFAULT)
|
---|
654 | {
|
---|
655 | // added checks for batch files V0.9.16 (2001-12-08) [umoeller]
|
---|
656 | PCSZ pcszExt;
|
---|
657 | if (pcszExt = doshGetExtension(pcszExecutable))
|
---|
658 | {
|
---|
659 | if (!stricmp(pcszExt, "BAT"))
|
---|
660 | {
|
---|
661 | ulWinAppType = PROG_WINDOWEDVDM;
|
---|
662 | arc = NO_ERROR;
|
---|
663 | }
|
---|
664 | else if (!stricmp(pcszExt, "CMD"))
|
---|
665 | {
|
---|
666 | ulWinAppType = PROG_WINDOWABLEVIO;
|
---|
667 | arc = NO_ERROR;
|
---|
668 | }
|
---|
669 | }
|
---|
670 | }
|
---|
671 |
|
---|
672 | *pulWinAppType = ulWinAppType;
|
---|
673 |
|
---|
674 | return arc;
|
---|
675 | }
|
---|
676 |
|
---|
677 | /*
|
---|
678 | *@@ PROGTYPESTRING:
|
---|
679 | *
|
---|
680 | *@@added V0.9.16 (2002-01-13) [umoeller]
|
---|
681 | */
|
---|
682 |
|
---|
683 | typedef struct _PROGTYPESTRING
|
---|
684 | {
|
---|
685 | PROGCATEGORY progc;
|
---|
686 | PCSZ pcsz;
|
---|
687 | } PROGTYPESTRING, *PPROGTYPESTRING;
|
---|
688 |
|
---|
689 | PROGTYPESTRING G_aProgTypes[] =
|
---|
690 | {
|
---|
691 | PROG_DEFAULT, "PROG_DEFAULT",
|
---|
692 | PROG_FULLSCREEN, "PROG_FULLSCREEN",
|
---|
693 | PROG_WINDOWABLEVIO, "PROG_WINDOWABLEVIO",
|
---|
694 | PROG_PM, "PROG_PM",
|
---|
695 | PROG_GROUP, "PROG_GROUP",
|
---|
696 | PROG_VDM, "PROG_VDM",
|
---|
697 | // same as PROG_REAL, "PROG_REAL",
|
---|
698 | PROG_WINDOWEDVDM, "PROG_WINDOWEDVDM",
|
---|
699 | PROG_DLL, "PROG_DLL",
|
---|
700 | PROG_PDD, "PROG_PDD",
|
---|
701 | PROG_VDD, "PROG_VDD",
|
---|
702 | PROG_WINDOW_REAL, "PROG_WINDOW_REAL",
|
---|
703 | PROG_30_STD, "PROG_30_STD",
|
---|
704 | // same as PROG_WINDOW_PROT, "PROG_WINDOW_PROT",
|
---|
705 | PROG_WINDOW_AUTO, "PROG_WINDOW_AUTO",
|
---|
706 | PROG_30_STDSEAMLESSVDM, "PROG_30_STDSEAMLESSVDM",
|
---|
707 | // same as PROG_SEAMLESSVDM, "PROG_SEAMLESSVDM",
|
---|
708 | PROG_30_STDSEAMLESSCOMMON, "PROG_30_STDSEAMLESSCOMMON",
|
---|
709 | // same as PROG_SEAMLESSCOMMON, "PROG_SEAMLESSCOMMON",
|
---|
710 | PROG_31_STDSEAMLESSVDM, "PROG_31_STDSEAMLESSVDM",
|
---|
711 | PROG_31_STDSEAMLESSCOMMON, "PROG_31_STDSEAMLESSCOMMON",
|
---|
712 | PROG_31_ENHSEAMLESSVDM, "PROG_31_ENHSEAMLESSVDM",
|
---|
713 | PROG_31_ENHSEAMLESSCOMMON, "PROG_31_ENHSEAMLESSCOMMON",
|
---|
714 | PROG_31_ENH, "PROG_31_ENH",
|
---|
715 | PROG_31_STD, "PROG_31_STD",
|
---|
716 |
|
---|
717 | // Warp 4 toolkit defines, whatever these were designed for...
|
---|
718 | #ifndef PROG_DOS_GAME
|
---|
719 | #define PROG_DOS_GAME (PROGCATEGORY)21
|
---|
720 | #endif
|
---|
721 | #ifndef PROG_WIN_GAME
|
---|
722 | #define PROG_WIN_GAME (PROGCATEGORY)22
|
---|
723 | #endif
|
---|
724 | #ifndef PROG_DOS_MODE
|
---|
725 | #define PROG_DOS_MODE (PROGCATEGORY)23
|
---|
726 | #endif
|
---|
727 |
|
---|
728 | PROG_DOS_GAME, "PROG_DOS_GAME",
|
---|
729 | PROG_WIN_GAME, "PROG_WIN_GAME",
|
---|
730 | PROG_DOS_MODE, "PROG_DOS_MODE",
|
---|
731 |
|
---|
732 | // added this V0.9.16 (2001-12-08) [umoeller]
|
---|
733 | PROG_WIN32, "PROG_WIN32"
|
---|
734 | };
|
---|
735 |
|
---|
736 | /*
|
---|
737 | *@@ appDescribeAppType:
|
---|
738 | * returns a "PROG_*" string for the given
|
---|
739 | * program type. Useful for WPProgram setup
|
---|
740 | * strings and such.
|
---|
741 | *
|
---|
742 | *@@added V0.9.16 (2001-10-06)
|
---|
743 | */
|
---|
744 |
|
---|
745 | PCSZ appDescribeAppType(PROGCATEGORY progc) // in: from PROGDETAILS.progc
|
---|
746 | {
|
---|
747 | ULONG ul;
|
---|
748 | for (ul = 0;
|
---|
749 | ul < ARRAYITEMCOUNT(G_aProgTypes);
|
---|
750 | ul++)
|
---|
751 | {
|
---|
752 | if (G_aProgTypes[ul].progc == progc)
|
---|
753 | return G_aProgTypes[ul].pcsz;
|
---|
754 | }
|
---|
755 |
|
---|
756 | return NULL;
|
---|
757 | }
|
---|
758 |
|
---|
759 | /*
|
---|
760 | *@@ appIsWindowsApp:
|
---|
761 | * checks the specified program category
|
---|
762 | * (PROGDETAILS.progt.progc) for whether
|
---|
763 | * it represents a Win-OS/2 application.
|
---|
764 | *
|
---|
765 | * Returns:
|
---|
766 | *
|
---|
767 | * -- 0: no windows app (it's VIO, OS/2
|
---|
768 | * or DOS fullscreen, or PM).
|
---|
769 | *
|
---|
770 | * -- 1: Win-OS/2 standard app.
|
---|
771 | *
|
---|
772 | * -- 2: Win-OS/2 enhanced-mode app.
|
---|
773 | *
|
---|
774 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
---|
775 | */
|
---|
776 |
|
---|
777 | ULONG appIsWindowsApp(ULONG ulProgCategory)
|
---|
778 | {
|
---|
779 | switch (ulProgCategory)
|
---|
780 | {
|
---|
781 | case PROG_31_ENHSEAMLESSVDM: // 17
|
---|
782 | case PROG_31_ENHSEAMLESSCOMMON: // 18
|
---|
783 | case PROG_31_ENH: // 19
|
---|
784 | return 2;
|
---|
785 |
|
---|
786 | #ifndef PROG_30_STD
|
---|
787 | #define PROG_30_STD (PROGCATEGORY)11
|
---|
788 | #endif
|
---|
789 |
|
---|
790 | #ifndef PROG_30_STDSEAMLESSVDM
|
---|
791 | #define PROG_30_STDSEAMLESSVDM (PROGCATEGORY)13
|
---|
792 | #endif
|
---|
793 |
|
---|
794 | case PROG_WINDOW_REAL: // 10
|
---|
795 | case PROG_30_STD: // 11
|
---|
796 | case PROG_WINDOW_AUTO: // 12
|
---|
797 | case PROG_30_STDSEAMLESSVDM: // 13
|
---|
798 | case PROG_30_STDSEAMLESSCOMMON: // 14
|
---|
799 | case PROG_31_STDSEAMLESSVDM: // 15
|
---|
800 | case PROG_31_STDSEAMLESSCOMMON: // 16
|
---|
801 | case PROG_31_STD: // 20
|
---|
802 | return 1;
|
---|
803 | }
|
---|
804 |
|
---|
805 | return 0;
|
---|
806 | }
|
---|
807 |
|
---|
808 | /* ******************************************************************
|
---|
809 | *
|
---|
810 | * Application start
|
---|
811 | *
|
---|
812 | ********************************************************************/
|
---|
813 |
|
---|
814 | /*
|
---|
815 | *@@ CheckAndQualifyExecutable:
|
---|
816 | * checks the executable in the given PROGDETAILS
|
---|
817 | * for whether it is fully qualified.
|
---|
818 | *
|
---|
819 | * If so, the existence is verified.
|
---|
820 | *
|
---|
821 | * If not, we search for it on the PATH. If we
|
---|
822 | * find it, we use pstrExecutablePath to store
|
---|
823 | * the fully qualified executable and set
|
---|
824 | * pDetails->pszExecutable to it. The caller
|
---|
825 | * must initialize the buffer and clear it
|
---|
826 | * after the call.
|
---|
827 | *
|
---|
828 | * Returns:
|
---|
829 | *
|
---|
830 | * -- NO_ERROR: executable exists and might
|
---|
831 | * have been fully qualified.
|
---|
832 | *
|
---|
833 | * -- ERROR_FILE_NOT_FOUND
|
---|
834 | *
|
---|
835 | *@@added V0.9.20 (2002-07-03) [umoeller]
|
---|
836 | *@@changed V1.0.0 (2002-08-21) [umoeller]: now allowing for UNC
|
---|
837 | */
|
---|
838 |
|
---|
839 | STATIC APIRET CheckAndQualifyExecutable(PPROGDETAILS pDetails, // in/out: program details
|
---|
840 | PXSTRING pstrExecutablePatched) // in/out: buffer for q'fied exec (must be init'ed)
|
---|
841 | {
|
---|
842 | APIRET arc = NO_ERROR;
|
---|
843 |
|
---|
844 | ULONG ulAttr;
|
---|
845 | // check if the executable is fully qualified; if so,
|
---|
846 | // check if the executable file exists
|
---|
847 | if ( // allow UNC V1.0.0 (2002-08-21) [umoeller]
|
---|
848 | ( (pDetails->pszExecutable[0] == '\\')
|
---|
849 | && (pDetails->pszExecutable[1] == '\\')
|
---|
850 | )
|
---|
851 | || ( (pDetails->pszExecutable[1] == ':')
|
---|
852 | && (strchr(pDetails->pszExecutable, '\\'))
|
---|
853 | )
|
---|
854 | )
|
---|
855 | {
|
---|
856 | arc = doshQueryPathAttr(pDetails->pszExecutable,
|
---|
857 | &ulAttr);
|
---|
858 | }
|
---|
859 | else
|
---|
860 | {
|
---|
861 | // _not_ fully qualified: look it up on the PATH then
|
---|
862 | // V0.9.16 (2001-12-06) [umoeller]
|
---|
863 | CHAR szFQExecutable[CCHMAXPATH];
|
---|
864 | if (!(arc = doshSearchPath("PATH",
|
---|
865 | pDetails->pszExecutable,
|
---|
866 | szFQExecutable,
|
---|
867 | sizeof(szFQExecutable))))
|
---|
868 | {
|
---|
869 | // alright, found it:
|
---|
870 | xstrcpy(pstrExecutablePatched, szFQExecutable, 0);
|
---|
871 | pDetails->pszExecutable = pstrExecutablePatched->psz;
|
---|
872 | }
|
---|
873 | }
|
---|
874 |
|
---|
875 | return arc;
|
---|
876 | }
|
---|
877 |
|
---|
878 | /*
|
---|
879 | *@@ CallBatchCorrectly:
|
---|
880 | * fixes the specified PROGDETAILS for
|
---|
881 | * command files in the executable part
|
---|
882 | * by inserting /C XXX into the parameters
|
---|
883 | * and setting the executable to the fully
|
---|
884 | * qualified command interpreter specified
|
---|
885 | * by the given environment variable.
|
---|
886 | *
|
---|
887 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
---|
888 | *@@changed V0.9.7 (2001-01-15) [umoeller]: now using XSTRING
|
---|
889 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
---|
890 | *@@changed V0.9.20 (2002-07-03) [umoeller]: now always qualifying executable to fix broken BAT files
|
---|
891 | *@@changed V1.0.0 (2002-08-12) [umoeller]: this didn't work for batch and cmd files that had "+" characters in their full path, fixed
|
---|
892 | */
|
---|
893 |
|
---|
894 | STATIC APIRET CallBatchCorrectly(PPROGDETAILS pProgDetails,
|
---|
895 | PXSTRING pstrExecutablePatched, // in/out: buffer for q'fied exec (must be init'ed)
|
---|
896 | PXSTRING pstrParams, // in/out: modified parameters (reallocated)
|
---|
897 | const char *pcszEnvVar, // in: env var spec'g command proc
|
---|
898 | // (e.g. "OS2_SHELL"); can be NULL
|
---|
899 | const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE")
|
---|
900 | {
|
---|
901 | APIRET arc = NO_ERROR;
|
---|
902 |
|
---|
903 | // XXX.CMD file as executable:
|
---|
904 | // fix args to /C XXX.CMD
|
---|
905 |
|
---|
906 | PSZ pszOldParams = NULL;
|
---|
907 | ULONG ulOldParamsLength = pstrParams->ulLength;
|
---|
908 | BOOL fQuotes = FALSE;
|
---|
909 |
|
---|
910 | if (ulOldParamsLength)
|
---|
911 | // we have parameters already:
|
---|
912 | // make a backup... we'll append that later
|
---|
913 | pszOldParams = strdup(pstrParams->psz);
|
---|
914 |
|
---|
915 | // set new params to "/C filename.cmd"
|
---|
916 | xstrcpy(pstrParams, "/C ", 0);
|
---|
917 |
|
---|
918 | // if the path has spaces, or other invalid characters,
|
---|
919 | // include it in quotes V1.0.0 (2002-08-12) [umoeller]
|
---|
920 | if (fQuotes = !!strpbrk(pProgDetails->pszExecutable, " +&|="))
|
---|
921 | xstrcatc(pstrParams, '"');
|
---|
922 | // @@bugbug "=" still doesn't work
|
---|
923 |
|
---|
924 | #ifdef DEBUG_PROGRAMSTART
|
---|
925 | _PmpfF(("fQuotes (parameters need quotes) is %d", fQuotes));
|
---|
926 | #endif
|
---|
927 |
|
---|
928 | xstrcat(pstrParams,
|
---|
929 | pProgDetails->pszExecutable,
|
---|
930 | 0);
|
---|
931 |
|
---|
932 | if (fQuotes)
|
---|
933 | xstrcatc(pstrParams, '"'); // V1.0.0 (2002-08-12) [umoeller]
|
---|
934 |
|
---|
935 | if (pszOldParams)
|
---|
936 | {
|
---|
937 | // .cmd had params:
|
---|
938 | // append space and old params
|
---|
939 | xstrcatc(pstrParams, ' ');
|
---|
940 | xstrcat(pstrParams,
|
---|
941 | pszOldParams,
|
---|
942 | ulOldParamsLength);
|
---|
943 | free(pszOldParams);
|
---|
944 | }
|
---|
945 |
|
---|
946 | // set executable to $(OS2_SHELL)
|
---|
947 | pProgDetails->pszExecutable = NULL;
|
---|
948 | if (pcszEnvVar)
|
---|
949 | pProgDetails->pszExecutable = getenv(pcszEnvVar);
|
---|
950 | if (!pProgDetails->pszExecutable)
|
---|
951 | pProgDetails->pszExecutable = (PSZ)pcszDefProc;
|
---|
952 | // should be on PATH
|
---|
953 |
|
---|
954 | // and make sure this is always qualified
|
---|
955 | // V0.9.20 (2002-07-03) [umoeller]
|
---|
956 | return CheckAndQualifyExecutable(pProgDetails,
|
---|
957 | pstrExecutablePatched);
|
---|
958 | }
|
---|
959 |
|
---|
960 | /*
|
---|
961 | *@@ appQueryDefaultWin31Environment:
|
---|
962 | * returns the default Win-OS/2 3.1 environment
|
---|
963 | * from OS2.INI, which you can then merge with
|
---|
964 | * your process environment to be able to
|
---|
965 | * start Win-OS/2 sessions properly with
|
---|
966 | * appStartApp.
|
---|
967 | *
|
---|
968 | * Caller must free() the return value.
|
---|
969 | *
|
---|
970 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
---|
971 | *@@changed V0.9.19 (2002-03-28) [umoeller]: now returning APIRET
|
---|
972 | */
|
---|
973 |
|
---|
974 | APIRET appQueryDefaultWin31Environment(PSZ *ppsz)
|
---|
975 | {
|
---|
976 | APIRET arc = NO_ERROR;
|
---|
977 | PSZ pszReturn = NULL;
|
---|
978 | ULONG ulSize = 0;
|
---|
979 |
|
---|
980 | // get default environment (from Win-OS/2 settings object) from OS2.INI
|
---|
981 | PSZ pszDefEnv;
|
---|
982 | if (pszDefEnv = prfhQueryProfileData(HINI_USER,
|
---|
983 | "WINOS2",
|
---|
984 | "PM_GlobalWindows31Settings",
|
---|
985 | &ulSize))
|
---|
986 | {
|
---|
987 | if (pszReturn = (PSZ)malloc(ulSize + 2))
|
---|
988 | {
|
---|
989 | PSZ p;
|
---|
990 | memset(pszReturn, 0, ulSize + 2);
|
---|
991 | memcpy(pszReturn, pszDefEnv, ulSize);
|
---|
992 |
|
---|
993 | for (p = pszReturn;
|
---|
994 | p < pszReturn + ulSize;
|
---|
995 | p++)
|
---|
996 | if (*p == ';')
|
---|
997 | *p = 0;
|
---|
998 |
|
---|
999 | // okay.... now we got an OS/2-style environment
|
---|
1000 | // with 0, 0, 00 strings
|
---|
1001 |
|
---|
1002 | *ppsz = pszReturn;
|
---|
1003 | }
|
---|
1004 | else
|
---|
1005 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
1006 |
|
---|
1007 | free(pszDefEnv);
|
---|
1008 | }
|
---|
1009 | else
|
---|
1010 | arc = ERROR_BAD_ENVIRONMENT;
|
---|
1011 |
|
---|
1012 | return arc;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | /*
|
---|
1016 | *@@ appBuildProgDetails:
|
---|
1017 | * extracted code from appStartApp to fix the
|
---|
1018 | * given PROGDETAILS data to support the typical
|
---|
1019 | * WPS stuff and allocate a single block of
|
---|
1020 | * shared memory containing all the data.
|
---|
1021 | *
|
---|
1022 | * This is now used by XWP's progOpenProgram
|
---|
1023 | * directly as a temporary fix for all the
|
---|
1024 | * session hangs.
|
---|
1025 | *
|
---|
1026 | * As input, this takes a PROGDETAILS structure,
|
---|
1027 | * which is converted in various ways. In detail,
|
---|
1028 | * this supports:
|
---|
1029 | *
|
---|
1030 | * -- starting "*" executables (command prompts
|
---|
1031 | * for OS/2, DOS, Win-OS/2);
|
---|
1032 | *
|
---|
1033 | * -- starting ".CMD" and ".BAT" files as
|
---|
1034 | * PROGDETAILS.pszExecutable; for those, we
|
---|
1035 | * convert the executable and parameters to
|
---|
1036 | * start CMD.EXE or COMMAND.COM with the "/C"
|
---|
1037 | * parameter instead;
|
---|
1038 | *
|
---|
1039 | * -- starting apps which are not fully qualified
|
---|
1040 | * and therefore assumed to be on the PATH
|
---|
1041 | * (for which doshSearchPath("PATH") is called).
|
---|
1042 | *
|
---|
1043 | * Unless it is "*", PROGDETAILS.pszExecutable must
|
---|
1044 | * be a proper file name. The full path may be omitted
|
---|
1045 | * if it is on the PATH, but the extension (.EXE etc.)
|
---|
1046 | * must be given. You can use doshFindExecutable to
|
---|
1047 | * find executables if you don't know the extension.
|
---|
1048 | *
|
---|
1049 | * This also handles and merges special and default
|
---|
1050 | * environments for the app to be started. The
|
---|
1051 | * following should be respected:
|
---|
1052 | *
|
---|
1053 | * -- As with WinStartApp, if PROGDETAILS.pszEnvironment
|
---|
1054 | * is NULL, the new app inherits the default environment
|
---|
1055 | * from the shell.
|
---|
1056 | *
|
---|
1057 | * -- However, if you specify an environment, you _must_
|
---|
1058 | * specify a complete environment. This function
|
---|
1059 | * will not merge environments. Use
|
---|
1060 | * appSetEnvironmentVar to change environment
|
---|
1061 | * variables in a complete environment set.
|
---|
1062 | *
|
---|
1063 | * -- If PROGDETAILS specifies a Win-OS/2 session
|
---|
1064 | * and PROGDETAILS.pszEnvironment is empty,
|
---|
1065 | * this uses the default Win-OS/2 environment
|
---|
1066 | * from OS2.INI. See appQueryDefaultWin31Environment.
|
---|
1067 | *
|
---|
1068 | * Even though this isn't clearly said in PMREF,
|
---|
1069 | * PROGDETAILS.swpInitial is important:
|
---|
1070 | *
|
---|
1071 | * -- To start a session minimized, set fl to SWP_MINIMIZE.
|
---|
1072 | *
|
---|
1073 | * -- To start a VIO session with auto-close disabled,
|
---|
1074 | * set the half-documented SWP_NOAUTOCLOSE flag (0x8000)
|
---|
1075 | * This flag is now in the newer toolkit headers.
|
---|
1076 | *
|
---|
1077 | * In addition, this supports the following session
|
---|
1078 | * flags with ulFlags if PROG_DEFAULT is specified:
|
---|
1079 | *
|
---|
1080 | * -- APP_RUN_FULLSCREEN: start a fullscreen session
|
---|
1081 | * for VIO, DOS, and Win-OS/2 programs. Otherwise
|
---|
1082 | * we start a windowed or (share) a seamless session.
|
---|
1083 | * Ignored if the program is PM.
|
---|
1084 | *
|
---|
1085 | * -- APP_RUN_ENHANCED: for Win-OS/2 sessions, use
|
---|
1086 | * enhanced mode.
|
---|
1087 | * Ignored if the program is not Win-OS/2.
|
---|
1088 | *
|
---|
1089 | * -- APP_RUN_STANDARD: for Win-OS/2 sessions, use
|
---|
1090 | * standard mode.
|
---|
1091 | * Ignored if the program is not Win-OS/2.
|
---|
1092 | *
|
---|
1093 | * -- APP_RUN_SEPARATE: for Win-OS/2 sessions, use
|
---|
1094 | * a separate session.
|
---|
1095 | * Ignored if the program is not Win-OS/2.
|
---|
1096 | *
|
---|
1097 | * If NO_ERROR is returned, *ppDetails receives a
|
---|
1098 | * new buffer of shared memory containing all the
|
---|
1099 | * data packed together.
|
---|
1100 | *
|
---|
1101 | * The shared memory is allocated unnamed and
|
---|
1102 | * with OBJ_GETTABLE. It is the responsibility
|
---|
1103 | * of the caller to call DosFreeMem on that buffer.
|
---|
1104 | *
|
---|
1105 | * Returns:
|
---|
1106 | *
|
---|
1107 | * -- NO_ERROR
|
---|
1108 | *
|
---|
1109 | * -- ERROR_INVALID_PARAMETER: pcProgDetails or
|
---|
1110 | * ppDetails is NULL; or PROGDETAILS.pszExecutable is NULL.
|
---|
1111 | *
|
---|
1112 | * -- ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND:
|
---|
1113 | * PROGDETAILS.pszExecutable and/or PROGDETAILS.pszStartupDir
|
---|
1114 | * are invalid.
|
---|
1115 | * A NULL PROGDETAILS.pszStartupDir is supported though.
|
---|
1116 | *
|
---|
1117 | * -- ERROR_BAD_FORMAT
|
---|
1118 | *
|
---|
1119 | * -- ERROR_BAD_ENVIRONMENT: environment is larger than 60.000 bytes.
|
---|
1120 | *
|
---|
1121 | * -- ERROR_NOT_ENOUGH_MEMORY
|
---|
1122 | *
|
---|
1123 | * plus the error codes from doshQueryPathAttr, doshSearchPath,
|
---|
1124 | * appParseEnvironment, appSetEnvironmentVar, and appConvertEnvironment.
|
---|
1125 | *
|
---|
1126 | *@@added V0.9.18 (2002-03-27) [umoeller]
|
---|
1127 | *@@changed V0.9.19 (2002-03-28) [umoeller]: now allocating contiguous buffer
|
---|
1128 | *@@changed V0.9.20 (2002-07-03) [umoeller]: fixed Win-OS/2 full screen breakage
|
---|
1129 | *@@changed V0.9.20 (2002-07-03) [umoeller]: fixed broken bat and cmd files when PROG_DEFAULT was set
|
---|
1130 | *@@changed V1.0.0 (2002-08-18) [umoeller]: fixed cmd and bat files that had "=" in their paths
|
---|
1131 | */
|
---|
1132 |
|
---|
1133 | APIRET appBuildProgDetails(PPROGDETAILS *ppDetails, // out: shared mem with fixed program spec (req.)
|
---|
1134 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
---|
1135 | ULONG ulFlags) // in: APP_RUN_* flags or 0
|
---|
1136 | {
|
---|
1137 | APIRET arc = NO_ERROR;
|
---|
1138 |
|
---|
1139 | XSTRING strExecutablePatched,
|
---|
1140 | strParamsPatched;
|
---|
1141 | PSZ pszWinOS2Env = 0;
|
---|
1142 |
|
---|
1143 | PROGDETAILS Details;
|
---|
1144 | ULONG ulIsWinApp;
|
---|
1145 |
|
---|
1146 | // parameter checking extended V1.0.0 (2002-08-21) [umoeller]
|
---|
1147 | if ( (!pcProgDetails)
|
---|
1148 | || (!pcProgDetails->pszExecutable)
|
---|
1149 | || (!pcProgDetails->pszExecutable[0])
|
---|
1150 | || (!ppDetails)
|
---|
1151 | )
|
---|
1152 | return ERROR_INVALID_PARAMETER;
|
---|
1153 |
|
---|
1154 | *ppDetails = NULL;
|
---|
1155 |
|
---|
1156 | /*
|
---|
1157 | * part 1:
|
---|
1158 | * fix up the PROGDETAILS fields
|
---|
1159 | */
|
---|
1160 |
|
---|
1161 | xstrInit(&strExecutablePatched, 0);
|
---|
1162 | xstrInit(&strParamsPatched, 0);
|
---|
1163 |
|
---|
1164 | memcpy(&Details, pcProgDetails, sizeof(PROGDETAILS));
|
---|
1165 | // pointers still point into old prog details buffer
|
---|
1166 | Details.Length = sizeof(PROGDETAILS);
|
---|
1167 | Details.progt.fbVisible = SHE_VISIBLE;
|
---|
1168 |
|
---|
1169 | // memset(&Details.swpInitial, 0, sizeof(SWP));
|
---|
1170 | // this wasn't a good idea... WPProgram stores stuff
|
---|
1171 | // in here, such as the "minimize on startup" -> SWP_MINIMIZE
|
---|
1172 |
|
---|
1173 | // duplicate parameters...
|
---|
1174 | // we need this for string manipulations below...
|
---|
1175 | if ( (Details.pszParameters)
|
---|
1176 | && (Details.pszParameters[0]) // V0.9.18
|
---|
1177 | )
|
---|
1178 | xstrcpy(&strParamsPatched,
|
---|
1179 | Details.pszParameters,
|
---|
1180 | 0);
|
---|
1181 |
|
---|
1182 | #ifdef DEBUG_PROGRAMSTART
|
---|
1183 | _PmpfF((" old progc: 0x%lX", pcProgDetails->progt.progc));
|
---|
1184 | _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle)));
|
---|
1185 | _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable)));
|
---|
1186 | _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters)));
|
---|
1187 | _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon)));
|
---|
1188 | #endif
|
---|
1189 |
|
---|
1190 | // program type fixups
|
---|
1191 | switch (Details.progt.progc) // that's a ULONG
|
---|
1192 | {
|
---|
1193 | case ((ULONG)-1): // we get that sometimes...
|
---|
1194 | case PROG_DEFAULT:
|
---|
1195 | {
|
---|
1196 | // V0.9.12 (2001-05-26) [umoeller]
|
---|
1197 | ULONG ulDosAppType;
|
---|
1198 | appQueryAppType(Details.pszExecutable,
|
---|
1199 | &ulDosAppType,
|
---|
1200 | &Details.progt.progc);
|
---|
1201 | }
|
---|
1202 | break;
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | // set session type from option flags
|
---|
1206 | if (ulFlags & APP_RUN_FULLSCREEN)
|
---|
1207 | {
|
---|
1208 | if (Details.progt.progc == PROG_WINDOWABLEVIO)
|
---|
1209 | Details.progt.progc = PROG_FULLSCREEN;
|
---|
1210 | else if (Details.progt.progc == PROG_WINDOWEDVDM)
|
---|
1211 | Details.progt.progc = PROG_VDM;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | if (ulIsWinApp = appIsWindowsApp(Details.progt.progc))
|
---|
1215 | {
|
---|
1216 | if (ulFlags & APP_RUN_FULLSCREEN)
|
---|
1217 | Details.progt.progc = (ulFlags & APP_RUN_ENHANCED)
|
---|
1218 | ? PROG_31_ENH
|
---|
1219 | : PROG_31_STD;
|
---|
1220 | else
|
---|
1221 | {
|
---|
1222 | if (ulFlags & APP_RUN_STANDARD)
|
---|
1223 | Details.progt.progc = (ulFlags & APP_RUN_SEPARATE)
|
---|
1224 | ? PROG_31_STDSEAMLESSVDM
|
---|
1225 | : PROG_31_STDSEAMLESSCOMMON;
|
---|
1226 | else if (ulFlags & APP_RUN_ENHANCED)
|
---|
1227 | Details.progt.progc = (ulFlags & APP_RUN_SEPARATE)
|
---|
1228 | ? PROG_31_ENHSEAMLESSVDM
|
---|
1229 | : PROG_31_ENHSEAMLESSCOMMON;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | // re-run V0.9.16 (2001-10-19) [umoeller]
|
---|
1233 | ulIsWinApp = appIsWindowsApp(Details.progt.progc);
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | /*
|
---|
1237 | * command lines fixups:
|
---|
1238 | *
|
---|
1239 | */
|
---|
1240 |
|
---|
1241 | if (!strcmp(Details.pszExecutable, "*"))
|
---|
1242 | {
|
---|
1243 | /*
|
---|
1244 | * "*" for command sessions:
|
---|
1245 | *
|
---|
1246 | */
|
---|
1247 |
|
---|
1248 | if (ulIsWinApp)
|
---|
1249 | {
|
---|
1250 | // cheat: WinStartApp doesn't support NULL
|
---|
1251 | // for Win-OS2 sessions, so manually start winos2.com
|
---|
1252 | Details.pszExecutable = "WINOS2.COM";
|
---|
1253 | // this is a DOS app, so fix this to DOS fullscreen
|
---|
1254 | Details.progt.progc = PROG_VDM;
|
---|
1255 |
|
---|
1256 | if (ulIsWinApp == 2)
|
---|
1257 | {
|
---|
1258 | // enhanced Win-OS/2 session:
|
---|
1259 | PSZ psz = NULL;
|
---|
1260 | if (strParamsPatched.ulLength)
|
---|
1261 | // "/3 " + existing params
|
---|
1262 | psz = strdup(strParamsPatched.psz);
|
---|
1263 |
|
---|
1264 | xstrcpy(&strParamsPatched, "/3 ", 0);
|
---|
1265 |
|
---|
1266 | if (psz)
|
---|
1267 | {
|
---|
1268 | xstrcat(&strParamsPatched, psz, 0);
|
---|
1269 | free(psz);
|
---|
1270 | }
|
---|
1271 | }
|
---|
1272 | }
|
---|
1273 | else
|
---|
1274 | // for all other executable types
|
---|
1275 | // (including OS/2 and DOS sessions),
|
---|
1276 | // set pszExecutable to NULL; this will
|
---|
1277 | // have WinStartApp start a cmd shell
|
---|
1278 | Details.pszExecutable = NULL;
|
---|
1279 |
|
---|
1280 | } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
|
---|
1281 |
|
---|
1282 | // else
|
---|
1283 |
|
---|
1284 | // no, this else breaks the WINOS2.COM hack above... we
|
---|
1285 | // need to look for that on the PATH as well
|
---|
1286 | // V0.9.20 (2002-07-03) [umoeller]
|
---|
1287 | if (Details.pszExecutable)
|
---|
1288 | {
|
---|
1289 | // check the executable and look for it on the
|
---|
1290 | // PATH if necessary
|
---|
1291 | if (!(arc = CheckAndQualifyExecutable(&Details,
|
---|
1292 | &strExecutablePatched)))
|
---|
1293 | {
|
---|
1294 | PSZ pszExtension;
|
---|
1295 |
|
---|
1296 | // make sure startup dir is really a directory
|
---|
1297 | // V0.9.20 (2002-07-03) [umoeller]: moved this down
|
---|
1298 | if (Details.pszStartupDir)
|
---|
1299 | {
|
---|
1300 | ULONG ulAttr;
|
---|
1301 | // it is valid to specify a startup dir of "C:"
|
---|
1302 | if ( (strlen(Details.pszStartupDir) > 2)
|
---|
1303 | && (!(arc = doshQueryPathAttr(Details.pszStartupDir,
|
---|
1304 | &ulAttr)))
|
---|
1305 | && (!(ulAttr & FILE_DIRECTORY))
|
---|
1306 | )
|
---|
1307 | arc = ERROR_PATH_NOT_FOUND;
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | // V1.0.0: this define is never set. I have thus completely
|
---|
1311 | // disabled the batch hacks that we used to provide, that is
|
---|
1312 | // we no longer change the "c:\path\batch.cmd" to "cmd.exe /c c:\path\batch.cmd"
|
---|
1313 | // because it is perfectly valid to call WinStartApp with a
|
---|
1314 | // batch file. The problem with my code was that cmd.exe has
|
---|
1315 | // a weird bug in that if you give it something via /c that
|
---|
1316 | // has an equals character (=) in its path, e.g. "c:\path=path\batch.cmd",
|
---|
1317 | // the command parser apparently stops at the first "=" and
|
---|
1318 | // reports "c:\path" not found or something. What a bitch.
|
---|
1319 | #ifdef ENABLEBATCHHACKS
|
---|
1320 |
|
---|
1321 | // we frequently get here for BAT and CMD files
|
---|
1322 | // with progtype == PROG_DEFAULT, so include
|
---|
1323 | // that in the check, or all BAT files will fail
|
---|
1324 | // V0.9.20 (2002-07-03) [umoeller]
|
---|
1325 |
|
---|
1326 | switch (Details.progt.progc)
|
---|
1327 | {
|
---|
1328 | /*
|
---|
1329 | * .CMD files fixups
|
---|
1330 | *
|
---|
1331 | */
|
---|
1332 |
|
---|
1333 | case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller]
|
---|
1334 | case PROG_FULLSCREEN: // OS/2 fullscreen
|
---|
1335 | case PROG_WINDOWABLEVIO: // OS/2 window
|
---|
1336 | {
|
---|
1337 | if ( (pszExtension = doshGetExtension(Details.pszExecutable))
|
---|
1338 | && (!stricmp(pszExtension, "CMD"))
|
---|
1339 | )
|
---|
1340 | {
|
---|
1341 | arc = CallBatchCorrectly(&Details,
|
---|
1342 | &strExecutablePatched,
|
---|
1343 | &strParamsPatched,
|
---|
1344 | "OS2_SHELL",
|
---|
1345 | "CMD.EXE");
|
---|
1346 | }
|
---|
1347 | }
|
---|
1348 | break;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | switch (Details.progt.progc)
|
---|
1352 | {
|
---|
1353 | case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller]
|
---|
1354 | case PROG_VDM: // DOS fullscreen
|
---|
1355 | case PROG_WINDOWEDVDM: // DOS window
|
---|
1356 | {
|
---|
1357 | if ( (pszExtension = doshGetExtension(Details.pszExecutable))
|
---|
1358 | && (!stricmp(pszExtension, "BAT"))
|
---|
1359 | )
|
---|
1360 | {
|
---|
1361 | arc = CallBatchCorrectly(&Details,
|
---|
1362 | &strExecutablePatched,
|
---|
1363 | &strParamsPatched,
|
---|
1364 | // there is no environment variable
|
---|
1365 | // for the DOS shell
|
---|
1366 | NULL,
|
---|
1367 | "COMMAND.COM");
|
---|
1368 | }
|
---|
1369 | }
|
---|
1370 | break;
|
---|
1371 | } // end switch (Details.progt.progc)
|
---|
1372 | #endif // ENABLEBATCHHACKS
|
---|
1373 | }
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | if (!arc)
|
---|
1377 | {
|
---|
1378 | if ( (ulIsWinApp)
|
---|
1379 | && ( (!(Details.pszEnvironment))
|
---|
1380 | || (!(*Details.pszEnvironment))
|
---|
1381 | )
|
---|
1382 | )
|
---|
1383 | {
|
---|
1384 | // this is a windoze app, and caller didn't bother
|
---|
1385 | // to give us an environment:
|
---|
1386 | // we MUST set one then, or we'll get the strangest
|
---|
1387 | // errors, up to system hangs. V0.9.12 (2001-05-26) [umoeller]
|
---|
1388 |
|
---|
1389 | DOSENVIRONMENT Env = {0};
|
---|
1390 |
|
---|
1391 | // get standard WIN-OS/2 environment
|
---|
1392 | PSZ pszTemp;
|
---|
1393 | if (!(arc = appQueryDefaultWin31Environment(&pszTemp)))
|
---|
1394 | {
|
---|
1395 | if (!(arc = appParseEnvironment(pszTemp,
|
---|
1396 | &Env)))
|
---|
1397 | {
|
---|
1398 | // now override KBD_CTRL_BYPASS=CTRL_ESC
|
---|
1399 | if ( (!(arc = appSetEnvironmentVar(&Env,
|
---|
1400 | "KBD_CTRL_BYPASS=CTRL_ESC",
|
---|
1401 | FALSE))) // add last
|
---|
1402 | && (!(arc = appConvertEnvironment(&Env,
|
---|
1403 | &pszWinOS2Env, // freed at bottom
|
---|
1404 | NULL)))
|
---|
1405 | )
|
---|
1406 | Details.pszEnvironment = pszWinOS2Env;
|
---|
1407 |
|
---|
1408 | appFreeEnvironment(&Env);
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | free(pszTemp);
|
---|
1412 | }
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 | if (!arc)
|
---|
1416 | {
|
---|
1417 | // if no title is given, use the executable
|
---|
1418 | if (!Details.pszTitle)
|
---|
1419 | Details.pszTitle = Details.pszExecutable;
|
---|
1420 |
|
---|
1421 | // make sure params have a leading space
|
---|
1422 | // V0.9.18 (2002-03-27) [umoeller]
|
---|
1423 | if (strParamsPatched.ulLength)
|
---|
1424 | {
|
---|
1425 | if (strParamsPatched.psz[0] != ' ')
|
---|
1426 | {
|
---|
1427 | XSTRING str2;
|
---|
1428 | xstrInit(&str2, 0);
|
---|
1429 | xstrcpy(&str2, " ", 1);
|
---|
1430 | xstrcats(&str2, &strParamsPatched);
|
---|
1431 | xstrcpys(&strParamsPatched, &str2);
|
---|
1432 | xstrClear(&str2);
|
---|
1433 | // we really need xstrInsert or something
|
---|
1434 | }
|
---|
1435 | Details.pszParameters = strParamsPatched.psz;
|
---|
1436 | }
|
---|
1437 | else
|
---|
1438 | // never pass null pointers
|
---|
1439 | Details.pszParameters = "";
|
---|
1440 |
|
---|
1441 | // never pass null pointers
|
---|
1442 | if (!Details.pszIcon)
|
---|
1443 | Details.pszIcon = "";
|
---|
1444 |
|
---|
1445 | // never pass null pointers
|
---|
1446 | if (!Details.pszStartupDir)
|
---|
1447 | Details.pszStartupDir = "";
|
---|
1448 |
|
---|
1449 | }
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | /*
|
---|
1453 | * part 2:
|
---|
1454 | * pack the fixed PROGDETAILS fields
|
---|
1455 | */
|
---|
1456 |
|
---|
1457 | if (!arc)
|
---|
1458 | {
|
---|
1459 | ULONG cb,
|
---|
1460 | cbTitle,
|
---|
1461 | cbExecutable,
|
---|
1462 | cbParameters,
|
---|
1463 | cbStartupDir,
|
---|
1464 | cbIcon,
|
---|
1465 | cbEnvironment;
|
---|
1466 |
|
---|
1467 | #ifdef DEBUG_PROGRAMSTART
|
---|
1468 | _PmpfF((" new progc: 0x%lX", pcProgDetails->progt.progc));
|
---|
1469 | _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle)));
|
---|
1470 | _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable)));
|
---|
1471 | _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters)));
|
---|
1472 | _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon)));
|
---|
1473 | #endif
|
---|
1474 |
|
---|
1475 | // allocate a chunk of tiled memory from OS/2 to make sure
|
---|
1476 | // this is aligned on a 64K memory (backed up by a 16-bit
|
---|
1477 | // LDT selector); if it is not, and the environment
|
---|
1478 | // crosses segments, it gets truncated!!
|
---|
1479 | cb = sizeof(PROGDETAILS);
|
---|
1480 | if (cbTitle = strhSize(Details.pszTitle))
|
---|
1481 | cb += cbTitle;
|
---|
1482 |
|
---|
1483 | if (cbExecutable = strhSize(Details.pszExecutable))
|
---|
1484 | cb += cbExecutable;
|
---|
1485 |
|
---|
1486 | if (cbParameters = strhSize(Details.pszParameters))
|
---|
1487 | cb += cbParameters;
|
---|
1488 |
|
---|
1489 | if (cbStartupDir = strhSize(Details.pszStartupDir))
|
---|
1490 | cb += cbStartupDir;
|
---|
1491 |
|
---|
1492 | if (cbIcon = strhSize(Details.pszIcon))
|
---|
1493 | cb += cbIcon;
|
---|
1494 |
|
---|
1495 | if (cbEnvironment = appQueryEnvironmentLen(Details.pszEnvironment))
|
---|
1496 | cb += cbEnvironment;
|
---|
1497 |
|
---|
1498 | if (cb > 60000) // to be on the safe side
|
---|
1499 | arc = ERROR_BAD_ENVIRONMENT; // 10;
|
---|
1500 | else
|
---|
1501 | {
|
---|
1502 | PPROGDETAILS pNewProgDetails;
|
---|
1503 | // alright, allocate the shared memory now
|
---|
1504 | if (!(arc = DosAllocSharedMem((PVOID*)&pNewProgDetails,
|
---|
1505 | NULL,
|
---|
1506 | cb,
|
---|
1507 | PAG_COMMIT | OBJ_GETTABLE | OBJ_TILE | PAG_EXECUTE | PAG_READ | PAG_WRITE)))
|
---|
1508 | {
|
---|
1509 | // and copy stuff
|
---|
1510 | PBYTE pThis;
|
---|
1511 |
|
---|
1512 | memset(pNewProgDetails, 0, cb);
|
---|
1513 |
|
---|
1514 | pNewProgDetails->Length = sizeof(PROGDETAILS);
|
---|
1515 |
|
---|
1516 | pNewProgDetails->progt.progc = Details.progt.progc;
|
---|
1517 |
|
---|
1518 | pNewProgDetails->progt.fbVisible = Details.progt.fbVisible;
|
---|
1519 | memcpy(&pNewProgDetails->swpInitial, &Details.swpInitial, sizeof(SWP));
|
---|
1520 |
|
---|
1521 | // start copying into buffer right after PROGDETAILS
|
---|
1522 | pThis = (PBYTE)(pNewProgDetails + 1);
|
---|
1523 |
|
---|
1524 | // handy macro to avoid typos
|
---|
1525 | #define COPY(id) if (cb ## id) { \
|
---|
1526 | memcpy(pThis, Details.psz ## id, cb ## id); \
|
---|
1527 | pNewProgDetails->psz ## id = pThis; \
|
---|
1528 | pThis += cb ## id; }
|
---|
1529 |
|
---|
1530 | COPY(Title);
|
---|
1531 | COPY(Executable);
|
---|
1532 | COPY(Parameters);
|
---|
1533 | COPY(StartupDir);
|
---|
1534 | COPY(Icon);
|
---|
1535 | COPY(Environment);
|
---|
1536 |
|
---|
1537 | *ppDetails = pNewProgDetails;
|
---|
1538 | }
|
---|
1539 | }
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | xstrClear(&strParamsPatched);
|
---|
1543 | xstrClear(&strExecutablePatched);
|
---|
1544 |
|
---|
1545 | if (pszWinOS2Env)
|
---|
1546 | free(pszWinOS2Env);
|
---|
1547 |
|
---|
1548 | return arc;
|
---|
1549 | }
|
---|
1550 |
|
---|
1551 | /*
|
---|
1552 | *@@ CallDosStartSession:
|
---|
1553 | *
|
---|
1554 | *@@added V0.9.18 (2002-03-27) [umoeller]
|
---|
1555 | */
|
---|
1556 |
|
---|
1557 | STATIC APIRET CallDosStartSession(HAPP *phapp,
|
---|
1558 | const PROGDETAILS *pNewProgDetails, // in: program spec (req.)
|
---|
1559 | ULONG cbFailingName,
|
---|
1560 | PSZ pszFailingName)
|
---|
1561 | {
|
---|
1562 | APIRET arc = NO_ERROR;
|
---|
1563 | volatile BOOL fCrit = FALSE; // XWP V1.0.4 (2005-10-09) [pr]
|
---|
1564 | volatile BOOL fResetDir = FALSE;
|
---|
1565 | CHAR szCurrentDir[CCHMAXPATH];
|
---|
1566 | ULONG sid,
|
---|
1567 | pid;
|
---|
1568 | STARTDATA SData;
|
---|
1569 |
|
---|
1570 | SData.Length = sizeof(STARTDATA);
|
---|
1571 | SData.Related = SSF_RELATED_INDEPENDENT; // SSF_RELATED_CHILD;
|
---|
1572 | // per default, try to start this in the foreground
|
---|
1573 | SData.FgBg = SSF_FGBG_FORE;
|
---|
1574 | SData.TraceOpt = SSF_TRACEOPT_NONE;
|
---|
1575 |
|
---|
1576 | SData.PgmTitle = pNewProgDetails->pszTitle;
|
---|
1577 | SData.PgmName = pNewProgDetails->pszExecutable;
|
---|
1578 | SData.PgmInputs = pNewProgDetails->pszParameters;
|
---|
1579 |
|
---|
1580 | SData.TermQ = NULL;
|
---|
1581 | SData.Environment = pNewProgDetails->pszEnvironment;
|
---|
1582 | SData.InheritOpt = SSF_INHERTOPT_PARENT; // ignored
|
---|
1583 |
|
---|
1584 | switch (pNewProgDetails->progt.progc)
|
---|
1585 | {
|
---|
1586 | case PROG_FULLSCREEN:
|
---|
1587 | SData.SessionType = SSF_TYPE_FULLSCREEN;
|
---|
1588 | break;
|
---|
1589 |
|
---|
1590 | case PROG_WINDOWABLEVIO:
|
---|
1591 | SData.SessionType = SSF_TYPE_WINDOWABLEVIO;
|
---|
1592 | break;
|
---|
1593 |
|
---|
1594 | case PROG_PM:
|
---|
1595 | SData.SessionType = SSF_TYPE_PM;
|
---|
1596 | SData.FgBg = SSF_FGBG_BACK; // otherwise we get ERROR_SMG_START_IN_BACKGROUND
|
---|
1597 | break;
|
---|
1598 |
|
---|
1599 | case PROG_VDM:
|
---|
1600 | SData.SessionType = SSF_TYPE_VDM;
|
---|
1601 | break;
|
---|
1602 |
|
---|
1603 | case PROG_WINDOWEDVDM:
|
---|
1604 | SData.SessionType = SSF_TYPE_WINDOWEDVDM;
|
---|
1605 | break;
|
---|
1606 |
|
---|
1607 | default:
|
---|
1608 | SData.SessionType = SSF_TYPE_DEFAULT;
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 | SData.IconFile = 0;
|
---|
1612 | SData.PgmHandle = 0;
|
---|
1613 |
|
---|
1614 | SData.PgmControl = 0;
|
---|
1615 |
|
---|
1616 | if (pNewProgDetails->progt.fbVisible == SHE_VISIBLE)
|
---|
1617 | SData.PgmControl |= SSF_CONTROL_VISIBLE;
|
---|
1618 |
|
---|
1619 | if (pNewProgDetails->swpInitial.fl & SWP_HIDE)
|
---|
1620 | SData.PgmControl |= SSF_CONTROL_INVISIBLE;
|
---|
1621 |
|
---|
1622 | if (pNewProgDetails->swpInitial.fl & SWP_MAXIMIZE)
|
---|
1623 | SData.PgmControl |= SSF_CONTROL_MAXIMIZE;
|
---|
1624 | if (pNewProgDetails->swpInitial.fl & SWP_MINIMIZE)
|
---|
1625 | {
|
---|
1626 | SData.PgmControl |= SSF_CONTROL_MINIMIZE;
|
---|
1627 | // use background then
|
---|
1628 | SData.FgBg = SSF_FGBG_BACK;
|
---|
1629 | }
|
---|
1630 | if (pNewProgDetails->swpInitial.fl & SWP_MOVE)
|
---|
1631 | SData.PgmControl |= SSF_CONTROL_SETPOS;
|
---|
1632 | if (pNewProgDetails->swpInitial.fl & SWP_NOAUTOCLOSE)
|
---|
1633 | SData.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
|
---|
1634 |
|
---|
1635 | SData.InitXPos = pNewProgDetails->swpInitial.x;
|
---|
1636 | SData.InitYPos = pNewProgDetails->swpInitial.y;
|
---|
1637 | SData.InitXSize = pNewProgDetails->swpInitial.cx;
|
---|
1638 | SData.InitYSize = pNewProgDetails->swpInitial.cy;
|
---|
1639 |
|
---|
1640 | SData.Reserved = 0;
|
---|
1641 | SData.ObjectBuffer = pszFailingName;
|
---|
1642 | SData.ObjectBuffLen = cbFailingName;
|
---|
1643 |
|
---|
1644 | // now, if a required module cannot be found,
|
---|
1645 | // DosStartSession still returns ERROR_FILE_NOT_FOUND
|
---|
1646 | // (2), but pszFailingName will be set to something
|
---|
1647 | // meaningful... so set it to a null string first
|
---|
1648 | // and we can then check if it has changed
|
---|
1649 | if (pszFailingName)
|
---|
1650 | *pszFailingName = '\0';
|
---|
1651 |
|
---|
1652 | TRY_QUIET(excpt1)
|
---|
1653 | {
|
---|
1654 | if ( (pNewProgDetails->pszStartupDir)
|
---|
1655 | && (pNewProgDetails->pszStartupDir[0])
|
---|
1656 | )
|
---|
1657 | {
|
---|
1658 | fCrit = !DosEnterCritSec();
|
---|
1659 | if ( (!(arc = doshQueryCurrentDir(szCurrentDir)))
|
---|
1660 | && (!(arc = doshSetCurrentDir(pNewProgDetails->pszStartupDir)))
|
---|
1661 | )
|
---|
1662 | fResetDir = TRUE;
|
---|
1663 | }
|
---|
1664 |
|
---|
1665 | if ( (!arc)
|
---|
1666 | && (!(arc = DosStartSession(&SData, &sid, &pid)))
|
---|
1667 | )
|
---|
1668 | {
|
---|
1669 | // app started:
|
---|
1670 | // compose HAPP from that
|
---|
1671 | *phapp = sid;
|
---|
1672 | }
|
---|
1673 | else if (pszFailingName && *pszFailingName)
|
---|
1674 | // DosStartSession has set this to something
|
---|
1675 | // other than NULL: then use error code 1804,
|
---|
1676 | // as cmd.exe does
|
---|
1677 | arc = 1804;
|
---|
1678 | }
|
---|
1679 | CATCH(excpt1)
|
---|
1680 | {
|
---|
1681 | arc = ERROR_PROTECTION_VIOLATION;
|
---|
1682 | } END_CATCH();
|
---|
1683 |
|
---|
1684 | if (fResetDir)
|
---|
1685 | doshSetCurrentDir(szCurrentDir);
|
---|
1686 |
|
---|
1687 | if (fCrit)
|
---|
1688 | DosExitCritSec();
|
---|
1689 |
|
---|
1690 | #ifdef DEBUG_PROGRAMSTART
|
---|
1691 | _Pmpf((" DosStartSession returned %d, pszFailingName: \"%s\"",
|
---|
1692 | arc, pszFailingName));
|
---|
1693 | #endif
|
---|
1694 |
|
---|
1695 | return arc;
|
---|
1696 | }
|
---|
1697 |
|
---|
1698 | /*
|
---|
1699 | *@@ CallWinStartApp:
|
---|
1700 | * wrapper around WinStartApp which copies all the
|
---|
1701 | * parameters into a contiguous block of tiled memory.
|
---|
1702 | *
|
---|
1703 | * This might fix some of the problems with truncated
|
---|
1704 | * environments we were having because apparently the
|
---|
1705 | * WinStartApp thunking to 16-bit doesn't always work.
|
---|
1706 | *
|
---|
1707 | *@@added V0.9.18 (2002-02-13) [umoeller]
|
---|
1708 | *@@changed V0.9.18 (2002-03-27) [umoeller]: made failing modules work
|
---|
1709 | */
|
---|
1710 |
|
---|
1711 | STATIC APIRET CallWinStartApp(HAPP *phapp, // out: application handle if NO_ERROR is returned
|
---|
1712 | HWND hwndNotify, // in: notify window or NULLHANDLE
|
---|
1713 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
---|
1714 | ULONG cbFailingName,
|
---|
1715 | PSZ pszFailingName)
|
---|
1716 | {
|
---|
1717 | APIRET arc = NO_ERROR;
|
---|
1718 |
|
---|
1719 | if (!pcProgDetails)
|
---|
1720 | return ERROR_INVALID_PARAMETER;
|
---|
1721 |
|
---|
1722 | if (pszFailingName)
|
---|
1723 | *pszFailingName = '\0';
|
---|
1724 |
|
---|
1725 | if (!(*phapp = WinStartApp(hwndNotify,
|
---|
1726 | // receives WM_APPTERMINATENOTIFY
|
---|
1727 | (PPROGDETAILS)pcProgDetails,
|
---|
1728 | pcProgDetails->pszParameters,
|
---|
1729 | NULL, // "reserved", PMREF says...
|
---|
1730 | SAF_INSTALLEDCMDLINE)))
|
---|
1731 | // we MUST use SAF_INSTALLEDCMDLINE
|
---|
1732 | // or no Win-OS/2 session will start...
|
---|
1733 | // whatever is going on here... Warp 4 FP11
|
---|
1734 |
|
---|
1735 | // do not use SAF_STARTCHILDAPP, or the
|
---|
1736 | // app will be terminated automatically
|
---|
1737 | // when the calling process terminates!
|
---|
1738 | {
|
---|
1739 | // cannot start app:
|
---|
1740 | PERRINFO pei;
|
---|
1741 |
|
---|
1742 | #ifdef DEBUG_PROGRAMSTART
|
---|
1743 | _Pmpf((__FUNCTION__ ": WinStartApp failed"));
|
---|
1744 | #endif
|
---|
1745 |
|
---|
1746 | // unfortunately WinStartApp doesn't
|
---|
1747 | // return meaningful codes like DosStartSession, so
|
---|
1748 | // try to see what happened
|
---|
1749 |
|
---|
1750 | if (pei = WinGetErrorInfo(0))
|
---|
1751 | {
|
---|
1752 | #ifdef DEBUG_PROGRAMSTART
|
---|
1753 | _Pmpf((" WinGetErrorInfo returned 0x%lX, errorid 0x%lX, %d",
|
---|
1754 | pei,
|
---|
1755 | pei->idError,
|
---|
1756 | ERRORIDERROR(pei->idError)));
|
---|
1757 | #endif
|
---|
1758 |
|
---|
1759 | switch (ERRORIDERROR(pei->idError))
|
---|
1760 | {
|
---|
1761 | case PMERR_DOS_ERROR: // (0x1200)
|
---|
1762 | {
|
---|
1763 | /*
|
---|
1764 | PUSHORT pausMsgOfs = (PUSHORT)(((PBYTE)pei) + pei->offaoffszMsg);
|
---|
1765 | PULONG pulData = (PULONG)(((PBYTE)pei) + pei->offBinaryData);
|
---|
1766 | PSZ pszMsg = (PSZ)(((PBYTE)pei) + *pausMsgOfs);
|
---|
1767 |
|
---|
1768 | CHAR szMsg[1000];
|
---|
1769 | sprintf(szMsg, "cDetail: %d\nmsg: %s\n*pul: %d",
|
---|
1770 | pei->cDetailLevel,
|
---|
1771 | pszMsg,
|
---|
1772 | *(pulData - 1));
|
---|
1773 |
|
---|
1774 | WinMessageBox(HWND_DESKTOP,
|
---|
1775 | NULLHANDLE,
|
---|
1776 | szMsg,
|
---|
1777 | "Error",
|
---|
1778 | 0,
|
---|
1779 | MB_OK | MB_MOVEABLE);
|
---|
1780 |
|
---|
1781 | // Very helpful. The message is "UNK 1200 E",
|
---|
1782 | // where I assume "UNK" means "unknown", which is
|
---|
1783 | // exactly what I was trying to find out. Oh my.
|
---|
1784 | // And cDetailLevel is always 1, which isn't terribly
|
---|
1785 | // helpful either. V0.9.18 (2002-03-27) [umoeller]
|
---|
1786 | // WHO THE &%õ$ CREATED THESE APIS?
|
---|
1787 |
|
---|
1788 | */
|
---|
1789 |
|
---|
1790 | // this is probably the case where the module
|
---|
1791 | // couldn't be loaded, so try DosStartSession
|
---|
1792 | // to get a meaningful return code... note that
|
---|
1793 | // this cannot handle hwndNotify then
|
---|
1794 | /* arc = CallDosStartSession(phapp,
|
---|
1795 | pcProgDetails,
|
---|
1796 | cbFailingName,
|
---|
1797 | pszFailingName); */
|
---|
1798 | arc = ERROR_FILE_NOT_FOUND;
|
---|
1799 | }
|
---|
1800 | break;
|
---|
1801 |
|
---|
1802 | case PMERR_INVALID_APPL: // (0x1530)
|
---|
1803 | // Attempted to start an application whose type is not
|
---|
1804 | // recognized by OS/2.
|
---|
1805 | // This we get also if the executable doesn't exist...
|
---|
1806 | // V0.9.18 (2002-03-27) [umoeller]
|
---|
1807 | // arc = ERROR_INVALID_EXE_SIGNATURE;
|
---|
1808 | arc = ERROR_FILE_NOT_FOUND;
|
---|
1809 | break;
|
---|
1810 |
|
---|
1811 | case PMERR_INVALID_PARAMETERS: // (0x1208)
|
---|
1812 | // An application parameter value is invalid for
|
---|
1813 | // its converted PM type. For example: a 4-byte
|
---|
1814 | // value outside the range -32 768 to +32 767 cannot be
|
---|
1815 | // converted to a SHORT, and a negative number cannot
|
---|
1816 | // be converted to a ULONG or USHORT.
|
---|
1817 | arc = ERROR_INVALID_DATA;
|
---|
1818 | break;
|
---|
1819 |
|
---|
1820 | case PMERR_STARTED_IN_BACKGROUND: // (0x1532)
|
---|
1821 | // The application started a new session in the
|
---|
1822 | // background.
|
---|
1823 | arc = ERROR_SMG_START_IN_BACKGROUND;
|
---|
1824 | break;
|
---|
1825 |
|
---|
1826 | case PMERR_INVALID_WINDOW: // (0x1206)
|
---|
1827 | // The window specified with a Window List call
|
---|
1828 | // is not a valid frame window.
|
---|
1829 |
|
---|
1830 | default:
|
---|
1831 | arc = ERROR_BAD_FORMAT;
|
---|
1832 | break;
|
---|
1833 | }
|
---|
1834 |
|
---|
1835 | WinFreeErrorInfo(pei);
|
---|
1836 | }
|
---|
1837 | }
|
---|
1838 |
|
---|
1839 | return arc;
|
---|
1840 | }
|
---|
1841 |
|
---|
1842 | /*
|
---|
1843 | *@@ appStartApp:
|
---|
1844 | * wrapper around WinStartApp which fixes the
|
---|
1845 | * specified PROGDETAILS to (hopefully) work
|
---|
1846 | * work with all executable types.
|
---|
1847 | *
|
---|
1848 | * This first calls appBuildProgDetails (see
|
---|
1849 | * remarks there) and then calls WinStartApp.
|
---|
1850 | *
|
---|
1851 | * Since this calls WinStartApp in turn, this
|
---|
1852 | * requires a message queue on the calling thread.
|
---|
1853 | *
|
---|
1854 | * Note that this also does minimal checking on
|
---|
1855 | * the specified parameters so it can return something
|
---|
1856 | * more meaningful than FALSE like WinStartApp.
|
---|
1857 | * As a result, you get a DOS error code now (V0.9.16).
|
---|
1858 | *
|
---|
1859 | * Most importantly:
|
---|
1860 | *
|
---|
1861 | * -- ERROR_INVALID_THREADID: not running on thread 1.
|
---|
1862 | * See remarks below.
|
---|
1863 | *
|
---|
1864 | * -- ERROR_NOT_ENOUGH_MEMORY
|
---|
1865 | *
|
---|
1866 | * plus the many error codes from appBuildProgDetails,
|
---|
1867 | * which gets called in turn.
|
---|
1868 | *
|
---|
1869 | * <B>About enforcing thread 1</B>
|
---|
1870 | *
|
---|
1871 | * OK, after long, long debugging hours, I have found
|
---|
1872 | * that WinStartApp hangs the system in the following
|
---|
1873 | * cases hard:
|
---|
1874 | *
|
---|
1875 | * -- If a Win-OS/2 session is started and WinStartApp
|
---|
1876 | * is _not_ on thread 1. For this reason, we check
|
---|
1877 | * if the caller is trying to start a Win-OS/2
|
---|
1878 | * session and return ERROR_INVALID_THREADID if
|
---|
1879 | * this is not running on thread 1.
|
---|
1880 | *
|
---|
1881 | * -- By contrast, there are many situations where
|
---|
1882 | * calling WinStartApp from within the Workplace
|
---|
1883 | * process will hang the system, most notably
|
---|
1884 | * with VIO sessions. I have been unable to figure
|
---|
1885 | * out why this happens, so XWorkplace now uses
|
---|
1886 | * its daemon to call WinStartApp instead.
|
---|
1887 | *
|
---|
1888 | * As a word of wisdom, do not call this from
|
---|
1889 | * within the Workplace process. For some strange
|
---|
1890 | * reason though, the XWorkplace "Run" dialog
|
---|
1891 | * (which uses this) _does_ work. Whatever.
|
---|
1892 | *
|
---|
1893 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
---|
1894 | *@@changed V0.9.7 (2000-12-10) [umoeller]: PROGDETAILS.swpInitial no longer zeroed... this broke VIOs
|
---|
1895 | *@@changed V0.9.7 (2000-12-17) [umoeller]: PROGDETAILS.pszEnvironment no longer zeroed
|
---|
1896 | *@@changed V0.9.9 (2001-01-27) [umoeller]: crashed if PROGDETAILS.pszExecutable was NULL
|
---|
1897 | *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed PROG_DEFAULT
|
---|
1898 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
---|
1899 | *@@changed V0.9.14 (2001-08-07) [pr]: removed some env. strings for Win. apps.
|
---|
1900 | *@@changed V0.9.14 (2001-08-23) [pr]: added session type options
|
---|
1901 | *@@changed V0.9.16 (2001-10-19) [umoeller]: added prototype to return APIRET
|
---|
1902 | *@@changed V0.9.16 (2001-10-19) [umoeller]: added thread-1 check
|
---|
1903 | *@@changed V0.9.16 (2001-12-06) [umoeller]: now using doshSearchPath for finding pszExecutable if not qualified
|
---|
1904 | *@@changed V0.9.16 (2002-01-04) [umoeller]: removed error report if startup directory was drive letter only
|
---|
1905 | *@@changed V0.9.16 (2002-01-04) [umoeller]: added more detailed error reports and *FailingName params
|
---|
1906 | *@@changed V0.9.18 (2002-02-13) [umoeller]: added CallWinStartApp to fix possible memory problems
|
---|
1907 | *@@changed V0.9.18 (2002-03-27) [umoeller]: no longer returning ERROR_INVALID_THREADID, except for Win-OS/2 sessions
|
---|
1908 | *@@changed V0.9.18 (2002-03-27) [umoeller]: extracted appBuildProgDetails
|
---|
1909 | *@@changed V0.9.19 (2002-03-28) [umoeller]: adjusted for new appBuildProgDetails
|
---|
1910 | */
|
---|
1911 |
|
---|
1912 | APIRET appStartApp(HWND hwndNotify, // in: notify window or NULLHANDLE
|
---|
1913 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
---|
1914 | ULONG ulFlags, // in: APP_RUN_* flags or 0
|
---|
1915 | HAPP *phapp, // out: application handle if NO_ERROR is returned
|
---|
1916 | ULONG cbFailingName,
|
---|
1917 | PSZ pszFailingName)
|
---|
1918 | {
|
---|
1919 | APIRET arc;
|
---|
1920 |
|
---|
1921 | PPROGDETAILS pDetails;
|
---|
1922 |
|
---|
1923 | if (!phapp)
|
---|
1924 | return ERROR_INVALID_PARAMETER;
|
---|
1925 |
|
---|
1926 | if (!(arc = appBuildProgDetails(&pDetails,
|
---|
1927 | pcProgDetails,
|
---|
1928 | ulFlags)))
|
---|
1929 | {
|
---|
1930 | if (pszFailingName)
|
---|
1931 | strhncpy0(pszFailingName, pDetails->pszExecutable, cbFailingName);
|
---|
1932 |
|
---|
1933 | if ( (appIsWindowsApp(pDetails->progt.progc))
|
---|
1934 | && (doshMyTID() != 1) // V0.9.16 (2001-10-19) [umoeller]
|
---|
1935 | )
|
---|
1936 | arc = ERROR_INVALID_THREADID;
|
---|
1937 | else
|
---|
1938 | arc = CallWinStartApp(phapp,
|
---|
1939 | hwndNotify,
|
---|
1940 | pDetails,
|
---|
1941 | cbFailingName,
|
---|
1942 | pszFailingName);
|
---|
1943 |
|
---|
1944 | DosFreeMem(pDetails);
|
---|
1945 |
|
---|
1946 | } // end if (ProgDetails.pszExecutable)
|
---|
1947 |
|
---|
1948 | #ifdef DEBUG_PROGRAMSTART
|
---|
1949 | _Pmpf((__FUNCTION__ ": returning %d", arc));
|
---|
1950 | #endif
|
---|
1951 |
|
---|
1952 | return arc;
|
---|
1953 | }
|
---|
1954 |
|
---|
1955 | /*
|
---|
1956 | *@@ appWaitForApp:
|
---|
1957 | * waits for the specified application to terminate
|
---|
1958 | * and returns its exit code.
|
---|
1959 | *
|
---|
1960 | *@@added V0.9.9 (2001-03-07) [umoeller]
|
---|
1961 | */
|
---|
1962 |
|
---|
1963 | BOOL appWaitForApp(HWND hwndNotify, // in: notify window
|
---|
1964 | HAPP happ, // in: app to wait for
|
---|
1965 | PULONG pulExitCode) // out: exit code (ptr can be NULL)
|
---|
1966 | {
|
---|
1967 | BOOL brc = FALSE;
|
---|
1968 |
|
---|
1969 | if (happ)
|
---|
1970 | {
|
---|
1971 | // app started:
|
---|
1972 | // enter a modal message loop until we get the
|
---|
1973 | // WM_APPTERMINATENOTIFY for happ. Then we
|
---|
1974 | // know the app is done.
|
---|
1975 | HAB hab = WinQueryAnchorBlock(hwndNotify);
|
---|
1976 | QMSG qmsg;
|
---|
1977 | // ULONG ulXFixReturnCode = 0;
|
---|
1978 | while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
|
---|
1979 | {
|
---|
1980 | if ( (qmsg.msg == WM_APPTERMINATENOTIFY)
|
---|
1981 | && (qmsg.hwnd == hwndNotify)
|
---|
1982 | && (qmsg.mp1 == (MPARAM)happ)
|
---|
1983 | )
|
---|
1984 | {
|
---|
1985 | // xfix has terminated:
|
---|
1986 | // get xfix return code from mp2... this is:
|
---|
1987 | // -- 0: everything's OK, continue.
|
---|
1988 | // -- 1: handle section was rewritten, restart Desktop
|
---|
1989 | // now.
|
---|
1990 | if (pulExitCode)
|
---|
1991 | *pulExitCode = (ULONG)qmsg.mp2;
|
---|
1992 | brc = TRUE;
|
---|
1993 | // do not dispatch this
|
---|
1994 | break;
|
---|
1995 | }
|
---|
1996 |
|
---|
1997 | WinDispatchMsg(hab, &qmsg);
|
---|
1998 | }
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 | return brc;
|
---|
2002 | }
|
---|
2003 |
|
---|
2004 | /*
|
---|
2005 | *@@ appQuickStartApp:
|
---|
2006 | * shortcut for simply starting an app.
|
---|
2007 | *
|
---|
2008 | * On errors, NULLHANDLE is returned.
|
---|
2009 | *
|
---|
2010 | * Only if pulExitCode != NULL, we wait for
|
---|
2011 | * the app to complete and return the
|
---|
2012 | * exit code.
|
---|
2013 | *
|
---|
2014 | *@@added V0.9.16 (2001-10-19) [umoeller]
|
---|
2015 | *@@changed V0.9.20 (2002-08-10) [umoeller]: fixed missing destroy window, made wait optional
|
---|
2016 | *@@changed V0.9.20 (2002-08-10) [umoeller]: added pcszWorkingDir
|
---|
2017 | *@@changed V1.0.0 (2002-08-18) [umoeller]: changed prototype to return APIRET
|
---|
2018 | */
|
---|
2019 |
|
---|
2020 | APIRET appQuickStartApp(const char *pcszFile,
|
---|
2021 | ULONG ulProgType, // e.g. PROG_PM
|
---|
2022 | const char *pcszArgs, // in: arguments (can be NULL)
|
---|
2023 | const char *pcszWorkingDir, // in: working dir (can be NULL)
|
---|
2024 | HAPP *phapp,
|
---|
2025 | PULONG pulExitCode) // out: exit code; if ptr is NULL, we don't wait
|
---|
2026 | {
|
---|
2027 | APIRET arc = NO_ERROR;
|
---|
2028 | PROGDETAILS pd = {0};
|
---|
2029 | HAPP happReturn = NULLHANDLE;
|
---|
2030 | CHAR szDir[CCHMAXPATH] = "";
|
---|
2031 | PCSZ p;
|
---|
2032 | HWND hwndObject = NULLHANDLE;
|
---|
2033 |
|
---|
2034 | pd.Length = sizeof(pd);
|
---|
2035 | pd.progt.progc = ulProgType;
|
---|
2036 | pd.progt.fbVisible = SHE_VISIBLE;
|
---|
2037 | pd.pszExecutable = (PSZ)pcszFile;
|
---|
2038 | pd.pszParameters = (PSZ)pcszArgs;
|
---|
2039 |
|
---|
2040 | if ( (!(pd.pszStartupDir = (PSZ)pcszWorkingDir))
|
---|
2041 | && (p = strrchr(pcszFile, '\\'))
|
---|
2042 | )
|
---|
2043 | {
|
---|
2044 | strhncpy0(szDir,
|
---|
2045 | pcszFile,
|
---|
2046 | p - pcszFile);
|
---|
2047 | pd.pszStartupDir = szDir;
|
---|
2048 | }
|
---|
2049 |
|
---|
2050 | if (pulExitCode)
|
---|
2051 | if (!(hwndObject = winhCreateObjectWindow(WC_STATIC, NULL)))
|
---|
2052 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
2053 |
|
---|
2054 | if ( (!arc)
|
---|
2055 | && (!(arc = appStartApp(hwndObject,
|
---|
2056 | &pd,
|
---|
2057 | 0,
|
---|
2058 | phapp,
|
---|
2059 | 0,
|
---|
2060 | NULL)))
|
---|
2061 | )
|
---|
2062 | {
|
---|
2063 | if (pulExitCode)
|
---|
2064 | appWaitForApp(hwndObject,
|
---|
2065 | *phapp,
|
---|
2066 | pulExitCode);
|
---|
2067 | }
|
---|
2068 |
|
---|
2069 | if (hwndObject)
|
---|
2070 | WinDestroyWindow(hwndObject); // was missing V0.9.20 (2002-08-10) [umoeller]
|
---|
2071 |
|
---|
2072 | return arc;
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 | /*
|
---|
2076 | *@@ appOpenURL:
|
---|
2077 | * opens the system default browser with the given
|
---|
2078 | * URL.
|
---|
2079 | *
|
---|
2080 | * We return TRUE if appQuickStartApp succeeded with
|
---|
2081 | * that URL.
|
---|
2082 | *
|
---|
2083 | *@@added V0.9.20 (2002-08-10) [umoeller]
|
---|
2084 | *@@changed V1.0.0 (2002-08-21) [umoeller]: changed prototype to return browser
|
---|
2085 | */
|
---|
2086 |
|
---|
2087 | APIRET appOpenURL(PCSZ pcszURL, // in: URL to open
|
---|
2088 | PSZ pszAppStarted, // out: application that was started (req.)
|
---|
2089 | ULONG cbAppStarted) // in: size of that buffer
|
---|
2090 | {
|
---|
2091 | APIRET arc = ERROR_NO_DATA;
|
---|
2092 |
|
---|
2093 | CHAR szStartupDir[CCHMAXPATH];
|
---|
2094 | XSTRING strParameters;
|
---|
2095 |
|
---|
2096 | if ( (!pcszURL)
|
---|
2097 | || (!pszAppStarted)
|
---|
2098 | || (!cbAppStarted)
|
---|
2099 | )
|
---|
2100 | return ERROR_INVALID_PARAMETER;
|
---|
2101 |
|
---|
2102 | xstrInit(&strParameters, 0);
|
---|
2103 |
|
---|
2104 | if (PrfQueryProfileString(HINI_USER,
|
---|
2105 | "WPURLDEFAULTSETTINGS",
|
---|
2106 | "DefaultBrowserExe",
|
---|
2107 | "NETSCAPE.EXE",
|
---|
2108 | pszAppStarted,
|
---|
2109 | cbAppStarted))
|
---|
2110 | {
|
---|
2111 | PSZ pszDefParams;
|
---|
2112 | HAPP happ;
|
---|
2113 |
|
---|
2114 | if (pszDefParams = prfhQueryProfileData(HINI_USER,
|
---|
2115 | "WPURLDEFAULTSETTINGS",
|
---|
2116 | "DefaultParameters",
|
---|
2117 | NULL))
|
---|
2118 | {
|
---|
2119 | xstrcpy(&strParameters, pszDefParams, 0);
|
---|
2120 | xstrcatc(&strParameters, ' ');
|
---|
2121 | free(pszDefParams);
|
---|
2122 | }
|
---|
2123 |
|
---|
2124 | xstrcat(&strParameters, pcszURL, 0);
|
---|
2125 |
|
---|
2126 | PrfQueryProfileString(HINI_USER,
|
---|
2127 | "WPURLDEFAULTSETTINGS",
|
---|
2128 | "DefaultWorkingDir",
|
---|
2129 | "",
|
---|
2130 | szStartupDir,
|
---|
2131 | sizeof(szStartupDir));
|
---|
2132 |
|
---|
2133 | arc = appQuickStartApp(pszAppStarted,
|
---|
2134 | PROG_DEFAULT,
|
---|
2135 | strParameters.psz,
|
---|
2136 | szStartupDir,
|
---|
2137 | &happ,
|
---|
2138 | NULL); // don't wait
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | xstrClear(&strParameters);
|
---|
2142 |
|
---|
2143 | return arc;
|
---|
2144 | }
|
---|