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