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