| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: grep.c 775 2007-08-11 21:07:07Z gyoung $
 | 
|---|
| 5 | 
 | 
|---|
| 6 |   grep tools
 | 
|---|
| 7 | 
 | 
|---|
| 8 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| 9 |   Copyright (c) 2001, 2006 Steven H. Levine
 | 
|---|
| 10 | 
 | 
|---|
| 11 |   12 Feb 03 SHL insert_grepfile: standardize EA math
 | 
|---|
| 12 |   12 Feb 03 SHL doonefile: standardize EA math
 | 
|---|
| 13 |   25 May 05 SHL Rework for ULONGLONG
 | 
|---|
| 14 |   25 May 05 SHL Rework for FillInRecordFromFFB
 | 
|---|
| 15 |   06 Jun 05 SHL Drop unused code
 | 
|---|
| 16 |   24 Oct 05 SHL dononefile: do not free EA list twice
 | 
|---|
| 17 |   22 Jul 06 SHL Use Runtime_Error
 | 
|---|
| 18 |   26 Jul 06 SHL Check more run time errors
 | 
|---|
| 19 |   19 Oct 06 SHL Correct . and .. detect
 | 
|---|
| 20 |   03 Nov 06 SHL Count thread usage
 | 
|---|
| 21 |   03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
 | 
|---|
| 22 |   06 Aug 07 GKY Reduce DosSleep times (ticket 148)
 | 
|---|
| 23 | 
 | 
|---|
| 24 | 
 | 
|---|
| 25 | ***********************************************************************/
 | 
|---|
| 26 | 
 | 
|---|
| 27 | #define INCL_DOS
 | 
|---|
| 28 | #define INCL_WIN
 | 
|---|
| 29 | #define INCL_LONGLONG
 | 
|---|
| 30 | #include <os2.h>
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include <stdlib.h>
 | 
|---|
| 33 | #include <string.h>
 | 
|---|
| 34 | #include <ctype.h>
 | 
|---|
| 35 | #include <stdio.h>
 | 
|---|
| 36 | #include <share.h>
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #include "fm3dll.h"
 | 
|---|
| 39 | #include "fm3str.h"
 | 
|---|
| 40 | #include "grep.h"
 | 
|---|
| 41 | 
 | 
|---|
| 42 | #pragma data_seg(DATA2)
 | 
|---|
| 43 | 
 | 
|---|
| 44 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
| 45 | 
 | 
|---|
| 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,
 | 
|---|
| 54 |                          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);
 | 
|---|
| 61 | 
 | 
|---|
| 62 | #define GREPCHARS "*?[] \\"
 | 
|---|
| 63 | 
 | 
|---|
| 64 | #define isleap(year) ((((year%4)==0) && ((year%100)!=0)) || \
 | 
|---|
| 65 |         ((year%400)==0))
 | 
|---|
| 66 | 
 | 
|---|
| 67 | static INT monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 | 
|---|
| 68 | 
 | 
|---|
| 69 | ULONG SecsSince1980(FDATE * date, FTIME * time)
 | 
|---|
| 70 | {
 | 
|---|
| 71 |   ULONG total = 0L;
 | 
|---|
| 72 |   register int x;
 | 
|---|
| 73 | 
 | 
|---|
| 74 |   for (x = 1980; x < date->year + 1980; x++) {
 | 
|---|
| 75 |     if (isleap(x))
 | 
|---|
| 76 |       total += (366L * (24L * 60L * 60L));
 | 
|---|
| 77 |     else
 | 
|---|
| 78 |       total += (365L * (24L * 60L * 60L));
 | 
|---|
| 79 |   }
 | 
|---|
| 80 |   for (x = 1; x < date->month; x++) {
 | 
|---|
| 81 |     if (x == 2 && isleap(date->year + 1980))
 | 
|---|
| 82 |       total += (29L * (24L * 60L * 60L));
 | 
|---|
| 83 |     else
 | 
|---|
| 84 |       total += ((long)monthdays[x - 1] * (24L * 60L * 60L));
 | 
|---|
| 85 |   }
 | 
|---|
| 86 |   total += (((long)date->day - 1L) * (24L * 60L * 60L));
 | 
|---|
| 87 |   total += ((long)time->hours * (60L * 60L));
 | 
|---|
| 88 |   total += ((long)time->minutes * 60L);
 | 
|---|
| 89 |   total += ((long)time->twosecs * 2L);
 | 
|---|
| 90 |   return total;
 | 
|---|
| 91 | }
 | 
|---|
| 92 | 
 | 
|---|
| 93 | /*
 | 
|---|
| 94 |  * this function originally from C_ECHO's Snippets -- modified
 | 
|---|
| 95 |  * brute force methodology
 | 
|---|
| 96 |  */
 | 
|---|
| 97 | 
 | 
|---|
| 98 | static BOOL m_match(CHAR * string, CHAR * pattern, BOOL absolute, BOOL ignore,
 | 
|---|
| 99 |                     LONG len)
 | 
|---|
| 100 | {
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   /* return TRUE if pattern found in string */
 | 
|---|
| 103 | 
 | 
|---|
| 104 |   register CHAR *tn = pattern;
 | 
|---|
| 105 |   register LONG len2 = 0;
 | 
|---|
| 106 |   LONG lastlen = 0;
 | 
|---|
| 107 |   CHAR lo, hi;
 | 
|---|
| 108 | 
 | 
|---|
| 109 |   if (len && string && pattern) {
 | 
|---|
| 110 |     if (absolute)                       /* no pattern matching */
 | 
|---|
| 111 |       return (findstring(pattern, strlen(pattern), string, len,
 | 
|---|
| 112 |                          (ignore == FALSE)) != NULL);
 | 
|---|
| 113 | 
 | 
|---|
| 114 |     while (*tn && len2 < len) {
 | 
|---|
| 115 |       switch (*tn) {
 | 
|---|
| 116 |       case ' ':
 | 
|---|
| 117 |         while (*tn == ' ')
 | 
|---|
| 118 |           tn++;
 | 
|---|
| 119 |         while (len2 < len && isspace(string[len2]))
 | 
|---|
| 120 |           len2++;
 | 
|---|
| 121 |         break;
 | 
|---|
| 122 | 
 | 
|---|
| 123 |       case '*':
 | 
|---|
| 124 |         while (*tn == '*' || *tn == '?')
 | 
|---|
| 125 |           tn++;
 | 
|---|
| 126 |         if (!*tn)
 | 
|---|
| 127 |           return TRUE;
 | 
|---|
| 128 |         if (ignore) {
 | 
|---|
| 129 |           while (len2 < len && string[len2] != *tn)
 | 
|---|
| 130 |             len2++;
 | 
|---|
| 131 |         }
 | 
|---|
| 132 |         else {
 | 
|---|
| 133 |           while (len2 < len && toupper(string[len2] != *tn))
 | 
|---|
| 134 |             len2++;
 | 
|---|
| 135 |         }
 | 
|---|
| 136 |         break;
 | 
|---|
| 137 | 
 | 
|---|
| 138 |       case '[':
 | 
|---|
| 139 |         tn++;
 | 
|---|
| 140 |         if (!*tn)
 | 
|---|
| 141 |           return FALSE;
 | 
|---|
| 142 |         lo = *tn;
 | 
|---|
| 143 |         tn++;
 | 
|---|
| 144 |         if (*tn != '-')
 | 
|---|
| 145 |           return FALSE;
 | 
|---|
| 146 |         tn++;
 | 
|---|
| 147 |         if (!*tn)
 | 
|---|
| 148 |           return FALSE;
 | 
|---|
| 149 |         hi = *tn;
 | 
|---|
| 150 |         tn++;
 | 
|---|
| 151 |         if (*tn != ']')
 | 
|---|
| 152 |           return FALSE;
 | 
|---|
| 153 |         tn++;
 | 
|---|
| 154 |         if (ignore) {
 | 
|---|
| 155 |           if ((toupper(string[len2]) >= toupper(lo)) &&
 | 
|---|
| 156 |               (toupper(string[len2]) <= toupper(hi)))
 | 
|---|
| 157 |             len2++;
 | 
|---|
| 158 |           else {
 | 
|---|
| 159 |             tn = pattern;
 | 
|---|
| 160 |             len2 = lastlen = lastlen + 1;
 | 
|---|
| 161 |           }
 | 
|---|
| 162 |         }
 | 
|---|
| 163 |         else {
 | 
|---|
| 164 |           if ((string[len2] >= lo) && (string[len2] <= hi))
 | 
|---|
| 165 |             len2++;
 | 
|---|
| 166 |           else {
 | 
|---|
| 167 |             tn = pattern;
 | 
|---|
| 168 |             len2 = lastlen = lastlen + 1;
 | 
|---|
| 169 |           }
 | 
|---|
| 170 |         }
 | 
|---|
| 171 |         break;
 | 
|---|
| 172 | 
 | 
|---|
| 173 |       case '?':
 | 
|---|
| 174 |         tn++;
 | 
|---|
| 175 |         len2++;
 | 
|---|
| 176 |         break;
 | 
|---|
| 177 | 
 | 
|---|
| 178 |       case '\\':
 | 
|---|
| 179 |         tn++;
 | 
|---|
| 180 |         if (!*tn)
 | 
|---|
| 181 |           return FALSE;
 | 
|---|
| 182 |         /* else intentional fallthru */
 | 
|---|
| 183 |       default:
 | 
|---|
| 184 |         if (ignore) {
 | 
|---|
| 185 |           if (toupper(*tn) == toupper(string[len2])) {
 | 
|---|
| 186 |             tn++;
 | 
|---|
| 187 |             len2++;
 | 
|---|
| 188 |           }
 | 
|---|
| 189 |           else {
 | 
|---|
| 190 |             tn = pattern;
 | 
|---|
| 191 |             len2 = lastlen = lastlen + 1;
 | 
|---|
| 192 |           }
 | 
|---|
| 193 |         }
 | 
|---|
| 194 |         else {
 | 
|---|
| 195 |           if (*tn == string[len2]) {
 | 
|---|
| 196 |             tn++;
 | 
|---|
| 197 |             len2++;
 | 
|---|
| 198 |           }
 | 
|---|
| 199 |           else {
 | 
|---|
| 200 |             tn = pattern;
 | 
|---|
| 201 |             len2 = lastlen = lastlen + 1;
 | 
|---|
| 202 |           }
 | 
|---|
| 203 |         }
 | 
|---|
| 204 |         break;
 | 
|---|
| 205 |       }
 | 
|---|
| 206 |     }
 | 
|---|
| 207 |     while (*tn == '*')
 | 
|---|
| 208 |       tn++;
 | 
|---|
| 209 | 
 | 
|---|
| 210 |     if (!*tn)
 | 
|---|
| 211 |       return TRUE;
 | 
|---|
| 212 |   }
 | 
|---|
| 213 |   return FALSE;
 | 
|---|
| 214 | }
 | 
