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