source: trunk/dll/grep.c@ 304

Last change on this file since 304 was 281, checked in by root, 20 years ago

dononefile: do not free EA list twice

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