source: trunk/dll/systemf.c@ 1533

Last change on this file since 1533 was 1533, checked in by Gregg Young, 15 years ago

Fixed possible loss of precision compiler warnings by casting the variables in question.

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