|---|
| 215 | 
 | 
|---|
| 216 | static BOOL match(CHAR * string, CHAR * patterns, BOOL absolute, BOOL ignore,
 | 
|---|
| 217 |                   LONG len, ULONG numlines, CHAR * matched, BOOL matchall)
 | 
|---|
| 218 | {
 | 
|---|
| 219 | 
 | 
|---|
| 220 |   BOOL ret = FALSE;
 | 
|---|
| 221 |   register CHAR *p;
 | 
|---|
| 222 |   register ULONG x = 0;
 | 
|---|
| 223 | 
 | 
|---|
| 224 |   p = patterns;
 | 
|---|
| 225 |   while (!ret && *p) {
 | 
|---|
| 226 |     ret = m_match(string, p, absolute, ignore, len);
 | 
|---|
| 227 |     if (matchall && ret)
 | 
|---|
| 228 |       break;
 | 
|---|
| 229 |     if (matched && ret && x < numlines)
 | 
|---|
| 230 |       matched[x] = 1;
 | 
|---|
| 231 |     p += strlen(p);                     /* check each pattern in 0-terminated list */
 | 
|---|
| 232 |     p++;
 | 
|---|
| 233 |     x++;
 | 
|---|
| 234 |   }
 | 
|---|
| 235 |   return ret;
 | 
|---|
| 236 | }
 | 
|---|
| 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)
 | 
|---|
| 248 |     return;
 | 
|---|
| 249 |   grep = *(GREP *) arg;
 | 
|---|
| 250 |   *grep.stopflag = 0;                   /* reset thread-killing flag */
 | 
|---|
| 251 |   grep.FilesToGet = FilesToGet;
 | 
|---|
| 252 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| 253 |   priority_normal();
 | 
|---|
| 254 | 
 | 
|---|
| 255 |   ghab = WinInitialize(0);
 | 
|---|
| 256 |   if (ghab) {
 | 
|---|
| 257 |     grep.ghab = ghab;
 | 
|---|
| 258 |     ghmq = WinCreateMsgQueue(ghab, 0);
 | 
|---|
| 259 |     if (ghmq) {
 | 
|---|
| 260 |       WinCancelShutdown(ghmq, TRUE);
 | 
|---|
| 261 |       IncrThreadUsage();
 | 
|---|
| 262 |       DosSleep(100); //05 Aug 07 GKY 128
 | 
|---|
| 263 |       WinSetWindowText(grep.hwndCurFile,
 | 
|---|
| 264 |                        GetPString((grep.finddupes) ?
 | 
|---|
| 265 |                                   IDS_GREPDUPETEXT : IDS_GREPSCANTEXT));
 | 
|---|
| 266 | 
 | 
|---|
| 267 |       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;
 | 
|---|
| 280 |       }
 | 
|---|
| 281 | 
 | 
|---|
| 282 |       grep.attrFile &= (~FILE_DIRECTORY);
 | 
|---|
| 283 |       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;
 | 
|---|
| 292 | 
 | 
|---|
| 293 |       grep.anyexcludes = FALSE;
 | 
|---|
| 294 |       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 |       } // while
 | 
|---|
| 355 | 
 | 
|---|
| 356 |       if (WinIsWindow(grep.ghab, grep.hwndFiles))
 | 
|---|
| 357 |         doinsertion(&grep);             /* insert any remaining objects */
 | 
|---|
| 358 | 
 | 
|---|
| 359 |       if (WinIsWindow(grep.ghab, grep.hwndFiles) && grep.finddupes &&
 | 
|---|
| 360 |           !*grep.stopflag)
 | 
|---|
| 361 |         FillDupes(&grep);
 | 
|---|
| 362 | 
 | 
|---|
| 363 |       if (!PostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID))        /* tell window we're done */
 | 
|---|
| 364 |         WinSendMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
 | 
|---|
| 365 |       WinDestroyMsgQueue(ghmq);
 | 
|---|
| 366 |     }
 | 
|---|
| 367 |     DecrThreadUsage();
 | 
|---|
| 368 |     WinTerminate(ghab);
 | 
|---|
| 369 |   }
 | 
|---|
| 370 |   if (!ghmq || !ghab)
 | 
|---|
| 371 |     WinPostMsg(grep.hwndFiles, UM_CONTAINER_FILLED, MPVOID, MPVOID);
 | 
|---|
| 372 |   if (grep.dupehead)
 | 
|---|
| 373 |     FreeDupes(&grep);
 | 
|---|
| 374 |   if (grep.numlines && grep.matched)
 | 
|---|
| 375 |     free(grep.matched);
 | 
|---|
| 376 |   DosPostEventSem(CompactSem);
 | 
|---|
| 377 | }
 | 
|---|
| 378 | 
 | 
|---|
| 379 | static BOOL IsExcluded(char *name, char **fle, int numfls)
 | 
|---|
| 380 | {
 | 
|---|
| 381 |   register int x;
 | 
|---|
| 382 |   char *n;
 | 
|---|
| 383 | 
 | 
|---|
| 384 |   n = strrchr(name, '\\');
 | 
|---|
| 385 |   if (!n)
 | 
|---|
| 386 |     n = strrchr(name, ':');
 | 
|---|
| 387 |   if (n)
 | 
|---|
| 388 |     n++;
 | 
|---|
| 389 |   else
 | 
|---|
| 390 |     n = name;
 | 
|---|
| 391 |   for (x = 0; x < numfls; x++) {
 | 
|---|
| 392 |     if (*fle[x] == '/' &&
 | 
|---|
| 393 |         wildcard((strchr(fle[x], '\\') ||
 | 
|---|
| 394 |                   strchr(fle[x], ':')) ? name : n, fle[x] + 1, FALSE))
 | 
|---|
| 395 |       return TRUE;
 | 
|---|
| 396 |   }
 | 
|---|
| 397 |   return FALSE;
 | 
|---|
| 398 | }
 | 
|---|
| 399 | 
 | 
|---|
| 400 | static VOID doallsubdirs(GREP * grep, CHAR * searchPath, BOOL recursing,
 | 
|---|
| 401 |                          char **fle, int numfls)
 | 
