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