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