|---|
| 402 | {
 | 
|---|
| 403 | 
 | 
|---|
| 404 |   /* process all subdirectories */
 | 
|---|
| 405 | 
 | 
|---|
| 406 |   FILEFINDBUF4 findBuffer;
 | 
|---|
| 407 |   HDIR findHandle = HDIR_CREATE;
 | 
|---|
| 408 |   LONG findCount = 1L;
 | 
|---|
| 409 |   CHAR *p = NULL;
 | 
|---|
| 410 | 
 | 
|---|
| 411 |   /* add a mask to search path */
 | 
|---|
| 412 |   if (searchPath[strlen(searchPath) - 1] != '\\')
 | 
|---|
| 413 |     strcat(searchPath, "\\");
 | 
|---|
| 414 |   strcat(searchPath, "*");
 | 
|---|
| 415 |   /* step through all subdirectories */
 | 
|---|
| 416 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| 417 |   if (!DosFindFirst(searchPath, &findHandle, (MUST_HAVE_DIRECTORY |
 | 
|---|
| 418 |                                               FILE_ARCHIVED | FILE_SYSTEM |
 | 
|---|
| 419 |                                               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 */
 | 
|---|
| 424 | 
 | 
|---|
| 425 |     p = strrchr(searchPath, '\\');
 | 
|---|
| 426 |     if (p)
 | 
|---|
| 427 |       p++;
 | 
|---|
| 428 |     else
 | 
|---|
| 429 |       p = searchPath;
 | 
|---|
| 430 |     do {                                /* Process each directory that matches the mask */
 | 
|---|
| 431 |       priority_normal();
 | 
|---|
| 432 |       if (*grep->stopflag)
 | 
|---|
| 433 |         break;
 | 
|---|
| 434 |       // Skip . and ..
 | 
|---|
| 435 |       if (findBuffer.achName[0] != '.' ||
 | 
|---|
| 436 |           (findBuffer.achName[1] &&
 | 
|---|
| 437 |            (findBuffer.achName[1] != '.' || findBuffer.achName[2]))) {
 | 
|---|
| 438 |         strcpy(p, findBuffer.achName);
 | 
|---|
| 439 |         if (!grep->anyexcludes || !IsExcluded(searchPath, fle, numfls)) {
 | 
|---|
| 440 |           domatchingfiles(grep, searchPath, fle, numfls);
 | 
|---|
| 441 |           doallsubdirs(grep, searchPath, TRUE, fle, numfls);
 | 
|---|
| 442 |           DosSleep(1);
 | 
|---|
| 443 |         }
 | 
|---|
| 444 |       }
 | 
|---|
| 445 |       findCount = 1;
 | 
|---|
| 446 |     } while (!DosFindNext(findHandle,
 | 
|---|
| 447 |                           &findBuffer,
 | 
|---|
| 448 |                           sizeof(findBuffer), (PULONG) & findCount));
 | 
|---|
| 449 |     DosFindClose(findHandle);
 | 
|---|
| 450 |     priority_normal();
 | 
|---|
| 451 |   }
 | 
|---|
| 452 |   if (p)                                /* strip off last directory addition */
 | 
|---|
| 453 |     *p = 0;
 | 
|---|
| 454 | }
 | 
|---|
| 455 | 
 | 
|---|
| 456 | static INT domatchingfiles(GREP * grep, CHAR * path, char **fle, int numfls)
 | 
|---|
| 457 | {
 | 
|---|
| 458 |   /* process all matching files in a directory */
 | 
|---|
| 459 | 
 | 
|---|
| 460 |   PFILEFINDBUF4 findBuffer;
 | 
|---|
| 461 |   PFILEFINDBUF4 pffbFile;
 | 
|---|
| 462 |   register PBYTE fb;
 | 
|---|
| 463 |   register ULONG x;
 | 
|---|
| 464 |   HDIR findHandle = HDIR_CREATE;
 | 
|---|
| 465 |   ULONG findCount = grep->FilesToGet;
 | 
|---|
| 466 |   CHAR newPath[CCHMAXPATH], *p;
 | 
|---|
| 467 |   APIRET rc;
 | 
|---|
| 468 | 
 | 
|---|
| 469 |   findBuffer =
 | 
|---|
| 470 |     xmalloc(grep->FilesToGet * sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
 | 
|---|
| 471 |   if (!findBuffer)
 | 
|---|
| 472 |     return 0;
 | 
|---|
| 473 | 
 | 
|---|
| 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, '\\');
 | 
|---|
| 485 |   if (p)
 | 
|---|
| 486 |     p++;
 | 
|---|
| 487 |   else
 | 
|---|
| 488 |     p = newPath;
 | 
|---|
| 489 | 
 | 
|---|
| 490 |   /* step through matching files */
 | 
|---|
| 491 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| 492 |   if (!DosFindFirst(newPath,
 | 
|---|
| 493 |                     &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 */
 | 
|---|
| 500 |       priority_normal();
 | 
|---|
| 501 |       fb = (PBYTE) findBuffer;
 | 
|---|
| 502 |       for (x = 0L; x < findCount; x++) {
 | 
|---|
| 503 |         pffbFile = (PFILEFINDBUF4) fb;
 | 
|---|
| 504 |         if (*grep->stopflag)
 | 
|---|
| 505 |           break;
 | 
|---|
| 506 |         if (*pffbFile->achName != '.' ||
 | 
|---|
| 507 |             (pffbFile->achName[1] && pffbFile->achName[1] != '.')) {
 | 
|---|
| 508 |           strcpy(p, pffbFile->achName); /* build filename */
 | 
|---|
| 509 |           if (!grep->anyexcludes || !IsExcluded(newPath, fle, numfls)) {
 | 
|---|
| 510 |             if (!grep->finddupes)
 | 
|---|
| 511 |               doonefile(grep, newPath, pffbFile);
 | 
|---|
| 512 |             else if (!InsertDupe(grep, newPath, pffbFile)) {
 | 
|---|
| 513 |               DosFindClose(findHandle);
 | 
|---|
| 514 |               free(findBuffer);
 | 
|---|
| 515 |               return 1;
 | 
|---|
| 516 |             }
 | 
|---|
| 517 |           }
 | 
|---|
| 518 |         }
 | 
|---|
| 519 |         if (!pffbFile->oNextEntryOffset)
 | 
|---|
| 520 |           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);
 | 
|---|
| 530 |     } while (!rc);
 | 
|---|
| 531 |     DosFindClose(findHandle);
 | 
|---|
| 532 |     priority_normal();
 | 
|---|
| 533 |   }
 | 
|---|
| 534 |   free(findBuffer);
 | 
|---|
| 535 |   return 0;
 | 
|---|
| 536 | }
 | 
|---|
| 537 | 
 | 
|---|
| 538 | #pragma alloc_text(GREP,insert_grepfile,doonefile,doinsertion,freegreplist)
 | 
|---|
| 539 | 
 | 
|---|
| 540 | static VOID freegreplist(GREP * grep)
 | 
|---|
| 541 | {
 | 
|---|
| 542 |   register INT x;
 | 
|---|
| 543 | 
 | 
|---|
| 544 |   if (grep) {
 | 
|---|
| 545 |     if (grep->insertffb) {
 | 
|---|
| 546 |       for (x = 0; grep->insertffb[x]; x++)
 | 
|---|
| 547 |         free(grep->insertffb[x]);
 | 
|---|
| 548 |       free(grep->insertffb);
 | 
|---|
| 549 |     }
 | 
|---|
| 550 |     if (grep->dir) {
 | 
|---|
| 551 |       for (x = 0; grep->dir[x]; x++)
 | 
|---|
| 552 |         free(grep->dir[x]);
 | 
|---|
| 553 |       free(grep->dir);
 | 
|---|
| 554 |     }
 | 
|---|
| 555 |     grep->dir = NULL;
 | 
|---|
| 556 |     grep->insertffb = NULL;
 | 
|---|
| 557 |     grep->toinsert = 0L;
 | 
|---|
| 558 |     grep->insertedbytes = 0L;
 | 
|---|
| 559 |   }
 | 
|---|
| 560 | }
 | 
|---|
| 561 | 
 | 
|---|
| 562 | static BOOL doinsertion(GREP * grep)
 | 
|---|
| 563 | {
 | 
|---|
| 564 |   RECORDINSERT ri;
 | 
|---|
| 565 |   DIRCNRDATA *dcd;
 | 
|---|
| 566 |   PCNRITEM pci, pciFirst;
 | 
|---|
| 567 |   INT x;
 | 
|---|
| 568 | 
 | 
|---|
| 569 |   if (!grep || !grep->toinsert || !grep->insertffb || !grep->dir)
 | 
|---|
| 570 |     return FALSE;
 | 
|---|
| 571 |   pci = WinSendMsg(grep->hwndFiles,
 | 
|---|
| 572 |                    CM_ALLOCRECORD,
 | 
|---|
| 573 |                    MPFROMLONG(EXTRA_RECORD_BYTES),
 | 
|---|
| 574 |                    MPFROMLONG(grep->toinsert));
 | 
|---|
| 575 |   if (pci) {
 | 
|---|
| 576 |     if (grep->sayfiles)
 | 
|---|
| 577 |       WinSetWindowText(grep->hwndCurFile, GetPString(IDS_GREPINSERTINGTEXT));
 | 
|---|
| 578 |     pciFirst = pci;
 | 
|---|
| 579 |     dcd = INSTDATA(grep->hwndFiles);
 | 
|---|
| 580 |     for (x = 0; grep->insertffb[x]; x++) {
 | 
|---|
| 581 |       FillInRecordFromFFB(grep->hwndFiles,
 | 
|---|
| 582 |                           pci, grep->dir[x], grep->insertffb[x], FALSE, dcd);
 | 
|---|
| 583 |       pci = (PCNRITEM) pci->rc.preccNextRecord;
 | 
|---|
| 584 |     }
 | 
|---|
| 585 |     memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 586 |     ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 587 |     ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 588 |     ri.pRecordParent = (PRECORDCORE) NULL;
 | 
|---|
| 589 |     ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 590 |     ri.cRecordsInsert = grep->toinsert;
 | 
|---|
| 591 |     ri.fInvalidateRecord = TRUE;
 | 
|---|
| 592 |     WinSendMsg(grep->hwndFiles,
 | 
|---|
| 593 |                CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri));
 | 
|---|
| 594 |     if (dcd) {
 | 
|---|
| 595 |       DosEnterCritSec();
 | 
|---|
| 596 |       dcd->ullTotalBytes += grep->insertedbytes;
 | 
|---|
| 597 |       DosExitCritSec();
 | 
|---|
| 598 |     }
 | 
|---|
| 599 |     if (grep->toinsert == grep->FilesToGet)
 | 
|---|
| 600 |       DosSleep(1);
 | 
|---|
| 601 |     freegreplist(grep);
 | 
|---|
| 602 |     PostMsg(grep->hwndFiles, UM_RESCAN, MPVOID, MPVOID);
 | 
|---|
| 603 |     return TRUE;
 | 
|---|
| 604 |   }
 | 
|---|
| 605 |   freegreplist(grep);
 | 
|---|
| 606 |   return FALSE;
 | 
|---|
| 607 | }
 | 
|---|
| 608 | 
 | 
|---|
| 609 | static BOOL insert_grepfile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f)
 | 
