Changeset 551 for trunk/dll/grep.c


Ignore:
Timestamp:
Feb 28, 2007, 2:33:51 AM (19 years ago)
Author:
Gregg Young
Message:

Indentation cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/grep.c

    r528 r551  
    4848/*****************************/
    4949
    50 static VOID  doallsubdirs    (GREP *grep,CHAR *searchPath,BOOL recursing,
    51                               char **fle,int numfls);
    52 static INT   domatchingfiles (GREP *grep,CHAR *path,char **fle,int numfls);
    53 static BOOL  doonefile       (GREP *grep,CHAR *fileName,FILEFINDBUF4 *f);
    54 static BOOL  doinsertion     (GREP *grep);
    55 static BOOL  InsertDupe      (GREP *grep,CHAR *dir,FILEFINDBUF4 *f);
    56 static VOID  FillDupes       (GREP *g);
    57 static VOID  FreeDupes       (GREP *g);
     50static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing,
     51                         char **fle, int numfls);
     52static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls);
     53static BOOL doonefile(GREP * grep, CHAR * fileName, FILEFINDBUF4 * f);
     54static BOOL doinsertion(GREP * grep);
     55static BOOL InsertDupe(GREP * grep, CHAR * dir, FILEFINDBUF4 * f);
     56static VOID FillDupes(GREP * g);
     57static VOID FreeDupes(GREP * g);
    5858
    5959#define GREPCHARS "*?[] \\"
     
    6262        ((year%400)==0))
    6363
    64 
    65 static INT monthdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    66 
    67 
    68 ULONG SecsSince1980 (FDATE *date,FTIME *time)
    69 {
    70   ULONG        total = 0L;
     64static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
     65
     66ULONG SecsSince1980(FDATE * date, FTIME * time)
     67{
     68  ULONG total = 0L;
    7169  register int x;
    7270
    73   for(x = 1980;x < date->year + 1980;x++) {
    74     if(isleap(x))
     71  for (x = 1980; x < date->year + 1980; x++) {
     72    if (isleap(x))
    7573      total += (366L * (24L * 60L * 60L));
    7674    else
    7775      total += (365L * (24L * 60L * 60L));
    7876  }
    79   for(x = 1;x < date->month;x++) {
    80     if(x == 2 && isleap(date->year + 1980))
     77  for (x = 1; x < date->month; x++) {
     78    if (x == 2 && isleap(date->year + 1980))
    8179      total += (29L * (24L * 60L * 60L));
    8280    else
     
    9088}
    9189
    92 
    9390/*
    9491 * this function originally from C_ECHO's Snippets -- modified
     
    9693 */
    9794
    98 static BOOL m_match (CHAR *string, CHAR *pattern, BOOL absolute, BOOL ignore,
    99                      LONG len) {
     95static BOOL m_match(CHAR * string, CHAR * pattern, BOOL absolute, BOOL ignore,
     96                    LONG len)
     97{
    10098
    10199  /* return TRUE if pattern found in string */
    102100
    103101  register CHAR *tn = pattern;
    104   register LONG  len2 = 0;
    105   LONG           lastlen = 0;
    106   CHAR           lo,hi;
    107 
    108   if(len && string && pattern) {
    109     if(absolute)                  /* no pattern matching */
    110       return(findstring(pattern,strlen(pattern),string,len,
    111                         (ignore == FALSE)) != NULL);
    112 
    113     while(*tn && len2 < len) {
    114       switch(*tn) {
    115         case ' ':
    116           while(*tn == ' ')
    117             tn++;
    118           while(len2 < len && isspace(string[len2]))
    119             len2++;
    120           break;
    121 
    122         case '*':
    123           while(*tn == '*' || *tn == '?')
    124             tn++;
    125           if(!*tn)
    126             return TRUE;
    127           if(ignore) {
    128             while(len2 < len && string[len2] != *tn)
    129               len2++;
    130           }
    131           else {
    132             while(len2 < len && toupper(string[len2] != *tn))
    133               len2++;
    134           }
    135           break;
    136 
    137         case '[':
    138           tn++;
    139           if(!*tn)
    140             return FALSE;
    141           lo = *tn;
    142           tn++;
    143           if(*tn != '-')
    144             return FALSE;
    145           tn++;
    146           if(!*tn)
    147             return FALSE;
    148           hi = *tn;
    149           tn++;
    150           if (*tn != ']')
    151             return FALSE;
    152           tn++;
    153           if(ignore) {
    154             if ((toupper(string[len2]) >= toupper(lo)) &&
    155                 (toupper(string[len2]) <= toupper(hi)))
    156               len2++;
    157             else {
    158               tn = pattern;
    159               len2 = lastlen = lastlen + 1;
    160             }
    161           }
    162           else {
    163             if ((string[len2] >= lo) && (string[len2] <= hi))
    164               len2++;
    165             else {
    166               tn = pattern;
    167               len2 = lastlen = lastlen + 1;
    168             }
    169           }
    170           break;
    171 
    172         case '?':
    173           tn++;
    174           len2++;
    175           break;
    176 
    177         case '\\':
    178           tn++;
    179           if(!*tn)
    180             return FALSE;
    181           /* else intentional fallthru */
    182         default:
    183           if(ignore) {
    184             if(toupper(*tn) == toupper(string[len2])) {
    185               tn++;
    186               len2++;
    187             }
    188             else {
    189               tn = pattern;
    190               len2 = lastlen = lastlen + 1;
    191             }
    192           }
    193           else {
    194             if(*tn == string[len2]) {
    195               tn++;
    196               len2++;
    197             }
    198             else {
    199               tn = pattern;
    200               len2 = lastlen = lastlen + 1;
    201             }
    202           }
    203           break;
    204       }
    205     }
    206     while(*tn == '*')
     102  register LONG len2 = 0;
     103  LONG lastlen = 0;
     104  CHAR lo, hi;
     105
     106  if (len && string && pattern) {
     107    if (absolute)                       /* no pattern matching */
     108      return (findstring(pattern, strlen(pattern), string, len,
     109                        (ignore == FALSE)) != NULL);
     110
     111    while (*tn && len2 < len) {
     112      switch (*tn) {
     113      case ' ':
     114        while (*tn == ' ')
     115          tn++;
     116        while (len2 < len && isspace(string[len2]))
     117          len2++;
     118        break;
     119
     120      case '*':
     121        while (*tn == '*' || *tn == '?')
     122          tn++;
     123        if (!*tn)
     124          return TRUE;
     125        if (ignore) {
     126          while (len2 < len && string[len2] != *tn)
     127            len2++;
     128        }
     129        else {
     130          while (len2 < len && toupper(string[len2] != *tn))
     131            len2++;
     132        }
     133        break;
     134
     135      case '[':
     136        tn++;
     137        if (!*tn)
     138          return FALSE;
     139        lo = *tn;
     140        tn++;
     141        if (*tn != '-')
     142          return FALSE;
     143        tn++;
     144        if (!*tn)
     145          return FALSE;
     146        hi = *tn;
     147        tn++;
     148        if (*tn != ']')
     149          return FALSE;
     150        tn++;
     151        if (ignore) {
     152          if ((toupper(string[len2]) >= toupper(lo)) &&
     153              (toupper(string[len2]) <= toupper(hi)))
     154            len2++;
     155          else {
     156            tn = pattern;
     157            len2 = lastlen = lastlen + 1;
     158          }
     159        }
     160        else {
     161          if ((string[len2] >= lo) && (string[len2] <= hi))
     162            len2++;
     163          else {
     164            tn = pattern;
     165            len2 = lastlen = lastlen + 1;
     166          }
     167        }
     168        break;
     169
     170      case '?':
     171        tn++;
     172        len2++;
     173        break;
     174
     175      case '\\':
     176        tn++;
     177        if (!*tn)
     178          return FALSE;
     179        /* else intentional fallthru */
     180      default:
     181        if (ignore) {
     182          if (toupper(*tn) == toupper(string[len2])) {
     183            tn++;
     184            len2++;
     185          }
     186          else {
     187            tn = pattern;
     188            len2 = lastlen = lastlen + 1;
     189          }
     190        }
     191        else {
     192          if (*tn == string[len2]) {
     193            tn++;
     194            len2++;
     195          }
     196          else {
     197            tn = pattern;
     198            len2 = lastlen = lastlen + 1;
     199          }
     200        }
     201        break;
     202      }
     203    }
     204    while (*tn == '*')
    207205      tn++;
    208206
     
    213211}
    214212
    215 
    216 static BOOL match (CHAR *string,CHAR *patterns,BOOL absolute,BOOL ignore,
    217                    LONG len,ULONG numlines,CHAR *matched,BOOL matchall) {
    218 
    219   BOOL           ret = FALSE;
     213static BOOL match(CHAR * string, CHAR * patterns, BOOL absolute, BOOL ignore,
     214                  LONG len, ULONG numlines, CHAR * matched, BOOL matchall)
     215{
     216
     217  BOOL ret = FALSE;
    220218  register CHAR *p;
    221219  register ULONG x = 0;
    222220
    223221  p = patterns;
    224   while(!ret && *p) {
    225     ret = m_match(string,p,absolute,ignore,len);
    226     if(matchall && ret)
     222  while (!ret && *p) {
     223    ret = m_match(string, p, absolute, ignore, len);
     224    if (matchall && ret)
    227225      break;
    228     if(matched && ret && x < numlines)
     226    if (matched && ret && x < numlines)
    229227      matched[x] = 1;
    230     p += strlen(p); /* check each pattern in 0-terminated list */
     228    p += strlen(p);                     /* check each pattern in 0-terminated list */
    231229    p++;
    232230    x++;
     
    235233}
    236234
    237 
    238 VOID GrepThread (VOID *arg)
    239 {
    240   HAB           ghab;
    241   HMQ           ghmq;
    242   GREP          grep;
    243   register INT  x,numfls;
    244   static CHAR  *fle[512];
    245   CHAR         *p,*pp,searchPath[CCHMAXPATH * 2];
    246 
    247   if(!arg)
     235VOID GrepThread(VOID * arg)
     236{
     237  HAB ghab;
     238  HMQ ghmq;
     239  GREP grep;
     240  register INT x, numfls;
     241  static CHAR *fle[512];
     242  CHAR *p, *pp, searchPath[CCHMAXPATH * 2];
     243
     244  if (!arg)
    248245    return;
    249   grep = *(GREP *)arg;
    250   *grep.stopflag = 0;  /* reset thread-killing flag */
    251   grep.FilesToGet = (grep.dirFlag) ? min(FilesToGet,128) : FilesToGet;
     246  grep = *(GREP *) arg;
     247  *grep.stopflag = 0;                   /* reset thread-killing flag */
     248  grep.FilesToGet = (grep.dirFlag) ? min(FilesToGet, 128) : FilesToGet;
    252249  DosError(FERR_DISABLEHARDERR);
    253250  priority_normal();
    254251
    255252  ghab = WinInitialize(0);
    256   if(ghab) {
     253  if (ghab) {
    257254    grep.ghab = ghab;
    258     ghmq = WinCreateMsgQueue(ghab,0);
    259     if(ghmq) {
    260       WinCancelShutdown(ghmq,TRUE);
     255    ghmq = WinCreateMsgQueue(ghab, 0);
     256    if (ghmq) {
     257      WinCancelShutdown(ghmq, TRUE);
    261258      IncrThreadUsage();
    262259      DosSleep(128L);
    263260      WinSetWindowText(grep.hwndCurFile,
    264                        GetPString((grep.finddupes) ?
    265                                   IDS_GREPDUPETEXT : IDS_GREPSCANTEXT));
     261                       GetPString((grep.finddupes) ?
     262                                  IDS_GREPDUPETEXT : IDS_GREPSCANTEXT));
    266263
    267264      pp = grep.searchPattern;
    268       while(*pp) {
    269         if(!grep.absFlag) {
    270           p = GREPCHARS;  /* see if any sense in pattern matching */
    271           while(*p) {
    272             if(strchr(pp,*p))
    273               break;
    274             p++;
    275           }
    276           if(!*p) /* nope, turn it off */
    277             grep.absFlag = TRUE;
    278         }
    279         pp = pp + strlen(pp) + 1;
     265      while (*pp) {
     266        if (!grep.absFlag) {
     267          p = GREPCHARS;                /* see if any sense in pattern matching */
     268          while (*p) {
     269            if (strchr(pp, *p))
     270              break;
     271            p++;
     272          }
     273          if (!*p)                      /* nope, turn it off */
     274            grep.absFlag = TRUE;
     275        }
     276        pp = pp + strlen(pp) + 1;
    280277      }
    281278
    282279      grep.attrFile &= (~FILE_DIRECTORY);
    283280      grep.antiattr &= (~FILE_DIRECTORY);
    284       if(grep.antiattr & FILE_READONLY)
    285         grep.antiattr |= MUST_HAVE_READONLY;
    286       if(grep.antiattr & FILE_HIDDEN)
    287         grep.antiattr |= MUST_HAVE_HIDDEN;
    288       if(grep.antiattr & FILE_SYSTEM)
    289         grep.antiattr |= MUST_HAVE_SYSTEM;
    290       if(grep.antiattr & FILE_ARCHIVED)
    291         grep.antiattr |= MUST_HAVE_ARCHIVED;
     281      if (grep.antiattr & FILE_READONLY)
     282        grep.antiattr |= MUST_HAVE_READONLY;
     283      if (grep.antiattr & FILE_HIDDEN)
     284        grep.antiattr |= MUST_HAVE_HIDDEN;
     285      if (grep.antiattr & FILE_SYSTEM)
     286        grep.antiattr |= MUST_HAVE_SYSTEM;
     287      if (grep.antiattr & FILE_ARCHIVED)
     288        grep.antiattr |= MUST_HAVE_ARCHIVED;
    292289
    293290      grep.anyexcludes = FALSE;
    294291      numfls = x = 0;
    295       fle[numfls++] = strtok(grep.tosearch,";");
    296       while((fle[numfls] = strtok(NULL,";")) != NULL && numfls < 511) {
    297         if(*fle[numfls] == '/')
    298           grep.anyexcludes = TRUE;
    299         numfls++;
    300       }
    301 
    302       while(x < numfls) { /* loop through search masks */
    303 
    304         if(*fle[x] == '/')  /* is an exclude mask only */
    305           goto ExcludeSkip;
    306 
    307         /* first, separate any path from mask */
    308 
    309         p = (char *)(fle[x] + (strlen(fle[x]) - 1));
    310         while(*p != '\\' && *p != ':' && p != fle[x])
    311           --p;
    312 
    313         if(p == fle[x]) {  /* no path */
    314           strcpy(searchPath,grep.curdir);
    315           strncpy(grep.fileMask,fle[x],CCHMAXPATH);
    316           grep.fileMask[CCHMAXPATH - 1] = 0;
    317         }
    318         else {  /* got to deal with a path */
    319           if(*p == ':') { /* just a drive, start in root dir */
    320             *p = 0;
    321             p++;
    322             strncpy(searchPath,fle[x],CCHMAXPATH - 2);
    323             searchPath[CCHMAXPATH - 3] = 0;
    324             strcat(searchPath,":\\");
    325             strcpy(grep.fileMask,p);
    326           }
    327           if(*p == '\\') {  /* got a 'full' path */
    328 
    329             CHAR temp;
    330 
    331             p++;
    332             temp = *p;
    333             *p = 0;
    334             strncpy(searchPath,fle[x],CCHMAXPATH);
    335             searchPath[CCHMAXPATH - 1] = 0;
    336             *p = temp;
    337             strcpy(grep.fileMask,p);
    338           }
    339           if(!*grep.fileMask)
    340             strcpy(grep.fileMask,"*");
    341         }
    342         if(*grep.stopflag)
    343           break;
    344         /* do single directory */
    345         domatchingfiles(&grep,searchPath,fle,numfls);
    346         if(grep.dirFlag)  /* do subdirs */
    347           doallsubdirs(&grep,searchPath,FALSE,fle,numfls);
    348 ExcludeSkip:
    349         if(*grep.stopflag)
    350           break;
    351         x++ ;
    352         if(WinIsWindow(grep.ghab,grep.hwndFiles))
    353           doinsertion(&grep); /* insert any remaining objects */
    354       }
    355 
    356 ShutDownThread:  /* kill pm connection, end thread */
    357 
    358       if(WinIsWindow(grep.ghab,grep.hwndFiles))
    359         doinsertion(&grep); /* insert any remaining objects */
    360 
    361       if(WinIsWindow(grep.ghab,grep.hwndFiles) && grep.finddupes &&
    362          !*grep.stopflag)
    363         FillDupes(&grep);
    364 
    365       if(!PostMsg(grep.hwndFiles,
    366                   UM_CONTAINER_FILLED,
    367                   MPVOID,
    368                   MPVOID)) /* tell window we're done */
    369         WinSendMsg(grep.hwndFiles,
    370                    UM_CONTAINER_FILLED,
    371                    MPVOID,
    372                    MPVOID);
     292      fle[numfls++] = strtok(grep.tosearch, ";");
     293      while ((fle[numfls] = strtok(NULL, ";")) != NULL && numfls < 511) {
     294        if (*fle[numfls] == '/')
     295          grep.anyexcludes = TRUE;
     296        numfls++;
     297      }
     298
     299      while (x < numfls) {              /* loop through search masks */
     300
     301        if (*fle[x] == '/')             /* is an exclude mask only */
     302          goto ExcludeSkip;
     303
     304        /* first, separate any path from mask */
     305
     306        p = (char *)(fle[x] + (strlen(fle[x]) - 1));
     307        while (*p != '\\' && *p != ':' && p != fle[x])
     308          --p;
     309
     310        if (p == fle[x]) {              /* no path */
     311          strcpy(searchPath, grep.curdir);
     312          strncpy(grep.fileMask, fle[x], CCHMAXPATH);
     313          grep.fileMask[CCHMAXPATH - 1] = 0;
     314        }
     315        else {                          /* got to deal with a path */
     316          if (*p == ':') {              /* just a drive, start in root dir */
     317            *p = 0;
     318            p++;
     319            strncpy(searchPath, fle[x], CCHMAXPATH - 2);
     320            searchPath[CCHMAXPATH - 3] = 0;
     321            strcat(searchPath, ":\\");
     322            strcpy(grep.fileMask, p);
     323          }
     324          if (*p == '\\') {             /* got a 'full' path */
     325
     326            CHAR temp;
     327
     328            p++;
     329            temp = *p;
     330            *p = 0;
     331            strncpy(searchPath, fle[x], CCHMAXPATH);
     332            searchPath[CCHMAXPATH - 1] = 0;
     333            *p = temp;
     334            strcpy(grep.fileMask, p);
     335          }
     336          if (!*grep.fileMask)
     337            strcpy(grep.fileMask, "*");
     338        }
     339        if (*grep.stopflag)
     340          break;
     341        /* do single directory */
     342        domatchingfiles(&grep, searchPath, fle, numfls);
     343        if (grep.dirFlag)               /* do subdirs */
     344          doallsubdirs(&grep, searchPath, FALSE, fle, numfls);
     345      ExcludeSkip:
     346        if (*grep.stopflag)
     347          break;
     348        x++;
     349        if (WinIsWindow(grep.ghab, grep.hwndFiles))
     350          doinsertion(&grep);           /* insert any remaining objects */
     351      }
     352
     353    ShutDownThread:                     /* kill pm connection, end thread */
     354
     355      if (WinIsWindow(grep.ghab, grep.hwndFiles))
     356        doinsertion(&grep);             /* insert any remaining objects */
     357
     358      if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes &&
     359          !*grep.stopflag)
     360        FillDupes(&grep);
     361
     362      if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID))        /* tell window we're done */
     363        WinSendMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
    373364      WinDestroyMsgQueue(ghmq);
    374365    }
     
    376367    WinTerminate(ghab);
    377368  }
    378   if(!ghmq || !ghab)
    379     WinPostMsg(grep.hwndFiles,
    380                UM_CONTAINER_FILLED,
    381                MPVOID,
    382                MPVOID);
    383   if(grep.dupehead)
     369  if (!ghmq || !ghab)
     370    WinPostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
     371  if (grep.dupehead)
    384372    FreeDupes(&grep);
    385   if(grep.numlines &&
    386      grep.matched)
     373  if (grep.numlines && grep.matched)
    387374    free(grep.matched);
    388375  DosPostEventSem(CompactSem);
    389376}
    390377
    391 
    392 static BOOL IsExcluded (char *name,char **fle,int numfls)
     378static BOOL IsExcluded(char *name, char **fle, int numfls)
    393379{
    394380  register int x;
    395   char        *n;
    396 
    397   n = strrchr(name,'\\');
    398   if(!n)
    399     n = strrchr(name,':');
    400   if(n)
     381  char *n;
     382
     383  n = strrchr(name, '\\');
     384  if (!n)
     385    n = strrchr(name, ':');
     386  if (n)
    401387    n++;
    402388  else
    403389    n = name;
    404   for(x = 0;x < numfls;x++) {
    405     if(*fle[x] == '/' &&
    406        wildcard((strchr(fle[x],'\\') ||
    407                  strchr(fle[x],':')) ?
    408                 name : n,fle[x] + 1,FALSE))
     390  for (x = 0; x < numfls; x++) {
     391    if (*fle[x] == '/' &&
     392        wildcard((strchr(fle[x], '\\') ||
     393                  strchr(fle[x], ':')) ? name : n, fle[x] + 1, FALSE))
    409394      return TRUE;
    410395  }
     
    412397}
    413398
    414 
    415 static VOID doallsubdirs (GREP *grep,CHAR *searchPath,BOOL recursing,
    416                           char **fle,int numfls) {
     399static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing,
     400                         char **fle, int numfls)
     401{
    417402
    418403  /* process all subdirectories */
    419404
    420405  FILEFINDBUF4 findBuffer;
    421   HDIR         findHandle = HDIR_CREATE;
    422   LONG         findCount  = 1L;
    423   CHAR         *p = NULL;
     406  HDIR findHandle = HDIR_CREATE;
     407  LONG findCount = 1L;
     408  CHAR *p = NULL;
    424409
    425410  /* add a mask to search path */
    426   if(searchPath[strlen(searchPath) - 1] != '\\')
    427     strcat(searchPath,"\\");
    428   strcat(searchPath,"*");
     411  if (searchPath[strlen(searchPath) - 1] != '\\')
     412    strcat(searchPath, "\\");
     413  strcat(searchPath, "*");
    429414  /* step through all subdirectories */
    430415  DosError(FERR_DISABLEHARDERR);
    431   if(!DosFindFirst(searchPath,&findHandle,(MUST_HAVE_DIRECTORY |
    432                   FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY),
    433                   &findBuffer,
    434                   (ULONG)sizeof(findBuffer),
    435                   (PULONG)&findCount,
    436                   FIL_QUERYEASIZE)) {
     416  if (!DosFindFirst(searchPath, &findHandle, (MUST_HAVE_DIRECTORY |
     417                                              FILE_ARCHIVED | FILE_SYSTEM |
     418                                              FILE_HIDDEN | FILE_READONLY),
     419                    &findBuffer, (ULONG) sizeof(findBuffer),
     420                    (PULONG) & findCount, FIL_QUERYEASIZE)) {
    437421
    438422    /* get rid of mask portion, save end-of-directory */
    439423
    440     p = strrchr(searchPath,'\\');
    441     if(p)
     424    p = strrchr(searchPath, '\\');
     425    if (p)
    442426      p++;
    443427    else
    444428      p = searchPath;
    445     do {   /* Process each directory that matches the mask */
     429    do {                                /* Process each directory that matches the mask */
    446430      priority_normal();
    447       if(*grep->stopflag)
    448         break;
     431      if (*grep->stopflag)
     432        break;
    449433      // Skip . and ..
    450434      if (findBuffer.achName[0] != '.' ||
    451           (findBuffer.achName[1] &&
     435          (findBuffer.achName[1] &&
    452436           (findBuffer.achName[1] != '.' || findBuffer.achName[2]))) {
    453         strcpy(p,findBuffer.achName) ;
    454         if(!grep->anyexcludes || !IsExcluded(searchPath,fle,numfls)) {
    455           domatchingfiles(grep,searchPath,fle,numfls) ;
    456           doallsubdirs(grep,searchPath,TRUE,fle,numfls);
    457           DosSleep(0L);
    458         }
     437        strcpy(p, findBuffer.achName);
     438        if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) {
     439          domatchingfiles(grep, searchPath, fle, numfls);
     440          doallsubdirs(grep, searchPath, TRUE, fle, numfls);
     441          DosSleep(0L);
     442        }
    459443      }
    460444      findCount = 1L;
    461     } while(!DosFindNext(findHandle,
    462                          &findBuffer,
    463                          sizeof(findBuffer),
    464                          (PULONG)&findCount));
     445    } while (!DosFindNext(findHandle,
     446                          &findBuffer,
     447                          sizeof(findBuffer), (PULONG) & findCount));
    465448    DosFindClose(findHandle);
    466449    priority_normal();
    467450  }
    468   if(p)    /* strip off last directory addition */
     451  if (p)                                /* strip off last directory addition */
    469452    *p = 0;
    470453}
    471454
    472 
    473 static INT domatchingfiles (GREP *grep,CHAR *path,char **fle,int numfls)
     455static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls)
    474456{
    475457  /* process all matching files in a directory */
    476458
    477   PFILEFINDBUF4  findBuffer;
    478   PFILEFINDBUF4  pffbFile;
     459  PFILEFINDBUF4 findBuffer;
     460  PFILEFINDBUF4 pffbFile;
    479461  register PBYTE fb;
    480462  register ULONG x;
    481   HDIR           findHandle  = HDIR_CREATE;
    482   ULONG          findCount = grep->FilesToGet;
    483   CHAR           newPath[CCHMAXPATH],*p;
    484   APIRET         rc;
    485 
    486   findBuffer = xmalloc(grep->FilesToGet * sizeof(FILEFINDBUF4),pszSrcFile,__LINE__);
    487   if(!findBuffer)
     463  HDIR findHandle = HDIR_CREATE;
     464  ULONG findCount = grep->FilesToGet;
     465  CHAR newPath[CCHMAXPATH], *p;
     466  APIRET rc;
     467
     468  findBuffer =
     469    xmalloc(grep->FilesToGet * sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
     470  if (!findBuffer)
    488471    return 0;
    489472
     
    491474
    492475  sprintf(newPath,
    493           "%s%s%s",
    494           path,
    495           (path[strlen(path) - 1] == '\\') ?
    496            NullStr : "\\",
    497           grep->fileMask);
     476          "%s%s%s",
     477          path,
     478          (path[strlen(path) - 1] == '\\') ? NullStr : "\\", grep->fileMask);
    498479
    499480  MakeFullName(newPath);
    500481
    501482  /* find and save end-of-dir position */
    502   p = strrchr(newPath,'\\');
    503   if(p)
     483  p = strrchr(newPath, '\\');
     484  if (p)
    504485    p++;
    505486  else
     
    508489  /* step through matching files */
    509490  DosError(FERR_DISABLEHARDERR);
    510   if(!DosFindFirst(newPath,
    511                   &findHandle,
    512                   (FILE_NORMAL | grep->attrFile | grep->antiattr),
    513                   findBuffer,
    514                   (ULONG)(grep->FilesToGet * sizeof(FILEFINDBUF4)),
    515                   (PULONG)&findCount,
    516                   FIL_QUERYEASIZE)) {
    517 
    518     do {   /* Process each file that matches the mask */
     491  if (!DosFindFirst(newPath,
     492                    &findHandle,
     493                    (FILE_NORMAL | grep->attrFile | grep->antiattr),
     494                    findBuffer,
     495                    (ULONG) (grep->FilesToGet * sizeof(FILEFINDBUF4)),
     496                    (PULONG) & findCount, FIL_QUERYEASIZE)) {
     497
     498    do {                                /* Process each file that matches the mask */
    519499      priority_normal();
    520       fb = (PBYTE)findBuffer;
    521       for(x = 0L;x < findCount;x++) {
    522         pffbFile = (PFILEFINDBUF4)fb;
    523         if(*grep->stopflag)
    524           break;
    525         if(*pffbFile->achName != '.' ||
    526            (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
    527           strcpy(p,pffbFile->achName);  /* build filename */
    528           if(!grep->anyexcludes ||
    529              !IsExcluded(newPath,fle,numfls)) {
    530             if(!grep->finddupes)
    531               doonefile(grep,
    532                         newPath,
    533                         pffbFile);
    534             else if(!InsertDupe(grep,
    535                                 newPath,
    536                                 pffbFile)) {
    537               DosFindClose(findHandle);
    538               free(findBuffer);
    539               return 1;
    540             }
    541           }
    542         }
    543         if(!pffbFile->oNextEntryOffset)
    544           break;
    545         fb += pffbFile->oNextEntryOffset;
     500      fb = (PBYTE) findBuffer;
     501      for (x = 0L; x < findCount; x++) {
     502        pffbFile = (PFILEFINDBUF4) fb;
     503        if (*grep->stopflag)
     504          break;
     505        if (*pffbFile->achName != '.' ||
     506            (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
     507          strcpy(p, pffbFile->achName); /* build filename */
     508          if (!grep->anyexcludes || !IsExcluded(newPath, fle, numfls)) {
     509            if (!grep->finddupes)
     510              doonefile(grep, newPath, pffbFile);
     511            else if (!InsertDupe(grep, newPath, pffbFile)) {
     512              DosFindClose(findHandle);
     513              free(findBuffer);
     514              return 1;
     515            }
     516          }
     517        }
     518        if (!pffbFile->oNextEntryOffset)
     519          break;
     520        fb += pffbFile->oNextEntryOffset;
    546521      }
    547522      findCount = grep->FilesToGet;
    548523      rc = DosFindNext(findHandle,
    549                        findBuffer,
    550                        (ULONG)(grep->FilesToGet * sizeof(FILEFINDBUF4)),
    551                        (PULONG)&findCount);
    552       if(!rc)
    553         DosSleep(1L);
    554     } while(!rc);
     524                       findBuffer,
     525                       (ULONG) (grep->FilesToGet * sizeof(FILEFINDBUF4)),
     526                       (PULONG) & findCount);
     527      if (!rc)
     528        DosSleep(1L);
     529    } while (!rc);
    555530    DosFindClose(findHandle);
    556531    priority_normal();
    557532  }
    558533  free(findBuffer);
    559   return 0 ;
     534  return 0;
    560535}
    561536
    562537#pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
    563538
    564 
    565 static VOID freegreplist (GREP *grep)
     539static VOID freegreplist(GREP * grep)
    566540{
    567541  register INT x;
    568542
    569   if(grep) {
    570     if(grep->insertffb) {
    571       for(x = 0;grep->insertffb[x];x++)
    572         free(grep->insertffb[x]);
     543  if (grep) {
     544    if (grep->insertffb) {
     545      for (x = 0; grep->insertffb[x]; x++)
     546        free(grep->insertffb[x]);
    573547      free(grep->insertffb);
    574548    }
    575     if(grep->dir) {
    576       for(x = 0;grep->dir[x];x++)
    577         free(grep->dir[x]);
     549    if (grep->dir) {
     550      for (x = 0; grep->dir[x]; x++)
     551        free(grep->dir[x]);
    578552      free(grep->dir);
    579553    }
     
    585559}
    586560
    587 
    588 static BOOL doinsertion (GREP *grep)
     561static BOOL doinsertion(GREP * grep)
    589562{
    590563  RECORDINSERT ri;
    591   DIRCNRDATA  *dcd;
    592   PCNRITEM     pci,pciFirst;
    593   INT          x;
    594 
    595   if(!grep ||
    596      !grep->toinsert ||
    597      !grep->insertffb ||
    598      !grep->dir)
     564  DIRCNRDATA *dcd;
     565  PCNRITEM pci, pciFirst;
     566  INT x;
     567
     568  if (!grep || !grep->toinsert || !grep->insertffb || !grep->dir)
    599569    return FALSE;
    600570  pci = WinSendMsg(grep->hwndFiles,
    601                    CM_ALLOCRECORD,
    602                    MPFROMLONG(EXTRA_RECORD_BYTES),
    603                    MPFROMLONG(grep->toinsert));
    604   if(pci) {
    605     if(grep->sayfiles)
    606       WinSetWindowText(grep->hwndCurFile,
    607                        GetPString(IDS_GREPINSERTINGTEXT));
     571                   CM_ALLOCRECORD,
     572                   MPFROMLONG(EXTRA_RECORD_BYTES),
     573                   MPFROMLONG(grep->toinsert));
     574  if (pci) {
     575    if (grep->sayfiles)
     576      WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT));
    608577    pciFirst = pci;
    609578    dcd = INSTDATA(grep->hwndFiles);
    610     for(x = 0; grep->insertffb[x]; x++) {
     579    for (x = 0; grep->insertffb[x]; x++) {
    611580      FillInRecordFromFFB(grep->hwndFiles,
    612                           pci,
    613                           grep->dir[x],
    614                           grep->insertffb[x],
    615                           FALSE,
    616                           dcd);
     581                          pci, grep->dir[x], grep->insertffb[x], FALSE, dcd);
    617582      pci = (PCNRITEM) pci->rc.preccNextRecord;
    618583    }
    619     memset(&ri,0,sizeof(RECORDINSERT));
    620     ri.cb                 = sizeof(RECORDINSERT);
    621     ri.pRecordOrder       = (PRECORDCORE) CMA_END;
    622     ri.pRecordParent      = (PRECORDCORE)NULL;
    623     ri.zOrder             = (USHORT) CMA_TOP;
    624     ri.cRecordsInsert     = grep->toinsert;
    625     ri.fInvalidateRecord  = TRUE;
     584    memset(&ri, 0, sizeof(RECORDINSERT));
     585    ri.cb = sizeof(RECORDINSERT);
     586    ri.pRecordOrder = (PRECORDCORE) CMA_END;
     587    ri.pRecordParent = (PRECORDCORE) NULL;
     588    ri.zOrder = (USHORT) CMA_TOP;
     589    ri.cRecordsInsert = grep->toinsert;
     590    ri.fInvalidateRecord = TRUE;
    626591    WinSendMsg(grep->hwndFiles,
    627                CM_INSERTRECORD,
    628                MPFROMP(pciFirst),
    629                MPFROMP(&ri));
    630     if(dcd) {
     592               CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri));
     593    if (dcd) {
    631594      DosEnterCritSec();
    632        dcd->ullTotalBytes += grep->insertedbytes;
     595      dcd->ullTotalBytes += grep->insertedbytes;
    633596      DosExitCritSec();
    634597    }
    635     if(grep->toinsert == grep->FilesToGet)
     598    if (grep->toinsert == grep->FilesToGet)
    636599      DosSleep(1L);
    637600    freegreplist(grep);
    638     PostMsg(grep->hwndFiles,
    639             UM_RESCAN,
    640             MPVOID,
    641             MPVOID);
     601    PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID);
    642602    return TRUE;
    643603  }
     
    646606}
    647607
    648 
    649 static BOOL insert_grepfile (GREP *grep,CHAR *filename,FILEFINDBUF4 *f)
    650 {
    651   CHAR        *p,szDirectory[CCHMAXPATH];
    652 
    653   if(WinIsWindow(grep->ghab,grep->hwndFiles)) {
     608static BOOL insert_grepfile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f)
     609{
     610  CHAR *p, szDirectory[CCHMAXPATH];
     611
     612  if (WinIsWindow(grep->ghab, grep->hwndFiles)) {
    654613    grep->numfiles++;
    655     strcpy(szDirectory,filename);
    656     p = strrchr(szDirectory,'\\');
    657     if(p) {
    658       if(p < szDirectory + 4)
    659         p++;
     614    strcpy(szDirectory, filename);
     615    p = strrchr(szDirectory, '\\');
     616    if (p) {
     617      if (p < szDirectory + 4)
     618        p++;
    660619      *p = 0;
    661       if(!grep->insertffb) {
    662         grep->insertffb = xmallocz(sizeof(FILEFINDBUF4 *) *
    663                                    (grep->FilesToGet + 1),pszSrcFile,__LINE__);
    664         if(!grep->insertffb)
    665           return FALSE;
    666         grep->dir = xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1),pszSrcFile,__LINE__);
    667         if(!grep->dir) {
    668           free(grep->insertffb);
    669           return FALSE;
    670         }
    671       }
    672       grep->insertffb[grep->toinsert] = xmalloc(sizeof(FILEFINDBUF4),pszSrcFile,__LINE__);
    673       if(!grep->insertffb[grep->toinsert])
    674         return FALSE;
    675       memcpy(grep->insertffb[grep->toinsert],f,sizeof(FILEFINDBUF4));
    676       grep->dir[grep->toinsert] = xstrdup(szDirectory,pszSrcFile,__LINE__);
    677       if(!grep->dir) {
    678         free(grep->insertffb[grep->toinsert]);
    679         return FALSE;
     620      if (!grep->insertffb) {
     621        grep->insertffb = xmallocz(sizeof(FILEFINDBUF4 *) *
     622                                   (grep->FilesToGet + 1), pszSrcFile,
     623                                   __LINE__);
     624        if (!grep->insertffb)
     625          return FALSE;
     626        grep->dir =
     627          xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1), pszSrcFile,
     628                   __LINE__);
     629        if (!grep->dir) {
     630          free(grep->insertffb);
     631          return FALSE;
     632        }
     633      }
     634      grep->insertffb[grep->toinsert] =
     635        xmalloc(sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
     636      if (!grep->insertffb[grep->toinsert])
     637        return FALSE;
     638      memcpy(grep->insertffb[grep->toinsert], f, sizeof(FILEFINDBUF4));
     639      grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__);
     640      if (!grep->dir) {
     641        free(grep->insertffb[grep->toinsert]);
     642        return FALSE;
    680643      }
    681644      grep->insertedbytes += f->cbFile + CBLIST_TO_EASIZE(f->cbList);
    682645      grep->toinsert++;
    683       if(grep->toinsert == grep->FilesToGet)
    684         return doinsertion(grep);
     646      if (grep->toinsert == grep->FilesToGet)
     647        return doinsertion(grep);
    685648      return TRUE;
    686649    }
     
    691654}
    692655
    693 
    694 static BOOL doonefile (GREP *grep,CHAR *filename,FILEFINDBUF4 *f)
     656static BOOL doonefile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f)
    695657{
    696658  /* process a single file */
    697659
    698   CHAR           *input;
    699   FILE           *inputFile;
    700   ULONG           pos;
    701   BOOL            ret = FALSE,strmatch = FALSE;
     660  CHAR *input;
     661  FILE *inputFile;
     662  ULONG pos;
     663  BOOL ret = FALSE, strmatch = FALSE;
    702664
    703665  grep->fileCount++;
    704   if(grep->sayfiles)
    705     WinSetWindowText(grep->hwndCurFile,
    706                      filename);
    707 
    708   if(grep->greaterthan || grep->lessthan) {
    709 
    710     BOOL  keep = TRUE;
     666  if (grep->sayfiles)
     667    WinSetWindowText(grep->hwndCurFile, filename);
     668
     669  if (grep->greaterthan || grep->lessthan) {
     670
     671    BOOL keep = TRUE;
    711672    ULONG adjsize;
    712673
    713     adjsize = f->cbFile +
    714               (grep->searchEAs ? CBLIST_TO_EASIZE(f->cbList) : 0);
    715     if(grep->greaterthan) {
    716       if(adjsize < grep->greaterthan)
    717         keep = FALSE;
    718     }
    719     if(keep && grep->lessthan) {
    720       if(adjsize > grep->lessthan)
    721         keep = FALSE;
    722     }
    723     if(!keep)
     674    adjsize = f->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(f->cbList) : 0);
     675    if (grep->greaterthan) {
     676      if (adjsize < grep->greaterthan)
     677        keep = FALSE;
     678    }
     679    if (keep && grep->lessthan) {
     680      if (adjsize > grep->lessthan)
     681        keep = FALSE;
     682    }
     683    if (!keep)
    724684      return ret;
    725685  }
    726686
    727   if(grep->newerthan || grep->olderthan) {
    728 
    729     BOOL  keep = TRUE;
     687  if (grep->newerthan || grep->olderthan) {
     688
     689    BOOL keep = TRUE;
    730690    ULONG numsecs;
    731691
    732     numsecs = SecsSince1980(&f->fdateLastWrite,
    733                             &f->ftimeLastWrite);
    734     if(grep->newerthan) {
    735       if(numsecs < grep->newerthan)
    736         keep = FALSE;
    737     }
    738     if(keep && grep->olderthan) {
    739       if(numsecs > grep->olderthan)
    740         keep = FALSE;
    741     }
    742     if(!keep)
     692    numsecs = SecsSince1980(&f->fdateLastWrite, &f->ftimeLastWrite);
     693    if (grep->newerthan) {
     694      if (numsecs < grep->newerthan)
     695        keep = FALSE;
     696    }
     697    if (keep && grep->olderthan) {
     698      if (numsecs > grep->olderthan)
     699        keep = FALSE;
     700    }
     701    if (!keep)
    743702      return ret;
    744703  }
    745704
    746   if((!grep->searchEAs && !grep->searchFiles) ||
    747       !*grep->searchPattern)    /* just a find */
    748     return insert_grepfile(grep,filename,f);
    749 
    750   if(grep->searchEAs) {
    751 
    752     HOLDFEA *head,*info;
    753     USHORT  type,len;
    754     BOOL    alltext;
    755     CHAR    *data,temp;
    756 
    757     head = GetFileEAs(filename,FALSE,TRUE);
    758     if(head) {
     705  if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern)        /* just a find */
     706    return insert_grepfile(grep, filename, f);
     707
     708  if (grep->searchEAs) {
     709
     710    HOLDFEA *head, *info;
     711    USHORT type, len;
     712    BOOL alltext;
     713    CHAR *data, temp;
     714
     715    head = GetFileEAs(filename, FALSE, TRUE);
     716    if (head) {
    759717      info = head;
    760       while(info && !strmatch) {
    761         alltext = TRUE;
    762         switch(*(USHORT *)info->value) {
    763           case EAT_ASCII:
    764             if(match(info->value + (sizeof(USHORT) * 2),
    765                      grep->searchPattern,grep->absFlag,
    766                      (grep->caseFlag == FALSE),
    767                      info->cbValue - (sizeof(USHORT) * 2),
    768                      grep->numlines,
    769                      grep->matched,
    770                      !grep->findifany)) {
    771               strmatch = TRUE;
    772             }
    773             break;
    774           case EAT_MVST:
    775             type = *(USHORT *)(info->value + (sizeof(USHORT) * 3));
    776             if(type == EAT_ASCII) {
    777               data = info->value + (sizeof(USHORT) * 4);
    778               len = *(USHORT *)data;
    779               data += sizeof(USHORT);
    780               while((data - info->value) + len <=
    781                     info->cbValue) {
    782                 temp = *(data + len);
    783                 *(data + len) = 0;
    784                 if(match(data,
    785                          grep->searchPattern,
    786                          grep->absFlag,
    787                          (grep->caseFlag == FALSE),
    788                          len,
    789                          grep->numlines,
    790                          grep->matched,
    791                          !grep->findifany)) {
    792                   strmatch = TRUE;
    793                   break;
    794                 }
    795                 data += len;
    796                 if(data - info->value >= info->cbValue)
    797                   break;
    798                 *data = temp;
    799                 len = *(USHORT *)data;
    800                 data += sizeof(USHORT);
    801               }
    802             }
    803             break;
    804           case EAT_MVMT:
    805             data = info->value + (sizeof(USHORT) * 3);
    806             type = *(USHORT *)data;
    807             data += sizeof(USHORT);
    808             len = *(USHORT *)data;
    809             data += sizeof(USHORT);
    810             while((data - info->value) - len <=
    811                   info->cbValue) {
    812               if(type != EAT_ASCII) {
    813                 alltext = FALSE;
    814                 break;
    815               }
    816               data += len;
    817               if(data - info->value >= info->cbValue)
    818                 break;
    819               type = *(USHORT *)data;
    820               data += sizeof(USHORT);
    821               len = *(USHORT *)data;
    822               data += sizeof(USHORT);
    823             }
    824             if(alltext) {
    825               data = info->value + (sizeof(USHORT) * 3);
    826               type = *(USHORT *)data;
    827               data += sizeof(USHORT);
    828               len = *(USHORT *)data;
    829               data += sizeof(USHORT);
    830               while((data - info->value) - len <=
    831                     info->cbValue) {
    832                 temp = *(data + len);
    833                 *(data + len) = 0;
    834                 if(match(data,
    835                          grep->searchPattern,
    836                          grep->absFlag,
    837                          (grep->caseFlag == FALSE),
    838                          len,
    839                          grep->numlines,
    840                          grep->matched,
    841                          !grep->findifany)) {
    842                   strmatch = TRUE;
    843                   break;
    844                 }
    845                 data += len;
    846                 *data = temp;
    847                 if(data - info->value >= info->cbValue)
    848                   break;
    849                 type = *(USHORT *)data;
    850                 data += sizeof(USHORT);
    851                 len = *(USHORT *)data;
    852                 data += sizeof(USHORT);
    853               }
    854             }
    855             break;
    856           default:
    857             break;
    858         }
    859         info = info->next;
    860       } // while
     718      while (info && !strmatch) {
     719        alltext = TRUE;
     720        switch (*(USHORT *) info->value) {
     721        case EAT_ASCII:
     722          if (match(info->value + (sizeof(USHORT) * 2),
     723                    grep->searchPattern, grep->absFlag,
     724                    (grep->caseFlag == FALSE),
     725                    info->cbValue - (sizeof(USHORT) * 2),
     726                    grep->numlines, grep->matched, !grep->findifany)) {
     727            strmatch = TRUE;
     728          }
     729          break;
     730        case EAT_MVST:
     731          type = *(USHORT *) (info->value + (sizeof(USHORT) * 3));
     732          if (type == EAT_ASCII) {
     733            data = info->value + (sizeof(USHORT) * 4);
     734            len = *(USHORT *) data;
     735            data += sizeof(USHORT);
     736            while ((data - info->value) + len <= info->cbValue) {
     737              temp = *(data + len);
     738              *(data + len) = 0;
     739              if (match(data,
     740                        grep->searchPattern,
     741                        grep->absFlag,
     742                        (grep->caseFlag == FALSE),
     743                        len,
     744                        grep->numlines, grep->matched, !grep->findifany)) {
     745                strmatch = TRUE;
     746                break;
     747              }
     748              data += len;
     749              if (data - info->value >= info->cbValue)
     750                break;
     751              *data = temp;
     752              len = *(USHORT *) data;
     753              data += sizeof(USHORT);
     754            }
     755          }
     756          break;
     757        case EAT_MVMT:
     758          data = info->value + (sizeof(USHORT) * 3);
     759          type = *(USHORT *) data;
     760          data += sizeof(USHORT);
     761          len = *(USHORT *) data;
     762          data += sizeof(USHORT);
     763          while ((data - info->value) - len <= info->cbValue) {
     764            if (type != EAT_ASCII) {
     765              alltext = FALSE;
     766              break;
     767            }
     768            data += len;
     769            if (data - info->value >= info->cbValue)
     770              break;
     771            type = *(USHORT *) data;
     772            data += sizeof(USHORT);
     773            len = *(USHORT *) data;
     774            data += sizeof(USHORT);
     775          }
     776          if (alltext) {
     777            data = info->value + (sizeof(USHORT) * 3);
     778            type = *(USHORT *) data;
     779            data += sizeof(USHORT);
     780            len = *(USHORT *) data;
     781            data += sizeof(USHORT);
     782            while ((data - info->value) - len <= info->cbValue) {
     783              temp = *(data + len);
     784              *(data + len) = 0;
     785              if (match(data,
     786                        grep->searchPattern,
     787                        grep->absFlag,
     788                        (grep->caseFlag == FALSE),
     789                        len,
     790                        grep->numlines, grep->matched, !grep->findifany)) {
     791                strmatch = TRUE;
     792                break;
     793              }
     794              data += len;
     795              *data = temp;
     796              if (data - info->value >= info->cbValue)
     797                break;
     798              type = *(USHORT *) data;
     799              data += sizeof(USHORT);
     800              len = *(USHORT *) data;
     801              data += sizeof(USHORT);
     802            }
     803          }
     804          break;
     805        default:
     806          break;
     807        }
     808        info = info->next;
     809      }                                 // while
    861810      Free_FEAList(head);
    862811      DosSleep(1L);
     
    864813  }
    865814
    866   if(grep->searchFiles) {
    867     input = xmalloc(65537,pszSrcFile,__LINE__);
    868     if(input) {
     815  if (grep->searchFiles) {
     816    input = xmalloc(65537, pszSrcFile, __LINE__);
     817    if (input) {
    869818      LONG len;
    870       inputFile = _fsopen(filename,"rb",SH_DENYNO);
     819
     820      inputFile = _fsopen(filename, "rb", SH_DENYNO);
    871821      if (inputFile) {
    872         pos = ftell(inputFile);
    873         while(!feof(inputFile)) {
    874           if(pos)
    875             fseek(inputFile,pos - 1024,SEEK_SET);
    876           len = fread(input,1,65536,inputFile);
    877           if(len >= 0) {
    878             if(*grep->stopflag)
    879               break;
    880             if(match(input,
    881                      grep->searchPattern,
    882                      grep->absFlag,
    883                      (grep->caseFlag == FALSE),
    884                      len,
    885                      grep->numlines,
    886                      grep->matched,
    887                      !grep->findifany)) {
    888               strmatch = TRUE;
    889               break;
    890             }
    891           }
    892           else
    893             break;
    894         }
    895         fclose(inputFile) ;
     822        pos = ftell(inputFile);
     823        while (!feof(inputFile)) {
     824          if (pos)
     825            fseek(inputFile, pos - 1024, SEEK_SET);
     826          len = fread(input, 1, 65536, inputFile);
     827          if (len >= 0) {
     828            if (*grep->stopflag)
     829              break;
     830            if (match(input,
     831                      grep->searchPattern,
     832                      grep->absFlag,
     833                      (grep->caseFlag == FALSE),
     834                      len, grep->numlines, grep->matched, !grep->findifany)) {
     835              strmatch = TRUE;
     836              break;
     837            }
     838          }
     839          else
     840            break;
     841        }
     842        fclose(inputFile);
    896843      }
    897844      free(input);
     
    902849Match:
    903850
    904   if(strmatch)
    905     ret = insert_grepfile(grep,
    906                           filename,
    907                           f);
     851  if (strmatch)
     852    ret = insert_grepfile(grep, filename, f);
    908853  return ret;
    909854}
    910 
    911855
    912856#pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock)
     
    914858#pragma alloc_text(DUPES,comparenamesbe,comparesizesq,comparesizesb)
    915859
    916 static LONG cr3tab[] = {    /* CRC polynomial 0xEDB88320 */
     860static LONG cr3tab[] = {        /* CRC polynomial 0xEDB88320 */
    917861
    918862  0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
     
    982926};
    983927
    984 
    985 LONG CRCBlock (register CHAR *str, register INT blklen, register LONG crc)
     928LONG CRCBlock(register CHAR * str, register INT blklen, register LONG crc)
    986929{
    987930  while (blklen--) {
    988     crc = cr3tab[((INT) crc ^ *str) & 0xff] ^ (((ULONG)crc >> 8) & 0x00FFFFFF);
     931    crc =
     932      cr3tab[((INT) crc ^ *str) & 0xff] ^ (((ULONG) crc >> 8) & 0x00FFFFFF);
    989933    str++;
    990934  }
     
    992936}
    993937
    994 
    995 LONG CRCFile (CHAR *filename,INT *error)
    996 {
    997   LONG CRC = -1L,len;
     938LONG CRCFile(CHAR * filename, INT * error)
     939{
     940  LONG CRC = -1L, len;
    998941  FILE *fp;
    999942  CHAR *buffer;
    1000943
    1001944  *error = 0;
    1002   buffer = xmalloc(65535,pszSrcFile,__LINE__);
     945  buffer = xmalloc(65535, pszSrcFile, __LINE__);
    1003946  if (!buffer)
    1004947    *error = -1;
    1005948  else {
    1006     fp = _fsopen(filename,"rb",SH_DENYNO);
     949    fp = _fsopen(filename, "rb", SH_DENYNO);
    1007950    if (!fp)
    1008951      *error = -2;
    1009952    else {
    1010       while(!feof(fp)) {
    1011         len = fread(buffer,1,65535,fp);
    1012         if(len && len < 65536L)
    1013           CRC = CRCBlock(buffer,len,CRC);
    1014         else
    1015           break;
    1016         DosSleep(0L);
     953      while (!feof(fp)) {
     954        len = fread(buffer, 1, 65535, fp);
     955        if (len && len < 65536L)
     956          CRC = CRCBlock(buffer, len, CRC);
     957        else
     958          break;
     959        DosSleep(0L);
    1017960      }
    1018961      fclose(fp);
     
    1024967}
    1025968
    1026 
    1027 static VOID FreeDupes (GREP *g)
    1028 {
    1029   DUPES *i,*next;
     969static VOID FreeDupes(GREP * g)
     970{
     971  DUPES *i, *next;
    1030972
    1031973  i = g->dupehead;
    1032   while(i) {
     974  while (i) {
    1033975    next = i->next;
    1034     if(i->name)
     976    if (i->name)
    1035977      free(i->name);
    1036978    free(i);
     
    1038980  }
    1039981  g->dupehead = g->dupelast = NULL;
    1040   if(g->dupenames)
     982  if (g->dupenames)
    1041983    free(g->dupenames);
    1042   if(g->dupesizes)
     984  if (g->dupesizes)
    1043985    free(g->dupesizes);
    1044986  g->dupesizes = g->dupenames = NULL;
    1045987}
    1046988
    1047 
    1048 int comparenamesq (const void *v1,const void *v2)
    1049 {
    1050   DUPES *d1 = *(DUPES **)v1;
    1051   DUPES *d2 = *(DUPES **)v2;
    1052   CHAR  *p1,*p2;
    1053 
    1054   p1 = strrchr(d1->name,'\\');
    1055   if(p1)
     989int comparenamesq(const void *v1, const void *v2)
     990{
     991  DUPES *d1 = *(DUPES **) v1;
     992  DUPES *d2 = *(DUPES **) v2;
     993  CHAR *p1, *p2;
     994
     995  p1 = strrchr(d1->name, '\\');
     996  if (p1)
    1056997    p1++;
    1057998  else
    1058999    p1 = d1->name;
    1059   p2 = strrchr(d2->name,'\\');
    1060   if(p2)
     1000  p2 = strrchr(d2->name, '\\');
     1001  if (p2)
    10611002    p2++;
    10621003  else
    10631004    p2 = d2->name;
    1064   return stricmp(p1,p2);
    1065 }
    1066 
    1067 
    1068 int comparenamesqe (const void *v1,const void *v2)
    1069 {
    1070   DUPES *d1 = *(DUPES **)v1;
    1071   DUPES *d2 = *(DUPES **)v2;
    1072   CHAR  *p1,*p2,*p1e,*p2e,e1,e2;
    1073   int    ret;
    1074 
    1075   p1 = strrchr(d1->name,'\\');
    1076   if(p1)
     1005  return stricmp(p1, p2);
     1006}
     1007
     1008int comparenamesqe(const void *v1, const void *v2)
     1009{
     1010  DUPES *d1 = *(DUPES **) v1;
     1011  DUPES *d2 = *(DUPES **) v2;
     1012  CHAR *p1, *p2, *p1e, *p2e, e1, e2;
     1013  int ret;
     1014
     1015  p1 = strrchr(d1->name, '\\');
     1016  if (p1)
    10771017    p1++;
    10781018  else
    10791019    p1 = d1->name;
    1080   p1e = strrchr(p1,'.');
    1081   if(p1e) {
     1020  p1e = strrchr(p1, '.');
     1021  if (p1e) {
    10821022    e1 = *p1e;
    10831023    *p1e = 0;
    10841024  }
    1085   p2 = strrchr(d2->name,'\\');
    1086   if(p2)
     1025  p2 = strrchr(d2->name, '\\');
     1026  if (p2)
    10871027    p2++;
    10881028  else
    10891029    p2 = d2->name;
    1090   p2e = strrchr(p2,'.');
    1091   if(p2e) {
     1030  p2e = strrchr(p2, '.');
     1031  if (p2e) {
    10921032    e2 = *p2e;
    10931033    *p2e = 0;
    10941034  }
    1095   ret = stricmp(p1,p2);
    1096   if(p1e)
     1035  ret = stricmp(p1, p2);
     1036  if (p1e)
    10971037    *p1e = e1;
    1098   if(p2e)
     1038  if (p2e)
    10991039    *p2e = e2;
    11001040  return ret;
    11011041}
    11021042
    1103 
    1104 int comparesizesq (const void *v1,const void *v2)
    1105 {
    1106   DUPES *d1 = *(DUPES **)v1;
    1107   DUPES *d2 = *(DUPES **)v2;
     1043int comparesizesq(const void *v1, const void *v2)
     1044{
     1045  DUPES *d1 = *(DUPES **) v1;
     1046  DUPES *d2 = *(DUPES **) v2;
    11081047
    11091048  return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
    11101049}
    11111050
    1112 
    1113 int comparenamesb (const void *v1,const void *v2)
    1114 {
    1115   DUPES *d1 = (DUPES *)v1;
    1116   DUPES *d2 = *(DUPES **)v2;
    1117   CHAR  *p1,*p2;
    1118 
    1119   p1 = strrchr(d1->name,'\\');
    1120   if(p1)
     1051int comparenamesb(const void *v1, const void *v2)
     1052{
     1053  DUPES *d1 = (DUPES *) v1;
     1054  DUPES *d2 = *(DUPES **) v2;
     1055  CHAR *p1, *p2;
     1056
     1057  p1 = strrchr(d1->name, '\\');
     1058  if (p1)
    11211059    p1++;
    11221060  else
    11231061    p1 = d1->name;
    1124   p2 = strrchr(d2->name,'\\');
    1125   if(p2)
     1062  p2 = strrchr(d2->name, '\\');
     1063  if (p2)
    11261064    p2++;
    11271065  else
    11281066    p2 = d2->name;
    1129   return stricmp(p1,p2);
    1130 }
    1131 
    1132 
    1133 int comparenamesbe (const void *v1,const void *v2)
    1134 {
    1135   DUPES *d1 = (DUPES *)v1;
    1136   DUPES *d2 = *(DUPES **)v2;
    1137   CHAR  *p1,*p2,*p1e,*p2e,e1,e2;
    1138   int    ret;
    1139 
    1140   p1 = strrchr(d1->name,'\\');
    1141   if(p1)
     1067  return stricmp(p1, p2);
     1068}
     1069
     1070int comparenamesbe(const void *v1, const void *v2)
     1071{
     1072  DUPES *d1 = (DUPES *) v1;
     1073  DUPES *d2 = *(DUPES **) v2;
     1074  CHAR *p1, *p2, *p1e, *p2e, e1, e2;
     1075  int ret;
     1076
     1077  p1 = strrchr(d1->name, '\\');
     1078  if (p1)
    11421079    p1++;
    11431080  else
    11441081    p1 = d1->name;
    1145   p1e = strrchr(p1,'.');
    1146   if(p1e) {
     1082  p1e = strrchr(p1, '.');
     1083  if (p1e) {
    11471084    e1 = *p1e;
    11481085    *p1e = 0;
    11491086  }
    1150   p2 = strrchr(d2->name,'\\');
    1151   if(p2)
     1087  p2 = strrchr(d2->name, '\\');
     1088  if (p2)
    11521089    p2++;
    11531090  else
    11541091    p2 = d2->name;
    1155   p2e = strrchr(p2,'.');
    1156   if(p2e) {
     1092  p2e = strrchr(p2, '.');
     1093  if (p2e) {
    11571094    e2 = *p2e;
    11581095    *p2e = 0;
    11591096  }
    1160   ret = stricmp(p1,p2);
    1161   if(p1e)
     1097  ret = stricmp(p1, p2);
     1098  if (p1e)
    11621099    *p1e = e1;
    1163   if(p2e)
     1100  if (p2e)
    11641101    *p2e = e2;
    11651102  return ret;
    11661103}
    11671104
    1168 
    1169 int comparesizesb (const void *v1,const void *v2)
    1170 {
    1171   DUPES *d1 = (DUPES *)v1;
    1172   DUPES *d2 = *(DUPES **)v2;
     1105int comparesizesb(const void *v1, const void *v2)
     1106{
     1107  DUPES *d1 = (DUPES *) v1;
     1108  DUPES *d2 = *(DUPES **) v2;
    11731109
    11741110  return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
    11751111}
    11761112
    1177 
    1178 static VOID FillDupes (GREP *g)
    1179 {
    1180   DUPES         *c,*i,**r;
    1181   register CHAR *pc,*pi;
    1182   CHAR         **list = NULL;
    1183   INT            numfiles = 0,numalloced = 0,error;
    1184   register ULONG x = 0L,y = 0L;
    1185   ULONG          cntr = 100;
    1186 
    1187   if(g->CRCdupes)
     1113static VOID FillDupes(GREP * g)
     1114{
     1115  DUPES *c, *i, **r;
     1116  register CHAR *pc, *pi;
     1117  CHAR **list = NULL;
     1118  INT numfiles = 0, numalloced = 0, error;
     1119  register ULONG x = 0L, y = 0L;
     1120  ULONG cntr = 100;
     1121
     1122  if (g->CRCdupes)
    11881123    cntr = 50;
    11891124  i = g->dupehead;
     
    11931128  }
    11941129  if (x) {
    1195     WinSetWindowText(g->hwndCurFile,
    1196                      GetPString(IDS_GREPDUPESORTINGTEXT));
     1130    WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
    11971131    DosSleep(1L);
    11981132    g->dupenames = xmalloc(sizeof(DUPES *) * (x + 1), pszSrcFile, __LINE__);
     
    12011135    if (g->dupenames && (g->nosizedupes || g->dupesizes)) {
    12021136      i = g->dupehead;
    1203       while(i) {
    1204         g->dupenames[y] = i;
    1205         if(!g->nosizedupes)
    1206           g->dupesizes[y] = i;
    1207         i = i->next;
    1208         y++;
     1137      while (i) {
     1138        g->dupenames[y] = i;
     1139        if (!g->nosizedupes)
     1140          g->dupesizes[y] = i;
     1141        i = i->next;
     1142        y++;
    12091143      }
    12101144      g->dupenames[y] = NULL;
    12111145      if (!g->nosizedupes)
    1212         g->dupesizes[y] = NULL;
     1146        g->dupesizes[y] = NULL;
    12131147      DosSleep(1L);
    12141148      qsort(g->dupenames,
    1215             x,
    1216             sizeof(DUPES *),
    1217             ((g->ignoreextdupes) ?
    1218              comparenamesqe :
    1219              comparenamesq));
     1149            x,
     1150            sizeof(DUPES *),
     1151            ((g->ignoreextdupes) ? comparenamesqe : comparenamesq));
    12201152      DosSleep(1L);
    12211153      if (!g->nosizedupes) {
    1222         qsort(g->dupesizes,
    1223               x,
    1224               sizeof(DUPES *),
    1225               comparesizesq);
    1226         DosSleep(1L);
    1227       }
    1228       WinSetWindowText(g->hwndCurFile,
    1229                        GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1154        qsort(g->dupesizes, x, sizeof(DUPES *), comparesizesq);
     1155        DosSleep(1L);
     1156      }
     1157      WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
    12301158
    12311159      i = g->dupehead;
    12321160      y = 0L;
    1233       while(i) {
    1234         if(*g->stopflag)
    1235           break;
    1236         if(!(i->flags & GF_SKIPME)) {
    1237           r = (DUPES **)bsearch(i,g->dupenames,x,sizeof(DUPES *),
    1238                                 ((g->ignoreextdupes) ? comparenamesbe :
    1239                                  comparenamesb));
    1240           if(r) {
    1241             while(r > g->dupenames && ((g->ignoreextdupes) ?
    1242                   !comparenamesqe((r - 1),&i) :
    1243                   !comparenamesq((r - 1),&i)))
    1244               r--;
    1245             while(*r && ((g->ignoreextdupes) ?
    1246                          !comparenamesqe(r,&i) :
    1247                          !comparenamesq(r,&i))) {
    1248               if(*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) {
    1249                 r++;
    1250                 continue;
    1251               }
    1252               if(g->CRCdupes) {
    1253                 if((*r)->CRC == -1L) {
    1254                   (*r)->CRC = CRCFile((*r)->name,&error);
    1255                   if(error)
    1256                     (*r)->CRC = -1L;
    1257                   else if((*r)->CRC == -1L)
    1258                     (*r)->CRC = 0L;
    1259                 }
    1260                 if(i->CRC == -1L) {
    1261                   i->CRC = CRCFile(i->name,&error);
    1262                   if(error)
    1263                     i->CRC = -1L;
    1264                   else if(i->CRC == -1L)
    1265                     i->CRC = 0L;
    1266                 }
    1267                 if(((*r)->size != i->size) || ((*r)->CRC != -1L &&
    1268                    i->CRC != -1L && (*r)->CRC != i->CRC)) {
    1269                   r++;
    1270                   continue;
    1271                 }
    1272               }
    1273               if(!AddToList((*r)->name,
    1274                             &list,
    1275                             &numfiles,
    1276                             &numalloced)) {
    1277                 (*r)->flags |= GF_INSERTED;
    1278                 if(g->sayfiles)
    1279                   WinSetWindowText(g->hwndFiles,
    1280                                    (*r)->name);
    1281                 if((*r)->size == i->size &&
    1282                    (i->date.year == (*r)->date.year &&
    1283                     i->date.month == (*r)->date.month &&
    1284                     i->date.day == (*r)->date.day &&
    1285                     i->time.hours == (*r)->time.hours &&
    1286                     i->time.minutes == (*r)->time.minutes &&
    1287                     i->time.twosecs == (*r)->time.twosecs))
    1288                   (*r)->flags |= GF_SKIPME;
    1289               }
    1290               if(!(i->flags & (GF_INSERTED | GF_SKIPME))) {
    1291                 if(!AddToList(i->name,
    1292                               &list,
    1293                               &numfiles,
    1294                               &numalloced)) {
    1295                   i->flags |= GF_INSERTED;
    1296                   if((*r)->flags & GF_SKIPME)
    1297                     i->flags |= GF_SKIPME;
    1298                 }
    1299               }
    1300               r++;
    1301             }
    1302           }
    1303           if(!g->nosizedupes) {
    1304             r = (DUPES **)bsearch(i,
    1305                                   g->dupesizes,
    1306                                   x,
    1307                                   sizeof(DUPES *),
    1308                                   comparesizesb);
    1309             if(r) {
    1310               while(r > g->dupesizes && !comparesizesq((r - 1),&i))
    1311                 r--;
    1312               while(*r && !comparesizesq(r,&i)) {
    1313                 if(*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME)) ||
    1314                    (i->date.year != (*r)->date.year ||
    1315                     i->date.month != (*r)->date.month ||
    1316                     i->date.day != (*r)->date.day ||
    1317                     i->time.hours != (*r)->time.hours ||
    1318                     i->time.minutes != (*r)->time.minutes ||
    1319                     i->time.twosecs != (*r)->time.twosecs)) {
    1320                   r++;
    1321                   continue;
    1322                 }
    1323                 if(g->CRCdupes) {
    1324                   if((*r)->CRC == -1L) {
    1325                     (*r)->CRC = CRCFile((*r)->name,&error);
    1326                     if(error)
    1327                       (*r)->CRC = -1L;
    1328                     else if((*r)->CRC == -1L)
    1329                       (*r)->CRC = 0L;
    1330                   }
    1331                   if(i->CRC == -1L) {
    1332                     i->CRC = CRCFile(i->name,&error);
    1333                     if(error)
    1334                       i->CRC = -1L;
    1335                     else if(i->CRC == -1L)
    1336                       i->CRC = 0L;
    1337                   }
    1338                   if((*r)->CRC != -1L && i->CRC != -1L &&
    1339                      (*r)->CRC != i->CRC) {
    1340                     *r++;
    1341                     continue;
    1342                   }
    1343                 }
    1344                 if(!AddToList((*r)->name,
    1345                               &list,
    1346                               &numfiles,
    1347                               &numalloced)) {
    1348                   if(g->sayfiles)
    1349                     WinSetWindowText(g->hwndCurFile,
    1350                                      (*r)->name);
    1351                   (*r)->flags |= GF_INSERTED;
    1352                   if(((g->ignoreextdupes) ?
    1353                       comparenamesqe(r,&i) :
    1354                       comparenamesq(r,&i)))
    1355                     (*r)->flags |= GF_SKIPME;
    1356                 }
    1357                 if(!(i->flags & (GF_INSERTED | GF_SKIPME))) {
    1358                   if(!AddToList(i->name,
    1359                                 &list,
    1360                                 &numfiles,
    1361                                 &numalloced)) {
    1362                     i->flags |= GF_INSERTED;
    1363                     if((*r)->flags & GF_SKIPME)
    1364                       i->flags |= GF_SKIPME;
    1365                   }
    1366                 }
    1367                 r++;
    1368               }
    1369             }
    1370           }
    1371         }
    1372         i = i->next;
    1373         y++;
    1374         if(!(y % cntr)) {
    1375 
    1376           CHAR s[44];
    1377 
    1378           sprintf(s,
    1379                   GetPString(IDS_GREPDUPECHECKPROGTEXT),
    1380                   y,
    1381                   g->numfiles);
    1382           WinSetWindowText(g->hwndCurFile,
    1383                            s);
    1384           DosSleep(128L);
    1385         }
    1386         DosSleep(y % 2);
     1161      while (i) {
     1162        if (*g->stopflag)
     1163          break;
     1164        if (!(i->flags & GF_SKIPME)) {
     1165          r = (DUPES **) bsearch(i, g->dupenames, x, sizeof(DUPES *),
     1166                                 ((g->ignoreextdupes) ? comparenamesbe :
     1167                                  comparenamesb));
     1168          if (r) {
     1169            while (r > g->dupenames && ((g->ignoreextdupes) ?
     1170                                        !comparenamesqe((r - 1), &i) :
     1171                                        !comparenamesq((r - 1), &i)))
     1172              r--;
     1173            while (*r && ((g->ignoreextdupes) ?
     1174                          !comparenamesqe(r, &i) : !comparenamesq(r, &i))) {
     1175              if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) {
     1176                r++;
     1177                continue;
     1178              }
     1179              if (g->CRCdupes) {
     1180                if ((*r)->CRC == -1L) {
     1181                  (*r)->CRC = CRCFile((*r)->name, &error);
     1182                  if (error)
     1183                    (*r)->CRC = -1L;
     1184                  else if ((*r)->CRC == -1L)
     1185                    (*r)->CRC = 0L;
     1186                }
     1187                if (i->CRC == -1L) {
     1188                  i->CRC = CRCFile(i->name, &error);
     1189                  if (error)
     1190                    i->CRC = -1L;
     1191                  else if (i->CRC == -1L)
     1192                    i->CRC = 0L;
     1193                }
     1194                if (((*r)->size != i->size) || ((*r)->CRC != -1L &&
     1195                                                i->CRC != -1L
     1196                                                && (*r)->CRC != i->CRC)) {
     1197                  r++;
     1198                  continue;
     1199                }
     1200              }
     1201              if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
     1202                (*r)->flags |= GF_INSERTED;
     1203                if (g->sayfiles)
     1204                  WinSetWindowText(g->hwndFiles, (*r)->name);
     1205                if ((*r)->size == i->size &&
     1206                    (i->date.year == (*r)->date.year &&
     1207                     i->date.month == (*r)->date.month &&
     1208                     i->date.day == (*r)->date.day &&
     1209                     i->time.hours == (*r)->time.hours &&
     1210                     i->time.minutes == (*r)->time.minutes &&
     1211                     i->time.twosecs == (*r)->time.twosecs))
     1212                  (*r)->flags |= GF_SKIPME;
     1213              }
     1214              if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
     1215                if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
     1216                  i->flags |= GF_INSERTED;
     1217                  if ((*r)->flags & GF_SKIPME)
     1218                    i->flags |= GF_SKIPME;
     1219                }
     1220              }
     1221              r++;
     1222            }
     1223          }
     1224          if (!g->nosizedupes) {
     1225            r = (DUPES **) bsearch(i,
     1226                                   g->dupesizes,
     1227                                   x, sizeof(DUPES *), comparesizesb);
     1228            if (r) {
     1229              while (r > g->dupesizes && !comparesizesq((r - 1), &i))
     1230                r--;
     1231              while (*r && !comparesizesq(r, &i)) {
     1232                if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME)) ||
     1233                    (i->date.year != (*r)->date.year ||
     1234                     i->date.month != (*r)->date.month ||
     1235                     i->date.day != (*r)->date.day ||
     1236                     i->time.hours != (*r)->time.hours ||
     1237                     i->time.minutes != (*r)->time.minutes ||
     1238                     i->time.twosecs != (*r)->time.twosecs)) {
     1239                  r++;
     1240                  continue;
     1241                }
     1242                if (g->CRCdupes) {
     1243                  if ((*r)->CRC == -1L) {
     1244                    (*r)->CRC = CRCFile((*r)->name, &error);
     1245                    if (error)
     1246                      (*r)->CRC = -1L;
     1247                    else if ((*r)->CRC == -1L)
     1248                      (*r)->CRC = 0L;
     1249                  }
     1250                  if (i->CRC == -1L) {
     1251                    i->CRC = CRCFile(i->name, &error);
     1252                    if (error)
     1253                      i->CRC = -1L;
     1254                    else if (i->CRC == -1L)
     1255                      i->CRC = 0L;
     1256                  }
     1257                  if ((*r)->CRC != -1L && i->CRC != -1L &&
     1258                      (*r)->CRC != i->CRC) {
     1259                    *r++;
     1260                    continue;
     1261                  }
     1262                }
     1263                if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
     1264                  if (g->sayfiles)
     1265                    WinSetWindowText(g->hwndCurFile, (*r)->name);
     1266                  (*r)->flags |= GF_INSERTED;
     1267                  if (((g->ignoreextdupes) ?
     1268                       comparenamesqe(r, &i) : comparenamesq(r, &i)))
     1269                    (*r)->flags |= GF_SKIPME;
     1270                }
     1271                if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
     1272                  if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
     1273                    i->flags |= GF_INSERTED;
     1274                    if ((*r)->flags & GF_SKIPME)
     1275                      i->flags |= GF_SKIPME;
     1276                  }
     1277                }
     1278                r++;
     1279              }
     1280            }
     1281          }
     1282        }
     1283        i = i->next;
     1284        y++;
     1285        if (!(y % cntr)) {
     1286
     1287          CHAR s[44];
     1288
     1289          sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g->numfiles);
     1290          WinSetWindowText(g->hwndCurFile, s);
     1291          DosSleep(128L);
     1292        }
     1293        DosSleep(y % 2);
    13871294      }
    13881295    }
    13891296    else {
    13901297      // Insufficient memory - fall back
    1391       DosBeep(50,100);
    1392       WinSetWindowText(g->hwndCurFile,
    1393                        GetPString(IDS_GREPDUPECOMPARINGTEXT));
     1298      DosBeep(50, 100);
     1299      WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
    13941300      x = y = 0L;
    1395       if(g->dupenames) {
    1396         free(g->dupenames);
    1397         g->dupenames = NULL;
    1398       }
    1399       if(g->dupesizes) {
    1400         free(g->dupesizes);
    1401         g->dupesizes = NULL;
     1301      if (g->dupenames) {
     1302        free(g->dupenames);
     1303        g->dupenames = NULL;
     1304      }
     1305      if (g->dupesizes) {
     1306        free(g->dupesizes);
     1307        g->dupesizes = NULL;
    14021308      }
    14031309      i = g->dupehead;
    1404       while(i) {
    1405         if(*g->stopflag)
    1406           break;
    1407         if(!(i->flags & GF_SKIPME)) {
    1408           if(!(y % cntr)) {
    1409 
    1410             CHAR s[44];
    1411 
    1412             sprintf(s,
    1413                     GetPString(IDS_GREPDUPECHECKPROGTEXT),
    1414                     y,
    1415                     g->numfiles);
    1416             WinSetWindowText(g->hwndCurFile,
    1417                              s);
    1418             DosSleep(0L);
    1419           }
    1420           y++;
    1421           pi = strrchr(i->name,'\\');
    1422           if(pi)
    1423             *pi++;
    1424           else
    1425             pi = i->name;
    1426           c = g->dupehead;
    1427           while(c) {
    1428             if(*g->stopflag)
    1429               break;
    1430             if(c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
    1431               x++;
    1432               pc = strrchr(c->name,'\\');
    1433               if(pc)
    1434                 pc++;
    1435               else
    1436                 pc = c->name;
    1437               if((!g->nosizedupes && i->size == c->size &&
    1438                   i->date.year == c->date.year &&
    1439                   i->date.month == c->date.month &&
    1440                   i->date.day == c->date.day &&
    1441                   i->time.hours == c->time.hours &&
    1442                   i->time.minutes == c->time.minutes &&
    1443                   i->time.twosecs == c->time.twosecs) ||
    1444                  !stricmp(pc,pi)) {         /* potential dupe */
    1445                 if(g->CRCdupes) {
    1446                   if(g->CRCdupes) {
    1447                     if(c->CRC == -1L) {
    1448                       c->CRC = CRCFile(c->name,&error);
    1449                       if(error)
    1450                         c->CRC = -1L;
    1451                       else if(c->CRC == -1L)
    1452                         c->CRC = 0L;
    1453                     }
    1454                     if(i->CRC == -1L) {
    1455                       i->CRC = CRCFile(i->name,&error);
    1456                       if(error)
    1457                         i->CRC = -1L;
    1458                       else if(i->CRC == -1L)
    1459                           i->CRC = 0L;
    1460                     }
    1461                     if((c->size != i->size) || (c->CRC != -1L &&
    1462                        i->CRC != -1L && c->CRC != i->CRC)) {
    1463                       c = c->next;
    1464                       continue;
    1465                     }
    1466                   }
    1467                 }
    1468                 if(AddToList(c->name,
    1469                              &list,
    1470                              &numfiles,
    1471                              &numalloced))
    1472                   goto BreakOut;                // Failed
    1473                 if(!(i->flags & GF_INSERTED)) {
    1474                   if(AddToList(i->name,
    1475                                &list,
    1476                                &numfiles,
    1477                                &numalloced))
    1478                     goto BreakOut;              // Failed
    1479                 }
    1480                 if(g->sayfiles)
    1481                   WinSetWindowText(g->hwndCurFile,
    1482                                    pc);
    1483                 c->flags |= GF_INSERTED;
    1484                 i->flags |= GF_INSERTED;
    1485                 if(!stricmp(pc,pi)) {
    1486                   c->flags |= GF_SKIPME;
    1487                   i->flags |= GF_SKIPME;
    1488                 }
    1489               }
    1490               else if(!(x % 100L))
    1491                 DosSleep(1L);
    1492             }
    1493             c = c->next;
    1494           }
    1495         }
    1496         i = i->next;
     1310      while (i) {
     1311        if (*g->stopflag)
     1312          break;
     1313        if (!(i->flags & GF_SKIPME)) {
     1314          if (!(y % cntr)) {
     1315
     1316            CHAR s[44];
     1317
     1318            sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g->numfiles);
     1319            WinSetWindowText(g->hwndCurFile, s);
     1320            DosSleep(0L);
     1321          }
     1322          y++;
     1323          pi = strrchr(i->name, '\\');
     1324          if (pi)
     1325            *pi++;
     1326          else
     1327            pi = i->name;
     1328          c = g->dupehead;
     1329          while (c) {
     1330            if (*g->stopflag)
     1331              break;
     1332            if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
     1333              x++;
     1334              pc = strrchr(c->name, '\\');
     1335              if (pc)
     1336                pc++;
     1337              else
     1338                pc = c->name;
     1339              if ((!g->nosizedupes && i->size == c->size && i->date.year == c->date.year && i->date.month == c->date.month && i->date.day == c->date.day && i->time.hours == c->time.hours && i->time.minutes == c->time.minutes && i->time.twosecs == c->time.twosecs) || !stricmp(pc, pi)) {  /* potential dupe */
     1340                if (g->CRCdupes) {
     1341                  if (g->CRCdupes) {
     1342                    if (c->CRC == -1L) {
     1343                      c->CRC = CRCFile(c->name, &error);
     1344                      if (error)
     1345                        c->CRC = -1L;
     1346                      else if (c->CRC == -1L)
     1347                        c->CRC = 0L;
     1348                    }
     1349                    if (i->CRC == -1L) {
     1350                      i->CRC = CRCFile(i->name, &error);
     1351                      if (error)
     1352                        i->CRC = -1L;
     1353                      else if (i->CRC == -1L)
     1354                        i->CRC = 0L;
     1355                    }
     1356                    if ((c->size != i->size) || (c->CRC != -1L &&
     1357                                                 i->CRC != -1L
     1358                                                 && c->CRC != i->CRC)) {
     1359                      c = c->next;
     1360                      continue;
     1361                    }
     1362                  }
     1363                }
     1364                if (AddToList(c->name, &list, &numfiles, &numalloced))
     1365                  goto BreakOut;        // Failed
     1366                if (!(i->flags & GF_INSERTED)) {
     1367                  if (AddToList(i->name, &list, &numfiles, &numalloced))
     1368                    goto BreakOut;      // Failed
     1369                }
     1370                if (g->sayfiles)
     1371                  WinSetWindowText(g->hwndCurFile, pc);
     1372                c->flags |= GF_INSERTED;
     1373                i->flags |= GF_INSERTED;
     1374                if (!stricmp(pc, pi)) {
     1375                  c->flags |= GF_SKIPME;
     1376                  i->flags |= GF_SKIPME;
     1377                }
     1378              }
     1379              else if (!(x % 100L))
     1380                DosSleep(1L);
     1381            }
     1382            c = c->next;
     1383          }
     1384        }
     1385        i = i->next;
    14971386      }
    14981387    }
     
    15001389BreakOut:
    15011390  FreeDupes(g);
    1502   if(numfiles && list) {
    1503     if(!PostMsg(g->hwndFiles,
    1504                 WM_COMMAND,
    1505                 MPFROM2SHORT(IDM_COLLECTOR,0),
    1506                 MPFROMP(list)))
     1391  if (numfiles && list) {
     1392    if (!PostMsg(g->hwndFiles,
     1393                 WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
    15071394      FreeList(list);
    15081395  }
     
    15111398}
    15121399
    1513 
    1514 static BOOL InsertDupe (GREP *g,CHAR *dir,FILEFINDBUF4 *f)
     1400static BOOL InsertDupe(GREP * g, CHAR * dir, FILEFINDBUF4 * f)
    15151401{
    15161402  DUPES *info;
    15171403
    15181404  if (*dir) {
    1519     info = xmallocz(sizeof(DUPES),pszSrcFile,__LINE__);
     1405    info = xmallocz(sizeof(DUPES), pszSrcFile, __LINE__);
    15201406    if (!info)
    15211407      return FALSE;
    15221408    else {
    1523       info->name = xstrdup(dir,pszSrcFile,__LINE__);
     1409      info->name = xstrdup(dir, pszSrcFile, __LINE__);
    15241410      if (!info->name) {
    1525         free(info);
    1526         return FALSE;
     1411        free(info);
     1412        return FALSE;
    15271413      }
    15281414      else {
    1529         info->size = f->cbFile;
    1530         info->date = f->fdateLastWrite;
    1531         info->time = f->ftimeLastWrite;
    1532         info->CRC = -1L;
    1533         g->numfiles++;
    1534         if (!g->dupehead)
    1535           g->dupehead = info;
    1536         if (g->dupelast)
    1537           g->dupelast->next = info;
    1538         g->dupelast = info;
    1539         info->next = NULL;
     1415        info->size = f->cbFile;
     1416        info->date = f->fdateLastWrite;
     1417        info->time = f->ftimeLastWrite;
     1418        info->CRC = -1L;
     1419        g->numfiles++;
     1420        if (!g->dupehead)
     1421          g->dupehead = info;
     1422        if (g->dupelast)
     1423          g->dupelast->next = info;
     1424        g->dupelast = info;
     1425        info->next = NULL;
    15401426      }
    15411427    }
Note: See TracChangeset for help on using the changeset viewer.