source: trunk/dll/grep.c@ 433

Last change on this file since 433 was 370, checked in by root, 19 years ago

Check more run time errors

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