/** * Print a hunk of a normal diff. This is a contiguous portion of a complete edit script, * describing changes in consecutive lines. */ @Override protected void print_hunk(final Diff.change hunk) { /* Determine range of line numbers involved in each file. */ analyze_hunk(hunk); if ((this.deletes == 0) && (this.inserts == 0)) { return; } /* Print out the line number header for this hunk */ print_number_range(',', this.first0, this.last0); this.outfile.print(Base.change_letter(this.inserts, this.deletes)); print_number_range(',', this.first1, this.last1); this.outfile.println(); /* Print the lines that the first file has. */ if (this.deletes != 0) { for (int i = this.first0; i <= this.last0; i++) { print_1_line("< ", this.file0[i]); } } if ((this.inserts != 0) && (this.deletes != 0)) { this.outfile.println("---"); } /* Print the lines that the second file has. */ if (this.inserts != 0) { for (int i = this.first1; i <= this.last1; i++) { print_1_line("> ", this.file1[i]); } } }
/** Print a hunk of an ed diff */ @Override protected void print_hunk(final Diff.change hunk) { /* Determine range of line numbers involved in each file. */ analyze_hunk(hunk); if ((this.deletes == 0) && (this.inserts == 0)) { return; } /* Print out the line number header for this hunk */ print_number_range(',', this.first0, this.last0); this.outfile.println(Base.change_letter(this.inserts, this.deletes)); /* Print new/changed lines from second file, if needed */ if (this.inserts != 0) { boolean inserting = true; for (int i = this.first1; i <= this.last1; i++) { /* Resume the insert, if we stopped. */ if (!inserting) { this.outfile.println(i - this.first1 + this.first0 + "a"); } inserting = true; /* If the file's line is just a dot, it would confuse `ed'. So output it with a double dot, and set the flag LEADING_DOT so that we will output another ed-command later to change the double dot into a single dot. */ if (".".equals(this.file1[i])) { this.outfile.println(".."); this.outfile.println("."); /* Now change that double dot to the desired single dot. */ this.outfile.println(i - this.first1 + this.first0 + 1 + "s/^\\.\\././"); inserting = false; } else { /* Line is not `.', so output it unmodified. */ print_1_line("", this.file1[i]); } } /* End insert mode, if we are still in it. */ if (inserting) { this.outfile.println("."); } } }