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