Changeset 948 for trunk/dll/grep.c


Ignore:
Timestamp:
Feb 12, 2008, 6:20:47 AM (18 years ago)
Author:
Steven Levine
Message:

Rework collector progress reporting and improve performance (ticket #79)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/grep.c

    r907 r948  
    99  Copyright (c) 2001, 2008 Steven H. Levine
    1010
    11   12 Feb 03 SHL insert_grepfile: standardize EA math
     11  12 Feb 03 SHL InsertGrepFile: standardize EA math
    1212  12 Feb 03 SHL doonefile: standardize EA math
    1313  25 May 05 SHL Rework for ULONGLONG
     
    2727  26 Aug 07 GKY DosSleep(1) in loops changed to (0)
    2828  21 Sep 07 GKY Fix trap on search that includes filenames that exceed maxpath
     29  07 Feb 08 SHL Use ITIMER_DESC to control sleeps and reporting
    2930
    3031***********************************************************************/
     
    4748#include "errutil.h"                    // Dos_Error...
    4849#include "strutil.h"                    // GetPString
     50#include "tmrsvcs.h"                    // ITIMER_DESC
    4951#include "fm3dll.h"
    5052
     
    5355static PSZ pszSrcFile = __FILE__;
    5456
    55 static VOID doallsubdirs(GREP *grep, CHAR *searchPath, BOOL recursing,
    56                          char **fle, int numfls);
    57 static INT domatchingfiles(GREP *grep, CHAR *path, char **fle, int numfls);
    58 static BOOL doonefile(GREP *grep, CHAR *fileName, FILEFINDBUF4L *pffb);
    59 static BOOL doinsertion(GREP *grep);
     57static VOID DoAllSubdirs(GREP *grep,
     58                         CHAR *searchPath,
     59                         BOOL recursing,
     60                         char **fle,
     61                         UINT numfls,
     62                         ITIMER_DESC *pitdSleep,
     63                         ITIMER_DESC *pitdReport);
     64static INT DoMatchingFiles(GREP *grep,
     65                           CHAR *path,
     66                           CHAR **fle,
     67                           UINT numfls,
     68                           ITIMER_DESC *pitdSleep,
     69                           ITIMER_DESC *pitdReport);
     70static BOOL DoOneFile(GREP *grep,
     71                      CHAR *fileName,
     72                      FILEFINDBUF4L *pffb,
     73                      ITIMER_DESC *pitdSleep,
     74                      ITIMER_DESC *pitdReport);
     75static BOOL DoInsertion(GREP *grep,
     76                        ITIMER_DESC *pitdSleep,
     77                        ITIMER_DESC *pitdReport);
    6078static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4L *pffb);
    61 static VOID FillDupes(GREP *grep);
     79static VOID FillDupes(GREP *grep,
     80                      ITIMER_DESC *pitdSleep,
     81                      ITIMER_DESC *pitdReport);
     82
    6283static VOID FreeDupes(GREP *grep);
    6384
     
    6990static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    7091
    71 ULONG SecsSince1980(FDATE * date, FTIME * time)
     92ULONG SecsSince1980(FDATE *date, FTIME *time)
    7293{
    7394  ULONG total = 0;
    74   register int x;
     95  UINT x;
    7596
    7697  for (x = 1980; x < date->year + 1980; x++) {
     
    98119 */
    99120
    100 static BOOL m_match(CHAR * string, CHAR * pattern, BOOL absolute, BOOL ignore,
     121static BOOL m_match(CHAR *string, CHAR *pattern, BOOL absolute, BOOL ignore,
    101122                    LONG len)
    102123{
     
    214235}
    215236
    216 static BOOL match(CHAR * string, CHAR * patterns, BOOL absolute, BOOL ignore,
    217                   LONG len, ULONG numlines, CHAR * matched, BOOL matchall)
     237static BOOL match(CHAR *string, CHAR *patterns, BOOL absolute, BOOL ignore,
     238                  LONG len, ULONG numlines, CHAR *matched, BOOL matchall)
    218239{
    219240  BOOL ret = FALSE;
     
    235256}
    236257
    237 VOID GrepThread(VOID * arg)
     258VOID GrepThread(VOID *arg)
    238259{
    239260  HAB ghab;
    240261  HMQ ghmq;
    241262  GREP grep;
    242   register INT x, numfls;
    243   static CHAR *fle[512];
     263  UINT x;
     264  UINT numfls;
     265  static CHAR *fle[512];                // 06 Feb 08 SHL fixme to not be static
    244266  CHAR *p, *pp, searchPath[CCHMAXPATH * 2];
     267
     268  ITIMER_DESC itdSleep = { 0 };         // 06 Feb 08 SHL
     269  ITIMER_DESC itdReport = { 0 };
    245270
    246271  if (!arg) {
     
    261286      WinCancelShutdown(ghmq, TRUE);
    262287      IncrThreadUsage();
    263       DosSleep(100); //05 Aug 07 GKY 128
    264       WinSetWindowText(grep.hwndCurFile,
    265                        GetPString((grep.finddupes) ?
    266                                   IDS_GREPDUPETEXT : IDS_GREPSCANTEXT));
     288      // DosSleep(100); //05 Aug 07 GKY 128     // 07 Feb 08 SHL
     289      // hwndStatus does not exist for applet
     290      WinSetWindowText(hwndStatus ? hwndStatus : grep.hwndCurFile,
     291                       GetPString(grep.finddupes ? IDS_GREPDUPETEXT :
     292                                                   IDS_GREPSCANTEXT));
    267293
    268294      pp = grep.searchPattern;
     
    293319
    294320      grep.anyexcludes = FALSE;
    295       numfls = x = 0;
     321      numfls = 0;
    296322      fle[numfls++] = strtok(grep.tosearch, ";");
     323
    297324      while ((fle[numfls] = strtok(NULL, ";")) != NULL && numfls < 511) {
    298325        if (*fle[numfls] == '/')
     
    301328      }
    302329
    303       while (x < numfls) {              // loop through search masks
     330      InitITimer(&itdSleep, 500);       // Sleep every 500 mSec
     331      InitITimer(&itdReport, 2000);     // Report every 2 sec
     332
     333      // loop through search masks
     334      for (x = 0; x < numfls; x++) {
    304335
    305336        if (*fle[x] == '/')             // is an exclude mask only
     
    326357            strcpy(grep.fileMask, p);
    327358          }
    328           if (*p == '\\') {             // got a 'full' path
    329 
     359          if (*p == '\\') {
     360            // got a 'full' path
    330361            CHAR temp;
    331362
     
    344375          break;
    345376        // do single directory
    346         domatchingfiles(&grep, searchPath, fle, numfls);
     377        DoMatchingFiles(&grep, searchPath, fle, numfls, &itdSleep, &itdReport);
    347378        if (grep.dirFlag)               // do subdirs
    348           doallsubdirs(&grep, searchPath, FALSE, fle, numfls);
     379          DoAllSubdirs(&grep, searchPath, FALSE, fle, numfls, &itdSleep, &itdReport);
    349380      ExcludeSkip:
    350381        if (*grep.stopflag)
    351382          break;
    352         x++;
    353383        if (WinIsWindow(grep.ghab, grep.hwndFiles))
    354           doinsertion(&grep);           // insert any remaining objects
    355       } // while
     384          DoInsertion(&grep, &itdSleep, &itdReport);    // insert any remaining objects
     385      } // for
    356386
    357387      if (WinIsWindow(grep.ghab, grep.hwndFiles))
    358         doinsertion(&grep);             // insert any remaining objects
    359 
    360       if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes &&
     388        DoInsertion(&grep, &itdSleep, &itdReport);      // insert any remaining objects
     389
     390      if (WinIsWindow(grep.ghab, grep.hwndFiles) &&
     391          grep.finddupes &&
    361392          !*grep.stopflag)
    362         FillDupes(&grep);
     393      {
     394        FillDupes(&grep, &itdSleep, &itdReport);
     395      }
    363396
    364397      if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID))        // tell window we're done
     
    375408  if (grep.numlines && grep.matched)
    376409    free(grep.matched);
     410  // 07 Feb 08 SHL fixme to free grep here when not static
    377411  DosPostEventSem(CompactSem);
    378412}
    379413
    380 static BOOL IsExcluded(char *name, char **fle, int numfls)
    381 {
    382   int x;
    383   char *n;
     414static BOOL IsExcluded(CHAR *name, CHAR **fle, UINT numfls)
     415{
     416  UINT x;
     417  CHAR *n;
    384418
    385419  n = strrchr(name, '\\');
     
    399433}
    400434
    401 static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing,
    402                          char **fle, int numfls)
     435static VOID DoAllSubdirs(GREP *grep,
     436                         CHAR *searchPath,
     437                         BOOL recursing,
     438                         CHAR **fle,
     439                         UINT numfls,
     440                         ITIMER_DESC *pitdSleep,
     441                         ITIMER_DESC *pitdReport)
    403442{
    404443  // process all subdirectories
     
    437476        strcpy(p, ffb.achName);
    438477        if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) {
    439           domatchingfiles(grep, searchPath, fle, numfls);
    440           doallsubdirs(grep, searchPath, TRUE, fle, numfls);
    441           DosSleep(0); //26 Aug 07 GKY 1
     478          // 07 Feb 08 SHL
     479          if (IsITimerExpired(pitdReport)) {
     480            if (!hwndStatus)
     481              WinSetWindowText(grep->hwndCurFile, searchPath);
     482            else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) {
     483              CHAR s[CCHMAXPATH + 64];
     484              sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), searchPath);
     485              WinSetWindowText(hwndStatus, s);
     486            }
     487          }
     488          DoMatchingFiles(grep, searchPath, fle, numfls, pitdSleep, pitdReport);
     489          // 07 Feb 08 SHL
     490          if (IsITimerExpired(pitdReport)) {
     491            if (!hwndStatus)
     492              WinSetWindowText(grep->hwndCurFile, searchPath);
     493            else {
     494              if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) {
     495                CHAR s[CCHMAXPATH + 64];
     496                sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), searchPath);
     497                WinSetWindowText(hwndStatus, s);
     498              }
     499            }
     500          }
     501          DoAllSubdirs(grep, searchPath, TRUE, fle, numfls, pitdSleep, pitdReport);
     502          // DosSleep(0); //26 Aug 07 GKY 1     // 07 Feb 08 SHL
    442503        }
    443504      }
     
    453514}
    454515
    455 static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls)
     516/**
     517 * Scan for files matching filespecs in single directory
     518 */
     519
     520static INT DoMatchingFiles(GREP *grep,
     521                           CHAR *path,
     522                           CHAR **fle,
     523                           UINT numfls,
     524                           ITIMER_DESC *pitdSleep,
     525                           ITIMER_DESC *pitdReport)
    456526{
    457527  // process all matching files in a directory
     
    473543    return 0;
    474544
    475   // build filemask
    476545  BldFullPathName(szFindPath, path, grep->fileMask);
    477   // sprintf(szFindPath,
    478   //      "%s%s%s",
    479   //      path,
    480   //      (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask);
    481546
    482547  MakeFullName(szFindPath);
     
    508573          break;
    509574        if (*pffbFile->achName != '.' ||
    510             (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
    511           strcpy(p, pffbFile->achName); // build filename
    512           if (strlen(szFindPath) > CCHMAXPATH){   //21 Sep GKY check for pathnames that exceed maxpath
    513             DosFindClose(findHandle);
    514             free(pffbArray);
    515             if (!fDone) {
    516               fDone = TRUE;
    517               saymsg(MB_OK | MB_ICONASTERISK,
    518                      HWND_DESKTOP,
     575            (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
     576          strcpy(p, pffbFile->achName); // build filename
     577          if (strlen(szFindPath) > CCHMAXPATH){
     578            // Complain if pathnames exceeds max
     579            DosFindClose(findHandle);
     580            free(pffbArray);
     581            if (!fDone) {
     582              fDone = TRUE;
     583              saymsg(MB_OK | MB_ICONASTERISK,
     584                     HWND_DESKTOP,
    519585                     GetPString(IDS_WARNINGTEXT),
    520                      "One or more of your files has a full path name that exceeds the OS/2 maximum");
    521             }
     586                     "One or more of your files has a full path name that exceeds the OS/2 maximum");
     587            }
    522588            return 1;
    523           }
     589          }
     590
     591          // 07 Feb 08 SHL
     592          if (IsITimerExpired(pitdReport)) {
     593            if (!hwndStatus)
     594              WinSetWindowText(grep->hwndCurFile, szFindPath);
     595            else {
     596              if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles) {
     597                CHAR s[CCHMAXPATH + 64];
     598                sprintf(s, "%s %s", GetPString(IDS_SCANNINGTEXT), szFindPath);
     599                WinSetWindowText(hwndStatus, s);
     600              }
     601            }
     602          }
     603
    524604          if (!grep->anyexcludes || !IsExcluded(szFindPath, fle, numfls)) {
    525605            if (!grep->finddupes)
    526               doonefile(grep, szFindPath, pffbFile);
     606              DoOneFile(grep, szFindPath, pffbFile, pitdSleep, pitdReport);
    527607            else if (!InsertDupe(grep, szFindPath, pffbFile)) {
    528608              DosFindClose(findHandle);
     
    538618      if (*grep->stopflag)
    539619        break;
    540       DosSleep(0); //26 Aug 07 GKY 1
     620      SleepIfNeeded(pitdSleep, 1);
     621      // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL
    541622      ulFindCnt = FilesToGet;
    542623      rc = xDosFindNext(findHandle, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
     
    556637}
    557638
    558 static VOID freegreplist(GREP * grep)
    559 {
    560   INT x;
     639static VOID freegreplist(GREP *grep)
     640{
     641  UINT x;
    561642
    562643  if (grep) {
     
    578659}
    579660
    580 static BOOL doinsertion(GREP * grep)
     661/**
     662 * Insert record into container
     663 */
     664
     665static BOOL DoInsertion(GREP *grep,
     666                        ITIMER_DESC *pitdSleep,
     667                        ITIMER_DESC *pitdReport)
    581668{
    582669  RECORDINSERT ri;
    583670  DIRCNRDATA *dcd;
    584671  PCNRITEM pci, pciFirst;
    585   INT x;
     672  UINT x;
    586673
    587674  if (!grep || !grep->toinsert || !grep->insertffb || !grep->dir)
    588675    return FALSE;
     676
    589677  pci = WinSendMsg(grep->hwndFiles,
    590678                   CM_ALLOCRECORD,
    591679                   MPFROMLONG(EXTRA_RECORD_BYTES),
    592680                   MPFROMLONG(grep->toinsert));
    593   // 04 Jan 08 SHL fixme to complain if CM_ALLOCRECORD fails
    594   if (pci) {
    595     // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
    596     if (grep->sayfiles)
    597       WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT));
     681  if (!pci) {
     682    Win_Error(grep->hwndFiles, grep->hwndFiles, pszSrcFile, __LINE__,
     683              "CM_ALLOCRECORD %u failed", grep->toinsert);
     684  }
     685  else {
     686    if (grep->sayfiles) {
     687      if (!hwndStatus)
     688        WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT));
     689      else {
     690        if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     691          WinSetWindowText(hwndStatus, GetPString(IDS_GREPINSERTINGTEXT));
     692      }
     693    }
    598694    pciFirst = pci;
    599695    dcd = INSTDATA(grep->hwndFiles);
     
    602698                          pci, grep->dir[x], grep->insertffb[x], FALSE, dcd);
    603699      pci = (PCNRITEM) pci->rc.preccNextRecord;
    604     }
     700      SleepIfNeeded(pitdSleep, 1);
     701    } // for
    605702    memset(&ri, 0, sizeof(RECORDINSERT));
    606703    ri.cb = sizeof(RECORDINSERT);
     
    617714      DosExitCritSec();
    618715    }
    619     if (grep->toinsert == FilesToGet)
    620       DosSleep(0);  //26 Aug 07 GKY 1
     716    SleepIfNeeded(pitdSleep, 1);
     717    // if (grep->toinsert == FilesToGet)        // 07 Feb 08 SHL
     718    //  DosSleep(0);  //26 Aug 07 GKY 1 // 07 Feb 08 SHL
    621719    freegreplist(grep);
    622720    PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID);
     
    627725}
    628726
    629 static BOOL insert_grepfile(GREP *grep, CHAR *filename, PFILEFINDBUF4L pffb)
     727/**
     728 * Insert file ffb and directory name into lists
     729 */
     730
     731static BOOL InsertGrepFile(GREP *grep,
     732                           CHAR *pszFileName,
     733                           PFILEFINDBUF4L pffb,
     734                           ITIMER_DESC *pitdSleep,
     735                           ITIMER_DESC *pitdReport)
    630736{
    631737  PSZ p;
    632738  CHAR szDirectory[CCHMAXPATH];
    633739
    634   if (WinIsWindow(grep->ghab, grep->hwndFiles)) {
     740  if (!WinIsWindow(grep->ghab, grep->hwndFiles)) {
     741    // Window closed - clean up and go away
     742    freegreplist(grep);
     743  }
     744  else {
    635745    grep->numfiles++;
    636     strcpy(szDirectory, filename);
     746    strcpy(szDirectory, pszFileName);
    637747    p = strrchr(szDirectory, '\\');
     748
    638749    if (p) {
     750      // Got directory
    639751      if (p < szDirectory + 4)
    640         p++;
     752        p++;                            // Include root backslash
    641753      *p = 0;
     754
    642755      if (!grep->insertffb) {
    643756        // Allocate 1 extra for end marker?
     
    653766        }
    654767      }
     768
    655769      grep->insertffb[grep->toinsert] =
    656770        xmalloc(sizeof(FILEFINDBUF4L), pszSrcFile, __LINE__);
     
    658772        return FALSE;
    659773      memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4L));
     774
    660775      grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__);
    661776      if (!grep->dir) {
     
    663778        return FALSE;
    664779      }
     780
    665781      grep->insertedbytes += pffb->cbFile + CBLIST_TO_EASIZE(pffb->cbList);
    666782      grep->toinsert++;
    667783      if (grep->toinsert == FilesToGet)
    668         return doinsertion(grep);
     784        return DoInsertion(grep, pitdSleep, pitdReport);
    669785      return TRUE;
    670786    }
    671787  }
    672   else
    673     freegreplist(grep);
    674788  return FALSE;
    675789}
    676790
    677 static BOOL doonefile(GREP *grep, CHAR *filename, FILEFINDBUF4L * pffb)
     791/**
     792 * Check file matches search criteria
     793 */
     794
     795static BOOL DoOneFile(GREP *grep,
     796                      CHAR *pszFileName,
     797                      FILEFINDBUF4L *pffb,
     798                      ITIMER_DESC *pitdSleep,
     799                      ITIMER_DESC *pitdReport)
    678800{
    679801  // process a single file
     
    684806
    685807  grep->fileCount++;
    686   if (grep->sayfiles)
    687     WinSetWindowText(grep->hwndCurFile, filename);
     808  if (grep->sayfiles) {
     809    if (!hwndStatus)
     810      WinSetWindowText(grep->hwndCurFile, pszFileName);
     811    else {
     812      if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     813        WinSetWindowText(hwndStatus, pszFileName);
     814    }
     815  }
    688816
    689817  if (grep->greaterthan || grep->lessthan) {
     
    724852
    725853  if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern)        // just a find
    726     return insert_grepfile(grep, filename, pffb);
     854    return InsertGrepFile(grep, pszFileName, pffb, pitdSleep, pitdReport);
    727855
    728856  if (grep->searchEAs) {
     
    733861    CHAR *data, temp;
    734862
    735     head = GetFileEAs(filename, FALSE, TRUE);
     863    head = GetFileEAs(pszFileName, FALSE, TRUE);
    736864    if (head) {
    737865      info = head;
    738866      while (info && !strmatch) {
    739867        alltext = TRUE;
    740         switch (*(USHORT *) info->value) {
     868        switch (*(USHORT *)info->value) {
    741869        case EAT_ASCII:
    742870          if (match(info->value + (sizeof(USHORT) * 2),
    743871                    grep->searchPattern, grep->absFlag,
    744                     (grep->caseFlag == FALSE),
     872                    grep->caseFlag == FALSE,
    745873                    info->cbValue - (sizeof(USHORT) * 2),
    746                     grep->numlines, grep->matched, !grep->findifany)) {
     874                    grep->numlines,
     875                    grep->matched,
     876                    !grep->findifany)) {
    747877            strmatch = TRUE;
    748878          }
    749879          break;
    750880        case EAT_MVST:
    751           type = *(USHORT *) (info->value + (sizeof(USHORT) * 3));
     881          type = *(USHORT *)(info->value + (sizeof(USHORT) * 3));
    752882          if (type == EAT_ASCII) {
    753883            data = info->value + (sizeof(USHORT) * 4);
     
    829959      }                                 // while
    830960      Free_FEAList(head);
    831       DosSleep(1);
     961      // DosSleep(1);                   // 07 Feb 08 SHL
    832962    }
    833963  }
     
    838968      LONG len;
    839969
    840       inputFile = _fsopen(filename, "rb", SH_DENYNO);
     970      inputFile = _fsopen(pszFileName, "rb", SH_DENYNO);
    841971      if (inputFile) {
    842972        pos = ftell(inputFile);
     
    863993      }
    864994      free(input);
    865       DosSleep(1);
     995      // DosSleep(1);                   // 07 Feb 08 SHL
    866996    }
    867997  } // if
    868998
    869999  if (strmatch)
    870     ret = insert_grepfile(grep, filename, pffb);
     1000    ret = InsertGrepFile(grep, pszFileName, pffb, pitdSleep, pitdReport);
    8711001  return ret;
    8721002}
    8731003
    874 static LONG cr3tab[] = {        // CRC polynomial 0xEDB88320
     1004static LONG cr3tab[] = {                // CRC polynomial 0xEDB88320
    8751005
    8761006  0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
     
    9401070};
    9411071
    942 LONG CRCBlock(register CHAR * str, register INT blklen, register LONG crc)
     1072LONG CRCBlock(register CHAR *str, register INT blklen, register LONG crc)
    9431073{
    9441074  while (blklen--) {
     
    9501080}
    9511081
    952 LONG CRCFile(CHAR * filename, INT * error)
     1082LONG CRCFile(CHAR *pszFileName, INT *error)
    9531083{
    9541084  LONG CRC = -1L, len;
     
    9611091    *error = -1;
    9621092  else {
    963     fp = _fsopen(filename, "rb", SH_DENYNO);
     1093    fp = _fsopen(pszFileName, "rb", SH_DENYNO);
    9641094    if (!fp)
    9651095      *error = -2;
     
    9711101        else
    9721102          break;
    973         DosSleep(0); //26 Aug 07 GKY 1
     1103        // DosSleep(0); //26 Aug 07 GKY 1       // 07 Feb 08 SHL
    9741104      }
    9751105      fclose(fp);
    976       DosSleep(1);
     1106      // DosSleep(1);                   // 07 Feb 08 SHL
    9771107    }
    9781108    free(buffer);
     
    10011131}
    10021132
    1003 int comparenamesq(const void *v1, const void *v2)
     1133INT comparenamesq(const VOID *v1, const VOID *v2)
    10041134{
    10051135  DUPES *d1 = *(DUPES **) v1;
     
    10201150}
    10211151
    1022 int comparenamesqe(const void *v1, const void *v2)
     1152INT comparenamesqe(const VOID *v1, const VOID *v2)
    10231153{
    10241154  DUPES *d1 = *(DUPES **) v1;
    10251155  DUPES *d2 = *(DUPES **) v2;
    10261156  CHAR *p1, *p2, *p1e, *p2e, e1, e2;
    1027   int ret;
     1157  INT ret;
    10281158
    10291159  p1 = strrchr(d1->name, '\\');
     
    10551185}
    10561186
    1057 int comparesizesq(const void *v1, const void *v2)
     1187INT comparesizesq(const void *v1, const void *v2)
    10581188{
    10591189  DUPES *d1 = *(DUPES **) v1;
     
    10631193}
    10641194
    1065 int comparenamesb(const void *v1, const void *v2)
     1195INT comparenamesb(const void *v1, const void *v2)
    10661196{
    10671197  DUPES *d1 = (DUPES *) v1;
     
    10821212}
    10831213
    1084 int comparenamesbe(const void *v1, const void *v2)
     1214INT comparenamesbe(const VOID *v1, const VOID *v2)
    10851215{
    10861216  DUPES *d1 = (DUPES *) v1;
    10871217  DUPES *d2 = *(DUPES **) v2;
    10881218  CHAR *p1, *p2, *p1e, *p2e, e1, e2;
    1089   int ret;
     1219  INT ret;
    10901220
    10911221  p1 = strrchr(d1->name, '\\');
     
    11171247}
    11181248
    1119 int comparesizesb(const void *v1, const void *v2)
     1249INT comparesizesb(const VOID *v1, const VOID *v2)
    11201250{
    11211251  DUPES *d1 = (DUPES *) v1;
     
    11251255}
    11261256
    1127 static VOID FillDupes(GREP * grep)
     1257static VOID FillDupes(GREP *grep,
     1258                      ITIMER_DESC *pitdSleep,
     1259                      ITIMER_DESC *pitdReport)
    11281260{
    11291261  DUPES *c, *i, **r;
     
    11321264  UINT numfiles = 0, numalloced = 0;
    11331265  INT error;
    1134   register ULONG x = 0, y = 0;
    1135   ULONG cntr = 1000;
    1136 
    1137   if (grep->CRCdupes)
    1138     cntr = 100;
    1139   i = grep->dupehead;
    1140   while (i) {
    1141     x++;
    1142     i = i->next;
    1143   }
     1266  ULONG x;
     1267  ULONG y;
     1268  // ULONG cntr = 1000;                 // 09 Feb 08 SHL
     1269
     1270  // if (grep->CRCdupes)                // 09 Feb 08 SHL
     1271  //  cntr = 100;                       // 09 Feb 08 SHL
     1272  x = 0;
     1273  for (i = grep->dupehead; i; i = i->next)
     1274    x++;                                // Count
     1275
    11441276  if (x) {
    1145     WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
    1146     DosSleep(0);  //26 Aug 07 GKY 1
     1277    if (!hwndStatus)
     1278      WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
     1279    else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1280      WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPESORTINGTEXT));
     1281    // DosSleep(0);  //26 Aug 07 GKY 1  // 07 Feb 08 SHL
    11471282    grep->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
    11481283    if (!grep->nosizedupes)
    11491284      grep->dupesizes = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
    11501285    if (grep->dupenames && (grep->nosizedupes || grep->dupesizes)) {
    1151       i = grep->dupehead;
    1152       while (i) {
     1286      y = 0;
     1287      for (i = grep->dupehead; i; i = i->next) {
    11531288        grep->dupenames[y] = i;
    11541289        if (!grep->nosizedupes)
    11551290          grep->dupesizes[y] = i;
    1156         i = i->next;
    11571291        y++;
    11581292      }
    1159       grep->dupenames[y] = NULL;
     1293      grep->dupenames[y] = NULL;        // Mark end
    11601294      if (!grep->nosizedupes)
    11611295        grep->dupesizes[y] = NULL;
    1162       DosSleep(0); //26 Aug 07 GKY 1
     1296
     1297      InitITimer(pitdSleep, 0);         // Reset rate estimator
     1298      SleepIfNeeded(pitdSleep, 1);
     1299      // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL
     1300
    11631301      qsort(grep->dupenames,
    11641302            x,
    11651303            sizeof(DUPES *),
    1166             ((grep->ignoreextdupes) ? comparenamesqe : comparenamesq));
    1167       DosSleep(0); //26 Aug 07 GKY 1
     1304            grep->ignoreextdupes ? comparenamesqe : comparenamesq);
     1305      SleepIfNeeded(pitdSleep, 1);
     1306      // DosSleep(0); //26 Aug 07 GKY 1 // 07 Feb 08 SHL
    11681307      if (!grep->nosizedupes) {
    11691308        qsort(grep->dupesizes, x, sizeof(DUPES *), comparesizesq);
    1170         DosSleep(0); //26 Aug 07 GKY 1
     1309        SleepIfNeeded(pitdSleep, 1);
     1310        // DosSleep(0); //26 Aug 07 GKY 1       // 07 Feb 08 SHL
    11711311      }
    1172       WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
    1173 
     1312
     1313      if (!hwndStatus)
     1314        WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1315      else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1316        WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1317
     1318      InitITimer(pitdSleep, 0);         // Reset rate estimator
    11741319      i = grep->dupehead;
    11751320      y = 0;
     
    11771322        if (*grep->stopflag)
    11781323          break;
     1324        SleepIfNeeded(pitdSleep, 1);    // 07 Feb 08 SHL
    11791325        if (!(i->flags & GF_SKIPME)) {
    11801326          r = (DUPES **) bsearch(i, grep->dupenames, x, sizeof(DUPES *),
     
    12161362              if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
    12171363                (*r)->flags |= GF_INSERTED;
    1218                 if (grep->sayfiles)
    1219                   WinSetWindowText(grep->hwndFiles, (*r)->name);
     1364                if (grep->sayfiles) {
     1365                  if (!hwndStatus)
     1366                    WinSetWindowText(grep->hwndFiles, (*r)->name);
     1367                  else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1368                    WinSetWindowText(hwndStatus, (*r)->name);
     1369                }
    12201370                if ((*r)->size == i->size &&
    12211371                    (i->date.year == (*r)->date.year &&
     
    12771427                }
    12781428                if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
    1279                   if (grep->sayfiles)
    1280                     WinSetWindowText(grep->hwndCurFile, (*r)->name);
     1429                  if (grep->sayfiles) {
     1430                    if (!hwndStatus)
     1431                      WinSetWindowText(grep->hwndCurFile, (*r)->name);
     1432                    else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1433                      WinSetWindowText(hwndStatus, (*r)->name);
     1434                  }
    12811435                  (*r)->flags |= GF_INSERTED;
    12821436                  if (((grep->ignoreextdupes) ?
     
    12981452        i = i->next;
    12991453        y++;
    1300         if (!(y % cntr)) {
    1301 
     1454        // 08 Feb 08 SHL
     1455        if (IsITimerExpired(pitdReport)) {
    13021456          CHAR s[44];
    1303 
    13041457          sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
    1305           WinSetWindowText(grep->hwndCurFile, s);
    1306           DosSleep(1);          //05 Aug 07 GKY 128
     1458          if (!hwndStatus)
     1459            WinSetWindowText(grep->hwndCurFile, s);
     1460          else {
     1461            if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1462              WinSetWindowText(hwndStatus, s);
     1463          }
    13071464        }
    1308         DosSleep(0); //26 Aug 07 GKY 1
    1309       }
     1465        // DosSleep(0); //26 Aug 07 GKY 1
     1466      } // while
    13101467    }
    13111468    else {
    1312       // Insufficient memory - fall back
     1469      // Insufficient memory - fall back to slow method - fixme to saymsg?
    13131470      DosBeep(50, 100);
    1314       WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1471      if (!hwndStatus)
     1472        WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1473      else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1474        WinSetWindowText(hwndStatus, GetPString(IDS_GREPDUPECOMPARINGTEXT));
    13151475      x = y = 0;
    13161476      if (grep->dupenames) {
     
    13221482        grep->dupesizes = NULL;
    13231483      }
     1484
     1485      InitITimer(pitdSleep, 0);         // Reset rate estimator
    13241486      i = grep->dupehead;
    13251487      while (i) {
    13261488        if (*grep->stopflag)
    13271489          break;
     1490        SleepIfNeeded(pitdSleep, 1);
    13281491        if (!(i->flags & GF_SKIPME)) {
    1329           if (!(y % cntr)) {
    1330 
     1492          if (IsITimerExpired(pitdReport)) {
     1493            // if (!(y % cntr)) { }
    13311494            CHAR s[44];
    1332 
    13331495            sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
    1334             WinSetWindowText(grep->hwndCurFile, s);
    1335             DosSleep(0); //26 Aug 07 GKY 1
     1496            if (!hwndStatus)
     1497              WinSetWindowText(grep->hwndCurFile, s);
     1498            else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1499              WinSetWindowText(hwndStatus, s);
     1500            // DosSleep(0); //26 Aug 07 GKY 1   // 07 Feb 08 SHL
    13361501          }
    13371502          y++;
     
    13831548                    goto BreakOut;      // Failed
    13841549                }
    1385                 if (grep->sayfiles)
    1386                   WinSetWindowText(grep->hwndCurFile, pc);
     1550                if (grep->sayfiles) {
     1551                  if (!hwndStatus)
     1552                    WinSetWindowText(grep->hwndCurFile, pc);
     1553                  else if (WinQueryFocus(HWND_DESKTOP) == grep->hwndFiles)
     1554                    WinSetWindowText(hwndStatus, pc);
     1555                }
    13871556                c->flags |= GF_INSERTED;
    13881557                i->flags |= GF_INSERTED;
     
    13921561                }
    13931562              }
    1394               else if (!(x % 100))
    1395                 DosSleep(0);  //26 Aug 07 GKY 1
     1563              // else if (!(x % 100))   // 07 Feb 08 SHL
     1564              //        DosSleep(0);  //26 Aug 07 GKY 1 // 07 Feb 08 SHL
    13961565            }
    13971566            c = c->next;
     
    13991568        }
    14001569        i = i->next;
    1401       }
     1570      } // while
    14021571    }
    14031572  }
     
    14061575  if (numfiles && list) {
    14071576    if (!PostMsg(grep->hwndFiles,
    1408                  WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
     1577                 WM_COMMAND,
     1578                 MPFROM2SHORT(IDM_COLLECTOR, 0),
     1579                 MPFROMP(list)))
    14091580      FreeList(list);
    14101581  }
     
    14431614}
    14441615
    1445 #pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
     1616#pragma alloc_text(GREP,InsertGrepFile,DoOneFile,DoInsertion,freegreplist)
    14461617#pragma alloc_text(GREP,SecsSince1980,match,mmatch,GrepThread)
    1447 #pragma alloc_text(GREP,doallsubdirs,domatchingfiles,InsertDupes,FreeDupes)
     1618#pragma alloc_text(GREP,DoAllSubdirs,DoMatchingFiles,InsertDupes,FreeDupes)
    14481619
    14491620#pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock)
Note: See TracChangeset for help on using the changeset viewer.