source: trunk/dll/grep.c@ 536

Last change on this file since 536 was 528, checked in by root, 19 years ago

Count thread usage

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