Changeset 1335 for trunk/dll/grep2.c
- Timestamp:
- Dec 13, 2008, 12:49:02 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/grep2.c
r1283 r1335 4 4 $Id$ 5 5 6 Grep dialog for collector6 grep dialog for collector 7 7 8 8 Copyright (c) 1993-98 M. Kimes 9 Copyright (c) 2004, 200 6Steven H. Levine9 Copyright (c) 2004, 2008 Steven H. Levine 10 10 11 11 01 Aug 04 SHL Rework lstrip/rstrip usage … … 22 22 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName 23 23 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file 24 10 Dec 08 SHL Integrate exception handler support 24 25 25 26 fixme for more excess locals to be gone … … 32 33 #include <share.h> 33 34 #include <time.h> 34 #include <process.h> // _beginthread35 // #include <process.h> // _beginthread 35 36 36 37 #define INCL_DOS … … 60 61 #include "dirs.h" // save_dir2 61 62 #include "fortify.h" 63 #include "excputil.h" // xbeginthread 62 64 63 65 #pragma data_seg(DATA1) … … 80 82 *(CHAR *)mp2 = 0; 81 83 { 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 84 CHAR *p; 85 CHAR *pp; 86 87 p = GetPString(IDS_ENVVARNAMES); 88 while (*p == ' ') 89 p++; 90 while (*p) { 91 *szPath = 0; 92 pp = szPath; 93 while (*p && *p != ' ') 94 *pp++ = *p++; 95 *pp = 0; 96 while (*p == ' ') 97 p++; 98 if (*szPath) 99 WinSendDlgItemMsg(hwnd, 100 ENV_LISTBOX, 101 LM_INSERTITEM, 102 MPFROM2SHORT(LIT_END, 0), MPFROMP(szPath)); 103 } 102 104 } 103 105 WinSendDlgItemMsg(hwnd, 104 105 106 ENV_NAME, 107 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID); 106 108 WinSetDlgItemText(hwnd, ENV_NAME, lastenv); 107 109 WinSendDlgItemMsg(hwnd, 108 109 110 ENV_NAME, 111 EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID); 110 112 } 111 113 else … … 118 120 switch (SHORT2FROMMP(mp1)) { 119 121 case LN_SELECT: 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 122 { 123 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 124 ENV_LISTBOX, 125 LM_QUERYSELECTION, 126 MPFROMSHORT(LIT_FIRST), MPVOID); 127 if (sSelect >= 0) { 128 *s = 0; 129 WinSendDlgItemMsg(hwnd, 130 ENV_LISTBOX, 131 LM_QUERYITEMTEXT, 132 MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s)); 133 bstrip(s); 134 if (*s) 135 WinSetDlgItemText(hwnd, ENV_NAME, s); 136 } 137 } 138 break; 137 139 case LN_ENTER: 138 139 140 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID); 141 break; 140 142 } 141 143 } … … 150 152 p = WinQueryWindowPtr(hwnd, QWL_USER); 151 153 if (p) { 152 153 154 155 156 157 158 159 160 161 154 WinQueryDlgItemText(hwnd, ENV_NAME, CCHMAXPATH, p); 155 bstrip(p); 156 if (!*p) { 157 DosBeep(50, 100); 158 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ENV_NAME)); 159 } 160 else { 161 strcpy(lastenv, p); 162 WinDismissDlg(hwnd, 1); 163 } 162 164 } 163 165 break; 164 166 case IDM_HELP: 165 167 if (hwndHelp) 166 167 168 168 WinSendMsg(hwndHelp, 169 HM_DISPLAY_HELP, 170 MPFROM2SHORT(HELP_ENV, 0), MPFROMSHORT(HM_RESOURCEID)); 169 171 break; 170 172 } … … 212 214 WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2); 213 215 WinSendDlgItemMsg(hwnd, 214 215 216 GREP_MASK, 217 EM_SETTEXTLIMIT, MPFROM2SHORT(8192, 0), MPVOID); 216 218 MLEsetlimit(hwndMLE, 4096); 217 219 MLEsetformat(hwndMLE, MLFIE_NOTRANS); 218 220 WinSendDlgItemMsg(hwnd, 219 220 221 GREP_NEWER, 222 EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); 221 223 WinSendDlgItemMsg(hwnd, 222 223 224 GREP_OLDER, 225 EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); 224 226 WinSendDlgItemMsg(hwnd, 225 226 227 GREP_GREATER, 228 EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); 227 229 WinSendDlgItemMsg(hwnd, 228 229 230 GREP_LESSER, 231 EM_SETTEXTLIMIT, MPFROM2SHORT(34, 0), MPVOID); 230 232 WinSetDlgItemText(hwnd, GREP_MASK, lastmask); 231 233 WinSendDlgItemMsg(hwnd, 232 234 GREP_MASK, EM_SETSEL, MPFROM2SHORT(0, 8192), MPVOID); 233 235 PrfQueryProfileData(fmprof, FM3Str, "RememberFlagsGrep", 234 236 (PVOID) & gRemember, &size); 235 237 WinCheckButton(hwnd, GREP_REMEMBERFLAGS, gRemember); 236 238 if (gRemember) { 237 239 PrfQueryProfileData(fmprof, FM3Str, "Grep_Recurse", 238 240 (PVOID) & recurse, &size); 239 241 PrfQueryProfileData(fmprof, FM3Str, "Grep_Absolute", 240 242 (PVOID) & absolute, &size); 241 243 PrfQueryProfileData(fmprof, FM3Str, "Grep_Case", 242 244 (PVOID) & sensitive, &size); 243 245 PrfQueryProfileData(fmprof, FM3Str, "Grep_Sayfiles", 244 246 (PVOID) & sayfiles, &size); 245 247 PrfQueryProfileData(fmprof, FM3Str, "Grep_Searchfiles", 246 248 (PVOID) & searchFiles, &size); 247 249 PrfQueryProfileData(fmprof, FM3Str, "Grep_SearchfEAs", 248 250 (PVOID) & searchEAs, &size); 249 251 } 250 252 if (!gRemember) { … … 261 263 MLEsetcurposa(hwndMLE, 4096); 262 264 if (!searchEAs) 263 265 searchFiles = TRUE; 264 266 } 265 267 WinCheckButton(hwnd, GREP_RECURSE, recurse); … … 288 290 if (fp) { 289 291 while (!feof(fp)) { 290 291 292 293 294 295 296 297 292 if (!xfgets_bstripcr(s, 8192 + 4, fp, pszSrcFile, __LINE__)) 293 break; 294 if (*s && *s != ';') { 295 WinSendDlgItemMsg(hwnd, 296 GREP_LISTBOX, 297 LM_INSERTITEM, 298 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s)); 299 } 298 300 } 299 301 fclose(fp); … … 301 303 302 304 FillPathListBox(hwnd, 303 304 305 WinWindowFromID(hwnd, GREP_DRIVELIST), 306 (HWND) 0, NULL, FALSE); 305 307 break; 306 308 … … 311 313 case UM_SETDIR: 312 314 PaintRecessedWindow(WinWindowFromID(hwnd, GREP_HELP), 313 315 (HPS) 0, FALSE, TRUE); 314 316 return 0; 315 317 … … 324 326 case GREP_REMEMBERFLAGS: 325 327 { 326 327 328 329 328 BOOL gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS); 329 330 PrfWriteProfileData(fmprof, FM3Str, "RememberFlagsGrep", 331 (PVOID) & gRemember, sizeof(BOOL)); 330 332 } 331 333 break; … … 334 336 switch (SHORT2FROMMP(mp1)) { 335 337 case LN_KILLFOCUS: 336 337 338 338 WinSetDlgItemText(hwnd, 339 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 340 break; 339 341 case LN_SETFOCUS: 340 341 342 342 WinSetDlgItemText(hwnd, 343 GREP_HELP, GetPString(IDS_2CLICKADDDRVMASKTEXT)); 344 break; 343 345 case LN_ENTER: 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 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 392 346 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); 347 bstrip(s); 348 p = strrchr(s, '\\'); 349 if (p) 350 strcpy(simple, p); 351 else if (*s) { 352 strcpy(simple, "\\"); 353 strcat(simple, s); 354 *s = 0; 355 } 356 else 357 strcpy(simple, "\\*"); 358 if (simple[strlen(simple) - 1] == ';') 359 simple[strlen(simple) - 1] = 0; 360 lLen = strlen(simple) + 1; 361 if (strlen(s) > 8192 - lLen) { 362 Runtime_Error(pszSrcFile, __LINE__, "too big"); 363 WinSetDlgItemText(hwnd, GREP_MASK, s); 364 break; 365 } 366 367 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 368 GREP_DRIVELIST, 369 LM_QUERYSELECTION, 370 MPFROMSHORT(LIT_FIRST), MPVOID); 371 if (sSelect >= 0) { 372 if (*s && s[strlen(s) - 1] != ';') 373 strcat(s, ";"); 374 WinSendDlgItemMsg(hwnd, 375 GREP_DRIVELIST, 376 LM_QUERYITEMTEXT, 377 MPFROM2SHORT(sSelect, 378 (8192 - strlen(s)) - lLen), 379 MPFROMP(&s[strlen(s)])); 380 rstrip(s); 381 if (*s) { 382 strcat(s, simple); 383 WinSetDlgItemText(hwnd, GREP_MASK, s); 384 WinSendDlgItemMsg(hwnd, 385 GREP_MASK, 386 EM_SETSEL, 387 MPFROM2SHORT(strlen(s) - (lLen + 1), 388 strlen(s)), MPVOID); 389 PostMsg(hwnd, 390 UM_FOCUSME, 391 MPFROMLONG(WinWindowFromID(hwnd, GREP_MASK)), MPVOID); 392 } 393 } 394 break; // LN_ENTER 393 395 } // switch 394 396 break; … … 397 399 switch (SHORT2FROMMP(mp1)) { 398 400 case LN_KILLFOCUS: 399 400 401 401 WinSetDlgItemText(hwnd, 402 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 403 break; 402 404 case LN_SETFOCUS: 403 404 405 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_ADDSELDELMASKTEXT)); 406 break; 405 407 case LN_ENTER: 406 408 case LN_SELECT: 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 409 if ((SHORT2FROMMP(mp1) == LN_ENTER && 410 !WinQueryButtonCheckstate(hwnd, GREP_APPEND)) || 411 (SHORT2FROMMP(mp1) == LN_SELECT && 412 WinQueryButtonCheckstate(hwnd, GREP_APPEND))) 413 break; 414 { 415 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 416 GREP_LISTBOX, 417 LM_QUERYSELECTION, 418 MPFROMSHORT(LIT_FIRST), MPVOID); 419 if (sSelect >= 0) { 420 *s = 0; 421 if (WinQueryButtonCheckstate(hwnd, GREP_APPEND)) { 422 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); 423 bstrip(s); 424 if (*s && strlen(s) < 8190 && s[strlen(s) - 1] != ';') 425 strcat(s, ";"); 426 } 427 WinSendDlgItemMsg(hwnd, 428 GREP_LISTBOX, 429 LM_QUERYITEMTEXT, 430 MPFROM2SHORT(sSelect, 8192 - strlen(s)), 431 MPFROMP(s + strlen(s))); 432 bstrip(s); 433 if (*s) 434 WinSetDlgItemText(hwnd, GREP_MASK, s); 435 } 436 } 437 break; 436 438 } 437 439 break; … … 439 441 case GREP_MASK: 440 442 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 441 442 443 WinSetDlgItemText(hwnd, 444 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 443 445 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 444 446 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MASKSFINDTEXT)); 445 447 break; 446 448 case GREP_SEARCH: 447 449 if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS) 448 449 450 WinSetDlgItemText(hwnd, 451 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 450 452 if (SHORT2FROMMP(mp1) == MLN_SETFOCUS) 451 453 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_TEXTFINDTEXT)); 452 454 break; 453 455 case GREP_GREATER: 454 456 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 455 456 457 WinSetDlgItemText(hwnd, 458 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 457 459 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 458 460 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINSIZEFINDTEXT)); 459 461 break; 460 462 case GREP_LESSER: 461 463 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 462 463 464 WinSetDlgItemText(hwnd, 465 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 464 466 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 465 467 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXSIZEFINDTEXT)); 466 468 break; 467 469 case GREP_NEWER: 468 470 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 469 470 471 WinSetDlgItemText(hwnd, 472 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 471 473 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 472 474 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MAXAGEFINDTEXT)); 473 475 break; 474 476 case GREP_OLDER: 475 477 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS) 476 477 478 WinSetDlgItemText(hwnd, 479 GREP_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT)); 478 480 if (SHORT2FROMMP(mp1) == EN_SETFOCUS) 479 481 WinSetDlgItemText(hwnd, GREP_HELP, GetPString(IDS_MINAGEFINDTEXT)); 480 482 break; 481 483 case GREP_FINDDUPES: 482 484 { 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 485 BOOL finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES); 486 487 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCH), !finddupes); 488 WinEnableWindow(WinWindowFromID(hwnd, GREP_ABSOLUTE), !finddupes); 489 WinEnableWindow(WinWindowFromID(hwnd, GREP_CASE), !finddupes); 490 WinEnableWindow(WinWindowFromID(hwnd, GREP_CRCDUPES), finddupes); 491 WinEnableWindow(WinWindowFromID(hwnd, GREP_NOSIZEDUPES), finddupes); 492 WinEnableWindow(WinWindowFromID(hwnd, GREP_IGNOREEXTDUPES), 493 finddupes); 494 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHFILES), !finddupes); 495 WinEnableWindow(WinWindowFromID(hwnd, GREP_SEARCHEAS), !finddupes); 496 WinEnableWindow(WinWindowFromID(hwnd, GREP_GREATER), !finddupes); 497 WinEnableWindow(WinWindowFromID(hwnd, GREP_LESSER), !finddupes); 498 WinEnableWindow(WinWindowFromID(hwnd, GREP_NEWER), !finddupes); 499 WinEnableWindow(WinWindowFromID(hwnd, GREP_OLDER), !finddupes); 500 WinEnableWindow(WinWindowFromID(hwnd, GREP_FINDIFANY), !finddupes); 501 WinEnableWindow(WinWindowFromID(hwnd, GREP_GK), !finddupes); 502 WinEnableWindow(WinWindowFromID(hwnd, GREP_LK), !finddupes); 503 WinEnableWindow(WinWindowFromID(hwnd, GREP_NM), !finddupes); 504 WinEnableWindow(WinWindowFromID(hwnd, GREP_OM), !finddupes); 505 if (finddupes) 506 WinCheckButton(hwnd, GREP_RECURSE, TRUE); 505 507 } 506 508 } … … 511 513 case GREP_ENV: 512 514 { 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 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 515 CHAR *t; 516 CHAR env[8192]; 517 518 *path = 0; 519 if (!WinDlgBox(HWND_DESKTOP, 520 hwnd, EnvDlgProc, FM3ModHandle, ENV_FRAME, path)) { 521 break; 522 } 523 bstrip(path); 524 if (!*path) 525 break; 526 if (!stricmp(path, "LIBPATH")) 527 LoadLibPath(env, 8192); 528 else { 529 p = getenv(path); 530 if (!p) 531 break; 532 strcpy(env, p); 533 } 534 bstrip(env); 535 if (!*env) 536 break; 537 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); 538 bstrip(s); 539 if (strlen(s) > 8192 - 5) { 540 Runtime_Error(pszSrcFile, __LINE__, "too big"); 541 break; 542 } 543 p = strrchr(s, '\\'); 544 if (p) 545 strcpy(simple, p + 1); 546 else if (*s) 547 strcpy(simple, s); 548 else 549 strcpy(simple, "*"); 550 if (!p) 551 *s = 0; 552 if (simple[strlen(simple) - 1] == ';') 553 simple[strlen(simple) - 1] = 0; 554 lLen = strlen(simple) + 1; 555 p = env; 556 while (p && *p) { 557 strncpy(path, p, CCHMAXPATH - 1); 558 path[CCHMAXPATH - 1] = 0; 559 t = strchr(path, ';'); 560 if (t) 561 *t = 0; 562 bstrip(path); 563 if (isalpha(*path) && path[1] == ':' && path[2] == '\\') { 564 if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) { 565 WinSetDlgItemText(hwnd, GREP_MASK, s); 566 break; 567 } 568 if (!*s || (*s && s[strlen(s) - 1] != ';')) { 569 if (*s) 570 strcat(s, ";"); 571 strcat(s, path); 572 lLen += strlen(path); 573 if (s[strlen(s) - 1] != '\\') { 574 lLen++; 575 strcat(s, "\\"); 576 } 577 rstrip(s); 578 if (*s) { 579 strcat(s, simple); 580 WinSetDlgItemText(hwnd, GREP_MASK, s); 581 WinSendDlgItemMsg(hwnd, 582 GREP_MASK, 583 EM_SETSEL, 584 MPFROM2SHORT(strlen(s) - (lLen - 1), 585 strlen(s)), MPVOID); 586 } 587 } 588 } 589 p = strchr(p, ';'); 590 if (p) 591 p++; 592 } 591 593 } 592 594 break; … … 596 598 bstrip(s); 597 599 if (strlen(s) > 8192 - 5) { 598 599 600 Runtime_Error(pszSrcFile, __LINE__, "too big"); 601 break; 600 602 } 601 603 *path = 0; 602 604 if (WinDlgBox(HWND_DESKTOP, 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 605 hwnd, 606 WalkAllDlgProc, 607 FM3ModHandle, WALK_FRAME, MPFROMP(path)) && *path) { 608 p = strrchr(s, '\\'); 609 if (p) 610 strcpy(simple, p + 1); 611 else if (*s) 612 strcpy(simple, s); 613 else 614 strcpy(simple, "*"); 615 if (!p) 616 *s = 0; 617 if (simple[strlen(simple) - 1] == ';') 618 simple[strlen(simple) - 1] = 0; 619 lLen = strlen(simple) + 1; 620 if (strlen(s) > (8192 - lLen) - (strlen(path) + 1)) { 621 Runtime_Error(pszSrcFile, __LINE__, "too big"); 622 WinSetDlgItemText(hwnd, GREP_MASK, s); 623 break; 624 } 625 if (!*s || (*s && s[strlen(s) - 1] != ';')) { 626 if (*s) 627 strcat(s, ";"); 628 strcat(s, path); 629 lLen += strlen(path); 630 if (s[strlen(s) - 1] != '\\') { 631 lLen++; 632 strcat(s, "\\"); 633 } 634 rstrip(s); 635 if (*s) { 636 strcat(s, simple); 637 WinSetDlgItemText(hwnd, GREP_MASK, s); 638 WinSendDlgItemMsg(hwnd, 639 GREP_MASK, 640 EM_SETSEL, 641 MPFROM2SHORT(strlen(s) - (lLen - 1), 642 strlen(s)), MPVOID); 643 } 644 } 643 645 } 644 646 break; … … 649 651 bstrip(s); 650 652 if (*s) { 651 652 653 654 655 656 657 658 659 660 661 662 653 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 654 GREP_LISTBOX, 655 LM_SEARCHSTRING, 656 MPFROM2SHORT(0, LIT_FIRST), 657 MPFROMP(s)); 658 if (sSelect < 0) { 659 WinSendDlgItemMsg(hwnd, 660 GREP_LISTBOX, 661 LM_INSERTITEM, 662 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s)); 663 changed = TRUE; 664 } 663 665 } 664 666 break; … … 666 668 case GREP_DELETE: 667 669 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 668 669 670 670 GREP_LISTBOX, 671 LM_QUERYSELECTION, 672 MPFROMSHORT(LIT_FIRST), MPVOID); 671 673 if (sSelect >= 0) { 672 673 674 675 674 WinSendDlgItemMsg(hwnd, 675 GREP_LISTBOX, 676 LM_DELETEITEM, MPFROM2SHORT(sSelect, 0), MPVOID); 677 changed = TRUE; 676 678 } 677 679 break; … … 715 717 case IDM_HELP: 716 718 if (hwndHelp) 717 718 719 719 WinSendMsg(hwndHelp, 720 HM_DISPLAY_HELP, 721 MPFROM2SHORT(HELP_GREP, 0), MPFROMSHORT(HM_RESOURCEID)); 720 722 break; 721 723 … … 724 726 case GREP_ALLHDS: 725 727 { 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 728 CHAR szDrive[] = " :\\"; 729 ULONG ulDriveNum; 730 ULONG ulDriveMap; 731 INT x; 732 BOOL incl; 733 734 CHAR new[8192]; 735 736 *s = 0; 737 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, s); 738 s[8192 - 1] = 0; 739 p = strchr(s, ';'); 740 if (p) 741 *p = 0; 742 p = strrchr(s, '\\'); 743 if (!p) 744 p = strrchr(s, '/'); 745 if (!p) 746 p = strrchr(s, ':'); 747 if (p) 748 strcpy(s, p + 1); 749 if (!*s) 750 strcpy(s, "*"); 751 DosError(FERR_DISABLEHARDERR); 752 DosQCurDisk(&ulDriveNum, &ulDriveMap); 753 *new = 0; 754 for (x = 2; x < 26; x++) { 755 incl = FALSE; 756 if (ulDriveMap & (1L << x)) { 757 switch (SHORT1FROMMP(mp1)) { 758 case GREP_ALLHDS: 759 if (!(driveflags[x] & (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_RAMDISK))) 760 incl = TRUE; 761 break; 762 case GREP_LOCALHDS: 763 if (!(driveflags[x] & 764 (DRIVE_REMOVABLE | DRIVE_IGNORE | DRIVE_REMOTE | 765 DRIVE_VIRTUAL | DRIVE_RAMDISK))) 766 incl = TRUE; 767 break; 768 case GREP_REMOTEHDS: 769 if (!(driveflags[x] & 770 (DRIVE_REMOVABLE | DRIVE_IGNORE)) && 771 (driveflags[x] & DRIVE_REMOTE)) 772 incl = TRUE; 773 break; 774 } 775 } 776 if (incl) { 777 if (strlen(new) + strlen(s) + 5 < 8192 - 1) { 778 if (*new) 779 strcat(new, ";"); 780 *szDrive = x + 'A'; 781 strcat(new, szDrive); 782 strcat(new, s); 783 } 784 } 785 } 786 if (*new) 787 WinSetDlgItemText(hwnd, GREP_MASK, new); 786 788 } 787 789 break; … … 790 792 hwndCollect = WinQueryWindowULong(hwnd, QWL_USER); 791 793 if (!hwndCollect) 792 794 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT); 793 795 else { 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 796 // 07 Feb 08 SHL - fixme to malloc and free in thread 797 static GREP g; // Passed to thread 798 799 p = xmalloc(8192 + 512, pszSrcFile, __LINE__); 800 if (!p) 801 break; 802 memset(&g, 0, sizeof(GREP)); 803 g.size = sizeof(GREP); 804 recurse = WinQueryButtonCheckstate(hwnd, GREP_RECURSE) != 0; 805 absolute = WinQueryButtonCheckstate(hwnd, GREP_ABSOLUTE) != 0; 806 sensitive = WinQueryButtonCheckstate(hwnd, GREP_CASE) != 0; 807 sayfiles = WinQueryButtonCheckstate(hwnd, GREP_SAYFILES) != 0; 808 searchEAs = WinQueryButtonCheckstate(hwnd, GREP_SEARCHEAS) != 0; 809 searchFiles = WinQueryButtonCheckstate(hwnd, GREP_SEARCHFILES) != 0; 810 findifany = WinQueryButtonCheckstate(hwnd, GREP_FINDIFANY) != 0; 811 gRemember = WinQueryButtonCheckstate(hwnd, GREP_REMEMBERFLAGS); 812 if (gRemember) { 813 PrfWriteProfileData(fmprof, FM3Str, "Grep_Recurse", 814 (PVOID) & recurse, sizeof(BOOL)); 815 PrfWriteProfileData(fmprof, FM3Str, "Grep_Absolute", 816 (PVOID) & absolute, sizeof(BOOL)); 817 PrfWriteProfileData(fmprof, FM3Str, "Grep_Case", 818 (PVOID) & sensitive, sizeof(BOOL)); 819 PrfWriteProfileData(fmprof, FM3Str, "Grep_Sayfiles", 820 (PVOID) & sayfiles, sizeof(BOOL)); 821 PrfWriteProfileData(fmprof, FM3Str, "Grep_Searchfiles", 822 (PVOID) & searchFiles, sizeof(BOOL)); 823 PrfWriteProfileData(fmprof, FM3Str, "Grep_SearchfEAs", 824 (PVOID) & searchEAs, sizeof(BOOL)); 825 } 826 g.finddupes = WinQueryButtonCheckstate(hwnd, GREP_FINDDUPES) != 0; 827 if (g.finddupes) { 828 g.CRCdupes = WinQueryButtonCheckstate(hwnd, GREP_CRCDUPES) != 0; 829 g.nosizedupes = 830 WinQueryButtonCheckstate(hwnd, GREP_NOSIZEDUPES) != 0; 831 g.ignoreextdupes = 832 WinQueryButtonCheckstate(hwnd, GREP_IGNOREEXTDUPES) != 0; 833 } 834 // Parse file masks 835 *p = 0; 836 WinQueryDlgItemText(hwnd, GREP_MASK, 8192, p); 837 bstrip(p); 838 if (!*p) { 839 DosBeep(50, 100); 840 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, GREP_MASK)); 841 free(p); 840 842 # ifdef FORTIFY 841 843 Fortify_LeaveScope(); 842 844 # endif 843 break; 844 } 845 strcpy(g.tosearch, p); 846 strcpy(lastmask, p); 847 // Parse search strings 848 *p = 0; 849 WinQueryWindowText(hwndMLE, 4096, p); 850 strcpy(lasttext, p); 851 { 852 CHAR *pszFrom; 853 CHAR *pszTo; 854 ULONG matched = 0; 855 856 pszTo = g.searchPattern; 857 pszFrom = p; 858 while (*pszFrom) { 859 if (*pszFrom == '\r') { 860 pszFrom++; 861 continue; 862 } 863 if (*pszFrom == '\n') { 864 if (*(pszFrom + 1)) 865 matched++; 866 *pszTo = 0; 867 } 868 else 869 *pszTo = *pszFrom; 870 pszTo++; 871 pszFrom++; 872 } 873 if (*g.searchPattern) 874 matched++; 875 *pszTo++ = 0; 876 *pszTo = 0; 877 g.numlines = matched; 878 if (matched) { 879 g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__); 880 if (!g.matched) 881 g.numlines = 0; 882 } 883 } 884 *p = 0; 885 WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p); 886 greater = atol(p); 887 *p = 0; 888 WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p); 889 lesser = atol(p); 890 *p = 0; 891 WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p); 892 newer = atoi(p); 893 *p = 0; 894 WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p); 895 older = atoi(p); 896 if (older || newer) { 897 FDATE fdate; 898 FTIME ftime; 899 struct tm tm; 900 time_t t; 901 902 t = time(NULL); 903 tm = *localtime(&t); 904 fdate.day = tm.tm_mday; 905 fdate.month = tm.tm_mon + 1; 906 fdate.year = tm.tm_year - 80; 907 ftime.hours = tm.tm_hour; 908 ftime.minutes = tm.tm_min; 909 ftime.twosecs = tm.tm_sec / 2; 910 if (older) { 911 g.olderthan = SecsSince1980(&fdate, &ftime); 912 g.olderthan -= (older * (24L * 60L * 60L)); 913 } 914 if (newer) { 915 g.newerthan = SecsSince1980(&fdate, &ftime); 916 g.newerthan -= (newer * (24L * 60L * 60L)); 917 } 918 } 919 if (!newer) 920 g.newerthan = 0; 921 if (!older) 922 g.olderthan = 0; 923 g.greaterthan = greater; 924 g.lessthan = lesser; 925 g.absFlag = absolute; 926 g.caseFlag = sensitive; 927 g.dirFlag = recurse; 928 g.sayfiles = sayfiles; 929 g.searchEAs = searchEAs; 930 g.searchFiles = searchFiles; 931 g.findifany = findifany; 932 g.hwndFiles = hwndCollect; 933 g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT); 934 g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED); 935 g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile; 936 g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr; 937 g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag; 938 if (_beginthread(GrepThread, NULL, 524280, (PVOID) & g) == -1) { 939 Runtime_Error(pszSrcFile, __LINE__, 940 GetPString(IDS_COULDNTSTARTTHREADTEXT)); 941 free(p); 845 break; 846 } 847 strcpy(g.tosearch, p); 848 strcpy(lastmask, p); 849 // Parse search strings 850 *p = 0; 851 WinQueryWindowText(hwndMLE, 4096, p); 852 strcpy(lasttext, p); 853 { 854 CHAR *pszFrom; 855 CHAR *pszTo; 856 ULONG matched = 0; 857 858 pszTo = g.searchPattern; 859 pszFrom = p; 860 while (*pszFrom) { 861 if (*pszFrom == '\r') { 862 pszFrom++; 863 continue; 864 } 865 if (*pszFrom == '\n') { 866 if (*(pszFrom + 1)) 867 matched++; 868 *pszTo = 0; 869 } 870 else 871 *pszTo = *pszFrom; 872 pszTo++; 873 pszFrom++; 874 } 875 if (*g.searchPattern) 876 matched++; 877 *pszTo++ = 0; 878 *pszTo = 0; 879 g.numlines = matched; 880 if (matched) { 881 g.matched = xmalloc(g.numlines, pszSrcFile, __LINE__); 882 if (!g.matched) 883 g.numlines = 0; 884 } 885 } 886 *p = 0; 887 WinQueryDlgItemText(hwnd, GREP_GREATER, 34, p); 888 greater = atol(p); 889 *p = 0; 890 WinQueryDlgItemText(hwnd, GREP_LESSER, 34, p); 891 lesser = atol(p); 892 *p = 0; 893 WinQueryDlgItemText(hwnd, GREP_NEWER, 34, p); 894 newer = atoi(p); 895 *p = 0; 896 WinQueryDlgItemText(hwnd, GREP_OLDER, 34, p); 897 older = atoi(p); 898 if (older || newer) { 899 FDATE fdate; 900 FTIME ftime; 901 struct tm tm; 902 time_t t; 903 904 t = time(NULL); 905 tm = *localtime(&t); 906 fdate.day = tm.tm_mday; 907 fdate.month = tm.tm_mon + 1; 908 fdate.year = tm.tm_year - 80; 909 ftime.hours = tm.tm_hour; 910 ftime.minutes = tm.tm_min; 911 ftime.twosecs = tm.tm_sec / 2; 912 if (older) { 913 g.olderthan = SecsSince1980(&fdate, &ftime); 914 g.olderthan -= (older * (24L * 60L * 60L)); 915 } 916 if (newer) { 917 g.newerthan = SecsSince1980(&fdate, &ftime); 918 g.newerthan -= (newer * (24L * 60L * 60L)); 919 } 920 } 921 if (!newer) 922 g.newerthan = 0; 923 if (!older) 924 g.olderthan = 0; 925 g.greaterthan = greater; 926 g.lessthan = lesser; 927 g.absFlag = absolute; 928 g.caseFlag = sensitive; 929 g.dirFlag = recurse; 930 g.sayfiles = sayfiles; 931 g.searchEAs = searchEAs; 932 g.searchFiles = searchFiles; 933 g.findifany = findifany; 934 g.hwndFiles = hwndCollect; 935 g.hwnd = WinQueryWindow(hwndCollect, QW_PARENT); 936 g.hwndCurFile = WinWindowFromID(g.hwnd, DIR_SELECTED); 937 g.attrFile = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.attrFile; 938 g.antiattr = ((DIRCNRDATA *)INSTDATA(hwndCollect))->mask.antiattr; 939 g.stopflag = &((DIRCNRDATA *)INSTDATA(hwndCollect))->stopflag; 940 if (xbeginthread(GrepThread, 941 524280, 942 &g, 943 pszSrcFile, 944 __LINE__) == -1) 945 { 946 free(p); 942 947 # ifdef FORTIFY 943 948 Fortify_LeaveScope(); 944 949 # endif 945 946 947 948 949 950 WinDismissDlg(hwnd, 0); 951 break; 952 } 953 DosSleep(100); //05 Aug 07 GKY 128 954 free(p); 950 955 # ifdef FORTIFY 951 956 Fortify_LeaveScope(); 952 957 # endif 953 958 } 954 959 if (changed) { 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 960 // Grep mask list changed 961 SHORT x; 962 963 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, 964 GREP_LISTBOX, 965 LM_QUERYITEMCOUNT, 966 MPVOID, MPVOID); 967 if (sSelect > 0) { 968 BldFullPathName(s, pFM2SaveDirectory, "GREPMASK.DAT"); 969 if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2) 970 break; //already gave error msg 971 fp = xfopen(s, "w", pszSrcFile, __LINE__); 972 if (fp) { 973 fputs(GetPString(IDS_GREPFILETEXT), fp); 974 for (x = 0; x < sSelect; x++) { 975 *s = 0; 976 WinSendDlgItemMsg(hwnd, 977 GREP_LISTBOX, 978 LM_QUERYITEMTEXT, 979 MPFROM2SHORT(x, 8192), MPFROMP(s)); 980 bstrip(s); 981 if (*s) 982 fprintf(fp, "%s\n", s); 983 } 984 fclose(fp); 985 } 986 } 982 987 } 983 988 WinDismissDlg(hwnd, 1);
Note:
See TracChangeset
for help on using the changeset viewer.