source: trunk/dll/grep.c@ 858

Last change on this file since 858 was 850, checked in by Steven Levine, 18 years ago

Rework large file support wrappers (ticket #41)
Add code to avoid NTFS driver small file read defect (ticket #159)
Add debug code to try to catch David's drive bar exception
Another attempt to correct newview fast viewer text load failure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: grep.c 850 2007-10-07 02:50:15Z stevenhl $
5
6 grep tools
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2007 Steven H. Levine
10
11 12 Feb 03 SHL insert_grepfile: standardize EA math
12 12 Feb 03 SHL doonefile: standardize EA math
13 25 May 05 SHL Rework for ULONGLONG
14 25 May 05 SHL Rework for FillInRecordFromFFB
15 06 Jun 05 SHL Drop unused code
16 24 Oct 05 SHL dononefile: do not free EA list twice
17 22 Jul 06 SHL Use Runtime_Error
18 26 Jul 06 SHL Check more run time errors
19 19 Oct 06 SHL Correct . and .. detect
20 03 Nov 06 SHL Count thread usage
21 03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
22 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
23 13 Aug 07 SHL Avoid pointer errors; sanitize code
24 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
25 15 Aug 07 SHL Use FilesToGet directly
26 26 Aug 07 GKY Improved performance of FillDups
27 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
28 21 Sep 07 GKY Fix trap on search that includes filenames that exceed maxpath
29
30***********************************************************************/
31
32#define INCL_DOS
33#define INCL_WIN
34#define INCL_DOSERRORS
35#define INCL_LONGLONG
36#include <os2.h>
37
38#include <stdlib.h>
39#include <string.h>
40#include <ctype.h>
41#include <stdio.h>
42#include <share.h>
43
44#include "fm3dll.h"
45#include "fm3str.h"
46#include "grep.h"
47
48#pragma data_seg(DATA2)
49
50static PSZ pszSrcFile = __FILE__;
51
52static VOID doallsubdirs(GREP *grep, CHAR *searchPath, BOOL recursing,
53 char **fle, int numfls);
54static INT domatchingfiles(GREP *grep, CHAR *path, char **fle, int numfls);
55static BOOL doonefile(GREP *grep, CHAR *fileName, FILEFINDBUF4L *pffb);
56static BOOL doinsertion(GREP *grep);
57static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4L *pffb);
58static VOID FillDupes(GREP *grep);
59static VOID FreeDupes(GREP *grep);
60
61#define GREPCHARS "*?[] \\"
62
63#define isleap(year) ((((year%4)==0) && ((year%100)!=0)) || \
64 ((year%400)==0))
65
66static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
67
68ULONG SecsSince1980(FDATE * date, FTIME * time)
69{
70 ULONG total = 0;
71 register int x;
72
73 for (x = 1980; x < date->year + 1980; x++) {
74 if (isleap(x))
75 total += (366 * (24 * 60 * 60));
76 else
77 total += (365 * (24 * 60 * 60));
78 }
79 for (x = 1; x < date->month; x++) {
80 if (x == 2 && isleap(date->year + 1980))
81 total += (29 * (24 * 60 * 60));
82 else
83 total += ((long)monthdays[x - 1] * (24 * 60 * 60));
84 }
85 total += (((long)date->day - 1) * (24 * 60 * 60));
86 total += ((long)time->hours * (60 * 60));
87 total += ((long)time->minutes * 60);
88 total += ((long)time->twosecs * 2);
89 return total;
90}
91
92/*
93 * this function originally from C_ECHO's Snippets -- modified
94 * brute force methodology
95 */
96
97static BOOL m_match(CHAR * string, CHAR * pattern, BOOL absolute, BOOL ignore,
98 LONG len)
99{
100 // return TRUE if pattern found in string
101 register CHAR *tn = pattern;
102 register LONG len2 = 0;
103 LONG lastlen = 0;
104 CHAR lo, hi;
105
106 if (len && string && pattern) {
107 if (absolute) // no pattern matching
108 return (findstring(pattern, strlen(pattern), string, len,
109 (ignore == FALSE)) != NULL);
110
111 while (*tn && len2 < len) {
112 switch (*tn) {
113 case ' ':
114 while (*tn == ' ')
115 tn++;
116 while (len2 < len && isspace(string[len2]))
117 len2++;
118 break;
119
120 case '*':
121 while (*tn == '*' || *tn == '?')
122 tn++;
123 if (!*tn)
124 return TRUE;
125 if (ignore) {
126 while (len2 < len && string[len2] != *tn)
127 len2++;
128 }
129 else {
130 while (len2 < len && toupper(string[len2] != *tn))
131 len2++;
132 }
133 break;
134
135 case '[':
136 tn++;
137 if (!*tn)
138 return FALSE;
139 lo = *tn;
140 tn++;
141 if (*tn != '-')
142 return FALSE;
143 tn++;
144 if (!*tn)
145 return FALSE;
146 hi = *tn;
147 tn++;
148 if (*tn != ']')
149 return FALSE;
150 tn++;
151 if (ignore) {
152 if ((toupper(string[len2]) >= toupper(lo)) &&
153 (toupper(string[len2]) <= toupper(hi)))
154 len2++;
155 else {
156 tn = pattern;
157 len2 = lastlen = lastlen + 1;
158 }
159 }
160 else {
161 if ((string[len2] >= lo) && (string[len2] <= hi))
162 len2++;
163 else {
164 tn = pattern;
165 len2 = lastlen = lastlen + 1;
166 }
167 }
168 break;
169
170 case '?':
171 tn++;
172 len2++;
173 break;
174
175 case '\\':
176 tn++;
177 if (!*tn)
178 return FALSE;
179 // else intentional fallthru
180 default:
181 if (ignore) {
182 if (toupper(*tn) == toupper(string[len2])) {
183 tn++;
184 len2++;
185 }
186 else {
187 tn = pattern;
188 len2 = lastlen = lastlen + 1;
189 }
190 }
191 else {
192 if (*tn == string[len2]) {
193 tn++;
194 len2++;
195 }
196 else {
197 tn = pattern;
198 len2 = lastlen = lastlen + 1;
199 }
200 }
201 break;
202 }
203 }
204 while (*tn == '*')
205 tn++;
206
207 if (!*tn)
208 return TRUE;
209 }
210 return FALSE;
211}
212
213static BOOL match(CHAR * string, CHAR * patterns, BOOL absolute, BOOL ignore,
214 LONG len, ULONG numlines, CHAR * matched, BOOL matchall)
215{
216 BOOL ret = FALSE;
217 register CHAR *p;
218 register ULONG x = 0;
219
220 p = patterns;
221 while (!ret && *p) {
222 ret = m_match(string, p, absolute, ignore, len);
223 if (matchall && ret)
224 break;
225 if (matched && ret && x < numlines)
226 matched[x] = 1;
227 p += strlen(p); // check each pattern in 0-terminated list
228 p++;
229 x++;
230 }
231 return ret;
232}
233
234VOID GrepThread(VOID * arg)
235{
236 HAB ghab;
237 HMQ ghmq;
238 GREP grep;
239 register INT x, numfls;
240 static CHAR *fle[512];
241 CHAR *p, *pp, searchPath[CCHMAXPATH * 2];
242
243 if (!arg) {
244 Runtime_Error(pszSrcFile, __LINE__, "no data");
245 return;
246 }
247
248 grep = *(GREP *)arg;
249 *grep.stopflag = 0; // reset thread-killing flag
250 DosError(FERR_DISABLEHARDERR);
251 priority_normal();
252
253 ghab = WinInitialize(0);
254 if (ghab) {
255 grep.ghab = ghab;
256 ghmq = WinCreateMsgQueue(ghab, 0);
257 if (ghmq) {
258 WinCancelShutdown(ghmq, TRUE);
259 IncrThreadUsage();
260 DosSleep(100); //05 Aug 07 GKY 128
261 WinSetWindowText(grep.hwndCurFile,
262 GetPString((grep.finddupes) ?
263 IDS_GREPDUPETEXT : IDS_GREPSCANTEXT));
264
265 pp = grep.searchPattern;
266 while (*pp) {
267 if (!grep.absFlag) {
268 p = GREPCHARS; // see if any sense in pattern matching
269 while (*p) {
270 if (strchr(pp, *p))
271 break;
272 p++;
273 }
274 if (!*p) // nope, turn it off
275 grep.absFlag = TRUE;
276 }
277 pp = pp + strlen(pp) + 1;
278 }
279
280 grep.attrFile &= (~FILE_DIRECTORY);
281 grep.antiattr &= (~FILE_DIRECTORY);
282 if (grep.antiattr & FILE_READONLY)
283 grep.antiattr |= MUST_HAVE_READONLY;
284 if (grep.antiattr & FILE_HIDDEN)
285 grep.antiattr |= MUST_HAVE_HIDDEN;
286 if (grep.antiattr & FILE_SYSTEM)
287 grep.antiattr |= MUST_HAVE_SYSTEM;
288 if (grep.antiattr & FILE_ARCHIVED)
289 grep.antiattr |= MUST_HAVE_ARCHIVED;
290
291 grep.anyexcludes = FALSE;
292 numfls = x = 0;
293 fle[numfls++] = strtok(grep.tosearch, ";");
294 while ((fle[numfls] = strtok(NULL, ";")) != NULL && numfls < 511) {
295 if (*fle[numfls] == '/')
296 grep.anyexcludes = TRUE;
297 numfls++;
298 }
299
300 while (x < numfls) { // loop through search masks
301
302 if (*fle[x] == '/') // is an exclude mask only
303 goto ExcludeSkip;
304
305 // first, separate any path from mask
306
307 p = (char *)(fle[x] + (strlen(fle[x]) - 1));
308 while (*p != '\\' && *p != ':' && p != fle[x])
309 --p;
310
311 if (p == fle[x]) { // no path
312 strcpy(searchPath, grep.curdir);
313 strncpy(grep.fileMask, fle[x], CCHMAXPATH);
314 grep.fileMask[CCHMAXPATH - 1] = 0;
315 }
316 else { // got to deal with a path
317 if (*p == ':') { // just a drive, start in root dir
318 *p = 0;
319 p++;
320 strncpy(searchPath, fle[x], CCHMAXPATH - 2);
321 searchPath[CCHMAXPATH - 3] = 0;
322 strcat(searchPath, ":\\");
323 strcpy(grep.fileMask, p);
324 }
325 if (*p == '\\') { // got a 'full' path
326
327 CHAR temp;
328
329 p++;
330 temp = *p;
331 *p = 0;
332 strncpy(searchPath, fle[x], CCHMAXPATH);
333 searchPath[CCHMAXPATH - 1] = 0;
334 *p = temp;
335 strcpy(grep.fileMask, p);
336 }
337 if (!*grep.fileMask)
338 strcpy(grep.fileMask, "*");
339 }
340 if (*grep.stopflag)
341 break;
342 // do single directory
343 domatchingfiles(&grep, searchPath, fle, numfls);
344 if (grep.dirFlag) // do subdirs
345 doallsubdirs(&grep, searchPath, FALSE, fle, numfls);
346 ExcludeSkip:
347 if (*grep.stopflag)
348 break;
349 x++;
350 if (WinIsWindow(grep.ghab, grep.hwndFiles))
351 doinsertion(&grep); // insert any remaining objects
352 } // while
353
354 if (WinIsWindow(grep.ghab, grep.hwndFiles))
355 doinsertion(&grep); // insert any remaining objects
356
357 if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes &&
358 !*grep.stopflag)
359 FillDupes(&grep);
360
361 if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID)) // tell window we're done
362 WinSendMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
363 WinDestroyMsgQueue(ghmq);
364 }
365 DecrThreadUsage();
366 WinTerminate(ghab);
367 }
368 if (!ghmq || !ghab)
369 WinPostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
370 if (grep.dupehead)
371 FreeDupes(&grep);
372 if (grep.numlines && grep.matched)
373 free(grep.matched);
374 DosPostEventSem(CompactSem);
375}
376
377static BOOL IsExcluded(char *name, char **fle, int numfls)
378{
379 int x;
380 char *n;
381
382 n = strrchr(name, '\\');
383 if (!n)
384 n = strrchr(name, ':');
385 if (n)
386 n++;
387 else
388 n = name;
389 for (x = 0; x < numfls; x++) {
390 if (*fle[x] == '/' &&
391 wildcard((strchr(fle[x], '\\') ||
392 strchr(fle[x], ':')) ? name : n, fle[x] + 1, FALSE))
393 return TRUE;
394 }
395 return FALSE;
396}
397
398static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing,
399 char **fle, int numfls)
400{
401 // process all subdirectories
402
403 FILEFINDBUF4 ffb;
404 HDIR findHandle = HDIR_CREATE;
405 LONG ulFindCnt = 1;
406 CHAR *p = NULL;
407
408 // add a mask to search path
409 if (searchPath[strlen(searchPath) - 1] != '\\')
410 strcat(searchPath, "\\");
411 strcat(searchPath, "*");
412 // step through all subdirectories
413 DosError(FERR_DISABLEHARDERR);
414 if (!DosFindFirst(searchPath, &findHandle, (MUST_HAVE_DIRECTORY |
415 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY),
416 &ffb, (ULONG) sizeof(ffb),
417 (PULONG) & ulFindCnt, FIL_QUERYEASIZE)) {
418
419 // get rid of mask portion, save end-of-directory
420
421 p = strrchr(searchPath, '\\');
422 if (p)
423 p++;
424 else
425 p = searchPath;
426 do { // Process each directory that matches the mask
427 priority_normal();
428 if (*grep->stopflag)
429 break;
430 // Skip . and ..
431 if (ffb.achName[0] != '.' ||
432 (ffb.achName[1] &&
433 (ffb.achName[1] != '.' || ffb.achName[2]))) {
434 strcpy(p, ffb.achName);
435 if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) {
436 domatchingfiles(grep, searchPath, fle, numfls);
437 doallsubdirs(grep, searchPath, TRUE, fle, numfls);
438 DosSleep(0); //26 Aug 07 GKY 1
439 }
440 }
441 ulFindCnt = 1;
442 } while (!DosFindNext(findHandle,
443 &ffb,
444 sizeof(ffb), (PULONG) & ulFindCnt));
445 DosFindClose(findHandle);
446 priority_normal();
447 }
448 if (p) // strip off last directory addition
449 *p = 0;
450}
451
452static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls)
453{
454 // process all matching files in a directory
455
456 PFILEFINDBUF4L pffbArray;
457 PFILEFINDBUF4L pffbFile;
458 ULONG x;
459 HDIR findHandle = HDIR_CREATE;
460 ULONG ulFindCnt;
461 CHAR szFindPath[CCHMAXPATH];
462 PSZ p;
463 APIRET rc;
464 // 06 Oct 07 SHL Correct size for xDosFindFirst
465 ULONG ulBufBytes = FilesToGet * sizeof(FILEFINDBUF4L);
466 static BOOL fDone;
467
468 pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
469 if (!pffbArray)
470 return 0;
471
472 // build filemask
473 BldFullPathName(szFindPath, path, grep->fileMask);
474 // sprintf(szFindPath,
475 // "%s%s%s",
476 // path,
477 // (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask);
478
479 MakeFullName(szFindPath);
480
481 // find and save end-of-dir position
482 p = strrchr(szFindPath, '\\');
483 if (p)
484 p++;
485 else
486 p = szFindPath;
487
488 // step through matching files
489 DosError(FERR_DISABLEHARDERR);
490 ulFindCnt = FilesToGet;
491 rc = xDosFindFirst(szFindPath,
492 &findHandle,
493 FILE_NORMAL | grep->attrFile | grep->antiattr,
494 pffbArray,
495 ulBufBytes,
496 &ulFindCnt,
497 FIL_QUERYEASIZEL);
498 if (!rc) {
499 do {
500 // Process each file that matches the mask
501 priority_normal();
502 pffbFile = pffbArray;
503 for (x = 0; x < ulFindCnt; x++) {
504 if (*grep->stopflag)
505 break;
506 if (*pffbFile->achName != '.' ||
507 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
508 strcpy(p, pffbFile->achName); // build filename
509 if (strlen(szFindPath) > CCHMAXPATH){ //21 Sep GKY check for pathnames that exceed maxpath
510 DosFindClose(findHandle);
511 free(pffbArray);
512 if (!fDone) {
513 fDone = TRUE;
514 saymsg(MB_OK | MB_ICONASTERISK,
515 HWND_DESKTOP,
516 GetPString(IDS_WARNINGTEXT),
517 "One or more of your files has a full path name that exceeds the OS/2 maximum");
518 }
519 return 1;
520 }
521 if (!grep->anyexcludes || !IsExcluded(szFindPath, fle, numfls)) {
522 if (!grep->finddupes)
523 doonefile(grep, szFindPath, pffbFile);
524 else if (!InsertDupe(grep, szFindPath, pffbFile)) {
525 DosFindClose(findHandle);
526 free(pffbArray);
527 return 1;
528 }
529 }
530 }
531 if (!pffbFile->oNextEntryOffset)
532 break;
533 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
534 } // for
535 if (*grep->stopflag)
536 break;
537 DosSleep(0); //26 Aug 07 GKY 1
538 ulFindCnt = FilesToGet;
539 rc = xDosFindNext(findHandle, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
540 } while (!rc);
541
542 DosFindClose(findHandle);
543 priority_normal();
544 } // if
545
546 if (rc && rc != ERROR_NO_MORE_FILES) {
547 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
548 GetPString(IDS_CANTFINDDIRTEXT), szFindPath);
549 }
550
551 free(pffbArray);
552 return 0;
553}
554
555static VOID freegreplist(GREP * grep)
556{
557 INT x;
558
559 if (grep) {
560 if (grep->insertffb) {
561 for (x = 0; grep->insertffb[x]; x++)
562 free(grep->insertffb[x]);
563 free(grep->insertffb);
564 }
565 if (grep->dir) {
566 for (x = 0; grep->dir[x]; x++)
567 free(grep->dir[x]);
568 free(grep->dir);
569 }
570 grep->dir = NULL;
571 grep->insertffb = NULL;
572 grep->toinsert = 0L;
573 grep->insertedbytes = 0L;
574 }
575}
576
577static BOOL doinsertion(GREP * grep)
578{
579 RECORDINSERT ri;
580 DIRCNRDATA *dcd;
581 PCNRITEM pci, pciFirst;
582 INT x;
583
584 if (!grep || !grep->toinsert || !grep->insertffb || !grep->dir)
585 return FALSE;
586 pci = WinSendMsg(grep->hwndFiles,
587 CM_ALLOCRECORD,
588 MPFROMLONG(EXTRA_RECORD_BYTES),
589 MPFROMLONG(grep->toinsert));
590 if (pci) {
591 if (grep->sayfiles)
592 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT));
593 pciFirst = pci;
594 dcd = INSTDATA(grep->hwndFiles);
595 for (x = 0; grep->insertffb[x]; x++) {
596 FillInRecordFromFFB(grep->hwndFiles,
597 pci, grep->dir[x], grep->insertffb[x], FALSE, dcd);
598 pci = (PCNRITEM) pci->rc.preccNextRecord;
599 }
600 memset(&ri, 0, sizeof(RECORDINSERT));
601 ri.cb = sizeof(RECORDINSERT);
602 ri.pRecordOrder = (PRECORDCORE) CMA_END;
603 ri.pRecordParent = (PRECORDCORE) NULL;
604 ri.zOrder = (USHORT) CMA_TOP;
605 ri.cRecordsInsert = grep->toinsert;
606 ri.fInvalidateRecord = TRUE;
607 WinSendMsg(grep->hwndFiles,
608 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri));
609 if (dcd) {
610 DosEnterCritSec();
611 dcd->ullTotalBytes += grep->insertedbytes;
612 DosExitCritSec();
613 }
614 if (grep->toinsert == FilesToGet)
615 DosSleep(0); //26 Aug 07 GKY 1
616 freegreplist(grep);
617 PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID);
618 return TRUE;
619 }
620 freegreplist(grep);
621 return FALSE;
622}
623
624static BOOL insert_grepfile(GREP *grep, CHAR *filename, PFILEFINDBUF4L pffb)
625{
626 PSZ p;
627 CHAR szDirectory[CCHMAXPATH];
628
629 if (WinIsWindow(grep->ghab, grep->hwndFiles)) {
630 grep->numfiles++;
631 strcpy(szDirectory, filename);
632 p = strrchr(szDirectory, '\\');
633 if (p) {
634 if (p < szDirectory + 4)
635 p++;
636 *p = 0;
637 if (!grep->insertffb) {
638 // Allocate 1 extra for end marker?
639 grep->insertffb = xmallocz(sizeof(PFILEFINDBUF4L) * (FilesToGet + 1),
640 pszSrcFile, __LINE__);
641 if (!grep->insertffb)
642 return FALSE;
643 grep->dir = xmallocz(sizeof(CHAR *) * (FilesToGet + 1),
644 pszSrcFile, __LINE__);
645 if (!grep->dir) {
646 free(grep->insertffb);
647 return FALSE;
648 }
649 }
650 grep->insertffb[grep->toinsert] =
651 xmalloc(sizeof(FILEFINDBUF4L), pszSrcFile, __LINE__);
652 if (!grep->insertffb[grep->toinsert])
653 return FALSE;
654 memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4L));
655 grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__);
656 if (!grep->dir) {
657 free(grep->insertffb[grep->toinsert]);
658 return FALSE;
659 }
660 grep->insertedbytes += pffb->cbFile + CBLIST_TO_EASIZE(pffb->cbList);
661 grep->toinsert++;
662 if (grep->toinsert == FilesToGet)
663 return doinsertion(grep);
664 return TRUE;
665 }
666 }
667 else
668 freegreplist(grep);
669 return FALSE;
670}
671
672static BOOL doonefile(GREP *grep, CHAR *filename, FILEFINDBUF4L * pffb)
673{
674 // process a single file
675 CHAR *input;
676 FILE *inputFile;
677 ULONG pos;
678 BOOL ret = FALSE, strmatch = FALSE;
679
680 grep->fileCount++;
681 if (grep->sayfiles)
682 WinSetWindowText(grep->hwndCurFile, filename);
683
684 if (grep->greaterthan || grep->lessthan) {
685
686 BOOL keep = TRUE;
687 ULONG adjsize;
688
689 adjsize = pffb->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(pffb->cbList) : 0);
690 if (grep->greaterthan) {
691 if (adjsize < grep->greaterthan)
692 keep = FALSE;
693 }
694 if (keep && grep->lessthan) {
695 if (adjsize > grep->lessthan)
696 keep = FALSE;
697 }
698 if (!keep)
699 return ret;
700 }
701
702 if (grep->newerthan || grep->olderthan) {
703
704 BOOL keep = TRUE;
705 ULONG numsecs;
706
707 numsecs = SecsSince1980(&pffb->fdateLastWrite, &pffb->ftimeLastWrite);
708 if (grep->newerthan) {
709 if (numsecs < grep->newerthan)
710 keep = FALSE;
711 }
712 if (keep && grep->olderthan) {
713 if (numsecs > grep->olderthan)
714 keep = FALSE;
715 }
716 if (!keep)
717 return ret;
718 }
719
720 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) // just a find
721 return insert_grepfile(grep, filename, pffb);
722
723 if (grep->searchEAs) {
724
725 HOLDFEA *head, *info;
726 USHORT type, len;
727 BOOL alltext;
728 CHAR *data, temp;
729
730 head = GetFileEAs(filename, FALSE, TRUE);
731 if (head) {
732 info = head;
733 while (info && !strmatch) {
734 alltext = TRUE;
735 switch (*(USHORT *) info->value) {
736 case EAT_ASCII:
737 if (match(info->value + (sizeof(USHORT) * 2),
738 grep->searchPattern, grep->absFlag,
739 (grep->caseFlag == FALSE),
740 info->cbValue - (sizeof(USHORT) * 2),
741 grep->numlines, grep->matched, !grep->findifany)) {
742 strmatch = TRUE;
743 }
744 break;
745 case EAT_MVST:
746 type = *(USHORT *) (info->value + (sizeof(USHORT) * 3));
747 if (type == EAT_ASCII) {
748 data = info->value + (sizeof(USHORT) * 4);
749 len = *(USHORT *) data;
750 data += sizeof(USHORT);
751 while ((data - info->value) + len <= info->cbValue) {
752 temp = *(data + len);
753 *(data + len) = 0;
754 if (match(data,
755 grep->searchPattern,
756 grep->absFlag,
757 (grep->caseFlag == FALSE),
758 len,
759 grep->numlines, grep->matched, !grep->findifany)) {
760 strmatch = TRUE;
761 break;
762 }
763 data += len;
764 if (data - info->value >= info->cbValue)
765 break;
766 *data = temp;
767 len = *(USHORT *) data;
768 data += sizeof(USHORT);
769 }
770 }
771 break;
772 case EAT_MVMT:
773 data = info->value + (sizeof(USHORT) * 3);
774 type = *(USHORT *) data;
775 data += sizeof(USHORT);
776 len = *(USHORT *) data;
777 data += sizeof(USHORT);
778 while ((data - info->value) - len <= info->cbValue) {
779 if (type != EAT_ASCII) {
780 alltext = FALSE;
781 break;
782 }
783 data += len;
784 if (data - info->value >= info->cbValue)
785 break;
786 type = *(USHORT *) data;
787 data += sizeof(USHORT);
788 len = *(USHORT *) data;
789 data += sizeof(USHORT);
790 }
791 if (alltext) {
792 data = info->value + (sizeof(USHORT) * 3);
793 type = *(USHORT *) data;
794 data += sizeof(USHORT);
795 len = *(USHORT *) data;
796 data += sizeof(USHORT);
797 while ((data - info->value) - len <= info->cbValue) {
798 temp = *(data + len);
799 *(data + len) = 0;
800 if (match(data,
801 grep->searchPattern,
802 grep->absFlag,
803 (grep->caseFlag == FALSE),
804 len,
805 grep->numlines, grep->matched, !grep->findifany)) {
806 strmatch = TRUE;
807 break;
808 }
809 data += len;
810 *data = temp;
811 if (data - info->value >= info->cbValue)
812 break;
813 type = *(USHORT *) data;
814 data += sizeof(USHORT);
815 len = *(USHORT *) data;
816 data += sizeof(USHORT);
817 }
818 }
819 break;
820 default:
821 break;
822 }
823 info = info->next;
824 } // while
825 Free_FEAList(head);
826 DosSleep(1);
827 }
828 }
829
830 if (grep->searchFiles) {
831 input = xmalloc(65537, pszSrcFile, __LINE__);
832 if (input) {
833 LONG len;
834
835 inputFile = _fsopen(filename, "rb", SH_DENYNO);
836 if (inputFile) {
837 pos = ftell(inputFile);
838 while (!feof(inputFile)) {
839 if (pos)
840 fseek(inputFile, pos - 1024, SEEK_SET);
841 len = fread(input, 1, 65536, inputFile);
842 if (len >= 0) {
843 if (*grep->stopflag)
844 break;
845 if (match(input,
846 grep->searchPattern,
847 grep->absFlag,
848 (grep->caseFlag == FALSE),
849 len, grep->numlines, grep->matched, !grep->findifany)) {
850 strmatch = TRUE;
851 break;
852 }
853 }
854 else
855 break;
856 }
857 fclose(inputFile);
858 }
859 free(input);
860 DosSleep(1);
861 }
862 } // if
863
864 if (strmatch)
865 ret = insert_grepfile(grep, filename, pffb);
866 return ret;
867}
868
869static LONG cr3tab[] = { // CRC polynomial 0xEDB88320
870
871 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
872 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
873 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
874 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
875 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
876 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
877 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
878 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
879 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
880 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
881 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
882 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
883 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
884 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
885 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
886 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
887 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
888 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
889 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
890 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
891 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
892 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
893 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
894 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
895 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
896 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
897 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
898 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
899 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
900 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
901 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
902 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
903 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
904 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
905 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
906 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
907 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
908 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
909 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
910 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
911 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
912 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
913 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
914 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
915 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
916 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
917 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
918 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
919 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
920 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
921 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
922 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
923 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
924 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
925 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
926 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
927 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
928 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
929 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
930 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
931 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
932 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
933 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
934 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
935};
936
937LONG CRCBlock(register CHAR * str, register INT blklen, register LONG crc)
938{
939 while (blklen--) {
940 crc =
941 cr3tab[((INT) crc ^ *str) & 0xff] ^ (((ULONG) crc >> 8) & 0x00FFFFFF);
942 str++;
943 }
944 return crc;
945}
946
947LONG CRCFile(CHAR * filename, INT * error)
948{
949 LONG CRC = -1L, len;
950 FILE *fp;
951 CHAR *buffer;
952
953 *error = 0;
954 buffer = xmalloc(65535, pszSrcFile, __LINE__);
955 if (!buffer)
956 *error = -1;
957 else {
958 fp = _fsopen(filename, "rb", SH_DENYNO);
959 if (!fp)
960 *error = -2;
961 else {
962 while (!feof(fp)) {
963 len = fread(buffer, 1, 65535, fp);
964 if (len && len < 65536L)
965 CRC = CRCBlock(buffer, len, CRC);
966 else
967 break;
968 DosSleep(0); //26 Aug 07 GKY 1
969 }
970 fclose(fp);
971 DosSleep(1);
972 }
973 free(buffer);
974 }
975 return CRC;
976}
977
978static VOID FreeDupes(GREP *grep)
979{
980 DUPES *i, *next;
981
982 i = grep->dupehead;
983 while (i) {
984 next = i->next;
985 if (i->name)
986 free(i->name);
987 free(i);
988 i = next;
989 }
990 grep->dupehead = grep->dupelast = NULL;
991 if (grep->dupenames)
992 free(grep->dupenames);
993 if (grep->dupesizes)
994 free(grep->dupesizes);
995 grep->dupesizes = grep->dupenames = NULL;
996}
997
998int comparenamesq(const void *v1, const void *v2)
999{
1000 DUPES *d1 = *(DUPES **) v1;
1001 DUPES *d2 = *(DUPES **) v2;
1002 CHAR *p1, *p2;
1003
1004 p1 = strrchr(d1->name, '\\');
1005 if (p1)
1006 p1++;
1007 else
1008 p1 = d1->name;
1009 p2 = strrchr(d2->name, '\\');
1010 if (p2)
1011 p2++;
1012 else
1013 p2 = d2->name;
1014 return stricmp(p1, p2);
1015}
1016
1017int comparenamesqe(const void *v1, const void *v2)
1018{
1019 DUPES *d1 = *(DUPES **) v1;
1020 DUPES *d2 = *(DUPES **) v2;
1021 CHAR *p1, *p2, *p1e, *p2e, e1, e2;
1022 int ret;
1023
1024 p1 = strrchr(d1->name, '\\');
1025 if (p1)
1026 p1++;
1027 else
1028 p1 = d1->name;
1029 p1e = strrchr(p1, '.');
1030 if (p1e) {
1031 e1 = *p1e;
1032 *p1e = 0;
1033 }
1034 p2 = strrchr(d2->name, '\\');
1035 if (p2)
1036 p2++;
1037 else
1038 p2 = d2->name;
1039 p2e = strrchr(p2, '.');
1040 if (p2e) {
1041 e2 = *p2e;
1042 *p2e = 0;
1043 }
1044 ret = stricmp(p1, p2);
1045 if (p1e)
1046 *p1e = e1;
1047 if (p2e)
1048 *p2e = e2;
1049 return ret;
1050}
1051
1052int comparesizesq(const void *v1, const void *v2)
1053{
1054 DUPES *d1 = *(DUPES **) v1;
1055 DUPES *d2 = *(DUPES **) v2;
1056
1057 return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
1058}
1059
1060int comparenamesb(const void *v1, const void *v2)
1061{
1062 DUPES *d1 = (DUPES *) v1;
1063 DUPES *d2 = *(DUPES **) v2;
1064 CHAR *p1, *p2;
1065
1066 p1 = strrchr(d1->name, '\\');
1067 if (p1)
1068 p1++;
1069 else
1070 p1 = d1->name;
1071 p2 = strrchr(d2->name, '\\');
1072 if (p2)
1073 p2++;
1074 else
1075 p2 = d2->name;
1076 return stricmp(p1, p2);
1077}
1078
1079int comparenamesbe(const void *v1, const void *v2)
1080{
1081 DUPES *d1 = (DUPES *) v1;
1082 DUPES *d2 = *(DUPES **) v2;
1083 CHAR *p1, *p2, *p1e, *p2e, e1, e2;
1084 int ret;
1085
1086 p1 = strrchr(d1->name, '\\');
1087 if (p1)
1088 p1++;
1089 else
1090 p1 = d1->name;
1091 p1e = strrchr(p1, '.');
1092 if (p1e) {
1093 e1 = *p1e;
1094 *p1e = 0;
1095 }
1096 p2 = strrchr(d2->name, '\\');
1097 if (p2)
1098 p2++;
1099 else
1100 p2 = d2->name;
1101 p2e = strrchr(p2, '.');
1102 if (p2e) {
1103 e2 = *p2e;
1104 *p2e = 0;
1105 }
1106 ret = stricmp(p1, p2);
1107 if (p1e)
1108 *p1e = e1;
1109 if (p2e)
1110 *p2e = e2;
1111 return ret;
1112}
1113
1114int comparesizesb(const void *v1, const void *v2)
1115{
1116 DUPES *d1 = (DUPES *) v1;
1117 DUPES *d2 = *(DUPES **) v2;
1118
1119 return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
1120}
1121
1122static VOID FillDupes(GREP * grep)
1123{
1124 DUPES *c, *i, **r;
1125 register CHAR *pc, *pi;
1126 CHAR **list = NULL;
1127 INT numfiles = 0, numalloced = 0, error;
1128 register ULONG x = 0, y = 0;
1129 ULONG cntr = 1000;
1130
1131 if (grep->CRCdupes)
1132 cntr = 100;
1133 i = grep->dupehead;
1134 while (i) {
1135 x++;
1136 i = i->next;
1137 }
1138 if (x) {
1139 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
1140 DosSleep(0); //26 Aug 07 GKY 1
1141 grep->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
1142 if (!grep->nosizedupes)
1143 grep->dupesizes = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
1144 if (grep->dupenames && (grep->nosizedupes || grep->dupesizes)) {
1145 i = grep->dupehead;
1146 while (i) {
1147 grep->dupenames[y] = i;
1148 if (!grep->nosizedupes)
1149 grep->dupesizes[y] = i;
1150 i = i->next;
1151 y++;
1152 }
1153 grep->dupenames[y] = NULL;
1154 if (!grep->nosizedupes)
1155 grep->dupesizes[y] = NULL;
1156 DosSleep(0); //26 Aug 07 GKY 1
1157 qsort(grep->dupenames,
1158 x,
1159 sizeof(DUPES *),
1160 ((grep->ignoreextdupes) ? comparenamesqe : comparenamesq));
1161 DosSleep(0); //26 Aug 07 GKY 1
1162 if (!grep->nosizedupes) {
1163 qsort(grep->dupesizes, x, sizeof(DUPES *), comparesizesq);
1164 DosSleep(0); //26 Aug 07 GKY 1
1165 }
1166 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
1167
1168 i = grep->dupehead;
1169 y = 0;
1170 while (i) {
1171 if (*grep->stopflag)
1172 break;
1173 if (!(i->flags & GF_SKIPME)) {
1174 r = (DUPES **) bsearch(i, grep->dupenames, x, sizeof(DUPES *),
1175 ((grep->ignoreextdupes) ? comparenamesbe :
1176 comparenamesb));
1177 if (r) {
1178 while (r > grep->dupenames && ((grep->ignoreextdupes) ?
1179 !comparenamesqe((r - 1), &i) :
1180 !comparenamesq((r - 1), &i)))
1181 r--;
1182 while (*r && ((grep->ignoreextdupes) ?
1183 !comparenamesqe(r, &i) : !comparenamesq(r, &i))) {
1184 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) {
1185 r++;
1186 continue;
1187 }
1188 if (grep->CRCdupes) {
1189 if ((*r)->CRC == -1L) {
1190 (*r)->CRC = CRCFile((*r)->name, &error);
1191 if (error)
1192 (*r)->CRC = -1L;
1193 else if ((*r)->CRC == -1L)
1194 (*r)->CRC = 0L;
1195 }
1196 if (i->CRC == -1L) {
1197 i->CRC = CRCFile(i->name, &error);
1198 if (error)
1199 i->CRC = -1L;
1200 else if (i->CRC == -1L)
1201 i->CRC = 0L;
1202 }
1203 if (((*r)->size != i->size) || ((*r)->CRC != -1L &&
1204 i->CRC != -1L
1205 && (*r)->CRC != i->CRC)) {
1206 r++;
1207 continue;
1208 }
1209 }
1210 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
1211 (*r)->flags |= GF_INSERTED;
1212 if (grep->sayfiles)
1213 WinSetWindowText(grep->hwndFiles, (*r)->name);
1214 if ((*r)->size == i->size &&
1215 (i->date.year == (*r)->date.year &&
1216 i->date.month == (*r)->date.month &&
1217 i->date.day == (*r)->date.day &&
1218 i->time.hours == (*r)->time.hours &&
1219 i->time.minutes == (*r)->time.minutes &&
1220 i->time.twosecs == (*r)->time.twosecs))
1221 (*r)->flags |= GF_SKIPME;
1222 }
1223 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
1224 if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
1225 i->flags |= GF_INSERTED;
1226 if ((*r)->flags & GF_SKIPME)
1227 i->flags |= GF_SKIPME;
1228 }
1229 }
1230 r++;
1231 }
1232 }
1233 if (!grep->nosizedupes) {
1234 r = (DUPES **) bsearch(i,
1235 grep->dupesizes,
1236 x, sizeof(DUPES *), comparesizesb);
1237 if (r) {
1238 while (r > grep->dupesizes && !comparesizesq((r - 1), &i))
1239 r--;
1240 while (*r && !comparesizesq(r, &i)) {
1241 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME)) ||
1242 (i->date.year != (*r)->date.year ||
1243 i->date.month != (*r)->date.month ||
1244 i->date.day != (*r)->date.day ||
1245 i->time.hours != (*r)->time.hours ||
1246 i->time.minutes != (*r)->time.minutes ||
1247 i->time.twosecs != (*r)->time.twosecs)) {
1248 r++;
1249 continue;
1250 }
1251 if (grep->CRCdupes) {
1252 if ((*r)->CRC == -1L) {
1253 (*r)->CRC = CRCFile((*r)->name, &error);
1254 if (error)
1255 (*r)->CRC = -1L;
1256 else if ((*r)->CRC == -1L)
1257 (*r)->CRC = 0L;
1258 }
1259 if (i->CRC == -1L) {
1260 i->CRC = CRCFile(i->name, &error);
1261 if (error)
1262 i->CRC = -1L;
1263 else if (i->CRC == -1L)
1264 i->CRC = 0L;
1265 }
1266 if ((*r)->CRC != -1L && i->CRC != -1L &&
1267 (*r)->CRC != i->CRC) {
1268 *r += 1;
1269 continue;
1270 }
1271 }
1272 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
1273 if (grep->sayfiles)
1274 WinSetWindowText(grep->hwndCurFile, (*r)->name);
1275 (*r)->flags |= GF_INSERTED;
1276 if (((grep->ignoreextdupes) ?
1277 comparenamesqe(r, &i) : comparenamesq(r, &i)))
1278 (*r)->flags |= GF_SKIPME;
1279 }
1280 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
1281 if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
1282 i->flags |= GF_INSERTED;
1283 if ((*r)->flags & GF_SKIPME)
1284 i->flags |= GF_SKIPME;
1285 }
1286 }
1287 r++;
1288 }
1289 }
1290 }
1291 }
1292 i = i->next;
1293 y++;
1294 if (!(y % cntr)) {
1295
1296 CHAR s[44];
1297
1298 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
1299 WinSetWindowText(grep->hwndCurFile, s);
1300 DosSleep(1); //05 Aug 07 GKY 128
1301 }
1302 DosSleep(0); //26 Aug 07 GKY 1
1303 }
1304 }
1305 else {
1306 // Insufficient memory - fall back
1307 DosBeep(50, 100);
1308 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
1309 x = y = 0;
1310 if (grep->dupenames) {
1311 free(grep->dupenames);
1312 grep->dupenames = NULL;
1313 }
1314 if (grep->dupesizes) {
1315 free(grep->dupesizes);
1316 grep->dupesizes = NULL;
1317 }
1318 i = grep->dupehead;
1319 while (i) {
1320 if (*grep->stopflag)
1321 break;
1322 if (!(i->flags & GF_SKIPME)) {
1323 if (!(y % cntr)) {
1324
1325 CHAR s[44];
1326
1327 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
1328 WinSetWindowText(grep->hwndCurFile, s);
1329 DosSleep(0); //26 Aug 07 GKY 1
1330 }
1331 y++;
1332 pi = strrchr(i->name, '\\');
1333 if (pi)
1334 pi++;
1335 else
1336 pi = i->name;
1337 c = grep->dupehead;
1338 while (c) {
1339 if (*grep->stopflag)
1340 break;
1341 if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
1342 x++;
1343 pc = strrchr(c->name, '\\');
1344 if (pc)
1345 pc++;
1346 else
1347 pc = c->name;
1348 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
1349 if (grep->CRCdupes) {
1350 if (grep->CRCdupes) {
1351 if (c->CRC == -1L) {
1352 c->CRC = CRCFile(c->name, &error);
1353 if (error)
1354 c->CRC = -1L;
1355 else if (c->CRC == -1L)
1356 c->CRC = 0L;
1357 }
1358 if (i->CRC == -1L) {
1359 i->CRC = CRCFile(i->name, &error);
1360 if (error)
1361 i->CRC = -1L;
1362 else if (i->CRC == -1L)
1363 i->CRC = 0L;
1364 }
1365 if ((c->size != i->size) || (c->CRC != -1L &&
1366 i->CRC != -1L
1367 && c->CRC != i->CRC)) {
1368 c = c->next;
1369 continue;
1370 }
1371 }
1372 }
1373 if (AddToList(c->name, &list, &numfiles, &numalloced))
1374 goto BreakOut; // Failed
1375 if (!(i->flags & GF_INSERTED)) {
1376 if (AddToList(i->name, &list, &numfiles, &numalloced))
1377 goto BreakOut; // Failed
1378 }
1379 if (grep->sayfiles)
1380 WinSetWindowText(grep->hwndCurFile, pc);
1381 c->flags |= GF_INSERTED;
1382 i->flags |= GF_INSERTED;
1383 if (!stricmp(pc, pi)) {
1384 c->flags |= GF_SKIPME;
1385 i->flags |= GF_SKIPME;
1386 }
1387 }
1388 else if (!(x % 100))
1389 DosSleep(0); //26 Aug 07 GKY 1
1390 }
1391 c = c->next;
1392 }
1393 }
1394 i = i->next;
1395 }
1396 }
1397 }
1398BreakOut:
1399 FreeDupes(grep);
1400 if (numfiles && list) {
1401 if (!PostMsg(grep->hwndFiles,
1402 WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
1403 FreeList(list);
1404 }
1405 else
1406 DosPostEventSem(CompactSem);
1407}
1408
1409static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4L *pffb)
1410{
1411 DUPES *info;
1412
1413 if (*dir) {
1414 info = xmallocz(sizeof(DUPES), pszSrcFile, __LINE__);
1415 if (!info)
1416 return FALSE;
1417
1418 info->name = xstrdup(dir, pszSrcFile, __LINE__);
1419 if (!info->name) {
1420 free(info);
1421 return FALSE;
1422 }
1423
1424 info->size = pffb->cbFile;
1425 info->date = pffb->fdateLastWrite;
1426 info->time = pffb->ftimeLastWrite;
1427 info->CRC = -1L;
1428 grep->numfiles++;
1429 if (!grep->dupehead)
1430 grep->dupehead = info;
1431 if (grep->dupelast)
1432 grep->dupelast->next = info;
1433 grep->dupelast = info;
1434 info->next = NULL;
1435 }
1436 return TRUE;
1437}
1438
1439#pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
1440#pragma alloc_text(GREP,SecsSince1980,match,mmatch,GrepThread)
1441#pragma alloc_text(GREP,doallsubdirs,domatchingfiles,InsertDupes,FreeDupes)
1442
1443#pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock)
1444#pragma alloc_text(DUPES,comparenamesq,comparenamesqe,comparenamesb)
1445#pragma alloc_text(DUPES,comparenamesbe,comparesizesq,comparesizesb)
Note: See TracBrowser for help on using the repository browser.