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