source: trunk/dll/grep.c@ 839

Last change on this file since 839 was 839, checked in by Gregg Young, 18 years ago

Added once per session error message for files whos full path name exceed max path length

  • 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 839 2007-09-21 20:01:38Z gyoung $
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, FILEFINDBUF4 *pffb);
56static BOOL doinsertion(GREP *grep);
57static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4 *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 = 0L;
71 register int x;
72
73 for (x = 1980; x < date->year + 1980; x++) {
74 if (isleap(x))
75 total += (366L * (24L * 60L * 60L));
76 else
77 total += (365L * (24L * 60L * 60L));
78 }
79 for (x = 1; x < date->month; x++) {
80 if (x == 2 && isleap(date->year + 1980))
81 total += (29L * (24L * 60L * 60L));
82 else
83 total += ((long)monthdays[x - 1] * (24L * 60L * 60L));
84 }
85 total += (((long)date->day - 1L) * (24L * 60L * 60L));
86 total += ((long)time->hours * (60L * 60L));
87 total += ((long)time->minutes * 60L);
88 total += ((long)time->twosecs * 2L);
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 (!xDosFindFirst(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 (!xDosFindNext(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 PFILEFINDBUF4 pffbArray;
457 PFILEFINDBUF4 pffbFile;
458 ULONG x;
459 HDIR findHandle = HDIR_CREATE;
460 ULONG ulFindCnt;
461 CHAR szFindPath[CCHMAXPATH];
462 PSZ p;
463 APIRET rc;
464 ULONG ulBufBytes = FilesToGet * sizeof(FILEFINDBUF4);
465 static BOOL fDone;
466
467 pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
468 if (!pffbArray)
469 return 0;
470
471 // build filemask
472 BldFullPathName(szFindPath, path, grep->fileMask);
473 // sprintf(szFindPath,
474 // "%s%s%s",
475 // path,
476 // (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask);
477
478 MakeFullName(szFindPath);
479
480 // find and save end-of-dir position
481 p = strrchr(szFindPath, '\\');
482 if (p)
483 p++;
484 else
485 p = szFindPath;
486
487 // step through matching files
488 DosError(FERR_DISABLEHARDERR);
489 ulFindCnt = FilesToGet;
490 rc = xDosFindFirst(szFindPath,
491 &findHandle,
492 FILE_NORMAL | grep->attrFile | grep->antiattr,
493 pffbArray,
494 ulBufBytes,
495 &ulFindCnt,
496 FIL_QUERYEASIZE);
497 if (!rc) {
498 do {
499 // Process each file that matches the mask
500 priority_normal();
501 pffbFile = pffbArray;
502 for (x = 0; x < ulFindCnt; x++) {
503 if (*grep->stopflag)
504 break;
505 if (*pffbFile->achName != '.' ||
506 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
507 strcpy(p, pffbFile->achName); // build filename
508 if (strlen(szFindPath) > 256){ //21 Sep GKY check for pathnames that exceed maxpath
509 DosFindClose(findHandle);
510 free(pffbArray);
511 if (!fDone) {
512 fDone = TRUE;
513 saymsg(MB_OK | MB_ICONASTERISK,
514 HWND_DESKTOP,
515 GetPString(IDS_WARNINGTEXT),
516 "One or more of your files has a full path name that exceeds the OS/2 maximum");
517 }
518 return 1;
519 }
520 if (!grep->anyexcludes || !IsExcluded(szFindPath, fle, numfls)) {
521 if (!grep->finddupes)
522 doonefile(grep, szFindPath, pffbFile);
523 else if (!InsertDupe(grep, szFindPath, pffbFile)) {
524 DosFindClose(findHandle);
525 free(pffbArray);
526 return 1;
527 }
528 }
529 }
530 if (!pffbFile->oNextEntryOffset)
531 break;
532 pffbFile = (PFILEFINDBUF4)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
533 } // for
534 if (*grep->stopflag)
535 break;
536 DosSleep(0); //26 Aug 07 GKY 1
537 ulFindCnt = FilesToGet;
538 rc = xDosFindNext(findHandle, pffbArray, ulBufBytes, &ulFindCnt);
539 } while (!rc);
540
541 DosFindClose(findHandle);
542 priority_normal();
543 } // if
544
545 if (rc && rc != ERROR_NO_MORE_FILES) {
546 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
547 GetPString(IDS_CANTFINDDIRTEXT), szFindPath);
548 }
549
550 free(pffbArray);
551 return 0;
552}
553
554static VOID freegreplist(GREP * grep)
555{
556 INT x;
557
558 if (grep) {
559 if (grep->insertffb) {
560 for (x = 0; grep->insertffb[x]; x++)
561 free(grep->insertffb[x]);
562 free(grep->insertffb);
563 }
564 if (grep->dir) {
565 for (x = 0; grep->dir[x]; x++)
566 free(grep->dir[x]);
567 free(grep->dir);
568 }
569 grep->dir = NULL;
570 grep->insertffb = NULL;
571 grep->toinsert = 0L;
572 grep->insertedbytes = 0L;
573 }
574}
575
576static BOOL doinsertion(GREP * grep)
577{
578 RECORDINSERT ri;
579 DIRCNRDATA *dcd;
580 PCNRITEM pci, pciFirst;
581 INT x;
582
583 if (!grep || !grep->toinsert || !grep->insertffb || !grep->dir)
584 return FALSE;
585 pci = WinSendMsg(grep->hwndFiles,
586 CM_ALLOCRECORD,
587 MPFROMLONG(EXTRA_RECORD_BYTES),
588 MPFROMLONG(grep->toinsert));
589 if (pci) {
590 if (grep->sayfiles)
591 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT));
592 pciFirst = pci;
593 dcd = INSTDATA(grep->hwndFiles);
594 for (x = 0; grep->insertffb[x]; x++) {
595 FillInRecordFromFFB(grep->hwndFiles,
596 pci, grep->dir[x], grep->insertffb[x], FALSE, dcd);
597 pci = (PCNRITEM) pci->rc.preccNextRecord;
598 }
599 memset(&ri, 0, sizeof(RECORDINSERT));
600 ri.cb = sizeof(RECORDINSERT);
601 ri.pRecordOrder = (PRECORDCORE) CMA_END;
602 ri.pRecordParent = (PRECORDCORE) NULL;
603 ri.zOrder = (USHORT) CMA_TOP;
604 ri.cRecordsInsert = grep->toinsert;
605 ri.fInvalidateRecord = TRUE;
606 WinSendMsg(grep->hwndFiles,
607 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri));
608 if (dcd) {
609 DosEnterCritSec();
610 dcd->ullTotalBytes += grep->insertedbytes;
611 DosExitCritSec();
612 }
613 if (grep->toinsert == FilesToGet)
614 DosSleep(0); //26 Aug 07 GKY 1
615 freegreplist(grep);
616 PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID);
617 return TRUE;
618 }
619 freegreplist(grep);
620 return FALSE;
621}
622
623static BOOL insert_grepfile(GREP *grep, CHAR *filename, PFILEFINDBUF4 pffb)
624{
625 PSZ p;
626 CHAR szDirectory[CCHMAXPATH];
627
628 if (WinIsWindow(grep->ghab, grep->hwndFiles)) {
629 grep->numfiles++;
630 strcpy(szDirectory, filename);
631 p = strrchr(szDirectory, '\\');
632 if (p) {
633 if (p < szDirectory + 4)
634 p++;
635 *p = 0;
636 if (!grep->insertffb) {
637 // Allocate 1 extra for end marker?
638 grep->insertffb = xmallocz(sizeof(PFILEFINDBUF4) * (FilesToGet + 1),
639 pszSrcFile, __LINE__);
640 if (!grep->insertffb)
641 return FALSE;
642 grep->dir = xmallocz(sizeof(CHAR *) * (FilesToGet + 1),
643 pszSrcFile, __LINE__);
644 if (!grep->dir) {
645 free(grep->insertffb);
646 return FALSE;
647 }
648 }
649 grep->insertffb[grep->toinsert] =
650 xmalloc(sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
651 if (!grep->insertffb[grep->toinsert])
652 return FALSE;
653 memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4));
654 grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__);
655 if (!grep->dir) {
656 free(grep->insertffb[grep->toinsert]);
657 return FALSE;
658 }
659 grep->insertedbytes += pffb->cbFile + CBLIST_TO_EASIZE(pffb->cbList);
660 grep->toinsert++;
661 if (grep->toinsert == FilesToGet)
662 return doinsertion(grep);
663 return TRUE;
664 }
665 }
666 else
667 freegreplist(grep);
668 return FALSE;
669}
670
671static BOOL doonefile(GREP *grep, CHAR *filename, FILEFINDBUF4 * pffb)
672{
673 // process a single file
674 CHAR *input;
675 FILE *inputFile;
676 ULONG pos;
677 BOOL ret = FALSE, strmatch = FALSE;
678
679 grep->fileCount++;
680 if (grep->sayfiles)
681 WinSetWindowText(grep->hwndCurFile, filename);
682
683 if (grep->greaterthan || grep->lessthan) {
684
685 BOOL keep = TRUE;
686 ULONG adjsize;
687
688 adjsize = pffb->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(pffb->cbList) : 0);
689 if (grep->greaterthan) {
690 if (adjsize < grep->greaterthan)
691 keep = FALSE;
692 }
693 if (keep && grep->lessthan) {
694 if (adjsize > grep->lessthan)
695 keep = FALSE;
696 }
697 if (!keep)
698 return ret;
699 }
700
701 if (grep->newerthan || grep->olderthan) {
702
703 BOOL keep = TRUE;
704 ULONG numsecs;
705
706 numsecs = SecsSince1980(&pffb->fdateLastWrite, &pffb->ftimeLastWrite);
707 if (grep->newerthan) {
708 if (numsecs < grep->newerthan)
709 keep = FALSE;
710 }
711 if (keep && grep->olderthan) {
712 if (numsecs > grep->olderthan)
713 keep = FALSE;
714 }
715 if (!keep)
716 return ret;
717 }
718
719 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) // just a find
720 return insert_grepfile(grep, filename, pffb);
721
722 if (grep->searchEAs) {
723
724 HOLDFEA *head, *info;
725 USHORT type, len;
726 BOOL alltext;
727 CHAR *data, temp;
728
729 head = GetFileEAs(filename, FALSE, TRUE);
730 if (head) {
731 info = head;
732 while (info && !strmatch) {
733 alltext = TRUE;
734 switch (*(USHORT *) info->value) {
735 case EAT_ASCII:
736 if (match(info->value + (sizeof(USHORT) * 2),
737 grep->searchPattern, grep->absFlag,
738 (grep->caseFlag == FALSE),
739 info->cbValue - (sizeof(USHORT) * 2),
740 grep->numlines, grep->matched, !grep->findifany)) {
741 strmatch = TRUE;
742 }
743 break;
744 case EAT_MVST:
745 type = *(USHORT *) (info->value + (sizeof(USHORT) * 3));
746 if (type == EAT_ASCII) {
747 data = info->value + (sizeof(USHORT) * 4);
748 len = *(USHORT *) data;
749 data += sizeof(USHORT);
750 while ((data - info->value) + len <= info->cbValue) {
751 temp = *(data + len);
752 *(data + len) = 0;
753 if (match(data,
754 grep->searchPattern,
755 grep->absFlag,
756 (grep->caseFlag == FALSE),
757 len,
758 grep->numlines, grep->matched, !grep->findifany)) {
759 strmatch = TRUE;
760 break;
761 }
762 data += len;
763 if (data - info->value >= info->cbValue)
764 break;
765 *data = temp;
766 len = *(USHORT *) data;
767 data += sizeof(USHORT);
768 }
769 }
770 break;
771 case EAT_MVMT:
772 data = info->value + (sizeof(USHORT) * 3);
773 type = *(USHORT *) data;
774 data += sizeof(USHORT);
775 len = *(USHORT *) data;
776 data += sizeof(USHORT);
777 while ((data - info->value) - len <= info->cbValue) {
778 if (type != EAT_ASCII) {
779 alltext = FALSE;
780 break;
781 }
782 data += len;
783 if (data - info->value >= info->cbValue)
784 break;
785 type = *(USHORT *) data;
786 data += sizeof(USHORT);
787 len = *(USHORT *) data;
788 data += sizeof(USHORT);
789 }
790 if (alltext) {
791 data = info->value + (sizeof(USHORT) * 3);
792 type = *(USHORT *) data;
793 data += sizeof(USHORT);
794 len = *(USHORT *) data;
795 data += sizeof(USHORT);
796 while ((data - info->value) - len <= info->cbValue) {
797 temp = *(data + len);
798 *(data + len) = 0;
799 if (match(data,
800 grep->searchPattern,
801 grep->absFlag,
802 (grep->caseFlag == FALSE),
803 len,
804 grep->numlines, grep->matched, !grep->findifany)) {
805 strmatch = TRUE;
806 break;
807 }
808 data += len;
809 *data = temp;
810 if (data - info->value >= info->cbValue)
811 break;
812 type = *(USHORT *) data;
813 data += sizeof(USHORT);
814 len = *(USHORT *) data;
815 data += sizeof(USHORT);
816 }
817 }
818 break;
819 default:
820 break;
821 }
822 info = info->next;
823 } // while
824 Free_FEAList(head);
825 DosSleep(1);
826 }
827 }
828
829 if (grep->searchFiles) {
830 input = xmalloc(65537, pszSrcFile, __LINE__);
831 if (input) {
832 LONG len;
833
834 inputFile = _fsopen(filename, "rb", SH_DENYNO);
835 if (inputFile) {
836 pos = ftell(inputFile);
837 while (!feof(inputFile)) {
838 if (pos)
839 fseek(inputFile, pos - 1024, SEEK_SET);
840 len = fread(input, 1, 65536, inputFile);
841 if (len >= 0) {
842 if (*grep->stopflag)
843 break;
844 if (match(input,
845 grep->searchPattern,
846 grep->absFlag,
847 (grep->caseFlag == FALSE),
848 len, grep->numlines, grep->matched, !grep->findifany)) {
849 strmatch = TRUE;
850 break;
851 }
852 }
853 else
854 break;
855 }
856 fclose(inputFile);
857 }
858 free(input);
859 DosSleep(1);
860 }
861 } // if
862
863 if (strmatch)
864 ret = insert_grepfile(grep, filename, pffb);
865 return ret;
866}
867
868static LONG cr3tab[] = { // CRC polynomial 0xEDB88320
869
870 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
871 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
872 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
873 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
874 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
875 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
876 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
877 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
878 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
879 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
880 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
881 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
882 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
883 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
884 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
885 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
886 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
887 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
888 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
889 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
890 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
891 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
892 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
893 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
894 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
895 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
896 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
897 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
898 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
899 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
900 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
901 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
902 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
903 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
904 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
905 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
906 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
907 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
908 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
909 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
910 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
911 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
912 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
913 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
914 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
915 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
916 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
917 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
918 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
919 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
920 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
921 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
922 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
923 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
924 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
925 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
926 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
927 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
928 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
929 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
930 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
931 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
932 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
933 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
934};
935
936LONG CRCBlock(register CHAR * str, register INT blklen, register LONG crc)
937{
938 while (blklen--) {
939 crc =
940 cr3tab[((INT) crc ^ *str) & 0xff] ^ (((ULONG) crc >> 8) & 0x00FFFFFF);
941 str++;
942 }
943 return crc;
944}
945
946LONG CRCFile(CHAR * filename, INT * error)
947{
948 LONG CRC = -1L, len;
949 FILE *fp;
950 CHAR *buffer;
951
952 *error = 0;
953 buffer = xmalloc(65535, pszSrcFile, __LINE__);
954 if (!buffer)
955 *error = -1;
956 else {
957 fp = _fsopen(filename, "rb", SH_DENYNO);
958 if (!fp)
959 *error = -2;
960 else {
961 while (!feof(fp)) {
962 len = fread(buffer, 1, 65535, fp);
963 if (len && len < 65536L)
964 CRC = CRCBlock(buffer, len, CRC);
965 else
966 break;
967 DosSleep(0); //26 Aug 07 GKY 1
968 }
969 fclose(fp);
970 DosSleep(1);
971 }
972 free(buffer);
973 }
974 return CRC;
975}
976
977static VOID FreeDupes(GREP *grep)
978{
979 DUPES *i, *next;
980
981 i = grep->dupehead;
982 while (i) {
983 next = i->next;
984 if (i->name)
985 free(i->name);
986 free(i);
987 i = next;
988 }
989 grep->dupehead = grep->dupelast = NULL;
990 if (grep->dupenames)
991 free(grep->dupenames);
992 if (grep->dupesizes)
993 free(grep->dupesizes);
994 grep->dupesizes = grep->dupenames = NULL;
995}
996
997int comparenamesq(const void *v1, const void *v2)
998{
999 DUPES *d1 = *(DUPES **) v1;
1000 DUPES *d2 = *(DUPES **) v2;
1001 CHAR *p1, *p2;
1002
1003 p1 = strrchr(d1->name, '\\');
1004 if (p1)
1005 p1++;
1006 else
1007 p1 = d1->name;
1008 p2 = strrchr(d2->name, '\\');
1009 if (p2)
1010 p2++;
1011 else
1012 p2 = d2->name;
1013 return stricmp(p1, p2);
1014}
1015
1016int comparenamesqe(const void *v1, const void *v2)
1017{
1018 DUPES *d1 = *(DUPES **) v1;
1019 DUPES *d2 = *(DUPES **) v2;
1020 CHAR *p1, *p2, *p1e, *p2e, e1, e2;
1021 int ret;
1022
1023 p1 = strrchr(d1->name, '\\');
1024 if (p1)
1025 p1++;
1026 else
1027 p1 = d1->name;
1028 p1e = strrchr(p1, '.');
1029 if (p1e) {
1030 e1 = *p1e;
1031 *p1e = 0;
1032 }
1033 p2 = strrchr(d2->name, '\\');
1034 if (p2)
1035 p2++;
1036 else
1037 p2 = d2->name;
1038 p2e = strrchr(p2, '.');
1039 if (p2e) {
1040 e2 = *p2e;
1041 *p2e = 0;
1042 }
1043 ret = stricmp(p1, p2);
1044 if (p1e)
1045 *p1e = e1;
1046 if (p2e)
1047 *p2e = e2;
1048 return ret;
1049}
1050
1051int comparesizesq(const void *v1, const void *v2)
1052{
1053 DUPES *d1 = *(DUPES **) v1;
1054 DUPES *d2 = *(DUPES **) v2;
1055
1056 return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
1057}
1058
1059int comparenamesb(const void *v1, const void *v2)
1060{
1061 DUPES *d1 = (DUPES *) v1;
1062 DUPES *d2 = *(DUPES **) v2;
1063 CHAR *p1, *p2;
1064
1065 p1 = strrchr(d1->name, '\\');
1066 if (p1)
1067 p1++;
1068 else
1069 p1 = d1->name;
1070 p2 = strrchr(d2->name, '\\');
1071 if (p2)
1072 p2++;
1073 else
1074 p2 = d2->name;
1075 return stricmp(p1, p2);
1076}
1077
1078int comparenamesbe(const void *v1, const void *v2)
1079{
1080 DUPES *d1 = (DUPES *) v1;
1081 DUPES *d2 = *(DUPES **) v2;
1082 CHAR *p1, *p2, *p1e, *p2e, e1, e2;
1083 int ret;
1084
1085 p1 = strrchr(d1->name, '\\');
1086 if (p1)
1087 p1++;
1088 else
1089 p1 = d1->name;
1090 p1e = strrchr(p1, '.');
1091 if (p1e) {
1092 e1 = *p1e;
1093 *p1e = 0;
1094 }
1095 p2 = strrchr(d2->name, '\\');
1096 if (p2)
1097 p2++;
1098 else
1099 p2 = d2->name;
1100 p2e = strrchr(p2, '.');
1101 if (p2e) {
1102 e2 = *p2e;
1103 *p2e = 0;
1104 }
1105 ret = stricmp(p1, p2);
1106 if (p1e)
1107 *p1e = e1;
1108 if (p2e)
1109 *p2e = e2;
1110 return ret;
1111}
1112
1113int comparesizesb(const void *v1, const void *v2)
1114{
1115 DUPES *d1 = (DUPES *) v1;
1116 DUPES *d2 = *(DUPES **) v2;
1117
1118 return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
1119}
1120
1121static VOID FillDupes(GREP * grep)
1122{
1123 DUPES *c, *i, **r;
1124 register CHAR *pc, *pi;
1125 CHAR **list = NULL;
1126 INT numfiles = 0, numalloced = 0, error;
1127 register ULONG x = 0, y = 0;
1128 ULONG cntr = 1000;
1129
1130 if (grep->CRCdupes)
1131 cntr = 100;
1132 i = grep->dupehead;
1133 while (i) {
1134 x++;
1135 i = i->next;
1136 }
1137 if (x) {
1138 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
1139 DosSleep(0); //26 Aug 07 GKY 1
1140 grep->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
1141 if (!grep->nosizedupes)
1142 grep->dupesizes = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
1143 if (grep->dupenames && (grep->nosizedupes || grep->dupesizes)) {
1144 i = grep->dupehead;
1145 while (i) {
1146 grep->dupenames[y] = i;
1147 if (!grep->nosizedupes)
1148 grep->dupesizes[y] = i;
1149 i = i->next;
1150 y++;
1151 }
1152 grep->dupenames[y] = NULL;
1153 if (!grep->nosizedupes)
1154 grep->dupesizes[y] = NULL;
1155 DosSleep(0); //26 Aug 07 GKY 1
1156 qsort(grep->dupenames,
1157 x,
1158 sizeof(DUPES *),
1159 ((grep->ignoreextdupes) ? comparenamesqe : comparenamesq));
1160 DosSleep(0); //26 Aug 07 GKY 1
1161 if (!grep->nosizedupes) {
1162 qsort(grep->dupesizes, x, sizeof(DUPES *), comparesizesq);
1163 DosSleep(0); //26 Aug 07 GKY 1
1164 }
1165 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
1166
1167 i = grep->dupehead;
1168 y = 0;
1169 while (i) {
1170 if (*grep->stopflag)
1171 break;
1172 if (!(i->flags & GF_SKIPME)) {
1173 r = (DUPES **) bsearch(i, grep->dupenames, x, sizeof(DUPES *),
1174 ((grep->ignoreextdupes) ? comparenamesbe :
1175 comparenamesb));
1176 if (r) {
1177 while (r > grep->dupenames && ((grep->ignoreextdupes) ?
1178 !comparenamesqe((r - 1), &i) :
1179 !comparenamesq((r - 1), &i)))
1180 r--;
1181 while (*r && ((grep->ignoreextdupes) ?
1182 !comparenamesqe(r, &i) : !comparenamesq(r, &i))) {
1183 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) {
1184 r++;
1185 continue;
1186 }
1187 if (grep->CRCdupes) {
1188 if ((*r)->CRC == -1L) {
1189 (*r)->CRC = CRCFile((*r)->name, &error);
1190 if (error)
1191 (*r)->CRC = -1L;
1192 else if ((*r)->CRC == -1L)
1193 (*r)->CRC = 0L;
1194 }
1195 if (i->CRC == -1L) {
1196 i->CRC = CRCFile(i->name, &error);
1197 if (error)
1198 i->CRC = -1L;
1199 else if (i->CRC == -1L)
1200 i->CRC = 0L;
1201 }
1202 if (((*r)->size != i->size) || ((*r)->CRC != -1L &&
1203 i->CRC != -1L
1204 && (*r)->CRC != i->CRC)) {
1205 r++;
1206 continue;
1207 }
1208 }
1209 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
1210 (*r)->flags |= GF_INSERTED;
1211 if (grep->sayfiles)
1212 WinSetWindowText(grep->hwndFiles, (*r)->name);
1213 if ((*r)->size == i->size &&
1214 (i->date.year == (*r)->date.year &&
1215 i->date.month == (*r)->date.month &&
1216 i->date.day == (*r)->date.day &&
1217 i->time.hours == (*r)->time.hours &&
1218 i->time.minutes == (*r)->time.minutes &&
1219 i->time.twosecs == (*r)->time.twosecs))
1220 (*r)->flags |= GF_SKIPME;
1221 }
1222 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
1223 if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
1224 i->flags |= GF_INSERTED;
1225 if ((*r)->flags & GF_SKIPME)
1226 i->flags |= GF_SKIPME;
1227 }
1228 }
1229 r++;
1230 }
1231 }
1232 if (!grep->nosizedupes) {
1233 r = (DUPES **) bsearch(i,
1234 grep->dupesizes,
1235 x, sizeof(DUPES *), comparesizesb);
1236 if (r) {
1237 while (r > grep->dupesizes && !comparesizesq((r - 1), &i))
1238 r--;
1239 while (*r && !comparesizesq(r, &i)) {
1240 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME)) ||
1241 (i->date.year != (*r)->date.year ||
1242 i->date.month != (*r)->date.month ||
1243 i->date.day != (*r)->date.day ||
1244 i->time.hours != (*r)->time.hours ||
1245 i->time.minutes != (*r)->time.minutes ||
1246 i->time.twosecs != (*r)->time.twosecs)) {
1247 r++;
1248 continue;
1249 }
1250 if (grep->CRCdupes) {
1251 if ((*r)->CRC == -1L) {
1252 (*r)->CRC = CRCFile((*r)->name, &error);
1253 if (error)
1254 (*r)->CRC = -1L;
1255 else if ((*r)->CRC == -1L)
1256 (*r)->CRC = 0L;
1257 }
1258 if (i->CRC == -1L) {
1259 i->CRC = CRCFile(i->name, &error);
1260 if (error)
1261 i->CRC = -1L;
1262 else if (i->CRC == -1L)
1263 i->CRC = 0L;
1264 }
1265 if ((*r)->CRC != -1L && i->CRC != -1L &&
1266 (*r)->CRC != i->CRC) {
1267 *r += 1;
1268 continue;
1269 }
1270 }
1271 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
1272 if (grep->sayfiles)
1273 WinSetWindowText(grep->hwndCurFile, (*r)->name);
1274 (*r)->flags |= GF_INSERTED;
1275 if (((grep->ignoreextdupes) ?
1276 comparenamesqe(r, &i) : comparenamesq(r, &i)))
1277 (*r)->flags |= GF_SKIPME;
1278 }
1279 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
1280 if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
1281 i->flags |= GF_INSERTED;
1282 if ((*r)->flags & GF_SKIPME)
1283 i->flags |= GF_SKIPME;
1284 }
1285 }
1286 r++;
1287 }
1288 }
1289 }
1290 }
1291 i = i->next;
1292 y++;
1293 if (!(y % cntr)) {
1294
1295 CHAR s[44];
1296
1297 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
1298 WinSetWindowText(grep->hwndCurFile, s);
1299 DosSleep(1); //05 Aug 07 GKY 128
1300 }
1301 DosSleep(0); //26 Aug 07 GKY 1
1302 }
1303 }
1304 else {
1305 // Insufficient memory - fall back
1306 DosBeep(50, 100);
1307 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
1308 x = y = 0;
1309 if (grep->dupenames) {
1310 free(grep->dupenames);
1311 grep->dupenames = NULL;
1312 }
1313 if (grep->dupesizes) {
1314 free(grep->dupesizes);
1315 grep->dupesizes = NULL;
1316 }
1317 i = grep->dupehead;
1318 while (i) {
1319 if (*grep->stopflag)
1320 break;
1321 if (!(i->flags & GF_SKIPME)) {
1322 if (!(y % cntr)) {
1323
1324 CHAR s[44];
1325
1326 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
1327 WinSetWindowText(grep->hwndCurFile, s);
1328 DosSleep(0); //26 Aug 07 GKY 1
1329 }
1330 y++;
1331 pi = strrchr(i->name, '\\');
1332 if (pi)
1333 pi++;
1334 else
1335 pi = i->name;
1336 c = grep->dupehead;
1337 while (c) {
1338 if (*grep->stopflag)
1339 break;
1340 if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
1341 x++;
1342 pc = strrchr(c->name, '\\');
1343 if (pc)
1344 pc++;
1345 else
1346 pc = c->name;
1347 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
1348 if (grep->CRCdupes) {
1349 if (grep->CRCdupes) {
1350 if (c->CRC == -1L) {
1351 c->CRC = CRCFile(c->name, &error);
1352 if (error)
1353 c->CRC = -1L;
1354 else if (c->CRC == -1L)
1355 c->CRC = 0L;
1356 }
1357 if (i->CRC == -1L) {
1358 i->CRC = CRCFile(i->name, &error);
1359 if (error)
1360 i->CRC = -1L;
1361 else if (i->CRC == -1L)
1362 i->CRC = 0L;
1363 }
1364 if ((c->size != i->size) || (c->CRC != -1L &&
1365 i->CRC != -1L
1366 && c->CRC != i->CRC)) {
1367 c = c->next;
1368 continue;
1369 }
1370 }
1371 }
1372 if (AddToList(c->name, &list, &numfiles, &numalloced))
1373 goto BreakOut; // Failed
1374 if (!(i->flags & GF_INSERTED)) {
1375 if (AddToList(i->name, &list, &numfiles, &numalloced))
1376 goto BreakOut; // Failed
1377 }
1378 if (grep->sayfiles)
1379 WinSetWindowText(grep->hwndCurFile, pc);
1380 c->flags |= GF_INSERTED;
1381 i->flags |= GF_INSERTED;
1382 if (!stricmp(pc, pi)) {
1383 c->flags |= GF_SKIPME;
1384 i->flags |= GF_SKIPME;
1385 }
1386 }
1387 else if (!(x % 100))
1388 DosSleep(0); //26 Aug 07 GKY 1
1389 }
1390 c = c->next;
1391 }
1392 }
1393 i = i->next;
1394 }
1395 }
1396 }
1397BreakOut:
1398 FreeDupes(grep);
1399 if (numfiles && list) {
1400 if (!PostMsg(grep->hwndFiles,
1401 WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
1402 FreeList(list);
1403 }
1404 else
1405 DosPostEventSem(CompactSem);
1406}
1407
1408static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4 *pffb)
1409{
1410 DUPES *info;
1411
1412 if (*dir) {
1413 info = xmallocz(sizeof(DUPES), pszSrcFile, __LINE__);
1414 if (!info)
1415 return FALSE;
1416
1417 info->name = xstrdup(dir, pszSrcFile, __LINE__);
1418 if (!info->name) {
1419 free(info);
1420 return FALSE;
1421 }
1422
1423 info->size = pffb->cbFile;
1424 info->date = pffb->fdateLastWrite;
1425 info->time = pffb->ftimeLastWrite;
1426 info->CRC = -1L;
1427 grep->numfiles++;
1428 if (!grep->dupehead)
1429 grep->dupehead = info;
1430 if (grep->dupelast)
1431 grep->dupelast->next = info;
1432 grep->dupelast = info;
1433 info->next = NULL;
1434 }
1435 return TRUE;
1436}
1437
1438#pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
1439#pragma alloc_text(GREP,SecsSince1980,match,mmatch,GrepThread)
1440#pragma alloc_text(GREP,doallsubdirs,domatchingfiles,InsertDupes,FreeDupes)
1441
1442#pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock)
1443#pragma alloc_text(DUPES,comparenamesq,comparenamesqe,comparenamesb)
1444#pragma alloc_text(DUPES,comparenamesbe,comparesizesq,comparesizesb)
Note: See TracBrowser for help on using the repository browser.