|---|
| 610 | {
 | 
|---|
| 611 |   CHAR *p, szDirectory[CCHMAXPATH];
 | 
|---|
| 612 | 
 | 
|---|
| 613 |   if (WinIsWindow(grep->ghab, grep->hwndFiles)) {
 | 
|---|
| 614 |     grep->numfiles++;
 | 
|---|
| 615 |     strcpy(szDirectory, filename);
 | 
|---|
| 616 |     p = strrchr(szDirectory, '\\');
 | 
|---|
| 617 |     if (p) {
 | 
|---|
| 618 |       if (p < szDirectory + 4)
 | 
|---|
| 619 |         p++;
 | 
|---|
| 620 |       *p = 0;
 | 
|---|
| 621 |       if (!grep->insertffb) {
 | 
|---|
| 622 |         grep->insertffb = xmallocz(sizeof(FILEFINDBUF4 *) *
 | 
|---|
| 623 |                                    (grep->FilesToGet + 1), pszSrcFile,
 | 
|---|
| 624 |                                    __LINE__);
 | 
|---|
| 625 |         if (!grep->insertffb)
 | 
|---|
| 626 |           return FALSE;
 | 
|---|
| 627 |         grep->dir =
 | 
|---|
| 628 |           xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1), pszSrcFile,
 | 
|---|
| 629 |                    __LINE__);
 | 
|---|
| 630 |         if (!grep->dir) {
 | 
|---|
| 631 |           free(grep->insertffb);
 | 
|---|
| 632 |           return FALSE;
 | 
|---|
| 633 |         }
 | 
|---|
| 634 |       }
 | 
|---|
| 635 |       grep->insertffb[grep->toinsert] =
 | 
|---|
| 636 |         xmalloc(sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
 | 
|---|
| 637 |       if (!grep->insertffb[grep->toinsert])
 | 
|---|
| 638 |         return FALSE;
 | 
|---|
| 639 |       memcpy(grep->insertffb[grep->toinsert], f, sizeof(FILEFINDBUF4));
 | 
|---|
| 640 |       grep->dir[grep->toinsert] = xstrdup(szDirectory, pszSrcFile, __LINE__);
 | 
|---|
| 641 |       if (!grep->dir) {
 | 
|---|
| 642 |         free(grep->insertffb[grep->toinsert]);
 | 
|---|
| 643 |         return FALSE;
 | 
|---|
| 644 |       }
 | 
|---|
| 645 |       grep->insertedbytes += f->cbFile + CBLIST_TO_EASIZE(f->cbList);
 | 
|---|
| 646 |       grep->toinsert++;
 | 
|---|
| 647 |       if (grep->toinsert == grep->FilesToGet)
 | 
|---|
| 648 |         return doinsertion(grep);
 | 
|---|
| 649 |       return TRUE;
 | 
|---|
| 650 |     }
 | 
|---|
| 651 |   }
 | 
|---|
| 652 |   else
 | 
|---|
| 653 |     freegreplist(grep);
 | 
|---|
| 654 |   return FALSE;
 | 
|---|
| 655 | }
 | 
|---|
| 656 | 
 | 
|---|
| 657 | static BOOL doonefile(GREP * grep, CHAR * filename, FILEFINDBUF4 * f)
 | 
|---|
| 658 | {
 | 
|---|
| 659 |   /* process a single file */
 | 
|---|
| 660 | 
 | 
|---|
| 661 |   CHAR *input;
 | 
|---|
| 662 |   FILE *inputFile;
 | 
|---|
| 663 |   ULONG pos;
 | 
|---|
| 664 |   BOOL ret = FALSE, strmatch = FALSE;
 | 
|---|
| 665 | 
 | 
|---|
| 666 |   grep->fileCount++;
 | 
|---|
| 667 |   if (grep->sayfiles)
 | 
|---|
| 668 |     WinSetWindowText(grep->hwndCurFile, filename);
 | 
|---|
| 669 | 
 | 
|---|
| 670 |   if (grep->greaterthan || grep->lessthan) {
 | 
|---|
| 671 | 
 | 
|---|
| 672 |     BOOL keep = TRUE;
 | 
|---|
| 673 |     ULONG adjsize;
 | 
|---|
| 674 | 
 | 
|---|
| 675 |     adjsize = f->cbFile + (grep->searchEAs ? CBLIST_TO_EASIZE(f->cbList) : 0);
 | 
|---|
| 676 |     if (grep->greaterthan) {
 | 
|---|
| 677 |       if (adjsize < grep->greaterthan)
 | 
|---|
| 678 |         keep = FALSE;
 | 
|---|
| 679 |     }
 | 
|---|
| 680 |     if (keep && grep->lessthan) {
 | 
|---|
| 681 |       if (adjsize > grep->lessthan)
 | 
|---|
| 682 |         keep = FALSE;
 | 
|---|
| 683 |     }
 | 
|---|
| 684 |     if (!keep)
 | 
|---|
| 685 |       return ret;
 | 
|---|
| 686 |   }
 | 
|---|
| 687 | 
 | 
|---|
| 688 |   if (grep->newerthan || grep->olderthan) {
 | 
|---|
| 689 | 
 | 
|---|
| 690 |     BOOL keep = TRUE;
 | 
|---|
| 691 |     ULONG numsecs;
 | 
|---|
| 692 | 
 | 
|---|
| 693 |     numsecs = SecsSince1980(&f->fdateLastWrite, &f->ftimeLastWrite);
 | 
|---|
| 694 |     if (grep->newerthan) {
 | 
|---|
| 695 |       if (numsecs < grep->newerthan)
 | 
|---|
| 696 |         keep = FALSE;
 | 
|---|
| 697 |     }
 | 
|---|
| 698 |     if (keep && grep->olderthan) {
 | 
|---|
| 699 |       if (numsecs > grep->olderthan)
 | 
|---|
| 700 |         keep = FALSE;
 | 
|---|
| 701 |     }
 | 
|---|
| 702 |     if (!keep)
 | 
|---|
| 703 |       return ret;
 | 
|---|
| 704 |   }
 | 
|---|
| 705 | 
 | 
|---|
| 706 |   if ((!grep->searchEAs && !grep->searchFiles) || !*grep->searchPattern)        /* just a find */
 | 
|---|
| 707 |     return insert_grepfile(grep, filename, f);
 | 
|---|
| 708 | 
 | 
|---|
| 709 |   if (grep->searchEAs) {
 | 
|---|
| 710 | 
 | 
|---|
| 711 |     HOLDFEA *head, *info;
 | 
|---|
| 712 |     USHORT type, len;
 | 
|---|
| 713 |     BOOL alltext;
 | 
|---|
| 714 |     CHAR *data, temp;
 | 
|---|
| 715 | 
 | 
|---|
| 716 |     head = GetFileEAs(filename, FALSE, TRUE);
 | 
|---|
| 717 |     if (head) {
 | 
|---|
| 718 |       info = head;
 | 
|---|
| 719 |       while (info && !strmatch) {
 | 
|---|
| 720 |         alltext = TRUE;
 | 
|---|
| 721 |         switch (*(USHORT *) info->value) {
 | 
|---|
| 722 |         case EAT_ASCII:
 | 
|---|
| 723 |           if (match(info->value + (sizeof(USHORT) * 2),
 | 
|---|
| 724 |                     grep->searchPattern, grep->absFlag,
 | 
|---|
| 725 |                     (grep->caseFlag == FALSE),
 | 
|---|
| 726 |                     info->cbValue - (sizeof(USHORT) * 2),
 | 
|---|
| 727 |                     grep->numlines, grep->matched, !grep->findifany)) {
 | 
|---|
| 728 |             strmatch = TRUE;
 | 
|---|
| 729 |           }
 | 
|---|
| 730 |           break;
 | 
|---|
| 731 |         case EAT_MVST:
 | 
|---|
| 732 |           type = *(USHORT *) (info->value + (sizeof(USHORT) * 3));
 | 
|---|
| 733 |           if (type == EAT_ASCII) {
 | 
|---|
| 734 |             data = info->value + (sizeof(USHORT) * 4);
 | 
|---|
| 735 |             len = *(USHORT *) data;
 | 
|---|
| 736 |             data += sizeof(USHORT);
 | 
|---|
| 737 |             while ((data - info->value) + len <= info->cbValue) {
 | 
|---|
| 738 |               temp = *(data + len);
 | 
|---|
| 739 |               *(data + len) = 0;
 | 
|---|
| 740 |               if (match(data,
 | 
|---|
| 741 |                         grep->searchPattern,
 | 
|---|
| 742 |                         grep->absFlag,
 | 
|---|
| 743 |                         (grep->caseFlag == FALSE),
 | 
|---|
| 744 |                         len,
 | 
|---|
| 745 |                         grep->numlines, grep->matched, !grep->findifany)) {
 | 
|---|
| 746 |                 strmatch = TRUE;
 | 
|---|
| 747 |                 break;
 | 
|---|
| 748 |               }
 | 
|---|
| 749 |               data += len;
 | 
|---|
| 750 |               if (data - info->value >= info->cbValue)
 | 
|---|
| 751 |                 break;
 | 
|---|
| 752 |               *data = temp;
 | 
|---|
| 753 |               len = *(USHORT *) data;
 | 
|---|
| 754 |               data += sizeof(USHORT);
 | 
|---|
| 755 |             }
 | 
|---|
| 756 |           }
 | 
|---|
| 757 |           break;
 | 
|---|
| 758 |         case EAT_MVMT:
 | 
|---|
| 759 |           data = info->value + (sizeof(USHORT) * 3);
 | 
|---|
| 760 |           type = *(USHORT *) data;
 | 
|---|
| 761 |           data += sizeof(USHORT);
 | 
|---|
| 762 |           len = *(USHORT *) data;
 | 
|---|
| 763 |           data += sizeof(USHORT);
 | 
|---|
| 764 |           while ((data - info->value) - len <= info->cbValue) {
 | 
|---|
| 765 |             if (type != EAT_ASCII) {
 | 
|---|
| 766 |               alltext = FALSE;
 | 
|---|
| 767 |               break;
 | 
|---|
| 768 |             }
 | 
|---|
| 769 |             data += len;
 | 
|---|
| 770 |             if (data - info->value >= info->cbValue)
 | 
|---|
| 771 |               break;
 | 
|---|
| 772 |             type = *(USHORT *) data;
 | 
|---|
| 773 |             data += sizeof(USHORT);
 | 
|---|
| 774 |             len = *(USHORT *) data;
 | 
|---|
| 775 |             data += sizeof(USHORT);
 | 
|---|
| 776 |           }
 | 
|---|
| 777 |           if (alltext) {
 | 
|---|
| 778 |             data = info->value + (sizeof(USHORT) * 3);
 | 
|---|
| 779 |             type = *(USHORT *) data;
 | 
|---|
| 780 |             data += sizeof(USHORT);
 | 
|---|
| 781 |             len = *(USHORT *) data;
 | 
|---|
| 782 |             data += sizeof(USHORT);
 | 
|---|
| 783 |             while ((data - info->value) - len <= info->cbValue) {
 | 
|---|
| 784 |               temp = *(data + len);
 | 
|---|
| 785 |               *(data + len) = 0;
 | 
|---|
| 786 |               if (match(data,
 | 
|---|
| 787 |                         grep->searchPattern,
 | 
|---|
| 788 |                         grep->absFlag,
 | 
|---|
| 789 |                         (grep->caseFlag == FALSE),
 | 
|---|
| 790 |                         len,
 | 
|---|
| 791 |                         grep->numlines, grep->matched, !grep->findifany)) {
 | 
|---|
| 792 |                 strmatch = TRUE;
 | 
|---|
| 793 |                 break;
 | 
|---|
| 794 |               }
 | 
|---|
| 795 |               data += len;
 | 
|---|
| 796 |               *data = temp;
 | 
|---|
| 797 |               if (data - info->value >= info->cbValue)
 | 
|---|
| 798 |                 break;
 | 
|---|
| 799 |               type = *(USHORT *) data;
 | 
|---|
| 800 |               data += sizeof(USHORT);
 | 
|---|
| 801 |               len = *(USHORT *) data;
 | 
|---|
| 802 |               data += sizeof(USHORT);
 | 
|---|
| 803 |             }
 | 
|---|
| 804 |           }
 | 
|---|
| 805 |           break;
 | 
|---|
| 806 |         default:
 | 
|---|
| 807 |           break;
 | 
|---|
| 808 |         }
 | 
|---|
| 809 |         info = info->next;
 | 
|---|
| 810 |       }                                 // while
 | 
|---|
| 811 |       Free_FEAList(head);
 | 
|---|
| 812 |       DosSleep(1);
 | 
|---|
| 813 |     }
 | 
|---|
| 814 |   }
 | 
|---|
| 815 | 
 | 
|---|
| 816 |   if (grep->searchFiles) {
 | 
|---|
| 817 |     input = xmalloc(65537, pszSrcFile, __LINE__);
 | 
|---|
| 818 |     if (input) {
 | 
|---|
| 819 |       LONG len;
 | 
|---|
| 820 | 
 | 
|---|
| 821 |       inputFile = _fsopen(filename, "rb", SH_DENYNO);
 | 
|---|
| 822 |       if (inputFile) {
 | 
|---|
| 823 |         pos = ftell(inputFile);
 | 
|---|
| 824 |         while (!feof(inputFile)) {
 | 
|---|
| 825 |           if (pos)
 | 
|---|
| 826 |             fseek(inputFile, pos - 1024, SEEK_SET);
 | 
|---|
| 827 |           len = fread(input, 1, 65536, inputFile);
 | 
|---|
| 828 |           if (len >= 0) {
 | 
|---|
| 829 |             if (*grep->stopflag)
 | 
|---|
| 830 |               break;
 | 
|---|
| 831 |             if (match(input,
 | 
|---|
| 832 |                       grep->searchPattern,
 | 
|---|
| 833 |                       grep->absFlag,
 | 
|---|
| 834 |                       (grep->caseFlag == FALSE),
 | 
|---|
| 835 |                       len, grep->numlines, grep->matched, !grep->findifany)) {
 | 
|---|
| 836 |               strmatch = TRUE;
 | 
|---|
| 837 |               break;
 | 
|---|
| 838 |             }
 | 
|---|
| 839 |           }
 | 
|---|
| 840 |           else
 | 
|---|
| 841 |             break;
 | 
|---|
| 842 |         }
 | 
|---|
| 843 |         fclose(inputFile);
 | 
|---|
| 844 |       }
 | 
|---|
| 845 |       free(input);
 | 
|---|
| 846 |       DosSleep(1);
 | 
|---|
| 847 |     }
 | 
|---|
| 848 |   } // if
 | 
|---|
| 849 | 
 | 
|---|
| 850 |   if (strmatch)
 | 
|---|
| 851 |     ret = insert_grepfile(grep, filename, f);
 | 
|---|
| 852 |   return ret;
 | 
|---|
| 853 | }
 | 
