source: trunk/dll/systemf.c@ 1497

Last change on this file since 1497 was 1497, checked in by Gregg Young, 16 years ago

Update ExecOnList to pass environment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: systemf.c 1497 2010-01-08 04:39:40Z gyoung $
5
6 System Interfaces
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2003, 2009 Steven H.Levine
10
11 21 Nov 03 SHL Comments
12 31 Jul 04 SHL Indent -i2
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 17 Jul 06 SHL Use Runtime_Error
15 26 Jul 06 SHL Use convert_nl_to_nul
16 15 Aug 06 SHL More error popups
17 01 Nov 06 SHL runemf2: temp fix for hung windows caused by termq errors
18 03 Nov 06 SHL runemf2: rework termination queue logic to work for multiple threads
19 07 Jan 07 GKY Move error strings etc. to string file
20 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
21 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
22 29 Feb 08 GKY Changes to enable user settable command line length
23 29 Feb 08 GKY Refactor global command line variables to notebook.h
24 26 May 08 SHL Use uiLineNumber correctly
25 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory or pTmpDir and use MakeTempName
26 03 Jan 09 GKY Check for system that is protectonly to gray out Dos/Win command lines and prevent
27 Dos/Win programs from being inserted into the execute dialog with message why.
28 12 Jul 09 GKY Allow FM/2 to load in high memory
29 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
30 27 Dec 09 GKY Provide human readable error message when DosQueryAppType fails because it
31 couldn't find the exe (such as missing archivers).
32
33***********************************************************************/
34
35#include <stdlib.h>
36#include <stdarg.h>
37#include <string.h>
38#include <ctype.h>
39
40#define INCL_DOS
41#define INCL_DOSERRORS
42#define INCL_WIN
43#define INCL_LONGLONG // dircnrs.h
44
45#include "fm3dll.h"
46#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
47#include "mkdir.h" // Data declaration(s)
48#include "init.h" // Data declaration(s)
49#include "mainwnd.h" // Data declaration(s)
50#include "fm3dlg.h"
51#include "fm3str.h"
52#include "errutil.h" // Dos_Error...
53#include "strutil.h" // GetPString
54#include "notebook.h" //targetdirectory
55#include "pathutil.h"
56#include "cmdline.h" // CmdLineDlgProc
57#include "shadow.h" // RunSeamless
58#include "systemf.h"
59#include "strips.h" // convert_nl_to_nul, strip_lead_char
60#include "dirs.h" // switch_to
61#include "valid.h" // MakeFullName
62#include "misc.h" // GetCmdSpec
63#include "copyf.h" // MakeTempName
64#include "wrappers.h" // xfopen
65#include "fortify.h"
66
67static PSZ pszSrcFile = __FILE__;
68
69
70//static HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
71// PROGTYPE * progt, ULONG fl, char *formatstring, ...);
72
73/**
74 * CheckExecutibleFlags checks the dialog controls and returns the appropriate
75 * flags to be passed the runemf
76 */
77
78ULONG CheckExecutibleFlags(HWND hwnd, INT caller)
79{
80 /**
81 * caller indicates the dialog calling the function:
82 * 1 = Associations (ASS_)
83 * 2 = CmdLine (EXEC_)
84 * 3 = Commands (CMD_)
85 **/
86
87 ULONG flags = 0;
88
89 if (caller != 2 &&
90 WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_DEFAULT : ASS_DEFAULT))
91 flags = 0;
92 else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_FULLSCREEN :
93 caller == 1 ? ASS_FULLSCREEN : EXEC_FULLSCREEN))
94 flags = FULLSCREEN;
95 else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_MINIMIZED :
96 caller == 1 ? ASS_MINIMIZED : EXEC_MINIMIZED))
97 flags = MINIMIZED;
98 else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_MAXIMIZED :
99 caller == 1 ? ASS_MAXIMIZED : EXEC_MAXIMIZED))
100 flags = MAXIMIZED;
101 else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_INVISIBLE :
102 caller == 1 ? ASS_INVISIBLE : EXEC_INVISIBLE))
103 flags = INVISIBLE;
104 if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_KEEP : caller == 1 ? ASS_KEEP :
105 EXEC_KEEP))
106 flags |= caller == 2 ? SEPARATEKEEP : KEEP;
107 else if (caller == 2)
108 flags |= SEPARATE;
109 if (caller !=2 && WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_PROMPT : ASS_PROMPT))
110 flags |= PROMPT;
111 if (caller == 3 && WinQueryButtonCheckstate(hwnd, CMD_ONCE))
112 flags |= ONCE;
113 if (caller == 1 && WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
114 flags |= DIEAFTER;
115 return flags;
116}
117
118/**
119 * Bring session foreground
120 * @return TRUE if OK, else FALSE
121 */
122
123BOOL ShowSession(HWND hwnd, PID pid)
124{
125 HSWITCH hswitch;
126 SWCNTRL swctl;
127 ULONG rc;
128
129 hswitch = WinQuerySwitchHandle(pid ? (HWND)0 : hwnd, pid);
130 if (hswitch) {
131 rc = WinQuerySwitchEntry(hswitch, &swctl);
132 if (!rc) {
133 if (swctl.idProcess == pid && swctl.uchVisibility == SWL_VISIBLE)
134 rc = WinSwitchToProgram(hswitch);
135 if (!rc)
136 return TRUE;
137 }
138 }
139 return FALSE;
140}
141
142/**
143 * Invoke runemf2 for command and file/directory list
144 * @return command return code or
145 * -1 if runtime error or
146 * -2 if user cancels command line edit dialog
147 */
148
149int ExecOnList(HWND hwnd, PSZ command, int flags, PSZ tpath, PSZ environment,
150 PSZ *list, PCSZ prompt, PCSZ pszCallingFile, UINT uiLineNumber)
151{
152 /* executes the command once for all files in list */
153
154 CHAR path[CCHMAXPATH], *commandline, modpath[CCHMAXPATH], listfile[CCHMAXPATH],
155 *p, *pp, drive, *file, *ext, *dot;
156 register int x;
157 BOOL spaces;
158
159 if (!command || !*command) {
160 Runtime_Error(pszSrcFile, __LINE__, NULL);
161 return -1;
162 }
163 commandline = xmalloc(MaxComLineStrg + 1, pszSrcFile, __LINE__);
164 if (!commandline)
165 return -1; //already complained
166 *listfile = 0;
167 bstrip(command);
168
169 *path = 0;
170 if (tpath && *tpath)
171 strcpy(path, tpath);
172 else if (*command != '<' || !strchr(command, '>')) {
173 strcpy(path, command + (*command == '"'));
174 if (*command == '\"')
175 p = strchr(path, '\"');
176 else
177 p = strchr(path, ' ');
178 if (p)
179 *p = 0;
180 p = strrchr(path, '\\');
181 if (!p)
182 p = strrchr(path, ':');
183 if (p) {
184 if (*p == ':') {
185 p++;
186 *p = '\\';
187 p++;
188 }
189 *p = 0;
190 }
191 else
192 *path = 0;
193 }
194 if (!*path) {
195 if (list && list[0])
196 strcpy(path, list[0]);
197 p = strrchr(path, '\\');
198 if (!p)
199 p = strrchr(path, ':');
200 if (p) {
201 if (*p == ':') {
202 p++;
203 *p = '\\';
204 p++;
205 }
206 *p = 0;
207 }
208 else
209 *path = 0;
210 }
211 *modpath = 0;
212 if (list && list[0])
213 strcpy(modpath, list[0]);
214 p = strrchr(modpath, '\\');
215 if (!p)
216 p = strrchr(modpath, ':');
217 if (p) {
218 if (*p == ':') {
219 p++;
220 *p = '\\';
221 p++;
222 }
223 *p = 0;
224 }
225 else
226 *modpath = 0;
227 if (!*modpath)
228 strcpy(modpath, path);
229 if (*path)
230 MakeFullName(path);
231 if (*modpath)
232 MakeFullName(modpath);
233 if (IsFullName(path))
234 drive = toupper(*path);
235 else
236 drive = 0;
237
238 p = command; // substitue for special % sequences
239
240 pp = commandline;
241 *commandline = 0;
242 while (*p) {
243 if (*p == '%') {
244 switch (*(p + 1)) {
245 case '!': /* write list to file, add filename */
246 if (list) {
247 if (!*listfile) {
248 FILE *fp;
249
250
251 strcpy(listfile, pTmpDir ? pTmpDir : pFM2SaveDirectory);
252 MakeTempName(listfile, "$FM2LI$T", 2);
253 fp = xfopen(listfile, "w",pszSrcFile,__LINE__);
254 if (fp) {
255 for (x = 0; list[x]; x++)
256 {
257 fputs(list[x], fp);
258 if (list[x + 1])
259 fputc('\n', fp);
260 }
261 fclose(fp);
262 }
263 }
264 strcpy(pp, listfile);
265 pp += strlen(listfile);
266 }
267 p += 2;
268 break;
269
270 case 'c': /* add name of command processor */
271 {
272 char *env = GetCmdSpec(FALSE);
273
274 if (needs_quoting(env) && !strchr(env, '\"')) {
275 *pp = '\"';
276 pp++;
277 spaces = TRUE;
278 }
279 else
280 spaces = FALSE;
281 strcpy(pp, env);
282 p += 2;
283 pp += strlen(env);
284 if (spaces) {
285 *pp = '\"';
286 pp++;
287 }
288 }
289 break;
290
291 case 't': /* add Target directory */
292 if (needs_quoting(targetdir) && !strchr(targetdir, '\"')) {
293 *pp = '\"';
294 pp++;
295 spaces = TRUE;
296 }
297 else
298 spaces = FALSE;
299 strcpy(pp, targetdir);
300 p += 2;
301 pp += strlen(targetdir);
302 if (spaces) {
303 *pp = '\"';
304 pp++;
305 }
306 break;
307
308 case '$': /* add drive letter */
309 if (drive)
310 *pp = drive;
311 else {
312 ULONG ulDriveNum = 3, ulDriveMap;
313
314 DosQCurDisk(&ulDriveNum, &ulDriveMap);
315 *pp = (char) (ulDriveNum + '@');
316 }
317 pp++;
318 p += 2;
319 break;
320
321 case 'U': /* add path of first list component */
322 case 'u':
323 if (*modpath) {
324 if (needs_quoting(modpath) && !strchr(modpath, '\"')) {
325 spaces = TRUE;
326 *pp = '\"';
327 pp++;
328 }
329 else
330 spaces = FALSE;
331 if (*(p + 1) == 'u') {
332 strcpy(pp, modpath);
333 pp += strlen(modpath);
334 }
335 else {
336 strcpy(pp, modpath + 2);
337 pp += strlen(modpath + 2);
338 }
339 if (spaces) {
340 if (modpath[strlen(modpath) - 1] == '\\') {
341 *pp = '\\';
342 pp++;
343 }
344 *pp = '\"';
345 pp++;
346 }
347 }
348 else {
349 char temp[CCHMAXPATH];
350
351 strcpy(temp, pFM2SaveDirectory);
352 if (needs_quoting(temp) && !strchr(temp, '\"')) {
353 spaces = TRUE;
354 *pp = '\"';
355 pp++;
356 }
357 else
358 spaces = FALSE;
359 strcpy(pp, temp);
360 pp += strlen(temp);
361 if (spaces) {
362 if (temp[strlen(temp) - 1] == '\\') {
363 *pp = '\\';
364 pp++;
365 }
366 *pp = '\"';
367 pp++;
368 }
369 }
370 p += 2;
371 break;
372
373 case 'P': /* add path of execution */
374 case 'p':
375 if (*path) {
376 if (needs_quoting(path) && !strchr(path, '\"')) {
377 spaces = TRUE;
378 *pp = '\"';
379 pp++;
380 }
381 else
382 spaces = FALSE;
383 if (*(p + 1) == 'p') {
384 strcpy(pp, path);
385 pp += strlen(path);
386 }
387 else {
388 strcpy(pp, path + 2);
389 pp += strlen(path + 2);
390 }
391 if (spaces) {
392 if (path[strlen(path) - 1] == '\\') {
393 *pp = '\\';
394 pp++;
395 }
396 *pp = '\"';
397 pp++;
398 }
399 }
400 else {
401 char temp[CCHMAXPATH];
402
403 strcpy(temp, pFM2SaveDirectory);
404 if (needs_quoting(temp) && !strchr(temp, '\"')) {
405 spaces = TRUE;
406 *pp = '\"';
407 pp++;
408 }
409 else
410 spaces = FALSE;
411 strcpy(pp, temp);
412 pp += strlen(temp);
413 if (spaces) {
414 if (temp[strlen(temp) - 1] == '\\') {
415 *pp = '\\';
416 pp++;
417 }
418 *pp = '\"';
419 pp++;
420 }
421 }
422 p += 2;
423 break;
424
425 case 'D':
426 if (hwndMain) {
427 PCNRITEM pci;
428
429 pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID(
430 hwndTree, FID_CLIENT), TREE_CNR),
431 CM_QUERYRECORDEMPHASIS,
432 MPFROMLONG(CMA_FIRST),
433 MPFROMSHORT(CRA_CURSORED));
434 if (pci && (int) pci != -1 && *pci->pszFileName) {
435 if (needs_quoting(pci->pszFileName) &&
436 !strchr(pci->pszFileName, '\"'))
437 {
438 *pp = '\"';
439 pp++;
440 spaces = TRUE;
441 }
442 else
443 spaces = FALSE;
444 strcpy(pp, pci->pszFileName);
445 pp += strlen(pci->pszFileName);
446 if (spaces) {
447 *pp = '\"';
448 pp++;
449 }
450 }
451 }
452 p += 2;
453 break;
454
455 case 'd':
456 if (hwndMain) {
457 HENUM henum;
458 char retstr[CCHMAXPATH];
459 HWND hwndC, hwndDir;
460 USHORT id;
461 BOOL first = TRUE;
462
463 henum = WinBeginEnumWindows(hwndMain);
464 while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
465 if (hwndC != hwndTree) {
466 id = WinQueryWindowUShort(hwndC, QWS_ID);
467 if (id) {
468 hwndDir = WinWindowFromID(hwndC, FID_CLIENT);
469 if (hwndDir) {
470 hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
471 if (hwndDir) {
472 *retstr = 0;
473 WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID);
474 if (*retstr) {
475 if (!first) {
476 *pp = ' ';
477 pp++;
478 }
479 first = FALSE;
480 if (needs_quoting(retstr) && !strchr(retstr, '\"')) {
481 *pp = '\"';
482 pp++;
483 spaces = TRUE;
484 }
485 else
486 spaces = FALSE;
487 strcpy(pp, retstr);
488 pp += strlen(retstr);
489 if (spaces) {
490 *pp = '\"';
491 pp++;
492 }
493 }
494 }
495 }
496 }
497 }
498 }
499 WinEndEnumWindows(henum);
500 }
501 p += 2;
502 break;
503
504 case '%':
505 *pp = '%';
506 pp++;
507 p += 2;
508 break;
509
510 case 'R':
511 case 'F':
512 case 'A':
513 case 'r':
514 case 'f':
515 case 'a':
516 case 'e':
517 if (list) {
518 for (x = 0; list[x]; x++)
519 {
520 file = strrchr(list[x], '\\');
521 if (!file)
522 file = strrchr(list[x], ':');
523 if (file)
524 file++;
525 else
526 file = list[x];
527 ext = strrchr(file, '.');
528 dot = ext;
529 if (ext)
530 ext++;
531 switch (*(p + 1)) {
532 case 'R':
533 case 'r':
534 if (pp + strlen(list[x]) > commandline + MaxComLineStrg)
535 goto BreakOut;
536 if (*(p + 1) == 'r') {
537 strcpy(pp, list[x]);
538 pp += strlen(list[x]);
539 }
540 else {
541 strcpy(pp, list[x] + 2);
542 pp += strlen(list[x] + 2);
543 }
544 break;
545
546 case 'F':
547 case 'f':
548 if (*(p + 1) == 'F' && dot)
549 *dot = 0;
550 if (pp + strlen(file) > commandline + MaxComLineStrg)
551 goto BreakOut;
552 if (needs_quoting(file)) {
553 spaces = TRUE;
554 *pp = '\"';
555 pp++;
556 }
557 else
558 spaces = FALSE;
559 strcpy(pp, file);
560 pp += strlen(file);
561 if (*(p + 1) == 'F' && dot)
562 *dot = '.';
563 if (spaces) {
564 if (*(pp - 1) != '\"') {
565 *pp = '\"';
566 pp++;
567 }
568 }
569 break;
570
571 case 'A':
572 case 'a':
573 if (pp + strlen(list[x]) > commandline + MaxComLineStrg)
574 goto BreakOut;
575 if (needs_quoting(list[x]) && !strchr(list[x], '\"')) {
576 spaces = TRUE;
577 *pp = '\"';
578 pp++;
579 }
580 else
581 spaces = FALSE;
582 if (*(p + 1) == 'a') {
583 strcpy(pp, list[x]);
584 pp += strlen(list[x]);
585 }
586 else {
587 strcpy(pp, list[x] + 2);
588 pp += strlen(list[x] + 2);
589 }
590 if (spaces) {
591 if (list[x][strlen(list[x]) - 1] == '\\') {
592 *pp = '\\';
593 pp++;
594 }
595 *pp = '\"';
596 pp++;
597 }
598 break;
599
600 case 'e':
601 if (ext) {
602 if (pp + strlen(ext) > commandline + MaxComLineStrg)
603 goto BreakOut;
604 if (needs_quoting(ext)) {
605 spaces = TRUE;
606 *pp = '\"';
607 pp++;
608 }
609 else
610 spaces = FALSE;
611 strcpy(pp, ext);
612 pp += strlen(ext);
613 if (spaces) {
614 if (*(pp - 1) != '\"') {
615 *pp = '\"';
616 pp++;
617 }
618 }
619 }
620 break;
621 }
622 if (list[x + 1]) {
623 *pp = ' ';
624 pp++;
625 }
626 }
627 }
628 p += 2;
629 break;
630
631 default:
632 *pp = *p;
633 p++;
634 pp++;
635 break;
636 }
637 }
638 else {
639 *pp = *p;
640 pp++;
641 p++;
642 }
643 *pp = 0;
644 }
645
646BreakOut:
647
648 {
649 EXECARGS ex;
650 //ULONG size;
651 int ret;
652
653 memset(&ex, 0, sizeof(EXECARGS));
654 //size = sizeof(ex.environment) - 1;
655 //PrfQueryProfileData(fmprof, FM3Str, command, ex.environment, &size);
656 if (flags & PROMPT) {
657 /* allow editing command line */
658 ex.flags = (flags & (~PROMPT));
659 ex.commandline = commandline;
660 strcpy(ex.path, path);
661 if (prompt)
662 strcpy(ex.title, prompt);
663 ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
664 EXEC_FRAME, &ex);
665 if (ret != 1) {
666 free(commandline);
667 return (ret == 0) ? -1 : -2;
668 }
669 }
670 else
671 ex.flags = flags;
672 ex.flags &= (~PROMPT);
673 //DbgMsg(pszSrcFile, __LINE__, "Inserted %s", environment);
674 ret = runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path,
675 environment ? environment : NULL,
676 "%s", commandline);
677 free(commandline);
678 return ret;
679 }
680}
681
682/** Run requested app
683 * @return application return code or -1 if problem starting app
684 */
685
686int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber,
687 char *pszDirectory, char *pszEnvironment,
688 char *formatstring,...)
689{
690 /** example:
691
692 * status = runemf2(SEPARATE | WINDOWED,
693 * hwnd, pszCallingFile, __LINE__,
694 * NullStr,
695 * NULL,
696 * "%s /C %s",
697 * getenv("COMSPEC"),
698 * batchfilename);
699 *
700 * use (HWND)0 for hwnd if window handle not handy.
701 * pszCallingFile and __LINE__ are used to determine caller for easier error tracking
702 */
703
704 /**
705 * type bitmapped flag -- see systemf.h
706 */
707
708 va_list parguments;
709 int ret = -1;
710 RESULTCODES results;
711 STARTDATA sdata;
712 REQUESTDATA rq;
713 ULONG ulSessID;
714 ULONG ulLength;
715 UINT ctr;
716 ULONG ulAppType;
717 PID sessPID;
718 BOOL wasquote;
719 char *p, *pszPgm, *pszArgs = NULL;
720 char szObject[32] = "";
721 char szSavedir[CCHMAXPATH];
722 BOOL useTermQ = FALSE;
723 char szTempdir[CCHMAXPATH];
724 BOOL fNoErrorMsg = FALSE;
725
726 typedef struct {
727 USHORT usSessID;
728 USHORT usRC;
729 } TERMINFO;
730
731 TERMINFO *pTermInfo;
732 BYTE bPriority;
733 APIRET rc;
734 PIB *ppib;
735 TIB *ptib;
736
737 // Shared by all threads
738# define TERMQ_BASE_NAME "\\QUEUES\\FM3WAIT"
739 static char szTermQName[30];
740 char szTermTemp[30];
741 static HQUEUE hTermQ;
742 static HEV hTermQSem;
743
744 if (pszDirectory && *pszDirectory) {
745 if (!DosQueryPathInfo(pszDirectory,
746 FIL_QUERYFULLNAME,
747 szTempdir,
748 sizeof(szTempdir)))
749 pszDirectory = szTempdir;
750 }
751
752 if (!hwnd)
753 hwnd = HWND_DESKTOP;
754
755 rc = DosAllocMem((PVOID)&pszPgm,
756 MaxComLineStrg,
757 PAG_COMMIT | PAG_READ | PAG_WRITE);
758 if (rc) {
759 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
760 return -1;
761 }
762
763 *szSavedir = 0;
764
765 *pszPgm = 0;
766 va_start(parguments,
767 formatstring);
768 vsprintf(pszPgm,
769 formatstring,
770 parguments);
771 va_end(parguments);
772
773 if (pszEnvironment) {
774 p = &pszEnvironment[strlen(pszEnvironment)] + 1;
775 *p = 0;
776 p = pszEnvironment;
777 while ((p = convert_nl_to_nul(p)) != NULL)
778 ; // loop
779 }
780
781 if (!stricmp(pszCallingFile, "init.c"))
782 fNoErrorMsg = TRUE;
783
784 if (!*pszPgm) {
785 p = GetCmdSpec(FALSE);
786 strcpy(pszPgm, p);
787 if (!*pszPgm) {
788 Runtime_Error(pszSrcFile, __LINE__, NULL);
789 return -1;
790 }
791 }
792
793 if (*pszPgm) {
794 if (*pszPgm == '<' && strchr(pszPgm, '>')) {
795 /* is a workplace object */
796 HOBJECT hWPSObject;
797 char temp;
798
799 p = strchr(pszPgm, '>');
800 p++;
801 temp = *p;
802 if (temp) {
803 rc = DosAllocMem((PVOID)&pszArgs,
804 MaxComLineStrg * 2,
805 PAG_COMMIT | PAG_READ | PAG_WRITE);
806 if (rc)
807 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
808 }
809 else
810 pszArgs = NULL;
811 *p = 0;
812 /* Find the handle of the WPS object */
813 hWPSObject = WinQueryObject(pszPgm);
814 *p = temp;
815 if (hWPSObject != NULLHANDLE) {
816 if (pszArgs && *p) {
817 sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
818 WinSetObjectData(hWPSObject,pszArgs);
819 }
820 else
821 WinSetObjectData(hWPSObject,"OPEN=DEFAULT");
822 ret = 0;
823 }
824 goto ObjectInterrupt;
825 }
826
827 if ((type & RUNTYPE_MASK) == SYNCHRONOUS ||
828 (type & RUNTYPE_MASK) == ASYNCHRONOUS ||
829 (type & RUNTYPE_MASK) == DETACHED)
830 {
831 strip_lead_char(" \t", pszPgm);
832 p = pszPgm;
833 wasquote = FALSE;
834 while (*p &&
835 (wasquote ||
836 (*p != ' ' &&
837 *p != '\t')))
838 {
839 if (*p == '\"') {
840 if (!wasquote) {
841 wasquote = TRUE;
842 memmove(p,
843 p + 1,
844 strlen(p));
845 while (*p == ' ' ||
846 *p == '\t')
847 p++;
848 }
849 else {
850 memmove(p,
851 p + 1,
852 strlen(p));
853 break;
854 }
855 }
856 else
857 p++;
858 }
859 if (*p) {
860 *p = 0;
861 p++;
862 }
863 else
864 p = pszPgm;
865 p[strlen(p) + 1] = 0; /* double-terminate args */
866 if (*pszPgm) {
867 if (!strchr(pszPgm, '\\') &&
868 !strchr(pszPgm, ':') &&
869 pszDirectory &&
870 *pszDirectory)
871 {
872 strcpy(szSavedir, pFM2SaveDirectory);
873 switch_to(pszDirectory);
874 }
875 rc = DosQueryAppType(pszPgm,&ulAppType);
876 if (!strchr(pszPgm, '\\') &&
877 !strchr(pszPgm, ':') &&
878 pszDirectory &&
879 *pszDirectory)
880 switch_to(szSavedir);
881 if (rc) {
882 if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
883 rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
884 saymsg(MB_OK, HWND_DESKTOP, NullStr,
885 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
886 else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
887 saymsg(MB_OK, HWND_DESKTOP, NullStr,
888 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
889 else
890 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
891 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
892 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
893 DosFreeMem(pszPgm);
894 if (pszArgs)
895 DosFreeMem(pszArgs);
896 return -1;
897 }
898 if (ulAppType) {
899 if (ulAppType & FAPPTYP_DLL || ulAppType & FAPPTYP_VIRTDRV ||
900 ulAppType & FAPPTYP_PHYSDRV || ulAppType & FAPPTYP_PROTDLL)
901 {
902 Runtime_Error(pszSrcFile, __LINE__,
903 GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
904 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
905 if (pszPgm)
906 DosFreeMem(pszPgm);
907 if (pszArgs)
908 DosFreeMem(pszArgs);
909 return -1;
910 }
911 if (ulAppType & FAPPTYP_DOS || ulAppType & FAPPTYP_WINDOWSREAL ||
912 ulAppType & FAPPTYP_WINDOWSPROT || ulAppType & FAPPTYP_WINDOWSPROT31)
913 {
914 Runtime_Error(pszSrcFile, __LINE__,
915 GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
916 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
917 if (pszPgm)
918 DosFreeMem(pszPgm);
919 if (pszArgs)
920 DosFreeMem(pszArgs);
921 return -1;
922 }
923 }
924 memset(&results, 0, sizeof(results));
925 if (pszDirectory && *pszDirectory) {
926 strcpy(szSavedir, pFM2SaveDirectory);
927 switch_to(pszDirectory);
928 }
929 ret = DosExecPgm(szObject, sizeof(szObject),
930 ((type & RUNTYPE_MASK) == ASYNCHRONOUS ? EXEC_ASYNC : 0) +
931 ((type & RUNTYPE_MASK) == DETACHED ? EXEC_BACKGROUND : 0),
932 pszPgm, pszEnvironment, &results, pszPgm);
933 if (pszDirectory && *pszDirectory)
934 switch_to(szSavedir);
935 if (ret && !fNoErrorMsg) {
936 Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
937 GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm,
938 pszCallingFile, uiLineNumber); // 26 May 08 SHL
939 }
940 }
941 }
942 else {
943 if (~type & FULLSCREEN)
944 type |= WINDOWED;
945 rc = DosAllocMem((PVOID) & pszArgs, MaxComLineStrg * 2,
946 PAG_COMMIT | PAG_READ | PAG_WRITE);
947 if (rc) {
948 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
949 DosFreeMem(pszPgm);
950 return -1;
951 }
952 *pszArgs = 0;
953 memset(&sdata, 0, sizeof(sdata));
954 strip_lead_char(" \t", pszPgm);
955 p = pszPgm;
956 wasquote = FALSE;
957 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
958 if (*p == '\"') {
959 if (!wasquote) {
960 wasquote = TRUE;
961 memmove(p, p + 1, strlen(p));
962 while (*p == ' ' || *p == '\t')
963 p++;
964 }
965 else {
966 memmove(p, p + 1, strlen(p));
967 break;
968 }
969 }
970 else
971 p++;
972 } // while
973 if (*p) {
974 *p = 0;
975 p++;
976 }
977 else
978 p = NullStr;
979 if (*p)
980 strcpy(pszArgs, p);
981
982 p = strrchr(pszPgm, '.');
983 if (p) {
984 char temp[CCHMAXPATH + 1];
985
986 if (!stricmp(p, PCSZ_DOTBAT)) {
987 if (!fProtectOnly) {
988 strcpy(temp, pszPgm);
989 strcpy(pszPgm, pszArgs);
990 strcpy(pszArgs, "/C ");
991 strcat(pszArgs, temp);
992 strcat(pszArgs, " ");
993 strcat(pszArgs, pszPgm);
994 strcpy(pszPgm, GetCmdSpec(TRUE)); // DOS
995 }
996 else
997 saymsg(MB_OK,
998 HWND_DESKTOP,
999 NullStr,
1000 GetPString(IDS_NOTPROTECTONLYEXE),
1001 pszPgm);
1002 }
1003 else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
1004 // Assume 4OS2 is BTM
1005 strcpy(temp, pszPgm);
1006 strcpy(pszPgm, pszArgs);
1007 strcpy(pszArgs, "/C ");
1008 strcat(pszArgs, temp);
1009 strcat(pszArgs, " ");
1010 strcat(pszArgs, pszPgm);
1011 strcpy(pszPgm, GetCmdSpec(FALSE)); // OS/2
1012 }
1013 }
1014
1015 // goddamned OS/2 limit
1016
1017 if (strlen(pszPgm) + strlen(pszArgs) > 1024)
1018 pszArgs[1024 - strlen(pszPgm)] = 0;
1019
1020 if (!strchr(pszPgm, '\\') &&
1021 !strchr(pszPgm, ':') &&
1022 pszDirectory &&
1023 *pszDirectory)
1024 {
1025 strcpy(szSavedir, pFM2SaveDirectory);
1026 switch_to(pszDirectory);
1027 }
1028 rc = DosQueryAppType(pszPgm,&ulAppType);
1029 if (!strchr(pszPgm, '\\') &&
1030 !strchr(pszPgm, ':') &&
1031 pszDirectory &&
1032 *pszDirectory)
1033 switch_to(szSavedir);
1034 if (rc) {
1035 if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
1036 rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
1037 saymsg(MB_OK, HWND_DESKTOP, NullStr,
1038 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
1039 else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
1040 saymsg(MB_OK, HWND_DESKTOP, NullStr,
1041 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
1042 else
1043 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
1044 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
1045 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
1046 DosFreeMem(pszPgm);
1047 if (pszArgs)
1048 DosFreeMem(pszArgs);
1049 return -1;
1050 }
1051
1052 if (ulAppType) {
1053 if (ulAppType & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL))
1054 {
1055 Runtime_Error(pszSrcFile, __LINE__,
1056 GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
1057 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
1058 DosFreeMem(pszPgm);
1059 if (pszArgs)
1060 DosFreeMem(pszArgs);
1061 return -1;
1062 }
1063 ulAppType &= ~FAPPTYP_BOUND;
1064 if (ulAppType & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
1065 {
1066 if (ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
1067 {
1068 if (~type & FULLSCREEN &&
1069 ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
1070 {
1071 ret = RunSeamless(pszPgm, pszArgs, hwnd);
1072 if (pszPgm)
1073 DosFreeMem(pszPgm);
1074 if (pszArgs)
1075 DosFreeMem(pszArgs);
1076 return ret ? 0 : -1;
1077 }
1078 else {
1079 strcat(pszPgm, " ");
1080 strcat(pszPgm, pszArgs);
1081 *pszArgs = 0;
1082 if (ulAppType & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31))
1083 strcat(pszArgs, "/3 ");
1084 strcat(pszArgs, pszPgm);
1085 strcpy(pszPgm, "WINOS2.COM");
1086 }
1087 }
1088 else {
1089 if (~type & FULLSCREEN) {
1090 type |= WINDOWED;
1091 ulAppType = SSF_TYPE_WINDOWEDVDM;
1092 }
1093 else {
1094 type &= ~WINDOWED;
1095 ulAppType = SSF_TYPE_VDM;
1096 }
1097 }
1098 }
1099 else if (ulAppType & FAPPTYP_32BIT) {
1100 ulAppType &= ~FAPPTYP_32BIT;
1101 if (ulAppType == FAPPTYP_WINDOWAPI)
1102 ulAppType = SSF_TYPE_PM;
1103 else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
1104 ulAppType = SSF_TYPE_WINDOWABLEVIO;
1105 else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
1106 ulAppType = SSF_TYPE_FULLSCREEN;
1107 type &= ~WINDOWED;
1108 type |= FULLSCREEN;
1109 }
1110 else /* ? */
1111 ulAppType = SSF_TYPE_WINDOWABLEVIO;
1112 }
1113 else if (ulAppType == FAPPTYP_WINDOWAPI)
1114 ulAppType = SSF_TYPE_PM;
1115 else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
1116 ulAppType = SSF_TYPE_WINDOWABLEVIO;
1117 else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
1118 type &= ~WINDOWED;
1119 ulAppType = SSF_TYPE_FULLSCREEN;
1120 }
1121 else
1122 ulAppType = SSF_TYPE_DEFAULT;
1123 if ((type & FULLSCREEN || ~type & WINDOWED) &&
1124 ulAppType == SSF_TYPE_WINDOWABLEVIO)
1125 {
1126 ulAppType = SSF_TYPE_FULLSCREEN;
1127 }
1128 // fixme parens?
1129 else if (type & FULLSCREEN ||
1130 (type & WINDOWED && ulAppType == SSF_TYPE_WINDOWEDVDM))
1131 {
1132 ulAppType = SSF_TYPE_VDM;
1133 }
1134 }
1135 if (ulAppType == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) {
1136 type &= ~SEPARATEKEEP;
1137 type |= SEPARATE;
1138 }
1139
1140 DosGetInfoBlocks(&ptib, &ppib);
1141
1142 if (~type & WAIT)
1143 useTermQ = FALSE;
1144 else {
1145 rc = 0;
1146 DosEnterCritSec();
1147 if (!hTermQ) {
1148 // Create term queue and event semaphore just once
1149 sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid);
1150 rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName);
1151 if (rc) {
1152 hTermQ = (HQUEUE)0; // Try to survive
1153 DosExitCritSec();
1154 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
1155 }
1156 else {
1157 rc = DosCreateEventSem(NULL,(PHEV)&hTermQSem,0,FALSE);
1158 if (rc) {
1159 hTermQSem = (HEV)0; // Try to survive
1160 DosCloseQueue(hTermQ);
1161 hTermQ = (HQUEUE)0; // Try to survive
1162 DosExitCritSec();
1163 Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__, PCSZ_DOSCREATEEVENTSEM);
1164 }
1165 // if (!rc) fprintf(stderr,"%s %d qcreated ptib %x hTermQ %x\n",__FILE__, __LINE__,ptib,hTermQ);
1166 }
1167 } // if 1st time
1168 useTermQ = hTermQ && hTermQSem;
1169 if (!rc)
1170 DosExitCritSec();
1171 } // if wait
1172
1173 memset(&sdata,0,sizeof(sdata));
1174 sdata.Length = sizeof(sdata);
1175 sdata.Related = type & (WAIT | CHILD) ? SSF_RELATED_CHILD :
1176 SSF_RELATED_INDEPENDENT;
1177 sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE;
1178 sdata.TraceOpt = SSF_TRACEOPT_NONE;
1179 sdata.PgmName = pszPgm;
1180 if (*pszArgs)
1181 sdata.PgmInputs = (PBYTE)pszArgs;
1182 if (useTermQ) {
1183 strcpy(szTermTemp, szTermQName);
1184 sdata.TermQ = (PBYTE)szTermTemp;
1185 }
1186 sdata.Environment = (PBYTE)pszEnvironment;
1187 sdata.InheritOpt = SSF_INHERTOPT_PARENT;
1188 sdata.SessionType = ulAppType;
1189 sdata.ObjectBuffer = szObject;
1190 sdata.ObjectBuffLen = sizeof(szObject);
1191 if ((type & RUNTYPE_MASK) == SEPARATEKEEP)
1192 sdata.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
1193 if (type & MAXIMIZED)
1194 sdata.PgmControl |= SSF_CONTROL_MAXIMIZE;
1195 if (type & MINIMIZED)
1196 sdata.PgmControl |= SSF_CONTROL_MINIMIZE;
1197 if (type & INVISIBLE)
1198 sdata.PgmControl |= SSF_CONTROL_INVISIBLE;
1199
1200 if (pszDirectory && *pszDirectory) {
1201 strcpy(szSavedir, pFM2SaveDirectory);
1202 switch_to(pszDirectory);
1203 }
1204 ret = DosStartSession(&sdata, &ulSessID, &sessPID);
1205
1206
1207 if (pszDirectory && *pszDirectory)
1208 switch_to(szSavedir);
1209
1210 if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
1211 if (!fNoErrorMsg)
1212 Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
1213 GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs,
1214 pszCallingFile, uiLineNumber); // 26 May 08 SHL
1215 }
1216 else if (type & WAIT) {
1217 if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
1218 ShowSession(hwnd, sessPID);
1219
1220 if (!useTermQ) {
1221 STATUSDATA sd;
1222
1223 memset(&sd, 0, sizeof(sd));
1224 sd.Length = (USHORT) sizeof(sd);
1225 sd.SelectInd = SET_SESSION_UNCHANGED;
1226 sd.BondInd = SET_SESSION_UNCHANGED;
1227 for (ctr = 0;; ctr++)
1228 {
1229 DosSleep(50);//05 Aug 07 GKY 200
1230 if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished)
1231 break;
1232 if (ctr > 10) {
1233 ShowSession(hwnd, sessPID); // Show every 2 seconds
1234 ctr = 0;
1235 }
1236 }
1237 }
1238 else {
1239 for (ctr = 0;; ctr++)
1240 {
1241 if (ctr < 20) {
1242 rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
1243 DCWW_NOWAIT, &bPriority, hTermQSem);
1244 if (rc == ERROR_QUE_EMPTY) {
1245 DosSleep(50);//05 Aug 07 GKY 100
1246 continue;
1247 }
1248 }
1249 else {
1250 if (ctr == 20) {
1251 ShowSession(hwnd, sessPID); // Show long running session
1252 }
1253 rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
1254 DCWW_WAIT, &bPriority, 0);
1255 }
1256
1257 if (rc) {
1258 // Oh heck
1259 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
1260 DosSleep(100);//05 Aug 07 GKY 500
1261 continue;
1262 }
1263
1264 // printf("%s %d DosReadQueue thread 0x%x sess %u sessRC %u rq.pid 0x%x rq.data 0x%x\n",
1265 // __FILE__, __LINE__,ptib->tib_ordinal,pTermInfo->usSessID,pTermInfo->usRC,rq.pid, rq.ulData); fflush(stdout);
1266
1267 if (pTermInfo->usSessID == ulSessID)
1268 break; // Our session is done
1269
1270 // Requeue session for other thread
1271 {
1272 static ULONG ulLastSessID;
1273 // printf("%s %d requeue thread 0x%x our sess %u term sess %u term rc %u\n",
1274 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,pTermInfo->usSessID,pTermInfo->usRC); fflush(stdout);
1275 // fixme to be gone when no longer needed for debug?
1276 if (ulLastSessID) {
1277 DosSleep(100);//05 Aug 07 GKY 500
1278 ulLastSessID = pTermInfo->usSessID;
1279 }
1280 // requeue term report for other thread and do not free yet
1281 rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority);
1282 if (rc)
1283 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue");
1284 DosSleep(50); //05 Aug 07 GKY 100 // Let other thread see queue entry
1285 }
1286 } // for
1287
1288 ret = pTermInfo->usRC == 0; // Set 1 if rc 0 else 0
1289 // printf("%s %d thread 0x%x term for sess %u\n",
1290 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID);fflush(stdout);
1291 DosFreeMem(pTermInfo);
1292 }
1293 } // if wait
1294 else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
1295 ShowSession(hwnd, sessPID);
1296 }
1297 }
1298
1299ObjectInterrupt:
1300
1301 if (pszPgm)
1302 DosFreeMem(pszPgm);
1303 if (pszArgs)
1304 DosFreeMem(pszArgs);
1305
1306 return ret;
1307}
1308
1309//== Exec() Start application with WinStartApp ==
1310#if 0 // JBS 11 Sep 08
1311HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
1312 PROGTYPE *progt, ULONG fl, char *formatstring,...)
1313{
1314 PROGDETAILS pgd;
1315 register char *p;
1316 char *parameters = NULL, *executable = NULL;
1317 HAPP happ = (HAPP)0;
1318 ULONG ulOptions = SAF_INSTALLEDCMDLINE;
1319 BOOL wasquote;
1320 va_list parguments;
1321
1322 if (child)
1323 ulOptions |= SAF_STARTCHILDAPP;
1324
1325 executable = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1326 if (executable) {
1327 va_start(parguments, formatstring);
1328 vsprintf(executable, formatstring, parguments);
1329 va_end(parguments);
1330 strip_lead_char(" \t", executable);
1331 if (*executable) {
1332 parameters = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
1333 if (parameters) {
1334 p = executable;
1335 wasquote = FALSE;
1336 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
1337 if (*p == '\"') {
1338 if (!wasquote) {
1339 wasquote = TRUE;
1340 memmove(p, p + 1, strlen(p));
1341 while (*p == ' ' || *p == '\t')
1342 p++;
1343 }
1344 else {
1345 memmove(p, p + 1, strlen(p));
1346 break;
1347 }
1348 }
1349 else
1350 p++;
1351 }
1352 if (*p) {
1353 *p = 0;
1354 p++;
1355 }
1356 else
1357 p = NullStr;
1358 if (*p)
1359 strcpy(parameters, p);
1360
1361 if (p && (!stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTCMD) ||
1362 !stricmp(p, PCSZ_DOTBTM))) {
1363 char *temp;
1364
1365 temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
1366 if (temp) {
1367 if (!stricmp(p, PCSZ_DOTBAT)) {
1368 if (!fProtectOnly) {
1369 strcpy(temp, executable);
1370 strcpy(executable, parameters);
1371 strcpy(parameters, "/C ");
1372 strcat(parameters, temp);
1373 strcat(parameters, " ");
1374 strcat(parameters, executable);
1375 strcpy(executable, GetCmdSpec(TRUE)); //DOS
1376 }
1377 else
1378 saymsg(MB_OK,
1379 HWND_DESKTOP,
1380 NullStr,
1381 GetPString(IDS_NOTPROTECTONLYEXE),
1382 filename);
1383 }
1384 else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
1385 strcpy(temp, executable);
1386 strcpy(executable, parameters);
1387 strcpy(parameters, "/C ");
1388 strcat(parameters, temp);
1389 strcat(parameters, " ");
1390 strcat(parameters, executable);
1391 strcpy(executable, GetCmdSpec(FALSE));
1392 }
1393 free(temp);
1394 }
1395 }
1396
1397 memset(&pgd, 0, sizeof(pgd));
1398 pgd.Length = sizeof(pgd);
1399 pgd.progt = *progt;
1400 pgd.swpInitial.fl = fl;
1401 pgd.pszEnvironment = env;
1402 pgd.pszStartupDir = startdir;
1403 pgd.pszParameters = *parameters ? parameters : NULL;
1404 pgd.pszExecutable = executable;
1405 pgd.swpInitial.hwndInsertBehind = HWND_TOP;
1406 happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions);
1407 free(parameters);
1408 }
1409 }
1410 free(executable);
1411 }
1412 return happ;
1413}
1414#endif
1415#pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
Note: See TracBrowser for help on using the repository browser.