comparison kdiff3/src/gnudiff_analyze.cpp @ 69:8febbfb1148c

KDiff3 0.9.89
author joachim99
date Mon, 10 Apr 2006 08:40:51 +0000
parents d7cafcda8c99
children
comparison
equal deleted inserted replaced
68:d7cafcda8c99 69:8febbfb1148c
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18 18
19 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. 20 along with this program; see the file COPYING.
21 If not, write to the Free Software Foundation, 21 If not, write to the Free Software Foundation,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 22 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */
23 23
24 /* The basic algorithm is described in: 24 /* The basic algorithm is described in:
25 "An O(ND) Difference Algorithm and its Variations", Eugene Myers, 25 "An O(ND) Difference Algorithm and its Variations", Eugene Myers,
26 Algorithmica Vol. 1 No. 2, 1986, pp. 251-266; 26 Algorithmica Vol. 1 No. 2, 1986, pp. 251-266;
27 see especially section 4.2, which describes the variation used below. 27 see especially section 4.2, which describes the variation used below.
790 return script; 790 return script;
791 } 791 }
792 792
793 793
794 /* Report the differences of two files. */ 794 /* Report the differences of two files. */
795 // WARNING:
796 // This algorithm has one big problem: It must have a line end character
797 // at the end of the last line, even if there is none in the file.
798 // Because of this the algorithm first places a line end character there
799 // which means that the input data can't be const and some extra bytes of memory
800 // must be allocated in advance for this purpose. This is very dangerous, because
801 // easy to forget.
802 GnuDiff::change* GnuDiff::diff_2_files (struct comparison *cmp) 795 GnuDiff::change* GnuDiff::diff_2_files (struct comparison *cmp)
803 { 796 {
804 lin diags; 797 lin diags;
805 int f; 798 int f;
806 //struct change *e, *p; 799 //struct change *e, *p;
857 in cases where that can validly be done. */ 850 in cases where that can validly be done. */
858 851
859 shift_boundaries (cmp->file); 852 shift_boundaries (cmp->file);
860 853
861 /* Get the results of comparison in the form of a chain 854 /* Get the results of comparison in the form of a chain
862 of `struct change's -- an edit script. */ 855 of `struct change's -- an edit script. */
863 856
864 if (output_style == OUTPUT_ED) 857 script = build_script (cmp->file);
865 script = build_reverse_script (cmp->file);
866 else
867 script = build_script (cmp->file);
868 858
869 changes = (script != 0); 859 changes = (script != 0);
870 860
871 free (cmp->file[0].undiscarded); 861 free (cmp->file[0].undiscarded);
872 862
879 } 869 }
880 } 870 }
881 871
882 return script; 872 return script;
883 } 873 }
884
885 /* Compare two lines (typically one from each input file)
886 according to the command line options.
887 For efficiency, this is invoked only when the lines do not match exactly
888 but an option like -i might cause us to ignore the difference.
889 Return nonzero if the lines differ. */
890
891 bool
892 GnuDiff::lines_differ (const QChar *s1, const QChar *s2)
893 {
894 const QChar *t1 = s1;
895 const QChar *t2 = s2;
896
897 while (1)
898 {
899 QChar c1 = *t1++;
900 QChar c2 = *t2++;
901
902 /* Test for exact char equality first, since it's a common case. */
903 if (c1 != c2)
904 {
905 while ( bIgnoreWhiteSpace && isWhite( c1 ) ||
906 bIgnoreNumbers && (c1.isDigit() || c1=='-' || c1=='.' ))
907 c1 = *t1++;
908
909 while ( bIgnoreWhiteSpace && isWhite( c2 ) ||
910 bIgnoreNumbers && (c2.isDigit() || c2=='-' || c2=='.' ))
911 c2 = *t2++;
912
913 /* Lowercase all letters if -i is specified. */
914
915 if (ignore_case)
916 {
917 c1 = c1.lower();
918 c2 = c2.lower();
919 }
920
921 if (c1 != c2)
922 break;
923 }
924 if (c1 == '\n')
925 return 0;
926 }
927
928 return 1;
929 }
930