source: trunk/dll/systemf.c@ 1492

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

Provide readable error message when DosQueryAppType fails because it can't find and exe. Ticket 403

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: systemf.c 1492 2009-12-28 02:22:35Z 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, char *command, int flags, char *tpath,
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 ret = runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path,
674 (*ex.environment) ? ex.environment : NULL,
675 "%s", commandline);
676 free(commandline);
677 return ret;
678 }
679}
680
681/** Run requested app
682 * @return application return code or -1 if problem starting app
683 */
684
685int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber,
686 char *pszDirectory, char *pszEnvironment,
687 char *formatstring,...)
688{
689 /** example:
690
691 * status = runemf2(SEPARATE | WINDOWED,
692 * hwnd, pszCallingFile, __LINE__,
693 * NullStr,
694 * NULL,
695 * "%s /C %s",
696 * getenv("COMSPEC"),
697 * batchfilename);
698 *
699 * use (HWND)0 for hwnd if window handle not handy.
700 * pszCallingFile and __LINE__ are used to determine caller for easier error tracking
701 */
702
703 /**
704 * type bitmapped flag -- see systemf.h
705 */
706
707 va_list parguments;
708 int ret = -1;
709 RESULTCODES results;
710 STARTDATA sdata;
711 REQUESTDATA rq;
712 ULONG ulSessID;
713 ULONG ulLength;
714 UINT ctr;
715 ULONG ulAppType;
716 PID sessPID;
717 BOOL wasquote;
718 char *p, *pszPgm, *pszArgs = NULL;
719 char szObject[32] = "";
720 char szSavedir[CCHMAXPATH];
721 BOOL useTermQ = FALSE;
722 char szTempdir[CCHMAXPATH];
723 BOOL fNoErrorMsg = FALSE;
724
725 typedef struct {
726 USHORT usSessID;
727 USHORT usRC;
728 } TERMINFO;
729
730 TERMINFO *pTermInfo;
731 BYTE bPriority;
732 APIRET rc;
733 PIB *ppib;
734 TIB *ptib;
735
736 // Shared by all threads
737# define TERMQ_BASE_NAME "\\QUEUES\\FM3WAIT"
738 static char szTermQName[30];
739 char szTermTemp[30];
740 static HQUEUE hTermQ;
741 static HEV hTermQSem;
742
743 if (pszDirectory && *pszDirectory) {
744 if (!DosQueryPathInfo(pszDirectory,
745 FIL_QUERYFULLNAME,
746 szTempdir,
747 sizeof(szTempdir)))
748 pszDirectory = szTempdir;
749 }
750
751 if (!hwnd)
752 hwnd = HWND_DESKTOP;
753
754 rc = DosAllocMem((PVOID)&pszPgm,
755 MaxComLineStrg,
756 PAG_COMMIT | PAG_READ | PAG_WRITE);
757 if (rc) {
758 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
759 return -1;
760 }
761
762 *szSavedir = 0;
763
764 *pszPgm = 0;
765 va_start(parguments,
766 formatstring);
767 vsprintf(pszPgm,
768 formatstring,
769 parguments);
770 va_end(parguments);
771
772 if (pszEnvironment) {
773 p = &pszEnvironment[strlen(pszEnvironment)] + 1;
774 *p = 0;
775 p = pszEnvironment;
776 while ((p = convert_nl_to_nul(p)) != NULL)
777 ; // loop
778 }
779
780 if (!stricmp(pszCallingFile, "init.c"))
781 fNoErrorMsg = TRUE;
782
783 if (!*pszPgm) {
784 p = GetCmdSpec(FALSE);
785 strcpy(pszPgm, p);
786 if (!*pszPgm) {
787 Runtime_Error(pszSrcFile, __LINE__, NULL);
788 return -1;
789 }
790 }
791
792 if (*pszPgm) {
793 if (*pszPgm == '<' && strchr(pszPgm, '>')) {
794 /* is a workplace object */
795 HOBJECT hWPSObject;
796 char temp;
797
798 p = strchr(pszPgm, '>');
799 p++;
800 temp = *p;
801 if (temp) {
802 rc = DosAllocMem((PVOID)&pszArgs,
803 MaxComLineStrg * 2,
804 PAG_COMMIT | PAG_READ | PAG_WRITE);
805 if (rc)
806 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
807 }
808 else
809 pszArgs = NULL;
810 *p = 0;
811 /* Find the handle of the WPS object */
812 hWPSObject = WinQueryObject(pszPgm);
813 *p = temp;
814 if (hWPSObject != NULLHANDLE) {
815 if (pszArgs && *p) {
816 sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
817 WinSetObjectData(hWPSObject,pszArgs);
818 }
819 else
820 WinSetObjectData(hWPSObject,"OPEN=DEFAULT");
821 ret = 0;
822 }
823 goto ObjectInterrupt;
824 }
825
826 if ((type & RUNTYPE_MASK) == SYNCHRONOUS ||
827 (type & RUNTYPE_MASK) == ASYNCHRONOUS ||
828 (type & RUNTYPE_MASK) == DETACHED)
829 {
830 strip_lead_char(" \t", pszPgm);
831 p = pszPgm;
832 wasquote = FALSE;
833 while (*p &&
834 (wasquote ||
835 (*p != ' ' &&
836 *p != '\t')))
837 {
838 if (*p == '\"') {
839 if (!wasquote) {
840 wasquote = TRUE;
841 memmove(p,
842 p + 1,
843 strlen(p));
844 while (*p == ' ' ||
845 *p == '\t')
846 p++;
847 }
848 else {
849 memmove(p,
850 p + 1,
851 strlen(p));
852 break;
853 }
854 }
855 else
856 p++;
857 }
858 if (*p) {
859 *p = 0;
860 p++;
861 }
862 else
863 p = pszPgm;
864 p[strlen(p) + 1] = 0; /* double-terminate args */
865 if (*pszPgm) {
866 if (!strchr(pszPgm, '\\') &&
867 !strchr(pszPgm, ':') &&
868 pszDirectory &&
869 *pszDirectory)
870 {
871 strcpy(szSavedir, pFM2SaveDirectory);
872 switch_to(pszDirectory);
873 }
874 rc = DosQueryAppType(pszPgm,&ulAppType);
875 if (!strchr(pszPgm, '\\') &&
876 !strchr(pszPgm, ':') &&
877 pszDirectory &&
878 *pszDirectory)
879 switch_to(szSavedir);
880 if (rc) {
881 if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
882 rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
883 saymsg(MB_OK, HWND_DESKTOP, NullStr,
884 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
885 else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
886 saymsg(MB_OK, HWND_DESKTOP, NullStr,
887 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
888 else
889 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
890 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
891 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
892 DosFreeMem(pszPgm);
893 if (pszArgs)
894 DosFreeMem(pszArgs);
895 return -1;
896 }
897 if (ulAppType) {
898 if (ulAppType & FAPPTYP_DLL || ulAppType & FAPPTYP_VIRTDRV ||
899 ulAppType & FAPPTYP_PHYSDRV || ulAppType & FAPPTYP_PROTDLL)
900 {
901 Runtime_Error(pszSrcFile, __LINE__,
902 GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
903 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
904 if (pszPgm)
905 DosFreeMem(pszPgm);
906 if (pszArgs)
907 DosFreeMem(pszArgs);
908 return -1;
909 }
910 if (ulAppType & FAPPTYP_DOS || ulAppType & FAPPTYP_WINDOWSREAL ||
911 ulAppType & FAPPTYP_WINDOWSPROT || ulAppType & FAPPTYP_WINDOWSPROT31)
912 {
913 Runtime_Error(pszSrcFile, __LINE__,
914 GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
915 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
916 if (pszPgm)
917 DosFreeMem(pszPgm);
918 if (pszArgs)
919 DosFreeMem(pszArgs);
920 return -1;
921 }
922 }
923 memset(&results, 0, sizeof(results));
924 if (pszDirectory && *pszDirectory) {
925 strcpy(szSavedir, pFM2SaveDirectory);
926 switch_to(pszDirectory);
927 }
928 ret = DosExecPgm(szObject, sizeof(szObject),
929 ((type & RUNTYPE_MASK) == ASYNCHRONOUS ? EXEC_ASYNC : 0) +
930 ((type & RUNTYPE_MASK) == DETACHED ? EXEC_BACKGROUND : 0),
931 pszPgm, pszEnvironment, &results, pszPgm);
932 if (pszDirectory && *pszDirectory)
933 switch_to(szSavedir);
934 if (ret && !fNoErrorMsg) {
935 Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
936 GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm,
937 pszCallingFile, uiLineNumber); // 26 May 08 SHL
938 }
939 }
940 }
941 else {
942 if (~type & FULLSCREEN)
943 type |= WINDOWED;
944 rc = DosAllocMem((PVOID) & pszArgs, MaxComLineStrg * 2,
945 PAG_COMMIT | PAG_READ | PAG_WRITE);
946 if (rc) {
947 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
948 DosFreeMem(pszPgm);
949 return -1;
950 }
951 *pszArgs = 0;
952 memset(&sdata, 0, sizeof(sdata));
953 strip_lead_char(" \t", pszPgm);
954 p = pszPgm;
955 wasquote = FALSE;
956 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
957 if (*p == '\"') {
958 if (!wasquote) {
959 wasquote = TRUE;
960 memmove(p, p + 1, strlen(p));
961 while (*p == ' ' || *p == '\t')
962 p++;
963 }
964 else {
965 memmove(p, p + 1, strlen(p));
966 break;
967 }
968 }
969 else
970 p++;
971 } // while
972 if (*p) {
973 *p = 0;
974 p++;
975 }
976 else
977 p = NullStr;
978 if (*p)
979 strcpy(pszArgs, p);
980
981 p = strrchr(pszPgm, '.');
982 if (p) {
983 char temp[CCHMAXPATH + 1];
984
985 if (!stricmp(p, PCSZ_DOTBAT)) {
986 if (!fProtectOnly) {
987 strcpy(temp, pszPgm);
988 strcpy(pszPgm, pszArgs);
989 strcpy(pszArgs, "/C ");
990 strcat(pszArgs, temp);
991 strcat(pszArgs, " ");
992 strcat(pszArgs, pszPgm);
993 strcpy(pszPgm, GetCmdSpec(TRUE)); // DOS
994 }
995 else
996 saymsg(MB_OK,
997 HWND_DESKTOP,
998 NullStr,
999 GetPString(IDS_NOTPROTECTONLYEXE),
1000 pszPgm);
1001 }
1002 else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
1003 // Assume 4OS2 is BTM
1004 strcpy(temp, pszPgm);
1005 strcpy(pszPgm, pszArgs);
1006 strcpy(pszArgs, "/C ");
1007 strcat(pszArgs, temp);
1008 strcat(pszArgs, " ");
1009 strcat(pszArgs, pszPgm);
1010 strcpy(pszPgm, GetCmdSpec(FALSE)); // OS/2
1011 }
1012 }
1013
1014 // goddamned OS/2 limit
1015
1016 if (strlen(pszPgm) + strlen(pszArgs) > 1024)
1017 pszArgs[1024 - strlen(pszPgm)] = 0;
1018
1019 if (!strchr(pszPgm, '\\') &&
1020 !strchr(pszPgm, ':') &&
1021 pszDirectory &&
1022 *pszDirectory)
1023 {
1024 strcpy(szSavedir, pFM2SaveDirectory);
1025 switch_to(pszDirectory);
1026 }
1027 rc = DosQueryAppType(pszPgm,&ulAppType);
1028 if (!strchr(pszPgm, '\\') &&
1029 !strchr(pszPgm, ':') &&
1030 pszDirectory &&
1031 *pszDirectory)
1032 switch_to(szSavedir);
1033 if (rc) {
1034 if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
1035 rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
1036 saymsg(MB_OK, HWND_DESKTOP, NullStr,
1037 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
1038 else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
1039 saymsg(MB_OK, HWND_DESKTOP, NullStr,
1040 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
1041 else
1042 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
1043 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
1044 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
1045 DosFreeMem(pszPgm);
1046 if (pszArgs)
1047 DosFreeMem(pszArgs);
1048 return -1;
1049 }
1050
1051 if (ulAppType) {
1052 if (ulAppType & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL))
1053 {
1054 Runtime_Error(pszSrcFile, __LINE__,
1055 GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
1056 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
1057 DosFreeMem(pszPgm);
1058 if (pszArgs)
1059 DosFreeMem(pszArgs);
1060 return -1;
1061 }
1062 ulAppType &= ~FAPPTYP_BOUND;
1063 if (ulAppType & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
1064 {
1065 if (ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
1066 {
1067 if (~type & FULLSCREEN &&
1068 ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
1069 {
1070 ret = RunSeamless(pszPgm, pszArgs, hwnd);
1071 if (pszPgm)
1072 DosFreeMem(pszPgm);
1073 if (pszArgs)
1074 DosFreeMem(pszArgs);
1075 return ret ? 0 : -1;
1076 }
1077 else {
1078 strcat(pszPgm, " ");
1079 strcat(pszPgm, pszArgs);
1080 *pszArgs = 0;
1081 if (ulAppType & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31))
1082 strcat(pszArgs, "/3 ");
1083 strcat(pszArgs, pszPgm);
1084 strcpy(pszPgm, "WINOS2.COM");
1085 }
1086 }
1087 else {
1088 if (~type & FULLSCREEN) {
1089 type |= WINDOWED;
1090 ulAppType = SSF_TYPE_WINDOWEDVDM;
1091 }
1092 else {
1093 type &= ~WINDOWED;
1094 ulAppType = SSF_TYPE_VDM;
1095 }
1096 }
1097 }
1098 else if (ulAppType & FAPPTYP_32BIT) {
1099 ulAppType &= ~FAPPTYP_32BIT;
1100 if (ulAppType == FAPPTYP_WINDOWAPI)
1101 ulAppType = SSF_TYPE_PM;
1102 else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
1103 ulAppType = SSF_TYPE_WINDOWABLEVIO;
1104 else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
1105 ulAppType = SSF_TYPE_FULLSCREEN;
1106 type &= ~WINDOWED;
1107 type |= FULLSCREEN;
1108 }
1109 else /* ? */
1110 ulAppType = SSF_TYPE_WINDOWABLEVIO;
1111 }
1112 else if (ulAppType == FAPPTYP_WINDOWAPI)
1113 ulAppType = SSF_TYPE_PM;
1114 else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
1115 ulAppType = SSF_TYPE_WINDOWABLEVIO;
1116 else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
1117 type &= ~WINDOWED;
1118 ulAppType = SSF_TYPE_FULLSCREEN;
1119 }
1120 else
1121 ulAppType = SSF_TYPE_DEFAULT;
1122 if ((type & FULLSCREEN || ~type & WINDOWED) &&
1123 ulAppType == SSF_TYPE_WINDOWABLEVIO)
1124 {
1125 ulAppType = SSF_TYPE_FULLSCREEN;
1126 }
1127 // fixme parens?
1128 else if (type & FULLSCREEN ||
1129 (type & WINDOWED && ulAppType == SSF_TYPE_WINDOWEDVDM))
1130 {
1131 ulAppType = SSF_TYPE_VDM;
1132 }
1133 }
1134 if (ulAppType == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) {
1135 type &= ~SEPARATEKEEP;
1136 type |= SEPARATE;
1137 }
1138
1139 DosGetInfoBlocks(&ptib, &ppib);
1140
1141 if (~type & WAIT)
1142 useTermQ = FALSE;
1143 else {
1144 rc = 0;
1145 DosEnterCritSec();
1146 if (!hTermQ) {
1147 // Create term queue and event semaphore just once
1148 sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid);
1149 rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName);
1150 if (rc) {
1151 hTermQ = (HQUEUE)0; // Try to survive
1152 DosExitCritSec();
1153 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
1154 }
1155 else {
1156 rc = DosCreateEventSem(NULL,(PHEV)&hTermQSem,0,FALSE);
1157 if (rc) {
1158 hTermQSem = (HEV)0; // Try to survive
1159 DosCloseQueue(hTermQ);
1160 hTermQ = (HQUEUE)0; // Try to survive
1161 DosExitCritSec();
1162 Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__, PCSZ_DOSCREATEEVENTSEM);
1163 }
1164 // if (!rc) fprintf(stderr,"%s %d qcreated ptib %x hTermQ %x\n",__FILE__, __LINE__,ptib,hTermQ);
1165 }
1166 } // if 1st time
1167 useTermQ = hTermQ && hTermQSem;
1168 if (!rc)
1169 DosExitCritSec();
1170 } // if wait
1171
1172 memset(&sdata,0,sizeof(sdata));
1173 sdata.Length = sizeof(sdata);
1174 sdata.Related = type & (WAIT | CHILD) ? SSF_RELATED_CHILD :
1175 SSF_RELATED_INDEPENDENT;
1176 sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE;
1177 sdata.TraceOpt = SSF_TRACEOPT_NONE;
1178 sdata.PgmName = pszPgm;
1179 if (*pszArgs)
1180 sdata.PgmInputs = (PBYTE)pszArgs;
1181 if (useTermQ) {
1182 strcpy(szTermTemp, szTermQName);
1183 sdata.TermQ = (PBYTE)szTermTemp;
1184 }
1185 sdata.Environment = (PBYTE)pszEnvironment;
1186 sdata.InheritOpt = SSF_INHERTOPT_PARENT;
1187 sdata.SessionType = ulAppType;
1188 sdata.ObjectBuffer = szObject;
1189 sdata.ObjectBuffLen = sizeof(szObject);
1190 if ((type & RUNTYPE_MASK) == SEPARATEKEEP)
1191 sdata.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
1192 if (type & MAXIMIZED)
1193 sdata.PgmControl |= SSF_CONTROL_MAXIMIZE;
1194 if (type & MINIMIZED)
1195 sdata.PgmControl |= SSF_CONTROL_MINIMIZE;
1196 if (type & INVISIBLE)
1197 sdata.PgmControl |= SSF_CONTROL_INVISIBLE;
1198
1199 if (pszDirectory && *pszDirectory) {
1200 strcpy(szSavedir, pFM2SaveDirectory);
1201 switch_to(pszDirectory);
1202 }
1203 ret = DosStartSession(&sdata, &ulSessID, &sessPID);
1204
1205
1206 if (pszDirectory && *pszDirectory)
1207 switch_to(szSavedir);
1208
1209 if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
1210 if (!fNoErrorMsg)
1211 Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
1212 GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs,
1213 pszCallingFile, uiLineNumber); // 26 May 08 SHL
1214 }
1215 else if (type & WAIT) {
1216 if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
1217 ShowSession(hwnd, sessPID);
1218
1219 if (!useTermQ) {
1220 STATUSDATA sd;
1221
1222 memset(&sd, 0, sizeof(sd));
1223 sd.Length = (USHORT) sizeof(sd);
1224 sd.SelectInd = SET_SESSION_UNCHANGED;
1225 sd.BondInd = SET_SESSION_UNCHANGED;
1226 for (ctr = 0;; ctr++)
1227 {
1228 DosSleep(50);//05 Aug 07 GKY 200
1229 if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished)
1230 break;
1231 if (ctr > 10) {
1232 ShowSession(hwnd, sessPID); // Show every 2 seconds
1233 ctr = 0;
1234 }
1235 }
1236 }
1237 else {
1238 for (ctr = 0;; ctr++)
1239 {
1240 if (ctr < 20) {
1241 rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
1242 DCWW_NOWAIT, &bPriority, hTermQSem);
1243 if (rc == ERROR_QUE_EMPTY) {
1244 DosSleep(50);//05 Aug 07 GKY 100
1245 continue;
1246 }
1247 }
1248 else {
1249 if (ctr == 20) {
1250 ShowSession(hwnd, sessPID); // Show long running session
1251 }
1252 rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
1253 DCWW_WAIT, &bPriority, 0);
1254 }
1255
1256 if (rc) {
1257 // Oh heck
1258 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
1259 DosSleep(100);//05 Aug 07 GKY 500
1260 continue;
1261 }
1262
1263 // printf("%s %d DosReadQueue thread 0x%x sess %u sessRC %u rq.pid 0x%x rq.data 0x%x\n",
1264 // __FILE__, __LINE__,ptib->tib_ordinal,pTermInfo->usSessID,pTermInfo->usRC,rq.pid, rq.ulData); fflush(stdout);
1265
1266 if (pTermInfo->usSessID == ulSessID)
1267 break; // Our session is done
1268
1269 // Requeue session for other thread
1270 {
1271 static ULONG ulLastSessID;
1272 // printf("%s %d requeue thread 0x%x our sess %u term sess %u term rc %u\n",
1273 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,pTermInfo->usSessID,pTermInfo->usRC); fflush(stdout);
1274 // fixme to be gone when no longer needed for debug?
1275 if (ulLastSessID) {
1276 DosSleep(100);//05 Aug 07 GKY 500
1277 ulLastSessID = pTermInfo->usSessID;
1278 }
1279 // requeue term report for other thread and do not free yet
1280 rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority);
1281 if (rc)
1282 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue");
1283 DosSleep(50); //05 Aug 07 GKY 100 // Let other thread see queue entry
1284 }
1285 } // for
1286
1287 ret = pTermInfo->usRC == 0; // Set 1 if rc 0 else 0
1288 // printf("%s %d thread 0x%x term for sess %u\n",
1289 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID);fflush(stdout);
1290 DosFreeMem(pTermInfo);
1291 }
1292 } // if wait
1293 else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
1294 ShowSession(hwnd, sessPID);
1295 }
1296 }
1297
1298ObjectInterrupt:
1299
1300 if (pszPgm)
1301 DosFreeMem(pszPgm);
1302 if (pszArgs)
1303 DosFreeMem(pszArgs);
1304
1305 return ret;
1306}
1307
1308//== Exec() Start application with WinStartApp ==
1309#if 0 // JBS 11 Sep 08
1310HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
1311 PROGTYPE *progt, ULONG fl, char *formatstring,...)
1312{
1313 PROGDETAILS pgd;
1314 register char *p;
1315 char *parameters = NULL, *executable = NULL;
1316 HAPP happ = (HAPP)0;
1317 ULONG ulOptions = SAF_INSTALLEDCMDLINE;
1318 BOOL wasquote;
1319 va_list parguments;
1320
1321 if (child)
1322 ulOptions |= SAF_STARTCHILDAPP;
1323
1324 executable = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1325 if (executable) {
1326 va_start(parguments, formatstring);
1327 vsprintf(executable, formatstring, parguments);
1328 va_end(parguments);
1329 strip_lead_char(" \t", executable);
1330 if (*executable) {
1331 parameters = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
1332 if (parameters) {
1333 p = executable;
1334 wasquote = FALSE;
1335 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
1336 if (*p == '\"') {
1337 if (!wasquote) {
1338 wasquote = TRUE;
1339 memmove(p, p + 1, strlen(p));
1340 while (*p == ' ' || *p == '\t')
1341 p++;
1342 }
1343 else {
1344 memmove(p, p + 1, strlen(p));
1345 break;
1346 }
1347 }
1348 else
1349 p++;
1350 }
1351 if (*p) {
1352 *p = 0;
1353 p++;
1354 }
1355 else
1356 p = NullStr;
1357 if (*p)
1358 strcpy(parameters, p);
1359
1360 if (p && (!stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTCMD) ||
1361 !stricmp(p, PCSZ_DOTBTM))) {
1362 char *temp;
1363
1364 temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
1365 if (temp) {
1366 if (!stricmp(p, PCSZ_DOTBAT)) {
1367 if (!fProtectOnly) {
1368 strcpy(temp, executable);
1369 strcpy(executable, parameters);
1370 strcpy(parameters, "/C ");
1371 strcat(parameters, temp);
1372 strcat(parameters, " ");
1373 strcat(parameters, executable);
1374 strcpy(executable, GetCmdSpec(TRUE)); //DOS
1375 }
1376 else
1377 saymsg(MB_OK,
1378 HWND_DESKTOP,
1379 NullStr,
1380 GetPString(IDS_NOTPROTECTONLYEXE),
1381 filename);
1382 }
1383 else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
1384 strcpy(temp, executable);
1385 strcpy(executable, parameters);
1386 strcpy(parameters, "/C ");
1387 strcat(parameters, temp);
1388 strcat(parameters, " ");
1389 strcat(parameters, executable);
1390 strcpy(executable, GetCmdSpec(FALSE));
1391 }
1392 free(temp);
1393 }
1394 }
1395
1396 memset(&pgd, 0, sizeof(pgd));
1397 pgd.Length = sizeof(pgd);
1398 pgd.progt = *progt;
1399 pgd.swpInitial.fl = fl;
1400 pgd.pszEnvironment = env;
1401 pgd.pszStartupDir = startdir;
1402 pgd.pszParameters = *parameters ? parameters : NULL;
1403 pgd.pszExecutable = executable;
1404 pgd.swpInitial.hwndInsertBehind = HWND_TOP;
1405 happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions);
1406 free(parameters);
1407 }
1408 }
1409 free(executable);
1410 }
1411 return happ;
1412}
1413#endif
1414#pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
Note: See TracBrowser for help on using the repository browser.