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