|---|
| 854 | 
 | 
|---|
| 855 | #pragma alloc_text(DUPES,InsertDupe,FillDupes,FreeDupes,CRCFile,CRCBlock)
 | 
|---|
| 856 | #pragma alloc_text(DUPES,comparenamesq,comparenamesqe,comparenamesb)
 | 
|---|
| 857 | #pragma alloc_text(DUPES,comparenamesbe,comparesizesq,comparesizesb)
 | 
|---|
| 858 | 
 | 
|---|
| 859 | static LONG cr3tab[] = {        /* CRC polynomial 0xEDB88320 */
 | 
|---|
| 860 | 
 | 
|---|
| 861 |   0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
 | 
|---|
| 862 |   0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
 | 
|---|
| 863 |   0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
 | 
|---|
| 864 |   0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
 | 
|---|
| 865 |   0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
 | 
|---|
| 866 |   0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
 | 
|---|
| 867 |   0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
 | 
|---|
| 868 |   0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
 | 
|---|
| 869 |   0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
 | 
|---|
| 870 |   0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
 | 
|---|
| 871 |   0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
 | 
|---|
| 872 |   0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
 | 
|---|
| 873 |   0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
 | 
|---|
| 874 |   0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
 | 
|---|
| 875 |   0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
 | 
|---|
| 876 |   0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
 | 
|---|
| 877 |   0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
 | 
|---|
| 878 |   0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
 | 
|---|
| 879 |   0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
 | 
|---|
| 880 |   0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
 | 
|---|
| 881 |   0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
 | 
|---|
| 882 |   0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
 | 
|---|
| 883 |   0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
 | 
|---|
| 884 |   0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
 | 
|---|
| 885 |   0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
 | 
|---|
| 886 |   0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
 | 
|---|
| 887 |   0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
 | 
|---|
| 888 |   0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
 | 
|---|
| 889 |   0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
 | 
|---|
| 890 |   0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
 | 
|---|
| 891 |   0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
 | 
|---|
| 892 |   0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
 | 
|---|
| 893 |   0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
 | 
|---|
| 894 |   0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
 | 
|---|
| 895 |   0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
 | 
|---|
| 896 |   0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
 | 
|---|
| 897 |   0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
 | 
|---|
| 898 |   0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
 | 
|---|
| 899 |   0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
 | 
|---|
| 900 |   0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
 | 
|---|
| 901 |   0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
 | 
|---|
| 902 |   0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
 | 
|---|
| 903 |   0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
 | 
|---|
| 904 |   0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
 | 
|---|
| 905 |   0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
 | 
|---|
| 906 |   0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
 | 
|---|
| 907 |   0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
 | 
|---|
| 908 |   0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
 | 
|---|
| 909 |   0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
 | 
|---|
| 910 |   0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
 | 
|---|
| 911 |   0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
 | 
|---|
| 912 |   0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
 | 
|---|
| 913 |   0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
 | 
|---|
| 914 |   0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
 | 
|---|
| 915 |   0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
 | 
|---|
| 916 |   0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
 | 
|---|
| 917 |   0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
 | 
|---|
| 918 |   0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
 | 
|---|
| 919 |   0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
 | 
|---|
| 920 |   0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
 | 
|---|
| 921 |   0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
 | 
|---|
| 922 |   0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
 | 
|---|
| 923 |   0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
 | 
|---|
| 924 |   0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
 | 
|---|
| 925 | };
 | 
|---|
| 926 | 
 | 
|---|
| 927 | LONG CRCBlock(register CHAR * str, register INT blklen, register LONG crc)
 | 
|---|
| 928 | {
 | 
|---|
| 929 |   while (blklen--) {
 | 
|---|
| 930 |     crc =
 | 
|---|
| 931 |       cr3tab[((INT) crc ^ *str) & 0xff] ^ (((ULONG) crc >> 8) & 0x00FFFFFF);
 | 
|---|
| 932 |     str++;
 | 
|---|
| 933 |   }
 | 
|---|
| 934 |   return crc;
 | 
|---|
| 935 | }
 | 
|---|
| 936 | 
 | 
|---|
| 937 | LONG CRCFile(CHAR * filename, INT * error)
 | 
