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