Changeset 948 for trunk/dll/grep.c
- Timestamp:
- Feb 12, 2008, 6:20:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/grep.c
r907 r948 9 9 Copyright (c) 2001, 2008 Steven H. Levine 10 10 11 12 Feb 03 SHL insert_grepfile: standardize EA math11 12 Feb 03 SHL InsertGrepFile: standardize EA math 12 12 12 Feb 03 SHL doonefile: standardize EA math 13 13 25 May 05 SHL Rework for ULONGLONG … … 27 27 26 Aug 07 GKY DosSleep(1) in loops changed to (0) 28 28 21 Sep 07 GKY Fix trap on search that includes filenames that exceed maxpath 29 07 Feb 08 SHL Use ITIMER_DESC to control sleeps and reporting 29 30 30 31 ***********************************************************************/ … … 47 48 #include "errutil.h" // Dos_Error... 48 49 #include "strutil.h" // GetPString 50 #include "tmrsvcs.h" // ITIMER_DESC 49 51 #include "fm3dll.h" 50 52 … … 53 55 static PSZ pszSrcFile = __FILE__; 54 56 55 static VOID doallsubdirs(GREP *grep, CHAR *searchPath, BOOL recursing, 56 char **fle, int numfls); 57 static INT domatchingfiles(GREP *grep, CHAR *path, char **fle, int numfls); 58 static BOOL doonefile(GREP *grep, CHAR *fileName, FILEFINDBUF4L *pffb); 59 static BOOL doinsertion(GREP *grep); 57 static VOID DoAllSubdirs(GREP *grep, 58 CHAR *searchPath, 59 BOOL recursing, 60 char **fle, 61 UINT numfls, 62 ITIMER_DESC *pitdSleep, 63 ITIMER_DESC *pitdReport); 64 static INT DoMatchingFiles(GREP *grep, 65 CHAR *path, 66 CHAR **fle, 67 UINT numfls, 68 ITIMER_DESC *pitdSleep, 69 ITIMER_DESC *pitdReport); 70 static BOOL DoOneFile(GREP *grep, 71 CHAR *fileName, 72 FILEFINDBUF4L *pffb, 73 ITIMER_DESC *pitdSleep, 74 ITIMER_DESC *pitdReport); 75 static BOOL DoInsertion(GREP *grep, 76 ITIMER_DESC *pitdSleep, 77 ITIMER_DESC *pitdReport); 60 78 static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4L *pffb); 61 static VOID FillDupes(GREP *grep); 79 static VOID FillDupes(GREP *grep, 80 ITIMER_DESC *pitdSleep, 81 ITIMER_DESC *pitdReport); 82 62 83 static VOID FreeDupes(GREP *grep); 63 84 … … 69 90 static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 70 91 71 ULONG SecsSince1980(FDATE * date, FTIME *time)92 ULONG SecsSince1980(FDATE *date, FTIME *time) 72 93 { 73 94 ULONG total = 0; 74 register intx;95 UINT x; 75 96 76 97 for (x = 1980; x < date->year + 1980; x++) { … … 98 119 */ 99 120 100 static BOOL m_match(CHAR * string, CHAR *pattern, BOOL absolute, BOOL ignore,121 static BOOL m_match(CHAR *string, CHAR *pattern, BOOL absolute, BOOL ignore, 101 122 LONG len) 102 123 { … … 214 235 } 215 236 216 static BOOL match(CHAR * string, CHAR *patterns, BOOL absolute, BOOL ignore,217 LONG len, ULONG numlines, CHAR * 237 static BOOL match(CHAR *string, CHAR *patterns, BOOL absolute, BOOL ignore, 238 LONG len, ULONG numlines, CHAR *matched, BOOL matchall) 218 239 { 219 240 BOOL ret = FALSE; … … 235 256 } 236 257 237 VOID GrepThread(VOID * 258 VOID GrepThread(VOID *arg) 238 259 { 239 260 HAB ghab; 240 261 HMQ ghmq; 241 262 GREP grep; 242 register INT x, numfls; 243 static CHAR *fle[512]; 263 UINT x; 264 UINT numfls; 265 static CHAR *fle[512]; // 06 Feb 08 SHL fixme to not be static 244 266 CHAR *p, *pp, searchPath[CCHMAXPATH * 2]; 267 268 ITIMER_DESC itdSleep = { 0 }; // 06 Feb 08 SHL 269 ITIMER_DESC itdReport = { 0 }; 245 270 246 271 if (!arg) { … … 261 286 WinCancelShutdown(ghmq, TRUE); 262 287 IncrThreadUsage(); 263 DosSleep(100); //05 Aug 07 GKY 128 264 WinSetWindowText(grep.hwndCurFile, 265 GetPString((grep.finddupes) ? 266 IDS_GREPDUPETEXT : IDS_GREPSCANTEXT)); 288 // DosSleep(100); //05 Aug 07 GKY 128 // 07 Feb 08 SHL 289 // hwndStatus does not exist for applet 290 WinSetWindowText(hwndStatus ? hwndStatus : grep.hwndCurFile, 291 GetPString(grep.finddupes ? IDS_GREPDUPETEXT : 292 IDS_GREPSCANTEXT)); 267 293 268 294 pp = grep.searchPattern; … … 293 319 294 320 grep.anyexcludes = FALSE; 295 numfls = x =0;321 numfls = 0; 296 322 fle[numfls++] = strtok(grep.tosearch, ";"); 323 297 324 while ((fle[numfls] = strtok(NULL, ";")) != NULL && numfls < 511) { 298 325 if (*fle[numfls] == '/') … … 301 328 } 302 329 303 while (x < numfls) { // loop through search masks 330 InitITimer(&itdSleep, 500); // Sleep every 500 mSec 331 InitITimer(&itdReport, 2000); // Report every 2 sec 332 333 // loop through search masks 334 for (x = 0; x < numfls; x++) { 304 335 305 336 if (*fle[x] == '/') // is an exclude mask only … … 326 357 strcpy(grep.fileMask, p); 327 358 } 328 if (*p == '\\') { // got a 'full' path329 359 if (*p == '\\') { 360 // got a 'full' path 330 361 CHAR temp; 331 362 … … 344 375 break; 345 376 // do single directory 346 domatchingfiles(&grep, searchPath, fle, numfls);377 DoMatchingFiles(&grep, searchPath, fle, numfls, &itdSleep, &itdReport); 347 378 if (grep.dirFlag) // do subdirs 348 doallsubdirs(&grep, searchPath, FALSE, fle, numfls);379 DoAllSubdirs(&grep, searchPath, FALSE, fle, numfls, &itdSleep, &itdReport); 349 380 ExcludeSkip: 350 381 if (*grep.stopflag) 351 382 break; 352 x++;353 383 if (WinIsWindow(grep.ghab, grep.hwndFiles)) 354 doinsertion(&grep);// insert any remaining objects355 } // while384 DoInsertion(&grep, &itdSleep, &itdReport); // insert any remaining objects 385 } // for 356 386 357 387 if (WinIsWindow(grep.ghab, grep.hwndFiles)) 358 doinsertion(&grep); // insert any remaining objects 359 360 if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes && 388 DoInsertion(&grep, &itdSleep, &itdReport); // insert any remaining objects 389 390 if (WinIsWindow(grep.ghab, grep.hwndFiles) && 391 grep.finddupes && 361 392 !*grep.stopflag) 362 FillDupes(&grep); 393 { 394 FillDupes(&grep, &itdSleep, &itdReport); 395 } 363 396 364 397 if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID)) // tell window we're done … … 375 408 if (grep.numlines && grep.matched) 376 409 free(grep.matched); 410 // 07 Feb 08 SHL fixme to free grep here when not static 377 411 DosPostEventSem(CompactSem); 378 412 } 379 413 380 static BOOL IsExcluded( char *name, char **fle, intnumfls)381 { 382 intx;383 char*n;414 static BOOL IsExcluded(CHAR *name, CHAR **fle, UINT numfls) 415 { 416 UINT x; 417 CHAR *n; 384 418 385 419 n = strrchr(name, '\\'); … … 399 433 } 400 434 401 static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing, 402 char **fle, int numfls) 435 static VOID DoAllSubdirs(GREP *grep, 436 CHAR *searchPath, 437 BOOL recursing, 438 CHAR **fle, 439 UINT numfls, 440 ITIMER_DESC *pitdSleep, 441 ITIMER_DESC *pitdReport) 403 442 { 404 443 // process all subdirectories … … 437 476 strcpy(p, ffb.achName); 438 477 if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) { 439 domatchingfiles(grep, searchPath, fle, numfls); 440 doallsubdirs(grep, searchPath, TRUE, fle, numfls); 441 DosSleep(0); //26 Aug 07 GKY 1 478 // 07 Feb 08 SHL 479 if (IsITimerExpired(pitdReport)) { 480 if (!hwndStatus) 481 WinSetWindowText(grep->hwndCurFile, searchPath); 482 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) { 483 CHAR s[CCHMAXPATH + 64]; 484 sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), searchPath); 485 WinSetWindowText(hwndStatus, s); 486 } 487 } 488 DoMatchingFiles(grep, searchPath, fle, numfls, pitdSleep, pitdReport); 489 // 07 Feb 08 SHL 490 if (IsITimerExpired(pitdReport)) { 491 if (!hwndStatus) 492 WinSetWindowText(grep->hwndCurFile, searchPath); 493 else { 494 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) { 495 CHAR s[CCHMAXPATH + 64]; 496 sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), searchPath); 497 WinSetWindowText(hwndStatus, s); 498 } 499 } 500 } 501 DoAllSubdirs(grep, searchPath, TRUE, fle, numfls, pitdSleep, pitdReport); 502 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 442 503 } 443 504 } … … 453 514 } 454 515 455 static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls) 516 /** 517 * Scan for files matching filespecs in single directory 518 */ 519 520 static INT DoMatchingFiles(GREP *grep, 521 CHAR *path, 522 CHAR **fle, 523 UINT numfls, 524 ITIMER_DESC *pitdSleep, 525 ITIMER_DESC *pitdReport) 456 526 { 457 527 // process all matching files in a directory … … 473 543 return 0; 474 544 475 // build filemask476 545 BldFullPathName(szFindPath, path, grep->fileMask); 477 // sprintf(szFindPath,478 // "%s%s%s",479 // path,480 // (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask);481 546 482 547 MakeFullName(szFindPath); … … 508 573 break; 509 574 if (*pffbFile->achName != '.' || 510 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) { 511 strcpy(p, pffbFile->achName); // build filename 512 if (strlen(szFindPath) > CCHMAXPATH){ //21 Sep GKY check for pathnames that exceed maxpath 513 DosFindClose(findHandle); 514 free(pffbArray); 515 if (!fDone) { 516 fDone = TRUE; 517 saymsg(MB_OK | MB_ICONASTERISK, 518 HWND_DESKTOP, 575 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) { 576 strcpy(p, pffbFile->achName); // build filename 577 if (strlen(szFindPath) > CCHMAXPATH){ 578 // Complain if pathnames exceeds max 579 DosFindClose(findHandle); 580 free(pffbArray); 581 if (!fDone) { 582 fDone = TRUE; 583 saymsg(MB_OK | MB_ICONASTERISK, 584 HWND_DESKTOP, 519 585 GetPString(IDS_WARNINGTEXT), 520 521 586 "One or more of your files has a full path name that exceeds the OS/2 maximum"); 587 } 522 588 return 1; 523 } 589 } 590 591 // 07 Feb 08 SHL 592 if (IsITimerExpired(pitdReport)) { 593 if (!hwndStatus) 594 WinSetWindowText(grep->hwndCurFile, szFindPath); 595 else { 596 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) { 597 CHAR s[CCHMAXPATH + 64]; 598 sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), szFindPath); 599 WinSetWindowText(hwndStatus, s); 600 } 601 } 602 } 603 524 604 if (!grep->anyexcludes || !IsExcluded(szFindPath, fle, numfls)) { 525 605 if (!grep->finddupes) 526 doonefile(grep, szFindPath, pffbFile);606 DoOneFile(grep, szFindPath, pffbFile, pitdSleep, pitdReport); 527 607 else if (!InsertDupe(grep, szFindPath, pffbFile)) { 528 608 DosFindClose(findHandle); … … 538 618 if (*grep->stopflag) 539 619 break; 540 DosSleep(0); //26 Aug 07 GKY 1 620 SleepIfNeeded(pitdSleep, 1); 621 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 541 622 ulFindCnt = FilesToGet; 542 623 rc = xDosFindNext(findHandle, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL); … … 556 637 } 557 638 558 static VOID freegreplist(GREP * 559 { 560 INT x;639 static VOID freegreplist(GREP *grep) 640 { 641 UINT x; 561 642 562 643 if (grep) { … … 578 659 } 579 660 580 static BOOL doinsertion(GREP * grep) 661 /** 662 * Insert record into container 663 */ 664 665 static BOOL DoInsertion(GREP *grep, 666 ITIMER_DESC *pitdSleep, 667 ITIMER_DESC *pitdReport) 581 668 { 582 669 RECORDINSERT ri; 583 670 DIRCNRDATA *dcd; 584 671 PCNRITEM pci, pciFirst; 585 INT x;672 UINT x; 586 673 587 674 if (!grep || !grep->toinsert || !grep->insertffb || !grep->dir) 588 675 return FALSE; 676 589 677 pci = WinSendMsg(grep->hwndFiles, 590 678 CM_ALLOCRECORD, 591 679 MPFROMLONG(EXTRA_RECORD_BYTES), 592 680 MPFROMLONG(grep->toinsert)); 593 // 04 Jan 08 SHL fixme to complain if CM_ALLOCRECORD fails 594 if (pci) { 595 // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records 596 if (grep->sayfiles) 597 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT)); 681 if (!pci) { 682 Win_Error(grep->hwndFiles, grep->hwndFiles, pszSrcFile, __LINE__, 683 "CM_ALLOCRECORD %u failed", grep->toinsert); 684 } 685 else { 686 if (grep->sayfiles) { 687 if (!hwndStatus) 688 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT)); 689 else { 690 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 691 WinSetWindowText(hwndStatus, GetPString(IDS_GREPINSERTINGTEXT)); 692 } 693 } 598 694 pciFirst = pci; 599 695 dcd = INSTDATA(grep->hwndFiles); … … 602 698 pci, grep->dir[x], grep->insertffb[x], FALSE, dcd); 603 699 pci = (PCNRITEM) pci->rc.preccNextRecord; 604 } 700 SleepIfNeeded(pitdSleep, 1); 701 } // for 605 702 memset(&ri, 0, sizeof(RECORDINSERT)); 606 703 ri.cb = sizeof(RECORDINSERT); … … 617 714 DosExitCritSec(); 618 715 } 619 if (grep->toinsert == FilesToGet) 620 DosSleep(0); //26 Aug 07 GKY 1 716 SleepIfNeeded(pitdSleep, 1); 717 // if (grep->toinsert == FilesToGet) // 07 Feb 08 SHL 718 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 621 719 freegreplist(grep); 622 720 PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID); … … 627 725 } 628 726 629 static BOOL insert_grepfile(GREP *grep, CHAR *filename, PFILEFINDBUF4L pffb) 727 /** 728 * Insert file ffb and directory name into lists 729 */ 730 731 static BOOL InsertGrepFile(GREP *grep, 732 CHAR *pszFileName, 733 PFILEFINDBUF4L pffb, 734 ITIMER_DESC *pitdSleep, 735 ITIMER_DESC *pitdReport) 630 736 { 631 737 PSZ p; 632 738 CHAR szDirectory[CCHMAXPATH]; 633 739 634 if (WinIsWindow(grep->ghab, grep->hwndFiles)) { 740 if (!WinIsWindow(grep->ghab, grep->hwndFiles)) { 741 // Window closed - clean up and go away 742 freegreplist(grep); 743 } 744 else { 635 745 grep->numfiles++; 636 strcpy(szDirectory, filename);746 strcpy(szDirectory, pszFileName); 637 747 p = strrchr(szDirectory, '\\'); 748 638 749 if (p) { 750 // Got directory 639 751 if (p < szDirectory + 4) 640 p++; 752 p++; // Include root backslash 641 753 *p = 0; 754 642 755 if (!grep->insertffb) { 643 756 // Allocate 1 extra for end marker? … … 653 766 } 654 767 } 768 655 769 grep->insertffb[grep->toinsert] = 656 770 xmalloc(sizeof(FILEFINDBUF4L), pszSrcFile, __LINE__); … … 658 772 return FALSE; 659 773 memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4L)); 774 660 775 grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__); 661 776 if (!grep->dir) { … … 663 778 return FALSE; 664 779 } 780 665 781 grep->insertedbytes += pffb->cbFile + CBLIST_TO_EASIZE(pffb->cbList); 666 782 grep->toinsert++; 667 783 if (grep->toinsert == FilesToGet) 668 return doinsertion(grep);784 return DoInsertion(grep, pitdSleep, pitdReport); 669 785 return TRUE; 670 786 } 671 787 } 672 else673 freegreplist(grep);674 788 return FALSE; 675 789 } 676 790 677 static BOOL doonefile(GREP *grep, CHAR *filename, FILEFINDBUF4L * pffb) 791 /** 792 * Check file matches search criteria 793 */ 794 795 static BOOL DoOneFile(GREP *grep, 796 CHAR *pszFileName, 797 FILEFINDBUF4L *pffb, 798 ITIMER_DESC *pitdSleep, 799 ITIMER_DESC *pitdReport) 678 800 { 679 801 // process a single file … … 684 806 685 807 grep->fileCount++; 686 if (grep->sayfiles) 687 WinSetWindowText(grep->hwndCurFile, filename); 808 if (grep->sayfiles) { 809 if (!hwndStatus) 810 WinSetWindowText(grep->hwndCurFile, pszFileName); 811 else { 812 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 813 WinSetWindowText(hwndStatus, pszFileName); 814 } 815 } 688 816 689 817 if (grep->greaterthan || grep->lessthan) { … … 724 852 725 853 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) // just a find 726 return insert_grepfile(grep, filename, pffb);854 return InsertGrepFile(grep, pszFileName, pffb, pitdSleep, pitdReport); 727 855 728 856 if (grep->searchEAs) { … … 733 861 CHAR *data, temp; 734 862 735 head = GetFileEAs( filename, FALSE, TRUE);863 head = GetFileEAs(pszFileName, FALSE, TRUE); 736 864 if (head) { 737 865 info = head; 738 866 while (info && !strmatch) { 739 867 alltext = TRUE; 740 switch (*(USHORT *) 868 switch (*(USHORT *)info->value) { 741 869 case EAT_ASCII: 742 870 if (match(info->value + (sizeof(USHORT) * 2), 743 871 grep->searchPattern, grep->absFlag, 744 (grep->caseFlag == FALSE),872 grep->caseFlag == FALSE, 745 873 info->cbValue - (sizeof(USHORT) * 2), 746 grep->numlines, grep->matched, !grep->findifany)) { 874 grep->numlines, 875 grep->matched, 876 !grep->findifany)) { 747 877 strmatch = TRUE; 748 878 } 749 879 break; 750 880 case EAT_MVST: 751 type = *(USHORT *) 881 type = *(USHORT *)(info->value + (sizeof(USHORT) * 3)); 752 882 if (type == EAT_ASCII) { 753 883 data = info->value + (sizeof(USHORT) * 4); … … 829 959 } // while 830 960 Free_FEAList(head); 831 DosSleep(1);961 // DosSleep(1); // 07 Feb 08 SHL 832 962 } 833 963 } … … 838 968 LONG len; 839 969 840 inputFile = _fsopen( filename, "rb", SH_DENYNO);970 inputFile = _fsopen(pszFileName, "rb", SH_DENYNO); 841 971 if (inputFile) { 842 972 pos = ftell(inputFile); … … 863 993 } 864 994 free(input); 865 DosSleep(1);995 // DosSleep(1); // 07 Feb 08 SHL 866 996 } 867 997 } // if 868 998 869 999 if (strmatch) 870 ret = insert_grepfile(grep, filename, pffb);1000 ret = InsertGrepFile(grep, pszFileName, pffb, pitdSleep, pitdReport); 871 1001 return ret; 872 1002 } 873 1003 874 static LONG cr3tab[] = { // CRC polynomial 0xEDB883201004 static LONG cr3tab[] = { // CRC polynomial 0xEDB88320 875 1005 876 1006 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, … … 940 1070 }; 941 1071 942 LONG CRCBlock(register CHAR * 1072 LONG CRCBlock(register CHAR *str, register INT blklen, register LONG crc) 943 1073 { 944 1074 while (blklen--) { … … 950 1080 } 951 1081 952 LONG CRCFile(CHAR * filename, INT *error)1082 LONG CRCFile(CHAR *pszFileName, INT *error) 953 1083 { 954 1084 LONG CRC = -1L, len; … … 961 1091 *error = -1; 962 1092 else { 963 fp = _fsopen( filename, "rb", SH_DENYNO);1093 fp = _fsopen(pszFileName, "rb", SH_DENYNO); 964 1094 if (!fp) 965 1095 *error = -2; … … 971 1101 else 972 1102 break; 973 DosSleep(0); //26 Aug 07 GKY 11103 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 974 1104 } 975 1105 fclose(fp); 976 DosSleep(1);1106 // DosSleep(1); // 07 Feb 08 SHL 977 1107 } 978 1108 free(buffer); … … 1001 1131 } 1002 1132 1003 int comparenamesq(const void *v1, const void*v2)1133 INT comparenamesq(const VOID *v1, const VOID *v2) 1004 1134 { 1005 1135 DUPES *d1 = *(DUPES **) v1; … … 1020 1150 } 1021 1151 1022 int comparenamesqe(const void *v1, const void*v2)1152 INT comparenamesqe(const VOID *v1, const VOID *v2) 1023 1153 { 1024 1154 DUPES *d1 = *(DUPES **) v1; 1025 1155 DUPES *d2 = *(DUPES **) v2; 1026 1156 CHAR *p1, *p2, *p1e, *p2e, e1, e2; 1027 intret;1157 INT ret; 1028 1158 1029 1159 p1 = strrchr(d1->name, '\\'); … … 1055 1185 } 1056 1186 1057 intcomparesizesq(const void *v1, const void *v2)1187 INT comparesizesq(const void *v1, const void *v2) 1058 1188 { 1059 1189 DUPES *d1 = *(DUPES **) v1; … … 1063 1193 } 1064 1194 1065 intcomparenamesb(const void *v1, const void *v2)1195 INT comparenamesb(const void *v1, const void *v2) 1066 1196 { 1067 1197 DUPES *d1 = (DUPES *) v1; … … 1082 1212 } 1083 1213 1084 int comparenamesbe(const void *v1, const void*v2)1214 INT comparenamesbe(const VOID *v1, const VOID *v2) 1085 1215 { 1086 1216 DUPES *d1 = (DUPES *) v1; 1087 1217 DUPES *d2 = *(DUPES **) v2; 1088 1218 CHAR *p1, *p2, *p1e, *p2e, e1, e2; 1089 intret;1219 INT ret; 1090 1220 1091 1221 p1 = strrchr(d1->name, '\\'); … … 1117 1247 } 1118 1248 1119 int comparesizesb(const void *v1, const void*v2)1249 INT comparesizesb(const VOID *v1, const VOID *v2) 1120 1250 { 1121 1251 DUPES *d1 = (DUPES *) v1; … … 1125 1255 } 1126 1256 1127 static VOID FillDupes(GREP * grep) 1257 static VOID FillDupes(GREP *grep, 1258 ITIMER_DESC *pitdSleep, 1259 ITIMER_DESC *pitdReport) 1128 1260 { 1129 1261 DUPES *c, *i, **r; … … 1132 1264 UINT numfiles = 0, numalloced = 0; 1133 1265 INT error; 1134 register ULONG x = 0, y = 0;1135 ULONG cntr = 1000;1136 1137 if (grep->CRCdupes) 1138 cntr = 100;1139 i = grep->dupehead;1140 while (i) {1141 x++;1142 i = i->next;1143 } 1266 ULONG x; 1267 ULONG y; 1268 // ULONG cntr = 1000; // 09 Feb 08 SHL 1269 1270 // if (grep->CRCdupes) // 09 Feb 08 SHL 1271 // cntr = 100; // 09 Feb 08 SHL 1272 x = 0; 1273 for (i = grep->dupehead; i; i = i->next) 1274 x++; // Count 1275 1144 1276 if (x) { 1145 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT)); 1146 DosSleep(0); //26 Aug 07 GKY 1 1277 if (!hwndStatus) 1278 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT)); 1279 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1280 WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPESORTINGTEXT)); 1281 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1147 1282 grep->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__); 1148 1283 if (!grep->nosizedupes) 1149 1284 grep->dupesizes = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__); 1150 1285 if (grep->dupenames && (grep->nosizedupes || grep->dupesizes)) { 1151 i = grep->dupehead;1152 while (i) {1286 y = 0; 1287 for (i = grep->dupehead; i; i = i->next) { 1153 1288 grep->dupenames[y] = i; 1154 1289 if (!grep->nosizedupes) 1155 1290 grep->dupesizes[y] = i; 1156 i = i->next;1157 1291 y++; 1158 1292 } 1159 grep->dupenames[y] = NULL; 1293 grep->dupenames[y] = NULL; // Mark end 1160 1294 if (!grep->nosizedupes) 1161 1295 grep->dupesizes[y] = NULL; 1162 DosSleep(0); //26 Aug 07 GKY 1 1296 1297 InitITimer(pitdSleep, 0); // Reset rate estimator 1298 SleepIfNeeded(pitdSleep, 1); 1299 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1300 1163 1301 qsort(grep->dupenames, 1164 1302 x, 1165 1303 sizeof(DUPES *), 1166 ((grep->ignoreextdupes) ? comparenamesqe : comparenamesq)); 1167 DosSleep(0); //26 Aug 07 GKY 1 1304 grep->ignoreextdupes ? comparenamesqe : comparenamesq); 1305 SleepIfNeeded(pitdSleep, 1); 1306 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1168 1307 if (!grep->nosizedupes) { 1169 1308 qsort(grep->dupesizes, x, sizeof(DUPES *), comparesizesq); 1170 DosSleep(0); //26 Aug 07 GKY 1 1309 SleepIfNeeded(pitdSleep, 1); 1310 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1171 1311 } 1172 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1173 1312 1313 if (!hwndStatus) 1314 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1315 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1316 WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1317 1318 InitITimer(pitdSleep, 0); // Reset rate estimator 1174 1319 i = grep->dupehead; 1175 1320 y = 0; … … 1177 1322 if (*grep->stopflag) 1178 1323 break; 1324 SleepIfNeeded(pitdSleep, 1); // 07 Feb 08 SHL 1179 1325 if (!(i->flags & GF_SKIPME)) { 1180 1326 r = (DUPES **) bsearch(i, grep->dupenames, x, sizeof(DUPES *), … … 1216 1362 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) { 1217 1363 (*r)->flags |= GF_INSERTED; 1218 if (grep->sayfiles) 1219 WinSetWindowText(grep->hwndFiles, (*r)->name); 1364 if (grep->sayfiles) { 1365 if (!hwndStatus) 1366 WinSetWindowText(grep->hwndFiles, (*r)->name); 1367 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1368 WinSetWindowText(hwndStatus, (*r)->name); 1369 } 1220 1370 if ((*r)->size == i->size && 1221 1371 (i->date.year == (*r)->date.year && … … 1277 1427 } 1278 1428 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) { 1279 if (grep->sayfiles) 1280 WinSetWindowText(grep->hwndCurFile, (*r)->name); 1429 if (grep->sayfiles) { 1430 if (!hwndStatus) 1431 WinSetWindowText(grep->hwndCurFile, (*r)->name); 1432 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1433 WinSetWindowText(hwndStatus, (*r)->name); 1434 } 1281 1435 (*r)->flags |= GF_INSERTED; 1282 1436 if (((grep->ignoreextdupes) ? … … 1298 1452 i = i->next; 1299 1453 y++; 1300 if (!(y % cntr)) {1301 1454 // 08 Feb 08 SHL 1455 if (IsITimerExpired(pitdReport)) { 1302 1456 CHAR s[44]; 1303 1304 1457 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles); 1305 WinSetWindowText(grep->hwndCurFile, s); 1306 DosSleep(1); //05 Aug 07 GKY 128 1458 if (!hwndStatus) 1459 WinSetWindowText(grep->hwndCurFile, s); 1460 else { 1461 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1462 WinSetWindowText(hwndStatus, s); 1463 } 1307 1464 } 1308 DosSleep(0); //26 Aug 07 GKY 11309 } 1465 // DosSleep(0); //26 Aug 07 GKY 1 1466 } // while 1310 1467 } 1311 1468 else { 1312 // Insufficient memory - fall back 1469 // Insufficient memory - fall back to slow method - fixme to saymsg? 1313 1470 DosBeep(50, 100); 1314 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1471 if (!hwndStatus) 1472 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1473 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1474 WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1315 1475 x = y = 0; 1316 1476 if (grep->dupenames) { … … 1322 1482 grep->dupesizes = NULL; 1323 1483 } 1484 1485 InitITimer(pitdSleep, 0); // Reset rate estimator 1324 1486 i = grep->dupehead; 1325 1487 while (i) { 1326 1488 if (*grep->stopflag) 1327 1489 break; 1490 SleepIfNeeded(pitdSleep, 1); 1328 1491 if (!(i->flags & GF_SKIPME)) { 1329 if ( !(y % cntr)) {1330 1492 if (IsITimerExpired(pitdReport)) { 1493 // if (!(y % cntr)) { } 1331 1494 CHAR s[44]; 1332 1333 1495 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles); 1334 WinSetWindowText(grep->hwndCurFile, s); 1335 DosSleep(0); //26 Aug 07 GKY 1 1496 if (!hwndStatus) 1497 WinSetWindowText(grep->hwndCurFile, s); 1498 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1499 WinSetWindowText(hwndStatus, s); 1500 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1336 1501 } 1337 1502 y++; … … 1383 1548 goto BreakOut; // Failed 1384 1549 } 1385 if (grep->sayfiles) 1386 WinSetWindowText(grep->hwndCurFile, pc); 1550 if (grep->sayfiles) { 1551 if (!hwndStatus) 1552 WinSetWindowText(grep->hwndCurFile, pc); 1553 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1554 WinSetWindowText(hwndStatus, pc); 1555 } 1387 1556 c->flags |= GF_INSERTED; 1388 1557 i->flags |= GF_INSERTED; … … 1392 1561 } 1393 1562 } 1394 else if (!(x % 100))1395 DosSleep(0); //26 Aug 07 GKY 11563 // else if (!(x % 100)) // 07 Feb 08 SHL 1564 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1396 1565 } 1397 1566 c = c->next; … … 1399 1568 } 1400 1569 i = i->next; 1401 } 1570 } // while 1402 1571 } 1403 1572 } … … 1406 1575 if (numfiles && list) { 1407 1576 if (!PostMsg(grep->hwndFiles, 1408 WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list))) 1577 WM_COMMAND, 1578 MPFROM2SHORT(IDM_COLLECTOR, 0), 1579 MPFROMP(list))) 1409 1580 FreeList(list); 1410 1581 } … … 1443 1614 } 1444 1615 1445 #pragma alloc_text(GREP, insert_grepfile,doonefile,doinsertion,freegreplist)1616 #pragma alloc_text(GREP,InsertGrepFile,DoOneFile,DoInsertion,freegreplist) 1446 1617 #pragma alloc_text(GREP,SecsSince1980,match,mmatch,GrepThread) 1447 #pragma alloc_text(GREP, doallsubdirs,domatchingfiles,InsertDupes,FreeDupes)1618 #pragma alloc_text(GREP,DoAllSubdirs,DoMatchingFiles,InsertDupes,FreeDupes) 1448 1619 1449 1620 #pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock)
Note:
See TracChangeset
for help on using the changeset viewer.