Changeset 1157 for trunk/dll/grep.c
- Timestamp:
- Sep 5, 2008, 11:39:52 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/grep.c
r1063 r1157 44 44 #include "fm3str.h" 45 45 #include "grep.h" 46 #include "pathutil.h" 47 #include "filldir.h" 48 #include "makelist.h" 49 #include "errutil.h" 50 #include "strutil.h" 51 #include "tmrsvcs.h" 46 #include "pathutil.h" // BldFullPathName 47 #include "filldir.h" // FillInRecordFromFFB 48 #include "makelist.h" // AddToList 49 #include "errutil.h" // Dos_Error... 50 #include "strutil.h" // GetPString 51 #include "tmrsvcs.h" // ITIMER_DESC 52 52 #include "fm3dll.h" 53 #include "eas.h" // Free_FEAList 53 54 #include "fortify.h" 54 55 … … 58 59 59 60 static VOID DoAllSubdirs(GREP *grep, 60 61 62 63 64 65 61 CHAR *searchPath, 62 BOOL recursing, 63 char **fle, 64 UINT numfls, 65 ITIMER_DESC *pitdSleep, 66 ITIMER_DESC *pitdReport); 66 67 static INT DoMatchingFiles(GREP *grep, 67 68 69 70 71 68 CHAR *path, 69 CHAR **fle, 70 UINT numfls, 71 ITIMER_DESC *pitdSleep, 72 ITIMER_DESC *pitdReport); 72 73 static BOOL DoOneFile(GREP *grep, 73 74 75 76 74 CHAR *fileName, 75 FILEFINDBUF4L *pffb, 76 ITIMER_DESC *pitdSleep, 77 ITIMER_DESC *pitdReport); 77 78 static BOOL DoInsertion(GREP *grep, 78 79 79 ITIMER_DESC *pitdSleep, 80 ITIMER_DESC *pitdReport); 80 81 static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4L *pffb); 81 82 static VOID FillDupes(GREP *grep, 82 83 83 ITIMER_DESC *pitdSleep, 84 ITIMER_DESC *pitdReport); 84 85 85 86 static VOID FreeDupes(GREP *grep); … … 88 89 89 90 #define isleap(year) ((((year%4)==0) && ((year%100)!=0)) || \ 90 91 ((year%400)==0)) 91 92 92 93 static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; … … 122 123 123 124 static BOOL m_match(CHAR *string, CHAR *pattern, BOOL absolute, BOOL ignore, 124 125 LONG len) 125 126 { 126 127 // return TRUE if pattern found in string … … 131 132 132 133 if (len && string && pattern) { 133 if (absolute) 134 if (absolute) // no pattern matching 134 135 return (findstring(pattern, strlen(pattern), string, len, 135 136 (ignore == FALSE)) != NULL); 136 137 137 138 while (*tn && len2 < len) { 138 139 switch (*tn) { 139 140 case ' ': 140 141 142 143 144 141 while (*tn == ' ') 142 tn++; 143 while (len2 < len && isspace(string[len2])) 144 len2++; 145 break; 145 146 146 147 case '*': 147 148 149 150 151 152 153 154 155 156 157 158 159 148 while (*tn == '*' || *tn == '?') 149 tn++; 150 if (!*tn) 151 return TRUE; 152 if (ignore) { 153 while (len2 < len && string[len2] != *tn) 154 len2++; 155 } 156 else { 157 while (len2 < len && toupper(string[len2] != *tn)) 158 len2++; 159 } 160 break; 160 161 161 162 case '[': 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 163 tn++; 164 if (!*tn) 165 return FALSE; 166 lo = *tn; 167 tn++; 168 if (*tn != '-') 169 return FALSE; 170 tn++; 171 if (!*tn) 172 return FALSE; 173 hi = *tn; 174 tn++; 175 if (*tn != ']') 176 return FALSE; 177 tn++; 178 if (ignore) { 179 if ((toupper(string[len2]) >= toupper(lo)) && 180 (toupper(string[len2]) <= toupper(hi))) 181 len2++; 182 else { 183 tn = pattern; 184 len2 = lastlen = lastlen + 1; 185 } 186 } 187 else { 188 if ((string[len2] >= lo) && (string[len2] <= hi)) 189 len2++; 190 else { 191 tn = pattern; 192 len2 = lastlen = lastlen + 1; 193 } 194 } 195 break; 195 196 196 197 case '?': 197 198 199 198 tn++; 199 len2++; 200 break; 200 201 201 202 case '\\': 202 203 204 205 203 tn++; 204 if (!*tn) 205 return FALSE; 206 // else intentional fallthru 206 207 default: 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 208 if (ignore) { 209 if (toupper(*tn) == toupper(string[len2])) { 210 tn++; 211 len2++; 212 } 213 else { 214 tn = pattern; 215 len2 = lastlen = lastlen + 1; 216 } 217 } 218 else { 219 if (*tn == string[len2]) { 220 tn++; 221 len2++; 222 } 223 else { 224 tn = pattern; 225 len2 = lastlen = lastlen + 1; 226 } 227 } 228 break; 228 229 } 229 230 } … … 238 239 239 240 static BOOL match(CHAR *string, CHAR *patterns, BOOL absolute, BOOL ignore, 240 241 LONG len, ULONG numlines, CHAR *matched, BOOL matchall) 241 242 { 242 243 BOOL ret = FALSE; … … 251 252 if (matched && ret && x < numlines) 252 253 matched[x] = 1; 253 p += strlen(p); 254 p += strlen(p); // check each pattern in 0-terminated list 254 255 p++; 255 256 x++; … … 265 266 UINT x; 266 267 UINT numfls; 267 static CHAR *fle[512]; 268 static CHAR *fle[512]; // 06 Feb 08 SHL fixme to not be static 268 269 CHAR *p, *pp, searchPath[CCHMAXPATH * 2]; 269 270 270 ITIMER_DESC itdSleep = { 0 }; 271 ITIMER_DESC itdSleep = { 0 }; // 06 Feb 08 SHL 271 272 ITIMER_DESC itdReport = { 0 }; 272 273 … … 280 281 # endif 281 282 grep = *(GREP *)arg; 282 *grep.stopflag = 0; 283 *grep.stopflag = 0; // reset thread-killing flag 283 284 DosError(FERR_DISABLEHARDERR); 284 285 priority_normal(); … … 291 292 WinCancelShutdown(ghmq, TRUE); 292 293 IncrThreadUsage(); 293 // DosSleep(100); //05 Aug 07 GKY 128 294 // DosSleep(100); //05 Aug 07 GKY 128 // 07 Feb 08 SHL 294 295 // hwndStatus does not exist for applet 295 296 WinSetWindowText(hwndStatus ? hwndStatus : grep.hwndCurFile, 296 297 297 GetPString(grep.finddupes ? IDS_GREPDUPETEXT : 298 IDS_GREPSCANTEXT)); 298 299 299 300 pp = grep.searchPattern; 300 301 while (*pp) { 301 302 p = GREPCHARS;// see if any sense in pattern matching303 304 305 306 307 308 if (!*p)// nope, turn it off309 310 311 302 if (!grep.absFlag) { 303 p = GREPCHARS; // see if any sense in pattern matching 304 while (*p) { 305 if (strchr(pp, *p)) 306 break; 307 p++; 308 } 309 if (!*p) // nope, turn it off 310 grep.absFlag = TRUE; 311 } 312 pp = pp + strlen(pp) + 1; 312 313 } 313 314 … … 315 316 grep.antiattr &= (~FILE_DIRECTORY); 316 317 if (grep.antiattr & FILE_READONLY) 317 318 grep.antiattr |= MUST_HAVE_READONLY; 318 319 if (grep.antiattr & FILE_HIDDEN) 319 320 grep.antiattr |= MUST_HAVE_HIDDEN; 320 321 if (grep.antiattr & FILE_SYSTEM) 321 322 grep.antiattr |= MUST_HAVE_SYSTEM; 322 323 if (grep.antiattr & FILE_ARCHIVED) 323 324 grep.antiattr |= MUST_HAVE_ARCHIVED; 324 325 325 326 grep.anyexcludes = FALSE; … … 328 329 329 330 while ((fle[numfls] = strtok(NULL, ";")) != NULL && numfls < 511) { 330 331 332 331 if (*fle[numfls] == '/') 332 grep.anyexcludes = TRUE; 333 numfls++; 333 334 } 334 335 335 InitITimer(&itdSleep, 500); 336 InitITimer(&itdReport, 2000); 336 InitITimer(&itdSleep, 500); // Sleep every 500 mSec 337 InitITimer(&itdReport, 2000); // Report every 2 sec 337 338 338 339 // loop through search masks 339 340 for (x = 0; x < numfls; x++) { 340 341 341 if (*fle[x] == '/')// is an exclude mask only342 343 344 345 346 347 348 349 350 if (p == fle[x]) {// no path351 352 353 354 355 else {// got to deal with a path356 if (*p == ':') {// just a drive, start in root dir357 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 if (grep.dirFlag)// do subdirs384 342 if (*fle[x] == '/') // is an exclude mask only 343 goto ExcludeSkip; 344 345 // first, separate any path from mask 346 347 p = (char *)(fle[x] + (strlen(fle[x]) - 1)); 348 while (*p != '\\' && *p != ':' && p != fle[x]) 349 --p; 350 351 if (p == fle[x]) { // no path 352 strcpy(searchPath, grep.curdir); 353 strncpy(grep.fileMask, fle[x], CCHMAXPATH); 354 grep.fileMask[CCHMAXPATH - 1] = 0; 355 } 356 else { // got to deal with a path 357 if (*p == ':') { // just a drive, start in root dir 358 *p = 0; 359 p++; 360 strncpy(searchPath, fle[x], CCHMAXPATH - 2); 361 searchPath[CCHMAXPATH - 3] = 0; 362 strcat(searchPath, ":\\"); 363 strcpy(grep.fileMask, p); 364 } 365 if (*p == '\\') { 366 // got a 'full' path 367 CHAR temp; 368 369 p++; 370 temp = *p; 371 *p = 0; 372 strncpy(searchPath, fle[x], CCHMAXPATH); 373 searchPath[CCHMAXPATH - 1] = 0; 374 *p = temp; 375 strcpy(grep.fileMask, p); 376 } 377 if (!*grep.fileMask) 378 strcpy(grep.fileMask, "*"); 379 } 380 if (*grep.stopflag) 381 break; 382 // do single directory 383 DoMatchingFiles(&grep, searchPath, fle, numfls, &itdSleep, &itdReport); 384 if (grep.dirFlag) // do subdirs 385 DoAllSubdirs(&grep, searchPath, FALSE, fle, numfls, &itdSleep, &itdReport); 385 386 ExcludeSkip: 386 387 388 389 DoInsertion(&grep, &itdSleep, &itdReport);// insert any remaining objects387 if (*grep.stopflag) 388 break; 389 if (WinIsWindow(grep.ghab, grep.hwndFiles)) 390 DoInsertion(&grep, &itdSleep, &itdReport); // insert any remaining objects 390 391 } // for 391 392 392 393 if (WinIsWindow(grep.ghab, grep.hwndFiles)) 393 DoInsertion(&grep, &itdSleep, &itdReport);// insert any remaining objects394 DoInsertion(&grep, &itdSleep, &itdReport); // insert any remaining objects 394 395 395 396 if (WinIsWindow(grep.ghab, grep.hwndFiles) && 396 397 397 grep.finddupes && 398 !*grep.stopflag) 398 399 { 399 400 FillDupes(&grep, &itdSleep, &itdReport); 400 401 } 401 402 402 if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID)) 403 403 if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID)) // tell window we're done 404 WinSendMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID); 404 405 WinDestroyMsgQueue(ghmq); 405 406 } … … 435 436 for (x = 0; x < numfls; x++) { 436 437 if (*fle[x] == '/' && 437 438 438 wildcard((strchr(fle[x], '\\') || 439 strchr(fle[x], ':')) ? name : n, fle[x] + 1, FALSE)) 439 440 return TRUE; 440 441 } … … 443 444 444 445 static VOID DoAllSubdirs(GREP *grep, 445 446 447 448 449 450 446 CHAR *searchPath, 447 BOOL recursing, 448 CHAR **fle, 449 UINT numfls, 450 ITIMER_DESC *pitdSleep, 451 ITIMER_DESC *pitdReport) 451 452 { 452 453 // process all subdirectories … … 464 465 DosError(FERR_DISABLEHARDERR); 465 466 if (!DosFindFirst(searchPath, &findHandle, (MUST_HAVE_DIRECTORY | 466 467 468 467 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY), 468 &ffb, (ULONG) sizeof(ffb), 469 (PULONG) & ulFindCnt, FIL_QUERYEASIZE)) { 469 470 470 471 // get rid of mask portion, save end-of-directory … … 475 476 else 476 477 p = searchPath; 477 do { 478 do { // Process each directory that matches the mask 478 479 priority_normal(); 479 480 if (*grep->stopflag) 480 481 break; 481 482 // Skip . and .. 482 483 if (ffb.achName[0] != '.' || 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 // DosSleep(0); //26 Aug 07 GKY 1// 07 Feb 08 SHL512 484 (ffb.achName[1] && 485 (ffb.achName[1] != '.' || ffb.achName[2]))) { 486 strcpy(p, ffb.achName); 487 if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) { 488 // 07 Feb 08 SHL 489 if (IsITimerExpired(pitdReport)) { 490 if (!hwndStatus) 491 WinSetWindowText(grep->hwndCurFile, searchPath); 492 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) { 493 CHAR s[CCHMAXPATH + 64]; 494 sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), searchPath); 495 WinSetWindowText(hwndStatus, s); 496 } 497 } 498 DoMatchingFiles(grep, searchPath, fle, numfls, pitdSleep, pitdReport); 499 // 07 Feb 08 SHL 500 if (IsITimerExpired(pitdReport)) { 501 if (!hwndStatus) 502 WinSetWindowText(grep->hwndCurFile, searchPath); 503 else { 504 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) { 505 CHAR s[CCHMAXPATH + 64]; 506 sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), searchPath); 507 WinSetWindowText(hwndStatus, s); 508 } 509 } 510 } 511 DoAllSubdirs(grep, searchPath, TRUE, fle, numfls, pitdSleep, pitdReport); 512 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 513 } 513 514 } 514 515 ulFindCnt = 1; 515 516 } while (!DosFindNext(findHandle, 516 517 517 &ffb, 518 sizeof(ffb), (PULONG) & ulFindCnt)); 518 519 DosFindClose(findHandle); 519 520 priority_normal(); 520 521 } 521 if (p) 522 if (p) // strip off last directory addition 522 523 *p = 0; 523 524 } … … 528 529 529 530 static INT DoMatchingFiles(GREP *grep, 530 531 532 533 534 531 CHAR *path, 532 CHAR **fle, 533 UINT numfls, 534 ITIMER_DESC *pitdSleep, 535 ITIMER_DESC *pitdReport) 535 536 { 536 537 // process all matching files in a directory … … 567 568 ulFindCnt = FilesToGet; 568 569 rc = xDosFindFirst(szFindPath, 569 570 571 572 573 574 570 &findHandle, 571 FILE_NORMAL | grep->attrFile | grep->antiattr, 572 pffbArray, 573 ulBufBytes, 574 &ulFindCnt, 575 FIL_QUERYEASIZEL); 575 576 if (!rc) { 576 577 do { … … 579 580 pffbFile = pffbArray; 580 581 for (x = 0; x < ulFindCnt; x++) { 581 582 583 584 585 strcpy(p, pffbFile->achName);// build filename586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 582 if (*grep->stopflag) 583 break; 584 if (*pffbFile->achName != '.' || 585 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) { 586 strcpy(p, pffbFile->achName); // build filename 587 if (strlen(szFindPath) > CCHMAXPATH){ 588 // Complain if pathnames exceeds max 589 DosFindClose(findHandle); 590 //xfree(pffbArray, pszSrcFile, __LINE__); 591 if (!fDone) { 592 fDone = TRUE; 593 saymsg(MB_OK | MB_ICONASTERISK, 594 HWND_DESKTOP, 595 GetPString(IDS_WARNINGTEXT), 596 "One or more of your files has a full path name that exceeds the OS/2 maximum"); 597 } 598 return 1; 599 } 600 601 // 07 Feb 08 SHL 602 if (IsITimerExpired(pitdReport)) { 603 if (!hwndStatus) 604 WinSetWindowText(grep->hwndCurFile, szFindPath); 605 else { 606 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) { 607 CHAR s[CCHMAXPATH + 64]; 608 sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), szFindPath); 609 WinSetWindowText(hwndStatus, s); 610 } 611 } 612 } 613 614 if (!grep->anyexcludes || !IsExcluded(szFindPath, fle, numfls)) { 615 if (!grep->finddupes) 616 DoOneFile(grep, szFindPath, pffbFile, pitdSleep, pitdReport); 617 else if (!InsertDupe(grep, szFindPath, pffbFile)) { 618 DosFindClose(findHandle); 619 free(pffbArray); 619 620 # ifdef FORTIFY 620 621 Fortify_LeaveScope(); 621 622 # endif 622 623 624 625 626 627 628 623 return 1; 624 } 625 } 626 } 627 if (!pffbFile->oNextEntryOffset) 628 break; 629 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + pffbFile->oNextEntryOffset); 629 630 } // for 630 631 if (*grep->stopflag) 631 632 break; 632 633 SleepIfNeeded(pitdSleep, 1); 633 // DosSleep(0); //26 Aug 07 GKY 1 634 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 634 635 ulFindCnt = FilesToGet; 635 636 rc = xDosFindNext(findHandle, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL); … … 642 643 if (rc && rc != ERROR_NO_MORE_FILES) { 643 644 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, 644 645 GetPString(IDS_CANTFINDDIRTEXT), szFindPath); 645 646 } 646 647 … … 684 685 685 686 static BOOL DoInsertion(GREP *grep, 686 687 687 ITIMER_DESC *pitdSleep, 688 ITIMER_DESC *pitdReport) 688 689 { 689 690 RECORDINSERT ri; … … 696 697 697 698 pci = WinSendMsg(grep->hwndFiles, 698 699 700 699 CM_ALLOCRECORD, 700 MPFROMLONG(EXTRA_RECORD_BYTES), 701 MPFROMLONG(grep->toinsert)); 701 702 if (!pci) { 702 703 Win_Error(grep->hwndFiles, grep->hwndFiles, pszSrcFile, __LINE__, 703 704 "CM_ALLOCRECORD %u failed", grep->toinsert); 704 705 } 705 706 else { 706 707 if (grep->sayfiles) { 707 708 if (!hwndStatus) 708 709 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT)); 709 710 else { 710 711 711 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 712 WinSetWindowText(hwndStatus, GetPString(IDS_GREPINSERTINGTEXT)); 712 713 } 713 714 } … … 716 717 for (x = 0; grep->insertffb[x]; x++) { 717 718 FillInRecordFromFFB(grep->hwndFiles, 718 719 pci, grep->dir[x], grep->insertffb[x], FALSE, dcd); 719 720 pci = (PCNRITEM) pci->rc.preccNextRecord; 720 721 SleepIfNeeded(pitdSleep, 1); … … 728 729 ri.fInvalidateRecord = TRUE; 729 730 WinSendMsg(grep->hwndFiles, 730 731 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri)); 731 732 if (dcd) { 732 733 DosEnterCritSec(); … … 735 736 } 736 737 SleepIfNeeded(pitdSleep, 1); 737 // if (grep->toinsert == FilesToGet) 738 // DosSleep(0); //26 Aug 07 GKY 1 738 // if (grep->toinsert == FilesToGet) // 07 Feb 08 SHL 739 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 739 740 freegreplist(grep); 740 741 PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID); … … 750 751 751 752 static BOOL InsertGrepFile(GREP *grep, 752 753 754 755 753 CHAR *pszFileName, 754 PFILEFINDBUF4L pffb, 755 ITIMER_DESC *pitdSleep, 756 ITIMER_DESC *pitdReport) 756 757 { 757 758 PSZ p; … … 770 771 // Got directory 771 772 if (p < szDirectory + 4) 772 p++;// Include root backslash773 p++; // Include root backslash 773 774 *p = 0; 774 775 775 776 if (!grep->insertffb) { 776 777 778 779 780 781 782 783 784 777 // Allocate 1 extra for end marker? 778 grep->insertffb = xmallocz(sizeof(PFILEFINDBUF4L) * (FilesToGet + 1), 779 pszSrcFile, __LINE__); 780 if (!grep->insertffb) 781 return FALSE; 782 grep->dir = xmallocz(sizeof(CHAR *) * (FilesToGet + 1), 783 pszSrcFile, __LINE__); 784 if (!grep->dir) { 785 free(grep->insertffb); 785 786 # ifdef FORTIFY 786 787 Fortify_LeaveScope(); 787 788 # endif 788 789 789 return FALSE; 790 } 790 791 } 791 792 792 793 grep->insertffb[grep->toinsert] = 793 794 xmalloc(sizeof(FILEFINDBUF4L), pszSrcFile, __LINE__); 794 795 if (!grep->insertffb[grep->toinsert]) 795 796 return FALSE; 796 797 memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4L)); 797 798 … … 802 803 Fortify_LeaveScope(); 803 804 # endif 804 805 return FALSE; 805 806 } 806 807 … … 808 809 grep->toinsert++; 809 810 if (grep->toinsert == FilesToGet) 810 811 return DoInsertion(grep, pitdSleep, pitdReport); 811 812 return TRUE; 812 813 } … … 820 821 821 822 static BOOL DoOneFile(GREP *grep, 822 823 824 825 823 CHAR *pszFileName, 824 FILEFINDBUF4L *pffb, 825 ITIMER_DESC *pitdSleep, 826 ITIMER_DESC *pitdReport) 826 827 { 827 828 // process a single file … … 837 838 else { 838 839 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 839 840 WinSetWindowText(hwndStatus, pszFileName); 840 841 } 841 842 } … … 849 850 if (grep->greaterthan) { 850 851 if (adjsize < grep->greaterthan) 851 852 keep = FALSE; 852 853 } 853 854 if (keep && grep->lessthan) { 854 855 if (adjsize > grep->lessthan) 855 856 keep = FALSE; 856 857 } 857 858 if (!keep) … … 867 868 if (grep->newerthan) { 868 869 if (numsecs < grep->newerthan) 869 870 keep = FALSE; 870 871 } 871 872 if (keep && grep->olderthan) { 872 873 if (numsecs > grep->olderthan) 873 874 keep = FALSE; 874 875 } 875 876 if (!keep) … … 877 878 } 878 879 879 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) 880 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) // just a find 880 881 return InsertGrepFile(grep, pszFileName, pffb, pitdSleep, pitdReport); 881 882 … … 891 892 info = head; 892 893 while (info && !strmatch) { 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 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 982 983 984 985 } 894 alltext = TRUE; 895 switch (*(USHORT *)info->value) { 896 case EAT_ASCII: 897 if (match(info->value + (sizeof(USHORT) * 2), 898 grep->searchPattern, grep->absFlag, 899 grep->caseFlag == FALSE, 900 info->cbValue - (sizeof(USHORT) * 2), 901 grep->numlines, 902 grep->matched, 903 !grep->findifany)) { 904 strmatch = TRUE; 905 } 906 break; 907 case EAT_MVST: 908 type = *(USHORT *)(info->value + (sizeof(USHORT) * 3)); 909 if (type == EAT_ASCII) { 910 data = info->value + (sizeof(USHORT) * 4); 911 len = *(USHORT *) data; 912 data += sizeof(USHORT); 913 while ((data - info->value) + len <= info->cbValue) { 914 temp = *(data + len); 915 *(data + len) = 0; 916 if (match(data, 917 grep->searchPattern, 918 grep->absFlag, 919 (grep->caseFlag == FALSE), 920 len, 921 grep->numlines, grep->matched, !grep->findifany)) { 922 strmatch = TRUE; 923 break; 924 } 925 data += len; 926 if (data - info->value >= info->cbValue) 927 break; 928 *data = temp; 929 len = *(USHORT *) data; 930 data += sizeof(USHORT); 931 } 932 } 933 break; 934 case EAT_MVMT: 935 data = info->value + (sizeof(USHORT) * 3); 936 type = *(USHORT *) data; 937 data += sizeof(USHORT); 938 len = *(USHORT *) data; 939 data += sizeof(USHORT); 940 while ((data - info->value) - len <= info->cbValue) { 941 if (type != EAT_ASCII) { 942 alltext = FALSE; 943 break; 944 } 945 data += len; 946 if (data - info->value >= info->cbValue) 947 break; 948 type = *(USHORT *) data; 949 data += sizeof(USHORT); 950 len = *(USHORT *) data; 951 data += sizeof(USHORT); 952 } 953 if (alltext) { 954 data = info->value + (sizeof(USHORT) * 3); 955 type = *(USHORT *) data; 956 data += sizeof(USHORT); 957 len = *(USHORT *) data; 958 data += sizeof(USHORT); 959 while ((data - info->value) - len <= info->cbValue) { 960 temp = *(data + len); 961 *(data + len) = 0; 962 if (match(data, 963 grep->searchPattern, 964 grep->absFlag, 965 (grep->caseFlag == FALSE), 966 len, 967 grep->numlines, grep->matched, !grep->findifany)) { 968 strmatch = TRUE; 969 break; 970 } 971 data += len; 972 *data = temp; 973 if (data - info->value >= info->cbValue) 974 break; 975 type = *(USHORT *) data; 976 data += sizeof(USHORT); 977 len = *(USHORT *) data; 978 data += sizeof(USHORT); 979 } 980 } 981 break; 982 default: 983 break; 984 } 985 info = info->next; 986 } // while 986 987 Free_FEAList(head); 987 // DosSleep(1); 988 // DosSleep(1); // 07 Feb 08 SHL 988 989 } 989 990 } … … 996 997 inputFile = _fsopen(pszFileName, "rb", SH_DENYNO); 997 998 if (inputFile) { 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 999 pos = ftell(inputFile); 1000 while (!feof(inputFile)) { 1001 if (pos) 1002 fseek(inputFile, pos - 1024, SEEK_SET); 1003 len = fread(input, 1, 65536, inputFile); 1004 if (len >= 0) { 1005 if (*grep->stopflag) 1006 break; 1007 if (match(input, 1008 grep->searchPattern, 1009 grep->absFlag, 1010 (grep->caseFlag == FALSE), 1011 len, grep->numlines, grep->matched, !grep->findifany)) { 1012 strmatch = TRUE; 1013 break; 1014 } 1015 } 1016 else 1017 break; 1018 } 1019 fclose(inputFile); 1019 1020 } 1020 1021 free(input); … … 1022 1023 Fortify_LeaveScope(); 1023 1024 # endif 1024 // DosSleep(1); 1025 // DosSleep(1); // 07 Feb 08 SHL 1025 1026 } 1026 1027 } // if … … 1031 1032 } 1032 1033 1033 static LONG cr3tab[] = { 1034 static LONG cr3tab[] = { // CRC polynomial 0xEDB88320 1034 1035 1035 1036 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, … … 1125 1126 else { 1126 1127 while (!feof(fp)) { 1127 1128 1129 1130 1131 1132 // DosSleep(0); //26 Aug 07 GKY 1// 07 Feb 08 SHL1128 len = fread(buffer, 1, 65535, fp); 1129 if (len && len < 65536L) 1130 CRC = CRCBlock(buffer, len, CRC); 1131 else 1132 break; 1133 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1133 1134 } 1134 1135 fclose(fp); 1135 // DosSleep(1); 1136 // DosSleep(1); // 07 Feb 08 SHL 1136 1137 } 1137 1138 free(buffer); … … 1290 1291 1291 1292 static VOID FillDupes(GREP *grep, 1292 1293 1293 ITIMER_DESC *pitdSleep, 1294 ITIMER_DESC *pitdReport) 1294 1295 { 1295 1296 DUPES *c, *i, **r; … … 1300 1301 ULONG x; 1301 1302 ULONG y; 1302 // ULONG cntr = 1000; 1303 1304 // if (grep->CRCdupes) 1305 // cntr = 100; 1303 // ULONG cntr = 1000; // 09 Feb 08 SHL 1304 1305 // if (grep->CRCdupes) // 09 Feb 08 SHL 1306 // cntr = 100; // 09 Feb 08 SHL 1306 1307 x = 0; 1307 1308 for (i = grep->dupehead; i; i = i->next) 1308 x++; 1309 x++; // Count 1309 1310 1310 1311 if (x) { … … 1313 1314 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1314 1315 WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPESORTINGTEXT)); 1315 // DosSleep(0); //26 Aug 07 GKY 1 1316 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1316 1317 grep->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__); 1317 1318 if (!grep->nosizedupes) … … 1320 1321 y = 0; 1321 1322 for (i = grep->dupehead; i; i = i->next) { 1322 1323 1324 1325 1323 grep->dupenames[y] = i; 1324 if (!grep->nosizedupes) 1325 grep->dupesizes[y] = i; 1326 y++; 1326 1327 } 1327 grep->dupenames[y] = NULL; 1328 grep->dupenames[y] = NULL; // Mark end 1328 1329 if (!grep->nosizedupes) 1329 1330 1331 InitITimer(pitdSleep, 0); 1330 grep->dupesizes[y] = NULL; 1331 1332 InitITimer(pitdSleep, 0); // Reset rate estimator 1332 1333 SleepIfNeeded(pitdSleep, 1); 1333 // DosSleep(0); //26 Aug 07 GKY 1 1334 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1334 1335 1335 1336 qsort(grep->dupenames, 1336 1337 1338 1337 x, 1338 sizeof(DUPES *), 1339 grep->ignoreextdupes ? comparenamesqe : comparenamesq); 1339 1340 SleepIfNeeded(pitdSleep, 1); 1340 // DosSleep(0); //26 Aug 07 GKY 1 1341 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1341 1342 if (!grep->nosizedupes) { 1342 1343 1344 // DosSleep(0); //26 Aug 07 GKY 1// 07 Feb 08 SHL1343 qsort(grep->dupesizes, x, sizeof(DUPES *), comparesizesq); 1344 SleepIfNeeded(pitdSleep, 1); 1345 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1345 1346 } 1346 1347 1347 1348 if (!hwndStatus) 1348 1349 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1349 1350 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1350 1351 1352 InitITimer(pitdSleep, 0); 1351 WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1352 1353 InitITimer(pitdSleep, 0); // Reset rate estimator 1353 1354 i = grep->dupehead; 1354 1355 y = 0; 1355 1356 while (i) { 1356 1357 1358 SleepIfNeeded(pitdSleep, 1);// 07 Feb 08 SHL1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1357 if (*grep->stopflag) 1358 break; 1359 SleepIfNeeded(pitdSleep, 1); // 07 Feb 08 SHL 1360 if (!(i->flags & GF_SKIPME)) { 1361 r = (DUPES **) bsearch(i, grep->dupenames, x, sizeof(DUPES *), 1362 ((grep->ignoreextdupes) ? comparenamesbe : 1363 comparenamesb)); 1364 if (r) { 1365 while (r > grep->dupenames && ((grep->ignoreextdupes) ? 1366 !comparenamesqe((r - 1), &i) : 1367 !comparenamesq((r - 1), &i))) 1368 r--; 1369 while (*r && ((grep->ignoreextdupes) ? 1370 !comparenamesqe(r, &i) : !comparenamesq(r, &i))) { 1371 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) { 1372 r++; 1373 continue; 1374 } 1375 if (grep->CRCdupes) { 1376 if ((*r)->CRC == -1L) { 1377 (*r)->CRC = CRCFile((*r)->name, &error); 1378 if (error) 1379 (*r)->CRC = -1L; 1380 else if ((*r)->CRC == -1L) 1381 (*r)->CRC = 0L; 1382 } 1383 if (i->CRC == -1L) { 1384 i->CRC = CRCFile(i->name, &error); 1385 if (error) 1386 i->CRC = -1L; 1387 else if (i->CRC == -1L) 1388 i->CRC = 0L; 1389 } 1390 if (((*r)->size != i->size) || ((*r)->CRC != -1L && 1391 i->CRC != -1L 1392 && (*r)->CRC != i->CRC)) { 1393 r++; 1394 continue; 1395 } 1396 } 1397 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) { 1398 (*r)->flags |= GF_INSERTED; 1399 if (grep->sayfiles) { 1400 if (!hwndStatus) 1401 WinSetWindowText(grep->hwndFiles, (*r)->name); 1402 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1403 WinSetWindowText(hwndStatus, (*r)->name); 1404 } 1405 if ((*r)->size == i->size && 1406 (i->date.year == (*r)->date.year && 1407 i->date.month == (*r)->date.month && 1408 i->date.day == (*r)->date.day && 1409 i->time.hours == (*r)->time.hours && 1410 i->time.minutes == (*r)->time.minutes && 1411 i->time.twosecs == (*r)->time.twosecs)) 1412 (*r)->flags |= GF_SKIPME; 1413 } 1414 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) { 1415 if (!AddToList(i->name, &list, &numfiles, &numalloced)) { 1416 i->flags |= GF_INSERTED; 1417 if ((*r)->flags & GF_SKIPME) 1418 i->flags |= GF_SKIPME; 1419 } 1420 } 1421 r++; 1422 } 1423 } 1424 if (!grep->nosizedupes) { 1425 r = (DUPES **) bsearch(i, 1426 grep->dupesizes, 1427 x, sizeof(DUPES *), comparesizesb); 1428 if (r) { 1429 while (r > grep->dupesizes && !comparesizesq((r - 1), &i)) 1430 r--; 1431 while (*r && !comparesizesq(r, &i)) { 1432 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME)) || 1433 (i->date.year != (*r)->date.year || 1434 i->date.month != (*r)->date.month || 1435 i->date.day != (*r)->date.day || 1436 i->time.hours != (*r)->time.hours || 1437 i->time.minutes != (*r)->time.minutes || 1438 i->time.twosecs != (*r)->time.twosecs)) { 1439 r++; 1440 continue; 1441 } 1442 if (grep->CRCdupes) { 1443 if ((*r)->CRC == -1L) { 1444 (*r)->CRC = CRCFile((*r)->name, &error); 1445 if (error) 1446 (*r)->CRC = -1L; 1447 else if ((*r)->CRC == -1L) 1448 (*r)->CRC = 0L; 1449 } 1450 if (i->CRC == -1L) { 1451 i->CRC = CRCFile(i->name, &error); 1452 if (error) 1453 i->CRC = -1L; 1454 else if (i->CRC == -1L) 1455 i->CRC = 0L; 1456 } 1457 if ((*r)->CRC != -1L && i->CRC != -1L && 1458 (*r)->CRC != i->CRC) { 1459 *r += 1; 1460 continue; 1461 } 1462 } 1463 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) { 1464 if (grep->sayfiles) { 1465 if (!hwndStatus) 1466 WinSetWindowText(grep->hwndCurFile, (*r)->name); 1467 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1468 WinSetWindowText(hwndStatus, (*r)->name); 1469 } 1470 (*r)->flags |= GF_INSERTED; 1471 if (((grep->ignoreextdupes) ? 1472 comparenamesqe(r, &i) : comparenamesq(r, &i))) 1473 (*r)->flags |= GF_SKIPME; 1474 } 1475 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) { 1476 if (!AddToList(i->name, &list, &numfiles, &numalloced)) { 1477 i->flags |= GF_INSERTED; 1478 if ((*r)->flags & GF_SKIPME) 1479 i->flags |= GF_SKIPME; 1480 } 1481 } 1482 r++; 1483 } 1484 } 1485 } 1486 } 1487 i = i->next; 1488 y++; 1489 // 08 Feb 08 SHL 1490 if (IsITimerExpired(pitdReport)) { 1491 CHAR s[44]; 1492 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles); 1493 if (!hwndStatus) 1494 WinSetWindowText(grep->hwndCurFile, s); 1495 else { 1496 if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1497 WinSetWindowText(hwndStatus, s); 1498 } 1499 } 1500 // DosSleep(0); //26 Aug 07 GKY 1 1500 1501 } // while 1501 1502 } … … 1504 1505 DosBeep(50, 100); 1505 1506 if (!hwndStatus) 1506 1507 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1507 1508 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1508 1509 WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1509 1510 x = y = 0; 1510 1511 xfree(grep->dupenames, pszSrcFile, __LINE__); … … 1516 1517 # endif 1517 1518 1518 InitITimer(pitdSleep, 0); 1519 InitITimer(pitdSleep, 0); // Reset rate estimator 1519 1520 i = grep->dupehead; 1520 1521 while (i) { 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 // DosSleep(0); //26 Aug 07 GKY 1// 07 Feb 08 SHL1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 if ((!grep->nosizedupes && i->size == c->size && i->date.year == c->date.year && i->date.month == c->date.month && i->date.day == c->date.day && i->time.hours == c->time.hours && i->time.minutes == c->time.minutes && i->time.twosecs == c->time.twosecs) || !stricmp(pc, pi)) {// potential dupe1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 goto BreakOut;// Failed1579 1580 1581 goto BreakOut;// Failed1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 // else if (!(x % 100))// 07 Feb 08 SHL1597 // DosSleep(0); //26 Aug 07 GKY 1// 07 Feb 08 SHL1598 1599 1600 1601 1602 1522 if (*grep->stopflag) 1523 break; 1524 SleepIfNeeded(pitdSleep, 1); 1525 if (!(i->flags & GF_SKIPME)) { 1526 if (IsITimerExpired(pitdReport)) { 1527 // if (!(y % cntr)) { } 1528 CHAR s[44]; 1529 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles); 1530 if (!hwndStatus) 1531 WinSetWindowText(grep->hwndCurFile, s); 1532 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1533 WinSetWindowText(hwndStatus, s); 1534 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1535 } 1536 y++; 1537 pi = strrchr(i->name, '\\'); 1538 if (pi) 1539 pi++; 1540 else 1541 pi = i->name; 1542 c = grep->dupehead; 1543 while (c) { 1544 if (*grep->stopflag) 1545 break; 1546 if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) { 1547 x++; 1548 pc = strrchr(c->name, '\\'); 1549 if (pc) 1550 pc++; 1551 else 1552 pc = c->name; 1553 if ((!grep->nosizedupes && i->size == c->size && i->date.year == c->date.year && i->date.month == c->date.month && i->date.day == c->date.day && i->time.hours == c->time.hours && i->time.minutes == c->time.minutes && i->time.twosecs == c->time.twosecs) || !stricmp(pc, pi)) { // potential dupe 1554 if (grep->CRCdupes) { 1555 if (grep->CRCdupes) { 1556 if (c->CRC == -1L) { 1557 c->CRC = CRCFile(c->name, &error); 1558 if (error) 1559 c->CRC = -1L; 1560 else if (c->CRC == -1L) 1561 c->CRC = 0L; 1562 } 1563 if (i->CRC == -1L) { 1564 i->CRC = CRCFile(i->name, &error); 1565 if (error) 1566 i->CRC = -1L; 1567 else if (i->CRC == -1L) 1568 i->CRC = 0L; 1569 } 1570 if ((c->size != i->size) || (c->CRC != -1L && 1571 i->CRC != -1L 1572 && c->CRC != i->CRC)) { 1573 c = c->next; 1574 continue; 1575 } 1576 } 1577 } 1578 if (AddToList(c->name, &list, &numfiles, &numalloced)) 1579 goto BreakOut; // Failed 1580 if (!(i->flags & GF_INSERTED)) { 1581 if (AddToList(i->name, &list, &numfiles, &numalloced)) 1582 goto BreakOut; // Failed 1583 } 1584 if (grep->sayfiles) { 1585 if (!hwndStatus) 1586 WinSetWindowText(grep->hwndCurFile, pc); 1587 else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) 1588 WinSetWindowText(hwndStatus, pc); 1589 } 1590 c->flags |= GF_INSERTED; 1591 i->flags |= GF_INSERTED; 1592 if (!stricmp(pc, pi)) { 1593 c->flags |= GF_SKIPME; 1594 i->flags |= GF_SKIPME; 1595 } 1596 } 1597 // else if (!(x % 100)) // 07 Feb 08 SHL 1598 // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL 1599 } 1600 c = c->next; 1601 } 1602 } 1603 i = i->next; 1603 1604 } // while 1604 1605 } … … 1608 1609 if (numfiles && list) { 1609 1610 if (!PostMsg(grep->hwndFiles, 1610 1611 1612 1611 WM_COMMAND, 1612 MPFROM2SHORT(IDM_COLLECTOR, 0), 1613 MPFROMP(list))) 1613 1614 FreeList(list); 1614 1615 }
Note:
See TracChangeset
for help on using the changeset viewer.