source: trunk/dll/grep.c@ 217

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

Suppress warning

  • 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 217 2005-06-18 03:54:00Z 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
17***********************************************************************/
18
19#define INCL_DOS
20#define INCL_WIN
21#define INCL_LONGLONG
22#include <os2.h>
23
24#include <stdlib.h>
25#include <string.h>
26#include <ctype.h>
27#include <stdio.h>
28#include <share.h>
29
30#include "fm3dll.h"
31#include "fm3str.h"
32#include "grep.h"
33
34#pragma data_seg(DATA2)
35#pragma alloc_text(GREP,SecsSince1980,match,mmatch,dogrep)
36#pragma alloc_text(GREP,doallsubdirs,domatchingfiles)
37
38/*****************************/
39/* Function Prototypes */
40/*****************************/
41
42static VOID doallsubdirs (GREP *grep,CHAR *searchPath,BOOL recursing,
43 char **fle,int numfls);
44static INT domatchingfiles (GREP *grep,CHAR *path,char **fle,int numfls);
45static BOOL doonefile (GREP *grep,CHAR *fileName,FILEFINDBUF4 *f);
46static BOOL doinsertion (GREP *grep);
47static BOOL InsertDupe (GREP *grep,CHAR *dir,FILEFINDBUF4 *f);
48static VOID FillDupes (GREP *g);
49static VOID FreeDupes (GREP *g);
50
51#define GREPCHARS "*?[] \\"
52
53#define isleap(year) ((((year%4)==0) && ((year%100)!=0)) || \
54 ((year%400)==0))
55
56
57static INT monthdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
58
59
60ULONG SecsSince1980 (FDATE *date,FTIME *time)
61{
62 ULONG total = 0L;
63 register int x;
64
65 for(x = 1980;x < date->year + 1980;x++) {
66 if(isleap(x))
67 total += (366L * (24L * 60L * 60L));
68 else
69 total += (365L * (24L * 60L * 60L));
70 }
71 for(x = 1;x < date->month;x++) {
72 if(x == 2 && isleap(date->year + 1980))
73 total += (29L * (24L * 60L * 60L));
74 else
75 total += ((long)monthdays[x - 1] * (24L * 60L * 60L));
76 }
77 total += (((long)date->day - 1L) * (24L * 60L * 60L));
78 total += ((long)time->hours * (60L * 60L));
79 total += ((long)time->minutes * 60L);
80 total += ((long)time->twosecs * 2L);
81 return total;
82}
83
84
85/*
86 * this function originally from C_ECHO's Snippets -- modified
87 * brute force methodology
88 */
89
90static BOOL m_match (CHAR *string, CHAR *pattern, BOOL absolute, BOOL ignore,
91 LONG len) {
92
93 /* return TRUE if pattern found in string */
94
95 register CHAR *tn = pattern;
96 register LONG len2 = 0;
97 LONG lastlen = 0;
98 CHAR lo,hi;
99
100 if(len && string && pattern) {
101 if(absolute) /* no pattern matching */
102 return(findstring(pattern,strlen(pattern),string,len,
103 (ignore == FALSE)) != NULL);
104
105 while(*tn && len2 < len) {
106 switch(*tn) {
107 case ' ':
108 while(*tn == ' ')
109 tn++;
110 while(len2 < len && isspace(string[len2]))
111 len2++;
112 break;
113
114 case '*':
115 while(*tn == '*' || *tn == '?')
116 tn++;
117 if(!*tn)
118 return TRUE;
119 if(ignore) {
120 while(len2 < len && string[len2] != *tn)
121 len2++;
122 }
123 else {
124 while(len2 < len && toupper(string[len2] != *tn))
125 len2++;
126 }
127 break;
128
129 case '[':
130 tn++;
131 if(!*tn)
132 return FALSE;
133 lo = *tn;
134 tn++;
135 if(*tn != '-')
136 return FALSE;
137 tn++;
138 if(!*tn)
139 return FALSE;
140 hi = *tn;
141 tn++;
142 if (*tn != ']')
143 return FALSE;
144 tn++;
145 if(ignore) {
146 if ((toupper(string[len2]) >= toupper(lo)) &&
147 (toupper(string[len2]) <= toupper(hi)))
148 len2++;
149 else {
150 tn = pattern;
151 len2 = lastlen = lastlen + 1;
152 }
153 }
154 else {
155 if ((string[len2] >= lo) && (string[len2] <= hi))
156 len2++;
157 else {
158 tn = pattern;
159 len2 = lastlen = lastlen + 1;
160 }
161 }
162 break;
163
164 case '?':
165 tn++;
166 len2++;
167 break;
168
169 case '\\':
170 tn++;
171 if(!*tn)
172 return FALSE;
173 /* else intentional fallthru */
174 default:
175 if(ignore) {
176 if(toupper(*tn) == toupper(string[len2])) {
177 tn++;
178 len2++;
179 }
180 else {
181 tn = pattern;
182 len2 = lastlen = lastlen + 1;
183 }
184 }
185 else {
186 if(*tn == string[len2]) {
187 tn++;
188 len2++;
189 }
190 else {
191 tn = pattern;
192 len2 = lastlen = lastlen + 1;
193 }
194 }
195 break;
196 }
197 }
198 while(*tn == '*')
199 tn++;
200
201 if (!*tn)
202 return TRUE;
203 }
204 return FALSE;
205}
206
207
208static BOOL match (CHAR *string,CHAR *patterns,BOOL absolute,BOOL ignore,
209 LONG len,ULONG numlines,CHAR *matched,BOOL matchall) {
210
211 BOOL ret = FALSE;
212 register CHAR *p;
213 register ULONG x = 0;
214
215 p = patterns;
216 while(!ret && *p) {
217 ret = m_match(string,p,absolute,ignore,len);
218 if(matchall && ret)
219 break;
220 if(matched && ret && x < numlines)
221 matched[x] = 1;
222 p += strlen(p); /* check each pattern in 0-terminated list */
223 p++;
224 x++;
225 }
226 return ret;
227}
228
229
230VOID dogrep (VOID *arg)
231{
232 HAB ghab;
233 HMQ ghmq;
234 GREP grep;
235 register INT x,numfls;
236 static CHAR *fle[512];
237 CHAR *p,*pp,searchPath[CCHMAXPATH * 2];
238
239 if(!arg)
240 return;
241 grep = *(GREP *)arg;
242 *grep.stopflag = 0; /* reset thread-killing flag */
243 grep.FilesToGet = (grep.dirFlag) ? min(FilesToGet,128) : FilesToGet;
244 DosError(FERR_DISABLEHARDERR);
245 priority_normal();
246
247 ghab = WinInitialize(0);
248 if(ghab) {
249 grep.ghab = ghab;
250 ghmq = WinCreateMsgQueue(ghab,0);
251 if(ghmq) {
252 WinCancelShutdown(ghmq,TRUE);
253 DosSleep(128L);
254 WinSetWindowText(grep.hwndCurFile,
255 GetPString((grep.finddupes) ?
256 IDS_GREPDUPETEXT : IDS_GREPSCANTEXT));
257
258 pp = grep.searchPattern;
259 while(*pp) {
260 if(!grep.absFlag) {
261 p = GREPCHARS; /* see if any sense in pattern matching */
262 while(*p) {
263 if(strchr(pp,*p))
264 break;
265 p++;
266 }
267 if(!*p) /* nope, turn it off */
268 grep.absFlag = TRUE;
269 }
270 pp = pp + strlen(pp) + 1;
271 }
272
273 grep.attrFile &= (~FILE_DIRECTORY);
274 grep.antiattr &= (~FILE_DIRECTORY);
275 if(grep.antiattr & FILE_READONLY)
276 grep.antiattr |= MUST_HAVE_READONLY;
277 if(grep.antiattr & FILE_HIDDEN)
278 grep.antiattr |= MUST_HAVE_HIDDEN;
279 if(grep.antiattr & FILE_SYSTEM)
280 grep.antiattr |= MUST_HAVE_SYSTEM;
281 if(grep.antiattr & FILE_ARCHIVED)
282 grep.antiattr |= MUST_HAVE_ARCHIVED;
283
284 grep.anyexcludes = FALSE;
285 numfls = x = 0;
286 fle[numfls++] = strtok(grep.tosearch,";");
287 while((fle[numfls] = strtok(NULL,";")) != NULL && numfls < 511) {
288 if(*fle[numfls] == '/')
289 grep.anyexcludes = TRUE;
290 numfls++;
291 }
292
293 while(x < numfls) { /* loop through search masks */
294
295 if(*fle[x] == '/') /* is an exclude mask only */
296 goto ExcludeSkip;
297
298 /* first, separate any path from mask */
299
300 p = (char *)(fle[x] + (strlen(fle[x]) - 1));
301 while(*p != '\\' && *p != ':' && p != fle[x])
302 --p;
303
304 if(p == fle[x]) { /* no path */
305 strcpy(searchPath,grep.curdir);
306 strncpy(grep.fileMask,fle[x],CCHMAXPATH);
307 grep.fileMask[CCHMAXPATH - 1] = 0;
308 }
309 else { /* got to deal with a path */
310 if(*p == ':') { /* just a drive, start in root dir */
311 *p = 0;
312 p++;
313 strncpy(searchPath,fle[x],CCHMAXPATH - 2);
314 searchPath[CCHMAXPATH - 3] = 0;
315 strcat(searchPath,":\\");
316 strcpy(grep.fileMask,p);
317 }
318 if(*p == '\\') { /* got a 'full' path */
319
320 CHAR temp;
321
322 p++;
323 temp = *p;
324 *p = 0;
325 strncpy(searchPath,fle[x],CCHMAXPATH);
326 searchPath[CCHMAXPATH - 1] = 0;
327 *p = temp;
328 strcpy(grep.fileMask,p);
329 }
330 if(!*grep.fileMask)
331 strcpy(grep.fileMask,"*");
332 }
333 if(*grep.stopflag)
334 break;
335 /* do single directory */
336 domatchingfiles(&grep,searchPath,fle,numfls);
337 if(grep.dirFlag) /* do subdirs */
338 doallsubdirs(&grep,searchPath,FALSE,fle,numfls);
339ExcludeSkip:
340 if(*grep.stopflag)
341 break;
342 x++ ;
343 if(WinIsWindow(grep.ghab,grep.hwndFiles))
344 doinsertion(&grep); /* insert any remaining objects */
345 }
346
347ShutDownThread: /* kill pm connection, end thread */
348
349 if(WinIsWindow(grep.ghab,grep.hwndFiles))
350 doinsertion(&grep); /* insert any remaining objects */
351
352 if(WinIsWindow(grep.ghab,grep.hwndFiles) && grep.finddupes &&
353 !*grep.stopflag)
354 FillDupes(&grep);
355
356 if(!PostMsg(grep.hwndFiles,
357 UM_CONTAINER_FILLED,
358 MPVOID,
359 MPVOID)) /* tell window we're done */
360 WinSendMsg(grep.hwndFiles,
361 UM_CONTAINER_FILLED,
362 MPVOID,
363 MPVOID);
364 WinDestroyMsgQueue(ghmq);
365 }
366 WinTerminate(ghab);
367 }
368 if(!ghmq || !ghab)
369 WinPostMsg(grep.hwndFiles,
370 UM_CONTAINER_FILLED,
371 MPVOID,
372 MPVOID);
373 if(grep.dupehead)
374 FreeDupes(&grep);
375 if(grep.numlines &&
376 grep.matched)
377 free(grep.matched);
378 DosPostEventSem(CompactSem);
379}
380
381
382static BOOL IsExcluded (char *name,char **fle,int numfls)
383{
384 register int x;
385 char *n;
386
387 n = strrchr(name,'\\');
388 if(!n)
389 n = strrchr(name,':');
390 if(n)
391 n++;
392 else
393 n = name;
394 for(x = 0;x < numfls;x++) {
395 if(*fle[x] == '/' &&
396 wildcard((strchr(fle[x],'\\') ||
397 strchr(fle[x],':')) ?
398 name : n,fle[x] + 1,FALSE))
399 return TRUE;
400 }
401 return FALSE;
402}
403
404
405static VOID doallsubdirs (GREP *grep,CHAR *searchPath,BOOL recursing,
406 char **fle,int numfls) {
407
408 /* process all subdirectories */
409
410 FILEFINDBUF4 findBuffer;
411 HDIR findHandle = HDIR_CREATE;
412 LONG findCount = 1L;
413 CHAR *p = NULL;
414
415 /* add a mask to search path */
416 if(searchPath[strlen(searchPath) - 1] != '\\')
417 strcat(searchPath,"\\");
418 strcat(searchPath,"*");
419 /* step through all subdirectories */
420 DosError(FERR_DISABLEHARDERR);
421 if(!DosFindFirst(searchPath,&findHandle,(MUST_HAVE_DIRECTORY |
422 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY),
423 &findBuffer,
424 (ULONG)sizeof(findBuffer),
425 (PULONG)&findCount,
426 FIL_QUERYEASIZE)) {
427
428 /* get rid of mask portion, save end-of-directory */
429
430 p = strrchr(searchPath,'\\');
431 if(p)
432 p++;
433 else
434 p = searchPath;
435 do { /* Process each directory that matches the mask */
436 priority_normal();
437 if(*grep->stopflag)
438 break;
439 if(*findBuffer.achName != '.' ||
440 (findBuffer.achName[1] && findBuffer.achName[1] != '.')) {
441 strcpy(p,findBuffer.achName) ;
442 if(!grep->anyexcludes || !IsExcluded(searchPath,fle,numfls)) {
443 domatchingfiles(grep,searchPath,fle,numfls) ;
444 doallsubdirs(grep,searchPath,TRUE,fle,numfls);
445 DosSleep(0L);
446 }
447 }
448 findCount = 1L;
449 } while(!DosFindNext(findHandle,
450 &findBuffer,
451 sizeof(findBuffer),
452 (PULONG)&findCount));
453 DosFindClose(findHandle);
454 priority_normal();
455 }
456 if(p) /* strip off last directory addition */
457 *p = 0;
458}
459
460
461static INT domatchingfiles (GREP *grep,CHAR *path,char **fle,int numfls)
462{
463 /* process all matching files in a directory */
464
465 PFILEFINDBUF4 findBuffer = malloc(grep->FilesToGet * sizeof(FILEFINDBUF4));
466 PFILEFINDBUF4 pffbFile;
467 register PBYTE fb;
468 register ULONG x;
469 HDIR findHandle = HDIR_CREATE;
470 ULONG findCount = grep->FilesToGet;
471 CHAR newPath[CCHMAXPATH],*p;
472 APIRET rc;
473
474 if(!findBuffer)
475 return 0;
476
477 /* build filemask */
478
479 sprintf(newPath,
480 "%s%s%s",
481 path,
482 (path[strlen(path) - 1] == '\\') ?
483 NullStr : "\\",
484 grep->fileMask);
485
486 MakeFullName(newPath);
487
488 /* find and save end-of-dir position */
489 p = strrchr(newPath,'\\');
490 if(p)
491 p++;
492 else
493 p = newPath;
494
495 /* step through matching files */
496 DosError(FERR_DISABLEHARDERR);
497 if(!DosFindFirst(newPath,
498 &findHandle,
499 (FILE_NORMAL | grep->attrFile | grep->antiattr),
500 findBuffer,
501 (ULONG)(grep->FilesToGet * sizeof(FILEFINDBUF4)),
502 (PULONG)&findCount,
503 FIL_QUERYEASIZE)) {
504
505 do { /* Process each file that matches the mask */
506 priority_normal();
507 fb = (PBYTE)findBuffer;
508 for(x = 0L;x < findCount;x++) {
509 pffbFile = (PFILEFINDBUF4)fb;
510 if(*grep->stopflag)
511 break;
512 if(*pffbFile->achName != '.' ||
513 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
514 strcpy(p,pffbFile->achName); /* build filename */
515 if(!grep->anyexcludes ||
516 !IsExcluded(newPath,fle,numfls)) {
517 if(!grep->finddupes)
518 doonefile(grep,
519 newPath,
520 pffbFile);
521 else if(!InsertDupe(grep,
522 newPath,
523 pffbFile)) {
524 DosFindClose(findHandle);
525 free(findBuffer);
526 return 1;
527 }
528 }
529 }
530 if(!pffbFile->oNextEntryOffset)
531 break;
532 fb += pffbFile->oNextEntryOffset;
533 }
534 findCount = grep->FilesToGet;
535 rc = DosFindNext(findHandle,
536 findBuffer,
537 (ULONG)(grep->FilesToGet * sizeof(FILEFINDBUF4)),
538 (PULONG)&findCount);
539 if(!rc)
540 DosSleep(1L);
541 } while(!rc);
542 DosFindClose(findHandle);
543 priority_normal();
544 }
545 free(findBuffer);
546 return 0 ;
547}
548
549#pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
550
551
552static VOID freegreplist (GREP *grep)
553{
554 register INT x;
555
556 if(grep) {
557 if(grep->insertffb) {
558 for(x = 0;grep->insertffb[x];x++)
559 free(grep->insertffb[x]);
560 free(grep->insertffb);
561 }
562 if(grep->dir) {
563 for(x = 0;grep->dir[x];x++)
564 free(grep->dir[x]);
565 free(grep->dir);
566 }
567 grep->dir = NULL;
568 grep->insertffb = NULL;
569 grep->toinsert = 0L;
570 grep->insertedbytes = 0L;
571 }
572}
573
574
575static BOOL doinsertion (GREP *grep)
576{
577 RECORDINSERT ri;
578 DIRCNRDATA *dcd;
579 PCNRITEM pci,pciFirst;
580 INT x;
581
582 if(!grep ||
583 !grep->toinsert ||
584 !grep->insertffb ||
585 !grep->dir)
586 return FALSE;
587 pci = WinSendMsg(grep->hwndFiles,
588 CM_ALLOCRECORD,
589 MPFROMLONG(EXTRA_RECORD_BYTES),
590 MPFROMLONG(grep->toinsert));
591 if(pci) {
592 if(grep->sayfiles)
593 WinSetWindowText(grep->hwndCurFile,
594 GetPString(IDS_GREPINSERTINGTEXT));
595 pciFirst = pci;
596 dcd = INSTDATA(grep->hwndFiles);
597 for(x = 0; grep->insertffb[x]; x++) {
598 FillInRecordFromFFB(grep->hwndFiles,
599 pci,
600 grep->dir[x],
601 grep->insertffb[x],
602 FALSE,
603 dcd);
604 pci = (PCNRITEM) pci->rc.preccNextRecord;
605 }
606 memset(&ri,0,sizeof(RECORDINSERT));
607 ri.cb = sizeof(RECORDINSERT);
608 ri.pRecordOrder = (PRECORDCORE) CMA_END;
609 ri.pRecordParent = (PRECORDCORE)NULL;
610 ri.zOrder = (USHORT) CMA_TOP;
611 ri.cRecordsInsert = grep->toinsert;
612 ri.fInvalidateRecord = TRUE;
613 WinSendMsg(grep->hwndFiles,
614 CM_INSERTRECORD,
615 MPFROMP(pciFirst),
616 MPFROMP(&ri));
617 if(dcd) {
618 DosEnterCritSec();
619 dcd->ullTotalBytes += grep->insertedbytes;
620 DosExitCritSec();
621 }
622 if(grep->toinsert == grep->FilesToGet)
623 DosSleep(1L);
624 freegreplist(grep);
625 PostMsg(grep->hwndFiles,
626 UM_RESCAN,
627 MPVOID,
628 MPVOID);
629 return TRUE;
630 }
631 freegreplist(grep);
632 return FALSE;
633}
634
635
636static BOOL insert_grepfile (GREP *grep,CHAR *filename,FILEFINDBUF4 *f)
637{
638 CHAR *p,szDirectory[CCHMAXPATH];
639
640 if(WinIsWindow(grep->ghab,grep->hwndFiles)) {
641 grep->numfiles++;
642 strcpy(szDirectory,filename);
643 p = strrchr(szDirectory,'\\');
644 if(p) {
645 if(p < szDirectory + 4)
646 p++;
647 *p = 0;
648 if(!grep->insertffb) {
649 grep->insertffb = malloc(sizeof(FILEFINDBUF4 *) *
650 (grep->FilesToGet + 1));
651 if(!grep->insertffb)
652 return FALSE;
653 memset(grep->insertffb,0,sizeof(FILEFINDBUF4 *) *
654 (grep->FilesToGet + 1));
655 grep->dir = malloc(sizeof(CHAR *) * (grep->FilesToGet + 1));
656 if(!grep->dir) {
657 free(grep->insertffb);
658 return FALSE;
659 }
660 memset(grep->dir,0,sizeof(CHAR *) * (grep->FilesToGet + 1));
661 }
662 grep->insertffb[grep->toinsert] = malloc(sizeof(FILEFINDBUF4));
663 if(!grep->insertffb[grep->toinsert])
664 return FALSE;
665 memcpy(grep->insertffb[grep->toinsert],f,sizeof(FILEFINDBUF4));
666 grep->dir[grep->toinsert] = strdup(szDirectory);
667 if(!grep->dir) {
668 free(grep->insertffb[grep->toinsert]);
669 return FALSE;
670 }
671 grep->insertedbytes += f->cbFile + CBLIST_TO_EASIZE(f->cbList);
672 grep->toinsert++;
673 if(grep->toinsert == grep->FilesToGet)
674 return doinsertion(grep);
675 return TRUE;
676 }
677 }
678 else
679 freegreplist(grep);
680 return FALSE;
681}
682
683
684static BOOL doonefile (GREP *grep,CHAR *filename,FILEFINDBUF4 *f)
685{
686 /* process a single file */
687
688 CHAR *input;
689 FILE *inputFile;
690 ULONG pos;
691 BOOL ret = FALSE,strmatch = FALSE;
692
693 grep->fileCount++;
694 if(grep->sayfiles)
695 WinSetWindowText(grep->hwndCurFile,
696 filename);
697
698 if(grep->greaterthan || grep->lessthan) {
699
700 BOOL keep = TRUE;
701 ULONG adjsize;
702
703 adjsize = f->cbFile +
704 (grep->searchEAs ? CBLIST_TO_EASIZE(f->cbList) : 0);
705 if(grep->greaterthan) {
706 if(adjsize < grep->greaterthan)
707 keep = FALSE;
708 }
709 if(keep && grep->lessthan) {
710 if(adjsize > grep->lessthan)
711 keep = FALSE;
712 }
713 if(!keep)
714 return ret;
715 }
716
717 if(grep->newerthan || grep->olderthan) {
718
719 BOOL keep = TRUE;
720 ULONG numsecs;
721
722 numsecs = SecsSince1980(&f->fdateLastWrite,
723 &f->ftimeLastWrite);
724 if(grep->newerthan) {
725 if(numsecs < grep->newerthan)
726 keep = FALSE;
727 }
728 if(keep && grep->olderthan) {
729 if(numsecs > grep->olderthan)
730 keep = FALSE;
731 }
732 if(!keep)
733 return ret;
734 }
735
736 if((!grep->searchEAs && !grep->searchFiles) ||
737 !*grep->searchPattern) /* just a find */
738 return insert_grepfile(grep,filename,f);
739
740 if(grep->searchEAs) {
741
742 HOLDFEA *head,*info;
743 USHORT type,len;
744 BOOL alltext;
745 CHAR *data,temp;
746
747 head = GetFileEAs(filename,FALSE,TRUE);
748 if(head) {
749 info = head;
750 while(info && !strmatch) {
751 alltext = TRUE;
752 switch(*(USHORT *)info->value) {
753 case EAT_ASCII:
754 if(match(info->value + (sizeof(USHORT) * 2),
755 grep->searchPattern,grep->absFlag,
756 (grep->caseFlag == FALSE),
757 info->cbValue - (sizeof(USHORT) * 2),
758 grep->numlines,
759 grep->matched,
760 !grep->findifany)) {
761 Free_FEAList(head);
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 Free_FEAList(head);
784 strmatch = TRUE;
785 break;
786 }
787 data += len;
788 if(data - info->value >= info->cbValue)
789 break;
790 *data = temp;
791 len = *(USHORT *)data;
792 data += sizeof(USHORT);
793 }
794 }
795 break;
796 case EAT_MVMT:
797 data = info->value + (sizeof(USHORT) * 3);
798 type = *(USHORT *)data;
799 data += sizeof(USHORT);
800 len = *(USHORT *)data;
801 data += sizeof(USHORT);
802 while((data - info->value) - len <=
803 info->cbValue) {
804 if(type != EAT_ASCII) {
805 alltext = FALSE;
806 break;
807 }
808 data += len;
809 if(data - info->value >= info->cbValue)
810 break;
811 type = *(USHORT *)data;
812 data += sizeof(USHORT);
813 len = *(USHORT *)data;
814 data += sizeof(USHORT);
815 }
816 if(alltext) {
817 data = info->value + (sizeof(USHORT) * 3);
818 type = *(USHORT *)data;
819 data += sizeof(USHORT);
820 len = *(USHORT *)data;
821 data += sizeof(USHORT);
822 while((data - info->value) - len <=
823 info->cbValue) {
824 temp = *(data + len);
825 *(data + len) = 0;
826 if(match(data,
827 grep->searchPattern,
828 grep->absFlag,
829 (grep->caseFlag == FALSE),
830 len,
831 grep->numlines,
832 grep->matched,
833 !grep->findifany)) {
834 Free_FEAList(head);
835 strmatch = TRUE;
836 break;
837 }
838 data += len;
839 *data = temp;
840 if(data - info->value >= info->cbValue)
841 break;
842 type = *(USHORT *)data;
843 data += sizeof(USHORT);
844 len = *(USHORT *)data;
845 data += sizeof(USHORT);
846 }
847 }
848 break;
849 default:
850 break;
851 }
852 info = info->next;
853 }
854 Free_FEAList(head);
855 DosSleep(1L);
856 }
857 }
858
859 if(grep->searchFiles) {
860 input = malloc(65537);
861 if(input) {
862
863 LONG len;
864
865 if((inputFile = _fsopen(filename,"rb",SH_DENYNO)) != NULL) {
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 = malloc(65535);
997 if(buffer) {
998 fp = _fsopen(filename,"rb",SH_DENYNO);
999 if(fp) {
1000 while(!feof(fp)) {
1001 len = fread(buffer,1,65535,fp);
1002 if(len && len < 65536L)
1003 CRC = CRCBlock(buffer,len,CRC);
1004 else
1005 break;
1006 DosSleep(0L);
1007 }
1008 fclose(fp);
1009 DosSleep(1L);
1010 }
1011 else
1012 *error = -2;
1013 free(buffer);
1014 }
1015 else
1016 *error = -1;
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 = malloc(sizeof(DUPES *) * (x + 1));
1193 if(!g->nosizedupes)
1194 g->dupesizes = malloc(sizeof(DUPES *) * (x + 1));
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 DosBeep(50,100);
1385 WinSetWindowText(g->hwndCurFile,
1386 GetPString(IDS_GREPDUPECOMPARINGTEXT));
1387 x = y = 0L;
1388 if(g->dupenames) {
1389 free(g->dupenames);
1390 g->dupenames = NULL;
1391 }
1392 if(g->dupesizes) {
1393 free(g->dupesizes);
1394 g->dupesizes = NULL;
1395 }
1396 i = g->dupehead;
1397 while(i) {
1398 if(*g->stopflag)
1399 break;
1400 if(!(i->flags & GF_SKIPME)) {
1401 if(!(y % cntr)) {
1402
1403 CHAR s[44];
1404
1405 sprintf(s,
1406 GetPString(IDS_GREPDUPECHECKPROGTEXT),
1407 y,
1408 g->numfiles);
1409 WinSetWindowText(g->hwndCurFile,
1410 s);
1411 DosSleep(0L);
1412 }
1413 y++;
1414 pi = strrchr(i->name,'\\');
1415 if(pi)
1416 *pi++;
1417 else
1418 pi = i->name;
1419 c = g->dupehead;
1420 while(c) {
1421 if(*g->stopflag)
1422 break;
1423 if(c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
1424 x++;
1425 pc = strrchr(c->name,'\\');
1426 if(pc)
1427 pc++;
1428 else
1429 pc = c->name;
1430 if((!g->nosizedupes && i->size == c->size &&
1431 i->date.year == c->date.year &&
1432 i->date.month == c->date.month &&
1433 i->date.day == c->date.day &&
1434 i->time.hours == c->time.hours &&
1435 i->time.minutes == c->time.minutes &&
1436 i->time.twosecs == c->time.twosecs) ||
1437 !stricmp(pc,pi)) { /* potential dupe */
1438 if(g->CRCdupes) {
1439 if(g->CRCdupes) {
1440 if(c->CRC == -1L) {
1441 c->CRC = CRCFile(c->name,&error);
1442 if(error)
1443 c->CRC = -1L;
1444 else if(c->CRC == -1L)
1445 c->CRC = 0L;
1446 }
1447 if(i->CRC == -1L) {
1448 i->CRC = CRCFile(i->name,&error);
1449 if(error)
1450 i->CRC = -1L;
1451 else if(i->CRC == -1L)
1452 i->CRC = 0L;
1453 }
1454 if((c->size != i->size) || (c->CRC != -1L &&
1455 i->CRC != -1L && c->CRC != i->CRC)) {
1456 c = c->next;
1457 continue;
1458 }
1459 }
1460 }
1461 if(AddToList(c->name,
1462 &list,
1463 &numfiles,
1464 &numalloced))
1465 goto BreakOut;
1466 if(!(i->flags & GF_INSERTED)) {
1467 if(AddToList(i->name,
1468 &list,
1469 &numfiles,
1470 &numalloced))
1471 goto BreakOut;
1472 }
1473 if(g->sayfiles)
1474 WinSetWindowText(g->hwndCurFile,
1475 pc);
1476 c->flags |= GF_INSERTED;
1477 i->flags |= GF_INSERTED;
1478 if(!stricmp(pc,pi)) {
1479 c->flags |= GF_SKIPME;
1480 i->flags |= GF_SKIPME;
1481 }
1482 }
1483 else if(!(x % 100L))
1484 DosSleep(1L);
1485 }
1486 c = c->next;
1487 }
1488 }
1489 i = i->next;
1490 }
1491 }
1492 }
1493BreakOut:
1494 FreeDupes(g);
1495 if(numfiles && list) {
1496 if(!PostMsg(g->hwndFiles,
1497 WM_COMMAND,
1498 MPFROM2SHORT(IDM_COLLECTOR,0),
1499 MPFROMP(list)))
1500 FreeList(list);
1501 }
1502 else
1503 DosPostEventSem(CompactSem);
1504}
1505
1506
1507static BOOL InsertDupe (GREP *g,CHAR *dir,FILEFINDBUF4 *f)
1508{
1509 DUPES *info;
1510
1511 if(*dir) {
1512 info = malloc(sizeof(DUPES));
1513 if(info) {
1514 memset(info,0,sizeof(DUPES));
1515 info->name = strdup(dir);
1516 if(info->name) {
1517 info->size = f->cbFile;
1518 info->date = f->fdateLastWrite;
1519 info->time = f->ftimeLastWrite;
1520 info->CRC = -1L;
1521 g->numfiles++;
1522 if(!g->dupehead)
1523 g->dupehead = info;
1524 if(g->dupelast)
1525 g->dupelast->next = info;
1526 g->dupelast = info;
1527 info->next = NULL;
1528 return TRUE;
1529 }
1530 else
1531 free(info);
1532 }
1533 DosBeep(50,100);
1534 return FALSE;
1535 }
1536 return TRUE;
1537}
Note: See TracBrowser for help on using the repository browser.