source: trunk/dll/systemf.c@ 1047

Last change on this file since 1047 was 1047, checked in by Gregg Young, 17 years ago

Minor code cleanup

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