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