source: trunk/dll/systemf.c@ 1193

Last change on this file since 1193 was 1193, checked in by John Small, 17 years ago

Improved comment on new "#if 0" lines.

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