Changeset 350 for trunk/dll/grep.c
- Timestamp:
- Jul 26, 2006, 9:01:20 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/grep.c
r281 r350 4 4 $Id$ 5 5 6 Info window6 grep tools 7 7 8 8 Copyright (c) 1993-98 M. Kimes 9 Copyright (c) 2001, 200 5Steven H. Levine9 Copyright (c) 2001, 2006 Steven H. Levine 10 10 11 11 12 Feb 03 SHL insert_grepfile: standardize EA math … … 15 15 06 Jun 05 SHL Drop unused code 16 16 24 Oct 05 SHL dononefile: do not free EA list twice 17 22 Jul 06 SHL Use Runtime_Error 17 18 18 19 ***********************************************************************/ … … 34 35 35 36 #pragma data_seg(DATA2) 37 38 static PSZ pszSrcFile = __FILE__; 39 36 40 #pragma alloc_text(GREP,SecsSince1980,match,mmatch,dogrep) 37 41 #pragma alloc_text(GREP,doallsubdirs,domatchingfiles) … … 464 468 /* process all matching files in a directory */ 465 469 466 PFILEFINDBUF4 findBuffer = malloc(grep->FilesToGet * sizeof(FILEFINDBUF4));470 PFILEFINDBUF4 findBuffer; 467 471 PFILEFINDBUF4 pffbFile; 468 472 register PBYTE fb; … … 473 477 APIRET rc; 474 478 479 findBuffer = xmalloc(grep->FilesToGet * sizeof(FILEFINDBUF4),pszSrcFile,__LINE__); 475 480 if(!findBuffer) 476 481 return 0; … … 648 653 *p = 0; 649 654 if(!grep->insertffb) { 650 grep->insertffb = malloc(sizeof(FILEFINDBUF4 *) *651 (grep->FilesToGet + 1));655 grep->insertffb = xmallocz(sizeof(FILEFINDBUF4 *) * 656 (grep->FilesToGet + 1),pszSrcFile,__LINE__); 652 657 if(!grep->insertffb) 653 658 return FALSE; 654 memset(grep->insertffb,0,sizeof(FILEFINDBUF4 *) * 655 (grep->FilesToGet + 1)); 656 grep->dir = malloc(sizeof(CHAR *) * (grep->FilesToGet + 1)); 659 grep->dir = xmallocz(sizeof(CHAR *) * (grep->FilesToGet + 1),pszSrcFile,__LINE__); 657 660 if(!grep->dir) { 658 661 free(grep->insertffb); 659 662 return FALSE; 660 663 } 661 memset(grep->dir,0,sizeof(CHAR *) * (grep->FilesToGet + 1)); 662 } 663 grep->insertffb[grep->toinsert] = malloc(sizeof(FILEFINDBUF4)); 664 } 665 grep->insertffb[grep->toinsert] = xmalloc(sizeof(FILEFINDBUF4),pszSrcFile,__LINE__); 664 666 if(!grep->insertffb[grep->toinsert]) 665 667 return FALSE; 666 668 memcpy(grep->insertffb[grep->toinsert],f,sizeof(FILEFINDBUF4)); 667 grep->dir[grep->toinsert] = strdup(szDirectory);669 grep->dir[grep->toinsert] = xstrdup(szDirectory,pszSrcFile,__LINE__); 668 670 if(!grep->dir) { 669 671 free(grep->insertffb[grep->toinsert]); … … 856 858 857 859 if(grep->searchFiles) { 858 input = malloc(65537);860 input = xmalloc(65537,pszSrcFile,__LINE__); 859 861 if(input) { 860 861 862 LONG len; 862 863 if ((inputFile = _fsopen(filename,"rb",SH_DENYNO)) != NULL) {863 inputFile = _fsopen(filename,"rb",SH_DENYNO); 864 if (inputFile) { 864 865 pos = ftell(inputFile); 865 866 while(!feof(inputFile)) { … … 992 993 993 994 *error = 0; 994 buffer = malloc(65535); 995 if(buffer) { 995 buffer = xmalloc(65535,pszSrcFile,__LINE__); 996 if (!buffer) 997 *error = -1; 998 else { 996 999 fp = _fsopen(filename,"rb",SH_DENYNO); 997 if(fp) { 1000 if (!fp) 1001 *error = -2; 1002 else { 998 1003 while(!feof(fp)) { 999 1004 len = fread(buffer,1,65535,fp); … … 1007 1012 DosSleep(1L); 1008 1013 } 1009 else1010 *error = -2;1011 1014 free(buffer); 1012 1015 } 1013 else1014 *error = -1;1015 1016 return CRC; 1016 1017 } … … 1180 1181 cntr = 50; 1181 1182 i = g->dupehead; 1182 while (i) {1183 while (i) { 1183 1184 x++; 1184 1185 i = i->next; 1185 1186 } 1186 if (x) {1187 if (x) { 1187 1188 WinSetWindowText(g->hwndCurFile, 1188 1189 GetPString(IDS_GREPDUPESORTINGTEXT)); 1189 1190 DosSleep(1L); 1190 1191 g->dupenames = malloc(sizeof(DUPES *) * (x + 1)); 1191 if (!g->nosizedupes)1192 if (!g->nosizedupes) 1192 1193 g->dupesizes = malloc(sizeof(DUPES *) * (x + 1)); 1193 if (g->dupenames && (g->nosizedupes || g->dupesizes)) {1194 if (g->dupenames && (g->nosizedupes || g->dupesizes)) { 1194 1195 i = g->dupehead; 1195 1196 while(i) { … … 1201 1202 } 1202 1203 g->dupenames[y] = NULL; 1203 if (!g->nosizedupes)1204 if (!g->nosizedupes) 1204 1205 g->dupesizes[y] = NULL; 1205 1206 DosSleep(1L); … … 1211 1212 comparenamesq)); 1212 1213 DosSleep(1L); 1213 if (!g->nosizedupes) {1214 if (!g->nosizedupes) { 1214 1215 qsort(g->dupesizes, 1215 1216 x, … … 1380 1381 } 1381 1382 else { 1383 // Insufficient memory - fall back 1382 1384 DosBeep(50,100); 1383 1385 WinSetWindowText(g->hwndCurFile, … … 1461 1463 &numfiles, 1462 1464 &numalloced)) 1463 goto BreakOut; 1465 goto BreakOut; // Failed 1464 1466 if(!(i->flags & GF_INSERTED)) { 1465 1467 if(AddToList(i->name, … … 1467 1469 &numfiles, 1468 1470 &numalloced)) 1469 goto BreakOut; 1471 goto BreakOut; // Failed 1470 1472 } 1471 1473 if(g->sayfiles) … … 1507 1509 DUPES *info; 1508 1510 1509 if(*dir) { 1510 info = malloc(sizeof(DUPES)); 1511 if(info) { 1512 memset(info,0,sizeof(DUPES)); 1513 info->name = strdup(dir); 1514 if(info->name) { 1511 if (*dir) { 1512 info = xmallocz(sizeof(DUPES),pszSrcFile,__LINE__); 1513 if (!info) 1514 return FALSE; 1515 else { 1516 info->name = xstrdup(dir,pszSrcFile,__LINE__); 1517 if (!info->name) { 1518 free(info); 1519 return FALSE; 1520 } 1521 else { 1515 1522 info->size = f->cbFile; 1516 1523 info->date = f->fdateLastWrite; … … 1518 1525 info->CRC = -1L; 1519 1526 g->numfiles++; 1520 if (!g->dupehead)1527 if (!g->dupehead) 1521 1528 g->dupehead = info; 1522 if (g->dupelast)1529 if (g->dupelast) 1523 1530 g->dupelast->next = info; 1524 1531 g->dupelast = info; 1525 1532 info->next = NULL; 1526 return TRUE; 1527 } 1528 else 1529 free(info); 1530 } 1531 DosBeep(50,100); 1532 return FALSE; 1533 } 1534 } 1533 1535 } 1534 1536 return TRUE;
Note:
See TracChangeset
for help on using the changeset viewer.