Main Page | Class Hierarchy | Class List | File List | Class Members

Hunk3.cs

00001 namespace JLibDiff
00002 {
00003         using System;
00004         
00005         /*
00006         * The <code>Hunk3</code> class represents a bloc of difference of three
00007         * files or  three Buffers.
00008         */
00009         public class Hunk3
00010         {
00011                 private void  InitBlock()
00012                 {
00013                          for (int i = 0; i < 3; i++)
00014                         {
00015                                 range[i] = new int[2];
00016                         }
00017                 }
00018                 
00019                 internal DiffType diff;
00020                 internal int[][] range = new int[3][];
00021                 
00022                 internal System.Collections.ArrayList a = new System.Collections.ArrayList();
00023                 internal System.Collections.ArrayList b = new System.Collections.ArrayList();
00024                 internal System.Collections.ArrayList c = new System.Collections.ArrayList();
00025                 
00026                 /*
00027                 * Allocates a new Hunk3.
00028                 */
00029                 public Hunk3()
00030                 {
00031                         InitBlock();
00032                 }
00033                 
00034                 /*
00035                 * Set range of difference which consern this bloc in etch file by values
00036                 * passed in argument.
00037                 *
00038                 * @param low0  start position of bloc of difference in the first file.
00039                 * @param high0 end position of bloc ob difference in thefirst file.   
00040                 * @param low1  start position of bloc of difference in the second file.
00041                 * @param high1 end position of bloc ob difference in the second file. 
00042                 * @param lowc  start position of bloc of difference in the therd file.
00043                 * @param highc end position of bloc ob difference in the therd file.
00044                 */
00045                 public virtual void  setRange(int low0, int high0, int low1, int high1, int lowc, int highc)
00046                 {
00047                         range[0][0] = low0;
00048                         range[0][1] = high0;
00049                         range[1][0] = low1;
00050                         range[1][1] = high1;
00051                         range[2][0] = lowc;
00052                         range[2][0] = highc;
00053                 }
00054                 
00055                 /*
00056                 * Returns a string representation of the current Hunk with normal format.
00057                 */
00058                 public virtual System.String convert()
00059                 {
00060                         int i;
00061                         int dontprint = 0;
00062                         int oddoneout;
00063                         System.Console.Out.Write("----------" + diff.code() + "\n");
00064                         System.String s = new System.String("====".ToCharArray());
00065                         switch (diff.code())
00066                         {
00067                                 case 5: 
00068                                         dontprint = 3;
00069                                         oddoneout = 3;
00070                                         s = System.String.Concat(s, "\n");
00071                                         break;
00072                                 
00073                                 case 6: case 7: case 8: 
00074                                         oddoneout = (int) diff.code() - 6;
00075                                         if (oddoneout == 0)
00076                                                 dontprint = 1;
00077                                         else
00078                                                 dontprint = 0;
00079                                         s = System.String.Concat(s, (+ oddoneout + 1) + "\n");
00080                                         break;
00081                                 
00082                                 default: 
00083                                         break;
00084                                 
00085                         }
00086                          for (i = 0; i < 3; i++)
00087                         {
00088                                 int lowt = this.lowLine(i), hight = this.highLine(i);
00089                                 s = System.String.Concat(s, + (i + 1) + ":");
00090                                 switch (lowt - hight)
00091                                 {
00092                                         case 1: 
00093                                                 s = System.String.Concat(s, + (lowt - 1) + "a\n");
00094                                                 break;
00095                                         
00096                                         case 0: 
00097                                                 s = System.String.Concat(s, + lowt + "c\n");
00098                                                 break;
00099                                         
00100                                         default: 
00101                                                 s = System.String.Concat(s, + lowt + "," + hight + "c\n");
00102                                                 break;
00103                                         
00104                                 }
00105                                 if (i == dontprint)
00106                                         continue;
00107                                 if (lowt <= hight)
00108                                 {
00109                                         
00110                                 }
00111                         }
00112                         return s;
00113                 }
00114                 
00115                 /*
00116                 * Returns the value of position of bloc start line reliding the
00117                 * file passed in argument.
00118                 *
00119                 * @param filenum   file number which can be:
00120                 *                    0 to indicate first file.
00121                 *                    1 to indicate second file.
00122                 *                    2 to indicate therd file.
00123                 */
00124                 public virtual int lowLine(int filenum)
00125                 {
00126                         return range[filenum][0];
00127                 }
00128                 
00129                 /*
00130                 * Returns the value of position of bloc end line reliding the
00131                 * file passed in argument.
00132                 *
00133                 * @param filenum   file number which can be:
00134                 *                    0 to indicate first file.
00135                 *                    1 to indicate second file.
00136                 *                    2 to indicate therd file.
00137                 */
00138                 public virtual int highLine(int filenum)
00139                 {
00140                         return range[filenum][1];
00141                 }
00142                 
00143                 /*
00144                 * Returns the number of lines reliding this bloc of difference and the
00145                 * file passed in argument.
00146                 *
00147                 * @param filenum   file number which can be:
00148                 *                    0 to indicate first file.
00149                 *                    1 to indicate second file.
00150                 *                    2 to indicate therd file.
00151                 */
00152                 public virtual int numLines(int filenum)
00153                 {
00154                         return (range[filenum][1] - range[filenum][0] + 1);
00155                 }
00156         }
00157 }

Generated on Mon May 8 22:07:27 2006 by  doxygen 1.3.9.1