source: trunk/src/helpers/apps.c@ 320

Last change on this file since 320 was 297, checked in by pr, 20 years ago

Update functions using exception handlers to force non-register variables

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