source: trunk/dll/systemf.c@ 396

Last change on this file since 396 was 396, checked in by root, 19 years ago

Clean

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