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