Subj : NodeDiff creation To : Dan Egli From : Jasen Betts Date : Sun Aug 17 2003 01:57 pm Hi Dan. 13-Aug-03 17:09:32, Dan Egli wrote to Jasen Betts >> Hi Dan. DE> That won't work. So I need some kind of algorythum for determining DE> how many lines have CHANGED. you have to count them DE> Make sense? sort of.... you want to know how to handle the case where the files differ not by an insertion or deletion but by an edit... Here's how I did it in 1998 after calling my resync() fseek the file pointers back and count how many lines each was advanced by the resync ... in the case when both line counts differ you shoudl emit a combination of a and d or a and i in the diff... (or vice-versa) matches is a a "fussinness" control, (how may lines must match for it to end the edit block) 1 would probably be an apropriate value for nodediffs. /**** excerpt from mkpatch.c ****/ #define LENGTH (1000) /* line length */ char* MyFgets(char *s,int n,FILE *f){ /* like fgets only nulls string on error */ *s='\0'; if(feof(f))return NULL; return fgets(s,n,f); } void resync(FILE*f1,FILE*f2,int matches){ /* attempts to resynchronise two file pointers, ** succeeds with both pointing to the next matching line ** fails with poth pointing to EOF - could be considered succes. */ /* I'm too lasy to use an array or other struct to hold the lines, ** i've initialised the files with a huge buffer and decided to ** let the library handle all that messy stuff. */ long po1,po2,pm1,pm2,pl1,pl2; int n,depth=1,y; static char l1[LENGTH],l2[LENGTH],lc1[LENGTH],lc2[LENGTH]; /* static to save the stack */ po1=ftell(f1); po2=ftell(f2); for(depth=1;1;depth++){ /* assertion: for all n,m <= depth : line[f1,m] != line[f2,n] * * so read the next line from file1 and compare it with the * * depth lines from file2 starting at po2 */ pl1=ftell(f1); MyFgets(l1,LENGTH,f1); fseek(f2,po2,SEEK_SET); for(y=1;y=matches) { /* success! */ fseek(f1,pl1,SEEK_SET); fseek(f2,pl2,SEEK_SET); return ; } fseek(f1,pm1,SEEK_SET); /* failure: restore pointers, keep looking */ fseek(f2,pm2,SEEK_SET); } } pl2=ftell(f2); /* this section is a mirror image of the */ MyFgets(l2,LENGTH,f2); /* section above, checking for a match */ fseek(f1,po1,SEEK_SET); /* from the other side */ for(y=1;y=matches) { fseek(f1,pl1,SEEK_SET); fseek(f2,pl2,SEEK_SET); return; } fseek(f1,pm1,SEEK_SET); fseek(f2,pm2,SEEK_SET); } } } } -=> Bye <=- -+- + Origin: I'm pink, therefore I'm SPAM. (3:640/1042) --- BBBS/LiI v4.01 Flag-5 * Origin: (1:3005/3) .