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