source: trunk/dll/systemf.c@ 2

Last change on this file since 2 was 2, checked in by root, 23 years ago

Initial revision

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