|---|
| 938 | {
 | 
|---|
| 939 |   LONG CRC = -1L, len;
 | 
|---|
| 940 |   FILE *fp;
 | 
|---|
| 941 |   CHAR *buffer;
 | 
|---|
| 942 | 
 | 
|---|
| 943 |   *error = 0;
 | 
|---|
| 944 |   buffer = xmalloc(65535, pszSrcFile, __LINE__);
 | 
|---|
| 945 |   if (!buffer)
 | 
|---|
| 946 |     *error = -1;
 | 
|---|
| 947 |   else {
 | 
|---|
| 948 |     fp = _fsopen(filename, "rb", SH_DENYNO);
 | 
|---|
| 949 |     if (!fp)
 | 
|---|
| 950 |       *error = -2;
 | 
|---|
| 951 |     else {
 | 
|---|
| 952 |       while (!feof(fp)) {
 | 
|---|
| 953 |         len = fread(buffer, 1, 65535, fp);
 | 
|---|
| 954 |         if (len && len < 65536L)
 | 
|---|
| 955 |           CRC = CRCBlock(buffer, len, CRC);
 | 
|---|
| 956 |         else
 | 
|---|
| 957 |           break;
 | 
|---|
| 958 |         DosSleep(1);
 | 
|---|
| 959 |       }
 | 
|---|
| 960 |       fclose(fp);
 | 
|---|
| 961 |       DosSleep(1);
 | 
|---|
| 962 |     }
 | 
|---|
| 963 |     free(buffer);
 | 
|---|
| 964 |   }
 | 
|---|
| 965 |   return CRC;
 | 
|---|
| 966 | }
 | 
|---|
| 967 | 
 | 
|---|
| 968 | static VOID FreeDupes(GREP * g)
 | 
|---|
| 969 | {
 | 
|---|
| 970 |   DUPES *i, *next;
 | 
|---|
| 971 | 
 | 
|---|
| 972 |   i = g->dupehead;
 | 
|---|
| 973 |   while (i) {
 | 
|---|
| 974 |     next = i->next;
 | 
|---|
| 975 |     if (i->name)
 | 
|---|
| 976 |       free(i->name);
 | 
|---|
| 977 |     free(i);
 | 
|---|
| 978 |     i = next;
 | 
|---|
| 979 |   }
 | 
|---|
| 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;
 | 
|---|
| 986 | }
 | 
|---|
| 987 | 
 | 
|---|
| 988 | int comparenamesq(const void *v1, const void *v2)
 | 
|---|
| 989 | {
 | 
|---|
| 990 |   DUPES *d1 = *(DUPES **) v1;
 | 
|---|
| 991 |   DUPES *d2 = *(DUPES **) v2;
 | 
|---|
| 992 |   CHAR *p1, *p2;
 | 
|---|
| 993 | 
 | 
|---|
| 994 |   p1 = strrchr(d1->name, '\\');
 | 
|---|
| 995 |   if (p1)
 | 
|---|
| 996 |     p1++;
 | 
|---|
| 997 |   else
 | 
|---|
| 998 |     p1 = d1->name;
 | 
|---|
| 999 |   p2 = strrchr(d2->name, '\\');
 | 
|---|
| 1000 |   if (p2)
 | 
|---|
| 1001 |     p2++;
 | 
|---|
| 1002 |   else
 | 
|---|
| 1003 |     p2 = d2->name;
 | 
|---|
| 1004 |   return stricmp(p1, p2);
 | 
|---|
| 1005 | }
 | 
|---|
| 1006 | 
 | 
|---|
| 1007 | int comparenamesqe(const void *v1, const void *v2)
 | 
|---|
| 1008 | {
 | 
|---|
| 1009 |   DUPES *d1 = *(DUPES **) v1;
 | 
|---|
| 1010 |   DUPES *d2 = *(DUPES **) v2;
 | 
|---|
| 1011 |   CHAR *p1, *p2, *p1e, *p2e, e1, e2;
 | 
|---|
| 1012 |   int ret;
 | 
|---|
| 1013 | 
 | 
|---|
| 1014 |   p1 = strrchr(d1->name, '\\');
 | 
|---|
| 1015 |   if (p1)
 | 
|---|
| 1016 |     p1++;
 | 
|---|
| 1017 |   else
 | 
|---|
| 1018 |     p1 = d1->name;
 | 
|---|
| 1019 |   p1e = strrchr(p1, '.');
 | 
|---|
| 1020 |   if (p1e) {
 | 
|---|
| 1021 |     e1 = *p1e;
 | 
|---|
| 1022 |     *p1e = 0;
 | 
|---|
| 1023 |   }
 | 
|---|
| 1024 |   p2 = strrchr(d2->name, '\\');
 | 
|---|
| 1025 |   if (p2)
 | 
|---|
| 1026 |     p2++;
 | 
|---|
| 1027 |   else
 | 
|---|
| 1028 |     p2 = d2->name;
 | 
|---|
| 1029 |   p2e = strrchr(p2, '.');
 | 
|---|
| 1030 |   if (p2e) {
 | 
|---|
| 1031 |     e2 = *p2e;
 | 
|---|
| 1032 |     *p2e = 0;
 | 
|---|
| 1033 |   }
 | 
|---|
| 1034 |   ret = stricmp(p1, p2);
 | 
|---|
| 1035 |   if (p1e)
 | 
|---|
| 1036 |     *p1e = e1;
 | 
|---|
| 1037 |   if (p2e)
 | 
|---|
| 1038 |     *p2e = e2;
 | 
|---|
| 1039 |   return ret;
 | 
|---|
| 1040 | }
 | 
|---|
| 1041 | 
 | 
|---|
| 1042 | int comparesizesq(const void *v1, const void *v2)
 | 
|---|
| 1043 | {
 | 
|---|
| 1044 |   DUPES *d1 = *(DUPES **) v1;
 | 
|---|
| 1045 |   DUPES *d2 = *(DUPES **) v2;
 | 
|---|
| 1046 | 
 | 
|---|
| 1047 |   return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
 | 
|---|
| 1048 | }
 | 
|---|
| 1049 | 
 | 
|---|
| 1050 | int comparenamesb(const void *v1, const void *v2)
 | 
|---|
| 1051 | {
 | 
|---|
| 1052 |   DUPES *d1 = (DUPES *) v1;
 | 
|---|
| 1053 |   DUPES *d2 = *(DUPES **) v2;
 | 
|---|
| 1054 |   CHAR *p1, *p2;
 | 
|---|
| 1055 | 
 | 
|---|
| 1056 |   p1 = strrchr(d1->name, '\\');
 | 
|---|
| 1057 |   if (p1)
 | 
|---|
| 1058 |     p1++;
 | 
|---|
| 1059 |   else
 | 
|---|
| 1060 |     p1 = d1->name;
 | 
|---|
| 1061 |   p2 = strrchr(d2->name, '\\');
 | 
|---|
| 1062 |   if (p2)
 | 
|---|
| 1063 |     p2++;
 | 
|---|
| 1064 |   else
 | 
|---|
| 1065 |     p2 = d2->name;
 | 
|---|
| 1066 |   return stricmp(p1, p2);
 | 
|---|
| 1067 | }
 | 
|---|
| 1068 | 
 | 
|---|
| 1069 | int comparenamesbe(const void *v1, const void *v2)
 | 
|---|
| 1070 | {
 | 
|---|
| 1071 |   DUPES *d1 = (DUPES *) v1;
 | 
|---|
| 1072 |   DUPES *d2 = *(DUPES **) v2;
 | 
|---|
| 1073 |   CHAR *p1, *p2, *p1e, *p2e, e1, e2;
 | 
|---|
| 1074 |   int ret;
 | 
|---|
| 1075 | 
 | 
|---|
| 1076 |   p1 = strrchr(d1->name, '\\');
 | 
|---|
| 1077 |   if (p1)
 | 
|---|
| 1078 |     p1++;
 | 
|---|
| 1079 |   else
 | 
|---|
| 1080 |     p1 = d1->name;
 | 
|---|
| 1081 |   p1e = strrchr(p1, '.');
 | 
|---|
| 1082 |   if (p1e) {
 | 
|---|
| 1083 |     e1 = *p1e;
 | 
|---|
| 1084 |     *p1e = 0;
 | 
|---|
| 1085 |   }
 | 
|---|
| 1086 |   p2 = strrchr(d2->name, '\\');
 | 
|---|
| 1087 |   if (p2)
 | 
|---|
| 1088 |     p2++;
 | 
|---|
| 1089 |   else
 | 
|---|
| 1090 |     p2 = d2->name;
 | 
|---|
| 1091 |   p2e = strrchr(p2, '.');
 | 
|---|
| 1092 |   if (p2e) {
 | 
|---|
| 1093 |     e2 = *p2e;
 | 
|---|
| 1094 |     *p2e = 0;
 | 
|---|
| 1095 |   }
 | 
|---|
| 1096 |   ret = stricmp(p1, p2);
 | 
|---|
| 1097 |   if (p1e)
 | 
|---|
| 1098 |     *p1e = e1;
 | 
|---|
| 1099 |   if (p2e)
 | 
|---|
| 1100 |     *p2e = e2;
 | 
|---|
| 1101 |   return ret;
 | 
|---|
| 1102 | }
 | 
|---|
| 1103 | 
 | 
|---|
| 1104 | int comparesizesb(const void *v1, const void *v2)
 | 
|---|
| 1105 | {
 | 
|---|
| 1106 |   DUPES *d1 = (DUPES *) v1;
 | 
|---|
| 1107 |   DUPES *d2 = *(DUPES **) v2;
 | 
|---|
| 1108 | 
 | 
|---|
| 1109 |   return (d1->size > d2->size) ? 1 : (d1->size == d2->size) ? 0 : -1;
 | 
|---|
| 1110 | }
 | 
|---|
| 1111 | 
 | 
|---|
| 1112 | static VOID FillDupes(GREP * g)
 | 
