Changeset 783 for trunk/dll/grep.c


Ignore:
Timestamp:
Aug 14, 2007, 6:09:54 AM (18 years ago)
Author:
Steven Levine
Message:

Rework DosFindFirst/Next loops to optimize memory allocation and code paths
Adjust FilesToGet limits
Update configuration notebook scanning page
Start updating #pragma alloc_text positioning for OpenWatcom compatibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/grep.c

    r775 r783  
    77
    88  Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2001, 2006 Steven H. Levine
     9  Copyright (c) 2001, 2007 Steven H. Levine
    1010
    1111  12 Feb 03 SHL insert_grepfile: standardize EA math
     
    2121  03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
    2222  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
    2425
    2526***********************************************************************/
     
    2728#define INCL_DOS
    2829#define INCL_WIN
     30#define INCL_DOSERRORS
    2931#define INCL_LONGLONG
    3032#include <os2.h>
     
    4446static PSZ pszSrcFile = __FILE__;
    4547
    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,
     48static VOID doallsubdirs(GREP *grep, CHAR *searchPath, BOOL recursing,
    5449                         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 * grep);
    58 static BOOL InsertDupe(GREP * grep, CHAR * dir, FILEFINDBUF4 * f);
    59 static VOID FillDupes(GREP * g);
    60 static VOID FreeDupes(GREP * g);
     50static INT domatchingfiles(GREP *grep, CHAR *path, char **fle, int numfls);
     51static BOOL doonefile(GREP *grep, CHAR *fileName, FILEFINDBUF4 *pffb);
     52static BOOL doinsertion(GREP *grep);
     53static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4 *pffb);
     54static VOID FillDupes(GREP *grep);
     55static VOID FreeDupes(GREP *grep);
    6156
    6257#define GREPCHARS "*?[] \\"
    6358
    6459#define isleap(year) ((((year%4)==0) && ((year%100)!=0)) || \
    65         ((year%400)==0))
     60        ((year%400)==0))
    6661
    6762static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
     
    9994                    LONG len)
    10095{
    101 
    102   /* return TRUE if pattern found in string */
    103 
     96  // return TRUE if pattern found in string
    10497  register CHAR *tn = pattern;
    10598  register LONG len2 = 0;
     
    108101
    109102  if (len && string && pattern) {
    110     if (absolute)                       /* no pattern matching */
     103    if (absolute)                       // no pattern matching
    111104      return (findstring(pattern, strlen(pattern), string, len,
    112105                         (ignore == FALSE)) != NULL);
     
    180173        if (!*tn)
    181174          return FALSE;
    182         /* else intentional fallthru */
     175        // else intentional fallthru
    183176      default:
    184177        if (ignore) {
     
    217210                  LONG len, ULONG numlines, CHAR * matched, BOOL matchall)
    218211{
    219 
    220212  BOOL ret = FALSE;
    221213  register CHAR *p;
     
    229221    if (matched && ret && x < numlines)
    230222      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
    232224    p++;
    233225    x++;
     
    245237  CHAR *p, *pp, searchPath[CCHMAXPATH * 2];
    246238
    247   if (!arg)
     239  if (!arg) {
     240    Runtime_Error(pszSrcFile, __LINE__, "no data");
    248241    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
    251246  grep.FilesToGet = FilesToGet;
    252247  DosError(FERR_DISABLEHARDERR);
     
    268263      while (*pp) {
    269264        if (!grep.absFlag) {
    270           p = GREPCHARS;                /* see if any sense in pattern matching */
     265          p = GREPCHARS;                // see if any sense in pattern matching
    271266          while (*p) {
    272267            if (strchr(pp, *p))
     
    274269            p++;
    275270          }
    276           if (!*p)                      /* nope, turn it off */
     271          if (!*p)                      // nope, turn it off
    277272            grep.absFlag = TRUE;
    278273        }
     
    300295      }
    301296
    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
    305300          goto ExcludeSkip;
    306301
    307         /* first, separate any path from mask */
     302        // first, separate any path from mask
    308303
    309304        p = (char *)(fle[x] + (strlen(fle[x]) - 1));
     
    311306          --p;
    312307
    313         if (p == fle[x]) {              /* no path */
     308        if (p == fle[x]) {              // no path
    314309          strcpy(searchPath, grep.curdir);
    315310          strncpy(grep.fileMask, fle[x], CCHMAXPATH);
    316311          grep.fileMask[CCHMAXPATH - 1] = 0;
    317312        }
    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
    320315            *p = 0;
    321316            p++;
     
    325320            strcpy(grep.fileMask, p);
    326321          }
    327           if (*p == '\\') {             /* got a 'full' path */
     322          if (*p == '\\') {             // got a 'full' path
    328323
    329324            CHAR temp;
     
    342337        if (*grep.stopflag)
    343338          break;
    344         /* do single directory */
     339        // do single directory
    345340        domatchingfiles(&grep, searchPath, fle, numfls);
    346         if (grep.dirFlag)               /* do subdirs */
     341        if (grep.dirFlag)               // do subdirs
    347342          doallsubdirs(&grep, searchPath, FALSE, fle, numfls);
    348343      ExcludeSkip:
     
    351346        x++;
    352347        if (WinIsWindow(grep.ghab, grep.hwndFiles))
    353           doinsertion(&grep);           /* insert any remaining objects */
     348          doinsertion(&grep);           // insert any remaining objects
    354349      } // while
    355350
    356351      if (WinIsWindow(grep.ghab, grep.hwndFiles))
    357         doinsertion(&grep);             /* insert any remaining objects */
     352        doinsertion(&grep);             // insert any remaining objects
    358353
    359354      if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes &&
     
    361356        FillDupes(&grep);
    362357
    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
    364359        WinSendMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
    365360      WinDestroyMsgQueue(ghmq);
     
    379374static BOOL IsExcluded(char *name, char **fle, int numfls)
    380375{
    381   register int x;
     376  int x;
    382377  char *n;
    383378
     
    401396                         char **fle, int numfls)
    402397{
    403 
    404   /* process all subdirectories */
    405 
    406   FILEFINDBUF4 findBuffer;
     398  // process all subdirectories
     399
     400  FILEFINDBUF4 ffb;
    407401  HDIR findHandle = HDIR_CREATE;
    408   LONG findCount = 1L;
     402  LONG ulFindCnt = 1;
    409403  CHAR *p = NULL;
    410404
    411   /* add a mask to search path */
     405  // add a mask to search path
    412406  if (searchPath[strlen(searchPath) - 1] != '\\')
    413407    strcat(searchPath, "\\");
    414408  strcat(searchPath, "*");
    415   /* step through all subdirectories */
     409  // step through all subdirectories
    416410  DosError(FERR_DISABLEHARDERR);
    417411  if (!DosFindFirst(searchPath, &findHandle, (MUST_HAVE_DIRECTORY |
    418412                                              FILE_ARCHIVED | FILE_SYSTEM |
    419413                                              FILE_HIDDEN | FILE_READONLY),
    420                     &findBuffer, (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
    424418
    425419    p = strrchr(searchPath, '\\');
     
    428422    else
    429423      p = searchPath;
    430     do {                                /* Process each directory that matches the mask */
     424    do {                                // Process each directory that matches the mask
    431425      priority_normal();
    432426      if (*grep->stopflag)
    433427        break;
    434428      // Skip . and ..
    435       if (findBuffer.achName[0] != '.' ||
    436           (findBuffer.achName[1] &&
    437            (findBuffer.achName[1] != '.' || findBuffer.achName[2]))) {
    438         strcpy(p, findBuffer.achName);
     429      if (ffb.achName[0] != '.' ||
     430          (ffb.achName[1] &&
     431           (ffb.achName[1] != '.' || ffb.achName[2]))) {
     432        strcpy(p, ffb.achName);
    439433        if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) {
    440434          domatchingfiles(grep, searchPath, fle, numfls);
     
    443437        }
    444438      }
    445       findCount = 1;
     439      ulFindCnt = 1;
    446440    } while (!DosFindNext(findHandle,
    447                           &findBuffer,
    448                           sizeof(findBuffer), (PULONG) & findCount));
     441                          &ffb,
     442                          sizeof(ffb), (PULONG) & ulFindCnt));
    449443    DosFindClose(findHandle);
    450444    priority_normal();
    451445  }
    452   if (p)                                /* strip off last directory addition */
     446  if (p)                                // strip off last directory addition
    453447    *p = 0;
    454448}
     
    456450static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls)
    457451{
    458   /* process all matching files in a directory */
    459 
    460   PFILEFINDBUF4 findBuffer;
     452  // process all matching files in a directory
     453
     454  PFILEFINDBUF4 pffbArray;
    461455  PFILEFINDBUF4 pffbFile;
    462   register PBYTE fb;
    463   register ULONG x;
     456  ULONG x;
    464457  HDIR findHandle = HDIR_CREATE;
    465   ULONG findCount = grep->FilesToGet;
    466   CHAR newPath[CCHMAXPATH], *p;
     458  ULONG ulFindCnt;
     459  CHAR szFindPath[CCHMAXPATH];
     460  PSZ p;
    467461  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)
    472466    return 0;
    473467
    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, '\\');
    485479  if (p)
    486480    p++;
    487481  else
    488     p = newPath;
    489 
    490   /* step through matching files */
     482    p = szFindPath;
     483
     484  // step through matching files
    491485  DosError(FERR_DISABLEHARDERR);
    492   if (!DosFindFirst(newPath,
     486  ulFindCnt = grep->FilesToGet;
     487  rc = DosFindFirst(szFindPath,
    493488                    &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
    500497      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++) {
    504500        if (*grep->stopflag)
    505501          break;
    506502        if (*pffbFile->achName != '.' ||
    507503            (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)) {
    510506            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)) {
    513509              DosFindClose(findHandle);
    514               free(findBuffer);
     510              free(pffbArray);
    515511              return 1;
    516512            }
     
    519515        if (!pffbFile->oNextEntryOffset)
    520516          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);
    530524    } while (!rc);
     525
    531526    DosFindClose(findHandle);
    532527    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);
    535536  return 0;
    536537}
    537538
    538 #pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
    539 
    540539static VOID freegreplist(GREP * grep)
    541540{
    542   register INT x;
     541  INT x;
    543542
    544543  if (grep) {
     
    607606}
    608607
    609 static BOOL insert_grepfile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f)
    610 {
    611   CHAR *p, szDirectory[CCHMAXPATH];
     608static BOOL insert_grepfile(GREP *grep, CHAR *filename, PFILEFINDBUF4 pffb)
     609{
     610  PSZ p;
     611  CHAR szDirectory[CCHMAXPATH];
    612612
    613613  if (WinIsWindow(grep->ghab, grep->hwndFiles)) {
     
    620620      *p = 0;
    621621      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__);
    625626        if (!grep->insertffb)
    626627          return FALSE;
    627628        grep->dir =
    628           xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1), pszSrcFile,
    629                    __LINE__);
     629          xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1),
     630                   pszSrcFile, __LINE__);
    630631        if (!grep->dir) {
    631632          free(grep->insertffb);
     
    637638      if (!grep->insertffb[grep->toinsert])
    638639        return FALSE;
    639       memcpy(grep->insertffb[grep->toinsert], f, sizeof(FILEFINDBUF4));
     640      memcpy(grep->insertffb[grep->toinsert], pffb, sizeof(FILEFINDBUF4));
    640641      grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__);
    641642      if (!grep->dir) {
     
    643644        return FALSE;
    644645      }
    645       grep->insertedbytes += f->cbFile + CBLIST_TO_EASIZE(f->cbList);
     646      grep->insertedbytes += pffb->cbFile + CBLIST_TO_EASIZE(pffb->cbList);
    646647      grep->toinsert++;
    647648      if (grep->toinsert == grep->FilesToGet)
     
    655656}
    656657
    657 static BOOL doonefile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f)
    658 {
    659   /* process a single file */
    660 
     658static BOOL doonefile(GREP *grep, CHAR *filename, FILEFINDBUF4 * pffb)
     659{
     660  // process a single file
    661661  CHAR *input;
    662662  FILE *inputFile;
     
    673673    ULONG adjsize;
    674674
    675     adjsize = f->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(f->cbList) : 0);
     675    adjsize = pffb->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(pffb->cbList) : 0);
    676676    if (grep->greaterthan) {
    677677      if (adjsize < grep->greaterthan)
     
    691691    ULONG numsecs;
    692692
    693     numsecs = SecsSince1980(&f->fdateLastWrite, &f->ftimeLastWrite);
     693    numsecs = SecsSince1980(&pffb->fdateLastWrite, &pffb->ftimeLastWrite);
    694694    if (grep->newerthan) {
    695695      if (numsecs < grep->newerthan)
     
    704704  }
    705705
    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);
    708708
    709709  if (grep->searchEAs) {
     
    849849
    850850  if (strmatch)
    851     ret = insert_grepfile(grep, filename, f);
     851    ret = insert_grepfile(grep, filename, pffb);
    852852  return ret;
    853853}
    854854
    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 */
     855static LONG cr3tab[] = {        // CRC polynomial 0xEDB88320
    860856
    861857  0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
     
    966962}
    967963
    968 static VOID FreeDupes(GREP * g)
     964static VOID FreeDupes(GREP *grep)
    969965{
    970966  DUPES *i, *next;
    971967
    972   i = g->dupehead;
     968  i = grep->dupehead;
    973969  while (i) {
    974970    next = i->next;
     
    978974    i = next;
    979975  }
    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;
    986982}
    987983
     
    11101106}
    11111107
    1112 static VOID FillDupes(GREP * g)
     1108static VOID FillDupes(GREP * grep)
    11131109{
    11141110  DUPES *c, *i, **r;
     
    11191115  ULONG cntr = 100;
    11201116
    1121   if (g->CRCdupes)
     1117  if (grep->CRCdupes)
    11221118    cntr = 50;
    1123   i = g->dupehead;
     1119  i = grep->dupehead;
    11241120  while (i) {
    11251121    x++;
     
    11271123  }
    11281124  if (x) {
    1129     WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
     1125    WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
    11301126    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;
    11361132      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;
    11401136        i = i->next;
    11411137        y++;
    11421138      }
    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;
    11461142      DosSleep(1);
    1147       qsort(g->dupenames,
     1143      qsort(grep->dupenames,
    11481144            x,
    11491145            sizeof(DUPES *),
    1150             ((g->ignoreextdupes) ? comparenamesqe : comparenamesq));
     1146            ((grep->ignoreextdupes) ? comparenamesqe : comparenamesq));
    11511147      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);
    11541150        DosSleep(1);
    11551151      }
    1156       WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
    1157 
    1158       i = g->dupehead;
     1152      WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1153
     1154      i = grep->dupehead;
    11591155      y = 0;
    11601156      while (i) {
    1161         if (*g->stopflag)
     1157        if (*grep->stopflag)
    11621158          break;
    11631159        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 :
    11661162                                  comparenamesb));
    11671163          if (r) {
    1168             while (r > g->dupenames && ((g->ignoreextdupes) ?
     1164            while (r > grep->dupenames && ((grep->ignoreextdupes) ?
    11691165                                        !comparenamesqe((r - 1), &i) :
    11701166                                        !comparenamesq((r - 1), &i)))
    11711167              r--;
    1172             while (*r && ((g->ignoreextdupes) ?
     1168            while (*r && ((grep->ignoreextdupes) ?
    11731169                          !comparenamesqe(r, &i) : !comparenamesq(r, &i))) {
    11741170              if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) {
     
    11761172                continue;
    11771173              }
    1178               if (g->CRCdupes) {
     1174              if (grep->CRCdupes) {
    11791175                if ((*r)->CRC == -1L) {
    11801176                  (*r)->CRC = CRCFile((*r)->name, &error);
     
    12001196              if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
    12011197                (*r)->flags |= GF_INSERTED;
    1202                 if (g->sayfiles)
    1203                   WinSetWindowText(g->hwndFiles, (*r)->name);
     1198                if (grep->sayfiles)
     1199                  WinSetWindowText(grep->hwndFiles, (*r)->name);
    12041200                if ((*r)->size == i->size &&
    12051201                    (i->date.year == (*r)->date.year &&
     
    12211217            }
    12221218          }
    1223           if (!g->nosizedupes) {
     1219          if (!grep->nosizedupes) {
    12241220            r = (DUPES **) bsearch(i,
    1225                                    g->dupesizes,
     1221                                   grep->dupesizes,
    12261222                                   x, sizeof(DUPES *), comparesizesb);
    12271223            if (r) {
    1228               while (r > g->dupesizes && !comparesizesq((r - 1), &i))
     1224              while (r > grep->dupesizes && !comparesizesq((r - 1), &i))
    12291225                r--;
    12301226              while (*r && !comparesizesq(r, &i)) {
     
    12391235                  continue;
    12401236                }
    1241                 if (g->CRCdupes) {
     1237                if (grep->CRCdupes) {
    12421238                  if ((*r)->CRC == -1L) {
    12431239                    (*r)->CRC = CRCFile((*r)->name, &error);
     
    12611257                }
    12621258                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);
    12651261                  (*r)->flags |= GF_INSERTED;
    1266                   if (((g->ignoreextdupes) ?
     1262                  if (((grep->ignoreextdupes) ?
    12671263                       comparenamesqe(r, &i) : comparenamesq(r, &i)))
    12681264                    (*r)->flags |= GF_SKIPME;
     
    12861282          CHAR s[44];
    12871283
    1288           sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g->numfiles);
    1289           WinSetWindowText(g->hwndCurFile, s);
    1290           DosSleep(100); //05 Aug 07 GKY 128
     1284          sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, grep->numfiles);
     1285          WinSetWindowText(grep->hwndCurFile, s);
     1286          DosSleep(100);                //05 Aug 07 GKY 128
    12911287        }
    12921288        DosSleep(y % 2);
     
    12961292      // Insufficient memory - fall back
    12971293      DosBeep(50, 100);
    1298       WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1294      WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
    12991295      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;
    13031299      }
    1304       if (g->dupesizes) {
    1305         free(g->dupesizes);
    1306         g->dupesizes = NULL;
     1300      if (grep->dupesizes) {
     1301        free(grep->dupesizes);
     1302        grep->dupesizes = NULL;
    13071303      }
    1308       i = g->dupehead;
     1304      i = grep->dupehead;
    13091305      while (i) {
    1310         if (*g->stopflag)
     1306        if (*grep->stopflag)
    13111307          break;
    13121308        if (!(i->flags & GF_SKIPME)) {
     
    13151311            CHAR s[44];
    13161312
    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);
    13191315            DosSleep(1);
    13201316          }
     
    13251321          else
    13261322            pi = i->name;
    1327           c = g->dupehead;
     1323          c = grep->dupehead;
    13281324          while (c) {
    1329             if (*g->stopflag)
     1325            if (*grep->stopflag)
    13301326              break;
    13311327            if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
     
    13361332              else
    13371333                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) {
    13411337                    if (c->CRC == -1L) {
    13421338                      c->CRC = CRCFile(c->name, &error);
     
    13671363                    goto BreakOut;      // Failed
    13681364                }
    1369                 if (g->sayfiles)
    1370                   WinSetWindowText(g->hwndCurFile, pc);
     1365                if (grep->sayfiles)
     1366                  WinSetWindowText(grep->hwndCurFile, pc);
    13711367                c->flags |= GF_INSERTED;
    13721368                i->flags |= GF_INSERTED;
     
    13871383  }
    13881384BreakOut:
    1389   FreeDupes(g);
     1385  FreeDupes(grep);
    13901386  if (numfiles && list) {
    1391     if (!PostMsg(g->hwndFiles,
     1387    if (!PostMsg(grep->hwndFiles,
    13921388                 WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
    13931389      FreeList(list);
     
    13971393}
    13981394
    1399 static BOOL InsertDupe(GREP * g, CHAR * dir, FILEFINDBUF4 * f)
     1395static BOOL InsertDupe(GREP *grep, CHAR *dir, FILEFINDBUF4 *pffb)
    14001396{
    14011397  DUPES *info;
     
    14051401    if (!info)
    14061402      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;
    14271421  }
    14281422  return TRUE;
    14291423}
     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.