[78] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: systemf.c 519 2006-11-03 20:23:21Z root $
|
---|
| 5 |
|
---|
| 6 | System Interfaces
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
---|
[330] | 9 | Copyright (c) 2003, 2006 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
|
---|
[78] | 18 |
|
---|
| 19 | ***********************************************************************/
|
---|
| 20 |
|
---|
[2] | 21 | #define INCL_WIN
|
---|
| 22 | #define INCL_WINERRORS
|
---|
| 23 | #define INCL_DOS
|
---|
| 24 | #define INCL_DOSERRORS
|
---|
[330] | 25 | #include <os2.h>
|
---|
[2] | 26 |
|
---|
| 27 | #include <stdlib.h>
|
---|
| 28 | #include <stdio.h>
|
---|
| 29 | #include <stdarg.h>
|
---|
| 30 | #include <string.h>
|
---|
| 31 | #include <ctype.h>
|
---|
| 32 | #include <time.h>
|
---|
[330] | 33 |
|
---|
[2] | 34 | #include "fm3dll.h"
|
---|
| 35 | #include "fm3dlg.h"
|
---|
| 36 | #include "fm3str.h"
|
---|
| 37 |
|
---|
[330] | 38 | static PSZ pszSrcFile = __FILE__;
|
---|
| 39 |
|
---|
[2] | 40 | #pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
|
---|
| 41 |
|
---|
[105] | 42 | #define MAXSTRG (4096) /* used to build command line strings */
|
---|
[2] | 43 |
|
---|
[519] | 44 | //== ShowSession() bring session for foreground ==
|
---|
[2] | 45 |
|
---|
[105] | 46 | BOOL ShowSession(HWND hwnd, PID pid)
|
---|
[78] | 47 | {
|
---|
[105] | 48 | HSWITCH hswitch;
|
---|
| 49 | SWCNTRL swctl;
|
---|
| 50 | ULONG rc;
|
---|
[2] | 51 |
|
---|
[519] | 52 | hswitch = WinQuerySwitchHandle(pid ? (HWND)0 : hwnd, pid);
|
---|
[441] | 53 | if (hswitch) {
|
---|
[105] | 54 | rc = WinQuerySwitchEntry(hswitch, &swctl);
|
---|
[441] | 55 | if (!rc) {
|
---|
[105] | 56 | if (swctl.idProcess == pid && swctl.uchVisibility == SWL_VISIBLE)
|
---|
| 57 | rc = WinSwitchToProgram(hswitch);
|
---|
| 58 | if (!rc)
|
---|
| 59 | return TRUE;
|
---|
[78] | 60 | // else saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Failed: %lu/%lx",rc,rc);
|
---|
[2] | 61 |
|
---|
[105] | 62 | }
|
---|
| 63 | }
|
---|
| 64 | return FALSE;
|
---|
[2] | 65 | }
|
---|
| 66 |
|
---|
[519] | 67 | //== ExecOnList() Invoke runemf2 for command and file/directory list ==
|
---|
| 68 |
|
---|
[105] | 69 | int ExecOnList(HWND hwnd, char *command, int flags, char *tpath,
|
---|
| 70 | char **list, char *prompt)
|
---|
[78] | 71 | {
|
---|
[105] | 72 | /* executes the command once for all files in list */
|
---|
[2] | 73 |
|
---|
[105] | 74 | char path[CCHMAXPATH], commandline[2048], modpath[CCHMAXPATH], listfile[CCHMAXPATH],
|
---|
| 75 | *p, *pp, drive, *file, *ext, *dot;
|
---|
[2] | 76 | register int x;
|
---|
[105] | 77 | BOOL spaces;
|
---|
[2] | 78 |
|
---|
[441] | 79 | if (!command || !*command) {
|
---|
| 80 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
---|
[105] | 81 | return -1;
|
---|
[441] | 82 | }
|
---|
[2] | 83 | *listfile = 0;
|
---|
[123] | 84 | bstrip(command);
|
---|
[2] | 85 |
|
---|
| 86 | *path = 0;
|
---|
[105] | 87 | if (tpath && *tpath)
|
---|
| 88 | strcpy(path, tpath);
|
---|
[441] | 89 | else if (*command != '<' || !strchr(command, '>')) {
|
---|
[105] | 90 | strcpy(path, command + (*command == '"'));
|
---|
| 91 | if (*command == '\"')
|
---|
| 92 | p = strchr(path, '\"');
|
---|
[2] | 93 | else
|
---|
[105] | 94 | p = strchr(path, ' ');
|
---|
| 95 | if (p)
|
---|
[2] | 96 | *p = 0;
|
---|
[105] | 97 | p = strrchr(path, '\\');
|
---|
| 98 | if (!p)
|
---|
| 99 | p = strrchr(path, ':');
|
---|
[441] | 100 | if (p) {
|
---|
| 101 | if (*p == ':') {
|
---|
[105] | 102 | p++;
|
---|
| 103 | *p = '\\';
|
---|
| 104 | p++;
|
---|
[2] | 105 | }
|
---|
| 106 | *p = 0;
|
---|
| 107 | }
|
---|
| 108 | else
|
---|
| 109 | *path = 0;
|
---|
| 110 | }
|
---|
[441] | 111 | if (!*path) {
|
---|
[105] | 112 | if (list && list[0])
|
---|
| 113 | strcpy(path, list[0]);
|
---|
| 114 | p = strrchr(path, '\\');
|
---|
| 115 | if (!p)
|
---|
| 116 | p = strrchr(path, ':');
|
---|
[441] | 117 | if (p) {
|
---|
| 118 | if (*p == ':') {
|
---|
[105] | 119 | p++;
|
---|
| 120 | *p = '\\';
|
---|
| 121 | p++;
|
---|
[2] | 122 | }
|
---|
| 123 | *p = 0;
|
---|
| 124 | }
|
---|
| 125 | else
|
---|
| 126 | *path = 0;
|
---|
| 127 | }
|
---|
| 128 | *modpath = 0;
|
---|
[105] | 129 | if (list && list[0])
|
---|
| 130 | strcpy(modpath, list[0]);
|
---|
| 131 | p = strrchr(modpath, '\\');
|
---|
| 132 | if (!p)
|
---|
| 133 | p = strrchr(modpath, ':');
|
---|
[441] | 134 | if (p) {
|
---|
| 135 | if (*p == ':') {
|
---|
[2] | 136 | p++;
|
---|
| 137 | *p = '\\';
|
---|
| 138 | p++;
|
---|
| 139 | }
|
---|
| 140 | *p = 0;
|
---|
| 141 | }
|
---|
| 142 | else
|
---|
| 143 | *modpath = 0;
|
---|
[105] | 144 | if (!*modpath)
|
---|
| 145 | strcpy(modpath, path);
|
---|
| 146 | if (*path)
|
---|
[2] | 147 | MakeFullName(path);
|
---|
[105] | 148 | if (*modpath)
|
---|
[2] | 149 | MakeFullName(modpath);
|
---|
[105] | 150 | if (IsFullName(path))
|
---|
| 151 | drive = toupper(*path);
|
---|
| 152 | else
|
---|
| 153 | drive = 0;
|
---|
[2] | 154 |
|
---|
[105] | 155 | p = command; // substitue for special % sequences
|
---|
[2] | 156 |
|
---|
[105] | 157 | pp = commandline;
|
---|
| 158 | *commandline = 0;
|
---|
[441] | 159 | while (*p) {
|
---|
| 160 | if (*p == '%') {
|
---|
| 161 | switch (*(p + 1)) {
|
---|
[105] | 162 | case '!': /* write list to file, add filename */
|
---|
[441] | 163 | if (list) {
|
---|
| 164 | if (!*listfile) {
|
---|
[105] | 165 | FILE *fp;
|
---|
[2] | 166 |
|
---|
[105] | 167 | save_dir2(listfile);
|
---|
| 168 | if (listfile[strlen(listfile) - 1] != '\\')
|
---|
| 169 | strcat(listfile, "\\");
|
---|
| 170 | sprintf(&listfile[strlen(listfile)], "%s%03x",
|
---|
| 171 | LISTTEMPROOT, (clock() & 4095L));
|
---|
[330] | 172 | fp = xfopen(listfile, "w",pszSrcFile,__LINE__);
|
---|
[441] | 173 | if (fp) {
|
---|
[105] | 174 | for (x = 0; list[x]; x++)
|
---|
| 175 | {
|
---|
| 176 | fputs(list[x], fp);
|
---|
| 177 | if (list[x + 1])
|
---|
| 178 | fputc('\n', fp);
|
---|
| 179 | }
|
---|
| 180 | fclose(fp);
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | strcpy(pp, listfile);
|
---|
| 184 | pp += strlen(listfile);
|
---|
| 185 | }
|
---|
| 186 | p += 2;
|
---|
| 187 | break;
|
---|
[2] | 188 |
|
---|
[105] | 189 | case 'c': /* add name of command processor */
|
---|
| 190 | {
|
---|
| 191 | char *env = GetCmdSpec(FALSE);
|
---|
[2] | 192 |
|
---|
[441] | 193 | if (needs_quoting(env) && !strchr(env, '\"')) {
|
---|
[105] | 194 | *pp = '\"';
|
---|
| 195 | pp++;
|
---|
| 196 | spaces = TRUE;
|
---|
| 197 | }
|
---|
| 198 | else
|
---|
| 199 | spaces = FALSE;
|
---|
| 200 | strcpy(pp, env);
|
---|
| 201 | p += 2;
|
---|
| 202 | pp += strlen(env);
|
---|
[441] | 203 | if (spaces) {
|
---|
[105] | 204 | *pp = '\"';
|
---|
| 205 | pp++;
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | break;
|
---|
[2] | 209 |
|
---|
[105] | 210 | case 't': /* add Target directory */
|
---|
[441] | 211 | if (needs_quoting(targetdir) && !strchr(targetdir, '\"')) {
|
---|
[105] | 212 | *pp = '\"';
|
---|
| 213 | pp++;
|
---|
| 214 | spaces = TRUE;
|
---|
| 215 | }
|
---|
| 216 | else
|
---|
| 217 | spaces = FALSE;
|
---|
| 218 | strcpy(pp, targetdir);
|
---|
| 219 | p += 2;
|
---|
| 220 | pp += strlen(targetdir);
|
---|
[441] | 221 | if (spaces) {
|
---|
[105] | 222 | *pp = '\"';
|
---|
| 223 | pp++;
|
---|
| 224 | }
|
---|
| 225 | break;
|
---|
[2] | 226 |
|
---|
[105] | 227 | case '$': /* add drive letter */
|
---|
| 228 | if (drive)
|
---|
| 229 | *pp = drive;
|
---|
[441] | 230 | else {
|
---|
[105] | 231 | ULONG ulDriveNum = 3L, ulDriveMap;
|
---|
[2] | 232 |
|
---|
[105] | 233 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 234 | *pp = (char) (ulDriveNum + '@');
|
---|
| 235 | }
|
---|
| 236 | pp++;
|
---|
| 237 | p += 2;
|
---|
| 238 | break;
|
---|
[2] | 239 |
|
---|
[105] | 240 | case 'U': /* add path of first list component */
|
---|
| 241 | case 'u':
|
---|
[441] | 242 | if (*modpath) {
|
---|
| 243 | if (needs_quoting(modpath) && !strchr(modpath, '\"')) {
|
---|
[105] | 244 | spaces = TRUE;
|
---|
| 245 | *pp = '\"';
|
---|
| 246 | pp++;
|
---|
| 247 | }
|
---|
| 248 | else
|
---|
| 249 | spaces = FALSE;
|
---|
[441] | 250 | if (*(p + 1) == 'u') {
|
---|
[105] | 251 | strcpy(pp, modpath);
|
---|
| 252 | pp += strlen(modpath);
|
---|
| 253 | }
|
---|
[441] | 254 | else {
|
---|
[105] | 255 | strcpy(pp, modpath + 2);
|
---|
| 256 | pp += strlen(modpath + 2);
|
---|
| 257 | }
|
---|
[441] | 258 | if (spaces) {
|
---|
| 259 | if (modpath[strlen(modpath) - 1] == '\\') {
|
---|
[105] | 260 | *pp = '\\';
|
---|
| 261 | pp++;
|
---|
| 262 | }
|
---|
| 263 | *pp = '\"';
|
---|
| 264 | pp++;
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
[441] | 267 | else {
|
---|
[105] | 268 | char temp[CCHMAXPATH];
|
---|
[2] | 269 |
|
---|
[105] | 270 | save_dir2(temp);
|
---|
[441] | 271 | if (needs_quoting(temp) && !strchr(temp, '\"')) {
|
---|
[105] | 272 | spaces = TRUE;
|
---|
| 273 | *pp = '\"';
|
---|
| 274 | pp++;
|
---|
| 275 | }
|
---|
| 276 | else
|
---|
| 277 | spaces = FALSE;
|
---|
| 278 | strcpy(pp, temp);
|
---|
| 279 | pp += strlen(temp);
|
---|
[441] | 280 | if (spaces) {
|
---|
| 281 | if (temp[strlen(temp) - 1] == '\\') {
|
---|
[105] | 282 | *pp = '\\';
|
---|
| 283 | pp++;
|
---|
| 284 | }
|
---|
| 285 | *pp = '\"';
|
---|
| 286 | pp++;
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 | p += 2;
|
---|
| 290 | break;
|
---|
[2] | 291 |
|
---|
[105] | 292 | case 'P': /* add path of execution */
|
---|
| 293 | case 'p':
|
---|
[441] | 294 | if (*path) {
|
---|
| 295 | if (needs_quoting(path) && !strchr(path, '\"')) {
|
---|
[105] | 296 | spaces = TRUE;
|
---|
| 297 | *pp = '\"';
|
---|
| 298 | pp++;
|
---|
| 299 | }
|
---|
| 300 | else
|
---|
| 301 | spaces = FALSE;
|
---|
[441] | 302 | if (*(p + 1) == 'p') {
|
---|
[105] | 303 | strcpy(pp, path);
|
---|
| 304 | pp += strlen(path);
|
---|
| 305 | }
|
---|
[441] | 306 | else {
|
---|
[105] | 307 | strcpy(pp, path + 2);
|
---|
| 308 | pp += strlen(path + 2);
|
---|
| 309 | }
|
---|
[441] | 310 | if (spaces) {
|
---|
| 311 | if (path[strlen(path) - 1] == '\\') {
|
---|
[105] | 312 | *pp = '\\';
|
---|
| 313 | pp++;
|
---|
| 314 | }
|
---|
| 315 | *pp = '\"';
|
---|
| 316 | pp++;
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
[441] | 319 | else {
|
---|
[105] | 320 | char temp[CCHMAXPATH];
|
---|
[2] | 321 |
|
---|
[105] | 322 | save_dir2(temp);
|
---|
[441] | 323 | if (needs_quoting(temp) && !strchr(temp, '\"')) {
|
---|
[105] | 324 | spaces = TRUE;
|
---|
| 325 | *pp = '\"';
|
---|
| 326 | pp++;
|
---|
| 327 | }
|
---|
| 328 | else
|
---|
| 329 | spaces = FALSE;
|
---|
| 330 | strcpy(pp, temp);
|
---|
| 331 | pp += strlen(temp);
|
---|
[441] | 332 | if (spaces) {
|
---|
| 333 | if (temp[strlen(temp) - 1] == '\\') {
|
---|
[105] | 334 | *pp = '\\';
|
---|
| 335 | pp++;
|
---|
| 336 | }
|
---|
| 337 | *pp = '\"';
|
---|
| 338 | pp++;
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | p += 2;
|
---|
| 342 | break;
|
---|
[2] | 343 |
|
---|
[105] | 344 | case 'D':
|
---|
[441] | 345 | if (hwndMain) {
|
---|
[105] | 346 | PCNRITEM pci;
|
---|
[2] | 347 |
|
---|
[105] | 348 | pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID(
|
---|
| 349 | hwndTree, FID_CLIENT), TREE_CNR),
|
---|
| 350 | CM_QUERYRECORDEMPHASIS,
|
---|
| 351 | MPFROMLONG(CMA_FIRST),
|
---|
| 352 | MPFROMSHORT(CRA_CURSORED));
|
---|
[441] | 353 | if (pci && (int) pci != -1 && *pci -> szFileName) {
|
---|
[105] | 354 | if (needs_quoting(pci -> szFileName) &&
|
---|
| 355 | !strchr(pci -> szFileName, '\"'))
|
---|
| 356 | {
|
---|
| 357 | *pp = '\"';
|
---|
| 358 | pp++;
|
---|
| 359 | spaces = TRUE;
|
---|
| 360 | }
|
---|
| 361 | else
|
---|
| 362 | spaces = FALSE;
|
---|
| 363 | strcpy(pp, pci -> szFileName);
|
---|
| 364 | pp += strlen(pci -> szFileName);
|
---|
[441] | 365 | if (spaces) {
|
---|
[105] | 366 | *pp = '\"';
|
---|
| 367 | pp++;
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 | p += 2;
|
---|
| 372 | break;
|
---|
[2] | 373 |
|
---|
[105] | 374 | case 'd':
|
---|
[441] | 375 | if (hwndMain) {
|
---|
[105] | 376 | HENUM henum;
|
---|
| 377 | char retstr[CCHMAXPATH];
|
---|
| 378 | HWND hwndC, hwndDir;
|
---|
| 379 | USHORT id;
|
---|
| 380 | BOOL first = TRUE;
|
---|
[2] | 381 |
|
---|
[105] | 382 | henum = WinBeginEnumWindows(hwndMain);
|
---|
[441] | 383 | while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
|
---|
| 384 | if (hwndC != hwndTree) {
|
---|
[105] | 385 | id = WinQueryWindowUShort(hwndC, QWS_ID);
|
---|
[441] | 386 | if (id) {
|
---|
[105] | 387 | hwndDir = WinWindowFromID(hwndC, FID_CLIENT);
|
---|
[441] | 388 | if (hwndDir) {
|
---|
[105] | 389 | hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
|
---|
[441] | 390 | if (hwndDir) {
|
---|
[105] | 391 | *retstr = 0;
|
---|
| 392 | WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID);
|
---|
[441] | 393 | if (*retstr) {
|
---|
| 394 | if (!first) {
|
---|
[105] | 395 | *pp = ' ';
|
---|
| 396 | pp++;
|
---|
| 397 | }
|
---|
| 398 | first = FALSE;
|
---|
[441] | 399 | if (needs_quoting(retstr) && !strchr(retstr, '\"')) {
|
---|
[105] | 400 | *pp = '\"';
|
---|
| 401 | pp++;
|
---|
| 402 | spaces = TRUE;
|
---|
| 403 | }
|
---|
| 404 | else
|
---|
| 405 | spaces = FALSE;
|
---|
| 406 | strcpy(pp, retstr);
|
---|
| 407 | pp += strlen(retstr);
|
---|
[441] | 408 | if (spaces) {
|
---|
[105] | 409 | *pp = '\"';
|
---|
| 410 | pp++;
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 | }
|
---|
| 416 | }
|
---|
| 417 | }
|
---|
| 418 | WinEndEnumWindows(henum);
|
---|
| 419 | }
|
---|
| 420 | p += 2;
|
---|
| 421 | break;
|
---|
[2] | 422 |
|
---|
[105] | 423 | case '%':
|
---|
| 424 | *pp = '%';
|
---|
| 425 | pp++;
|
---|
| 426 | p += 2;
|
---|
| 427 | break;
|
---|
[2] | 428 |
|
---|
[105] | 429 | case 'R':
|
---|
| 430 | case 'F':
|
---|
| 431 | case 'A':
|
---|
| 432 | case 'r':
|
---|
| 433 | case 'f':
|
---|
| 434 | case 'a':
|
---|
| 435 | case 'e':
|
---|
[441] | 436 | if (list) {
|
---|
[105] | 437 | for (x = 0; list[x]; x++)
|
---|
| 438 | {
|
---|
| 439 | file = strrchr(list[x], '\\');
|
---|
| 440 | if (!file)
|
---|
| 441 | file = strrchr(list[x], ':');
|
---|
| 442 | if (file)
|
---|
| 443 | file++;
|
---|
| 444 | else
|
---|
| 445 | file = list[x];
|
---|
| 446 | ext = strrchr(file, '.');
|
---|
| 447 | dot = ext;
|
---|
| 448 | if (ext)
|
---|
| 449 | ext++;
|
---|
[441] | 450 | switch (*(p + 1)) {
|
---|
[105] | 451 | case 'R':
|
---|
| 452 | case 'r':
|
---|
| 453 | if (pp + strlen(list[x]) > commandline + 1250)
|
---|
| 454 | goto BreakOut;
|
---|
[441] | 455 | if (*(p + 1) == 'r') {
|
---|
[105] | 456 | strcpy(pp, list[x]);
|
---|
| 457 | pp += strlen(list[x]);
|
---|
| 458 | }
|
---|
[441] | 459 | else {
|
---|
[105] | 460 | strcpy(pp, list[x] + 2);
|
---|
| 461 | pp += strlen(list[x] + 2);
|
---|
| 462 | }
|
---|
| 463 | break;
|
---|
[2] | 464 |
|
---|
[105] | 465 | case 'F':
|
---|
| 466 | case 'f':
|
---|
| 467 | if (*(p + 1) == 'F' && dot)
|
---|
| 468 | *dot = 0;
|
---|
| 469 | if (pp + strlen(file) > commandline + 1250)
|
---|
| 470 | goto BreakOut;
|
---|
[441] | 471 | if (needs_quoting(file)) {
|
---|
[105] | 472 | spaces = TRUE;
|
---|
| 473 | *pp = '\"';
|
---|
| 474 | pp++;
|
---|
| 475 | }
|
---|
| 476 | else
|
---|
| 477 | spaces = FALSE;
|
---|
| 478 | strcpy(pp, file);
|
---|
| 479 | pp += strlen(file);
|
---|
| 480 | if (*(p + 1) == 'F' && dot)
|
---|
| 481 | *dot = '.';
|
---|
[441] | 482 | if (spaces) {
|
---|
| 483 | if (*(pp - 1) != '\"') {
|
---|
[105] | 484 | *pp = '\"';
|
---|
| 485 | pp++;
|
---|
| 486 | }
|
---|
| 487 | }
|
---|
| 488 | break;
|
---|
[2] | 489 |
|
---|
[105] | 490 | case 'A':
|
---|
| 491 | case 'a':
|
---|
| 492 | if (pp + strlen(list[x]) > commandline + 1250)
|
---|
| 493 | goto BreakOut;
|
---|
[441] | 494 | if (needs_quoting(list[x]) && !strchr(list[x], '\"')) {
|
---|
[105] | 495 | spaces = TRUE;
|
---|
| 496 | *pp = '\"';
|
---|
| 497 | pp++;
|
---|
| 498 | }
|
---|
| 499 | else
|
---|
| 500 | spaces = FALSE;
|
---|
[441] | 501 | if (*(p + 1) == 'a') {
|
---|
[105] | 502 | strcpy(pp, list[x]);
|
---|
| 503 | pp += strlen(list[x]);
|
---|
| 504 | }
|
---|
[441] | 505 | else {
|
---|
[105] | 506 | strcpy(pp, list[x] + 2);
|
---|
| 507 | pp += strlen(list[x] + 2);
|
---|
| 508 | }
|
---|
[441] | 509 | if (spaces) {
|
---|
| 510 | if (list[x][strlen(list[x]) - 1] == '\\') {
|
---|
[105] | 511 | *pp = '\\';
|
---|
| 512 | pp++;
|
---|
| 513 | }
|
---|
| 514 | *pp = '\"';
|
---|
| 515 | pp++;
|
---|
| 516 | }
|
---|
| 517 | break;
|
---|
[2] | 518 |
|
---|
[105] | 519 | case 'e':
|
---|
[441] | 520 | if (ext) {
|
---|
[105] | 521 | if (pp + strlen(ext) > commandline + 1250)
|
---|
| 522 | goto BreakOut;
|
---|
[441] | 523 | if (needs_quoting(ext)) {
|
---|
[105] | 524 | spaces = TRUE;
|
---|
| 525 | *pp = '\"';
|
---|
| 526 | pp++;
|
---|
[2] | 527 | }
|
---|
[105] | 528 | else
|
---|
| 529 | spaces = FALSE;
|
---|
| 530 | strcpy(pp, ext);
|
---|
| 531 | pp += strlen(ext);
|
---|
[441] | 532 | if (spaces) {
|
---|
| 533 | if (*(pp - 1) != '\"') {
|
---|
[105] | 534 | *pp = '\"';
|
---|
| 535 | pp++;
|
---|
| 536 | }
|
---|
[2] | 537 | }
|
---|
[105] | 538 | }
|
---|
| 539 | break;
|
---|
| 540 | }
|
---|
[441] | 541 | if (list[x + 1]) {
|
---|
[105] | 542 | *pp = ' ';
|
---|
| 543 | pp++;
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
[2] | 546 | }
|
---|
[105] | 547 | p += 2;
|
---|
| 548 | break;
|
---|
[2] | 549 |
|
---|
[105] | 550 | default:
|
---|
| 551 | *pp = *p;
|
---|
| 552 | p++;
|
---|
| 553 | pp++;
|
---|
| 554 | break;
|
---|
| 555 | }
|
---|
| 556 | }
|
---|
[441] | 557 | else {
|
---|
[105] | 558 | *pp = *p;
|
---|
| 559 | pp++;
|
---|
| 560 | p++;
|
---|
| 561 | }
|
---|
| 562 | *pp = 0;
|
---|
| 563 | }
|
---|
| 564 |
|
---|
[2] | 565 | BreakOut:
|
---|
| 566 |
|
---|
[105] | 567 | {
|
---|
| 568 | EXECARGS ex;
|
---|
| 569 | ULONG size;
|
---|
| 570 | int ret;
|
---|
[2] | 571 |
|
---|
[105] | 572 | memset(&ex, 0, sizeof(EXECARGS));
|
---|
| 573 | size = sizeof(ex.environment) - 1;
|
---|
| 574 | PrfQueryProfileData(fmprof, FM3Str, command, ex.environment, &size);
|
---|
[441] | 575 | if (flags & PROMPT) {
|
---|
| 576 | /* allow editing command line */
|
---|
[105] | 577 | ex.flags = (flags & (~PROMPT));
|
---|
| 578 | ex.commandline = commandline;
|
---|
| 579 | strcpy(ex.path, path);
|
---|
| 580 | if (prompt)
|
---|
| 581 | strcpy(ex.title, prompt);
|
---|
| 582 | ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
|
---|
| 583 | EXEC_FRAME, &ex);
|
---|
| 584 | if (ret != 1)
|
---|
| 585 | return (ret == 0) ? -1 : -2;
|
---|
| 586 | }
|
---|
| 587 | else
|
---|
| 588 | ex.flags = flags;
|
---|
| 589 | ex.flags &= (~PROMPT);
|
---|
| 590 | return runemf2(ex.flags, hwnd, path,
|
---|
| 591 | (*ex.environment) ? ex.environment : NULL,
|
---|
| 592 | "%s", commandline);
|
---|
| 593 | }
|
---|
[2] | 594 | }
|
---|
| 595 |
|
---|
[519] | 596 | //== runemf2() run requested app, return -1 if problem starting else return app rc ==
|
---|
[441] | 597 |
|
---|
[105] | 598 | int runemf2(int type, HWND hwnd, char *directory, char *environment,
|
---|
| 599 | char *formatstring,...)
|
---|
[78] | 600 | {
|
---|
[105] | 601 | /* example:
|
---|
| 602 |
|
---|
[2] | 603 | * status = runemf2(SEPARATE | WINDOWED,
|
---|
| 604 | * hwnd,
|
---|
| 605 | * NullStr,
|
---|
| 606 | * NULL,
|
---|
| 607 | * "%s /C %s",
|
---|
| 608 | * getenv("COMSPEC"),
|
---|
| 609 | * batchfilename);
|
---|
[105] | 610 | *
|
---|
| 611 | * use (HWND)0 for hwnd if window handle not handy.
|
---|
| 612 | */
|
---|
[2] | 613 |
|
---|
| 614 | /*
|
---|
| 615 | * type bitmapped flag -- see FM3DLL.H
|
---|
| 616 | */
|
---|
| 617 |
|
---|
[105] | 618 | va_list parguments;
|
---|
| 619 | int ret = -1;
|
---|
| 620 | RESULTCODES rt;
|
---|
[519] | 621 | STARTDATA sdata;
|
---|
[105] | 622 | REQUESTDATA rq;
|
---|
[519] | 623 | ULONG ulSessID, apptype, ulLength, ctr = 0;
|
---|
[105] | 624 | PID sessPID;
|
---|
| 625 | BOOL wasquote;
|
---|
| 626 | char *s = NULL, *s2 = NULL, object[32] = "", *p, savedir[CCHMAXPATH];
|
---|
[519] | 627 | HQUEUE hque;
|
---|
| 628 | char szQueueName[] = "\\QUEUES\\FM3WAIT";
|
---|
| 629 | char tempdir[CCHMAXPATH];
|
---|
| 630 | typedef struct {
|
---|
| 631 | USHORT usSessID;
|
---|
| 632 | USHORT usRC;
|
---|
| 633 | } TERMINFO;
|
---|
| 634 |
|
---|
| 635 | TERMINFO *pTermInfo = NULL;
|
---|
[105] | 636 | BYTE bPriority;
|
---|
| 637 | APIRET rc;
|
---|
[519] | 638 | PIB *ppib;
|
---|
| 639 | TIB *ptib;
|
---|
[2] | 640 |
|
---|
[441] | 641 | if (directory && *directory) {
|
---|
[105] | 642 | if (!DosQueryPathInfo(directory,
|
---|
| 643 | FIL_QUERYFULLNAME,
|
---|
| 644 | tempdir,
|
---|
| 645 | sizeof(tempdir)))
|
---|
| 646 | directory = tempdir;
|
---|
| 647 | }
|
---|
[2] | 648 |
|
---|
[105] | 649 | if (!hwnd)
|
---|
| 650 | hwnd = HWND_DESKTOP;
|
---|
[2] | 651 |
|
---|
[330] | 652 | rc = DosAllocMem((PVOID)&s,
|
---|
[105] | 653 | MAXSTRG,
|
---|
| 654 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
[330] | 655 | if (rc) {
|
---|
| 656 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
[105] | 657 | return -1;
|
---|
[330] | 658 | }
|
---|
[2] | 659 |
|
---|
[105] | 660 | *savedir = 0;
|
---|
[2] | 661 |
|
---|
[105] | 662 | *s = 0;
|
---|
| 663 | va_start(parguments,
|
---|
| 664 | formatstring);
|
---|
| 665 | vsprintf(s,
|
---|
| 666 | formatstring,
|
---|
| 667 | parguments);
|
---|
| 668 | va_end(parguments);
|
---|
[2] | 669 |
|
---|
[441] | 670 | if (environment) {
|
---|
[105] | 671 | p = &environment[strlen(environment)] + 1;
|
---|
| 672 | *p = 0;
|
---|
| 673 | p = environment;
|
---|
[373] | 674 | while ((p = convert_nl_to_nul(p)) != NULL)
|
---|
| 675 | ; // loop
|
---|
[105] | 676 | }
|
---|
[2] | 677 |
|
---|
[441] | 678 | if (!*s) {
|
---|
[105] | 679 | p = GetCmdSpec(FALSE);
|
---|
| 680 | strcpy(s, p);
|
---|
[441] | 681 | if (!*s) {
|
---|
| 682 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
---|
[105] | 683 | return -1;
|
---|
[441] | 684 | }
|
---|
[105] | 685 | }
|
---|
[2] | 686 |
|
---|
[441] | 687 | if (*s) {
|
---|
| 688 | if (*s == '<' && strchr(s, '>')) {
|
---|
| 689 | /* is a workplace object */
|
---|
[105] | 690 | HOBJECT hWPSObject;
|
---|
| 691 | char temp;
|
---|
[2] | 692 |
|
---|
[105] | 693 | p = strchr(s, '>');
|
---|
| 694 | p++;
|
---|
| 695 | temp = *p;
|
---|
[330] | 696 | if (temp) {
|
---|
| 697 | rc = DosAllocMem((PVOID)&s2,
|
---|
[105] | 698 | MAXSTRG * 2,
|
---|
| 699 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
[330] | 700 | if (rc)
|
---|
| 701 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
| 702 | }
|
---|
[105] | 703 | else
|
---|
| 704 | s2 = NULL;
|
---|
| 705 | *p = 0;
|
---|
| 706 | /* Find the handle of the WPS object */
|
---|
| 707 | hWPSObject = WinQueryObject(s);
|
---|
| 708 | *p = temp;
|
---|
[441] | 709 | if (hWPSObject != NULLHANDLE) {
|
---|
| 710 | if (s2 && *p) {
|
---|
| 711 | sprintf(s2,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
|
---|
| 712 | WinSetObjectData(hWPSObject,s2);
|
---|
[105] | 713 | }
|
---|
| 714 | else
|
---|
[441] | 715 | WinSetObjectData(hWPSObject,"OPEN=DEFAULT");
|
---|
[105] | 716 | ret = 0;
|
---|
| 717 | }
|
---|
| 718 | goto ObjectInterrupt;
|
---|
| 719 | }
|
---|
[2] | 720 |
|
---|
[105] | 721 | if ((type & 15) == SYNCHRONOUS ||
|
---|
| 722 | (type & 15) == ASYNCHRONOUS ||
|
---|
| 723 | (type & 15) == DETACHED)
|
---|
| 724 | {
|
---|
| 725 | strip_lead_char(" \t", s);
|
---|
| 726 | p = s;
|
---|
| 727 | wasquote = FALSE;
|
---|
| 728 | while (*p &&
|
---|
| 729 | (wasquote ||
|
---|
| 730 | (*p != ' ' &&
|
---|
| 731 | *p != '\t')))
|
---|
| 732 | {
|
---|
[441] | 733 | if (*p == '\"') {
|
---|
| 734 | if (!wasquote) {
|
---|
[105] | 735 | wasquote = TRUE;
|
---|
| 736 | memmove(p,
|
---|
| 737 | p + 1,
|
---|
| 738 | strlen(p));
|
---|
| 739 | while (*p == ' ' ||
|
---|
| 740 | *p == '\t')
|
---|
| 741 | p++;
|
---|
| 742 | }
|
---|
[441] | 743 | else {
|
---|
[105] | 744 | memmove(p,
|
---|
| 745 | p + 1,
|
---|
| 746 | strlen(p));
|
---|
| 747 | break;
|
---|
| 748 | }
|
---|
| 749 | }
|
---|
| 750 | else
|
---|
| 751 | p++;
|
---|
| 752 | }
|
---|
[441] | 753 | if (*p) {
|
---|
[105] | 754 | *p = 0;
|
---|
| 755 | p++;
|
---|
| 756 | }
|
---|
| 757 | else
|
---|
| 758 | p = s;
|
---|
| 759 | p[strlen(p) + 1] = 0; /* double-terminate args */
|
---|
[441] | 760 | if (*s) {
|
---|
[105] | 761 | if (!strchr(s, '\\') &&
|
---|
| 762 | !strchr(s, ':') &&
|
---|
| 763 | directory &&
|
---|
| 764 | *directory)
|
---|
| 765 | {
|
---|
| 766 | save_dir2(savedir);
|
---|
| 767 | switch_to(directory);
|
---|
| 768 | }
|
---|
[441] | 769 | rc = DosQAppType(s,&apptype);
|
---|
[105] | 770 | if (!strchr(s, '\\') &&
|
---|
| 771 | !strchr(s, ':') &&
|
---|
| 772 | directory &&
|
---|
| 773 | *directory)
|
---|
| 774 | switch_to(savedir);
|
---|
[441] | 775 | if (rc) {
|
---|
| 776 | // fixme to be in fm2dll.str
|
---|
| 777 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosQAppType failed for %s.", s);
|
---|
| 778 | DosFreeMem(s);
|
---|
[105] | 779 | if (s2)
|
---|
| 780 | DosFreeMem(s2);
|
---|
| 781 | return -1;
|
---|
| 782 | }
|
---|
[441] | 783 | if (apptype) {
|
---|
[105] | 784 | if ((apptype & FAPPTYP_DLL) || (apptype & FAPPTYP_VIRTDRV) ||
|
---|
| 785 | (apptype & FAPPTYP_PHYSDRV) || (apptype & FAPPTYP_PROTDLL))
|
---|
| 786 | {
|
---|
[441] | 787 | // fixme to be in fm2dll.str
|
---|
| 788 | Runtime_Error(pszSrcFile, __LINE__, "apptype 0x%x unexpected for %s.", apptype, s);
|
---|
[105] | 789 | if (s)
|
---|
| 790 | DosFreeMem(s);
|
---|
| 791 | if (s2)
|
---|
| 792 | DosFreeMem(s2);
|
---|
| 793 | return -1;
|
---|
| 794 | }
|
---|
| 795 | if ((apptype & FAPPTYP_DOS) || (apptype & FAPPTYP_WINDOWSREAL) ||
|
---|
| 796 | (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000))
|
---|
| 797 | {
|
---|
[441] | 798 | Runtime_Error(pszSrcFile, __LINE__, "apptype 0x%x unexpected for %s.", apptype, s);
|
---|
[105] | 799 | if (s)
|
---|
| 800 | DosFreeMem(s);
|
---|
| 801 | if (s2)
|
---|
| 802 | DosFreeMem(s2);
|
---|
| 803 | return -1;
|
---|
| 804 | }
|
---|
| 805 | }
|
---|
| 806 | memset(&rt, 0, sizeof(RESULTCODES));
|
---|
[441] | 807 | if (directory && *directory) {
|
---|
[105] | 808 | save_dir2(savedir);
|
---|
| 809 | switch_to(directory);
|
---|
| 810 | }
|
---|
[441] | 811 | ret = DosExecPgm(object, 24L,
|
---|
[105] | 812 | (ULONG) (((type & 15) == ASYNCHRONOUS) * EXEC_ASYNC) +
|
---|
| 813 | (((type & 15) == DETACHED) * EXEC_BACKGROUND),
|
---|
| 814 | s, environment, &rt, s);
|
---|
| 815 | if (directory && *directory)
|
---|
| 816 | switch_to(savedir);
|
---|
[330] | 817 | if (ret) {
|
---|
| 818 | Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
|
---|
[441] | 819 | GetPString(IDS_DOSEXECPGMFAILEDTEXT), s);
|
---|
[330] | 820 | }
|
---|
[105] | 821 | }
|
---|
| 822 | }
|
---|
[441] | 823 | else {
|
---|
[519] | 824 | if (~type & FULLSCREEN)
|
---|
[105] | 825 | type |= WINDOWED;
|
---|
| 826 | rc = DosAllocMem((PVOID) & s2, MAXSTRG * 2,
|
---|
| 827 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
[441] | 828 | if (rc) {
|
---|
[330] | 829 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
[105] | 830 | DosFreeMem(s);
|
---|
| 831 | return -1;
|
---|
| 832 | }
|
---|
| 833 | *s2 = 0;
|
---|
[519] | 834 | memset(&sdata, 0, sizeof(STARTDATA));
|
---|
[105] | 835 | strip_lead_char(" \t", s);
|
---|
| 836 | p = s;
|
---|
| 837 | wasquote = FALSE;
|
---|
[441] | 838 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
| 839 | if (*p == '\"') {
|
---|
| 840 | if (!wasquote) {
|
---|
[105] | 841 | wasquote = TRUE;
|
---|
| 842 | memmove(p, p + 1, strlen(p));
|
---|
| 843 | while (*p == ' ' || *p == '\t')
|
---|
| 844 | p++;
|
---|
| 845 | }
|
---|
[441] | 846 | else {
|
---|
[105] | 847 | memmove(p, p + 1, strlen(p));
|
---|
| 848 | break;
|
---|
| 849 | }
|
---|
| 850 | }
|
---|
| 851 | else
|
---|
| 852 | p++;
|
---|
| 853 | }
|
---|
[441] | 854 | if (*p) {
|
---|
[105] | 855 | *p = 0;
|
---|
| 856 | p++;
|
---|
| 857 | }
|
---|
| 858 | else
|
---|
| 859 | p = NullStr;
|
---|
| 860 | if (*p)
|
---|
| 861 | strcpy(s2, p);
|
---|
[2] | 862 |
|
---|
[105] | 863 | p = strrchr(s, '.');
|
---|
[441] | 864 | if (p) {
|
---|
[105] | 865 | char temp[CCHMAXPATH + 1];
|
---|
[2] | 866 |
|
---|
[441] | 867 | if (!stricmp(p, ".BAT")) {
|
---|
[105] | 868 | strcpy(temp, s);
|
---|
| 869 | strcpy(s, s2);
|
---|
| 870 | strcpy(s2, "/C ");
|
---|
| 871 | strcat(s2, temp);
|
---|
| 872 | strcat(s2, " ");
|
---|
| 873 | strcat(s2, s);
|
---|
| 874 | strcpy(s, GetCmdSpec(TRUE));
|
---|
| 875 | }
|
---|
[441] | 876 | else if (!stricmp(p, ".CMD")) {
|
---|
[105] | 877 | strcpy(temp, s);
|
---|
| 878 | strcpy(s, s2);
|
---|
| 879 | strcpy(s2, "/C ");
|
---|
| 880 | strcat(s2, temp);
|
---|
| 881 | strcat(s2, " ");
|
---|
| 882 | strcat(s2, s);
|
---|
| 883 | strcpy(s, GetCmdSpec(FALSE));
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
[2] | 886 |
|
---|
[105] | 887 | /* goddamned OS/2 limit */
|
---|
[2] | 888 |
|
---|
[105] | 889 | if (strlen(s) + strlen(s2) > 1024)
|
---|
| 890 | s2[1024 - strlen(s)] = 0;
|
---|
[2] | 891 |
|
---|
[105] | 892 | if (!strchr(s, '\\') &&
|
---|
| 893 | !strchr(s, ':') &&
|
---|
| 894 | directory &&
|
---|
| 895 | *directory)
|
---|
| 896 | {
|
---|
| 897 | save_dir2(savedir);
|
---|
| 898 | switch_to(directory);
|
---|
| 899 | }
|
---|
[441] | 900 | rc = DosQAppType(s,&apptype);
|
---|
[105] | 901 | if (!strchr(s, '\\') &&
|
---|
| 902 | !strchr(s, ':') &&
|
---|
| 903 | directory &&
|
---|
| 904 | *directory)
|
---|
| 905 | switch_to(savedir);
|
---|
[441] | 906 | if (rc) {
|
---|
| 907 | // fixme to be in fm2dll.str
|
---|
| 908 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosQAppType failed for %s.", s);
|
---|
| 909 | DosFreeMem(s);
|
---|
[105] | 910 | if (s2)
|
---|
| 911 | DosFreeMem(s2);
|
---|
| 912 | return -1;
|
---|
| 913 | }
|
---|
[2] | 914 |
|
---|
[441] | 915 | if (apptype) {
|
---|
[105] | 916 | if ((apptype & FAPPTYP_DLL) || (apptype & FAPPTYP_VIRTDRV) ||
|
---|
| 917 | (apptype & FAPPTYP_PHYSDRV) || (apptype & FAPPTYP_PROTDLL))
|
---|
| 918 | {
|
---|
[441] | 919 | // fixme to be in fm2dll.str
|
---|
| 920 | Runtime_Error(pszSrcFile, __LINE__, "apptype %d unexpected for %s.", s);
|
---|
| 921 | DosFreeMem(s);
|
---|
[105] | 922 | if (s2)
|
---|
| 923 | DosFreeMem(s2);
|
---|
| 924 | return -1;
|
---|
| 925 | }
|
---|
| 926 | apptype &= (~FAPPTYP_BOUND);
|
---|
| 927 | if ((apptype & FAPPTYP_DOS) || (apptype & FAPPTYP_WINDOWSREAL) ||
|
---|
| 928 | (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000))
|
---|
| 929 | {
|
---|
| 930 | if ((apptype & FAPPTYP_WINDOWSREAL) ||
|
---|
| 931 | (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000))
|
---|
| 932 | {
|
---|
| 933 | if (!(type & FULLSCREEN) && ((apptype & FAPPTYP_WINDOWSREAL) ||
|
---|
| 934 | (apptype & FAPPTYP_WINDOWSPROT) || (apptype & 0x1000)))
|
---|
| 935 | {
|
---|
| 936 | ret = RunSeamless(s, s2, hwnd);
|
---|
| 937 | if (s)
|
---|
| 938 | DosFreeMem(s);
|
---|
| 939 | if (s2)
|
---|
| 940 | DosFreeMem(s2);
|
---|
[441] | 941 | return ret ? 0 : -1;
|
---|
[105] | 942 | }
|
---|
[441] | 943 | else {
|
---|
[105] | 944 | strcat(s, " ");
|
---|
| 945 | strcat(s, s2);
|
---|
| 946 | *s2 = 0;
|
---|
| 947 | if ((apptype & FAPPTYP_WINDOWSPROT) ||
|
---|
| 948 | (apptype & FAPPTYP_WINDOWSREAL) ||
|
---|
| 949 | (apptype & 0x1000))
|
---|
| 950 | strcat(s2, "/3 ");
|
---|
| 951 | strcat(s2, s);
|
---|
| 952 | strcpy(s, "WINOS2.COM");
|
---|
| 953 | }
|
---|
| 954 | }
|
---|
[441] | 955 | else {
|
---|
| 956 | if (!(type & FULLSCREEN)) {
|
---|
[105] | 957 | type |= WINDOWED;
|
---|
| 958 | apptype = SSF_TYPE_WINDOWEDVDM;
|
---|
| 959 | }
|
---|
[441] | 960 | else {
|
---|
[105] | 961 | type &= (~WINDOWED);
|
---|
| 962 | apptype = SSF_TYPE_VDM;
|
---|
| 963 | }
|
---|
| 964 | }
|
---|
| 965 | }
|
---|
[441] | 966 | else if (apptype & FAPPTYP_32BIT) {
|
---|
[105] | 967 | apptype &= (~FAPPTYP_32BIT);
|
---|
| 968 | if (apptype == FAPPTYP_WINDOWAPI)
|
---|
| 969 | apptype = SSF_TYPE_PM;
|
---|
| 970 | else if (apptype == FAPPTYP_WINDOWCOMPAT)
|
---|
| 971 | apptype = SSF_TYPE_WINDOWABLEVIO;
|
---|
[441] | 972 | else if (apptype == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
[105] | 973 | apptype = SSF_TYPE_FULLSCREEN;
|
---|
| 974 | type &= (~WINDOWED);
|
---|
| 975 | type |= FULLSCREEN;
|
---|
| 976 | }
|
---|
| 977 | else /* ? */
|
---|
| 978 | apptype = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 979 | }
|
---|
| 980 | else if (apptype == FAPPTYP_WINDOWAPI)
|
---|
| 981 | apptype = SSF_TYPE_PM;
|
---|
| 982 | else if (apptype == FAPPTYP_WINDOWCOMPAT)
|
---|
| 983 | apptype = SSF_TYPE_WINDOWABLEVIO;
|
---|
[441] | 984 | else if (apptype == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
[105] | 985 | type &= (~WINDOWED);
|
---|
| 986 | apptype = SSF_TYPE_FULLSCREEN;
|
---|
| 987 | }
|
---|
| 988 | else
|
---|
| 989 | apptype = SSF_TYPE_DEFAULT;
|
---|
| 990 | if (((type & FULLSCREEN) || !(type & WINDOWED)) &&
|
---|
| 991 | apptype == SSF_TYPE_WINDOWABLEVIO)
|
---|
| 992 | {
|
---|
| 993 | apptype = SSF_TYPE_FULLSCREEN;
|
---|
| 994 | }
|
---|
[519] | 995 | // fixme parens?
|
---|
[105] | 996 | else if (((type & FULLSCREEN) || !(type & WINDOWED) &&
|
---|
| 997 | apptype == SSF_TYPE_WINDOWEDVDM))
|
---|
| 998 | apptype = SSF_TYPE_VDM;
|
---|
| 999 | }
|
---|
[441] | 1000 | if (apptype == SSF_TYPE_WINDOWEDVDM && (type & SEPARATEKEEP)) {
|
---|
[519] | 1001 | type &= ~SEPARATEKEEP;
|
---|
[105] | 1002 | type |= SEPARATE;
|
---|
| 1003 | }
|
---|
[2] | 1004 |
|
---|
[519] | 1005 | DosGetInfoBlocks(&ptib, &ppib);
|
---|
| 1006 | fprintf(stderr,"runemf2 ptib %x pgm %s\n",ptib,s);
|
---|
| 1007 |
|
---|
[441] | 1008 | if (type & WAIT) {
|
---|
[519] | 1009 | rc = DosCreateQueue(&hque, QUE_FIFO | QUE_CONVERT_ADDRESS, szQueueName);
|
---|
| 1010 | if (rc) {
|
---|
| 1011 | if (rc != ERROR_QUE_DUPLICATE)
|
---|
| 1012 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
|
---|
| 1013 | hque = (HQUEUE)0; // Try to survive
|
---|
| 1014 | *szQueueName = 0; // Try to survive
|
---|
| 1015 | }
|
---|
| 1016 | else
|
---|
| 1017 | fprintf(stderr,"runemf2 ptib %x hque %x created\n",ptib,hque);
|
---|
[105] | 1018 | }
|
---|
[519] | 1019 | else {
|
---|
| 1020 | hque = (HQUEUE)0; // No queue if not waiting
|
---|
| 1021 | *szQueueName = 0; // No queue if not waiting
|
---|
| 1022 | }
|
---|
| 1023 | sdata.Length = sizeof(sdata);
|
---|
| 1024 | sdata.Related = type & (WAIT | CHILD) ?
|
---|
| 1025 | SSF_RELATED_CHILD : SSF_RELATED_INDEPENDENT;
|
---|
| 1026 | sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE;
|
---|
| 1027 | sdata.TraceOpt = SSF_TRACEOPT_NONE;
|
---|
| 1028 | sdata.PgmTitle = NULL;
|
---|
| 1029 | sdata.PgmName = s;
|
---|
| 1030 | sdata.PgmInputs = (*s2) ? s2 : NULL;
|
---|
| 1031 | sdata.TermQ = *szQueueName ? szQueueName : NULL;
|
---|
| 1032 | sdata.Environment = environment;
|
---|
| 1033 | sdata.InheritOpt = SSF_INHERTOPT_PARENT;
|
---|
| 1034 | sdata.SessionType = (USHORT)apptype;
|
---|
| 1035 | sdata.ObjectBuffer = object;
|
---|
| 1036 | sdata.ObjectBuffLen = sizeof(object) - 1;
|
---|
| 1037 | sdata.IconFile = NULL;
|
---|
| 1038 | sdata.PgmHandle = 0L;
|
---|
| 1039 | sdata.Reserved = 0;
|
---|
| 1040 | sdata.PgmControl = (USHORT) ((SSF_CONTROL_NOAUTOCLOSE * ((type & 15) == SEPARATEKEEP)) |
|
---|
[105] | 1041 | (SSF_CONTROL_MAXIMIZE * ((type & MAXIMIZED) != 0)) |
|
---|
| 1042 | (SSF_CONTROL_MINIMIZE * ((type & MINIMIZED) != 0)) |
|
---|
| 1043 | (SSF_CONTROL_INVISIBLE * ((type & INVISIBLE) != 0)));
|
---|
[441] | 1044 | if (directory && *directory) {
|
---|
[105] | 1045 | save_dir2(savedir);
|
---|
| 1046 | switch_to(directory);
|
---|
| 1047 | }
|
---|
[519] | 1048 | ret = DosStartSession(&sdata, &ulSessID, &sessPID);
|
---|
[105] | 1049 | if (directory && *directory)
|
---|
| 1050 | switch_to(savedir);
|
---|
[330] | 1051 | if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
|
---|
| 1052 | Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
|
---|
| 1053 | GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),s,s2);
|
---|
| 1054 | }
|
---|
[441] | 1055 | else if (type & WAIT) {
|
---|
[105] | 1056 | if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
| 1057 | ShowSession(hwnd, sessPID);
|
---|
[2] | 1058 |
|
---|
[441] | 1059 | if (!hque) {
|
---|
[519] | 1060 | // No queue
|
---|
[105] | 1061 | STATUSDATA sd;
|
---|
[2] | 1062 |
|
---|
[105] | 1063 | memset(&sd, 0, sizeof(sd));
|
---|
| 1064 | sd.Length = (USHORT) sizeof(sd);
|
---|
| 1065 | sd.SelectInd = SET_SESSION_UNCHANGED;
|
---|
| 1066 | sd.BondInd = SET_SESSION_UNCHANGED;
|
---|
| 1067 | for (ctr = 0;; ctr++)
|
---|
| 1068 | {
|
---|
| 1069 | DosSleep(200L);
|
---|
[519] | 1070 | if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished)
|
---|
[105] | 1071 | break;
|
---|
[519] | 1072 | if (ctr > 10) {
|
---|
| 1073 | ShowSession(hwnd, sessPID); // Show every 2 seconds
|
---|
| 1074 | ctr = 0;
|
---|
| 1075 | }
|
---|
[105] | 1076 | }
|
---|
| 1077 | }
|
---|
[441] | 1078 | else {
|
---|
[519] | 1079 | // This thread owns queue
|
---|
| 1080 | fprintf(stderr,"runemf2 ptib %x hque %x sessID %x sessPID %x\n",ptib,hque,ulSessID,sessPID);
|
---|
| 1081 | fflush(stderr);
|
---|
[105] | 1082 | for (ctr = 0;; ctr++)
|
---|
| 1083 | {
|
---|
[519] | 1084 | // ulLength = sizeof(TERMINFO);
|
---|
| 1085 | // fixme to supply event semaphore or not wait
|
---|
| 1086 | rc = DosReadQueue(hque, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
[105] | 1087 | DCWW_NOWAIT, &bPriority, 0);
|
---|
[441] | 1088 | if (rc == ERROR_QUE_EMPTY) {
|
---|
| 1089 | if (ctr > 20) {
|
---|
[105] | 1090 | ShowSession(hwnd, sessPID);
|
---|
[519] | 1091 | ulLength = sizeof(TERMINFO);
|
---|
| 1092 | rc = DosReadQueue(hque, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
| 1093 | DCWW_WAIT, &bPriority, 0);
|
---|
[105] | 1094 | break;
|
---|
| 1095 | }
|
---|
[519] | 1096 | DosSleep(100);
|
---|
[105] | 1097 | }
|
---|
[441] | 1098 | else {
|
---|
[519] | 1099 | if (rc) {
|
---|
| 1100 | if (rc != ERROR_INVALID_PARAMETER)
|
---|
| 1101 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
|
---|
| 1102 | // ulLength = sizeof(TERMINFO);
|
---|
| 1103 | rc = DosReadQueue(hque, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
| 1104 | DCWW_WAIT, &bPriority, 0);
|
---|
| 1105 | }
|
---|
| 1106 | // fixme to be much smarter
|
---|
| 1107 | if (!rc && pTermInfo && pTermInfo->usSessID != ulSessID) {
|
---|
| 1108 | // fixme to requeue
|
---|
| 1109 | continue;
|
---|
| 1110 | }
|
---|
[105] | 1111 | break;
|
---|
| 1112 | }
|
---|
[519] | 1113 | } // for
|
---|
| 1114 | fprintf(stderr,"runemf2 ptib %x hque %x rq pid %x ul %d\n",ptib,hque,rq.pid,rq.ulData);
|
---|
| 1115 | if (pTermInfo) {
|
---|
| 1116 | ret = !(!pTermInfo->usRC); // Set TRUE if rc 0
|
---|
| 1117 | fprintf(stderr,"runemf2 ptib %x hque %x terminfo sessId %x rc %d\n",ptib,hque,pTermInfo->usSessID,pTermInfo->usRC);
|
---|
| 1118 | DosFreeMem(pTermInfo);
|
---|
[105] | 1119 | }
|
---|
| 1120 | DosCloseQueue(hque);
|
---|
[519] | 1121 | fprintf(stderr,"runemf2 ptib %x hque %x closed\n",ptib,hque);
|
---|
| 1122 | fflush(stderr);
|
---|
[105] | 1123 | }
|
---|
| 1124 | }
|
---|
| 1125 | else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
| 1126 | ShowSession(hwnd, sessPID);
|
---|
| 1127 | }
|
---|
| 1128 | }
|
---|
[2] | 1129 |
|
---|
| 1130 | ObjectInterrupt:
|
---|
| 1131 |
|
---|
[105] | 1132 | if (s)
|
---|
| 1133 | DosFreeMem(s);
|
---|
| 1134 | if (s2)
|
---|
| 1135 | DosFreeMem(s2);
|
---|
| 1136 | return ret;
|
---|
[2] | 1137 | }
|
---|
| 1138 |
|
---|
[519] | 1139 | //== Exec() Start application with WinStartApp ==
|
---|
| 1140 |
|
---|
[105] | 1141 | HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
[519] | 1142 | PROGTYPE *progt, ULONG fl, char *formatstring,...)
|
---|
[78] | 1143 | {
|
---|
[105] | 1144 | PROGDETAILS pgd;
|
---|
[2] | 1145 | register char *p;
|
---|
[105] | 1146 | char *parameters = NULL, *executable = NULL;
|
---|
[519] | 1147 | HAPP happ = (HAPP)0;
|
---|
[105] | 1148 | ULONG ulOptions = SAF_INSTALLEDCMDLINE;
|
---|
| 1149 | BOOL wasquote;
|
---|
| 1150 | va_list parguments;
|
---|
[2] | 1151 |
|
---|
[105] | 1152 | if (child)
|
---|
[2] | 1153 | ulOptions |= SAF_STARTCHILDAPP;
|
---|
| 1154 |
|
---|
[330] | 1155 | executable = xmallocz(MAXSTRG,pszSrcFile,__LINE__);
|
---|
| 1156 | if (executable) {
|
---|
[105] | 1157 | va_start(parguments, formatstring);
|
---|
| 1158 | vsprintf(executable, formatstring, parguments);
|
---|
[2] | 1159 | va_end(parguments);
|
---|
[105] | 1160 | strip_lead_char(" \t", executable);
|
---|
[441] | 1161 | if (*executable) {
|
---|
[330] | 1162 | parameters = xmalloc(MAXSTRG,pszSrcFile,__LINE__);
|
---|
[441] | 1163 | if (parameters) {
|
---|
[105] | 1164 | p = executable;
|
---|
| 1165 | wasquote = FALSE;
|
---|
[441] | 1166 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
| 1167 | if (*p == '\"') {
|
---|
| 1168 | if (!wasquote) {
|
---|
[105] | 1169 | wasquote = TRUE;
|
---|
| 1170 | memmove(p, p + 1, strlen(p));
|
---|
| 1171 | while (*p == ' ' || *p == '\t')
|
---|
| 1172 | p++;
|
---|
| 1173 | }
|
---|
[441] | 1174 | else {
|
---|
[105] | 1175 | memmove(p, p + 1, strlen(p));
|
---|
| 1176 | break;
|
---|
| 1177 | }
|
---|
| 1178 | }
|
---|
| 1179 | else
|
---|
| 1180 | p++;
|
---|
| 1181 | }
|
---|
[441] | 1182 | if (*p) {
|
---|
[105] | 1183 | *p = 0;
|
---|
| 1184 | p++;
|
---|
| 1185 | }
|
---|
| 1186 | else
|
---|
| 1187 | p = NullStr;
|
---|
| 1188 | if (*p)
|
---|
| 1189 | strcpy(parameters, p);
|
---|
[2] | 1190 |
|
---|
[441] | 1191 | if (p && (!stricmp(p, ".BAT") || !stricmp(p, ".CMD"))) {
|
---|
[105] | 1192 | char *temp;
|
---|
[2] | 1193 |
|
---|
[330] | 1194 | temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
|
---|
[441] | 1195 | if (temp) {
|
---|
| 1196 | if (!stricmp(p, ".BAT")) {
|
---|
[105] | 1197 | strcpy(temp, executable);
|
---|
| 1198 | strcpy(executable, parameters);
|
---|
| 1199 | strcpy(parameters, "/C ");
|
---|
| 1200 | strcat(parameters, temp);
|
---|
| 1201 | strcat(parameters, " ");
|
---|
| 1202 | strcat(parameters, executable);
|
---|
| 1203 | strcpy(executable, GetCmdSpec(TRUE));
|
---|
| 1204 | }
|
---|
[441] | 1205 | else if (!stricmp(p, ".CMD")) {
|
---|
[105] | 1206 | strcpy(temp, executable);
|
---|
| 1207 | strcpy(executable, parameters);
|
---|
| 1208 | strcpy(parameters, "/C ");
|
---|
| 1209 | strcat(parameters, temp);
|
---|
| 1210 | strcat(parameters, " ");
|
---|
| 1211 | strcat(parameters, executable);
|
---|
| 1212 | strcpy(executable, GetCmdSpec(FALSE));
|
---|
| 1213 | }
|
---|
| 1214 | free(temp);
|
---|
| 1215 | }
|
---|
| 1216 | }
|
---|
[2] | 1217 |
|
---|
[105] | 1218 | memset(&pgd, 0, sizeof(pgd));
|
---|
| 1219 | pgd.Length = sizeof(pgd);
|
---|
| 1220 | pgd.progt = *progt;
|
---|
| 1221 | pgd.swpInitial.fl = fl;
|
---|
| 1222 | pgd.pszEnvironment = env;
|
---|
| 1223 | pgd.pszStartupDir = startdir;
|
---|
| 1224 | pgd.pszParameters = (*parameters) ? parameters : NULL;
|
---|
| 1225 | pgd.pszExecutable = executable;
|
---|
| 1226 | pgd.swpInitial.hwndInsertBehind = HWND_TOP;
|
---|
| 1227 | happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions);
|
---|
| 1228 | free(parameters);
|
---|
[2] | 1229 | }
|
---|
| 1230 | }
|
---|
| 1231 | free(executable);
|
---|
| 1232 | }
|
---|
| 1233 | return happ;
|
---|
| 1234 | }
|
---|