source: trunk/dll/systemf.c@ 1628

Last change on this file since 1628 was 1628, checked in by Gregg Young, 14 years ago

Hard coded the flags for the xDosAlloc* wrappers and added a description for each of them.

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