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