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
|
---|
9 | Copyright (c) 2003, 2006 Steven H.Levine
|
---|
10 |
|
---|
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
|
---|
15 | 26 Jul 06 SHL Use convert_nl_to_nul
|
---|
16 |
|
---|
17 | ***********************************************************************/
|
---|
18 |
|
---|
19 | #define INCL_WIN
|
---|
20 | #define INCL_WINERRORS
|
---|
21 | #define INCL_DOS
|
---|
22 | #define INCL_DOSERRORS
|
---|
23 | #include <os2.h>
|
---|
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>
|
---|
31 |
|
---|
32 | #include "fm3dll.h"
|
---|
33 | #include "fm3dlg.h"
|
---|
34 | #include "fm3str.h"
|
---|
35 |
|
---|
36 | static PSZ pszSrcFile = __FILE__;
|
---|
37 |
|
---|
38 | #pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
|
---|
39 |
|
---|
40 | #define MAXSTRG (4096) /* used to build command line strings */
|
---|
41 |
|
---|
42 | /* quick and dirty program launcher for OS/2 2.x */
|
---|
43 |
|
---|
44 | BOOL ShowSession(HWND hwnd, PID pid)
|
---|
45 | {
|
---|
46 | HSWITCH hswitch;
|
---|
47 | SWCNTRL swctl;
|
---|
48 | ULONG rc;
|
---|
49 |
|
---|
50 | hswitch = WinQuerySwitchHandle((pid) ? (HWND)0 : hwnd, pid);
|
---|
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;
|
---|
60 | // else saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Failed: %lu/%lx",rc,rc);
|
---|
61 |
|
---|
62 | }
|
---|
63 | }
|
---|
64 | return FALSE;
|
---|
65 | }
|
---|
66 |
|
---|
67 | int ExecOnList(HWND hwnd, char *command, int flags, char *tpath,
|
---|
68 | char **list, char *prompt)
|
---|
69 | {
|
---|
70 | /* executes the command once for all files in list */
|
---|
71 |
|
---|
72 | char path[CCHMAXPATH], commandline[2048], modpath[CCHMAXPATH], listfile[CCHMAXPATH],
|
---|
73 | *p, *pp, drive, *file, *ext, *dot;
|
---|
74 | register int x;
|
---|
75 | BOOL spaces;
|
---|
76 |
|
---|
77 | if (!command || !*command)
|
---|
78 | return -1;
|
---|
79 | *listfile = 0;
|
---|
80 | bstrip(command);
|
---|
81 |
|
---|
82 | *path = 0;
|
---|
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, '\"');
|
---|
90 | else
|
---|
91 | p = strchr(path, ' ');
|
---|
92 | if (p)
|
---|
93 | *p = 0;
|
---|
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++;
|
---|
104 | }
|
---|
105 | *p = 0;
|
---|
106 | }
|
---|
107 | else
|
---|
108 | *path = 0;
|
---|
109 | }
|
---|
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++;
|
---|
124 | }
|
---|
125 | *p = 0;
|
---|
126 | }
|
---|
127 | else
|
---|
128 | *path = 0;
|
---|
129 | }
|
---|
130 | *modpath = 0;
|
---|
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 | {
|
---|
140 | p++;
|
---|
141 | *p = '\\';
|
---|
142 | p++;
|
---|
143 | }
|
---|
144 | *p = 0;
|
---|
145 | }
|
---|
146 | else
|
---|
147 | *modpath = 0;
|
---|
148 | if (!*modpath)
|
---|
149 | strcpy(modpath, path);
|
---|
150 | if (*path)
|
---|
151 | MakeFullName(path);
|
---|
152 | if (*modpath)
|
---|
153 | MakeFullName(modpath);
|
---|
154 | if (IsFullName(path))
|
---|
155 | drive = toupper(*path);
|
---|
156 | else
|
---|
157 | drive = 0;
|
---|
158 |
|
---|
159 | p = command; // substitue for special % sequences
|
---|
160 |
|
---|
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 | {
|
---|
174 |
|
---|
175 | FILE *fp;
|
---|
176 |
|
---|
177 | save_dir2(listfile);
|
---|
178 | if (listfile[strlen(listfile) - 1] != '\\')
|
---|
179 | strcat(listfile, "\\");
|
---|
180 | sprintf(&listfile[strlen(listfile)], "%s%03x",
|
---|
181 | LISTTEMPROOT, (clock() & 4095L));
|
---|
182 | fp = xfopen(listfile, "w",pszSrcFile,__LINE__);
|
---|
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;
|
---|
199 |
|
---|
200 | case 'c': /* add name of command processor */
|
---|
201 | {
|
---|
202 | char *env = GetCmdSpec(FALSE);
|
---|
203 |
|
---|
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;
|
---|
222 |
|
---|
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;
|
---|
241 |
|
---|
242 | case '$': /* add drive letter */
|
---|
243 | if (drive)
|
---|
244 | *pp = drive;
|
---|
245 | else
|
---|
246 | {
|
---|
247 |
|
---|
248 | ULONG ulDriveNum = 3L, ulDriveMap;
|
---|
249 |
|
---|
250 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
251 | *pp = (char) (ulDriveNum + '@');
|
---|
252 | }
|
---|
253 | pp++;
|
---|
254 | p += 2;
|
---|
255 | break;
|
---|
256 |
|
---|
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 | {
|
---|
292 |
|
---|
293 | char temp[CCHMAXPATH];
|
---|
294 |
|
---|
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;
|
---|
319 |
|
---|
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 | {
|
---|
355 |
|
---|
356 | char temp[CCHMAXPATH];
|
---|
357 |
|
---|
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;
|
---|
382 |
|
---|
383 | case 'D':
|
---|
384 | if (hwndMain)
|
---|
385 | {
|
---|
386 |
|
---|
387 | PCNRITEM pci;
|
---|
388 |
|
---|
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;
|
---|
416 |
|
---|
417 | case 'd':
|
---|
418 | if (hwndMain)
|
---|
419 | {
|
---|
420 |
|
---|
421 | HENUM henum;
|
---|
422 | char retstr[CCHMAXPATH];
|
---|
423 | HWND hwndC, hwndDir;
|
---|
424 | USHORT id;
|
---|
425 | BOOL first = TRUE;
|
---|
426 |
|
---|
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;
|
---|
476 |
|
---|
477 | case '%':
|
---|
478 | *pp = '%';
|
---|
479 | pp++;
|
---|
480 | p += 2;
|
---|
481 | break;
|
---|
482 |
|
---|
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;
|
---|
522 |
|
---|
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;
|
---|
550 |
|
---|
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;
|
---|
584 |
|
---|
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++;
|
---|
595 | }
|
---|
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 | }
|
---|
607 | }
|
---|
608 | }
|
---|
609 | break;
|
---|
610 | }
|
---|
611 | if (list[x + 1])
|
---|
612 | {
|
---|
613 | *pp = ' ';
|
---|
614 | pp++;
|
---|
615 | }
|
---|
616 | }
|
---|
617 | }
|
---|
618 | p += 2;
|
---|
619 | break;
|
---|
620 |
|
---|
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 |
|
---|
637 | BreakOut:
|
---|
638 |
|
---|
639 | {
|
---|
640 |
|
---|
641 | EXECARGS ex;
|
---|
642 | ULONG size;
|
---|
643 | int ret;
|
---|
644 |
|
---|
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 | }
|
---|
667 | }
|
---|
668 |
|
---|
669 | int runemf2(int type, HWND hwnd, char *directory, char *environment,
|
---|
670 | char *formatstring,...)
|
---|
671 | {
|
---|
672 | /* example:
|
---|
673 |
|
---|
674 | * status = runemf2(SEPARATE | WINDOWED,
|
---|
675 | * hwnd,
|
---|
676 | * NullStr,
|
---|
677 | * NULL,
|
---|
678 | * "%s /C %s",
|
---|
679 | * getenv("COMSPEC"),
|
---|
680 | * batchfilename);
|
---|
681 | *
|
---|
682 | * use (HWND)0 for hwnd if window handle not handy.
|
---|
683 | */
|
---|
684 |
|
---|
685 | /*
|
---|
686 | * type bitmapped flag -- see FM3DLL.H
|
---|
687 | */
|
---|
688 |
|
---|
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;
|
---|
703 |
|
---|
704 | if (directory &&
|
---|
705 | *directory)
|
---|
706 | {
|
---|
707 | if (!DosQueryPathInfo(directory,
|
---|
708 | FIL_QUERYFULLNAME,
|
---|
709 | tempdir,
|
---|
710 | sizeof(tempdir)))
|
---|
711 | directory = tempdir;
|
---|
712 | }
|
---|
713 |
|
---|
714 | if (!hwnd)
|
---|
715 | hwnd = HWND_DESKTOP;
|
---|
716 |
|
---|
717 | rc = DosAllocMem((PVOID)&s,
|
---|
718 | MAXSTRG,
|
---|
719 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
720 | if (rc) {
|
---|
721 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
722 | return -1;
|
---|
723 | }
|
---|
724 |
|
---|
725 | *savedir = 0;
|
---|
726 |
|
---|
727 | *s = 0;
|
---|
728 | va_start(parguments,
|
---|
729 | formatstring);
|
---|
730 | vsprintf(s,
|
---|
731 | formatstring,
|
---|
732 | parguments);
|
---|
733 | va_end(parguments);
|
---|
734 |
|
---|
735 | if (environment)
|
---|
736 | {
|
---|
737 | p = &environment[strlen(environment)] + 1;
|
---|
738 | *p = 0;
|
---|
739 | p = environment;
|
---|
740 | while ((p = convert_nl_to_nul(p)) != NULL)
|
---|
741 | ; // loop
|
---|
742 | }
|
---|
743 |
|
---|
744 | if (!*s)
|
---|
745 | {
|
---|
746 | p = GetCmdSpec(FALSE);
|
---|
747 | strcpy(s, p);
|
---|
748 | if (!*s)
|
---|
749 | return -1;
|
---|
750 | }
|
---|
751 |
|
---|
752 | if (*s)
|
---|
753 | {
|
---|
754 | if (*s == '<' &&
|
---|
755 | strchr(s, '>'))
|
---|
756 | { /* is a workplace object */
|
---|
757 |
|
---|
758 | HOBJECT hWPSObject;
|
---|
759 | char temp;
|
---|
760 |
|
---|
761 | p = strchr(s, '>');
|
---|
762 | p++;
|
---|
763 | temp = *p;
|
---|
764 | if (temp) {
|
---|
765 | rc = DosAllocMem((PVOID)&s2,
|
---|
766 | MAXSTRG * 2,
|
---|
767 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
768 | if (rc)
|
---|
769 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
770 | }
|
---|
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 | }
|
---|
794 |
|
---|
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 | }
|
---|
848 | ret = (int) DosQAppType(s,&apptype);
|
---|
849 | if (!strchr(s, '\\') &&
|
---|
850 | !strchr(s, ':') &&
|
---|
851 | directory &&
|
---|
852 | *directory)
|
---|
853 | switch_to(savedir);
|
---|
854 | if (ret)
|
---|
855 | {
|
---|
856 | Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,"DosQAppType");
|
---|
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 | {
|
---|
868 | Runtime_Error(pszSrcFile, __LINE__, "unexpected apptype");
|
---|
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 | {
|
---|
878 | Runtime_Error(pszSrcFile, __LINE__, "unexpected apptype");
|
---|
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);
|
---|
898 | if (ret) {
|
---|
899 | Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
|
---|
900 | GetPString(IDS_DOSEXECPGMFAILEDTEXT));
|
---|
901 | }
|
---|
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 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
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);
|
---|
950 |
|
---|
951 | p = strrchr(s, '.');
|
---|
952 | if (p)
|
---|
953 | {
|
---|
954 |
|
---|
955 | char temp[CCHMAXPATH + 1];
|
---|
956 |
|
---|
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 | }
|
---|
978 |
|
---|
979 | /* goddamned OS/2 limit */
|
---|
980 |
|
---|
981 | if (strlen(s) + strlen(s2) > 1024)
|
---|
982 | s2[1024 - strlen(s)] = 0;
|
---|
983 |
|
---|
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 | }
|
---|
1007 |
|
---|
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 | }
|
---|
1104 |
|
---|
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);
|
---|
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 | }
|
---|
1148 | else if (type & WAIT)
|
---|
1149 | {
|
---|
1150 | if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
1151 | ShowSession(hwnd, sessPID);
|
---|
1152 |
|
---|
1153 | if (!hque)
|
---|
1154 | {
|
---|
1155 | STATUSDATA sd;
|
---|
1156 |
|
---|
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 | }
|
---|
1210 |
|
---|
1211 | ObjectInterrupt:
|
---|
1212 |
|
---|
1213 | if (s)
|
---|
1214 | DosFreeMem(s);
|
---|
1215 | if (s2)
|
---|
1216 | DosFreeMem(s2);
|
---|
1217 | return ret;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
1221 | PROGTYPE * progt, ULONG fl, char *formatstring,...)
|
---|
1222 | {
|
---|
1223 | PROGDETAILS pgd;
|
---|
1224 | register char *p;
|
---|
1225 | char *parameters = NULL, *executable = NULL;
|
---|
1226 | HAPP happ = (HAPP) 0;
|
---|
1227 | ULONG ulOptions = SAF_INSTALLEDCMDLINE;
|
---|
1228 | BOOL wasquote;
|
---|
1229 | va_list parguments;
|
---|
1230 |
|
---|
1231 | if (child)
|
---|
1232 | ulOptions |= SAF_STARTCHILDAPP;
|
---|
1233 |
|
---|
1234 | executable = xmallocz(MAXSTRG,pszSrcFile,__LINE__);
|
---|
1235 | if (executable) {
|
---|
1236 | va_start(parguments, formatstring);
|
---|
1237 | vsprintf(executable, formatstring, parguments);
|
---|
1238 | va_end(parguments);
|
---|
1239 | strip_lead_char(" \t", executable);
|
---|
1240 | if (*executable)
|
---|
1241 | {
|
---|
1242 | parameters = xmalloc(MAXSTRG,pszSrcFile,__LINE__);
|
---|
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);
|
---|
1276 |
|
---|
1277 | if (p && (!stricmp(p, ".BAT") || !stricmp(p, ".CMD")))
|
---|
1278 | {
|
---|
1279 |
|
---|
1280 | char *temp;
|
---|
1281 |
|
---|
1282 | temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
|
---|
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 | }
|
---|
1308 |
|
---|
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);
|
---|
1320 | }
|
---|
1321 | }
|
---|
1322 | free(executable);
|
---|
1323 | }
|
---|
1324 | return happ;
|
---|
1325 | }
|
---|