source: trunk/dll/systemf.c@ 78

Last change on this file since 78 was 78, checked in by root, 22 years ago

Comments

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