[78] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: systemf.c 1628 2011-08-27 19:35:39Z gyoung $
|
---|
| 5 |
|
---|
| 6 | System Interfaces
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
---|
[1498] | 9 | Copyright (c) 2003, 2010 Steven H.Levine
|
---|
[78] | 10 |
|
---|
[330] | 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
|
---|
[373] | 15 | 26 Jul 06 SHL Use convert_nl_to_nul
|
---|
[441] | 16 | 15 Aug 06 SHL More error popups
|
---|
[519] | 17 | 01 Nov 06 SHL runemf2: temp fix for hung windows caused by termq errors
|
---|
[540] | 18 | 03 Nov 06 SHL runemf2: rework termination queue logic to work for multiple threads
|
---|
[552] | 19 | 07 Jan 07 GKY Move error strings etc. to string file
|
---|
[775] | 20 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
---|
[793] | 21 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[985] | 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
|
---|
[1021] | 24 | 26 May 08 SHL Use uiLineNumber correctly
|
---|
[1082] | 25 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory or pTmpDir and use MakeTempName
|
---|
[1375] | 26 | 03 Jan 09 GKY Check for system that is protectonly to gray out Dos/Win command lines and prevent
|
---|
[1394] | 27 | Dos/Win programs from being inserted into the execute dialog with message why.
|
---|
[1439] | 28 | 12 Jul 09 GKY Allow FM/2 to load in high memory
|
---|
[1488] | 29 | 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
|
---|
[1492] | 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).
|
---|
[1498] | 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).
|
---|
[1554] | 37 | 20 Nov 10 GKY Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused
|
---|
| 38 | by temp file creation failures.
|
---|
[1627] | 39 | 26 Aug 11 GKY Add a low mem version of xDosAlloc* wrappers; move error checking into all the
|
---|
| 40 | xDosAlloc* wrappers.
|
---|
[78] | 41 |
|
---|
| 42 | ***********************************************************************/
|
---|
| 43 |
|
---|
[2] | 44 | #include <stdlib.h>
|
---|
| 45 | #include <stdarg.h>
|
---|
| 46 | #include <string.h>
|
---|
| 47 | #include <ctype.h>
|
---|
[330] | 48 |
|
---|
[907] | 49 | #define INCL_DOS
|
---|
| 50 | #define INCL_DOSERRORS
|
---|
| 51 | #define INCL_WIN
|
---|
[1162] | 52 | #define INCL_LONGLONG // dircnrs.h
|
---|
[907] | 53 |
|
---|
[1186] | 54 | #include "fm3dll.h"
|
---|
[1227] | 55 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
[1213] | 56 | #include "mkdir.h" // Data declaration(s)
|
---|
| 57 | #include "init.h" // Data declaration(s)
|
---|
| 58 | #include "mainwnd.h" // Data declaration(s)
|
---|
[2] | 59 | #include "fm3dlg.h"
|
---|
| 60 | #include "fm3str.h"
|
---|
[1162] | 61 | #include "errutil.h" // Dos_Error...
|
---|
| 62 | #include "strutil.h" // GetPString
|
---|
[985] | 63 | #include "notebook.h" //targetdirectory
|
---|
[907] | 64 | #include "pathutil.h"
|
---|
[1162] | 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
|
---|
[1186] | 70 | #include "valid.h" // MakeFullName
|
---|
| 71 | #include "misc.h" // GetCmdSpec
|
---|
| 72 | #include "copyf.h" // MakeTempName
|
---|
| 73 | #include "wrappers.h" // xfopen
|
---|
[1039] | 74 | #include "fortify.h"
|
---|
[2] | 75 |
|
---|
[330] | 76 | static PSZ pszSrcFile = __FILE__;
|
---|
| 77 |
|
---|
[1488] | 78 |
|
---|
[1162] | 79 | //static HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
| 80 | // PROGTYPE * progt, ULONG fl, char *formatstring, ...);
|
---|
| 81 |
|
---|
[917] | 82 | /**
|
---|
[1488] | 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 | /**
|
---|
[917] | 128 | * Bring session foreground
|
---|
| 129 | * @return TRUE if OK, else FALSE
|
---|
| 130 | */
|
---|
[2] | 131 |
|
---|
[105] | 132 | BOOL ShowSession(HWND hwnd, PID pid)
|
---|
[78] | 133 | {
|
---|
[105] | 134 | HSWITCH hswitch;
|
---|
| 135 | SWCNTRL swctl;
|
---|
| 136 | ULONG rc;
|
---|
[2] | 137 |
|
---|
[519] | 138 | hswitch = WinQuerySwitchHandle(pid ? (HWND)0 : hwnd, pid);
|
---|
[441] | 139 | if (hswitch) {
|
---|
[105] | 140 | rc = WinQuerySwitchEntry(hswitch, &swctl);
|
---|
[441] | 141 | if (!rc) {
|
---|
[105] | 142 | if (swctl.idProcess == pid && swctl.uchVisibility == SWL_VISIBLE)
|
---|
[1394] | 143 | rc = WinSwitchToProgram(hswitch);
|
---|
[105] | 144 | if (!rc)
|
---|
[1394] | 145 | return TRUE;
|
---|
[105] | 146 | }
|
---|
| 147 | }
|
---|
| 148 | return FALSE;
|
---|
[2] | 149 | }
|
---|
| 150 |
|
---|
[917] | 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 | */
|
---|
[519] | 157 |
|
---|
[1497] | 158 | int ExecOnList(HWND hwnd, PSZ command, int flags, PSZ tpath, PSZ environment,
|
---|
[1394] | 159 | PSZ *list, PCSZ prompt, PCSZ pszCallingFile, UINT uiLineNumber)
|
---|
[78] | 160 | {
|
---|
[105] | 161 | /* executes the command once for all files in list */
|
---|
[2] | 162 |
|
---|
[1394] | 163 | CHAR path[CCHMAXPATH], *commandline, modpath[CCHMAXPATH], listfile[CCHMAXPATH],
|
---|
[105] | 164 | *p, *pp, drive, *file, *ext, *dot;
|
---|
[2] | 165 | register int x;
|
---|
[105] | 166 | BOOL spaces;
|
---|
[2] | 167 |
|
---|
[441] | 168 | if (!command || !*command) {
|
---|
[1398] | 169 | Runtime_Error(pszSrcFile, __LINE__, NULL);
|
---|
[105] | 170 | return -1;
|
---|
[441] | 171 | }
|
---|
[989] | 172 | commandline = xmalloc(MaxComLineStrg + 1, pszSrcFile, __LINE__);
|
---|
[985] | 173 | if (!commandline)
|
---|
| 174 | return -1; //already complained
|
---|
[2] | 175 | *listfile = 0;
|
---|
[123] | 176 | bstrip(command);
|
---|
[2] | 177 |
|
---|
| 178 | *path = 0;
|
---|
[105] | 179 | if (tpath && *tpath)
|
---|
| 180 | strcpy(path, tpath);
|
---|
[441] | 181 | else if (*command != '<' || !strchr(command, '>')) {
|
---|
[105] | 182 | strcpy(path, command + (*command == '"'));
|
---|
| 183 | if (*command == '\"')
|
---|
| 184 | p = strchr(path, '\"');
|
---|
[2] | 185 | else
|
---|
[105] | 186 | p = strchr(path, ' ');
|
---|
| 187 | if (p)
|
---|
[2] | 188 | *p = 0;
|
---|
[105] | 189 | p = strrchr(path, '\\');
|
---|
| 190 | if (!p)
|
---|
| 191 | p = strrchr(path, ':');
|
---|
[441] | 192 | if (p) {
|
---|
| 193 | if (*p == ':') {
|
---|
[1394] | 194 | p++;
|
---|
| 195 | *p = '\\';
|
---|
| 196 | p++;
|
---|
[2] | 197 | }
|
---|
| 198 | *p = 0;
|
---|
| 199 | }
|
---|
| 200 | else
|
---|
| 201 | *path = 0;
|
---|
| 202 | }
|
---|
[441] | 203 | if (!*path) {
|
---|
[105] | 204 | if (list && list[0])
|
---|
| 205 | strcpy(path, list[0]);
|
---|
| 206 | p = strrchr(path, '\\');
|
---|
| 207 | if (!p)
|
---|
| 208 | p = strrchr(path, ':');
|
---|
[441] | 209 | if (p) {
|
---|
| 210 | if (*p == ':') {
|
---|
[1394] | 211 | p++;
|
---|
| 212 | *p = '\\';
|
---|
| 213 | p++;
|
---|
[2] | 214 | }
|
---|
| 215 | *p = 0;
|
---|
| 216 | }
|
---|
| 217 | else
|
---|
| 218 | *path = 0;
|
---|
| 219 | }
|
---|
| 220 | *modpath = 0;
|
---|
[105] | 221 | if (list && list[0])
|
---|
| 222 | strcpy(modpath, list[0]);
|
---|
| 223 | p = strrchr(modpath, '\\');
|
---|
| 224 | if (!p)
|
---|
| 225 | p = strrchr(modpath, ':');
|
---|
[441] | 226 | if (p) {
|
---|
| 227 | if (*p == ':') {
|
---|
[2] | 228 | p++;
|
---|
| 229 | *p = '\\';
|
---|
| 230 | p++;
|
---|
| 231 | }
|
---|
| 232 | *p = 0;
|
---|
| 233 | }
|
---|
| 234 | else
|
---|
| 235 | *modpath = 0;
|
---|
[105] | 236 | if (!*modpath)
|
---|
| 237 | strcpy(modpath, path);
|
---|
| 238 | if (*path)
|
---|
[2] | 239 | MakeFullName(path);
|
---|
[105] | 240 | if (*modpath)
|
---|
[2] | 241 | MakeFullName(modpath);
|
---|
[105] | 242 | if (IsFullName(path))
|
---|
| 243 | drive = toupper(*path);
|
---|
| 244 | else
|
---|
| 245 | drive = 0;
|
---|
[2] | 246 |
|
---|
[1162] | 247 | p = command; // substitue for special % sequences
|
---|
[2] | 248 |
|
---|
[105] | 249 | pp = commandline;
|
---|
| 250 | *commandline = 0;
|
---|
[441] | 251 | while (*p) {
|
---|
| 252 | if (*p == '%') {
|
---|
| 253 | switch (*(p + 1)) {
|
---|
[1162] | 254 | case '!': /* write list to file, add filename */
|
---|
[1394] | 255 | if (list) {
|
---|
| 256 | if (!*listfile) {
|
---|
| 257 | FILE *fp;
|
---|
[1544] | 258 | CHAR *modew = "w";
|
---|
[2] | 259 |
|
---|
[1554] | 260 | if (pTmpDir && !IsValidDir(pTmpDir))
|
---|
| 261 | DosCreateDir(pTmpDir, 0);
|
---|
[1394] | 262 | strcpy(listfile, pTmpDir ? pTmpDir : pFM2SaveDirectory);
|
---|
| 263 | MakeTempName(listfile, "$FM2LI$T", 2);
|
---|
[1544] | 264 | fp = xfopen(listfile, modew,pszSrcFile,__LINE__, FALSE);
|
---|
[1394] | 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;
|
---|
[2] | 280 |
|
---|
[1162] | 281 | case 'c': /* add name of command processor */
|
---|
[1394] | 282 | {
|
---|
| 283 | char *env = GetCmdSpec(FALSE);
|
---|
[2] | 284 |
|
---|
[1394] | 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;
|
---|
[2] | 301 |
|
---|
[1162] | 302 | case 't': /* add Target directory */
|
---|
[1394] | 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;
|
---|
[2] | 318 |
|
---|
[1162] | 319 | case '$': /* add drive letter */
|
---|
[1394] | 320 | if (drive)
|
---|
| 321 | *pp = drive;
|
---|
| 322 | else {
|
---|
| 323 | ULONG ulDriveNum = 3, ulDriveMap;
|
---|
[2] | 324 |
|
---|
[1394] | 325 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 326 | *pp = (char) (ulDriveNum + '@');
|
---|
| 327 | }
|
---|
| 328 | pp++;
|
---|
| 329 | p += 2;
|
---|
| 330 | break;
|
---|
[2] | 331 |
|
---|
[1162] | 332 | case 'U': /* add path of first list component */
|
---|
[105] | 333 | case 'u':
|
---|
[1394] | 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];
|
---|
[2] | 361 |
|
---|
[1394] | 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;
|
---|
[2] | 383 |
|
---|
[1162] | 384 | case 'P': /* add path of execution */
|
---|
[105] | 385 | case 'p':
|
---|
[1394] | 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];
|
---|
[2] | 413 |
|
---|
[1394] | 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;
|
---|
[2] | 435 |
|
---|
[105] | 436 | case 'D':
|
---|
[1394] | 437 | if (hwndMain) {
|
---|
| 438 | PCNRITEM pci;
|
---|
[2] | 439 |
|
---|
[1394] | 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;
|
---|
[2] | 465 |
|
---|
[105] | 466 | case 'd':
|
---|
[1394] | 467 | if (hwndMain) {
|
---|
| 468 | HENUM henum;
|
---|
| 469 | char retstr[CCHMAXPATH];
|
---|
| 470 | HWND hwndC, hwndDir;
|
---|
| 471 | USHORT id;
|
---|
| 472 | BOOL first = TRUE;
|
---|
[2] | 473 |
|
---|
[1394] | 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;
|
---|
[2] | 514 |
|
---|
[105] | 515 | case '%':
|
---|
[1394] | 516 | *pp = '%';
|
---|
| 517 | pp++;
|
---|
| 518 | p += 2;
|
---|
| 519 | break;
|
---|
[2] | 520 |
|
---|
[105] | 521 | case 'R':
|
---|
| 522 | case 'F':
|
---|
| 523 | case 'A':
|
---|
| 524 | case 'r':
|
---|
| 525 | case 'f':
|
---|
| 526 | case 'a':
|
---|
| 527 | case 'e':
|
---|
[1394] | 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;
|
---|
[2] | 556 |
|
---|
[1394] | 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;
|
---|
[2] | 581 |
|
---|
[1394] | 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;
|
---|
[2] | 610 |
|
---|
[1394] | 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;
|
---|
[2] | 641 |
|
---|
[105] | 642 | default:
|
---|
[1394] | 643 | *pp = *p;
|
---|
| 644 | p++;
|
---|
| 645 | pp++;
|
---|
| 646 | break;
|
---|
[105] | 647 | }
|
---|
| 648 | }
|
---|
[441] | 649 | else {
|
---|
[105] | 650 | *pp = *p;
|
---|
| 651 | pp++;
|
---|
| 652 | p++;
|
---|
| 653 | }
|
---|
| 654 | *pp = 0;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
[2] | 657 | BreakOut:
|
---|
| 658 |
|
---|
[105] | 659 | {
|
---|
| 660 | EXECARGS ex;
|
---|
| 661 | int ret;
|
---|
[2] | 662 |
|
---|
[105] | 663 | memset(&ex, 0, sizeof(EXECARGS));
|
---|
[1505] | 664 | //DbgMsg(pszSrcFile, __LINE__, "env %s", environment);
|
---|
[1498] | 665 | if (!environment) {
|
---|
| 666 | ULONG size;
|
---|
| 667 |
|
---|
| 668 | size = ENVIRONMENT_SIZE;
|
---|
[1505] | 669 | PrfQueryProfileData(fmprof, FM3Str, command, ex.environment, &size);
|
---|
[1498] | 670 | }
|
---|
| 671 | else
|
---|
| 672 | strcpy(ex.environment, environment);
|
---|
[441] | 673 | if (flags & PROMPT) {
|
---|
| 674 | /* allow editing command line */
|
---|
[105] | 675 | ex.flags = (flags & (~PROMPT));
|
---|
| 676 | ex.commandline = commandline;
|
---|
| 677 | strcpy(ex.path, path);
|
---|
| 678 | if (prompt)
|
---|
[1394] | 679 | strcpy(ex.title, prompt);
|
---|
[105] | 680 | ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
|
---|
[1394] | 681 | EXEC_FRAME, &ex);
|
---|
[985] | 682 | if (ret != 1) {
|
---|
[1394] | 683 | free(commandline);
|
---|
| 684 | return (ret == 0) ? -1 : -2;
|
---|
[985] | 685 | }
|
---|
[105] | 686 | }
|
---|
| 687 | else
|
---|
| 688 | ex.flags = flags;
|
---|
[1498] | 689 | //ex.flags &= (~PROMPT); redundant GKY 1-9-10
|
---|
[1497] | 690 | //DbgMsg(pszSrcFile, __LINE__, "Inserted %s", environment);
|
---|
[1014] | 691 | ret = runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path,
|
---|
[1498] | 692 | *ex.environment ? ex.environment : NULL,
|
---|
[1394] | 693 | "%s", commandline);
|
---|
[1039] | 694 | free(commandline);
|
---|
[1014] | 695 | return ret;
|
---|
[105] | 696 | }
|
---|
[2] | 697 | }
|
---|
| 698 |
|
---|
[917] | 699 | /** Run requested app
|
---|
| 700 | * @return application return code or -1 if problem starting app
|
---|
| 701 | */
|
---|
[441] | 702 |
|
---|
[888] | 703 | int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber,
|
---|
[1394] | 704 | char *pszDirectory, char *pszEnvironment,
|
---|
| 705 | char *formatstring,...)
|
---|
[78] | 706 | {
|
---|
[920] | 707 | /** example:
|
---|
[105] | 708 |
|
---|
[2] | 709 | * status = runemf2(SEPARATE | WINDOWED,
|
---|
[888] | 710 | * hwnd, pszCallingFile, __LINE__,
|
---|
[2] | 711 | * NullStr,
|
---|
| 712 | * NULL,
|
---|
| 713 | * "%s /C %s",
|
---|
| 714 | * getenv("COMSPEC"),
|
---|
| 715 | * batchfilename);
|
---|
[105] | 716 | *
|
---|
| 717 | * use (HWND)0 for hwnd if window handle not handy.
|
---|
[888] | 718 | * pszCallingFile and __LINE__ are used to determine caller for easier error tracking
|
---|
[105] | 719 | */
|
---|
[2] | 720 |
|
---|
[920] | 721 | /**
|
---|
[1252] | 722 | * type bitmapped flag -- see systemf.h
|
---|
[2] | 723 | */
|
---|
| 724 |
|
---|
[105] | 725 | va_list parguments;
|
---|
| 726 | int ret = -1;
|
---|
[540] | 727 | RESULTCODES results;
|
---|
[519] | 728 | STARTDATA sdata;
|
---|
[105] | 729 | REQUESTDATA rq;
|
---|
[562] | 730 | ULONG ulSessID;
|
---|
| 731 | ULONG ulLength;
|
---|
| 732 | UINT ctr;
|
---|
| 733 | ULONG ulAppType;
|
---|
[105] | 734 | PID sessPID;
|
---|
| 735 | BOOL wasquote;
|
---|
[1438] | 736 | char *p, *pszPgm, *pszArgs = NULL;
|
---|
| 737 | char szObject[32] = "";
|
---|
| 738 | char szSavedir[CCHMAXPATH];
|
---|
[540] | 739 | BOOL useTermQ = FALSE;
|
---|
| 740 | char szTempdir[CCHMAXPATH];
|
---|
[1369] | 741 | BOOL fNoErrorMsg = FALSE;
|
---|
[540] | 742 |
|
---|
[519] | 743 | typedef struct {
|
---|
| 744 | USHORT usSessID;
|
---|
| 745 | USHORT usRC;
|
---|
| 746 | } TERMINFO;
|
---|
| 747 |
|
---|
[540] | 748 | TERMINFO *pTermInfo;
|
---|
[105] | 749 | BYTE bPriority;
|
---|
| 750 | APIRET rc;
|
---|
[519] | 751 | PIB *ppib;
|
---|
| 752 | TIB *ptib;
|
---|
[2] | 753 |
|
---|
[540] | 754 | // Shared by all threads
|
---|
| 755 | # define TERMQ_BASE_NAME "\\QUEUES\\FM3WAIT"
|
---|
| 756 | static char szTermQName[30];
|
---|
[1480] | 757 | char szTermTemp[30];
|
---|
[540] | 758 | static HQUEUE hTermQ;
|
---|
[1271] | 759 | static HEV hTermQSem;
|
---|
[540] | 760 |
|
---|
| 761 | if (pszDirectory && *pszDirectory) {
|
---|
| 762 | if (!DosQueryPathInfo(pszDirectory,
|
---|
[1394] | 763 | FIL_QUERYFULLNAME,
|
---|
| 764 | szTempdir,
|
---|
| 765 | sizeof(szTempdir)))
|
---|
[540] | 766 | pszDirectory = szTempdir;
|
---|
[105] | 767 | }
|
---|
[2] | 768 |
|
---|
[105] | 769 | if (!hwnd)
|
---|
| 770 | hwnd = HWND_DESKTOP;
|
---|
[2] | 771 |
|
---|
[1628] | 772 | if (xDosAllocMemLow((PVOID)&pszPgm, MaxComLineStrg, pszSrcFile,__LINE__))
|
---|
[1627] | 773 | return -1; //already complained
|
---|
[540] | 774 | *szSavedir = 0;
|
---|
[2] | 775 |
|
---|
[540] | 776 | *pszPgm = 0;
|
---|
[105] | 777 | va_start(parguments,
|
---|
[1394] | 778 | formatstring);
|
---|
[540] | 779 | vsprintf(pszPgm,
|
---|
[1394] | 780 | formatstring,
|
---|
| 781 | parguments);
|
---|
[105] | 782 | va_end(parguments);
|
---|
[906] | 783 |
|
---|
[540] | 784 | if (pszEnvironment) {
|
---|
| 785 | p = &pszEnvironment[strlen(pszEnvironment)] + 1;
|
---|
[105] | 786 | *p = 0;
|
---|
[540] | 787 | p = pszEnvironment;
|
---|
[373] | 788 | while ((p = convert_nl_to_nul(p)) != NULL)
|
---|
| 789 | ; // loop
|
---|
[105] | 790 | }
|
---|
[2] | 791 |
|
---|
[1369] | 792 | if (!stricmp(pszCallingFile, "init.c"))
|
---|
| 793 | fNoErrorMsg = TRUE;
|
---|
| 794 |
|
---|
[540] | 795 | if (!*pszPgm) {
|
---|
[105] | 796 | p = GetCmdSpec(FALSE);
|
---|
[540] | 797 | strcpy(pszPgm, p);
|
---|
| 798 | if (!*pszPgm) {
|
---|
[1398] | 799 | Runtime_Error(pszSrcFile, __LINE__, NULL);
|
---|
[105] | 800 | return -1;
|
---|
[441] | 801 | }
|
---|
[105] | 802 | }
|
---|
[2] | 803 |
|
---|
[540] | 804 | if (*pszPgm) {
|
---|
| 805 | if (*pszPgm == '<' && strchr(pszPgm, '>')) {
|
---|
[441] | 806 | /* is a workplace object */
|
---|
[105] | 807 | HOBJECT hWPSObject;
|
---|
| 808 | char temp;
|
---|
[2] | 809 |
|
---|
[540] | 810 | p = strchr(pszPgm, '>');
|
---|
[105] | 811 | p++;
|
---|
| 812 | temp = *p;
|
---|
[330] | 813 | if (temp) {
|
---|
[1628] | 814 | if (xDosAllocMemLow((PVOID)&pszArgs, MaxComLineStrg * 2, pszSrcFile, __LINE__)) {
|
---|
[1627] | 815 | DosFreeMem(pszPgm);
|
---|
| 816 | return -1; //already complained
|
---|
| 817 | }
|
---|
[330] | 818 | }
|
---|
[105] | 819 | else
|
---|
[1394] | 820 | pszArgs = NULL;
|
---|
[105] | 821 | *p = 0;
|
---|
| 822 | /* Find the handle of the WPS object */
|
---|
[540] | 823 | hWPSObject = WinQueryObject(pszPgm);
|
---|
[105] | 824 | *p = temp;
|
---|
[441] | 825 | if (hWPSObject != NULLHANDLE) {
|
---|
[1394] | 826 | if (pszArgs && *p) {
|
---|
| 827 | sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
|
---|
| 828 | WinSetObjectData(hWPSObject,pszArgs);
|
---|
| 829 | }
|
---|
| 830 | else
|
---|
| 831 | WinSetObjectData(hWPSObject,"OPEN=DEFAULT");
|
---|
| 832 | ret = 0;
|
---|
[105] | 833 | }
|
---|
| 834 | goto ObjectInterrupt;
|
---|
| 835 | }
|
---|
[2] | 836 |
|
---|
[773] | 837 | if ((type & RUNTYPE_MASK) == SYNCHRONOUS ||
|
---|
[1394] | 838 | (type & RUNTYPE_MASK) == ASYNCHRONOUS ||
|
---|
| 839 | (type & RUNTYPE_MASK) == DETACHED)
|
---|
[105] | 840 | {
|
---|
[540] | 841 | strip_lead_char(" \t", pszPgm);
|
---|
| 842 | p = pszPgm;
|
---|
[105] | 843 | wasquote = FALSE;
|
---|
| 844 | while (*p &&
|
---|
[1394] | 845 | (wasquote ||
|
---|
| 846 | (*p != ' ' &&
|
---|
| 847 | *p != '\t')))
|
---|
[105] | 848 | {
|
---|
[1394] | 849 | if (*p == '\"') {
|
---|
| 850 | if (!wasquote) {
|
---|
| 851 | wasquote = TRUE;
|
---|
| 852 | memmove(p,
|
---|
| 853 | p + 1,
|
---|
| 854 | strlen(p));
|
---|
| 855 | while (*p == ' ' ||
|
---|
| 856 | *p == '\t')
|
---|
| 857 | p++;
|
---|
| 858 | }
|
---|
| 859 | else {
|
---|
| 860 | memmove(p,
|
---|
| 861 | p + 1,
|
---|
| 862 | strlen(p));
|
---|
| 863 | break;
|
---|
| 864 | }
|
---|
| 865 | }
|
---|
| 866 | else
|
---|
| 867 | p++;
|
---|
[105] | 868 | }
|
---|
[441] | 869 | if (*p) {
|
---|
[1394] | 870 | *p = 0;
|
---|
| 871 | p++;
|
---|
[105] | 872 | }
|
---|
| 873 | else
|
---|
[1394] | 874 | p = pszPgm;
|
---|
[1162] | 875 | p[strlen(p) + 1] = 0; /* double-terminate args */
|
---|
[540] | 876 | if (*pszPgm) {
|
---|
[1394] | 877 | if (!strchr(pszPgm, '\\') &&
|
---|
| 878 | !strchr(pszPgm, ':') &&
|
---|
| 879 | pszDirectory &&
|
---|
| 880 | *pszDirectory)
|
---|
| 881 | {
|
---|
| 882 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 883 | switch_to(pszDirectory);
|
---|
| 884 | }
|
---|
| 885 | rc = DosQueryAppType(pszPgm,&ulAppType);
|
---|
| 886 | if (!strchr(pszPgm, '\\') &&
|
---|
| 887 | !strchr(pszPgm, ':') &&
|
---|
| 888 | pszDirectory &&
|
---|
| 889 | *pszDirectory)
|
---|
| 890 | switch_to(szSavedir);
|
---|
[1492] | 891 | if (rc) {
|
---|
| 892 | if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
|
---|
| 893 | rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
|
---|
| 894 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
| 895 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
|
---|
| 896 | else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
|
---|
| 897 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
| 898 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
|
---|
| 899 | else
|
---|
| 900 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
|
---|
| 901 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
|
---|
| 902 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
[1394] | 903 | DosFreeMem(pszPgm);
|
---|
| 904 | if (pszArgs)
|
---|
| 905 | DosFreeMem(pszArgs);
|
---|
| 906 | return -1;
|
---|
| 907 | }
|
---|
| 908 | if (ulAppType) {
|
---|
| 909 | if (ulAppType & FAPPTYP_DLL || ulAppType & FAPPTYP_VIRTDRV ||
|
---|
| 910 | ulAppType & FAPPTYP_PHYSDRV || ulAppType & FAPPTYP_PROTDLL)
|
---|
| 911 | {
|
---|
| 912 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
| 913 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
| 914 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 915 | if (pszPgm)
|
---|
| 916 | DosFreeMem(pszPgm);
|
---|
| 917 | if (pszArgs)
|
---|
| 918 | DosFreeMem(pszArgs);
|
---|
| 919 | return -1;
|
---|
| 920 | }
|
---|
| 921 | if (ulAppType & FAPPTYP_DOS || ulAppType & FAPPTYP_WINDOWSREAL ||
|
---|
| 922 | ulAppType & FAPPTYP_WINDOWSPROT || ulAppType & FAPPTYP_WINDOWSPROT31)
|
---|
| 923 | {
|
---|
| 924 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
| 925 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
| 926 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 927 | if (pszPgm)
|
---|
| 928 | DosFreeMem(pszPgm);
|
---|
| 929 | if (pszArgs)
|
---|
| 930 | DosFreeMem(pszArgs);
|
---|
| 931 | return -1;
|
---|
| 932 | }
|
---|
| 933 | }
|
---|
| 934 | memset(&results, 0, sizeof(results));
|
---|
| 935 | if (pszDirectory && *pszDirectory) {
|
---|
| 936 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 937 | switch_to(pszDirectory);
|
---|
| 938 | }
|
---|
| 939 | ret = DosExecPgm(szObject, sizeof(szObject),
|
---|
| 940 | ((type & RUNTYPE_MASK) == ASYNCHRONOUS ? EXEC_ASYNC : 0) +
|
---|
| 941 | ((type & RUNTYPE_MASK) == DETACHED ? EXEC_BACKGROUND : 0),
|
---|
| 942 | pszPgm, pszEnvironment, &results, pszPgm);
|
---|
| 943 | if (pszDirectory && *pszDirectory)
|
---|
| 944 | switch_to(szSavedir);
|
---|
| 945 | if (ret && !fNoErrorMsg) {
|
---|
| 946 | Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
|
---|
| 947 | GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm,
|
---|
| 948 | pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 949 | }
|
---|
[105] | 950 | }
|
---|
| 951 | }
|
---|
[441] | 952 | else {
|
---|
[519] | 953 | if (~type & FULLSCREEN)
|
---|
[1394] | 954 | type |= WINDOWED;
|
---|
[1628] | 955 | if (xDosAllocMemLow((PVOID) &pszArgs, MaxComLineStrg * 2, pszSrcFile, __LINE__)) {
|
---|
[1394] | 956 | DosFreeMem(pszPgm);
|
---|
[1627] | 957 | return -1; //already complained
|
---|
[105] | 958 | }
|
---|
[540] | 959 | *pszArgs = 0;
|
---|
| 960 | memset(&sdata, 0, sizeof(sdata));
|
---|
| 961 | strip_lead_char(" \t", pszPgm);
|
---|
| 962 | p = pszPgm;
|
---|
[105] | 963 | wasquote = FALSE;
|
---|
[441] | 964 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
[1394] | 965 | if (*p == '\"') {
|
---|
| 966 | if (!wasquote) {
|
---|
| 967 | wasquote = TRUE;
|
---|
| 968 | memmove(p, p + 1, strlen(p));
|
---|
| 969 | while (*p == ' ' || *p == '\t')
|
---|
| 970 | p++;
|
---|
| 971 | }
|
---|
| 972 | else {
|
---|
| 973 | memmove(p, p + 1, strlen(p));
|
---|
| 974 | break;
|
---|
| 975 | }
|
---|
| 976 | }
|
---|
| 977 | else
|
---|
| 978 | p++;
|
---|
[540] | 979 | } // while
|
---|
[441] | 980 | if (*p) {
|
---|
[1394] | 981 | *p = 0;
|
---|
| 982 | p++;
|
---|
[105] | 983 | }
|
---|
| 984 | else
|
---|
[1394] | 985 | p = NullStr;
|
---|
[105] | 986 | if (*p)
|
---|
[1394] | 987 | strcpy(pszArgs, p);
|
---|
[2] | 988 |
|
---|
[540] | 989 | p = strrchr(pszPgm, '.');
|
---|
[441] | 990 | if (p) {
|
---|
[1394] | 991 | char temp[CCHMAXPATH + 1];
|
---|
[2] | 992 |
|
---|
[1398] | 993 | if (!stricmp(p, PCSZ_DOTBAT)) {
|
---|
| 994 | if (!fProtectOnly) {
|
---|
| 995 | strcpy(temp, pszPgm);
|
---|
| 996 | strcpy(pszPgm, pszArgs);
|
---|
| 997 | strcpy(pszArgs, "/C ");
|
---|
| 998 | strcat(pszArgs, temp);
|
---|
| 999 | strcat(pszArgs, " ");
|
---|
| 1000 | strcat(pszArgs, pszPgm);
|
---|
| 1001 | strcpy(pszPgm, GetCmdSpec(TRUE)); // DOS
|
---|
| 1002 | }
|
---|
| 1003 | else
|
---|
| 1004 | saymsg(MB_OK,
|
---|
| 1005 | HWND_DESKTOP,
|
---|
| 1006 | NullStr,
|
---|
| 1007 | GetPString(IDS_NOTPROTECTONLYEXE),
|
---|
| 1008 | pszPgm);
|
---|
[1394] | 1009 | }
|
---|
[1398] | 1010 | else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
|
---|
[1394] | 1011 | // Assume 4OS2 is BTM
|
---|
| 1012 | strcpy(temp, pszPgm);
|
---|
| 1013 | strcpy(pszPgm, pszArgs);
|
---|
| 1014 | strcpy(pszArgs, "/C ");
|
---|
| 1015 | strcat(pszArgs, temp);
|
---|
| 1016 | strcat(pszArgs, " ");
|
---|
| 1017 | strcat(pszArgs, pszPgm);
|
---|
| 1018 | strcpy(pszPgm, GetCmdSpec(FALSE)); // OS/2
|
---|
| 1019 | }
|
---|
[105] | 1020 | }
|
---|
[2] | 1021 |
|
---|
[888] | 1022 | // goddamned OS/2 limit
|
---|
[2] | 1023 |
|
---|
[540] | 1024 | if (strlen(pszPgm) + strlen(pszArgs) > 1024)
|
---|
[1394] | 1025 | pszArgs[1024 - strlen(pszPgm)] = 0;
|
---|
[2] | 1026 |
|
---|
[540] | 1027 | if (!strchr(pszPgm, '\\') &&
|
---|
[1394] | 1028 | !strchr(pszPgm, ':') &&
|
---|
| 1029 | pszDirectory &&
|
---|
| 1030 | *pszDirectory)
|
---|
[105] | 1031 | {
|
---|
[1394] | 1032 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 1033 | switch_to(pszDirectory);
|
---|
[105] | 1034 | }
|
---|
[562] | 1035 | rc = DosQueryAppType(pszPgm,&ulAppType);
|
---|
[540] | 1036 | if (!strchr(pszPgm, '\\') &&
|
---|
[1394] | 1037 | !strchr(pszPgm, ':') &&
|
---|
| 1038 | pszDirectory &&
|
---|
| 1039 | *pszDirectory)
|
---|
[1492] | 1040 | switch_to(szSavedir);
|
---|
[917] | 1041 | if (rc) {
|
---|
[1492] | 1042 | if (rc == ERROR_FILE_NOT_FOUND || rc == ERROR_PATH_NOT_FOUND ||
|
---|
| 1043 | rc == ERROR_INVALID_EXE_SIGNATURE || rc == ERROR_EXE_MARKED_INVALID)
|
---|
| 1044 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
| 1045 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT2), pszPgm);
|
---|
| 1046 | else if (rc == ERROR_INVALID_DRIVE || rc == ERROR_DRIVE_LOCKED)
|
---|
| 1047 | saymsg(MB_OK, HWND_DESKTOP, NullStr,
|
---|
| 1048 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT3), pszPgm);
|
---|
| 1049 | else
|
---|
| 1050 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
|
---|
| 1051 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
|
---|
| 1052 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
[1394] | 1053 | DosFreeMem(pszPgm);
|
---|
| 1054 | if (pszArgs)
|
---|
| 1055 | DosFreeMem(pszArgs);
|
---|
| 1056 | return -1;
|
---|
[105] | 1057 | }
|
---|
[2] | 1058 |
|
---|
[562] | 1059 | if (ulAppType) {
|
---|
[1394] | 1060 | if (ulAppType & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL))
|
---|
| 1061 | {
|
---|
| 1062 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
| 1063 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
| 1064 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 1065 | DosFreeMem(pszPgm);
|
---|
| 1066 | if (pszArgs)
|
---|
| 1067 | DosFreeMem(pszArgs);
|
---|
| 1068 | return -1;
|
---|
| 1069 | }
|
---|
| 1070 | ulAppType &= ~FAPPTYP_BOUND;
|
---|
| 1071 | if (ulAppType & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
| 1072 | {
|
---|
| 1073 | if (ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
| 1074 | {
|
---|
| 1075 | if (~type & FULLSCREEN &&
|
---|
| 1076 | ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
| 1077 | {
|
---|
| 1078 | ret = RunSeamless(pszPgm, pszArgs, hwnd);
|
---|
| 1079 | if (pszPgm)
|
---|
| 1080 | DosFreeMem(pszPgm);
|
---|
| 1081 | if (pszArgs)
|
---|
| 1082 | DosFreeMem(pszArgs);
|
---|
| 1083 | return ret ? 0 : -1;
|
---|
| 1084 | }
|
---|
| 1085 | else {
|
---|
| 1086 | strcat(pszPgm, " ");
|
---|
| 1087 | strcat(pszPgm, pszArgs);
|
---|
| 1088 | *pszArgs = 0;
|
---|
| 1089 | if (ulAppType & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31))
|
---|
| 1090 | strcat(pszArgs, "/3 ");
|
---|
| 1091 | strcat(pszArgs, pszPgm);
|
---|
| 1092 | strcpy(pszPgm, "WINOS2.COM");
|
---|
| 1093 | }
|
---|
| 1094 | }
|
---|
| 1095 | else {
|
---|
| 1096 | if (~type & FULLSCREEN) {
|
---|
| 1097 | type |= WINDOWED;
|
---|
| 1098 | ulAppType = SSF_TYPE_WINDOWEDVDM;
|
---|
| 1099 | }
|
---|
| 1100 | else {
|
---|
| 1101 | type &= ~WINDOWED;
|
---|
| 1102 | ulAppType = SSF_TYPE_VDM;
|
---|
| 1103 | }
|
---|
| 1104 | }
|
---|
| 1105 | }
|
---|
| 1106 | else if (ulAppType & FAPPTYP_32BIT) {
|
---|
| 1107 | ulAppType &= ~FAPPTYP_32BIT;
|
---|
| 1108 | if (ulAppType == FAPPTYP_WINDOWAPI)
|
---|
| 1109 | ulAppType = SSF_TYPE_PM;
|
---|
| 1110 | else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
|
---|
| 1111 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 1112 | else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
| 1113 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
| 1114 | type &= ~WINDOWED;
|
---|
| 1115 | type |= FULLSCREEN;
|
---|
| 1116 | }
|
---|
| 1117 | else /* ? */
|
---|
| 1118 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 1119 | }
|
---|
| 1120 | else if (ulAppType == FAPPTYP_WINDOWAPI)
|
---|
| 1121 | ulAppType = SSF_TYPE_PM;
|
---|
| 1122 | else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
|
---|
| 1123 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 1124 | else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
| 1125 | type &= ~WINDOWED;
|
---|
| 1126 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
| 1127 | }
|
---|
| 1128 | else
|
---|
| 1129 | ulAppType = SSF_TYPE_DEFAULT;
|
---|
| 1130 | if ((type & FULLSCREEN || ~type & WINDOWED) &&
|
---|
| 1131 | ulAppType == SSF_TYPE_WINDOWABLEVIO)
|
---|
| 1132 | {
|
---|
| 1133 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
| 1134 | }
|
---|
| 1135 | // fixme parens?
|
---|
| 1136 | else if (type & FULLSCREEN ||
|
---|
| 1137 | (type & WINDOWED && ulAppType == SSF_TYPE_WINDOWEDVDM))
|
---|
| 1138 | {
|
---|
| 1139 | ulAppType = SSF_TYPE_VDM;
|
---|
| 1140 | }
|
---|
[105] | 1141 | }
|
---|
[562] | 1142 | if (ulAppType == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) {
|
---|
[1394] | 1143 | type &= ~SEPARATEKEEP;
|
---|
| 1144 | type |= SEPARATE;
|
---|
[105] | 1145 | }
|
---|
[2] | 1146 |
|
---|
[519] | 1147 | DosGetInfoBlocks(&ptib, &ppib);
|
---|
| 1148 |
|
---|
[540] | 1149 | if (~type & WAIT)
|
---|
[1394] | 1150 | useTermQ = FALSE;
|
---|
[519] | 1151 | else {
|
---|
[1394] | 1152 | rc = 0;
|
---|
| 1153 | DosEnterCritSec();
|
---|
| 1154 | if (!hTermQ) {
|
---|
| 1155 | // Create term queue and event semaphore just once
|
---|
| 1156 | sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid);
|
---|
| 1157 | rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName);
|
---|
| 1158 | if (rc) {
|
---|
| 1159 | hTermQ = (HQUEUE)0; // Try to survive
|
---|
| 1160 | DosExitCritSec();
|
---|
| 1161 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
|
---|
| 1162 | }
|
---|
| 1163 | else {
|
---|
| 1164 | rc = DosCreateEventSem(NULL,(PHEV)&hTermQSem,0,FALSE);
|
---|
| 1165 | if (rc) {
|
---|
| 1166 | hTermQSem = (HEV)0; // Try to survive
|
---|
| 1167 | DosCloseQueue(hTermQ);
|
---|
| 1168 | hTermQ = (HQUEUE)0; // Try to survive
|
---|
| 1169 | DosExitCritSec();
|
---|
[1450] | 1170 | Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__, PCSZ_DOSCREATEEVENTSEM);
|
---|
[1394] | 1171 | }
|
---|
| 1172 | // if (!rc) fprintf(stderr,"%s %d qcreated ptib %x hTermQ %x\n",__FILE__, __LINE__,ptib,hTermQ);
|
---|
| 1173 | }
|
---|
[1439] | 1174 | } // if 1st time
|
---|
| 1175 | useTermQ = hTermQ && hTermQSem;
|
---|
[1394] | 1176 | if (!rc)
|
---|
[1439] | 1177 | DosExitCritSec();
|
---|
[540] | 1178 | } // if wait
|
---|
[562] | 1179 |
|
---|
| 1180 | memset(&sdata,0,sizeof(sdata));
|
---|
[519] | 1181 | sdata.Length = sizeof(sdata);
|
---|
[562] | 1182 | sdata.Related = type & (WAIT | CHILD) ? SSF_RELATED_CHILD :
|
---|
[1394] | 1183 | SSF_RELATED_INDEPENDENT;
|
---|
[519] | 1184 | sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE;
|
---|
| 1185 | sdata.TraceOpt = SSF_TRACEOPT_NONE;
|
---|
[540] | 1186 | sdata.PgmName = pszPgm;
|
---|
[562] | 1187 | if (*pszArgs)
|
---|
[1394] | 1188 | sdata.PgmInputs = (PBYTE)pszArgs;
|
---|
[1480] | 1189 | if (useTermQ) {
|
---|
| 1190 | strcpy(szTermTemp, szTermQName);
|
---|
| 1191 | sdata.TermQ = (PBYTE)szTermTemp;
|
---|
| 1192 | }
|
---|
[1321] | 1193 | sdata.Environment = (PBYTE)pszEnvironment;
|
---|
[519] | 1194 | sdata.InheritOpt = SSF_INHERTOPT_PARENT;
|
---|
[1533] | 1195 | sdata.SessionType = (USHORT) ulAppType;
|
---|
[540] | 1196 | sdata.ObjectBuffer = szObject;
|
---|
| 1197 | sdata.ObjectBuffLen = sizeof(szObject);
|
---|
[773] | 1198 | if ((type & RUNTYPE_MASK) == SEPARATEKEEP)
|
---|
[1394] | 1199 | sdata.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
|
---|
[562] | 1200 | if (type & MAXIMIZED)
|
---|
[1394] | 1201 | sdata.PgmControl |= SSF_CONTROL_MAXIMIZE;
|
---|
[562] | 1202 | if (type & MINIMIZED)
|
---|
[1394] | 1203 | sdata.PgmControl |= SSF_CONTROL_MINIMIZE;
|
---|
[562] | 1204 | if (type & INVISIBLE)
|
---|
[1394] | 1205 | sdata.PgmControl |= SSF_CONTROL_INVISIBLE;
|
---|
[562] | 1206 |
|
---|
[540] | 1207 | if (pszDirectory && *pszDirectory) {
|
---|
[1394] | 1208 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 1209 | switch_to(pszDirectory);
|
---|
[105] | 1210 | }
|
---|
[519] | 1211 | ret = DosStartSession(&sdata, &ulSessID, &sessPID);
|
---|
[562] | 1212 |
|
---|
[563] | 1213 |
|
---|
[540] | 1214 | if (pszDirectory && *pszDirectory)
|
---|
[1394] | 1215 | switch_to(szSavedir);
|
---|
[562] | 1216 |
|
---|
[330] | 1217 | if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
|
---|
[1394] | 1218 | if (!fNoErrorMsg)
|
---|
[1439] | 1219 | Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
|
---|
[1394] | 1220 | GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs,
|
---|
[1439] | 1221 | pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
[330] | 1222 | }
|
---|
[441] | 1223 | else if (type & WAIT) {
|
---|
[1394] | 1224 | if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
| 1225 | ShowSession(hwnd, sessPID);
|
---|
[2] | 1226 |
|
---|
[1394] | 1227 | if (!useTermQ) {
|
---|
| 1228 | STATUSDATA sd;
|
---|
[2] | 1229 |
|
---|
[1394] | 1230 | memset(&sd, 0, sizeof(sd));
|
---|
| 1231 | sd.Length = (USHORT) sizeof(sd);
|
---|
| 1232 | sd.SelectInd = SET_SESSION_UNCHANGED;
|
---|
| 1233 | sd.BondInd = SET_SESSION_UNCHANGED;
|
---|
| 1234 | for (ctr = 0;; ctr++)
|
---|
| 1235 | {
|
---|
[1439] | 1236 | DosSleep(50);//05 Aug 07 GKY 200
|
---|
[1394] | 1237 | if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished)
|
---|
| 1238 | break;
|
---|
| 1239 | if (ctr > 10) {
|
---|
| 1240 | ShowSession(hwnd, sessPID); // Show every 2 seconds
|
---|
| 1241 | ctr = 0;
|
---|
| 1242 | }
|
---|
| 1243 | }
|
---|
| 1244 | }
|
---|
| 1245 | else {
|
---|
| 1246 | for (ctr = 0;; ctr++)
|
---|
| 1247 | {
|
---|
| 1248 | if (ctr < 20) {
|
---|
| 1249 | rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
[1439] | 1250 | DCWW_NOWAIT, &bPriority, hTermQSem);
|
---|
[1394] | 1251 | if (rc == ERROR_QUE_EMPTY) {
|
---|
| 1252 | DosSleep(50);//05 Aug 07 GKY 100
|
---|
| 1253 | continue;
|
---|
| 1254 | }
|
---|
| 1255 | }
|
---|
| 1256 | else {
|
---|
[1439] | 1257 | if (ctr == 20) {
|
---|
[1394] | 1258 | ShowSession(hwnd, sessPID); // Show long running session
|
---|
[1439] | 1259 | }
|
---|
[1394] | 1260 | rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
| 1261 | DCWW_WAIT, &bPriority, 0);
|
---|
| 1262 | }
|
---|
[540] | 1263 |
|
---|
[1394] | 1264 | if (rc) {
|
---|
| 1265 | // Oh heck
|
---|
| 1266 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
|
---|
| 1267 | DosSleep(100);//05 Aug 07 GKY 500
|
---|
| 1268 | continue;
|
---|
| 1269 | }
|
---|
[540] | 1270 |
|
---|
[1394] | 1271 | // printf("%s %d DosReadQueue thread 0x%x sess %u sessRC %u rq.pid 0x%x rq.data 0x%x\n",
|
---|
| 1272 | // __FILE__, __LINE__,ptib->tib_ordinal,pTermInfo->usSessID,pTermInfo->usRC,rq.pid, rq.ulData); fflush(stdout);
|
---|
[562] | 1273 |
|
---|
[1394] | 1274 | if (pTermInfo->usSessID == ulSessID)
|
---|
| 1275 | break; // Our session is done
|
---|
[540] | 1276 |
|
---|
[1394] | 1277 | // Requeue session for other thread
|
---|
| 1278 | {
|
---|
| 1279 | static ULONG ulLastSessID;
|
---|
| 1280 | // printf("%s %d requeue thread 0x%x our sess %u term sess %u term rc %u\n",
|
---|
| 1281 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,pTermInfo->usSessID,pTermInfo->usRC); fflush(stdout);
|
---|
| 1282 | // fixme to be gone when no longer needed for debug?
|
---|
| 1283 | if (ulLastSessID) {
|
---|
| 1284 | DosSleep(100);//05 Aug 07 GKY 500
|
---|
| 1285 | ulLastSessID = pTermInfo->usSessID;
|
---|
| 1286 | }
|
---|
| 1287 | // requeue term report for other thread and do not free yet
|
---|
| 1288 | rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority);
|
---|
| 1289 | if (rc)
|
---|
| 1290 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue");
|
---|
| 1291 | DosSleep(50); //05 Aug 07 GKY 100 // Let other thread see queue entry
|
---|
| 1292 | }
|
---|
| 1293 | } // for
|
---|
[540] | 1294 |
|
---|
[1394] | 1295 | ret = pTermInfo->usRC == 0; // Set 1 if rc 0 else 0
|
---|
| 1296 | // printf("%s %d thread 0x%x term for sess %u\n",
|
---|
| 1297 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID);fflush(stdout);
|
---|
| 1298 | DosFreeMem(pTermInfo);
|
---|
| 1299 | }
|
---|
[540] | 1300 | } // if wait
|
---|
[105] | 1301 | else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
[1394] | 1302 | ShowSession(hwnd, sessPID);
|
---|
[105] | 1303 | }
|
---|
| 1304 | }
|
---|
[2] | 1305 |
|
---|
| 1306 | ObjectInterrupt:
|
---|
| 1307 |
|
---|
[540] | 1308 | if (pszPgm)
|
---|
| 1309 | DosFreeMem(pszPgm);
|
---|
| 1310 | if (pszArgs)
|
---|
| 1311 | DosFreeMem(pszArgs);
|
---|
[562] | 1312 |
|
---|
[105] | 1313 | return ret;
|
---|
[2] | 1314 | }
|
---|
| 1315 |
|
---|
[519] | 1316 | //== Exec() Start application with WinStartApp ==
|
---|
[1193] | 1317 | #if 0 // JBS 11 Sep 08
|
---|
[105] | 1318 | HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
[1394] | 1319 | PROGTYPE *progt, ULONG fl, char *formatstring,...)
|
---|
[78] | 1320 | {
|
---|
[105] | 1321 | PROGDETAILS pgd;
|
---|
[2] | 1322 | register char *p;
|
---|
[105] | 1323 | char *parameters = NULL, *executable = NULL;
|
---|
[519] | 1324 | HAPP happ = (HAPP)0;
|
---|
[105] | 1325 | ULONG ulOptions = SAF_INSTALLEDCMDLINE;
|
---|
| 1326 | BOOL wasquote;
|
---|
| 1327 | va_list parguments;
|
---|
[2] | 1328 |
|
---|
[105] | 1329 | if (child)
|
---|
[2] | 1330 | ulOptions |= SAF_STARTCHILDAPP;
|
---|
| 1331 |
|
---|
[985] | 1332 | executable = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
[330] | 1333 | if (executable) {
|
---|
[105] | 1334 | va_start(parguments, formatstring);
|
---|
| 1335 | vsprintf(executable, formatstring, parguments);
|
---|
[2] | 1336 | va_end(parguments);
|
---|
[105] | 1337 | strip_lead_char(" \t", executable);
|
---|
[441] | 1338 | if (*executable) {
|
---|
[985] | 1339 | parameters = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
[441] | 1340 | if (parameters) {
|
---|
[1394] | 1341 | p = executable;
|
---|
| 1342 | wasquote = FALSE;
|
---|
| 1343 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
| 1344 | if (*p == '\"') {
|
---|
| 1345 | if (!wasquote) {
|
---|
| 1346 | wasquote = TRUE;
|
---|
| 1347 | memmove(p, p + 1, strlen(p));
|
---|
| 1348 | while (*p == ' ' || *p == '\t')
|
---|
| 1349 | p++;
|
---|
| 1350 | }
|
---|
| 1351 | else {
|
---|
| 1352 | memmove(p, p + 1, strlen(p));
|
---|
| 1353 | break;
|
---|
| 1354 | }
|
---|
| 1355 | }
|
---|
| 1356 | else
|
---|
| 1357 | p++;
|
---|
| 1358 | }
|
---|
| 1359 | if (*p) {
|
---|
| 1360 | *p = 0;
|
---|
| 1361 | p++;
|
---|
| 1362 | }
|
---|
| 1363 | else
|
---|
| 1364 | p = NullStr;
|
---|
| 1365 | if (*p)
|
---|
| 1366 | strcpy(parameters, p);
|
---|
[2] | 1367 |
|
---|
[1398] | 1368 | if (p && (!stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTCMD) ||
|
---|
| 1369 | !stricmp(p, PCSZ_DOTBTM))) {
|
---|
[1394] | 1370 | char *temp;
|
---|
[2] | 1371 |
|
---|
[1394] | 1372 | temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
|
---|
| 1373 | if (temp) {
|
---|
[1398] | 1374 | if (!stricmp(p, PCSZ_DOTBAT)) {
|
---|
| 1375 | if (!fProtectOnly) {
|
---|
| 1376 | strcpy(temp, executable);
|
---|
| 1377 | strcpy(executable, parameters);
|
---|
| 1378 | strcpy(parameters, "/C ");
|
---|
| 1379 | strcat(parameters, temp);
|
---|
| 1380 | strcat(parameters, " ");
|
---|
| 1381 | strcat(parameters, executable);
|
---|
[1475] | 1382 | strcpy(executable, GetCmdSpec(TRUE)); //DOS
|
---|
[1398] | 1383 | }
|
---|
| 1384 | else
|
---|
| 1385 | saymsg(MB_OK,
|
---|
| 1386 | HWND_DESKTOP,
|
---|
| 1387 | NullStr,
|
---|
| 1388 | GetPString(IDS_NOTPROTECTONLYEXE),
|
---|
| 1389 | filename);
|
---|
[1394] | 1390 | }
|
---|
[1398] | 1391 | else if (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM)) {
|
---|
[1394] | 1392 | strcpy(temp, executable);
|
---|
| 1393 | strcpy(executable, parameters);
|
---|
| 1394 | strcpy(parameters, "/C ");
|
---|
| 1395 | strcat(parameters, temp);
|
---|
| 1396 | strcat(parameters, " ");
|
---|
| 1397 | strcat(parameters, executable);
|
---|
| 1398 | strcpy(executable, GetCmdSpec(FALSE));
|
---|
| 1399 | }
|
---|
| 1400 | free(temp);
|
---|
| 1401 | }
|
---|
| 1402 | }
|
---|
[2] | 1403 |
|
---|
[1394] | 1404 | memset(&pgd, 0, sizeof(pgd));
|
---|
| 1405 | pgd.Length = sizeof(pgd);
|
---|
| 1406 | pgd.progt = *progt;
|
---|
| 1407 | pgd.swpInitial.fl = fl;
|
---|
| 1408 | pgd.pszEnvironment = env;
|
---|
| 1409 | pgd.pszStartupDir = startdir;
|
---|
| 1410 | pgd.pszParameters = *parameters ? parameters : NULL;
|
---|
| 1411 | pgd.pszExecutable = executable;
|
---|
| 1412 | pgd.swpInitial.hwndInsertBehind = HWND_TOP;
|
---|
| 1413 | happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions);
|
---|
| 1414 | free(parameters);
|
---|
[2] | 1415 | }
|
---|
| 1416 | }
|
---|
[1039] | 1417 | free(executable);
|
---|
[2] | 1418 | }
|
---|
| 1419 | return happ;
|
---|
| 1420 | }
|
---|
[1162] | 1421 | #endif
|
---|
[920] | 1422 | #pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
|
---|