git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@2095 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2006/07/18 19:58:49... | ... |
@@ -1,3 +1,11 @@ |
1 |
+Tue Jul 18 12:54:39 CEST 2006 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * sigtool/sigtool.c: --diff: detect removal of last lines |
|
4 |
+ |
|
5 |
+Tue Jul 18 01:59:53 CEST 2006 (tk) |
|
6 |
+---------------------------------- |
|
7 |
+ * sigtool/sigtool.c: --diff: algorithm now detects line removals |
|
8 |
+ |
|
1 | 9 |
Mon Jul 17 16:54:05 BST 2006 (njh) |
2 | 10 |
---------------------------------- |
3 | 11 |
* clamav-milter: Fix compilation error on NetBSD 2.0 |
... | ... |
@@ -59,6 +59,7 @@ |
59 | 59 |
#include "libclamav/ole2_extract.h" |
60 | 60 |
#include "libclamav/htmlnorm.h" |
61 | 61 |
|
62 |
+#define MAX_DEL_LOOKAHEAD 50 |
|
62 | 63 |
|
63 | 64 |
static int hexdump(void) |
64 | 65 |
{ |
... | ... |
@@ -942,8 +943,9 @@ static int runcdiff(struct optstruct *opt) |
942 | 942 |
static int compare(const char *oldpath, const char *newpath, FILE *diff) |
943 | 943 |
{ |
944 | 944 |
FILE *old, *new; |
945 |
- char obuff[1024], nbuff[1024], *pt, *omd5, *nmd5; |
|
946 |
- unsigned int line = 0; |
|
945 |
+ char obuff[1024], nbuff[1024], tbuff[1024], *pt, *omd5, *nmd5; |
|
946 |
+ unsigned int oline = 0, tline, found, i; |
|
947 |
+ long opos; |
|
947 | 948 |
|
948 | 949 |
|
949 | 950 |
if(!(new = fopen(newpath, "r"))) { |
... | ... |
@@ -971,23 +973,50 @@ static int compare(const char *oldpath, const char *newpath, FILE *diff) |
971 | 971 |
old = fopen(oldpath, "r"); |
972 | 972 |
|
973 | 973 |
while(fgets(nbuff, sizeof(nbuff), new)) { |
974 |
- line++; |
|
975 | 974 |
cli_chomp(nbuff); |
976 | 975 |
|
977 | 976 |
if(!old) { |
978 | 977 |
fprintf(diff, "ADD %s\n", nbuff); |
979 | 978 |
} else { |
980 | 979 |
if(fgets(obuff, sizeof(obuff), old)) { |
980 |
+ oline++; |
|
981 | 981 |
cli_chomp(obuff); |
982 | 982 |
if(!strcmp(nbuff, obuff)) { |
983 | 983 |
continue; |
984 | 984 |
} else { |
985 |
- /* TODO: Improve/add detection of DEL, XCHG */ |
|
986 |
- if(!strncmp(nbuff, obuff, 5)) { |
|
987 |
- obuff[8] = 0; |
|
985 |
+ tline = 0; |
|
986 |
+ found = 0; |
|
987 |
+ opos = ftell(old); |
|
988 |
+ while(fgets(tbuff, sizeof(tbuff), old)) { |
|
989 |
+ tline++; |
|
990 |
+ cli_chomp(tbuff); |
|
991 |
+ |
|
992 |
+ if(tline > MAX_DEL_LOOKAHEAD) |
|
993 |
+ break; |
|
994 |
+ |
|
995 |
+ if(!strcmp(tbuff, nbuff)) { |
|
996 |
+ found = 1; |
|
997 |
+ break; |
|
998 |
+ } |
|
999 |
+ } |
|
1000 |
+ fseek(old, opos, SEEK_SET); |
|
1001 |
+ |
|
1002 |
+ if(found) { |
|
1003 |
+ strncpy(tbuff, obuff, sizeof(tbuff)); |
|
1004 |
+ for(i = 0; i < tline; i++) { |
|
1005 |
+ tbuff[16] = 0; |
|
1006 |
+ if((pt = strchr(tbuff, ' '))) |
|
1007 |
+ *pt = 0; |
|
1008 |
+ fprintf(diff, "DEL %u %s\n", oline + i, tbuff); |
|
1009 |
+ fgets(tbuff, sizeof(tbuff), old); |
|
1010 |
+ } |
|
1011 |
+ oline += tline; |
|
1012 |
+ |
|
1013 |
+ } else { |
|
1014 |
+ obuff[16] = 0; |
|
988 | 1015 |
if((pt = strchr(obuff, ' '))) |
989 | 1016 |
*pt = 0; |
990 |
- fprintf(diff, "XCHG %u %s %s\n", line, obuff, nbuff); |
|
1017 |
+ fprintf(diff, "XCHG %u %s %s\n", oline, obuff, nbuff); |
|
991 | 1018 |
} |
992 | 1019 |
} |
993 | 1020 |
} else { |
... | ... |
@@ -998,8 +1027,17 @@ static int compare(const char *oldpath, const char *newpath, FILE *diff) |
998 | 998 |
} |
999 | 999 |
} |
1000 | 1000 |
|
1001 |
- if(old) |
|
1001 |
+ if(old) { |
|
1002 |
+ while(fgets(obuff, sizeof(obuff), old)) { |
|
1003 |
+ oline++; |
|
1004 |
+ obuff[16] = 0; |
|
1005 |
+ if((pt = strchr(obuff, ' '))) |
|
1006 |
+ *pt = 0; |
|
1007 |
+ fprintf(diff, "DEL %u %s\n", oline, obuff); |
|
1008 |
+ } |
|
1002 | 1009 |
fclose(old); |
1010 |
+ } |
|
1011 |
+ |
|
1003 | 1012 |
fprintf(diff, "CLOSE\n"); |
1004 | 1013 |
return 0; |
1005 | 1014 |
} |