Changeset 1162 for trunk/dll/systemf.c
- Timestamp:
- Sep 5, 2008, 11:43:09 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/systemf.c
r1104 r1162 35 35 #define INCL_DOSERRORS 36 36 #define INCL_WIN 37 #define INCL_LONGLONG 37 #define INCL_LONGLONG // dircnrs.h 38 38 39 39 #include "fm3dlg.h" 40 40 #include "fm3str.h" 41 #include "errutil.h" 42 #include "strutil.h" 41 #include "errutil.h" // Dos_Error... 42 #include "strutil.h" // GetPString 43 43 #include "notebook.h" //targetdirectory 44 44 #include "pathutil.h" 45 #include "cmdline.h" // CmdLineDlgProc 46 #include "shadow.h" // RunSeamless 47 #include "systemf.h" 48 #include "strips.h" // convert_nl_to_nul, strip_lead_char 49 #include "dirs.h" // switch_to 45 50 #include "fm3dll.h" 46 51 #include "fortify.h" 47 52 48 53 static PSZ pszSrcFile = __FILE__; 54 55 //static HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env, 56 // PROGTYPE * progt, ULONG fl, char *formatstring, ...); 49 57 50 58 /** … … 64 72 if (!rc) { 65 73 if (swctl.idProcess == pid && swctl.uchVisibility == SWL_VISIBLE) 66 74 rc = WinSwitchToProgram(hswitch); 67 75 if (!rc) 68 76 return TRUE; 69 77 // else saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Failed: %lu/%lx",rc,rc); 70 78 … … 82 90 83 91 int ExecOnList(HWND hwnd, char *command, int flags, char *tpath, 84 92 char **list, char *prompt, PCSZ pszCallingFile, UINT uiLineNumber) 85 93 { 86 94 /* executes the command once for all files in list */ … … 117 125 if (p) { 118 126 if (*p == ':') { 119 120 121 127 p++; 128 *p = '\\'; 129 p++; 122 130 } 123 131 *p = 0; … … 134 142 if (p) { 135 143 if (*p == ':') { 136 137 138 144 p++; 145 *p = '\\'; 146 p++; 139 147 } 140 148 *p = 0; … … 170 178 drive = 0; 171 179 172 p = command; 180 p = command; // substitue for special % sequences 173 181 174 182 pp = commandline; … … 177 185 if (*p == '%') { 178 186 switch (*(p + 1)) { 179 case '!': 180 181 182 187 case '!': /* write list to file, add filename */ 188 if (list) { 189 if (!*listfile) { 190 FILE *fp; 183 191 184 192 … … 202 210 strcpy(pp, listfile); 203 211 pp += strlen(listfile); 204 205 206 207 208 case 'c': 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 case 't': 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 case '$': 247 248 249 250 251 252 253 254 255 256 257 258 259 case 'U': 212 } 213 p += 2; 214 break; 215 216 case 'c': /* add name of command processor */ 217 { 218 char *env = GetCmdSpec(FALSE); 219 220 if (needs_quoting(env) && !strchr(env, '\"')) { 221 *pp = '\"'; 222 pp++; 223 spaces = TRUE; 224 } 225 else 226 spaces = FALSE; 227 strcpy(pp, env); 228 p += 2; 229 pp += strlen(env); 230 if (spaces) { 231 *pp = '\"'; 232 pp++; 233 } 234 } 235 break; 236 237 case 't': /* add Target directory */ 238 if (needs_quoting(targetdir) && !strchr(targetdir, '\"')) { 239 *pp = '\"'; 240 pp++; 241 spaces = TRUE; 242 } 243 else 244 spaces = FALSE; 245 strcpy(pp, targetdir); 246 p += 2; 247 pp += strlen(targetdir); 248 if (spaces) { 249 *pp = '\"'; 250 pp++; 251 } 252 break; 253 254 case '$': /* add drive letter */ 255 if (drive) 256 *pp = drive; 257 else { 258 ULONG ulDriveNum = 3, ulDriveMap; 259 260 DosQCurDisk(&ulDriveNum, &ulDriveMap); 261 *pp = (char) (ulDriveNum + '@'); 262 } 263 pp++; 264 p += 2; 265 break; 266 267 case 'U': /* add path of first list component */ 260 268 case 'u': 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 case 'P': 269 if (*modpath) { 270 if (needs_quoting(modpath) && !strchr(modpath, '\"')) { 271 spaces = TRUE; 272 *pp = '\"'; 273 pp++; 274 } 275 else 276 spaces = FALSE; 277 if (*(p + 1) == 'u') { 278 strcpy(pp, modpath); 279 pp += strlen(modpath); 280 } 281 else { 282 strcpy(pp, modpath + 2); 283 pp += strlen(modpath + 2); 284 } 285 if (spaces) { 286 if (modpath[strlen(modpath) - 1] == '\\') { 287 *pp = '\\'; 288 pp++; 289 } 290 *pp = '\"'; 291 pp++; 292 } 293 } 294 else { 295 char temp[CCHMAXPATH]; 296 297 strcpy(temp, pFM2SaveDirectory); 298 if (needs_quoting(temp) && !strchr(temp, '\"')) { 299 spaces = TRUE; 300 *pp = '\"'; 301 pp++; 302 } 303 else 304 spaces = FALSE; 305 strcpy(pp, temp); 306 pp += strlen(temp); 307 if (spaces) { 308 if (temp[strlen(temp) - 1] == '\\') { 309 *pp = '\\'; 310 pp++; 311 } 312 *pp = '\"'; 313 pp++; 314 } 315 } 316 p += 2; 317 break; 318 319 case 'P': /* add path of execution */ 312 320 case 'p': 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 321 if (*path) { 322 if (needs_quoting(path) && !strchr(path, '\"')) { 323 spaces = TRUE; 324 *pp = '\"'; 325 pp++; 326 } 327 else 328 spaces = FALSE; 329 if (*(p + 1) == 'p') { 330 strcpy(pp, path); 331 pp += strlen(path); 332 } 333 else { 334 strcpy(pp, path + 2); 335 pp += strlen(path + 2); 336 } 337 if (spaces) { 338 if (path[strlen(path) - 1] == '\\') { 339 *pp = '\\'; 340 pp++; 341 } 342 *pp = '\"'; 343 pp++; 344 } 345 } 346 else { 347 char temp[CCHMAXPATH]; 348 349 strcpy(temp, pFM2SaveDirectory); 350 if (needs_quoting(temp) && !strchr(temp, '\"')) { 351 spaces = TRUE; 352 *pp = '\"'; 353 pp++; 354 } 355 else 356 spaces = FALSE; 357 strcpy(pp, temp); 358 pp += strlen(temp); 359 if (spaces) { 360 if (temp[strlen(temp) - 1] == '\\') { 361 *pp = '\\'; 362 pp++; 363 } 364 *pp = '\"'; 365 pp++; 366 } 367 } 368 p += 2; 369 break; 362 370 363 371 case 'D': 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 372 if (hwndMain) { 373 PCNRITEM pci; 374 375 pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID( 376 hwndTree, FID_CLIENT), TREE_CNR), 377 CM_QUERYRECORDEMPHASIS, 378 MPFROMLONG(CMA_FIRST), 379 MPFROMSHORT(CRA_CURSORED)); 380 if (pci && (int) pci != -1 && *pci->pszFileName) { 381 if (needs_quoting(pci->pszFileName) && 382 !strchr(pci->pszFileName, '\"')) 383 { 384 *pp = '\"'; 385 pp++; 386 spaces = TRUE; 387 } 388 else 389 spaces = FALSE; 390 strcpy(pp, pci->pszFileName); 391 pp += strlen(pci->pszFileName); 392 if (spaces) { 393 *pp = '\"'; 394 pp++; 395 } 396 } 397 } 398 p += 2; 399 break; 392 400 393 401 case 'd': 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 402 if (hwndMain) { 403 HENUM henum; 404 char retstr[CCHMAXPATH]; 405 HWND hwndC, hwndDir; 406 USHORT id; 407 BOOL first = TRUE; 408 409 henum = WinBeginEnumWindows(hwndMain); 410 while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) { 411 if (hwndC != hwndTree) { 412 id = WinQueryWindowUShort(hwndC, QWS_ID); 413 if (id) { 414 hwndDir = WinWindowFromID(hwndC, FID_CLIENT); 415 if (hwndDir) { 416 hwndDir = WinWindowFromID(hwndDir, DIR_CNR); 417 if (hwndDir) { 418 *retstr = 0; 419 WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID); 420 if (*retstr) { 421 if (!first) { 422 *pp = ' '; 423 pp++; 424 } 425 first = FALSE; 426 if (needs_quoting(retstr) && !strchr(retstr, '\"')) { 427 *pp = '\"'; 428 pp++; 429 spaces = TRUE; 430 } 431 else 432 spaces = FALSE; 433 strcpy(pp, retstr); 434 pp += strlen(retstr); 435 if (spaces) { 436 *pp = '\"'; 437 pp++; 438 } 439 } 440 } 441 } 442 } 443 } 444 } 445 WinEndEnumWindows(henum); 446 } 447 p += 2; 448 break; 441 449 442 450 case '%': 443 444 445 446 451 *pp = '%'; 452 pp++; 453 p += 2; 454 break; 447 455 448 456 case 'R': … … 453 461 case 'a': 454 462 case 'e': 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 463 if (list) { 464 for (x = 0; list[x]; x++) 465 { 466 file = strrchr(list[x], '\\'); 467 if (!file) 468 file = strrchr(list[x], ':'); 469 if (file) 470 file++; 471 else 472 file = list[x]; 473 ext = strrchr(file, '.'); 474 dot = ext; 475 if (ext) 476 ext++; 477 switch (*(p + 1)) { 478 case 'R': 479 case 'r': 480 if (pp + strlen(list[x]) > commandline + MaxComLineStrg) 481 goto BreakOut; 482 if (*(p + 1) == 'r') { 483 strcpy(pp, list[x]); 484 pp += strlen(list[x]); 485 } 486 else { 487 strcpy(pp, list[x] + 2); 488 pp += strlen(list[x] + 2); 489 } 490 break; 491 492 case 'F': 493 case 'f': 494 if (*(p + 1) == 'F' && dot) 495 *dot = 0; 496 if (pp + strlen(file) > commandline + MaxComLineStrg) 497 goto BreakOut; 498 if (needs_quoting(file)) { 499 spaces = TRUE; 500 *pp = '\"'; 501 pp++; 502 } 503 else 504 spaces = FALSE; 505 strcpy(pp, file); 506 pp += strlen(file); 507 if (*(p + 1) == 'F' && dot) 508 *dot = '.'; 509 if (spaces) { 510 if (*(pp - 1) != '\"') { 511 *pp = '\"'; 512 pp++; 513 } 514 } 515 break; 516 517 case 'A': 518 case 'a': 519 if (pp + strlen(list[x]) > commandline + MaxComLineStrg) 520 goto BreakOut; 521 if (needs_quoting(list[x]) && !strchr(list[x], '\"')) { 522 spaces = TRUE; 523 *pp = '\"'; 524 pp++; 525 } 526 else 527 spaces = FALSE; 528 if (*(p + 1) == 'a') { 529 strcpy(pp, list[x]); 530 pp += strlen(list[x]); 531 } 532 else { 533 strcpy(pp, list[x] + 2); 534 pp += strlen(list[x] + 2); 535 } 536 if (spaces) { 537 if (list[x][strlen(list[x]) - 1] == '\\') { 538 *pp = '\\'; 539 pp++; 540 } 541 *pp = '\"'; 542 pp++; 543 } 544 break; 545 546 case 'e': 547 if (ext) { 548 if (pp + strlen(ext) > commandline + MaxComLineStrg) 549 goto BreakOut; 550 if (needs_quoting(ext)) { 551 spaces = TRUE; 552 *pp = '\"'; 553 pp++; 554 } 555 else 556 spaces = FALSE; 557 strcpy(pp, ext); 558 pp += strlen(ext); 559 if (spaces) { 560 if (*(pp - 1) != '\"') { 561 *pp = '\"'; 562 pp++; 563 } 564 } 565 } 566 break; 567 } 568 if (list[x + 1]) { 569 *pp = ' '; 570 pp++; 571 } 572 } 573 } 574 p += 2; 575 break; 568 576 569 577 default: 570 571 572 573 578 *pp = *p; 579 p++; 580 pp++; 581 break; 574 582 } 575 583 } … … 598 606 strcpy(ex.path, path); 599 607 if (prompt) 600 608 strcpy(ex.title, prompt); 601 609 ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle, 602 610 EXEC_FRAME, &ex); 603 611 if (ret != 1) { 604 612 free(commandline); … … 610 618 ex.flags &= (~PROMPT); 611 619 ret = runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path, 612 620 (*ex.environment) ? ex.environment : NULL, 613 621 "%s", commandline); 614 622 free(commandline); … … 622 630 623 631 int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber, 624 625 632 char *pszDirectory, char *pszEnvironment, 633 char *formatstring,...) 626 634 { 627 635 /** example: … … 678 686 if (pszDirectory && *pszDirectory) { 679 687 if (!DosQueryPathInfo(pszDirectory, 680 681 682 688 FIL_QUERYFULLNAME, 689 szTempdir, 690 sizeof(szTempdir))) 683 691 pszDirectory = szTempdir; 684 692 } … … 688 696 689 697 rc = DosAllocMem((PVOID)&pszPgm, 690 691 698 MaxComLineStrg, 699 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 692 700 if (rc) { 693 701 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); … … 699 707 *pszPgm = 0; 700 708 va_start(parguments, 701 709 formatstring); 702 710 vsprintf(pszPgm, 703 704 711 formatstring, 712 parguments); 705 713 va_end(parguments); 706 714 … … 732 740 temp = *p; 733 741 if (temp) { 734 735 736 737 738 742 rc = DosAllocMem((PVOID)&pszArgs, 743 MaxComLineStrg * 2, 744 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 745 if (rc) 746 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 739 747 } 740 748 else 741 749 pszArgs = NULL; 742 750 *p = 0; 743 751 /* Find the handle of the WPS object */ … … 745 753 *p = temp; 746 754 if (hWPSObject != NULLHANDLE) { 747 748 749 750 751 752 753 755 if (pszArgs && *p) { 756 sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p); 757 WinSetObjectData(hWPSObject,pszArgs); 758 } 759 else 760 WinSetObjectData(hWPSObject,"OPEN=DEFAULT"); 761 ret = 0; 754 762 } 755 763 goto ObjectInterrupt; … … 757 765 758 766 if ((type & RUNTYPE_MASK) == SYNCHRONOUS || 759 760 767 (type & RUNTYPE_MASK) == ASYNCHRONOUS || 768 (type & RUNTYPE_MASK) == DETACHED) 761 769 { 762 770 strip_lead_char(" \t", pszPgm); … … 764 772 wasquote = FALSE; 765 773 while (*p && 766 767 768 774 (wasquote || 775 (*p != ' ' && 776 *p != '\t'))) 769 777 { 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 778 if (*p == '\"') { 779 if (!wasquote) { 780 wasquote = TRUE; 781 memmove(p, 782 p + 1, 783 strlen(p)); 784 while (*p == ' ' || 785 *p == '\t') 786 p++; 787 } 788 else { 789 memmove(p, 790 p + 1, 791 strlen(p)); 792 break; 793 } 794 } 795 else 796 p++; 789 797 } 790 798 if (*p) { 791 792 799 *p = 0; 800 p++; 793 801 } 794 802 else 795 796 p[strlen(p) + 1] = 0; 803 p = pszPgm; 804 p[strlen(p) + 1] = 0; /* double-terminate args */ 797 805 if (*pszPgm) { 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 pszPgm, pszCallingFile, uiLineNumber);// 26 May 08 SHL816 817 818 819 820 821 822 823 824 825 826 827 ulAppType, pszPgm, pszCallingFile, uiLineNumber);// 26 May 08 SHL828 829 830 831 832 833 834 835 836 837 838 839 ulAppType, pszPgm, pszCallingFile, uiLineNumber);// 26 May 08 SHL840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 pszCallingFile, uiLineNumber);// 26 May 08 SHL862 806 if (!strchr(pszPgm, '\\') && 807 !strchr(pszPgm, ':') && 808 pszDirectory && 809 *pszDirectory) 810 { 811 strcpy(szSavedir, pFM2SaveDirectory); 812 switch_to(pszDirectory); 813 } 814 rc = DosQueryAppType(pszPgm,&ulAppType); 815 if (!strchr(pszPgm, '\\') && 816 !strchr(pszPgm, ':') && 817 pszDirectory && 818 *pszDirectory) 819 switch_to(szSavedir); 820 if (rc) { 821 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__, 822 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT), 823 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL 824 DosFreeMem(pszPgm); 825 if (pszArgs) 826 DosFreeMem(pszArgs); 827 return -1; 828 } 829 if (ulAppType) { 830 if (ulAppType & FAPPTYP_DLL || ulAppType & FAPPTYP_VIRTDRV || 831 ulAppType & FAPPTYP_PHYSDRV || ulAppType & FAPPTYP_PROTDLL) 832 { 833 Runtime_Error(pszSrcFile, __LINE__, 834 GetPString(IDS_APPTYPEUNEXPECTEDTEXT), 835 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL 836 if (pszPgm) 837 DosFreeMem(pszPgm); 838 if (pszArgs) 839 DosFreeMem(pszArgs); 840 return -1; 841 } 842 if (ulAppType & FAPPTYP_DOS || ulAppType & FAPPTYP_WINDOWSREAL || 843 ulAppType & FAPPTYP_WINDOWSPROT || ulAppType & FAPPTYP_WINDOWSPROT31) 844 { 845 Runtime_Error(pszSrcFile, __LINE__, 846 GetPString(IDS_APPTYPEUNEXPECTEDTEXT), 847 ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL 848 if (pszPgm) 849 DosFreeMem(pszPgm); 850 if (pszArgs) 851 DosFreeMem(pszArgs); 852 return -1; 853 } 854 } 855 memset(&results, 0, sizeof(results)); 856 if (pszDirectory && *pszDirectory) { 857 strcpy(szSavedir, pFM2SaveDirectory); 858 switch_to(pszDirectory); 859 } 860 ret = DosExecPgm(szObject, sizeof(szObject), 861 ((type & RUNTYPE_MASK) == ASYNCHRONOUS ? EXEC_ASYNC : 0) + 862 ((type & RUNTYPE_MASK) == DETACHED ? EXEC_BACKGROUND : 0), 863 pszPgm, pszEnvironment, &results, pszPgm); 864 if (pszDirectory && *pszDirectory) 865 switch_to(szSavedir); 866 if (ret) { 867 Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__, 868 GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm, 869 pszCallingFile, uiLineNumber); // 26 May 08 SHL 870 } 863 871 } 864 872 } 865 873 else { 866 874 if (~type & FULLSCREEN) 867 875 type |= WINDOWED; 868 876 rc = DosAllocMem((PVOID) & pszArgs, MaxComLineStrg * 2, 869 877 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); 870 878 if (rc) { 871 872 873 879 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); 880 DosFreeMem(pszPgm); 881 return -1; 874 882 } 875 883 *pszArgs = 0; … … 879 887 wasquote = FALSE; 880 888 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) { 881 882 883 884 885 886 887 888 889 890 891 892 893 894 889 if (*p == '\"') { 890 if (!wasquote) { 891 wasquote = TRUE; 892 memmove(p, p + 1, strlen(p)); 893 while (*p == ' ' || *p == '\t') 894 p++; 895 } 896 else { 897 memmove(p, p + 1, strlen(p)); 898 break; 899 } 900 } 901 else 902 p++; 895 903 } // while 896 904 if (*p) { 897 898 905 *p = 0; 906 p++; 899 907 } 900 908 else 901 909 p = NullStr; 902 910 if (*p) 903 911 strcpy(pszArgs, p); 904 912 905 913 p = strrchr(pszPgm, '.'); 906 914 if (p) { 907 908 909 910 911 912 913 914 915 916 strcpy(pszPgm, GetCmdSpec(TRUE));// DOS917 918 919 920 921 922 923 924 925 926 strcpy(pszPgm, GetCmdSpec(FALSE));// OS/2927 915 char temp[CCHMAXPATH + 1]; 916 917 if (!stricmp(p, ".BAT")) { 918 strcpy(temp, pszPgm); 919 strcpy(pszPgm, pszArgs); 920 strcpy(pszArgs, "/C "); 921 strcat(pszArgs, temp); 922 strcat(pszArgs, " "); 923 strcat(pszArgs, pszPgm); 924 strcpy(pszPgm, GetCmdSpec(TRUE)); // DOS 925 } 926 else if (!stricmp(p, ".CMD") || !stricmp(p, ".BTM")) { 927 // Assume 4OS2 is BTM 928 strcpy(temp, pszPgm); 929 strcpy(pszPgm, pszArgs); 930 strcpy(pszArgs, "/C "); 931 strcat(pszArgs, temp); 932 strcat(pszArgs, " "); 933 strcat(pszArgs, pszPgm); 934 strcpy(pszPgm, GetCmdSpec(FALSE)); // OS/2 935 } 928 936 } 929 937 … … 931 939 932 940 if (strlen(pszPgm) + strlen(pszArgs) > 1024) 933 941 pszArgs[1024 - strlen(pszPgm)] = 0; 934 942 935 943 if (!strchr(pszPgm, '\\') && 936 937 938 944 !strchr(pszPgm, ':') && 945 pszDirectory && 946 *pszDirectory) 939 947 { 940 941 948 strcpy(szSavedir, pFM2SaveDirectory); 949 switch_to(pszDirectory); 942 950 } 943 951 rc = DosQueryAppType(pszPgm,&ulAppType); 944 952 if (!strchr(pszPgm, '\\') && 945 946 947 948 953 !strchr(pszPgm, ':') && 954 pszDirectory && 955 *pszDirectory) 956 switch_to(szSavedir); 949 957 if (rc) { 950 951 952 pszPgm, pszCallingFile, uiLineNumber);// 26 May 08 SHL953 954 955 956 958 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__, 959 GetPString(IDS_DOSQAPPTYPEFAILEDTEXT), 960 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL 961 DosFreeMem(pszPgm); 962 if (pszArgs) 963 DosFreeMem(pszArgs); 964 return -1; 957 965 } 958 966 959 967 if (ulAppType) { 960 961 962 963 964 pszPgm, pszCallingFile, uiLineNumber);// 26 May 08 SHL965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 else/* ? */1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 968 if (ulAppType & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL)) 969 { 970 Runtime_Error(pszSrcFile, __LINE__, 971 GetPString(IDS_APPTYPEUNEXPECTEDTEXT), 972 pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL 973 DosFreeMem(pszPgm); 974 if (pszArgs) 975 DosFreeMem(pszArgs); 976 return -1; 977 } 978 ulAppType &= ~FAPPTYP_BOUND; 979 if (ulAppType & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31)) 980 { 981 if (ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31)) 982 { 983 if (~type & FULLSCREEN && 984 ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31)) 985 { 986 ret = RunSeamless(pszPgm, pszArgs, hwnd); 987 if (pszPgm) 988 DosFreeMem(pszPgm); 989 if (pszArgs) 990 DosFreeMem(pszArgs); 991 return ret ? 0 : -1; 992 } 993 else { 994 strcat(pszPgm, " "); 995 strcat(pszPgm, pszArgs); 996 *pszArgs = 0; 997 if (ulAppType & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31)) 998 strcat(pszArgs, "/3 "); 999 strcat(pszArgs, pszPgm); 1000 strcpy(pszPgm, "WINOS2.COM"); 1001 } 1002 } 1003 else { 1004 if (~type & FULLSCREEN) { 1005 type |= WINDOWED; 1006 ulAppType = SSF_TYPE_WINDOWEDVDM; 1007 } 1008 else { 1009 type &= ~WINDOWED; 1010 ulAppType = SSF_TYPE_VDM; 1011 } 1012 } 1013 } 1014 else if (ulAppType & FAPPTYP_32BIT) { 1015 ulAppType &= ~FAPPTYP_32BIT; 1016 if (ulAppType == FAPPTYP_WINDOWAPI) 1017 ulAppType = SSF_TYPE_PM; 1018 else if (ulAppType == FAPPTYP_WINDOWCOMPAT) 1019 ulAppType = SSF_TYPE_WINDOWABLEVIO; 1020 else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) { 1021 ulAppType = SSF_TYPE_FULLSCREEN; 1022 type &= ~WINDOWED; 1023 type |= FULLSCREEN; 1024 } 1025 else /* ? */ 1026 ulAppType = SSF_TYPE_WINDOWABLEVIO; 1027 } 1028 else if (ulAppType == FAPPTYP_WINDOWAPI) 1029 ulAppType = SSF_TYPE_PM; 1030 else if (ulAppType == FAPPTYP_WINDOWCOMPAT) 1031 ulAppType = SSF_TYPE_WINDOWABLEVIO; 1032 else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) { 1033 type &= ~WINDOWED; 1034 ulAppType = SSF_TYPE_FULLSCREEN; 1035 } 1036 else 1037 ulAppType = SSF_TYPE_DEFAULT; 1038 if ((type & FULLSCREEN || ~type & WINDOWED) && 1039 ulAppType == SSF_TYPE_WINDOWABLEVIO) 1040 { 1041 ulAppType = SSF_TYPE_FULLSCREEN; 1042 } 1043 // fixme parens? 1044 else if (type & FULLSCREEN || 1045 (type & WINDOWED && ulAppType == SSF_TYPE_WINDOWEDVDM)) 1046 { 1047 ulAppType = SSF_TYPE_VDM; 1048 } 1041 1049 } 1042 1050 if (ulAppType == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) { 1043 1044 1051 type &= ~SEPARATEKEEP; 1052 type |= SEPARATE; 1045 1053 } 1046 1054 … … 1048 1056 1049 1057 if (~type & WAIT) 1050 1058 useTermQ = FALSE; 1051 1059 else { 1052 1053 1054 1055 1056 1057 1058 1059 hTermQ = (HQUEUE)0;// Try to survive1060 1061 1062 1063 1064 1065 1066 hTermQSem = (HEV)0;// Try to survive1067 1068 hTermQ = (HQUEUE)0;// Try to survive1069 1070 1071 1072 1073 1074 1075 1076 1077 1060 rc = 0; 1061 DosEnterCritSec(); 1062 if (!hTermQ) { 1063 // Create term queue and event semaphore just once 1064 sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid); 1065 rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName); 1066 if (rc) { 1067 hTermQ = (HQUEUE)0; // Try to survive 1068 DosExitCritSec(); 1069 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue"); 1070 } 1071 else { 1072 rc = DosCreateEventSem(NULL,(PHEV)&hTermQSem,0,FALSE); 1073 if (rc) { 1074 hTermQSem = (HEV)0; // Try to survive 1075 DosCloseQueue(hTermQ); 1076 hTermQ = (HQUEUE)0; // Try to survive 1077 DosExitCritSec(); 1078 Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__,"DoCreateEventSem"); 1079 } 1080 // if (!rc) fprintf(stderr,"%s %d qcreated ptib %x hTermQ %x\n",__FILE__, __LINE__,ptib,hTermQ); 1081 } 1082 } // if 1st time 1083 useTermQ = hTermQ && hTermQSem; 1084 if (!rc) 1085 DosExitCritSec(); 1078 1086 } // if wait 1079 1087 … … 1081 1089 sdata.Length = sizeof(sdata); 1082 1090 sdata.Related = type & (WAIT | CHILD) ? SSF_RELATED_CHILD : 1083 1091 SSF_RELATED_INDEPENDENT; 1084 1092 sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE; 1085 1093 sdata.TraceOpt = SSF_TRACEOPT_NONE; 1086 1094 sdata.PgmName = pszPgm; 1087 1095 if (*pszArgs) 1088 1096 sdata.PgmInputs = pszArgs; 1089 1097 if (useTermQ) 1090 1098 sdata.TermQ = szTermQName; 1091 1099 sdata.Environment = pszEnvironment; 1092 1100 sdata.InheritOpt = SSF_INHERTOPT_PARENT; … … 1095 1103 sdata.ObjectBuffLen = sizeof(szObject); 1096 1104 if ((type & RUNTYPE_MASK) == SEPARATEKEEP) 1097 1105 sdata.PgmControl |= SSF_CONTROL_NOAUTOCLOSE; 1098 1106 if (type & MAXIMIZED) 1099 1107 sdata.PgmControl |= SSF_CONTROL_MAXIMIZE; 1100 1108 if (type & MINIMIZED) 1101 1109 sdata.PgmControl |= SSF_CONTROL_MINIMIZE; 1102 1110 if (type & INVISIBLE) 1103 1111 sdata.PgmControl |= SSF_CONTROL_INVISIBLE; 1104 1112 1105 1113 if (pszDirectory && *pszDirectory) { 1106 1107 1114 strcpy(szSavedir, pFM2SaveDirectory); 1115 switch_to(pszDirectory); 1108 1116 } 1109 1117 1110 1118 // printf("%s %d DosStartsession thread 0x%x data\n ", 1111 // __FILE__, __LINE__,ptib->tib_ordinal); fflush(stdout); 1119 // __FILE__, __LINE__,ptib->tib_ordinal); fflush(stdout); // 10 Mar 07 SHL hang 1112 1120 // printf(" %d %d %d %s %s %s %d %d\n %s %x %x\n", 1113 1121 // sdata.Length , sdata.Related, sdata.FgBg, sdata.PgmName, … … 1119 1127 // if (type & WAIT) { 1120 1128 // printf("%s %d DosStartession thread 0x%x rc = %d sess = %u pid = 0x%x\n", 1121 // __FILE__, __LINE__, ptib->tib_ordinal,ret, ulSessID, sessPID); fflush(stdout); 1129 // __FILE__, __LINE__, ptib->tib_ordinal,ret, ulSessID, sessPID); fflush(stdout); // 10 Mar 07 SHL hang 1122 1130 // } 1123 1131 // else { 1124 1132 // printf("%s %d DosStartession thread 0x%x nowait rc = %d\n", 1125 // __FILE__, __LINE__, ptib->tib_ordinal,ret); fflush(stdout); 1133 // __FILE__, __LINE__, ptib->tib_ordinal,ret); fflush(stdout); // 10 Mar 07 SHL hang 1126 1134 // } 1127 1135 1128 1136 if (pszDirectory && *pszDirectory) 1129 1137 switch_to(szSavedir); 1130 1138 1131 1139 if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) { 1132 1133 1134 pszCallingFile, uiLineNumber);// 26 May 08 SHL1140 Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__, 1141 GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs, 1142 pszCallingFile, uiLineNumber); // 26 May 08 SHL 1135 1143 } 1136 1144 else if (type & WAIT) { 1137 1138 1139 1140 1141 1142 1143 // printf("%s %d waiting wo/termq\n", __FILE__, __LINE__); fflush(stdout);// 12 Mar 07 SHL hang1144 1145 1146 1147 1148 1149 1150 1151 1152 if (DosSetSession(ulSessID, &sd))// Check if session gone (i.e. finished)1153 1154 1155 1156 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,sessPID); fflush(stdout);// 12 Mar 07 SHL1157 ShowSession(hwnd, sessPID);// Show every 2 seconds1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 ShowSession(hwnd, sessPID);// Show long running session1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 break;// Our session is done1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 DosSleep(50); //05 Aug 07 GKY 100// Let other thread see queue entry1211 1212 1213 1214 ret = pTermInfo->usRC == 0;// Set 1 if rc 0 else 01215 1216 1217 1218 1145 if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE))) 1146 ShowSession(hwnd, sessPID); 1147 1148 if (!useTermQ) { 1149 STATUSDATA sd; 1150 // Could not create queue - fallback - fixme to be gone? 1151 // printf("%s %d waiting wo/termq\n", __FILE__, __LINE__); fflush(stdout); // 12 Mar 07 SHL hang 1152 1153 memset(&sd, 0, sizeof(sd)); 1154 sd.Length = (USHORT) sizeof(sd); 1155 sd.SelectInd = SET_SESSION_UNCHANGED; 1156 sd.BondInd = SET_SESSION_UNCHANGED; 1157 for (ctr = 0;; ctr++) 1158 { 1159 DosSleep(100);//05 Aug 07 GKY 200 1160 if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished) 1161 break; 1162 if (ctr > 10) { 1163 // printf("%s %d thread 0x%x showing slow sess %u pid 0x%x\n", 1164 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,sessPID); fflush(stdout); // 12 Mar 07 SHL 1165 ShowSession(hwnd, sessPID); // Show every 2 seconds 1166 ctr = 0; 1167 } 1168 } 1169 } 1170 else { 1171 for (ctr = 0;; ctr++) 1172 { 1173 if (ctr < 20) { 1174 rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0, 1175 DCWW_NOWAIT, &bPriority, hTermQSem); 1176 if (rc == ERROR_QUE_EMPTY) { 1177 DosSleep(50);//05 Aug 07 GKY 100 1178 continue; 1179 } 1180 } 1181 else { 1182 if (ctr == 20) { 1183 // printf("%s %d thread 0x%x showing slow sess %u pid 0x%x\n", 1184 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,sessPID); fflush(stdout); 1185 ShowSession(hwnd, sessPID); // Show long running session 1186 } 1187 rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0, 1188 DCWW_WAIT, &bPriority, 0); 1189 } 1190 1191 if (rc) { 1192 // Oh heck 1193 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue"); 1194 DosSleep(100);//05 Aug 07 GKY 500 1195 continue; 1196 } 1197 1198 // printf("%s %d DosReadQueue thread 0x%x sess %u sessRC %u rq.pid 0x%x rq.data 0x%x\n", 1199 // __FILE__, __LINE__,ptib->tib_ordinal,pTermInfo->usSessID,pTermInfo->usRC,rq.pid, rq.ulData); fflush(stdout); 1200 1201 if (pTermInfo->usSessID == ulSessID) 1202 break; // Our session is done 1203 1204 // Requeue session for other thread 1205 { 1206 static ULONG ulLastSessID; 1207 // printf("%s %d requeue thread 0x%x our sess %u term sess %u term rc %u\n", 1208 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,pTermInfo->usSessID,pTermInfo->usRC); fflush(stdout); 1209 // fixme to be gone when no longer needed for debug? 1210 if (ulLastSessID) { 1211 DosSleep(100);//05 Aug 07 GKY 500 1212 ulLastSessID = pTermInfo->usSessID; 1213 } 1214 // requeue term report for other thread and do not free yet 1215 rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority); 1216 if (rc) 1217 Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue"); 1218 DosSleep(50); //05 Aug 07 GKY 100 // Let other thread see queue entry 1219 } 1220 } // for 1221 1222 ret = pTermInfo->usRC == 0; // Set 1 if rc 0 else 0 1223 // printf("%s %d thread 0x%x term for sess %u\n", 1224 // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID);fflush(stdout); 1225 DosFreeMem(pTermInfo); 1226 } 1219 1227 } // if wait 1220 1228 else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE))) 1221 1229 ShowSession(hwnd, sessPID); 1222 1230 } 1223 1231 } … … 1234 1242 1235 1243 //== Exec() Start application with WinStartApp == 1236 1244 #if 0 //JBS 1237 1245 HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env, 1238 1246 PROGTYPE *progt, ULONG fl, char *formatstring,...) 1239 1247 { 1240 1248 PROGDETAILS pgd; … … 1258 1266 parameters = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__); 1259 1267 if (parameters) { 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1268 p = executable; 1269 wasquote = FALSE; 1270 while (*p && (wasquote || (*p != ' ' && *p != '\t'))) { 1271 if (*p == '\"') { 1272 if (!wasquote) { 1273 wasquote = TRUE; 1274 memmove(p, p + 1, strlen(p)); 1275 while (*p == ' ' || *p == '\t') 1276 p++; 1277 } 1278 else { 1279 memmove(p, p + 1, strlen(p)); 1280 break; 1281 } 1282 } 1283 else 1284 p++; 1285 } 1286 if (*p) { 1287 *p = 0; 1288 p++; 1289 } 1290 else 1291 p = NullStr; 1292 if (*p) 1293 strcpy(parameters, p); 1294 1295 if (p && (!stricmp(p, ".BAT") || !stricmp(p, ".CMD"))) { 1296 char *temp; 1297 1298 temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__); 1299 if (temp) { 1300 if (!stricmp(p, ".BAT")) { 1301 strcpy(temp, executable); 1302 strcpy(executable, parameters); 1303 strcpy(parameters, "/C "); 1304 strcat(parameters, temp); 1305 strcat(parameters, " "); 1306 strcat(parameters, executable); 1307 strcpy(executable, GetCmdSpec(TRUE)); 1308 } 1309 else if (!stricmp(p, ".CMD")) { 1310 strcpy(temp, executable); 1311 strcpy(executable, parameters); 1312 strcpy(parameters, "/C "); 1313 strcat(parameters, temp); 1314 strcat(parameters, " "); 1315 strcat(parameters, executable); 1316 strcpy(executable, GetCmdSpec(FALSE)); 1317 } 1318 free(temp); 1319 } 1320 } 1321 1322 memset(&pgd, 0, sizeof(pgd)); 1323 pgd.Length = sizeof(pgd); 1324 pgd.progt = *progt; 1325 pgd.swpInitial.fl = fl; 1326 pgd.pszEnvironment = env; 1327 pgd.pszStartupDir = startdir; 1328 pgd.pszParameters = *parameters ? parameters : NULL; 1329 pgd.pszExecutable = executable; 1330 pgd.swpInitial.hwndInsertBehind = HWND_TOP; 1331 happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions); 1332 free(parameters); 1325 1333 } 1326 1334 } … … 1329 1337 return happ; 1330 1338 } 1331 1339 #endif 1332 1340 #pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
Note:
See TracChangeset
for help on using the changeset viewer.