|---|
| 1113 | {
 | 
|---|
| 1114 |   DUPES *c, *i, **r;
 | 
|---|
| 1115 |   register CHAR *pc, *pi;
 | 
|---|
| 1116 |   CHAR **list = NULL;
 | 
|---|
| 1117 |   INT numfiles = 0, numalloced = 0, error;
 | 
|---|
| 1118 |   register ULONG x = 0, y = 0;
 | 
|---|
| 1119 |   ULONG cntr = 100;
 | 
|---|
| 1120 | 
 | 
|---|
| 1121 |   if (g->CRCdupes)
 | 
|---|
| 1122 |     cntr = 50;
 | 
|---|
| 1123 |   i = g->dupehead;
 | 
|---|
| 1124 |   while (i) {
 | 
|---|
| 1125 |     x++;
 | 
|---|
| 1126 |     i = i->next;
 | 
|---|
| 1127 |   }
 | 
|---|
| 1128 |   if (x) {
 | 
|---|
| 1129 |     WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPESORTINGTEXT));
 | 
|---|
| 1130 |     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;
 | 
|---|
| 1136 |       while (i) {
 | 
|---|
| 1137 |         g->dupenames[y] = i;
 | 
|---|
| 1138 |         if (!g->nosizedupes)
 | 
|---|
| 1139 |           g->dupesizes[y] = i;
 | 
|---|
| 1140 |         i = i->next;
 | 
|---|
| 1141 |         y++;
 | 
|---|
| 1142 |       }
 | 
|---|
| 1143 |       g->dupenames[y] = NULL;
 | 
|---|
| 1144 |       if (!g->nosizedupes)
 | 
|---|
| 1145 |         g->dupesizes[y] = NULL;
 | 
|---|
| 1146 |       DosSleep(1);
 | 
|---|
| 1147 |       qsort(g->dupenames,
 | 
|---|
| 1148 |             x,
 | 
|---|
| 1149 |             sizeof(DUPES *),
 | 
|---|
| 1150 |             ((g->ignoreextdupes) ? comparenamesqe : comparenamesq));
 | 
|---|
| 1151 |       DosSleep(1);
 | 
|---|
| 1152 |       if (!g->nosizedupes) {
 | 
|---|
| 1153 |         qsort(g->dupesizes, x, sizeof(DUPES *), comparesizesq);
 | 
|---|
| 1154 |         DosSleep(1);
 | 
|---|
| 1155 |       }
 | 
|---|
| 1156 |       WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
 | 
|---|
| 1157 | 
 | 
|---|
| 1158 |       i = g->dupehead;
 | 
|---|
| 1159 |       y = 0;
 | 
|---|
| 1160 |       while (i) {
 | 
|---|
| 1161 |         if (*g->stopflag)
 | 
|---|
| 1162 |           break;
 | 
|---|
| 1163 |         if (!(i->flags & GF_SKIPME)) {
 | 
|---|
| 1164 |           r = (DUPES **) bsearch(i, g->dupenames, x, sizeof(DUPES *),
 | 
|---|
| 1165 |                                  ((g->ignoreextdupes) ? comparenamesbe :
 | 
|---|
| 1166 |                                   comparenamesb));
 | 
|---|
| 1167 |           if (r) {
 | 
|---|
| 1168 |             while (r > g->dupenames && ((g->ignoreextdupes) ?
 | 
|---|
| 1169 |                                         !comparenamesqe((r - 1), &i) :
 | 
|---|
| 1170 |                                         !comparenamesq((r - 1), &i)))
 | 
|---|
| 1171 |               r--;
 | 
|---|
| 1172 |             while (*r && ((g->ignoreextdupes) ?
 | 
|---|
| 1173 |                           !comparenamesqe(r, &i) : !comparenamesq(r, &i))) {
 | 
|---|
| 1174 |               if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME))) {
 | 
|---|
| 1175 |                 r++;
 | 
|---|
| 1176 |                 continue;
 | 
|---|
| 1177 |               }
 | 
|---|
| 1178 |               if (g->CRCdupes) {
 | 
|---|
| 1179 |                 if ((*r)->CRC == -1L) {
 | 
|---|
| 1180 |                   (*r)->CRC = CRCFile((*r)->name, &error);
 | 
|---|
| 1181 |                   if (error)
 | 
|---|
| 1182 |                     (*r)->CRC = -1L;
 | 
|---|
| 1183 |                   else if ((*r)->CRC == -1L)
 | 
|---|
| 1184 |                     (*r)->CRC = 0L;
 | 
|---|
| 1185 |                 }
 | 
|---|
| 1186 |                 if (i->CRC == -1L) {
 | 
|---|
| 1187 |                   i->CRC = CRCFile(i->name, &error);
 | 
|---|
| 1188 |                   if (error)
 | 
|---|
| 1189 |                     i->CRC = -1L;
 | 
|---|
| 1190 |                   else if (i->CRC == -1L)
 | 
|---|
| 1191 |                     i->CRC = 0L;
 | 
|---|
| 1192 |                 }
 | 
|---|
| 1193 |                 if (((*r)->size != i->size) || ((*r)->CRC != -1L &&
 | 
|---|
| 1194 |                                                 i->CRC != -1L
 | 
|---|
| 1195 |                                                 && (*r)->CRC != i->CRC)) {
 | 
|---|
| 1196 |                   r++;
 | 
|---|
| 1197 |                   continue;
 | 
|---|
| 1198 |                 }
 | 
|---|
| 1199 |               }
 | 
|---|
| 1200 |               if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
 | 
|---|
| 1201 |                 (*r)->flags |= GF_INSERTED;
 | 
|---|
| 1202 |                 if (g->sayfiles)
 | 
|---|
| 1203 |                   WinSetWindowText(g->hwndFiles, (*r)->name);
 | 
|---|
| 1204 |                 if ((*r)->size == i->size &&
 | 
|---|
| 1205 |                     (i->date.year == (*r)->date.year &&
 | 
|---|
| 1206 |                      i->date.month == (*r)->date.month &&
 | 
|---|
| 1207 |                      i->date.day == (*r)->date.day &&
 | 
|---|
| 1208 |                      i->time.hours == (*r)->time.hours &&
 | 
|---|
| 1209 |                      i->time.minutes == (*r)->time.minutes &&
 | 
|---|
| 1210 |                      i->time.twosecs == (*r)->time.twosecs))
 | 
|---|
| 1211 |                   (*r)->flags |= GF_SKIPME;
 | 
|---|
| 1212 |               }
 | 
|---|
| 1213 |               if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
 | 
|---|
| 1214 |                 if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
 | 
|---|
| 1215 |                   i->flags |= GF_INSERTED;
 | 
|---|
| 1216 |                   if ((*r)->flags & GF_SKIPME)
 | 
|---|
| 1217 |                     i->flags |= GF_SKIPME;
 | 
|---|
| 1218 |                 }
 | 
|---|
| 1219 |               }
 | 
|---|
| 1220 |               r++;
 | 
|---|
| 1221 |             }
 | 
|---|
| 1222 |           }
 | 
|---|
| 1223 |           if (!g->nosizedupes) {
 | 
|---|
| 1224 |             r = (DUPES **) bsearch(i,
 | 
|---|
| 1225 |                                    g->dupesizes,
 | 
|---|
| 1226 |                                    x, sizeof(DUPES *), comparesizesb);
 | 
|---|
| 1227 |             if (r) {
 | 
|---|
| 1228 |               while (r > g->dupesizes && !comparesizesq((r - 1), &i))
 | 
|---|
| 1229 |                 r--;
 | 
|---|
| 1230 |               while (*r && !comparesizesq(r, &i)) {
 | 
|---|
| 1231 |                 if (*r == i || ((*r)->flags & (GF_INSERTED | GF_SKIPME)) ||
 | 
|---|
| 1232 |                     (i->date.year != (*r)->date.year ||
 | 
|---|
| 1233 |                      i->date.month != (*r)->date.month ||
 | 
|---|
| 1234 |                      i->date.day != (*r)->date.day ||
 | 
|---|
| 1235 |                      i->time.hours != (*r)->time.hours ||
 | 
|---|
| 1236 |                      i->time.minutes != (*r)->time.minutes ||
 | 
|---|
| 1237 |                      i->time.twosecs != (*r)->time.twosecs)) {
 | 
|---|
| 1238 |                   r++;
 | 
|---|
| 1239 |                   continue;
 | 
|---|
| 1240 |                 }
 | 
|---|
| 1241 |                 if (g->CRCdupes) {
 | 
|---|
| 1242 |                   if ((*r)->CRC == -1L) {
 | 
|---|
| 1243 |                     (*r)->CRC = CRCFile((*r)->name, &error);
 | 
|---|
| 1244 |                     if (error)
 | 
|---|
| 1245 |                       (*r)->CRC = -1L;
 | 
|---|
| 1246 |                     else if ((*r)->CRC == -1L)
 | 
|---|
| 1247 |                       (*r)->CRC = 0L;
 | 
|---|
| 1248 |                   }
 | 
|---|
| 1249 |                   if (i->CRC == -1L) {
 | 
|---|
| 1250 |                     i->CRC = CRCFile(i->name, &error);
 | 
|---|
| 1251 |                     if (error)
 | 
|---|
| 1252 |                       i->CRC = -1L;
 | 
|---|
| 1253 |                     else if (i->CRC == -1L)
 | 
|---|
| 1254 |                       i->CRC = 0L;
 | 
|---|
| 1255 |                   }
 | 
|---|
| 1256 |                   if ((*r)->CRC != -1L && i->CRC != -1L &&
 | 
|---|
| 1257 |                       (*r)->CRC != i->CRC) {
 | 
|---|
| 1258 |                     *r += 1;
 | 
|---|
| 1259 |                     continue;
 | 
|---|
| 1260 |                   }
 | 
|---|
| 1261 |                 }
 | 
|---|
| 1262 |                 if (!AddToList((*r)->name, &list, &numfiles, &numalloced)) {
 | 
|---|
| 1263 |                   if (g->sayfiles)
 | 
|---|
| 1264 |                     WinSetWindowText(g->hwndCurFile, (*r)->name);
 | 
|---|
| 1265 |                   (*r)->flags |= GF_INSERTED;
 | 
|---|
| 1266 |                   if (((g->ignoreextdupes) ?
 | 
|---|
| 1267 |                        comparenamesqe(r, &i) : comparenamesq(r, &i)))
 | 
|---|
| 1268 |                     (*r)->flags |= GF_SKIPME;
 | 
|---|
| 1269 |                 }
 | 
|---|
| 1270 |                 if (!(i->flags & (GF_INSERTED | GF_SKIPME))) {
 | 
|---|
| 1271 |                   if (!AddToList(i->name, &list, &numfiles, &numalloced)) {
 | 
|---|
| 1272 |                     i->flags |= GF_INSERTED;
 | 
|---|
| 1273 |                     if ((*r)->flags & GF_SKIPME)
 | 
|---|
| 1274 |                       i->flags |= GF_SKIPME;
 | 
|---|
| 1275 |                   }
 | 
|---|
| 1276 |                 }
 | 
|---|
| 1277 |                 r++;
 | 
|---|
| 1278 |               }
 | 
|---|
| 1279 |             }
 | 
|---|
| 1280 |           }
 | 
