Changeset 783 for trunk/dll/grep.c
- Timestamp:
- Aug 14, 2007, 6:09:54 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/grep.c
r775 r783 7 7 8 8 Copyright (c) 1993-98 M. Kimes 9 Copyright (c) 2001, 200 6Steven H. Levine9 Copyright (c) 2001, 2007 Steven H. Levine 10 10 11 11 12 Feb 03 SHL insert_grepfile: standardize EA math … … 21 21 03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading) 22 22 06 Aug 07 GKY Reduce DosSleep times (ticket 148) 23 23 13 Aug 07 SHL Avoid pointer errors; sanitize code 24 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat 24 25 25 26 ***********************************************************************/ … … 27 28 #define INCL_DOS 28 29 #define INCL_WIN 30 #define INCL_DOSERRORS 29 31 #define INCL_LONGLONG 30 32 #include <os2.h> … … 44 46 static PSZ pszSrcFile = __FILE__; 45 47 46 #pragma alloc_text(GREP,SecsSince1980,match,mmatch,GrepThread) 47 #pragma alloc_text(GREP,doallsubdirs,domatchingfiles) 48 49 /*****************************/ 50 /* Function Prototypes */ 51 /*****************************/ 52 53 static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing, 48 static VOID doallsubdirs(GREP *grep, CHAR *searchPath, BOOL recursing, 54 49 char **fle, int numfls); 55 static INT domatchingfiles(GREP * grep, CHAR *path, char **fle, int numfls);56 static BOOL doonefile(GREP * grep, CHAR * fileName, FILEFINDBUF4 * f);57 static BOOL doinsertion(GREP * 58 static BOOL InsertDupe(GREP * grep, CHAR * dir, FILEFINDBUF4 * f);59 static VOID FillDupes(GREP * g);60 static VOID FreeDupes(GREP * g);50 static INT domatchingfiles(GREP *grep, CHAR *path, char **fle, int numfls); 51 static BOOL doonefile(GREP *grep, CHAR *fileName, FILEFINDBUF4 *pffb); 52 static BOOL doinsertion(GREP *grep); 53 static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4 *pffb); 54 static VOID FillDupes(GREP *grep); 55 static VOID FreeDupes(GREP *grep); 61 56 62 57 #define GREPCHARS "*?[] \\" 63 58 64 59 #define isleap(year) ((((year%4)==0) && ((year%100)!=0)) || \ 65 60 ((year%400)==0)) 66 61 67 62 static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; … … 99 94 LONG len) 100 95 { 101 102 /* return TRUE if pattern found in string */ 103 96 // return TRUE if pattern found in string 104 97 register CHAR *tn = pattern; 105 98 register LONG len2 = 0; … … 108 101 109 102 if (len && string && pattern) { 110 if (absolute) / * no pattern matching */103 if (absolute) // no pattern matching 111 104 return (findstring(pattern, strlen(pattern), string, len, 112 105 (ignore == FALSE)) != NULL); … … 180 173 if (!*tn) 181 174 return FALSE; 182 / * else intentional fallthru */175 // else intentional fallthru 183 176 default: 184 177 if (ignore) { … … 217 210 LONG len, ULONG numlines, CHAR * matched, BOOL matchall) 218 211 { 219 220 212 BOOL ret = FALSE; 221 213 register CHAR *p; … … 229 221 if (matched && ret && x < numlines) 230 222 matched[x] = 1; 231 p += strlen(p); / * check each pattern in 0-terminated list */223 p += strlen(p); // check each pattern in 0-terminated list 232 224 p++; 233 225 x++; … … 245 237 CHAR *p, *pp, searchPath[CCHMAXPATH * 2]; 246 238 247 if (!arg) 239 if (!arg) { 240 Runtime_Error(pszSrcFile, __LINE__, "no data"); 248 241 return; 249 grep = *(GREP *) arg; 250 *grep.stopflag = 0; /* reset thread-killing flag */ 242 } 243 244 grep = *(GREP *)arg; 245 *grep.stopflag = 0; // reset thread-killing flag 251 246 grep.FilesToGet = FilesToGet; 252 247 DosError(FERR_DISABLEHARDERR); … … 268 263 while (*pp) { 269 264 if (!grep.absFlag) { 270 p = GREPCHARS; / * see if any sense in pattern matching */265 p = GREPCHARS; // see if any sense in pattern matching 271 266 while (*p) { 272 267 if (strchr(pp, *p)) … … 274 269 p++; 275 270 } 276 if (!*p) / * nope, turn it off */271 if (!*p) // nope, turn it off 277 272 grep.absFlag = TRUE; 278 273 } … … 300 295 } 301 296 302 while (x < numfls) { / * loop through search masks */303 304 if (*fle[x] == '/') / * is an exclude mask only */297 while (x < numfls) { // loop through search masks 298 299 if (*fle[x] == '/') // is an exclude mask only 305 300 goto ExcludeSkip; 306 301 307 / * first, separate any path from mask */302 // first, separate any path from mask 308 303 309 304 p = (char *)(fle[x] + (strlen(fle[x]) - 1)); … … 311 306 --p; 312 307 313 if (p == fle[x]) { / * no path */308 if (p == fle[x]) { // no path 314 309 strcpy(searchPath, grep.curdir); 315 310 strncpy(grep.fileMask, fle[x], CCHMAXPATH); 316 311 grep.fileMask[CCHMAXPATH - 1] = 0; 317 312 } 318 else { / * got to deal with a path */319 if (*p == ':') { / * just a drive, start in root dir */313 else { // got to deal with a path 314 if (*p == ':') { // just a drive, start in root dir 320 315 *p = 0; 321 316 p++; … … 325 320 strcpy(grep.fileMask, p); 326 321 } 327 if (*p == '\\') { / * got a 'full' path */322 if (*p == '\\') { // got a 'full' path 328 323 329 324 CHAR temp; … … 342 337 if (*grep.stopflag) 343 338 break; 344 / * do single directory */339 // do single directory 345 340 domatchingfiles(&grep, searchPath, fle, numfls); 346 if (grep.dirFlag) / * do subdirs */341 if (grep.dirFlag) // do subdirs 347 342 doallsubdirs(&grep, searchPath, FALSE, fle, numfls); 348 343 ExcludeSkip: … … 351 346 x++; 352 347 if (WinIsWindow(grep.ghab, grep.hwndFiles)) 353 doinsertion(&grep); / * insert any remaining objects */348 doinsertion(&grep); // insert any remaining objects 354 349 } // while 355 350 356 351 if (WinIsWindow(grep.ghab, grep.hwndFiles)) 357 doinsertion(&grep); / * insert any remaining objects */352 doinsertion(&grep); // insert any remaining objects 358 353 359 354 if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes && … … 361 356 FillDupes(&grep); 362 357 363 if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID)) / * tell window we're done */358 if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID)) // tell window we're done 364 359 WinSendMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID); 365 360 WinDestroyMsgQueue(ghmq); … … 379 374 static BOOL IsExcluded(char *name, char **fle, int numfls) 380 375 { 381 registerint x;376 int x; 382 377 char *n; 383 378 … … 401 396 char **fle, int numfls) 402 397 { 403 404 /* process all subdirectories */ 405 406 FILEFINDBUF4 findBuffer; 398 // process all subdirectories 399 400 FILEFINDBUF4 ffb; 407 401 HDIR findHandle = HDIR_CREATE; 408 LONG findCount = 1L;402 LONG ulFindCnt = 1; 409 403 CHAR *p = NULL; 410 404 411 / * add a mask to search path */405 // add a mask to search path 412 406 if (searchPath[strlen(searchPath) - 1] != '\\') 413 407 strcat(searchPath, "\\"); 414 408 strcat(searchPath, "*"); 415 / * step through all subdirectories */409 // step through all subdirectories 416 410 DosError(FERR_DISABLEHARDERR); 417 411 if (!DosFindFirst(searchPath, &findHandle, (MUST_HAVE_DIRECTORY | 418 412 FILE_ARCHIVED | FILE_SYSTEM | 419 413 FILE_HIDDEN | FILE_READONLY), 420 &f indBuffer, (ULONG) sizeof(findBuffer),421 (PULONG) & findCount, FIL_QUERYEASIZE)) {422 423 / * get rid of mask portion, save end-of-directory */414 &ffb, (ULONG) sizeof(ffb), 415 (PULONG) & ulFindCnt, FIL_QUERYEASIZE)) { 416 417 // get rid of mask portion, save end-of-directory 424 418 425 419 p = strrchr(searchPath, '\\'); … … 428 422 else 429 423 p = searchPath; 430 do { / * Process each directory that matches the mask */424 do { // Process each directory that matches the mask 431 425 priority_normal(); 432 426 if (*grep->stopflag) 433 427 break; 434 428 // Skip . and .. 435 if (f indBuffer.achName[0] != '.' ||436 (f indBuffer.achName[1] &&437 (f indBuffer.achName[1] != '.' || findBuffer.achName[2]))) {438 strcpy(p, f indBuffer.achName);429 if (ffb.achName[0] != '.' || 430 (ffb.achName[1] && 431 (ffb.achName[1] != '.' || ffb.achName[2]))) { 432 strcpy(p, ffb.achName); 439 433 if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) { 440 434 domatchingfiles(grep, searchPath, fle, numfls); … … 443 437 } 444 438 } 445 findCount = 1;439 ulFindCnt = 1; 446 440 } while (!DosFindNext(findHandle, 447 &f indBuffer,448 sizeof(f indBuffer), (PULONG) & findCount));441 &ffb, 442 sizeof(ffb), (PULONG) & ulFindCnt)); 449 443 DosFindClose(findHandle); 450 444 priority_normal(); 451 445 } 452 if (p) / * strip off last directory addition */446 if (p) // strip off last directory addition 453 447 *p = 0; 454 448 } … … 456 450 static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls) 457 451 { 458 / * process all matching files in a directory */459 460 PFILEFINDBUF4 findBuffer;452 // process all matching files in a directory 453 454 PFILEFINDBUF4 pffbArray; 461 455 PFILEFINDBUF4 pffbFile; 462 register PBYTE fb; 463 register ULONG x; 456 ULONG x; 464 457 HDIR findHandle = HDIR_CREATE; 465 ULONG findCount = grep->FilesToGet; 466 CHAR newPath[CCHMAXPATH], *p; 458 ULONG ulFindCnt; 459 CHAR szFindPath[CCHMAXPATH]; 460 PSZ p; 467 461 APIRET rc; 468 469 findBuffer = 470 xmalloc(grep->FilesToGet * sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);471 if (! findBuffer)462 ULONG ulBufBytes = grep->FilesToGet * sizeof(FILEFINDBUF4); 463 464 pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__); 465 if (!pffbArray) 472 466 return 0; 473 467 474 / * build filemask */475 476 sprintf(newPath,477 "%s%s%s",478 path,479 (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask);480 481 MakeFullName( newPath);482 483 / * find and save end-of-dir position */484 p = strrchr( newPath, '\\');468 // build filemask 469 BldFullPathName(szFindPath, path, grep->fileMask); 470 // sprintf(szFindPath, 471 // "%s%s%s", 472 // path, 473 // (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask); 474 475 MakeFullName(szFindPath); 476 477 // find and save end-of-dir position 478 p = strrchr(szFindPath, '\\'); 485 479 if (p) 486 480 p++; 487 481 else 488 p = newPath;489 490 / * step through matching files */482 p = szFindPath; 483 484 // step through matching files 491 485 DosError(FERR_DISABLEHARDERR); 492 if (!DosFindFirst(newPath, 486 ulFindCnt = grep->FilesToGet; 487 rc = DosFindFirst(szFindPath, 493 488 &findHandle, 494 (FILE_NORMAL | grep->attrFile | grep->antiattr), 495 findBuffer, 496 (ULONG) (grep->FilesToGet * sizeof(FILEFINDBUF4)), 497 (PULONG) & findCount, FIL_QUERYEASIZE)) { 498 499 do { /* Process each file that matches the mask */ 489 FILE_NORMAL | grep->attrFile | grep->antiattr, 490 pffbArray, 491 ulBufBytes, 492 &ulFindCnt, 493 FIL_QUERYEASIZE); 494 if (!rc) { 495 do { 496 // Process each file that matches the mask 500 497 priority_normal(); 501 fb = (PBYTE) findBuffer; 502 for (x = 0L; x < findCount; x++) { 503 pffbFile = (PFILEFINDBUF4) fb; 498 pffbFile = pffbArray; 499 for (x = 0; x < ulFindCnt; x++) { 504 500 if (*grep->stopflag) 505 501 break; 506 502 if (*pffbFile->achName != '.' || 507 503 (pffbFile->achName[1] && pffbFile->achName[1] != '.')) { 508 strcpy(p, pffbFile->achName); / * build filename */509 if (!grep->anyexcludes || !IsExcluded( newPath, fle, numfls)) {504 strcpy(p, pffbFile->achName); // build filename 505 if (!grep->anyexcludes || !IsExcluded(szFindPath, fle, numfls)) { 510 506 if (!grep->finddupes) 511 doonefile(grep, newPath, pffbFile);512 else if (!InsertDupe(grep, newPath, pffbFile)) {507 doonefile(grep, szFindPath, pffbFile); 508 else if (!InsertDupe(grep, szFindPath, pffbFile)) { 513 509 DosFindClose(findHandle); 514 free( findBuffer);510 free(pffbArray); 515 511 return 1; 516 512 } … … 519 515 if (!pffbFile->oNextEntryOffset) 520 516 break; 521 fb += pffbFile->oNextEntryOffset; 522 } 523 findCount = grep->FilesToGet; 524 rc = DosFindNext(findHandle, 525 findBuffer, 526 (ULONG) (grep->FilesToGet * sizeof(FILEFINDBUF4)), 527 (PULONG) & findCount); 528 if (!rc) 529 DosSleep(1); 517 pffbFile = (PFILEFINDBUF4)((PBYTE)pffbFile + pffbFile->oNextEntryOffset); 518 } // for 519 if (*grep->stopflag) 520 break; 521 DosSleep(1); 522 ulFindCnt = grep->FilesToGet; 523 rc = DosFindNext(findHandle, pffbArray, ulBufBytes, &ulFindCnt); 530 524 } while (!rc); 525 531 526 DosFindClose(findHandle); 532 527 priority_normal(); 533 } 534 free(findBuffer); 528 } // if 529 530 if (rc && rc != ERROR_NO_MORE_FILES) { 531 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, 532 GetPString(IDS_CANTFINDDIRTEXT), szFindPath); 533 } 534 535 free(pffbArray); 535 536 return 0; 536 537 } 537 538 538 #pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)539 540 539 static VOID freegreplist(GREP * grep) 541 540 { 542 registerINT x;541 INT x; 543 542 544 543 if (grep) { … … 607 606 } 608 607 609 static BOOL insert_grepfile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f) 610 { 611 CHAR *p, szDirectory[CCHMAXPATH]; 608 static BOOL insert_grepfile(GREP *grep, CHAR *filename, PFILEFINDBUF4 pffb) 609 { 610 PSZ p; 611 CHAR szDirectory[CCHMAXPATH]; 612 612 613 613 if (WinIsWindow(grep->ghab, grep->hwndFiles)) { … … 620 620 *p = 0; 621 621 if (!grep->insertffb) { 622 grep->insertffb = xmallocz(sizeof(FILEFINDBUF4 *) * 623 (grep->FilesToGet + 1), pszSrcFile, 624 __LINE__); 622 // Allocate 1 extra for end marker? 623 grep->insertffb = 624 xmallocz(sizeof(PFILEFINDBUF4) * (grep->FilesToGet + 1), 625 pszSrcFile, __LINE__); 625 626 if (!grep->insertffb) 626 627 return FALSE; 627 628 grep->dir = 628 xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1), pszSrcFile,629 __LINE__);629 xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1), 630 pszSrcFile, __LINE__); 630 631 if (!grep->dir) { 631 632 free(grep->insertffb); … … 637 638 if (!grep->insertffb[grep->toinsert]) 638 639 return FALSE; 639 memcpy(grep->insertffb[grep->toinsert], f, sizeof(FILEFINDBUF4));640 memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4)); 640 641 grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__); 641 642 if (!grep->dir) { … … 643 644 return FALSE; 644 645 } 645 grep->insertedbytes += f->cbFile + CBLIST_TO_EASIZE(f->cbList);646 grep->insertedbytes += pffb->cbFile + CBLIST_TO_EASIZE(pffb->cbList); 646 647 grep->toinsert++; 647 648 if (grep->toinsert == grep->FilesToGet) … … 655 656 } 656 657 657 static BOOL doonefile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f) 658 { 659 /* process a single file */ 660 658 static BOOL doonefile(GREP *grep, CHAR *filename, FILEFINDBUF4 * pffb) 659 { 660 // process a single file 661 661 CHAR *input; 662 662 FILE *inputFile; … … 673 673 ULONG adjsize; 674 674 675 adjsize = f->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(f->cbList) : 0);675 adjsize = pffb->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(pffb->cbList) : 0); 676 676 if (grep->greaterthan) { 677 677 if (adjsize < grep->greaterthan) … … 691 691 ULONG numsecs; 692 692 693 numsecs = SecsSince1980(& f->fdateLastWrite, &f->ftimeLastWrite);693 numsecs = SecsSince1980(&pffb->fdateLastWrite, &pffb->ftimeLastWrite); 694 694 if (grep->newerthan) { 695 695 if (numsecs < grep->newerthan) … … 704 704 } 705 705 706 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) / * just a find */707 return insert_grepfile(grep, filename, f);706 if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern) // just a find 707 return insert_grepfile(grep, filename, pffb); 708 708 709 709 if (grep->searchEAs) { … … 849 849 850 850 if (strmatch) 851 ret = insert_grepfile(grep, filename, f);851 ret = insert_grepfile(grep, filename, pffb); 852 852 return ret; 853 853 } 854 854 855 #pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock) 856 #pragma alloc_text(DUPES,comparenamesq,comparenamesqe,comparenamesb) 857 #pragma alloc_text(DUPES,comparenamesbe,comparesizesq,comparesizesb) 858 859 static LONG cr3tab[] = { /* CRC polynomial 0xEDB88320 */ 855 static LONG cr3tab[] = { // CRC polynomial 0xEDB88320 860 856 861 857 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, … … 966 962 } 967 963 968 static VOID FreeDupes(GREP * g)964 static VOID FreeDupes(GREP *grep) 969 965 { 970 966 DUPES *i, *next; 971 967 972 i = g ->dupehead;968 i = grep->dupehead; 973 969 while (i) { 974 970 next = i->next; … … 978 974 i = next; 979 975 } 980 g ->dupehead = g->dupelast = NULL;981 if (g ->dupenames)982 free(g ->dupenames);983 if (g ->dupesizes)984 free(g ->dupesizes);985 g ->dupesizes = g->dupenames = NULL;976 grep->dupehead = grep->dupelast = NULL; 977 if (grep->dupenames) 978 free(grep->dupenames); 979 if (grep->dupesizes) 980 free(grep->dupesizes); 981 grep->dupesizes = grep->dupenames = NULL; 986 982 } 987 983 … … 1110 1106 } 1111 1107 1112 static VOID FillDupes(GREP * g )1108 static VOID FillDupes(GREP * grep) 1113 1109 { 1114 1110 DUPES *c, *i, **r; … … 1119 1115 ULONG cntr = 100; 1120 1116 1121 if (g ->CRCdupes)1117 if (grep->CRCdupes) 1122 1118 cntr = 50; 1123 i = g ->dupehead;1119 i = grep->dupehead; 1124 1120 while (i) { 1125 1121 x++; … … 1127 1123 } 1128 1124 if (x) { 1129 WinSetWindowText(g ->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));1125 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT)); 1130 1126 DosSleep(1); 1131 g ->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);1132 if (!g ->nosizedupes)1133 g ->dupesizes = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);1134 if (g ->dupenames && (g->nosizedupes || g->dupesizes)) {1135 i = g ->dupehead;1127 grep->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__); 1128 if (!grep->nosizedupes) 1129 grep->dupesizes = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__); 1130 if (grep->dupenames && (grep->nosizedupes || grep->dupesizes)) { 1131 i = grep->dupehead; 1136 1132 while (i) { 1137 g ->dupenames[y] = i;1138 if (!g ->nosizedupes)1139 g ->dupesizes[y] = i;1133 grep->dupenames[y] = i; 1134 if (!grep->nosizedupes) 1135 grep->dupesizes[y] = i; 1140 1136 i = i->next; 1141 1137 y++; 1142 1138 } 1143 g ->dupenames[y] = NULL;1144 if (!g ->nosizedupes)1145 g ->dupesizes[y] = NULL;1139 grep->dupenames[y] = NULL; 1140 if (!grep->nosizedupes) 1141 grep->dupesizes[y] = NULL; 1146 1142 DosSleep(1); 1147 qsort(g ->dupenames,1143 qsort(grep->dupenames, 1148 1144 x, 1149 1145 sizeof(DUPES *), 1150 ((g ->ignoreextdupes) ? comparenamesqe : comparenamesq));1146 ((grep->ignoreextdupes) ? comparenamesqe : comparenamesq)); 1151 1147 DosSleep(1); 1152 if (!g ->nosizedupes) {1153 qsort(g ->dupesizes, x, sizeof(DUPES *), comparesizesq);1148 if (!grep->nosizedupes) { 1149 qsort(grep->dupesizes, x, sizeof(DUPES *), comparesizesq); 1154 1150 DosSleep(1); 1155 1151 } 1156 WinSetWindowText(g ->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));1157 1158 i = g ->dupehead;1152 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1153 1154 i = grep->dupehead; 1159 1155 y = 0; 1160 1156 while (i) { 1161 if (*g ->stopflag)1157 if (*grep->stopflag) 1162 1158 break; 1163 1159 if (!(i->flags & GF_SKIPME)) { 1164 r = (DUPES **) bsearch(i, g ->dupenames, x, sizeof(DUPES *),1165 ((g ->ignoreextdupes) ? comparenamesbe :1160 r = (DUPES **) bsearch(i, grep->dupenames, x, sizeof(DUPES *), 1161 ((grep->ignoreextdupes) ? comparenamesbe : 1166 1162 comparenamesb)); 1167 1163 if (r) { 1168 while (r > g ->dupenames && ((g->ignoreextdupes) ?1164 while (r > grep->dupenames && ((grep->ignoreextdupes) ? 1169 1165 !comparenamesqe((r - 1), &i) : 1170 1166 !comparenamesq((r - 1), &i))) 1171 1167 r--; 1172 while (*r && ((g ->ignoreextdupes) ?1168 while (*r && ((grep->ignoreextdupes) ? 1173 1169 !comparenamesqe(r, &i) : !comparenamesq(r, &i))) { 1174 1170 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) { … … 1176 1172 continue; 1177 1173 } 1178 if (g ->CRCdupes) {1174 if (grep->CRCdupes) { 1179 1175 if ((*r)->CRC == -1L) { 1180 1176 (*r)->CRC = CRCFile((*r)->name, &error); … … 1200 1196 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) { 1201 1197 (*r)->flags |= GF_INSERTED; 1202 if (g ->sayfiles)1203 WinSetWindowText(g ->hwndFiles, (*r)->name);1198 if (grep->sayfiles) 1199 WinSetWindowText(grep->hwndFiles, (*r)->name); 1204 1200 if ((*r)->size == i->size && 1205 1201 (i->date.year == (*r)->date.year && … … 1221 1217 } 1222 1218 } 1223 if (!g ->nosizedupes) {1219 if (!grep->nosizedupes) { 1224 1220 r = (DUPES **) bsearch(i, 1225 g ->dupesizes,1221 grep->dupesizes, 1226 1222 x, sizeof(DUPES *), comparesizesb); 1227 1223 if (r) { 1228 while (r > g ->dupesizes && !comparesizesq((r - 1), &i))1224 while (r > grep->dupesizes && !comparesizesq((r - 1), &i)) 1229 1225 r--; 1230 1226 while (*r && !comparesizesq(r, &i)) { … … 1239 1235 continue; 1240 1236 } 1241 if (g ->CRCdupes) {1237 if (grep->CRCdupes) { 1242 1238 if ((*r)->CRC == -1L) { 1243 1239 (*r)->CRC = CRCFile((*r)->name, &error); … … 1261 1257 } 1262 1258 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) { 1263 if (g ->sayfiles)1264 WinSetWindowText(g ->hwndCurFile, (*r)->name);1259 if (grep->sayfiles) 1260 WinSetWindowText(grep->hwndCurFile, (*r)->name); 1265 1261 (*r)->flags |= GF_INSERTED; 1266 if (((g ->ignoreextdupes) ?1262 if (((grep->ignoreextdupes) ? 1267 1263 comparenamesqe(r, &i) : comparenamesq(r, &i))) 1268 1264 (*r)->flags |= GF_SKIPME; … … 1286 1282 CHAR s[44]; 1287 1283 1288 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g ->numfiles);1289 WinSetWindowText(g ->hwndCurFile, s);1290 DosSleep(100); 1284 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles); 1285 WinSetWindowText(grep->hwndCurFile, s); 1286 DosSleep(100); //05 Aug 07 GKY 128 1291 1287 } 1292 1288 DosSleep(y % 2); … … 1296 1292 // Insufficient memory - fall back 1297 1293 DosBeep(50, 100); 1298 WinSetWindowText(g ->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));1294 WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT)); 1299 1295 x = y = 0; 1300 if (g ->dupenames) {1301 free(g ->dupenames);1302 g ->dupenames = NULL;1296 if (grep->dupenames) { 1297 free(grep->dupenames); 1298 grep->dupenames = NULL; 1303 1299 } 1304 if (g ->dupesizes) {1305 free(g ->dupesizes);1306 g ->dupesizes = NULL;1300 if (grep->dupesizes) { 1301 free(grep->dupesizes); 1302 grep->dupesizes = NULL; 1307 1303 } 1308 i = g ->dupehead;1304 i = grep->dupehead; 1309 1305 while (i) { 1310 if (*g ->stopflag)1306 if (*grep->stopflag) 1311 1307 break; 1312 1308 if (!(i->flags & GF_SKIPME)) { … … 1315 1311 CHAR s[44]; 1316 1312 1317 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g ->numfiles);1318 WinSetWindowText(g ->hwndCurFile, s);1313 sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles); 1314 WinSetWindowText(grep->hwndCurFile, s); 1319 1315 DosSleep(1); 1320 1316 } … … 1325 1321 else 1326 1322 pi = i->name; 1327 c = g ->dupehead;1323 c = grep->dupehead; 1328 1324 while (c) { 1329 if (*g ->stopflag)1325 if (*grep->stopflag) 1330 1326 break; 1331 1327 if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) { … … 1336 1332 else 1337 1333 pc = c->name; 1338 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 */1339 if (g ->CRCdupes) {1340 if (g ->CRCdupes) {1334 if ((!grep->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 1335 if (grep->CRCdupes) { 1336 if (grep->CRCdupes) { 1341 1337 if (c->CRC == -1L) { 1342 1338 c->CRC = CRCFile(c->name, &error); … … 1367 1363 goto BreakOut; // Failed 1368 1364 } 1369 if (g ->sayfiles)1370 WinSetWindowText(g ->hwndCurFile, pc);1365 if (grep->sayfiles) 1366 WinSetWindowText(grep->hwndCurFile, pc); 1371 1367 c->flags |= GF_INSERTED; 1372 1368 i->flags |= GF_INSERTED; … … 1387 1383 } 1388 1384 BreakOut: 1389 FreeDupes(g );1385 FreeDupes(grep); 1390 1386 if (numfiles && list) { 1391 if (!PostMsg(g ->hwndFiles,1387 if (!PostMsg(grep->hwndFiles, 1392 1388 WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list))) 1393 1389 FreeList(list); … … 1397 1393 } 1398 1394 1399 static BOOL InsertDupe(GREP * g, CHAR * dir, FILEFINDBUF4 * f)1395 static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4 *pffb) 1400 1396 { 1401 1397 DUPES *info; … … 1405 1401 if (!info) 1406 1402 return FALSE; 1407 else { 1408 info->name = xstrdup(dir, pszSrcFile, __LINE__); 1409 if (!info->name) { 1410 free(info); 1411 return FALSE; 1412 } 1413 else { 1414 info->size = f->cbFile; 1415 info->date = f->fdateLastWrite; 1416 info->time = f->ftimeLastWrite; 1417 info->CRC = -1L; 1418 g->numfiles++; 1419 if (!g->dupehead) 1420 g->dupehead = info; 1421 if (g->dupelast) 1422 g->dupelast->next = info; 1423 g->dupelast = info; 1424 info->next = NULL; 1425 } 1426 } 1403 1404 info->name = xstrdup(dir, pszSrcFile, __LINE__); 1405 if (!info->name) { 1406 free(info); 1407 return FALSE; 1408 } 1409 1410 info->size = pffb->cbFile; 1411 info->date = pffb->fdateLastWrite; 1412 info->time = pffb->ftimeLastWrite; 1413 info->CRC = -1L; 1414 grep->numfiles++; 1415 if (!grep->dupehead) 1416 grep->dupehead = info; 1417 if (grep->dupelast) 1418 grep->dupelast->next = info; 1419 grep->dupelast = info; 1420 info->next = NULL; 1427 1421 } 1428 1422 return TRUE; 1429 1423 } 1424 1425 #pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist) 1426 #pragma alloc_text(GREP,SecsSince1980,match,mmatch,GrepThread) 1427 #pragma alloc_text(GREP,doallsubdirs,domatchingfiles,InsertDupes,FreeDupes) 1428 1429 #pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock) 1430 #pragma alloc_text(DUPES,comparenamesq,comparenamesqe,comparenamesb) 1431 #pragma alloc_text(DUPES,comparenamesbe,comparesizesq,comparesizesb)
Note:
See TracChangeset
for help on using the changeset viewer.