1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: systemf.c 1673 2012-12-30 18:51:01Z gyoung $
|
---|
5 |
|
---|
6 | System Interfaces
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2003, 2010 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 | 15 Aug 06 SHL More error popups
|
---|
17 | 01 Nov 06 SHL runemf2: temp fix for hung windows caused by termq errors
|
---|
18 | 03 Nov 06 SHL runemf2: rework termination queue logic to work for multiple threads
|
---|
19 | 07 Jan 07 GKY Move error strings etc. to string file
|
---|
20 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
---|
21 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
22 | 29 Feb 08 GKY Changes to enable user settable command line length
|
---|
23 | 29 Feb 08 GKY Refactor global command line variables to notebook.h
|
---|
24 | 26 May 08 SHL Use uiLineNumber correctly
|
---|
25 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory or pTmpDir and use MakeTempName
|
---|
26 | 03 Jan 09 GKY Check for system that is protectonly to gray out Dos/Win command lines and prevent
|
---|
27 | Dos/Win programs from being inserted into the execute dialog with message why.
|
---|
28 | 12 Jul 09 GKY Allow FM/2 to load in high memory
|
---|
29 | 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
|
---|
30 | 27 Dec 09 GKY Provide human readable error message when DosQueryAppType fails because it
|
---|
31 | couldn't find the exe (such as missing archivers).
|
---|
32 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
|
---|
33 | 17 JAN 10 GKY Changes to environment handling in ExecuteOnList to facilitate move of commands to INI and allow
|
---|
34 | the same commandline to have different environments (multiple different command titles).
|
---|
35 | 17 JAN 10 GKY Add ENVIRONMENT_SIZE vaiable to replace multiple (often different hard coded sizes) set to 2048
|
---|
36 | (the largest value I found).
|
---|
37 | 20 Nov 10 GKY Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused
|
---|
38 | by temp file creation failures.
|
---|
39 | 26 Aug 11 GKY Add a low mem version of xDosAlloc* wrappers; move error checking into all the
|
---|
40 | xDosAlloc* wrappers.
|
---|
41 |
|
---|
42 | ***********************************************************************/
|
---|
43 |
|
---|
44 | #include <stdlib.h>
|
---|
45 | #include <stdarg.h>
|
---|
46 | #include <string.h>
|
---|
47 | #include <ctype.h>
|
---|
48 |
|
---|
49 | #define INCL_DOS
|
---|
50 | #define INCL_DOSERRORS
|
---|
51 | #define INCL_WIN
|
---|
52 | #define INCL_LONGLONG // dircnrs.h
|
---|
53 |
|
---|
54 | #include "fm3dll.h"
|
---|
55 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
56 | #include "mkdir.h" // Data declaration(s)
|
---|
57 | #include "init.h" // Data declaration(s)
|
---|
58 | #include "mainwnd.h" // Data declaration(s)
|
---|
59 | #include "fm3dlg.h"
|
---|
60 | #include "fm3str.h"
|
---|
61 | #include "errutil.h" // Dos_Error...
|
---|
62 | #include "strutil.h" // GetPString
|
---|
63 | #include "notebook.h" //targetdirectory
|
---|
64 | #include "pathutil.h"
|
---|
65 | #include "cmdline.h" // CmdLineDlgProc
|
---|
66 | #include "shadow.h" // RunSeamless
|
---|
67 | #include "systemf.h"
|
---|
68 | #include "strips.h" // convert_nl_to_nul, strip_lead_char
|
---|
69 | #include "dirs.h" // switch_to
|
---|
70 | #include "valid.h" // MakeFullName
|
---|
71 | #include "misc.h" // GetCmdSpec
|
---|
72 | #include "copyf.h" // MakeTempName
|
---|
73 | #include "wrappers.h" // xfopen
|
---|
74 | #include "fortify.h"
|
---|
75 |
|
---|
76 | static PSZ pszSrcFile = __FILE__;
|
---|
77 |
|
---|
78 |
|
---|
79 | //static HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
80 | // PROGTYPE * progt, ULONG fl, char *formatstring, ...);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * CheckExecutibleFlags checks the dialog controls and returns the appropriate
|
---|
84 | * flags to be passed the runemf
|
---|
85 | */
|
---|
86 |
|
---|
87 | ULONG CheckExecutibleFlags(HWND hwnd, INT caller)
|
---|
88 | {
|
---|
89 | /**
|
---|
90 | * caller indicates the dialog calling the function:
|
---|
91 | * 1 = Associations (ASS_)
|
---|
92 | * 2 = CmdLine (EXEC_)
|
---|
93 | * 3 = Commands (CMD_)
|
---|
94 | **/
|
---|
95 |
|
---|
96 | ULONG flags = 0;
|
---|
97 |
|
---|
98 | if (caller != 2 &&
|
---|
99 | WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_DEFAULT : ASS_DEFAULT))
|
---|
100 | flags = 0;
|
---|
101 | else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_FULLSCREEN :
|
---|
102 | caller == 1 ? ASS_FULLSCREEN : EXEC_FULLSCREEN))
|
---|
103 | flags = FULLSCREEN;
|
---|
104 | else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_MINIMIZED :
|
---|
105 | caller == 1 ? ASS_MINIMIZED : EXEC_MINIMIZED))
|
---|
106 | flags = MINIMIZED;
|
---|
107 | else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_MAXIMIZED :
|
---|
108 | caller == 1 ? ASS_MAXIMIZED : EXEC_MAXIMIZED))
|
---|
109 | flags = MAXIMIZED;
|
---|
110 | else if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_INVISIBLE :
|
---|
111 | caller == 1 ? ASS_INVISIBLE : EXEC_INVISIBLE))
|
---|
112 | flags = INVISIBLE;
|
---|
113 | if (WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_KEEP : caller == 1 ? ASS_KEEP :
|
---|
114 | EXEC_KEEP))
|
---|
115 | flags |= caller == 2 ? SEPARATEKEEP : KEEP;
|
---|
116 | else if (caller == 2)
|
---|
117 | flags |= SEPARATE;
|
---|
118 | if (caller !=2 && WinQueryButtonCheckstate(hwnd, caller == 3 ? CMD_PROMPT : ASS_PROMPT))
|
---|
119 | flags |= PROMPT;
|
---|
120 | if (caller == 3 && WinQueryButtonCheckstate(hwnd, CMD_ONCE))
|
---|
121 | flags |= ONCE;
|
---|
122 | if (caller == 1 && WinQueryButtonCheckstate(hwnd, ASS_DIEAFTER))
|
---|
123 | flags |= DIEAFTER;
|
---|
124 | return flags;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Bring session foreground
|
---|
129 | * @return TRUE if OK, else FALSE
|
---|
130 | */
|
---|
131 |
|
---|
132 | BOOL ShowSession(HWND hwnd, PID pid)
|
---|
133 | {
|
---|
134 | HSWITCH hswitch;
|
---|
135 | SWCNTRL swctl;
|
---|
136 | ULONG rc;
|
---|
137 |
|
---|
138 | hswitch = WinQuerySwitchHandle(pid ? (HWND)0 : hwnd, pid);
|
---|
139 | if (hswitch) {
|
---|
140 | rc = WinQuerySwitchEntry(hswitch, &swctl);
|
---|
141 | if (!rc) {
|
---|
142 | if (swctl.idProcess == pid && swctl.uchVisibility == SWL_VISIBLE)
|
---|
143 | rc = WinSwitchToProgram(hswitch);
|
---|
144 | if (!rc)
|
---|
145 | return TRUE;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | return FALSE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Invoke runemf2 for command and file/directory list
|
---|
153 | * @return command return code or
|
---|
154 | * -1 if runtime error or
|
---|
155 | * -2 if user cancels command line edit dialog
|
---|
156 | */
|
---|
157 |
|
---|
158 | int ExecOnList(HWND hwnd, PSZ command, int flags, PSZ tpath, PSZ environment,
|
---|
159 | PSZ *list, PCSZ prompt, PCSZ pszCallingFile, UINT uiLineNumber)
|
---|
160 | {
|
---|
161 | // executes the command once for all files in list
|
---|
162 |
|
---|
163 | CHAR path[CCHMAXPATH], *commandline, modpath[CCHMAXPATH], listfile[CCHMAXPATH],
|
---|
164 | *p, *pp, drive, *file, *ext, *dot;
|
---|
165 | register int x;
|
---|
166 | BOOL spaces;
|
---|
167 |
|
---|
168 | if (!command || !*command) {
|
---|
169 | Runtime_Error(pszSrcFile, __LINE__, NULL);
|
---|
170 | return -1;
|
---|
171 | }
|
---|
172 | commandline = xmalloc(MaxComLineStrg + 1, pszSrcFile, __LINE__);
|
---|
173 | if (!commandline)
|
---|
174 | return -1; //already complained
|
---|
175 | *listfile = 0;
|
---|
176 | bstrip(command);
|
---|
177 |
|
---|
178 | *path = 0;
|
---|
179 | if (tpath && *tpath)
|
---|
180 | strcpy(path, tpath);
|
---|
181 | else if (*command != '<' || !strchr(command, '>')) {
|
---|
182 | strcpy(path, command + (*command == '"'));
|
---|
183 | if (*command == '\"')
|
---|
184 | p = strchr(path, '\"');
|
---|
185 | else
|
---|
186 | p = strchr(path, ' ');
|
---|
187 | if (p)
|
---|
188 | *p = 0;
|
---|
189 | p = strrchr(path, '\\');
|
---|
190 | if (!p)
|
---|
191 | p = strrchr(path, ':');
|
---|
192 | if (p) {
|
---|
193 | if (*p == ':') {
|
---|
194 | p++;
|
---|
195 | *p = '\\';
|
---|
196 | p++;
|
---|
197 | }
|
---|
198 | *p = 0;
|
---|
199 | }
|
---|
200 | else
|
---|
201 | *path = 0;
|
---|
202 | }
|
---|
203 | if (!*path) {
|
---|
204 | if (list && list[0])
|
---|
205 | strcpy(path, list[0]);
|
---|
206 | p = strrchr(path, '\\');
|
---|
207 | if (!p)
|
---|
208 | p = strrchr(path, ':');
|
---|
209 | if (p) {
|
---|
210 | if (*p == ':') {
|
---|
211 | p++;
|
---|
212 | *p = '\\';
|
---|
213 | p++;
|
---|
214 | }
|
---|
215 | *p = 0;
|
---|
216 | }
|
---|
217 | else
|
---|
218 | *path = 0;
|
---|
219 | }
|
---|
220 | *modpath = 0;
|
---|
221 | if (list && list[0])
|
---|
222 | strcpy(modpath, list[0]);
|
---|
223 | p = strrchr(modpath, '\\');
|
---|
224 | if (!p)
|
---|
225 | p = strrchr(modpath, ':');
|
---|
226 | if (p) {
|
---|
227 | if (*p == ':') {
|
---|
228 | p++;
|
---|
229 | *p = '\\';
|
---|
230 | p++;
|
---|
231 | }
|
---|
232 | *p = 0;
|
---|
233 | }
|
---|
234 | else
|
---|
235 | *modpath = 0;
|
---|
236 | if (!*modpath)
|
---|
237 | strcpy(modpath, path);
|
---|
238 | if (*path)
|
---|
239 | MakeFullName(path);
|
---|
240 | if (*modpath)
|
---|
241 | MakeFullName(modpath);
|
---|
242 | if (IsFullName(path))
|
---|
243 | drive = toupper(*path);
|
---|
244 | else
|
---|
245 | drive = 0;
|
---|
246 |
|
---|
247 | p = command; // substitue for special % sequences
|
---|
248 |
|
---|
249 | pp = commandline;
|
---|
250 | *commandline = 0;
|
---|
251 | while (*p) {
|
---|
252 | if (*p == '%') {
|
---|
253 | switch (*(p + 1)) {
|
---|
254 | case '!': // write list to file, add filename
|
---|
255 | if (list) {
|
---|
256 | if (!*listfile) {
|
---|
257 | FILE *fp;
|
---|
258 | CHAR *modew = "w";
|
---|
259 |
|
---|
260 | if (pTmpDir && !IsValidDir(pTmpDir))
|
---|
261 | DosCreateDir(pTmpDir, 0);
|
---|
262 | strcpy(listfile, pTmpDir ? pTmpDir : pFM2SaveDirectory);
|
---|
263 | MakeTempName(listfile, "$FM2LI$T", 2);
|
---|
264 | fp = xfopen(listfile, modew,pszSrcFile,__LINE__, FALSE);
|
---|
265 | if (fp) {
|
---|
266 | for (x = 0; list[x]; x++)
|
---|
267 | {
|
---|
268 | fputs(list[x], fp);
|
---|
269 | if (list[x + 1])
|
---|
270 | fputc('\n', fp);
|
---|
271 | }
|
---|
272 | fclose(fp);
|
---|
273 | }
|
---|
274 | }
|
---|
275 | strcpy(pp, listfile);
|
---|
276 | pp += strlen(listfile);
|
---|
277 | }
|
---|
278 | p += 2;
|
---|
279 | break;
|
---|
280 |
|
---|
281 | case 'c': // add name of command processor
|
---|
282 | {
|
---|
283 | char *env = GetCmdSpec(FALSE);
|
---|
284 |
|
---|
285 | if (needs_quoting(env) && !strchr(env, '\"')) {
|
---|
286 | *pp = '\"';
|
---|
287 | pp++;
|
---|
288 | spaces = TRUE;
|
---|
289 | }
|
---|
290 | else
|
---|
291 | spaces = FALSE;
|
---|
292 | strcpy(pp, env);
|
---|
293 | p += 2;
|
---|
294 | pp += strlen(env);
|
---|
295 | if (spaces) {
|
---|
296 | *pp = '\"';
|
---|
297 | pp++;
|
---|
298 | }
|
---|
299 | }
|
---|
300 | break;
|
---|
301 |
|
---|
302 | case 't': // add Target directory
|
---|
303 | if (needs_quoting(targetdir) && !strchr(targetdir, '\"')) {
|
---|
304 | *pp = '\"';
|
---|
305 | pp++;
|
---|
306 | spaces = TRUE;
|
---|
307 | }
|
---|
308 | else
|
---|
309 | spaces = FALSE;
|
---|
310 | strcpy(pp, targetdir);
|
---|
311 | p += 2;
|
---|
312 | pp += strlen(targetdir);
|
---|
313 | if (spaces) {
|
---|
314 | *pp = '\"';
|
---|
315 | pp++;
|
---|
316 | }
|
---|
317 | break;
|
---|
318 |
|
---|
319 | case '$': // add drive letter
|
---|
320 | if (drive)
|
---|
321 | *pp = drive;
|
---|
322 | else {
|
---|
323 | ULONG ulDriveNum = 3, ulDriveMap;
|
---|
324 |
|
---|
325 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
326 | *pp = (char) (ulDriveNum + '@');
|
---|
327 | }
|
---|
328 | pp++;
|
---|
329 | p += 2;
|
---|
330 | break;
|
---|
331 |
|
---|
332 | case 'U': // add path of first list component
|
---|
333 | case 'u':
|
---|
334 | if (*modpath) {
|
---|
335 | if (needs_quoting(modpath) && !strchr(modpath, '\"')) {
|
---|
336 | spaces = TRUE;
|
---|
337 | *pp = '\"';
|
---|
338 | pp++;
|
---|
339 | }
|
---|
340 | else
|
---|
341 | spaces = FALSE;
|
---|
342 | if (*(p + 1) == 'u') {
|
---|
343 | strcpy(pp, modpath);
|
---|
344 | pp += strlen(modpath);
|
---|
345 | }
|
---|
346 | else {
|
---|
347 | strcpy(pp, modpath + 2);
|
---|
348 | pp += strlen(modpath + 2);
|
---|
349 | }
|
---|
350 | if (spaces) {
|
---|
351 | if (modpath[strlen(modpath) - 1] == '\\') {
|
---|
352 | *pp = '\\';
|
---|
353 | pp++;
|
---|
354 | }
|
---|
355 | *pp = '\"';
|
---|
356 | pp++;
|
---|
357 | }
|
---|
358 | }
|
---|
359 | else {
|
---|
360 | char temp[CCHMAXPATH];
|
---|
361 |
|
---|
362 | strcpy(temp, pFM2SaveDirectory);
|
---|
363 | if (needs_quoting(temp) && !strchr(temp, '\"')) {
|
---|
364 | spaces = TRUE;
|
---|
365 | *pp = '\"';
|
---|
366 | pp++;
|
---|
367 | }
|
---|
368 | else
|
---|
369 | spaces = FALSE;
|
---|
370 | strcpy(pp, temp);
|
---|
371 | pp += strlen(temp);
|
---|
372 | if (spaces) {
|
---|
373 | if (temp[strlen(temp) - 1] == '\\') {
|
---|
374 | *pp = '\\';
|
---|
375 | pp++;
|
---|
376 | }
|
---|
377 | *pp = '\"';
|
---|
378 | pp++;
|
---|
379 | }
|
---|
380 | }
|
---|
381 | p += 2;
|
---|
382 | break;
|
---|
383 |
|
---|
384 | case 'P': // add path of execution
|
---|
385 | case 'p':
|
---|
386 | if (*path) {
|
---|
387 | if (needs_quoting(path) && !strchr(path, '\"')) {
|
---|
388 | spaces = TRUE;
|
---|
389 | *pp = '\"';
|
---|
390 | pp++;
|
---|
391 | }
|
---|
392 | else
|
---|
393 | spaces = FALSE;
|
---|
394 | if (*(p + 1) == 'p') {
|
---|
395 | strcpy(pp, path);
|
---|
396 | pp += strlen(path);
|
---|
397 | }
|
---|
398 | else {
|
---|
399 | strcpy(pp, path + 2);
|
---|
400 | pp += strlen(path + 2);
|
---|
401 | }
|
---|
402 | if (spaces) {
|
---|
403 | if (path[strlen(path) - 1] == '\\') {
|
---|
404 | *pp = '\\';
|
---|
405 | pp++;
|
---|
406 | }
|
---|
407 | *pp = '\"';
|
---|
408 | pp++;
|
---|
409 | }
|
---|
410 | }
|
---|
411 | else {
|
---|
412 | char temp[CCHMAXPATH];
|
---|
413 |
|
---|
414 | strcpy(temp, pFM2SaveDirectory);
|
---|
415 | if (needs_quoting(temp) && !strchr(temp, '\"')) {
|
---|
416 | spaces = TRUE;
|
---|
417 | *pp = '\"';
|
---|
418 | pp++;
|
---|
419 | }
|
---|
420 | else
|
---|
421 | spaces = FALSE;
|
---|
422 | strcpy(pp, temp);
|
---|
423 | pp += strlen(temp);
|
---|
424 | if (spaces) {
|
---|
425 | if (temp[strlen(temp) - 1] == '\\') {
|
---|
426 | *pp = '\\';
|
---|
427 | pp++;
|
---|
428 | }
|
---|
429 | *pp = '\"';
|
---|
430 | pp++;
|
---|
431 | }
|
---|
432 | }
|
---|
433 | p += 2;
|
---|
434 | break;
|
---|
435 |
|
---|
436 | case 'D':
|
---|
437 | if (hwndMain) {
|
---|
438 | PCNRITEM pci;
|
---|
439 |
|
---|
440 | pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID(
|
---|
441 | hwndTree, FID_CLIENT), TREE_CNR),
|
---|
442 | CM_QUERYRECORDEMPHASIS,
|
---|
443 | MPFROMLONG(CMA_FIRST),
|
---|
444 | MPFROMSHORT(CRA_CURSORED));
|
---|
445 | if (pci && (int) pci != -1 && *pci->pszFileName) {
|
---|
446 | if (needs_quoting(pci->pszFileName) &&
|
---|
447 | !strchr(pci->pszFileName, '\"'))
|
---|
448 | {
|
---|
449 | *pp = '\"';
|
---|
450 | pp++;
|
---|
451 | spaces = TRUE;
|
---|
452 | }
|
---|
453 | else
|
---|
454 | spaces = FALSE;
|
---|
455 | strcpy(pp, pci->pszFileName);
|
---|
456 | pp += strlen(pci->pszFileName);
|
---|
457 | if (spaces) {
|
---|
458 | *pp = '\"';
|
---|
459 | pp++;
|
---|
460 | }
|
---|
461 | }
|
---|
462 | }
|
---|
463 | p += 2;
|
---|
464 | break;
|
---|
465 |
|
---|
466 | case 'd':
|
---|
467 | if (hwndMain) {
|
---|
468 | HENUM henum;
|
---|
469 | char retstr[CCHMAXPATH];
|
---|
470 | HWND hwndC, hwndDir;
|
---|
471 | USHORT id;
|
---|
472 | BOOL first = TRUE;
|
---|
473 |
|
---|
474 | henum = WinBeginEnumWindows(hwndMain);
|
---|
475 | while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
|
---|
476 | if (hwndC != hwndTree) {
|
---|
477 | id = WinQueryWindowUShort(hwndC, QWS_ID);
|
---|
478 | if (id) {
|
---|
479 | hwndDir = WinWindowFromID(hwndC, FID_CLIENT);
|
---|
480 | if (hwndDir) {
|
---|
481 | hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
|
---|
482 | if (hwndDir) {
|
---|
483 | *retstr = 0;
|
---|
484 | WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID);
|
---|
485 | if (*retstr) {
|
---|
486 | if (!first) {
|
---|
487 | *pp = ' ';
|
---|
488 | pp++;
|
---|
489 | }
|
---|
490 | first = FALSE;
|
---|
491 | if (needs_quoting(retstr) && !strchr(retstr, '\"')) {
|
---|
492 | *pp = '\"';
|
---|
493 | pp++;
|
---|
494 | spaces = TRUE;
|
---|
495 | }
|
---|
496 | else
|
---|
497 | spaces = FALSE;
|
---|
498 | strcpy(pp, retstr);
|
---|
499 | pp += strlen(retstr);
|
---|
500 | if (spaces) {
|
---|
501 | *pp = '\"';
|
---|
502 | pp++;
|
---|
503 | }
|
---|
504 | }
|
---|
505 | }
|
---|
506 | }
|
---|
507 | }
|
---|
508 | }
|
---|
509 | }
|
---|
510 | WinEndEnumWindows(henum);
|
---|
511 | }
|
---|
512 | p += 2;
|
---|
513 | break;
|
---|
514 |
|
---|
515 | case '%':
|
---|
516 | *pp = '%';
|
---|
517 | pp++;
|
---|
518 | p += 2;
|
---|
519 | break;
|
---|
520 |
|
---|
521 | case 'R':
|
---|
522 | case 'F':
|
---|
523 | case 'A':
|
---|
524 | case 'r':
|
---|
525 | case 'f':
|
---|
526 | case 'a':
|
---|
527 | case 'e':
|
---|
528 | if (list) {
|
---|
529 | for (x = 0; list[x]; x++)
|
---|
530 | {
|
---|
531 | file = strrchr(list[x], '\\');
|
---|
532 | if (!file)
|
---|
533 | file = strrchr(list[x], ':');
|
---|
534 | if (file)
|
---|
535 | file++;
|
---|
536 | else
|
---|
537 | file = list[x];
|
---|
538 | ext = strrchr(file, '.');
|
---|
539 | dot = ext;
|
---|
540 | if (ext)
|
---|
541 | ext++;
|
---|
542 | switch (*(p + 1)) {
|
---|
543 | case 'R':
|
---|
544 | case 'r':
|
---|
545 | if (pp + strlen(list[x]) > commandline + MaxComLineStrg)
|
---|
546 | goto BreakOut;
|
---|
547 | if (*(p + 1) == 'r') {
|
---|
548 | strcpy(pp, list[x]);
|
---|
549 | pp += strlen(list[x]);
|
---|
550 | }
|
---|
551 | else {
|
---|
552 | strcpy(pp, list[x] + 2);
|
---|
553 | pp += strlen(list[x] + 2);
|
---|
554 | }
|
---|
555 | break;
|
---|
556 |
|
---|
557 | case 'F':
|
---|
558 | case 'f':
|
---|
559 | if (*(p + 1) == 'F' && dot)
|
---|
560 | *dot = 0;
|
---|
561 | if (pp + strlen(file) > commandline + MaxComLineStrg)
|
---|
562 | goto BreakOut;
|
---|
563 | if (needs_quoting(file)) {
|
---|
564 | spaces = TRUE;
|
---|
565 | *pp = '\"';
|
---|
566 | pp++;
|
---|
567 | }
|
---|
568 | else
|
---|
569 | spaces = FALSE;
|
---|
570 | strcpy(pp, file);
|
---|
571 | pp += strlen(file);
|
---|
572 | if (*(p + 1) == 'F' && dot)
|
---|
573 | *dot = '.';
|
---|
574 | if (spaces) {
|
---|
575 | if (*(pp - 1) != '\"') {
|
---|
576 | *pp = '\"';
|
---|
577 | pp++;
|
---|
578 | }
|
---|
579 | }
|
---|
580 | break;
|
---|
581 |
|
---|
582 | case 'A':
|
---|
583 | case 'a':
|
---|
584 | if (pp + strlen(list[x]) > commandline + MaxComLineStrg)
|
---|
585 | goto BreakOut;
|
---|
586 | if (needs_quoting(list[x]) && !strchr(list[x], '\"')) {
|
---|
587 | spaces = TRUE;
|
---|
588 | *pp = '\"';
|
---|
589 | pp++;
|
---|
590 | }
|
---|
591 | else
|
---|
592 | spaces = FALSE;
|
---|
593 | if (*(p + 1) == 'a') {
|
---|
594 | strcpy(pp, list[x]);
|
---|
595 | pp += strlen(list[x]);
|
---|
596 | }
|
---|
597 | else {
|
---|
598 | strcpy(pp, list[x] + 2);
|
---|
599 | pp += strlen(list[x] + 2);
|
---|
600 | }
|
---|
601 | if (spaces) {
|
---|
602 | if (list[x][strlen(list[x]) - 1] == '\\') {
|
---|
603 | *pp = '\\';
|
---|
604 | pp++;
|
---|
605 | }
|
---|
606 | *pp = '\"';
|
---|
607 | pp++;
|
---|
608 | }
|
---|
609 | break;
|
---|
610 |
|
---|
611 | case 'e':
|
---|
612 | if (ext) {
|
---|
613 | if (pp + strlen(ext) > commandline + MaxComLineStrg)
|
---|
614 | goto BreakOut;
|
---|
615 | if (needs_quoting(ext)) {
|
---|
616 | spaces = TRUE;
|
---|
617 | *pp = '\"';
|
---|
618 | pp++;
|
---|
619 | }
|
---|
620 | else
|
---|
621 | spaces = FALSE;
|
---|
622 | strcpy(pp, ext);
|
---|
623 | pp += strlen(ext);
|
---|
624 | if (spaces) {
|
---|
625 | if (*(pp - 1) != '\"') {
|
---|
626 | *pp = '\"';
|
---|
627 | pp++;
|
---|
628 | }
|
---|
629 | }
|
---|
630 | }
|
---|
631 | break;
|
---|
632 | }
|
---|
633 | if (list[x + 1]) {
|
---|
634 | *pp = ' ';
|
---|
635 | pp++;
|
---|
636 | }
|
---|
637 | }
|
---|
638 | }
|
---|
639 | p += 2;
|
---|
640 | break;
|
---|
641 |
|
---|
642 | default:
|
---|
643 | *pp = *p;
|
---|
644 | p++;
|
---|
645 | pp++;
|
---|
646 | break;
|
---|
647 | }
|
---|
648 | }
|
---|
649 | else {
|
---|
650 | *pp = *p;
|
---|
651 | pp++;
|
---|
652 | p++;
|
---|
653 | }
|
---|
654 | *pp = 0;
|
---|
655 | }
|
---|
656 |
|
---|
657 | BreakOut:
|
---|
658 |
|
---|
659 | {
|
---|
660 | EXECARGS ex;
|
---|
661 | int ret;
|
---|
662 |
|
---|
663 | memset(&ex, 0, sizeof(EXECARGS));
|
---|
664 | //DbgMsg(pszSrcFile, __LINE__, "env %s", environment);
|
---|
665 | if (!environment) {
|
---|
666 | ULONG size;
|
---|
667 |
|
---|
668 | size = ENVIRONMENT_SIZE;
|
---|
669 | PrfQueryProfileData(fmprof, FM3Str, command, ex.environment, &size);
|
---|
670 | }
|
---|
671 | else
|
---|
672 | strcpy(ex.environment, environment);
|
---|
673 | if (flags & PROMPT) {
|
---|
674 | // allow editing command line
|
---|
675 | ex.flags = (flags & (~PROMPT));
|
---|
676 | ex.commandline = commandline;
|
---|
677 | strcpy(ex.path, path);
|
---|
678 | if (prompt)
|
---|
679 | strcpy(ex.title, prompt);
|
---|
680 | ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
|
---|
681 | EXEC_FRAME, &ex);
|
---|
682 | if (ret != 1) {
|
---|
683 | free(commandline);
|
---|
684 | return (ret == 0) ? -1 : -2;
|
---|
685 | }
|
---|
686 | }
|
---|
687 | else
|
---|
688 | ex.flags = flags;
|
---|
689 | //DbgMsg(pszSrcFile, __LINE__, "Inserted %s", environment);
|
---|
690 | ret = runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path,
|
---|
691 | *ex.environment ? ex.environment : NULL,
|
---|
692 | "%s", commandline);
|
---|
693 | free(commandline);
|
---|
694 | return ret;
|
---|
695 | }
|
---|
696 | }
|
---|
697 |
|
---|
698 | /** Run requested app
|
---|
699 | * @return application return code or -1 if problem starting app
|
---|
700 | */
|
---|
701 |
|
---|
702 | int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber,
|
---|
703 | char *pszDirectory, char *pszEnvironment,
|
---|
704 | char *formatstring,...)
|
---|
705 | {
|
---|
706 | /** example:
|
---|
707 | *
|
---|
708 | * status = runemf2(SEPARATE | WINDOWED,
|
---|
709 | * hwnd, pszCallingFile, __LINE__,
|
---|
710 | * NullStr,
|
---|
711 | * NULL,
|
---|
712 | * "%s /C %s",
|
---|
713 | * getenv("COMSPEC"),
|
---|
714 | * batchfilename);
|
---|
715 | *
|
---|
716 | * use (HWND)0 for hwnd if window handle not handy.
|
---|
717 | * pszCallingFile and __LINE__ are used to determine caller for easier error tracking
|
---|
718 | */
|
---|
719 | /**
|
---|
720 | * type bitmapped flag -- see systemf.h
|
---|
721 | */
|
---|
722 |
|
---|
723 | va_list parguments;
|
---|
724 | int ret = -1;
|
---|
725 | RESULTCODES results;
|
---|
726 | STARTDATA sdata;
|
---|
727 | REQUESTDATA rq;
|
---|
728 | ULONG ulSessID;
|
---|
729 | ULONG ulLength;
|
---|
730 | UINT ctr;
|
---|
731 | ULONG ulAppType;
|
---|
732 | PID sessPID;
|
---|
733 | BOOL wasquote;
|
---|
734 | char *p, *pszPgm, *pszArgs = NULL;
|
---|
735 | char szObject[32] = "";
|
---|
736 | char szSavedir[CCHMAXPATH];
|
---|
737 | BOOL useTermQ = FALSE;
|
---|
738 | char szTempdir[CCHMAXPATH];
|
---|
739 | BOOL fNoErrorMsg = FALSE;
|
---|
740 |
|
---|
741 | typedef struct {
|
---|
742 | USHORT usSessID;
|
---|
743 | USHORT usRC;
|
---|
744 | } TERMINFO;
|
---|
745 |
|
---|
746 | TERMINFO *pTermInfo;
|
---|
747 | BYTE bPriority;
|
---|
748 | APIRET rc;
|
---|
749 | PIB *ppib;
|
---|
750 | TIB *ptib;
|
---|
751 |
|
---|
752 | // Shared by all threads
|
---|
753 | # define TERMQ_BASE_NAME "\\QUEUES\\FM3WAIT"
|
---|
754 | static char szTermQName[30];
|
---|
755 | char szTermTemp[30];
|
---|
756 | static HQUEUE hTermQ;
|
---|
757 | static HEV hTermQSem;
|
---|
758 |
|
---|
759 | if (pszDirectory && *pszDirectory) {
|
---|
760 | if (!DosQueryPathInfo(pszDirectory,
|
---|
761 | FIL_QUERYFULLNAME,
|
---|
762 | szTempdir,
|
---|
763 | sizeof(szTempdir)))
|
---|
764 | pszDirectory = szTempdir;
|
---|
765 | }
|
---|
766 |
|
---|
767 | if (!hwnd)
|
---|
768 | hwnd = HWND_DESKTOP;
|
---|
769 |
|
---|
770 | if (xDosAllocMemLow((PVOID)&pszPgm, MaxComLineStrg, pszSrcFile,__LINE__))
|
---|
771 | return -1; //already complained
|
---|
772 | *szSavedir = 0;
|
---|
773 |
|
---|
774 | *pszPgm = 0;
|
---|
775 | va_start(parguments,
|
---|
776 | formatstring);
|
---|
777 | vsprintf(pszPgm,
|
---|
778 | formatstring,
|
---|
779 | parguments);
|
---|
780 | va_end(parguments);
|
---|
781 |
|
---|
782 | if (pszEnvironment) {
|
---|
783 | p = &pszEnvironment[strlen(pszEnvironment)] + 1;
|
---|
784 | *p = 0;
|
---|
785 | p = pszEnvironment;
|
---|
786 | while ((p = convert_nl_to_nul(p)) != NULL)
|
---|
787 | ; // loop
|
---|
788 | }
|
---|
789 |
|
---|
790 | if (!stricmp(pszCallingFile, "init.c"))
|
---|
791 | fNoErrorMsg = TRUE;
|
---|
792 |
|
---|
793 | if (!*pszPgm) {
|
---|
794 | p = GetCmdSpec(FALSE);
|
---|
795 | strcpy(pszPgm, p);
|
---|
796 | if (!*pszPgm) {
|
---|
797 | Runtime_Error(pszSrcFile, __LINE__, NULL);
|
---|
798 | return -1;
|
---|
799 | }
|
---|
800 | }
|
---|
801 |
|
---|
802 | if (*pszPgm) {
|
---|
803 | if (*pszPgm == '<' && strchr(pszPgm, '>')) {
|
---|
804 | // is a workplace object
|
---|
805 | HOBJECT hWPSObject;
|
---|
806 | char temp;
|
---|
807 |
|
---|
808 | p = strchr(pszPgm, '>');
|
---|
809 | p++;
|
---|
810 | temp = *p;
|
---|
811 | if (temp) {
|
---|
812 | if (xDosAllocMemLow((PVOID)&pszArgs, MaxComLineStrg * 2, pszSrcFile, __LINE__)) {
|
---|
813 | DosFreeMem(pszPgm);
|
---|
814 | return -1; //already complained
|
---|
815 | }
|
---|
816 | }
|
---|
817 | else
|
---|
818 | pszArgs = NULL;
|
---|
819 | *p = 0;
|
---|
820 | // Find the handle of the WPS object
|
---|
821 | hWPSObject = WinQueryObject(pszPgm);
|
---|
822 | *p = temp;
|
---|
823 | if (hWPSObject != NULLHANDLE) {
|
---|
824 | if (pszArgs && *p) {
|
---|
825 | sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
|
---|
826 | WinSetObjectData(hWPSObject,pszArgs);
|
---|
827 | }
|
---|
828 | else
|
---|
829 | WinSetObjectData(hWPSObject,"OPEN=DEFAULT");
|
---|
830 | ret = 0;
|
---|
831 | }
|
---|
832 | goto ObjectInterrupt;
|
---|
833 | }
|
---|
834 |
|
---|
835 | if ((type & RUNTYPE_MASK) == SYNCHRONOUS ||
|
---|
836 | (type & RUNTYPE_MASK) == ASYNCHRONOUS ||
|
---|
837 | (type & RUNTYPE_MASK) == DETACHED)
|
---|
838 | {
|
---|
839 | strip_lead_char(" \t", pszPgm);
|
---|
840 | p = pszPgm;
|
---|
841 | wasquote = FALSE;
|
---|
842 | while (*p &&
|
---|
843 | (wasquote ||
|
---|
844 | (*p != ' ' &&
|
---|
845 | *p != '\t')))
|
---|
846 | {
|
---|
847 | if (*p == '\"') {
|
---|
848 | if (!wasquote) {
|
---|
849 | wasquote = TRUE;
|
---|
850 | memmove(p,
|
---|
851 | p + 1,
|
---|
852 | strlen(p));
|
---|
853 | while (*p == ' ' ||
|
---|
854 | *p == '\t')
|
---|
855 | p++;
|
---|
856 | }
|
---|
857 | else {
|
---|
858 | memmove(p,
|
---|
859 | p + 1,
|
---|
860 | strlen(p));
|
---|
861 | break;
|
---|
862 | }
|
---|
863 | }
|
---|
864 | else
|
---|
865 | p++;
|
---|
866 | }
|
---|
867 | if (*p) {
|
---|
868 | *p = 0;
|
---|
869 | p++;
|
---|
870 | }
|
---|
871 | else
|
---|
872 | p = pszPgm;
|
---|
873 | p[strlen(p) + 1] = 0; // double-terminate args
|
---|
874 | if (*pszPgm) {
|
---|
875 | if (!strchr(pszPgm, '\\') &&
|
---|
876 | !strchr(pszPgm, ':') &&
|
---|
877 | pszDirectory &&
|
---|
878 | *pszDirectory)
|
---|
879 | {
|
---|
880 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
881 | switch_to(pszDirectory);
|
---|
882 | }
|
---|
883 | rc = DosQueryAppType(pszPgm,&ulAppType);
|
---|
884 | if (!strchr(pszPgm, '\\') &&
|
---|
885 | !strchr(pszPgm, ':') &&
|
---|
886 | pszDirectory &&
|
---|
887 | *pszDirectory)
|
---|
888 | switch_to(szSavedir);
|
---|
889 | if (rc) {
|
---|
890 | if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
|
---|
891 | rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
|
---|
892 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
893 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
|
---|
894 | else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
|
---|
895 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
896 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
|
---|
897 | else
|
---|
898 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
|
---|
899 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
|
---|
900 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
901 | DosFreeMem(pszPgm);
|
---|
902 | if (pszArgs)
|
---|
903 | DosFreeMem(pszArgs);
|
---|
904 | return -1;
|
---|
905 | }
|
---|
906 | if (ulAppType) {
|
---|
907 | if (ulAppType & FAPPTYP_DLL || ulAppType & FAPPTYP_VIRTDRV ||
|
---|
908 | ulAppType & FAPPTYP_PHYSDRV || ulAppType & FAPPTYP_PROTDLL)
|
---|
909 | {
|
---|
910 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
911 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
912 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
913 | if (pszPgm)
|
---|
914 | DosFreeMem(pszPgm);
|
---|
915 | if (pszArgs)
|
---|
916 | DosFreeMem(pszArgs);
|
---|
917 | return -1;
|
---|
918 | }
|
---|
919 | if (ulAppType & FAPPTYP_DOS || ulAppType & FAPPTYP_WINDOWSREAL ||
|
---|
920 | ulAppType & FAPPTYP_WINDOWSPROT || ulAppType & FAPPTYP_WINDOWSPROT31)
|
---|
921 | {
|
---|
922 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
923 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
924 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
925 | if (pszPgm)
|
---|
926 | DosFreeMem(pszPgm);
|
---|
927 | if (pszArgs)
|
---|
928 | DosFreeMem(pszArgs);
|
---|
929 | return -1;
|
---|
930 | }
|
---|
931 | }
|
---|
932 | memset(&results, 0, sizeof(results));
|
---|
933 | if (pszDirectory && *pszDirectory) {
|
---|
934 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
935 | switch_to(pszDirectory);
|
---|
936 | }
|
---|
937 | ret = DosExecPgm(szObject, sizeof(szObject),
|
---|
938 | ((type & RUNTYPE_MASK) == ASYNCHRONOUS ? EXEC_ASYNC : 0) +
|
---|
939 | ((type & RUNTYPE_MASK) == DETACHED ? EXEC_BACKGROUND : 0),
|
---|
940 | pszPgm, pszEnvironment, &results, pszPgm);
|
---|
941 | if (pszDirectory && *pszDirectory)
|
---|
942 | switch_to(szSavedir);
|
---|
943 | if (ret && !fNoErrorMsg) {
|
---|
944 | Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
|
---|
945 | GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm,
|
---|
946 | pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
947 | }
|
---|
948 | }
|
---|
949 | }
|
---|
950 | else {
|
---|
951 | if (~type & FULLSCREEN)
|
---|
952 | type |= WINDOWED;
|
---|
953 | if (xDosAllocMemLow((PVOID) &pszArgs, MaxComLineStrg * 2, pszSrcFile, __LINE__)) {
|
---|
954 | DosFreeMem(pszPgm);
|
---|
955 | return -1; //already complained
|
---|
956 | }
|
---|
957 | *pszArgs = 0;
|
---|
958 | memset(&sdata, 0, sizeof(sdata));
|
---|
959 | strip_lead_char(" \t", pszPgm);
|
---|
960 | p = pszPgm;
|
---|
961 | wasquote = FALSE;
|
---|
962 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
963 | if (*p == '\"') {
|
---|
964 | if (!wasquote) {
|
---|
965 | wasquote = TRUE;
|
---|
966 | memmove(p, p + 1, strlen(p));
|
---|
967 | while (*p == ' ' || *p == '\t')
|
---|
968 | p++;
|
---|
969 | }
|
---|
970 | else {
|
---|
971 | memmove(p, p + 1, strlen(p));
|
---|
972 | break;
|
---|
973 | }
|
---|
974 | }
|
---|
975 | else
|
---|
976 | p++;
|
---|
977 | } // while
|
---|
978 | if (*p) {
|
---|
979 | *p = 0;
|
---|
980 | p++;
|
---|
981 | }
|
---|
982 | else
|
---|
983 | p = NullStr;
|
---|
984 | if (*p)
|
---|
985 | strcpy(pszArgs, p);
|
---|
986 |
|
---|
987 | p = strrchr(pszPgm, '.');
|
---|
988 | if (p) {
|
---|
989 | char temp[CCHMAXPATH + 1];
|
---|
990 |
|
---|
991 | if (!stricmp(p, PCSZ_DOTBAT)) {
|
---|
992 | if (!fProtectOnly) {
|
---|
993 | strcpy(temp, pszPgm);
|
---|
994 | strcpy(pszPgm, pszArgs);
|
---|
995 | strcpy(pszArgs, "/C ");
|
---|
996 | strcat(pszArgs, temp);
|
---|
997 | strcat(pszArgs, " ");
|
---|
998 | strcat(pszArgs, pszPgm);
|
---|
999 | strcpy(pszPgm, GetCmdSpec(TRUE)); // DOS
|
---|
1000 | }
|
---|
1001 | else
|
---|
1002 | saymsg(MB_OK,
|
---|
1003 | HWND_DESKTOP,
|
---|
1004 | NullStr,
|
---|
1005 | GetPString(IDS_NOTPROTECTONLYEXE),
|
---|
1006 | pszPgm);
|
---|
1007 | }
|
---|
1008 | else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
|
---|
1009 | // Assume 4OS2 is BTM
|
---|
1010 | strcpy(temp, pszPgm);
|
---|
1011 | strcpy(pszPgm, pszArgs);
|
---|
1012 | strcpy(pszArgs, "/C ");
|
---|
1013 | strcat(pszArgs, temp);
|
---|
1014 | strcat(pszArgs, " ");
|
---|
1015 | strcat(pszArgs, pszPgm);
|
---|
1016 | strcpy(pszPgm, GetCmdSpec(FALSE)); // OS/2
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | // goddamned OS/2 limit
|
---|
1021 |
|
---|
1022 | if (strlen(pszPgm) + strlen(pszArgs) > 1024)
|
---|
1023 | pszArgs[1024 - strlen(pszPgm)] = 0;
|
---|
1024 |
|
---|
1025 | if (!strchr(pszPgm, '\\') &&
|
---|
1026 | !strchr(pszPgm, ':') &&
|
---|
1027 | pszDirectory &&
|
---|
1028 | *pszDirectory)
|
---|
1029 | {
|
---|
1030 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
1031 | switch_to(pszDirectory);
|
---|
1032 | }
|
---|
1033 | rc = DosQueryAppType(pszPgm,&ulAppType);
|
---|
1034 | if (!strchr(pszPgm, '\\') &&
|
---|
1035 | !strchr(pszPgm, ':') &&
|
---|
1036 | pszDirectory &&
|
---|
1037 | *pszDirectory)
|
---|
1038 | switch_to(szSavedir);
|
---|
1039 | if (rc) {
|
---|
1040 | if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
|
---|
1041 | rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
|
---|
1042 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
1043 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
|
---|
1044 | else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
|
---|
1045 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
1046 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
|
---|
1047 | else
|
---|
1048 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
|
---|
1049 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
|
---|
1050 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
1051 | DosFreeMem(pszPgm);
|
---|
1052 | if (pszArgs)
|
---|
1053 | DosFreeMem(pszArgs);
|
---|
1054 | return -1;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | if (ulAppType) {
|
---|
1058 | if (ulAppType & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL))
|
---|
1059 | {
|
---|
1060 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
1061 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
1062 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
1063 | DosFreeMem(pszPgm);
|
---|
1064 | if (pszArgs)
|
---|
1065 | DosFreeMem(pszArgs);
|
---|
1066 | return -1;
|
---|
1067 | }
|
---|
1068 | ulAppType &= ~FAPPTYP_BOUND;
|
---|
1069 | if (ulAppType & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
1070 | {
|
---|
1071 | if (ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
1072 | {
|
---|
1073 | if (~type & FULLSCREEN &&
|
---|
1074 | ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
1075 | {
|
---|
1076 | ret = RunSeamless(pszPgm, pszArgs, hwnd);
|
---|
1077 | if (pszPgm)
|
---|
1078 | DosFreeMem(pszPgm);
|
---|
1079 | if (pszArgs)
|
---|
1080 | DosFreeMem(pszArgs);
|
---|
1081 | return ret ? 0 : -1;
|
---|
1082 | }
|
---|
1083 | else {
|
---|
1084 | strcat(pszPgm, " ");
|
---|
1085 | strcat(pszPgm, pszArgs);
|
---|
1086 | *pszArgs = 0;
|
---|
1087 | if (ulAppType & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31))
|
---|
1088 | strcat(pszArgs, "/3 ");
|
---|
1089 | strcat(pszArgs, pszPgm);
|
---|
1090 | strcpy(pszPgm, "WINOS2.COM");
|
---|
1091 | }
|
---|
1092 | }
|
---|
1093 | else {
|
---|
1094 | if (~type & FULLSCREEN) {
|
---|
1095 | type |= WINDOWED;
|
---|
1096 | ulAppType = SSF_TYPE_WINDOWEDVDM;
|
---|
1097 | }
|
---|
1098 | else {
|
---|
1099 | type &= ~WINDOWED;
|
---|
1100 | ulAppType = SSF_TYPE_VDM;
|
---|
1101 | }
|
---|
1102 | }
|
---|
1103 | }
|
---|
1104 | else if (ulAppType & FAPPTYP_32BIT) {
|
---|
1105 | ulAppType &= ~FAPPTYP_32BIT;
|
---|
1106 | if (ulAppType == FAPPTYP_WINDOWAPI)
|
---|
1107 | ulAppType = SSF_TYPE_PM;
|
---|
1108 | else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
|
---|
1109 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
1110 | else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
1111 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
1112 | type &= ~WINDOWED;
|
---|
1113 | type |= FULLSCREEN;
|
---|
1114 | }
|
---|
1115 | else // ?
|
---|
1116 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
1117 | }
|
---|
1118 | else if (ulAppType == FAPPTYP_WINDOWAPI)
|
---|
1119 | ulAppType = SSF_TYPE_PM;
|
---|
1120 | else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
|
---|
1121 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
1122 | else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
1123 | type &= ~WINDOWED;
|
---|
1124 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
1125 | }
|
---|
1126 | else
|
---|
1127 | ulAppType = SSF_TYPE_DEFAULT;
|
---|
1128 | if ((type & FULLSCREEN || ~type & WINDOWED) &&
|
---|
1129 | ulAppType == SSF_TYPE_WINDOWABLEVIO)
|
---|
1130 | {
|
---|
1131 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
1132 | }
|
---|
1133 | // fixme parens?
|
---|
1134 | else if (type & FULLSCREEN ||
|
---|
1135 | (type & WINDOWED && ulAppType == SSF_TYPE_WINDOWEDVDM))
|
---|
1136 | {
|
---|
1137 | ulAppType = SSF_TYPE_VDM;
|
---|
1138 | }
|
---|
1139 | }
|
---|
1140 | if (ulAppType == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) {
|
---|
1141 | type &= ~SEPARATEKEEP;
|
---|
1142 | type |= SEPARATE;
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | DosGetInfoBlocks(&ptib, &ppib);
|
---|
1146 |
|
---|
1147 | if (~type & WAIT)
|
---|
1148 | useTermQ = FALSE;
|
---|
1149 | else {
|
---|
1150 | rc = 0;
|
---|
1151 | DosEnterCritSec();
|
---|
1152 | if (!hTermQ) {
|
---|
1153 | // Create term queue and event semaphore just once
|
---|
1154 | sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid);
|
---|
1155 | rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName);
|
---|
1156 | if (rc) {
|
---|
1157 | hTermQ = (HQUEUE)0; // Try to survive
|
---|
1158 | DosExitCritSec();
|
---|
1159 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
|
---|
1160 | }
|
---|
1161 | else {
|
---|
1162 | rc = DosCreateEventSem(NULL,(PHEV)&hTermQSem,0,FALSE);
|
---|
1163 | if (rc) {
|
---|
1164 | hTermQSem = (HEV)0; // Try to survive
|
---|
1165 | DosCloseQueue(hTermQ);
|
---|
1166 | hTermQ = (HQUEUE)0; // Try to survive
|
---|
1167 | DosExitCritSec();
|
---|
1168 | Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__, PCSZ_DOSCREATEEVENTSEM);
|
---|
1169 | }
|
---|
1170 | // if (!rc) fprintf(stderr,"%s %d qcreated ptib %x hTermQ %x\n",__FILE__, __LINE__,ptib,hTermQ);
|
---|
1171 | }
|
---|
1172 | } // if 1st time
|
---|
1173 | useTermQ = hTermQ && hTermQSem;
|
---|
1174 | if (!rc)
|
---|
1175 | DosExitCritSec();
|
---|
1176 | } // if wait
|
---|
1177 |
|
---|
1178 | memset(&sdata,0,sizeof(sdata));
|
---|
1179 | sdata.Length = sizeof(sdata);
|
---|
1180 | sdata.Related = type & (WAIT | CHILD) ? SSF_RELATED_CHILD :
|
---|
1181 | SSF_RELATED_INDEPENDENT;
|
---|
1182 | sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE;
|
---|
1183 | sdata.TraceOpt = SSF_TRACEOPT_NONE;
|
---|
1184 | sdata.PgmName = pszPgm;
|
---|
1185 | if (*pszArgs)
|
---|
1186 | sdata.PgmInputs = (PBYTE)pszArgs;
|
---|
1187 | if (useTermQ) {
|
---|
1188 | strcpy(szTermTemp, szTermQName);
|
---|
1189 | sdata.TermQ = (PBYTE)szTermTemp;
|
---|
1190 | }
|
---|
1191 | sdata.Environment = (PBYTE)pszEnvironment;
|
---|
1192 | sdata.InheritOpt = SSF_INHERTOPT_PARENT;
|
---|
1193 | sdata.SessionType = (USHORT) ulAppType;
|
---|
1194 | sdata.ObjectBuffer = szObject;
|
---|
1195 | sdata.ObjectBuffLen = sizeof(szObject);
|
---|
1196 | if ((type & RUNTYPE_MASK) == SEPARATEKEEP)
|
---|
1197 | sdata.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
|
---|
1198 | if (type & MAXIMIZED)
|
---|
1199 | sdata.PgmControl |= SSF_CONTROL_MAXIMIZE;
|
---|
1200 | if (type & MINIMIZED)
|
---|
1201 | sdata.PgmControl |= SSF_CONTROL_MINIMIZE;
|
---|
1202 | if (type & INVISIBLE)
|
---|
1203 | sdata.PgmControl |= SSF_CONTROL_INVISIBLE;
|
---|
1204 |
|
---|
1205 | if (pszDirectory && *pszDirectory) {
|
---|
1206 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
1207 | switch_to(pszDirectory);
|
---|
1208 | }
|
---|
1209 | ret = DosStartSession(&sdata, &ulSessID, &sessPID);
|
---|
1210 |
|
---|
1211 |
|
---|
1212 | if (pszDirectory && *pszDirectory)
|
---|
1213 | switch_to(szSavedir);
|
---|
1214 |
|
---|
1215 | if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
|
---|
1216 | if (!fNoErrorMsg)
|
---|
1217 | Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
|
---|
1218 | GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs,
|
---|
1219 | pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
1220 | }
|
---|
1221 | else if (type & WAIT) {
|
---|
1222 | if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
1223 | ShowSession(hwnd, sessPID);
|
---|
1224 |
|
---|
1225 | if (!useTermQ) {
|
---|
1226 | STATUSDATA sd;
|
---|
1227 |
|
---|
1228 | memset(&sd, 0, sizeof(sd));
|
---|
1229 | sd.Length = (USHORT) sizeof(sd);
|
---|
1230 | sd.SelectInd = SET_SESSION_UNCHANGED;
|
---|
1231 | sd.BondInd = SET_SESSION_UNCHANGED;
|
---|
1232 | for (ctr = 0;; ctr++)
|
---|
1233 | {
|
---|
1234 | DosSleep(50);//05 Aug 07 GKY 200
|
---|
1235 | if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished)
|
---|
1236 | break;
|
---|
1237 | if (ctr > 10) {
|
---|
1238 | ShowSession(hwnd, sessPID); // Show every 2 seconds
|
---|
1239 | ctr = 0;
|
---|
1240 | }
|
---|
1241 | }
|
---|
1242 | }
|
---|
1243 | else {
|
---|
1244 | for (ctr = 0;; ctr++)
|
---|
1245 | {
|
---|
1246 | if (ctr < 20) {
|
---|
1247 | rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
1248 | DCWW_NOWAIT, &bPriority, hTermQSem);
|
---|
1249 | if (rc == ERROR_QUE_EMPTY) {
|
---|
1250 | DosSleep(50);//05 Aug 07 GKY 100
|
---|
1251 | continue;
|
---|
1252 | }
|
---|
1253 | }
|
---|
1254 | else {
|
---|
1255 | if (ctr == 20) {
|
---|
1256 | ShowSession(hwnd, sessPID); // Show long running session
|
---|
1257 | }
|
---|
1258 | rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
1259 | DCWW_WAIT, &bPriority, 0);
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | if (rc) {
|
---|
1263 | // Oh heck
|
---|
1264 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
|
---|
1265 | DosSleep(100);//05 Aug 07 GKY 500
|
---|
1266 | continue;
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | // printf("%s %d DosReadQueue thread 0x%x sess %u sessRC %u rq.pid 0x%x rq.data 0x%x\n",
|
---|
1270 | // __FILE__, __LINE__,ptib->tib_ordinal,pTermInfo->usSessID,pTermInfo->usRC,rq.pid, rq.ulData); fflush(stdout);
|
---|
1271 |
|
---|
1272 | if (pTermInfo->usSessID == ulSessID)
|
---|
1273 | break; // Our session is done
|
---|
1274 |
|
---|
1275 | // Requeue session for other thread
|
---|
1276 | {
|
---|
1277 | static ULONG ulLastSessID;
|
---|
1278 | // printf("%s %d requeue thread 0x%x our sess %u term sess %u term rc %u\n",
|
---|
1279 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,pTermInfo->usSessID,pTermInfo->usRC); fflush(stdout);
|
---|
1280 | // fixme to be gone when no longer needed for debug?
|
---|
1281 | if (ulLastSessID) {
|
---|
1282 | DosSleep(100);//05 Aug 07 GKY 500
|
---|
1283 | ulLastSessID = pTermInfo->usSessID;
|
---|
1284 | }
|
---|
1285 | // requeue term report for other thread and do not free yet
|
---|
1286 | rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority);
|
---|
1287 | if (rc)
|
---|
1288 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue");
|
---|
1289 | DosSleep(50); //05 Aug 07 GKY 100 // Let other thread see queue entry
|
---|
1290 | }
|
---|
1291 | } // for
|
---|
1292 |
|
---|
1293 | ret = pTermInfo->usRC == 0; // Set 1 if rc 0 else 0
|
---|
1294 | // printf("%s %d thread 0x%x term for sess %u\n",
|
---|
1295 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID);fflush(stdout);
|
---|
1296 | DosFreeMem(pTermInfo);
|
---|
1297 | }
|
---|
1298 | } // if wait
|
---|
1299 | else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
1300 | ShowSession(hwnd, sessPID);
|
---|
1301 | }
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | ObjectInterrupt:
|
---|
1305 |
|
---|
1306 | if (pszPgm)
|
---|
1307 | DosFreeMem(pszPgm);
|
---|
1308 | if (pszArgs)
|
---|
1309 | DosFreeMem(pszArgs);
|
---|
1310 |
|
---|
1311 | return ret;
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | //== Exec() Start application with WinStartApp ==
|
---|
1315 | #if 0 // JBS 11 Sep 08
|
---|
1316 | HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
1317 | PROGTYPE *progt, ULONG fl, char *formatstring,...)
|
---|
1318 | {
|
---|
1319 | PROGDETAILS pgd;
|
---|
1320 | register char *p;
|
---|
1321 | char *parameters = NULL, *executable = NULL;
|
---|
1322 | HAPP happ = (HAPP)0;
|
---|
1323 | ULONG ulOptions = SAF_INSTALLEDCMDLINE;
|
---|
1324 | BOOL wasquote;
|
---|
1325 | va_list parguments;
|
---|
1326 |
|
---|
1327 | if (child)
|
---|
1328 | ulOptions |= SAF_STARTCHILDAPP;
|
---|
1329 |
|
---|
1330 | executable = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
1331 | if (executable) {
|
---|
1332 | va_start(parguments, formatstring);
|
---|
1333 | vsprintf(executable, formatstring, parguments);
|
---|
1334 | va_end(parguments);
|
---|
1335 | strip_lead_char(" \t", executable);
|
---|
1336 | if (*executable) {
|
---|
1337 | parameters = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
1338 | if (parameters) {
|
---|
1339 | p = executable;
|
---|
1340 | wasquote = FALSE;
|
---|
1341 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
1342 | if (*p == '\"') {
|
---|
1343 | if (!wasquote) {
|
---|
1344 | wasquote = TRUE;
|
---|
1345 | memmove(p, p + 1, strlen(p));
|
---|
1346 | while (*p == ' ' || *p == '\t')
|
---|
1347 | p++;
|
---|
1348 | }
|
---|
1349 | else {
|
---|
1350 | memmove(p, p + 1, strlen(p));
|
---|
1351 | break;
|
---|
1352 | }
|
---|
1353 | }
|
---|
1354 | else
|
---|
1355 | p++;
|
---|
1356 | }
|
---|
1357 | if (*p) {
|
---|
1358 | *p = 0;
|
---|
1359 | p++;
|
---|
1360 | }
|
---|
1361 | else
|
---|
1362 | p = NullStr;
|
---|
1363 | if (*p)
|
---|
1364 | strcpy(parameters, p);
|
---|
1365 |
|
---|
1366 | if (p && (!stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTCMD) ||
|
---|
1367 | !stricmp(p, PCSZ_DOTBTM))) {
|
---|
1368 | char *temp;
|
---|
1369 |
|
---|
1370 | temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
|
---|
1371 | if (temp) {
|
---|
1372 | if (!stricmp(p, PCSZ_DOTBAT)) {
|
---|
1373 | if (!fProtectOnly) {
|
---|
1374 | strcpy(temp, executable);
|
---|
1375 | strcpy(executable, parameters);
|
---|
1376 | strcpy(parameters, "/C ");
|
---|
1377 | strcat(parameters, temp);
|
---|
1378 | strcat(parameters, " ");
|
---|
1379 | strcat(parameters, executable);
|
---|
1380 | strcpy(executable, GetCmdSpec(TRUE)); //DOS
|
---|
1381 | }
|
---|
1382 | else
|
---|
1383 | saymsg(MB_OK,
|
---|
1384 | HWND_DESKTOP,
|
---|
1385 | NullStr,
|
---|
1386 | GetPString(IDS_NOTPROTECTONLYEXE),
|
---|
1387 | filename);
|
---|
1388 | }
|
---|
1389 | else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
|
---|
1390 | strcpy(temp, executable);
|
---|
1391 | strcpy(executable, parameters);
|
---|
1392 | strcpy(parameters, "/C ");
|
---|
1393 | strcat(parameters, temp);
|
---|
1394 | strcat(parameters, " ");
|
---|
1395 | strcat(parameters, executable);
|
---|
1396 | strcpy(executable, GetCmdSpec(FALSE));
|
---|
1397 | }
|
---|
1398 | free(temp);
|
---|
1399 | }
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | memset(&pgd, 0, sizeof(pgd));
|
---|
1403 | pgd.Length = sizeof(pgd);
|
---|
1404 | pgd.progt = *progt;
|
---|
1405 | pgd.swpInitial.fl = fl;
|
---|
1406 | pgd.pszEnvironment = env;
|
---|
1407 | pgd.pszStartupDir = startdir;
|
---|
1408 | pgd.pszParameters = *parameters ? parameters : NULL;
|
---|
1409 | pgd.pszExecutable = executable;
|
---|
1410 | pgd.swpInitial.hwndInsertBehind = HWND_TOP;
|
---|
1411 | happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions);
|
---|
1412 | free(parameters);
|
---|
1413 | }
|
---|
1414 | }
|
---|
1415 | free(executable);
|
---|
1416 | }
|
---|
1417 | return happ;
|
---|
1418 | }
|
---|
1419 | #endif
|
---|
1420 | #pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
|
---|