|---|
| 1281 |         }
 | 
|---|
| 1282 |         i = i->next;
 | 
|---|
| 1283 |         y++;
 | 
|---|
| 1284 |         if (!(y % cntr)) {
 | 
|---|
| 1285 | 
 | 
|---|
| 1286 |           CHAR s[44];
 | 
|---|
| 1287 | 
 | 
|---|
| 1288 |           sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g->numfiles);
 | 
|---|
| 1289 |           WinSetWindowText(g->hwndCurFile, s);
 | 
|---|
| 1290 |           DosSleep(100); //05 Aug 07 GKY 128
 | 
|---|
| 1291 |         }
 | 
|---|
| 1292 |         DosSleep(y % 2);
 | 
|---|
| 1293 |       }
 | 
|---|
| 1294 |     }
 | 
|---|
| 1295 |     else {
 | 
|---|
| 1296 |       // Insufficient memory - fall back
 | 
|---|
| 1297 |       DosBeep(50, 100);
 | 
|---|
| 1298 |       WinSetWindowText(g->hwndCurFile, GetPString(IDS_GREPDUPECOMPARINGTEXT));
 | 
|---|
| 1299 |       x = y = 0;
 | 
|---|
| 1300 |       if (g->dupenames) {
 | 
|---|
| 1301 |         free(g->dupenames);
 | 
|---|
| 1302 |         g->dupenames = NULL;
 | 
|---|
| 1303 |       }
 | 
|---|
| 1304 |       if (g->dupesizes) {
 | 
|---|
| 1305 |         free(g->dupesizes);
 | 
|---|
| 1306 |         g->dupesizes = NULL;
 | 
|---|
| 1307 |       }
 | 
|---|
| 1308 |       i = g->dupehead;
 | 
|---|
| 1309 |       while (i) {
 | 
|---|
| 1310 |         if (*g->stopflag)
 | 
|---|
| 1311 |           break;
 | 
|---|
| 1312 |         if (!(i->flags & GF_SKIPME)) {
 | 
|---|
| 1313 |           if (!(y % cntr)) {
 | 
|---|
| 1314 | 
 | 
|---|
| 1315 |             CHAR s[44];
 | 
|---|
| 1316 | 
 | 
|---|
| 1317 |             sprintf(s, GetPString(IDS_GREPDUPECHECKPROGTEXT), y, g->numfiles);
 | 
|---|
| 1318 |             WinSetWindowText(g->hwndCurFile, s);
 | 
|---|
| 1319 |             DosSleep(1);
 | 
|---|
| 1320 |           }
 | 
|---|
| 1321 |           y++;
 | 
|---|
| 1322 |           pi = strrchr(i->name, '\\');
 | 
|---|
| 1323 |           if (pi)
 | 
|---|
| 1324 |             pi++;
 | 
|---|
| 1325 |           else
 | 
|---|
| 1326 |             pi = i->name;
 | 
|---|
| 1327 |           c = g->dupehead;
 | 
|---|
| 1328 |           while (c) {
 | 
|---|
| 1329 |             if (*g->stopflag)
 | 
|---|
| 1330 |               break;
 | 
|---|
| 1331 |             if (c != i && !(c->flags & (GF_INSERTED | GF_SKIPME))) {
 | 
|---|
| 1332 |               x++;
 | 
|---|
| 1333 |               pc = strrchr(c->name, '\\');
 | 
|---|
| 1334 |               if (pc)
 | 
|---|
| 1335 |                 pc++;
 | 
|---|
| 1336 |               else
 | 
|---|
| 1337 |                 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) {
 | 
|---|
| 1341 |                     if (c->CRC == -1L) {
 | 
|---|
| 1342 |                       c->CRC = CRCFile(c->name, &error);
 | 
|---|
| 1343 |                       if (error)
 | 
|---|
| 1344 |                         c->CRC = -1L;
 | 
|---|
| 1345 |                       else if (c->CRC == -1L)
 | 
|---|
| 1346 |                         c->CRC = 0L;
 | 
|---|
| 1347 |                     }
 | 
|---|
| 1348 |                     if (i->CRC == -1L) {
 | 
|---|
| 1349 |                       i->CRC = CRCFile(i->name, &error);
 | 
|---|
| 1350 |                       if (error)
 | 
|---|
| 1351 |                         i->CRC = -1L;
 | 
|---|
| 1352 |                       else if (i->CRC == -1L)
 | 
|---|
| 1353 |                         i->CRC = 0L;
 | 
|---|
| 1354 |                     }
 | 
|---|
| 1355 |                     if ((c->size != i->size) || (c->CRC != -1L &&
 | 
|---|
| 1356 |                                                  i->CRC != -1L
 | 
|---|
| 1357 |                                                  && c->CRC != i->CRC)) {
 | 
|---|
| 1358 |                       c = c->next;
 | 
|---|
| 1359 |                       continue;
 | 
|---|
| 1360 |                     }
 | 
|---|
| 1361 |                   }
 | 
|---|
| 1362 |                 }
 | 
|---|
| 1363 |                 if (AddToList(c->name, &list, &numfiles, &numalloced))
 | 
|---|
| 1364 |                   goto BreakOut;        // Failed
 | 
|---|
| 1365 |                 if (!(i->flags & GF_INSERTED)) {
 | 
|---|
| 1366 |                   if (AddToList(i->name, &list, &numfiles, &numalloced))
 | 
|---|
| 1367 |                     goto BreakOut;      // Failed
 | 
|---|
| 1368 |                 }
 | 
|---|
| 1369 |                 if (g->sayfiles)
 | 
|---|
| 1370 |                   WinSetWindowText(g->hwndCurFile, pc);
 | 
|---|
| 1371 |                 c->flags |= GF_INSERTED;
 | 
|---|
| 1372 |                 i->flags |= GF_INSERTED;
 | 
|---|
| 1373 |                 if (!stricmp(pc, pi)) {
 | 
|---|
| 1374 |                   c->flags |= GF_SKIPME;
 | 
|---|
| 1375 |                   i->flags |= GF_SKIPME;
 | 
|---|
| 1376 |                 }
 | 
|---|
| 1377 |               }
 | 
|---|
| 1378 |               else if (!(x % 100))
 | 
|---|
| 1379 |                 DosSleep(1);
 | 
|---|
| 1380 |             }
 | 
|---|
| 1381 |             c = c->next;
 | 
|---|
| 1382 |           }
 | 
|---|
| 1383 |         }
 | 
|---|
| 1384 |         i = i->next;
 | 
|---|
| 1385 |       }
 | 
|---|
| 1386 |     }
 | 
|---|
| 1387 |   }
 | 
|---|
| 1388 | BreakOut:
 | 
|---|
| 1389 |   FreeDupes(g);
 | 
|---|
| 1390 |   if (numfiles && list) {
 | 
|---|
| 1391 |     if (!PostMsg(g->hwndFiles,
 | 
|---|
| 1392 |                  WM_COMMAND, MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list)))
 | 
|---|
| 1393 |       FreeList(list);
 | 
|---|
| 1394 |   }
 | 
|---|
| 1395 |   else
 | 
|---|
| 1396 |     DosPostEventSem(CompactSem);
 | 
|---|
| 1397 | }
 | 
|---|
| 1398 | 
 | 
|---|
| 1399 | static BOOL InsertDupe(GREP * g, CHAR * dir, FILEFINDBUF4 * f)
 | 
|---|
| 1400 | {
 | 
|---|
| 1401 |   DUPES *info;
 | 
|---|
| 1402 | 
 | 
|---|
| 1403 |   if (*dir) {
 | 
|---|
| 1404 |     info = xmallocz(sizeof(DUPES), pszSrcFile, __LINE__);
 | 
|---|
| 1405 |     if (!info)
 | 
|---|
| 1406 |       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 |     }
 | 
|---|
| 1427 |   }
 | 
|---|
| 1428 |   return TRUE;
 | 
|---|
| 1429 | }
 | 
|---|